@opennextjs/cloudflare 0.0.0-88fe982 → 0.0.0-9a03245
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 +59 -12
- package/dist/api/chunk-VTBEIZPQ.mjs +32 -0
- package/dist/api/get-cloudflare-context.d.mts +26 -0
- package/dist/api/get-cloudflare-context.mjs +6 -0
- package/dist/api/index.d.mts +1 -0
- package/dist/api/index.mjs +6 -0
- package/dist/cli/cache-handler.mjs +48 -0
- package/dist/cli/chunk-UJCSKKID.mjs +30 -0
- package/dist/{index.mjs → cli/index.mjs} +246 -221
- package/dist/{templates → cli/templates}/worker.ts +42 -25
- package/package.json +19 -6
- /package/dist/{templates → cli/templates}/shims/empty.ts +0 -0
- /package/dist/{templates → cli/templates}/shims/env.ts +0 -0
- /package/dist/{templates → cli/templates}/shims/node-fs.ts +0 -0
- /package/dist/{templates → cli/templates}/shims/throw.ts +0 -0
|
@@ -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;
|
|
@@ -233,10 +213,10 @@ var require_brace_expansion = __commonJS({
|
|
|
233
213
|
}
|
|
234
214
|
});
|
|
235
215
|
|
|
236
|
-
// src/index.ts
|
|
216
|
+
// src/cli/index.ts
|
|
237
217
|
import { resolve as resolve2 } from "node:path";
|
|
238
218
|
|
|
239
|
-
// src/args.ts
|
|
219
|
+
// src/cli/args.ts
|
|
240
220
|
import { mkdirSync, statSync } from "node:fs";
|
|
241
221
|
import { parseArgs } from "node:util";
|
|
242
222
|
import { resolve } from "node:path";
|
|
@@ -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(path13, argName, make) {
|
|
270
250
|
let dirStats;
|
|
271
251
|
try {
|
|
272
|
-
dirStats = statSync(
|
|
252
|
+
dirStats = statSync(path13);
|
|
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(path13);
|
|
278
258
|
return;
|
|
279
259
|
}
|
|
280
260
|
if (!dirStats.isDirectory()) {
|
|
@@ -282,13 +262,13 @@ function assertDirArg(path6, argName, make) {
|
|
|
282
262
|
}
|
|
283
263
|
}
|
|
284
264
|
|
|
285
|
-
// src/index.ts
|
|
286
|
-
import { existsSync as
|
|
265
|
+
// src/cli/index.ts
|
|
266
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
287
267
|
|
|
288
|
-
// src/build/
|
|
268
|
+
// src/cli/build/index.ts
|
|
289
269
|
import { rm } from "node:fs/promises";
|
|
290
270
|
|
|
291
|
-
// src/build/build-next-app.ts
|
|
271
|
+
// src/cli/build/build-next-app.ts
|
|
292
272
|
import { execSync } from "node:child_process";
|
|
293
273
|
function buildNextjsApp(nextAppDir2) {
|
|
294
274
|
runNextBuildCommand("pnpm", nextAppDir2);
|
|
@@ -307,34 +287,36 @@ function runNextBuildCommand(packager, nextAppDir2) {
|
|
|
307
287
|
});
|
|
308
288
|
}
|
|
309
289
|
|
|
310
|
-
// src/build/build-worker.ts
|
|
290
|
+
// src/cli/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 path10 from "node:path";
|
|
295
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
314
296
|
|
|
315
|
-
// src/build/patches/investigated/patch-require.ts
|
|
297
|
+
// src/cli/build/patches/investigated/patch-require.ts
|
|
316
298
|
function patchRequire(code) {
|
|
317
299
|
console.log("# patchRequire");
|
|
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/cli/build/patches/investigated/copy-package-cli-files.ts
|
|
323
304
|
import { cpSync } from "node:fs";
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
305
|
+
import path from "node:path";
|
|
306
|
+
function copyPackageCliFiles(packageDistDir2, config) {
|
|
307
|
+
console.log("# copyPackageTemplateFiles");
|
|
308
|
+
const sourceDir = path.join(packageDistDir2, "cli");
|
|
309
|
+
const destinationDir = path.join(config.paths.internalPackage, "cli");
|
|
310
|
+
cpSync(sourceDir, destinationDir, { recursive: true });
|
|
329
311
|
}
|
|
330
312
|
|
|
331
|
-
// src/build/patches/to-investigate/patch-read-file.ts
|
|
313
|
+
// src/cli/build/patches/to-investigate/patch-read-file.ts
|
|
332
314
|
import { readFileSync } from "node:fs";
|
|
333
315
|
|
|
334
|
-
//
|
|
316
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
|
|
335
317
|
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
336
318
|
|
|
337
|
-
//
|
|
319
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
338
320
|
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
339
321
|
var assertValidPattern = (pattern) => {
|
|
340
322
|
if (typeof pattern !== "string") {
|
|
@@ -345,7 +327,7 @@ var assertValidPattern = (pattern) => {
|
|
|
345
327
|
}
|
|
346
328
|
};
|
|
347
329
|
|
|
348
|
-
//
|
|
330
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/brace-expressions.js
|
|
349
331
|
var posixClasses = {
|
|
350
332
|
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
351
333
|
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
@@ -454,12 +436,12 @@ var parseClass = (glob2, position) => {
|
|
|
454
436
|
return [comb, uflag, endPos - pos, true];
|
|
455
437
|
};
|
|
456
438
|
|
|
457
|
-
//
|
|
439
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/unescape.js
|
|
458
440
|
var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
459
441
|
return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
|
|
460
442
|
};
|
|
461
443
|
|
|
462
|
-
//
|
|
444
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/ast.js
|
|
463
445
|
var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
464
446
|
var isExtglobType = (c) => types.has(c);
|
|
465
447
|
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
@@ -938,12 +920,12 @@ var AST = class _AST {
|
|
|
938
920
|
}
|
|
939
921
|
};
|
|
940
922
|
|
|
941
|
-
//
|
|
923
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/escape.js
|
|
942
924
|
var escape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
943
925
|
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
944
926
|
};
|
|
945
927
|
|
|
946
|
-
//
|
|
928
|
+
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
|
|
947
929
|
var minimatch = (p, pattern, options = {}) => {
|
|
948
930
|
assertValidPattern(pattern);
|
|
949
931
|
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
@@ -1661,10 +1643,10 @@ minimatch.Minimatch = Minimatch;
|
|
|
1661
1643
|
minimatch.escape = escape;
|
|
1662
1644
|
minimatch.unescape = unescape;
|
|
1663
1645
|
|
|
1664
|
-
//
|
|
1646
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/glob.js
|
|
1665
1647
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1666
1648
|
|
|
1667
|
-
//
|
|
1649
|
+
// ../../node_modules/.pnpm/lru-cache@11.0.0/node_modules/lru-cache/dist/esm/index.js
|
|
1668
1650
|
var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
1669
1651
|
var warned = /* @__PURE__ */ new Set();
|
|
1670
1652
|
var PROCESS = typeof process === "object" && !!process ? process : {};
|
|
@@ -3033,14 +3015,14 @@ var LRUCache = class _LRUCache {
|
|
|
3033
3015
|
}
|
|
3034
3016
|
};
|
|
3035
3017
|
|
|
3036
|
-
//
|
|
3018
|
+
// ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
|
|
3037
3019
|
import { posix, win32 } from "node:path";
|
|
3038
3020
|
import { fileURLToPath } from "node:url";
|
|
3039
3021
|
import { lstatSync, readdir as readdirCB, readdirSync, readlinkSync, realpathSync as rps } from "fs";
|
|
3040
3022
|
import * as actualFS from "node:fs";
|
|
3041
3023
|
import { lstat, readdir, readlink, realpath } from "node:fs/promises";
|
|
3042
3024
|
|
|
3043
|
-
//
|
|
3025
|
+
// ../../node_modules/.pnpm/minipass@7.1.2/node_modules/minipass/dist/esm/index.js
|
|
3044
3026
|
import { EventEmitter } from "node:events";
|
|
3045
3027
|
import Stream from "node:stream";
|
|
3046
3028
|
import { StringDecoder } from "node:string_decoder";
|
|
@@ -3918,7 +3900,7 @@ var Minipass = class extends EventEmitter {
|
|
|
3918
3900
|
}
|
|
3919
3901
|
};
|
|
3920
3902
|
|
|
3921
|
-
//
|
|
3903
|
+
// ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
|
|
3922
3904
|
var realpathSync = rps.native;
|
|
3923
3905
|
var defaultFS = {
|
|
3924
3906
|
lstatSync,
|
|
@@ -4183,12 +4165,12 @@ var PathBase = class {
|
|
|
4183
4165
|
/**
|
|
4184
4166
|
* Get the Path object referenced by the string path, resolved from this Path
|
|
4185
4167
|
*/
|
|
4186
|
-
resolve(
|
|
4187
|
-
if (!
|
|
4168
|
+
resolve(path13) {
|
|
4169
|
+
if (!path13) {
|
|
4188
4170
|
return this;
|
|
4189
4171
|
}
|
|
4190
|
-
const rootPath = this.getRootString(
|
|
4191
|
-
const dir =
|
|
4172
|
+
const rootPath = this.getRootString(path13);
|
|
4173
|
+
const dir = path13.substring(rootPath.length);
|
|
4192
4174
|
const dirParts = dir.split(this.splitSep);
|
|
4193
4175
|
const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
|
|
4194
4176
|
return result;
|
|
@@ -4940,8 +4922,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
|
|
|
4940
4922
|
/**
|
|
4941
4923
|
* @internal
|
|
4942
4924
|
*/
|
|
4943
|
-
getRootString(
|
|
4944
|
-
return win32.parse(
|
|
4925
|
+
getRootString(path13) {
|
|
4926
|
+
return win32.parse(path13).root;
|
|
4945
4927
|
}
|
|
4946
4928
|
/**
|
|
4947
4929
|
* @internal
|
|
@@ -4987,8 +4969,8 @@ var PathPosix = class _PathPosix extends PathBase {
|
|
|
4987
4969
|
/**
|
|
4988
4970
|
* @internal
|
|
4989
4971
|
*/
|
|
4990
|
-
getRootString(
|
|
4991
|
-
return
|
|
4972
|
+
getRootString(path13) {
|
|
4973
|
+
return path13.startsWith("/") ? "/" : "";
|
|
4992
4974
|
}
|
|
4993
4975
|
/**
|
|
4994
4976
|
* @internal
|
|
@@ -5077,11 +5059,11 @@ var PathScurryBase = class {
|
|
|
5077
5059
|
/**
|
|
5078
5060
|
* Get the depth of a provided path, string, or the cwd
|
|
5079
5061
|
*/
|
|
5080
|
-
depth(
|
|
5081
|
-
if (typeof
|
|
5082
|
-
|
|
5062
|
+
depth(path13 = this.cwd) {
|
|
5063
|
+
if (typeof path13 === "string") {
|
|
5064
|
+
path13 = this.cwd.resolve(path13);
|
|
5083
5065
|
}
|
|
5084
|
-
return
|
|
5066
|
+
return path13.depth();
|
|
5085
5067
|
}
|
|
5086
5068
|
/**
|
|
5087
5069
|
* Return the cache of child entries. Exposed so subclasses can create
|
|
@@ -5568,9 +5550,9 @@ var PathScurryBase = class {
|
|
|
5568
5550
|
process2();
|
|
5569
5551
|
return results;
|
|
5570
5552
|
}
|
|
5571
|
-
chdir(
|
|
5553
|
+
chdir(path13 = this.cwd) {
|
|
5572
5554
|
const oldCwd = this.cwd;
|
|
5573
|
-
this.cwd = typeof
|
|
5555
|
+
this.cwd = typeof path13 === "string" ? this.cwd.resolve(path13) : path13;
|
|
5574
5556
|
this.cwd[setAsCwd](oldCwd);
|
|
5575
5557
|
}
|
|
5576
5558
|
};
|
|
@@ -5644,7 +5626,7 @@ var PathScurryDarwin = class extends PathScurryPosix {
|
|
|
5644
5626
|
var Path = process.platform === "win32" ? PathWin32 : PathPosix;
|
|
5645
5627
|
var PathScurry = process.platform === "win32" ? PathScurryWin32 : process.platform === "darwin" ? PathScurryDarwin : PathScurryPosix;
|
|
5646
5628
|
|
|
5647
|
-
//
|
|
5629
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/pattern.js
|
|
5648
5630
|
var isPatternList = (pl) => pl.length >= 1;
|
|
5649
5631
|
var isGlobList = (gl) => gl.length >= 1;
|
|
5650
5632
|
var Pattern = class _Pattern {
|
|
@@ -5809,7 +5791,7 @@ var Pattern = class _Pattern {
|
|
|
5809
5791
|
}
|
|
5810
5792
|
};
|
|
5811
5793
|
|
|
5812
|
-
//
|
|
5794
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/ignore.js
|
|
5813
5795
|
var defaultPlatform2 = typeof process === "object" && process && typeof process.platform === "string" ? process.platform : "linux";
|
|
5814
5796
|
var Ignore = class {
|
|
5815
5797
|
relative;
|
|
@@ -5896,7 +5878,7 @@ var Ignore = class {
|
|
|
5896
5878
|
}
|
|
5897
5879
|
};
|
|
5898
5880
|
|
|
5899
|
-
//
|
|
5881
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/processor.js
|
|
5900
5882
|
var HasWalkedCache = class _HasWalkedCache {
|
|
5901
5883
|
store;
|
|
5902
5884
|
constructor(store = /* @__PURE__ */ new Map()) {
|
|
@@ -5926,8 +5908,8 @@ var MatchRecord = class {
|
|
|
5926
5908
|
}
|
|
5927
5909
|
// match, absolute, ifdir
|
|
5928
5910
|
entries() {
|
|
5929
|
-
return [...this.store.entries()].map(([
|
|
5930
|
-
|
|
5911
|
+
return [...this.store.entries()].map(([path13, n]) => [
|
|
5912
|
+
path13,
|
|
5931
5913
|
!!(n & 2),
|
|
5932
5914
|
!!(n & 1)
|
|
5933
5915
|
]);
|
|
@@ -6117,7 +6099,7 @@ var Processor = class _Processor {
|
|
|
6117
6099
|
}
|
|
6118
6100
|
};
|
|
6119
6101
|
|
|
6120
|
-
//
|
|
6102
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/walker.js
|
|
6121
6103
|
var makeIgnore = (ignore, opts) => typeof ignore === "string" ? new Ignore([ignore], opts) : Array.isArray(ignore) ? new Ignore(ignore, opts) : ignore;
|
|
6122
6104
|
var GlobUtil = class {
|
|
6123
6105
|
path;
|
|
@@ -6132,9 +6114,9 @@ var GlobUtil = class {
|
|
|
6132
6114
|
signal;
|
|
6133
6115
|
maxDepth;
|
|
6134
6116
|
includeChildMatches;
|
|
6135
|
-
constructor(patterns,
|
|
6117
|
+
constructor(patterns, path13, opts) {
|
|
6136
6118
|
this.patterns = patterns;
|
|
6137
|
-
this.path =
|
|
6119
|
+
this.path = path13;
|
|
6138
6120
|
this.opts = opts;
|
|
6139
6121
|
this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
|
|
6140
6122
|
this.includeChildMatches = opts.includeChildMatches !== false;
|
|
@@ -6153,11 +6135,11 @@ var GlobUtil = class {
|
|
|
6153
6135
|
});
|
|
6154
6136
|
}
|
|
6155
6137
|
}
|
|
6156
|
-
#ignored(
|
|
6157
|
-
return this.seen.has(
|
|
6138
|
+
#ignored(path13) {
|
|
6139
|
+
return this.seen.has(path13) || !!this.#ignore?.ignored?.(path13);
|
|
6158
6140
|
}
|
|
6159
|
-
#childrenIgnored(
|
|
6160
|
-
return !!this.#ignore?.childrenIgnored?.(
|
|
6141
|
+
#childrenIgnored(path13) {
|
|
6142
|
+
return !!this.#ignore?.childrenIgnored?.(path13);
|
|
6161
6143
|
}
|
|
6162
6144
|
// backpressure mechanism
|
|
6163
6145
|
pause() {
|
|
@@ -6372,8 +6354,8 @@ var GlobUtil = class {
|
|
|
6372
6354
|
};
|
|
6373
6355
|
var GlobWalker = class extends GlobUtil {
|
|
6374
6356
|
matches = /* @__PURE__ */ new Set();
|
|
6375
|
-
constructor(patterns,
|
|
6376
|
-
super(patterns,
|
|
6357
|
+
constructor(patterns, path13, opts) {
|
|
6358
|
+
super(patterns, path13, opts);
|
|
6377
6359
|
}
|
|
6378
6360
|
matchEmit(e) {
|
|
6379
6361
|
this.matches.add(e);
|
|
@@ -6410,8 +6392,8 @@ var GlobWalker = class extends GlobUtil {
|
|
|
6410
6392
|
};
|
|
6411
6393
|
var GlobStream = class extends GlobUtil {
|
|
6412
6394
|
results;
|
|
6413
|
-
constructor(patterns,
|
|
6414
|
-
super(patterns,
|
|
6395
|
+
constructor(patterns, path13, opts) {
|
|
6396
|
+
super(patterns, path13, opts);
|
|
6415
6397
|
this.results = new Minipass({
|
|
6416
6398
|
signal: this.signal,
|
|
6417
6399
|
objectMode: true
|
|
@@ -6444,7 +6426,7 @@ var GlobStream = class extends GlobUtil {
|
|
|
6444
6426
|
}
|
|
6445
6427
|
};
|
|
6446
6428
|
|
|
6447
|
-
//
|
|
6429
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/glob.js
|
|
6448
6430
|
var defaultPlatform3 = typeof process === "object" && process && typeof process.platform === "string" ? process.platform : "linux";
|
|
6449
6431
|
var Glob = class {
|
|
6450
6432
|
absolute;
|
|
@@ -6644,7 +6626,7 @@ var Glob = class {
|
|
|
6644
6626
|
}
|
|
6645
6627
|
};
|
|
6646
6628
|
|
|
6647
|
-
//
|
|
6629
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/has-magic.js
|
|
6648
6630
|
var hasMagic = (pattern, options = {}) => {
|
|
6649
6631
|
if (!Array.isArray(pattern)) {
|
|
6650
6632
|
pattern = [pattern];
|
|
@@ -6656,7 +6638,7 @@ var hasMagic = (pattern, options = {}) => {
|
|
|
6656
6638
|
return false;
|
|
6657
6639
|
};
|
|
6658
6640
|
|
|
6659
|
-
//
|
|
6641
|
+
// ../../node_modules/.pnpm/glob@11.0.0/node_modules/glob/dist/esm/index.js
|
|
6660
6642
|
function globStreamSync(pattern, options = {}) {
|
|
6661
6643
|
return new Glob(pattern, options).streamSync();
|
|
6662
6644
|
}
|
|
@@ -6704,17 +6686,18 @@ var glob = Object.assign(glob_, {
|
|
|
6704
6686
|
});
|
|
6705
6687
|
glob.glob = glob;
|
|
6706
6688
|
|
|
6707
|
-
// src/build/patches/to-investigate/patch-read-file.ts
|
|
6708
|
-
|
|
6689
|
+
// src/cli/build/patches/to-investigate/patch-read-file.ts
|
|
6690
|
+
import path3 from "node:path";
|
|
6691
|
+
function patchReadFile(code, config) {
|
|
6709
6692
|
console.log("# patchReadFile");
|
|
6710
6693
|
code = code.replace(
|
|
6711
6694
|
"getBuildId() {",
|
|
6712
6695
|
`getBuildId() {
|
|
6713
|
-
return ${JSON.stringify(readFileSync(
|
|
6696
|
+
return ${JSON.stringify(readFileSync(path3.join(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
|
|
6714
6697
|
`
|
|
6715
6698
|
);
|
|
6716
|
-
const manifestJsons = globSync(
|
|
6717
|
-
(file) => file.replace(
|
|
6699
|
+
const manifestJsons = globSync(path3.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
|
|
6700
|
+
(file) => file.replace(config.paths.standaloneApp + "/", "")
|
|
6718
6701
|
);
|
|
6719
6702
|
code = code.replace(
|
|
6720
6703
|
/function loadManifest\((.+?), .+?\) {/,
|
|
@@ -6722,7 +6705,7 @@ function patchReadFile(code, nextjsAppPaths) {
|
|
|
6722
6705
|
${manifestJsons.map(
|
|
6723
6706
|
(manifestJson) => `
|
|
6724
6707
|
if ($1.endsWith("${manifestJson}")) {
|
|
6725
|
-
return ${readFileSync(
|
|
6708
|
+
return ${readFileSync(path3.join(config.paths.standaloneApp, manifestJson), "utf-8")};
|
|
6726
6709
|
}
|
|
6727
6710
|
`
|
|
6728
6711
|
).join("\n")}
|
|
@@ -6732,28 +6715,34 @@ function patchReadFile(code, nextjsAppPaths) {
|
|
|
6732
6715
|
return code;
|
|
6733
6716
|
}
|
|
6734
6717
|
|
|
6735
|
-
// src/build/patches/to-investigate/patch-find-dir.ts
|
|
6718
|
+
// src/cli/build/patches/to-investigate/patch-find-dir.ts
|
|
6719
|
+
import path4 from "node:path";
|
|
6736
6720
|
import { existsSync } from "node:fs";
|
|
6737
|
-
function patchFindDir(code,
|
|
6721
|
+
function patchFindDir(code, config) {
|
|
6738
6722
|
console.log("# patchFindDir");
|
|
6739
6723
|
return code.replace(
|
|
6740
6724
|
"function findDir(dir, name) {",
|
|
6741
6725
|
`function findDir(dir, name) {
|
|
6742
6726
|
if (dir.endsWith(".next/server")) {
|
|
6743
|
-
if (name === "app")
|
|
6744
|
-
|
|
6727
|
+
if (name === "app") {
|
|
6728
|
+
return ${existsSync(`${path4.join(config.paths.standaloneAppServer, "app")}`)};
|
|
6729
|
+
}
|
|
6730
|
+
if (name === "pages") {
|
|
6731
|
+
return ${existsSync(`${path4.join(config.paths.standaloneAppServer, "pages")}`)};
|
|
6732
|
+
}
|
|
6745
6733
|
}
|
|
6746
6734
|
throw new Error("Unknown findDir call: " + dir + " " + name);
|
|
6747
6735
|
`
|
|
6748
6736
|
);
|
|
6749
6737
|
}
|
|
6750
6738
|
|
|
6751
|
-
// src/build/patches/to-investigate/inline-next-require.ts
|
|
6739
|
+
// src/cli/build/patches/to-investigate/inline-next-require.ts
|
|
6752
6740
|
import { readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
|
|
6753
|
-
|
|
6741
|
+
import path5 from "node:path";
|
|
6742
|
+
function inlineNextRequire(code, config) {
|
|
6754
6743
|
console.log("# inlineNextRequire");
|
|
6755
|
-
const pagesManifestFile =
|
|
6756
|
-
const appPathsManifestFile =
|
|
6744
|
+
const pagesManifestFile = path5.join(config.paths.standaloneAppServer, "pages-manifest.json");
|
|
6745
|
+
const appPathsManifestFile = path5.join(config.paths.standaloneAppServer, "app-paths-manifest.json");
|
|
6757
6746
|
const pagesManifestFiles = existsSync2(pagesManifestFile) ? Object.values(JSON.parse(readFileSync2(pagesManifestFile, "utf-8"))).map(
|
|
6758
6747
|
(file) => ".next/server/" + file
|
|
6759
6748
|
) : [];
|
|
@@ -6769,14 +6758,14 @@ function inlineNextRequire(code, nextjsAppPaths) {
|
|
|
6769
6758
|
${htmlPages.map(
|
|
6770
6759
|
(htmlPage) => `
|
|
6771
6760
|
if (pagePath.endsWith("${htmlPage}")) {
|
|
6772
|
-
return ${JSON.stringify(readFileSync2(
|
|
6761
|
+
return ${JSON.stringify(readFileSync2(path5.join(config.paths.standaloneApp, htmlPage), "utf-8"))};
|
|
6773
6762
|
}
|
|
6774
6763
|
`
|
|
6775
6764
|
).join("\n")}
|
|
6776
6765
|
${pageModules.map(
|
|
6777
6766
|
(module) => `
|
|
6778
6767
|
if (pagePath.endsWith("${module}")) {
|
|
6779
|
-
return require("${
|
|
6768
|
+
return require("${path5.join(config.paths.standaloneApp, module)}");
|
|
6780
6769
|
}
|
|
6781
6770
|
`
|
|
6782
6771
|
).join("\n")}
|
|
@@ -6785,19 +6774,20 @@ function inlineNextRequire(code, nextjsAppPaths) {
|
|
|
6785
6774
|
);
|
|
6786
6775
|
}
|
|
6787
6776
|
|
|
6788
|
-
// src/build/patches/to-investigate/inline-eval-manifest.ts
|
|
6789
|
-
|
|
6777
|
+
// src/cli/build/patches/to-investigate/inline-eval-manifest.ts
|
|
6778
|
+
import path6 from "node:path";
|
|
6779
|
+
function inlineEvalManifest(code, config) {
|
|
6790
6780
|
console.log("# inlineEvalManifest");
|
|
6791
6781
|
const manifestJss = globSync(
|
|
6792
|
-
|
|
6793
|
-
).map((file) => file.replace(`${
|
|
6782
|
+
path6.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
|
|
6783
|
+
).map((file) => file.replace(`${config.paths.standaloneApp}/`, ""));
|
|
6794
6784
|
return code.replace(
|
|
6795
6785
|
/function evalManifest\((.+?), .+?\) {/,
|
|
6796
6786
|
`$&
|
|
6797
6787
|
${manifestJss.map(
|
|
6798
6788
|
(manifestJs) => `
|
|
6799
6789
|
if ($1.endsWith("${manifestJs}")) {
|
|
6800
|
-
require("${
|
|
6790
|
+
require("${path6.join(config.paths.standaloneApp, manifestJs)}");
|
|
6801
6791
|
return {
|
|
6802
6792
|
__RSC_MANIFEST: {
|
|
6803
6793
|
"${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
|
|
@@ -6811,14 +6801,13 @@ function inlineEvalManifest(code, nextjsAppPaths) {
|
|
|
6811
6801
|
);
|
|
6812
6802
|
}
|
|
6813
6803
|
|
|
6814
|
-
// src/build/patches/to-investigate/wrangler-deps.ts
|
|
6815
|
-
import
|
|
6804
|
+
// src/cli/build/patches/to-investigate/wrangler-deps.ts
|
|
6805
|
+
import path7 from "node:path";
|
|
6816
6806
|
import fs, { writeFileSync } from "node:fs";
|
|
6817
|
-
function patchWranglerDeps(
|
|
6807
|
+
function patchWranglerDeps(config) {
|
|
6818
6808
|
console.log("# patchWranglerDeps");
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
paths.standaloneAppDir,
|
|
6809
|
+
const pagesRuntimeFile = path7.join(
|
|
6810
|
+
config.paths.standaloneApp,
|
|
6822
6811
|
"node_modules",
|
|
6823
6812
|
"next",
|
|
6824
6813
|
"dist",
|
|
@@ -6828,8 +6817,8 @@ function patchWranglerDeps(paths) {
|
|
|
6828
6817
|
);
|
|
6829
6818
|
const patchedPagesRuntime = fs.readFileSync(pagesRuntimeFile, "utf-8").replace(`e.exports=require("critters")`, `e.exports={}`);
|
|
6830
6819
|
fs.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
|
|
6831
|
-
const tracerFile =
|
|
6832
|
-
paths.
|
|
6820
|
+
const tracerFile = path7.join(
|
|
6821
|
+
config.paths.standaloneApp,
|
|
6833
6822
|
"node_modules",
|
|
6834
6823
|
"next",
|
|
6835
6824
|
"dist",
|
|
@@ -6842,10 +6831,11 @@ function patchWranglerDeps(paths) {
|
|
|
6842
6831
|
writeFileSync(tracerFile, pacthedTracer);
|
|
6843
6832
|
}
|
|
6844
6833
|
|
|
6845
|
-
// src/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6834
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6846
6835
|
import { readdirSync as readdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6836
|
+
import path8 from "node:path";
|
|
6847
6837
|
|
|
6848
|
-
// src/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts
|
|
6838
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts
|
|
6849
6839
|
import * as ts from "ts-morph";
|
|
6850
6840
|
async function getChunkInstallationIdentifiers(sourceFile) {
|
|
6851
6841
|
const installChunkDeclaration = getInstallChunkDeclaration(sourceFile);
|
|
@@ -6891,7 +6881,7 @@ function getInstalledChunksDeclaration(sourceFile, installChunkDeclaration) {
|
|
|
6891
6881
|
return installedChunksDeclaration;
|
|
6892
6882
|
}
|
|
6893
6883
|
|
|
6894
|
-
// src/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.ts
|
|
6884
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.ts
|
|
6895
6885
|
import * as ts2 from "ts-morph";
|
|
6896
6886
|
async function getFileContentWithUpdatedWebpackFRequireCode(sourceFile, { installedChunks, installChunk }, chunks) {
|
|
6897
6887
|
const webpackFRequireFunction = sourceFile.getDescendantsOfKind(ts2.SyntaxKind.ArrowFunction).find((arrowFunction) => {
|
|
@@ -6935,7 +6925,7 @@ if(${chunkId} === ${chunk}) return ${installChunk}(require("./chunks/${chunk}.js
|
|
|
6935
6925
|
return sourceFile.print();
|
|
6936
6926
|
}
|
|
6937
6927
|
|
|
6938
|
-
// src/build/utils/ts-parse-file.ts
|
|
6928
|
+
// src/cli/build/utils/ts-parse-file.ts
|
|
6939
6929
|
import * as ts3 from "ts-morph";
|
|
6940
6930
|
function tsParseFile(fileContent) {
|
|
6941
6931
|
const project = new ts3.Project();
|
|
@@ -6943,7 +6933,7 @@ function tsParseFile(fileContent) {
|
|
|
6943
6933
|
return sourceFile;
|
|
6944
6934
|
}
|
|
6945
6935
|
|
|
6946
|
-
// src/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.ts
|
|
6936
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.ts
|
|
6947
6937
|
async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
|
|
6948
6938
|
const tsSourceFile = tsParseFile(fileContent);
|
|
6949
6939
|
const chunkInstallationIdentifiers = await getChunkInstallationIdentifiers(tsSourceFile);
|
|
@@ -6955,12 +6945,12 @@ async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
|
|
|
6955
6945
|
return updatedFileContent;
|
|
6956
6946
|
}
|
|
6957
6947
|
|
|
6958
|
-
// src/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6959
|
-
async function updateWebpackChunksFile(
|
|
6948
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6949
|
+
async function updateWebpackChunksFile(config) {
|
|
6960
6950
|
console.log("# updateWebpackChunksFile");
|
|
6961
|
-
const webpackRuntimeFile =
|
|
6951
|
+
const webpackRuntimeFile = path8.join(config.paths.standaloneAppServer, "webpack-runtime.js");
|
|
6962
6952
|
const fileContent = readFileSync3(webpackRuntimeFile, "utf-8");
|
|
6963
|
-
const chunks = readdirSync2(
|
|
6953
|
+
const chunks = readdirSync2(path8.join(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
|
|
6964
6954
|
console.log(` - chunk ${chunk}`);
|
|
6965
6955
|
return chunk.replace(/\.js$/, "");
|
|
6966
6956
|
});
|
|
@@ -6968,18 +6958,53 @@ async function updateWebpackChunksFile(nextjsAppPaths) {
|
|
|
6968
6958
|
writeFileSync2(webpackRuntimeFile, updatedFileContent);
|
|
6969
6959
|
}
|
|
6970
6960
|
|
|
6971
|
-
// src/build/
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
const
|
|
6976
|
-
const
|
|
6961
|
+
// src/cli/build/patches/investigated/patch-cache.ts
|
|
6962
|
+
import path9 from "node:path";
|
|
6963
|
+
function patchCache(code, config) {
|
|
6964
|
+
console.log("# patchCached");
|
|
6965
|
+
const cacheHandler = path9.join(config.paths.internalPackage, "cli", "cache-handler.mjs");
|
|
6966
|
+
const patchedCode = code.replace(
|
|
6967
|
+
"const { cacheHandler } = this.nextConfig;",
|
|
6968
|
+
`const cacheHandler = null;
|
|
6969
|
+
CacheHandler = (await import('${cacheHandler}')).default;
|
|
6970
|
+
CacheHandler.maybeKVNamespace = process.env["${config.cache.kvBindingName}"];
|
|
6971
|
+
`
|
|
6972
|
+
);
|
|
6973
|
+
if (patchedCode === code) {
|
|
6974
|
+
throw new Error("Cache patch not applied");
|
|
6975
|
+
}
|
|
6976
|
+
return patchedCode;
|
|
6977
|
+
}
|
|
6978
|
+
|
|
6979
|
+
// src/cli/build/build-worker.ts
|
|
6980
|
+
var packageDistDir = path10.join(path10.dirname(fileURLToPath3(import.meta.url)), "..");
|
|
6981
|
+
async function buildWorker(config) {
|
|
6982
|
+
console.log(`\x1B[35m\u2699\uFE0F Copying files...
|
|
6983
|
+
\x1B[0m`);
|
|
6984
|
+
await cp(
|
|
6985
|
+
path10.join(config.paths.dotNext, "static"),
|
|
6986
|
+
path10.join(config.paths.builderOutput, "assets", "_next", "static"),
|
|
6987
|
+
{
|
|
6988
|
+
recursive: true
|
|
6989
|
+
}
|
|
6990
|
+
);
|
|
6991
|
+
const publicDir = path10.join(config.paths.nextApp, "public");
|
|
6992
|
+
if (existsSync3(publicDir)) {
|
|
6993
|
+
await cp(publicDir, path10.join(config.paths.builderOutput, "assets"), {
|
|
6994
|
+
recursive: true
|
|
6995
|
+
});
|
|
6996
|
+
}
|
|
6997
|
+
copyPackageCliFiles(packageDistDir, config);
|
|
6998
|
+
const templateDir = path10.join(config.paths.internalPackage, "cli", "templates");
|
|
6999
|
+
const workerEntrypoint = path10.join(templateDir, "worker.ts");
|
|
7000
|
+
const workerOutputFile = path10.join(config.paths.builderOutput, "index.mjs");
|
|
7001
|
+
const nextConfigStr = readFileSync4(path10.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
|
|
6977
7002
|
/const nextConfig = ({.+?})\n/
|
|
6978
7003
|
)?.[1] ?? {};
|
|
6979
7004
|
console.log(`\x1B[35m\u2699\uFE0F Bundling the worker file...
|
|
6980
7005
|
\x1B[0m`);
|
|
6981
|
-
patchWranglerDeps(
|
|
6982
|
-
updateWebpackChunksFile(
|
|
7006
|
+
patchWranglerDeps(config);
|
|
7007
|
+
updateWebpackChunksFile(config);
|
|
6983
7008
|
await build({
|
|
6984
7009
|
entryPoints: [workerEntrypoint],
|
|
6985
7010
|
bundle: true,
|
|
@@ -6992,15 +7017,15 @@ async function buildWorker(outputDir2, nextjsAppPaths, templateSrcDir) {
|
|
|
6992
7017
|
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
|
|
6993
7018
|
// eval("require")("bufferutil");
|
|
6994
7019
|
// eval("require")("utf-8-validate");
|
|
6995
|
-
"next/dist/compiled/ws":
|
|
7020
|
+
"next/dist/compiled/ws": path10.join(templateDir, "shims", "empty.ts"),
|
|
6996
7021
|
// Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
|
|
6997
7022
|
// eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
|
|
6998
7023
|
// which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
|
|
6999
7024
|
// QUESTION: Why did I encountered this but mhart didn't?
|
|
7000
|
-
"next/dist/compiled/edge-runtime":
|
|
7025
|
+
"next/dist/compiled/edge-runtime": path10.join(templateDir, "shims", "empty.ts"),
|
|
7001
7026
|
// `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
|
|
7002
7027
|
// source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
|
|
7003
|
-
"@next/env":
|
|
7028
|
+
"@next/env": path10.join(templateDir, "shims", "env.ts")
|
|
7004
7029
|
},
|
|
7005
7030
|
define: {
|
|
7006
7031
|
// 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 +7059,21 @@ async function buildWorker(outputDir2, nextjsAppPaths, templateSrcDir) {
|
|
|
7034
7059
|
// Do not crash on cache not supported
|
|
7035
7060
|
// https://github.com/cloudflare/workerd/pull/2434
|
|
7036
7061
|
// compatibility flag "cache_option_enabled" -> does not support "force-cache"
|
|
7037
|
-
let isPatchedAlready = globalThis.fetch.__nextPatched;
|
|
7038
7062
|
const curFetch = globalThis.fetch;
|
|
7039
7063
|
globalThis.fetch = (input, init) => {
|
|
7040
|
-
|
|
7041
|
-
|
|
7064
|
+
if (init) {
|
|
7065
|
+
delete init.cache;
|
|
7066
|
+
}
|
|
7042
7067
|
return curFetch(input, init);
|
|
7043
7068
|
};
|
|
7044
7069
|
import { Readable } from 'node:stream';
|
|
7045
|
-
globalThis.fetch.__nextPatched = isPatchedAlready;
|
|
7046
7070
|
fetch = globalThis.fetch;
|
|
7047
7071
|
const CustomRequest = class extends globalThis.Request {
|
|
7048
7072
|
constructor(input, init) {
|
|
7049
|
-
console.log("CustomRequest", input);
|
|
7050
7073
|
if (init) {
|
|
7051
7074
|
delete init.cache;
|
|
7052
7075
|
if (init.body?.__node_stream__ === true) {
|
|
7076
|
+
// https://github.com/cloudflare/workerd/issues/2746
|
|
7053
7077
|
init.body = Readable.toWeb(init.body);
|
|
7054
7078
|
}
|
|
7055
7079
|
}
|
|
@@ -7058,26 +7082,22 @@ const CustomRequest = class extends globalThis.Request {
|
|
|
7058
7082
|
};
|
|
7059
7083
|
globalThis.Request = CustomRequest;
|
|
7060
7084
|
Request = globalThis.Request;
|
|
7061
|
-
|
|
7085
|
+
`
|
|
7062
7086
|
}
|
|
7063
7087
|
});
|
|
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
|
-
});
|
|
7088
|
+
await updateWorkerBundledCode(workerOutputFile, config);
|
|
7070
7089
|
console.log(`\x1B[35mWorker saved in \`${workerOutputFile}\` \u{1F680}
|
|
7071
7090
|
\x1B[0m`);
|
|
7072
7091
|
}
|
|
7073
|
-
async function updateWorkerBundledCode(workerOutputFile,
|
|
7092
|
+
async function updateWorkerBundledCode(workerOutputFile, config) {
|
|
7074
7093
|
const originalCode = await readFile(workerOutputFile, "utf8");
|
|
7075
7094
|
let patchedCode = originalCode;
|
|
7076
7095
|
patchedCode = patchRequire(patchedCode);
|
|
7077
|
-
patchedCode = patchReadFile(patchedCode,
|
|
7078
|
-
patchedCode = inlineNextRequire(patchedCode,
|
|
7079
|
-
patchedCode = patchFindDir(patchedCode,
|
|
7080
|
-
patchedCode = inlineEvalManifest(patchedCode,
|
|
7096
|
+
patchedCode = patchReadFile(patchedCode, config);
|
|
7097
|
+
patchedCode = inlineNextRequire(patchedCode, config);
|
|
7098
|
+
patchedCode = patchFindDir(patchedCode, config);
|
|
7099
|
+
patchedCode = inlineEvalManifest(patchedCode, config);
|
|
7100
|
+
patchedCode = patchCache(patchedCode, config);
|
|
7081
7101
|
await writeFile(workerOutputFile, patchedCode);
|
|
7082
7102
|
}
|
|
7083
7103
|
function createFixRequiresESBuildPlugin(templateDir) {
|
|
@@ -7085,100 +7105,105 @@ function createFixRequiresESBuildPlugin(templateDir) {
|
|
|
7085
7105
|
name: "replaceRelative",
|
|
7086
7106
|
setup(build3) {
|
|
7087
7107
|
build3.onResolve({ filter: /^\.\/require-hook$/ }, (args) => ({
|
|
7088
|
-
path:
|
|
7108
|
+
path: path10.join(templateDir, "shims", "empty.ts")
|
|
7089
7109
|
}));
|
|
7090
7110
|
build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, (args) => ({
|
|
7091
|
-
path:
|
|
7111
|
+
path: path10.join(templateDir, "shims", "empty.ts")
|
|
7092
7112
|
}));
|
|
7093
7113
|
}
|
|
7094
7114
|
};
|
|
7095
7115
|
}
|
|
7096
7116
|
|
|
7097
|
-
// src/
|
|
7117
|
+
// src/cli/config.ts
|
|
7098
7118
|
import { readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
|
|
7099
|
-
import
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7119
|
+
import path11, { relative } from "node:path";
|
|
7120
|
+
var PACKAGE_NAME = "@opennextjs/cloudflare";
|
|
7121
|
+
var UserConfig = {
|
|
7122
|
+
cache: {
|
|
7123
|
+
bindingName: "NEXT_CACHE_WORKERS_KV"
|
|
7124
|
+
}
|
|
7125
|
+
};
|
|
7126
|
+
function getConfig(appDir, outputDir2) {
|
|
7127
|
+
const dotNext = path11.join(outputDir2, ".next");
|
|
7128
|
+
const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
|
|
7129
|
+
const standaloneApp = path11.join(dotNext, "standalone", appPath);
|
|
7130
|
+
const standaloneAppDotNext = path11.join(standaloneApp, ".next");
|
|
7131
|
+
const standaloneAppServer = path11.join(standaloneAppDotNext, "server");
|
|
7132
|
+
const nodeModules = path11.join(standaloneApp, "node_modules");
|
|
7133
|
+
const internalPackage = path11.join(nodeModules, ...PACKAGE_NAME.split("/"));
|
|
7104
7134
|
return {
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7135
|
+
paths: {
|
|
7136
|
+
nextApp: appDir,
|
|
7137
|
+
builderOutput: outputDir2,
|
|
7138
|
+
dotNext,
|
|
7139
|
+
standaloneApp,
|
|
7140
|
+
standaloneAppDotNext,
|
|
7141
|
+
standaloneAppServer,
|
|
7142
|
+
internalPackage
|
|
7143
|
+
},
|
|
7144
|
+
cache: {
|
|
7145
|
+
kvBindingName: UserConfig.cache.bindingName
|
|
7146
|
+
},
|
|
7147
|
+
internalPackageName: PACKAGE_NAME
|
|
7110
7148
|
};
|
|
7111
7149
|
}
|
|
7112
|
-
function
|
|
7113
|
-
const dotNextDirPath = `${nextAppDir2}/.next`;
|
|
7150
|
+
function containsDotNextDir(folder) {
|
|
7114
7151
|
try {
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
throw new Error(`Error: \`.next\` directory not found!`);
|
|
7152
|
+
return statSync2(path11.join(folder, ".next")).isDirectory();
|
|
7153
|
+
} catch (e) {
|
|
7154
|
+
return false;
|
|
7119
7155
|
}
|
|
7120
|
-
return dotNextDirPath;
|
|
7121
7156
|
}
|
|
7122
7157
|
function getNextjsApplicationPath(dotNextDir) {
|
|
7123
7158
|
const serverPath = findServerParentPath(dotNextDir);
|
|
7124
7159
|
if (!serverPath) {
|
|
7125
7160
|
throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
|
|
7126
7161
|
}
|
|
7127
|
-
return relative(
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
} catch {
|
|
7162
|
+
return relative(path11.join(dotNextDir, "standalone"), serverPath);
|
|
7163
|
+
}
|
|
7164
|
+
function findServerParentPath(parentPath) {
|
|
7165
|
+
try {
|
|
7166
|
+
if (statSync2(path11.join(parentPath, ".next", "server")).isDirectory()) {
|
|
7167
|
+
return parentPath;
|
|
7134
7168
|
}
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7169
|
+
} catch {
|
|
7170
|
+
}
|
|
7171
|
+
const folders = readdirSync3(parentPath);
|
|
7172
|
+
for (const folder of folders) {
|
|
7173
|
+
const subFolder = path11.join(parentPath, folder);
|
|
7174
|
+
if (statSync2(path11.join(parentPath, folder)).isDirectory()) {
|
|
7175
|
+
const dirServerPath = findServerParentPath(subFolder);
|
|
7176
|
+
if (dirServerPath) {
|
|
7177
|
+
return dirServerPath;
|
|
7142
7178
|
}
|
|
7143
7179
|
}
|
|
7144
7180
|
}
|
|
7145
7181
|
}
|
|
7146
7182
|
|
|
7147
|
-
// src/build/
|
|
7148
|
-
import
|
|
7149
|
-
import
|
|
7150
|
-
|
|
7151
|
-
var SAVE_DIR = ".save.next";
|
|
7152
|
-
async function build2(inputNextAppDir, opts) {
|
|
7183
|
+
// src/cli/build/index.ts
|
|
7184
|
+
import { cpSync as cpSync2 } from "node:fs";
|
|
7185
|
+
import path12 from "node:path";
|
|
7186
|
+
async function build2(appDir, opts) {
|
|
7153
7187
|
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
|
-
});
|
|
7188
|
+
buildNextjsApp(appDir);
|
|
7189
|
+
}
|
|
7190
|
+
if (!containsDotNextDir(appDir)) {
|
|
7191
|
+
throw new Error(`.next folder not found in ${appDir}`);
|
|
7167
7192
|
}
|
|
7168
|
-
const outputDir2 =
|
|
7193
|
+
const outputDir2 = path12.resolve(opts.outputDir ?? appDir, ".worker-next");
|
|
7169
7194
|
await cleanDirectory(outputDir2);
|
|
7170
|
-
|
|
7171
|
-
const
|
|
7172
|
-
await buildWorker(
|
|
7195
|
+
cpSync2(path12.join(appDir, ".next"), path12.join(outputDir2, ".next"), { recursive: true });
|
|
7196
|
+
const config = getConfig(appDir, outputDir2);
|
|
7197
|
+
await buildWorker(config);
|
|
7173
7198
|
}
|
|
7174
|
-
async function cleanDirectory(
|
|
7175
|
-
return await rm(
|
|
7199
|
+
async function cleanDirectory(path13) {
|
|
7200
|
+
return await rm(path13, { recursive: true, force: true });
|
|
7176
7201
|
}
|
|
7177
7202
|
|
|
7178
|
-
// src/index.ts
|
|
7203
|
+
// src/cli/index.ts
|
|
7179
7204
|
var nextAppDir = resolve2(".");
|
|
7180
7205
|
console.log(`Building the Next.js app in the current folder (${nextAppDir})`);
|
|
7181
|
-
if (!["js", "cjs", "mjs", "ts"].some((ext2) =>
|
|
7206
|
+
if (!["js", "cjs", "mjs", "ts"].some((ext2) => existsSync4(`./next.config.${ext2}`))) {
|
|
7182
7207
|
throw new Error("Error: Not in a Next.js app project");
|
|
7183
7208
|
}
|
|
7184
7209
|
var { skipBuild, outputDir } = getArgs();
|