Skip to content

Commit a06e345

Browse files
change getRule params
1 parent 5644761 commit a06e345

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

packages/cloudflare/src/cli/build/patches/plugins/load-instrumentation.spec.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
21
import { describe, expect, test, vi } from "vitest";
32

43
import { patchCode } from "../ast/util.js";
@@ -46,17 +45,7 @@ export default class NextNodeServer extends BaseServer<
4645
}
4746
}`;
4847

49-
expect(
50-
patchCode(
51-
code,
52-
await getRule({
53-
appBuildOutputPath: "",
54-
appPath: "",
55-
monorepoRoot: "",
56-
outputDir: "",
57-
} as BuildOptions)
58-
)
59-
).toMatchInlineSnapshot(`
48+
expect(patchCode(code, await getRule("_file_does_not_exist_"))).toMatchInlineSnapshot(`
6049
"export default class NextNodeServer extends BaseServer<
6150
Options,
6251
NodeNextRequest,
@@ -98,23 +87,13 @@ export default class NextNodeServer extends BaseServer<
9887
}
9988
}`;
10089

101-
expect(
102-
patchCode(
103-
code,
104-
await getRule({
105-
appBuildOutputPath: "_file_exists_",
106-
appPath: "test",
107-
monorepoRoot: "",
108-
outputDir: "",
109-
} as BuildOptions)
110-
)
111-
).toMatchInlineSnapshot(`
90+
expect(patchCode(code, await getRule("/_file_exists_/instrumentation.js"))).toMatchInlineSnapshot(`
11291
"export default class NextNodeServer extends BaseServer<
11392
Options,
11493
NodeNextRequest,
11594
NodeNextResponse
11695
> {
117-
async loadInstrumentationModule() { this.instrumentation = require('server-functions/default/_file_exists_/.next/server/instrumentation.js'); return this.instrumentation; }
96+
async loadInstrumentationModule() { this.instrumentation = require('/_file_exists_/instrumentation.js'); return this.instrumentation; }
11897
}"
11998
`);
12099
});

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import { patchCode } from "../ast/util.js";
1111
import type { ContentUpdater } from "./content-updater.js";
1212

1313
export function patchLoadInstrumentation(updater: ContentUpdater, buildOpts: BuildOptions) {
14-
return updater.updateContent(
15-
"patch-load-instrumentation",
16-
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /async loadInstrumentationModule\(/ },
17-
async ({ contents }) => patchCode(contents, await getRule(buildOpts))
18-
);
19-
}
20-
21-
export async function getRule(buildOpts: BuildOptions) {
2214
const { outputDir } = buildOpts;
2315

2416
const baseDir = join(outputDir, "server-functions/default", getPackagePath(buildOpts));
2517
const dotNextDir = join(baseDir, ".next");
2618
const builtInstrumentationPath = join(dotNextDir, "server", `${INSTRUMENTATION_HOOK_FILENAME}.js`);
2719

20+
return updater.updateContent(
21+
"patch-load-instrumentation",
22+
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /async loadInstrumentationModule\(/ },
23+
async ({ contents }) => patchCode(contents, await getRule(builtInstrumentationPath))
24+
);
25+
}
26+
27+
export async function getRule(builtInstrumentationPath: string) {
2828
return `
2929
rule:
3030
kind: method_definition

0 commit comments

Comments
 (0)