@vercel/client 13.0.1 → 13.0.3

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.
@@ -1,114 +1,137 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkDeploymentStatus = void 0;
7
- const sleep_promise_1 = __importDefault(require("sleep-promise"));
8
- const utils_1 = require("./utils");
9
- const get_polling_delay_1 = require("./utils/get-polling-delay");
10
- const ready_state_1 = require("./utils/ready-state");
11
- const utils_2 = require("./utils");
12
- /* eslint-disable */
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var check_deployment_status_exports = {};
30
+ __export(check_deployment_status_exports, {
31
+ checkDeploymentStatus: () => checkDeploymentStatus
32
+ });
33
+ module.exports = __toCommonJS(check_deployment_status_exports);
34
+ var import_sleep_promise = __toESM(require("sleep-promise"));
35
+ var import_utils = require("./utils");
36
+ var import_get_polling_delay = require("./utils/get-polling-delay");
37
+ var import_ready_state = require("./utils/ready-state");
38
+ var import_utils2 = require("./utils");
13
39
  async function* checkDeploymentStatus(deployment, clientOptions) {
14
- const { token, teamId, apiUrl, userAgent } = clientOptions;
15
- const debug = (0, utils_2.createDebug)(clientOptions.debug);
16
- let deploymentState = deployment;
17
- const apiDeployments = (0, utils_1.getApiDeploymentsUrl)({
18
- builds: deployment.builds,
19
- functions: deployment.functions,
20
- });
21
- // If the deployment is ready, we don't want any of this to run
22
- if ((0, ready_state_1.isDone)(deploymentState) && (0, ready_state_1.isAliasAssigned)(deploymentState)) {
23
- debug(`Deployment is already READY and aliases are assigned. Not running status checks`);
24
- return;
40
+ const { token, teamId, apiUrl, userAgent } = clientOptions;
41
+ const debug = (0, import_utils2.createDebug)(clientOptions.debug);
42
+ let deploymentState = deployment;
43
+ const apiDeployments = (0, import_utils.getApiDeploymentsUrl)({
44
+ builds: deployment.builds,
45
+ functions: deployment.functions
46
+ });
47
+ if ((0, import_ready_state.isDone)(deploymentState) && (0, import_ready_state.isAliasAssigned)(deploymentState)) {
48
+ debug(
49
+ `Deployment is already READY and aliases are assigned. Not running status checks`
50
+ );
51
+ return;
52
+ }
53
+ debug("Waiting for builds and the deployment to complete...");
54
+ const finishedEvents = /* @__PURE__ */ new Set();
55
+ const startTime = Date.now();
56
+ while (true) {
57
+ const deploymentData = await (0, import_utils.fetch)(
58
+ `${apiDeployments}/${deployment.id || deployment.deploymentId}${teamId ? `?teamId=${teamId}` : ""}`,
59
+ token,
60
+ { apiUrl, userAgent, agent: clientOptions.agent }
61
+ );
62
+ const deploymentUpdate = await deploymentData.json();
63
+ if (deploymentUpdate.error) {
64
+ debug("Deployment status check has errorred");
65
+ return yield { type: "error", payload: deploymentUpdate.error };
25
66
  }
26
- // Build polling
27
- debug('Waiting for builds and the deployment to complete...');
28
- const finishedEvents = new Set();
29
- const startTime = Date.now();
30
- while (true) {
31
- // Deployment polling
32
- const deploymentData = await (0, utils_1.fetch)(`${apiDeployments}/${deployment.id || deployment.deploymentId}${teamId ? `?teamId=${teamId}` : ''}`, token, { apiUrl, userAgent, agent: clientOptions.agent });
33
- const deploymentUpdate = await deploymentData.json();
34
- if (deploymentUpdate.error) {
35
- debug('Deployment status check has errorred');
36
- return yield { type: 'error', payload: deploymentUpdate.error };
37
- }
38
- if (deploymentUpdate.readyState === 'BUILDING' &&
39
- !finishedEvents.has('building')) {
40
- debug('Deployment state changed to BUILDING');
41
- finishedEvents.add('building');
42
- yield { type: 'building', payload: deploymentUpdate };
43
- }
44
- if (deploymentUpdate.readyState === 'CANCELED' &&
45
- !finishedEvents.has('canceled')) {
46
- debug('Deployment state changed to CANCELED');
47
- finishedEvents.add('canceled');
48
- yield { type: 'canceled', payload: deploymentUpdate };
49
- }
50
- if ((0, ready_state_1.isReady)(deploymentUpdate) && !finishedEvents.has('ready')) {
51
- debug('Deployment state changed to READY');
52
- finishedEvents.add('ready');
53
- yield { type: 'ready', payload: deploymentUpdate };
54
- }
55
- if (deploymentUpdate.checksState !== undefined) {
56
- if (deploymentUpdate.checksState === 'completed' &&
57
- !finishedEvents.has('checks-completed')) {
58
- finishedEvents.add('checks-completed');
59
- if (deploymentUpdate.checksConclusion === 'succeeded') {
60
- yield {
61
- type: 'checks-conclusion-succeeded',
62
- payload: deploymentUpdate,
63
- };
64
- }
65
- else if (deploymentUpdate.checksConclusion === 'failed') {
66
- yield { type: 'checks-conclusion-failed', payload: deploymentUpdate };
67
- }
68
- else if (deploymentUpdate.checksConclusion === 'skipped') {
69
- yield {
70
- type: 'checks-conclusion-skipped',
71
- payload: deploymentUpdate,
72
- };
73
- }
74
- else if (deploymentUpdate.checksConclusion === 'canceled') {
75
- yield {
76
- type: 'checks-conclusion-canceled',
77
- payload: deploymentUpdate,
78
- };
79
- }
80
- }
81
- if (deploymentUpdate.checksState === 'registered' &&
82
- !finishedEvents.has('checks-registered')) {
83
- finishedEvents.add('checks-registered');
84
- yield { type: 'checks-registered', payload: deploymentUpdate };
85
- }
86
- if (deploymentUpdate.checksState === 'running' &&
87
- !finishedEvents.has('checks-running')) {
88
- finishedEvents.add('checks-running');
89
- yield { type: 'checks-running', payload: deploymentUpdate };
90
- }
91
- }
92
- if ((0, ready_state_1.isAliasAssigned)(deploymentUpdate)) {
93
- debug('Deployment alias assigned');
94
- return yield { type: 'alias-assigned', payload: deploymentUpdate };
95
- }
96
- if ((0, ready_state_1.isAliasError)(deploymentUpdate)) {
97
- return yield { type: 'error', payload: deploymentUpdate.aliasError };
98
- }
99
- if (deploymentUpdate.readyState === 'ERROR' &&
100
- deploymentUpdate.errorCode === 'BUILD_FAILED') {
101
- return yield { type: 'error', payload: deploymentUpdate };
102
- }
103
- if ((0, ready_state_1.isFailed)(deploymentUpdate)) {
104
- return yield {
105
- type: 'error',
106
- payload: deploymentUpdate.error || deploymentUpdate,
107
- };
67
+ if (deploymentUpdate.readyState === "BUILDING" && !finishedEvents.has("building")) {
68
+ debug("Deployment state changed to BUILDING");
69
+ finishedEvents.add("building");
70
+ yield { type: "building", payload: deploymentUpdate };
71
+ }
72
+ if (deploymentUpdate.readyState === "CANCELED" && !finishedEvents.has("canceled")) {
73
+ debug("Deployment state changed to CANCELED");
74
+ finishedEvents.add("canceled");
75
+ yield { type: "canceled", payload: deploymentUpdate };
76
+ }
77
+ if ((0, import_ready_state.isReady)(deploymentUpdate) && !finishedEvents.has("ready")) {
78
+ debug("Deployment state changed to READY");
79
+ finishedEvents.add("ready");
80
+ yield { type: "ready", payload: deploymentUpdate };
81
+ }
82
+ if (deploymentUpdate.checksState !== void 0) {
83
+ if (deploymentUpdate.checksState === "completed" && !finishedEvents.has("checks-completed")) {
84
+ finishedEvents.add("checks-completed");
85
+ if (deploymentUpdate.checksConclusion === "succeeded") {
86
+ yield {
87
+ type: "checks-conclusion-succeeded",
88
+ payload: deploymentUpdate
89
+ };
90
+ } else if (deploymentUpdate.checksConclusion === "failed") {
91
+ yield { type: "checks-conclusion-failed", payload: deploymentUpdate };
92
+ } else if (deploymentUpdate.checksConclusion === "skipped") {
93
+ yield {
94
+ type: "checks-conclusion-skipped",
95
+ payload: deploymentUpdate
96
+ };
97
+ } else if (deploymentUpdate.checksConclusion === "canceled") {
98
+ yield {
99
+ type: "checks-conclusion-canceled",
100
+ payload: deploymentUpdate
101
+ };
108
102
  }
109
- const elapsed = Date.now() - startTime;
110
- const duration = (0, get_polling_delay_1.getPollingDelay)(elapsed);
111
- await (0, sleep_promise_1.default)(duration);
103
+ }
104
+ if (deploymentUpdate.checksState === "registered" && !finishedEvents.has("checks-registered")) {
105
+ finishedEvents.add("checks-registered");
106
+ yield { type: "checks-registered", payload: deploymentUpdate };
107
+ }
108
+ if (deploymentUpdate.checksState === "running" && !finishedEvents.has("checks-running")) {
109
+ finishedEvents.add("checks-running");
110
+ yield { type: "checks-running", payload: deploymentUpdate };
111
+ }
112
+ }
113
+ if ((0, import_ready_state.isAliasAssigned)(deploymentUpdate)) {
114
+ debug("Deployment alias assigned");
115
+ return yield { type: "alias-assigned", payload: deploymentUpdate };
116
+ }
117
+ if ((0, import_ready_state.isAliasError)(deploymentUpdate)) {
118
+ return yield { type: "error", payload: deploymentUpdate.aliasError };
119
+ }
120
+ if (deploymentUpdate.readyState === "ERROR" && deploymentUpdate.errorCode === "BUILD_FAILED") {
121
+ return yield { type: "error", payload: deploymentUpdate };
122
+ }
123
+ if ((0, import_ready_state.isFailed)(deploymentUpdate)) {
124
+ return yield {
125
+ type: "error",
126
+ payload: deploymentUpdate.error || deploymentUpdate
127
+ };
112
128
  }
129
+ const elapsed = Date.now() - startTime;
130
+ const duration = (0, import_get_polling_delay.getPollingDelay)(elapsed);
131
+ await (0, import_sleep_promise.default)(duration);
132
+ }
113
133
  }
114
- exports.checkDeploymentStatus = checkDeploymentStatus;
134
+ // Annotate the CommonJS export names for ESM import in node:
135
+ 0 && (module.exports = {
136
+ checkDeploymentStatus
137
+ });
@@ -1,114 +1,135 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fs_extra_1 = require("fs-extra");
7
- const path_1 = require("path");
8
- const hashes_1 = require("./utils/hashes");
9
- const upload_1 = require("./upload");
10
- const utils_1 = require("./utils");
11
- const errors_1 = require("./errors");
12
- const build_utils_1 = require("@vercel/build-utils");
13
- const tar_fs_1 = __importDefault(require("tar-fs"));
14
- const zlib_1 = require("zlib");
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var create_deployment_exports = {};
30
+ __export(create_deployment_exports, {
31
+ default: () => buildCreateDeployment
32
+ });
33
+ module.exports = __toCommonJS(create_deployment_exports);
34
+ var import_fs_extra = require("fs-extra");
35
+ var import_path = require("path");
36
+ var import_hashes = require("./utils/hashes");
37
+ var import_upload = require("./upload");
38
+ var import_utils = require("./utils");
39
+ var import_errors = require("./errors");
40
+ var import_build_utils = require("@vercel/build-utils");
41
+ var import_tar_fs = __toESM(require("tar-fs"));
42
+ var import_zlib = require("zlib");
15
43
  function buildCreateDeployment() {
16
- return async function* createDeployment(clientOptions, deploymentOptions = {}) {
17
- const { path } = clientOptions;
18
- const debug = (0, utils_1.createDebug)(clientOptions.debug);
19
- debug('Creating deployment...');
20
- if (typeof path !== 'string' && !Array.isArray(path)) {
21
- debug(`Error: 'path' is expected to be a string or an array. Received ${typeof path}`);
22
- throw new errors_1.DeploymentError({
23
- code: 'missing_path',
24
- message: 'Path not provided',
25
- });
26
- }
27
- if (typeof clientOptions.token !== 'string') {
28
- debug(`Error: 'token' is expected to be a string. Received ${typeof clientOptions.token}`);
29
- throw new errors_1.DeploymentError({
30
- code: 'token_not_provided',
31
- message: 'Options object must include a `token`',
32
- });
33
- }
34
- clientOptions.isDirectory =
35
- !Array.isArray(path) && (0, fs_extra_1.lstatSync)(path).isDirectory();
36
- if (Array.isArray(path)) {
37
- for (const filePath of path) {
38
- if (!(0, path_1.isAbsolute)(filePath)) {
39
- throw new errors_1.DeploymentError({
40
- code: 'invalid_path',
41
- message: `Provided path ${filePath} is not absolute`,
42
- });
43
- }
44
- }
45
- }
46
- else if (!(0, path_1.isAbsolute)(path)) {
47
- throw new errors_1.DeploymentError({
48
- code: 'invalid_path',
49
- message: `Provided path ${path} is not absolute`,
50
- });
51
- }
52
- if (clientOptions.isDirectory && !Array.isArray(path)) {
53
- debug(`Provided 'path' is a directory.`);
54
- }
55
- else if (Array.isArray(path)) {
56
- debug(`Provided 'path' is an array of file paths`);
57
- }
58
- else {
59
- debug(`Provided 'path' is a single file`);
60
- }
61
- const { fileList } = await (0, utils_1.buildFileTree)(path, clientOptions, debug);
62
- // This is a useful warning because it prevents people
63
- // from getting confused about a deployment that renders 404.
64
- if (fileList.length === 0) {
65
- debug('Deployment path has no files. Yielding a warning event');
66
- yield {
67
- type: 'warning',
68
- payload: 'There are no files inside your deployment.',
69
- };
70
- }
71
- // Populate Files -> FileFsRef mapping
72
- const workPath = typeof path === 'string' ? path : path[0];
73
- let files;
74
- if (clientOptions.archive === 'tgz') {
75
- debug('Packing tarball');
76
- const tarStream = tar_fs_1.default
77
- .pack(workPath, {
78
- entries: fileList.map(file => (0, path_1.relative)(workPath, file)),
79
- })
80
- .pipe((0, zlib_1.createGzip)());
81
- const tarBuffer = await (0, build_utils_1.streamToBuffer)(tarStream);
82
- debug('Packed tarball');
83
- files = new Map([
84
- [
85
- (0, hashes_1.hash)(tarBuffer),
86
- {
87
- names: [(0, path_1.join)(workPath, '.vercel/source.tgz')],
88
- data: tarBuffer,
89
- mode: 0o666,
90
- },
91
- ],
92
- ]);
93
- }
94
- else {
95
- files = await (0, hashes_1.hashes)(fileList);
96
- }
97
- debug(`Yielding a 'hashes-calculated' event with ${files.size} hashes`);
98
- yield { type: 'hashes-calculated', payload: (0, hashes_1.mapToObject)(files) };
99
- if (clientOptions.apiUrl) {
100
- debug(`Using provided API URL: ${clientOptions.apiUrl}`);
101
- }
102
- if (clientOptions.userAgent) {
103
- debug(`Using provided user agent: ${clientOptions.userAgent}`);
104
- }
105
- debug(`Setting platform version to harcoded value 2`);
106
- deploymentOptions.version = 2;
107
- debug(`Creating the deployment and starting upload...`);
108
- for await (const event of (0, upload_1.upload)(files, clientOptions, deploymentOptions)) {
109
- debug(`Yielding a '${event.type}' event`);
110
- yield event;
44
+ return async function* createDeployment(clientOptions, deploymentOptions = {}) {
45
+ const { path } = clientOptions;
46
+ const debug = (0, import_utils.createDebug)(clientOptions.debug);
47
+ debug("Creating deployment...");
48
+ if (typeof path !== "string" && !Array.isArray(path)) {
49
+ debug(
50
+ `Error: 'path' is expected to be a string or an array. Received ${typeof path}`
51
+ );
52
+ throw new import_errors.DeploymentError({
53
+ code: "missing_path",
54
+ message: "Path not provided"
55
+ });
56
+ }
57
+ if (typeof clientOptions.token !== "string") {
58
+ debug(
59
+ `Error: 'token' is expected to be a string. Received ${typeof clientOptions.token}`
60
+ );
61
+ throw new import_errors.DeploymentError({
62
+ code: "token_not_provided",
63
+ message: "Options object must include a `token`"
64
+ });
65
+ }
66
+ clientOptions.isDirectory = !Array.isArray(path) && (0, import_fs_extra.lstatSync)(path).isDirectory();
67
+ if (Array.isArray(path)) {
68
+ for (const filePath of path) {
69
+ if (!(0, import_path.isAbsolute)(filePath)) {
70
+ throw new import_errors.DeploymentError({
71
+ code: "invalid_path",
72
+ message: `Provided path ${filePath} is not absolute`
73
+ });
111
74
  }
112
- };
75
+ }
76
+ } else if (!(0, import_path.isAbsolute)(path)) {
77
+ throw new import_errors.DeploymentError({
78
+ code: "invalid_path",
79
+ message: `Provided path ${path} is not absolute`
80
+ });
81
+ }
82
+ if (clientOptions.isDirectory && !Array.isArray(path)) {
83
+ debug(`Provided 'path' is a directory.`);
84
+ } else if (Array.isArray(path)) {
85
+ debug(`Provided 'path' is an array of file paths`);
86
+ } else {
87
+ debug(`Provided 'path' is a single file`);
88
+ }
89
+ const { fileList } = await (0, import_utils.buildFileTree)(path, clientOptions, debug);
90
+ if (fileList.length === 0) {
91
+ debug("Deployment path has no files. Yielding a warning event");
92
+ yield {
93
+ type: "warning",
94
+ payload: "There are no files inside your deployment."
95
+ };
96
+ }
97
+ const workPath = typeof path === "string" ? path : path[0];
98
+ let files;
99
+ if (clientOptions.archive === "tgz") {
100
+ debug("Packing tarball");
101
+ const tarStream = import_tar_fs.default.pack(workPath, {
102
+ entries: fileList.map((file) => (0, import_path.relative)(workPath, file))
103
+ }).pipe((0, import_zlib.createGzip)());
104
+ const tarBuffer = await (0, import_build_utils.streamToBuffer)(tarStream);
105
+ debug("Packed tarball");
106
+ files = /* @__PURE__ */ new Map([
107
+ [
108
+ (0, import_hashes.hash)(tarBuffer),
109
+ {
110
+ names: [(0, import_path.join)(workPath, ".vercel/source.tgz")],
111
+ data: tarBuffer,
112
+ mode: 438
113
+ }
114
+ ]
115
+ ]);
116
+ } else {
117
+ files = await (0, import_hashes.hashes)(fileList);
118
+ }
119
+ debug(`Yielding a 'hashes-calculated' event with ${files.size} hashes`);
120
+ yield { type: "hashes-calculated", payload: (0, import_hashes.mapToObject)(files) };
121
+ if (clientOptions.apiUrl) {
122
+ debug(`Using provided API URL: ${clientOptions.apiUrl}`);
123
+ }
124
+ if (clientOptions.userAgent) {
125
+ debug(`Using provided user agent: ${clientOptions.userAgent}`);
126
+ }
127
+ debug(`Setting platform version to harcoded value 2`);
128
+ deploymentOptions.version = 2;
129
+ debug(`Creating the deployment and starting upload...`);
130
+ for await (const event of (0, import_upload.upload)(files, clientOptions, deploymentOptions)) {
131
+ debug(`Yielding a '${event.type}' event`);
132
+ yield event;
133
+ }
134
+ };
113
135
  }
114
- exports.default = buildCreateDeployment;