@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 CHANGED
@@ -1,5 +1,19 @@
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
+
11
+ ## 7.1.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Support serverless function architecture ([#10392](https://github.com/vercel/vercel/pull/10392))
16
+
3
17
  ## 7.0.0
4
18
 
5
19
  ### Major Changes
package/build.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { tsc, esbuild } from '../../utils/build.mjs';
2
+
3
+ await Promise.all([tsc(), esbuild().then(() => esbuild({ bundle: true }))]);
package/dist/clone-env.js CHANGED
@@ -1,34 +1,43 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cloneEnv = void 0;
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
- return envs.reduce((obj, env) => {
15
- if (env === undefined || env === null) {
16
- return obj;
17
- }
18
- // mixin the env first
19
- obj = Object.assign(obj, env);
20
- if (hasOwnProperty.call(env, 'Path')) {
21
- // the system path is called `Path` on Windows and Node.js will
22
- // automatically return the system path when accessing `PATH`,
23
- // however we lose this proxied value when we destructure and
24
- // thus we must explicitly copy it, but we must also remove the
25
- // `Path` property since we can't have both a `PATH` and `Path`
26
- if (obj.Path !== undefined) {
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
- exports.cloneEnv = cloneEnv;
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(exports, "__esModule", { value: true });
3
- const get_platform_env_1 = require("./get-platform-env");
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
- if ((0, get_platform_env_1.getPlatformEnv)('BUILDER_DEBUG')) {
6
- console.log(message, ...additional);
7
- }
8
- else if (process.env.VERCEL_DEBUG_PREFIX) {
9
- console.log(`${process.env.VERCEL_DEBUG_PREFIX}${message}`, ...additional);
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;
@@ -1,19 +1,39 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EdgeFunction = void 0;
4
- /**
5
- * An Edge Functions output
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
- constructor(params) {
9
- this.type = 'EdgeFunction';
10
- this.name = params.name;
11
- this.deploymentTarget = params.deploymentTarget;
12
- this.entrypoint = params.entrypoint;
13
- this.files = params.files;
14
- this.assets = params.assets;
15
- this.regions = params.regions;
16
- this.framework = params.framework;
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
- exports.EdgeFunction = EdgeFunction;
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(exports, "__esModule", { value: true });
3
- exports.getPrettyError = exports.NowBuildError = void 0;
4
- /**
5
- * This error should be thrown from a Builder in
6
- * order to stop the build and print a message.
7
- * This is necessary to avoid printing a stack trace.
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
- constructor({ message, code, link, action }) {
11
- super(message);
12
- this.hideStackTrace = true;
13
- this.code = code;
14
- this.link = link;
15
- this.action = action;
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
- const docsUrl = 'https://vercel.com/docs/concepts/projects/project-configuration';
21
- try {
22
- const { dataPath, params, message: ajvMessage } = obj;
23
- const prop = getTopLevelPropertyName(dataPath);
24
- let message = dataPath && dataPath.startsWith('.') ? `\`${dataPath.slice(1)}\` ` : '';
25
- if (params && typeof params.additionalProperty === 'string') {
26
- const suggestion = getSuggestion(prop, params.additionalProperty);
27
- message += `should NOT have additional property \`${params.additionalProperty}\`. ${suggestion}`;
28
- }
29
- else if (params && typeof params.missingProperty === 'string') {
30
- message += `missing required property \`${params.missingProperty}\`.`;
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
- if (dataPath && dataPath.startsWith('.')) {
61
- const lastIndex = dataPath.indexOf('[');
62
- return lastIndex > -1 ? dataPath.slice(1, lastIndex) : dataPath.slice(1);
63
- }
64
- return '';
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
- builder: 'builds',
69
- 'build.env': '{ "build": { "env": {"name": "value"} } }',
70
- 'builds.env': '{ "build": { "env": {"name": "value"} } }',
71
- },
72
- rewrites: { src: 'source', dest: 'destination' },
73
- redirects: { src: 'source', dest: 'destination', status: 'statusCode' },
74
- headers: { src: 'source', header: 'headers' },
75
- routes: {
76
- source: 'src',
77
- destination: 'dest',
78
- header: 'headers',
79
- method: 'methods',
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
- const choices = mapTypoToSuggestion[topLevelProp];
84
- const choice = choices ? choices[additionalProperty] : undefined;
85
- return choice ? `Did you mean \`${choice}\`?` : 'Please remove it.';
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 __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 assert_1 = __importDefault(require("assert"));
7
- const into_stream_1 = __importDefault(require("into-stream"));
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
- constructor({ mode = 0o100644, contentType, data }) {
10
- (0, assert_1.default)(typeof mode === 'number');
11
- (0, assert_1.default)(typeof data === 'string' || Buffer.isBuffer(data));
12
- this.type = 'FileBlob';
13
- this.mode = mode;
14
- this.contentType = contentType;
15
- this.data = data;
16
- }
17
- static async fromStream({ mode = 0o100644, contentType, stream, }) {
18
- (0, assert_1.default)(typeof mode === 'number');
19
- (0, assert_1.default)(typeof stream.pipe === 'function'); // is-stream
20
- const chunks = [];
21
- await new Promise((resolve, reject) => {
22
- stream.on('data', chunk => chunks.push(Buffer.from(chunk)));
23
- stream.on('error', error => reject(error));
24
- stream.on('end', () => resolve());
25
- });
26
- const data = Buffer.concat(chunks);
27
- return new FileBlob({ mode, contentType, data });
28
- }
29
- async toStreamAsync() {
30
- return this.toStream();
31
- }
32
- toStream() {
33
- return (0, into_stream_1.default)(this.data);
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;
@@ -1,70 +1,104 @@
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 assert_1 = __importDefault(require("assert"));
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const multistream_1 = __importDefault(require("multistream"));
9
- const path_1 = __importDefault(require("path"));
10
- const async_sema_1 = __importDefault(require("async-sema"));
11
- const semaToPreventEMFILE = new async_sema_1.default(20);
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
- constructor({ mode = 0o100644, contentType, fsPath }) {
14
- (0, assert_1.default)(typeof mode === 'number');
15
- (0, assert_1.default)(typeof fsPath === 'string');
16
- this.type = 'FileFsRef';
17
- this.mode = mode;
18
- this.contentType = contentType;
19
- this.fsPath = fsPath;
20
- }
21
- static async fromFsPath({ mode, contentType, fsPath, }) {
22
- let m = mode;
23
- if (!m) {
24
- const stat = await fs_extra_1.default.lstat(fsPath);
25
- m = stat.mode;
26
- }
27
- return new FileFsRef({ mode: m, contentType, fsPath });
28
- }
29
- static async fromStream({ mode = 0o100644, contentType, stream, fsPath, }) {
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
- exports.default = FileFsRef;
104
+ var file_fs_ref_default = FileFsRef;