@opennextjs/cloudflare 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -68,9 +68,17 @@ export async function getFileContentWithUpdatedWebpackFRequireCode(sourceFile, {
|
|
|
68
68
|
.map((parameter) => parameter.getName());
|
|
69
69
|
const chunkId = functionParameterNames[0];
|
|
70
70
|
const functionBody = webpackFRequireFunction.getBody();
|
|
71
|
-
functionBody.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
functionBody.replaceWithText(`
|
|
72
|
+
{
|
|
73
|
+
if (${installedChunks}[${chunkId}]) {
|
|
74
|
+
return;
|
|
75
|
+
}${chunks
|
|
76
|
+
.map((chunk) => `
|
|
77
|
+
if(${chunkId} === ${chunk}) {
|
|
78
|
+
return ${installChunk}(require("./chunks/${chunk}.js"));
|
|
79
|
+
}`)
|
|
80
|
+
.join("")}
|
|
81
|
+
throw new Error(\`Unknown chunk \${${chunkId}}\`);
|
|
82
|
+
}`);
|
|
75
83
|
return sourceFile.print();
|
|
76
84
|
}
|
|
@@ -7,15 +7,17 @@ describe("getFileContentWithUpdatedWebpackFRequireCode", () => {
|
|
|
7
7
|
const fileContent = await readFile(`${import.meta.dirname}/test-fixtures/unminified-webpacks-file.js`, "utf8");
|
|
8
8
|
const tsSourceFile = tsParseFile(fileContent);
|
|
9
9
|
const updatedFCode = await getFileContentWithUpdatedWebpackFRequireCode(tsSourceFile, { installChunk: "installChunk", installedChunks: "installedChunks" }, ["658"]);
|
|
10
|
-
expect(unstyleCode(updatedFCode)).toContain(`if (installedChunks[chunkId]) return
|
|
11
|
-
expect(unstyleCode(updatedFCode)).toContain(`if (chunkId === 658) return installChunk(require("./chunks/658.js"))
|
|
10
|
+
expect(unstyleCode(updatedFCode)).toContain(`if (installedChunks[chunkId]) { return; }`);
|
|
11
|
+
expect(unstyleCode(updatedFCode)).toContain(`if (chunkId === 658) { return installChunk(require("./chunks/658.js")); }`);
|
|
12
|
+
expect(unstyleCode(updatedFCode)).not.toContain(`require("./chunks/" +`);
|
|
12
13
|
});
|
|
13
14
|
test("returns the updated content of the f.require function from minified webpack runtime code", async () => {
|
|
14
15
|
const fileContent = await readFile(`${import.meta.dirname}/test-fixtures/minified-webpacks-file.js`, "utf8");
|
|
15
16
|
const tsSourceFile = tsParseFile(fileContent);
|
|
16
17
|
const updatedFCode = await getFileContentWithUpdatedWebpackFRequireCode(tsSourceFile, { installChunk: "r", installedChunks: "e" }, ["658"]);
|
|
17
|
-
expect(unstyleCode(updatedFCode)).toContain("if (e[o]) return;");
|
|
18
|
-
expect(unstyleCode(updatedFCode)).toContain(`if (o === 658) return r(require("./chunks/658.js"))
|
|
18
|
+
expect(unstyleCode(updatedFCode)).toContain("if (e[o]) { return; }");
|
|
19
|
+
expect(unstyleCode(updatedFCode)).toContain(`if (o === 658) { return r(require("./chunks/658.js")); }`);
|
|
20
|
+
expect(unstyleCode(updatedFCode)).not.toContain(`require("./chunks/" +`);
|
|
19
21
|
});
|
|
20
22
|
});
|
|
21
23
|
function unstyleCode(text) {
|