Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/funny-onions-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/cloudflare": patch
---

bump @opennextjs/aws to 3.7.2

See details at <https://github.com/opennextjs/opennextjs-aws/releases/tag/v3.7.2>
2 changes: 1 addition & 1 deletion packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
"dependencies": {
"@dotenvx/dotenvx": "catalog:",
"@opennextjs/aws": "3.7.1",
"@opennextjs/aws": "3.7.2",
"cloudflare": "^4.4.1",
"enquirer": "^2.4.1",
"glob": "catalog:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,18 @@ function getRequires(idVariable: string, files: string[], serverDir: string) {
export function inlineDynamicRequires(updater: ContentUpdater, buildOpts: BuildOptions): Plugin {
updater.updateContent("inline-node-module-loader", [
{
field: {
filter: getCrossPlatformPathRegex(String.raw`/module-loader/node-module-loader\.js$`, {
escape: false,
}),
contentFilter: /class NodeModuleLoader {/,
callback: async ({ contents }) => patchCode(contents, await getNodeModuleLoaderRule(buildOpts)),
},
filter: getCrossPlatformPathRegex(String.raw`/module-loader/node-module-loader\.js$`, {
escape: false,
}),
contentFilter: /class NodeModuleLoader {/,
callback: async ({ contents }) => patchCode(contents, await getNodeModuleLoaderRule(buildOpts)),
},
]);
updater.updateContent("inline-require-page", [
{
field: {
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/require\.js$`, { escape: false }),
contentFilter: /function requirePage\(/,
callback: async ({ contents }) => patchCode(contents, await getRequirePageRule(buildOpts)),
},
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/require\.js$`, { escape: false }),
contentFilter: /function requirePage\(/,
callback: async ({ contents }) => patchCode(contents, await getRequirePageRule(buildOpts)),
},
]);
return { name: "inline-dynamic-requires", setup() {} };
Expand Down
8 changes: 3 additions & 5 deletions packages/cloudflare/src/cli/build/patches/plugins/find-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
export function inlineFindDir(updater: ContentUpdater, buildOpts: BuildOptions): Plugin {
return updater.updateContent("inline-find-dir", [
{
field: {
filter: getCrossPlatformPathRegex(String.raw`/next/dist/lib/find-pages-dir\.js$`, { escape: false }),
contentFilter: /function findDir\(/,
callback: async ({ contents }) => patchCode(contents, await getRule(buildOpts)),
},
filter: getCrossPlatformPathRegex(String.raw`/next/dist/lib/find-pages-dir\.js$`, { escape: false }),
contentFilter: /function findDir\(/,
callback: async ({ contents }) => patchCode(contents, await getRule(buildOpts)),
},
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,30 @@ export function patchInstrumentation(updater: ContentUpdater, buildOpts: BuildOp

updater.updateContent("patch-instrumentation-next15-4", [
{
field: {
filter: getCrossPlatformPathRegex(
String.raw`/server/lib/router-utils/instrumentation-globals.external\.js$`,
{
escape: false,
}
),
contentFilter: /getInstrumentationModule\(/,
callback: ({ contents }) => patchCode(contents, getNext154Rule(builtInstrumentationPath)),
},
filter: getCrossPlatformPathRegex(
String.raw`/server/lib/router-utils/instrumentation-globals.external\.js$`,
{
escape: false,
}
),
contentFilter: /getInstrumentationModule\(/,
callback: ({ contents }) => patchCode(contents, getNext154Rule(builtInstrumentationPath)),
},
]);

updater.updateContent("patch-instrumentation-next15", [
{
field: {
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /async loadInstrumentationModule\(/,
callback: ({ contents }) => patchCode(contents, getNext15Rule(builtInstrumentationPath)),
},
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /async loadInstrumentationModule\(/,
callback: ({ contents }) => patchCode(contents, getNext15Rule(builtInstrumentationPath)),
},
]);

updater.updateContent("patch-instrumentation-next14", [
{
field: {
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /async prepareImpl\(/,
callback: ({ contents }) => patchCode(contents, getNext14Rule(builtInstrumentationPath)),
},
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /async prepareImpl\(/,
callback: ({ contents }) => patchCode(contents, getNext14Rule(builtInstrumentationPath)),
},
]);

Expand Down
18 changes: 8 additions & 10 deletions packages/cloudflare/src/cli/build/patches/plugins/load-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ import { normalizePath } from "../../utils/normalize-path.js";
export function inlineLoadManifest(updater: ContentUpdater, buildOpts: BuildOptions): Plugin {
return updater.updateContent("inline-load-manifest", [
{
field: {
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/load-manifest(\.external)?\.js$`, {
escape: false,
}),
contentFilter: /function loadManifest\(/,
callback: async ({ contents }) => {
contents = await patchCode(contents, await getLoadManifestRule(buildOpts));
contents = await patchCode(contents, await getEvalManifestRule(buildOpts));
return contents;
},
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/load-manifest(\.external)?\.js$`, {
escape: false,
}),
contentFilter: /function loadManifest\(/,
callback: async ({ contents }) => {
contents = await patchCode(contents, await getLoadManifestRule(buildOpts));
contents = await patchCode(contents, await getEvalManifestRule(buildOpts));
return contents;
},
},
]);
Expand Down
36 changes: 17 additions & 19 deletions packages/cloudflare/src/cli/build/patches/plugins/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,26 @@ import { normalizePath } from "../../utils/index.js";
export function patchNextServer(updater: ContentUpdater, buildOpts: BuildOptions): Plugin {
return updater.updateContent("next-server", [
{
field: {
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/next-server\.js$`, {
escape: false,
}),
contentFilter: /getBuildId\(/,
callback: async ({ contents }) => {
const { outputDir } = buildOpts;
filter: getCrossPlatformPathRegex(String.raw`/next/dist/server/next-server\.js$`, {
escape: false,
}),
contentFilter: /getBuildId\(/,
callback: async ({ contents }) => {
const { outputDir } = buildOpts;

contents = patchCode(contents, buildIdRule);
contents = patchCode(contents, buildIdRule);

const outputPath = path.join(outputDir, "server-functions/default");
const cacheHandler = path.join(outputPath, getPackagePath(buildOpts), "cache.cjs");
contents = patchCode(contents, createCacheHandlerRule(cacheHandler));
const outputPath = path.join(outputDir, "server-functions/default");
const cacheHandler = path.join(outputPath, getPackagePath(buildOpts), "cache.cjs");
contents = patchCode(contents, createCacheHandlerRule(cacheHandler));

const composableCacheHandler = path.join(
outputPath,
getPackagePath(buildOpts),
"composable-cache.cjs"
);
contents = patchCode(contents, createComposableCacheHandlersRule(composableCacheHandler));
return contents;
},
const composableCacheHandler = path.join(
outputPath,
getPackagePath(buildOpts),
"composable-cache.cjs"
);
contents = patchCode(contents, createComposableCacheHandlersRule(composableCacheHandler));
return contents;
},
},
]);
Expand Down
14 changes: 6 additions & 8 deletions packages/cloudflare/src/cli/build/patches/plugins/open-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ export function patchResolveCache(updater: ContentUpdater, buildOpts: BuildOptio

return updater.updateContent("patch-resolve-cache", [
{
field: {
filter: getCrossPlatformPathRegex(indexPath),
contentFilter: /cacheHandlerPath/,
callback: async ({ contents }) => {
contents = patchCode(contents, cacheHandlerRule);
contents = patchCode(contents, compositeCacheHandlerRule);
return contents;
},
filter: getCrossPlatformPathRegex(indexPath),
contentFilter: /cacheHandlerPath/,
callback: async ({ contents }) => {
contents = patchCode(contents, cacheHandlerRule);
contents = patchCode(contents, compositeCacheHandlerRule);
return contents;
},
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import type { ContentUpdater, Plugin } from "@opennextjs/aws/plugins/content-upd
export function patchDepdDeprecations(updater: ContentUpdater): Plugin {
return updater.updateContent("patch-depd-deprecations", [
{
field: {
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /argument fn must be a function/,
callback: ({ contents }) => patchCode(contents, rule),
},
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /argument fn must be a function/,
callback: ({ contents }) => patchCode(contents, rule),
},
]);
}
Expand Down
80 changes: 39 additions & 41 deletions packages/cloudflare/src/cli/build/patches/plugins/require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,47 @@ import type { ContentUpdater, Plugin } from "@opennextjs/aws/plugins/content-upd
export function fixRequire(updater: ContentUpdater): Plugin {
return updater.updateContent("fix-require", [
{
field: {
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /.*/,
callback: ({ contents }) => {
// `eval(...)` is not supported by workerd.
contents = contents.replaceAll(`eval("require")`, "require");
filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/,
contentFilter: /.*/,
callback: ({ contents }) => {
// `eval(...)` is not supported by workerd.
contents = contents.replaceAll(`eval("require")`, "require");

// `@opentelemetry` has a few issues.
//
// Next.js has the following code in `next/dist/server/lib/trace/tracer.js`:
//
// try {
// api = require('@opentelemetry/api');
// } catch (err) {
// api = require('next/dist/compiled/@opentelemetry/api');
// }
//
// The intent is to allow users to install their own version of `@opentelemetry/api`.
//
// The problem is that even when users do not explicitly install `@opentelemetry/api`,
// `require('@opentelemetry/api')` resolves to the package which is a dependency
// of Next.
//
// The second problem is that when Next traces files, it would not copy the `api/build/esm`
// folder (used by the `module` conditions in package.json) it would only copy `api/build/src`.
// This could be solved by updating the next config:
//
// const nextConfig: NextConfig = {
// // ...
// outputFileTracingIncludes: {
// "*": ["./node_modules/@opentelemetry/api/build/**/*"],
// },
// };
//
// We can consider doing that when we want to enable users to install their own version
// of `@opentelemetry/api`. For now we simply use the pre-compiled version.
contents = contents.replace(
/require\(.@opentelemetry\/api.\)/g,
`require("next/dist/compiled/@opentelemetry/api")`
);
// `@opentelemetry` has a few issues.
//
// Next.js has the following code in `next/dist/server/lib/trace/tracer.js`:
//
// try {
// api = require('@opentelemetry/api');
// } catch (err) {
// api = require('next/dist/compiled/@opentelemetry/api');
// }
//
// The intent is to allow users to install their own version of `@opentelemetry/api`.
//
// The problem is that even when users do not explicitly install `@opentelemetry/api`,
// `require('@opentelemetry/api')` resolves to the package which is a dependency
// of Next.
//
// The second problem is that when Next traces files, it would not copy the `api/build/esm`
// folder (used by the `module` conditions in package.json) it would only copy `api/build/src`.
// This could be solved by updating the next config:
//
// const nextConfig: NextConfig = {
// // ...
// outputFileTracingIncludes: {
// "*": ["./node_modules/@opentelemetry/api/build/**/*"],
// },
// };
//
// We can consider doing that when we want to enable users to install their own version
// of `@opentelemetry/api`. For now we simply use the pre-compiled version.
contents = contents.replace(
/require\(.@opentelemetry\/api.\)/g,
`require("next/dist/compiled/@opentelemetry/api")`
);

return contents;
},
return contents;
},
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,14 @@ export const patchResRevalidate: CodePatcher = {
patches: [
{
versions: ">=14.2.0",
field: {
pathFilter: getCrossPlatformPathRegex(
String.raw`(pages-api\.runtime\.prod\.js|node/api-resolver\.js)$`,
{
escape: false,
}
),
contentFilter: /\.trustHostHeader/,
patchCode: async ({ code }) => patchCode(code, rule),
},
pathFilter: getCrossPlatformPathRegex(
String.raw`(pages-api\.runtime\.prod\.js|node/api-resolver\.js)$`,
{
escape: false,
}
),
contentFilter: /\.trustHostHeader/,
patchCode: async ({ code }) => patchCode(code, rule),
},
],
};
12 changes: 5 additions & 7 deletions packages/cloudflare/src/cli/build/patches/plugins/use-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ export const patchUseCacheIO: CodePatcher = {
patches: [
{
versions: ">=15.3.1",
field: {
pathFilter: getCrossPlatformPathRegex(String.raw`server/app-render/async-local-storage\.js$`, {
escape: false,
}),
contentFilter: /createSnapshot/,
patchCode: async ({ code }) => patchCode(code, rule),
},
pathFilter: getCrossPlatformPathRegex(String.raw`server/app-render/async-local-storage\.js$`, {
escape: false,
}),
contentFilter: /createSnapshot/,
patchCode: async ({ code }) => patchCode(code, rule),
},
],
};
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.