@cloudflare/deploy-helpers 0.24.4 → 0.25.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.
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,9 @@ 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
703
  */
704
- declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId: string, workerName: string, environment: string): Promise<{
704
+ declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId: string, workerName: string, environment: string, fetchRoutes: boolean, fetchCustomDomains: boolean): Promise<{
705
705
  bindings: _cloudflare_workers_utils.WorkerMetadataBinding[];
706
706
  routes: RoutesRes;
707
707
  customDomains: CustomDomainsRes;
@@ -738,7 +738,7 @@ declare function fetchWorkerConfig(complianceConfig: ComplianceConfig, accountId
738
738
  * Downloads all the remote information we can gather for a worker and from them generates a raw configuration object that
739
739
  * approximates what a wrangler config object for the worker was/would have been.
740
740
  */
741
- declare function downloadWorkerConfig(complianceConfig: ComplianceConfig, workerName: string, environment: string, entrypoint: string, accountId: string): Promise<RawConfig>;
741
+ declare function downloadWorkerConfig(complianceConfig: ComplianceConfig, workerName: string, environment: string, entrypoint: string, accountId: string, fetchRoutes: boolean, fetchCustomDomains: boolean): Promise<RawConfig>;
742
742
 
743
743
  /**
744
744
  * 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;
@@ -30911,7 +30923,7 @@ function getDeployConfirmFunction(options) {
30911
30923
  return confirm;
30912
30924
  }
30913
30925
  __name(getDeployConfirmFunction, "getDeployConfirmFunction");
30914
- async function fetchWorkerConfig(complianceConfig, accountId, workerName, environment) {
30926
+ async function fetchWorkerConfig(complianceConfig, accountId, workerName, environment, fetchRoutes, fetchCustomDomains) {
30915
30927
  const [
30916
30928
  bindings,
30917
30929
  routes,
@@ -30924,14 +30936,14 @@ async function fetchWorkerConfig(complianceConfig, accountId, workerName, enviro
30924
30936
  complianceConfig,
30925
30937
  `/accounts/${accountId}/workers/services/${workerName}/environments/${environment}/bindings`
30926
30938
  ),
30927
- fetchResult(
30939
+ fetchRoutes ? fetchResult(
30928
30940
  complianceConfig,
30929
30941
  `/accounts/${accountId}/workers/services/${workerName}/environments/${environment}/routes?show_zonename=true`
30930
- ),
30931
- fetchResult(
30942
+ ) : Promise.resolve([]),
30943
+ fetchCustomDomains ? fetchResult(
30932
30944
  complianceConfig,
30933
30945
  `/accounts/${accountId}/workers/domains/records?page=0&per_page=5&service=${workerName}&environment=${environment}`
30934
- ),
30946
+ ) : Promise.resolve([]),
30935
30947
  fetchResult(
30936
30948
  complianceConfig,
30937
30949
  `/accounts/${accountId}/workers/services/${workerName}/environments/${environment}/subdomain`
@@ -30960,7 +30972,7 @@ async function fetchWorkerConfig(complianceConfig, accountId, workerName, enviro
30960
30972
  };
30961
30973
  }
30962
30974
  __name(fetchWorkerConfig, "fetchWorkerConfig");
30963
- async function downloadWorkerConfig(complianceConfig, workerName, environment, entrypoint, accountId) {
30975
+ async function downloadWorkerConfig(complianceConfig, workerName, environment, entrypoint, accountId, fetchRoutes, fetchCustomDomains) {
30964
30976
  const {
30965
30977
  bindings,
30966
30978
  routes,
@@ -30972,7 +30984,9 @@ async function downloadWorkerConfig(complianceConfig, workerName, environment, e
30972
30984
  complianceConfig,
30973
30985
  accountId,
30974
30986
  workerName,
30975
- environment
30987
+ environment,
30988
+ fetchRoutes,
30989
+ fetchCustomDomains
30976
30990
  );
30977
30991
  return constructWranglerConfig({
30978
30992
  name: workerName,
@@ -31310,12 +31324,17 @@ async function preUploadApiChecks(props, config2, queueCreateCommand) {
31310
31324
  );
31311
31325
  }
31312
31326
  if (script.last_deployed_from === "dash") {
31327
+ const { routesOnly, customDomainsOnly } = partitionRoutes(
31328
+ props.command === "deploy" ? props.routes : []
31329
+ );
31313
31330
  const remoteWorkerConfig = await downloadWorkerConfig(
31314
31331
  config2,
31315
31332
  name,
31316
31333
  serviceMetaData.default_environment.environment,
31317
31334
  props.entry.file,
31318
- accountId
31335
+ accountId,
31336
+ routesOnly.length > 0,
31337
+ customDomainsOnly.length > 0
31319
31338
  );
31320
31339
  const configForDiff = props.command === "deploy" ? {
31321
31340
  ...config2,
@@ -33364,10 +33383,10 @@ async function prepareContainersForPreview(config2, workerName, previewSlug, opt
33364
33383
  }
33365
33384
  __name(prepareContainersForPreview, "prepareContainersForPreview");
33366
33385
  var NO_ACTIVE_PREVIEW_URLS_MESSAGE = "Note: This Preview deployment has no active URLs.";
33367
- function isCustomDomainRoute(route) {
33386
+ function isCustomDomainRoute2(route) {
33368
33387
  return typeof route === "object" && route.custom_domain === true;
33369
33388
  }
33370
- __name(isCustomDomainRoute, "isCustomDomainRoute");
33389
+ __name(isCustomDomainRoute2, "isCustomDomainRoute");
33371
33390
  function formatPreviewConfigUpdate(config2, update) {
33372
33391
  const configPath = config2.userConfigPath ?? config2.configPath;
33373
33392
  if (!config2.targetEnvironment) {
@@ -33380,8 +33399,8 @@ function formatPreviewConfigUpdate(config2, update) {
33380
33399
  }
33381
33400
  __name(formatPreviewConfigUpdate, "formatPreviewConfigUpdate");
33382
33401
  function formatNoActivePreviewUrlsMessage(config2, deployCommand = "your deploy command", previewCommand = "the preview command") {
33383
- const customDomainRouteEntries = (config2.routes ?? []).filter(isCustomDomainRoute).map((route) => ({ route, singular: false }));
33384
- if (config2.route && isCustomDomainRoute(config2.route)) {
33402
+ const customDomainRouteEntries = (config2.routes ?? []).filter(isCustomDomainRoute2).map((route) => ({ route, singular: false }));
33403
+ if (config2.route && isCustomDomainRoute2(config2.route)) {
33385
33404
  customDomainRouteEntries.push({ route: config2.route, singular: true });
33386
33405
  }
33387
33406
  const customDomainRouteEntry = customDomainRouteEntries.find(
@@ -33710,7 +33729,7 @@ __name(formatPreviewDeploymentSummary, "formatPreviewDeploymentSummary");
33710
33729
  function getPreviewCustomDomainHostnames(config2) {
33711
33730
  const routes = config2.routes ?? (config2.route ? [config2.route] : []);
33712
33731
  return routes.filter(
33713
- (route) => isCustomDomainRoute(route) && route.previews_enabled === true
33732
+ (route) => isCustomDomainRoute2(route) && route.previews_enabled === true
33714
33733
  ).map((route) => normalizeHostname(route.pattern));
33715
33734
  }
33716
33735
  __name(getPreviewCustomDomainHostnames, "getPreviewCustomDomainHostnames");