@cloudflare/deploy-helpers 0.19.1 → 0.20.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.
|
@@ -98,6 +98,7 @@ function createWorkerUploadForm(worker, bindings, options) {
|
|
|
98
98
|
const assetConfig = {
|
|
99
99
|
html_handling: assets?.assetConfig?.html_handling,
|
|
100
100
|
not_found_handling: assets?.assetConfig?.not_found_handling,
|
|
101
|
+
base_path: assets?.assetConfig?.base_path,
|
|
101
102
|
run_worker_first: assets?.run_worker_first,
|
|
102
103
|
_redirects: assets?._redirects,
|
|
103
104
|
_headers: assets?._headers
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './chunk-
|
|
2
|
+
export { createWorkerUploadForm, fromMimeType, moduleTypeMimeType } from './chunk-DSGVRFIS.mjs';
|
|
3
3
|
import './chunk-U6NEESU5.mjs';
|
|
4
4
|
|
|
5
5
|
createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
|
package/dist/index.d.mts
CHANGED
|
@@ -500,7 +500,7 @@ compatibilityFlags: string[], { noBundle, }: {
|
|
|
500
500
|
noBundle?: boolean;
|
|
501
501
|
}): NodeJSCompatMode;
|
|
502
502
|
|
|
503
|
-
declare const validateRoutes: (routes: Route[], assets: AssetsOptions | undefined) => void;
|
|
503
|
+
declare const validateRoutes: (routes: Route[], assets: AssetsOptions | undefined, workersDevEnabled?: boolean) => void;
|
|
504
504
|
|
|
505
505
|
declare function hasDefinedEnvironments(config: Config): boolean;
|
|
506
506
|
declare function applyServiceAndEnvironmentTags(config: Config, tags: string[]): string[];
|
|
@@ -1003,6 +1003,7 @@ type CreatePreviewDeploymentRequestParams = {
|
|
|
1003
1003
|
config: {
|
|
1004
1004
|
html_handling?: string;
|
|
1005
1005
|
not_found_handling?: string;
|
|
1006
|
+
base_path?: string;
|
|
1006
1007
|
run_worker_first?: string[] | boolean;
|
|
1007
1008
|
};
|
|
1008
1009
|
};
|
|
@@ -1171,6 +1172,7 @@ type PreviewAssetsOptions = {
|
|
|
1171
1172
|
assetConfig: {
|
|
1172
1173
|
html_handling?: string;
|
|
1173
1174
|
not_found_handling?: string;
|
|
1175
|
+
base_path?: string;
|
|
1174
1176
|
};
|
|
1175
1177
|
run_worker_first?: string[] | boolean;
|
|
1176
1178
|
_headers?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import { fetchResult, fetchPagedListResult, logger, confirm, fetchListResult, prompt, select } from './chunk-Y4VATABS.mjs';
|
|
3
3
|
export { initDeployHelpersContext } from './chunk-Y4VATABS.mjs';
|
|
4
|
-
import { createWorkerUploadForm, moduleTypeMimeType } from './chunk-
|
|
5
|
-
export { createWorkerUploadForm, fromMimeType, handleUnsafeCapnp, moduleTypeMimeType } from './chunk-
|
|
4
|
+
import { createWorkerUploadForm, moduleTypeMimeType } from './chunk-DSGVRFIS.mjs';
|
|
5
|
+
export { createWorkerUploadForm, fromMimeType, handleUnsafeCapnp, moduleTypeMimeType } from './chunk-DSGVRFIS.mjs';
|
|
6
6
|
import { __commonJS, __name, __require, __toESM, __export } from './chunk-U6NEESU5.mjs';
|
|
7
7
|
import assert6 from 'node:assert';
|
|
8
8
|
import { readFileSync, mkdirSync, writeFileSync, createReadStream } from 'node:fs';
|
|
@@ -28,8 +28,8 @@ import { setTimeout as setTimeout$1 } from 'node:timers/promises';
|
|
|
28
28
|
import readline from 'node:readline';
|
|
29
29
|
import { parse as parse$1 } from 'dotenv';
|
|
30
30
|
import { getFreshSourceMapSupport, getNodeCompat } from 'miniflare';
|
|
31
|
-
import { execSync } from 'node:child_process';
|
|
32
31
|
import { createHash } from 'node:crypto';
|
|
32
|
+
import { execSync } from 'node:child_process';
|
|
33
33
|
import { convertToWranglerConfig } from '@cloudflare/config';
|
|
34
34
|
|
|
35
35
|
createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
|
|
@@ -6420,6 +6420,7 @@ function resolveAssetOptions({ assetsDir, main }, config2) {
|
|
|
6420
6420
|
const assetConfig = {
|
|
6421
6421
|
html_handling: config2.assets?.html_handling,
|
|
6422
6422
|
not_found_handling: config2.assets?.not_found_handling,
|
|
6423
|
+
base_path: config2.assets?.base_path,
|
|
6423
6424
|
// The _redirects and _headers files are parsed in Miniflare in dev and parsing is not required for deploy
|
|
6424
6425
|
compatibility_date: config2.compatibility_date,
|
|
6425
6426
|
compatibility_flags: config2.compatibility_flags
|
|
@@ -25164,7 +25165,65 @@ async function verifyWorkerMatchesCITag(complianceConfig, accountId, workerName,
|
|
|
25164
25165
|
}
|
|
25165
25166
|
}
|
|
25166
25167
|
__name(verifyWorkerMatchesCITag, "verifyWorkerMatchesCITag");
|
|
25167
|
-
|
|
25168
|
+
|
|
25169
|
+
// ../workers-shared/utils/base-path.ts
|
|
25170
|
+
var CONTROL_CHARACTER = /[\u0000-\u001f\u007f]/;
|
|
25171
|
+
function normalizeBasePath(value) {
|
|
25172
|
+
if (value === "/") {
|
|
25173
|
+
return { valid: true, value: "/" };
|
|
25174
|
+
}
|
|
25175
|
+
if (typeof value !== "string") {
|
|
25176
|
+
return {
|
|
25177
|
+
valid: false,
|
|
25178
|
+
error: `Expected a string but got ${typeof value}.`
|
|
25179
|
+
};
|
|
25180
|
+
}
|
|
25181
|
+
if (value.length === 0) {
|
|
25182
|
+
return { valid: false, error: `The value must not be empty.` };
|
|
25183
|
+
}
|
|
25184
|
+
if (value.startsWith("//") || /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(value)) {
|
|
25185
|
+
return {
|
|
25186
|
+
valid: false,
|
|
25187
|
+
error: `The value must be a pathname, not a URL.`
|
|
25188
|
+
};
|
|
25189
|
+
}
|
|
25190
|
+
if (value.includes("\\")) {
|
|
25191
|
+
return { valid: false, error: `The value must not contain backslashes.` };
|
|
25192
|
+
}
|
|
25193
|
+
if (CONTROL_CHARACTER.test(value)) {
|
|
25194
|
+
return {
|
|
25195
|
+
valid: false,
|
|
25196
|
+
error: `The value must not contain control characters.`
|
|
25197
|
+
};
|
|
25198
|
+
}
|
|
25199
|
+
if (value.includes("?") || value.includes("#")) {
|
|
25200
|
+
return {
|
|
25201
|
+
valid: false,
|
|
25202
|
+
error: `The value must not contain query strings or fragments.`
|
|
25203
|
+
};
|
|
25204
|
+
}
|
|
25205
|
+
if (value.includes("%")) {
|
|
25206
|
+
return {
|
|
25207
|
+
valid: false,
|
|
25208
|
+
error: `The value must not contain percent-encoded sequences.`
|
|
25209
|
+
};
|
|
25210
|
+
}
|
|
25211
|
+
const normalizedSegments = [];
|
|
25212
|
+
for (const segment of value.split("/")) {
|
|
25213
|
+
if (segment === "" || segment === ".") {
|
|
25214
|
+
continue;
|
|
25215
|
+
}
|
|
25216
|
+
if (segment === "..") {
|
|
25217
|
+
normalizedSegments.pop();
|
|
25218
|
+
continue;
|
|
25219
|
+
}
|
|
25220
|
+
normalizedSegments.push(segment);
|
|
25221
|
+
}
|
|
25222
|
+
const canonical = normalizedSegments.length === 0 ? "/" : `/${normalizedSegments.join("/")}/`;
|
|
25223
|
+
return { valid: true, value: canonical };
|
|
25224
|
+
}
|
|
25225
|
+
__name(normalizeBasePath, "normalizeBasePath");
|
|
25226
|
+
var validateRoutes = /* @__PURE__ */ __name((routes, assets, workersDevEnabled) => {
|
|
25168
25227
|
const invalidRoutes = {};
|
|
25169
25228
|
const mountedAssetRoutes = [];
|
|
25170
25229
|
for (const route of routes) {
|
|
@@ -25202,6 +25261,12 @@ var validateRoutes = /* @__PURE__ */ __name((routes, assets) => {
|
|
|
25202
25261
|
{ telemetryMessage: "deploy invalid routes" }
|
|
25203
25262
|
);
|
|
25204
25263
|
}
|
|
25264
|
+
const basePath = normalizeBasePath(assets?.assetConfig.base_path);
|
|
25265
|
+
if (workersDevEnabled === false && basePath.valid && basePath.value !== "/" && !routes.some((route) => routeMatchesPath(route, basePath.value))) {
|
|
25266
|
+
logger.warn(
|
|
25267
|
+
`The configured assets base path "${basePath.value}" is not reachable through any configured route. Add a route that matches "${basePath.value}" or enable \`workers_dev\`.`
|
|
25268
|
+
);
|
|
25269
|
+
}
|
|
25205
25270
|
if (mountedAssetRoutes.length > 0 && assets?.directory !== void 0) {
|
|
25206
25271
|
const relativeAssetsDir = path__default.relative(process.cwd(), assets.directory);
|
|
25207
25272
|
const warnFn = logger.once?.warn ?? logger.warn;
|
|
@@ -25218,6 +25283,21 @@ ${mountedAssetRoutes.map((route) => {
|
|
|
25218
25283
|
);
|
|
25219
25284
|
}
|
|
25220
25285
|
}, "validateRoutes");
|
|
25286
|
+
function routeMatchesPath(route, pathname) {
|
|
25287
|
+
if (typeof route !== "string" && route.custom_domain) {
|
|
25288
|
+
return !("enabled" in route) || route.enabled !== false;
|
|
25289
|
+
}
|
|
25290
|
+
const pattern = typeof route === "string" ? route : route.pattern;
|
|
25291
|
+
const patternWithoutScheme = pattern.replace(/^https?:\/\//, "");
|
|
25292
|
+
const pathStart = patternWithoutScheme.indexOf("/");
|
|
25293
|
+
if (pathStart === -1) {
|
|
25294
|
+
return false;
|
|
25295
|
+
}
|
|
25296
|
+
const pathPattern = patternWithoutScheme.slice(pathStart);
|
|
25297
|
+
const regexpPattern = pathPattern.split("*").map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*");
|
|
25298
|
+
return new RegExp(`^${regexpPattern}$`).test(pathname);
|
|
25299
|
+
}
|
|
25300
|
+
__name(routeMatchesPath, "routeMatchesPath");
|
|
25221
25301
|
|
|
25222
25302
|
// src/deploy/helpers/validate-worker-props.ts
|
|
25223
25303
|
function validateWorkerProps(props, config2) {
|
|
@@ -25266,7 +25346,12 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
|
|
|
25266
25346
|
validateOwnedWorkflowDeclarations(config2, name);
|
|
25267
25347
|
if (props.command === "deploy") {
|
|
25268
25348
|
validateEventTriggerTargets(config2, name);
|
|
25269
|
-
|
|
25349
|
+
const workersDevEnabled = getSubdomainValues(
|
|
25350
|
+
config2.workers_dev,
|
|
25351
|
+
config2.preview_urls,
|
|
25352
|
+
props.routes
|
|
25353
|
+
).workers_dev;
|
|
25354
|
+
validateRoutes(props.routes, props.assetsOptions, workersDevEnabled);
|
|
25270
25355
|
assert6(
|
|
25271
25356
|
!config2.site || config2.site.bucket,
|
|
25272
25357
|
"A [site] definition requires a `bucket` field with a path to the site's assets directory."
|
|
@@ -26358,6 +26443,37 @@ Changes to triggers (routes, custom domains, cron schedules, etc) must be applie
|
|
|
26358
26443
|
};
|
|
26359
26444
|
}
|
|
26360
26445
|
__name(uploadWorkerVersion, "uploadWorkerVersion");
|
|
26446
|
+
function gitCommandText(stdout) {
|
|
26447
|
+
if (typeof stdout === "string") {
|
|
26448
|
+
return stdout;
|
|
26449
|
+
}
|
|
26450
|
+
if (stdout instanceof Uint8Array) {
|
|
26451
|
+
return new TextDecoder().decode(stdout);
|
|
26452
|
+
}
|
|
26453
|
+
return "";
|
|
26454
|
+
}
|
|
26455
|
+
__name(gitCommandText, "gitCommandText");
|
|
26456
|
+
function resolveGitBranchName() {
|
|
26457
|
+
try {
|
|
26458
|
+
execSync(`git rev-parse --is-inside-work-tree`, {
|
|
26459
|
+
stdio: ["ignore", "ignore", "ignore"]
|
|
26460
|
+
});
|
|
26461
|
+
} catch {
|
|
26462
|
+
return void 0;
|
|
26463
|
+
}
|
|
26464
|
+
try {
|
|
26465
|
+
const branch = gitCommandText(
|
|
26466
|
+
execSync(`git branch --show-current`, {
|
|
26467
|
+
encoding: "utf8",
|
|
26468
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
26469
|
+
})
|
|
26470
|
+
).trim();
|
|
26471
|
+
return branch || void 0;
|
|
26472
|
+
} catch {
|
|
26473
|
+
return void 0;
|
|
26474
|
+
}
|
|
26475
|
+
}
|
|
26476
|
+
__name(resolveGitBranchName, "resolveGitBranchName");
|
|
26361
26477
|
var SHORT_HASH_LENGTH = 7;
|
|
26362
26478
|
function truncateWithSuffix(body, suffix, maxLength) {
|
|
26363
26479
|
const maxBodyLength = Math.max(0, maxLength - suffix.length);
|
|
@@ -26382,12 +26498,7 @@ function getBranchName() {
|
|
|
26382
26498
|
if (ciBranchName) {
|
|
26383
26499
|
return ciBranchName;
|
|
26384
26500
|
}
|
|
26385
|
-
|
|
26386
|
-
execSync(`git rev-parse --is-inside-work-tree`, { stdio: "ignore" });
|
|
26387
|
-
return execSync(`git rev-parse --abbrev-ref HEAD`).toString().trim();
|
|
26388
|
-
} catch {
|
|
26389
|
-
return void 0;
|
|
26390
|
-
}
|
|
26501
|
+
return resolveGitBranchName();
|
|
26391
26502
|
}
|
|
26392
26503
|
__name(getBranchName, "getBranchName");
|
|
26393
26504
|
function createTruncatedAlias(branchName, sanitizedAlias, availableSpace) {
|
|
@@ -26607,6 +26718,15 @@ async function patchPreviewBaseConfig(config2, accountId, workerName, previewBas
|
|
|
26607
26718
|
}
|
|
26608
26719
|
__name(patchPreviewBaseConfig, "patchPreviewBaseConfig");
|
|
26609
26720
|
var MAX_CONTAINER_APP_NAME_LENGTH = 253;
|
|
26721
|
+
function readGitStdout(command) {
|
|
26722
|
+
return gitCommandText(
|
|
26723
|
+
execSync(command, {
|
|
26724
|
+
encoding: "utf8",
|
|
26725
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
26726
|
+
})
|
|
26727
|
+
).trim();
|
|
26728
|
+
}
|
|
26729
|
+
__name(readGitStdout, "readGitStdout");
|
|
26610
26730
|
function getBranchName2() {
|
|
26611
26731
|
const workersCIBranch = getWorkersCIBranchName();
|
|
26612
26732
|
if (workersCIBranch) {
|
|
@@ -26620,12 +26740,7 @@ function getBranchName2() {
|
|
|
26620
26740
|
if (gitlabBranch) {
|
|
26621
26741
|
return gitlabBranch;
|
|
26622
26742
|
}
|
|
26623
|
-
|
|
26624
|
-
execSync(`git rev-parse --is-inside-work-tree`, { stdio: "ignore" });
|
|
26625
|
-
return execSync(`git rev-parse --abbrev-ref HEAD`).toString().trim();
|
|
26626
|
-
} catch {
|
|
26627
|
-
return void 0;
|
|
26628
|
-
}
|
|
26743
|
+
return resolveGitBranchName();
|
|
26629
26744
|
}
|
|
26630
26745
|
__name(getBranchName2, "getBranchName");
|
|
26631
26746
|
function shouldUseCIMetadataFallback() {
|
|
@@ -26635,7 +26750,7 @@ __name(shouldUseCIMetadataFallback, "shouldUseCIMetadataFallback");
|
|
|
26635
26750
|
function getHeadCommitRef() {
|
|
26636
26751
|
try {
|
|
26637
26752
|
execSync(`git rev-parse --is-inside-work-tree`, { stdio: "ignore" });
|
|
26638
|
-
return
|
|
26753
|
+
return readGitStdout(`git rev-parse --short HEAD`);
|
|
26639
26754
|
} catch {
|
|
26640
26755
|
return void 0;
|
|
26641
26756
|
}
|
|
@@ -26644,7 +26759,7 @@ __name(getHeadCommitRef, "getHeadCommitRef");
|
|
|
26644
26759
|
function getHeadCommitMessage() {
|
|
26645
26760
|
try {
|
|
26646
26761
|
execSync(`git rev-parse --is-inside-work-tree`, { stdio: "ignore" });
|
|
26647
|
-
return
|
|
26762
|
+
return readGitStdout(`git log -1 --format=%B`);
|
|
26648
26763
|
} catch {
|
|
26649
26764
|
return void 0;
|
|
26650
26765
|
}
|
|
@@ -26700,7 +26815,7 @@ function getRepositoryUrl() {
|
|
|
26700
26815
|
try {
|
|
26701
26816
|
execSync(`git rev-parse --is-inside-work-tree`, { stdio: "ignore" });
|
|
26702
26817
|
return normalizeRepositoryUrl(
|
|
26703
|
-
|
|
26818
|
+
readGitStdout(`git config --get remote.origin.url`)
|
|
26704
26819
|
);
|
|
26705
26820
|
} catch {
|
|
26706
26821
|
return void 0;
|
|
@@ -27519,6 +27634,7 @@ async function assemblePreviewDeploymentSettings(config2, buildResult, accountId
|
|
|
27519
27634
|
config: {
|
|
27520
27635
|
html_handling: options.assetsOptions.assetConfig.html_handling,
|
|
27521
27636
|
not_found_handling: options.assetsOptions.assetConfig.not_found_handling,
|
|
27637
|
+
base_path: options.assetsOptions.assetConfig.base_path,
|
|
27522
27638
|
run_worker_first: options.assetsOptions.run_worker_first
|
|
27523
27639
|
}
|
|
27524
27640
|
};
|
|
@@ -28013,7 +28129,8 @@ async function previewBuildOutput(accountId, args, buildOutput, callbacks) {
|
|
|
28013
28129
|
_redirects: assets._redirects ?? maybeGetFile(path__default.join(assets.directory, "_redirects")),
|
|
28014
28130
|
assetConfig: {
|
|
28015
28131
|
html_handling: convertedConfig.assets?.html_handling,
|
|
28016
|
-
not_found_handling: convertedConfig.assets?.not_found_handling
|
|
28132
|
+
not_found_handling: convertedConfig.assets?.not_found_handling,
|
|
28133
|
+
base_path: convertedConfig.assets?.base_path
|
|
28017
28134
|
},
|
|
28018
28135
|
run_worker_first: convertedConfig.assets?.run_worker_first
|
|
28019
28136
|
};
|