@vercel/build-utils 7.0.0 → 7.1.1
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/CHANGELOG.md +14 -0
- package/build.mjs +3 -0
- package/dist/clone-env.js +39 -30
- package/dist/debug.js +28 -9
- package/dist/edge-function.js +36 -16
- package/dist/errors.js +83 -74
- package/dist/file-blob.js +63 -32
- package/dist/file-fs-ref.js +99 -65
- package/dist/file-ref.js +97 -77
- package/dist/fs/download.js +121 -91
- package/dist/fs/get-writable-directory.js +29 -9
- package/dist/fs/glob.js +104 -77
- package/dist/fs/node-version.js +115 -82
- package/dist/fs/normalize-path.js +28 -8
- package/dist/fs/read-config-file.js +66 -40
- package/dist/fs/rename.js +27 -14
- package/dist/fs/run-user-scripts.js +457 -419
- package/dist/fs/stream-to-buffer.js +51 -24
- package/dist/get-ignore-filter.js +80 -49
- package/dist/get-platform-env.js +41 -22
- package/dist/get-prefixed-env-vars.js +48 -32
- package/dist/hard-link-dir.js +90 -70
- package/dist/index.js +22266 -29399
- package/dist/lambda.d.ts +3 -0
- package/dist/lambda.js +208 -140
- package/dist/nodejs-lambda.js +40 -12
- package/dist/prerender.js +109 -64
- package/dist/schemas.js +83 -57
- package/dist/should-serve.js +43 -16
- package/dist/types.d.ts +4 -0
- package/dist/types.js +15 -1
- package/dist/validate-npmrc.js +38 -24
- package/package.json +4 -4
- package/build.js +0 -30
package/dist/file-ref.js
CHANGED
@@ -1,85 +1,105 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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 file_ref_exports = {};
|
30
|
+
__export(file_ref_exports, {
|
31
|
+
default: () => FileRef
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(file_ref_exports);
|
34
|
+
var import_assert = __toESM(require("assert"));
|
35
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
36
|
+
var import_multistream = __toESM(require("multistream"));
|
37
|
+
var import_async_retry = __toESM(require("async-retry"));
|
38
|
+
var import_async_sema = __toESM(require("async-sema"));
|
39
|
+
const semaToDownloadFromS3 = new import_async_sema.default(5);
|
12
40
|
class BailableError extends Error {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
41
|
+
constructor(...args) {
|
42
|
+
super(...args);
|
43
|
+
this.bail = false;
|
44
|
+
}
|
17
45
|
}
|
18
46
|
class FileRef {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
// change. We shouldn't cache it on CloudFront because it'd always be a
|
43
|
-
// MISS.
|
44
|
-
url = `https://now-ephemeral-files.s3.amazonaws.com/${digestHash}`;
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
throw new Error('Expected digest to be sha');
|
48
|
-
}
|
49
|
-
await semaToDownloadFromS3.acquire();
|
50
|
-
// console.time(`downloading ${url}`);
|
51
|
-
try {
|
52
|
-
return await (0, async_retry_1.default)(async () => {
|
53
|
-
const resp = await (0, node_fetch_1.default)(url);
|
54
|
-
if (!resp.ok) {
|
55
|
-
const error = new BailableError(`download: ${resp.status} ${resp.statusText} for ${url}`);
|
56
|
-
if (resp.status === 403)
|
57
|
-
error.bail = true;
|
58
|
-
throw error;
|
59
|
-
}
|
60
|
-
return resp.body;
|
61
|
-
}, { factor: 1, retries: 3 });
|
62
|
-
}
|
63
|
-
finally {
|
64
|
-
// console.timeEnd(`downloading ${url}`);
|
65
|
-
semaToDownloadFromS3.release();
|
66
|
-
}
|
47
|
+
constructor({
|
48
|
+
mode = 33188,
|
49
|
+
digest,
|
50
|
+
contentType,
|
51
|
+
mutable = false
|
52
|
+
}) {
|
53
|
+
(0, import_assert.default)(typeof mode === "number");
|
54
|
+
(0, import_assert.default)(typeof digest === "string");
|
55
|
+
this.type = "FileRef";
|
56
|
+
this.mode = mode;
|
57
|
+
this.digest = digest;
|
58
|
+
this.contentType = contentType;
|
59
|
+
this.mutable = mutable;
|
60
|
+
}
|
61
|
+
async toStreamAsync() {
|
62
|
+
let url = "";
|
63
|
+
const [digestType, digestHash] = this.digest.split(":");
|
64
|
+
if (digestType === "sha") {
|
65
|
+
url = this.mutable ? `https://now-files.s3.amazonaws.com/${digestHash}` : `https://dmmcy0pwk6bqi.cloudfront.net/${digestHash}`;
|
66
|
+
} else if (digestType === "sha+ephemeral") {
|
67
|
+
url = `https://now-ephemeral-files.s3.amazonaws.com/${digestHash}`;
|
68
|
+
} else {
|
69
|
+
throw new Error("Expected digest to be sha");
|
67
70
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
71
|
+
await semaToDownloadFromS3.acquire();
|
72
|
+
try {
|
73
|
+
return await (0, import_async_retry.default)(
|
74
|
+
async () => {
|
75
|
+
const resp = await (0, import_node_fetch.default)(url);
|
76
|
+
if (!resp.ok) {
|
77
|
+
const error = new BailableError(
|
78
|
+
`download: ${resp.status} ${resp.statusText} for ${url}`
|
79
|
+
);
|
80
|
+
if (resp.status === 403)
|
81
|
+
error.bail = true;
|
82
|
+
throw error;
|
83
|
+
}
|
84
|
+
return resp.body;
|
85
|
+
},
|
86
|
+
{ factor: 1, retries: 3 }
|
87
|
+
);
|
88
|
+
} finally {
|
89
|
+
semaToDownloadFromS3.release();
|
83
90
|
}
|
91
|
+
}
|
92
|
+
toStream() {
|
93
|
+
let flag = false;
|
94
|
+
return (0, import_multistream.default)((cb) => {
|
95
|
+
if (flag)
|
96
|
+
return cb(null, null);
|
97
|
+
flag = true;
|
98
|
+
this.toStreamAsync().then((stream) => {
|
99
|
+
cb(null, stream);
|
100
|
+
}).catch((error) => {
|
101
|
+
cb(error, null);
|
102
|
+
});
|
103
|
+
});
|
104
|
+
}
|
84
105
|
}
|
85
|
-
exports.default = FileRef;
|
package/dist/fs/download.js
CHANGED
@@ -1,106 +1,136 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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 download_exports = {};
|
30
|
+
__export(download_exports, {
|
31
|
+
default: () => download,
|
32
|
+
downloadFile: () => downloadFile,
|
33
|
+
isDirectory: () => isDirectory,
|
34
|
+
isSymbolicLink: () => isSymbolicLink
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(download_exports);
|
37
|
+
var import_path = __toESM(require("path"));
|
38
|
+
var import_debug = __toESM(require("../debug"));
|
39
|
+
var import_file_fs_ref = __toESM(require("../file-fs-ref"));
|
40
|
+
var import_fs_extra = require("fs-extra");
|
41
|
+
var import_stream_to_buffer = __toESM(require("./stream-to-buffer"));
|
42
|
+
const S_IFDIR = 16384;
|
43
|
+
const S_IFLNK = 40960;
|
44
|
+
const S_IFMT = 61440;
|
15
45
|
function isDirectory(mode) {
|
16
|
-
|
46
|
+
return (mode & S_IFMT) === S_IFDIR;
|
17
47
|
}
|
18
|
-
exports.isDirectory = isDirectory;
|
19
48
|
function isSymbolicLink(mode) {
|
20
|
-
|
49
|
+
return (mode & S_IFMT) === S_IFLNK;
|
21
50
|
}
|
22
|
-
exports.isSymbolicLink = isSymbolicLink;
|
23
51
|
async function prepareSymlinkTarget(file, fsPath) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
52
|
+
const mkdirPromise = (0, import_fs_extra.mkdirp)(import_path.default.dirname(fsPath));
|
53
|
+
if (file.type === "FileFsRef") {
|
54
|
+
const [target] = await Promise.all([(0, import_fs_extra.readlink)(file.fsPath), mkdirPromise]);
|
55
|
+
return target;
|
56
|
+
}
|
57
|
+
if (file.type === "FileRef" || file.type === "FileBlob") {
|
58
|
+
const targetPathBufferPromise = (0, import_stream_to_buffer.default)(await file.toStreamAsync());
|
59
|
+
const [targetPathBuffer] = await Promise.all([
|
60
|
+
targetPathBufferPromise,
|
61
|
+
mkdirPromise
|
62
|
+
]);
|
63
|
+
return targetPathBuffer.toString("utf8");
|
64
|
+
}
|
65
|
+
throw new Error(
|
66
|
+
`file.type "${file.type}" not supported for symlink`
|
67
|
+
);
|
38
68
|
}
|
39
69
|
async function downloadFile(file, fsPath) {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
const stream = file.toStream();
|
55
|
-
return file_fs_ref_1.default.fromStream({ mode, stream, fsPath });
|
70
|
+
const { mode } = file;
|
71
|
+
if (isDirectory(mode)) {
|
72
|
+
await (0, import_fs_extra.mkdirp)(fsPath);
|
73
|
+
await (0, import_fs_extra.chmod)(fsPath, mode);
|
74
|
+
return import_file_fs_ref.default.fromFsPath({ mode, fsPath });
|
75
|
+
}
|
76
|
+
if (isSymbolicLink(mode)) {
|
77
|
+
const target = await prepareSymlinkTarget(file, fsPath);
|
78
|
+
await (0, import_fs_extra.symlink)(target, fsPath);
|
79
|
+
return import_file_fs_ref.default.fromFsPath({ mode, fsPath });
|
80
|
+
}
|
81
|
+
const stream = file.toStream();
|
82
|
+
return import_file_fs_ref.default.fromStream({ mode, stream, fsPath });
|
56
83
|
}
|
57
|
-
exports.downloadFile = downloadFile;
|
58
84
|
async function removeFile(basePath, fileMatched) {
|
59
|
-
|
60
|
-
|
85
|
+
const file = import_path.default.join(basePath, fileMatched);
|
86
|
+
await (0, import_fs_extra.remove)(file);
|
61
87
|
}
|
62
88
|
async function download(files, basePath, meta) {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
console.warn(`Warning: file "${name}" is within a symlinked directory "${dir}" and will be ignored`);
|
95
|
-
return;
|
96
|
-
}
|
89
|
+
const {
|
90
|
+
isDev = false,
|
91
|
+
skipDownload = false,
|
92
|
+
filesChanged = null,
|
93
|
+
filesRemoved = null
|
94
|
+
} = meta || {};
|
95
|
+
if (isDev || skipDownload) {
|
96
|
+
return files;
|
97
|
+
}
|
98
|
+
(0, import_debug.default)("Downloading deployment source files...");
|
99
|
+
const start = Date.now();
|
100
|
+
const files2 = {};
|
101
|
+
const filenames = Object.keys(files);
|
102
|
+
await Promise.all(
|
103
|
+
filenames.map(async (name) => {
|
104
|
+
if (Array.isArray(filesRemoved) && filesRemoved.includes(name)) {
|
105
|
+
await removeFile(basePath, name);
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
if (Array.isArray(filesChanged) && !filesChanged.includes(name)) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
const parts = name.split("/");
|
112
|
+
for (let i = 1; i < parts.length; i++) {
|
113
|
+
const dir = parts.slice(0, i).join("/");
|
114
|
+
const parent = files[dir];
|
115
|
+
if (parent && isSymbolicLink(parent.mode)) {
|
116
|
+
console.warn(
|
117
|
+
`Warning: file "${name}" is within a symlinked directory "${dir}" and will be ignored`
|
118
|
+
);
|
119
|
+
return;
|
97
120
|
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
121
|
+
}
|
122
|
+
const file = files[name];
|
123
|
+
const fsPath = import_path.default.join(basePath, name);
|
124
|
+
files2[name] = await downloadFile(file, fsPath);
|
125
|
+
})
|
126
|
+
);
|
127
|
+
const duration = Date.now() - start;
|
128
|
+
(0, import_debug.default)(`Downloaded ${filenames.length} source files: ${duration}ms`);
|
129
|
+
return files2;
|
105
130
|
}
|
106
|
-
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
132
|
+
0 && (module.exports = {
|
133
|
+
downloadFile,
|
134
|
+
isDirectory,
|
135
|
+
isSymbolicLink
|
136
|
+
});
|
@@ -1,12 +1,32 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
|
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 get_writable_directory_exports = {};
|
20
|
+
__export(get_writable_directory_exports, {
|
21
|
+
default: () => getWritableDirectory
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(get_writable_directory_exports);
|
24
|
+
var import_path = require("path");
|
25
|
+
var import_os = require("os");
|
26
|
+
var import_fs_extra = require("fs-extra");
|
6
27
|
async function getWritableDirectory() {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
28
|
+
const name = Math.floor(Math.random() * 2147483647).toString(16);
|
29
|
+
const directory = (0, import_path.join)((0, import_os.tmpdir)(), name);
|
30
|
+
await (0, import_fs_extra.mkdirp)(directory);
|
31
|
+
return directory;
|
11
32
|
}
|
12
|
-
exports.default = getWritableDirectory;
|
package/dist/fs/glob.js
CHANGED
@@ -1,84 +1,111 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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 glob_exports = {};
|
30
|
+
__export(glob_exports, {
|
31
|
+
default: () => glob
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(glob_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_assert = __toESM(require("assert"));
|
36
|
+
var import_glob = __toESM(require("glob"));
|
37
|
+
var import_util = require("util");
|
38
|
+
var import_fs_extra = require("fs-extra");
|
39
|
+
var import_normalize_path = require("./normalize-path");
|
40
|
+
var import_file_fs_ref = __toESM(require("../file-fs-ref"));
|
41
|
+
const vanillaGlob = (0, import_util.promisify)(import_glob.default);
|
14
42
|
async function glob(pattern, opts, mountpoint) {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
43
|
+
const options = typeof opts === "string" ? { cwd: opts } : opts;
|
44
|
+
if (!options.cwd) {
|
45
|
+
throw new Error(
|
46
|
+
"Second argument (basePath) must be specified for names of resulting files"
|
47
|
+
);
|
48
|
+
}
|
49
|
+
if (!import_path.default.isAbsolute(options.cwd)) {
|
50
|
+
throw new Error(`basePath/cwd must be an absolute path (${options.cwd})`);
|
51
|
+
}
|
52
|
+
const results = {};
|
53
|
+
const statCache = {};
|
54
|
+
const symlinks = {};
|
55
|
+
const files = await vanillaGlob(pattern, {
|
56
|
+
...options,
|
57
|
+
symlinks,
|
58
|
+
statCache,
|
59
|
+
stat: true,
|
60
|
+
dot: true
|
61
|
+
});
|
62
|
+
const dirs = /* @__PURE__ */ new Set();
|
63
|
+
const dirsWithEntries = /* @__PURE__ */ new Set();
|
64
|
+
for (const relativePath of files) {
|
65
|
+
const absPath = import_path.default.join(options.cwd, relativePath);
|
66
|
+
const fsPath = (0, import_normalize_path.normalizePath)(absPath);
|
67
|
+
let stat = statCache[fsPath];
|
68
|
+
(0, import_assert.default)(
|
69
|
+
stat,
|
70
|
+
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
71
|
+
);
|
72
|
+
const isSymlink = symlinks[fsPath];
|
73
|
+
if (options.follow && (isSymlink || (await (0, import_fs_extra.lstat)(fsPath)).isSymbolicLink())) {
|
74
|
+
const target = await (0, import_fs_extra.readlink)(absPath);
|
75
|
+
const absTarget = import_path.default.resolve(import_path.default.dirname(absPath), target);
|
76
|
+
if (import_path.default.relative(options.cwd, absTarget).startsWith(`..${import_path.default.sep}`)) {
|
77
|
+
continue;
|
78
|
+
}
|
21
79
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
let stat = statCache[fsPath];
|
38
|
-
(0, assert_1.default)(stat, `statCache does not contain value for ${relativePath} (resolved to ${fsPath})`);
|
39
|
-
const isSymlink = symlinks[fsPath];
|
40
|
-
// When `follow` mode is enabled, ensure that the entry is not a symlink
|
41
|
-
// that points to outside of `cwd`
|
42
|
-
if (options.follow &&
|
43
|
-
(isSymlink || (await (0, fs_extra_1.lstat)(fsPath)).isSymbolicLink())) {
|
44
|
-
const target = await (0, fs_extra_1.readlink)(absPath);
|
45
|
-
const absTarget = path_1.default.resolve(path_1.default.dirname(absPath), target);
|
46
|
-
if (path_1.default.relative(options.cwd, absTarget).startsWith(`..${path_1.default.sep}`)) {
|
47
|
-
continue;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
if (isSymlink || stat.isFile() || stat.isDirectory()) {
|
51
|
-
if (isSymlink) {
|
52
|
-
stat = await (0, fs_extra_1.lstat)(absPath);
|
53
|
-
}
|
54
|
-
// Some bookkeeping to track which directories already have entries within
|
55
|
-
const dirname = path_1.default.dirname(relativePath);
|
56
|
-
dirsWithEntries.add(dirname);
|
57
|
-
if (stat.isDirectory()) {
|
58
|
-
dirs.add(relativePath);
|
59
|
-
continue;
|
60
|
-
}
|
61
|
-
let finalPath = relativePath;
|
62
|
-
if (mountpoint) {
|
63
|
-
finalPath = path_1.default.join(mountpoint, finalPath);
|
64
|
-
}
|
65
|
-
results[finalPath] = new file_fs_ref_1.default({ mode: stat.mode, fsPath });
|
66
|
-
}
|
80
|
+
if (isSymlink || stat.isFile() || stat.isDirectory()) {
|
81
|
+
if (isSymlink) {
|
82
|
+
stat = await (0, import_fs_extra.lstat)(absPath);
|
83
|
+
}
|
84
|
+
const dirname = import_path.default.dirname(relativePath);
|
85
|
+
dirsWithEntries.add(dirname);
|
86
|
+
if (stat.isDirectory()) {
|
87
|
+
dirs.add(relativePath);
|
88
|
+
continue;
|
89
|
+
}
|
90
|
+
let finalPath = relativePath;
|
91
|
+
if (mountpoint) {
|
92
|
+
finalPath = import_path.default.join(mountpoint, finalPath);
|
93
|
+
}
|
94
|
+
results[finalPath] = new import_file_fs_ref.default({ mode: stat.mode, fsPath });
|
67
95
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
96
|
+
}
|
97
|
+
if (options.includeDirectories) {
|
98
|
+
for (const relativePath of dirs) {
|
99
|
+
if (dirsWithEntries.has(relativePath))
|
100
|
+
continue;
|
101
|
+
let finalPath = relativePath;
|
102
|
+
if (mountpoint) {
|
103
|
+
finalPath = import_path.default.join(mountpoint, finalPath);
|
104
|
+
}
|
105
|
+
const fsPath = (0, import_normalize_path.normalizePath)(import_path.default.join(options.cwd, relativePath));
|
106
|
+
const stat = statCache[fsPath];
|
107
|
+
results[finalPath] = new import_file_fs_ref.default({ mode: stat.mode, fsPath });
|
81
108
|
}
|
82
|
-
|
109
|
+
}
|
110
|
+
return results;
|
83
111
|
}
|
84
|
-
exports.default = glob;
|