mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-01 21:59:30 +08:00
178 lines
6.7 KiB
JavaScript
Executable file
178 lines
6.7 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
"use strict";
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
|
|
// lib/npm/node-platform.ts
|
|
var fs = require("fs");
|
|
var os = require("os");
|
|
var path = require("path");
|
|
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
var knownWindowsPackages = {
|
|
"win32 arm64 LE": "esbuild-windows-arm64",
|
|
"win32 ia32 LE": "esbuild-windows-32",
|
|
"win32 x64 LE": "esbuild-windows-64"
|
|
};
|
|
var knownUnixlikePackages = {
|
|
"android arm64 LE": "esbuild-android-arm64",
|
|
"darwin arm64 LE": "esbuild-darwin-arm64",
|
|
"darwin x64 LE": "esbuild-darwin-64",
|
|
"freebsd arm64 LE": "esbuild-freebsd-arm64",
|
|
"freebsd x64 LE": "esbuild-freebsd-64",
|
|
"linux arm LE": "esbuild-linux-arm",
|
|
"linux arm64 LE": "esbuild-linux-arm64",
|
|
"linux ia32 LE": "esbuild-linux-32",
|
|
"linux mips64el LE": "esbuild-linux-mips64le",
|
|
"linux ppc64 LE": "esbuild-linux-ppc64le",
|
|
"linux riscv64 LE": "esbuild-linux-riscv64",
|
|
"linux s390x BE": "esbuild-linux-s390x",
|
|
"linux x64 LE": "esbuild-linux-64",
|
|
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
"netbsd x64 LE": "esbuild-netbsd-64",
|
|
"openbsd x64 LE": "esbuild-openbsd-64",
|
|
"sunos x64 LE": "esbuild-sunos-64"
|
|
};
|
|
var knownWebAssemblyFallbackPackages = {
|
|
"android x64 LE": "esbuild-android-64"
|
|
};
|
|
function pkgAndSubpathForCurrentPlatform() {
|
|
let pkg;
|
|
let subpath;
|
|
let isWASM2 = false;
|
|
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
if (platformKey in knownWindowsPackages) {
|
|
pkg = knownWindowsPackages[platformKey];
|
|
subpath = "esbuild.exe";
|
|
} else if (platformKey in knownUnixlikePackages) {
|
|
pkg = knownUnixlikePackages[platformKey];
|
|
subpath = "bin/esbuild";
|
|
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
|
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
|
subpath = "bin/esbuild";
|
|
isWASM2 = true;
|
|
} else {
|
|
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
}
|
|
return { pkg, subpath, isWASM: isWASM2 };
|
|
}
|
|
function pkgForSomeOtherPlatform() {
|
|
const libMainJS = require.resolve("esbuild");
|
|
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
for (const unixKey in knownUnixlikePackages) {
|
|
try {
|
|
const pkg = knownUnixlikePackages[unixKey];
|
|
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
return pkg;
|
|
} catch {
|
|
}
|
|
}
|
|
for (const windowsKey in knownWindowsPackages) {
|
|
try {
|
|
const pkg = knownWindowsPackages[windowsKey];
|
|
if (fs.existsSync(path.join(nodeModulesDirectory, pkg)))
|
|
return pkg;
|
|
} catch {
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
function downloadedBinPath(pkg, subpath) {
|
|
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
|
return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`);
|
|
}
|
|
function generateBinPath() {
|
|
if (ESBUILD_BINARY_PATH) {
|
|
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
}
|
|
const { pkg, subpath, isWASM: isWASM2 } = pkgAndSubpathForCurrentPlatform();
|
|
let binPath2;
|
|
try {
|
|
binPath2 = require.resolve(`${pkg}/${subpath}`);
|
|
} catch (e) {
|
|
binPath2 = downloadedBinPath(pkg, subpath);
|
|
if (!fs.existsSync(binPath2)) {
|
|
try {
|
|
require.resolve(pkg);
|
|
} catch {
|
|
const otherPkg = pkgForSomeOtherPlatform();
|
|
if (otherPkg) {
|
|
throw new Error(`
|
|
You installed esbuild on another platform than the one you're currently using.
|
|
This won't work because esbuild is written with native code and needs to
|
|
install a platform-specific binary executable.
|
|
|
|
Specifically the "${otherPkg}" package is present but this platform
|
|
needs the "${pkg}" package instead. People often get into this
|
|
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
Windows and WSL environments.
|
|
|
|
If you are installing with npm, you can try not copying the "node_modules"
|
|
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
on the destination platform after the copy. Or you could consider using yarn
|
|
instead which has built-in support for installing a package on multiple
|
|
platforms simultaneously.
|
|
|
|
If you are installing with yarn, you can try listing both this platform and the
|
|
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
Keep in mind that this means multiple copies of esbuild will be present.
|
|
|
|
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
the same way on all platforms. But it comes with a heavy performance cost and
|
|
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
want to do that.
|
|
`);
|
|
}
|
|
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
|
|
If you are installing esbuild with npm, make sure that you don't specify the
|
|
"--no-optional" flag. The "optionalDependencies" package.json feature is used
|
|
by esbuild to install the correct binary executable for your current platform.`);
|
|
}
|
|
throw e;
|
|
}
|
|
}
|
|
let isYarnPnP = false;
|
|
try {
|
|
require("pnpapi");
|
|
isYarnPnP = true;
|
|
} catch (e) {
|
|
}
|
|
if (isYarnPnP) {
|
|
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
|
const binTargetPath = path.join(esbuildLibDir, `pnpapi-${pkg}-${path.basename(subpath)}`);
|
|
if (!fs.existsSync(binTargetPath)) {
|
|
fs.copyFileSync(binPath2, binTargetPath);
|
|
fs.chmodSync(binTargetPath, 493);
|
|
}
|
|
return { binPath: binTargetPath, isWASM: isWASM2 };
|
|
}
|
|
return { binPath: binPath2, isWASM: isWASM2 };
|
|
}
|
|
|
|
// lib/npm/node-shim.ts
|
|
var { binPath, isWASM } = generateBinPath();
|
|
if (isWASM) {
|
|
require("child_process").execFileSync("node", [binPath].concat(process.argv.slice(2)), { stdio: "inherit" });
|
|
} else {
|
|
require("child_process").execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
|
|
}
|