wrangler 4.132.0 → 4.133.0

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.
@@ -14,7 +14,6 @@ var crypto3 = require('crypto');
14
14
  var timersPromises = require('timers/promises');
15
15
  var buffer = require('buffer');
16
16
  var fs$1 = require('fs/promises');
17
- var console$1 = require('console');
18
17
  var esbuild = require('esbuild');
19
18
  var miniflare = require('miniflare');
20
19
  var async_hooks = require('async_hooks');
@@ -3592,6 +3591,9 @@ var init_patch_config = __esm({
3592
3591
  for (const [k7, v8] of Object.entries(obj)) {
3593
3592
  const currentPath = [...prevPath, k7];
3594
3593
  if (Array.isArray(v8)) {
3594
+ if (v8.length === 0 && !isArrayInsertion) {
3595
+ allPaths.push([...currentPath, v8]);
3596
+ }
3595
3597
  v8.forEach((x7, i8) => {
3596
3598
  if (isArrayInsertion) {
3597
3599
  allPaths.push([...currentPath, -1, x7]);
@@ -3602,7 +3604,13 @@ var init_patch_config = __esm({
3602
3604
  }
3603
3605
  });
3604
3606
  } else if (typeof v8 === "object" && v8 !== null) {
3605
- getJSONPath(v8, allPaths, isArrayInsertion, currentPath);
3607
+ if (Object.keys(v8).length === 0) {
3608
+ if (!isArrayInsertion) {
3609
+ allPaths.push([...currentPath, v8]);
3610
+ }
3611
+ } else {
3612
+ getJSONPath(v8, allPaths, isArrayInsertion, currentPath);
3613
+ }
3606
3614
  } else {
3607
3615
  allPaths.push([...currentPath, v8]);
3608
3616
  }
@@ -20764,17 +20772,31 @@ function validateRoutes(diagnostics, topLevelEnv, rawEnv, envName) {
20764
20772
  }
20765
20773
  return result;
20766
20774
  }
20767
- function normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv) {
20768
- if (rawEnv.placement) {
20775
+ function normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv, diagnosticField = "placement") {
20776
+ if (rawEnv.placement !== void 0) {
20777
+ if (typeof rawEnv.placement !== "object" || rawEnv.placement === null || Array.isArray(rawEnv.placement)) {
20778
+ diagnostics.errors.push(
20779
+ `The field "${diagnosticField}" should be an object but got ${JSON.stringify(rawEnv.placement)}.`
20780
+ );
20781
+ return inheritable(
20782
+ diagnostics,
20783
+ topLevelEnv,
20784
+ rawEnv,
20785
+ "placement",
20786
+ () => true,
20787
+ void 0
20788
+ );
20789
+ }
20769
20790
  const placement = rawEnv.placement;
20770
20791
  const hasHint = "hint" in placement;
20771
- const hasRegion = "region" in placement;
20772
- const hasHost = "host" in placement;
20773
- const hasHostname = "hostname" in placement;
20774
- const hasTargetedFields = hasRegion || hasHost || hasHostname;
20792
+ const targetedFields = ["region", "host", "hostname"];
20793
+ const presentTargetedFields = targetedFields.filter(
20794
+ (field) => field in placement
20795
+ );
20796
+ const hasTargetedFields = presentTargetedFields.length > 0;
20775
20797
  if (hasHint && hasTargetedFields) {
20776
20798
  diagnostics.errors.push(
20777
- `"placement" cannot have both "hint" (smart format) and "region"/"host"/"hostname" (targeted format) fields`
20799
+ `"${diagnosticField}" cannot have both "hint" (smart format) and "region"/"host"/"hostname" (targeted format) fields`
20778
20800
  );
20779
20801
  return inheritable(
20780
20802
  diagnostics,
@@ -20788,7 +20810,7 @@ function normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv) {
20788
20810
  if (hasHint) {
20789
20811
  validateRequiredProperty(
20790
20812
  diagnostics,
20791
- "placement",
20813
+ diagnosticField,
20792
20814
  "mode",
20793
20815
  placement.mode,
20794
20816
  "string",
@@ -20798,75 +20820,58 @@ function normalizeAndValidatePlacement(diagnostics, topLevelEnv, rawEnv) {
20798
20820
  const hint = placement.hint;
20799
20821
  if (hint !== void 0 && typeof hint !== "string") {
20800
20822
  diagnostics.errors.push(
20801
- `"placement.hint" must be a string when "placement.mode" is "${mode}"`
20823
+ `"${diagnosticField}.hint" must be a string when "${diagnosticField}.mode" is "${mode}"`
20802
20824
  );
20803
20825
  }
20804
20826
  if (hint && mode !== "smart") {
20805
20827
  diagnostics.errors.push(
20806
- `"placement.hint" can only be set when "placement.mode" is "smart"`
20828
+ `"${diagnosticField}.hint" can only be set when "${diagnosticField}.mode" is "smart"`
20807
20829
  );
20808
20830
  }
20809
20831
  } else if (hasTargetedFields) {
20810
20832
  validateOptionalProperty(
20811
20833
  diagnostics,
20812
- "placement",
20834
+ diagnosticField,
20813
20835
  "mode",
20814
20836
  placement.mode,
20815
20837
  "string",
20816
- ["off", "targeted"]
20838
+ ["targeted"]
20817
20839
  );
20818
- if (hasRegion) {
20819
- validateOptionalProperty(
20820
- diagnostics,
20821
- "placement",
20822
- "region",
20823
- placement.region,
20824
- "string"
20825
- );
20826
- }
20827
- if (hasHost) {
20828
- validateOptionalProperty(
20829
- diagnostics,
20830
- "placement",
20831
- "host",
20832
- placement.host,
20833
- "string"
20834
- );
20835
- }
20836
- if (hasHostname) {
20837
- validateOptionalProperty(
20840
+ for (const field of presentTargetedFields) {
20841
+ validateRequiredProperty(
20838
20842
  diagnostics,
20839
- "placement",
20840
- "hostname",
20841
- placement.hostname,
20843
+ diagnosticField,
20844
+ field,
20845
+ placement[field],
20842
20846
  "string"
20843
20847
  );
20844
- }
20845
- const fieldsPresent = [hasRegion, hasHost, hasHostname].filter(Boolean);
20846
- if (fieldsPresent.length > 1) {
20847
- const presentFields = [];
20848
- if (hasRegion) {
20849
- presentFields.push("region");
20850
- }
20851
- if (hasHost) {
20852
- presentFields.push("host");
20853
- }
20854
- if (hasHostname) {
20855
- presentFields.push("hostname");
20848
+ if (placement[field] === "") {
20849
+ diagnostics.errors.push(
20850
+ `"${diagnosticField}.${field}" must be a non-empty string.`
20851
+ );
20856
20852
  }
20853
+ }
20854
+ if (presentTargetedFields.length > 1) {
20857
20855
  diagnostics.errors.push(
20858
- `"placement" fields ${presentFields.map((f8) => `"${f8}"`).join(", ")} are mutually exclusive. Only one can be specified.`
20856
+ `"${diagnosticField}" fields ${presentTargetedFields.map((field) => `"${field}"`).join(", ")} are mutually exclusive. Only one can be specified.`
20859
20857
  );
20860
20858
  }
20861
20859
  } else {
20862
20860
  validateRequiredProperty(
20863
20861
  diagnostics,
20864
- "placement",
20862
+ diagnosticField,
20865
20863
  "mode",
20866
20864
  placement.mode,
20867
20865
  "string",
20868
20866
  ["off", "smart", "targeted"]
20869
20867
  );
20868
+ if (placement.mode === "targeted") {
20869
+ validateAtLeastOnePropertyRequired(diagnostics, diagnosticField, [
20870
+ { key: "region", value: placement.region, type: "string" },
20871
+ { key: "host", value: placement.host, type: "string" },
20872
+ { key: "hostname", value: placement.hostname, type: "string" }
20873
+ ]);
20874
+ }
20870
20875
  }
20871
20876
  }
20872
20877
  return inheritable(
@@ -25377,6 +25382,7 @@ ${resolution}`);
25377
25382
  "logpush",
25378
25383
  "observability",
25379
25384
  "limits",
25385
+ "placement",
25380
25386
  "cache"
25381
25387
  ]) && isValid;
25382
25388
  isValid = validateVars(envName)(
@@ -25391,6 +25397,12 @@ ${resolution}`);
25391
25397
  previews.define,
25392
25398
  void 0
25393
25399
  ) && isValid;
25400
+ normalizeAndValidatePlacement(
25401
+ diagnostics,
25402
+ void 0,
25403
+ previews,
25404
+ `${field}.placement`
25405
+ );
25394
25406
  isValid = validateBindingsProperty(envName, validateDurableObjectBinding)(
25395
25407
  diagnostics,
25396
25408
  `${field}.durable_objects`,
@@ -26912,7 +26924,7 @@ var DEFAULT_COMPAT_DATE;
26912
26924
  var init_default_compat_date = __esm({
26913
26925
  "../workers-utils/src/default-compat-date.ts"() {
26914
26926
  init_import_meta_url();
26915
- DEFAULT_COMPAT_DATE = "2026-09-15";
26927
+ DEFAULT_COMPAT_DATE = "2026-09-16";
26916
26928
  }
26917
26929
  });
26918
26930
 
@@ -59426,7 +59438,7 @@ var init_worker_name = __esm({
59426
59438
  }
59427
59439
  });
59428
59440
  function toUrlPath(filePath) {
59429
- console$1.assert(
59441
+ assert38__default.default(
59430
59442
  !/^[a-z]:/i.test(filePath),
59431
59443
  "Tried to convert a Windows file path with a drive to a URL path."
59432
59444
  );
@@ -61283,7 +61295,7 @@ var name, version2;
61283
61295
  var init_package = __esm({
61284
61296
  "package.json"() {
61285
61297
  name = "wrangler";
61286
- version2 = "4.132.0";
61298
+ version2 = "4.133.0";
61287
61299
  }
61288
61300
  });
61289
61301
 
@@ -142913,8 +142925,8 @@ var require_sync = __commonJS({
142913
142925
  }
142914
142926
  return x7;
142915
142927
  }, "maybeRealpathSync");
142916
- var defaultReadPackageSync = /* @__PURE__ */ __name(function defaultReadPackageSync2(readFileSync36, pkgfile) {
142917
- var body = readFileSync36(pkgfile);
142928
+ var defaultReadPackageSync = /* @__PURE__ */ __name(function defaultReadPackageSync2(readFileSync37, pkgfile) {
142929
+ var body = readFileSync37(pkgfile);
142918
142930
  try {
142919
142931
  var pkg = JSON.parse(body);
142920
142932
  return pkg;
@@ -142934,7 +142946,7 @@ var require_sync = __commonJS({
142934
142946
  }
142935
142947
  var opts = normalizeOptions2(x7, options);
142936
142948
  var isFile3 = opts.isFile || defaultIsFile;
142937
- var readFileSync36 = opts.readFileSync || fs37.readFileSync;
142949
+ var readFileSync37 = opts.readFileSync || fs37.readFileSync;
142938
142950
  var isDirectory4 = opts.isDirectory || defaultIsDir;
142939
142951
  var realpathSync5 = opts.realpathSync || defaultRealpathSync;
142940
142952
  var readPackageSync = opts.readPackageSync || defaultReadPackageSync;
@@ -142991,7 +143003,7 @@ var require_sync = __commonJS({
142991
143003
  if (!isFile3(pkgfile)) {
142992
143004
  return loadpkg(path105.dirname(dir2));
142993
143005
  }
142994
- var pkg = readPackageSync(readFileSync36, pkgfile);
143006
+ var pkg = readPackageSync(readFileSync37, pkgfile);
142995
143007
  if (pkg && opts.packageFilter) {
142996
143008
  pkg = opts.packageFilter(
142997
143009
  pkg,
@@ -143005,7 +143017,7 @@ var require_sync = __commonJS({
143005
143017
  var pkgfile = path105.join(maybeRealpathSync(realpathSync5, x8, opts), "/package.json");
143006
143018
  if (isFile3(pkgfile)) {
143007
143019
  try {
143008
- var pkg = readPackageSync(readFileSync36, pkgfile);
143020
+ var pkg = readPackageSync(readFileSync37, pkgfile);
143009
143021
  } catch (e11) {
143010
143022
  }
143011
143023
  if (pkg && opts.packageFilter) {
@@ -162110,9 +162122,9 @@ var init_parse_bulk_input = __esm({
162110
162122
  });
162111
162123
 
162112
162124
  // ../deploy-helpers/src/deploy/helpers/placement.ts
162113
- function parseConfigPlacement(config2) {
162114
- if (config2.placement) {
162115
- const configPlacement = config2.placement;
162125
+ function parseConfigPlacement(placement) {
162126
+ if (placement) {
162127
+ const configPlacement = placement;
162116
162128
  const hint = "hint" in configPlacement ? configPlacement.hint : void 0;
162117
162129
  if (!hint && configPlacement.mode === "off") {
162118
162130
  return void 0;
@@ -167873,7 +167885,7 @@ async function deployWorker(props, config2, buildResult, callbacks) {
167873
167885
  type: "text"
167874
167886
  });
167875
167887
  }
167876
- const placement = parseConfigPlacement(config2);
167888
+ const placement = parseConfigPlacement(config2.placement);
167877
167889
  const entryPointName = path25__namespace.default.basename(resolvedEntryPointPath);
167878
167890
  const main2 = {
167879
167891
  name: entryPointName,
@@ -168424,7 +168436,7 @@ async function uploadWorkerVersion(props, config2, buildResult, callbacks) {
168424
168436
  preparedContainerImages ?? {},
168425
168437
  { exports: config2.exports }
168426
168438
  );
168427
- const placement = parseConfigPlacement(config2);
168439
+ const placement = parseConfigPlacement(config2.placement);
168428
168440
  const entryPointName = path25__namespace.default.basename(resolvedEntryPointPath);
168429
168441
  const main2 = {
168430
168442
  name: entryPointName,
@@ -169230,13 +169242,18 @@ function extractConfigBindings(config2) {
169230
169242
  };
169231
169243
  }
169232
169244
  for (const r22 of previews?.r2_buckets ?? []) {
169233
- env6[r22.binding] = { type: "r2_bucket", bucket_name: r22.bucket_name };
169245
+ env6[r22.binding] = {
169246
+ type: "r2_bucket",
169247
+ bucket_name: r22.bucket_name,
169248
+ jurisdiction: r22.jurisdiction
169249
+ };
169234
169250
  }
169235
169251
  for (const service of previews?.services ?? []) {
169236
- const crossAccountGrant = service.cross_account_grant;
169252
+ const { cross_account_grant: crossAccountGrant, environment } = service;
169237
169253
  env6[service.binding] = {
169238
169254
  type: "service",
169239
169255
  service: service.service,
169256
+ environment,
169240
169257
  entrypoint: service.entrypoint,
169241
169258
  ...crossAccountGrant !== void 0 && {
169242
169259
  cross_account_grant: crossAccountGrant
@@ -169531,6 +169548,15 @@ function buildPreviewContainerConfig(config2, parentWorkerName, previewSlug, pre
169531
169548
  observability
169532
169549
  };
169533
169550
  }
169551
+ function getPreviewExports(exports$1) {
169552
+ const previewExports = structuredClone(exports$1);
169553
+ for (const configuredExport of Object.values(previewExports)) {
169554
+ if (configuredExport.type === "durable-object" && "container" in configuredExport) {
169555
+ delete configuredExport.container;
169556
+ }
169557
+ }
169558
+ return previewExports;
169559
+ }
169534
169560
  async function prepareContainersForPreview(config2, workerName, previewSlug, callbacks) {
169535
169561
  const previewContainers = config2.previews?.containers ?? [];
169536
169562
  if (previewContainers.length === 0 || !callbacks.getNormalizedContainerOptions) {
@@ -169769,6 +169795,9 @@ async function assemblePreviewDeploymentSettings(config2, buildResult, accountId
169769
169795
  if (config2.compatibility_flags && config2.compatibility_flags.length > 0) {
169770
169796
  request4.compatibility_flags = config2.compatibility_flags;
169771
169797
  }
169798
+ if (Object.keys(config2.exports).length > 0) {
169799
+ request4.exports = getPreviewExports(config2.exports);
169800
+ }
169772
169801
  const repositoryUrl = options.repositoryUrl;
169773
169802
  const pullRequest = options.pullRequest;
169774
169803
  const commitSha = options.commitSha;
@@ -169822,8 +169851,9 @@ async function assemblePreviewDeploymentSettings(config2, buildResult, accountId
169822
169851
  } else if (config2.cache !== void 0) {
169823
169852
  request4.cache = config2.cache;
169824
169853
  }
169825
- if (config2.placement) {
169826
- request4.placement = parseConfigPlacement(config2);
169854
+ const placement = previews?.placement ?? config2.placement;
169855
+ if (placement !== void 0) {
169856
+ request4.placement = placement.mode === "off" ? null : parseConfigPlacement(placement);
169827
169857
  }
169828
169858
  const previewContainers = previews?.containers ?? [];
169829
169859
  if (previewContainers.length > 0) {
@@ -169870,36 +169900,36 @@ function formatPreviewDeploymentSummary(config2, previewResource, deployment, is
169870
169900
  return [
169871
169901
  `${source_default.bold("Preview:")} ${previewResource.name} ${statusLabel}`,
169872
169902
  ...formatUrlLines("Preview", previewResource.urls),
169873
- "",
169874
- `${source_default.bold("Deployment ID:")} ${deployment.id}`,
169875
- ...formatUrlLines("Deployment", deployment.urls),
169876
169903
  ...pullRequestUrl || pullRequestNumber ? [
169877
169904
  `${source_default.bold("Pull Request:")} ${pullRequestUrl ?? `#${pullRequestNumber}`}`
169878
169905
  ] : [],
169906
+ ...formatUrlLines("Unique Deployment", deployment.urls),
169879
169907
  ...hasActiveUrls ? [] : [formatNoActivePreviewUrlsMessage(config2)]
169880
169908
  ].join("\n");
169881
169909
  }
169882
- function logMissingPreviewsBindingsWarning(topLevelBindings, remotePreviewDefaultBindings, localPreviewBindings) {
169910
+ function logMissingPreviewsBindingsWarning(productionBindingsExpectedInPreview, remotePreviewDefaultBindings, localPreviewBindings) {
169883
169911
  const availableBindingNames = /* @__PURE__ */ new Set([
169884
169912
  ...Object.keys(remotePreviewDefaultBindings ?? {}),
169885
169913
  ...Object.keys(localPreviewBindings)
169886
169914
  ]);
169887
- const missingBindings = Object.fromEntries(
169888
- Object.entries(topLevelBindings).filter(
169915
+ const missingPreviewBindings = Object.fromEntries(
169916
+ Object.entries(productionBindingsExpectedInPreview).filter(
169889
169917
  ([name2]) => !availableBindingNames.has(name2)
169890
169918
  )
169891
169919
  );
169892
- if (Object.keys(missingBindings).length === 0) {
169920
+ if (Object.keys(missingPreviewBindings).length === 0) {
169893
169921
  return;
169894
169922
  }
169895
- logger.warn(`Your configuration has diverged.
169896
- The following bindings are configured at the top level of your Wrangler config file, but are missing from the Previews settings of your Worker.
169923
+ logger.warn(`These bindings are configured for your production Worker but not for Previews:
169897
169924
 
169898
- ${Object.entries(missingBindings).map(
169925
+ ${Object.entries(missingPreviewBindings).map(
169899
169926
  ([name2, binding]) => ` ${source_default.cyan(name2)} ${source_default.dim(getBindingTypeFriendlyName(binding.type))}`
169900
169927
  ).join("\n")}
169901
169928
 
169902
- Either include these bindings in the ${source_default.cyan(`"previews"`)} field of your Wrangler config or update the Previews settings of your Worker in the Cloudflare dashboard.`);
169929
+ Parts of your Worker that depend on these bindings may not work correctly in the Preview. If this is not intentional, add Preview-safe values to the ${source_default.cyan("previews")} field.
169930
+
169931
+ Configuration: https://developers.cloudflare.com/workers/previews/configuration/
169932
+ Resources: https://developers.cloudflare.com/workers/previews/resources/`);
169903
169933
  }
169904
169934
  async function provisionParentWorker(config2, accountId, workerName, json2) {
169905
169935
  const confirmed = json2 || await confirm(
@@ -170053,28 +170083,28 @@ async function preview(accountId, args, config2, buildResult, assetsOptions, cal
170053
170083
  JSON.stringify({ preview: previewResource, deployment }, null, 2)
170054
170084
  );
170055
170085
  } else {
170056
- logger.log(
170057
- formatPreviewDeploymentSummary(
170058
- config2,
170059
- previewResource,
170060
- deployment,
170061
- isNewPreview,
170062
- pullRequest
170063
- )
170064
- );
170065
- const topLevelBindings = getBindings(config2);
170066
- if (Object.keys(topLevelBindings).length > 0) {
170086
+ const productionBindingsExpectedInPreview = callbacks.productionBindingsExpectedInPreview ?? {};
170087
+ if (Object.keys(productionBindingsExpectedInPreview).length > 0) {
170067
170088
  const previewBaseConfig = await getPreviewBaseConfig(
170068
170089
  config2,
170069
170090
  accountId,
170070
170091
  workerName
170071
170092
  );
170072
170093
  logMissingPreviewsBindingsWarning(
170073
- topLevelBindings,
170094
+ productionBindingsExpectedInPreview,
170074
170095
  previewBaseConfig.env,
170075
170096
  deploymentRequest.env ?? {}
170076
170097
  );
170077
170098
  }
170099
+ logger.log(
170100
+ formatPreviewDeploymentSummary(
170101
+ config2,
170102
+ previewResource,
170103
+ deployment,
170104
+ isNewPreview,
170105
+ pullRequest
170106
+ )
170107
+ );
170078
170108
  }
170079
170109
  return { preview: previewResource, deployment, isNewPreview };
170080
170110
  }
@@ -170122,6 +170152,7 @@ var init_preview2 = __esm({
170122
170152
  init_api2();
170123
170153
  init_shared2();
170124
170154
  __name(buildPreviewContainerConfig, "buildPreviewContainerConfig");
170155
+ __name(getPreviewExports, "getPreviewExports");
170125
170156
  __name(prepareContainersForPreview, "prepareContainersForPreview");
170126
170157
  NO_ACTIVE_PREVIEW_URLS_MESSAGE = "Note: This Preview deployment has no active URLs.";
170127
170158
  __name(isCustomDomainRoute, "isCustomDomainRoute");
@@ -172584,7 +172615,7 @@ var init_dist12 = __esm({
172584
172615
  init_wrapper();
172585
172616
  init_create_worker_upload_form();
172586
172617
  import_undici13 = __toESM(require_undici(), 1);
172587
- version3 = "0.0.25";
172618
+ version3 = "0.0.26";
172588
172619
  NoDefaultValueProvided2 = class extends UserError {
172589
172620
  static {
172590
172621
  __name(this, "NoDefaultValueProvided");
@@ -283389,9 +283420,11 @@ async function buildOperationsSummary(autoConfigDetails, workerConfig, configura
283389
283420
  const scriptOverrides = target === "wrangler" ? packageJsonScriptsOverrides : void 0;
283390
283421
  const buildCommandPrefix = target === "wrangler" && autoConfigDetails.buildCommand ? `${autoConfigDetails.buildCommand} && ` : "";
283391
283422
  summary.scripts = {
283392
- deploy: scriptOverrides?.deploy ?? `${buildCommandPrefix}${target} deploy`,
283393
- preview: scriptOverrides?.preview ?? `${buildCommandPrefix}${target} dev`
283423
+ deploy: scriptOverrides?.deploy ?? `${buildCommandPrefix}${target} deploy`
283394
283424
  };
283425
+ if (target === "wrangler") {
283426
+ summary.scripts.preview = scriptOverrides?.preview ?? `${buildCommandPrefix}${target} dev`;
283427
+ }
283395
283428
  const containsServerSideCode = (
283396
283429
  // If there is an entrypoint then we know that there is server side code
283397
283430
  !!workerConfig?.entrypoint
@@ -292028,7 +292061,7 @@ function createWorkerBundleFormData(workerBundle, config2) {
292028
292061
  };
292029
292062
  let placement;
292030
292063
  if (config2 !== void 0) {
292031
- placement = parseConfigPlacement(config2);
292064
+ placement = parseConfigPlacement(config2.placement);
292032
292065
  } else {
292033
292066
  placement = void 0;
292034
292067
  }
@@ -335616,6 +335649,782 @@ var init_containers4 = __esm({
335616
335649
  }
335617
335650
  });
335618
335651
 
335652
+ // src/utils/omit-nullish.ts
335653
+ function omitNullish(object2) {
335654
+ return Object.fromEntries(
335655
+ Object.entries(object2).filter(
335656
+ ([, value]) => value !== null && value !== void 0
335657
+ )
335658
+ );
335659
+ }
335660
+ var init_omit_nullish = __esm({
335661
+ "src/utils/omit-nullish.ts"() {
335662
+ init_import_meta_url();
335663
+ __name(omitNullish, "omitNullish");
335664
+ }
335665
+ });
335666
+
335667
+ // src/preview/preview-config.ts
335668
+ function convertPreviewBaseToPreviewsConfig(baseConfig) {
335669
+ const convertedSettings = convertPreviewSettings(
335670
+ baseConfig.env ?? {},
335671
+ {
335672
+ define: void 0,
335673
+ observability: baseConfig.observability,
335674
+ logpush: baseConfig.logpush,
335675
+ limits: baseConfig.limits,
335676
+ placement: baseConfig.placement,
335677
+ cache: baseConfig.cache,
335678
+ containers: void 0,
335679
+ tail_consumers: baseConfig.tail_consumers?.map(({ name: name2 }) => ({
335680
+ service: name2
335681
+ })),
335682
+ streaming_tail_consumers: void 0,
335683
+ queues: {},
335684
+ triggers: {}
335685
+ },
335686
+ false
335687
+ );
335688
+ return convertedSettings;
335689
+ }
335690
+ function convertProductionToPreviewsConfig(config2) {
335691
+ const convertedSettings = convertPreviewSettings(
335692
+ extractConfigBindings({ ...config2, previews: config2 }),
335693
+ {
335694
+ define: config2.define,
335695
+ observability: config2.observability,
335696
+ logpush: config2.logpush,
335697
+ limits: config2.limits,
335698
+ placement: config2.placement,
335699
+ cache: config2.cache,
335700
+ containers: config2.containers,
335701
+ tail_consumers: config2.tail_consumers,
335702
+ streaming_tail_consumers: config2.streaming_tail_consumers,
335703
+ queues: config2.queues,
335704
+ triggers: config2.triggers
335705
+ },
335706
+ true
335707
+ );
335708
+ return convertedSettings;
335709
+ }
335710
+ function getProductionBindingsExpectedInPreview(config2) {
335711
+ const bindings = extractConfigBindings({ ...config2, previews: config2 });
335712
+ return Object.fromEntries(
335713
+ Object.entries(bindings).filter(
335714
+ ([name2, binding]) => convertBinding(name2, binding, true).config !== void 0
335715
+ )
335716
+ );
335717
+ }
335718
+ function convertTopLevelSetting(settings, setting, usePlaceholderValue) {
335719
+ const converted = {};
335720
+ switch (setting) {
335721
+ case "define": {
335722
+ const define2 = settings.define;
335723
+ if (define2 === void 0 || usePlaceholderValue && Object.keys(define2).length === 0) {
335724
+ break;
335725
+ }
335726
+ converted.define = Object.fromEntries(
335727
+ Object.keys(define2).map((name2) => [
335728
+ name2,
335729
+ usePlaceholderValue ? REPLACE_ME : define2[name2]
335730
+ ])
335731
+ );
335732
+ break;
335733
+ }
335734
+ case "observability": {
335735
+ if (usePlaceholderValue) {
335736
+ break;
335737
+ }
335738
+ const observability = settings.observability;
335739
+ if (observability === void 0) {
335740
+ break;
335741
+ }
335742
+ converted.observability = omitNullish({
335743
+ enabled: observability.enabled,
335744
+ head_sampling_rate: observability.head_sampling_rate,
335745
+ redact_query_string: observability.redact_query_string,
335746
+ logs: observability.logs === void 0 ? void 0 : omitNullish({
335747
+ enabled: observability.logs.enabled,
335748
+ head_sampling_rate: observability.logs.head_sampling_rate,
335749
+ invocation_logs: observability.logs.invocation_logs,
335750
+ persist: observability.logs.persist,
335751
+ destinations: observability.logs.destinations === void 0 ? void 0 : usePlaceholderValue ? observability.logs.destinations.map(() => REPLACE_ME) : observability.logs.destinations
335752
+ }),
335753
+ traces: observability.traces === void 0 ? void 0 : omitNullish({
335754
+ enabled: observability.traces.enabled,
335755
+ head_sampling_rate: observability.traces.head_sampling_rate,
335756
+ persist: observability.traces.persist,
335757
+ destinations: observability.traces.destinations === void 0 ? void 0 : usePlaceholderValue ? observability.traces.destinations.map(() => REPLACE_ME) : observability.traces.destinations
335758
+ })
335759
+ });
335760
+ break;
335761
+ }
335762
+ case "logpush":
335763
+ if (!usePlaceholderValue && settings.logpush !== void 0) {
335764
+ converted.logpush = settings.logpush;
335765
+ }
335766
+ break;
335767
+ case "limits":
335768
+ if (!usePlaceholderValue && settings.limits !== void 0) {
335769
+ converted.limits = omitNullish({
335770
+ cpu_ms: settings.limits.cpu_ms,
335771
+ subrequests: settings.limits.subrequests
335772
+ });
335773
+ }
335774
+ break;
335775
+ case "placement": {
335776
+ const placement = settings.placement;
335777
+ if (placement === void 0) {
335778
+ break;
335779
+ }
335780
+ if (placement.mode === "smart") {
335781
+ converted.placement = {
335782
+ mode: placement.mode,
335783
+ ...placement.hint !== void 0 && {
335784
+ hint: usePlaceholderValue ? REPLACE_ME : placement.hint
335785
+ }
335786
+ };
335787
+ } else if (placement.mode === "off") {
335788
+ converted.placement = { mode: placement.mode };
335789
+ } else if ("region" in placement) {
335790
+ converted.placement = omitNullish({
335791
+ mode: placement.mode,
335792
+ region: usePlaceholderValue ? REPLACE_ME : placement.region
335793
+ });
335794
+ } else if ("host" in placement) {
335795
+ converted.placement = omitNullish({
335796
+ mode: placement.mode,
335797
+ host: usePlaceholderValue ? REPLACE_ME : placement.host
335798
+ });
335799
+ } else if ("hostname" in placement) {
335800
+ converted.placement = omitNullish({
335801
+ mode: placement.mode,
335802
+ hostname: usePlaceholderValue ? REPLACE_ME : placement.hostname
335803
+ });
335804
+ }
335805
+ break;
335806
+ }
335807
+ case "cache":
335808
+ if (!usePlaceholderValue && settings.cache !== void 0) {
335809
+ converted.cache = omitNullish({
335810
+ enabled: settings.cache.enabled,
335811
+ cross_version_cache: settings.cache.cross_version_cache
335812
+ });
335813
+ }
335814
+ break;
335815
+ case "tail_consumers":
335816
+ if (settings.tail_consumers !== void 0) {
335817
+ converted.tail_consumers = settings.tail_consumers.map(
335818
+ ({ service }) => ({
335819
+ service: usePlaceholderValue ? REPLACE_ME : service
335820
+ })
335821
+ );
335822
+ if (settings.tail_consumers.some(
335823
+ ({ environment }) => environment !== void 0
335824
+ )) {
335825
+ return {
335826
+ config: converted,
335827
+ bindingLimitationName: "Tail consumer environments"
335828
+ };
335829
+ }
335830
+ }
335831
+ break;
335832
+ case "containers":
335833
+ if (settings.containers !== void 0 && settings.containers.length > 0) {
335834
+ return {
335835
+ blockDeploymentMessage: "This Worker uses Containers. They are not included in the suggested Preview configuration.\nFollow the setup instructions so each Preview automatically gets a new, isolated Container app and state:\nhttps://developers.cloudflare.com/workers/previews/resources/#containers"
335836
+ };
335837
+ }
335838
+ break;
335839
+ case "streaming_tail_consumers":
335840
+ break;
335841
+ case "queues":
335842
+ if ((settings.queues?.consumers?.length ?? 0) > 0) {
335843
+ return { bindingLimitationName: "Queue consumers" };
335844
+ }
335845
+ break;
335846
+ case "triggers": {
335847
+ const hasCrons = (settings.triggers?.crons?.length ?? 0) > 0;
335848
+ const hasEvents = (settings.triggers?.events?.length ?? 0) > 0;
335849
+ if (hasCrons || hasEvents) {
335850
+ return {
335851
+ bindingLimitationName: hasCrons && hasEvents ? "Cron and Artifacts event triggers" : hasCrons ? "Cron triggers" : "Artifacts event triggers"
335852
+ };
335853
+ }
335854
+ break;
335855
+ }
335856
+ default: {
335857
+ const exhaustiveCheck = setting;
335858
+ throw new Error(`Unexpected Preview setting: ${exhaustiveCheck}`);
335859
+ }
335860
+ }
335861
+ return Object.keys(converted).length > 0 ? { config: converted } : {};
335862
+ }
335863
+ function convertPreviewSettings(bindings, settings, usePlaceholderValue) {
335864
+ const config2 = /* @__PURE__ */ new Map();
335865
+ const bindingLimitationNames = /* @__PURE__ */ new Set();
335866
+ const blockingDeploymentMessages = /* @__PURE__ */ new Set();
335867
+ const conversions = [
335868
+ ...Object.entries(bindings).map(
335869
+ ([name2, binding]) => convertBinding(name2, binding, usePlaceholderValue)
335870
+ ),
335871
+ ...Object.keys(settings).map(
335872
+ (setting) => convertTopLevelSetting(settings, setting, usePlaceholderValue)
335873
+ )
335874
+ ];
335875
+ for (const converted of conversions) {
335876
+ if (converted.bindingLimitationName !== void 0) {
335877
+ bindingLimitationNames.add(converted.bindingLimitationName);
335878
+ }
335879
+ if (converted.blockDeploymentMessage !== void 0) {
335880
+ blockingDeploymentMessages.add(converted.blockDeploymentMessage);
335881
+ }
335882
+ if (converted.config !== void 0) {
335883
+ for (const [configField, configValue] of Object.entries(
335884
+ converted.config
335885
+ )) {
335886
+ const current = config2.get(configField);
335887
+ if (current === void 0) {
335888
+ config2.set(configField, configValue);
335889
+ continue;
335890
+ }
335891
+ if (Array.isArray(current) && Array.isArray(configValue)) {
335892
+ config2.set(configField, [...current, ...configValue]);
335893
+ continue;
335894
+ }
335895
+ if (typeof current === "object" && current !== null && !Array.isArray(current) && typeof configValue === "object" && configValue !== null && !Array.isArray(configValue)) {
335896
+ const merged = new Map(Object.entries(current));
335897
+ for (const [key, next] of Object.entries(configValue)) {
335898
+ const existing = merged.get(key);
335899
+ if (existing === void 0) {
335900
+ merged.set(key, next);
335901
+ } else if (Array.isArray(existing) && Array.isArray(next)) {
335902
+ merged.set(key, [...existing, ...next]);
335903
+ } else {
335904
+ throw new UserError(
335905
+ `Preview ${configField} binding is defined more than once. Rename one of the bindings so each Preview setting is produced only once.`,
335906
+ {
335907
+ telemetryMessage: "preview command duplicate previews binding"
335908
+ }
335909
+ );
335910
+ }
335911
+ }
335912
+ config2.set(configField, Object.fromEntries(merged));
335913
+ continue;
335914
+ }
335915
+ throw new UserError(
335916
+ `Preview ${configField} binding is defined more than once. Rename one of the bindings so each Preview setting is produced only once.`,
335917
+ {
335918
+ telemetryMessage: "preview command duplicate previews binding"
335919
+ }
335920
+ );
335921
+ }
335922
+ }
335923
+ }
335924
+ return {
335925
+ config: Object.fromEntries(config2),
335926
+ messages: [
335927
+ ...bindingLimitationNames.size === 0 ? [] : [
335928
+ `These settings have limitations in Worker Previews: ${[
335929
+ ...bindingLimitationNames
335930
+ ].join(
335931
+ ", "
335932
+ )}.
335933
+ Wrangler did not add them automatically. Review the limitations, then decide how you want to configure them for your Preview.
335934
+ Learn more: https://developers.cloudflare.com/workers/previews/limitations/`
335935
+ ]
335936
+ ],
335937
+ blockingDeploymentMessages: [...blockingDeploymentMessages]
335938
+ };
335939
+ }
335940
+ function convertBinding(name2, binding, usePlaceholderValue) {
335941
+ let config2;
335942
+ switch (binding.type) {
335943
+ case "plain_text":
335944
+ if (binding.text === void 0) {
335945
+ break;
335946
+ }
335947
+ config2 = {
335948
+ vars: {
335949
+ [name2]: usePlaceholderValue ? REPLACE_ME : binding.text
335950
+ }
335951
+ };
335952
+ break;
335953
+ case "json":
335954
+ if (binding.json === void 0) {
335955
+ break;
335956
+ }
335957
+ config2 = {
335958
+ vars: {
335959
+ [name2]: usePlaceholderValue ? REPLACE_ME : binding.json
335960
+ }
335961
+ };
335962
+ break;
335963
+ case "browser":
335964
+ config2 = { browser: { binding: name2 } };
335965
+ break;
335966
+ case "ai":
335967
+ config2 = {
335968
+ ai: {
335969
+ binding: name2,
335970
+ ...binding.staging !== void 0 && {
335971
+ staging: binding.staging
335972
+ }
335973
+ }
335974
+ };
335975
+ break;
335976
+ case "images":
335977
+ config2 = { images: { binding: name2 } };
335978
+ break;
335979
+ case "stream":
335980
+ config2 = { stream: { binding: name2 } };
335981
+ break;
335982
+ case "version_metadata":
335983
+ config2 = { version_metadata: { binding: name2 } };
335984
+ break;
335985
+ case "kv_namespace":
335986
+ if (binding.namespace_id === void 0) {
335987
+ break;
335988
+ }
335989
+ config2 = {
335990
+ kv_namespaces: [
335991
+ {
335992
+ binding: name2,
335993
+ id: usePlaceholderValue ? REPLACE_ME : binding.namespace_id
335994
+ }
335995
+ ]
335996
+ };
335997
+ break;
335998
+ case "media":
335999
+ config2 = { media: { binding: name2 } };
336000
+ break;
336001
+ case "send_email":
336002
+ config2 = {
336003
+ send_email: [
336004
+ {
336005
+ name: name2,
336006
+ ...binding.destination_address !== void 0 && {
336007
+ destination_address: usePlaceholderValue ? REPLACE_ME : binding.destination_address
336008
+ },
336009
+ ...binding.allowed_destination_addresses !== void 0 && {
336010
+ allowed_destination_addresses: usePlaceholderValue ? binding.allowed_destination_addresses.map(() => REPLACE_ME) : binding.allowed_destination_addresses
336011
+ },
336012
+ ...binding.allowed_sender_addresses !== void 0 && {
336013
+ allowed_sender_addresses: usePlaceholderValue ? binding.allowed_sender_addresses.map(() => REPLACE_ME) : binding.allowed_sender_addresses
336014
+ }
336015
+ }
336016
+ ]
336017
+ };
336018
+ break;
336019
+ case "durable_object_namespace":
336020
+ return {
336021
+ blockDeploymentMessage: "This Worker uses Durable Objects. They are not included in the suggested Preview configuration.\nFollow the setup instructions so each Preview automatically gets a new, isolated Durable Object namespace:\nhttps://developers.cloudflare.com/workers/previews/resources/#durable-objects"
336022
+ };
336023
+ case "workflow":
336024
+ return { bindingLimitationName: "Workflows" };
336025
+ case "queue":
336026
+ if (binding.queue_name === void 0) {
336027
+ break;
336028
+ }
336029
+ config2 = {
336030
+ queues: {
336031
+ producers: [
336032
+ omitNullish({
336033
+ binding: name2,
336034
+ queue: usePlaceholderValue ? REPLACE_ME : binding.queue_name,
336035
+ delivery_delay: binding.delivery_delay
336036
+ })
336037
+ ]
336038
+ }
336039
+ };
336040
+ break;
336041
+ case "r2_bucket":
336042
+ if (binding.bucket_name === void 0) {
336043
+ break;
336044
+ }
336045
+ config2 = {
336046
+ r2_buckets: [
336047
+ {
336048
+ binding: name2,
336049
+ bucket_name: usePlaceholderValue ? REPLACE_ME : binding.bucket_name,
336050
+ jurisdiction: binding.jurisdiction
336051
+ }
336052
+ ]
336053
+ };
336054
+ break;
336055
+ case "d1": {
336056
+ const databaseId = binding.database_id ?? binding.id;
336057
+ if (databaseId === void 0) {
336058
+ break;
336059
+ }
336060
+ config2 = {
336061
+ d1_databases: [
336062
+ {
336063
+ binding: name2,
336064
+ database_id: usePlaceholderValue ? REPLACE_ME : databaseId
336065
+ }
336066
+ ]
336067
+ };
336068
+ break;
336069
+ }
336070
+ case "vectorize":
336071
+ if (binding.index_name === void 0) {
336072
+ break;
336073
+ }
336074
+ config2 = {
336075
+ vectorize: [
336076
+ {
336077
+ binding: name2,
336078
+ index_name: usePlaceholderValue ? REPLACE_ME : binding.index_name
336079
+ }
336080
+ ]
336081
+ };
336082
+ break;
336083
+ case "ai_search_namespace":
336084
+ if (binding.namespace === void 0) {
336085
+ break;
336086
+ }
336087
+ config2 = {
336088
+ ai_search_namespaces: [
336089
+ {
336090
+ binding: name2,
336091
+ namespace: usePlaceholderValue ? REPLACE_ME : binding.namespace
336092
+ }
336093
+ ]
336094
+ };
336095
+ break;
336096
+ case "ai_search":
336097
+ if (binding.instance_name === void 0) {
336098
+ break;
336099
+ }
336100
+ config2 = {
336101
+ ai_search: [
336102
+ {
336103
+ binding: name2,
336104
+ instance_name: usePlaceholderValue ? REPLACE_ME : binding.instance_name
336105
+ }
336106
+ ]
336107
+ };
336108
+ break;
336109
+ case "hyperdrive":
336110
+ if (binding.id === void 0) {
336111
+ break;
336112
+ }
336113
+ config2 = {
336114
+ hyperdrive: [
336115
+ {
336116
+ binding: name2,
336117
+ id: usePlaceholderValue ? REPLACE_ME : binding.id
336118
+ }
336119
+ ]
336120
+ };
336121
+ break;
336122
+ case "service":
336123
+ return { bindingLimitationName: "Service Bindings" };
336124
+ case "analytics_engine":
336125
+ config2 = {
336126
+ analytics_engine_datasets: [
336127
+ {
336128
+ binding: name2,
336129
+ ...binding.dataset !== void 0 && {
336130
+ dataset: usePlaceholderValue ? REPLACE_ME : binding.dataset
336131
+ }
336132
+ }
336133
+ ]
336134
+ };
336135
+ break;
336136
+ case "dispatch_namespace":
336137
+ if (binding.namespace === void 0) {
336138
+ break;
336139
+ }
336140
+ config2 = {
336141
+ dispatch_namespaces: [
336142
+ {
336143
+ binding: name2,
336144
+ namespace: usePlaceholderValue ? REPLACE_ME : binding.namespace,
336145
+ ...binding.outbound !== void 0 && {
336146
+ outbound: {
336147
+ service: usePlaceholderValue ? REPLACE_ME : binding.outbound.worker.service,
336148
+ ...binding.outbound.worker.environment !== void 0 && {
336149
+ environment: usePlaceholderValue ? REPLACE_ME : binding.outbound.worker.environment
336150
+ },
336151
+ parameters: usePlaceholderValue ? Array.from(
336152
+ { length: binding.outbound.params?.length ?? 0 },
336153
+ () => REPLACE_ME
336154
+ ) : binding.outbound.params?.map(
336155
+ ({ name: parameterName }) => parameterName
336156
+ ) ?? []
336157
+ }
336158
+ }
336159
+ }
336160
+ ]
336161
+ };
336162
+ break;
336163
+ case "mtls_certificate":
336164
+ if (binding.certificate_id === void 0) {
336165
+ break;
336166
+ }
336167
+ config2 = {
336168
+ mtls_certificates: [
336169
+ {
336170
+ binding: name2,
336171
+ certificate_id: usePlaceholderValue ? REPLACE_ME : binding.certificate_id
336172
+ }
336173
+ ]
336174
+ };
336175
+ break;
336176
+ case "pipelines":
336177
+ if (binding.stream === void 0 && binding.pipeline === void 0) {
336178
+ break;
336179
+ }
336180
+ config2 = {
336181
+ pipelines: [
336182
+ {
336183
+ binding: name2,
336184
+ ...binding.stream !== void 0 && {
336185
+ stream: usePlaceholderValue ? REPLACE_ME : binding.stream
336186
+ },
336187
+ ...binding.pipeline !== void 0 && {
336188
+ pipeline: usePlaceholderValue ? REPLACE_ME : binding.pipeline
336189
+ }
336190
+ }
336191
+ ]
336192
+ };
336193
+ break;
336194
+ case "secrets_store_secret":
336195
+ if (binding.store_id === void 0 || binding.secret_name === void 0) {
336196
+ break;
336197
+ }
336198
+ config2 = {
336199
+ secrets_store_secrets: [
336200
+ {
336201
+ binding: name2,
336202
+ store_id: usePlaceholderValue ? REPLACE_ME : binding.store_id,
336203
+ secret_name: usePlaceholderValue ? REPLACE_ME : binding.secret_name
336204
+ }
336205
+ ]
336206
+ };
336207
+ break;
336208
+ case "artifacts":
336209
+ if (binding.namespace === void 0) {
336210
+ break;
336211
+ }
336212
+ config2 = {
336213
+ artifacts: [
336214
+ {
336215
+ binding: name2,
336216
+ namespace: usePlaceholderValue ? REPLACE_ME : binding.namespace
336217
+ }
336218
+ ]
336219
+ };
336220
+ break;
336221
+ case "flagship":
336222
+ if (binding.app_id === void 0) {
336223
+ break;
336224
+ }
336225
+ config2 = {
336226
+ flagship: [
336227
+ {
336228
+ binding: name2,
336229
+ app_id: usePlaceholderValue ? REPLACE_ME : binding.app_id
336230
+ }
336231
+ ]
336232
+ };
336233
+ break;
336234
+ case "ratelimit":
336235
+ if (binding.namespace_id === void 0 || binding.simple === void 0) {
336236
+ break;
336237
+ }
336238
+ config2 = {
336239
+ ratelimits: [
336240
+ {
336241
+ name: name2,
336242
+ namespace_id: usePlaceholderValue ? REPLACE_ME : binding.namespace_id,
336243
+ simple: binding.simple
336244
+ }
336245
+ ]
336246
+ };
336247
+ break;
336248
+ case "vpc_service":
336249
+ if (binding.service_id === void 0) {
336250
+ break;
336251
+ }
336252
+ config2 = {
336253
+ vpc_services: [
336254
+ {
336255
+ binding: name2,
336256
+ service_id: usePlaceholderValue ? REPLACE_ME : binding.service_id
336257
+ }
336258
+ ]
336259
+ };
336260
+ break;
336261
+ case "worker_loader":
336262
+ config2 = { worker_loaders: [{ binding: name2 }] };
336263
+ break;
336264
+ }
336265
+ return config2 === void 0 ? {} : { config: config2 };
336266
+ }
336267
+ var REPLACE_ME;
336268
+ var init_preview_config = __esm({
336269
+ "src/preview/preview-config.ts"() {
336270
+ init_import_meta_url();
336271
+ init_src3();
336272
+ init_src();
336273
+ init_omit_nullish();
336274
+ REPLACE_ME = "<REPLACE_ME>";
336275
+ __name(convertPreviewBaseToPreviewsConfig, "convertPreviewBaseToPreviewsConfig");
336276
+ __name(convertProductionToPreviewsConfig, "convertProductionToPreviewsConfig");
336277
+ __name(getProductionBindingsExpectedInPreview, "getProductionBindingsExpectedInPreview");
336278
+ __name(convertTopLevelSetting, "convertTopLevelSetting");
336279
+ __name(convertPreviewSettings, "convertPreviewSettings");
336280
+ __name(convertBinding, "convertBinding");
336281
+ }
336282
+ });
336283
+ function logConversionMessages(messages, json2) {
336284
+ if (!json2) {
336285
+ for (const message of messages) {
336286
+ logger2.warn(message);
336287
+ }
336288
+ }
336289
+ }
336290
+ function hasConfiguredFields(value) {
336291
+ return value !== void 0 && Object.keys(value).length > 0;
336292
+ }
336293
+ function containsGeneratedPlaceholder(value) {
336294
+ if (value === REPLACE_ME) {
336295
+ return true;
336296
+ }
336297
+ if (Array.isArray(value)) {
336298
+ return value.some(containsGeneratedPlaceholder);
336299
+ }
336300
+ if (typeof value === "object" && value !== null) {
336301
+ return Object.entries(value).some(
336302
+ ([key, child]) => key === REPLACE_ME || containsGeneratedPlaceholder(child)
336303
+ );
336304
+ }
336305
+ return false;
336306
+ }
336307
+ function writePreviewsConfig(config2, previews) {
336308
+ const configPath = config2.userConfigPath;
336309
+ if (configPath === void 0) {
336310
+ throw new Error("Cannot write Preview configuration without a user config");
336311
+ }
336312
+ const patch = config2.targetEnvironment ? { env: { [config2.targetEnvironment]: { previews } } } : { previews };
336313
+ exports.experimental_patchConfig(configPath, patch, false);
336314
+ }
336315
+ async function ensurePreviewsConfig(accountId, args, config2) {
336316
+ if (config2.previews !== void 0) {
336317
+ if (containsGeneratedPlaceholder(config2.previews)) {
336318
+ throw new UserError(
336319
+ "Your Preview configuration still contains <REPLACE_ME>. Replace it with a Preview-safe value before deploying.",
336320
+ {
336321
+ telemetryMessage: "preview command previews configuration placeholder"
336322
+ }
336323
+ );
336324
+ }
336325
+ return config2;
336326
+ }
336327
+ if (!args.json && config2.targetEnvironment === void 0 && config2.definedEnvironments !== void 0 && config2.definedEnvironments.length > 0) {
336328
+ logger2.warn(
336329
+ "Wrangler found named environments in your configuration. Pass `--env <environment>` to target a named environment, or omit `--env` to target the top-level Worker.\nSee https://developers.cloudflare.com/workers/previews/compare-workflows/#wrangler-environments for more information."
336330
+ );
336331
+ }
336332
+ const configPath = config2.userConfigPath ?? config2.configPath;
336333
+ const workerName = resolveWorkerName(args, config2);
336334
+ let baseConfig;
336335
+ if (!args.ignoreBaseConfig) {
336336
+ try {
336337
+ baseConfig = await getPreviewBaseConfig(config2, accountId, workerName);
336338
+ } catch (error53) {
336339
+ if (!isWorkerNotFoundError(error53)) {
336340
+ throw error53;
336341
+ }
336342
+ }
336343
+ }
336344
+ const productionConversion = convertProductionToPreviewsConfig(config2);
336345
+ const baseConversion = baseConfig ? convertPreviewBaseToPreviewsConfig(baseConfig) : { config: {}, messages: [], blockingDeploymentMessages: [] };
336346
+ const hasPreviewBase = hasConfiguredFields(baseConfig);
336347
+ const selectedConversion = hasPreviewBase ? baseConversion : productionConversion;
336348
+ const proposedConfig = selectedConversion.config;
336349
+ const proposedConfigPatch = config2.targetEnvironment ? { env: { [config2.targetEnvironment]: { previews: proposedConfig } } } : { previews: proposedConfig };
336350
+ const formattedProposedConfig = formatConfigSnippet(
336351
+ proposedConfigPatch,
336352
+ configPath
336353
+ );
336354
+ const conversionMessages = [
336355
+ .../* @__PURE__ */ new Set([
336356
+ ...selectedConversion.messages,
336357
+ ...selectedConversion.blockingDeploymentMessages
336358
+ ])
336359
+ ];
336360
+ if (!hasPreviewBase && containsGeneratedPlaceholder(proposedConfig)) {
336361
+ conversionMessages.push(
336362
+ "Replace each <REPLACE_ME> placeholder with a Preview-safe value. Do not use production resources unless you intend for this Preview to access them."
336363
+ );
336364
+ }
336365
+ const hasEmptyProposedConfig = Object.keys(proposedConfig).length === 0;
336366
+ const hasBlockingDeploymentMessages = selectedConversion.blockingDeploymentMessages.length > 0;
336367
+ const missingPreviewsConfigParagraphs = [
336368
+ hasEmptyProposedConfig && conversionMessages.length === 0 ? "Your Wrangler configuration is missing a `previews` block to run this command. Add the following to your configuration file:" : hasEmptyProposedConfig || hasBlockingDeploymentMessages ? "Your Wrangler configuration needs a `previews` block to run this command. Add the following to your configuration file:" : "Your Wrangler configuration is missing a `previews` block. Add the following to your configuration file:",
336369
+ formattedProposedConfig
336370
+ ];
336371
+ if (hasEmptyProposedConfig && conversionMessages.length === 0) {
336372
+ missingPreviewsConfigParagraphs.push(
336373
+ "To create or update a Preview with `npx wrangler preview`, your Wrangler configuration must include a `previews` block. The block can be empty. Assets, compatibility settings, migrations, and placement stay at the top level and do not need to be added to `previews`.\nLearn more: https://developers.cloudflare.com/workers/previews/configuration/#wrangler-configuration-file"
336374
+ );
336375
+ }
336376
+ const missingPreviewsConfigMessage = missingPreviewsConfigParagraphs.join("\n");
336377
+ if (hasBlockingDeploymentMessages) {
336378
+ logConversionMessages(conversionMessages, args.json);
336379
+ throw new UserError(missingPreviewsConfigMessage, {
336380
+ telemetryMessage: "preview command previews configuration missing"
336381
+ });
336382
+ }
336383
+ if (!hasPreviewBase) {
336384
+ logConversionMessages(conversionMessages, args.json);
336385
+ throw new UserError(missingPreviewsConfigMessage, {
336386
+ telemetryMessage: "preview command previews configuration missing"
336387
+ });
336388
+ }
336389
+ const format9 = configFormat(config2.userConfigPath);
336390
+ const canWriteConfig = config2.userConfigPath !== void 0 && config2.userConfigPath === config2.configPath && (JSON_CONFIG_FORMATS.includes(format9) || format9 === "toml" && !fs12.readFileSync(config2.userConfigPath, "utf8").includes("#"));
336391
+ if (!canWriteConfig || args.json || isNonInteractiveOrCI()) {
336392
+ logConversionMessages(conversionMessages, args.json);
336393
+ throw new UserError(missingPreviewsConfigMessage, {
336394
+ telemetryMessage: "preview command previews configuration missing"
336395
+ });
336396
+ }
336397
+ logConversionMessages(conversionMessages, args.json);
336398
+ logger2.info(
336399
+ `Wrangler detected Preview configuration set via the Cloudflare Dashboard:
336400
+ ${formattedProposedConfig}`
336401
+ );
336402
+ if (!await confirm2(
336403
+ "Would you like Wrangler to add this configuration to your local configuration file?"
336404
+ )) {
336405
+ throw new UserError(missingPreviewsConfigMessage, {
336406
+ telemetryMessage: "preview command previews configuration missing"
336407
+ });
336408
+ }
336409
+ writePreviewsConfig(config2, baseConversion.config);
336410
+ return { ...config2, previews: baseConversion.config };
336411
+ }
336412
+ var init_ensure_config = __esm({
336413
+ "src/preview/ensure-config.ts"() {
336414
+ init_import_meta_url();
336415
+ init_src3();
336416
+ init_src();
336417
+ init_dialogs();
336418
+ init_logger2();
336419
+ init_preview_config();
336420
+ __name(logConversionMessages, "logConversionMessages");
336421
+ __name(hasConfiguredFields, "hasConfiguredFields");
336422
+ __name(containsGeneratedPlaceholder, "containsGeneratedPlaceholder");
336423
+ __name(writePreviewsConfig, "writePreviewsConfig");
336424
+ __name(ensurePreviewsConfig, "ensurePreviewsConfig");
336425
+ }
336426
+ });
336427
+
335619
336428
  // src/preview/preview.ts
335620
336429
  var previewCommand;
335621
336430
  var init_preview3 = __esm({
@@ -335633,6 +336442,8 @@ var init_preview3 = __esm({
335633
336442
  init_user3();
335634
336443
  init_collectKeyValues();
335635
336444
  init_containers4();
336445
+ init_ensure_config();
336446
+ init_preview_config();
335636
336447
  previewCommand = createCommand({
335637
336448
  metadata: {
335638
336449
  description: "\u{1F440} Create a Preview deployment of the current Worker",
@@ -335696,41 +336507,48 @@ var init_preview3 = __esm({
335696
336507
  },
335697
336508
  handler: /* @__PURE__ */ __name(async function previewHandler(args, { config: config2 }) {
335698
336509
  const accountId = await requireAuth(config2);
335699
- const entry = await getEntry({ script: args.script }, config2, "deploy");
336510
+ const productionBindingsExpectedInPreview = getProductionBindingsExpectedInPreview(config2);
336511
+ const previewConfig = await ensurePreviewsConfig(accountId, args, config2);
336512
+ const entry = await getEntry(
336513
+ { script: args.script },
336514
+ previewConfig,
336515
+ "deploy"
336516
+ );
335700
336517
  const destination = getWranglerTmpDir(entry.projectRoot, "preview");
335701
336518
  const buildResult = await buildWorker(
335702
336519
  {
335703
336520
  entry,
335704
- name: config2.name,
335705
- compatibilityDate: config2.compatibility_date,
335706
- compatibilityFlags: config2.compatibility_flags,
335707
- uploadSourceMaps: config2.upload_source_maps,
335708
- jsxFactory: config2.jsx_factory,
335709
- jsxFragment: config2.jsx_fragment,
335710
- tsconfig: config2.tsconfig,
335711
- minify: config2.minify,
335712
- noBundle: config2.no_bundle ?? false,
335713
- defines: config2.previews?.define ?? {},
335714
- alias: { ...config2.alias },
335715
- doBindings: config2.previews?.durable_objects?.bindings ?? [],
335716
- workflowBindings: config2.previews?.workflows ?? [],
336521
+ name: previewConfig.name,
336522
+ compatibilityDate: previewConfig.compatibility_date,
336523
+ compatibilityFlags: previewConfig.compatibility_flags,
336524
+ uploadSourceMaps: previewConfig.upload_source_maps,
336525
+ jsxFactory: previewConfig.jsx_factory,
336526
+ jsxFragment: previewConfig.jsx_fragment,
336527
+ tsconfig: previewConfig.tsconfig,
336528
+ minify: previewConfig.minify,
336529
+ noBundle: previewConfig.no_bundle ?? false,
336530
+ defines: previewConfig.previews?.define ?? {},
336531
+ alias: { ...previewConfig.alias },
336532
+ doBindings: previewConfig.previews?.durable_objects?.bindings ?? [],
336533
+ workflowBindings: previewConfig.previews?.workflows ?? [],
335717
336534
  destination,
335718
336535
  outdir: void 0,
335719
336536
  metafile: void 0
335720
336537
  },
335721
- config2
336538
+ previewConfig
335722
336539
  );
335723
336540
  const assetsOptions = getAssetsOptions({
335724
336541
  args: { assets: void 0, script: args.script },
335725
- config: config2
336542
+ config: previewConfig
335726
336543
  });
335727
336544
  const { preview: previewResource, deployment } = await preview(
335728
336545
  accountId,
335729
336546
  { ...args, cliVars: collectKeyValues(args.var) },
335730
- config2,
336547
+ previewConfig,
335731
336548
  buildResult,
335732
336549
  assetsOptions,
335733
336550
  {
336551
+ productionBindingsExpectedInPreview,
335734
336552
  getNormalizedContainerOptions,
335735
336553
  deployPreviewContainers,
335736
336554
  verifyContainersScope
@@ -349211,11 +350029,11 @@ async function getLocalInstanceIdFromArgs(port, args, options = {}) {
349211
350029
  }
349212
350030
  return id;
349213
350031
  }
349214
- async function updateLocalInstanceStatus(port, workflowName, instanceId, action, from, rollback) {
350032
+ async function updateLocalInstanceStatus(port, workflowName, instanceId, status2, from, rollback) {
349215
350033
  const body = {
349216
- action,
350034
+ status: status2,
349217
350035
  ...from ? { from } : {},
349218
- ...action === "terminate" && rollback === true ? { rollback: true } : {}
350036
+ ...status2 === "terminate" && rollback === true ? { rollback: true } : {}
349219
350037
  };
349220
350038
  return fetchLocalResult(
349221
350039
  port,