@opennextjs/cloudflare 0.0.0-88fe982 → 0.0.0-9758666
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/README.md +40 -12
- package/dist/cache-handler.mjs +48 -0
- package/dist/chunk-UJCSKKID.mjs +30 -0
- package/dist/index.mjs +223 -201
- package/dist/templates/worker.ts +0 -1
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,37 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenNext for Cloudflare
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Deploy Next.js apps to Cloudflare!
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
OpenNext for Cloudflare is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
pnpm add -D wrangler@latest @opennextjs/cloudflare
|
|
9
|
-
```
|
|
7
|
+
## Getting started
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/create-next-app) to start a new application or take an existing Next.js application and deploy it to Cloudflare using the following few steps:
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Configure your app
|
|
12
|
+
|
|
13
|
+
- add the following `devDependencies` to the `package.json`:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
pnpm add -D wrangler@latest @opennextjs/cloudflare
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
- add a `wrangler.toml` at the root of your project
|
|
20
20
|
|
|
21
21
|
```toml
|
|
22
22
|
#:schema node_modules/wrangler/config-schema.json
|
|
23
|
-
name = "<app-name>"
|
|
23
|
+
name = "<your-app-name>"
|
|
24
24
|
main = ".worker-next/index.mjs"
|
|
25
25
|
|
|
26
|
-
compatibility_date = "2024-
|
|
27
|
-
compatibility_flags = ["
|
|
26
|
+
compatibility_date = "2024-09-23"
|
|
27
|
+
compatibility_flags = ["nodejs_compat"]
|
|
28
28
|
|
|
29
29
|
# Use the new Workers + Assets to host the static frontend files
|
|
30
30
|
experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" }
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
## Local development
|
|
34
|
+
|
|
35
|
+
- you can use the regular `next` CLI to start the Next.js dev server:
|
|
36
|
+
|
|
37
|
+
## Local preview
|
|
38
|
+
|
|
39
|
+
Run the following commands to preview the production build of your application locally:
|
|
40
|
+
|
|
41
|
+
- build the app and adapt it for Cloudflare
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pnpx cloudflare
|
|
45
|
+
```
|
|
46
|
+
|
|
33
47
|
- Preview the app in Wrangler
|
|
34
48
|
|
|
35
49
|
```bash
|
|
36
50
|
pnpm wrangler dev
|
|
37
51
|
```
|
|
52
|
+
|
|
53
|
+
## Deploy your app
|
|
54
|
+
|
|
55
|
+
Deploy your application to production with the following:
|
|
56
|
+
|
|
57
|
+
- build the app and adapt it for Cloudflare
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpx cloudflare
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm wrangler deploy
|
|
65
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import "./chunk-UJCSKKID.mjs";
|
|
2
|
+
|
|
3
|
+
// src/cache-handler.ts
|
|
4
|
+
var CfWorkersKvCacheHandler = class _CfWorkersKvCacheHandler {
|
|
5
|
+
constructor(ctx) {
|
|
6
|
+
this.ctx = ctx;
|
|
7
|
+
}
|
|
8
|
+
static maybeKVNamespace = void 0;
|
|
9
|
+
async get(key) {
|
|
10
|
+
if (_CfWorkersKvCacheHandler.maybeKVNamespace === void 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
console.log(`[Cf] Getting cache[${key}]`);
|
|
14
|
+
try {
|
|
15
|
+
return await _CfWorkersKvCacheHandler.maybeKVNamespace.get(key, "json") ?? null;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error(`Failed to get value for key = ${key}: ${e}`);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async set(key, entry, ctx) {
|
|
22
|
+
if (_CfWorkersKvCacheHandler.maybeKVNamespace === void 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
console.log(`[Cf] Setting cache[${key}]`);
|
|
26
|
+
try {
|
|
27
|
+
const data = {
|
|
28
|
+
lastModified: Date.now(),
|
|
29
|
+
value: entry
|
|
30
|
+
};
|
|
31
|
+
await _CfWorkersKvCacheHandler.maybeKVNamespace.put(key, JSON.stringify(data));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(`Failed to set value for key = ${key}: ${e}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async revalidateTag(tags) {
|
|
37
|
+
if (_CfWorkersKvCacheHandler.maybeKVNamespace === void 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
tags = [tags].flat();
|
|
41
|
+
console.log(`[Cf] revalidateTag ${JSON.stringify(tags)}}`);
|
|
42
|
+
}
|
|
43
|
+
resetRequestCache() {
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
CfWorkersKvCacheHandler as default
|
|
48
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
__commonJS,
|
|
29
|
+
__toESM
|
|
30
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
__commonJS,
|
|
4
|
+
__toESM
|
|
5
|
+
} from "./chunk-UJCSKKID.mjs";
|
|
26
6
|
|
|
27
|
-
//
|
|
7
|
+
// ../../node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
|
|
28
8
|
var require_balanced_match = __commonJS({
|
|
29
|
-
"
|
|
9
|
+
"../../node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js"(exports, module) {
|
|
30
10
|
"use strict";
|
|
31
11
|
module.exports = balanced;
|
|
32
12
|
function balanced(a, b, str) {
|
|
@@ -82,9 +62,9 @@ var require_balanced_match = __commonJS({
|
|
|
82
62
|
}
|
|
83
63
|
});
|
|
84
64
|
|
|
85
|
-
//
|
|
65
|
+
// ../../node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js
|
|
86
66
|
var require_brace_expansion = __commonJS({
|
|
87
|
-
"
|
|
67
|
+
"../../node_modules/.pnpm/brace-expansion@2.0.1/node_modules/brace-expansion/index.js"(exports, module) {
|
|
88
68
|
"use strict";
|
|
89
69
|
var balanced = require_balanced_match();
|
|
90
70
|
module.exports = expandTop;
|
|
@@ -266,15 +246,15 @@ function getArgs() {
|
|
|
266
246
|
skipBuild: skipBuild2 || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD))
|
|
267
247
|
};
|
|
268
248
|
}
|
|
269
|
-
function assertDirArg(
|
|
249
|
+
function assertDirArg(path12, argName, make) {
|
|
270
250
|
let dirStats;
|
|
271
251
|
try {
|
|
272
|
-
dirStats = statSync(
|
|
252
|
+
dirStats = statSync(path12);
|
|
273
253
|
} catch {
|
|
274
254
|
if (!make) {
|
|
275
255
|
throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
|
|
276
256
|
}
|
|
277
|
-
mkdirSync(
|
|
257
|
+
mkdirSync(path12);
|
|
278
258
|
return;
|
|
279
259
|
}
|
|
280
260
|
if (!dirStats.isDirectory()) {
|
|
@@ -283,7 +263,7 @@ function assertDirArg(path6, argName, make) {
|
|
|
283
263
|
}
|
|
284
264
|
|
|
285
265
|
// src/index.ts
|
|
286
|
-
import { existsSync as
|
|
266
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
287
267
|
|
|
288
268
|
// src/build/build.ts
|
|
289
269
|
import { rm } from "node:fs/promises";
|
|
@@ -309,8 +289,10 @@ function runNextBuildCommand(packager, nextAppDir2) {
|
|
|
309
289
|
|
|
310
290
|
// src/build/build-worker.ts
|
|
311
291
|
import { build } from "esbuild";
|
|
312
|
-
import { readFileSync as readFileSync4 } from "node:fs";
|
|
292
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
313
293
|
import { cp, readFile, writeFile } from "node:fs/promises";
|
|
294
|
+
import path9 from "node:path";
|
|
295
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
314
296
|
|
|
315
297
|
// src/build/patches/investigated/patch-require.ts
|
|
316
298
|
function patchRequire(code) {
|
|
@@ -318,23 +300,20 @@ function patchRequire(code) {
|
|
|
318
300
|
return code.replace(/__require\d?\(/g, "require(").replace(/__require\d?\./g, "require.");
|
|
319
301
|
}
|
|
320
302
|
|
|
321
|
-
// src/build/patches/investigated/copy-
|
|
322
|
-
import path from "node:path";
|
|
303
|
+
// src/build/patches/investigated/copy-package.ts
|
|
323
304
|
import { cpSync } from "node:fs";
|
|
324
|
-
function
|
|
325
|
-
console.log("#
|
|
326
|
-
|
|
327
|
-
cpSync(srcDir, destDir, { recursive: true });
|
|
328
|
-
return destDir;
|
|
305
|
+
function copyPackage(srcDir, config) {
|
|
306
|
+
console.log("# copyPackage");
|
|
307
|
+
cpSync(srcDir, config.paths.internalPackage, { recursive: true });
|
|
329
308
|
}
|
|
330
309
|
|
|
331
310
|
// src/build/patches/to-investigate/patch-read-file.ts
|
|
332
311
|
import { readFileSync } from "node:fs";
|
|
333
312
|
|
|
334
|
-
//
|
|
313
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
|
|
335
314
|
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
336
315
|
|
|
337
|
-
//
|
|
316
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
338
317
|
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
339
318
|
var assertValidPattern = (pattern) => {
|
|
340
319
|
if (typeof pattern !== "string") {
|
|
@@ -345,7 +324,7 @@ var assertValidPattern = (pattern) => {
|
|
|
345
324
|
}
|
|
346
325
|
};
|
|
347
326
|
|
|
348
|
-
//
|
|
327
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/brace-expressions.js
|
|
349
328
|
var posixClasses = {
|
|
350
329
|
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
351
330
|
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
@@ -454,12 +433,12 @@ var parseClass = (glob2, position) => {
|
|
|
454
433
|
return [comb, uflag, endPos - pos, true];
|
|
455
434
|
};
|
|
456
435
|
|
|
457
|
-
//
|
|
436
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/unescape.js
|
|
458
437
|
var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
459
438
|
return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
|
|
460
439
|
};
|
|
461
440
|
|
|
462
|
-
//
|
|
441
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/ast.js
|
|
463
442
|
var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
464
443
|
var isExtglobType = (c) => types.has(c);
|
|
465
444
|
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
@@ -938,12 +917,12 @@ var AST = class _AST {
|
|
|
938
917
|
}
|
|
939
918
|
};
|
|
940
919
|
|
|
941
|
-
//
|
|
920
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/escape.js
|
|
942
921
|
var escape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
943
922
|
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
944
923
|
};
|
|
945
924
|
|
|
946
|
-
//
|
|
925
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
|
|
947
926
|
var minimatch = (p, pattern, options = {}) => {
|
|
948
927
|
assertValidPattern(pattern);
|
|
949
928
|
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
@@ -1002,11 +981,11 @@ var qmarksTestNoExtDot = ([$0]) => {
|
|
|
1002
981
|
return (f) => f.length === len && f !== "." && f !== "..";
|
|
1003
982
|
};
|
|
1004
983
|
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
1005
|
-
var
|
|
984
|
+
var path = {
|
|
1006
985
|
win32: { sep: "\\" },
|
|
1007
986
|
posix: { sep: "/" }
|
|
1008
987
|
};
|
|
1009
|
-
var sep = defaultPlatform === "win32" ?
|
|
988
|
+
var sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
|
|
1010
989
|
minimatch.sep = sep;
|
|
1011
990
|
var GLOBSTAR = Symbol("globstar **");
|
|
1012
991
|
minimatch.GLOBSTAR = GLOBSTAR;
|
|
@@ -1661,10 +1640,10 @@ minimatch.Minimatch = Minimatch;
|
|
|
1661
1640
|
minimatch.escape = escape;
|
|
1662
1641
|
minimatch.unescape = unescape;
|
|
1663
1642
|
|
|
1664
|
-
//
|
|
1643
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/glob.js
|
|
1665
1644
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1666
1645
|
|
|
1667
|
-
//
|
|
1646
|
+
// ../../node_modules/.pnpm/lru-cache@11.0.0/node_modules/lru-cache/dist/esm/index.js
|
|
1668
1647
|
var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
1669
1648
|
var warned = /* @__PURE__ */ new Set();
|
|
1670
1649
|
var PROCESS = typeof process === "object" && !!process ? process : {};
|
|
@@ -3033,14 +3012,14 @@ var LRUCache = class _LRUCache {
|
|
|
3033
3012
|
}
|
|
3034
3013
|
};
|
|
3035
3014
|
|
|
3036
|
-
//
|
|
3015
|
+
// ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
|
|
3037
3016
|
import { posix, win32 } from "node:path";
|
|
3038
3017
|
import { fileURLToPath } from "node:url";
|
|
3039
3018
|
import { lstatSync, readdir as readdirCB, readdirSync, readlinkSync, realpathSync as rps } from "fs";
|
|
3040
3019
|
import * as actualFS from "node:fs";
|
|
3041
3020
|
import { lstat, readdir, readlink, realpath } from "node:fs/promises";
|
|
3042
3021
|
|
|
3043
|
-
//
|
|
3022
|
+
// ../../node_modules/.pnpm/minipass@7.1.2/node_modules/minipass/dist/esm/index.js
|
|
3044
3023
|
import { EventEmitter } from "node:events";
|
|
3045
3024
|
import Stream from "node:stream";
|
|
3046
3025
|
import { StringDecoder } from "node:string_decoder";
|
|
@@ -3918,7 +3897,7 @@ var Minipass = class extends EventEmitter {
|
|
|
3918
3897
|
}
|
|
3919
3898
|
};
|
|
3920
3899
|
|
|
3921
|
-
//
|
|
3900
|
+
// ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
|
|
3922
3901
|
var realpathSync = rps.native;
|
|
3923
3902
|
var defaultFS = {
|
|
3924
3903
|
lstatSync,
|
|
@@ -4183,12 +4162,12 @@ var PathBase = class {
|
|
|
4183
4162
|
/**
|
|
4184
4163
|
* Get the Path object referenced by the string path, resolved from this Path
|
|
4185
4164
|
*/
|
|
4186
|
-
resolve(
|
|
4187
|
-
if (!
|
|
4165
|
+
resolve(path12) {
|
|
4166
|
+
if (!path12) {
|
|
4188
4167
|
return this;
|
|
4189
4168
|
}
|
|
4190
|
-
const rootPath = this.getRootString(
|
|
4191
|
-
const dir =
|
|
4169
|
+
const rootPath = this.getRootString(path12);
|
|
4170
|
+
const dir = path12.substring(rootPath.length);
|
|
4192
4171
|
const dirParts = dir.split(this.splitSep);
|
|
4193
4172
|
const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
|
|
4194
4173
|
return result;
|
|
@@ -4940,8 +4919,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
|
|
|
4940
4919
|
/**
|
|
4941
4920
|
* @internal
|
|
4942
4921
|
*/
|
|
4943
|
-
getRootString(
|
|
4944
|
-
return win32.parse(
|
|
4922
|
+
getRootString(path12) {
|
|
4923
|
+
return win32.parse(path12).root;
|
|
4945
4924
|
}
|
|
4946
4925
|
/**
|
|
4947
4926
|
* @internal
|
|
@@ -4987,8 +4966,8 @@ var PathPosix = class _PathPosix extends PathBase {
|
|
|
4987
4966
|
/**
|
|
4988
4967
|
* @internal
|
|
4989
4968
|
*/
|
|
4990
|
-
getRootString(
|
|
4991
|
-
return
|
|
4969
|
+
getRootString(path12) {
|
|
4970
|
+
return path12.startsWith("/") ? "/" : "";
|
|
4992
4971
|
}
|
|
4993
4972
|
/**
|
|
4994
4973
|
* @internal
|
|
@@ -5077,11 +5056,11 @@ var PathScurryBase = class {
|
|
|
5077
5056
|
/**
|
|
5078
5057
|
* Get the depth of a provided path, string, or the cwd
|
|
5079
5058
|
*/
|
|
5080
|
-
depth(
|
|
5081
|
-
if (typeof
|
|
5082
|
-
|
|
5059
|
+
depth(path12 = this.cwd) {
|
|
5060
|
+
if (typeof path12 === "string") {
|
|
5061
|
+
path12 = this.cwd.resolve(path12);
|
|
5083
5062
|
}
|
|
5084
|
-
return
|
|
5063
|
+
return path12.depth();
|
|
5085
5064
|
}
|
|
5086
5065
|
/**
|
|
5087
5066
|
* Return the cache of child entries. Exposed so subclasses can create
|
|
@@ -5568,9 +5547,9 @@ var PathScurryBase = class {
|
|
|
5568
5547
|
process2();
|
|
5569
5548
|
return results;
|
|
5570
5549
|
}
|
|
5571
|
-
chdir(
|
|
5550
|
+
chdir(path12 = this.cwd) {
|
|
5572
5551
|
const oldCwd = this.cwd;
|
|
5573
|
-
this.cwd = typeof
|
|
5552
|
+
this.cwd = typeof path12 === "string" ? this.cwd.resolve(path12) : path12;
|
|
5574
5553
|
this.cwd[setAsCwd](oldCwd);
|
|
5575
5554
|
}
|
|
5576
5555
|
};
|
|
@@ -5644,7 +5623,7 @@ var PathScurryDarwin = class extends PathScurryPosix {
|
|
|
5644
5623
|
var Path = process.platform === "win32" ? PathWin32 : PathPosix;
|
|
5645
5624
|
var PathScurry = process.platform === "win32" ? PathScurryWin32 : process.platform === "darwin" ? PathScurryDarwin : PathScurryPosix;
|
|
5646
5625
|
|
|
5647
|
-
//
|
|
5626
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/pattern.js
|
|
5648
5627
|
var isPatternList = (pl) => pl.length >= 1;
|
|
5649
5628
|
var isGlobList = (gl) => gl.length >= 1;
|
|
5650
5629
|
var Pattern = class _Pattern {
|
|
@@ -5809,7 +5788,7 @@ var Pattern = class _Pattern {
|
|
|
5809
5788
|
}
|
|
5810
5789
|
};
|
|
5811
5790
|
|
|
5812
|
-
//
|
|
5791
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/ignore.js
|
|
5813
5792
|
var defaultPlatform2 = typeof process === "object" && process && typeof process.platform === "string" ? process.platform : "linux";
|
|
5814
5793
|
var Ignore = class {
|
|
5815
5794
|
relative;
|
|
@@ -5896,7 +5875,7 @@ var Ignore = class {
|
|
|
5896
5875
|
}
|
|
5897
5876
|
};
|
|
5898
5877
|
|
|
5899
|
-
//
|
|
5878
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/processor.js
|
|
5900
5879
|
var HasWalkedCache = class _HasWalkedCache {
|
|
5901
5880
|
store;
|
|
5902
5881
|
constructor(store = /* @__PURE__ */ new Map()) {
|
|
@@ -5926,8 +5905,8 @@ var MatchRecord = class {
|
|
|
5926
5905
|
}
|
|
5927
5906
|
// match, absolute, ifdir
|
|
5928
5907
|
entries() {
|
|
5929
|
-
return [...this.store.entries()].map(([
|
|
5930
|
-
|
|
5908
|
+
return [...this.store.entries()].map(([path12, n]) => [
|
|
5909
|
+
path12,
|
|
5931
5910
|
!!(n & 2),
|
|
5932
5911
|
!!(n & 1)
|
|
5933
5912
|
]);
|
|
@@ -6117,7 +6096,7 @@ var Processor = class _Processor {
|
|
|
6117
6096
|
}
|
|
6118
6097
|
};
|
|
6119
6098
|
|
|
6120
|
-
//
|
|
6099
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/walker.js
|
|
6121
6100
|
var makeIgnore = (ignore, opts) => typeof ignore === "string" ? new Ignore([ignore], opts) : Array.isArray(ignore) ? new Ignore(ignore, opts) : ignore;
|
|
6122
6101
|
var GlobUtil = class {
|
|
6123
6102
|
path;
|
|
@@ -6132,9 +6111,9 @@ var GlobUtil = class {
|
|
|
6132
6111
|
signal;
|
|
6133
6112
|
maxDepth;
|
|
6134
6113
|
includeChildMatches;
|
|
6135
|
-
constructor(patterns,
|
|
6114
|
+
constructor(patterns, path12, opts) {
|
|
6136
6115
|
this.patterns = patterns;
|
|
6137
|
-
this.path =
|
|
6116
|
+
this.path = path12;
|
|
6138
6117
|
this.opts = opts;
|
|
6139
6118
|
this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
|
|
6140
6119
|
this.includeChildMatches = opts.includeChildMatches !== false;
|
|
@@ -6153,11 +6132,11 @@ var GlobUtil = class {
|
|
|
6153
6132
|
});
|
|
6154
6133
|
}
|
|
6155
6134
|
}
|
|
6156
|
-
#ignored(
|
|
6157
|
-
return this.seen.has(
|
|
6135
|
+
#ignored(path12) {
|
|
6136
|
+
return this.seen.has(path12) || !!this.#ignore?.ignored?.(path12);
|
|
6158
6137
|
}
|
|
6159
|
-
#childrenIgnored(
|
|
6160
|
-
return !!this.#ignore?.childrenIgnored?.(
|
|
6138
|
+
#childrenIgnored(path12) {
|
|
6139
|
+
return !!this.#ignore?.childrenIgnored?.(path12);
|
|
6161
6140
|
}
|
|
6162
6141
|
// backpressure mechanism
|
|
6163
6142
|
pause() {
|
|
@@ -6372,8 +6351,8 @@ var GlobUtil = class {
|
|
|
6372
6351
|
};
|
|
6373
6352
|
var GlobWalker = class extends GlobUtil {
|
|
6374
6353
|
matches = /* @__PURE__ */ new Set();
|
|
6375
|
-
constructor(patterns,
|
|
6376
|
-
super(patterns,
|
|
6354
|
+
constructor(patterns, path12, opts) {
|
|
6355
|
+
super(patterns, path12, opts);
|
|
6377
6356
|
}
|
|
6378
6357
|
matchEmit(e) {
|
|
6379
6358
|
this.matches.add(e);
|
|
@@ -6410,8 +6389,8 @@ var GlobWalker = class extends GlobUtil {
|
|
|
6410
6389
|
};
|
|
6411
6390
|
var GlobStream = class extends GlobUtil {
|
|
6412
6391
|
results;
|
|
6413
|
-
constructor(patterns,
|
|
6414
|
-
super(patterns,
|
|
6392
|
+
constructor(patterns, path12, opts) {
|
|
6393
|
+
super(patterns, path12, opts);
|
|
6415
6394
|
this.results = new Minipass({
|
|
6416
6395
|
signal: this.signal,
|
|
6417
6396
|
objectMode: true
|
|
@@ -6444,7 +6423,7 @@ var GlobStream = class extends GlobUtil {
|
|
|
6444
6423
|
}
|
|
6445
6424
|
};
|
|
6446
6425
|
|
|
6447
|
-
//
|
|
6426
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/glob.js
|
|
6448
6427
|
var defaultPlatform3 = typeof process === "object" && process && typeof process.platform === "string" ? process.platform : "linux";
|
|
6449
6428
|
var Glob = class {
|
|
6450
6429
|
absolute;
|
|
@@ -6644,7 +6623,7 @@ var Glob = class {
|
|
|
6644
6623
|
}
|
|
6645
6624
|
};
|
|
6646
6625
|
|
|
6647
|
-
//
|
|
6626
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/has-magic.js
|
|
6648
6627
|
var hasMagic = (pattern, options = {}) => {
|
|
6649
6628
|
if (!Array.isArray(pattern)) {
|
|
6650
6629
|
pattern = [pattern];
|
|
@@ -6656,7 +6635,7 @@ var hasMagic = (pattern, options = {}) => {
|
|
|
6656
6635
|
return false;
|
|
6657
6636
|
};
|
|
6658
6637
|
|
|
6659
|
-
//
|
|
6638
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/index.js
|
|
6660
6639
|
function globStreamSync(pattern, options = {}) {
|
|
6661
6640
|
return new Glob(pattern, options).streamSync();
|
|
6662
6641
|
}
|
|
@@ -6705,16 +6684,17 @@ var glob = Object.assign(glob_, {
|
|
|
6705
6684
|
glob.glob = glob;
|
|
6706
6685
|
|
|
6707
6686
|
// src/build/patches/to-investigate/patch-read-file.ts
|
|
6708
|
-
|
|
6687
|
+
import path2 from "node:path";
|
|
6688
|
+
function patchReadFile(code, config) {
|
|
6709
6689
|
console.log("# patchReadFile");
|
|
6710
6690
|
code = code.replace(
|
|
6711
6691
|
"getBuildId() {",
|
|
6712
6692
|
`getBuildId() {
|
|
6713
|
-
return ${JSON.stringify(readFileSync(
|
|
6693
|
+
return ${JSON.stringify(readFileSync(path2.join(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
|
|
6714
6694
|
`
|
|
6715
6695
|
);
|
|
6716
|
-
const manifestJsons = globSync(
|
|
6717
|
-
(file) => file.replace(
|
|
6696
|
+
const manifestJsons = globSync(path2.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
|
|
6697
|
+
(file) => file.replace(config.paths.standaloneApp + "/", "")
|
|
6718
6698
|
);
|
|
6719
6699
|
code = code.replace(
|
|
6720
6700
|
/function loadManifest\((.+?), .+?\) {/,
|
|
@@ -6722,7 +6702,7 @@ function patchReadFile(code, nextjsAppPaths) {
|
|
|
6722
6702
|
${manifestJsons.map(
|
|
6723
6703
|
(manifestJson) => `
|
|
6724
6704
|
if ($1.endsWith("${manifestJson}")) {
|
|
6725
|
-
return ${readFileSync(
|
|
6705
|
+
return ${readFileSync(path2.join(config.paths.standaloneApp, manifestJson), "utf-8")};
|
|
6726
6706
|
}
|
|
6727
6707
|
`
|
|
6728
6708
|
).join("\n")}
|
|
@@ -6733,15 +6713,20 @@ function patchReadFile(code, nextjsAppPaths) {
|
|
|
6733
6713
|
}
|
|
6734
6714
|
|
|
6735
6715
|
// src/build/patches/to-investigate/patch-find-dir.ts
|
|
6716
|
+
import path3 from "node:path";
|
|
6736
6717
|
import { existsSync } from "node:fs";
|
|
6737
|
-
function patchFindDir(code,
|
|
6718
|
+
function patchFindDir(code, config) {
|
|
6738
6719
|
console.log("# patchFindDir");
|
|
6739
6720
|
return code.replace(
|
|
6740
6721
|
"function findDir(dir, name) {",
|
|
6741
6722
|
`function findDir(dir, name) {
|
|
6742
6723
|
if (dir.endsWith(".next/server")) {
|
|
6743
|
-
if (name === "app")
|
|
6744
|
-
|
|
6724
|
+
if (name === "app") {
|
|
6725
|
+
return ${existsSync(`${path3.join(config.paths.standaloneAppServer, "app")}`)};
|
|
6726
|
+
}
|
|
6727
|
+
if (name === "pages") {
|
|
6728
|
+
return ${existsSync(`${path3.join(config.paths.standaloneAppServer, "pages")}`)};
|
|
6729
|
+
}
|
|
6745
6730
|
}
|
|
6746
6731
|
throw new Error("Unknown findDir call: " + dir + " " + name);
|
|
6747
6732
|
`
|
|
@@ -6750,10 +6735,11 @@ function patchFindDir(code, nextjsAppPaths) {
|
|
|
6750
6735
|
|
|
6751
6736
|
// src/build/patches/to-investigate/inline-next-require.ts
|
|
6752
6737
|
import { readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
|
|
6753
|
-
|
|
6738
|
+
import path4 from "node:path";
|
|
6739
|
+
function inlineNextRequire(code, config) {
|
|
6754
6740
|
console.log("# inlineNextRequire");
|
|
6755
|
-
const pagesManifestFile =
|
|
6756
|
-
const appPathsManifestFile =
|
|
6741
|
+
const pagesManifestFile = path4.join(config.paths.standaloneAppServer, "pages-manifest.json");
|
|
6742
|
+
const appPathsManifestFile = path4.join(config.paths.standaloneAppServer, "app-paths-manifest.json");
|
|
6757
6743
|
const pagesManifestFiles = existsSync2(pagesManifestFile) ? Object.values(JSON.parse(readFileSync2(pagesManifestFile, "utf-8"))).map(
|
|
6758
6744
|
(file) => ".next/server/" + file
|
|
6759
6745
|
) : [];
|
|
@@ -6769,14 +6755,14 @@ function inlineNextRequire(code, nextjsAppPaths) {
|
|
|
6769
6755
|
${htmlPages.map(
|
|
6770
6756
|
(htmlPage) => `
|
|
6771
6757
|
if (pagePath.endsWith("${htmlPage}")) {
|
|
6772
|
-
return ${JSON.stringify(readFileSync2(
|
|
6758
|
+
return ${JSON.stringify(readFileSync2(path4.join(config.paths.standaloneApp, htmlPage), "utf-8"))};
|
|
6773
6759
|
}
|
|
6774
6760
|
`
|
|
6775
6761
|
).join("\n")}
|
|
6776
6762
|
${pageModules.map(
|
|
6777
6763
|
(module) => `
|
|
6778
6764
|
if (pagePath.endsWith("${module}")) {
|
|
6779
|
-
return require("${
|
|
6765
|
+
return require("${path4.join(config.paths.standaloneApp, module)}");
|
|
6780
6766
|
}
|
|
6781
6767
|
`
|
|
6782
6768
|
).join("\n")}
|
|
@@ -6786,18 +6772,19 @@ function inlineNextRequire(code, nextjsAppPaths) {
|
|
|
6786
6772
|
}
|
|
6787
6773
|
|
|
6788
6774
|
// src/build/patches/to-investigate/inline-eval-manifest.ts
|
|
6789
|
-
|
|
6775
|
+
import path5 from "node:path";
|
|
6776
|
+
function inlineEvalManifest(code, config) {
|
|
6790
6777
|
console.log("# inlineEvalManifest");
|
|
6791
6778
|
const manifestJss = globSync(
|
|
6792
|
-
|
|
6793
|
-
).map((file) => file.replace(`${
|
|
6779
|
+
path5.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
|
|
6780
|
+
).map((file) => file.replace(`${config.paths.standaloneApp}/`, ""));
|
|
6794
6781
|
return code.replace(
|
|
6795
6782
|
/function evalManifest\((.+?), .+?\) {/,
|
|
6796
6783
|
`$&
|
|
6797
6784
|
${manifestJss.map(
|
|
6798
6785
|
(manifestJs) => `
|
|
6799
6786
|
if ($1.endsWith("${manifestJs}")) {
|
|
6800
|
-
require("${
|
|
6787
|
+
require("${path5.join(config.paths.standaloneApp, manifestJs)}");
|
|
6801
6788
|
return {
|
|
6802
6789
|
__RSC_MANIFEST: {
|
|
6803
6790
|
"${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
|
|
@@ -6812,13 +6799,12 @@ function inlineEvalManifest(code, nextjsAppPaths) {
|
|
|
6812
6799
|
}
|
|
6813
6800
|
|
|
6814
6801
|
// src/build/patches/to-investigate/wrangler-deps.ts
|
|
6815
|
-
import
|
|
6802
|
+
import path6 from "node:path";
|
|
6816
6803
|
import fs, { writeFileSync } from "node:fs";
|
|
6817
|
-
function patchWranglerDeps(
|
|
6804
|
+
function patchWranglerDeps(config) {
|
|
6818
6805
|
console.log("# patchWranglerDeps");
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
paths.standaloneAppDir,
|
|
6806
|
+
const pagesRuntimeFile = path6.join(
|
|
6807
|
+
config.paths.standaloneApp,
|
|
6822
6808
|
"node_modules",
|
|
6823
6809
|
"next",
|
|
6824
6810
|
"dist",
|
|
@@ -6828,8 +6814,8 @@ function patchWranglerDeps(paths) {
|
|
|
6828
6814
|
);
|
|
6829
6815
|
const patchedPagesRuntime = fs.readFileSync(pagesRuntimeFile, "utf-8").replace(`e.exports=require("critters")`, `e.exports={}`);
|
|
6830
6816
|
fs.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
|
|
6831
|
-
const tracerFile =
|
|
6832
|
-
paths.
|
|
6817
|
+
const tracerFile = path6.join(
|
|
6818
|
+
config.paths.standaloneApp,
|
|
6833
6819
|
"node_modules",
|
|
6834
6820
|
"next",
|
|
6835
6821
|
"dist",
|
|
@@ -6844,6 +6830,7 @@ function patchWranglerDeps(paths) {
|
|
|
6844
6830
|
|
|
6845
6831
|
// src/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6846
6832
|
import { readdirSync as readdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6833
|
+
import path7 from "node:path";
|
|
6847
6834
|
|
|
6848
6835
|
// src/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts
|
|
6849
6836
|
import * as ts from "ts-morph";
|
|
@@ -6956,11 +6943,11 @@ async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
|
|
|
6956
6943
|
}
|
|
6957
6944
|
|
|
6958
6945
|
// src/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6959
|
-
async function updateWebpackChunksFile(
|
|
6946
|
+
async function updateWebpackChunksFile(config) {
|
|
6960
6947
|
console.log("# updateWebpackChunksFile");
|
|
6961
|
-
const webpackRuntimeFile =
|
|
6948
|
+
const webpackRuntimeFile = path7.join(config.paths.standaloneAppServer, "webpack-runtime.js");
|
|
6962
6949
|
const fileContent = readFileSync3(webpackRuntimeFile, "utf-8");
|
|
6963
|
-
const chunks = readdirSync2(
|
|
6950
|
+
const chunks = readdirSync2(path7.join(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
|
|
6964
6951
|
console.log(` - chunk ${chunk}`);
|
|
6965
6952
|
return chunk.replace(/\.js$/, "");
|
|
6966
6953
|
});
|
|
@@ -6968,18 +6955,53 @@ async function updateWebpackChunksFile(nextjsAppPaths) {
|
|
|
6968
6955
|
writeFileSync2(webpackRuntimeFile, updatedFileContent);
|
|
6969
6956
|
}
|
|
6970
6957
|
|
|
6958
|
+
// src/build/patches/investigated/patch-cache.ts
|
|
6959
|
+
import path8 from "node:path";
|
|
6960
|
+
function patchCache(code, config) {
|
|
6961
|
+
console.log("# patchCached");
|
|
6962
|
+
const cacheHandler = path8.join(config.paths.internalPackage, "cache-handler.mjs");
|
|
6963
|
+
const patchedCode = code.replace(
|
|
6964
|
+
"const { cacheHandler } = this.nextConfig;",
|
|
6965
|
+
`const cacheHandler = null;
|
|
6966
|
+
CacheHandler = (await import('${cacheHandler}')).default;
|
|
6967
|
+
CacheHandler.maybeKVNamespace = process.env["${config.cache.kvBindingName}"];
|
|
6968
|
+
`
|
|
6969
|
+
);
|
|
6970
|
+
if (patchedCode === code) {
|
|
6971
|
+
throw new Error("Cache patch not applied");
|
|
6972
|
+
}
|
|
6973
|
+
return patchedCode;
|
|
6974
|
+
}
|
|
6975
|
+
|
|
6971
6976
|
// src/build/build-worker.ts
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
6976
|
-
|
|
6977
|
+
var packageDir = path9.dirname(fileURLToPath3(import.meta.url));
|
|
6978
|
+
async function buildWorker(config) {
|
|
6979
|
+
console.log(`\x1B[35m\u2699\uFE0F Copying files...
|
|
6980
|
+
\x1B[0m`);
|
|
6981
|
+
await cp(
|
|
6982
|
+
path9.join(config.paths.dotNext, "static"),
|
|
6983
|
+
path9.join(config.paths.builderOutput, "assets", "_next", "static"),
|
|
6984
|
+
{
|
|
6985
|
+
recursive: true
|
|
6986
|
+
}
|
|
6987
|
+
);
|
|
6988
|
+
const publicDir = path9.join(config.paths.nextApp, "public");
|
|
6989
|
+
if (existsSync3(publicDir)) {
|
|
6990
|
+
await cp(publicDir, path9.join(config.paths.builderOutput, "assets"), {
|
|
6991
|
+
recursive: true
|
|
6992
|
+
});
|
|
6993
|
+
}
|
|
6994
|
+
copyPackage(packageDir, config);
|
|
6995
|
+
const templateDir = path9.join(config.paths.internalPackage, "templates");
|
|
6996
|
+
const workerEntrypoint = path9.join(templateDir, "worker.ts");
|
|
6997
|
+
const workerOutputFile = path9.join(config.paths.builderOutput, "index.mjs");
|
|
6998
|
+
const nextConfigStr = readFileSync4(path9.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
|
|
6977
6999
|
/const nextConfig = ({.+?})\n/
|
|
6978
7000
|
)?.[1] ?? {};
|
|
6979
7001
|
console.log(`\x1B[35m\u2699\uFE0F Bundling the worker file...
|
|
6980
7002
|
\x1B[0m`);
|
|
6981
|
-
patchWranglerDeps(
|
|
6982
|
-
updateWebpackChunksFile(
|
|
7003
|
+
patchWranglerDeps(config);
|
|
7004
|
+
updateWebpackChunksFile(config);
|
|
6983
7005
|
await build({
|
|
6984
7006
|
entryPoints: [workerEntrypoint],
|
|
6985
7007
|
bundle: true,
|
|
@@ -6992,15 +7014,15 @@ async function buildWorker(outputDir2, nextjsAppPaths, templateSrcDir) {
|
|
|
6992
7014
|
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
|
|
6993
7015
|
// eval("require")("bufferutil");
|
|
6994
7016
|
// eval("require")("utf-8-validate");
|
|
6995
|
-
"next/dist/compiled/ws":
|
|
7017
|
+
"next/dist/compiled/ws": path9.join(templateDir, "shims", "empty.ts"),
|
|
6996
7018
|
// Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
|
|
6997
7019
|
// eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
|
|
6998
7020
|
// which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
|
|
6999
7021
|
// QUESTION: Why did I encountered this but mhart didn't?
|
|
7000
|
-
"next/dist/compiled/edge-runtime":
|
|
7022
|
+
"next/dist/compiled/edge-runtime": path9.join(templateDir, "shims", "empty.ts"),
|
|
7001
7023
|
// `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
|
|
7002
7024
|
// source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
|
|
7003
|
-
"@next/env":
|
|
7025
|
+
"@next/env": path9.join(templateDir, "shims", "env.ts")
|
|
7004
7026
|
},
|
|
7005
7027
|
define: {
|
|
7006
7028
|
// config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139
|
|
@@ -7034,22 +7056,21 @@ async function buildWorker(outputDir2, nextjsAppPaths, templateSrcDir) {
|
|
|
7034
7056
|
// Do not crash on cache not supported
|
|
7035
7057
|
// https://github.com/cloudflare/workerd/pull/2434
|
|
7036
7058
|
// compatibility flag "cache_option_enabled" -> does not support "force-cache"
|
|
7037
|
-
let isPatchedAlready = globalThis.fetch.__nextPatched;
|
|
7038
7059
|
const curFetch = globalThis.fetch;
|
|
7039
7060
|
globalThis.fetch = (input, init) => {
|
|
7040
|
-
|
|
7041
|
-
|
|
7061
|
+
if (init) {
|
|
7062
|
+
delete init.cache;
|
|
7063
|
+
}
|
|
7042
7064
|
return curFetch(input, init);
|
|
7043
7065
|
};
|
|
7044
7066
|
import { Readable } from 'node:stream';
|
|
7045
|
-
globalThis.fetch.__nextPatched = isPatchedAlready;
|
|
7046
7067
|
fetch = globalThis.fetch;
|
|
7047
7068
|
const CustomRequest = class extends globalThis.Request {
|
|
7048
7069
|
constructor(input, init) {
|
|
7049
|
-
console.log("CustomRequest", input);
|
|
7050
7070
|
if (init) {
|
|
7051
7071
|
delete init.cache;
|
|
7052
7072
|
if (init.body?.__node_stream__ === true) {
|
|
7073
|
+
// https://github.com/cloudflare/workerd/issues/2746
|
|
7053
7074
|
init.body = Readable.toWeb(init.body);
|
|
7054
7075
|
}
|
|
7055
7076
|
}
|
|
@@ -7058,26 +7079,22 @@ const CustomRequest = class extends globalThis.Request {
|
|
|
7058
7079
|
};
|
|
7059
7080
|
globalThis.Request = CustomRequest;
|
|
7060
7081
|
Request = globalThis.Request;
|
|
7061
|
-
|
|
7082
|
+
`
|
|
7062
7083
|
}
|
|
7063
7084
|
});
|
|
7064
|
-
await updateWorkerBundledCode(workerOutputFile,
|
|
7065
|
-
console.log(`\x1B[35m\u2699\uFE0F Copying asset files...
|
|
7066
|
-
\x1B[0m`);
|
|
7067
|
-
await cp(`${nextjsAppPaths.dotNextDir}/static`, `${outputDir2}/assets/_next/static`, {
|
|
7068
|
-
recursive: true
|
|
7069
|
-
});
|
|
7085
|
+
await updateWorkerBundledCode(workerOutputFile, config);
|
|
7070
7086
|
console.log(`\x1B[35mWorker saved in \`${workerOutputFile}\` \u{1F680}
|
|
7071
7087
|
\x1B[0m`);
|
|
7072
7088
|
}
|
|
7073
|
-
async function updateWorkerBundledCode(workerOutputFile,
|
|
7089
|
+
async function updateWorkerBundledCode(workerOutputFile, config) {
|
|
7074
7090
|
const originalCode = await readFile(workerOutputFile, "utf8");
|
|
7075
7091
|
let patchedCode = originalCode;
|
|
7076
7092
|
patchedCode = patchRequire(patchedCode);
|
|
7077
|
-
patchedCode = patchReadFile(patchedCode,
|
|
7078
|
-
patchedCode = inlineNextRequire(patchedCode,
|
|
7079
|
-
patchedCode = patchFindDir(patchedCode,
|
|
7080
|
-
patchedCode = inlineEvalManifest(patchedCode,
|
|
7093
|
+
patchedCode = patchReadFile(patchedCode, config);
|
|
7094
|
+
patchedCode = inlineNextRequire(patchedCode, config);
|
|
7095
|
+
patchedCode = patchFindDir(patchedCode, config);
|
|
7096
|
+
patchedCode = inlineEvalManifest(patchedCode, config);
|
|
7097
|
+
patchedCode = patchCache(patchedCode, config);
|
|
7081
7098
|
await writeFile(workerOutputFile, patchedCode);
|
|
7082
7099
|
}
|
|
7083
7100
|
function createFixRequiresESBuildPlugin(templateDir) {
|
|
@@ -7085,100 +7102,105 @@ function createFixRequiresESBuildPlugin(templateDir) {
|
|
|
7085
7102
|
name: "replaceRelative",
|
|
7086
7103
|
setup(build3) {
|
|
7087
7104
|
build3.onResolve({ filter: /^\.\/require-hook$/ }, (args) => ({
|
|
7088
|
-
path:
|
|
7105
|
+
path: path9.join(templateDir, "shims", "empty.ts")
|
|
7089
7106
|
}));
|
|
7090
7107
|
build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, (args) => ({
|
|
7091
|
-
path:
|
|
7108
|
+
path: path9.join(templateDir, "shims", "empty.ts")
|
|
7092
7109
|
}));
|
|
7093
7110
|
}
|
|
7094
7111
|
};
|
|
7095
7112
|
}
|
|
7096
7113
|
|
|
7097
|
-
// src/
|
|
7114
|
+
// src/config.ts
|
|
7098
7115
|
import { readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
|
|
7099
|
-
import
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7116
|
+
import path10, { relative } from "node:path";
|
|
7117
|
+
var PACKAGE_NAME = "@opennextjs/cloudflare";
|
|
7118
|
+
var UserConfig = {
|
|
7119
|
+
cache: {
|
|
7120
|
+
bindingName: "NEXT_CACHE_WORKERS_KV"
|
|
7121
|
+
}
|
|
7122
|
+
};
|
|
7123
|
+
function getConfig(appDir, outputDir2) {
|
|
7124
|
+
const dotNext = path10.join(outputDir2, ".next");
|
|
7125
|
+
const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
|
|
7126
|
+
const standaloneApp = path10.join(dotNext, "standalone", appPath);
|
|
7127
|
+
const standaloneAppDotNext = path10.join(standaloneApp, ".next");
|
|
7128
|
+
const standaloneAppServer = path10.join(standaloneAppDotNext, "server");
|
|
7129
|
+
const nodeModules = path10.join(standaloneApp, "node_modules");
|
|
7130
|
+
const internalPackage = path10.join(nodeModules, ...PACKAGE_NAME.split("/"));
|
|
7104
7131
|
return {
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7132
|
+
paths: {
|
|
7133
|
+
nextApp: appDir,
|
|
7134
|
+
builderOutput: outputDir2,
|
|
7135
|
+
dotNext,
|
|
7136
|
+
standaloneApp,
|
|
7137
|
+
standaloneAppDotNext,
|
|
7138
|
+
standaloneAppServer,
|
|
7139
|
+
internalPackage
|
|
7140
|
+
},
|
|
7141
|
+
cache: {
|
|
7142
|
+
kvBindingName: UserConfig.cache.bindingName
|
|
7143
|
+
},
|
|
7144
|
+
internalPackageName: PACKAGE_NAME
|
|
7110
7145
|
};
|
|
7111
7146
|
}
|
|
7112
|
-
function
|
|
7113
|
-
const dotNextDirPath = `${nextAppDir2}/.next`;
|
|
7147
|
+
function containsDotNextDir(folder) {
|
|
7114
7148
|
try {
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
throw new Error(`Error: \`.next\` directory not found!`);
|
|
7149
|
+
return statSync2(path10.join(folder, ".next")).isDirectory();
|
|
7150
|
+
} catch (e) {
|
|
7151
|
+
return false;
|
|
7119
7152
|
}
|
|
7120
|
-
return dotNextDirPath;
|
|
7121
7153
|
}
|
|
7122
7154
|
function getNextjsApplicationPath(dotNextDir) {
|
|
7123
7155
|
const serverPath = findServerParentPath(dotNextDir);
|
|
7124
7156
|
if (!serverPath) {
|
|
7125
7157
|
throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
|
|
7126
7158
|
}
|
|
7127
|
-
return relative(
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
} catch {
|
|
7159
|
+
return relative(path10.join(dotNextDir, "standalone"), serverPath);
|
|
7160
|
+
}
|
|
7161
|
+
function findServerParentPath(parentPath) {
|
|
7162
|
+
try {
|
|
7163
|
+
if (statSync2(path10.join(parentPath, ".next", "server")).isDirectory()) {
|
|
7164
|
+
return parentPath;
|
|
7134
7165
|
}
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7166
|
+
} catch {
|
|
7167
|
+
}
|
|
7168
|
+
const folders = readdirSync3(parentPath);
|
|
7169
|
+
for (const folder of folders) {
|
|
7170
|
+
const subFolder = path10.join(parentPath, folder);
|
|
7171
|
+
if (statSync2(path10.join(parentPath, folder)).isDirectory()) {
|
|
7172
|
+
const dirServerPath = findServerParentPath(subFolder);
|
|
7173
|
+
if (dirServerPath) {
|
|
7174
|
+
return dirServerPath;
|
|
7142
7175
|
}
|
|
7143
7176
|
}
|
|
7144
7177
|
}
|
|
7145
7178
|
}
|
|
7146
7179
|
|
|
7147
7180
|
// src/build/build.ts
|
|
7148
|
-
import
|
|
7149
|
-
import
|
|
7150
|
-
|
|
7151
|
-
var SAVE_DIR = ".save.next";
|
|
7152
|
-
async function build2(inputNextAppDir, opts) {
|
|
7181
|
+
import { cpSync as cpSync3 } from "node:fs";
|
|
7182
|
+
import path11 from "node:path";
|
|
7183
|
+
async function build2(appDir, opts) {
|
|
7153
7184
|
if (!opts.skipBuild) {
|
|
7154
|
-
buildNextjsApp(
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
});
|
|
7159
|
-
cpSync2(`${inputNextAppDir}/.next`, `${inputNextAppDir}/${SAVE_DIR}`, {
|
|
7160
|
-
recursive: true
|
|
7161
|
-
});
|
|
7162
|
-
} else {
|
|
7163
|
-
rmSync(`${inputNextAppDir}/.next`, { recursive: true, force: true });
|
|
7164
|
-
cpSync2(`${inputNextAppDir}/${SAVE_DIR}`, `${inputNextAppDir}/.next`, {
|
|
7165
|
-
recursive: true
|
|
7166
|
-
});
|
|
7185
|
+
buildNextjsApp(appDir);
|
|
7186
|
+
}
|
|
7187
|
+
if (!containsDotNextDir(appDir)) {
|
|
7188
|
+
throw new Error(`.next folder not found in ${appDir}`);
|
|
7167
7189
|
}
|
|
7168
|
-
const outputDir2 =
|
|
7190
|
+
const outputDir2 = path11.resolve(opts.outputDir ?? appDir, ".worker-next");
|
|
7169
7191
|
await cleanDirectory(outputDir2);
|
|
7170
|
-
|
|
7171
|
-
const
|
|
7172
|
-
await buildWorker(
|
|
7192
|
+
cpSync3(path11.join(appDir, ".next"), path11.join(outputDir2, ".next"), { recursive: true });
|
|
7193
|
+
const config = getConfig(appDir, outputDir2);
|
|
7194
|
+
await buildWorker(config);
|
|
7173
7195
|
}
|
|
7174
|
-
async function cleanDirectory(
|
|
7175
|
-
return await rm(
|
|
7196
|
+
async function cleanDirectory(path12) {
|
|
7197
|
+
return await rm(path12, { recursive: true, force: true });
|
|
7176
7198
|
}
|
|
7177
7199
|
|
|
7178
7200
|
// src/index.ts
|
|
7179
7201
|
var nextAppDir = resolve2(".");
|
|
7180
7202
|
console.log(`Building the Next.js app in the current folder (${nextAppDir})`);
|
|
7181
|
-
if (!["js", "cjs", "mjs", "ts"].some((ext2) =>
|
|
7203
|
+
if (!["js", "cjs", "mjs", "ts"].some((ext2) => existsSync4(`./next.config.${ext2}`))) {
|
|
7182
7204
|
throw new Error("Error: Not in a Next.js app project");
|
|
7183
7205
|
}
|
|
7184
7206
|
var { skipBuild, outputDir } = getArgs();
|
package/dist/templates/worker.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opennextjs/cloudflare",
|
|
3
3
|
"description": "Cloudflare builder for next apps",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-9758666",
|
|
5
5
|
"bin": "dist/index.mjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"README.md",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
],
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/
|
|
13
|
-
"directory": "
|
|
12
|
+
"url": "https://github.com/opennextjs/opennextjs-cloudflare.git",
|
|
13
|
+
"directory": "packages/cloudflare"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"cloudflare",
|
|
@@ -19,13 +19,15 @@
|
|
|
19
19
|
],
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/opennextjs/opennextjs-cloudflare/issues"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://github.com/
|
|
24
|
+
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@cloudflare/workers-types": "^4.20240919.0",
|
|
26
27
|
"@types/node": "^22.2.0",
|
|
27
28
|
"esbuild": "^0.23.0",
|
|
28
29
|
"glob": "^11.0.0",
|
|
30
|
+
"next": "14.2.11",
|
|
29
31
|
"tsup": "^8.2.4",
|
|
30
32
|
"typescript": "^5.5.4",
|
|
31
33
|
"vitest": "^2.1.1"
|