@opennextjs/cloudflare 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/dist/cli/index.mjs +123 -125
  2. package/package.json +1 -1
@@ -235,19 +235,19 @@ var require_brace_expansion = __commonJS({
235
235
  });
236
236
 
237
237
  // src/cli/config.ts
238
- import path, { relative } from "node:path";
238
+ import { join, relative } from "node:path";
239
239
  import { readdirSync, statSync } from "node:fs";
240
240
  var PACKAGE_NAME = "@opennextjs/cloudflare";
241
241
  function getConfig(projectOpts) {
242
- const dotNext = path.join(projectOpts.outputDir, ".next");
242
+ const dotNext = join(projectOpts.outputDir, ".next");
243
243
  const appPath = getNextjsApplicationPath(dotNext).replace(/\/$/, "");
244
- const standaloneRoot = path.join(dotNext, "standalone");
245
- const standaloneApp = path.join(standaloneRoot, appPath);
246
- const standaloneAppDotNext = path.join(standaloneApp, ".next");
247
- const standaloneAppServer = path.join(standaloneAppDotNext, "server");
248
- const nodeModules = path.join(standaloneApp, "node_modules");
249
- const internalPackage = path.join(nodeModules, ...PACKAGE_NAME.split("/"));
250
- const internalTemplates = path.join(internalPackage, "cli", "templates");
244
+ const standaloneRoot = join(dotNext, "standalone");
245
+ const standaloneApp = join(standaloneRoot, appPath);
246
+ const standaloneAppDotNext = join(standaloneApp, ".next");
247
+ const standaloneAppServer = join(standaloneAppDotNext, "server");
248
+ const nodeModules = join(standaloneApp, "node_modules");
249
+ const internalPackage = join(nodeModules, ...PACKAGE_NAME.split("/"));
250
+ const internalTemplates = join(internalPackage, "cli", "templates");
251
251
  process.env.__OPENNEXT_KV_BINDING_NAME ??= "NEXT_CACHE_WORKERS_KV";
252
252
  return {
253
253
  build: {
@@ -274,7 +274,7 @@ function getConfig(projectOpts) {
274
274
  }
275
275
  function containsDotNextDir(folder) {
276
276
  try {
277
- return statSync(path.join(folder, ".next")).isDirectory();
277
+ return statSync(join(folder, ".next")).isDirectory();
278
278
  } catch {
279
279
  return false;
280
280
  }
@@ -284,19 +284,19 @@ function getNextjsApplicationPath(dotNextDir) {
284
284
  if (!serverPath) {
285
285
  throw new Error(`Unexpected Error: no \`.next/server\` folder could be found in \`${serverPath}\``);
286
286
  }
287
- return relative(path.join(dotNextDir, "standalone"), serverPath);
287
+ return relative(join(dotNextDir, "standalone"), serverPath);
288
288
  }
289
289
  function findServerParentPath(parentPath) {
290
290
  try {
291
- if (statSync(path.join(parentPath, ".next", "server")).isDirectory()) {
291
+ if (statSync(join(parentPath, ".next", "server")).isDirectory()) {
292
292
  return parentPath;
293
293
  }
294
294
  } catch {
295
295
  }
296
296
  const folders = readdirSync(parentPath);
297
297
  for (const folder of folders) {
298
- const subFolder = path.join(parentPath, folder);
299
- if (statSync(path.join(parentPath, folder)).isDirectory()) {
298
+ const subFolder = join(parentPath, folder);
299
+ if (statSync(join(parentPath, folder)).isDirectory()) {
300
300
  const dirServerPath = findServerParentPath(subFolder);
301
301
  if (dirServerPath) {
302
302
  return dirServerPath;
@@ -325,32 +325,32 @@ var LOCKS = {
325
325
  // ../../node_modules/.pnpm/package-manager-detector@0.2.0/node_modules/package-manager-detector/dist/detect.mjs
326
326
  import fs from "node:fs";
327
327
  import fsPromises from "node:fs/promises";
328
- import path2 from "node:path";
328
+ import path from "node:path";
329
329
  import process2 from "node:process";
330
330
  async function detect({ cwd, onUnknown } = {}) {
331
331
  for (const directory of lookup(cwd)) {
332
332
  for (const lock of Object.keys(LOCKS)) {
333
- if (await fileExists(path2.join(directory, lock))) {
333
+ if (await fileExists(path.join(directory, lock))) {
334
334
  const name = LOCKS[lock];
335
- const result2 = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
335
+ const result2 = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
336
336
  if (result2)
337
337
  return result2;
338
338
  else
339
339
  return { name, agent: name };
340
340
  }
341
341
  }
342
- const result = await parsePackageJson(path2.join(directory, "package.json"), onUnknown);
342
+ const result = await parsePackageJson(path.join(directory, "package.json"), onUnknown);
343
343
  if (result)
344
344
  return result;
345
345
  }
346
346
  return null;
347
347
  }
348
348
  function* lookup(cwd = process2.cwd()) {
349
- let directory = path2.resolve(cwd);
350
- const { root } = path2.parse(directory);
349
+ let directory = path.resolve(cwd);
350
+ const { root } = path.parse(directory);
351
351
  while (directory && directory !== root) {
352
352
  yield directory;
353
- directory = path2.dirname(directory);
353
+ directory = path.dirname(directory);
354
354
  }
355
355
  }
356
356
  async function parsePackageJson(filepath, onUnknown) {
@@ -417,15 +417,16 @@ function runNextBuildCommand(packager, nextAppDir2) {
417
417
  // src/cli/build/build-worker.ts
418
418
  import { build as build2 } from "esbuild";
419
419
  import { cp, readFile, writeFile } from "node:fs/promises";
420
+ import { dirname as dirname2, join as join13 } from "node:path";
420
421
  import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
421
422
 
422
423
  // src/cli/build/patches/investigated/copy-package-cli-files.ts
423
424
  import { cpSync } from "node:fs";
424
- import path3 from "node:path";
425
+ import { join as join2 } from "node:path";
425
426
  function copyPackageCliFiles(packageDistDir2, config) {
426
427
  console.log("# copyPackageTemplateFiles");
427
- const sourceDir = path3.join(packageDistDir2, "cli");
428
- const destinationDir = path3.join(config.paths.internalPackage, "cli");
428
+ const sourceDir = join2(packageDistDir2, "cli");
429
+ const destinationDir = join2(config.paths.internalPackage, "cli");
429
430
  cpSync(sourceDir, destinationDir, { recursive: true });
430
431
  }
431
432
 
@@ -443,16 +444,16 @@ var SEED_DATA_DIR = "cdn-cgi/_cf_seed_data";
443
444
 
444
445
  // src/cli/build/utils/copy-prerendered-routes.ts
445
446
  import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
446
- import { dirname, join as join2 } from "node:path";
447
+ import { dirname, join as join4 } from "node:path";
447
448
 
448
449
  // src/cli/build/utils/read-paths-recursively.ts
449
- import { join } from "node:path";
450
+ import { join as join3 } from "node:path";
450
451
  import { readdirSync as readdirSync2 } from "node:fs";
451
452
  function readPathsRecursively(dir) {
452
453
  try {
453
454
  const files = readdirSync2(dir, { withFileTypes: true });
454
455
  return files.flatMap((file) => {
455
- const filePath = join(dir, file.name);
456
+ const filePath = join3(dir, file.name);
456
457
  return file.isDirectory() ? readPathsRecursively(filePath) : filePath;
457
458
  });
458
459
  } catch {
@@ -463,16 +464,16 @@ function readPathsRecursively(dir) {
463
464
  // src/cli/build/utils/copy-prerendered-routes.ts
464
465
  function copyPrerenderedRoutes(config) {
465
466
  console.log("# copyPrerenderedRoutes");
466
- const serverAppDirPath = join2(config.paths.standaloneAppServer, "app");
467
- const prerenderManifestPath = join2(config.paths.standaloneAppDotNext, "prerender-manifest.json");
468
- const outputPath = join2(config.paths.outputDir, "assets", SEED_DATA_DIR);
467
+ const serverAppDirPath = join4(config.paths.standaloneAppServer, "app");
468
+ const prerenderManifestPath = join4(config.paths.standaloneAppDotNext, "prerender-manifest.json");
469
+ const outputPath = join4(config.paths.outputDir, "assets", SEED_DATA_DIR);
469
470
  const prerenderManifest = existsSync(prerenderManifestPath) ? JSON.parse(readFileSync(prerenderManifestPath, "utf8")) : {};
470
471
  const prerenderedRoutes = Object.keys(prerenderManifest.routes);
471
472
  const prerenderedAssets = readPathsRecursively(serverAppDirPath).map((fullPath) => ({ fullPath, relativePath: fullPath.replace(serverAppDirPath, "") })).filter(
472
473
  ({ relativePath }) => prerenderedRoutes.includes(relativePath.replace(/\.\w+$/, "").replace(/^\/index$/, "/"))
473
474
  );
474
475
  prerenderedAssets.forEach(({ fullPath, relativePath }) => {
475
- const destPath = join2(outputPath, relativePath);
476
+ const destPath = join4(outputPath, relativePath);
476
477
  mkdirSync(dirname(destPath), { recursive: true });
477
478
  if (fullPath.endsWith(NEXT_META_SUFFIX)) {
478
479
  const data = JSON.parse(readFileSync(fullPath, "utf8"));
@@ -483,9 +484,18 @@ function copyPrerenderedRoutes(config) {
483
484
  });
484
485
  }
485
486
 
487
+ // src/cli/build/utils/normalize-path.ts
488
+ import { posix, sep } from "node:path";
489
+ function normalizePath(path3) {
490
+ return path3.replaceAll(sep, posix.sep);
491
+ }
492
+
486
493
  // src/cli/build/build-worker.ts
487
494
  import { fileURLToPath as fileURLToPath3 } from "node:url";
488
495
 
496
+ // src/cli/build/patches/to-investigate/inline-eval-manifest.ts
497
+ import { join as join5, posix as posix3 } from "node:path";
498
+
489
499
  // ../../node_modules/.pnpm/minimatch@10.0.1/node_modules/minimatch/dist/esm/index.js
490
500
  var import_brace_expansion = __toESM(require_brace_expansion(), 1);
491
501
 
@@ -1157,12 +1167,12 @@ var qmarksTestNoExtDot = ([$0]) => {
1157
1167
  return (f) => f.length === len && f !== "." && f !== "..";
1158
1168
  };
1159
1169
  var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
1160
- var path4 = {
1170
+ var path2 = {
1161
1171
  win32: { sep: "\\" },
1162
1172
  posix: { sep: "/" }
1163
1173
  };
1164
- var sep = defaultPlatform === "win32" ? path4.win32.sep : path4.posix.sep;
1165
- minimatch.sep = sep;
1174
+ var sep2 = defaultPlatform === "win32" ? path2.win32.sep : path2.posix.sep;
1175
+ minimatch.sep = sep2;
1166
1176
  var GLOBSTAR = Symbol("globstar **");
1167
1177
  minimatch.GLOBSTAR = GLOBSTAR;
1168
1178
  var qmark2 = "[^/]";
@@ -3189,7 +3199,7 @@ var LRUCache = class _LRUCache {
3189
3199
  };
3190
3200
 
3191
3201
  // ../../node_modules/.pnpm/path-scurry@2.0.0/node_modules/path-scurry/dist/esm/index.js
3192
- import { posix, win32 } from "node:path";
3202
+ import { posix as posix2, win32 } from "node:path";
3193
3203
  import { fileURLToPath } from "node:url";
3194
3204
  import { lstatSync, readdir as readdirCB, readdirSync as readdirSync3, readlinkSync, realpathSync as rps } from "fs";
3195
3205
  import * as actualFS from "node:fs";
@@ -4338,12 +4348,12 @@ var PathBase = class {
4338
4348
  /**
4339
4349
  * Get the Path object referenced by the string path, resolved from this Path
4340
4350
  */
4341
- resolve(path13) {
4342
- if (!path13) {
4351
+ resolve(path3) {
4352
+ if (!path3) {
4343
4353
  return this;
4344
4354
  }
4345
- const rootPath = this.getRootString(path13);
4346
- const dir = path13.substring(rootPath.length);
4355
+ const rootPath = this.getRootString(path3);
4356
+ const dir = path3.substring(rootPath.length);
4347
4357
  const dirParts = dir.split(this.splitSep);
4348
4358
  const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
4349
4359
  return result;
@@ -5095,8 +5105,8 @@ var PathWin32 = class _PathWin32 extends PathBase {
5095
5105
  /**
5096
5106
  * @internal
5097
5107
  */
5098
- getRootString(path13) {
5099
- return win32.parse(path13).root;
5108
+ getRootString(path3) {
5109
+ return win32.parse(path3).root;
5100
5110
  }
5101
5111
  /**
5102
5112
  * @internal
@@ -5142,8 +5152,8 @@ var PathPosix = class _PathPosix extends PathBase {
5142
5152
  /**
5143
5153
  * @internal
5144
5154
  */
5145
- getRootString(path13) {
5146
- return path13.startsWith("/") ? "/" : "";
5155
+ getRootString(path3) {
5156
+ return path3.startsWith("/") ? "/" : "";
5147
5157
  }
5148
5158
  /**
5149
5159
  * @internal
@@ -5192,7 +5202,7 @@ var PathScurryBase = class {
5192
5202
  *
5193
5203
  * @internal
5194
5204
  */
5195
- constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs: fs2 = defaultFS } = {}) {
5205
+ constructor(cwd = process.cwd(), pathImpl, sep3, { nocase, childrenCacheSize = 16 * 1024, fs: fs2 = defaultFS } = {}) {
5196
5206
  this.#fs = fsFromOption(fs2);
5197
5207
  if (cwd instanceof URL || cwd.startsWith("file://")) {
5198
5208
  cwd = fileURLToPath(cwd);
@@ -5203,7 +5213,7 @@ var PathScurryBase = class {
5203
5213
  this.#resolveCache = new ResolveCache();
5204
5214
  this.#resolvePosixCache = new ResolveCache();
5205
5215
  this.#children = new ChildrenCache(childrenCacheSize);
5206
- const split = cwdPath.substring(this.rootPath.length).split(sep2);
5216
+ const split = cwdPath.substring(this.rootPath.length).split(sep3);
5207
5217
  if (split.length === 1 && !split[0]) {
5208
5218
  split.pop();
5209
5219
  }
@@ -5232,11 +5242,11 @@ var PathScurryBase = class {
5232
5242
  /**
5233
5243
  * Get the depth of a provided path, string, or the cwd
5234
5244
  */
5235
- depth(path13 = this.cwd) {
5236
- if (typeof path13 === "string") {
5237
- path13 = this.cwd.resolve(path13);
5245
+ depth(path3 = this.cwd) {
5246
+ if (typeof path3 === "string") {
5247
+ path3 = this.cwd.resolve(path3);
5238
5248
  }
5239
- return path13.depth();
5249
+ return path3.depth();
5240
5250
  }
5241
5251
  /**
5242
5252
  * Return the cache of child entries. Exposed so subclasses can create
@@ -5723,9 +5733,9 @@ var PathScurryBase = class {
5723
5733
  process3();
5724
5734
  return results;
5725
5735
  }
5726
- chdir(path13 = this.cwd) {
5736
+ chdir(path3 = this.cwd) {
5727
5737
  const oldCwd = this.cwd;
5728
- this.cwd = typeof path13 === "string" ? this.cwd.resolve(path13) : path13;
5738
+ this.cwd = typeof path3 === "string" ? this.cwd.resolve(path3) : path3;
5729
5739
  this.cwd[setAsCwd](oldCwd);
5730
5740
  }
5731
5741
  };
@@ -5768,7 +5778,7 @@ var PathScurryPosix = class extends PathScurryBase {
5768
5778
  sep = "/";
5769
5779
  constructor(cwd = process.cwd(), opts = {}) {
5770
5780
  const { nocase = false } = opts;
5771
- super(cwd, posix, "/", { ...opts, nocase });
5781
+ super(cwd, posix2, "/", { ...opts, nocase });
5772
5782
  this.nocase = nocase;
5773
5783
  }
5774
5784
  /**
@@ -6081,8 +6091,8 @@ var MatchRecord = class {
6081
6091
  }
6082
6092
  // match, absolute, ifdir
6083
6093
  entries() {
6084
- return [...this.store.entries()].map(([path13, n]) => [
6085
- path13,
6094
+ return [...this.store.entries()].map(([path3, n]) => [
6095
+ path3,
6086
6096
  !!(n & 2),
6087
6097
  !!(n & 1)
6088
6098
  ]);
@@ -6287,9 +6297,9 @@ var GlobUtil = class {
6287
6297
  signal;
6288
6298
  maxDepth;
6289
6299
  includeChildMatches;
6290
- constructor(patterns, path13, opts) {
6300
+ constructor(patterns, path3, opts) {
6291
6301
  this.patterns = patterns;
6292
- this.path = path13;
6302
+ this.path = path3;
6293
6303
  this.opts = opts;
6294
6304
  this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
6295
6305
  this.includeChildMatches = opts.includeChildMatches !== false;
@@ -6308,11 +6318,11 @@ var GlobUtil = class {
6308
6318
  });
6309
6319
  }
6310
6320
  }
6311
- #ignored(path13) {
6312
- return this.seen.has(path13) || !!this.#ignore?.ignored?.(path13);
6321
+ #ignored(path3) {
6322
+ return this.seen.has(path3) || !!this.#ignore?.ignored?.(path3);
6313
6323
  }
6314
- #childrenIgnored(path13) {
6315
- return !!this.#ignore?.childrenIgnored?.(path13);
6324
+ #childrenIgnored(path3) {
6325
+ return !!this.#ignore?.childrenIgnored?.(path3);
6316
6326
  }
6317
6327
  // backpressure mechanism
6318
6328
  pause() {
@@ -6527,8 +6537,8 @@ var GlobUtil = class {
6527
6537
  };
6528
6538
  var GlobWalker = class extends GlobUtil {
6529
6539
  matches = /* @__PURE__ */ new Set();
6530
- constructor(patterns, path13, opts) {
6531
- super(patterns, path13, opts);
6540
+ constructor(patterns, path3, opts) {
6541
+ super(patterns, path3, opts);
6532
6542
  }
6533
6543
  matchEmit(e) {
6534
6544
  this.matches.add(e);
@@ -6565,8 +6575,8 @@ var GlobWalker = class extends GlobUtil {
6565
6575
  };
6566
6576
  var GlobStream = class extends GlobUtil {
6567
6577
  results;
6568
- constructor(patterns, path13, opts) {
6569
- super(patterns, path13, opts);
6578
+ constructor(patterns, path3, opts) {
6579
+ super(patterns, path3, opts);
6570
6580
  this.results = new Minipass({
6571
6581
  signal: this.signal,
6572
6582
  objectMode: true
@@ -6860,21 +6870,18 @@ var glob = Object.assign(glob_, {
6860
6870
  glob.glob = glob;
6861
6871
 
6862
6872
  // src/cli/build/patches/to-investigate/inline-eval-manifest.ts
6863
- import path5 from "node:path";
6864
6873
  function inlineEvalManifest(code, config) {
6865
6874
  console.log("# inlineEvalManifest");
6866
6875
  const manifestJss = globSync(
6867
- path5.join(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js").replaceAll(path5.sep, path5.posix.sep)
6868
- ).map(
6869
- (file) => file.replaceAll(path5.sep, path5.posix.sep).replace(config.paths.standaloneApp.replaceAll(path5.sep, path5.posix.sep) + path5.posix.sep, "")
6870
- );
6876
+ normalizePath(join5(config.paths.standaloneAppDotNext, "**", "*_client-reference-manifest.js"))
6877
+ ).map((file) => normalizePath(file).replace(normalizePath(config.paths.standaloneApp) + posix3.sep, ""));
6871
6878
  return code.replace(
6872
6879
  /function evalManifest\((.+?), .+?\) {/,
6873
6880
  `$&
6874
6881
  ${manifestJss.map(
6875
6882
  (manifestJs) => `
6876
6883
  if ($1.endsWith("${manifestJs}")) {
6877
- require(${JSON.stringify(path5.join(config.paths.standaloneApp, manifestJs))});
6884
+ require(${JSON.stringify(join5(config.paths.standaloneApp, manifestJs))});
6878
6885
  return {
6879
6886
  __RSC_MANIFEST: {
6880
6887
  "${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}": globalThis.__RSC_MANIFEST["${manifestJs.replace(".next/server/app", "").replace("_client-reference-manifest.js", "")}"],
@@ -6890,10 +6897,10 @@ function inlineEvalManifest(code, config) {
6890
6897
 
6891
6898
  // src/cli/build/patches/to-investigate/inline-middleware-manifest-require.ts
6892
6899
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
6893
- import path6 from "node:path";
6900
+ import { join as join6 } from "node:path";
6894
6901
  function inlineMiddlewareManifestRequire(code, config) {
6895
6902
  console.log("# inlineMiddlewareManifestRequire");
6896
- const middlewareManifestPath = path6.join(config.paths.standaloneAppServer, "middleware-manifest.json");
6903
+ const middlewareManifestPath = join6(config.paths.standaloneAppServer, "middleware-manifest.json");
6897
6904
  const middlewareManifest = existsSync2(middlewareManifestPath) ? JSON.parse(readFileSync2(middlewareManifestPath, "utf-8")) : {};
6898
6905
  const patchedCode = code.replace(
6899
6906
  "require(this.middlewareManifestPath)",
@@ -6907,11 +6914,11 @@ function inlineMiddlewareManifestRequire(code, config) {
6907
6914
 
6908
6915
  // src/cli/build/patches/to-investigate/inline-next-require.ts
6909
6916
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
6910
- import path7 from "node:path";
6917
+ import { join as join7 } from "node:path";
6911
6918
  function inlineNextRequire(code, config) {
6912
6919
  console.log("# inlineNextRequire");
6913
- const pagesManifestFile = path7.join(config.paths.standaloneAppServer, "pages-manifest.json");
6914
- const appPathsManifestFile = path7.join(config.paths.standaloneAppServer, "app-paths-manifest.json");
6920
+ const pagesManifestFile = join7(config.paths.standaloneAppServer, "pages-manifest.json");
6921
+ const appPathsManifestFile = join7(config.paths.standaloneAppServer, "app-paths-manifest.json");
6915
6922
  const pagesManifestFiles = existsSync3(pagesManifestFile) ? Object.values(JSON.parse(readFileSync3(pagesManifestFile, "utf-8"))).map(
6916
6923
  (file) => ".next/server/" + file
6917
6924
  ) : [];
@@ -6927,14 +6934,14 @@ function inlineNextRequire(code, config) {
6927
6934
  ${htmlPages.map(
6928
6935
  (htmlPage) => `
6929
6936
  if (pagePath.endsWith("${htmlPage}")) {
6930
- return ${JSON.stringify(readFileSync3(path7.join(config.paths.standaloneApp, htmlPage), "utf-8"))};
6937
+ return ${JSON.stringify(readFileSync3(join7(config.paths.standaloneApp, htmlPage), "utf-8"))};
6931
6938
  }
6932
6939
  `
6933
6940
  ).join("\n")}
6934
6941
  ${pageModules.map(
6935
6942
  (module) => `
6936
6943
  if (pagePath.endsWith("${module}")) {
6937
- return require(${JSON.stringify(path7.join(config.paths.standaloneApp, module))});
6944
+ return require(${JSON.stringify(join7(config.paths.standaloneApp, module))});
6938
6945
  }
6939
6946
  `
6940
6947
  ).join("\n")}
@@ -6945,12 +6952,12 @@ function inlineNextRequire(code, config) {
6945
6952
 
6946
6953
  // src/cli/build/patches/investigated/patch-cache.ts
6947
6954
  import { build } from "esbuild";
6948
- import { join as join3 } from "node:path";
6955
+ import { join as join8 } from "node:path";
6949
6956
  async function patchCache(code, config) {
6950
6957
  console.log("# patchCache");
6951
6958
  const cacheHandlerFileName = "cache-handler.mjs";
6952
- const cacheHandlerEntrypoint = join3(config.paths.internalTemplates, "cache-handler", "index.ts");
6953
- const cacheHandlerOutputFile = join3(config.paths.outputDir, cacheHandlerFileName);
6959
+ const cacheHandlerEntrypoint = join8(config.paths.internalTemplates, "cache-handler", "index.ts");
6960
+ const cacheHandlerOutputFile = join8(config.paths.outputDir, cacheHandlerFileName);
6954
6961
  await build({
6955
6962
  entryPoints: [cacheHandlerEntrypoint],
6956
6963
  bundle: true,
@@ -6986,7 +6993,7 @@ function patchExceptionBubbling(code) {
6986
6993
 
6987
6994
  // src/cli/build/patches/to-investigate/patch-find-dir.ts
6988
6995
  import { existsSync as existsSync4 } from "node:fs";
6989
- import path8 from "node:path";
6996
+ import { join as join9 } from "node:path";
6990
6997
  function patchFindDir(code, config) {
6991
6998
  console.log("# patchFindDir");
6992
6999
  return code.replace(
@@ -6994,10 +7001,10 @@ function patchFindDir(code, config) {
6994
7001
  `function findDir(dir, name) {
6995
7002
  if (dir.endsWith(".next/server")) {
6996
7003
  if (name === "app") {
6997
- return ${existsSync4(`${path8.join(config.paths.standaloneAppServer, "app")}`)};
7004
+ return ${existsSync4(`${join9(config.paths.standaloneAppServer, "app")}`)};
6998
7005
  }
6999
7006
  if (name === "pages") {
7000
- return ${existsSync4(`${path8.join(config.paths.standaloneAppServer, "pages")}`)};
7007
+ return ${existsSync4(`${join9(config.paths.standaloneAppServer, "pages")}`)};
7001
7008
  }
7002
7009
  }
7003
7010
  throw new Error("Unknown findDir call: " + dir + " " + name);
@@ -7006,28 +7013,26 @@ function patchFindDir(code, config) {
7006
7013
  }
7007
7014
 
7008
7015
  // src/cli/build/patches/to-investigate/patch-read-file.ts
7009
- import path9 from "node:path";
7016
+ import { join as join10, posix as posix4 } from "node:path";
7010
7017
  import { readFileSync as readFileSync4 } from "node:fs";
7011
7018
  function patchReadFile(code, config) {
7012
7019
  console.log("# patchReadFile");
7013
7020
  code = code.replace(
7014
7021
  "getBuildId() {",
7015
7022
  `getBuildId() {
7016
- return ${JSON.stringify(readFileSync4(path9.join(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
7023
+ return ${JSON.stringify(readFileSync4(join10(config.paths.standaloneAppDotNext, "BUILD_ID"), "utf-8"))};
7017
7024
  `
7018
7025
  );
7019
7026
  const manifestJsons = globSync(
7020
- path9.join(config.paths.standaloneAppDotNext, "**", "*-manifest.json").replaceAll(path9.sep, path9.posix.sep)
7021
- ).map(
7022
- (file) => file.replaceAll(path9.sep, path9.posix.sep).replace(config.paths.standaloneApp.replaceAll(path9.sep, path9.posix.sep) + path9.posix.sep, "")
7023
- );
7027
+ normalizePath(join10(config.paths.standaloneAppDotNext, "**", "*-manifest.json"))
7028
+ ).map((file) => normalizePath(file).replace(normalizePath(config.paths.standaloneApp) + posix4.sep, ""));
7024
7029
  code = code.replace(
7025
7030
  /function loadManifest\((.+?), .+?\) {/,
7026
7031
  `$&
7027
7032
  ${manifestJsons.map(
7028
7033
  (manifestJson) => `
7029
7034
  if ($1.endsWith("${manifestJson}")) {
7030
- return ${readFileSync4(path9.join(config.paths.standaloneApp, manifestJson), "utf-8")};
7035
+ return ${readFileSync4(join10(config.paths.standaloneApp, manifestJson), "utf-8")};
7031
7036
  }
7032
7037
  `
7033
7038
  ).join("\n")}
@@ -7045,17 +7050,17 @@ function patchRequire(code) {
7045
7050
 
7046
7051
  // src/cli/build/patches/to-investigate/wrangler-deps.ts
7047
7052
  import { readFileSync as readFileSync5, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
7048
- import path10 from "node:path";
7053
+ import { join as join11 } from "node:path";
7049
7054
  function patchWranglerDeps(config) {
7050
7055
  console.log("# patchWranglerDeps");
7051
7056
  const distPath = getDistPath(config);
7052
- const pagesRuntimeFile = path10.join(distPath, "compiled", "next-server", "pages.runtime.prod.js");
7057
+ const pagesRuntimeFile = join11(distPath, "compiled", "next-server", "pages.runtime.prod.js");
7053
7058
  const patchedPagesRuntime = readFileSync5(pagesRuntimeFile, "utf-8").replace(
7054
7059
  `e.exports=require("critters")`,
7055
7060
  `e.exports={}`
7056
7061
  );
7057
7062
  writeFileSync2(pagesRuntimeFile, patchedPagesRuntime);
7058
- const tracerFile = path10.join(distPath, "server", "lib", "trace", "tracer.js");
7063
+ const tracerFile = join11(distPath, "server", "lib", "trace", "tracer.js");
7059
7064
  const patchedTracer = readFileSync5(tracerFile, "utf-8").replaceAll(
7060
7065
  /\w+\s*=\s*require\([^/]*opentelemetry.*\)/g,
7061
7066
  `throw new Error("@opentelemetry/api")`
@@ -7065,7 +7070,7 @@ function patchWranglerDeps(config) {
7065
7070
  function getDistPath(config) {
7066
7071
  for (const root of [config.paths.standaloneApp, config.paths.standaloneRoot]) {
7067
7072
  try {
7068
- const distPath = path10.join(root, "node_modules", "next", "dist");
7073
+ const distPath = join11(root, "node_modules", "next", "dist");
7069
7074
  if (statSync2(distPath).isDirectory()) return distPath;
7070
7075
  } catch {
7071
7076
  }
@@ -7073,9 +7078,6 @@ function getDistPath(config) {
7073
7078
  throw new Error("Unexpected error: unable to detect the node_modules/next/dist directory");
7074
7079
  }
7075
7080
 
7076
- // src/cli/build/build-worker.ts
7077
- import path12 from "node:path";
7078
-
7079
7081
  // src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
7080
7082
  import { readFileSync as readFileSync6, readdirSync as readdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
7081
7083
 
@@ -7182,12 +7184,12 @@ async function getUpdatedWebpackChunksFileContent(fileContent, chunks) {
7182
7184
  }
7183
7185
 
7184
7186
  // src/cli/build/patches/investigated/update-webpack-chunks-file/index.ts
7185
- import path11 from "node:path";
7187
+ import { join as join12 } from "node:path";
7186
7188
  async function updateWebpackChunksFile(config) {
7187
7189
  console.log("# updateWebpackChunksFile");
7188
- const webpackRuntimeFile = path11.join(config.paths.standaloneAppServer, "webpack-runtime.js");
7190
+ const webpackRuntimeFile = join12(config.paths.standaloneAppServer, "webpack-runtime.js");
7189
7191
  const fileContent = readFileSync6(webpackRuntimeFile, "utf-8");
7190
- const chunks = readdirSync4(path11.join(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
7192
+ const chunks = readdirSync4(join12(config.paths.standaloneAppServer, "chunks")).filter((chunk) => /^\d+\.js$/.test(chunk)).map((chunk) => {
7191
7193
  console.log(` - chunk ${chunk}`);
7192
7194
  return chunk.replace(/\.js$/, "");
7193
7195
  });
@@ -7196,28 +7198,24 @@ async function updateWebpackChunksFile(config) {
7196
7198
  }
7197
7199
 
7198
7200
  // src/cli/build/build-worker.ts
7199
- var packageDistDir = path12.join(path12.dirname(fileURLToPath3(import.meta.url)), "..");
7201
+ var packageDistDir = join13(dirname2(fileURLToPath3(import.meta.url)), "..");
7200
7202
  async function buildWorker(config) {
7201
7203
  console.log(`\x1B[35m\u2699\uFE0F Copying files...
7202
7204
  \x1B[0m`);
7203
- await cp(
7204
- path12.join(config.paths.dotNext, "static"),
7205
- path12.join(config.paths.outputDir, "assets", "_next", "static"),
7206
- {
7207
- recursive: true
7208
- }
7209
- );
7210
- const publicDir = path12.join(config.paths.sourceDir, "public");
7205
+ await cp(join13(config.paths.dotNext, "static"), join13(config.paths.outputDir, "assets", "_next", "static"), {
7206
+ recursive: true
7207
+ });
7208
+ const publicDir = join13(config.paths.sourceDir, "public");
7211
7209
  if (existsSync5(publicDir)) {
7212
- await cp(publicDir, path12.join(config.paths.outputDir, "assets"), {
7210
+ await cp(publicDir, join13(config.paths.outputDir, "assets"), {
7213
7211
  recursive: true
7214
7212
  });
7215
7213
  }
7216
7214
  copyPrerenderedRoutes(config);
7217
7215
  copyPackageCliFiles(packageDistDir, config);
7218
- const workerEntrypoint = path12.join(config.paths.internalTemplates, "worker.ts");
7219
- const workerOutputFile = path12.join(config.paths.outputDir, "index.mjs");
7220
- const nextConfigStr = readFileSync7(path12.join(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
7216
+ const workerEntrypoint = join13(config.paths.internalTemplates, "worker.ts");
7217
+ const workerOutputFile = join13(config.paths.outputDir, "index.mjs");
7218
+ const nextConfigStr = readFileSync7(join13(config.paths.standaloneApp, "/server.js"), "utf8")?.match(
7221
7219
  /const nextConfig = ({.+?})\n/
7222
7220
  )?.[1] ?? {};
7223
7221
  console.log(`\x1B[35m\u2699\uFE0F Bundling the worker file...
@@ -7236,15 +7234,15 @@ async function buildWorker(config) {
7236
7234
  // Note: we apply an empty shim to next/dist/compiled/ws because it generates two `eval`s:
7237
7235
  // eval("require")("bufferutil");
7238
7236
  // eval("require")("utf-8-validate");
7239
- "next/dist/compiled/ws": path12.join(config.paths.internalTemplates, "shims", "empty.ts"),
7237
+ "next/dist/compiled/ws": join13(config.paths.internalTemplates, "shims", "empty.ts"),
7240
7238
  // Note: we apply an empty shim to next/dist/compiled/edge-runtime since (amongst others) it generated the following `eval`:
7241
7239
  // eval(getModuleCode)(module, module.exports, throwingRequire, params.context, ...Object.values(params.scopedContext));
7242
7240
  // which comes from https://github.com/vercel/edge-runtime/blob/6e96b55f/packages/primitives/src/primitives/load.js#L57-L63
7243
7241
  // QUESTION: Why did I encountered this but mhart didn't?
7244
- "next/dist/compiled/edge-runtime": path12.join(config.paths.internalTemplates, "shims", "empty.ts"),
7242
+ "next/dist/compiled/edge-runtime": join13(config.paths.internalTemplates, "shims", "empty.ts"),
7245
7243
  // `@next/env` is a library Next.js uses for loading dotenv files, for obvious reasons we need to stub it here
7246
7244
  // source: https://github.com/vercel/next.js/tree/0ac10d79720/packages/next-env
7247
- "@next/env": path12.join(config.paths.internalTemplates, "shims", "env.ts")
7245
+ "@next/env": join13(config.paths.internalTemplates, "shims", "env.ts")
7248
7246
  },
7249
7247
  define: {
7250
7248
  // config file used by Next.js, see: https://github.com/vercel/next.js/blob/68a7128/packages/next/src/build/utils.ts#L2137-L2139
@@ -7322,10 +7320,10 @@ function createFixRequiresESBuildPlugin(config) {
7322
7320
  name: "replaceRelative",
7323
7321
  setup(build4) {
7324
7322
  build4.onResolve({ filter: /^\.\/require-hook$/ }, () => ({
7325
- path: path12.join(config.paths.internalTemplates, "shims", "empty.ts")
7323
+ path: join13(config.paths.internalTemplates, "shims", "empty.ts")
7326
7324
  }));
7327
7325
  build4.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, () => ({
7328
- path: path12.join(config.paths.internalTemplates, "shims", "empty.ts")
7326
+ path: join13(config.paths.internalTemplates, "shims", "empty.ts")
7329
7327
  }));
7330
7328
  }
7331
7329
  };
@@ -7333,7 +7331,7 @@ function createFixRequiresESBuildPlugin(config) {
7333
7331
 
7334
7332
  // src/cli/build/index.ts
7335
7333
  import { cpSync as cpSync2 } from "node:fs";
7336
- import { join as join4 } from "node:path";
7334
+ import { join as join14 } from "node:path";
7337
7335
  import { rm } from "node:fs/promises";
7338
7336
  async function build3(projectOpts) {
7339
7337
  if (!projectOpts.skipNextBuild) {
@@ -7343,12 +7341,12 @@ async function build3(projectOpts) {
7343
7341
  throw new Error(`.next folder not found in ${projectOpts.sourceDir}`);
7344
7342
  }
7345
7343
  await cleanDirectory(projectOpts.outputDir);
7346
- cpSync2(join4(projectOpts.sourceDir, ".next"), join4(projectOpts.outputDir, ".next"), { recursive: true });
7344
+ cpSync2(join14(projectOpts.sourceDir, ".next"), join14(projectOpts.outputDir, ".next"), { recursive: true });
7347
7345
  const config = getConfig(projectOpts);
7348
7346
  await buildWorker(config);
7349
7347
  }
7350
- async function cleanDirectory(path13) {
7351
- return await rm(path13, { recursive: true, force: true });
7348
+ async function cleanDirectory(path3) {
7349
+ return await rm(path3, { recursive: true, force: true });
7352
7350
  }
7353
7351
 
7354
7352
  // src/cli/index.ts
@@ -7389,15 +7387,15 @@ function getArgs() {
7389
7387
  minify: !noMinify
7390
7388
  };
7391
7389
  }
7392
- function assertDirArg(path13, argName, make) {
7390
+ function assertDirArg(path3, argName, make) {
7393
7391
  let dirStats;
7394
7392
  try {
7395
- dirStats = statSync3(path13);
7393
+ dirStats = statSync3(path3);
7396
7394
  } catch {
7397
7395
  if (!make) {
7398
7396
  throw new Error(`Error: the provided${argName ? ` "${argName}"` : ""} input is not a valid path`);
7399
7397
  }
7400
- mkdirSync2(path13);
7398
+ mkdirSync2(path3);
7401
7399
  return;
7402
7400
  }
7403
7401
  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.2.0",
4
+ "version": "0.2.1",
5
5
  "bin": "dist/cli/index.mjs",
6
6
  "main": "./dist/api/index.mjs",
7
7
  "types": "./dist/api/index.d.mts",