@opennextjs/cloudflare 0.4.6 → 0.4.8

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.
Files changed (48) hide show
  1. package/dist/api/kv-cache.d.ts +22 -0
  2. package/dist/api/kv-cache.js +123 -0
  3. package/dist/api/kvCache.d.ts +3 -20
  4. package/dist/api/kvCache.js +3 -106
  5. package/dist/cli/build/bundle-server.js +12 -17
  6. package/dist/cli/build/open-next/copyCacheAssets.js +1 -1
  7. package/dist/cli/build/patches/ast/webpack-runtime.d.ts +23 -0
  8. package/dist/cli/build/patches/ast/webpack-runtime.js +57 -0
  9. package/dist/cli/build/patches/ast/webpack-runtime.spec.js +57 -0
  10. package/dist/cli/build/patches/investigated/index.d.ts +0 -1
  11. package/dist/cli/build/patches/investigated/index.js +0 -1
  12. package/dist/cli/build/patches/plugins/content-updater.d.ts +34 -0
  13. package/dist/cli/build/patches/plugins/content-updater.js +52 -0
  14. package/dist/cli/build/patches/plugins/load-instrumentation.d.ts +6 -0
  15. package/dist/cli/build/patches/plugins/load-instrumentation.js +20 -0
  16. package/dist/cli/build/patches/plugins/load-instrumentation.spec.js +45 -0
  17. package/dist/cli/build/patches/plugins/require-hook.d.ts +3 -0
  18. package/dist/cli/build/patches/plugins/require-hook.js +13 -0
  19. package/dist/cli/build/patches/plugins/require-page.d.ts +2 -5
  20. package/dist/cli/build/patches/plugins/require-page.js +30 -29
  21. package/dist/cli/build/patches/plugins/require.d.ts +2 -5
  22. package/dist/cli/build/patches/plugins/require.js +36 -43
  23. package/dist/cli/build/patches/to-investigate/index.d.ts +0 -1
  24. package/dist/cli/build/patches/to-investigate/index.js +0 -1
  25. package/dist/cli/build/utils/ensure-cf-config.js +7 -2
  26. package/dist/cli/build/utils/index.d.ts +0 -1
  27. package/dist/cli/build/utils/index.js +0 -1
  28. package/dist/cli/utils/ask-confirmation.js +2 -1
  29. package/package.json +3 -4
  30. package/templates/defaults/open-next.config.ts +1 -1
  31. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.d.ts +0 -13
  32. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.js +0 -82
  33. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.test.js +0 -20
  34. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.d.ts +0 -19
  35. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.js +0 -84
  36. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.test.js +0 -25
  37. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.d.ts +0 -14
  38. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.js +0 -22
  39. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.test.d.ts +0 -1
  40. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.test.js +0 -15
  41. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/index.d.ts +0 -5
  42. package/dist/cli/build/patches/investigated/update-webpack-chunks-file/index.js +0 -22
  43. package/dist/cli/build/patches/to-investigate/patch-load-instrumentation-module.d.ts +0 -14
  44. package/dist/cli/build/patches/to-investigate/patch-load-instrumentation-module.js +0 -34
  45. package/dist/cli/build/utils/ts-parse-file.d.ts +0 -8
  46. package/dist/cli/build/utils/ts-parse-file.js +0 -12
  47. /package/dist/cli/build/patches/{investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.test.d.ts → ast/webpack-runtime.spec.d.ts} +0 -0
  48. /package/dist/cli/build/patches/{investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.test.d.ts → plugins/load-instrumentation.spec.d.ts} +0 -0
@@ -1,22 +0,0 @@
1
- import { tsParseFile } from "../../../utils/index.js";
2
- import { getChunkInstallationIdentifiers } from "./get-chunk-installation-identifiers.js";
3
- import { getFileContentWithUpdatedWebpackFRequireCode } from "./get-file-content-with-updated-webpack-f-require-code.js";
4
- /**
5
- * Updates the content of the webpack runtime file in a manner so that it doesn't perform runtime dynamic `require` calls which fail in our runtime.
6
- *
7
- * It does so by appropriately updating a function that in the unminified webpack runtime file appears as `__webpack_require__.f.require` which is
8
- * the one that normally would cause dynamic requires to happen at runtime.
9
- *
10
- * `__webpack_require__.f.require` example: https://github.com/webpack/webpack/blob/dae16ad11e/examples/module-worker/README.md?plain=1#L284-L304
11
- *
12
- *
13
- * @param fileContent the content of the webpack runtime file
14
- * @param chunks the identifiers of the chunks (found on the filesystem)
15
- * @returns the content of the webpack runtime file updated with our custom logic
16
- */
17
- export async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
18
- const tsSourceFile = tsParseFile(fileContent);
19
- const chunkInstallationIdentifiers = await getChunkInstallationIdentifiers(tsSourceFile);
20
- const updatedFileContent = getFileContentWithUpdatedWebpackFRequireCode(tsSourceFile, chunkInstallationIdentifiers, chunks);
21
- return updatedFileContent;
22
- }
@@ -1,15 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { describe, expect, test } from "vitest";
3
- import { getUpdatedWebpackChunksFileContent } from "./get-updated-webpack-chunks-file-content.js";
4
- describe("getUpdatedWebpackChunksFileContent", () => {
5
- test("returns the updated content of a webpack runtime chunks unminified file", async () => {
6
- const fileContent = await readFile(`${import.meta.dirname}/test-fixtures/unminified-webpacks-file.js`, "utf8");
7
- const updatedContent = await getUpdatedWebpackChunksFileContent(fileContent, ["658"]);
8
- expect(updatedContent).toMatchFileSnapshot("./test-snapshots/unminified-webpacks-file.js");
9
- });
10
- test("returns the updated content of a webpack runtime chunks minified file", async () => {
11
- const fileContent = await readFile(`${import.meta.dirname}/test-fixtures/minified-webpacks-file.js`, "utf8");
12
- const updatedContent = await getUpdatedWebpackChunksFileContent(fileContent, ["658"]);
13
- expect(updatedContent).toMatchFileSnapshot("./test-snapshots/minified-webpacks-file.js");
14
- });
15
- });
@@ -1,5 +0,0 @@
1
- import { type BuildOptions } from "@opennextjs/aws/build/helper.js";
2
- /**
3
- * Fixes the webpack-runtime.js file by removing its webpack dynamic requires.
4
- */
5
- export declare function updateWebpackChunksFile(buildOpts: BuildOptions): Promise<void>;
@@ -1,22 +0,0 @@
1
- import { readdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { getPackagePath } from "@opennextjs/aws/build/helper.js";
4
- import { getUpdatedWebpackChunksFileContent } from "./get-updated-webpack-chunks-file-content.js";
5
- /**
6
- * Fixes the webpack-runtime.js file by removing its webpack dynamic requires.
7
- */
8
- export async function updateWebpackChunksFile(buildOpts) {
9
- console.log("# updateWebpackChunksFile");
10
- const { outputDir } = buildOpts;
11
- const dotNextServerDir = join(outputDir, "server-functions/default", getPackagePath(buildOpts), ".next/server");
12
- const webpackRuntimeFile = join(dotNextServerDir, "webpack-runtime.js");
13
- const fileContent = readFileSync(webpackRuntimeFile, "utf-8");
14
- const chunks = readdirSync(join(dotNextServerDir, "chunks"))
15
- .filter((chunk) => /^\d+\.js$/.test(chunk))
16
- .map((chunk) => {
17
- console.log(` - chunk ${chunk}`);
18
- return chunk.replace(/\.js$/, "");
19
- });
20
- const updatedFileContent = await getUpdatedWebpackChunksFileContent(fileContent, chunks);
21
- writeFileSync(webpackRuntimeFile, updatedFileContent);
22
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * The `loadInstrumentationModule` method (source: https://github.com/vercel/next.js/blob/5b7833e3/packages/next/src/server/next-server.ts#L301)
3
- * calls `module.findSourceMap` (https://nodejs.org/api/module.html#modulefindsourcemappath) which we haven't implemented causing a runtime error.
4
- *
5
- * To solve this issue this function gets all the `loadInstrumentationModule` declarations found in the file and removes all the statements
6
- * from their bodies (making them no-op methods).
7
- *
8
- * Instrumentation is a Next.js feature for monitoring and logging (see: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation),
9
- * the removal of this method's logic most likely breaks this feature (see: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation),
10
- * so this function is likely temporary and something that we'll have to fix in the future.
11
- *
12
- * TODO: investigate and re-enable instrumentation (https://github.com/opennextjs/opennextjs-cloudflare/issues/171)
13
- */
14
- export declare function patchLoadInstrumentationModule(code: string): string;
@@ -1,34 +0,0 @@
1
- import * as ts from "ts-morph";
2
- import { tsParseFile } from "../../utils/index.js";
3
- /**
4
- * The `loadInstrumentationModule` method (source: https://github.com/vercel/next.js/blob/5b7833e3/packages/next/src/server/next-server.ts#L301)
5
- * calls `module.findSourceMap` (https://nodejs.org/api/module.html#modulefindsourcemappath) which we haven't implemented causing a runtime error.
6
- *
7
- * To solve this issue this function gets all the `loadInstrumentationModule` declarations found in the file and removes all the statements
8
- * from their bodies (making them no-op methods).
9
- *
10
- * Instrumentation is a Next.js feature for monitoring and logging (see: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation),
11
- * the removal of this method's logic most likely breaks this feature (see: https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation),
12
- * so this function is likely temporary and something that we'll have to fix in the future.
13
- *
14
- * TODO: investigate and re-enable instrumentation (https://github.com/opennextjs/opennextjs-cloudflare/issues/171)
15
- */
16
- export function patchLoadInstrumentationModule(code) {
17
- const file = tsParseFile(code);
18
- const loadInstrumentationModuleDeclarations = file
19
- .getDescendantsOfKind(ts.SyntaxKind.MethodDeclaration)
20
- .filter((methodDeclaration) => {
21
- if (methodDeclaration.getName() !== "loadInstrumentationModule") {
22
- return false;
23
- }
24
- const methodModifierKinds = methodDeclaration.getModifiers().map((modifier) => modifier.getKind());
25
- if (methodModifierKinds.length !== 1 || methodModifierKinds[0] !== ts.SyntaxKind.AsyncKeyword) {
26
- return false;
27
- }
28
- return true;
29
- });
30
- loadInstrumentationModuleDeclarations.forEach((loadInstrumentationModuleDeclaration) => {
31
- loadInstrumentationModuleDeclaration.setBodyText("");
32
- });
33
- return file.print();
34
- }
@@ -1,8 +0,0 @@
1
- import * as ts from "ts-morph";
2
- /**
3
- * Parses a javascript file using ts-morph.
4
- *
5
- * @param fileContent the content of the file to parse
6
- * @returns the parsed result
7
- */
8
- export declare function tsParseFile(fileContent: string): ts.SourceFile;
@@ -1,12 +0,0 @@
1
- import * as ts from "ts-morph";
2
- /**
3
- * Parses a javascript file using ts-morph.
4
- *
5
- * @param fileContent the content of the file to parse
6
- * @returns the parsed result
7
- */
8
- export function tsParseFile(fileContent) {
9
- const project = new ts.Project();
10
- const sourceFile = project.createSourceFile("file.js", fileContent);
11
- return sourceFile;
12
- }