@vercel/build-utils 5.7.0 → 5.7.2
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/fs/download.d.ts +1 -0
- package/dist/fs/download.js +13 -4
- package/dist/fs/glob.js +32 -14
- package/dist/index.js +45 -18
- package/package.json +2 -2
package/dist/fs/download.d.ts
CHANGED
@@ -4,5 +4,6 @@ export interface DownloadedFiles {
|
|
4
4
|
[filePath: string]: FileFsRef;
|
5
5
|
}
|
6
6
|
export declare function isSymbolicLink(mode: number): boolean;
|
7
|
+
export declare function isDirectory(mode: number): boolean;
|
7
8
|
export declare function downloadFile(file: File, fsPath: string): Promise<FileFsRef>;
|
8
9
|
export default function download(files: Files, basePath: string, meta?: Meta): Promise<DownloadedFiles>;
|
package/dist/fs/download.js
CHANGED
@@ -3,18 +3,23 @@ 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.downloadFile = exports.isSymbolicLink = void 0;
|
6
|
+
exports.downloadFile = exports.isDirectory = exports.isSymbolicLink = void 0;
|
7
7
|
const path_1 = __importDefault(require("path"));
|
8
8
|
const debug_1 = __importDefault(require("../debug"));
|
9
9
|
const file_fs_ref_1 = __importDefault(require("../file-fs-ref"));
|
10
10
|
const fs_extra_1 = require("fs-extra");
|
11
11
|
const stream_to_buffer_1 = __importDefault(require("./stream-to-buffer"));
|
12
|
-
const
|
13
|
-
const S_IFLNK = 40960; /* 0120000 symbolic link */
|
12
|
+
const STAT = new fs_extra_1.Stats();
|
14
13
|
function isSymbolicLink(mode) {
|
15
|
-
|
14
|
+
STAT.mode = mode;
|
15
|
+
return STAT.isSymbolicLink();
|
16
16
|
}
|
17
17
|
exports.isSymbolicLink = isSymbolicLink;
|
18
|
+
function isDirectory(mode) {
|
19
|
+
STAT.mode = mode;
|
20
|
+
return STAT.isDirectory();
|
21
|
+
}
|
22
|
+
exports.isDirectory = isDirectory;
|
18
23
|
async function prepareSymlinkTarget(file, fsPath) {
|
19
24
|
const mkdirPromise = fs_extra_1.mkdirp(path_1.default.dirname(fsPath));
|
20
25
|
if (file.type === 'FileFsRef') {
|
@@ -33,6 +38,10 @@ async function prepareSymlinkTarget(file, fsPath) {
|
|
33
38
|
}
|
34
39
|
async function downloadFile(file, fsPath) {
|
35
40
|
const { mode } = file;
|
41
|
+
if (isDirectory(mode)) {
|
42
|
+
await fs_extra_1.mkdirp(fsPath);
|
43
|
+
return file_fs_ref_1.default.fromFsPath({ mode, fsPath });
|
44
|
+
}
|
36
45
|
// If the source is a symlink, try to create it instead of copying the file.
|
37
46
|
// Note: creating symlinks on Windows requires admin priviliges or symlinks
|
38
47
|
// enabled in the group policy. We may want to improve the error message.
|
package/dist/fs/glob.js
CHANGED
@@ -12,13 +12,7 @@ const normalize_path_1 = require("./normalize-path");
|
|
12
12
|
const file_fs_ref_1 = __importDefault(require("../file-fs-ref"));
|
13
13
|
const vanillaGlob = util_1.promisify(glob_1.default);
|
14
14
|
async function glob(pattern, opts, mountpoint) {
|
15
|
-
|
16
|
-
if (typeof opts === 'string') {
|
17
|
-
options = { cwd: opts };
|
18
|
-
}
|
19
|
-
else {
|
20
|
-
options = opts;
|
21
|
-
}
|
15
|
+
const options = typeof opts === 'string' ? { cwd: opts } : opts;
|
22
16
|
if (!options.cwd) {
|
23
17
|
throw new Error('Second argument (basePath) must be specified for names of resulting files');
|
24
18
|
}
|
@@ -27,20 +21,32 @@ async function glob(pattern, opts, mountpoint) {
|
|
27
21
|
}
|
28
22
|
const results = {};
|
29
23
|
const statCache = {};
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
const symlinks = {};
|
25
|
+
const files = await vanillaGlob(pattern, {
|
26
|
+
...options,
|
27
|
+
symlinks,
|
28
|
+
statCache,
|
29
|
+
stat: true,
|
30
|
+
dot: true,
|
31
|
+
});
|
32
|
+
const dirs = new Set();
|
33
|
+
const dirsWithEntries = new Set();
|
35
34
|
for (const relativePath of files) {
|
36
35
|
const fsPath = normalize_path_1.normalizePath(path_1.default.join(options.cwd, relativePath));
|
37
36
|
let stat = statCache[fsPath];
|
38
37
|
assert_1.default(stat, `statCache does not contain value for ${relativePath} (resolved to ${fsPath})`);
|
39
|
-
const isSymlink =
|
40
|
-
if (isSymlink || stat.isFile()) {
|
38
|
+
const isSymlink = symlinks[fsPath];
|
39
|
+
if (isSymlink || stat.isFile() || stat.isDirectory()) {
|
41
40
|
if (isSymlink) {
|
42
41
|
stat = await fs_extra_1.lstat(fsPath);
|
43
42
|
}
|
43
|
+
// Some bookkeeping to track which directories already have entries within
|
44
|
+
const dirname = path_1.default.dirname(relativePath);
|
45
|
+
dirsWithEntries.add(dirname);
|
46
|
+
if (stat.isDirectory()) {
|
47
|
+
dirs.add(relativePath);
|
48
|
+
continue;
|
49
|
+
}
|
44
50
|
let finalPath = relativePath;
|
45
51
|
if (mountpoint) {
|
46
52
|
finalPath = path_1.default.join(mountpoint, finalPath);
|
@@ -48,6 +54,18 @@ async function glob(pattern, opts, mountpoint) {
|
|
48
54
|
results[finalPath] = new file_fs_ref_1.default({ mode: stat.mode, fsPath });
|
49
55
|
}
|
50
56
|
}
|
57
|
+
// Add empty directory entries
|
58
|
+
for (const relativePath of dirs) {
|
59
|
+
if (dirsWithEntries.has(relativePath))
|
60
|
+
continue;
|
61
|
+
let finalPath = relativePath;
|
62
|
+
if (mountpoint) {
|
63
|
+
finalPath = path_1.default.join(mountpoint, finalPath);
|
64
|
+
}
|
65
|
+
const fsPath = normalize_path_1.normalizePath(path_1.default.join(options.cwd, relativePath));
|
66
|
+
const stat = statCache[fsPath];
|
67
|
+
results[finalPath] = new file_fs_ref_1.default({ mode: stat.mode, fsPath });
|
68
|
+
}
|
51
69
|
return results;
|
52
70
|
}
|
53
71
|
exports.default = glob;
|
package/dist/index.js
CHANGED
@@ -30517,18 +30517,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30517
30517
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
30518
30518
|
};
|
30519
30519
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
30520
|
-
exports.downloadFile = exports.isSymbolicLink = void 0;
|
30520
|
+
exports.downloadFile = exports.isDirectory = exports.isSymbolicLink = void 0;
|
30521
30521
|
const path_1 = __importDefault(__webpack_require__(5622));
|
30522
30522
|
const debug_1 = __importDefault(__webpack_require__(1868));
|
30523
30523
|
const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
|
30524
30524
|
const fs_extra_1 = __webpack_require__(5392);
|
30525
30525
|
const stream_to_buffer_1 = __importDefault(__webpack_require__(2560));
|
30526
|
-
const
|
30527
|
-
const S_IFLNK = 40960; /* 0120000 symbolic link */
|
30526
|
+
const STAT = new fs_extra_1.Stats();
|
30528
30527
|
function isSymbolicLink(mode) {
|
30529
|
-
|
30528
|
+
STAT.mode = mode;
|
30529
|
+
return STAT.isSymbolicLink();
|
30530
30530
|
}
|
30531
30531
|
exports.isSymbolicLink = isSymbolicLink;
|
30532
|
+
function isDirectory(mode) {
|
30533
|
+
STAT.mode = mode;
|
30534
|
+
return STAT.isDirectory();
|
30535
|
+
}
|
30536
|
+
exports.isDirectory = isDirectory;
|
30532
30537
|
async function prepareSymlinkTarget(file, fsPath) {
|
30533
30538
|
const mkdirPromise = fs_extra_1.mkdirp(path_1.default.dirname(fsPath));
|
30534
30539
|
if (file.type === 'FileFsRef') {
|
@@ -30547,6 +30552,10 @@ async function prepareSymlinkTarget(file, fsPath) {
|
|
30547
30552
|
}
|
30548
30553
|
async function downloadFile(file, fsPath) {
|
30549
30554
|
const { mode } = file;
|
30555
|
+
if (isDirectory(mode)) {
|
30556
|
+
await fs_extra_1.mkdirp(fsPath);
|
30557
|
+
return file_fs_ref_1.default.fromFsPath({ mode, fsPath });
|
30558
|
+
}
|
30550
30559
|
// If the source is a symlink, try to create it instead of copying the file.
|
30551
30560
|
// Note: creating symlinks on Windows requires admin priviliges or symlinks
|
30552
30561
|
// enabled in the group policy. We may want to improve the error message.
|
@@ -30650,13 +30659,7 @@ const normalize_path_1 = __webpack_require__(6261);
|
|
30650
30659
|
const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
|
30651
30660
|
const vanillaGlob = util_1.promisify(glob_1.default);
|
30652
30661
|
async function glob(pattern, opts, mountpoint) {
|
30653
|
-
|
30654
|
-
if (typeof opts === 'string') {
|
30655
|
-
options = { cwd: opts };
|
30656
|
-
}
|
30657
|
-
else {
|
30658
|
-
options = opts;
|
30659
|
-
}
|
30662
|
+
const options = typeof opts === 'string' ? { cwd: opts } : opts;
|
30660
30663
|
if (!options.cwd) {
|
30661
30664
|
throw new Error('Second argument (basePath) must be specified for names of resulting files');
|
30662
30665
|
}
|
@@ -30665,20 +30668,32 @@ async function glob(pattern, opts, mountpoint) {
|
|
30665
30668
|
}
|
30666
30669
|
const results = {};
|
30667
30670
|
const statCache = {};
|
30668
|
-
|
30669
|
-
|
30670
|
-
|
30671
|
-
|
30672
|
-
|
30671
|
+
const symlinks = {};
|
30672
|
+
const files = await vanillaGlob(pattern, {
|
30673
|
+
...options,
|
30674
|
+
symlinks,
|
30675
|
+
statCache,
|
30676
|
+
stat: true,
|
30677
|
+
dot: true,
|
30678
|
+
});
|
30679
|
+
const dirs = new Set();
|
30680
|
+
const dirsWithEntries = new Set();
|
30673
30681
|
for (const relativePath of files) {
|
30674
30682
|
const fsPath = normalize_path_1.normalizePath(path_1.default.join(options.cwd, relativePath));
|
30675
30683
|
let stat = statCache[fsPath];
|
30676
30684
|
assert_1.default(stat, `statCache does not contain value for ${relativePath} (resolved to ${fsPath})`);
|
30677
|
-
const isSymlink =
|
30678
|
-
if (isSymlink || stat.isFile()) {
|
30685
|
+
const isSymlink = symlinks[fsPath];
|
30686
|
+
if (isSymlink || stat.isFile() || stat.isDirectory()) {
|
30679
30687
|
if (isSymlink) {
|
30680
30688
|
stat = await fs_extra_1.lstat(fsPath);
|
30681
30689
|
}
|
30690
|
+
// Some bookkeeping to track which directories already have entries within
|
30691
|
+
const dirname = path_1.default.dirname(relativePath);
|
30692
|
+
dirsWithEntries.add(dirname);
|
30693
|
+
if (stat.isDirectory()) {
|
30694
|
+
dirs.add(relativePath);
|
30695
|
+
continue;
|
30696
|
+
}
|
30682
30697
|
let finalPath = relativePath;
|
30683
30698
|
if (mountpoint) {
|
30684
30699
|
finalPath = path_1.default.join(mountpoint, finalPath);
|
@@ -30686,6 +30701,18 @@ async function glob(pattern, opts, mountpoint) {
|
|
30686
30701
|
results[finalPath] = new file_fs_ref_1.default({ mode: stat.mode, fsPath });
|
30687
30702
|
}
|
30688
30703
|
}
|
30704
|
+
// Add empty directory entries
|
30705
|
+
for (const relativePath of dirs) {
|
30706
|
+
if (dirsWithEntries.has(relativePath))
|
30707
|
+
continue;
|
30708
|
+
let finalPath = relativePath;
|
30709
|
+
if (mountpoint) {
|
30710
|
+
finalPath = path_1.default.join(mountpoint, finalPath);
|
30711
|
+
}
|
30712
|
+
const fsPath = normalize_path_1.normalizePath(path_1.default.join(options.cwd, relativePath));
|
30713
|
+
const stat = statCache[fsPath];
|
30714
|
+
results[finalPath] = new file_fs_ref_1.default({ mode: stat.mode, fsPath });
|
30715
|
+
}
|
30689
30716
|
return results;
|
30690
30717
|
}
|
30691
30718
|
exports.default = glob;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/build-utils",
|
3
|
-
"version": "5.7.
|
3
|
+
"version": "5.7.2",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.js",
|
@@ -47,5 +47,5 @@
|
|
47
47
|
"typescript": "4.3.4",
|
48
48
|
"yazl": "2.5.1"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "cb29bfdd684893cace5454f50a11a777407a9e45"
|
51
51
|
}
|