feat(bindings): Remove swcx from @swc/core (#6720)

This commit is contained in:
OJ Kwon 2022-12-29 22:31:57 -08:00 committed by GitHub
parent 0a652096ae
commit 30dd65bb83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 3 additions and 93 deletions

View File

@ -1,82 +0,0 @@
#!/usr/bin/env node
/**
* Lightweight entrypoint to native swc cli binary.
*
* This is to locate corresponding per-platform executables correctly, as well as
* let npm links binary to `node_modules/.bin` allows npm-related ecosystem (`npx swcx`, etcs)
* works correctly. However, it means spawning native binary still requires warmup from node.js
* process.
*
* NOTE: THIS IS NOT A PERMANENT APPROACH.
* Distribution of native cli binary is not fully concluded yet. This allows easier
* opt-in while implementation is in progress to collect feedback.
*/
import { spawn, StdioOptions } from "child_process";
import path from "path";
import { readFileSync } from "fs";
const { platform, arch } = process;
const isMusl = () => (() => {
function isMusl() {
if (!process.report || typeof process.report.getReport !== "function") {
try {
return readFileSync("/usr/bin/ldd", "utf8").includes("musl");
} catch (e) {
return true;
}
} else {
const { glibcVersionRuntime } = (process.report.getReport() as any).header;
return !glibcVersionRuntime;
}
}
return isMusl();
})();
const platformPackagesMap: Record<string, Partial<Record<string, string>>> = {
"android": {
"arm64": "@swc/core-android-arm64",
"arm": "@swc/core-android-arm-eabi",
},
"win32": {
"x64": "@swc/core-win32-x64-msvc",
"ia32": "@swc/core-win32-ia32-msvc",
"arm64": "@swc/core-win32-arm64-msvc"
},
"darwin": {
"x64": "@swc/core-darwin-x64",
"arm64": "@swc/core-darwin-arm64",
},
"freebsd": {
"x64": "@swc/core-freebsd-x64",
},
"linux": {
"x64": `@swc/core-linux-x64-${isMusl() ? 'musl' : 'gnu'}`,
"arm64": `@swc/core-linux-arm64-${isMusl() ? 'musl' : 'gnu'}`,
"arm": "@swc/core-linux-arm64-gnu"
},
};
const inferBinaryName = () => {
const packageName = platformPackagesMap[platform][arch];
if (!packageName) {
throw new Error(`Unsupported platform: binary for '${platform} ${arch}' is not available`);
}
return path.join(path.dirname(require.resolve(packageName)), platform === 'win32' ? 'swc.exe' : 'swc');
}
const executeBinary = async () => {
const binary = inferBinaryName();
const [, , ...args] = process.argv;
const options = { cwd: process.cwd(), stdio: "inherit" as StdioOptions };
return spawn(binary, args, options);
};
executeBinary().catch((e) => console.error(e));

View File

@ -4,9 +4,6 @@
"description": "Super-fast alternative for babel",
"homepage": "https://swc.rs",
"main": "./index.js",
"bin": {
"swcx": "run_swcx.js"
},
"author": "강동윤 <kdy1997.dev@gmail.com>",
"license": "Apache-2.0",
"keywords": [
@ -162,7 +159,6 @@
"Visitor.js",
"binding.d.ts",
"index.js",
"run_swcx.js",
"types.d.ts",
"util.js",
"README.md",
@ -174,4 +170,4 @@
"bindings/binding_core_wasm/pkg/binding_core_wasm.d.ts"
],
"packageManager": "yarn@3.3.0"
}
}

View File

@ -15,10 +15,8 @@ do
if [ -f "$CLI_BINARY_PATH" ]; then
chmod +x $CLI_BINARY_PATH
cp -v $CLI_BINARY_PATH ./artifacts_cli/swc-$BINDING_ABI
mv $CLI_BINARY_PATH ./scripts/npm/$BINDING_ABI
mv -v $CLI_BINARY_PATH ./artifacts_cli/swc-$BINDING_ABI
elif [ -f "$CLI_BINARY_PATH.exe" ]; then
cp -v $CLI_BINARY_PATH.exe ./artifacts_cli/swc-$BINDING_ABI.exe
mv $CLI_BINARY_PATH.exe ./scripts/npm/$BINDING_ABI
mv -v $CLI_BINARY_PATH.exe ./artifacts_cli/swc-$BINDING_ABI.exe
fi
done

View File

@ -2522,8 +2522,6 @@ __metadata:
optional: true
"@swc/core-win32-x64-msvc":
optional: true
bin:
swcx: run_swcx.js
languageName: unknown
linkType: soft