@opennextjs/cloudflare 0.0.0-28d3ca1 → 0.0.0-361f2b7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.mjs +188 -98
- package/package.json +2 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -279,13 +279,103 @@ function findServerParentPath(parentPath) {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
// ../../node_modules/.pnpm/package-manager-detector@0.2.0/node_modules/package-manager-detector/dist/constants.mjs
|
|
283
|
+
var AGENTS = [
|
|
284
|
+
"npm",
|
|
285
|
+
"yarn",
|
|
286
|
+
"yarn@berry",
|
|
287
|
+
"pnpm",
|
|
288
|
+
"pnpm@6",
|
|
289
|
+
"bun"
|
|
290
|
+
];
|
|
291
|
+
var LOCKS = {
|
|
292
|
+
"bun.lockb": "bun",
|
|
293
|
+
"pnpm-lock.yaml": "pnpm",
|
|
294
|
+
"yarn.lock": "yarn",
|
|
295
|
+
"package-lock.json": "npm",
|
|
296
|
+
"npm-shrinkwrap.json": "npm"
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// ../../node_modules/.pnpm/package-manager-detector@0.2.0/node_modules/package-manager-detector/dist/detect.mjs
|
|
300
|
+
import fs from "node:fs";
|
|
301
|
+
import fsPromises from "node:fs/promises";
|
|
302
|
+
import path2 from "node:path";
|
|
303
|
+
import process2 from "node:process";
|
|
304
|
+
async function detect({ cwd, onUnknown } = {}) {
|
|
305
|
+
for (const directory of lookup(cwd)) {
|
|
306
|
+
for (const lock of Object.keys(LOCKS)) {
|
|
307
|
+
if (await fileExists(path2.join(directory, lock))) {
|
|
308
|
+
const name = LOCKS[lock];
|
|
309
|
+
const result2 = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
|
|
310
|
+
if (result2)
|
|
311
|
+
return result2;
|
|
312
|
+
else
|
|
313
|
+
return { name, agent: name };
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
|
|
317
|
+
if (result)
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function* lookup(cwd = process2.cwd()) {
|
|
323
|
+
let directory = path2.resolve(cwd);
|
|
324
|
+
const { root } = path2.parse(directory);
|
|
325
|
+
while (directory && directory !== root) {
|
|
326
|
+
yield directory;
|
|
327
|
+
directory = path2.dirname(directory);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async function parsePackageJson(filepath, onUnknown) {
|
|
331
|
+
if (!filepath || !await fileExists(filepath))
|
|
332
|
+
return null;
|
|
333
|
+
try {
|
|
334
|
+
const pkg = JSON.parse(fs.readFileSync(filepath, "utf8"));
|
|
335
|
+
let agent;
|
|
336
|
+
if (typeof pkg.packageManager === "string") {
|
|
337
|
+
const [name, ver] = pkg.packageManager.replace(/^\^/, "").split("@");
|
|
338
|
+
let version = ver;
|
|
339
|
+
if (name === "yarn" && Number.parseInt(ver) > 1) {
|
|
340
|
+
agent = "yarn@berry";
|
|
341
|
+
version = "berry";
|
|
342
|
+
return { name, agent, version };
|
|
343
|
+
} else if (name === "pnpm" && Number.parseInt(ver) < 7) {
|
|
344
|
+
agent = "pnpm@6";
|
|
345
|
+
return { name, agent, version };
|
|
346
|
+
} else if (AGENTS.includes(name)) {
|
|
347
|
+
agent = name;
|
|
348
|
+
return { name, agent, version };
|
|
349
|
+
} else {
|
|
350
|
+
return onUnknown?.(pkg.packageManager) ?? null;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
} catch {
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
async function fileExists(filePath) {
|
|
358
|
+
try {
|
|
359
|
+
const stats = await fsPromises.stat(filePath);
|
|
360
|
+
if (stats.isFile()) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
} catch {
|
|
364
|
+
}
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
|
|
282
368
|
// src/cli/build/build-next-app.ts
|
|
283
369
|
import { execSync } from "node:child_process";
|
|
284
|
-
function buildNextjsApp(nextAppDir2) {
|
|
285
|
-
|
|
370
|
+
async function buildNextjsApp(nextAppDir2) {
|
|
371
|
+
const pm = await detect();
|
|
372
|
+
if (!pm) {
|
|
373
|
+
throw new Error("Fatal Error: package manager detection failed, aborting");
|
|
374
|
+
}
|
|
375
|
+
runNextBuildCommand(pm.name, nextAppDir2);
|
|
286
376
|
}
|
|
287
377
|
function runNextBuildCommand(packager, nextAppDir2) {
|
|
288
|
-
const command =
|
|
378
|
+
const command = `${packager === "npm" ? "npx" : packager} next build`;
|
|
289
379
|
execSync(command, {
|
|
290
380
|
stdio: "inherit",
|
|
291
381
|
cwd: nextAppDir2,
|
|
@@ -305,11 +395,11 @@ import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:f
|
|
|
305
395
|
|
|
306
396
|
// src/cli/build/patches/investigated/copy-package-cli-files.ts
|
|
307
397
|
import { cpSync } from "node:fs";
|
|
308
|
-
import
|
|
398
|
+
import path3 from "node:path";
|
|
309
399
|
function copyPackageCliFiles(packageDistDir2, config) {
|
|
310
400
|
console.log("# copyPackageTemplateFiles");
|
|
311
|
-
const sourceDir =
|
|
312
|
-
const destinationDir =
|
|
401
|
+
const sourceDir = path3.join(packageDistDir2, "cli");
|
|
402
|
+
const destinationDir = path3.join(config.paths.internalPackage, "cli");
|
|
313
403
|
cpSync(sourceDir, destinationDir, { recursive: true });
|
|
314
404
|
}
|
|
315
405
|
|
|
@@ -987,11 +1077,11 @@ var qmarksTestNoExtDot = ([$0]) => {
|
|
|
987
1077
|
return (f) => f.length === len && f !== "." && f !== "..";
|
|
988
1078
|
};
|
|
989
1079
|
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
990
|
-
var
|
|
1080
|
+
var path4 = {
|
|
991
1081
|
win32: { sep: "\\" },
|
|
992
1082
|
posix: { sep: "/" }
|
|
993
1083
|
};
|
|
994
|
-
var sep = defaultPlatform === "win32" ?
|
|
1084
|
+
var sep = defaultPlatform === "win32" ? path4.win32.sep : path4.posix.sep;
|
|
995
1085
|
minimatch.sep = sep;
|
|
996
1086
|
var GLOBSTAR = Symbol("globstar **");
|
|
997
1087
|
minimatch.GLOBSTAR = GLOBSTAR;
|
|
@@ -4168,12 +4258,12 @@ var PathBase = class {
|
|
|
4168
4258
|
/**
|
|
4169
4259
|
* Get the Path object referenced by the string path, resolved from this Path
|
|
4170
4260
|
*/
|
|
4171
|
-
resolve(
|
|
4172
|
-
if (!
|
|
4261
|
+
resolve(path14) {
|
|
4262
|
+
if (!path14) {
|
|
4173
4263
|
return this;
|
|
4174
4264
|
}
|
|
4175
|
-
const rootPath = this.getRootString(
|
|
4176
|
-
const dir =
|
|
4265
|
+
const rootPath = this.getRootString(path14);
|
|
4266
|
+
const dir = path14.substring(rootPath.length);
|
|
4177
4267
|
const dirParts = dir.split(this.splitSep);
|
|
4178
4268
|
const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
|
|
4179
4269
|
return result;
|
|
@@ -4925,8 +5015,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
|
|
|
4925
5015
|
/**
|
|
4926
5016
|
* @internal
|
|
4927
5017
|
*/
|
|
4928
|
-
getRootString(
|
|
4929
|
-
return win32.parse(
|
|
5018
|
+
getRootString(path14) {
|
|
5019
|
+
return win32.parse(path14).root;
|
|
4930
5020
|
}
|
|
4931
5021
|
/**
|
|
4932
5022
|
* @internal
|
|
@@ -4972,8 +5062,8 @@ var PathPosix = class _PathPosix extends PathBase {
|
|
|
4972
5062
|
/**
|
|
4973
5063
|
* @internal
|
|
4974
5064
|
*/
|
|
4975
|
-
getRootString(
|
|
4976
|
-
return
|
|
5065
|
+
getRootString(path14) {
|
|
5066
|
+
return path14.startsWith("/") ? "/" : "";
|
|
4977
5067
|
}
|
|
4978
5068
|
/**
|
|
4979
5069
|
* @internal
|
|
@@ -5022,8 +5112,8 @@ var PathScurryBase = class {
|
|
|
5022
5112
|
*
|
|
5023
5113
|
* @internal
|
|
5024
5114
|
*/
|
|
5025
|
-
constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs:
|
|
5026
|
-
this.#fs = fsFromOption(
|
|
5115
|
+
constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs: fs3 = defaultFS } = {}) {
|
|
5116
|
+
this.#fs = fsFromOption(fs3);
|
|
5027
5117
|
if (cwd instanceof URL || cwd.startsWith("file://")) {
|
|
5028
5118
|
cwd = fileURLToPath(cwd);
|
|
5029
5119
|
}
|
|
@@ -5062,11 +5152,11 @@ var PathScurryBase = class {
|
|
|
5062
5152
|
/**
|
|
5063
5153
|
* Get the depth of a provided path, string, or the cwd
|
|
5064
5154
|
*/
|
|
5065
|
-
depth(
|
|
5066
|
-
if (typeof
|
|
5067
|
-
|
|
5155
|
+
depth(path14 = this.cwd) {
|
|
5156
|
+
if (typeof path14 === "string") {
|
|
5157
|
+
path14 = this.cwd.resolve(path14);
|
|
5068
5158
|
}
|
|
5069
|
-
return
|
|
5159
|
+
return path14.depth();
|
|
5070
5160
|
}
|
|
5071
5161
|
/**
|
|
5072
5162
|
* Return the cache of child entries. Exposed so subclasses can create
|
|
@@ -5445,7 +5535,7 @@ var PathScurryBase = class {
|
|
|
5445
5535
|
const dirs = /* @__PURE__ */ new Set();
|
|
5446
5536
|
const queue = [entry];
|
|
5447
5537
|
let processing = 0;
|
|
5448
|
-
const
|
|
5538
|
+
const process3 = () => {
|
|
5449
5539
|
let paused = false;
|
|
5450
5540
|
while (!paused) {
|
|
5451
5541
|
const dir = queue.shift();
|
|
@@ -5486,9 +5576,9 @@ var PathScurryBase = class {
|
|
|
5486
5576
|
}
|
|
5487
5577
|
}
|
|
5488
5578
|
if (paused && !results.flowing) {
|
|
5489
|
-
results.once("drain",
|
|
5579
|
+
results.once("drain", process3);
|
|
5490
5580
|
} else if (!sync2) {
|
|
5491
|
-
|
|
5581
|
+
process3();
|
|
5492
5582
|
}
|
|
5493
5583
|
};
|
|
5494
5584
|
let sync2 = true;
|
|
@@ -5496,7 +5586,7 @@ var PathScurryBase = class {
|
|
|
5496
5586
|
sync2 = false;
|
|
5497
5587
|
}
|
|
5498
5588
|
};
|
|
5499
|
-
|
|
5589
|
+
process3();
|
|
5500
5590
|
return results;
|
|
5501
5591
|
}
|
|
5502
5592
|
streamSync(entry = this.cwd, opts = {}) {
|
|
@@ -5514,7 +5604,7 @@ var PathScurryBase = class {
|
|
|
5514
5604
|
}
|
|
5515
5605
|
const queue = [entry];
|
|
5516
5606
|
let processing = 0;
|
|
5517
|
-
const
|
|
5607
|
+
const process3 = () => {
|
|
5518
5608
|
let paused = false;
|
|
5519
5609
|
while (!paused) {
|
|
5520
5610
|
const dir = queue.shift();
|
|
@@ -5548,14 +5638,14 @@ var PathScurryBase = class {
|
|
|
5548
5638
|
}
|
|
5549
5639
|
}
|
|
5550
5640
|
if (paused && !results.flowing)
|
|
5551
|
-
results.once("drain",
|
|
5641
|
+
results.once("drain", process3);
|
|
5552
5642
|
};
|
|
5553
|
-
|
|
5643
|
+
process3();
|
|
5554
5644
|
return results;
|
|
5555
5645
|
}
|
|
5556
|
-
chdir(
|
|
5646
|
+
chdir(path14 = this.cwd) {
|
|
5557
5647
|
const oldCwd = this.cwd;
|
|
5558
|
-
this.cwd = typeof
|
|
5648
|
+
this.cwd = typeof path14 === "string" ? this.cwd.resolve(path14) : path14;
|
|
5559
5649
|
this.cwd[setAsCwd](oldCwd);
|
|
5560
5650
|
}
|
|
5561
5651
|
};
|
|
@@ -5581,8 +5671,8 @@ var PathScurryWin32 = class extends PathScurryBase {
|
|
|
5581
5671
|
/**
|
|
5582
5672
|
* @internal
|
|
5583
5673
|
*/
|
|
5584
|
-
newRoot(
|
|
5585
|
-
return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
5674
|
+
newRoot(fs3) {
|
|
5675
|
+
return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs3 });
|
|
5586
5676
|
}
|
|
5587
5677
|
/**
|
|
5588
5678
|
* Return true if the provided path string is an absolute path
|
|
@@ -5610,8 +5700,8 @@ var PathScurryPosix = class extends PathScurryBase {
|
|
|
5610
5700
|
/**
|
|
5611
5701
|
* @internal
|
|
5612
5702
|
*/
|
|
5613
|
-
newRoot(
|
|
5614
|
-
return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
5703
|
+
newRoot(fs3) {
|
|
5704
|
+
return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs3 });
|
|
5615
5705
|
}
|
|
5616
5706
|
/**
|
|
5617
5707
|
* Return true if the provided path string is an absolute path
|
|
@@ -5911,8 +6001,8 @@ var MatchRecord = class {
|
|
|
5911
6001
|
}
|
|
5912
6002
|
// match, absolute, ifdir
|
|
5913
6003
|
entries() {
|
|
5914
|
-
return [...this.store.entries()].map(([
|
|
5915
|
-
|
|
6004
|
+
return [...this.store.entries()].map(([path14, n]) => [
|
|
6005
|
+
path14,
|
|
5916
6006
|
!!(n & 2),
|
|
5917
6007
|
!!(n & 1)
|
|
5918
6008
|
]);
|
|
@@ -6117,9 +6207,9 @@ var GlobUtil = class {
|
|
|
6117
6207
|
signal;
|
|
6118
6208
|
maxDepth;
|
|
6119
6209
|
includeChildMatches;
|
|
6120
|
-
constructor(patterns,
|
|
6210
|
+
constructor(patterns, path14, opts) {
|
|
6121
6211
|
this.patterns = patterns;
|
|
6122
|
-
this.path =
|
|
6212
|
+
this.path = path14;
|
|
6123
6213
|
this.opts = opts;
|
|
6124
6214
|
this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
|
|
6125
6215
|
this.includeChildMatches = opts.includeChildMatches !== false;
|
|
@@ -6138,11 +6228,11 @@ var GlobUtil = class {
|
|
|
6138
6228
|
});
|
|
6139
6229
|
}
|
|
6140
6230
|
}
|
|
6141
|
-
#ignored(
|
|
6142
|
-
return this.seen.has(
|
|
6231
|
+
#ignored(path14) {
|
|
6232
|
+
return this.seen.has(path14) || !!this.#ignore?.ignored?.(path14);
|
|
6143
6233
|
}
|
|
6144
|
-
#childrenIgnored(
|
|
6145
|
-
return !!this.#ignore?.childrenIgnored?.(
|
|
6234
|
+
#childrenIgnored(path14) {
|
|
6235
|
+
return !!this.#ignore?.childrenIgnored?.(path14);
|
|
6146
6236
|
}
|
|
6147
6237
|
// backpressure mechanism
|
|
6148
6238
|
pause() {
|
|
@@ -6357,8 +6447,8 @@ var GlobUtil = class {
|
|
|
6357
6447
|
};
|
|
6358
6448
|
var GlobWalker = class extends GlobUtil {
|
|
6359
6449
|
matches = /* @__PURE__ */ new Set();
|
|
6360
|
-
constructor(patterns,
|
|
6361
|
-
super(patterns,
|
|
6450
|
+
constructor(patterns, path14, opts) {
|
|
6451
|
+
super(patterns, path14, opts);
|
|
6362
6452
|
}
|
|
6363
6453
|
matchEmit(e) {
|
|
6364
6454
|
this.matches.add(e);
|
|
@@ -6395,8 +6485,8 @@ var GlobWalker = class extends GlobUtil {
|
|
|
6395
6485
|
};
|
|
6396
6486
|
var GlobStream = class extends GlobUtil {
|
|
6397
6487
|
results;
|
|
6398
|
-
constructor(patterns,
|
|
6399
|
-
super(patterns,
|
|
6488
|
+
constructor(patterns, path14, opts) {
|
|
6489
|
+
super(patterns, path14, opts);
|
|
6400
6490
|
this.results = new Minipass({
|
|
6401
6491
|
signal: this.signal,
|
|
6402
6492
|
objectMode: true
|
|
@@ -6690,11 +6780,11 @@ var glob = Object.assign(glob_, {
|
|
|
6690
6780
|
glob.glob = glob;
|
|
6691
6781
|
|
|
6692
6782
|
// src/cli/build/patches/to-investigate/inline-eval-manifest.ts
|
|
6693
|
-
import
|
|
6783
|
+
import path5 from "node:path";
|
|
6694
6784
|
function inlineEvalManifest(code, config) {
|
|
6695
6785
|
console.log("# inlineEvalManifest");
|
|
6696
6786
|
const manifestJss = globSync(
|
|
6697
|
-
|
|
6787
|
+
path5.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
|
|
6698
6788
|
).map((file) => file.replace(`${config.paths.standaloneApp}/`, ""));
|
|
6699
6789
|
return code.replace(
|
|
6700
6790
|
/function evalManifest\((.+?), .+?\) {/,
|
|
@@ -6702,7 +6792,7 @@ function inlineEvalManifest(code, config) {
|
|
|
6702
6792
|
${manifestJss.map(
|
|
6703
6793
|
(manifestJs) => `
|
|
6704
6794
|
if ($1.endsWith("${manifestJs}")) {
|
|
6705
|
-
require("${
|
|
6795
|
+
require("${path5.join(config.paths.standaloneApp, manifestJs)}");
|
|
6706
6796
|
return {
|
|
6707
6797
|
__RSC_MANIFEST: {
|
|
6708
6798
|
"${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
|
|
@@ -6718,11 +6808,11 @@ function inlineEvalManifest(code, config) {
|
|
|
6718
6808
|
|
|
6719
6809
|
// src/cli/build/patches/to-investigate/inline-next-require.ts
|
|
6720
6810
|
import { existsSync, readFileSync } from "node:fs";
|
|
6721
|
-
import
|
|
6811
|
+
import path6 from "node:path";
|
|
6722
6812
|
function inlineNextRequire(code, config) {
|
|
6723
6813
|
console.log("# inlineNextRequire");
|
|
6724
|
-
const pagesManifestFile =
|
|
6725
|
-
const appPathsManifestFile =
|
|
6814
|
+
const pagesManifestFile = path6.join(config.paths.standaloneAppServer, "pages-manifest.json");
|
|
6815
|
+
const appPathsManifestFile = path6.join(config.paths.standaloneAppServer, "app-paths-manifest.json");
|
|
6726
6816
|
const pagesManifestFiles = existsSync(pagesManifestFile) ? Object.values(JSON.parse(readFileSync(pagesManifestFile, "utf-8"))).map(
|
|
6727
6817
|
(file) => ".next/server/" + file
|
|
6728
6818
|
) : [];
|
|
@@ -6738,14 +6828,14 @@ function inlineNextRequire(code, config) {
|
|
|
6738
6828
|
${htmlPages.map(
|
|
6739
6829
|
(htmlPage) => `
|
|
6740
6830
|
if (pagePath.endsWith("${htmlPage}")) {
|
|
6741
|
-
return ${JSON.stringify(readFileSync(
|
|
6831
|
+
return ${JSON.stringify(readFileSync(path6.join(config.paths.standaloneApp, htmlPage), "utf-8"))};
|
|
6742
6832
|
}
|
|
6743
6833
|
`
|
|
6744
6834
|
).join("\n")}
|
|
6745
6835
|
${pageModules.map(
|
|
6746
6836
|
(module) => `
|
|
6747
6837
|
if (pagePath.endsWith("${module}")) {
|
|
6748
|
-
return require("${
|
|
6838
|
+
return require("${path6.join(config.paths.standaloneApp, module)}");
|
|
6749
6839
|
}
|
|
6750
6840
|
`
|
|
6751
6841
|
).join("\n")}
|
|
@@ -6755,10 +6845,10 @@ function inlineNextRequire(code, config) {
|
|
|
6755
6845
|
}
|
|
6756
6846
|
|
|
6757
6847
|
// src/cli/build/patches/investigated/patch-cache.ts
|
|
6758
|
-
import
|
|
6848
|
+
import path7 from "node:path";
|
|
6759
6849
|
function patchCache(code, config) {
|
|
6760
6850
|
console.log("# patchCached");
|
|
6761
|
-
const cacheHandler =
|
|
6851
|
+
const cacheHandler = path7.join(config.paths.internalPackage, "cli", "cache-handler.mjs");
|
|
6762
6852
|
const patchedCode = code.replace(
|
|
6763
6853
|
"const { cacheHandler } = this.nextConfig;",
|
|
6764
6854
|
`const cacheHandler = null;
|
|
@@ -6774,7 +6864,7 @@ CacheHandler.maybeKVNamespace = process.env["${config.cache.kvBindingName}"];
|
|
|
6774
6864
|
|
|
6775
6865
|
// src/cli/build/patches/to-investigate/patch-find-dir.ts
|
|
6776
6866
|
import { existsSync as existsSync2 } from "node:fs";
|
|
6777
|
-
import
|
|
6867
|
+
import path8 from "node:path";
|
|
6778
6868
|
function patchFindDir(code, config) {
|
|
6779
6869
|
console.log("# patchFindDir");
|
|
6780
6870
|
return code.replace(
|
|
@@ -6782,10 +6872,10 @@ function patchFindDir(code, config) {
|
|
|
6782
6872
|
`function findDir(dir, name) {
|
|
6783
6873
|
if (dir.endsWith(".next/server")) {
|
|
6784
6874
|
if (name === "app") {
|
|
6785
|
-
return ${existsSync2(`${
|
|
6875
|
+
return ${existsSync2(`${path8.join(config.paths.standaloneAppServer, "app")}`)};
|
|
6786
6876
|
}
|
|
6787
6877
|
if (name === "pages") {
|
|
6788
|
-
return ${existsSync2(`${
|
|
6878
|
+
return ${existsSync2(`${path8.join(config.paths.standaloneAppServer, "pages")}`)};
|
|
6789
6879
|
}
|
|
6790
6880
|
}
|
|
6791
6881
|
throw new Error("Unknown findDir call: " + dir + " " + name);
|
|
@@ -6794,17 +6884,17 @@ function patchFindDir(code, config) {
|
|
|
6794
6884
|
}
|
|
6795
6885
|
|
|
6796
6886
|
// src/cli/build/patches/to-investigate/patch-read-file.ts
|
|
6797
|
-
import
|
|
6887
|
+
import path9 from "node:path";
|
|
6798
6888
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
6799
6889
|
function patchReadFile(code, config) {
|
|
6800
6890
|
console.log("# patchReadFile");
|
|
6801
6891
|
code = code.replace(
|
|
6802
6892
|
"getBuildId() {",
|
|
6803
6893
|
`getBuildId() {
|
|
6804
|
-
return ${JSON.stringify(readFileSync2(
|
|
6894
|
+
return ${JSON.stringify(readFileSync2(path9.join(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
|
|
6805
6895
|
`
|
|
6806
6896
|
);
|
|
6807
|
-
const manifestJsons = globSync(
|
|
6897
|
+
const manifestJsons = globSync(path9.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
|
|
6808
6898
|
(file) => file.replace(config.paths.standaloneApp + "/", "")
|
|
6809
6899
|
);
|
|
6810
6900
|
code = code.replace(
|
|
@@ -6813,7 +6903,7 @@ function patchReadFile(code, config) {
|
|
|
6813
6903
|
${manifestJsons.map(
|
|
6814
6904
|
(manifestJson) => `
|
|
6815
6905
|
if ($1.endsWith("${manifestJson}")) {
|
|
6816
|
-
return ${readFileSync2(
|
|
6906
|
+
return ${readFileSync2(path9.join(config.paths.standaloneApp, manifestJson), "utf-8")};
|
|
6817
6907
|
}
|
|
6818
6908
|
`
|
|
6819
6909
|
).join("\n")}
|
|
@@ -6830,11 +6920,11 @@ function patchRequire(code) {
|
|
|
6830
6920
|
}
|
|
6831
6921
|
|
|
6832
6922
|
// src/cli/build/patches/to-investigate/wrangler-deps.ts
|
|
6833
|
-
import
|
|
6834
|
-
import
|
|
6923
|
+
import fs2, { writeFileSync } from "node:fs";
|
|
6924
|
+
import path10 from "node:path";
|
|
6835
6925
|
function patchWranglerDeps(config) {
|
|
6836
6926
|
console.log("# patchWranglerDeps");
|
|
6837
|
-
const pagesRuntimeFile =
|
|
6927
|
+
const pagesRuntimeFile = path10.join(
|
|
6838
6928
|
config.paths.standaloneApp,
|
|
6839
6929
|
"node_modules",
|
|
6840
6930
|
"next",
|
|
@@ -6843,9 +6933,9 @@ function patchWranglerDeps(config) {
|
|
|
6843
6933
|
"next-server",
|
|
6844
6934
|
"pages.runtime.prod.js"
|
|
6845
6935
|
);
|
|
6846
|
-
const patchedPagesRuntime =
|
|
6847
|
-
|
|
6848
|
-
const tracerFile =
|
|
6936
|
+
const patchedPagesRuntime = fs2.readFileSync(pagesRuntimeFile, "utf-8").replace(`e.exports=require("critters")`, `e.exports={}`);
|
|
6937
|
+
fs2.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
|
|
6938
|
+
const tracerFile = path10.join(
|
|
6849
6939
|
config.paths.standaloneApp,
|
|
6850
6940
|
"node_modules",
|
|
6851
6941
|
"next",
|
|
@@ -6855,12 +6945,12 @@ function patchWranglerDeps(config) {
|
|
|
6855
6945
|
"trace",
|
|
6856
6946
|
"tracer.js"
|
|
6857
6947
|
);
|
|
6858
|
-
const pacthedTracer =
|
|
6948
|
+
const pacthedTracer = fs2.readFileSync(tracerFile, "utf-8").replaceAll(/\w+\s*=\s*require\([^/]*opentelemetry.*\)/g, `throw new Error("@opentelemetry/api")`);
|
|
6859
6949
|
writeFileSync(tracerFile, pacthedTracer);
|
|
6860
6950
|
}
|
|
6861
6951
|
|
|
6862
6952
|
// src/cli/build/build-worker.ts
|
|
6863
|
-
import
|
|
6953
|
+
import path12 from "node:path";
|
|
6864
6954
|
|
|
6865
6955
|
// src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6866
6956
|
import { readFileSync as readFileSync3, readdirSync as readdirSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
@@ -6976,12 +7066,12 @@ async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
|
|
|
6976
7066
|
}
|
|
6977
7067
|
|
|
6978
7068
|
// src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
|
|
6979
|
-
import
|
|
7069
|
+
import path11 from "node:path";
|
|
6980
7070
|
async function updateWebpackChunksFile(config) {
|
|
6981
7071
|
console.log("# updateWebpackChunksFile");
|
|
6982
|
-
const webpackRuntimeFile =
|
|
7072
|
+
const webpackRuntimeFile = path11.join(config.paths.standaloneAppServer, "webpack-runtime.js");
|
|
6983
7073
|
const fileContent = readFileSync3(webpackRuntimeFile, "utf-8");
|
|
6984
|
-
const chunks = readdirSync3(
|
|
7074
|
+
const chunks = readdirSync3(path11.join(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
|
|
6985
7075
|
console.log(` - chunk ${chunk}`);
|
|
6986
7076
|
return chunk.replace(/\.js$/, "");
|
|
6987
7077
|
});
|
|
@@ -6990,28 +7080,28 @@ async function updateWebpackChunksFile(config) {
|
|
|
6990
7080
|
}
|
|
6991
7081
|
|
|
6992
7082
|
// src/cli/build/build-worker.ts
|
|
6993
|
-
var packageDistDir =
|
|
7083
|
+
var packageDistDir = path12.join(path12.dirname(fileURLToPath3(import.meta.url)), "..");
|
|
6994
7084
|
async function buildWorker(config) {
|
|
6995
7085
|
console.log(`\x1B[35m\u2699\uFE0F Copying files...
|
|
6996
7086
|
\x1B[0m`);
|
|
6997
7087
|
await cp(
|
|
6998
|
-
|
|
6999
|
-
|
|
7088
|
+
path12.join(config.paths.dotNext, "static"),
|
|
7089
|
+
path12.join(config.paths.builderOutput, "assets", "_next", "static"),
|
|
7000
7090
|
{
|
|
7001
7091
|
recursive: true
|
|
7002
7092
|
}
|
|
7003
7093
|
);
|
|
7004
|
-
const publicDir =
|
|
7094
|
+
const publicDir = path12.join(config.paths.nextApp, "public");
|
|
7005
7095
|
if (existsSync3(publicDir)) {
|
|
7006
|
-
await cp(publicDir,
|
|
7096
|
+
await cp(publicDir, path12.join(config.paths.builderOutput, "assets"), {
|
|
7007
7097
|
recursive: true
|
|
7008
7098
|
});
|
|
7009
7099
|
}
|
|
7010
7100
|
copyPackageCliFiles(packageDistDir, config);
|
|
7011
|
-
const templateDir =
|
|
7012
|
-
const workerEntrypoint =
|
|
7013
|
-
const workerOutputFile =
|
|
7014
|
-
const nextConfigStr = readFileSync4(
|
|
7101
|
+
const templateDir = path12.join(config.paths.internalPackage, "cli", "templates");
|
|
7102
|
+
const workerEntrypoint = path12.join(templateDir, "worker.ts");
|
|
7103
|
+
const workerOutputFile = path12.join(config.paths.builderOutput, "index.mjs");
|
|
7104
|
+
const nextConfigStr = readFileSync4(path12.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
|
|
7015
7105
|
/const nextConfig = ({.+?})\n/
|
|
7016
7106
|
)?.[1] ?? {};
|
|
7017
7107
|
console.log(`\x1B[35m\u2699\uFE0F Bundling the worker file...
|
|
@@ -7030,15 +7120,15 @@ async function buildWorker(config) {
|
|
|
7030
7120
|
// Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
|
|
7031
7121
|
// eval("require")("bufferutil");
|
|
7032
7122
|
// eval("require")("utf-8-validate");
|
|
7033
|
-
"next/dist/compiled/ws":
|
|
7123
|
+
"next/dist/compiled/ws": path12.join(templateDir, "shims", "empty.ts"),
|
|
7034
7124
|
// Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
|
|
7035
7125
|
// eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
|
|
7036
7126
|
// which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
|
|
7037
7127
|
// QUESTION: Why did I encountered this but mhart didn't?
|
|
7038
|
-
"next/dist/compiled/edge-runtime":
|
|
7128
|
+
"next/dist/compiled/edge-runtime": path12.join(templateDir, "shims", "empty.ts"),
|
|
7039
7129
|
// `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
|
|
7040
7130
|
// source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
|
|
7041
|
-
"@next/env":
|
|
7131
|
+
"@next/env": path12.join(templateDir, "shims", "env.ts")
|
|
7042
7132
|
},
|
|
7043
7133
|
define: {
|
|
7044
7134
|
// config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139
|
|
@@ -7118,10 +7208,10 @@ function createFixRequiresESBuildPlugin(templateDir) {
|
|
|
7118
7208
|
name: "replaceRelative",
|
|
7119
7209
|
setup(build3) {
|
|
7120
7210
|
build3.onResolve({ filter: /^\.\/require-hook$/ }, () => ({
|
|
7121
|
-
path:
|
|
7211
|
+
path: path12.join(templateDir, "shims", "empty.ts")
|
|
7122
7212
|
}));
|
|
7123
7213
|
build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, () => ({
|
|
7124
|
-
path:
|
|
7214
|
+
path: path12.join(templateDir, "shims", "empty.ts")
|
|
7125
7215
|
}));
|
|
7126
7216
|
}
|
|
7127
7217
|
};
|
|
@@ -7129,23 +7219,23 @@ function createFixRequiresESBuildPlugin(templateDir) {
|
|
|
7129
7219
|
|
|
7130
7220
|
// src/cli/build/index.ts
|
|
7131
7221
|
import { cpSync as cpSync2 } from "node:fs";
|
|
7132
|
-
import
|
|
7222
|
+
import path13 from "node:path";
|
|
7133
7223
|
import { rm } from "node:fs/promises";
|
|
7134
7224
|
async function build2(appDir, opts) {
|
|
7135
7225
|
if (!opts.skipBuild) {
|
|
7136
|
-
buildNextjsApp(appDir);
|
|
7226
|
+
await buildNextjsApp(appDir);
|
|
7137
7227
|
}
|
|
7138
7228
|
if (!containsDotNextDir(appDir)) {
|
|
7139
7229
|
throw new Error(`.next folder not found in ${appDir}`);
|
|
7140
7230
|
}
|
|
7141
|
-
const outputDir2 =
|
|
7231
|
+
const outputDir2 = path13.resolve(opts.outputDir ?? appDir, ".worker-next");
|
|
7142
7232
|
await cleanDirectory(outputDir2);
|
|
7143
|
-
cpSync2(
|
|
7233
|
+
cpSync2(path13.join(appDir, ".next"), path13.join(outputDir2, ".next"), { recursive: true });
|
|
7144
7234
|
const config = getConfig(appDir, outputDir2);
|
|
7145
7235
|
await buildWorker(config);
|
|
7146
7236
|
}
|
|
7147
|
-
async function cleanDirectory(
|
|
7148
|
-
return await rm(
|
|
7237
|
+
async function cleanDirectory(path14) {
|
|
7238
|
+
return await rm(path14, { recursive: true, force: true });
|
|
7149
7239
|
}
|
|
7150
7240
|
|
|
7151
7241
|
// src/cli/index.ts
|
|
@@ -7181,15 +7271,15 @@ function getArgs() {
|
|
|
7181
7271
|
skipBuild: skipBuild2 || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD))
|
|
7182
7272
|
};
|
|
7183
7273
|
}
|
|
7184
|
-
function assertDirArg(
|
|
7274
|
+
function assertDirArg(path14, argName, make) {
|
|
7185
7275
|
let dirStats;
|
|
7186
7276
|
try {
|
|
7187
|
-
dirStats = statSync2(
|
|
7277
|
+
dirStats = statSync2(path14);
|
|
7188
7278
|
} catch {
|
|
7189
7279
|
if (!make) {
|
|
7190
7280
|
throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
|
|
7191
7281
|
}
|
|
7192
|
-
mkdirSync(
|
|
7282
|
+
mkdirSync(path14);
|
|
7193
7283
|
return;
|
|
7194
7284
|
}
|
|
7195
7285
|
if (!dirStats.isDirectory()) {
|
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-361f2b7",
|
|
5
5
|
"bin": "dist/cli/index.mjs",
|
|
6
6
|
"main": "./dist/api/index.mjs",
|
|
7
7
|
"types": "./dist/api/index.d.mts",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"glob": "^11.0.0",
|
|
41
41
|
"globals": "^15.9.0",
|
|
42
42
|
"next": "14.2.11",
|
|
43
|
+
"package-manager-detector": "^0.2.0",
|
|
43
44
|
"tsup": "^8.2.4",
|
|
44
45
|
"typescript": "^5.5.4",
|
|
45
46
|
"typescript-eslint": "^8.7.0",
|