From 30dd65bb83a3159ca9d569af6b29aed03796056f Mon Sep 17 00:00:00 2001 From: OJ Kwon <1210596+kwonoj@users.noreply.github.com> Date: Thu, 29 Dec 2022 22:31:57 -0800 Subject: [PATCH] feat(bindings): Remove `swcx` from `@swc/core` (#6720) --- node-swc/src/run_swcx.ts | 82 ---------------------------------------- package.json | 6 +-- scripts/cli_artifacts.sh | 6 +-- yarn.lock | 2 - 4 files changed, 3 insertions(+), 93 deletions(-) delete mode 100644 node-swc/src/run_swcx.ts diff --git a/node-swc/src/run_swcx.ts b/node-swc/src/run_swcx.ts deleted file mode 100644 index 387ea7669554..000000000000 --- a/node-swc/src/run_swcx.ts +++ /dev/null @@ -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>> = { - "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)); \ No newline at end of file diff --git a/package.json b/package.json index da98f4515987..a2dfa1a0a004 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,6 @@ "description": "Super-fast alternative for babel", "homepage": "https://swc.rs", "main": "./index.js", - "bin": { - "swcx": "run_swcx.js" - }, "author": "강동윤 ", "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" -} +} \ No newline at end of file diff --git a/scripts/cli_artifacts.sh b/scripts/cli_artifacts.sh index 332e8b8a35ee..19ef8af25749 100755 --- a/scripts/cli_artifacts.sh +++ b/scripts/cli_artifacts.sh @@ -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 \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f73ef1e86455..9ebf5ed015c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2522,8 +2522,6 @@ __metadata: optional: true "@swc/core-win32-x64-msvc": optional: true - bin: - swcx: run_swcx.js languageName: unknown linkType: soft