Skip to content

Commit e690889

Browse files
Apply suggestions from code review
Co-authored-by: Victor Berchet <[email protected]>
1 parent f77ff61 commit e690889

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

packages/cloudflare/src/cli/build/bundle-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export async function bundleServer(buildOpts: BuildOptions): Promise<void> {
9191
setWranglerExternal(),
9292
fixRequire(updater),
9393
handleOptionalDependencies(optionalDependencies),
94-
...patchInstrumentation(updater, buildOpts),
94+
patchInstrumentation(updater, buildOpts),
9595
patchFetchCacheSetMissingWaitUntil(updater),
9696
inlineEvalManifest(updater, buildOpts),
9797
inlineFindDir(updater, buildOpts),

packages/cloudflare/src/cli/build/patches/plugins/instrumentation.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ import type { ContentUpdater } from "./content-updater.js";
99
export function patchInstrumentation(updater: ContentUpdater, buildOpts: BuildOptions) {
1010
const builtInstrumentationPath = getBuiltInstrumentationPath(buildOpts);
1111

12-
return [
13-
updater.updateContent(
14-
"patch-load-instrumentation",
15-
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /async loadInstrumentationModule\(/ },
16-
async ({ contents }) => patchCode(contents, getNext15Rule(builtInstrumentationPath))
17-
),
18-
updater.updateContent(
19-
"patch-prepareImpl",
20-
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /async prepareImpl\(/ },
21-
async ({ contents }) => patchCode(contents, getNext14Rule(builtInstrumentationPath))
22-
),
23-
];
12+
updater.updateContent(
13+
"patch-instrumentation-next15",
14+
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /async loadInstrumentationModule\(/ },
15+
async ({ contents }) => patchCode(contents, getNext15Rule(builtInstrumentationPath))
16+
);
17+
18+
updater.updateContent(
19+
"patch-instrumentation-next14",
20+
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /async prepareImpl\(/ },
21+
async ({ contents }) => patchCode(contents, getNext14Rule(builtInstrumentationPath))
22+
);
23+
24+
return {
25+
"patch-instrumentation",
26+
setup() {},
27+
};
2428
}
2529

2630
export function getNext15Rule(builtInstrumentationPath: string | null) {
@@ -62,19 +66,15 @@ export function getNext14Rule(builtInstrumentationPath: string | null) {
6266
* instrumentation hook is provided in the app's source
6367
*
6468
* @param buildOpts the open-next build options
65-
* @returns a string pointing to the instrumentation.js file location, or null if such file is not found
69+
* @returns the path to instrumentation.js, or null if it doesn't exist
6670
*/
6771
function getBuiltInstrumentationPath(buildOpts: BuildOptions): string | null {
6872
const { outputDir } = buildOpts;
6973

70-
const baseDir = join(outputDir, "server-functions/default", getPackagePath(buildOpts));
71-
const dotNextDir = join(baseDir, ".next");
72-
const maybeBuiltInstrumentationPath = join(dotNextDir, "server", `${INSTRUMENTATION_HOOK_FILENAME}.js`);
73-
const builtInstrumentationPath = existsSync(maybeBuiltInstrumentationPath)
74+
const maybeBuiltInstrumentationPath = join(outputDir, "server-functions/default", getPackagePath(buildOpts), `.next/server/${INSTRUMENTATION_HOOK_FILENAME}.js` );
75+
return existsSync(maybeBuiltInstrumentationPath)
7476
? maybeBuiltInstrumentationPath
7577
: null;
76-
77-
return builtInstrumentationPath;
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)