This commit is contained in:
vd
2026-10-12 20:38:04 +02:00
parent 18172b4004
commit 4a01f0d7a9
132 changed files with 3809 additions and 4830 deletions
BIN
View File
Binary file not shown.
+26 -12
View File
@@ -49,6 +49,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",
@@ -56,7 +57,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;
@@ -89,8 +91,9 @@ var os2 = require("os");
var path2 = require("path");
var zlib = require("zlib");
var https = require("https");
var crypto = require("crypto");
var child_process = require("child_process");
var versionFromPackageJSON = require(path2.join(__dirname, "package.json")).version;
var packageJSON = require(path2.join(__dirname, "package.json"));
var toPath = path2.join(__dirname, "bin", "esbuild");
var isToPathJS = true;
function validateBinaryVersion(...command) {
@@ -130,8 +133,8 @@ which means the "esbuild" binary executable can't be run. You can either:
}
throw err;
}
if (stdout !== versionFromPackageJSON) {
throw new Error(`Expected ${JSON.stringify(versionFromPackageJSON)} but got ${JSON.stringify(stdout)}`);
if (stdout !== packageJSON.version) {
throw new Error(`Expected ${JSON.stringify(packageJSON.version)} but got ${JSON.stringify(stdout)}`);
}
}
function isYarn() {
@@ -167,7 +170,7 @@ function extractFileFromTarGzip(buffer, subpath) {
let name = str(offset, 100);
let size = parseInt(str(offset + 124, 12), 8);
offset += 512;
if (!isNaN(size)) {
if (!isNaN(size) && size >= 0) {
if (name === subpath) return buffer.subarray(offset, offset + size);
offset += size + 511 & ~511;
}
@@ -182,10 +185,11 @@ function installUsingNPM(pkg, subpath, binPath) {
try {
fs2.writeFileSync(path2.join(installDir, "package.json"), "{}");
child_process.execSync(
`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${versionFromPackageJSON}`,
`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${packageJSON.version}`,
{ cwd: installDir, stdio: "pipe", env }
);
const installedBinPath = path2.join(installDir, "node_modules", pkg, subpath);
binaryIntegrityCheck(pkg, subpath, fs2.readFileSync(installedBinPath));
fs2.renameSync(installedBinPath, binPath);
} finally {
try {
@@ -218,8 +222,8 @@ require('child_process').execFileSync(${pathString}, process.argv.slice(2), { st
fs2.writeFileSync(libMain, `var ESBUILD_BINARY_PATH = ${pathString};
${code}`);
}
function maybeOptimizePackage(binPath) {
if (os2.platform() !== "win32" && !isYarn()) {
function maybeOptimizePackage(binPath, isWASM) {
if (os2.platform() !== "win32" && !isYarn() && !isWASM) {
const tempPath = path2.join(__dirname, "bin-esbuild");
try {
fs2.linkSync(binPath, tempPath);
@@ -230,11 +234,20 @@ function maybeOptimizePackage(binPath) {
}
}
}
function binaryIntegrityCheck(pkg, subpath, bytes) {
const hash = crypto.createHash("sha256").update(bytes).digest("hex");
const key = `${pkg}/${subpath}`;
const expected = packageJSON["esbuild.binaryHashes"][key];
if (!expected) throw new Error(`Missing hash for "${key}"`);
if (hash !== expected) throw new Error(`"${hash.slice(0, 8)}..." doesn't match "${expected.slice(0, 8)}..." for "${pkg}"`);
}
async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace("@esbuild/", "")}-${versionFromPackageJSON}.tgz`;
const url = `https://registry.npmjs.org/${pkg}/-/${pkg.replace("@esbuild/", "")}-${packageJSON.version}.tgz`;
console.error(`[esbuild] Trying to download ${JSON.stringify(url)}`);
try {
fs2.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath));
const bytes = extractFileFromTarGzip(await fetch(url), subpath);
binaryIntegrityCheck(pkg, subpath, bytes);
fs2.writeFileSync(binPath, bytes);
fs2.chmodSync(binPath, 493);
} catch (e) {
console.error(`[esbuild] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`);
@@ -250,7 +263,7 @@ async function checkAndPreparePackage() {
return;
}
}
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
let binPath;
try {
binPath = require.resolve(`${pkg}/${subpath}`);
@@ -262,6 +275,7 @@ package.json feature is used by esbuild to install the correct binary executable
for your current platform. This install script will now attempt to work around
this. If that fails, you need to remove the "--no-optional" flag to use esbuild.
`);
if (isWASM) throw new Error(`Failed to install package "${pkg}"`);
binPath = downloadedBinPath(pkg, subpath);
try {
console.error(`[esbuild] Trying to install package "${pkg}" using npm`);
@@ -275,7 +289,7 @@ this. If that fails, you need to remove the "--no-optional" flag to use esbuild.
}
}
}
maybeOptimizePackage(binPath);
maybeOptimizePackage(binPath, isWASM);
}
checkAndPreparePackage().then(() => {
if (isToPathJS) {
+17 -2
View File
@@ -2,8 +2,10 @@ export type Platform = 'browser' | 'node' | 'neutral'
export type Format = 'iife' | 'cjs' | 'esm'
export type Loader = 'base64' | 'binary' | 'copy' | 'css' | 'dataurl' | 'default' | 'empty' | 'file' | 'js' | 'json' | 'jsx' | 'local-css' | 'text' | 'ts' | 'tsx'
export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent'
export type LogStyle = 'default' | 'visualstudio'
export type Charset = 'ascii' | 'utf8'
export type Drop = 'console' | 'debugger'
export type AbsPaths = 'code' | 'log' | 'metafile'
interface CommonOptions {
/** Documentation: https://esbuild.github.io/api/#sourcemap */
@@ -75,6 +77,8 @@ interface CommonOptions {
/** Documentation: https://esbuild.github.io/api/#keep-names */
keepNames?: boolean
/** Documentation: https://esbuild.github.io/api/#abs-paths */
absPaths?: AbsPaths[]
/** Documentation: https://esbuild.github.io/api/#color */
color?: boolean
/** Documentation: https://esbuild.github.io/api/#log-level */
@@ -83,6 +87,8 @@ interface CommonOptions {
logLimit?: number
/** Documentation: https://esbuild.github.io/api/#log-override */
logOverride?: Record<string, LogLevel>
/** Documentation: https://esbuild.github.io/api/#log-style */
logStyle?: LogStyle
/** Documentation: https://esbuild.github.io/api/#tsconfig-raw */
tsconfigRaw?: string | TsconfigRaw
@@ -159,7 +165,7 @@ export interface BuildOptions extends CommonOptions {
/** Documentation: https://esbuild.github.io/api/#footer */
footer?: { [type: string]: string }
/** Documentation: https://esbuild.github.io/api/#entry-points */
entryPoints?: string[] | Record<string, string> | { in: string, out: string }[]
entryPoints?: (string | { in: string, out: string })[] | Record<string, string>
/** Documentation: https://esbuild.github.io/api/#stdin */
stdin?: StdinOptions
/** Documentation: https://esbuild.github.io/plugins/ */
@@ -241,9 +247,15 @@ export interface ServeOptions {
keyfile?: string
certfile?: string
fallback?: string
cors?: CORSOptions
onRequest?: (args: ServeOnRequestArgs) => void
}
/** Documentation: https://esbuild.github.io/api/#cors */
export interface CORSOptions {
origin?: string | string[]
}
export interface ServeOnRequestArgs {
remoteAddress: string
method: string
@@ -256,7 +268,7 @@ export interface ServeOnRequestArgs {
/** Documentation: https://esbuild.github.io/api/#serve-return-values */
export interface ServeResult {
port: number
host: string
hosts: string[]
}
export interface TransformOptions extends CommonOptions {
@@ -500,6 +512,7 @@ export interface FormatMessagesOptions {
kind: 'error' | 'warning'
color?: boolean
terminalWidth?: number
logStyle?: LogStyle
}
export interface AnalyzeMetafileOptions {
@@ -507,7 +520,9 @@ export interface AnalyzeMetafileOptions {
verbose?: boolean
}
/** Documentation: https://esbuild.github.io/api/#watch-arguments */
export interface WatchOptions {
delay?: number // In milliseconds
}
export interface BuildContext<ProvidedOptions extends BuildOptions = BuildOptions> {
+363 -67
View File
@@ -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
//
+53 -26
View File
@@ -1,6 +1,6 @@
{
"name": "esbuild",
"version": "0.23.0",
"version": "0.28.2",
"description": "An extremely fast JavaScript and CSS bundler and minifier.",
"repository": {
"type": "git",
@@ -18,30 +18,57 @@
"esbuild": "bin/esbuild"
},
"optionalDependencies": {
"@esbuild/aix-ppc64": "0.23.0",
"@esbuild/android-arm": "0.23.0",
"@esbuild/android-arm64": "0.23.0",
"@esbuild/android-x64": "0.23.0",
"@esbuild/darwin-arm64": "0.23.0",
"@esbuild/darwin-x64": "0.23.0",
"@esbuild/freebsd-arm64": "0.23.0",
"@esbuild/freebsd-x64": "0.23.0",
"@esbuild/linux-arm": "0.23.0",
"@esbuild/linux-arm64": "0.23.0",
"@esbuild/linux-ia32": "0.23.0",
"@esbuild/linux-loong64": "0.23.0",
"@esbuild/linux-mips64el": "0.23.0",
"@esbuild/linux-ppc64": "0.23.0",
"@esbuild/linux-riscv64": "0.23.0",
"@esbuild/linux-s390x": "0.23.0",
"@esbuild/linux-x64": "0.23.0",
"@esbuild/netbsd-x64": "0.23.0",
"@esbuild/openbsd-arm64": "0.23.0",
"@esbuild/openbsd-x64": "0.23.0",
"@esbuild/sunos-x64": "0.23.0",
"@esbuild/win32-arm64": "0.23.0",
"@esbuild/win32-ia32": "0.23.0",
"@esbuild/win32-x64": "0.23.0"
"@esbuild/aix-ppc64": "0.28.2",
"@esbuild/android-arm": "0.28.2",
"@esbuild/android-arm64": "0.28.2",
"@esbuild/android-x64": "0.28.2",
"@esbuild/darwin-arm64": "0.28.2",
"@esbuild/darwin-x64": "0.28.2",
"@esbuild/freebsd-arm64": "0.28.2",
"@esbuild/freebsd-x64": "0.28.2",
"@esbuild/linux-arm": "0.28.2",
"@esbuild/linux-arm64": "0.28.2",
"@esbuild/linux-ia32": "0.28.2",
"@esbuild/linux-loong64": "0.28.2",
"@esbuild/linux-mips64el": "0.28.2",
"@esbuild/linux-ppc64": "0.28.2",
"@esbuild/linux-riscv64": "0.28.2",
"@esbuild/linux-s390x": "0.28.2",
"@esbuild/linux-x64": "0.28.2",
"@esbuild/netbsd-arm64": "0.28.2",
"@esbuild/netbsd-x64": "0.28.2",
"@esbuild/openbsd-arm64": "0.28.2",
"@esbuild/openbsd-x64": "0.28.2",
"@esbuild/openharmony-arm64": "0.28.2",
"@esbuild/sunos-x64": "0.28.2",
"@esbuild/win32-arm64": "0.28.2",
"@esbuild/win32-ia32": "0.28.2",
"@esbuild/win32-x64": "0.28.2"
},
"license": "MIT"
"license": "MIT",
"esbuild.binaryHashes": {
"@esbuild/aix-ppc64/bin/esbuild": "6de148b932fc5d3b28a97f9f0bc4de8e2b47db478b8ad679e0eaa6b96e00420d",
"@esbuild/android-arm64/bin/esbuild": "84efbbd2cbf21bbfec2aaf304bee79cb2a4a05fe2ea7b861a87f7b8f213ac27d",
"@esbuild/darwin-arm64/bin/esbuild": "10b6243df618d374bb2d5c9cfbe7052e1405f6aa4e53a6164f11a91b9f2e1384",
"@esbuild/darwin-x64/bin/esbuild": "7fe5c9c905fff0a05d92db98929434ab4d3b6dd92d7a7688922db74380c75df3",
"@esbuild/freebsd-arm64/bin/esbuild": "6aba108a68b93064e491bfb1ecfa28843b4d4e504dff0627f53f68f6bb015c01",
"@esbuild/freebsd-x64/bin/esbuild": "8a237e222bee0e50556e7b00d83ec2ff43721bf72f19811a5f0ee56f1d40177c",
"@esbuild/linux-arm/bin/esbuild": "d88f751b22095b2f3b42c8c2e8a3f36fabc1705438c5d6e78366b681f8b4e7a5",
"@esbuild/linux-arm64/bin/esbuild": "90bd269553d258e80b19e3ccab4f98f0831f87442a2f056510ce24fd1b425fc2",
"@esbuild/linux-ia32/bin/esbuild": "b1e2d87d79f9a2baa0d3043cdf0dc6716f9f2eea66c58f47588641fd6019f36f",
"@esbuild/linux-loong64/bin/esbuild": "55a66f9854d6798f36b2b5471db74f2e552481887ea14d8bda1634a512383a43",
"@esbuild/linux-mips64el/bin/esbuild": "6bf7921a3af4a801051e056d85c360fe24bb446f488ef3da25f0b8e5cf973db1",
"@esbuild/linux-ppc64/bin/esbuild": "c30df60d09bb0ba4853d7b06e244ce966890d61ce60cadd9b22335f6379c316a",
"@esbuild/linux-riscv64/bin/esbuild": "36bdcdc8230eef385838cdfeb0d9a1565cbe4b9ace30097a511d77e894de36a1",
"@esbuild/linux-s390x/bin/esbuild": "bbbc1f92a76a5ca6e2976065222e42b02797363a1f119490dda315f74047741f",
"@esbuild/linux-x64/bin/esbuild": "e1698a3d5c6c0798fee4fd3b5cc816651f460c63d390a7a26ea4beb0b1884100",
"@esbuild/netbsd-arm64/bin/esbuild": "62548519d7ae875d060aa8c94bfb8ed38ef191671a5173d9f626bdb6b7516970",
"@esbuild/netbsd-x64/bin/esbuild": "f9d0e59d2b404559e3a0c958164d96960ebf0e04583b878b1d64d8f1c3698fcc",
"@esbuild/openbsd-arm64/bin/esbuild": "e10c45a0b62456632da41df058d7626b2e7cfe710780a2dc7f9f84681753f3aa",
"@esbuild/openbsd-x64/bin/esbuild": "720bbe607736716f2ecd37962436c5589d801966e868a2ae4e0e7e62d1e4e887",
"@esbuild/sunos-x64/bin/esbuild": "01a3bd9183631ca749f34d15601ea21ba6834614184c5c859f99d54bd683203d",
"@esbuild/win32-arm64/esbuild.exe": "530fb3933af14eefe85dfd06502f826e6ef60fdf4e75228ea67c696db312ecb1",
"@esbuild/win32-ia32/esbuild.exe": "b2e62af5c17e00939583be0a0762fdc469f352869a617edc91371b00454c76f0",
"@esbuild/win32-x64/esbuild.exe": "c7bee37877d0aa6a046e52783fa0a2cf1a9ce5579d68bb3083bda99d4bff18ef"
}
}