wrangler 2.8.0 → 2.8.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 (44) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +12 -8
  3. package/src/__tests__/deployments.test.ts +4 -4
  4. package/src/__tests__/helpers/msw/handlers/deployments.ts +10 -18
  5. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  6. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  7. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  8. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  9. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  10. package/src/__tests__/pages.test.ts +34 -37
  11. package/src/__tests__/publish.test.ts +126 -0
  12. package/src/__tests__/r2.test.ts +11 -35
  13. package/src/__tests__/tail.test.ts +6 -18
  14. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  15. package/src/__tests__/user.test.ts +0 -1
  16. package/src/__tests__/whoami.test.tsx +6 -17
  17. package/src/__tests__/worker-namespace.test.ts +56 -48
  18. package/src/api/index.ts +1 -0
  19. package/src/api/pages/index.ts +5 -0
  20. package/src/api/pages/publish.tsx +321 -0
  21. package/src/bundle.ts +62 -10
  22. package/src/cli.ts +2 -2
  23. package/src/config/environment.ts +12 -10
  24. package/src/d1/utils.ts +1 -1
  25. package/src/deployments.ts +16 -6
  26. package/src/dev/local.tsx +1 -10
  27. package/src/dev/start-server.ts +5 -10
  28. package/src/dev/use-esbuild.ts +1 -0
  29. package/src/entry.ts +1 -2
  30. package/src/index.ts +1 -1
  31. package/src/metrics/send-event.ts +2 -1
  32. package/src/pages/build.ts +4 -124
  33. package/src/pages/buildFunctions.ts +129 -0
  34. package/src/pages/dev.ts +12 -2
  35. package/src/pages/functions/buildPlugin.ts +1 -0
  36. package/src/pages/functions/buildWorker.ts +8 -2
  37. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  38. package/src/pages/publish.tsx +9 -235
  39. package/src/publish/publish.ts +1 -0
  40. package/templates/d1-beta-facade.js +1 -1
  41. package/templates/middleware/loader-modules.ts +2 -0
  42. package/templates/tsconfig.tsbuildinfo +1 -1
  43. package/wrangler-dist/cli.d.ts +132 -10
  44. package/wrangler-dist/cli.js +486 -388
@@ -18797,7 +18797,7 @@ var require_lodash = __commonJS({
18797
18797
  }
18798
18798
  return mapped.length && mapped[0] === arrays[0] ? baseIntersection(mapped, undefined2, comparator) : [];
18799
18799
  });
18800
- function join13(array, separator) {
18800
+ function join12(array, separator) {
18801
18801
  return array == null ? "" : nativeJoin.call(array, separator);
18802
18802
  }
18803
18803
  function last(array) {
@@ -20716,7 +20716,7 @@ var require_lodash = __commonJS({
20716
20716
  lodash.isUndefined = isUndefined;
20717
20717
  lodash.isWeakMap = isWeakMap;
20718
20718
  lodash.isWeakSet = isWeakSet;
20719
- lodash.join = join13;
20719
+ lodash.join = join12;
20720
20720
  lodash.kebabCase = kebabCase;
20721
20721
  lodash.last = last;
20722
20722
  lodash.lastIndexOf = lastIndexOf;
@@ -78601,7 +78601,7 @@ var require_view = __commonJS({
78601
78601
  var dirname12 = path41.dirname;
78602
78602
  var basename5 = path41.basename;
78603
78603
  var extname5 = path41.extname;
78604
- var join13 = path41.join;
78604
+ var join12 = path41.join;
78605
78605
  var resolve16 = path41.resolve;
78606
78606
  module2.exports = View;
78607
78607
  function View(name, options6) {
@@ -78649,12 +78649,12 @@ var require_view = __commonJS({
78649
78649
  };
78650
78650
  View.prototype.resolve = function resolve17(dir, file) {
78651
78651
  var ext = this.ext;
78652
- var path42 = join13(dir, file);
78652
+ var path42 = join12(dir, file);
78653
78653
  var stat3 = tryStat(path42);
78654
78654
  if (stat3 && stat3.isFile()) {
78655
78655
  return path42;
78656
78656
  }
78657
- path42 = join13(dir, basename5(file, ext), "index" + ext);
78657
+ path42 = join12(dir, basename5(file, ext), "index" + ext);
78658
78658
  stat3 = tryStat(path42);
78659
78659
  if (stat3 && stat3.isFile()) {
78660
78660
  return path42;
@@ -79789,7 +79789,7 @@ var require_send = __commonJS({
79789
79789
  var Stream = require("stream");
79790
79790
  var util3 = require("util");
79791
79791
  var extname5 = path41.extname;
79792
- var join13 = path41.join;
79792
+ var join12 = path41.join;
79793
79793
  var normalize2 = path41.normalize;
79794
79794
  var resolve16 = path41.resolve;
79795
79795
  var sep2 = path41.sep;
@@ -80008,7 +80008,7 @@ var require_send = __commonJS({
80008
80008
  return res;
80009
80009
  }
80010
80010
  parts = path42.split(sep2);
80011
- path42 = normalize2(join13(root, path42));
80011
+ path42 = normalize2(join12(root, path42));
80012
80012
  } else {
80013
80013
  if (UP_PATH_REGEXP.test(path42)) {
80014
80014
  debug('malicious path "%s"', path42);
@@ -80149,7 +80149,7 @@ var require_send = __commonJS({
80149
80149
  return self2.onStatError(err);
80150
80150
  return self2.error(404);
80151
80151
  }
80152
- var p = join13(path42, self2._index[i]);
80152
+ var p = join12(path42, self2._index[i]);
80153
80153
  debug('stat "%s"', p);
80154
80154
  fs18.stat(p, function(err2, stat3) {
80155
80155
  if (err2)
@@ -114586,7 +114586,7 @@ var require_rc = __commonJS({
114586
114586
  "../../node_modules/rc/index.js"(exports2, module2) {
114587
114587
  init_import_meta_url();
114588
114588
  var cc = require_utils6();
114589
- var join13 = require("path").join;
114589
+ var join12 = require("path").join;
114590
114590
  var deepExtend = require_deep_extend();
114591
114591
  var etc = "/etc";
114592
114592
  var win = process.platform === "win32";
@@ -114612,15 +114612,15 @@ var require_rc = __commonJS({
114612
114612
  }
114613
114613
  if (!win)
114614
114614
  [
114615
- join13(etc, name, "config"),
114616
- join13(etc, name + "rc")
114615
+ join12(etc, name, "config"),
114616
+ join12(etc, name + "rc")
114617
114617
  ].forEach(addConfigFile);
114618
114618
  if (home)
114619
114619
  [
114620
- join13(home, ".config", name, "config"),
114621
- join13(home, ".config", name),
114622
- join13(home, "." + name, "config"),
114623
- join13(home, "." + name + "rc")
114620
+ join12(home, ".config", name, "config"),
114621
+ join12(home, ".config", name),
114622
+ join12(home, "." + name, "config"),
114623
+ join12(home, "." + name + "rc")
114624
114624
  ].forEach(addConfigFile);
114625
114625
  addConfigFile(cc.find("." + name + "rc"));
114626
114626
  if (env5.config)
@@ -114823,19 +114823,19 @@ var require_update_check = __commonJS({
114823
114823
  "../../node_modules/update-check/index.js"(exports2, module2) {
114824
114824
  init_import_meta_url();
114825
114825
  var { URL: URL4 } = require("url");
114826
- var { join: join13 } = require("path");
114826
+ var { join: join12 } = require("path");
114827
114827
  var fs18 = require("fs");
114828
114828
  var { promisify: promisify2 } = require("util");
114829
114829
  var { tmpdir: tmpdir4 } = require("os");
114830
114830
  var registryUrl = require_registry_url();
114831
- var writeFile6 = promisify2(fs18.writeFile);
114831
+ var writeFile4 = promisify2(fs18.writeFile);
114832
114832
  var mkdir4 = promisify2(fs18.mkdir);
114833
114833
  var readFile7 = promisify2(fs18.readFile);
114834
114834
  var compareVersions = (a, b) => a.localeCompare(b, "en-US", { numeric: true });
114835
114835
  var encode = (value) => encodeURIComponent(value).replace(/^%40/, "@");
114836
114836
  var getFile = async (details, distTag) => {
114837
114837
  const rootDir = tmpdir4();
114838
- const subDir = join13(rootDir, "update-check");
114838
+ const subDir = join12(rootDir, "update-check");
114839
114839
  if (!fs18.existsSync(subDir)) {
114840
114840
  await mkdir4(subDir);
114841
114841
  }
@@ -114843,7 +114843,7 @@ var require_update_check = __commonJS({
114843
114843
  if (details.scope) {
114844
114844
  name = `${details.scope}-${name}`;
114845
114845
  }
114846
- return join13(subDir, name);
114846
+ return join12(subDir, name);
114847
114847
  };
114848
114848
  var evaluateCache = async (file, time, interval2) => {
114849
114849
  if (fs18.existsSync(file)) {
@@ -114867,7 +114867,7 @@ var require_update_check = __commonJS({
114867
114867
  latest,
114868
114868
  lastUpdate
114869
114869
  });
114870
- await writeFile6(file, content, "utf8");
114870
+ await writeFile4(file, content, "utf8");
114871
114871
  };
114872
114872
  var loadPackage = (url3, authInfo) => new Promise((resolve16, reject) => {
114873
114873
  const options6 = {
@@ -114976,7 +114976,8 @@ var require_update_check = __commonJS({
114976
114976
  // src/cli.ts
114977
114977
  var cli_exports = {};
114978
114978
  __export(cli_exports, {
114979
- unstable_dev: () => unstable_dev
114979
+ unstable_dev: () => unstable_dev,
114980
+ unstable_pages: () => unstable_pages
114980
114981
  });
114981
114982
  module.exports = __toCommonJS(cli_exports);
114982
114983
  init_import_meta_url();
@@ -116638,7 +116639,7 @@ var import_undici13 = __toESM(require_undici());
116638
116639
 
116639
116640
  // src/dev.tsx
116640
116641
  init_import_meta_url();
116641
- var import_node_path39 = __toESM(require("node:path"));
116642
+ var import_node_path40 = __toESM(require("node:path"));
116642
116643
  var import_chalk10 = __toESM(require_chalk());
116643
116644
  var import_chokidar5 = require("chokidar");
116644
116645
 
@@ -121172,7 +121173,7 @@ var import_websocket_server = __toESM(require_websocket_server2(), 1);
121172
121173
  var wrapper_default = import_websocket.default;
121173
121174
 
121174
121175
  // package.json
121175
- var version = "2.8.0";
121176
+ var version = "2.8.1";
121176
121177
  var package_default = {
121177
121178
  name: "wrangler",
121178
121179
  version,
@@ -124166,12 +124167,6 @@ function useLocalWorker({
124166
124167
  async function startLocalWorker() {
124167
124168
  if (!bundle || !format6)
124168
124169
  return;
124169
- for (const module2 of bundle.modules) {
124170
- await (0, import_promises3.writeFile)(
124171
- import_node_path17.default.join(import_node_path17.default.dirname(bundle.path), module2.name),
124172
- module2.content
124173
- );
124174
- }
124175
124170
  const scriptPath = (0, import_node_fs8.realpathSync)(bundle.path);
124176
124171
  const upstream = typeof localUpstream === "string" ? `${localProtocol}://${localUpstream}` : void 0;
124177
124172
  const {
@@ -125120,6 +125115,7 @@ async function bundleWorker(entry, destination, options6) {
125120
125115
  const {
125121
125116
  serveAssetsFromWorker,
125122
125117
  betaD1Shims,
125118
+ doBindings,
125123
125119
  jsxFactory,
125124
125120
  jsxFragment,
125125
125121
  rules,
@@ -125208,7 +125204,13 @@ async function bundleWorker(entry, destination, options6) {
125208
125204
  return applyFirstPartyWorkerDevFacade(currentEntry, tmpDir.path);
125209
125205
  }),
125210
125206
  Array.isArray(betaD1Shims) && betaD1Shims.length > 0 && ((currentEntry) => {
125211
- return applyD1BetaFacade(currentEntry, tmpDir.path, betaD1Shims, local);
125207
+ return applyD1BetaFacade(
125208
+ currentEntry,
125209
+ tmpDir.path,
125210
+ betaD1Shims,
125211
+ local,
125212
+ doBindings
125213
+ );
125212
125214
  }),
125213
125215
  (middlewareToLoad.filter(
125214
125216
  (m) => m.publish && targetConsumer === "publish" || m.dev !== false && targetConsumer === "dev"
@@ -125298,13 +125300,20 @@ async function bundleWorker(entry, destination, options6) {
125298
125300
  const sourceMapPath = Object.keys(result.metafile.outputs).filter(
125299
125301
  (_path) => _path.includes(".map")
125300
125302
  )[0];
125303
+ const resolvedEntryPointPath = path16.resolve(
125304
+ entry.directory,
125305
+ entryPointOutputs[0][0]
125306
+ );
125307
+ for (const module2 of moduleCollector.modules) {
125308
+ fs6.writeFileSync(
125309
+ path16.join(path16.dirname(resolvedEntryPointPath), module2.name),
125310
+ module2.content
125311
+ );
125312
+ }
125301
125313
  return {
125302
125314
  modules: moduleCollector.modules,
125303
125315
  dependencies,
125304
- resolvedEntryPointPath: path16.resolve(
125305
- entry.directory,
125306
- entryPointOutputs[0][0]
125307
- ),
125316
+ resolvedEntryPointPath,
125308
125317
  bundleType,
125309
125318
  stop: result.stop,
125310
125319
  sourceMapPath
@@ -125570,10 +125579,36 @@ async function applyFirstPartyWorkerDevFacade(entry, tmpDirPath) {
125570
125579
  file: targetPath
125571
125580
  };
125572
125581
  }
125573
- async function applyD1BetaFacade(entry, tmpDirPath, betaD1Shims, local) {
125582
+ async function applyD1BetaFacade(entry, tmpDirPath, betaD1Shims, local, doBindings) {
125583
+ let entrypointPath = path16.resolve(
125584
+ getBasePath(),
125585
+ "templates/d1-beta-facade.js"
125586
+ );
125587
+ if (Array.isArray(doBindings) && doBindings.length > 0) {
125588
+ const maskedDoBindings = doBindings.filter((b) => !b.script_name).map(
125589
+ (b) => `export const ${b.class_name} = maskDurableObjectDefinition(OTHER_EXPORTS.${b.class_name});`
125590
+ ).join("\n");
125591
+ const baseFile = fs6.readFileSync(
125592
+ path16.resolve(getBasePath(), "templates/d1-beta-facade.js"),
125593
+ "utf8"
125594
+ );
125595
+ const contents = `
125596
+ ${baseFile}
125597
+
125598
+ var maskDurableObjectDefinition = (cls) =>
125599
+ class extends cls {
125600
+ constructor(state, env) {
125601
+ super(state, getMaskedEnv(env));
125602
+ }
125603
+ };
125604
+ ${maskedDoBindings}`;
125605
+ const doD1FacadePath = path16.join(tmpDirPath, "d1-do-facade.js");
125606
+ fs6.writeFileSync(doD1FacadePath, contents);
125607
+ entrypointPath = doD1FacadePath;
125608
+ }
125574
125609
  const targetPath = path16.join(tmpDirPath, "d1-beta-facade.entry.js");
125575
125610
  await esbuild2.build({
125576
- entryPoints: [path16.resolve(getBasePath(), "templates/d1-beta-facade.js")],
125611
+ entryPoints: [entrypointPath],
125577
125612
  bundle: true,
125578
125613
  format: "esm",
125579
125614
  sourcemap: true,
@@ -126880,6 +126915,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
126880
126915
  betaD1Shims: identifyD1BindingsAsBeta(config.d1_databases)?.map(
126881
126916
  (db) => db.binding
126882
126917
  ),
126918
+ doBindings: config.durable_objects.bindings,
126883
126919
  jsxFactory,
126884
126920
  jsxFragment,
126885
126921
  rules: props.rules,
@@ -127799,6 +127835,7 @@ function useEsbuild({
127799
127835
  minify,
127800
127836
  nodeCompat,
127801
127837
  betaD1Shims,
127838
+ doBindings: durableObjects.bindings,
127802
127839
  define: define2,
127803
127840
  checkFetch: true,
127804
127841
  assets: assets && {
@@ -128327,7 +128364,6 @@ function getLocalPersistencePath(persistTo, doPersist, configPath) {
128327
128364
  init_import_meta_url();
128328
128365
  var import_node_child_process4 = require("node:child_process");
128329
128366
  var import_node_fs12 = require("node:fs");
128330
- var import_promises6 = require("node:fs/promises");
128331
128367
  var path24 = __toESM(require("node:path"));
128332
128368
  var util2 = __toESM(require("node:util"));
128333
128369
  var import_signal_exit4 = __toESM(require_signal_exit());
@@ -128387,7 +128423,8 @@ async function startDevServer(props) {
128387
128423
  firstPartyWorkerDevFacade: props.firstPartyWorker,
128388
128424
  testScheduled: props.testScheduled,
128389
128425
  local: props.local,
128390
- experimentalLocal: props.experimentalLocal
128426
+ experimentalLocal: props.experimentalLocal,
128427
+ doBindings: props.bindings.durable_objects?.bindings ?? []
128391
128428
  });
128392
128429
  if (props.local) {
128393
128430
  const { stop, inspectorUrl } = await startLocalServer({
@@ -128490,7 +128527,8 @@ async function runEsbuild({
128490
128527
  firstPartyWorkerDevFacade,
128491
128528
  testScheduled,
128492
128529
  local,
128493
- experimentalLocal
128530
+ experimentalLocal,
128531
+ doBindings
128494
128532
  }) {
128495
128533
  if (!destination)
128496
128534
  return;
@@ -128528,7 +128566,8 @@ async function runEsbuild({
128528
128566
  targetConsumer: "dev",
128529
128567
  testScheduled,
128530
128568
  local,
128531
- experimentalLocal
128569
+ experimentalLocal,
128570
+ doBindings
128532
128571
  });
128533
128572
  return {
128534
128573
  id: 0,
@@ -128589,12 +128628,6 @@ async function startLocalServer({
128589
128628
  "\u2394 Support for service bindings in local mode is experimental and may change."
128590
128629
  );
128591
128630
  }
128592
- for (const module2 of bundle.modules) {
128593
- await (0, import_promises6.writeFile)(
128594
- path24.join(path24.dirname(bundle.path), module2.name),
128595
- module2.content
128596
- );
128597
- }
128598
128631
  const scriptPath = (0, import_node_fs12.realpathSync)(bundle.path);
128599
128632
  const upstream = typeof localUpstream === "string" ? `${localProtocol}://${localUpstream}` : void 0;
128600
128633
  const {
@@ -132119,7 +132152,7 @@ init_import_meta_url();
132119
132152
 
132120
132153
  // src/d1/backups.tsx
132121
132154
  init_import_meta_url();
132122
- var import_promises7 = __toESM(require("node:fs/promises"));
132155
+ var import_promises6 = __toESM(require("node:fs/promises"));
132123
132156
  var path25 = __toESM(require("path"));
132124
132157
  var import_ink5 = __toESM(require_build2());
132125
132158
  var import_ink_table2 = __toESM(require_dist3());
@@ -134794,7 +134827,7 @@ var getDatabaseByNameOrBinding = async (config, accountId, name) => {
134794
134827
  }
134795
134828
  return matchingDB;
134796
134829
  };
134797
- var d1BetaWarning = process.env.NO_D1_WARNING ? "" : "\u{1F6A7} D1 is currently in open alpha and is not recommended for production data and traffic.\nPlease report any bugs to https://github.com/cloudflare/wrangler2/issues/new/choose.\nTo request features, visit https://community.cloudflare.com/c/developers/d1.\nTo give feedback, visit https://discord.gg/cloudflaredev";
134830
+ var d1BetaWarning = process.env.NO_D1_WARNING ? "" : "--------------------\n\u{1F6A7} D1 is currently in open alpha and is not recommended for production data and traffic\n\u{1F6A7} Please report any bugs to https://github.com/cloudflare/wrangler2/issues/new/choose\n\u{1F6A7} To request features, visit https://community.cloudflare.com/c/developers/d1\n\u{1F6A7} To give feedback, visit https://discord.gg/cloudflaredev\n--------------------\n";
134798
134831
 
134799
134832
  // src/d1/options.ts
134800
134833
  function Name(yargs) {
@@ -134949,7 +134982,7 @@ var DownloadHandler = withConfig(
134949
134982
  }
134950
134983
  logger.log(`\u{1F300} Saving to ${filename}`);
134951
134984
  const buffer = await response.arrayBuffer();
134952
- await import_promises7.default.writeFile(filename, new Buffer(buffer));
134985
+ await import_promises6.default.writeFile(filename, new Buffer(buffer));
134953
134986
  logger.log(`\u{1F300} Done!`);
134954
134987
  }
134955
134988
  );
@@ -135037,7 +135070,7 @@ var Handler3 = withConfig(
135037
135070
  // src/d1/execute.tsx
135038
135071
  init_import_meta_url();
135039
135072
  var import_node_fs13 = require("node:fs");
135040
- var import_promises8 = require("node:fs/promises");
135073
+ var import_promises7 = require("node:fs/promises");
135041
135074
  var import_node_path22 = __toESM(require("node:path"));
135042
135075
  var import_chalk6 = __toESM(require_chalk());
135043
135076
  var import_ink7 = __toESM(require_build2());
@@ -135264,7 +135297,7 @@ async function executeLocally(config, name, shouldPrompt, queries, persistTo) {
135264
135297
  );
135265
135298
  if (!ok)
135266
135299
  return null;
135267
- await (0, import_promises8.mkdir)(dbDir, { recursive: true });
135300
+ await (0, import_promises7.mkdir)(dbDir, { recursive: true });
135268
135301
  }
135269
135302
  logger.log(`\u{1F300} Loading DB at ${readableRelative(dbPath)}`);
135270
135303
  const db = await createSQLiteDB(dbPath);
@@ -135859,12 +135892,19 @@ async function deleteSiteNamespaceIfExisting(scriptName, accountId) {
135859
135892
  // src/deployments.ts
135860
135893
  init_import_meta_url();
135861
135894
  var import_url3 = require("url");
135862
- async function deployments(accountId, scriptName) {
135895
+ async function deployments(accountId, scriptName, { send_metrics: sendMetrics } = {}) {
135863
135896
  if (!scriptName) {
135864
135897
  throw new Error(
135865
135898
  "Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with `--name`"
135866
135899
  );
135867
135900
  }
135901
+ await sendMetricsEvent(
135902
+ "view deployments",
135903
+ { view: scriptName ? "single" : "all" },
135904
+ {
135905
+ sendMetrics
135906
+ }
135907
+ );
135868
135908
  const scriptMetadata = await fetchResult(
135869
135909
  `/accounts/${accountId}/workers/services/${scriptName}`
135870
135910
  );
@@ -135889,13 +135929,13 @@ Source: ${sourceStr(versions.metadata.source)}
135889
135929
  function sourceStr(source) {
135890
135930
  switch (source) {
135891
135931
  case "api":
135892
- return "API";
135932
+ return "\u{1F4E1} API";
135893
135933
  case "dash":
135894
- return "Dashboard";
135934
+ return "\u{1F5A5}\uFE0F Dashboard";
135895
135935
  case "wrangler":
135896
- return "Wrangler";
135936
+ return "\u{1F920} Wrangler";
135897
135937
  case "terraform":
135898
- return "Terraform";
135938
+ return "\u{1F3D7}\uFE0F Terraform";
135899
135939
  default:
135900
135940
  return "Other";
135901
135941
  }
@@ -136346,7 +136386,7 @@ async function cloneIntoDirectory(remote, targetDirectory, subdirectory) {
136346
136386
  // src/init.ts
136347
136387
  init_import_meta_url();
136348
136388
  var fs12 = __toESM(require("node:fs"));
136349
- var import_promises9 = require("node:fs/promises");
136389
+ var import_promises8 = require("node:fs/promises");
136350
136390
  var import_node_path25 = __toESM(require("node:path"));
136351
136391
  var import_toml4 = __toESM(require_toml());
136352
136392
 
@@ -136604,10 +136644,10 @@ Have you considered using Cloudflare Pages instead? See https://pages.cloudflare
136604
136644
  return;
136605
136645
  }
136606
136646
  } else {
136607
- await (0, import_promises9.mkdir)(creationDirectory, { recursive: true });
136647
+ await (0, import_promises8.mkdir)(creationDirectory, { recursive: true });
136608
136648
  const compatibilityDate = new Date().toISOString().substring(0, 10);
136609
136649
  try {
136610
- await (0, import_promises9.writeFile)(
136650
+ await (0, import_promises8.writeFile)(
136611
136651
  wranglerTomlDestination,
136612
136652
  import_toml4.default.stringify({
136613
136653
  name: workerName,
@@ -136633,7 +136673,7 @@ ${err.message ?? err}`
136633
136673
  const shouldInitGit = yesFlag || await confirm("Would you like to use git to manage this Worker?");
136634
136674
  if (shouldInitGit) {
136635
136675
  await initializeGit(creationDirectory);
136636
- await (0, import_promises9.writeFile)(
136676
+ await (0, import_promises8.writeFile)(
136637
136677
  import_node_path25.default.join(creationDirectory, ".gitignore"),
136638
136678
  readFileSync5(import_node_path25.default.join(getBasePath(), "templates/gitignore"))
136639
136679
  );
@@ -136657,7 +136697,7 @@ ${err.message ?? err}`
136657
136697
  if (!pathToPackageJson) {
136658
136698
  shouldCreatePackageJson = yesFlag || await confirm("No package.json found. Would you like to create one?");
136659
136699
  if (shouldCreatePackageJson) {
136660
- await (0, import_promises9.writeFile)(
136700
+ await (0, import_promises8.writeFile)(
136661
136701
  import_node_path25.default.join(creationDirectory, "./package.json"),
136662
136702
  JSON.stringify(
136663
136703
  {
@@ -136706,7 +136746,7 @@ ${err.message ?? err}`
136706
136746
  if (!pathToTSConfig) {
136707
136747
  if (yesFlag || await confirm("Would you like to use TypeScript?")) {
136708
136748
  isTypescriptProject = true;
136709
- await (0, import_promises9.writeFile)(
136749
+ await (0, import_promises8.writeFile)(
136710
136750
  import_node_path25.default.join(creationDirectory, "./tsconfig.json"),
136711
136751
  readFileSync5(import_node_path25.default.join(getBasePath(), "templates/tsconfig.init.json"))
136712
136752
  );
@@ -136768,7 +136808,7 @@ ${err.message ?? err}`
136768
136808
  const isNamedWorker = isCreatingWranglerToml && import_node_path25.default.dirname(packagePath) !== process.cwd();
136769
136809
  const isAddingTestScripts = isAddingTests && !packageJsonContent.scripts?.test;
136770
136810
  if (isWritingScripts) {
136771
- await (0, import_promises9.writeFile)(
136811
+ await (0, import_promises8.writeFile)(
136772
136812
  packagePath,
136773
136813
  JSON.stringify(
136774
136814
  {
@@ -136814,14 +136854,14 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
136814
136854
  logger.warn(
136815
136855
  "After running `wrangler init --from-dash`, modifying your worker via the Cloudflare dashboard is discouraged.\nEdits made via the Dashboard will not be synchronized locally and will be overridden by your local code and config when you publish."
136816
136856
  );
136817
- await (0, import_promises9.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136857
+ await (0, import_promises8.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136818
136858
  recursive: true
136819
136859
  });
136820
136860
  const defaultEnvironment = serviceMetadata?.default_environment.environment;
136821
136861
  const dashScript = await fetchDashboardScript(
136822
136862
  `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/content`
136823
136863
  );
136824
- await (0, import_promises9.writeFile)(
136864
+ await (0, import_promises8.writeFile)(
136825
136865
  import_node_path25.default.join(creationDirectory, "./src/index.ts"),
136826
136866
  dashScript
136827
136867
  );
@@ -136839,10 +136879,10 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
136839
136879
  const newWorkerType = yesFlag ? "fetch" : await getNewWorkerType(newWorkerFilename);
136840
136880
  if (newWorkerType !== "none") {
136841
136881
  const template = getNewWorkerTemplate("ts", newWorkerType);
136842
- await (0, import_promises9.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136882
+ await (0, import_promises8.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136843
136883
  recursive: true
136844
136884
  });
136845
- await (0, import_promises9.writeFile)(
136885
+ await (0, import_promises8.writeFile)(
136846
136886
  import_node_path25.default.join(creationDirectory, "./src/index.ts"),
136847
136887
  readFileSync5(import_node_path25.default.join(getBasePath(), `templates/${template}`))
136848
136888
  );
@@ -136861,7 +136901,7 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
136861
136901
  }
136862
136902
  newWorkerTestType = "vitest";
136863
136903
  devDepsToInstall.push(newWorkerTestType);
136864
- await (0, import_promises9.writeFile)(
136904
+ await (0, import_promises8.writeFile)(
136865
136905
  import_node_path25.default.join(creationDirectory, "./src/index.test.ts"),
136866
136906
  readFileSync5(
136867
136907
  import_node_path25.default.join(
@@ -136899,14 +136939,14 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
136899
136939
  logger.warn(
136900
136940
  "After running `wrangler init --from-dash`, modifying your worker via the Cloudflare dashboard is discouraged.\nEdits made via the Dashboard will not be synchronized locally and will be overridden by your local code and config when you publish."
136901
136941
  );
136902
- await (0, import_promises9.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136942
+ await (0, import_promises8.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136903
136943
  recursive: true
136904
136944
  });
136905
136945
  const defaultEnvironment = serviceMetadata?.default_environment.environment;
136906
136946
  const dashScript = await fetchDashboardScript(
136907
136947
  `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/content`
136908
136948
  );
136909
- await (0, import_promises9.writeFile)(
136949
+ await (0, import_promises8.writeFile)(
136910
136950
  import_node_path25.default.join(creationDirectory, "./src/index.js"),
136911
136951
  dashScript
136912
136952
  );
@@ -136924,10 +136964,10 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
136924
136964
  const newWorkerType = yesFlag ? "fetch" : await getNewWorkerType(newWorkerFilename);
136925
136965
  if (newWorkerType !== "none") {
136926
136966
  const template = getNewWorkerTemplate("js", newWorkerType);
136927
- await (0, import_promises9.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136967
+ await (0, import_promises8.mkdir)(import_node_path25.default.join(creationDirectory, "./src"), {
136928
136968
  recursive: true
136929
136969
  });
136930
- await (0, import_promises9.writeFile)(
136970
+ await (0, import_promises8.writeFile)(
136931
136971
  import_node_path25.default.join(creationDirectory, "./src/index.js"),
136932
136972
  readFileSync5(import_node_path25.default.join(getBasePath(), `templates/${template}`))
136933
136973
  );
@@ -136941,7 +136981,7 @@ To start developing your Worker, run \`npx wrangler dev\`${isCreatingWranglerTom
136941
136981
  if (shouldCreateTests) {
136942
136982
  newWorkerTestType = await getNewWorkerTestType(yesFlag);
136943
136983
  devDepsToInstall.push(newWorkerTestType);
136944
- await (0, import_promises9.writeFile)(
136984
+ await (0, import_promises8.writeFile)(
136945
136985
  import_node_path25.default.join(creationDirectory, "./src/index.test.js"),
136946
136986
  readFileSync5(
136947
136987
  import_node_path25.default.join(
@@ -137826,10 +137866,17 @@ init_import_meta_url();
137826
137866
 
137827
137867
  // src/pages/build.ts
137828
137868
  init_import_meta_url();
137869
+ var import_node_path33 = require("node:path");
137870
+
137871
+ // src/pages/buildFunctions.ts
137872
+ init_import_meta_url();
137829
137873
  var import_node_fs20 = require("node:fs");
137830
137874
  var import_node_os10 = require("node:os");
137831
137875
  var import_node_path32 = require("node:path");
137832
137876
 
137877
+ // src/pages/errors.ts
137878
+ init_import_meta_url();
137879
+
137833
137880
  // src/pages/constants.ts
137834
137881
  init_import_meta_url();
137835
137882
  var MAX_ASSET_COUNT = 2e4;
@@ -137847,9 +137894,6 @@ var MAX_FUNCTIONS_ROUTES_RULE_LENGTH = 100;
137847
137894
  var ROUTES_SPEC_VERSION = 1;
137848
137895
  var ROUTES_SPEC_DESCRIPTION = `Generated by wrangler@${version}`;
137849
137896
 
137850
- // src/pages/errors.ts
137851
- init_import_meta_url();
137852
-
137853
137897
  // src/pages/functions/routes-validation.ts
137854
137898
  init_import_meta_url();
137855
137899
  function isRoutesJSONSpec(data) {
@@ -138008,12 +138052,12 @@ and that at least one include rule is provided.
138008
138052
 
138009
138053
  // src/pages/functions/buildPlugin.ts
138010
138054
  init_import_meta_url();
138011
- var import_promises11 = require("node:fs/promises");
138055
+ var import_promises10 = require("node:fs/promises");
138012
138056
  var import_node_path28 = require("node:path");
138013
138057
 
138014
138058
  // src/pages/functions/buildWorker.ts
138015
138059
  init_import_meta_url();
138016
- var import_promises10 = require("node:fs/promises");
138060
+ var import_promises9 = require("node:fs/promises");
138017
138061
  var import_node_path27 = require("node:path");
138018
138062
  var import_esbuild3 = require("esbuild");
138019
138063
 
@@ -138063,7 +138107,8 @@ function buildWorker({
138063
138107
  nodeCompat,
138064
138108
  functionsDirectory,
138065
138109
  local,
138066
- betaD1Shims
138110
+ betaD1Shims,
138111
+ experimentalWorkerBundle = false
138067
138112
  }) {
138068
138113
  return bundleWorker(
138069
138114
  {
@@ -138088,6 +138133,7 @@ function buildWorker({
138088
138133
  betaD1Shims: (betaD1Shims || []).map(
138089
138134
  (binding) => `${D1_BETA_PREFIX}${binding}`
138090
138135
  ),
138136
+ doBindings: [],
138091
138137
  plugins: [
138092
138138
  buildNotifierPlugin(onEnd),
138093
138139
  {
@@ -138099,8 +138145,8 @@ function buildWorker({
138099
138145
  args.resolveDir,
138100
138146
  args.path.slice("assets:".length)
138101
138147
  );
138102
- const exists = await (0, import_promises10.access)(directory).then(() => true).catch(() => false);
138103
- const isDirectory2 = exists && (await (0, import_promises10.lstat)(directory)).isDirectory();
138148
+ const exists = await (0, import_promises9.access)(directory).then(() => true).catch(() => false);
138149
+ const isDirectory2 = exists && (await (0, import_promises9.lstat)(directory)).isDirectory();
138104
138150
  if (!isDirectory2) {
138105
138151
  return {
138106
138152
  errors: [
@@ -138129,11 +138175,11 @@ function buildWorker({
138129
138175
  "pages-plugins",
138130
138176
  identifier
138131
138177
  );
138132
- await (0, import_promises10.rm)(staticAssetsOutputDirectory, {
138178
+ await (0, import_promises9.rm)(staticAssetsOutputDirectory, {
138133
138179
  force: true,
138134
138180
  recursive: true
138135
138181
  });
138136
- await (0, import_promises10.cp)(args.path, staticAssetsOutputDirectory, {
138182
+ await (0, import_promises9.cp)(args.path, staticAssetsOutputDirectory, {
138137
138183
  force: true,
138138
138184
  recursive: true
138139
138185
  });
@@ -138154,7 +138200,7 @@ function buildWorker({
138154
138200
  ],
138155
138201
  isOutfile: true,
138156
138202
  serveAssetsFromWorker: false,
138157
- disableModuleCollection: true,
138203
+ disableModuleCollection: experimentalWorkerBundle ? false : true,
138158
138204
  rules: [],
138159
138205
  checkFetch: local,
138160
138206
  targetConsumer: local ? "dev" : "publish",
@@ -138175,7 +138221,8 @@ function buildRawWorker({
138175
138221
  },
138176
138222
  nodeCompat,
138177
138223
  local,
138178
- betaD1Shims
138224
+ betaD1Shims,
138225
+ experimentalWorkerBundle = false
138179
138226
  }) {
138180
138227
  return bundleWorker(
138181
138228
  {
@@ -138197,10 +138244,11 @@ function buildRawWorker({
138197
138244
  betaD1Shims: (betaD1Shims || []).map(
138198
138245
  (binding) => `${D1_BETA_PREFIX}${binding}`
138199
138246
  ),
138247
+ doBindings: [],
138200
138248
  plugins: [...plugins, buildNotifierPlugin(onEnd)],
138201
138249
  isOutfile: true,
138202
138250
  serveAssetsFromWorker: false,
138203
- disableModuleCollection: true,
138251
+ disableModuleCollection: experimentalWorkerBundle ? false : true,
138204
138252
  rules: [],
138205
138253
  checkFetch: local,
138206
138254
  targetConsumer: local ? "dev" : "publish",
@@ -138287,6 +138335,7 @@ function buildPlugin({
138287
138335
  betaD1Shims: (betaD1Shims || []).map(
138288
138336
  (binding) => `${D1_BETA_PREFIX}${binding}`
138289
138337
  ),
138338
+ doBindings: [],
138290
138339
  plugins: [
138291
138340
  buildNotifierPlugin(onEnd),
138292
138341
  {
@@ -138299,8 +138348,8 @@ function buildPlugin({
138299
138348
  args.resolveDir,
138300
138349
  args.path.slice("assets:".length)
138301
138350
  );
138302
- const exists = await (0, import_promises11.access)(directory).then(() => true).catch(() => false);
138303
- const isDirectory2 = exists && (await (0, import_promises11.lstat)(directory)).isDirectory();
138351
+ const exists = await (0, import_promises10.access)(directory).then(() => true).catch(() => false);
138352
+ const isDirectory2 = exists && (await (0, import_promises10.lstat)(directory)).isDirectory();
138304
138353
  if (!isDirectory2) {
138305
138354
  return {
138306
138355
  errors: [
@@ -138331,7 +138380,7 @@ function buildPlugin({
138331
138380
 
138332
138381
  // src/pages/functions/filepath-routing.ts
138333
138382
  init_import_meta_url();
138334
- var import_promises12 = __toESM(require("node:fs/promises"));
138383
+ var import_promises11 = __toESM(require("node:fs/promises"));
138335
138384
  var import_node_path29 = __toESM(require("node:path"));
138336
138385
  var import_esbuild4 = require("esbuild");
138337
138386
  async function generateConfigFromFileTree({
@@ -138452,7 +138501,7 @@ async function forEachFile(baseDir, fn) {
138452
138501
  const returnValues = [];
138453
138502
  while (isNotEmpty(searchPaths)) {
138454
138503
  const cwd2 = searchPaths.shift();
138455
- const dir = await import_promises12.default.readdir(cwd2, { withFileTypes: true });
138504
+ const dir = await import_promises11.default.readdir(cwd2, { withFileTypes: true });
138456
138505
  for (const entry of dir) {
138457
138506
  const pathname = import_node_path29.default.join(cwd2, entry.name);
138458
138507
  if (entry.isDirectory()) {
@@ -138470,7 +138519,7 @@ function isNotEmpty(array) {
138470
138519
 
138471
138520
  // src/pages/functions/routes.ts
138472
138521
  init_import_meta_url();
138473
- var import_promises13 = __toESM(require("node:fs/promises"));
138522
+ var import_promises12 = __toESM(require("node:fs/promises"));
138474
138523
  var import_node_path30 = __toESM(require("node:path"));
138475
138524
 
138476
138525
  // src/pages/functions/identifiers.ts
@@ -138550,7 +138599,7 @@ async function writeRoutesModule({
138550
138599
  }) {
138551
138600
  const { importMap, routes } = parseConfig(config, srcDir);
138552
138601
  const routesModule = generateRoutesModule(importMap, routes);
138553
- await import_promises13.default.writeFile(outfile, routesModule);
138602
+ await import_promises12.default.writeFile(outfile, routesModule);
138554
138603
  return outfile;
138555
138604
  }
138556
138605
  function parseConfig(config, baseDir) {
@@ -138736,6 +138785,90 @@ function isUrl(maybeUrl) {
138736
138785
  }
138737
138786
  }
138738
138787
 
138788
+ // src/pages/buildFunctions.ts
138789
+ async function buildFunctions({
138790
+ outfile,
138791
+ outputConfigPath,
138792
+ functionsDirectory,
138793
+ minify = false,
138794
+ sourcemap = false,
138795
+ fallbackService = "ASSETS",
138796
+ watch: watch6 = false,
138797
+ onEnd,
138798
+ plugin = false,
138799
+ buildOutputDirectory,
138800
+ routesOutputPath,
138801
+ nodeCompat,
138802
+ local,
138803
+ d1Databases,
138804
+ experimentalWorkerBundle = false
138805
+ }) {
138806
+ RUNNING_BUILDERS.forEach(
138807
+ (runningBuilder) => runningBuilder.stop && runningBuilder.stop()
138808
+ );
138809
+ const routesModule = (0, import_node_path32.join)((0, import_node_os10.tmpdir)(), `./functionsRoutes-${Math.random()}.mjs`);
138810
+ const baseURL = toUrlPath("/");
138811
+ const config = await generateConfigFromFileTree({
138812
+ baseDir: functionsDirectory,
138813
+ baseURL
138814
+ });
138815
+ if (!config.routes || config.routes.length === 0) {
138816
+ throw new FunctionsNoRoutesError(
138817
+ `Failed to find any routes while compiling Functions in: ${functionsDirectory}`
138818
+ );
138819
+ }
138820
+ if (routesOutputPath) {
138821
+ const routesJSON = convertRoutesToRoutesJSONSpec(config.routes);
138822
+ (0, import_node_fs20.writeFileSync)(routesOutputPath, JSON.stringify(routesJSON, null, 2));
138823
+ }
138824
+ if (outputConfigPath) {
138825
+ (0, import_node_fs20.writeFileSync)(
138826
+ outputConfigPath,
138827
+ JSON.stringify({ ...config, baseURL }, null, 2)
138828
+ );
138829
+ }
138830
+ await writeRoutesModule({
138831
+ config,
138832
+ srcDir: functionsDirectory,
138833
+ outfile: routesModule
138834
+ });
138835
+ const absoluteFunctionsDirectory = (0, import_node_path32.resolve)(functionsDirectory);
138836
+ if (plugin) {
138837
+ RUNNING_BUILDERS.push(
138838
+ await buildPlugin({
138839
+ routesModule,
138840
+ outfile,
138841
+ minify,
138842
+ sourcemap,
138843
+ watch: watch6,
138844
+ nodeCompat,
138845
+ functionsDirectory: absoluteFunctionsDirectory,
138846
+ local,
138847
+ betaD1Shims: d1Databases,
138848
+ onEnd
138849
+ })
138850
+ );
138851
+ } else {
138852
+ RUNNING_BUILDERS.push(
138853
+ await buildWorker({
138854
+ routesModule,
138855
+ outfile,
138856
+ minify,
138857
+ sourcemap,
138858
+ fallbackService,
138859
+ watch: watch6,
138860
+ functionsDirectory: absoluteFunctionsDirectory,
138861
+ local,
138862
+ betaD1Shims: d1Databases,
138863
+ onEnd,
138864
+ buildOutputDirectory,
138865
+ nodeCompat,
138866
+ experimentalWorkerBundle
138867
+ })
138868
+ );
138869
+ }
138870
+ }
138871
+
138739
138872
  // src/pages/build.ts
138740
138873
  function Options5(yargs) {
138741
138874
  return yargs.positional("directory", {
@@ -138830,7 +138963,7 @@ var Handler5 = async ({
138830
138963
  throw new FatalError("Could not parse a valid set of 'bindings'.", 1);
138831
138964
  }
138832
138965
  }
138833
- buildOutputDirectory ??= (0, import_node_path32.dirname)(outfile);
138966
+ buildOutputDirectory ??= (0, import_node_path33.dirname)(outfile);
138834
138967
  try {
138835
138968
  await buildFunctions({
138836
138969
  outfile,
@@ -138859,90 +138992,10 @@ var Handler5 = async ({
138859
138992
  }
138860
138993
  await sendMetricsEvent("build pages functions");
138861
138994
  };
138862
- async function buildFunctions({
138863
- outfile,
138864
- outputConfigPath,
138865
- functionsDirectory,
138866
- minify = false,
138867
- sourcemap = false,
138868
- fallbackService = "ASSETS",
138869
- watch: watch6 = false,
138870
- onEnd,
138871
- plugin = false,
138872
- buildOutputDirectory,
138873
- routesOutputPath,
138874
- nodeCompat,
138875
- local,
138876
- d1Databases
138877
- }) {
138878
- RUNNING_BUILDERS.forEach(
138879
- (runningBuilder) => runningBuilder.stop && runningBuilder.stop()
138880
- );
138881
- const routesModule = (0, import_node_path32.join)((0, import_node_os10.tmpdir)(), `./functionsRoutes-${Math.random()}.mjs`);
138882
- const baseURL = toUrlPath("/");
138883
- const config = await generateConfigFromFileTree({
138884
- baseDir: functionsDirectory,
138885
- baseURL
138886
- });
138887
- if (!config.routes || config.routes.length === 0) {
138888
- throw new FunctionsNoRoutesError(
138889
- `Failed to find any routes while compiling Functions in: ${functionsDirectory}`
138890
- );
138891
- }
138892
- if (routesOutputPath) {
138893
- const routesJSON = convertRoutesToRoutesJSONSpec(config.routes);
138894
- (0, import_node_fs20.writeFileSync)(routesOutputPath, JSON.stringify(routesJSON, null, 2));
138895
- }
138896
- if (outputConfigPath) {
138897
- (0, import_node_fs20.writeFileSync)(
138898
- outputConfigPath,
138899
- JSON.stringify({ ...config, baseURL }, null, 2)
138900
- );
138901
- }
138902
- await writeRoutesModule({
138903
- config,
138904
- srcDir: functionsDirectory,
138905
- outfile: routesModule
138906
- });
138907
- const absoluteFunctionsDirectory = (0, import_node_path32.resolve)(functionsDirectory);
138908
- if (plugin) {
138909
- RUNNING_BUILDERS.push(
138910
- await buildPlugin({
138911
- routesModule,
138912
- outfile,
138913
- minify,
138914
- sourcemap,
138915
- watch: watch6,
138916
- nodeCompat,
138917
- functionsDirectory: absoluteFunctionsDirectory,
138918
- local,
138919
- betaD1Shims: d1Databases,
138920
- onEnd
138921
- })
138922
- );
138923
- } else {
138924
- RUNNING_BUILDERS.push(
138925
- await buildWorker({
138926
- routesModule,
138927
- outfile,
138928
- minify,
138929
- sourcemap,
138930
- fallbackService,
138931
- watch: watch6,
138932
- functionsDirectory: absoluteFunctionsDirectory,
138933
- local,
138934
- betaD1Shims: d1Databases,
138935
- onEnd,
138936
- buildOutputDirectory,
138937
- nodeCompat
138938
- })
138939
- );
138940
- }
138941
- }
138942
138995
 
138943
138996
  // src/pages/deployment-tails.ts
138944
138997
  init_import_meta_url();
138945
- var import_promises14 = require("node:timers/promises");
138998
+ var import_promises13 = require("node:timers/promises");
138946
138999
  var import_signal_exit5 = __toESM(require_signal_exit());
138947
139000
 
138948
139001
  // src/tail/createTail.ts
@@ -139521,10 +139574,10 @@ async function Handler6({
139521
139574
  while (tail.readyState !== tail.OPEN) {
139522
139575
  switch (tail.readyState) {
139523
139576
  case tail.CONNECTING:
139524
- await (0, import_promises14.setTimeout)(100);
139577
+ await (0, import_promises13.setTimeout)(100);
139525
139578
  break;
139526
139579
  case tail.CLOSING:
139527
- await (0, import_promises14.setTimeout)(100);
139580
+ await (0, import_promises13.setTimeout)(100);
139528
139581
  break;
139529
139582
  case tail.CLOSED:
139530
139583
  await sendMetricsEvent("end log stream", {
@@ -139603,7 +139656,7 @@ init_import_meta_url();
139603
139656
  var import_node_child_process6 = require("node:child_process");
139604
139657
  var import_node_fs21 = require("node:fs");
139605
139658
  var import_node_os11 = require("node:os");
139606
- var import_node_path33 = require("node:path");
139659
+ var import_node_path34 = require("node:path");
139607
139660
  var import_chokidar4 = require("chokidar");
139608
139661
  var esbuild3 = __toESM(require("esbuild"));
139609
139662
  var DURABLE_OBJECTS_BINDING_REGEXP = new RegExp(
@@ -139667,6 +139720,12 @@ function Options7(yargs) {
139667
139720
  default: true,
139668
139721
  description: "Whether to run bundling on `_worker.js`"
139669
139722
  },
139723
+ "experimental-worker-bundle": {
139724
+ type: "boolean",
139725
+ default: false,
139726
+ hidden: true,
139727
+ description: "Whether to process non-JS module imports or not, such as wasm/text/binary, when we run bundling on `functions` or `_worker.js`"
139728
+ },
139670
139729
  binding: {
139671
139730
  type: "array",
139672
139731
  description: "Bind variable/secret (KEY=VALUE)",
@@ -139748,6 +139807,7 @@ var Handler7 = async ({
139748
139807
  "script-path": singleWorkerScriptPath,
139749
139808
  bundle,
139750
139809
  noBundle,
139810
+ experimentalWorkerBundle,
139751
139811
  binding: bindings = [],
139752
139812
  kv: kvs = [],
139753
139813
  do: durableObjects = [],
@@ -139789,7 +139849,7 @@ var Handler7 = async ({
139789
139849
  if (proxyPort === void 0)
139790
139850
  return void 0;
139791
139851
  } else {
139792
- directory = (0, import_node_path33.resolve)(directory);
139852
+ directory = (0, import_node_path34.resolve)(directory);
139793
139853
  }
139794
139854
  if (!compatibilityDate) {
139795
139855
  const currentDate = new Date().toISOString().substring(0, 10);
@@ -139814,7 +139874,7 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139814
139874
  const scriptReadyPromise = new Promise(
139815
139875
  (promiseResolve) => scriptReadyResolve = promiseResolve
139816
139876
  );
139817
- const workerScriptPath = directory !== void 0 ? (0, import_node_path33.join)(directory, singleWorkerScriptPath) : singleWorkerScriptPath;
139877
+ const workerScriptPath = directory !== void 0 ? (0, import_node_path34.join)(directory, singleWorkerScriptPath) : singleWorkerScriptPath;
139818
139878
  const usingWorkerScript = (0, import_node_fs21.existsSync)(workerScriptPath);
139819
139879
  const functionsDirectory = "./functions";
139820
139880
  let usingFunctions = !usingWorkerScript && (0, import_node_fs21.existsSync)(functionsDirectory);
@@ -139824,9 +139884,9 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139824
139884
  let runBuild = async () => {
139825
139885
  await checkRawWorker(workerScriptPath, () => scriptReadyResolve());
139826
139886
  };
139827
- const enableBundling = bundle || !noBundle;
139887
+ const enableBundling = bundle || !noBundle || experimentalWorkerBundle;
139828
139888
  if (enableBundling) {
139829
- scriptPath = (0, import_node_path33.join)((0, import_node_os11.tmpdir)(), `./bundledWorker-${Math.random()}.mjs`);
139889
+ scriptPath = (0, import_node_path34.join)((0, import_node_os11.tmpdir)(), `./bundledWorker-${Math.random()}.mjs`);
139830
139890
  runBuild = async () => {
139831
139891
  try {
139832
139892
  await buildRawWorker({
@@ -139836,7 +139896,8 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139836
139896
  local: true,
139837
139897
  sourcemap: true,
139838
139898
  watch: true,
139839
- onEnd: () => scriptReadyResolve()
139899
+ onEnd: () => scriptReadyResolve(),
139900
+ experimentalWorkerBundle
139840
139901
  });
139841
139902
  } catch (e2) {
139842
139903
  logger.warn("Failed to bundle _worker.js.", e2);
@@ -139851,7 +139912,7 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139851
139912
  await runBuild();
139852
139913
  });
139853
139914
  } else if (usingFunctions) {
139854
- scriptPath = (0, import_node_path33.join)((0, import_node_os11.tmpdir)(), `./functionsWorker-${Math.random()}.mjs`);
139915
+ scriptPath = (0, import_node_path34.join)((0, import_node_os11.tmpdir)(), `./functionsWorker-${Math.random()}.mjs`);
139855
139916
  if (nodeCompat) {
139856
139917
  console.warn(
139857
139918
  "Enabling node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
@@ -139869,7 +139930,8 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139869
139930
  onEnd,
139870
139931
  buildOutputDirectory: directory,
139871
139932
  nodeCompat,
139872
- local: true
139933
+ local: true,
139934
+ experimentalWorkerBundle
139873
139935
  });
139874
139936
  await sendMetricsEvent("build pages functions");
139875
139937
  };
@@ -139905,7 +139967,7 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139905
139967
  if (!usingFunctions && !usingWorkerScript) {
139906
139968
  scriptReadyResolve();
139907
139969
  logger.log("No functions. Shimming...");
139908
- scriptPath = (0, import_node_path33.resolve)(getBasePath(), "templates/pages-shim.ts");
139970
+ scriptPath = (0, import_node_path34.resolve)(getBasePath(), "templates/pages-shim.ts");
139909
139971
  }
139910
139972
  await scriptReadyPromise;
139911
139973
  if (scriptPath === "") {
@@ -139916,13 +139978,13 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139916
139978
  }
139917
139979
  let entrypoint = scriptPath;
139918
139980
  if (directory && (usingFunctions || usingWorkerScript)) {
139919
- const routesJSONPath = (0, import_node_path33.join)(directory, "_routes.json");
139981
+ const routesJSONPath = (0, import_node_path34.join)(directory, "_routes.json");
139920
139982
  if ((0, import_node_fs21.existsSync)(routesJSONPath)) {
139921
139983
  let routesJSONContents;
139922
139984
  const runBuild = async (entrypointFile, outfile, routes) => {
139923
139985
  await esbuild3.build({
139924
139986
  entryPoints: [
139925
- (0, import_node_path33.resolve)(getBasePath(), "templates/pages-dev-pipeline.ts")
139987
+ (0, import_node_path34.resolve)(getBasePath(), "templates/pages-dev-pipeline.ts")
139926
139988
  ],
139927
139989
  bundle: true,
139928
139990
  sourcemap: true,
@@ -139930,7 +139992,7 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139930
139992
  plugins: [
139931
139993
  esbuildAliasExternalPlugin({
139932
139994
  __ENTRY_POINT__: entrypointFile,
139933
- "./pages-dev-util": (0, import_node_path33.resolve)(
139995
+ "./pages-dev-util": (0, import_node_path34.resolve)(
139934
139996
  getBasePath(),
139935
139997
  "templates/pages-dev-util.ts"
139936
139998
  )
@@ -139945,7 +140007,7 @@ use --persist-to=./wrangler-local-state to keep using the old path.`
139945
140007
  try {
139946
140008
  routesJSONContents = (0, import_node_fs21.readFileSync)(routesJSONPath, "utf-8");
139947
140009
  validateRoutes2(JSON.parse(routesJSONContents), directory);
139948
- entrypoint = (0, import_node_path33.join)(
140010
+ entrypoint = (0, import_node_path34.join)(
139949
140011
  (0, import_node_os11.tmpdir)(),
139950
140012
  `${Math.random().toString(36).slice(2)}.js`
139951
140013
  );
@@ -140165,7 +140227,7 @@ async function spawnProxyProcess({
140165
140227
  // src/pages/functions.ts
140166
140228
  init_import_meta_url();
140167
140229
  var import_node_fs22 = require("node:fs");
140168
- var import_node_path34 = __toESM(require("node:path"));
140230
+ var import_node_path35 = __toESM(require("node:path"));
140169
140231
  function OptimizeRoutesOptions(yargs) {
140170
140232
  return yargs.options({
140171
140233
  "routes-path": {
@@ -140189,7 +140251,7 @@ async function OptimizeRoutesHandler({
140189
140251
  logger.log(pagesBetaWarning);
140190
140252
  }
140191
140253
  let routesFileContents;
140192
- const routesOutputDirectory = import_node_path34.default.dirname(outputRoutesPath);
140254
+ const routesOutputDirectory = import_node_path35.default.dirname(outputRoutesPath);
140193
140255
  if (!(0, import_node_fs22.existsSync)(routesPath)) {
140194
140256
  throw new FatalError(
140195
140257
  `Oops! File ${routesPath} does not exist. Please make sure --routes-path is a valid file path (for example "/public/_routes.json").`,
@@ -140224,19 +140286,22 @@ async function OptimizeRoutesHandler({
140224
140286
  // src/pages/publish.tsx
140225
140287
  init_import_meta_url();
140226
140288
  var import_node_child_process7 = require("node:child_process");
140227
- var import_node_fs23 = require("node:fs");
140228
- var import_node_os12 = require("node:os");
140229
- var import_node_path36 = require("node:path");
140230
- var import_node_process7 = require("node:process");
140231
140289
  var import_ink15 = __toESM(require_build2());
140232
140290
  var import_ink_select_input3 = __toESM(require_build3());
140233
140291
  var import_react18 = __toESM(require_react());
140292
+
140293
+ // src/api/pages/publish.tsx
140294
+ init_import_meta_url();
140295
+ var import_node_fs23 = require("node:fs");
140296
+ var import_node_os12 = require("node:os");
140297
+ var import_node_path37 = require("node:path");
140298
+ var import_node_process7 = require("node:process");
140234
140299
  var import_undici11 = __toESM(require_undici());
140235
140300
 
140236
140301
  // src/pages/upload.tsx
140237
140302
  init_import_meta_url();
140238
- var import_promises15 = require("node:fs/promises");
140239
- var import_node_path35 = require("node:path");
140303
+ var import_promises14 = require("node:fs/promises");
140304
+ var import_node_path36 = require("node:path");
140240
140305
  var import_ink14 = __toESM(require_build2());
140241
140306
  var import_ink_spinner = __toESM(require_build4());
140242
140307
  var import_mime2 = __toESM(require_mime2());
@@ -140696,8 +140761,8 @@ var Handler8 = async ({
140696
140761
  skipCaching: skipCaching ?? false
140697
140762
  });
140698
140763
  if (outputManifestPath) {
140699
- await (0, import_promises15.mkdir)((0, import_node_path35.dirname)(outputManifestPath), { recursive: true });
140700
- await (0, import_promises15.writeFile)(outputManifestPath, JSON.stringify(manifest));
140764
+ await (0, import_promises14.mkdir)((0, import_node_path36.dirname)(outputManifestPath), { recursive: true });
140765
+ await (0, import_promises14.writeFile)(outputManifestPath, JSON.stringify(manifest));
140701
140766
  }
140702
140767
  logger.log(`\u2728 Upload complete!`);
140703
140768
  };
@@ -140721,14 +140786,14 @@ var upload = async (args) => {
140721
140786
  "**/node_modules",
140722
140787
  "**/.git"
140723
140788
  ].map((pattern) => new import_minimatch.Minimatch(pattern));
140724
- const directory = (0, import_node_path35.resolve)(args.directory);
140789
+ const directory = (0, import_node_path36.resolve)(args.directory);
140725
140790
  const walk = async (dir, fileMap2 = /* @__PURE__ */ new Map(), startingDir = dir) => {
140726
- const files2 = await (0, import_promises15.readdir)(dir);
140791
+ const files2 = await (0, import_promises14.readdir)(dir);
140727
140792
  await Promise.all(
140728
140793
  files2.map(async (file) => {
140729
- const filepath = (0, import_node_path35.join)(dir, file);
140730
- const relativeFilepath = (0, import_node_path35.relative)(startingDir, filepath);
140731
- const filestat = await (0, import_promises15.stat)(filepath);
140794
+ const filepath = (0, import_node_path36.join)(dir, file);
140795
+ const relativeFilepath = (0, import_node_path36.relative)(startingDir, filepath);
140796
+ const filestat = await (0, import_promises14.stat)(filepath);
140732
140797
  for (const minimatch of IGNORE_LIST) {
140733
140798
  if (minimatch.match(relativeFilepath)) {
140734
140799
  return;
@@ -140740,7 +140805,7 @@ var upload = async (args) => {
140740
140805
  if (filestat.isDirectory()) {
140741
140806
  fileMap2 = await walk(filepath, fileMap2, startingDir);
140742
140807
  } else {
140743
- const name = relativeFilepath.split(import_node_path35.sep).join("/");
140808
+ const name = relativeFilepath.split(import_node_path36.sep).join("/");
140744
140809
  if (filestat.size > MAX_ASSET_SIZE) {
140745
140810
  throw new FatalError(
140746
140811
  `Error: Pages only supports files up to ${prettyBytes(
@@ -140844,7 +140909,7 @@ ${name} is ${prettyBytes(filestat.size)} in size`,
140844
140909
  const payload = await Promise.all(
140845
140910
  bucket.files.map(async (file) => ({
140846
140911
  key: file.hash,
140847
- value: (await (0, import_promises15.readFile)(file.path)).toString("base64"),
140912
+ value: (await (0, import_promises14.readFile)(file.path)).toString("base64"),
140848
140913
  metadata: {
140849
140914
  contentType: file.contentType
140850
140915
  },
@@ -140975,6 +141040,194 @@ function Progress({ done, total }) {
140975
141040
  `));
140976
141041
  }
140977
141042
 
141043
+ // src/api/pages/publish.tsx
141044
+ async function publish2({
141045
+ directory,
141046
+ accountId,
141047
+ projectName,
141048
+ branch,
141049
+ skipCaching,
141050
+ commitMessage,
141051
+ commitHash,
141052
+ commitDirty,
141053
+ functionsDirectory: customFunctionsDirectory,
141054
+ bundle
141055
+ }) {
141056
+ let _headers, _redirects, _routesGenerated, _routesCustom, _workerJS;
141057
+ const workerScriptPath = (0, import_node_path37.resolve)(directory, "_worker.js");
141058
+ try {
141059
+ _headers = (0, import_node_fs23.readFileSync)((0, import_node_path37.join)(directory, "_headers"), "utf-8");
141060
+ } catch {
141061
+ }
141062
+ try {
141063
+ _redirects = (0, import_node_fs23.readFileSync)((0, import_node_path37.join)(directory, "_redirects"), "utf-8");
141064
+ } catch {
141065
+ }
141066
+ try {
141067
+ _routesCustom = (0, import_node_fs23.readFileSync)((0, import_node_path37.join)(directory, "_routes.json"), "utf-8");
141068
+ } catch {
141069
+ }
141070
+ try {
141071
+ _workerJS = (0, import_node_fs23.readFileSync)(workerScriptPath, "utf-8");
141072
+ } catch {
141073
+ }
141074
+ const project = await fetchResult(
141075
+ `/accounts/${accountId}/pages/projects/${projectName}`
141076
+ );
141077
+ let isProduction = true;
141078
+ if (branch) {
141079
+ isProduction = project.production_branch === branch;
141080
+ }
141081
+ let builtFunctions = void 0;
141082
+ const functionsDirectory = customFunctionsDirectory || (0, import_node_path37.join)((0, import_node_process7.cwd)(), "functions");
141083
+ const routesOutputPath = !(0, import_node_fs23.existsSync)((0, import_node_path37.join)(directory, "_routes.json")) ? (0, import_node_path37.join)((0, import_node_os12.tmpdir)(), `_routes-${Math.random()}.json`) : void 0;
141084
+ let filepathRoutingConfig;
141085
+ if (!_workerJS && (0, import_node_fs23.existsSync)(functionsDirectory)) {
141086
+ const outfile = (0, import_node_path37.join)((0, import_node_os12.tmpdir)(), `./functionsWorker-${Math.random()}.js`);
141087
+ const outputConfigPath = (0, import_node_path37.join)(
141088
+ (0, import_node_os12.tmpdir)(),
141089
+ `functions-filepath-routing-config-${Math.random()}.json`
141090
+ );
141091
+ try {
141092
+ await buildFunctions({
141093
+ outfile,
141094
+ outputConfigPath,
141095
+ functionsDirectory,
141096
+ onEnd: () => {
141097
+ },
141098
+ buildOutputDirectory: (0, import_node_path37.dirname)(outfile),
141099
+ routesOutputPath,
141100
+ local: false,
141101
+ d1Databases: Object.keys(
141102
+ project.deployment_configs[isProduction ? "production" : "preview"].d1_databases ?? {}
141103
+ )
141104
+ });
141105
+ builtFunctions = (0, import_node_fs23.readFileSync)(outfile, "utf-8");
141106
+ filepathRoutingConfig = (0, import_node_fs23.readFileSync)(outputConfigPath, "utf-8");
141107
+ } catch (e2) {
141108
+ if (e2 instanceof FunctionsNoRoutesError) {
141109
+ logger.warn(
141110
+ getFunctionsNoRoutesWarning(functionsDirectory, "skipping")
141111
+ );
141112
+ } else {
141113
+ throw e2;
141114
+ }
141115
+ }
141116
+ }
141117
+ const manifest = await upload({
141118
+ directory,
141119
+ accountId,
141120
+ projectName,
141121
+ skipCaching: skipCaching ?? false
141122
+ });
141123
+ const formData = new import_undici11.FormData();
141124
+ formData.append("manifest", JSON.stringify(manifest));
141125
+ if (branch) {
141126
+ formData.append("branch", branch);
141127
+ }
141128
+ if (commitMessage) {
141129
+ formData.append("commit_message", commitMessage);
141130
+ }
141131
+ if (commitHash) {
141132
+ formData.append("commit_hash", commitHash);
141133
+ }
141134
+ if (commitDirty !== void 0) {
141135
+ formData.append("commit_dirty", commitDirty);
141136
+ }
141137
+ if (_headers) {
141138
+ formData.append("_headers", new import_undici11.File([_headers], "_headers"));
141139
+ logger.log(`\u2728 Uploading _headers`);
141140
+ }
141141
+ if (_redirects) {
141142
+ formData.append("_redirects", new import_undici11.File([_redirects], "_redirects"));
141143
+ logger.log(`\u2728 Uploading _redirects`);
141144
+ }
141145
+ if (filepathRoutingConfig) {
141146
+ formData.append(
141147
+ "functions-filepath-routing-config.json",
141148
+ new import_undici11.File(
141149
+ [filepathRoutingConfig],
141150
+ "functions-filepath-routing-config.json"
141151
+ )
141152
+ );
141153
+ }
141154
+ if (_workerJS) {
141155
+ let workerFileContents = _workerJS;
141156
+ if (bundle) {
141157
+ const outfile = (0, import_node_path37.join)((0, import_node_os12.tmpdir)(), `./bundledWorker-${Math.random()}.mjs`);
141158
+ await buildRawWorker({
141159
+ workerScriptPath,
141160
+ outfile,
141161
+ directory: directory ?? ".",
141162
+ local: false,
141163
+ sourcemap: true,
141164
+ watch: false,
141165
+ onEnd: () => {
141166
+ }
141167
+ });
141168
+ workerFileContents = (0, import_node_fs23.readFileSync)(outfile, "utf8");
141169
+ } else {
141170
+ await checkRawWorker(workerScriptPath, () => {
141171
+ });
141172
+ }
141173
+ formData.append("_worker.js", new import_undici11.File([workerFileContents], "_worker.js"));
141174
+ logger.log(`\u2728 Uploading _worker.js`);
141175
+ if (_routesCustom) {
141176
+ try {
141177
+ const routesCustomJSON = JSON.parse(_routesCustom);
141178
+ validateRoutes2(routesCustomJSON, (0, import_node_path37.join)(directory, "_routes.json"));
141179
+ formData.append(
141180
+ "_routes.json",
141181
+ new import_undici11.File([_routesCustom], "_routes.json")
141182
+ );
141183
+ logger.log(`\u2728 Uploading _routes.json`);
141184
+ } catch (err) {
141185
+ if (err instanceof FatalError) {
141186
+ throw err;
141187
+ }
141188
+ }
141189
+ }
141190
+ }
141191
+ if (builtFunctions && !_workerJS) {
141192
+ formData.append("_worker.js", new import_undici11.File([builtFunctions], "_worker.js"));
141193
+ logger.log(`\u2728 Uploading Functions`);
141194
+ if (_routesCustom) {
141195
+ try {
141196
+ const routesCustomJSON = JSON.parse(_routesCustom);
141197
+ validateRoutes2(routesCustomJSON, (0, import_node_path37.join)(directory, "_routes.json"));
141198
+ formData.append(
141199
+ "_routes.json",
141200
+ new import_undici11.File([_routesCustom], "_routes.json")
141201
+ );
141202
+ logger.log(`\u2728 Uploading _routes.json`);
141203
+ } catch (err) {
141204
+ if (err instanceof FatalError) {
141205
+ throw err;
141206
+ }
141207
+ }
141208
+ } else if (routesOutputPath) {
141209
+ try {
141210
+ _routesGenerated = (0, import_node_fs23.readFileSync)(routesOutputPath, "utf-8");
141211
+ if (_routesGenerated) {
141212
+ formData.append(
141213
+ "_routes.json",
141214
+ new import_undici11.File([_routesGenerated], "_routes.json")
141215
+ );
141216
+ }
141217
+ } catch {
141218
+ }
141219
+ }
141220
+ }
141221
+ const deploymentResponse = await fetchResult(
141222
+ `/accounts/${accountId}/pages/projects/${projectName}/deployments`,
141223
+ {
141224
+ method: "POST",
141225
+ body: formData
141226
+ }
141227
+ );
141228
+ return deploymentResponse;
141229
+ }
141230
+
140978
141231
  // src/pages/publish.tsx
140979
141232
  function Options9(yargs) {
140980
141233
  return yargs.positional("directory", {
@@ -141047,7 +141300,7 @@ var Handler9 = async ({
141047
141300
  const isInteractive2 = process.stdin.isTTY;
141048
141301
  if (!projectName && isInteractive2) {
141049
141302
  const projects = (await listProjects({ accountId })).filter(
141050
- (project2) => !project2.source
141303
+ (project) => !project.source
141051
141304
  );
141052
141305
  let existingOrNew = "new";
141053
141306
  if (projects.length > 0) {
@@ -141156,179 +141409,17 @@ To silence this warning, pass in --commit-dirty=true`
141156
141409
  commitDirty = isGitDirty;
141157
141410
  }
141158
141411
  }
141159
- let _headers, _redirects, _routesGenerated, _routesCustom, _workerJS;
141160
- const workerScriptPath = (0, import_node_path36.resolve)(directory, "_worker.js");
141161
- try {
141162
- _headers = (0, import_node_fs23.readFileSync)((0, import_node_path36.join)(directory, "_headers"), "utf-8");
141163
- } catch {
141164
- }
141165
- try {
141166
- _redirects = (0, import_node_fs23.readFileSync)((0, import_node_path36.join)(directory, "_redirects"), "utf-8");
141167
- } catch {
141168
- }
141169
- try {
141170
- _routesCustom = (0, import_node_fs23.readFileSync)((0, import_node_path36.join)(directory, "_routes.json"), "utf-8");
141171
- } catch {
141172
- }
141173
- try {
141174
- _workerJS = (0, import_node_fs23.readFileSync)(workerScriptPath, "utf-8");
141175
- } catch {
141176
- }
141177
- const project = await fetchResult(
141178
- `/accounts/${accountId}/pages/projects/${projectName}`
141179
- );
141180
- let isProduction = true;
141181
- if (branch) {
141182
- isProduction = project.production_branch === branch;
141183
- }
141184
- let builtFunctions = void 0;
141185
- const functionsDirectory = (0, import_node_path36.join)((0, import_node_process7.cwd)(), "functions");
141186
- const routesOutputPath = !(0, import_node_fs23.existsSync)((0, import_node_path36.join)(directory, "_routes.json")) ? (0, import_node_path36.join)((0, import_node_os12.tmpdir)(), `_routes-${Math.random()}.json`) : void 0;
141187
- let filepathRoutingConfig;
141188
- if (!_workerJS && (0, import_node_fs23.existsSync)(functionsDirectory)) {
141189
- const outfile = (0, import_node_path36.join)((0, import_node_os12.tmpdir)(), `./functionsWorker-${Math.random()}.js`);
141190
- const outputConfigPath = (0, import_node_path36.join)(
141191
- (0, import_node_os12.tmpdir)(),
141192
- `functions-filepath-routing-config-${Math.random()}.json`
141193
- );
141194
- try {
141195
- await buildFunctions({
141196
- outfile,
141197
- outputConfigPath,
141198
- functionsDirectory,
141199
- onEnd: () => {
141200
- },
141201
- buildOutputDirectory: (0, import_node_path36.dirname)(outfile),
141202
- routesOutputPath,
141203
- local: false,
141204
- d1Databases: Object.keys(
141205
- project.deployment_configs[isProduction ? "production" : "preview"].d1_databases ?? {}
141206
- )
141207
- });
141208
- builtFunctions = (0, import_node_fs23.readFileSync)(outfile, "utf-8");
141209
- filepathRoutingConfig = (0, import_node_fs23.readFileSync)(outputConfigPath, "utf-8");
141210
- } catch (e2) {
141211
- if (e2 instanceof FunctionsNoRoutesError) {
141212
- logger.warn(
141213
- getFunctionsNoRoutesWarning(functionsDirectory, "skipping")
141214
- );
141215
- } else {
141216
- throw e2;
141217
- }
141218
- }
141219
- }
141220
- const manifest = await upload({
141412
+ const deploymentResponse = await publish2({
141221
141413
  directory,
141222
141414
  accountId,
141223
141415
  projectName,
141224
- skipCaching: skipCaching ?? false
141416
+ branch,
141417
+ skipCaching,
141418
+ commitMessage,
141419
+ commitHash,
141420
+ commitDirty,
141421
+ bundle: bundle ?? !noBundle
141225
141422
  });
141226
- const formData = new import_undici11.FormData();
141227
- formData.append("manifest", JSON.stringify(manifest));
141228
- if (branch) {
141229
- formData.append("branch", branch);
141230
- }
141231
- if (commitMessage) {
141232
- formData.append("commit_message", commitMessage);
141233
- }
141234
- if (commitHash) {
141235
- formData.append("commit_hash", commitHash);
141236
- }
141237
- if (commitDirty !== void 0) {
141238
- formData.append("commit_dirty", commitDirty);
141239
- }
141240
- if (_headers) {
141241
- formData.append("_headers", new import_undici11.File([_headers], "_headers"));
141242
- logger.log(`\u2728 Uploading _headers`);
141243
- }
141244
- if (_redirects) {
141245
- formData.append("_redirects", new import_undici11.File([_redirects], "_redirects"));
141246
- logger.log(`\u2728 Uploading _redirects`);
141247
- }
141248
- if (filepathRoutingConfig) {
141249
- formData.append(
141250
- "functions-filepath-routing-config.json",
141251
- new import_undici11.File(
141252
- [filepathRoutingConfig],
141253
- "functions-filepath-routing-config.json"
141254
- )
141255
- );
141256
- }
141257
- if (_workerJS) {
141258
- let workerFileContents = _workerJS;
141259
- const enableBundling = bundle || !noBundle;
141260
- if (enableBundling) {
141261
- const outfile = (0, import_node_path36.join)((0, import_node_os12.tmpdir)(), `./bundledWorker-${Math.random()}.mjs`);
141262
- await buildRawWorker({
141263
- workerScriptPath,
141264
- outfile,
141265
- directory: directory ?? ".",
141266
- local: false,
141267
- sourcemap: true,
141268
- watch: false,
141269
- onEnd: () => {
141270
- }
141271
- });
141272
- workerFileContents = (0, import_node_fs23.readFileSync)(outfile, "utf8");
141273
- } else {
141274
- await checkRawWorker(workerScriptPath, () => {
141275
- });
141276
- }
141277
- formData.append("_worker.js", new import_undici11.File([workerFileContents], "_worker.js"));
141278
- logger.log(`\u2728 Uploading _worker.js`);
141279
- if (_routesCustom) {
141280
- try {
141281
- const routesCustomJSON = JSON.parse(_routesCustom);
141282
- validateRoutes2(routesCustomJSON, (0, import_node_path36.join)(directory, "_routes.json"));
141283
- formData.append(
141284
- "_routes.json",
141285
- new import_undici11.File([_routesCustom], "_routes.json")
141286
- );
141287
- logger.log(`\u2728 Uploading _routes.json`);
141288
- } catch (err) {
141289
- if (err instanceof FatalError) {
141290
- throw err;
141291
- }
141292
- }
141293
- }
141294
- }
141295
- if (builtFunctions && !_workerJS) {
141296
- formData.append("_worker.js", new import_undici11.File([builtFunctions], "_worker.js"));
141297
- logger.log(`\u2728 Uploading Functions`);
141298
- if (_routesCustom) {
141299
- try {
141300
- const routesCustomJSON = JSON.parse(_routesCustom);
141301
- validateRoutes2(routesCustomJSON, (0, import_node_path36.join)(directory, "_routes.json"));
141302
- formData.append(
141303
- "_routes.json",
141304
- new import_undici11.File([_routesCustom], "_routes.json")
141305
- );
141306
- logger.log(`\u2728 Uploading _routes.json`);
141307
- } catch (err) {
141308
- if (err instanceof FatalError) {
141309
- throw err;
141310
- }
141311
- }
141312
- } else if (routesOutputPath) {
141313
- try {
141314
- _routesGenerated = (0, import_node_fs23.readFileSync)(routesOutputPath, "utf-8");
141315
- if (_routesGenerated) {
141316
- formData.append(
141317
- "_routes.json",
141318
- new import_undici11.File([_routesGenerated], "_routes.json")
141319
- );
141320
- }
141321
- } catch {
141322
- }
141323
- }
141324
- }
141325
- const deploymentResponse = await fetchResult(
141326
- `/accounts/${accountId}/pages/projects/${projectName}/deployments`,
141327
- {
141328
- method: "POST",
141329
- body: formData
141330
- }
141331
- );
141332
141423
  saveToConfigCache(PAGES_CONFIG_CACHE_FILENAME, {
141333
141424
  account_id: accountId,
141334
141425
  project_name: projectName
@@ -141411,7 +141502,7 @@ var pages = (yargs) => {
141411
141502
 
141412
141503
  // src/publish/index.ts
141413
141504
  init_import_meta_url();
141414
- var import_node_path37 = __toESM(require("node:path"));
141505
+ var import_node_path38 = __toESM(require("node:path"));
141415
141506
  function publishOptions(yargs) {
141416
141507
  return yargs.positional("script", {
141417
141508
  describe: "The path to an entry point for your worker",
@@ -141534,7 +141625,7 @@ function publishOptions(yargs) {
141534
141625
  }
141535
141626
  async function publishHandler(args) {
141536
141627
  await printWranglerBanner();
141537
- const configPath = args.config || args.script && findWranglerToml(import_node_path37.default.dirname(args.script));
141628
+ const configPath = args.config || args.script && findWranglerToml(import_node_path38.default.dirname(args.script));
141538
141629
  const config = readConfig(configPath, args);
141539
141630
  const entry = await getEntry(args, config, "publish");
141540
141631
  await sendMetricsEvent(
@@ -142700,7 +142791,7 @@ ${key} is ${prettyBytes(objectSize)} in size`,
142700
142791
 
142701
142792
  // src/secret/index.ts
142702
142793
  init_import_meta_url();
142703
- var import_node_path38 = __toESM(require("node:path"));
142794
+ var import_node_path39 = __toESM(require("node:path"));
142704
142795
  var secret = (secretYargs) => {
142705
142796
  return secretYargs.option("legacy-env", {
142706
142797
  type: "boolean",
@@ -142917,7 +143008,7 @@ var secretBulkHandler = async (secretBulkArgs) => {
142917
143008
  logger.log(
142918
143009
  `\u{1F300} Creating the secrets for the Worker "${scriptName}" ${secretBulkArgs.env && !isLegacyEnv(config) ? `(${secretBulkArgs.env})` : ""}`
142919
143010
  );
142920
- const jsonFilePath = import_node_path38.default.resolve(secretBulkArgs.json);
143011
+ const jsonFilePath = import_node_path39.default.resolve(secretBulkArgs.json);
142921
143012
  const content = parseJSON(
142922
143013
  readFileSync5(jsonFilePath),
142923
143014
  jsonFilePath
@@ -142964,7 +143055,7 @@ var secretBulkHandler = async (secretBulkArgs) => {
142964
143055
 
142965
143056
  // src/tail/index.ts
142966
143057
  init_import_meta_url();
142967
- var import_promises16 = require("node:timers/promises");
143058
+ var import_promises15 = require("node:timers/promises");
142968
143059
  var import_signal_exit6 = __toESM(require_signal_exit());
142969
143060
  function tailOptions(yargs) {
142970
143061
  return yargs.positional("worker", {
@@ -143081,10 +143172,10 @@ async function tailHandler(args) {
143081
143172
  while (tail.readyState !== tail.OPEN) {
143082
143173
  switch (tail.readyState) {
143083
143174
  case tail.CONNECTING:
143084
- await (0, import_promises16.setTimeout)(100);
143175
+ await (0, import_promises15.setTimeout)(100);
143085
143176
  break;
143086
143177
  case tail.CLOSING:
143087
- await (0, import_promises16.setTimeout)(100);
143178
+ await (0, import_promises15.setTimeout)(100);
143088
143179
  break;
143089
143180
  case tail.CLOSED:
143090
143181
  await sendMetricsEvent("end log stream", {
@@ -143725,7 +143816,7 @@ function createCLIParser(argv) {
143725
143816
  );
143726
143817
  logger.log(`${deploymentsWarning}
143727
143818
  `);
143728
- await deployments(accountId, scriptName);
143819
+ await deployments(accountId, scriptName, config);
143729
143820
  }
143730
143821
  );
143731
143822
  wrangler.version(false);
@@ -144022,7 +144113,7 @@ Switch out --local for ${import_chalk10.default.bold(
144022
144113
  )
144023
144114
  );
144024
144115
  }
144025
- const configPath = args.config || args.script && findWranglerToml(import_node_path39.default.dirname(args.script));
144116
+ const configPath = args.config || args.script && findWranglerToml(import_node_path40.default.dirname(args.script));
144026
144117
  let config = readConfig(configPath, args);
144027
144118
  if (config.configPath) {
144028
144119
  watcher = (0, import_chokidar5.watch)(config.configPath, {
@@ -144030,7 +144121,7 @@ Switch out --local for ${import_chalk10.default.bold(
144030
144121
  }).on("change", async (_event) => {
144031
144122
  config = readConfig(configPath, args);
144032
144123
  if (config.configPath) {
144033
- logger.log(`${import_node_path39.default.basename(config.configPath)} changed...`);
144124
+ logger.log(`${import_node_path40.default.basename(config.configPath)} changed...`);
144034
144125
  rerender(await getDevReactElement(config));
144035
144126
  }
144036
144127
  });
@@ -144137,7 +144228,7 @@ async function startApiDev(args) {
144137
144228
  logger.loggerLevel = args.logLevel;
144138
144229
  }
144139
144230
  await printWranglerBanner();
144140
- const configPath = args.config || args.script && findWranglerToml(import_node_path39.default.dirname(args.script));
144231
+ const configPath = args.config || args.script && findWranglerToml(import_node_path40.default.dirname(args.script));
144141
144232
  const config = readConfig(configPath, args);
144142
144233
  const {
144143
144234
  entry,
@@ -144596,6 +144687,12 @@ function parseRequestInput(readyAddress, readyPort, input, init, protocol = "htt
144596
144687
  return [input, init];
144597
144688
  }
144598
144689
 
144690
+ // src/api/pages/index.ts
144691
+ init_import_meta_url();
144692
+ var unstable_pages = {
144693
+ publish: publish2
144694
+ };
144695
+
144599
144696
  // src/cli.ts
144600
144697
  if (typeof jest === "undefined" && require.main === module) {
144601
144698
  main(hideBin(import_process.default.argv)).catch((e2) => {
@@ -144605,7 +144702,8 @@ if (typeof jest === "undefined" && require.main === module) {
144605
144702
  }
144606
144703
  // Annotate the CommonJS export names for ESM import in node:
144607
144704
  0 && (module.exports = {
144608
- unstable_dev
144705
+ unstable_dev,
144706
+ unstable_pages
144609
144707
  });
144610
144708
  /*
144611
144709
  object-assign