@opennextjs/cloudflare 1.11.0 → 1.11.1
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.
- package/dist/cli/build/build.js +9 -3
- package/dist/cli/build/open-next/compileDurableObjects.js +4 -4
- package/dist/cli/build/utils/middleware.d.ts +8 -0
- package/dist/cli/build/utils/middleware.js +21 -0
- package/dist/cli/commands/helpers.js +12 -0
- package/dist/cli/commands/utils.js +2 -1
- package/package.json +1 -1
package/dist/cli/build/build.js
CHANGED
|
@@ -13,6 +13,7 @@ import { compileInit } from "./open-next/compile-init.js";
|
|
|
13
13
|
import { compileSkewProtection } from "./open-next/compile-skew-protection.js";
|
|
14
14
|
import { compileDurableObjects } from "./open-next/compileDurableObjects.js";
|
|
15
15
|
import { createServerBundle } from "./open-next/createServerBundle.js";
|
|
16
|
+
import { useNodeMiddleware } from "./utils/middleware.js";
|
|
16
17
|
import { getVersion } from "./utils/version.js";
|
|
17
18
|
/**
|
|
18
19
|
* Builds the application in a format that can be passed to workerd
|
|
@@ -45,13 +46,18 @@ export async function build(options, config, projectOpts, wranglerConfig) {
|
|
|
45
46
|
setStandaloneBuildMode(options);
|
|
46
47
|
buildNextjsApp(options);
|
|
47
48
|
}
|
|
49
|
+
// Make sure no Node.js middleware is used
|
|
50
|
+
if (useNodeMiddleware(options)) {
|
|
51
|
+
logger.error("Node.js middleware is not currently supported. Consider switching to Edge Middleware.");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
48
54
|
// Generate deployable bundle
|
|
49
55
|
printHeader("Generating bundle");
|
|
50
56
|
compileCache(options);
|
|
51
57
|
compileEnvFiles(options);
|
|
52
|
-
compileInit(options, wranglerConfig);
|
|
53
|
-
compileImages(options);
|
|
54
|
-
compileSkewProtection(options, config);
|
|
58
|
+
await compileInit(options, wranglerConfig);
|
|
59
|
+
await compileImages(options);
|
|
60
|
+
await compileSkewProtection(options, config);
|
|
55
61
|
// Compile middleware
|
|
56
62
|
await createMiddleware(options, { forceOnlyBuildOnce: true });
|
|
57
63
|
createStaticAssets(options, { useBasePath: true });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { loadBuildId, loadPrerenderManifest } from "@opennextjs/aws/adapters/config/util.js";
|
|
4
|
-
import { esbuildSync
|
|
4
|
+
import { esbuildSync } from "@opennextjs/aws/build/helper.js";
|
|
5
5
|
export function compileDurableObjects(buildOpts) {
|
|
6
6
|
const _require = createRequire(import.meta.url);
|
|
7
7
|
const entryPoints = [
|
|
@@ -9,10 +9,10 @@ export function compileDurableObjects(buildOpts) {
|
|
|
9
9
|
_require.resolve("@opennextjs/cloudflare/durable-objects/sharded-tag-cache"),
|
|
10
10
|
_require.resolve("@opennextjs/cloudflare/durable-objects/bucket-cache-purge"),
|
|
11
11
|
];
|
|
12
|
-
const
|
|
13
|
-
const prerenderManifest = loadPrerenderManifest(
|
|
12
|
+
const buildOutputDotNextDir = path.join(buildOpts.appBuildOutputPath, ".next");
|
|
13
|
+
const prerenderManifest = loadPrerenderManifest(buildOutputDotNextDir);
|
|
14
14
|
const previewModeId = prerenderManifest.preview.previewModeId;
|
|
15
|
-
const BUILD_ID = loadBuildId(
|
|
15
|
+
const BUILD_ID = loadBuildId(buildOutputDotNextDir);
|
|
16
16
|
return esbuildSync({
|
|
17
17
|
entryPoints,
|
|
18
18
|
bundle: true,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as buildHelper from "@opennextjs/aws/build/helper.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns whether the project is using a Node.js middleware.
|
|
4
|
+
*
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns Whether the project is using a Node.js middleware
|
|
7
|
+
*/
|
|
8
|
+
export declare function useNodeMiddleware(options: buildHelper.BuildOptions): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { loadFunctionsConfigManifest, loadMiddlewareManifest } from "@opennextjs/aws/adapters/config/util.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns whether the project is using a Node.js middleware.
|
|
5
|
+
*
|
|
6
|
+
* @param options
|
|
7
|
+
* @returns Whether the project is using a Node.js middleware
|
|
8
|
+
*/
|
|
9
|
+
export function useNodeMiddleware(options) {
|
|
10
|
+
const buildOutputDotNextDir = path.join(options.appBuildOutputPath, ".next");
|
|
11
|
+
// Look for the edge middleware
|
|
12
|
+
const middlewareManifest = loadMiddlewareManifest(buildOutputDotNextDir);
|
|
13
|
+
const edgeMiddleware = middlewareManifest.middleware["/"];
|
|
14
|
+
if (edgeMiddleware) {
|
|
15
|
+
// The app uses an edge middleware
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
// Look for the node middleware
|
|
19
|
+
const functionsConfigManifest = loadFunctionsConfigManifest(buildOutputDotNextDir);
|
|
20
|
+
return Boolean(functionsConfigManifest?.functions["/_middleware"]);
|
|
21
|
+
}
|
|
@@ -71,6 +71,18 @@ export async function getEnvFromPlatformProxy(options, buildOpts) {
|
|
|
71
71
|
* @returns escaped arg
|
|
72
72
|
*/
|
|
73
73
|
export function quoteShellMeta(arg) {
|
|
74
|
+
if (process.platform === "win32") {
|
|
75
|
+
if (arg.length === 0) {
|
|
76
|
+
return '""';
|
|
77
|
+
}
|
|
78
|
+
const needsEscaping = /[&|<>^()%!"]/;
|
|
79
|
+
const needsQuotes = /\s/.test(arg) || needsEscaping.test(arg);
|
|
80
|
+
let escaped = arg.replace(/"/g, '""');
|
|
81
|
+
if (/[&|<>^()%!]/.test(arg)) {
|
|
82
|
+
escaped = escaped.replace(/[&|<>^()%!]/g, "^$&");
|
|
83
|
+
}
|
|
84
|
+
return needsQuotes ? `"${escaped}"` : escaped;
|
|
85
|
+
}
|
|
74
86
|
if (/["\s]/.test(arg) && !/'/.test(arg)) {
|
|
75
87
|
return `'${arg.replace(/(['\\])/g, "\\$1")}'`;
|
|
76
88
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import url from "node:url";
|
|
4
5
|
import { compileOpenNextConfig } from "@opennextjs/aws/build/compileConfig.js";
|
|
5
6
|
import { normalizeOptions } from "@opennextjs/aws/build/helper.js";
|
|
6
7
|
import { printHeader, showWarningOnWindows } from "@opennextjs/aws/build/utils.js";
|
|
@@ -50,7 +51,7 @@ export async function retrieveCompiledConfig() {
|
|
|
50
51
|
logger.error("Could not find compiled Open Next config, did you run the build command?");
|
|
51
52
|
process.exit(1);
|
|
52
53
|
}
|
|
53
|
-
const config = await import(configPath).then((mod) => mod.default);
|
|
54
|
+
const config = await import(url.pathToFileURL(configPath).href).then((mod) => mod.default);
|
|
54
55
|
ensureCloudflareConfig(config);
|
|
55
56
|
return { config };
|
|
56
57
|
}
|