@opennextjs/cloudflare 0.0.0-698638 → 0.0.0-953d0b1

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.
@@ -1,29 +1,8 @@
1
1
  #!/usr/bin/env node
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
2
+ import {
3
+ __commonJS,
4
+ __toESM
5
+ } from "./chunk-UJCSKKID.mjs";
27
6
 
28
7
  // ../../node_modules/.pnpm/balanced-match@1.0.2/node_modules/balanced-match/index.js
29
8
  var require_balanced_match = __commonJS({
@@ -234,62 +213,73 @@ var require_brace_expansion = __commonJS({
234
213
  }
235
214
  });
236
215
 
237
- // src/index.ts
238
- import { resolve as resolve2 } from "node:path";
239
-
240
- // src/args.ts
241
- import { mkdirSync, statSync } from "node:fs";
242
- import { parseArgs } from "node:util";
243
- import { resolve } from "node:path";
244
- function getArgs() {
245
- const {
246
- values: { skipBuild: skipBuild2, output }
247
- } = parseArgs({
248
- options: {
249
- skipBuild: {
250
- type: "boolean",
251
- short: "s",
252
- default: false
253
- },
254
- output: {
255
- type: "string",
256
- short: "o"
257
- }
258
- },
259
- allowPositionals: false
260
- });
261
- const outputDir2 = output ? resolve(output) : void 0;
262
- if (outputDir2) {
263
- 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"
264
223
  }
224
+ };
225
+ function getConfig(appDir, outputDir2) {
226
+ const dotNext = path.join(outputDir2, ".next");
227
+ const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
228
+ const standaloneApp = path.join(dotNext, "standalone", appPath);
229
+ const standaloneAppDotNext = path.join(standaloneApp, ".next");
230
+ const standaloneAppServer = path.join(standaloneAppDotNext, "server");
231
+ const nodeModules = path.join(standaloneApp, "node_modules");
232
+ const internalPackage = path.join(nodeModules, ...PACKAGE_NAME.split("/"));
265
233
  return {
266
- outputDir: outputDir2,
267
- skipBuild: skipBuild2 || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD))
234
+ paths: {
235
+ nextApp: appDir,
236
+ builderOutput: outputDir2,
237
+ dotNext,
238
+ standaloneApp,
239
+ standaloneAppDotNext,
240
+ standaloneAppServer,
241
+ internalPackage
242
+ },
243
+ cache: {
244
+ kvBindingName: UserConfig.cache.bindingName
245
+ },
246
+ internalPackageName: PACKAGE_NAME
268
247
  };
269
248
  }
270
- function assertDirArg(path6, argName, make) {
271
- let dirStats;
249
+ function containsDotNextDir(folder) {
272
250
  try {
273
- dirStats = statSync(path6);
251
+ return statSync(path.join(folder, ".next")).isDirectory();
274
252
  } catch {
275
- if (!make) {
276
- throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
253
+ return false;
254
+ }
255
+ }
256
+ function getNextjsApplicationPath(dotNextDir) {
257
+ const serverPath = findServerParentPath(dotNextDir);
258
+ if (!serverPath) {
259
+ throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
260
+ }
261
+ return relative(path.join(dotNextDir, "standalone"), serverPath);
262
+ }
263
+ function findServerParentPath(parentPath) {
264
+ try {
265
+ if (statSync(path.join(parentPath, ".next", "server")).isDirectory()) {
266
+ return parentPath;
277
267
  }
278
- mkdirSync(path6);
279
- return;
268
+ } catch {
280
269
  }
281
- if (!dirStats.isDirectory()) {
282
- throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a directory`);
270
+ const folders = readdirSync(parentPath);
271
+ for (const folder of folders) {
272
+ const subFolder = path.join(parentPath, folder);
273
+ if (statSync(path.join(parentPath, folder)).isDirectory()) {
274
+ const dirServerPath = findServerParentPath(subFolder);
275
+ if (dirServerPath) {
276
+ return dirServerPath;
277
+ }
278
+ }
283
279
  }
284
280
  }
285
281
 
286
- // src/index.ts
287
- import { existsSync as existsSync4 } from "node:fs";
288
-
289
- // src/build/build.ts
290
- import { rm } from "node:fs/promises";
291
-
292
- // src/build/build-next-app.ts
282
+ // src/cli/build/build-next-app.ts
293
283
  import { execSync } from "node:child_process";
294
284
  function buildNextjsApp(nextAppDir2) {
295
285
  runNextBuildCommand("pnpm", nextAppDir2);
@@ -308,29 +298,23 @@ function runNextBuildCommand(packager, nextAppDir2) {
308
298
  });
309
299
  }
310
300
 
311
- // src/build/build-worker.ts
301
+ // src/cli/build/build-worker.ts
312
302
  import { build } from "esbuild";
313
- import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
314
303
  import { cp, readFile, writeFile } from "node:fs/promises";
304
+ import { existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
315
305
 
316
- // src/build/patches/investigated/patch-require.ts
317
- function patchRequire(code) {
318
- console.log("# patchRequire");
319
- return code.replace(/__require\d?\(/g, "require(").replace(/__require\d?\./g, "require.");
320
- }
321
-
322
- // src/build/patches/investigated/copy-templates.ts
323
- import path from "node:path";
306
+ // src/cli/build/patches/investigated/copy-package-cli-files.ts
324
307
  import { cpSync } from "node:fs";
325
- function copyTemplates(srcDir, nextjsAppPaths) {
326
- console.log("# copyTemplates");
327
- const destDir = path.join(nextjsAppPaths.standaloneAppDir, "node_modules/cf/templates");
328
- cpSync(srcDir, destDir, { recursive: true });
329
- return destDir;
308
+ import path2 from "node:path";
309
+ function copyPackageCliFiles(packageDistDir2, config) {
310
+ console.log("# copyPackageTemplateFiles");
311
+ const sourceDir = path2.join(packageDistDir2, "cli");
312
+ const destinationDir = path2.join(config.paths.internalPackage, "cli");
313
+ cpSync(sourceDir, destinationDir, { recursive: true });
330
314
  }
331
315
 
332
- // src/build/patches/to-investigate/patch-read-file.ts
333
- import { readFileSync } from "node:fs";
316
+ // src/cli/build/build-worker.ts
317
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
334
318
 
335
319
  // ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
336
320
  var import_brace_expansion = __toESM(require_brace_expansion(), 1);
@@ -1003,11 +987,11 @@ var qmarksTestNoExtDot = ([$0]) => {
1003
987
  return (f) => f.length === len && f !== "." && f !== "..";
1004
988
  };
1005
989
  var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
1006
- var path2 = {
990
+ var path3 = {
1007
991
  win32: { sep: "\\" },
1008
992
  posix: { sep: "/" }
1009
993
  };
1010
- var sep = defaultPlatform === "win32" ? path2.win32.sep : path2.posix.sep;
994
+ var sep = defaultPlatform === "win32" ? path3.win32.sep : path3.posix.sep;
1011
995
  minimatch.sep = sep;
1012
996
  var GLOBSTAR = Symbol("globstar **");
1013
997
  minimatch.GLOBSTAR = GLOBSTAR;
@@ -3037,7 +3021,7 @@ var LRUCache = class _LRUCache {
3037
3021
  // ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
3038
3022
  import { posix, win32 } from "node:path";
3039
3023
  import { fileURLToPath } from "node:url";
3040
- import { lstatSync, readdir as readdirCB, readdirSync, readlinkSync, realpathSync as rps } from "fs";
3024
+ import { lstatSync, readdir as readdirCB, readdirSync as readdirSync2, readlinkSync, realpathSync as rps } from "fs";
3041
3025
  import * as actualFS from "node:fs";
3042
3026
  import { lstat, readdir, readlink, realpath } from "node:fs/promises";
3043
3027
 
@@ -3924,7 +3908,7 @@ var realpathSync = rps.native;
3924
3908
  var defaultFS = {
3925
3909
  lstatSync,
3926
3910
  readdir: readdirCB,
3927
- readdirSync,
3911
+ readdirSync: readdirSync2,
3928
3912
  readlinkSync,
3929
3913
  realpathSync,
3930
3914
  promises: {
@@ -4184,12 +4168,12 @@ var PathBase = class {
4184
4168
  /**
4185
4169
  * Get the Path object referenced by the string path, resolved from this Path
4186
4170
  */
4187
- resolve(path6) {
4188
- if (!path6) {
4171
+ resolve(path13) {
4172
+ if (!path13) {
4189
4173
  return this;
4190
4174
  }
4191
- const rootPath = this.getRootString(path6);
4192
- const dir = path6.substring(rootPath.length);
4175
+ const rootPath = this.getRootString(path13);
4176
+ const dir = path13.substring(rootPath.length);
4193
4177
  const dirParts = dir.split(this.splitSep);
4194
4178
  const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
4195
4179
  return result;
@@ -4941,8 +4925,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
4941
4925
  /**
4942
4926
  * @internal
4943
4927
  */
4944
- getRootString(path6) {
4945
- return win32.parse(path6).root;
4928
+ getRootString(path13) {
4929
+ return win32.parse(path13).root;
4946
4930
  }
4947
4931
  /**
4948
4932
  * @internal
@@ -4988,8 +4972,8 @@ var PathPosix = class _PathPosix extends PathBase {
4988
4972
  /**
4989
4973
  * @internal
4990
4974
  */
4991
- getRootString(path6) {
4992
- return path6.startsWith("/") ? "/" : "";
4975
+ getRootString(path13) {
4976
+ return path13.startsWith("/") ? "/" : "";
4993
4977
  }
4994
4978
  /**
4995
4979
  * @internal
@@ -5078,11 +5062,11 @@ var PathScurryBase = class {
5078
5062
  /**
5079
5063
  * Get the depth of a provided path, string, or the cwd
5080
5064
  */
5081
- depth(path6 = this.cwd) {
5082
- if (typeof path6 === "string") {
5083
- path6 = this.cwd.resolve(path6);
5065
+ depth(path13 = this.cwd) {
5066
+ if (typeof path13 === "string") {
5067
+ path13 = this.cwd.resolve(path13);
5084
5068
  }
5085
- return path6.depth();
5069
+ return path13.depth();
5086
5070
  }
5087
5071
  /**
5088
5072
  * Return the cache of child entries. Exposed so subclasses can create
@@ -5569,9 +5553,9 @@ var PathScurryBase = class {
5569
5553
  process2();
5570
5554
  return results;
5571
5555
  }
5572
- chdir(path6 = this.cwd) {
5556
+ chdir(path13 = this.cwd) {
5573
5557
  const oldCwd = this.cwd;
5574
- this.cwd = typeof path6 === "string" ? this.cwd.resolve(path6) : path6;
5558
+ this.cwd = typeof path13 === "string" ? this.cwd.resolve(path13) : path13;
5575
5559
  this.cwd[setAsCwd](oldCwd);
5576
5560
  }
5577
5561
  };
@@ -5927,8 +5911,8 @@ var MatchRecord = class {
5927
5911
  }
5928
5912
  // match, absolute, ifdir
5929
5913
  entries() {
5930
- return [...this.store.entries()].map(([path6, n]) => [
5931
- path6,
5914
+ return [...this.store.entries()].map(([path13, n]) => [
5915
+ path13,
5932
5916
  !!(n & 2),
5933
5917
  !!(n & 1)
5934
5918
  ]);
@@ -6133,9 +6117,9 @@ var GlobUtil = class {
6133
6117
  signal;
6134
6118
  maxDepth;
6135
6119
  includeChildMatches;
6136
- constructor(patterns, path6, opts) {
6120
+ constructor(patterns, path13, opts) {
6137
6121
  this.patterns = patterns;
6138
- this.path = path6;
6122
+ this.path = path13;
6139
6123
  this.opts = opts;
6140
6124
  this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
6141
6125
  this.includeChildMatches = opts.includeChildMatches !== false;
@@ -6154,11 +6138,11 @@ var GlobUtil = class {
6154
6138
  });
6155
6139
  }
6156
6140
  }
6157
- #ignored(path6) {
6158
- return this.seen.has(path6) || !!this.#ignore?.ignored?.(path6);
6141
+ #ignored(path13) {
6142
+ return this.seen.has(path13) || !!this.#ignore?.ignored?.(path13);
6159
6143
  }
6160
- #childrenIgnored(path6) {
6161
- return !!this.#ignore?.childrenIgnored?.(path6);
6144
+ #childrenIgnored(path13) {
6145
+ return !!this.#ignore?.childrenIgnored?.(path13);
6162
6146
  }
6163
6147
  // backpressure mechanism
6164
6148
  pause() {
@@ -6373,8 +6357,8 @@ var GlobUtil = class {
6373
6357
  };
6374
6358
  var GlobWalker = class extends GlobUtil {
6375
6359
  matches = /* @__PURE__ */ new Set();
6376
- constructor(patterns, path6, opts) {
6377
- super(patterns, path6, opts);
6360
+ constructor(patterns, path13, opts) {
6361
+ super(patterns, path13, opts);
6378
6362
  }
6379
6363
  matchEmit(e) {
6380
6364
  this.matches.add(e);
@@ -6411,8 +6395,8 @@ var GlobWalker = class extends GlobUtil {
6411
6395
  };
6412
6396
  var GlobStream = class extends GlobUtil {
6413
6397
  results;
6414
- constructor(patterns, path6, opts) {
6415
- super(patterns, path6, opts);
6398
+ constructor(patterns, path13, opts) {
6399
+ super(patterns, path13, opts);
6416
6400
  this.results = new Minipass({
6417
6401
  signal: this.signal,
6418
6402
  objectMode: true
@@ -6705,60 +6689,44 @@ var glob = Object.assign(glob_, {
6705
6689
  });
6706
6690
  glob.glob = glob;
6707
6691
 
6708
- // src/build/patches/to-investigate/patch-read-file.ts
6709
- function patchReadFile(code, nextjsAppPaths) {
6710
- console.log("# patchReadFile");
6711
- code = code.replace(
6712
- "getBuildId() {",
6713
- `getBuildId() {
6714
- return ${JSON.stringify(readFileSync(`${nextjsAppPaths.standaloneAppDotNextDir}/BUILD_ID`, "utf-8"))};
6715
- `
6716
- );
6717
- const manifestJsons = globSync(`${nextjsAppPaths.standaloneAppDotNextDir}/**/*-manifest.json`).map(
6718
- (file) => file.replace(nextjsAppPaths.standaloneAppDir + "/", "")
6719
- );
6720
- code = code.replace(
6721
- /function loadManifest\((.+?), .+?\) {/,
6692
+ // src/cli/build/patches/to-investigate/inline-eval-manifest.ts
6693
+ import path4 from "node:path";
6694
+ function inlineEvalManifest(code, config) {
6695
+ console.log("# inlineEvalManifest");
6696
+ const manifestJss = globSync(
6697
+ path4.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js")
6698
+ ).map((file) => file.replace(`${config.paths.standaloneApp}/`, ""));
6699
+ return code.replace(
6700
+ /function evalManifest\((.+?), .+?\) {/,
6722
6701
  `$&
6723
- ${manifestJsons.map(
6724
- (manifestJson) => `
6725
- if ($1.endsWith("${manifestJson}")) {
6726
- return ${readFileSync(`${nextjsAppPaths.standaloneAppDir}/${manifestJson}`, "utf-8")};
6727
- }
6728
- `
6702
+ ${manifestJss.map(
6703
+ (manifestJs) => `
6704
+ if ($1.endsWith("${manifestJs}")) {
6705
+ require("${path4.join(config.paths.standaloneApp, manifestJs)}");
6706
+ return {
6707
+ __RSC_MANIFEST: {
6708
+ "${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
6709
+ },
6710
+ };
6711
+ }
6712
+ `
6729
6713
  ).join("\n")}
6730
- throw new Error("Unknown loadManifest: " + $1);
6731
- `
6732
- );
6733
- return code;
6734
- }
6735
-
6736
- // src/build/patches/to-investigate/patch-find-dir.ts
6737
- import { existsSync } from "node:fs";
6738
- function patchFindDir(code, nextjsAppPaths) {
6739
- console.log("# patchFindDir");
6740
- return code.replace(
6741
- "function findDir(dir, name) {",
6742
- `function findDir(dir, name) {
6743
- if (dir.endsWith(".next/server")) {
6744
- if (name === "app") return ${existsSync(`${nextjsAppPaths.standaloneAppServerDir}/app`)};
6745
- if (name === "pages") return ${existsSync(`${nextjsAppPaths.standaloneAppServerDir}/pages`)};
6746
- }
6747
- throw new Error("Unknown findDir call: " + dir + " " + name);
6714
+ throw new Error("Unknown evalManifest: " + $1);
6748
6715
  `
6749
6716
  );
6750
6717
  }
6751
6718
 
6752
- // src/build/patches/to-investigate/inline-next-require.ts
6753
- import { readFileSync as readFileSync2, existsSync as existsSync2 } from "node:fs";
6754
- function inlineNextRequire(code, nextjsAppPaths) {
6719
+ // src/cli/build/patches/to-investigate/inline-next-require.ts
6720
+ import { existsSync, readFileSync } from "node:fs";
6721
+ import path5 from "node:path";
6722
+ function inlineNextRequire(code, config) {
6755
6723
  console.log("# inlineNextRequire");
6756
- const pagesManifestFile = `${nextjsAppPaths.standaloneAppServerDir}/pages-manifest.json`;
6757
- const appPathsManifestFile = `${nextjsAppPaths.standaloneAppServerDir}/app-paths-manifest.json`;
6758
- const pagesManifestFiles = existsSync2(pagesManifestFile) ? Object.values(JSON.parse(readFileSync2(pagesManifestFile, "utf-8"))).map(
6724
+ const pagesManifestFile = path5.join(config.paths.standaloneAppServer, "pages-manifest.json");
6725
+ const appPathsManifestFile = path5.join(config.paths.standaloneAppServer, "app-paths-manifest.json");
6726
+ const pagesManifestFiles = existsSync(pagesManifestFile) ? Object.values(JSON.parse(readFileSync(pagesManifestFile, "utf-8"))).map(
6759
6727
  (file) => ".next/server/" + file
6760
6728
  ) : [];
6761
- const appPathsManifestFiles = existsSync2(appPathsManifestFile) ? Object.values(JSON.parse(readFileSync2(appPathsManifestFile, "utf-8"))).map(
6729
+ const appPathsManifestFiles = existsSync(appPathsManifestFile) ? Object.values(JSON.parse(readFileSync(appPathsManifestFile, "utf-8"))).map(
6762
6730
  (file) => ".next/server/" + file
6763
6731
  ) : [];
6764
6732
  const allManifestFiles = pagesManifestFiles.concat(appPathsManifestFiles);
@@ -6770,14 +6738,14 @@ function inlineNextRequire(code, nextjsAppPaths) {
6770
6738
  ${htmlPages.map(
6771
6739
  (htmlPage) => `
6772
6740
  if (pagePath.endsWith("${htmlPage}")) {
6773
- return ${JSON.stringify(readFileSync2(`${nextjsAppPaths.standaloneAppDir}/${htmlPage}`, "utf-8"))};
6741
+ return ${JSON.stringify(readFileSync(path5.join(config.paths.standaloneApp, htmlPage), "utf-8"))};
6774
6742
  }
6775
6743
  `
6776
6744
  ).join("\n")}
6777
6745
  ${pageModules.map(
6778
6746
  (module) => `
6779
6747
  if (pagePath.endsWith("${module}")) {
6780
- return require("${nextjsAppPaths.standaloneAppDir}/${module}");
6748
+ return require("${path5.join(config.paths.standaloneApp, module)}");
6781
6749
  }
6782
6750
  `
6783
6751
  ).join("\n")}
@@ -6786,40 +6754,88 @@ function inlineNextRequire(code, nextjsAppPaths) {
6786
6754
  );
6787
6755
  }
6788
6756
 
6789
- // src/build/patches/to-investigate/inline-eval-manifest.ts
6790
- function inlineEvalManifest(code, nextjsAppPaths) {
6791
- console.log("# inlineEvalManifest");
6792
- const manifestJss = globSync(
6793
- `${nextjsAppPaths.standaloneAppDotNextDir}/**/*_client-reference-manifest.js`
6794
- ).map((file) => file.replace(`${nextjsAppPaths.standaloneAppDir}/`, ""));
6757
+ // src/cli/build/patches/investigated/patch-cache.ts
6758
+ import path6 from "node:path";
6759
+ function patchCache(code, config) {
6760
+ console.log("# patchCached");
6761
+ const cacheHandler = path6.join(config.paths.internalPackage, "cli", "cache-handler.mjs");
6762
+ const patchedCode = code.replace(
6763
+ "const { cacheHandler } = this.nextConfig;",
6764
+ `const cacheHandler = null;
6765
+ CacheHandler = (await import('${cacheHandler}')).default;
6766
+ CacheHandler.maybeKVNamespace = process.env["${config.cache.kvBindingName}"];
6767
+ `
6768
+ );
6769
+ if (patchedCode === code) {
6770
+ throw new Error("Cache patch not applied");
6771
+ }
6772
+ return patchedCode;
6773
+ }
6774
+
6775
+ // src/cli/build/patches/to-investigate/patch-find-dir.ts
6776
+ import { existsSync as existsSync2 } from "node:fs";
6777
+ import path7 from "node:path";
6778
+ function patchFindDir(code, config) {
6779
+ console.log("# patchFindDir");
6795
6780
  return code.replace(
6796
- /function evalManifest\((.+?), .+?\) {/,
6781
+ "function findDir(dir, name) {",
6782
+ `function findDir(dir, name) {
6783
+ if (dir.endsWith(".next/server")) {
6784
+ if (name === "app") {
6785
+ return ${existsSync2(`${path7.join(config.paths.standaloneAppServer, "app")}`)};
6786
+ }
6787
+ if (name === "pages") {
6788
+ return ${existsSync2(`${path7.join(config.paths.standaloneAppServer, "pages")}`)};
6789
+ }
6790
+ }
6791
+ throw new Error("Unknown findDir call: " + dir + " " + name);
6792
+ `
6793
+ );
6794
+ }
6795
+
6796
+ // src/cli/build/patches/to-investigate/patch-read-file.ts
6797
+ import path8 from "node:path";
6798
+ import { readFileSync as readFileSync2 } from "node:fs";
6799
+ function patchReadFile(code, config) {
6800
+ console.log("# patchReadFile");
6801
+ code = code.replace(
6802
+ "getBuildId() {",
6803
+ `getBuildId() {
6804
+ return ${JSON.stringify(readFileSync2(path8.join(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
6805
+ `
6806
+ );
6807
+ const manifestJsons = globSync(path8.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json")).map(
6808
+ (file) => file.replace(config.paths.standaloneApp + "/", "")
6809
+ );
6810
+ code = code.replace(
6811
+ /function loadManifest\((.+?), .+?\) {/,
6797
6812
  `$&
6798
- ${manifestJss.map(
6799
- (manifestJs) => `
6800
- if ($1.endsWith("${manifestJs}")) {
6801
- require("${nextjsAppPaths.standaloneAppDir}/${manifestJs}");
6802
- return {
6803
- __RSC_MANIFEST: {
6804
- "${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
6805
- },
6806
- };
6807
- }
6808
- `
6813
+ ${manifestJsons.map(
6814
+ (manifestJson) => `
6815
+ if ($1.endsWith("${manifestJson}")) {
6816
+ return ${readFileSync2(path8.join(config.paths.standaloneApp, manifestJson), "utf-8")};
6817
+ }
6818
+ `
6809
6819
  ).join("\n")}
6810
- throw new Error("Unknown evalManifest: " + $1);
6811
- `
6820
+ throw new Error("Unknown loadManifest: " + $1);
6821
+ `
6812
6822
  );
6823
+ return code;
6824
+ }
6825
+
6826
+ // src/cli/build/patches/investigated/patch-require.ts
6827
+ function patchRequire(code) {
6828
+ console.log("# patchRequire");
6829
+ return code.replace(/__require\d?\(/g, "require(").replace(/__require\d?\./g, "require.");
6813
6830
  }
6814
6831
 
6815
- // src/build/patches/to-investigate/wrangler-deps.ts
6816
- import path3 from "node:path";
6832
+ // src/cli/build/patches/to-investigate/wrangler-deps.ts
6817
6833
  import fs, { writeFileSync } from "node:fs";
6818
- function patchWranglerDeps(paths) {
6834
+ import path9 from "node:path";
6835
+ function patchWranglerDeps(config) {
6819
6836
  console.log("# patchWranglerDeps");
6820
- console.log({ base: paths.standaloneAppDotNextDir });
6821
- const pagesRuntimeFile = path3.join(
6822
- paths.standaloneAppDir,
6837
+ const pagesRuntimeFile = path9.join(
6838
+ config.paths.standaloneApp,
6823
6839
  "node_modules",
6824
6840
  "next",
6825
6841
  "dist",
@@ -6829,8 +6845,8 @@ function patchWranglerDeps(paths) {
6829
6845
  );
6830
6846
  const patchedPagesRuntime = fs.readFileSync(pagesRuntimeFile, "utf-8").replace(`e.exports=require("critters")`, `e.exports={}`);
6831
6847
  fs.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
6832
- const tracerFile = path3.join(
6833
- paths.standaloneAppDir,
6848
+ const tracerFile = path9.join(
6849
+ config.paths.standaloneApp,
6834
6850
  "node_modules",
6835
6851
  "next",
6836
6852
  "dist",
@@ -6843,10 +6859,13 @@ function patchWranglerDeps(paths) {
6843
6859
  writeFileSync(tracerFile, pacthedTracer);
6844
6860
  }
6845
6861
 
6846
- // src/build/patches/investigated/update-webpack-chunks-file/index.ts
6847
- import { readdirSync as readdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "node:fs";
6862
+ // src/cli/build/build-worker.ts
6863
+ import path11 from "node:path";
6848
6864
 
6849
- // src/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts
6865
+ // src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
6866
+ import { readFileSync as readFileSync3, readdirSync as readdirSync3, writeFileSync as writeFileSync2 } from "node:fs";
6867
+
6868
+ // src/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts
6850
6869
  import * as ts from "ts-morph";
6851
6870
  async function getChunkInstallationIdentifiers(sourceFile) {
6852
6871
  const installChunkDeclaration = getInstallChunkDeclaration(sourceFile);
@@ -6892,7 +6911,7 @@ function getInstalledChunksDeclaration(sourceFile, installChunkDeclaration) {
6892
6911
  return installedChunksDeclaration;
6893
6912
  }
6894
6913
 
6895
- // src/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.ts
6914
+ // src/cli/build/patches/investigated/update-webpack-chunks-file/get-file-content-with-updated-webpack-f-require-code.ts
6896
6915
  import * as ts2 from "ts-morph";
6897
6916
  async function getFileContentWithUpdatedWebpackFRequireCode(sourceFile, { installedChunks, installChunk }, chunks) {
6898
6917
  const webpackFRequireFunction = sourceFile.getDescendantsOfKind(ts2.SyntaxKind.ArrowFunction).find((arrowFunction) => {
@@ -6936,7 +6955,7 @@ if(${chunkId} === ${chunk}) return ${installChunk}(require("./chunks/${chunk}.js
6936
6955
  return sourceFile.print();
6937
6956
  }
6938
6957
 
6939
- // src/build/utils/ts-parse-file.ts
6958
+ // src/cli/build/utils/ts-parse-file.ts
6940
6959
  import * as ts3 from "ts-morph";
6941
6960
  function tsParseFile(fileContent) {
6942
6961
  const project = new ts3.Project();
@@ -6944,7 +6963,7 @@ function tsParseFile(fileContent) {
6944
6963
  return sourceFile;
6945
6964
  }
6946
6965
 
6947
- // src/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.ts
6966
+ // src/cli/build/patches/investigated/update-webpack-chunks-file/get-updated-webpack-chunks-file-content.ts
6948
6967
  async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
6949
6968
  const tsSourceFile = tsParseFile(fileContent);
6950
6969
  const chunkInstallationIdentifiers = await getChunkInstallationIdentifiers(tsSourceFile);
@@ -6956,12 +6975,13 @@ async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
6956
6975
  return updatedFileContent;
6957
6976
  }
6958
6977
 
6959
- // src/build/patches/investigated/update-webpack-chunks-file/index.ts
6960
- async function updateWebpackChunksFile(nextjsAppPaths) {
6978
+ // src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
6979
+ import path10 from "node:path";
6980
+ async function updateWebpackChunksFile(config) {
6961
6981
  console.log("# updateWebpackChunksFile");
6962
- const webpackRuntimeFile = `${nextjsAppPaths.standaloneAppServerDir}/webpack-runtime.js`;
6982
+ const webpackRuntimeFile = path10.join(config.paths.standaloneAppServer, "webpack-runtime.js");
6963
6983
  const fileContent = readFileSync3(webpackRuntimeFile, "utf-8");
6964
- const chunks = readdirSync2(`${nextjsAppPaths.standaloneAppServerDir}/chunks`).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
6984
+ const chunks = readdirSync3(path10.join(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
6965
6985
  console.log(` - chunk ${chunk}`);
6966
6986
  return chunk.replace(/\.js$/, "");
6967
6987
  });
@@ -6969,18 +6989,35 @@ async function updateWebpackChunksFile(nextjsAppPaths) {
6969
6989
  writeFileSync2(webpackRuntimeFile, updatedFileContent);
6970
6990
  }
6971
6991
 
6972
- // src/build/build-worker.ts
6973
- async function buildWorker(inputNextAppDir, outputDir2, nextjsAppPaths, templateSrcDir) {
6974
- const templateDir = copyTemplates(templateSrcDir, nextjsAppPaths);
6975
- const workerEntrypoint = `${templateDir}/worker.ts`;
6976
- const workerOutputFile = `${outputDir2}/index.mjs`;
6977
- const nextConfigStr = readFileSync4(nextjsAppPaths.standaloneAppDir + "/server.js", "utf8")?.match(
6992
+ // src/cli/build/build-worker.ts
6993
+ var packageDistDir = path11.join(path11.dirname(fileURLToPath3(import.meta.url)), "..");
6994
+ async function buildWorker(config) {
6995
+ console.log(`\x1B[35m\u2699\uFE0F Copying files...
6996
+ \x1B[0m`);
6997
+ await cp(
6998
+ path11.join(config.paths.dotNext, "static"),
6999
+ path11.join(config.paths.builderOutput, "assets", "_next", "static"),
7000
+ {
7001
+ recursive: true
7002
+ }
7003
+ );
7004
+ const publicDir = path11.join(config.paths.nextApp, "public");
7005
+ if (existsSync3(publicDir)) {
7006
+ await cp(publicDir, path11.join(config.paths.builderOutput, "assets"), {
7007
+ recursive: true
7008
+ });
7009
+ }
7010
+ copyPackageCliFiles(packageDistDir, config);
7011
+ const templateDir = path11.join(config.paths.internalPackage, "cli", "templates");
7012
+ const workerEntrypoint = path11.join(templateDir, "worker.ts");
7013
+ const workerOutputFile = path11.join(config.paths.builderOutput, "index.mjs");
7014
+ const nextConfigStr = readFileSync4(path11.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
6978
7015
  /const nextConfig = ({.+?})\n/
6979
7016
  )?.[1] ?? {};
6980
7017
  console.log(`\x1B[35m\u2699\uFE0F Bundling the worker file...
6981
7018
  \x1B[0m`);
6982
- patchWranglerDeps(nextjsAppPaths);
6983
- updateWebpackChunksFile(nextjsAppPaths);
7019
+ patchWranglerDeps(config);
7020
+ updateWebpackChunksFile(config);
6984
7021
  await build({
6985
7022
  entryPoints: [workerEntrypoint],
6986
7023
  bundle: true,
@@ -6993,15 +7030,15 @@ async function buildWorker(inputNextAppDir, outputDir2, nextjsAppPaths, template
6993
7030
  // Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
6994
7031
  // eval("require")("bufferutil");
6995
7032
  // eval("require")("utf-8-validate");
6996
- "next/dist/compiled/ws": `${templateDir}/shims/empty.ts`,
7033
+ "next/dist/compiled/ws": path11.join(templateDir, "shims", "empty.ts"),
6997
7034
  // Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
6998
7035
  // eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
6999
7036
  // which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
7000
7037
  // QUESTION: Why did I encountered this but mhart didn't?
7001
- "next/dist/compiled/edge-runtime": `${templateDir}/shims/empty.ts`,
7038
+ "next/dist/compiled/edge-runtime": path11.join(templateDir, "shims", "empty.ts"),
7002
7039
  // `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
7003
7040
  // source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
7004
- "@next/env": `${templateDir}/shims/env.ts`
7041
+ "@next/env": path11.join(templateDir, "shims", "env.ts")
7005
7042
  },
7006
7043
  define: {
7007
7044
  // config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139
@@ -7035,22 +7072,21 @@ async function buildWorker(inputNextAppDir, outputDir2, nextjsAppPaths, template
7035
7072
  // Do not crash on cache not supported
7036
7073
  // https://github.com/cloudflare/workerd/pull/2434
7037
7074
  // compatibility flag "cache_option_enabled" -> does not support "force-cache"
7038
- let isPatchedAlready = globalThis.fetch.__nextPatched;
7039
7075
  const curFetch = globalThis.fetch;
7040
7076
  globalThis.fetch = (input, init) => {
7041
- console.log("globalThis.fetch", input);
7042
- if (init) delete init.cache;
7077
+ if (init) {
7078
+ delete init.cache;
7079
+ }
7043
7080
  return curFetch(input, init);
7044
7081
  };
7045
7082
  import { Readable } from 'node:stream';
7046
- globalThis.fetch.__nextPatched = isPatchedAlready;
7047
7083
  fetch = globalThis.fetch;
7048
7084
  const CustomRequest = class extends globalThis.Request {
7049
7085
  constructor(input, init) {
7050
- console.log("CustomRequest", input);
7051
7086
  if (init) {
7052
7087
  delete init.cache;
7053
7088
  if (init.body?.__node_stream__ === true) {
7089
+ // https://github.com/cloudflare/workerd/issues/2746
7054
7090
  init.body = Readable.toWeb(init.body);
7055
7091
  }
7056
7092
  }
@@ -7059,129 +7095,110 @@ const CustomRequest = class extends globalThis.Request {
7059
7095
  };
7060
7096
  globalThis.Request = CustomRequest;
7061
7097
  Request = globalThis.Request;
7062
- `
7098
+ `
7063
7099
  }
7064
7100
  });
7065
- await updateWorkerBundledCode(workerOutputFile, nextjsAppPaths);
7066
- console.log(`\x1B[35m\u2699\uFE0F Copying asset files...
7067
- \x1B[0m`);
7068
- await cp(`${nextjsAppPaths.dotNextDir}/static`, `${outputDir2}/assets/_next/static`, {
7069
- recursive: true
7070
- });
7071
- if (existsSync3(`${inputNextAppDir}/public`)) {
7072
- await cp(`${inputNextAppDir}/public`, `${outputDir2}/assets`, {
7073
- recursive: true
7074
- });
7075
- }
7101
+ await updateWorkerBundledCode(workerOutputFile, config);
7076
7102
  console.log(`\x1B[35mWorker saved in \`${workerOutputFile}\` \u{1F680}
7077
7103
  \x1B[0m`);
7078
7104
  }
7079
- async function updateWorkerBundledCode(workerOutputFile, nextjsAppPaths) {
7105
+ async function updateWorkerBundledCode(workerOutputFile, config) {
7080
7106
  const originalCode = await readFile(workerOutputFile, "utf8");
7081
7107
  let patchedCode = originalCode;
7082
7108
  patchedCode = patchRequire(patchedCode);
7083
- patchedCode = patchReadFile(patchedCode, nextjsAppPaths);
7084
- patchedCode = inlineNextRequire(patchedCode, nextjsAppPaths);
7085
- patchedCode = patchFindDir(patchedCode, nextjsAppPaths);
7086
- patchedCode = inlineEvalManifest(patchedCode, nextjsAppPaths);
7109
+ patchedCode = patchReadFile(patchedCode, config);
7110
+ patchedCode = inlineNextRequire(patchedCode, config);
7111
+ patchedCode = patchFindDir(patchedCode, config);
7112
+ patchedCode = inlineEvalManifest(patchedCode, config);
7113
+ patchedCode = patchCache(patchedCode, config);
7087
7114
  await writeFile(workerOutputFile, patchedCode);
7088
7115
  }
7089
7116
  function createFixRequiresESBuildPlugin(templateDir) {
7090
7117
  return {
7091
7118
  name: "replaceRelative",
7092
7119
  setup(build3) {
7093
- build3.onResolve({ filter: /^\.\/require-hook$/ }, (args) => ({
7094
- path: `${templateDir}/shims/empty.ts`
7120
+ build3.onResolve({ filter: /^\.\/require-hook$/ }, () => ({
7121
+ path: path11.join(templateDir, "shims", "empty.ts")
7095
7122
  }));
7096
- build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, (args) => ({
7097
- path: `${templateDir}/shims/node-fs.ts`
7123
+ build3.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, () => ({
7124
+ path: path11.join(templateDir, "shims", "empty.ts")
7098
7125
  }));
7099
7126
  }
7100
7127
  };
7101
7128
  }
7102
7129
 
7103
- // src/nextjs-paths.ts
7104
- import { readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
7105
- import path4, { relative } from "node:path";
7106
- function getNextjsAppPaths(nextAppDir2) {
7107
- const dotNextDir = getDotNextDirPath(nextAppDir2);
7108
- const appPath = getNextjsApplicationPath(dotNextDir).replace(/\/$/, "");
7109
- const standaloneAppDir = path4.join(dotNextDir, "standalone", appPath);
7130
+ // src/cli/build/index.ts
7131
+ import { cpSync as cpSync2 } from "node:fs";
7132
+ import path12 from "node:path";
7133
+ import { rm } from "node:fs/promises";
7134
+ async function build2(appDir, opts) {
7135
+ if (!opts.skipBuild) {
7136
+ buildNextjsApp(appDir);
7137
+ }
7138
+ if (!containsDotNextDir(appDir)) {
7139
+ throw new Error(`.next folder not found in ${appDir}`);
7140
+ }
7141
+ const outputDir2 = path12.resolve(opts.outputDir ?? appDir, ".worker-next");
7142
+ await cleanDirectory(outputDir2);
7143
+ cpSync2(path12.join(appDir, ".next"), path12.join(outputDir2, ".next"), { recursive: true });
7144
+ const config = getConfig(appDir, outputDir2);
7145
+ await buildWorker(config);
7146
+ }
7147
+ async function cleanDirectory(path13) {
7148
+ return await rm(path13, { recursive: true, force: true });
7149
+ }
7150
+
7151
+ // src/cli/index.ts
7152
+ import { existsSync as existsSync4 } from "node:fs";
7153
+
7154
+ // src/cli/args.ts
7155
+ import { mkdirSync, statSync as statSync2 } from "node:fs";
7156
+ import { parseArgs } from "node:util";
7157
+ import { resolve } from "node:path";
7158
+ function getArgs() {
7159
+ const {
7160
+ values: { skipBuild: skipBuild2, output }
7161
+ } = parseArgs({
7162
+ options: {
7163
+ skipBuild: {
7164
+ type: "boolean",
7165
+ short: "s",
7166
+ default: false
7167
+ },
7168
+ output: {
7169
+ type: "string",
7170
+ short: "o"
7171
+ }
7172
+ },
7173
+ allowPositionals: false
7174
+ });
7175
+ const outputDir2 = output ? resolve(output) : void 0;
7176
+ if (outputDir2) {
7177
+ assertDirArg(outputDir2, "output", true);
7178
+ }
7110
7179
  return {
7111
- appDir: nextAppDir2,
7112
- dotNextDir,
7113
- standaloneAppDir,
7114
- standaloneAppDotNextDir: path4.join(standaloneAppDir, ".next"),
7115
- standaloneAppServerDir: path4.join(standaloneAppDir, ".next", "server")
7180
+ outputDir: outputDir2,
7181
+ skipBuild: skipBuild2 || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD))
7116
7182
  };
7117
7183
  }
7118
- function getDotNextDirPath(nextAppDir2) {
7119
- const dotNextDirPath = `${nextAppDir2}/.next`;
7184
+ function assertDirArg(path13, argName, make) {
7185
+ let dirStats;
7120
7186
  try {
7121
- const dirStats = statSync2(dotNextDirPath);
7122
- if (!dirStats.isDirectory()) throw new Error();
7187
+ dirStats = statSync2(path13);
7123
7188
  } catch {
7124
- throw new Error(`Error: \`.next\` directory not found!`);
7125
- }
7126
- return dotNextDirPath;
7127
- }
7128
- function getNextjsApplicationPath(dotNextDir) {
7129
- const serverPath = findServerParentPath(dotNextDir);
7130
- if (!serverPath) {
7131
- throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
7132
- }
7133
- return relative(`${dotNextDir}/standalone`, serverPath);
7134
- function findServerParentPath(path6) {
7135
- try {
7136
- if (statSync2(`${path6}/.next/server`).isDirectory()) {
7137
- return path6;
7138
- }
7139
- } catch {
7140
- }
7141
- const files = readdirSync3(path6);
7142
- for (const file of files) {
7143
- if (statSync2(`${path6}/${file}`).isDirectory()) {
7144
- const dirServerPath = findServerParentPath(`${path6}/${file}`);
7145
- if (dirServerPath) {
7146
- return dirServerPath;
7147
- }
7148
- }
7189
+ if (!make) {
7190
+ throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
7149
7191
  }
7192
+ mkdirSync(path13);
7193
+ return;
7150
7194
  }
7151
- }
7152
-
7153
- // src/build/build.ts
7154
- import path5 from "node:path";
7155
- import { fileURLToPath as fileURLToPath3 } from "node:url";
7156
- import { cpSync as cpSync2, rmSync } from "node:fs";
7157
- var SAVE_DIR = ".save.next";
7158
- async function build2(inputNextAppDir, opts) {
7159
- if (!opts.skipBuild) {
7160
- buildNextjsApp(inputNextAppDir);
7161
- rmSync(`${inputNextAppDir}/${SAVE_DIR}`, {
7162
- recursive: true,
7163
- force: true
7164
- });
7165
- cpSync2(`${inputNextAppDir}/.next`, `${inputNextAppDir}/${SAVE_DIR}`, {
7166
- recursive: true
7167
- });
7168
- } else {
7169
- rmSync(`${inputNextAppDir}/.next`, { recursive: true, force: true });
7170
- cpSync2(`${inputNextAppDir}/${SAVE_DIR}`, `${inputNextAppDir}/.next`, {
7171
- recursive: true
7172
- });
7195
+ if (!dirStats.isDirectory()) {
7196
+ throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a directory`);
7173
7197
  }
7174
- const outputDir2 = `${opts.outputDir ?? inputNextAppDir}/.worker-next`;
7175
- await cleanDirectory(outputDir2);
7176
- const nextjsAppPaths = getNextjsAppPaths(inputNextAppDir);
7177
- const templateDir = path5.join(path5.dirname(fileURLToPath3(import.meta.url)), "templates");
7178
- await buildWorker(inputNextAppDir, outputDir2, nextjsAppPaths, templateDir);
7179
- }
7180
- async function cleanDirectory(path6) {
7181
- return await rm(path6, { recursive: true, force: true });
7182
7198
  }
7183
7199
 
7184
- // src/index.ts
7200
+ // src/cli/index.ts
7201
+ import { resolve as resolve2 } from "node:path";
7185
7202
  var nextAppDir = resolve2(".");
7186
7203
  console.log(`Building the Next.js app in the current folder (${nextAppDir})`);
7187
7204
  if (!["js", "cjs", "mjs", "ts"].some((ext2) => existsSync4(`./next.config.${ext2}`))) {