@vercel/build-utils 8.5.0 → 8.6.0
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 +6 -0
- package/dist/file-ref.d.ts +19 -0
- package/dist/file-ref.js +44 -2
- package/dist/index.js +65 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# @vercel/build-utils
|
2
2
|
|
3
|
+
## 8.6.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- Add support for `NOW_EPHEMERAL_FILES_S3_URL`, `NOW_FILES_CLOUDFRONT_URL` and `NOW_FILES_S3_URL` environment variables ([#12643](https://github.com/vercel/vercel/pull/12643))
|
8
|
+
|
3
9
|
## 8.5.0
|
4
10
|
|
5
11
|
### Minor Changes
|
package/dist/file-ref.d.ts
CHANGED
@@ -13,6 +13,25 @@ export default class FileRef implements FileBase {
|
|
13
13
|
contentType: string | undefined;
|
14
14
|
private mutable;
|
15
15
|
constructor({ mode, digest, contentType, mutable, }: FileRefOptions);
|
16
|
+
/**
|
17
|
+
* Retrieves the URL of the CloudFront distribution for the S3
|
18
|
+
* bucket represented by {@link getNowFilesS3Url}.
|
19
|
+
*
|
20
|
+
* @returns The URL of the CloudFront distribution
|
21
|
+
*/
|
22
|
+
private getNowFilesCloudfrontUrl;
|
23
|
+
/**
|
24
|
+
* Retrieves the URL of the S3 bucket for storing ephemeral files.
|
25
|
+
*
|
26
|
+
* @returns The URL of the S3 bucket
|
27
|
+
*/
|
28
|
+
private getNowEphemeralFilesS3Url;
|
29
|
+
/**
|
30
|
+
* Retrieves the URL of the S3 bucket for storing files.
|
31
|
+
*
|
32
|
+
* @returns The URL of the S3 bucket
|
33
|
+
*/
|
34
|
+
private getNowFilesS3Url;
|
16
35
|
toStreamAsync(): Promise<NodeJS.ReadableStream>;
|
17
36
|
toStream(): NodeJS.ReadableStream;
|
18
37
|
}
|
package/dist/file-ref.js
CHANGED
@@ -58,13 +58,38 @@ class FileRef {
|
|
58
58
|
this.contentType = contentType;
|
59
59
|
this.mutable = mutable;
|
60
60
|
}
|
61
|
+
/**
|
62
|
+
* Retrieves the URL of the CloudFront distribution for the S3
|
63
|
+
* bucket represented by {@link getNowFilesS3Url}.
|
64
|
+
*
|
65
|
+
* @returns The URL of the CloudFront distribution
|
66
|
+
*/
|
67
|
+
getNowFilesCloudfrontUrl() {
|
68
|
+
return getEnvAsUrlOrThrow("NOW_FILES_CLOUDFRONT_URL") || "https://dmmcy0pwk6bqi.cloudfront.net";
|
69
|
+
}
|
70
|
+
/**
|
71
|
+
* Retrieves the URL of the S3 bucket for storing ephemeral files.
|
72
|
+
*
|
73
|
+
* @returns The URL of the S3 bucket
|
74
|
+
*/
|
75
|
+
getNowEphemeralFilesS3Url() {
|
76
|
+
return getEnvAsUrlOrThrow("NOW_EPHEMERAL_FILES_S3_URL") || "https://now-ephemeral-files.s3.amazonaws.com";
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* Retrieves the URL of the S3 bucket for storing files.
|
80
|
+
*
|
81
|
+
* @returns The URL of the S3 bucket
|
82
|
+
*/
|
83
|
+
getNowFilesS3Url() {
|
84
|
+
return getEnvAsUrlOrThrow("NOW_FILES_S3_URL") || "https://now-files.s3.amazonaws.com";
|
85
|
+
}
|
61
86
|
async toStreamAsync() {
|
62
87
|
let url = "";
|
63
88
|
const [digestType, digestHash] = this.digest.split(":");
|
64
89
|
if (digestType === "sha") {
|
65
|
-
url = this.mutable ?
|
90
|
+
url = this.mutable ? `${this.getNowFilesS3Url()}/${digestHash}` : `${this.getNowFilesCloudfrontUrl()}/${digestHash}`;
|
66
91
|
} else if (digestType === "sha+ephemeral") {
|
67
|
-
url =
|
92
|
+
url = `${this.getNowEphemeralFilesS3Url()}/${digestHash}`;
|
68
93
|
} else {
|
69
94
|
throw new Error("Expected digest to be sha");
|
70
95
|
}
|
@@ -103,3 +128,20 @@ class FileRef {
|
|
103
128
|
});
|
104
129
|
}
|
105
130
|
}
|
131
|
+
function getEnvAsUrlOrThrow(key) {
|
132
|
+
const value = process.env[key];
|
133
|
+
if (value === void 0)
|
134
|
+
return void 0;
|
135
|
+
try {
|
136
|
+
new URL(value);
|
137
|
+
return value;
|
138
|
+
} catch (e) {
|
139
|
+
if (e instanceof TypeError && "code" in e && e.code === "ERR_INVALID_URL") {
|
140
|
+
throw new Error(
|
141
|
+
`A non-URL value was supplied to the ${key} environment variable`
|
142
|
+
);
|
143
|
+
} else {
|
144
|
+
throw e;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
package/dist/index.js
CHANGED
@@ -8619,8 +8619,8 @@ var require_URL = __commonJS({
|
|
8619
8619
|
var utils = require_utils3();
|
8620
8620
|
var Impl = require_URL_impl();
|
8621
8621
|
var impl = utils.implSymbol;
|
8622
|
-
function
|
8623
|
-
if (!this || this[impl] || !(this instanceof
|
8622
|
+
function URL2(url) {
|
8623
|
+
if (!this || this[impl] || !(this instanceof URL2)) {
|
8624
8624
|
throw new TypeError("Failed to construct 'URL': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
|
8625
8625
|
}
|
8626
8626
|
if (arguments.length < 1) {
|
@@ -8636,7 +8636,7 @@ var require_URL = __commonJS({
|
|
8636
8636
|
}
|
8637
8637
|
module2.exports.setup(this, args);
|
8638
8638
|
}
|
8639
|
-
|
8639
|
+
URL2.prototype.toJSON = function toJSON() {
|
8640
8640
|
if (!this || !module2.exports.is(this)) {
|
8641
8641
|
throw new TypeError("Illegal invocation");
|
8642
8642
|
}
|
@@ -8646,7 +8646,7 @@ var require_URL = __commonJS({
|
|
8646
8646
|
}
|
8647
8647
|
return this[impl].toJSON.apply(this[impl], args);
|
8648
8648
|
};
|
8649
|
-
Object.defineProperty(
|
8649
|
+
Object.defineProperty(URL2.prototype, "href", {
|
8650
8650
|
get() {
|
8651
8651
|
return this[impl].href;
|
8652
8652
|
},
|
@@ -8657,20 +8657,20 @@ var require_URL = __commonJS({
|
|
8657
8657
|
enumerable: true,
|
8658
8658
|
configurable: true
|
8659
8659
|
});
|
8660
|
-
|
8660
|
+
URL2.prototype.toString = function() {
|
8661
8661
|
if (!this || !module2.exports.is(this)) {
|
8662
8662
|
throw new TypeError("Illegal invocation");
|
8663
8663
|
}
|
8664
8664
|
return this.href;
|
8665
8665
|
};
|
8666
|
-
Object.defineProperty(
|
8666
|
+
Object.defineProperty(URL2.prototype, "origin", {
|
8667
8667
|
get() {
|
8668
8668
|
return this[impl].origin;
|
8669
8669
|
},
|
8670
8670
|
enumerable: true,
|
8671
8671
|
configurable: true
|
8672
8672
|
});
|
8673
|
-
Object.defineProperty(
|
8673
|
+
Object.defineProperty(URL2.prototype, "protocol", {
|
8674
8674
|
get() {
|
8675
8675
|
return this[impl].protocol;
|
8676
8676
|
},
|
@@ -8681,7 +8681,7 @@ var require_URL = __commonJS({
|
|
8681
8681
|
enumerable: true,
|
8682
8682
|
configurable: true
|
8683
8683
|
});
|
8684
|
-
Object.defineProperty(
|
8684
|
+
Object.defineProperty(URL2.prototype, "username", {
|
8685
8685
|
get() {
|
8686
8686
|
return this[impl].username;
|
8687
8687
|
},
|
@@ -8692,7 +8692,7 @@ var require_URL = __commonJS({
|
|
8692
8692
|
enumerable: true,
|
8693
8693
|
configurable: true
|
8694
8694
|
});
|
8695
|
-
Object.defineProperty(
|
8695
|
+
Object.defineProperty(URL2.prototype, "password", {
|
8696
8696
|
get() {
|
8697
8697
|
return this[impl].password;
|
8698
8698
|
},
|
@@ -8703,7 +8703,7 @@ var require_URL = __commonJS({
|
|
8703
8703
|
enumerable: true,
|
8704
8704
|
configurable: true
|
8705
8705
|
});
|
8706
|
-
Object.defineProperty(
|
8706
|
+
Object.defineProperty(URL2.prototype, "host", {
|
8707
8707
|
get() {
|
8708
8708
|
return this[impl].host;
|
8709
8709
|
},
|
@@ -8714,7 +8714,7 @@ var require_URL = __commonJS({
|
|
8714
8714
|
enumerable: true,
|
8715
8715
|
configurable: true
|
8716
8716
|
});
|
8717
|
-
Object.defineProperty(
|
8717
|
+
Object.defineProperty(URL2.prototype, "hostname", {
|
8718
8718
|
get() {
|
8719
8719
|
return this[impl].hostname;
|
8720
8720
|
},
|
@@ -8725,7 +8725,7 @@ var require_URL = __commonJS({
|
|
8725
8725
|
enumerable: true,
|
8726
8726
|
configurable: true
|
8727
8727
|
});
|
8728
|
-
Object.defineProperty(
|
8728
|
+
Object.defineProperty(URL2.prototype, "port", {
|
8729
8729
|
get() {
|
8730
8730
|
return this[impl].port;
|
8731
8731
|
},
|
@@ -8736,7 +8736,7 @@ var require_URL = __commonJS({
|
|
8736
8736
|
enumerable: true,
|
8737
8737
|
configurable: true
|
8738
8738
|
});
|
8739
|
-
Object.defineProperty(
|
8739
|
+
Object.defineProperty(URL2.prototype, "pathname", {
|
8740
8740
|
get() {
|
8741
8741
|
return this[impl].pathname;
|
8742
8742
|
},
|
@@ -8747,7 +8747,7 @@ var require_URL = __commonJS({
|
|
8747
8747
|
enumerable: true,
|
8748
8748
|
configurable: true
|
8749
8749
|
});
|
8750
|
-
Object.defineProperty(
|
8750
|
+
Object.defineProperty(URL2.prototype, "search", {
|
8751
8751
|
get() {
|
8752
8752
|
return this[impl].search;
|
8753
8753
|
},
|
@@ -8758,7 +8758,7 @@ var require_URL = __commonJS({
|
|
8758
8758
|
enumerable: true,
|
8759
8759
|
configurable: true
|
8760
8760
|
});
|
8761
|
-
Object.defineProperty(
|
8761
|
+
Object.defineProperty(URL2.prototype, "hash", {
|
8762
8762
|
get() {
|
8763
8763
|
return this[impl].hash;
|
8764
8764
|
},
|
@@ -8774,7 +8774,7 @@ var require_URL = __commonJS({
|
|
8774
8774
|
return !!obj && obj[impl] instanceof Impl.implementation;
|
8775
8775
|
},
|
8776
8776
|
create(constructorArgs, privateData) {
|
8777
|
-
let obj = Object.create(
|
8777
|
+
let obj = Object.create(URL2.prototype);
|
8778
8778
|
this.setup(obj, constructorArgs, privateData);
|
8779
8779
|
return obj;
|
8780
8780
|
},
|
@@ -8785,10 +8785,10 @@ var require_URL = __commonJS({
|
|
8785
8785
|
obj[impl] = new Impl.implementation(constructorArgs, privateData);
|
8786
8786
|
obj[impl][utils.wrapperSymbol] = obj;
|
8787
8787
|
},
|
8788
|
-
interface:
|
8788
|
+
interface: URL2,
|
8789
8789
|
expose: {
|
8790
|
-
Window: { URL },
|
8791
|
-
Worker: { URL }
|
8790
|
+
Window: { URL: URL2 },
|
8791
|
+
Worker: { URL: URL2 }
|
8792
8792
|
}
|
8793
8793
|
};
|
8794
8794
|
}
|
@@ -9639,12 +9639,12 @@ var require_lib3 = __commonJS({
|
|
9639
9639
|
configurable: true
|
9640
9640
|
});
|
9641
9641
|
var INTERNALS$2 = Symbol("Request internals");
|
9642
|
-
var
|
9642
|
+
var URL2 = Url.URL || whatwgUrl.URL;
|
9643
9643
|
var parse_url = Url.parse;
|
9644
9644
|
var format_url = Url.format;
|
9645
9645
|
function parseURL(urlStr) {
|
9646
9646
|
if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
|
9647
|
-
urlStr = new
|
9647
|
+
urlStr = new URL2(urlStr).toString();
|
9648
9648
|
}
|
9649
9649
|
return parse_url(urlStr);
|
9650
9650
|
}
|
@@ -23651,13 +23651,38 @@ var FileRef = class {
|
|
23651
23651
|
this.contentType = contentType;
|
23652
23652
|
this.mutable = mutable;
|
23653
23653
|
}
|
23654
|
+
/**
|
23655
|
+
* Retrieves the URL of the CloudFront distribution for the S3
|
23656
|
+
* bucket represented by {@link getNowFilesS3Url}.
|
23657
|
+
*
|
23658
|
+
* @returns The URL of the CloudFront distribution
|
23659
|
+
*/
|
23660
|
+
getNowFilesCloudfrontUrl() {
|
23661
|
+
return getEnvAsUrlOrThrow("NOW_FILES_CLOUDFRONT_URL") || "https://dmmcy0pwk6bqi.cloudfront.net";
|
23662
|
+
}
|
23663
|
+
/**
|
23664
|
+
* Retrieves the URL of the S3 bucket for storing ephemeral files.
|
23665
|
+
*
|
23666
|
+
* @returns The URL of the S3 bucket
|
23667
|
+
*/
|
23668
|
+
getNowEphemeralFilesS3Url() {
|
23669
|
+
return getEnvAsUrlOrThrow("NOW_EPHEMERAL_FILES_S3_URL") || "https://now-ephemeral-files.s3.amazonaws.com";
|
23670
|
+
}
|
23671
|
+
/**
|
23672
|
+
* Retrieves the URL of the S3 bucket for storing files.
|
23673
|
+
*
|
23674
|
+
* @returns The URL of the S3 bucket
|
23675
|
+
*/
|
23676
|
+
getNowFilesS3Url() {
|
23677
|
+
return getEnvAsUrlOrThrow("NOW_FILES_S3_URL") || "https://now-files.s3.amazonaws.com";
|
23678
|
+
}
|
23654
23679
|
async toStreamAsync() {
|
23655
23680
|
let url = "";
|
23656
23681
|
const [digestType, digestHash] = this.digest.split(":");
|
23657
23682
|
if (digestType === "sha") {
|
23658
|
-
url = this.mutable ?
|
23683
|
+
url = this.mutable ? `${this.getNowFilesS3Url()}/${digestHash}` : `${this.getNowFilesCloudfrontUrl()}/${digestHash}`;
|
23659
23684
|
} else if (digestType === "sha+ephemeral") {
|
23660
|
-
url =
|
23685
|
+
url = `${this.getNowEphemeralFilesS3Url()}/${digestHash}`;
|
23661
23686
|
} else {
|
23662
23687
|
throw new Error("Expected digest to be sha");
|
23663
23688
|
}
|
@@ -23696,6 +23721,23 @@ var FileRef = class {
|
|
23696
23721
|
});
|
23697
23722
|
}
|
23698
23723
|
};
|
23724
|
+
function getEnvAsUrlOrThrow(key) {
|
23725
|
+
const value = process.env[key];
|
23726
|
+
if (value === void 0)
|
23727
|
+
return void 0;
|
23728
|
+
try {
|
23729
|
+
new URL(value);
|
23730
|
+
return value;
|
23731
|
+
} catch (e) {
|
23732
|
+
if (e instanceof TypeError && "code" in e && e.code === "ERR_INVALID_URL") {
|
23733
|
+
throw new Error(
|
23734
|
+
`A non-URL value was supplied to the ${key} environment variable`
|
23735
|
+
);
|
23736
|
+
} else {
|
23737
|
+
throw e;
|
23738
|
+
}
|
23739
|
+
}
|
23740
|
+
}
|
23699
23741
|
|
23700
23742
|
// src/lambda.ts
|
23701
23743
|
var import_assert4 = __toESM(require("assert"));
|