@vercel/client 18.12.4 → 18.13.0-snapshot-c9dfd83f2293

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.
@@ -9,6 +9,7 @@ export interface CollectedDeploymentFiles {
9
9
  isDirectory: boolean;
10
10
  ignoreList: string[];
11
11
  warning?: string;
12
+ referenceWarning?: string;
12
13
  }
13
14
  export declare function assertDeploymentPath(path: VercelClientOptions['path'] | undefined, debug: Debug): asserts path is VercelClientOptions['path'];
14
15
  export declare function collectDeploymentFiles(path: VercelClientOptions['path'] | undefined, clientOptions: CollectDeploymentFilesOptions, debug: Debug): Promise<CollectedDeploymentFiles>;
@@ -67,11 +67,7 @@ async function collectDeploymentFiles(path, clientOptions, debug) {
67
67
  } else {
68
68
  debug(`Provided 'path' is a single file`);
69
69
  }
70
- const { fileList, ignoreList, warning } = await (0, import_utils.buildFileTree)(
71
- path,
72
- clientOptions,
73
- debug
74
- );
70
+ const { fileList, ignoreList, warning, referenceWarning } = await (0, import_utils.buildFileTree)(path, clientOptions, debug);
75
71
  const workPath = typeof path === "string" ? path : path[0];
76
72
  let filesMap;
77
73
  try {
@@ -90,7 +86,15 @@ ${err.message}`;
90
86
  if (clientOptions.servePageAtRoot && !clientOptions.prebuilt && clientOptions.archive !== "tgz" && typeof path === "string") {
91
87
  addRootPageAlias(filesMap, isDirectory ? path : (0, import_path.dirname)(path), debug);
92
88
  }
93
- return { fileList, filesMap, workPath, isDirectory, ignoreList, warning };
89
+ return {
90
+ fileList,
91
+ filesMap,
92
+ workPath,
93
+ isDirectory,
94
+ ignoreList,
95
+ warning,
96
+ referenceWarning
97
+ };
94
98
  }
95
99
  function addRootPageAlias(filesMap, root, debug) {
96
100
  let page;
package/dist/continue.js CHANGED
@@ -54,7 +54,7 @@ async function* continueDeployment(options) {
54
54
  })
55
55
  };
56
56
  }
57
- const { fileList, warning } = await (0, import_utils.buildFileTree)(
57
+ const { fileList, warning, referenceWarning } = await (0, import_utils.buildFileTree)(
58
58
  options.path,
59
59
  { isDirectory: true, prebuilt: true, vercelOutputDir: outputDir },
60
60
  debug
@@ -67,6 +67,14 @@ async function* continueDeployment(options) {
67
67
  code: "PREBUILT_FILEPATHMAP_IGNORED"
68
68
  };
69
69
  }
70
+ if (referenceWarning) {
71
+ debug("Yielding a prebuilt skipped references warning");
72
+ yield {
73
+ type: "warning",
74
+ payload: referenceWarning,
75
+ code: "PREBUILT_REFERENCE_SKIPPED"
76
+ };
77
+ }
70
78
  const provisionJsonPath = (0, import_path.join)(outputDir, "provision.json");
71
79
  const unbundledFiles = fileList.filter((f) => f === provisionJsonPath);
72
80
  let files;
@@ -65,7 +65,8 @@ function buildCreateDeployment() {
65
65
  const {
66
66
  fileList,
67
67
  filesMap: files,
68
- warning
68
+ warning,
69
+ referenceWarning
69
70
  } = await (0, import_collect_deployment_files.collectDeploymentFiles)(path, clientOptions, debug);
70
71
  if (warning) {
71
72
  debug("Yielding a prebuilt filePathMap ignore warning");
@@ -75,6 +76,14 @@ function buildCreateDeployment() {
75
76
  code: "PREBUILT_FILEPATHMAP_IGNORED"
76
77
  };
77
78
  }
79
+ if (referenceWarning) {
80
+ debug("Yielding a prebuilt skipped references warning");
81
+ yield {
82
+ type: "warning",
83
+ payload: referenceWarning,
84
+ code: "PREBUILT_REFERENCE_SKIPPED"
85
+ };
86
+ }
78
87
  if (fileList.length === 0) {
79
88
  debug("Deployment path has no files. Yielding a warning event");
80
89
  yield {
package/dist/deploy.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { FilesMap } from './utils/hashes';
2
+ import { GzipRequestBodies } from './utils/gzip-request-body';
2
3
  import { DeploymentOptions, VercelClientOptions, DeploymentEventType } from './types';
3
- export declare function deploy(files: FilesMap, clientOptions: VercelClientOptions, deploymentOptions: DeploymentOptions): AsyncIterableIterator<{
4
+ export declare function deploy(files: FilesMap, clientOptions: VercelClientOptions, deploymentOptions: DeploymentOptions, gzipRequestBodies?: GzipRequestBodies): AsyncIterableIterator<{
4
5
  type: DeploymentEventType;
5
6
  payload: any;
6
7
  }>;
package/dist/deploy.js CHANGED
@@ -25,7 +25,13 @@ var import_query_string = require("./utils/query-string");
25
25
  var import_ready_state = require("./utils/ready-state");
26
26
  var import_check_deployment_status = require("./check-deployment-status");
27
27
  var import_utils = require("./utils");
28
- async function* postDeployment(files, clientOptions, deploymentOptions) {
28
+ var import_gzip_request_body = require("./utils/gzip-request-body");
29
+ function hasEnvValues({ env, build }) {
30
+ return [env, build?.env].some(
31
+ (values) => values && Object.keys(values).length > 0
32
+ );
33
+ }
34
+ async function* postDeployment(files, clientOptions, deploymentOptions, gzipRequestBodies) {
29
35
  const debug = (0, import_utils.createDebug)(clientOptions.debug);
30
36
  const inlineFiles = (0, import_utils.shouldInlineStaticFiles)(files) || clientOptions.firstDeployment === true && !clientOptions.prebuilt && !clientOptions.archive && (0, import_utils.shouldInlineSmallProject)(files);
31
37
  const apiDeployments = (0, import_utils.getApiDeploymentsUrl)();
@@ -39,7 +45,7 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
39
45
  deploymentOptions.customEnvironmentSlugOrId = deploymentOptions.target;
40
46
  deploymentOptions.target = void 0;
41
47
  }
42
- const sendDeployment = async (preparedFiles) => {
48
+ const requestDeployment = async (requestBody) => {
43
49
  const response = await (0, import_utils.fetchApi)(
44
50
  `${apiDeployments}${(0, import_query_string.generateQueryString)(clientOptions)}`,
45
51
  clientOptions.token,
@@ -47,12 +53,10 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
47
53
  method: "POST",
48
54
  headers: {
49
55
  Accept: "application/json",
50
- "Content-Type": "application/json"
56
+ "Content-Type": "application/json",
57
+ ...requestBody.headers
51
58
  },
52
- body: JSON.stringify({
53
- ...deploymentOptions,
54
- files: preparedFiles
55
- }),
59
+ body: requestBody.body,
56
60
  apiUrl: clientOptions.apiUrl,
57
61
  userAgent: clientOptions.userAgent,
58
62
  dispatcher: clientOptions.dispatcher,
@@ -63,6 +67,33 @@ async function* postDeployment(files, clientOptions, deploymentOptions) {
63
67
  try {
64
68
  deployment = await response.json();
65
69
  } catch (_error) {
70
+ }
71
+ return { response, deployment };
72
+ };
73
+ const sendDeployment = async (preparedFiles) => {
74
+ const json = JSON.stringify({
75
+ ...deploymentOptions,
76
+ files: preparedFiles
77
+ });
78
+ const requestBody = await gzipRequestBodies.encode(
79
+ json,
80
+ !hasEnvValues(deploymentOptions)
81
+ );
82
+ if (requestBody.gzip) {
83
+ debug(
84
+ `Sending a gzip request body (${requestBody.bytes} of ${requestBody.decodedBytes} bytes)`
85
+ );
86
+ }
87
+ let { response, deployment } = await requestDeployment(requestBody);
88
+ if (gzipRequestBodies.settle(requestBody, response, deployment?.error?.code)) {
89
+ debug(
90
+ `The API refused the gzip request body with status ${response.status}. Sending it uncompressed`
91
+ );
92
+ ({ response, deployment } = await requestDeployment(
93
+ await gzipRequestBodies.encode(json, false)
94
+ ));
95
+ }
96
+ if (deployment === void 0) {
66
97
  throw new Error("Invalid JSON response");
67
98
  }
68
99
  if (clientOptions.debug) {
@@ -128,7 +159,7 @@ function getDefaultName(files, clientOptions) {
128
159
  return filePath.split("/").pop() || filePath;
129
160
  }
130
161
  }
131
- async function* deploy(files, clientOptions, deploymentOptions) {
162
+ async function* deploy(files, clientOptions, deploymentOptions, gzipRequestBodies = new import_gzip_request_body.GzipRequestBodies()) {
132
163
  const debug = (0, import_utils.createDebug)(clientOptions.debug);
133
164
  if (!deploymentOptions.name && files.size > 0) {
134
165
  deploymentOptions.version = 2;
@@ -152,7 +183,8 @@ async function* deploy(files, clientOptions, deploymentOptions) {
152
183
  for await (const event of postDeployment(
153
184
  files,
154
185
  clientOptions,
155
- deploymentOptions
186
+ deploymentOptions,
187
+ gzipRequestBodies
156
188
  )) {
157
189
  if (event.type === "created") {
158
190
  debug("Deployment created");
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { continueDeployment } from './continue';
2
2
  export { checkDeploymentStatus } from './check-deployment-status';
3
3
  export { inspectDeploymentFiles } from './inspect-deployment-files';
4
- export { getVercelIgnore, buildFileTree } from './utils/index';
4
+ export { getVercelIgnore, buildFileTree, isVercelStateFile, } from './utils/index';
5
5
  export { DPOP_CLOCK_SKEW_TOLERANCE_SECONDS, getDpopServerTime, shouldResendDpopRequest, } from './utils/dpop';
6
6
  export declare const createDeployment: (clientOptions: import("./types").VercelClientOptions, deploymentOptions?: import("./types").DeploymentOptions | Promise<import("./types").DeploymentOptions>) => AsyncIterableIterator<{
7
7
  type: import("./types").DeploymentEventType;
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ __export(src_exports, {
37
37
  getDpopServerTime: () => import_dpop.getDpopServerTime,
38
38
  getVercelIgnore: () => import_utils.getVercelIgnore,
39
39
  inspectDeploymentFiles: () => import_inspect_deployment_files.inspectDeploymentFiles,
40
+ isVercelStateFile: () => import_utils.isVercelStateFile,
40
41
  shouldResendDpopRequest: () => import_dpop.shouldResendDpopRequest
41
42
  });
42
43
  module.exports = __toCommonJS(src_exports);
@@ -59,6 +60,7 @@ const createDeployment = (0, import_create_deployment.default)();
59
60
  getDpopServerTime,
60
61
  getVercelIgnore,
61
62
  inspectDeploymentFiles,
63
+ isVercelStateFile,
62
64
  shouldResendDpopRequest,
63
65
  ...require("./errors"),
64
66
  ...require("./types")
@@ -13,5 +13,6 @@ export interface DeploymentFileSummary {
13
13
  files: DeploymentFileItem[];
14
14
  ignored: string[];
15
15
  warning?: string;
16
+ referenceWarning?: string;
16
17
  }
17
18
  export declare function inspectDeploymentFiles(clientOptions: Pick<VercelClientOptions, 'archive' | 'bulkRedirectsPath' | 'debug' | 'path' | 'prebuilt' | 'projectName' | 'rootDirectory' | 'servePageAtRoot' | 'vercelOutputDir'>): Promise<DeploymentFileSummary>;
@@ -27,7 +27,14 @@ var import_utils = require("./utils");
27
27
  async function inspectDeploymentFiles(clientOptions) {
28
28
  const { path } = clientOptions;
29
29
  const debug = (0, import_utils.createDebug)(clientOptions.debug);
30
- const { filesMap, workPath, isDirectory, ignoreList, warning } = await (0, import_collect_deployment_files.collectDeploymentFiles)(path, { ...clientOptions }, debug);
30
+ const {
31
+ filesMap,
32
+ workPath,
33
+ isDirectory,
34
+ ignoreList,
35
+ warning,
36
+ referenceWarning
37
+ } = await (0, import_collect_deployment_files.collectDeploymentFiles)(path, { ...clientOptions }, debug);
31
38
  const files = [];
32
39
  let totalSize = 0;
33
40
  for (const [sha, file] of filesMap) {
@@ -55,7 +62,8 @@ async function inspectDeploymentFiles(clientOptions) {
55
62
  ignoredCount: ignoreList.length,
56
63
  files,
57
64
  ignored: ignoreList.sort(),
58
- warning
65
+ warning,
66
+ referenceWarning
59
67
  };
60
68
  }
61
69
  // Annotate the CommonJS export names for ESM import in node:
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Builder, BuilderFunctions, Images, ProjectSettings, Cron, VercelJsonSchedules, ExperimentalServices, ExperimentalServiceGroups, ExperimentalServicesV2, Services, Daemons } from '@vercel/build-utils';
1
+ import type { Builder, BuilderFunctions, Images, ProjectSettings, Cron, VercelJsonSchedules, ExperimentalServices, ExperimentalServiceGroups, ExperimentalServicesV2, Services, Daemons, ProxyConfig } from '@vercel/build-utils';
2
2
  import type { Header, Route, Redirect, Rewrite } from '@vercel/routing-utils';
3
3
  export type { DeploymentEventType } from './utils';
4
4
  /**
@@ -12,10 +12,7 @@ export interface FetchDispatcher {
12
12
  export interface Dictionary<T> {
13
13
  [key: string]: T;
14
14
  }
15
- export interface ProxyConfig {
16
- entrypoint: string;
17
- matcher?: string | string[];
18
- }
15
+ export type { ProxyConfig };
19
16
  export declare const VALID_ARCHIVE_FORMATS: readonly ["tgz"];
20
17
  export type ArchiveFormat = (typeof VALID_ARCHIVE_FORMATS)[number];
21
18
  export interface DeploymentAliasError {
package/dist/upload.js CHANGED
@@ -42,6 +42,7 @@ var import_utils = require("./utils");
42
42
  var import_errors = require("./errors");
43
43
  var import_network_error = require("./utils/network-error");
44
44
  var import_deploy = require("./deploy");
45
+ var import_gzip_request_body = require("./utils/gzip-request-body");
45
46
  async function* upload(files, clientOptions, deploymentOptions) {
46
47
  const debug = (0, import_utils.createDebug)(clientOptions.debug);
47
48
  if (!files && !clientOptions.token && !clientOptions.teamId) {
@@ -49,8 +50,14 @@ async function* upload(files, clientOptions, deploymentOptions) {
49
50
  return;
50
51
  }
51
52
  let shas = [];
53
+ const gzipRequestBodies = new import_gzip_request_body.GzipRequestBodies();
52
54
  debug("Determining necessary files for upload...");
53
- for await (const event of (0, import_deploy.deploy)(files, clientOptions, deploymentOptions)) {
55
+ for await (const event of (0, import_deploy.deploy)(
56
+ files,
57
+ clientOptions,
58
+ deploymentOptions,
59
+ gzipRequestBodies
60
+ )) {
54
61
  if (event.type === "error") {
55
62
  if (event.payload.code === "missing_files") {
56
63
  shas = event.payload.missing;
@@ -98,7 +105,12 @@ async function* upload(files, clientOptions, deploymentOptions) {
98
105
  yield { type: "all-files-uploaded", payload: files };
99
106
  try {
100
107
  debug("Starting deployment creation");
101
- for await (const event of (0, import_deploy.deploy)(files, clientOptions, deploymentOptions)) {
108
+ for await (const event of (0, import_deploy.deploy)(
109
+ files,
110
+ clientOptions,
111
+ deploymentOptions,
112
+ gzipRequestBodies
113
+ )) {
102
114
  if (event.type === "alias-assigned" || event.type === "checks-v2-failed") {
103
115
  debug("Deployment is ready");
104
116
  return yield event;
@@ -0,0 +1,36 @@
1
+ export interface RequestBody {
2
+ body: string | Buffer;
3
+ headers: Record<string, string>;
4
+ /** The byte length of `body`. */
5
+ bytes: number;
6
+ /** The byte length of the JSON that `body` carries. */
7
+ decodedBytes: number;
8
+ gzip: boolean;
9
+ }
10
+ interface ApiResponse {
11
+ status: number;
12
+ headers: {
13
+ get(name: string): string | null | undefined;
14
+ };
15
+ }
16
+ /**
17
+ * Decides whether the creation requests of one deployment send a gzip body.
18
+ *
19
+ * The API sends `Accept-Encoding: gzip` on the responses of the creation
20
+ * endpoint when it accepts a gzip body there. A request is compressed only
21
+ * after such a response, so the first request of a deployment never is.
22
+ */
23
+ export declare class GzipRequestBodies {
24
+ private accepted;
25
+ private refused;
26
+ /** `allowed: false` keeps the body of this request uncompressed. */
27
+ encode(json: string, allowed?: boolean): Promise<RequestBody>;
28
+ /**
29
+ * Takes the response to a creation request. Returns `true` when the answer
30
+ * to a gzip body can come from the encoding. The API created nothing then,
31
+ * so the caller sends the request again, and no later request is
32
+ * compressed.
33
+ */
34
+ settle(sent: RequestBody, response: ApiResponse, errorCode?: unknown): boolean;
35
+ }
36
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var gzip_request_body_exports = {};
20
+ __export(gzip_request_body_exports, {
21
+ GzipRequestBodies: () => GzipRequestBodies
22
+ });
23
+ module.exports = __toCommonJS(gzip_request_body_exports);
24
+ var import_node_util = require("node:util");
25
+ var import_node_zlib = require("node:zlib");
26
+ const gzipAsync = (0, import_node_util.promisify)(import_node_zlib.gzip);
27
+ const MIN_GZIP_BYTES = 16 * 1024;
28
+ class GzipRequestBodies {
29
+ constructor() {
30
+ this.accepted = false;
31
+ this.refused = false;
32
+ }
33
+ /** `allowed: false` keeps the body of this request uncompressed. */
34
+ async encode(json, allowed = true) {
35
+ const decodedBytes = Buffer.byteLength(json);
36
+ const plain = {
37
+ body: json,
38
+ headers: {},
39
+ bytes: decodedBytes,
40
+ decodedBytes,
41
+ gzip: false
42
+ };
43
+ if (!allowed || !this.accepted || this.refused || decodedBytes < MIN_GZIP_BYTES) {
44
+ return plain;
45
+ }
46
+ const body = await gzipAsync(json).catch(() => void 0);
47
+ if (!body || body.byteLength >= decodedBytes) {
48
+ return plain;
49
+ }
50
+ return {
51
+ body,
52
+ headers: {
53
+ "Content-Encoding": "gzip",
54
+ "x-vercel-decoded-length": String(decodedBytes)
55
+ },
56
+ bytes: body.byteLength,
57
+ decodedBytes,
58
+ gzip: true
59
+ };
60
+ }
61
+ /**
62
+ * Takes the response to a creation request. Returns `true` when the answer
63
+ * to a gzip body can come from the encoding. The API created nothing then,
64
+ * so the caller sends the request again, and no later request is
65
+ * compressed.
66
+ */
67
+ settle(sent, response, errorCode) {
68
+ if (sent.gzip && refusedGzip(response.status, errorCode)) {
69
+ this.refused = true;
70
+ return true;
71
+ }
72
+ this.accepted = acceptsGzip(response);
73
+ return false;
74
+ }
75
+ }
76
+ function refusedGzip(status, errorCode) {
77
+ if (status === 415) {
78
+ return true;
79
+ }
80
+ return status === 400 && (errorCode === void 0 || errorCode === "invalid_request_encoding" || errorCode === "bad_request");
81
+ }
82
+ function acceptsGzip(response) {
83
+ const value = response.headers.get("accept-encoding");
84
+ if (!value) {
85
+ return false;
86
+ }
87
+ return value.split(",").some((item) => {
88
+ const [coding, ...params] = item.split(";").map((part) => part.trim());
89
+ return coding.toLowerCase() === "gzip" && !params.some((param) => /^q=0(\.0*)?$/i.test(param));
90
+ });
91
+ }
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ GzipRequestBodies
95
+ });
@@ -9,10 +9,21 @@ export type DeploymentEventType = (typeof EVENTS_ARRAY)[number];
9
9
  export declare const EVENTS: Set<"alias-assigned" | "error" | "hashes-calculated" | "file-count" | "file-uploaded" | "all-files-uploaded" | "created" | "building" | "ready" | "warning" | "notice" | "tip" | "canceled" | "blocked" | "checks-registered" | "checks-completed" | "checks-running" | "checks-conclusion-succeeded" | "checks-conclusion-failed" | "checks-conclusion-skipped" | "checks-conclusion-canceled" | "checks-v2-failed">;
10
10
  export declare function getApiDeploymentsUrl(): string;
11
11
  export declare function parseVercelConfig(filePath?: string): Promise<VercelConfig>;
12
+ /**
13
+ * Whether a root-relative POSIX path is a file directly inside a `.vercel/`
14
+ * directory at any depth. The CLI keeps its local state there: anonymous
15
+ * deployment credentials (`anonymous.json`), link files (`project.json`,
16
+ * `repo.json`), and env files from `vercel pull` (`.env.<target>.local`).
17
+ * Builder work directories nested under `.vercel/` (such as the Python venv in
18
+ * `.vercel/python/.venv`) are not matched; builders reference them in
19
+ * `filePathMap`.
20
+ */
21
+ export declare function isVercelStateFile(posixRel: string): boolean;
12
22
  export declare function buildFileTree(path: string | string[], { isDirectory, prebuilt, vercelOutputDir, rootDirectory, projectName, bulkRedirectsPath, }: Pick<VercelClientOptions, 'isDirectory' | 'prebuilt' | 'vercelOutputDir' | 'rootDirectory' | 'projectName' | 'bulkRedirectsPath'>, debug: Debug): Promise<{
13
23
  fileList: string[];
14
24
  ignoreList: string[];
15
25
  warning?: string;
26
+ referenceWarning?: string;
16
27
  }>;
17
28
  export declare function getVercelIgnore(cwd: string | string[], prebuilt?: boolean, vercelOutputDir?: string): Promise<{
18
29
  ig: Ignore;
@@ -35,6 +35,7 @@ __export(utils_exports, {
35
35
  fetchApi: () => fetchApi,
36
36
  getApiDeploymentsUrl: () => getApiDeploymentsUrl,
37
37
  getVercelIgnore: () => getVercelIgnore,
38
+ isVercelStateFile: () => isVercelStateFile,
38
39
  needsNewDpopProof: () => needsNewDpopProof,
39
40
  parseVercelConfig: () => parseVercelConfig,
40
41
  prepareFiles: () => prepareFiles,
@@ -44,6 +45,7 @@ __export(utils_exports, {
44
45
  module.exports = __toCommonJS(utils_exports);
45
46
  var import_network_error = require("./network-error");
46
47
  var import_path = require("path");
48
+ var import_fs = require("fs");
47
49
  var import_stream = require("stream");
48
50
  var import_url = require("url");
49
51
  var import_ignore = __toESM(require("ignore"));
@@ -130,6 +132,16 @@ async function getUserIgnore(cwd) {
130
132
  }
131
133
  const VCS_DEFAULTS = [".hg", ".git", ".gitmodules", ".svn", "CVS"];
132
134
  const filePathMapVcsDefaults = (0, import_ignore.default)().add(VCS_DEFAULTS);
135
+ function isVercelStateFile(posixRel) {
136
+ const parts = posixRel.split("/");
137
+ return parts.length >= 2 && parts[parts.length - 2].toLowerCase() === ".vercel";
138
+ }
139
+ function isInsideDir(dir, path) {
140
+ if (!dir)
141
+ return false;
142
+ const rel = (0, import_path.relative)(dir, path);
143
+ return rel !== "" && !rel.startsWith("..") && !(0, import_path.isAbsolute)(rel);
144
+ }
133
145
  const FILEPATHMAP_VERCELIGNORE_EXCEPTIONS = [
134
146
  "node_modules",
135
147
  ".next",
@@ -182,6 +194,97 @@ function formatFilePathMapIgnoreWarning(entries, ignoreFileName, truncated = fal
182
194
  `Remove the colliding rules from \`${ignoreFileName}\`, or exclude those paths from tracing with \`outputFileTracingExcludes\`.`
183
195
  ].join("\n");
184
196
  }
197
+ const SENSITIVE_DEFAULT_SEGMENT = /^(?:\.now|\.vercel|\.env\.local|\.env\.[^/]*\.local)$/i;
198
+ function matchesSensitiveDefault(posixRel) {
199
+ return posixRel.split("/").some((segment) => SENSITIVE_DEFAULT_SEGMENT.test(segment));
200
+ }
201
+ function isInDirectory(dir, absPath) {
202
+ if (!dir)
203
+ return false;
204
+ const rel = (0, import_path.relative)(dir, absPath);
205
+ return !rel.startsWith("..") && !(0, import_path.isAbsolute)(rel);
206
+ }
207
+ function realPathOf(absPath) {
208
+ try {
209
+ return import_fs.realpathSync.native(absPath);
210
+ } catch (_err) {
211
+ return void 0;
212
+ }
213
+ }
214
+ function createPrebuiltReferencePolicy(root, vercelOutputDir, userIg) {
215
+ return (absPath, kind) => {
216
+ const rel = (0, import_path.relative)(root, absPath);
217
+ if (rel.startsWith("..") || (0, import_path.isAbsolute)(rel)) {
218
+ return "outside-root";
219
+ }
220
+ const posixRel = rel.split(import_path.sep).join("/");
221
+ if (kind === "filePathMap") {
222
+ if (filePathMapVcsDefaults.ignores(posixRel)) {
223
+ return "vcs-default";
224
+ }
225
+ return userIg?.ig.ignores(posixRel) && !isFilePathMapIgnoreException(posixRel) ? "user-ignore" : void 0;
226
+ }
227
+ if (!posixRel || isInDirectory(vercelOutputDir, absPath)) {
228
+ return void 0;
229
+ }
230
+ if (filePathMapVcsDefaults.ignores(posixRel)) {
231
+ return "vcs-default";
232
+ }
233
+ if (matchesSensitiveDefault(posixRel)) {
234
+ return "sensitive-default";
235
+ }
236
+ return userIg?.ig.ignores(posixRel) ? "user-ignore" : void 0;
237
+ };
238
+ }
239
+ const EXCLUDED_REFERENCE_WARNING_LIST_LIMIT = 20;
240
+ function printable(text) {
241
+ return text.replace(
242
+ /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g,
243
+ "?"
244
+ );
245
+ }
246
+ function formatSkippedReferencesWarning(entries, total, userRuleTotal, ignoreFileName) {
247
+ const lines = entries.map(
248
+ ([path, exclusion]) => ` ${printable(path)} (${exclusion === "user-ignore" ? `\`${ignoreFileName}\` rule` : exclusion === "unresolved" ? "unknown on-disk path" : "default exclusion"})`
249
+ );
250
+ if (total > entries.length) {
251
+ lines.push(` \u2026and ${total - entries.length} more`);
252
+ }
253
+ return [
254
+ total === 1 ? "A source exclusion matches 1 path that this prebuilt deployment references. The CLI skipped it." : `Source exclusions match ${total} paths that this prebuilt deployment references. The CLI skipped them.`,
255
+ "",
256
+ ...lines,
257
+ "",
258
+ userRuleTotal > 0 ? `To upload a skipped path, remove its rule from \`${ignoreFileName}\`, or move or rename the file.` : "To upload a skipped path, move or rename the file."
259
+ ].join("\n");
260
+ }
261
+ const EXCLUSION_ERROR_TEXT_LIMIT = 200;
262
+ function bulkRedirectsExcludedError(bulkRedirectsPath, exclusion, userIg, posixRels) {
263
+ const shown = (text) => printable(text).slice(0, EXCLUSION_ERROR_TEXT_LIMIT);
264
+ const ignoreFileName = userIg?.ignoreFileName || ".vercelignore";
265
+ let reason;
266
+ let fix;
267
+ if (exclusion === "each-file") {
268
+ reason = `Source exclusions match each file in the bulk redirects path "${shown(bulkRedirectsPath)}".`;
269
+ fix = `Remove the rules from \`${ignoreFileName}\`, or move the redirects to a different path.`;
270
+ } else if (exclusion === "user-ignore" && userIg) {
271
+ const match = posixRels.map((posixRel) => findMatchingIgnoreRule(userIg.ignoreFile, posixRel)).find(({ rule, line }) => rule && line);
272
+ reason = match ? `The bulk redirects path "${shown(bulkRedirectsPath)}" matches the rule \`${shown(match.rule)}\` (\`${ignoreFileName}:${match.line}\`).` : `The bulk redirects path "${shown(bulkRedirectsPath)}" matches a rule in \`${ignoreFileName}\`.`;
273
+ fix = "Remove the rule, or move the redirects to a different path.";
274
+ } else if (exclusion === "unresolved") {
275
+ return new import_build_utils.NowBuildError({
276
+ code: "PREBUILT_BULK_REDIRECTS_EXCLUDED",
277
+ message: `The CLI cannot find the on-disk path of the bulk redirects path "${shown(bulkRedirectsPath)}". The CLI does not upload a path that it cannot check against the source exclusions. Move the redirects to a different path.`
278
+ });
279
+ } else {
280
+ reason = `The bulk redirects path "${shown(bulkRedirectsPath)}" matches a default source exclusion.`;
281
+ fix = "Move the redirects to a different path.";
282
+ }
283
+ return new import_build_utils.NowBuildError({
284
+ code: "PREBUILT_BULK_REDIRECTS_EXCLUDED",
285
+ message: `${reason} The CLI does not upload a path that a source exclusion matches. ${fix}`
286
+ });
287
+ }
185
288
  async function buildFileTree(path, {
186
289
  isDirectory,
187
290
  prebuilt,
@@ -193,6 +296,7 @@ async function buildFileTree(path, {
193
296
  const ignoreList = [];
194
297
  let fileList;
195
298
  let warning;
299
+ let referenceWarning;
196
300
  let { ig, ignores } = await getVercelIgnore(path, prebuilt, vercelOutputDir);
197
301
  debug(`Found ${ignores.length} rules in .vercelignore`);
198
302
  debug("Building file tree...");
@@ -207,11 +311,52 @@ async function buildFileTree(path, {
207
311
  };
208
312
  fileList = await (0, import_readdir_recursive.default)(path, [ignores2]);
209
313
  const refs = /* @__PURE__ */ new Set();
314
+ const userIg = prebuilt ? await getUserIgnore(path) : null;
315
+ const getReferenceExclusion = createPrebuiltReferencePolicy(
316
+ path,
317
+ vercelOutputDir,
318
+ userIg
319
+ );
320
+ let realRoot = null;
321
+ const toRootPath = (realPath) => {
322
+ if (realRoot === null) {
323
+ realRoot = realPathOf(path);
324
+ }
325
+ return realRoot === void 0 ? void 0 : (0, import_path.join)(path, (0, import_path.relative)(realRoot, realPath));
326
+ };
327
+ const getOnDiskExclusion = (absPath, realPath, kind) => {
328
+ const exclusion = getReferenceExclusion(absPath, kind);
329
+ if (exclusion || realPath === absPath) {
330
+ return exclusion;
331
+ }
332
+ const rootPath = realPath === void 0 ? void 0 : toRootPath(realPath);
333
+ if (rootPath === void 0) {
334
+ return "unresolved";
335
+ }
336
+ const onDiskExclusion = getReferenceExclusion(rootPath, kind);
337
+ return onDiskExclusion === "outside-root" ? void 0 : onDiskExclusion;
338
+ };
339
+ const skippedReferences = /* @__PURE__ */ new Map();
340
+ let skippedReferenceCount = 0;
341
+ let skippedByUserRuleCount = 0;
342
+ const skipReference = (absPath, exclusion) => {
343
+ const posixRel = (0, import_path.relative)(path, absPath).split(import_path.sep).join("/");
344
+ debug(`Skipping the reference "${printable(posixRel)}": ${exclusion}`);
345
+ if (exclusion === "outside-root" || skippedReferences.has(posixRel)) {
346
+ return;
347
+ }
348
+ skippedReferenceCount++;
349
+ if (exclusion === "user-ignore") {
350
+ skippedByUserRuleCount++;
351
+ }
352
+ if (skippedReferences.size < EXCLUDED_REFERENCE_WARNING_LIST_LIMIT) {
353
+ skippedReferences.set(posixRel, exclusion);
354
+ }
355
+ };
210
356
  if (prebuilt) {
211
357
  const vcConfigFilePaths = fileList.filter(
212
358
  (file) => (0, import_path.basename)(file) === ".vc-config.json"
213
359
  );
214
- const userIg = await getUserIgnore(path);
215
360
  const ignoredFilePathMap = /* @__PURE__ */ new Map();
216
361
  let ignoredFilePathMapTruncated = false;
217
362
  const vcConfigs = await Promise.all(
@@ -227,20 +372,25 @@ async function buildFileTree(path, {
227
372
  const absPath = (0, import_path.join)(path, v);
228
373
  const rel = (0, import_path.relative)(path, absPath);
229
374
  const posixRel = rel.split(import_path.sep).join("/");
230
- if (rel.startsWith("..") || (0, import_path.isAbsolute)(rel)) {
375
+ const exclusion = getReferenceExclusion(absPath, "filePathMap");
376
+ if (exclusion === "outside-root") {
231
377
  debug(
232
378
  `Ignoring "filePathMap" entry "${v}": resolves outside the deployment root`
233
379
  );
234
380
  continue;
235
381
  }
236
- if (filePathMapVcsDefaults.ignores(posixRel)) {
382
+ if (exclusion === "vcs-default") {
237
383
  throw new import_build_utils.NowBuildError({
238
384
  code: "PREBUILT_FILEPATHMAP_VCS",
239
385
  message: "Prebuilt functions reference version-control files that cannot be uploaded. Exclude version-control files from tracing and rebuild the prebuilt output."
240
386
  });
241
387
  }
388
+ if (isVercelStateFile(posixRel) && !isInsideDir(vercelOutputDir, absPath)) {
389
+ debug('Excluding a "filePathMap" entry: Vercel CLI state file');
390
+ continue;
391
+ }
242
392
  if (userIg && userIg.ig.ignores(posixRel)) {
243
- if (isFilePathMapIgnoreException(posixRel)) {
393
+ if (exclusion !== "user-ignore") {
244
394
  debug(
245
395
  `Keeping "filePathMap" entry "${v}": matches a default-ignored dependency/output path`
246
396
  );
@@ -294,7 +444,16 @@ async function buildFileTree(path, {
294
444
  });
295
445
  }
296
446
  if (microfrontendConfigPath) {
297
- refs.add(microfrontendConfigPath);
447
+ const exclusion = getOnDiskExclusion(
448
+ microfrontendConfigPath,
449
+ realPathOf(microfrontendConfigPath),
450
+ "microfrontends"
451
+ );
452
+ if (exclusion) {
453
+ skipReference(microfrontendConfigPath, exclusion);
454
+ } else {
455
+ refs.add(microfrontendConfigPath);
456
+ }
298
457
  }
299
458
  } catch (e) {
300
459
  debug(`Error detecting microfrontend config: ${e}`);
@@ -318,16 +477,61 @@ async function buildFileTree(path, {
318
477
  rootDirectory || "",
319
478
  bulkRedirectsPath
320
479
  );
321
- const relativeFromRoot = (0, import_path.relative)(projectRoot, bulkRedirectsFullPath);
322
- if (relativeFromRoot.startsWith("..")) {
480
+ if (getReferenceExclusion(bulkRedirectsFullPath, "bulkRedirects") === "outside-root") {
323
481
  debug(
324
482
  `Skipping bulk redirects path "${bulkRedirectsPath}" - path traversal detected (resolves outside project root)`
325
483
  );
326
484
  } else {
327
485
  try {
328
486
  const stats = await (0, import_fs_extra.stat)(bulkRedirectsFullPath);
329
- if (stats.isDirectory()) {
330
- const dirFiles = await (0, import_readdir_recursive.default)(bulkRedirectsFullPath, []);
487
+ const realBulkRedirectsPath = realPathOf(bulkRedirectsFullPath);
488
+ const exclusion = getOnDiskExclusion(
489
+ bulkRedirectsFullPath,
490
+ realBulkRedirectsPath,
491
+ "bulkRedirects"
492
+ );
493
+ if (exclusion || realBulkRedirectsPath === void 0) {
494
+ const rootPath = realBulkRedirectsPath && toRootPath(realBulkRedirectsPath);
495
+ throw bulkRedirectsExcludedError(
496
+ bulkRedirectsPath,
497
+ exclusion || "unresolved",
498
+ userIg,
499
+ [bulkRedirectsFullPath, rootPath || bulkRedirectsFullPath].map(
500
+ (file) => (0, import_path.relative)(path, file).split(import_path.sep).join("/")
501
+ )
502
+ );
503
+ } else if (stats.isDirectory()) {
504
+ let skipped = 0;
505
+ let kept = 0;
506
+ const dirFiles = await (0, import_readdir_recursive.default)(bulkRedirectsFullPath, [
507
+ (file, fileStats) => {
508
+ const fileExclusion = getOnDiskExclusion(
509
+ file,
510
+ (0, import_path.join)(
511
+ realBulkRedirectsPath,
512
+ (0, import_path.relative)(bulkRedirectsFullPath, file)
513
+ ),
514
+ "bulkRedirects"
515
+ );
516
+ if (!fileExclusion) {
517
+ if (!fileStats.isDirectory()) {
518
+ kept++;
519
+ }
520
+ return false;
521
+ }
522
+ skipReference(file, fileExclusion);
523
+ skipped++;
524
+ return true;
525
+ }
526
+ ]);
527
+ if (kept === 0 && skipped > 0) {
528
+ throw bulkRedirectsExcludedError(
529
+ bulkRedirectsPath,
530
+ "each-file",
531
+ userIg,
532
+ []
533
+ );
534
+ }
331
535
  for (const file of dirFiles) {
332
536
  refs.add(file);
333
537
  }
@@ -340,14 +544,28 @@ async function buildFileTree(path, {
340
544
  `Including bulk redirects file "${bulkRedirectsPath}" in deployment`
341
545
  );
342
546
  }
343
- } catch (_e) {
547
+ } catch (e) {
548
+ if (e instanceof import_build_utils.NowBuildError) {
549
+ throw e;
550
+ }
344
551
  debug(`Bulk redirects path "${bulkRedirectsPath}" not found`);
345
552
  }
346
553
  }
347
554
  } catch (e) {
555
+ if (e instanceof import_build_utils.NowBuildError) {
556
+ throw e;
557
+ }
348
558
  debug(`Error checking for bulk redirects path: ${e}`);
349
559
  }
350
560
  }
561
+ if (skippedReferenceCount > 0) {
562
+ referenceWarning = formatSkippedReferencesWarning(
563
+ [...skippedReferences.entries()].sort(([a], [b]) => a.localeCompare(b)),
564
+ skippedReferenceCount,
565
+ skippedByUserRuleCount,
566
+ userIg?.ignoreFileName || ".vercelignore"
567
+ );
568
+ }
351
569
  if (refs.size > 0) {
352
570
  fileList = fileList.concat(Array.from(refs));
353
571
  }
@@ -359,7 +577,7 @@ async function buildFileTree(path, {
359
577
  fileList = [path];
360
578
  debug(`Deploying the provided path as single file`);
361
579
  }
362
- return { fileList, ignoreList, warning };
580
+ return { fileList, ignoreList, warning, referenceWarning };
363
581
  }
364
582
  async function getVercelIgnore(cwd, prebuilt, vercelOutputDir) {
365
583
  const ig = (0, import_ignore.default)();
@@ -606,6 +824,7 @@ function createDebug(debug) {
606
824
  fetchApi,
607
825
  getApiDeploymentsUrl,
608
826
  getVercelIgnore,
827
+ isVercelStateFile,
609
828
  needsNewDpopProof,
610
829
  parseVercelConfig,
611
830
  prepareFiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/client",
3
- "version": "18.12.4",
3
+ "version": "18.13.0-snapshot-c9dfd83f2293",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "homepage": "https://vercel.com",
@@ -37,8 +37,8 @@
37
37
  "querystring": "^0.2.0",
38
38
  "sleep-promise": "8.0.1",
39
39
  "tar-fs": "1.16.3",
40
- "@vercel/build-utils": "15.5.0",
41
40
  "@vercel/error-utils": "2.2.1",
41
+ "@vercel/build-utils": "15.7.0-snapshot-c9dfd83f2293",
42
42
  "@vercel/routing-utils": "6.6.1"
43
43
  },
44
44
  "scripts": {