1.0.1
This commit is contained in:
+363
-67
@@ -205,7 +205,7 @@ esbuild in this environment because esbuild relies on this invariant. This
|
||||
is not a problem with esbuild. You need to fix your environment instead.
|
||||
`);
|
||||
function readUInt32LE(buffer, offset) {
|
||||
return buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24;
|
||||
return (buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24) >>> 0;
|
||||
}
|
||||
function writeUInt32LE(buffer, value, offset) {
|
||||
buffer[offset++] = value;
|
||||
@@ -214,29 +214,316 @@ function writeUInt32LE(buffer, value, offset) {
|
||||
buffer[offset++] = value >> 24;
|
||||
}
|
||||
|
||||
// lib/shared/uint8array_json_parser.ts
|
||||
var fromCharCode = String.fromCharCode;
|
||||
function throwSyntaxError(bytes, index, message) {
|
||||
const c = bytes[index];
|
||||
let line = 1;
|
||||
let column = 0;
|
||||
for (let i = 0; i < index; i++) {
|
||||
if (bytes[i] === 10 /* Newline */) {
|
||||
line++;
|
||||
column = 0;
|
||||
} else {
|
||||
column++;
|
||||
}
|
||||
}
|
||||
throw new SyntaxError(
|
||||
message ? message : index === bytes.length ? "Unexpected end of input while parsing JSON" : c >= 32 && c <= 126 ? `Unexpected character ${fromCharCode(c)} in JSON at position ${index} (line ${line}, column ${column})` : `Unexpected byte 0x${c.toString(16)} in JSON at position ${index} (line ${line}, column ${column})`
|
||||
);
|
||||
}
|
||||
function JSON_parse(bytes) {
|
||||
if (!(bytes instanceof Uint8Array)) {
|
||||
throw new Error(`JSON input must be a Uint8Array`);
|
||||
}
|
||||
const propertyStack = [];
|
||||
const objectStack = [];
|
||||
const stateStack = [];
|
||||
const length = bytes.length;
|
||||
let property = null;
|
||||
let state = 0 /* TopLevel */;
|
||||
let object;
|
||||
let i = 0;
|
||||
while (i < length) {
|
||||
let c = bytes[i++];
|
||||
if (c <= 32 /* Space */) {
|
||||
continue;
|
||||
}
|
||||
let value;
|
||||
if (state === 2 /* Object */ && property === null && c !== 34 /* Quote */ && c !== 125 /* CloseBrace */) {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
switch (c) {
|
||||
// True
|
||||
case 116 /* LowerT */: {
|
||||
if (bytes[i++] !== 114 /* LowerR */ || bytes[i++] !== 117 /* LowerU */ || bytes[i++] !== 101 /* LowerE */) {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
value = true;
|
||||
break;
|
||||
}
|
||||
// False
|
||||
case 102 /* LowerF */: {
|
||||
if (bytes[i++] !== 97 /* LowerA */ || bytes[i++] !== 108 /* LowerL */ || bytes[i++] !== 115 /* LowerS */ || bytes[i++] !== 101 /* LowerE */) {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
value = false;
|
||||
break;
|
||||
}
|
||||
// Null
|
||||
case 110 /* LowerN */: {
|
||||
if (bytes[i++] !== 117 /* LowerU */ || bytes[i++] !== 108 /* LowerL */ || bytes[i++] !== 108 /* LowerL */) {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
value = null;
|
||||
break;
|
||||
}
|
||||
// Number begin
|
||||
case 45 /* Minus */:
|
||||
case 46 /* Dot */:
|
||||
case 48 /* Digit0 */:
|
||||
case 49 /* Digit1 */:
|
||||
case 50 /* Digit2 */:
|
||||
case 51 /* Digit3 */:
|
||||
case 52 /* Digit4 */:
|
||||
case 53 /* Digit5 */:
|
||||
case 54 /* Digit6 */:
|
||||
case 55 /* Digit7 */:
|
||||
case 56 /* Digit8 */:
|
||||
case 57 /* Digit9 */: {
|
||||
let index = i;
|
||||
value = fromCharCode(c);
|
||||
c = bytes[i];
|
||||
while (true) {
|
||||
switch (c) {
|
||||
case 43 /* Plus */:
|
||||
case 45 /* Minus */:
|
||||
case 46 /* Dot */:
|
||||
case 48 /* Digit0 */:
|
||||
case 49 /* Digit1 */:
|
||||
case 50 /* Digit2 */:
|
||||
case 51 /* Digit3 */:
|
||||
case 52 /* Digit4 */:
|
||||
case 53 /* Digit5 */:
|
||||
case 54 /* Digit6 */:
|
||||
case 55 /* Digit7 */:
|
||||
case 56 /* Digit8 */:
|
||||
case 57 /* Digit9 */:
|
||||
case 101 /* LowerE */:
|
||||
case 69 /* UpperE */: {
|
||||
value += fromCharCode(c);
|
||||
c = bytes[++i];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
value = +value;
|
||||
if (isNaN(value)) {
|
||||
throwSyntaxError(bytes, --index, "Invalid number");
|
||||
}
|
||||
break;
|
||||
}
|
||||
// String begin
|
||||
case 34 /* Quote */: {
|
||||
value = "";
|
||||
while (true) {
|
||||
if (i >= length) {
|
||||
throwSyntaxError(bytes, length);
|
||||
}
|
||||
c = bytes[i++];
|
||||
if (c === 34 /* Quote */) {
|
||||
break;
|
||||
} else if (c === 92 /* Backslash */) {
|
||||
switch (bytes[i++]) {
|
||||
// Normal escape sequence
|
||||
case 34 /* Quote */:
|
||||
value += '"';
|
||||
break;
|
||||
case 47 /* Slash */:
|
||||
value += "/";
|
||||
break;
|
||||
case 92 /* Backslash */:
|
||||
value += "\\";
|
||||
break;
|
||||
case 98 /* LowerB */:
|
||||
value += "\b";
|
||||
break;
|
||||
case 102 /* LowerF */:
|
||||
value += "\f";
|
||||
break;
|
||||
case 110 /* LowerN */:
|
||||
value += "\n";
|
||||
break;
|
||||
case 114 /* LowerR */:
|
||||
value += "\r";
|
||||
break;
|
||||
case 116 /* LowerT */:
|
||||
value += " ";
|
||||
break;
|
||||
// Unicode escape sequence
|
||||
case 117 /* LowerU */: {
|
||||
let code = 0;
|
||||
for (let j = 0; j < 4; j++) {
|
||||
c = bytes[i++];
|
||||
code <<= 4;
|
||||
if (c >= 48 /* Digit0 */ && c <= 57 /* Digit9 */) code |= c - 48 /* Digit0 */;
|
||||
else if (c >= 97 /* LowerA */ && c <= 102 /* LowerF */) code |= c + (10 - 97 /* LowerA */);
|
||||
else if (c >= 65 /* UpperA */ && c <= 70 /* UpperF */) code |= c + (10 - 65 /* UpperA */);
|
||||
else throwSyntaxError(bytes, --i);
|
||||
}
|
||||
value += fromCharCode(code);
|
||||
break;
|
||||
}
|
||||
// Invalid escape sequence
|
||||
default:
|
||||
throwSyntaxError(bytes, --i);
|
||||
break;
|
||||
}
|
||||
} else if (c <= 127) {
|
||||
value += fromCharCode(c);
|
||||
} else if ((c & 224) === 192) {
|
||||
value += fromCharCode((c & 31) << 6 | bytes[i++] & 63);
|
||||
} else if ((c & 240) === 224) {
|
||||
value += fromCharCode((c & 15) << 12 | (bytes[i++] & 63) << 6 | bytes[i++] & 63);
|
||||
} else if ((c & 248) == 240) {
|
||||
let codePoint = (c & 7) << 18 | (bytes[i++] & 63) << 12 | (bytes[i++] & 63) << 6 | bytes[i++] & 63;
|
||||
if (codePoint > 65535) {
|
||||
codePoint -= 65536;
|
||||
value += fromCharCode(codePoint >> 10 & 1023 | 55296);
|
||||
codePoint = 56320 | codePoint & 1023;
|
||||
}
|
||||
value += fromCharCode(codePoint);
|
||||
}
|
||||
}
|
||||
value[0];
|
||||
break;
|
||||
}
|
||||
// Array begin
|
||||
case 91 /* OpenBracket */: {
|
||||
value = [];
|
||||
propertyStack.push(property);
|
||||
objectStack.push(object);
|
||||
stateStack.push(state);
|
||||
property = null;
|
||||
object = value;
|
||||
state = 1 /* Array */;
|
||||
continue;
|
||||
}
|
||||
// Object begin
|
||||
case 123 /* OpenBrace */: {
|
||||
value = {};
|
||||
propertyStack.push(property);
|
||||
objectStack.push(object);
|
||||
stateStack.push(state);
|
||||
property = null;
|
||||
object = value;
|
||||
state = 2 /* Object */;
|
||||
continue;
|
||||
}
|
||||
// Array end
|
||||
case 93 /* CloseBracket */: {
|
||||
if (state !== 1 /* Array */) {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
value = object;
|
||||
property = propertyStack.pop();
|
||||
object = objectStack.pop();
|
||||
state = stateStack.pop();
|
||||
break;
|
||||
}
|
||||
// Object end
|
||||
case 125 /* CloseBrace */: {
|
||||
if (state !== 2 /* Object */) {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
value = object;
|
||||
property = propertyStack.pop();
|
||||
object = objectStack.pop();
|
||||
state = stateStack.pop();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throwSyntaxError(bytes, --i);
|
||||
}
|
||||
}
|
||||
c = bytes[i];
|
||||
while (c <= 32 /* Space */) {
|
||||
c = bytes[++i];
|
||||
}
|
||||
switch (state) {
|
||||
case 0 /* TopLevel */: {
|
||||
if (i === length) {
|
||||
return value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1 /* Array */: {
|
||||
object.push(value);
|
||||
if (c === 44 /* Comma */) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (c === 93 /* CloseBracket */) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2 /* Object */: {
|
||||
if (property === null) {
|
||||
property = value;
|
||||
if (c === 58 /* Colon */) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
object[property] = value;
|
||||
property = null;
|
||||
if (c === 44 /* Comma */) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (c === 125 /* CloseBrace */) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
throwSyntaxError(bytes, i);
|
||||
}
|
||||
|
||||
// lib/shared/common.ts
|
||||
var quote = JSON.stringify;
|
||||
var buildLogLevelDefault = "warning";
|
||||
var transformLogLevelDefault = "silent";
|
||||
function validateTarget(target) {
|
||||
validateStringValue(target, "target");
|
||||
if (target.indexOf(",") >= 0) throw new Error(`Invalid target: ${target}`);
|
||||
return target;
|
||||
function validateAndJoinStringArray(values, what) {
|
||||
const toJoin = [];
|
||||
for (const value of values) {
|
||||
validateStringValue(value, what);
|
||||
if (value.indexOf(",") >= 0) throw new Error(`Invalid ${what}: ${value}`);
|
||||
toJoin.push(value);
|
||||
}
|
||||
return toJoin.join(",");
|
||||
}
|
||||
var canBeAnything = () => null;
|
||||
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
||||
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
||||
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
||||
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
||||
var mustBeValidPortNumber = (value) => typeof value === "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number";
|
||||
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
||||
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
||||
var mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "an array of strings";
|
||||
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
||||
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
||||
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
||||
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
||||
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
||||
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
||||
var mustBeStringOrArray = (value) => typeof value === "string" || Array.isArray(value) ? null : "a string or an array";
|
||||
var mustBeStringOrArrayOfStrings = (value) => typeof value === "string" || Array.isArray(value) && value.every((x) => typeof x === "string") ? null : "a string or an array of strings";
|
||||
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
||||
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
||||
function getFlag(object, keys, key, mustBeFn) {
|
||||
@@ -285,10 +572,12 @@ function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
||||
let color = getFlag(options, keys, "color", mustBeBoolean);
|
||||
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
||||
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
||||
let logStyle = getFlag(options, keys, "logStyle", mustBeString);
|
||||
if (color !== void 0) flags.push(`--color=${color}`);
|
||||
else if (isTTY2) flags.push(`--color=true`);
|
||||
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
||||
flags.push(`--log-limit=${logLimit || 0}`);
|
||||
if (logStyle) flags.push(`--log-style=${logStyle}`);
|
||||
}
|
||||
function validateStringValue(value, what, key) {
|
||||
if (typeof value !== "string") {
|
||||
@@ -300,7 +589,7 @@ function pushCommonFlags(flags, options, keys) {
|
||||
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
||||
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
||||
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
||||
let target = getFlag(options, keys, "target", mustBeStringOrArray);
|
||||
let target = getFlag(options, keys, "target", mustBeStringOrArrayOfStrings);
|
||||
let format = getFlag(options, keys, "format", mustBeString);
|
||||
let globalName = getFlag(options, keys, "globalName", mustBeString);
|
||||
let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
|
||||
@@ -311,8 +600,8 @@ function pushCommonFlags(flags, options, keys) {
|
||||
let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
|
||||
let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
|
||||
let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
|
||||
let drop = getFlag(options, keys, "drop", mustBeArray);
|
||||
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArray);
|
||||
let drop = getFlag(options, keys, "drop", mustBeArrayOfStrings);
|
||||
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings);
|
||||
let charset = getFlag(options, keys, "charset", mustBeString);
|
||||
let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
|
||||
let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
|
||||
@@ -325,17 +614,15 @@ function pushCommonFlags(flags, options, keys) {
|
||||
let define = getFlag(options, keys, "define", mustBeObject);
|
||||
let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
|
||||
let supported = getFlag(options, keys, "supported", mustBeObject);
|
||||
let pure = getFlag(options, keys, "pure", mustBeArray);
|
||||
let pure = getFlag(options, keys, "pure", mustBeArrayOfStrings);
|
||||
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
||||
let platform = getFlag(options, keys, "platform", mustBeString);
|
||||
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
||||
let absPaths = getFlag(options, keys, "absPaths", mustBeArrayOfStrings);
|
||||
if (legalComments) flags.push(`--legal-comments=${legalComments}`);
|
||||
if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
|
||||
if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
|
||||
if (target) {
|
||||
if (Array.isArray(target)) flags.push(`--target=${Array.from(target).map(validateTarget).join(",")}`);
|
||||
else flags.push(`--target=${validateTarget(target)}`);
|
||||
}
|
||||
if (target) flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`);
|
||||
if (format) flags.push(`--format=${format}`);
|
||||
if (globalName) flags.push(`--global-name=${globalName}`);
|
||||
if (platform) flags.push(`--platform=${platform}`);
|
||||
@@ -349,9 +636,10 @@ function pushCommonFlags(flags, options, keys) {
|
||||
if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
|
||||
if (ignoreAnnotations) flags.push(`--ignore-annotations`);
|
||||
if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
||||
if (dropLabels) flags.push(`--drop-labels=${Array.from(dropLabels).map((what) => validateStringValue(what, "dropLabels")).join(",")}`);
|
||||
if (mangleProps) flags.push(`--mangle-props=${mangleProps.source}`);
|
||||
if (reserveProps) flags.push(`--reserve-props=${reserveProps.source}`);
|
||||
if (dropLabels) flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`);
|
||||
if (absPaths) flags.push(`--abs-paths=${validateAndJoinStringArray(absPaths, "abs paths")}`);
|
||||
if (mangleProps) flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`);
|
||||
if (reserveProps) flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`);
|
||||
if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
|
||||
if (jsx) flags.push(`--jsx=${jsx}`);
|
||||
if (jsxFactory) flags.push(`--jsx-factory=${jsxFactory}`);
|
||||
@@ -400,11 +688,11 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
||||
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
||||
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
||||
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
||||
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArray);
|
||||
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArray);
|
||||
let mainFields = getFlag(options, keys, "mainFields", mustBeArray);
|
||||
let conditions = getFlag(options, keys, "conditions", mustBeArray);
|
||||
let external = getFlag(options, keys, "external", mustBeArray);
|
||||
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings);
|
||||
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings);
|
||||
let mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings);
|
||||
let conditions = getFlag(options, keys, "conditions", mustBeArrayOfStrings);
|
||||
let external = getFlag(options, keys, "external", mustBeArrayOfStrings);
|
||||
let packages = getFlag(options, keys, "packages", mustBeString);
|
||||
let alias = getFlag(options, keys, "alias", mustBeObject);
|
||||
let loader = getFlag(options, keys, "loader", mustBeObject);
|
||||
@@ -413,7 +701,7 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
||||
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
||||
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
||||
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
||||
let inject = getFlag(options, keys, "inject", mustBeArray);
|
||||
let inject = getFlag(options, keys, "inject", mustBeArrayOfStrings);
|
||||
let banner = getFlag(options, keys, "banner", mustBeObject);
|
||||
let footer = getFlag(options, keys, "footer", mustBeObject);
|
||||
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
||||
@@ -435,37 +723,13 @@ function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeD
|
||||
if (outbase) flags.push(`--outbase=${outbase}`);
|
||||
if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
|
||||
if (packages) flags.push(`--packages=${packages}`);
|
||||
if (resolveExtensions) {
|
||||
let values = [];
|
||||
for (let value of resolveExtensions) {
|
||||
validateStringValue(value, "resolve extension");
|
||||
if (value.indexOf(",") >= 0) throw new Error(`Invalid resolve extension: ${value}`);
|
||||
values.push(value);
|
||||
}
|
||||
flags.push(`--resolve-extensions=${values.join(",")}`);
|
||||
}
|
||||
if (resolveExtensions) flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`);
|
||||
if (publicPath) flags.push(`--public-path=${publicPath}`);
|
||||
if (entryNames) flags.push(`--entry-names=${entryNames}`);
|
||||
if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
|
||||
if (assetNames) flags.push(`--asset-names=${assetNames}`);
|
||||
if (mainFields) {
|
||||
let values = [];
|
||||
for (let value of mainFields) {
|
||||
validateStringValue(value, "main field");
|
||||
if (value.indexOf(",") >= 0) throw new Error(`Invalid main field: ${value}`);
|
||||
values.push(value);
|
||||
}
|
||||
flags.push(`--main-fields=${values.join(",")}`);
|
||||
}
|
||||
if (conditions) {
|
||||
let values = [];
|
||||
for (let value of conditions) {
|
||||
validateStringValue(value, "condition");
|
||||
if (value.indexOf(",") >= 0) throw new Error(`Invalid condition: ${value}`);
|
||||
values.push(value);
|
||||
}
|
||||
flags.push(`--conditions=${values.join(",")}`);
|
||||
}
|
||||
if (mainFields) flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`);
|
||||
if (conditions) flags.push(`--conditions=${validateAndJoinStringArray(conditions, "condition")}`);
|
||||
if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
||||
if (alias) {
|
||||
for (let old in alias) {
|
||||
@@ -662,8 +926,8 @@ function createChannel(streamIn) {
|
||||
if (isFirstPacket) {
|
||||
isFirstPacket = false;
|
||||
let binaryVersion = String.fromCharCode(...bytes);
|
||||
if (binaryVersion !== "0.23.0") {
|
||||
throw new Error(`Cannot start service: Host version "${"0.23.0"}" does not match binary version ${quote(binaryVersion)}`);
|
||||
if (binaryVersion !== "0.28.2") {
|
||||
throw new Error(`Cannot start service: Host version "${"0.28.2"}" does not match binary version ${quote(binaryVersion)}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -802,6 +1066,7 @@ function createChannel(streamIn) {
|
||||
let kind = getFlag(options, keys, "kind", mustBeString);
|
||||
let color = getFlag(options, keys, "color", mustBeBoolean);
|
||||
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
||||
let logStyle = getFlag(options, keys, "logStyle", mustBeString);
|
||||
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
||||
if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`);
|
||||
if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
||||
@@ -812,6 +1077,7 @@ function createChannel(streamIn) {
|
||||
};
|
||||
if (color !== void 0) request.color = color;
|
||||
if (terminalWidth !== void 0) request.terminalWidth = terminalWidth;
|
||||
if (logStyle !== void 0) request.logStyle = logStyle;
|
||||
sendRequest(refs, request, (error, response) => {
|
||||
if (error) return callback(new Error(error), null);
|
||||
callback(null, response.messages);
|
||||
@@ -937,7 +1203,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
||||
const originalErrors = result.errors.slice();
|
||||
const originalWarnings = result.warnings.slice();
|
||||
if (response.outputFiles) result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
||||
if (response.metafile) result.metafile = JSON.parse(response.metafile);
|
||||
if (response.metafile && response.metafile.length) result.metafile = parseJSON(response.metafile);
|
||||
if (response.mangleCache) result.mangleCache = response.mangleCache;
|
||||
if (response.writeToStdout !== void 0) console.log(decodeUTF8(response.writeToStdout).replace(/\n$/, ""));
|
||||
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
||||
@@ -1005,11 +1271,13 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
||||
watch: (options2 = {}) => new Promise((resolve, reject) => {
|
||||
if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
|
||||
const keys = {};
|
||||
const delay = getFlag(options2, keys, "delay", mustBeInteger);
|
||||
checkForInvalidFlags(options2, keys, `in watch() call`);
|
||||
const request2 = {
|
||||
command: "watch",
|
||||
key: buildKey
|
||||
};
|
||||
if (delay) request2.delay = delay;
|
||||
sendRequest(refs, request2, (error2) => {
|
||||
if (error2) reject(new Error(error2));
|
||||
else resolve(void 0);
|
||||
@@ -1018,12 +1286,13 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
||||
serve: (options2 = {}) => new Promise((resolve, reject) => {
|
||||
if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
|
||||
const keys = {};
|
||||
const port = getFlag(options2, keys, "port", mustBeInteger);
|
||||
const port = getFlag(options2, keys, "port", mustBeValidPortNumber);
|
||||
const host = getFlag(options2, keys, "host", mustBeString);
|
||||
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
||||
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
||||
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
||||
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
||||
const cors = getFlag(options2, keys, "cors", mustBeObject);
|
||||
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
||||
checkForInvalidFlags(options2, keys, `in serve() call`);
|
||||
const request2 = {
|
||||
@@ -1037,6 +1306,13 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
|
||||
if (keyfile !== void 0) request2.keyfile = keyfile;
|
||||
if (certfile !== void 0) request2.certfile = certfile;
|
||||
if (fallback !== void 0) request2.fallback = fallback;
|
||||
if (cors) {
|
||||
const corsKeys = {};
|
||||
const origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
|
||||
checkForInvalidFlags(cors, corsKeys, `on "cors" object`);
|
||||
if (Array.isArray(origin)) request2.corsOrigin = origin;
|
||||
else if (origin !== void 0) request2.corsOrigin = [origin];
|
||||
}
|
||||
sendRequest(refs, request2, (error2, response2) => {
|
||||
if (error2) return reject(new Error(error2));
|
||||
if (onRequest) {
|
||||
@@ -1172,7 +1448,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
||||
if (filter == null) throw new Error(`onResolve() call is missing a filter`);
|
||||
let id = nextCallbackID++;
|
||||
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
||||
plugin.onResolve.push({ id, filter: filter.source, namespace: namespace || "" });
|
||||
plugin.onResolve.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
||||
},
|
||||
onLoad(options, callback) {
|
||||
let registeredText = `This error came from the "onLoad" callback registered here:`;
|
||||
@@ -1184,7 +1460,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
||||
if (filter == null) throw new Error(`onLoad() call is missing a filter`);
|
||||
let id = nextCallbackID++;
|
||||
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
||||
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
|
||||
plugin.onLoad.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
||||
},
|
||||
onDispose(callback) {
|
||||
onDisposeCallbacks.push(callback);
|
||||
@@ -1198,6 +1474,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
||||
}
|
||||
}
|
||||
requestCallbacks["on-start"] = async (id, request) => {
|
||||
details.clear();
|
||||
let response = { errors: [], warnings: [] };
|
||||
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
||||
try {
|
||||
@@ -1243,8 +1520,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
||||
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
||||
let errors = getFlag(result, keys, "errors", mustBeArray);
|
||||
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
||||
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
||||
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
||||
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
||||
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
||||
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
||||
response.id = id2;
|
||||
if (pluginName != null) response.pluginName = pluginName;
|
||||
@@ -1289,8 +1566,8 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
|
||||
let loader = getFlag(result, keys, "loader", mustBeString);
|
||||
let errors = getFlag(result, keys, "errors", mustBeArray);
|
||||
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
||||
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArray);
|
||||
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArray);
|
||||
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
||||
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
||||
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
||||
response.id = id2;
|
||||
if (pluginName != null) response.pluginName = pluginName;
|
||||
@@ -1371,6 +1648,9 @@ function createObjectStash() {
|
||||
const map = /* @__PURE__ */ new Map();
|
||||
let nextID = 0;
|
||||
return {
|
||||
clear() {
|
||||
map.clear();
|
||||
},
|
||||
load(id) {
|
||||
return map.get(id);
|
||||
},
|
||||
@@ -1591,6 +1871,20 @@ function convertOutputFiles({ path: path3, contents, hash }) {
|
||||
}
|
||||
};
|
||||
}
|
||||
function jsRegExpToGoRegExp(regexp) {
|
||||
let result = regexp.source;
|
||||
if (regexp.flags) result = `(?${regexp.flags})${result}`;
|
||||
return result;
|
||||
}
|
||||
function parseJSON(bytes) {
|
||||
let text;
|
||||
try {
|
||||
text = decodeUTF8(bytes);
|
||||
} catch {
|
||||
return JSON_parse(bytes);
|
||||
}
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
// lib/npm/node-platform.ts
|
||||
var fs = require("fs");
|
||||
@@ -1621,6 +1915,7 @@ var knownUnixlikePackages = {
|
||||
"linux s390x BE": "@esbuild/linux-s390x",
|
||||
"linux x64 LE": "@esbuild/linux-x64",
|
||||
"linux loong64 LE": "@esbuild/linux-loong64",
|
||||
"netbsd arm64 LE": "@esbuild/netbsd-arm64",
|
||||
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
||||
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
||||
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
||||
@@ -1628,7 +1923,8 @@ var knownUnixlikePackages = {
|
||||
};
|
||||
var knownWebAssemblyFallbackPackages = {
|
||||
"android arm LE": "@esbuild/android-arm",
|
||||
"android x64 LE": "@esbuild/android-x64"
|
||||
"android x64 LE": "@esbuild/android-x64",
|
||||
"openharmony arm64 LE": "@esbuild/openharmony-arm64"
|
||||
};
|
||||
function pkgAndSubpathForCurrentPlatform() {
|
||||
let pkg;
|
||||
@@ -1768,7 +2064,7 @@ for your current platform.`);
|
||||
"node_modules",
|
||||
".cache",
|
||||
"esbuild",
|
||||
`pnpapi-${pkg.replace("/", "-")}-${"0.23.0"}-${path.basename(subpath)}`
|
||||
`pnpapi-${pkg.replace("/", "-")}-${"0.28.2"}-${path.basename(subpath)}`
|
||||
);
|
||||
if (!fs.existsSync(binTargetPath)) {
|
||||
fs.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
||||
@@ -1803,7 +2099,7 @@ if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
||||
}
|
||||
}
|
||||
var _a;
|
||||
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.23.0";
|
||||
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.28.2";
|
||||
var esbuildCommandAndArgs = () => {
|
||||
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
||||
throw new Error(
|
||||
@@ -1870,7 +2166,7 @@ var fsAsync = {
|
||||
}
|
||||
}
|
||||
};
|
||||
var version = "0.23.0";
|
||||
var version = "0.28.2";
|
||||
var build = (options) => ensureServiceIsRunning().build(options);
|
||||
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
||||
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
||||
@@ -1973,7 +2269,7 @@ var stopService;
|
||||
var ensureServiceIsRunning = () => {
|
||||
if (longLivedService) return longLivedService;
|
||||
let [command, args] = esbuildCommandAndArgs();
|
||||
let child = child_process.spawn(command, args.concat(`--service=${"0.23.0"}`, "--ping"), {
|
||||
let child = child_process.spawn(command, args.concat(`--service=${"0.28.2"}`, "--ping"), {
|
||||
windowsHide: true,
|
||||
stdio: ["pipe", "pipe", "inherit"],
|
||||
cwd: defaultWD
|
||||
@@ -2077,7 +2373,7 @@ var runServiceSync = (callback) => {
|
||||
esbuild: node_exports
|
||||
});
|
||||
callback(service);
|
||||
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.23.0"}`), {
|
||||
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.28.2"}`), {
|
||||
cwd: defaultWD,
|
||||
windowsHide: true,
|
||||
input: stdin,
|
||||
@@ -2097,7 +2393,7 @@ var workerThreadService = null;
|
||||
var startWorkerThreadService = (worker_threads2) => {
|
||||
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
||||
let worker = new worker_threads2.Worker(__filename, {
|
||||
workerData: { workerPort, defaultWD, esbuildVersion: "0.23.0" },
|
||||
workerData: { workerPort, defaultWD, esbuildVersion: "0.28.2" },
|
||||
transferList: [workerPort],
|
||||
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user