@@ -9,18 +9,22 @@ import type { ContentUpdater } from "./content-updater.js";
99export function patchInstrumentation ( updater : ContentUpdater , buildOpts : BuildOptions ) {
1010 const builtInstrumentationPath = getBuiltInstrumentationPath ( buildOpts ) ;
1111
12- return [
13- updater . updateContent (
14- "patch-load-instrumentation" ,
15- { filter : / \. ( j s | m j s | c j s | j s x | t s | t s x ) $ / , contentFilter : / a s y n c l o a d I n s t r u m e n t a t i o n M o d u l e \( / } ,
16- async ( { contents } ) => patchCode ( contents , getNext15Rule ( builtInstrumentationPath ) )
17- ) ,
18- updater . updateContent (
19- "patch-prepareImpl" ,
20- { filter : / \. ( j s | m j s | c j s | j s x | t s | t s x ) $ / , contentFilter : / a s y n c p r e p a r e I m p l \( / } ,
21- async ( { contents } ) => patchCode ( contents , getNext14Rule ( builtInstrumentationPath ) )
22- ) ,
23- ] ;
12+ updater . updateContent (
13+ "patch-instrumentation-next15" ,
14+ { filter : / \. ( j s | m j s | c j s | j s x | t s | t s x ) $ / , contentFilter : / a s y n c l o a d I n s t r u m e n t a t i o n M o d u l e \( / } ,
15+ async ( { contents } ) => patchCode ( contents , getNext15Rule ( builtInstrumentationPath ) )
16+ ) ;
17+
18+ updater . updateContent (
19+ "patch-instrumentation-next14" ,
20+ { filter : / \. ( j s | m j s | c j s | j s x | t s | t s x ) $ / , contentFilter : / a s y n c p r e p a r e I m p l \( / } ,
21+ async ( { contents } ) => patchCode ( contents , getNext14Rule ( builtInstrumentationPath ) )
22+ ) ;
23+
24+ return {
25+ "patch-instrumentation" ,
26+ setup ( ) { } ,
27+ } ;
2428}
2529
2630export 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 */
6771function 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