@vercel/client 10.2.3-canary.41 → 10.2.3-canary.45

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,5 +1,5 @@
1
- import { NowConfig, VercelClientOptions, DeploymentOptions, DeploymentEventType } from './types';
2
- export default function buildCreateDeployment(): (clientOptions: VercelClientOptions, deploymentOptions?: DeploymentOptions, nowConfig?: NowConfig) => AsyncIterableIterator<{
1
+ import { VercelConfig, VercelClientOptions, DeploymentOptions, DeploymentEventType } from './types';
2
+ export default function buildCreateDeployment(): (clientOptions: VercelClientOptions, deploymentOptions?: DeploymentOptions, nowConfig?: VercelConfig) => AsyncIterableIterator<{
3
3
  type: DeploymentEventType;
4
4
  payload: any;
5
5
  }>;
@@ -1,27 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  const fs_extra_1 = require("fs-extra");
23
4
  const path_1 = require("path");
24
- const hashes_1 = __importStar(require("./utils/hashes"));
5
+ const hashes_1 = require("./utils/hashes");
25
6
  const upload_1 = require("./upload");
26
7
  const utils_1 = require("./utils");
27
8
  const errors_1 = require("./errors");
@@ -72,7 +53,7 @@ function buildCreateDeployment() {
72
53
  else {
73
54
  debug(`Provided 'path' is a single file`);
74
55
  }
75
- let { fileList } = await utils_1.buildFileTree(path, clientOptions.isDirectory, debug, clientOptions.prebuilt);
56
+ let { fileList } = await utils_1.buildFileTree(path, clientOptions, debug);
76
57
  let configPath;
77
58
  if (!nowConfig) {
78
59
  // If the user did not provide a config file, use the one in the root directory.
@@ -102,7 +83,11 @@ function buildCreateDeployment() {
102
83
  payload: 'There are no files inside your deployment.',
103
84
  };
104
85
  }
105
- const files = await hashes_1.default(fileList);
86
+ const hashedFileMap = await hashes_1.hashes(fileList);
87
+ const nftFileList = clientOptions.prebuilt
88
+ ? await hashes_1.resolveNftJsonFiles(hashedFileMap)
89
+ : [];
90
+ const files = await hashes_1.hashes(nftFileList, hashedFileMap);
106
91
  debug(`Yielding a 'hashes-calculated' event with ${files.size} hashes`);
107
92
  yield { type: 'hashes-calculated', payload: hashes_1.mapToObject(files) };
108
93
  if (clientOptions.apiUrl) {
package/dist/types.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface VercelClientOptions {
12
12
  apiUrl?: string;
13
13
  force?: boolean;
14
14
  prebuilt?: boolean;
15
+ rootDirectory?: string;
15
16
  withCache?: boolean;
16
17
  userAgent?: string;
17
18
  defaultName?: string;
@@ -15,8 +15,9 @@ export declare const mapToObject: (map: Map<string, DeploymentFile>) => {
15
15
  /**
16
16
  * Computes hashes for the contents of each file given.
17
17
  *
18
- * @param {Array} of {String} full paths
19
- * @return {Map}
18
+ * @param files - absolute file paths
19
+ * @param map - optional map of files to append
20
+ * @return Map of hash digest to file object
20
21
  */
21
- declare function hashes(files: string[]): Promise<Map<string, DeploymentFile>>;
22
- export default hashes;
22
+ export declare function hashes(files: string[], map?: Map<string, DeploymentFile>): Promise<Map<string, DeploymentFile>>;
23
+ export declare function resolveNftJsonFiles(hashedFiles: Map<string, DeploymentFile>): Promise<string[]>;
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mapToObject = void 0;
6
+ exports.resolveNftJsonFiles = exports.hashes = exports.mapToObject = void 0;
7
7
  const crypto_1 = require("crypto");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const async_sema_1 = require("async-sema");
10
+ const path_1 = require("path");
10
11
  /**
11
12
  * Computes a hash for the given buf.
12
13
  *
@@ -14,9 +15,7 @@ const async_sema_1 = require("async-sema");
14
15
  * @return {String} hex digest
15
16
  */
16
17
  function hash(buf) {
17
- return crypto_1.createHash('sha1')
18
- .update(buf)
19
- .digest('hex');
18
+ return crypto_1.createHash('sha1').update(buf).digest('hex');
20
19
  }
21
20
  /**
22
21
  * Transforms map to object
@@ -34,11 +33,11 @@ exports.mapToObject = mapToObject;
34
33
  /**
35
34
  * Computes hashes for the contents of each file given.
36
35
  *
37
- * @param {Array} of {String} full paths
38
- * @return {Map}
36
+ * @param files - absolute file paths
37
+ * @param map - optional map of files to append
38
+ * @return Map of hash digest to file object
39
39
  */
40
- async function hashes(files) {
41
- const map = new Map();
40
+ async function hashes(files, map = new Map()) {
42
41
  const semaphore = new async_sema_1.Sema(100);
43
42
  await Promise.all(files.map(async (name) => {
44
43
  await semaphore.acquire();
@@ -47,7 +46,9 @@ async function hashes(files) {
47
46
  const h = hash(data);
48
47
  const entry = map.get(h);
49
48
  if (entry) {
50
- entry.names.push(name);
49
+ if (entry.names[0] !== name) {
50
+ entry.names.push(name);
51
+ }
51
52
  }
52
53
  else {
53
54
  map.set(h, { names: [name], data, mode });
@@ -56,4 +57,29 @@ async function hashes(files) {
56
57
  }));
57
58
  return map;
58
59
  }
59
- exports.default = hashes;
60
+ exports.hashes = hashes;
61
+ async function resolveNftJsonFiles(hashedFiles) {
62
+ const semaphore = new async_sema_1.Sema(100);
63
+ const existingFiles = Array.from(hashedFiles.values());
64
+ const resolvedFiles = new Set();
65
+ await Promise.all(existingFiles.map(async (file) => {
66
+ await semaphore.acquire();
67
+ const fsPath = file.names[0];
68
+ if (fsPath.endsWith('.nft.json')) {
69
+ const json = file.data.toString('utf8');
70
+ const { version, files } = JSON.parse(json);
71
+ if (version === 1 || version === 2) {
72
+ for (let f of files) {
73
+ const relPath = typeof f === 'string' ? f : f.input;
74
+ resolvedFiles.add(path_1.join(path_1.dirname(fsPath), relPath));
75
+ }
76
+ }
77
+ else {
78
+ console.error(`Invalid nft.json version: ${version}`);
79
+ }
80
+ }
81
+ semaphore.release();
82
+ }));
83
+ return Array.from(resolvedFiles);
84
+ }
85
+ exports.resolveNftJsonFiles = resolveNftJsonFiles;
@@ -9,11 +9,11 @@ export declare type DeploymentEventType = typeof EVENTS_ARRAY[number];
9
9
  export declare const EVENTS: Set<"warning" | "error" | "hashes-calculated" | "file-count" | "file-uploaded" | "all-files-uploaded" | "created" | "building" | "ready" | "alias-assigned" | "notice" | "tip" | "canceled" | "checks-registered" | "checks-completed" | "checks-running" | "checks-conclusion-succeeded" | "checks-conclusion-failed" | "checks-conclusion-skipped" | "checks-conclusion-canceled">;
10
10
  export declare function getApiDeploymentsUrl(metadata?: Pick<DeploymentOptions, 'builds' | 'functions'>): "/v10/now/deployments" | "/v13/now/deployments";
11
11
  export declare function parseVercelConfig(filePath?: string): Promise<NowConfig>;
12
- export declare function buildFileTree(path: string | string[], isDirectory: boolean, debug: Debug, prebuilt?: boolean): Promise<{
12
+ export declare function buildFileTree(path: string | string[], { isDirectory, prebuilt, rootDirectory, }: Pick<VercelClientOptions, 'isDirectory' | 'prebuilt' | 'rootDirectory'>, debug: Debug): Promise<{
13
13
  fileList: string[];
14
14
  ignoreList: string[];
15
15
  }>;
16
- export declare function getVercelIgnore(cwd: string | string[], prebuilt?: boolean): Promise<{
16
+ export declare function getVercelIgnore(cwd: string | string[], prebuilt?: boolean, rootDirectory?: string): Promise<{
17
17
  ig: Ignore;
18
18
  ignores: string[];
19
19
  }>;
@@ -71,10 +71,10 @@ const maybeRead = async function (path, default_) {
71
71
  return default_;
72
72
  }
73
73
  };
74
- async function buildFileTree(path, isDirectory, debug, prebuilt) {
74
+ async function buildFileTree(path, { isDirectory, prebuilt, rootDirectory, }, debug) {
75
75
  const ignoreList = [];
76
76
  let fileList;
77
- let { ig, ignores } = await getVercelIgnore(path, prebuilt);
77
+ let { ig, ignores } = await getVercelIgnore(path, prebuilt, rootDirectory);
78
78
  debug(`Found ${ignores.length} rules in .vercelignore`);
79
79
  debug('Building file tree...');
80
80
  if (isDirectory && !Array.isArray(path)) {
@@ -103,10 +103,20 @@ async function buildFileTree(path, isDirectory, debug, prebuilt) {
103
103
  return { fileList, ignoreList };
104
104
  }
105
105
  exports.buildFileTree = buildFileTree;
106
- async function getVercelIgnore(cwd, prebuilt) {
107
- const ignores = prebuilt
108
- ? ['*', '!.output', '!.output/**']
109
- : [
106
+ async function getVercelIgnore(cwd, prebuilt, rootDirectory) {
107
+ let ignores = [];
108
+ const outputDir = path_1.posix.join(rootDirectory || '', '.output');
109
+ if (prebuilt) {
110
+ ignores.push('*');
111
+ const parts = outputDir.split('/');
112
+ parts.forEach((_, i) => {
113
+ const level = parts.slice(0, i + 1).join('/');
114
+ ignores.push(`!${level}`);
115
+ });
116
+ ignores.push(`!${outputDir}/**`);
117
+ }
118
+ else {
119
+ ignores = [
110
120
  '.hg',
111
121
  '.git',
112
122
  '.gitmodules',
@@ -131,8 +141,9 @@ async function getVercelIgnore(cwd, prebuilt) {
131
141
  '__pycache__',
132
142
  'venv',
133
143
  'CVS',
134
- '.output',
144
+ `.output`,
135
145
  ];
146
+ }
136
147
  const cwds = Array.isArray(cwd) ? cwd : [cwd];
137
148
  const files = await Promise.all(cwds.map(async (cwd) => {
138
149
  const [vercelignore, nowignore] = await Promise.all([
@@ -192,9 +203,8 @@ const fetch = async (url, token, opts = {}, debugEnabled, useNodeFetch) => {
192
203
  exports.fetch = fetch;
193
204
  const isWin = process.platform.includes('win');
194
205
  const prepareFiles = (files, clientOptions) => {
195
- const preparedFiles = [...files.keys()].reduce((acc, sha) => {
196
- const next = [...acc];
197
- const file = files.get(sha);
206
+ const preparedFiles = [];
207
+ for (const [sha, file] of files) {
198
208
  for (const name of file.names) {
199
209
  let fileName;
200
210
  if (clientOptions.isDirectory) {
@@ -209,15 +219,14 @@ const prepareFiles = (files, clientOptions) => {
209
219
  const segments = name.split(path_1.sep);
210
220
  fileName = segments[segments.length - 1];
211
221
  }
212
- next.push({
222
+ preparedFiles.push({
213
223
  file: isWin ? fileName.replace(/\\/g, '/') : fileName,
214
224
  size: file.data.byteLength || file.data.length,
215
225
  mode: file.mode,
216
226
  sha,
217
227
  });
218
228
  }
219
- return next;
220
- }, []);
229
+ }
221
230
  return preparedFiles;
222
231
  };
223
232
  exports.prepareFiles = prepareFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/client",
3
- "version": "10.2.3-canary.41",
3
+ "version": "10.2.3-canary.45",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "homepage": "https://vercel.com",
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@vercel/build-utils": "2.12.3-canary.40",
43
+ "@vercel/build-utils": "2.12.3-canary.42",
44
44
  "@zeit/fetch": "5.2.0",
45
45
  "async-retry": "1.2.3",
46
46
  "async-sema": "3.0.0",
@@ -52,5 +52,5 @@
52
52
  "recursive-readdir": "2.2.2",
53
53
  "sleep-promise": "8.0.1"
54
54
  },
55
- "gitHead": "d31ebbabe4d9533d0e98137d76eb319b01ac8b13"
55
+ "gitHead": "d3ef240f6e01fff3d11d0499c9aaf892968748e3"
56
56
  }