@cloudflare/deploy-helpers 0.24.3 → 0.24.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -6,7 +6,7 @@ import { FormData } from 'undici';
6
6
  export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './create-worker-upload-form.mjs';
7
7
  import { Options } from '@cspotcode/source-map-support';
8
8
  import Protocol from 'devtools-protocol';
9
- import { NodeJSCompatMode } from 'miniflare';
9
+ import { NodeJSCompatMode } from '@cloudflare/workers-utils/node-compat';
10
10
  import { ParsedOutputWorkerConfig, ParsedOutputRootConfig, ParsedOutputContainerConfig } from '@cloudflare/config';
11
11
  import { ContainerNormalizedConfig } from '@cloudflare/containers-shared';
12
12
 
@@ -699,9 +699,11 @@ type RoutesRes = {
699
699
  script: string;
700
700
  }[];
701
701
  /**
702
- * Downloads all information required to construct a Wrangler config file for a Worker from the API
702
+ * Downloads the information required to construct a Wrangler config file for a Worker from the API.
703
+ * When `localRoutes` is provided, only fetches the route categories that the
704
+ * current deployment can change. Omit it when downloading a complete config.
703
705
  */
704
- declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId: string, workerName: string, environment: string): Promise<{
706
+ declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId: string, workerName: string, environment: string, localRoutes?: Route[]): Promise<{
705
707
  bindings: _cloudflare_workers_utils.WorkerMetadataBinding[];
706
708
  routes: RoutesRes;
707
709
  customDomains: CustomDomainsRes;
@@ -737,8 +739,10 @@ declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId
737
739
  /**
738
740
  * Downloads all the remote information we can gather for a worker and from them generates a raw configuration object that
739
741
  * approximates what a wrangler config object for the worker was/would have been.
742
+ * When `localRoutes` is provided, route metadata is limited to categories that
743
+ * the current deployment can change. Omit it when downloading a complete config.
740
744
  */
741
- declare function downloadWorkerConfig(complianceConfig: ComplianceConfig, workerName: string, environment: string, entrypoint: string, accountId: string): Promise<RawConfig>;
745
+ declare function downloadWorkerConfig(complianceConfig: ComplianceConfig, workerName: string, environment: string, entrypoint: string, accountId: string, localRoutes?: Route[]): Promise<RawConfig>;
742
746
 
743
747
  /**
744
748
  * For a given Worker + migrations config, figure out which migrations
package/dist/index.mjs CHANGED
@@ -28,9 +28,10 @@ import { brandColor, white, gray, bold, yellow, dim, red, blue } from '@cloudfla
28
28
  import { setTimeout as setTimeout$1 } from 'node:timers/promises';
29
29
  import readline from 'node:readline';
30
30
  import { parse as parse$1 } from 'dotenv';
31
- import { getFreshSourceMapSupport, getNodeCompat } from 'miniflare';
31
+ import { getFreshSourceMapSupport } from '@cloudflare/workers-utils/sourcemap';
32
32
  import { createHash } from 'node:crypto';
33
33
  import { execSync } from 'node:child_process';
34
+ import { getNodeCompat } from '@cloudflare/workers-utils/node-compat';
34
35
  import { convertToWranglerConfig } from '@cloudflare/config';
35
36
 
36
37
  createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
@@ -2837,6 +2838,25 @@ function validateOwnedWorkflowDeclarations(config2, scriptName) {
2837
2838
  }
2838
2839
  __name(validateOwnedWorkflowDeclarations, "validateOwnedWorkflowDeclarations");
2839
2840
 
2841
+ // src/shared/partition-routes.ts
2842
+ function partitionRoutes(routes) {
2843
+ const routesOnly = [];
2844
+ const customDomainsOnly = [];
2845
+ for (const route of routes) {
2846
+ if (isCustomDomainRoute(route)) {
2847
+ customDomainsOnly.push(route);
2848
+ } else {
2849
+ routesOnly.push(route);
2850
+ }
2851
+ }
2852
+ return { routesOnly, customDomainsOnly };
2853
+ }
2854
+ __name(partitionRoutes, "partitionRoutes");
2855
+ function isCustomDomainRoute(route) {
2856
+ return typeof route !== "string" && route.custom_domain === true;
2857
+ }
2858
+ __name(isCustomDomainRoute, "isCustomDomainRoute");
2859
+
2840
2860
  // src/deploy/helpers/worker-not-found-error.ts
2841
2861
  var WORKER_NOT_FOUND_ERR_CODE = 10007;
2842
2862
  var WORKER_LEGACY_ENVIRONMENT_NOT_FOUND_ERR_CODE = 10090;
@@ -4146,15 +4166,7 @@ async function triggersDeploy(props) {
4146
4166
  props.queueCreateCommand
4147
4167
  );
4148
4168
  }
4149
- const routesOnly = [];
4150
- const customDomainsOnly = [];
4151
- for (const route of routes) {
4152
- if (typeof route !== "string" && route.custom_domain) {
4153
- customDomainsOnly.push(route);
4154
- } else {
4155
- routesOnly.push(route);
4156
- }
4157
- }
4169
+ const { routesOnly, customDomainsOnly } = partitionRoutes(routes);
4158
4170
  const start = Date.now();
4159
4171
  const workerUrl = `/accounts/${accountId}/workers/scripts/${scriptName}`;
4160
4172
  const uploadMs = Date.now() - start;
@@ -6180,11 +6192,14 @@ var syncAssets = /* @__PURE__ */ __name(async (complianceConfig, accountId, asse
6180
6192
  const manifest = await buildAssetManifest(assetDirectory);
6181
6193
  const url3 = dispatchNamespace ? `/accounts/${accountId}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${scriptName}/assets-upload-session` : `/accounts/${accountId}/workers/scripts/${scriptName}/assets-upload-session`;
6182
6194
  logger.info("\u{1F300} Starting asset upload...");
6183
- const initializeAssetsResponse = await fetchResult(complianceConfig, url3, {
6184
- headers: { "Content-Type": "application/json" },
6185
- method: "POST",
6186
- body: JSON.stringify({ manifest })
6187
- });
6195
+ const initializeAssetsResponse = await retryOnAPIFailure(
6196
+ () => fetchResult(complianceConfig, url3, {
6197
+ headers: { "Content-Type": "application/json" },
6198
+ method: "POST",
6199
+ body: JSON.stringify({ manifest })
6200
+ }),
6201
+ logger
6202
+ );
6188
6203
  if (!initializeAssetsResponse) {
6189
6204
  throw new FatalError(
6190
6205
  "An unexpected response has been received from the Cloudflare API for assets upload. Please try again.",
@@ -29980,14 +29995,18 @@ function getSourceMappedStack(details) {
29980
29995
  }
29981
29996
  __name(getSourceMappedStack, "getSourceMappedStack");
29982
29997
  function callFrameToCallSite(frame) {
29998
+ const lineNumber = frame.lineNumber + 1;
29999
+ const columnNumber = frame.columnNumber + 1;
30000
+ const location = `${frame.url}:${lineNumber}:${columnNumber}`;
29983
30001
  return new CallSite({
29984
30002
  typeName: null,
29985
30003
  functionName: frame.functionName,
29986
30004
  methodName: null,
29987
30005
  fileName: frame.url,
29988
- lineNumber: frame.lineNumber + 1,
29989
- columnNumber: frame.columnNumber + 1,
29990
- native: false
30006
+ lineNumber,
30007
+ columnNumber,
30008
+ native: false,
30009
+ text: frame.functionName ? `${frame.functionName} (${location})` : location
29991
30010
  });
29992
30011
  }
29993
30012
  __name(callFrameToCallSite, "callFrameToCallSite");
@@ -30076,7 +30095,8 @@ function lineMatchToCallSite(lineMatch) {
30076
30095
  fileName: lineMatch[2],
30077
30096
  lineNumber: parseInt(lineMatch[3]) || null,
30078
30097
  columnNumber: parseInt(lineMatch[4]) || null,
30079
- native: isNative
30098
+ native: isNative,
30099
+ text: lineMatch[0].substring(lineMatch[0].indexOf("at ") + 3)
30080
30100
  });
30081
30101
  }
30082
30102
  __name(lineMatchToCallSite, "lineMatchToCallSite");
@@ -30154,6 +30174,11 @@ var CallSite = class {
30154
30174
  getPromiseIndex() {
30155
30175
  return null;
30156
30176
  }
30177
+ // Source mapping passes some call sites (e.g. `wasm://` frames) through
30178
+ // unchanged and stringifies them, relying on V8's `CallSite#toString()`.
30179
+ toString() {
30180
+ return this.opts.text;
30181
+ }
30157
30182
  };
30158
30183
 
30159
30184
  // src/deploy/helpers/check-remote-secrets-override.ts
@@ -30898,7 +30923,10 @@ function getDeployConfirmFunction(options) {
30898
30923
  return confirm;
30899
30924
  }
30900
30925
  __name(getDeployConfirmFunction, "getDeployConfirmFunction");
30901
- async function fetchWorkerConfig(complianceConfig, accountId, workerName, environment) {
30926
+ async function fetchWorkerConfig(complianceConfig, accountId, workerName, environment, localRoutes) {
30927
+ const partitionedRoutes = localRoutes === void 0 ? void 0 : partitionRoutes(localRoutes);
30928
+ const fetchRoutes = partitionedRoutes === void 0 || partitionedRoutes.routesOnly.length > 0;
30929
+ const fetchCustomDomains = partitionedRoutes === void 0 || partitionedRoutes.customDomainsOnly.length > 0;
30902
30930
  const [
30903
30931
  bindings,
30904
30932
  routes,
@@ -30911,14 +30939,14 @@ async function fetchWorkerConfig(complianceConfig, accountId, workerName, enviro
30911
30939
  complianceConfig,
30912
30940
  `/accounts/${accountId}/workers/services/${workerName}/environments/${environment}/bindings`
30913
30941
  ),
30914
- fetchResult(
30942
+ fetchRoutes ? fetchResult(
30915
30943
  complianceConfig,
30916
30944
  `/accounts/${accountId}/workers/services/${workerName}/environments/${environment}/routes?show_zonename=true`
30917
- ),
30918
- fetchResult(
30945
+ ) : Promise.resolve([]),
30946
+ fetchCustomDomains ? fetchResult(
30919
30947
  complianceConfig,
30920
30948
  `/accounts/${accountId}/workers/domains/records?page=0&per_page=5&service=${workerName}&environment=${environment}`
30921
- ),
30949
+ ) : Promise.resolve([]),
30922
30950
  fetchResult(
30923
30951
  complianceConfig,
30924
30952
  `/accounts/${accountId}/workers/services/${workerName}/environments/${environment}/subdomain`
@@ -30947,7 +30975,7 @@ async function fetchWorkerConfig(complianceConfig, accountId, workerName, enviro
30947
30975
  };
30948
30976
  }
30949
30977
  __name(fetchWorkerConfig, "fetchWorkerConfig");
30950
- async function downloadWorkerConfig(complianceConfig, workerName, environment, entrypoint, accountId) {
30978
+ async function downloadWorkerConfig(complianceConfig, workerName, environment, entrypoint, accountId, localRoutes) {
30951
30979
  const {
30952
30980
  bindings,
30953
30981
  routes,
@@ -30959,7 +30987,8 @@ async function downloadWorkerConfig(complianceConfig, workerName, environment, e
30959
30987
  complianceConfig,
30960
30988
  accountId,
30961
30989
  workerName,
30962
- environment
30990
+ environment,
30991
+ localRoutes
30963
30992
  );
30964
30993
  return constructWranglerConfig({
30965
30994
  name: workerName,
@@ -31297,12 +31326,14 @@ async function preUploadApiChecks(props, config2, queueCreateCommand) {
31297
31326
  );
31298
31327
  }
31299
31328
  if (script.last_deployed_from === "dash") {
31329
+ const localRoutes = props.command === "deploy" ? props.routes : [];
31300
31330
  const remoteWorkerConfig = await downloadWorkerConfig(
31301
31331
  config2,
31302
31332
  name,
31303
31333
  serviceMetaData.default_environment.environment,
31304
31334
  props.entry.file,
31305
- accountId
31335
+ accountId,
31336
+ localRoutes
31306
31337
  );
31307
31338
  const configForDiff = props.command === "deploy" ? {
31308
31339
  ...config2,
@@ -33351,10 +33382,10 @@ async function prepareContainersForPreview(config2, workerName, previewSlug, opt
33351
33382
  }
33352
33383
  __name(prepareContainersForPreview, "prepareContainersForPreview");
33353
33384
  var NO_ACTIVE_PREVIEW_URLS_MESSAGE = "Note: This Preview deployment has no active URLs.";
33354
- function isCustomDomainRoute(route) {
33385
+ function isCustomDomainRoute2(route) {
33355
33386
  return typeof route === "object" && route.custom_domain === true;
33356
33387
  }
33357
- __name(isCustomDomainRoute, "isCustomDomainRoute");
33388
+ __name(isCustomDomainRoute2, "isCustomDomainRoute");
33358
33389
  function formatPreviewConfigUpdate(config2, update) {
33359
33390
  const configPath = config2.userConfigPath ?? config2.configPath;
33360
33391
  if (!config2.targetEnvironment) {
@@ -33367,8 +33398,8 @@ function formatPreviewConfigUpdate(config2, update) {
33367
33398
  }
33368
33399
  __name(formatPreviewConfigUpdate, "formatPreviewConfigUpdate");
33369
33400
  function formatNoActivePreviewUrlsMessage(config2, deployCommand = "your deploy command", previewCommand = "the preview command") {
33370
- const customDomainRouteEntries = (config2.routes ?? []).filter(isCustomDomainRoute).map((route) => ({ route, singular: false }));
33371
- if (config2.route && isCustomDomainRoute(config2.route)) {
33401
+ const customDomainRouteEntries = (config2.routes ?? []).filter(isCustomDomainRoute2).map((route) => ({ route, singular: false }));
33402
+ if (config2.route && isCustomDomainRoute2(config2.route)) {
33372
33403
  customDomainRouteEntries.push({ route: config2.route, singular: true });
33373
33404
  }
33374
33405
  const customDomainRouteEntry = customDomainRouteEntries.find(
@@ -33697,7 +33728,7 @@ __name(formatPreviewDeploymentSummary, "formatPreviewDeploymentSummary");
33697
33728
  function getPreviewCustomDomainHostnames(config2) {
33698
33729
  const routes = config2.routes ?? (config2.route ? [config2.route] : []);
33699
33730
  return routes.filter(
33700
- (route) => isCustomDomainRoute(route) && route.previews_enabled === true
33731
+ (route) => isCustomDomainRoute2(route) && route.previews_enabled === true
33701
33732
  ).map((route) => normalizeHostname(route.pattern));
33702
33733
  }
33703
33734
  __name(getPreviewCustomDomainHostnames, "getPreviewCustomDomainHostnames");