@vercel/build-utils 7.1.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 +8 -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 -29403
- package/dist/lambda.js +208 -144
- 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 +3 -3
- package/build.js +0 -30
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# @vercel/build-utils
|
2
2
|
|
3
|
+
## 7.1.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- add descriptions to NodeVersion properties ([#10403](https://github.com/vercel/vercel/pull/10403))
|
8
|
+
|
9
|
+
- Updated semver dependency ([#10411](https://github.com/vercel/vercel/pull/10411))
|
10
|
+
|
3
11
|
## 7.1.0
|
4
12
|
|
5
13
|
### Minor Changes
|
package/build.mjs
ADDED
package/dist/clone-env.js
CHANGED
@@ -1,34 +1,43 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
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 clone_env_exports = {};
|
20
|
+
__export(clone_env_exports, {
|
21
|
+
cloneEnv: () => cloneEnv
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(clone_env_exports);
|
4
24
|
const { hasOwnProperty } = Object.prototype;
|
5
|
-
/**
|
6
|
-
* Clones zero or more objects into a single new object while ensuring that the
|
7
|
-
* `PATH` environment variable is defined when the `PATH` or `Path` environment
|
8
|
-
* variables are defined.
|
9
|
-
*
|
10
|
-
* @param {Object} [...envs] Objects and/or `process.env` to clone and merge
|
11
|
-
* @returns {Object} The new object
|
12
|
-
*/
|
13
25
|
function cloneEnv(...envs) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
obj.PATH = obj.Path;
|
28
|
-
}
|
29
|
-
delete obj.Path;
|
30
|
-
}
|
31
|
-
return obj;
|
32
|
-
}, {});
|
26
|
+
return envs.reduce((obj, env) => {
|
27
|
+
if (env === void 0 || env === null) {
|
28
|
+
return obj;
|
29
|
+
}
|
30
|
+
obj = Object.assign(obj, env);
|
31
|
+
if (hasOwnProperty.call(env, "Path")) {
|
32
|
+
if (obj.Path !== void 0) {
|
33
|
+
obj.PATH = obj.Path;
|
34
|
+
}
|
35
|
+
delete obj.Path;
|
36
|
+
}
|
37
|
+
return obj;
|
38
|
+
}, {});
|
33
39
|
}
|
34
|
-
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
41
|
+
0 && (module.exports = {
|
42
|
+
cloneEnv
|
43
|
+
});
|
package/dist/debug.js
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
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 debug_exports = {};
|
20
|
+
__export(debug_exports, {
|
21
|
+
default: () => debug
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(debug_exports);
|
24
|
+
var import_get_platform_env = require("./get-platform-env");
|
4
25
|
function debug(message, ...additional) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
26
|
+
if ((0, import_get_platform_env.getPlatformEnv)("BUILDER_DEBUG")) {
|
27
|
+
console.log(message, ...additional);
|
28
|
+
} else if (process.env.VERCEL_DEBUG_PREFIX) {
|
29
|
+
console.log(`${process.env.VERCEL_DEBUG_PREFIX}${message}`, ...additional);
|
30
|
+
}
|
11
31
|
}
|
12
|
-
exports.default = debug;
|
package/dist/edge-function.js
CHANGED
@@ -1,19 +1,39 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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 edge_function_exports = {};
|
20
|
+
__export(edge_function_exports, {
|
21
|
+
EdgeFunction: () => EdgeFunction
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(edge_function_exports);
|
7
24
|
class EdgeFunction {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
25
|
+
constructor(params) {
|
26
|
+
this.type = "EdgeFunction";
|
27
|
+
this.name = params.name;
|
28
|
+
this.deploymentTarget = params.deploymentTarget;
|
29
|
+
this.entrypoint = params.entrypoint;
|
30
|
+
this.files = params.files;
|
31
|
+
this.assets = params.assets;
|
32
|
+
this.regions = params.regions;
|
33
|
+
this.framework = params.framework;
|
34
|
+
}
|
18
35
|
}
|
19
|
-
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
37
|
+
0 && (module.exports = {
|
38
|
+
EdgeFunction
|
39
|
+
});
|
package/dist/errors.js
CHANGED
@@ -1,86 +1,95 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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 errors_exports = {};
|
20
|
+
__export(errors_exports, {
|
21
|
+
NowBuildError: () => NowBuildError,
|
22
|
+
getPrettyError: () => getPrettyError
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(errors_exports);
|
9
25
|
class NowBuildError extends Error {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
constructor({ message, code, link, action }) {
|
27
|
+
super(message);
|
28
|
+
this.hideStackTrace = true;
|
29
|
+
this.code = code;
|
30
|
+
this.link = link;
|
31
|
+
this.action = action;
|
32
|
+
}
|
17
33
|
}
|
18
|
-
exports.NowBuildError = NowBuildError;
|
19
34
|
function getPrettyError(obj) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else {
|
33
|
-
message += `${ajvMessage}.`;
|
34
|
-
}
|
35
|
-
return new NowBuildError({
|
36
|
-
code: 'INVALID_VERCEL_CONFIG',
|
37
|
-
message: message,
|
38
|
-
link: prop ? `${docsUrl}#${prop.toLowerCase()}` : docsUrl,
|
39
|
-
action: 'View Documentation',
|
40
|
-
});
|
41
|
-
}
|
42
|
-
catch (e) {
|
43
|
-
return new NowBuildError({
|
44
|
-
code: 'INVALID_VERCEL_CONFIG',
|
45
|
-
message: `Failed to validate configuration.`,
|
46
|
-
link: docsUrl,
|
47
|
-
action: 'View Documentation',
|
48
|
-
});
|
35
|
+
const docsUrl = "https://vercel.com/docs/concepts/projects/project-configuration";
|
36
|
+
try {
|
37
|
+
const { dataPath, params, message: ajvMessage } = obj;
|
38
|
+
const prop = getTopLevelPropertyName(dataPath);
|
39
|
+
let message = dataPath && dataPath.startsWith(".") ? `\`${dataPath.slice(1)}\` ` : "";
|
40
|
+
if (params && typeof params.additionalProperty === "string") {
|
41
|
+
const suggestion = getSuggestion(prop, params.additionalProperty);
|
42
|
+
message += `should NOT have additional property \`${params.additionalProperty}\`. ${suggestion}`;
|
43
|
+
} else if (params && typeof params.missingProperty === "string") {
|
44
|
+
message += `missing required property \`${params.missingProperty}\`.`;
|
45
|
+
} else {
|
46
|
+
message += `${ajvMessage}.`;
|
49
47
|
}
|
48
|
+
return new NowBuildError({
|
49
|
+
code: "INVALID_VERCEL_CONFIG",
|
50
|
+
message,
|
51
|
+
link: prop ? `${docsUrl}#${prop.toLowerCase()}` : docsUrl,
|
52
|
+
action: "View Documentation"
|
53
|
+
});
|
54
|
+
} catch (e) {
|
55
|
+
return new NowBuildError({
|
56
|
+
code: "INVALID_VERCEL_CONFIG",
|
57
|
+
message: `Failed to validate configuration.`,
|
58
|
+
link: docsUrl,
|
59
|
+
action: "View Documentation"
|
60
|
+
});
|
61
|
+
}
|
50
62
|
}
|
51
|
-
exports.getPrettyError = getPrettyError;
|
52
|
-
/**
|
53
|
-
* Get the top level property from the dataPath.
|
54
|
-
* `.cleanUrls` => `cleanUrls`
|
55
|
-
* `.headers[0].source` => `headers`
|
56
|
-
* `.headers[0].headers[0]` => `headers`
|
57
|
-
* `` => ``
|
58
|
-
*/
|
59
63
|
function getTopLevelPropertyName(dataPath) {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
if (dataPath && dataPath.startsWith(".")) {
|
65
|
+
const lastIndex = dataPath.indexOf("[");
|
66
|
+
return lastIndex > -1 ? dataPath.slice(1, lastIndex) : dataPath.slice(1);
|
67
|
+
}
|
68
|
+
return "";
|
65
69
|
}
|
66
70
|
const mapTypoToSuggestion = {
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
71
|
+
"": {
|
72
|
+
builder: "builds",
|
73
|
+
"build.env": '{ "build": { "env": {"name": "value"} } }',
|
74
|
+
"builds.env": '{ "build": { "env": {"name": "value"} } }'
|
75
|
+
},
|
76
|
+
rewrites: { src: "source", dest: "destination" },
|
77
|
+
redirects: { src: "source", dest: "destination", status: "statusCode" },
|
78
|
+
headers: { src: "source", header: "headers" },
|
79
|
+
routes: {
|
80
|
+
source: "src",
|
81
|
+
destination: "dest",
|
82
|
+
header: "headers",
|
83
|
+
method: "methods"
|
84
|
+
}
|
81
85
|
};
|
82
86
|
function getSuggestion(topLevelProp, additionalProperty) {
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
const choices = mapTypoToSuggestion[topLevelProp];
|
88
|
+
const choice = choices ? choices[additionalProperty] : void 0;
|
89
|
+
return choice ? `Did you mean \`${choice}\`?` : "Please remove it.";
|
86
90
|
}
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
92
|
+
0 && (module.exports = {
|
93
|
+
NowBuildError,
|
94
|
+
getPrettyError
|
95
|
+
});
|
package/dist/file-blob.js
CHANGED
@@ -1,36 +1,67 @@
|
|
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
|
-
|
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_blob_exports = {};
|
30
|
+
__export(file_blob_exports, {
|
31
|
+
default: () => FileBlob
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(file_blob_exports);
|
34
|
+
var import_assert = __toESM(require("assert"));
|
35
|
+
var import_into_stream = __toESM(require("into-stream"));
|
8
36
|
class FileBlob {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
constructor({ mode = 33188, contentType, data }) {
|
38
|
+
(0, import_assert.default)(typeof mode === "number");
|
39
|
+
(0, import_assert.default)(typeof data === "string" || Buffer.isBuffer(data));
|
40
|
+
this.type = "FileBlob";
|
41
|
+
this.mode = mode;
|
42
|
+
this.contentType = contentType;
|
43
|
+
this.data = data;
|
44
|
+
}
|
45
|
+
static async fromStream({
|
46
|
+
mode = 33188,
|
47
|
+
contentType,
|
48
|
+
stream
|
49
|
+
}) {
|
50
|
+
(0, import_assert.default)(typeof mode === "number");
|
51
|
+
(0, import_assert.default)(typeof stream.pipe === "function");
|
52
|
+
const chunks = [];
|
53
|
+
await new Promise((resolve, reject) => {
|
54
|
+
stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
55
|
+
stream.on("error", (error) => reject(error));
|
56
|
+
stream.on("end", () => resolve());
|
57
|
+
});
|
58
|
+
const data = Buffer.concat(chunks);
|
59
|
+
return new FileBlob({ mode, contentType, data });
|
60
|
+
}
|
61
|
+
async toStreamAsync() {
|
62
|
+
return this.toStream();
|
63
|
+
}
|
64
|
+
toStream() {
|
65
|
+
return (0, import_into_stream.default)(this.data);
|
66
|
+
}
|
35
67
|
}
|
36
|
-
exports.default = FileBlob;
|
package/dist/file-fs-ref.js
CHANGED
@@ -1,70 +1,104 @@
|
|
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_fs_ref_exports = {};
|
30
|
+
__export(file_fs_ref_exports, {
|
31
|
+
default: () => file_fs_ref_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(file_fs_ref_exports);
|
34
|
+
var import_assert = __toESM(require("assert"));
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
36
|
+
var import_multistream = __toESM(require("multistream"));
|
37
|
+
var import_path = __toESM(require("path"));
|
38
|
+
var import_async_sema = __toESM(require("async-sema"));
|
39
|
+
const semaToPreventEMFILE = new import_async_sema.default(20);
|
12
40
|
class FileFsRef {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
(0, assert_1.default)(typeof mode === 'number');
|
31
|
-
(0, assert_1.default)(typeof stream.pipe === 'function'); // is-stream
|
32
|
-
(0, assert_1.default)(typeof fsPath === 'string');
|
33
|
-
await fs_extra_1.default.mkdirp(path_1.default.dirname(fsPath));
|
34
|
-
await new Promise((resolve, reject) => {
|
35
|
-
const dest = fs_extra_1.default.createWriteStream(fsPath, {
|
36
|
-
mode: mode & 0o777,
|
37
|
-
});
|
38
|
-
stream.pipe(dest);
|
39
|
-
stream.on('error', reject);
|
40
|
-
dest.on('finish', resolve);
|
41
|
-
dest.on('error', reject);
|
42
|
-
});
|
43
|
-
return new FileFsRef({ mode, contentType, fsPath });
|
44
|
-
}
|
45
|
-
async toStreamAsync() {
|
46
|
-
await semaToPreventEMFILE.acquire();
|
47
|
-
const release = () => semaToPreventEMFILE.release();
|
48
|
-
const stream = fs_extra_1.default.createReadStream(this.fsPath);
|
49
|
-
stream.on('close', release);
|
50
|
-
stream.on('error', release);
|
51
|
-
return stream;
|
52
|
-
}
|
53
|
-
toStream() {
|
54
|
-
let flag = false;
|
55
|
-
// eslint-disable-next-line consistent-return
|
56
|
-
return (0, multistream_1.default)(cb => {
|
57
|
-
if (flag)
|
58
|
-
return cb(null, null);
|
59
|
-
flag = true;
|
60
|
-
this.toStreamAsync()
|
61
|
-
.then(stream => {
|
62
|
-
cb(null, stream);
|
63
|
-
})
|
64
|
-
.catch(error => {
|
65
|
-
cb(error, null);
|
66
|
-
});
|
67
|
-
});
|
41
|
+
constructor({ mode = 33188, contentType, fsPath }) {
|
42
|
+
(0, import_assert.default)(typeof mode === "number");
|
43
|
+
(0, import_assert.default)(typeof fsPath === "string");
|
44
|
+
this.type = "FileFsRef";
|
45
|
+
this.mode = mode;
|
46
|
+
this.contentType = contentType;
|
47
|
+
this.fsPath = fsPath;
|
48
|
+
}
|
49
|
+
static async fromFsPath({
|
50
|
+
mode,
|
51
|
+
contentType,
|
52
|
+
fsPath
|
53
|
+
}) {
|
54
|
+
let m = mode;
|
55
|
+
if (!m) {
|
56
|
+
const stat = await import_fs_extra.default.lstat(fsPath);
|
57
|
+
m = stat.mode;
|
68
58
|
}
|
59
|
+
return new FileFsRef({ mode: m, contentType, fsPath });
|
60
|
+
}
|
61
|
+
static async fromStream({
|
62
|
+
mode = 33188,
|
63
|
+
contentType,
|
64
|
+
stream,
|
65
|
+
fsPath
|
66
|
+
}) {
|
67
|
+
(0, import_assert.default)(typeof mode === "number");
|
68
|
+
(0, import_assert.default)(typeof stream.pipe === "function");
|
69
|
+
(0, import_assert.default)(typeof fsPath === "string");
|
70
|
+
await import_fs_extra.default.mkdirp(import_path.default.dirname(fsPath));
|
71
|
+
await new Promise((resolve, reject) => {
|
72
|
+
const dest = import_fs_extra.default.createWriteStream(fsPath, {
|
73
|
+
mode: mode & 511
|
74
|
+
});
|
75
|
+
stream.pipe(dest);
|
76
|
+
stream.on("error", reject);
|
77
|
+
dest.on("finish", resolve);
|
78
|
+
dest.on("error", reject);
|
79
|
+
});
|
80
|
+
return new FileFsRef({ mode, contentType, fsPath });
|
81
|
+
}
|
82
|
+
async toStreamAsync() {
|
83
|
+
await semaToPreventEMFILE.acquire();
|
84
|
+
const release = () => semaToPreventEMFILE.release();
|
85
|
+
const stream = import_fs_extra.default.createReadStream(this.fsPath);
|
86
|
+
stream.on("close", release);
|
87
|
+
stream.on("error", release);
|
88
|
+
return stream;
|
89
|
+
}
|
90
|
+
toStream() {
|
91
|
+
let flag = false;
|
92
|
+
return (0, import_multistream.default)((cb) => {
|
93
|
+
if (flag)
|
94
|
+
return cb(null, null);
|
95
|
+
flag = true;
|
96
|
+
this.toStreamAsync().then((stream) => {
|
97
|
+
cb(null, stream);
|
98
|
+
}).catch((error) => {
|
99
|
+
cb(error, null);
|
100
|
+
});
|
101
|
+
});
|
102
|
+
}
|
69
103
|
}
|
70
|
-
|
104
|
+
var file_fs_ref_default = FileFsRef;
|