@opennextjs/cloudflare 0.0.0-42bf0ff → 0.0.0-5105d31
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 +85 -14
- 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/{cache-handler.mjs → cli/cache-handler.mjs} +2 -2
- package/dist/{index.mjs → cli/index.mjs} +412 -325
- package/dist/{templates → cli/templates}/shims/node-fs.ts +1 -1
- package/dist/{templates → cli/templates}/worker.ts +57 -33
- package/package.json +22 -3
- /package/dist/{chunk-UJCSKKID.mjs → cli/chunk-UJCSKKID.mjs} +0 -0
- /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/throw.ts +0 -0
|
@@ -213,68 +213,171 @@ var require_brace_expansion = __commonJS({
|
|
|
213
213
|
}
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
-
// src/
|
|
217
|
-
import {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
function getArgs() {
|
|
224
|
-
const {
|
|
225
|
-
values: { skipBuild: skipBuild2, output }
|
|
226
|
-
} = parseArgs({
|
|
227
|
-
options: {
|
|
228
|
-
skipBuild: {
|
|
229
|
-
type: "boolean",
|
|
230
|
-
short: "s",
|
|
231
|
-
default: false
|
|
232
|
-
},
|
|
233
|
-
output: {
|
|
234
|
-
type: "string",
|
|
235
|
-
short: "o"
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
allowPositionals: false
|
|
239
|
-
});
|
|
240
|
-
const outputDir2 = output ? resolve(output) : void 0;
|
|
241
|
-
if (outputDir2) {
|
|
242
|
-
assertDirArg(outputDir2, "output", true);
|
|
216
|
+
// src/cli/config.ts
|
|
217
|
+
import path, { relative } from "node:path";
|
|
218
|
+
import { readdirSync, statSync } from "node:fs";
|
|
219
|
+
var PACKAGE_NAME = "@opennextjs/cloudflare";
|
|
220
|
+
var UserConfig = {
|
|
221
|
+
cache: {
|
|
222
|
+
bindingName: "NEXT_CACHE_WORKERS_KV"
|
|
243
223
|
}
|
|
224
|
+
};
|
|
225
|
+
function getConfig(appDir, outputDir2) {
|
|
226
|
+
const dotNext = path.join(outputDir2, ".next");
|
|
227
|
+
const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
|
|
228
|
+
const standaloneRoot = path.join(dotNext, "standalone");
|
|
229
|
+
const standaloneApp = path.join(standaloneRoot, appPath);
|
|
230
|
+
const standaloneAppDotNext = path.join(standaloneApp, ".next");
|
|
231
|
+
const standaloneAppServer = path.join(standaloneAppDotNext, "server");
|
|
232
|
+
const nodeModules = path.join(standaloneApp, "node_modules");
|
|
233
|
+
const internalPackage = path.join(nodeModules, ...PACKAGE_NAME.split("/"));
|
|
244
234
|
return {
|
|
245
|
-
|
|
246
|
-
|
|
235
|
+
paths: {
|
|
236
|
+
nextApp: appDir,
|
|
237
|
+
builderOutput: outputDir2,
|
|
238
|
+
dotNext,
|
|
239
|
+
standaloneRoot,
|
|
240
|
+
standaloneApp,
|
|
241
|
+
standaloneAppDotNext,
|
|
242
|
+
standaloneAppServer,
|
|
243
|
+
internalPackage
|
|
244
|
+
},
|
|
245
|
+
cache: {
|
|
246
|
+
kvBindingName: UserConfig.cache.bindingName
|
|
247
|
+
},
|
|
248
|
+
internalPackageName: PACKAGE_NAME
|
|
247
249
|
};
|
|
248
250
|
}
|
|
249
|
-
function
|
|
250
|
-
let dirStats;
|
|
251
|
+
function containsDotNextDir(folder) {
|
|
251
252
|
try {
|
|
252
|
-
|
|
253
|
+
return statSync(path.join(folder, ".next")).isDirectory();
|
|
253
254
|
} catch {
|
|
254
|
-
|
|
255
|
-
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function getNextjsApplicationPath(dotNextDir) {
|
|
259
|
+
const serverPath = findServerParentPath(dotNextDir);
|
|
260
|
+
if (!serverPath) {
|
|
261
|
+
throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
|
|
262
|
+
}
|
|
263
|
+
return relative(path.join(dotNextDir, "standalone"), serverPath);
|
|
264
|
+
}
|
|
265
|
+
function findServerParentPath(parentPath) {
|
|
266
|
+
try {
|
|
267
|
+
if (statSync(path.join(parentPath, ".next", "server")).isDirectory()) {
|
|
268
|
+
return parentPath;
|
|
256
269
|
}
|
|
257
|
-
|
|
258
|
-
return;
|
|
270
|
+
} catch {
|
|
259
271
|
}
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
const folders = readdirSync(parentPath);
|
|
273
|
+
for (const folder of folders) {
|
|
274
|
+
const subFolder = path.join(parentPath, folder);
|
|
275
|
+
if (statSync(path.join(parentPath, folder)).isDirectory()) {
|
|
276
|
+
const dirServerPath = findServerParentPath(subFolder);
|
|
277
|
+
if (dirServerPath) {
|
|
278
|
+
return dirServerPath;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
262
281
|
}
|
|
263
282
|
}
|
|
264
283
|
|
|
265
|
-
//
|
|
266
|
-
|
|
284
|
+
// ../../node_modules/.pnpm/package-manager-detector@0.2.0/node_modules/package-manager-detector/dist/constants.mjs
|
|
285
|
+
var AGENTS = [
|
|
286
|
+
"npm",
|
|
287
|
+
"yarn",
|
|
288
|
+
"yarn@berry",
|
|
289
|
+
"pnpm",
|
|
290
|
+
"pnpm@6",
|
|
291
|
+
"bun"
|
|
292
|
+
];
|
|
293
|
+
var LOCKS = {
|
|
294
|
+
"bun.lockb": "bun",
|
|
295
|
+
"pnpm-lock.yaml": "pnpm",
|
|
296
|
+
"yarn.lock": "yarn",
|
|
297
|
+
"package-lock.json": "npm",
|
|
298
|
+
"npm-shrinkwrap.json": "npm"
|
|
299
|
+
};
|
|
267
300
|
|
|
268
|
-
//
|
|
269
|
-
import
|
|
301
|
+
// ../../node_modules/.pnpm/package-manager-detector@0.2.0/node_modules/package-manager-detector/dist/detect.mjs
|
|
302
|
+
import fs from "node:fs";
|
|
303
|
+
import fsPromises from "node:fs/promises";
|
|
304
|
+
import path2 from "node:path";
|
|
305
|
+
import process2 from "node:process";
|
|
306
|
+
async function detect({ cwd, onUnknown } = {}) {
|
|
307
|
+
for (const directory of lookup(cwd)) {
|
|
308
|
+
for (const lock of Object.keys(LOCKS)) {
|
|
309
|
+
if (await fileExists(path2.join(directory, lock))) {
|
|
310
|
+
const name = LOCKS[lock];
|
|
311
|
+
const result2 = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
|
|
312
|
+
if (result2)
|
|
313
|
+
return result2;
|
|
314
|
+
else
|
|
315
|
+
return { name, agent: name };
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
|
|
319
|
+
if (result)
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
function* lookup(cwd = process2.cwd()) {
|
|
325
|
+
let directory = path2.resolve(cwd);
|
|
326
|
+
const { root } = path2.parse(directory);
|
|
327
|
+
while (directory && directory !== root) {
|
|
328
|
+
yield directory;
|
|
329
|
+
directory = path2.dirname(directory);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async function parsePackageJson(filepath, onUnknown) {
|
|
333
|
+
if (!filepath || !await fileExists(filepath))
|
|
334
|
+
return null;
|
|
335
|
+
try {
|
|
336
|
+
const pkg = JSON.parse(fs.readFileSync(filepath, "utf8"));
|
|
337
|
+
let agent;
|
|
338
|
+
if (typeof pkg.packageManager === "string") {
|
|
339
|
+
const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
|
|
340
|
+
let version = ver;
|
|
341
|
+
if (name === "yarn" && Number.parseInt(ver) > 1) {
|
|
342
|
+
agent = "yarn@berry";
|
|
343
|
+
version = "berry";
|
|
344
|
+
return { name, agent, version };
|
|
345
|
+
} else if (name === "pnpm" && Number.parseInt(ver) < 7) {
|
|
346
|
+
agent = "pnpm@6";
|
|
347
|
+
return { name, agent, version };
|
|
348
|
+
} else if (AGENTS.includes(name)) {
|
|
349
|
+
agent = name;
|
|
350
|
+
return { name, agent, version };
|
|
351
|
+
} else {
|
|
352
|
+
return onUnknown?.(pkg.packageManager) ?? null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
} catch {
|
|
356
|
+
}
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
async function fileExists(filePath) {
|
|
360
|
+
try {
|
|
361
|
+
const stats = await fsPromises.stat(filePath);
|
|
362
|
+
if (stats.isFile()) {
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
} catch {
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
270
369
|
|
|
271
|
-
// src/build/build-next-app.ts
|
|
370
|
+
// src/cli/build/build-next-app.ts
|
|
272
371
|
import { execSync } from "node:child_process";
|
|
273
|
-
function buildNextjsApp(nextAppDir2) {
|
|
274
|
-
|
|
372
|
+
async function buildNextjsApp(nextAppDir2) {
|
|
373
|
+
const pm = await detect();
|
|
374
|
+
if (!pm) {
|
|
375
|
+
throw new Error("Fatal Error: package manager detection failed, aborting");
|
|
376
|
+
}
|
|
377
|
+
runNextBuildCommand(pm.name, nextAppDir2);
|
|
275
378
|
}
|
|
276
379
|
function runNextBuildCommand(packager, nextAppDir2) {
|
|
277
|
-
const command =
|
|
380
|
+
const command = `${packager === "npm" ? "npx" : packager} next build`;
|
|
278
381
|
execSync(command, {
|
|
279
382
|
stdio: "inherit",
|
|
280
383
|
cwd: nextAppDir2,
|
|
@@ -287,28 +390,23 @@ function runNextBuildCommand(packager, nextAppDir2) {
|
|
|
287
390
|
});
|
|
288
391
|
}
|
|
289
392
|
|
|
290
|
-
// src/build/build-worker.ts
|
|
393
|
+
// src/cli/build/build-worker.ts
|
|
291
394
|
import { build } from "esbuild";
|
|
292
|
-
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
293
395
|
import { cp, readFile, writeFile } from "node:fs/promises";
|
|
294
|
-
import
|
|
295
|
-
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
296
|
-
|
|
297
|
-
// src/build/patches/investigated/patch-require.ts
|
|
298
|
-
function patchRequire(code) {
|
|
299
|
-
console.log("# patchRequire");
|
|
300
|
-
return code.replace(/__require\d?\(/g, "require(").replace(/__require\d?\./g, "require.");
|
|
301
|
-
}
|
|
396
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
302
397
|
|
|
303
|
-
// src/build/patches/investigated/copy-package.ts
|
|
398
|
+
// src/cli/build/patches/investigated/copy-package-cli-files.ts
|
|
304
399
|
import { cpSync } from "node:fs";
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
400
|
+
import path3 from "node:path";
|
|
401
|
+
function copyPackageCliFiles(packageDistDir2, config) {
|
|
402
|
+
console.log("# copyPackageTemplateFiles");
|
|
403
|
+
const sourceDir = path3.join(packageDistDir2, "cli");
|
|
404
|
+
const destinationDir = path3.join(config.paths.internalPackage, "cli");
|
|
405
|
+
cpSync(sourceDir, destinationDir, { recursive: true });
|
|
308
406
|
}
|
|
309
407
|
|
|
310
|
-
// src/build/
|
|
311
|
-
import {
|
|
408
|
+
// src/cli/build/build-worker.ts
|
|
409
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
312
410
|
|
|
313
411
|
// ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
|
|
314
412
|
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
@@ -981,11 +1079,11 @@ var qmarksTestNoExtDot = ([$0]) => {
|
|
|
981
1079
|
return (f) => f.length === len && f !== "." && f !== "..";
|
|
982
1080
|
};
|
|
983
1081
|
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
984
|
-
var
|
|
1082
|
+
var path4 = {
|
|
985
1083
|
win32: { sep: "\\" },
|
|
986
1084
|
posix: { sep: "/" }
|
|
987
1085
|
};
|
|
988
|
-
var sep = defaultPlatform === "win32" ?
|
|
1086
|
+
var sep = defaultPlatform === "win32" ? path4.win32.sep : path4.posix.sep;
|
|
989
1087
|
minimatch.sep = sep;
|
|
990
1088
|
var GLOBSTAR = Symbol("globstar **");
|
|
991
1089
|
minimatch.GLOBSTAR = GLOBSTAR;
|
|
@@ -3015,7 +3113,7 @@ var LRUCache = class _LRUCache {
|
|
|
3015
3113
|
// ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
|
|
3016
3114
|
import { posix, win32 } from "node:path";
|
|
3017
3115
|
import { fileURLToPath } from "node:url";
|
|
3018
|
-
import { lstatSync, readdir as readdirCB, readdirSync, readlinkSync, realpathSync as rps } from "fs";
|
|
3116
|
+
import { lstatSync, readdir as readdirCB, readdirSync as readdirSync2, readlinkSync, realpathSync as rps } from "fs";
|
|
3019
3117
|
import * as actualFS from "node:fs";
|
|
3020
3118
|
import { lstat, readdir, readlink, realpath } from "node:fs/promises";
|
|
3021
3119
|
|
|
@@ -3902,7 +4000,7 @@ var realpathSync = rps.native;
|
|
|
3902
4000
|
var defaultFS = {
|
|
3903
4001
|
lstatSync,
|
|
3904
4002
|
readdir: readdirCB,
|
|
3905
|
-
readdirSync,
|
|
4003
|
+
readdirSync: readdirSync2,
|
|
3906
4004
|
readlinkSync,
|
|
3907
4005
|
realpathSync,
|
|
3908
4006
|
promises: {
|
|
@@ -4162,12 +4260,12 @@ var PathBase = class {
|
|
|
4162
4260
|
/**
|
|
4163
4261
|
* Get the Path object referenced by the string path, resolved from this Path
|
|
4164
4262
|
*/
|
|
4165
|
-
resolve(
|
|
4166
|
-
if (!
|
|
4263
|
+
resolve(path14) {
|
|
4264
|
+
if (!path14) {
|
|
4167
4265
|
return this;
|
|
4168
4266
|
}
|
|
4169
|
-
const rootPath = this.getRootString(
|
|
4170
|
-
const dir =
|
|
4267
|
+
const rootPath = this.getRootString(path14);
|
|
4268
|
+
const dir = path14.substring(rootPath.length);
|
|
4171
4269
|
const dirParts = dir.split(this.splitSep);
|
|
4172
4270
|
const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
|
|
4173
4271
|
return result;
|
|
@@ -4919,8 +5017,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
|
|
|
4919
5017
|
/**
|
|
4920
5018
|
* @internal
|
|
4921
5019
|
*/
|
|
4922
|
-
getRootString(
|
|
4923
|
-
return win32.parse(
|
|
5020
|
+
getRootString(path14) {
|
|
5021
|
+
return win32.parse(path14).root;
|
|
4924
5022
|
}
|
|
4925
5023
|
/**
|
|
4926
5024
|
* @internal
|
|
@@ -4966,8 +5064,8 @@ var PathPosix = class _PathPosix extends PathBase {
|
|
|
4966
5064
|
/**
|
|
4967
5065
|
* @internal
|
|
4968
5066
|
*/
|
|
4969
|
-
getRootString(
|
|
4970
|
-
return
|
|
5067
|
+
getRootString(path14) {
|
|
5068
|
+
return path14.startsWith("/") ? "/" : "";
|
|
4971
5069
|
}
|
|
4972
5070
|
/**
|
|
4973
5071
|
* @internal
|
|
@@ -5016,8 +5114,8 @@ var PathScurryBase = class {
|
|
|
5016
5114
|
*
|
|
5017
5115
|
* @internal
|
|
5018
5116
|
*/
|
|
5019
|
-
constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs:
|
|
5020
|
-
this.#fs = fsFromOption(
|
|
5117
|
+
constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs: fs3 = defaultFS } = {}) {
|
|
5118
|
+
this.#fs = fsFromOption(fs3);
|
|
5021
5119
|
if (cwd instanceof URL || cwd.startsWith("file://")) {
|
|
5022
5120
|
cwd = fileURLToPath(cwd);
|
|
5023
5121
|
}
|
|
@@ -5056,11 +5154,11 @@ var PathScurryBase = class {
|
|
|
5056
5154
|
/**
|
|
5057
5155
|
* Get the depth of a provided path, string, or the cwd
|
|
5058
5156
|
*/
|
|
5059
|
-
depth(
|
|
5060
|
-
if (typeof
|
|
5061
|
-
|
|
5157
|
+
depth(path14 = this.cwd) {
|
|
5158
|
+
if (typeof path14 === "string") {
|
|
5159
|
+
path14 = this.cwd.resolve(path14);
|
|
5062
5160
|
}
|
|
5063
|
-
return
|
|
5161
|
+
return path14.depth();
|
|
5064
5162
|
}
|
|
5065
5163
|
/**
|
|
5066
5164
|
* Return the cache of child entries. Exposed so subclasses can create
|
|
@@ -5439,7 +5537,7 @@ var PathScurryBase = class {
|
|
|
5439
5537
|
const dirs = /* @__PURE__ */ new Set();
|
|
5440
5538
|
const queue = [entry];
|
|
5441
5539
|
let processing = 0;
|
|
5442
|
-
const
|
|
5540
|
+
const process3 = () => {
|
|
5443
5541
|
let paused = false;
|
|
5444
5542
|
while (!paused) {
|
|
5445
5543
|
const dir = queue.shift();
|
|
@@ -5480,9 +5578,9 @@ var PathScurryBase = class {
|
|
|
5480
5578
|
}
|
|
5481
5579
|
}
|
|
5482
5580
|
if (paused && !results.flowing) {
|
|
5483
|
-
results.once("drain",
|
|
5581
|
+
results.once("drain", process3);
|
|
5484
5582
|
} else if (!sync2) {
|
|
5485
|
-
|
|
5583
|
+
process3();
|
|
5486
5584
|
}
|
|
5487
5585
|
};
|
|
5488
5586
|
let sync2 = true;
|
|
@@ -5490,7 +5588,7 @@ var PathScurryBase = class {
|
|
|
5490
5588
|
sync2 = false;
|
|
5491
5589
|
}
|
|
5492
5590
|
};
|
|
5493
|
-
|
|
5591
|
+
process3();
|
|
5494
5592
|
return results;
|
|
5495
5593
|
}
|
|
5496
5594
|
streamSync(entry = this.cwd, opts = {}) {
|
|
@@ -5508,7 +5606,7 @@ var PathScurryBase = class {
|
|
|
5508
5606
|
}
|
|
5509
5607
|
const queue = [entry];
|
|
5510
5608
|
let processing = 0;
|
|
5511
|
-
const
|
|
5609
|
+
const process3 = () => {
|
|
5512
5610
|
let paused = false;
|
|
5513
5611
|
while (!paused) {
|
|
5514
5612
|
const dir = queue.shift();
|
|
@@ -5542,14 +5640,14 @@ var PathScurryBase = class {
|
|
|
5542
5640
|
}
|
|
5543
5641
|
}
|
|
5544
5642
|
if (paused && !results.flowing)
|
|
5545
|
-
results.once("drain",
|
|
5643
|
+
results.once("drain", process3);
|
|
5546
5644
|
};
|
|
5547
|
-
|
|
5645
|
+
process3();
|
|
5548
5646
|
return results;
|
|
5549
5647
|
}
|
|
5550
|
-
chdir(
|
|
5648
|
+
chdir(path14 = this.cwd) {
|
|
5551
5649
|
const oldCwd = this.cwd;
|
|
5552
|
-
this.cwd = typeof
|
|
5650
|
+
this.cwd = typeof path14 === "string" ? this.cwd.resolve(path14) : path14;
|
|
5553
5651
|
this.cwd[setAsCwd](oldCwd);
|
|
5554
5652
|
}
|
|
5555
5653
|
};
|
|
@@ -5575,8 +5673,8 @@ var PathScurryWin32 = class extends PathScurryBase {
|
|
|
5575
5673
|
/**
|
|
5576
5674
|
* @internal
|
|
5577
5675
|
*/
|
|
5578
|
-
newRoot(
|
|
5579
|
-
return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
5676
|
+
newRoot(fs3) {
|
|
5677
|
+
return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs3 });
|
|
5580
5678
|
}
|
|
5581
5679
|
/**
|
|
5582
5680
|
* Return true if the provided path string is an absolute path
|
|
@@ -5604,8 +5702,8 @@ var PathScurryPosix = class extends PathScurryBase {
|
|
|
5604
5702
|
/**
|
|
5605
5703
|
* @internal
|
|
5606
5704
|
*/
|
|
5607
|
-
newRoot(
|
|
5608
|
-
return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
5705
|
+
newRoot(fs3) {
|
|
5706
|
+
return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs3 });
|
|
5609
5707
|
}
|
|
5610
5708
|
/**
|
|
5611
5709
|
* Return true if the provided path string is an absolute path
|
|
@@ -5905,8 +6003,8 @@ var MatchRecord = class {
|
|
|
5905
6003
|
}
|
|
5906
6004
|
// match, absolute, ifdir
|
|
5907
6005
|
entries() {
|
|
5908
|
-
return [...this.store.entries()].map(([
|
|
5909
|
-
|
|
6006
|
+
return [...this.store.entries()].map(([path14, n]) => [
|
|
6007
|
+
path14,
|
|
5910
6008
|
!!(n & 2),
|
|
5911
6009
|
!!(n & 1)
|
|
5912
6010
|
]);
|
|
@@ -6111,9 +6209,9 @@ var GlobUtil = class {
|
|
|
6111
6209
|
signal;
|
|
6112
6210
|
maxDepth;
|
|
6113
6211
|
includeChildMatches;
|
|
6114
|
-
constructor(patterns,
|
|
6212
|
+
constructor(patterns, path14, opts) {
|
|
6115
6213
|
this.patterns = patterns;
|
|
6116
|
-
this.path =
|
|
6214
|
+
this.path = path14;
|
|
6117
6215
|
this.opts = opts;
|
|
6118
6216
|
this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
|
|
6119
6217
|
this.includeChildMatches = opts.includeChildMatches !== false;
|
|
@@ -6132,11 +6230,11 @@ var GlobUtil = class {
|
|
|
6132
6230
|
});
|
|
6133
6231
|
}
|
|
6134
6232
|
}
|
|
6135
|
-
#ignored(
|
|
6136
|
-
return this.seen.has(
|
|
6233
|
+
#ignored(path14) {
|
|
6234
|
+
return this.seen.has(path14) || !!this.#ignore?.ignored?.(path14);
|
|
6137
6235
|
}
|
|
6138
|
-
#childrenIgnored(
|
|
6139
|
-
return !!this.#ignore?.childrenIgnored?.(
|
|
6236
|
+
#childrenIgnored(path14) {
|
|
6237
|
+
return !!this.#ignore?.childrenIgnored?.(path14);
|
|
6140
6238
|
}
|
|
6141
6239
|
// backpressure mechanism
|
|
6142
6240
|
pause() {
|
|
@@ -6351,8 +6449,8 @@ var GlobUtil = class {
|
|
|
6351
6449
|
};
|
|
6352
6450
|
var GlobWalker = class extends GlobUtil {
|
|
6353
6451
|
matches = /* @__PURE__ */ new Set();
|
|
6354
|
-
constructor(patterns,
|
|
6355
|
-
super(patterns,
|
|
6452
|
+
constructor(patterns, path14, opts) {
|
|
6453
|
+
super(patterns, path14, opts);
|
|
6356
6454
|
}
|
|
6357
6455
|
matchEmit(e) {
|
|
6358
6456
|
this.matches.add(e);
|
|
@@ -6389,8 +6487,8 @@ var GlobWalker = class extends GlobUtil {
|
|
|
6389
6487
|
};
|
|
6390
6488
|
var GlobStream = class extends GlobUtil {
|
|
6391
6489
|
results;
|
|
6392
|
-
constructor(patterns,
|
|
6393
|
-
super(patterns,
|
|
6490
|
+
constructor(patterns, path14, opts) {
|
|
6491
|
+
super(patterns, path14, opts);
|
|
6394
6492
|
this.results = new Minipass({
|
|
6395
6493
|
signal: this.signal,
|
|
6396
6494
|
objectMode: true
|
|
@@ -6683,67 +6781,44 @@ var glob = Object.assign(glob_, {
|
|
|
6683
6781
|
});
|
|
6684
6782
|
glob.glob = glob;
|
|
6685
6783
|
|
|
6686
|
-
// src/build/patches/to-investigate/
|
|
6687
|
-
import
|
|
6688
|
-
function
|
|
6689
|
-
console.log("#
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
);
|
|
6696
|
-
const manifestJsons = globSync(path2.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
|
|
6697
|
-
(file) => file.replace(config.paths.standaloneApp + "/", "")
|
|
6698
|
-
);
|
|
6699
|
-
code = code.replace(
|
|
6700
|
-
/function loadManifest\((.+?), .+?\) {/,
|
|
6784
|
+
// src/cli/build/patches/to-investigate/inline-eval-manifest.ts
|
|
6785
|
+
import path5 from "node:path";
|
|
6786
|
+
function inlineEvalManifest(code, config) {
|
|
6787
|
+
console.log("# inlineEvalManifest");
|
|
6788
|
+
const manifestJss = globSync(
|
|
6789
|
+
path5.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
|
|
6790
|
+
).map((file) => file.replace(`${config.paths.standaloneApp}/`, ""));
|
|
6791
|
+
return code.replace(
|
|
6792
|
+
/function evalManifest\((.+?), .+?\) {/,
|
|
6701
6793
|
`$&
|
|
6702
|
-
|
|
6703
|
-
(
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6794
|
+
${manifestJss.map(
|
|
6795
|
+
(manifestJs) => `
|
|
6796
|
+
if ($1.endsWith("${manifestJs}")) {
|
|
6797
|
+
require("${path5.join(config.paths.standaloneApp, manifestJs)}");
|
|
6798
|
+
return {
|
|
6799
|
+
__RSC_MANIFEST: {
|
|
6800
|
+
"${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
|
|
6801
|
+
},
|
|
6802
|
+
};
|
|
6803
|
+
}
|
|
6804
|
+
`
|
|
6708
6805
|
).join("\n")}
|
|
6709
|
-
|
|
6710
|
-
`
|
|
6711
|
-
);
|
|
6712
|
-
return code;
|
|
6713
|
-
}
|
|
6714
|
-
|
|
6715
|
-
// src/build/patches/to-investigate/patch-find-dir.ts
|
|
6716
|
-
import path3 from "node:path";
|
|
6717
|
-
import { existsSync } from "node:fs";
|
|
6718
|
-
function patchFindDir(code, config) {
|
|
6719
|
-
console.log("# patchFindDir");
|
|
6720
|
-
return code.replace(
|
|
6721
|
-
"function findDir(dir, name) {",
|
|
6722
|
-
`function findDir(dir, name) {
|
|
6723
|
-
if (dir.endsWith(".next/server")) {
|
|
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
|
-
}
|
|
6730
|
-
}
|
|
6731
|
-
throw new Error("Unknown findDir call: " + dir + " " + name);
|
|
6806
|
+
throw new Error("Unknown evalManifest: " + $1);
|
|
6732
6807
|
`
|
|
6733
6808
|
);
|
|
6734
6809
|
}
|
|
6735
6810
|
|
|
6736
|
-
// src/build/patches/to-investigate/inline-next-require.ts
|
|
6737
|
-
import {
|
|
6738
|
-
import
|
|
6811
|
+
// src/cli/build/patches/to-investigate/inline-next-require.ts
|
|
6812
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6813
|
+
import path6 from "node:path";
|
|
6739
6814
|
function inlineNextRequire(code, config) {
|
|
6740
6815
|
console.log("# inlineNextRequire");
|
|
6741
|
-
const pagesManifestFile =
|
|
6742
|
-
const appPathsManifestFile =
|
|
6743
|
-
const pagesManifestFiles =
|
|
6816
|
+
const pagesManifestFile = path6.join(config.paths.standaloneAppServer, "pages-manifest.json");
|
|
6817
|
+
const appPathsManifestFile = path6.join(config.paths.standaloneAppServer, "app-paths-manifest.json");
|
|
6818
|
+
const pagesManifestFiles = existsSync(pagesManifestFile) ? Object.values(JSON.parse(readFileSync(pagesManifestFile, "utf-8"))).map(
|
|
6744
6819
|
(file) => ".next/server/" + file
|
|
6745
6820
|
) : [];
|
|
6746
|
-
const appPathsManifestFiles =
|
|
6821
|
+
const appPathsManifestFiles = existsSync(appPathsManifestFile) ? Object.values(JSON.parse(readFileSync(appPathsManifestFile, "utf-8"))).map(
|
|
6747
6822
|
(file) => ".next/server/" + file
|
|
6748
6823
|
) : [];
|
|
6749
6824
|
const allManifestFiles = pagesManifestFiles.concat(appPathsManifestFiles);
|
|
@@ -6755,14 +6830,14 @@ function inlineNextRequire(code, config) {
|
|
|
6755
6830
|
${htmlPages.map(
|
|
6756
6831
|
(htmlPage) => `
|
|
6757
6832
|
if (pagePath.endsWith("${htmlPage}")) {
|
|
6758
|
-
return ${JSON.stringify(
|
|
6833
|
+
return ${JSON.stringify(readFileSync(path6.join(config.paths.standaloneApp, htmlPage), "utf-8"))};
|
|
6759
6834
|
}
|
|
6760
6835
|
`
|
|
6761
6836
|
).join("\n")}
|
|
6762
6837
|
${pageModules.map(
|
|
6763
6838
|
(module) => `
|
|
6764
6839
|
if (pagePath.endsWith("${module}")) {
|
|
6765
|
-
return require("${
|
|
6840
|
+
return require("${path6.join(config.paths.standaloneApp, module)}");
|
|
6766
6841
|
}
|
|
6767
6842
|
`
|
|
6768
6843
|
).join("\n")}
|
|
@@ -6771,68 +6846,112 @@ function inlineNextRequire(code, config) {
|
|
|
6771
6846
|
);
|
|
6772
6847
|
}
|
|
6773
6848
|
|
|
6774
|
-
// src/build/patches/
|
|
6775
|
-
import
|
|
6776
|
-
function
|
|
6777
|
-
console.log("#
|
|
6778
|
-
const
|
|
6779
|
-
|
|
6780
|
-
|
|
6849
|
+
// src/cli/build/patches/investigated/patch-cache.ts
|
|
6850
|
+
import path7 from "node:path";
|
|
6851
|
+
function patchCache(code, config) {
|
|
6852
|
+
console.log("# patchCached");
|
|
6853
|
+
const cacheHandler = path7.join(config.paths.internalPackage, "cli", "cache-handler.mjs");
|
|
6854
|
+
const patchedCode = code.replace(
|
|
6855
|
+
"const { cacheHandler } = this.nextConfig;",
|
|
6856
|
+
`const cacheHandler = null;
|
|
6857
|
+
CacheHandler = (await import('${cacheHandler}')).default;
|
|
6858
|
+
CacheHandler.maybeKVNamespace = process.env["${config.cache.kvBindingName}"];
|
|
6859
|
+
`
|
|
6860
|
+
);
|
|
6861
|
+
if (patchedCode === code) {
|
|
6862
|
+
throw new Error("Cache patch not applied");
|
|
6863
|
+
}
|
|
6864
|
+
return patchedCode;
|
|
6865
|
+
}
|
|
6866
|
+
|
|
6867
|
+
// src/cli/build/patches/to-investigate/patch-find-dir.ts
|
|
6868
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
6869
|
+
import path8 from "node:path";
|
|
6870
|
+
function patchFindDir(code, config) {
|
|
6871
|
+
console.log("# patchFindDir");
|
|
6781
6872
|
return code.replace(
|
|
6782
|
-
|
|
6873
|
+
"function findDir(dir, name) {",
|
|
6874
|
+
`function findDir(dir, name) {
|
|
6875
|
+
if (dir.endsWith(".next/server")) {
|
|
6876
|
+
if (name === "app") {
|
|
6877
|
+
return ${existsSync2(`${path8.join(config.paths.standaloneAppServer, "app")}`)};
|
|
6878
|
+
}
|
|
6879
|
+
if (name === "pages") {
|
|
6880
|
+
return ${existsSync2(`${path8.join(config.paths.standaloneAppServer, "pages")}`)};
|
|
6881
|
+
}
|
|
6882
|
+
}
|
|
6883
|
+
throw new Error("Unknown findDir call: " + dir + " " + name);
|
|
6884
|
+
`
|
|
6885
|
+
);
|
|
6886
|
+
}
|
|
6887
|
+
|
|
6888
|
+
// src/cli/build/patches/to-investigate/patch-read-file.ts
|
|
6889
|
+
import path9 from "node:path";
|
|
6890
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
6891
|
+
function patchReadFile(code, config) {
|
|
6892
|
+
console.log("# patchReadFile");
|
|
6893
|
+
code = code.replace(
|
|
6894
|
+
"getBuildId() {",
|
|
6895
|
+
`getBuildId() {
|
|
6896
|
+
return ${JSON.stringify(readFileSync2(path9.join(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
|
|
6897
|
+
`
|
|
6898
|
+
);
|
|
6899
|
+
const manifestJsons = globSync(path9.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
|
|
6900
|
+
(file) => file.replace(config.paths.standaloneApp + "/", "")
|
|
6901
|
+
);
|
|
6902
|
+
code = code.replace(
|
|
6903
|
+
/function loadManifest\((.+?), .+?\) {/,
|
|
6783
6904
|
`$&
|
|
6784
|
-
|
|
6785
|
-
(
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
"${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
|
|
6791
|
-
},
|
|
6792
|
-
};
|
|
6793
|
-
}
|
|
6794
|
-
`
|
|
6905
|
+
${manifestJsons.map(
|
|
6906
|
+
(manifestJson) => `
|
|
6907
|
+
if ($1.endsWith("${manifestJson}")) {
|
|
6908
|
+
return ${readFileSync2(path9.join(config.paths.standaloneApp, manifestJson), "utf-8")};
|
|
6909
|
+
}
|
|
6910
|
+
`
|
|
6795
6911
|
).join("\n")}
|
|
6796
|
-
|
|
6797
|
-
|
|
6912
|
+
throw new Error("Unknown loadManifest: " + $1);
|
|
6913
|
+
`
|
|
6798
6914
|
);
|
|
6915
|
+
return code;
|
|
6799
6916
|
}
|
|
6800
6917
|
|
|
6801
|
-
// src/build/patches/
|
|
6802
|
-
|
|
6803
|
-
|
|
6918
|
+
// src/cli/build/patches/investigated/patch-require.ts
|
|
6919
|
+
function patchRequire(code) {
|
|
6920
|
+
console.log("# patchRequire");
|
|
6921
|
+
return code.replace(/__require\d?\(/g, "require(").replace(/__require\d?\./g, "require.");
|
|
6922
|
+
}
|
|
6923
|
+
|
|
6924
|
+
// src/cli/build/patches/to-investigate/wrangler-deps.ts
|
|
6925
|
+
import fs2, { writeFileSync } from "node:fs";
|
|
6926
|
+
import path10 from "node:path";
|
|
6804
6927
|
function patchWranglerDeps(config) {
|
|
6805
6928
|
console.log("# patchWranglerDeps");
|
|
6806
|
-
const
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
"next-server",
|
|
6813
|
-
"pages.runtime.prod.js"
|
|
6814
|
-
);
|
|
6815
|
-
const patchedPagesRuntime = fs.readFileSync(pagesRuntimeFile, "utf-8").replace(`e.exports=require("critters")`, `e.exports={}`);
|
|
6816
|
-
fs.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
|
|
6817
|
-
const tracerFile = path6.join(
|
|
6818
|
-
config.paths.standaloneApp,
|
|
6819
|
-
"node_modules",
|
|
6820
|
-
"next",
|
|
6821
|
-
"dist",
|
|
6822
|
-
"server",
|
|
6823
|
-
"lib",
|
|
6824
|
-
"trace",
|
|
6825
|
-
"tracer.js"
|
|
6826
|
-
);
|
|
6827
|
-
const pacthedTracer = fs.readFileSync(tracerFile, "utf-8").replaceAll(/\w+\s*=\s*require\([^/]*opentelemetry.*\)/g, `throw new Error("@opentelemetry/api")`);
|
|
6929
|
+
const distPath = getDistPath(config);
|
|
6930
|
+
const pagesRuntimeFile = path10.join(distPath, "compiled", "next-server", "pages.runtime.prod.js");
|
|
6931
|
+
const patchedPagesRuntime = fs2.readFileSync(pagesRuntimeFile, "utf-8").replace(`e.exports=require("critters")`, `e.exports={}`);
|
|
6932
|
+
fs2.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
|
|
6933
|
+
const tracerFile = path10.join(distPath, "server", "lib", "trace", "tracer.js");
|
|
6934
|
+
const pacthedTracer = fs2.readFileSync(tracerFile, "utf-8").replaceAll(/\w+\s*=\s*require\([^/]*opentelemetry.*\)/g, `throw new Error("@opentelemetry/api")`);
|
|
6828
6935
|
writeFileSync(tracerFile, pacthedTracer);
|
|
6829
6936
|
}
|
|
6937
|
+
function getDistPath(config) {
|
|
6938
|
+
for (const root of [config.paths.standaloneApp, config.paths.standaloneRoot]) {
|
|
6939
|
+
try {
|
|
6940
|
+
const distPath = path10.join(root, "node_modules", "next", "dist");
|
|
6941
|
+
if (fs2.statSync(distPath).isDirectory()) return distPath;
|
|
6942
|
+
} catch {
|
|
6943
|
+
}
|
|
6944
|
+
}
|
|
6945
|
+
throw new Error("Unexpected error: unable to detect the node_modules/next/dist directory");
|
|
6946
|
+
}
|
|
6830
6947
|
|
|
6831
|
-
// src/build/
|
|
6832
|
-
import
|
|
6833
|
-
import path7 from "node:path";
|
|
6948
|
+
// src/cli/build/build-worker.ts
|
|
6949
|
+
import path12 from "node:path";
|
|
6834
6950
|
|
|
6835
|
-
// src/build/patches/investigated/update-webpack-chunks-file/
|
|
6951
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6952
|
+
import { readFileSync as readFileSync3, readdirSync as readdirSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6953
|
+
|
|
6954
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts
|
|
6836
6955
|
import * as ts from "ts-morph";
|
|
6837
6956
|
async function getChunkInstallationIdentifiers(sourceFile) {
|
|
6838
6957
|
const installChunkDeclaration = getInstallChunkDeclaration(sourceFile);
|
|
@@ -6878,7 +6997,7 @@ function getInstalledChunksDeclaration(sourceFile, installChunkDeclaration) {
|
|
|
6878
6997
|
return installedChunksDeclaration;
|
|
6879
6998
|
}
|
|
6880
6999
|
|
|
6881
|
-
// src/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.ts
|
|
7000
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.ts
|
|
6882
7001
|
import * as ts2 from "ts-morph";
|
|
6883
7002
|
async function getFileContentWithUpdatedWebpackFRequireCode(sourceFile, { installedChunks, installChunk }, chunks) {
|
|
6884
7003
|
const webpackFRequireFunction = sourceFile.getDescendantsOfKind(ts2.SyntaxKind.ArrowFunction).find((arrowFunction) => {
|
|
@@ -6922,7 +7041,7 @@ if(${chunkId} === ${chunk}) return ${installChunk}(require("./chunks/${chunk}.js
|
|
|
6922
7041
|
return sourceFile.print();
|
|
6923
7042
|
}
|
|
6924
7043
|
|
|
6925
|
-
// src/build/utils/ts-parse-file.ts
|
|
7044
|
+
// src/cli/build/utils/ts-parse-file.ts
|
|
6926
7045
|
import * as ts3 from "ts-morph";
|
|
6927
7046
|
function tsParseFile(fileContent) {
|
|
6928
7047
|
const project = new ts3.Project();
|
|
@@ -6930,7 +7049,7 @@ function tsParseFile(fileContent) {
|
|
|
6930
7049
|
return sourceFile;
|
|
6931
7050
|
}
|
|
6932
7051
|
|
|
6933
|
-
// src/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.ts
|
|
7052
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.ts
|
|
6934
7053
|
async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
|
|
6935
7054
|
const tsSourceFile = tsParseFile(fileContent);
|
|
6936
7055
|
const chunkInstallationIdentifiers = await getChunkInstallationIdentifiers(tsSourceFile);
|
|
@@ -6942,12 +7061,13 @@ async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
|
|
|
6942
7061
|
return updatedFileContent;
|
|
6943
7062
|
}
|
|
6944
7063
|
|
|
6945
|
-
// src/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
7064
|
+
// src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
7065
|
+
import path11 from "node:path";
|
|
6946
7066
|
async function updateWebpackChunksFile(config) {
|
|
6947
7067
|
console.log("# updateWebpackChunksFile");
|
|
6948
|
-
const webpackRuntimeFile =
|
|
7068
|
+
const webpackRuntimeFile = path11.join(config.paths.standaloneAppServer, "webpack-runtime.js");
|
|
6949
7069
|
const fileContent = readFileSync3(webpackRuntimeFile, "utf-8");
|
|
6950
|
-
const chunks =
|
|
7070
|
+
const chunks = readdirSync3(path11.join(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
|
|
6951
7071
|
console.log(` - chunk ${chunk}`);
|
|
6952
7072
|
return chunk.replace(/\.js$/, "");
|
|
6953
7073
|
});
|
|
@@ -6955,47 +7075,29 @@ async function updateWebpackChunksFile(config) {
|
|
|
6955
7075
|
writeFileSync2(webpackRuntimeFile, updatedFileContent);
|
|
6956
7076
|
}
|
|
6957
7077
|
|
|
6958
|
-
// src/build/
|
|
6959
|
-
|
|
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
|
-
|
|
6976
|
-
// src/build/build-worker.ts
|
|
6977
|
-
var packageDir = path9.dirname(fileURLToPath3(import.meta.url));
|
|
7078
|
+
// src/cli/build/build-worker.ts
|
|
7079
|
+
var packageDistDir = path12.join(path12.dirname(fileURLToPath3(import.meta.url)), "..");
|
|
6978
7080
|
async function buildWorker(config) {
|
|
6979
7081
|
console.log(`\x1B[35m\u2699\uFE0F Copying files...
|
|
6980
7082
|
\x1B[0m`);
|
|
6981
7083
|
await cp(
|
|
6982
|
-
|
|
6983
|
-
|
|
7084
|
+
path12.join(config.paths.dotNext, "static"),
|
|
7085
|
+
path12.join(config.paths.builderOutput, "assets", "_next", "static"),
|
|
6984
7086
|
{
|
|
6985
7087
|
recursive: true
|
|
6986
7088
|
}
|
|
6987
7089
|
);
|
|
6988
|
-
const publicDir =
|
|
7090
|
+
const publicDir = path12.join(config.paths.nextApp, "public");
|
|
6989
7091
|
if (existsSync3(publicDir)) {
|
|
6990
|
-
await cp(publicDir,
|
|
7092
|
+
await cp(publicDir, path12.join(config.paths.builderOutput, "assets"), {
|
|
6991
7093
|
recursive: true
|
|
6992
7094
|
});
|
|
6993
7095
|
}
|
|
6994
|
-
|
|
6995
|
-
const templateDir =
|
|
6996
|
-
const workerEntrypoint =
|
|
6997
|
-
const workerOutputFile =
|
|
6998
|
-
const nextConfigStr = readFileSync4(
|
|
7096
|
+
copyPackageCliFiles(packageDistDir, config);
|
|
7097
|
+
const templateDir = path12.join(config.paths.internalPackage, "cli", "templates");
|
|
7098
|
+
const workerEntrypoint = path12.join(templateDir, "worker.ts");
|
|
7099
|
+
const workerOutputFile = path12.join(config.paths.builderOutput, "index.mjs");
|
|
7100
|
+
const nextConfigStr = readFileSync4(path12.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
|
|
6999
7101
|
/const nextConfig = ({.+?})\n/
|
|
7000
7102
|
)?.[1] ?? {};
|
|
7001
7103
|
console.log(`\x1B[35m\u2699\uFE0F Bundling the worker file...
|
|
@@ -7014,15 +7116,15 @@ async function buildWorker(config) {
|
|
|
7014
7116
|
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
|
|
7015
7117
|
// eval("require")("bufferutil");
|
|
7016
7118
|
// eval("require")("utf-8-validate");
|
|
7017
|
-
"next/dist/compiled/ws":
|
|
7119
|
+
"next/dist/compiled/ws": path12.join(templateDir, "shims", "empty.ts"),
|
|
7018
7120
|
// Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
|
|
7019
7121
|
// eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
|
|
7020
7122
|
// which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
|
|
7021
7123
|
// QUESTION: Why did I encountered this but mhart didn't?
|
|
7022
|
-
"next/dist/compiled/edge-runtime":
|
|
7124
|
+
"next/dist/compiled/edge-runtime": path12.join(templateDir, "shims", "empty.ts"),
|
|
7023
7125
|
// `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
|
|
7024
7126
|
// source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
|
|
7025
|
-
"@next/env":
|
|
7127
|
+
"@next/env": path12.join(templateDir, "shims", "env.ts")
|
|
7026
7128
|
},
|
|
7027
7129
|
define: {
|
|
7028
7130
|
// config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139
|
|
@@ -7101,103 +7203,88 @@ function createFixRequiresESBuildPlugin(templateDir) {
|
|
|
7101
7203
|
return {
|
|
7102
7204
|
name: "replaceRelative",
|
|
7103
7205
|
setup(build3) {
|
|
7104
|
-
build3.onResolve({ filter: /^\.\/require-hook$/ }, (
|
|
7105
|
-
path:
|
|
7206
|
+
build3.onResolve({ filter: /^\.\/require-hook$/ }, () => ({
|
|
7207
|
+
path: path12.join(templateDir, "shims", "empty.ts")
|
|
7106
7208
|
}));
|
|
7107
|
-
build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, (
|
|
7108
|
-
path:
|
|
7209
|
+
build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, () => ({
|
|
7210
|
+
path: path12.join(templateDir, "shims", "empty.ts")
|
|
7109
7211
|
}));
|
|
7110
7212
|
}
|
|
7111
7213
|
};
|
|
7112
7214
|
}
|
|
7113
7215
|
|
|
7114
|
-
// src/
|
|
7115
|
-
import {
|
|
7116
|
-
import
|
|
7117
|
-
|
|
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("/"));
|
|
7131
|
-
return {
|
|
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
|
|
7145
|
-
};
|
|
7146
|
-
}
|
|
7147
|
-
function containsDotNextDir(folder) {
|
|
7148
|
-
try {
|
|
7149
|
-
return statSync2(path10.join(folder, ".next")).isDirectory();
|
|
7150
|
-
} catch (e) {
|
|
7151
|
-
return false;
|
|
7152
|
-
}
|
|
7153
|
-
}
|
|
7154
|
-
function getNextjsApplicationPath(dotNextDir) {
|
|
7155
|
-
const serverPath = findServerParentPath(dotNextDir);
|
|
7156
|
-
if (!serverPath) {
|
|
7157
|
-
throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
|
|
7158
|
-
}
|
|
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;
|
|
7165
|
-
}
|
|
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;
|
|
7175
|
-
}
|
|
7176
|
-
}
|
|
7177
|
-
}
|
|
7178
|
-
}
|
|
7179
|
-
|
|
7180
|
-
// src/build/build.ts
|
|
7181
|
-
import { cpSync as cpSync3 } from "node:fs";
|
|
7182
|
-
import path11 from "node:path";
|
|
7216
|
+
// src/cli/build/index.ts
|
|
7217
|
+
import { cpSync as cpSync2 } from "node:fs";
|
|
7218
|
+
import path13 from "node:path";
|
|
7219
|
+
import { rm } from "node:fs/promises";
|
|
7183
7220
|
async function build2(appDir, opts) {
|
|
7184
7221
|
if (!opts.skipBuild) {
|
|
7185
|
-
buildNextjsApp(appDir);
|
|
7222
|
+
await buildNextjsApp(appDir);
|
|
7186
7223
|
}
|
|
7187
7224
|
if (!containsDotNextDir(appDir)) {
|
|
7188
7225
|
throw new Error(`.next folder not found in ${appDir}`);
|
|
7189
7226
|
}
|
|
7190
|
-
const outputDir2 =
|
|
7227
|
+
const outputDir2 = path13.resolve(opts.outputDir ?? appDir, ".worker-next");
|
|
7191
7228
|
await cleanDirectory(outputDir2);
|
|
7192
|
-
|
|
7229
|
+
cpSync2(path13.join(appDir, ".next"), path13.join(outputDir2, ".next"), { recursive: true });
|
|
7193
7230
|
const config = getConfig(appDir, outputDir2);
|
|
7194
7231
|
await buildWorker(config);
|
|
7195
7232
|
}
|
|
7196
|
-
async function cleanDirectory(
|
|
7197
|
-
return await rm(
|
|
7233
|
+
async function cleanDirectory(path14) {
|
|
7234
|
+
return await rm(path14, { recursive: true, force: true });
|
|
7198
7235
|
}
|
|
7199
7236
|
|
|
7200
|
-
// src/index.ts
|
|
7237
|
+
// src/cli/index.ts
|
|
7238
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
7239
|
+
|
|
7240
|
+
// src/cli/args.ts
|
|
7241
|
+
import { mkdirSync, statSync as statSync2 } from "node:fs";
|
|
7242
|
+
import { parseArgs } from "node:util";
|
|
7243
|
+
import { resolve } from "node:path";
|
|
7244
|
+
function getArgs() {
|
|
7245
|
+
const {
|
|
7246
|
+
values: { skipBuild: skipBuild2, output }
|
|
7247
|
+
} = parseArgs({
|
|
7248
|
+
options: {
|
|
7249
|
+
skipBuild: {
|
|
7250
|
+
type: "boolean",
|
|
7251
|
+
short: "s",
|
|
7252
|
+
default: false
|
|
7253
|
+
},
|
|
7254
|
+
output: {
|
|
7255
|
+
type: "string",
|
|
7256
|
+
short: "o"
|
|
7257
|
+
}
|
|
7258
|
+
},
|
|
7259
|
+
allowPositionals: false
|
|
7260
|
+
});
|
|
7261
|
+
const outputDir2 = output ? resolve(output) : void 0;
|
|
7262
|
+
if (outputDir2) {
|
|
7263
|
+
assertDirArg(outputDir2, "output", true);
|
|
7264
|
+
}
|
|
7265
|
+
return {
|
|
7266
|
+
outputDir: outputDir2,
|
|
7267
|
+
skipBuild: skipBuild2 || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD))
|
|
7268
|
+
};
|
|
7269
|
+
}
|
|
7270
|
+
function assertDirArg(path14, argName, make) {
|
|
7271
|
+
let dirStats;
|
|
7272
|
+
try {
|
|
7273
|
+
dirStats = statSync2(path14);
|
|
7274
|
+
} catch {
|
|
7275
|
+
if (!make) {
|
|
7276
|
+
throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
|
|
7277
|
+
}
|
|
7278
|
+
mkdirSync(path14);
|
|
7279
|
+
return;
|
|
7280
|
+
}
|
|
7281
|
+
if (!dirStats.isDirectory()) {
|
|
7282
|
+
throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a directory`);
|
|
7283
|
+
}
|
|
7284
|
+
}
|
|
7285
|
+
|
|
7286
|
+
// src/cli/index.ts
|
|
7287
|
+
import { resolve as resolve2 } from "node:path";
|
|
7201
7288
|
var nextAppDir = resolve2(".");
|
|
7202
7289
|
console.log(`Building the Next.js app in the current folder (${nextAppDir})`);
|
|
7203
7290
|
if (!["js", "cjs", "mjs", "ts"].some((ext2) => existsSync4(`./next.config.${ext2}`))) {
|