mirror of
https://github.com/swc-project/swc.git
synced 2024-09-11 08:45:34 +03:00
refactor(bindings): Make @swc/core
a subpackage (#8625)
**Description:** This is for consistency and future extensions.
This commit is contained in:
parent
edca394374
commit
f960d52364
34
.github/workflows/CI.yml
vendored
34
.github/workflows/CI.yml
vendored
@ -146,6 +146,8 @@ jobs:
|
||||
# toolchain: stable
|
||||
# override: true
|
||||
|
||||
- run: corepack enable
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "18"
|
||||
@ -154,6 +156,7 @@ jobs:
|
||||
- name: Install node dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
corepack enable
|
||||
yarn
|
||||
|
||||
# Ensure that all components are compilable.
|
||||
@ -168,6 +171,9 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- shell: bash
|
||||
run: corepack enable
|
||||
|
||||
# We explicitly do this to cache properly.
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
@ -191,6 +197,7 @@ jobs:
|
||||
- name: Install node dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
corepack enable
|
||||
yarn
|
||||
|
||||
- name: Build
|
||||
@ -589,6 +596,8 @@ jobs:
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- run: corepack enable
|
||||
|
||||
# Source map format
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
@ -613,6 +622,7 @@ jobs:
|
||||
- name: Install node dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
corepack enable
|
||||
yarn
|
||||
# I don't want to think deeply about this
|
||||
yarn global add jest@27 mocha || \
|
||||
@ -633,7 +643,7 @@ jobs:
|
||||
- name: Verify dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
jest --version && mocha --version
|
||||
yarn jest --version && yarn mocha --version
|
||||
|
||||
- name: Configure execution cache
|
||||
shell: bash
|
||||
@ -725,8 +735,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Corepack
|
||||
shell: bash
|
||||
- shell: bash
|
||||
run: corepack enable
|
||||
|
||||
# We explicitly do this to cache properly.
|
||||
@ -735,7 +744,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
node-version: 18
|
||||
cache: "yarn"
|
||||
|
||||
- name: Patch
|
||||
@ -761,7 +770,14 @@ jobs:
|
||||
corepack enable
|
||||
yarn
|
||||
|
||||
- name: Build
|
||||
working-directory: packages/core
|
||||
run: |
|
||||
yarn build:dev
|
||||
|
||||
- name: Test
|
||||
working-directory: packages/core
|
||||
run: |
|
||||
yarn test
|
||||
|
||||
integration-test:
|
||||
@ -772,8 +788,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Corepack
|
||||
shell: bash
|
||||
- shell: bash
|
||||
run: corepack enable
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
@ -878,6 +893,9 @@ jobs:
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- shell: bash
|
||||
run: corepack enable
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "18"
|
||||
@ -885,7 +903,9 @@ jobs:
|
||||
|
||||
- name: Install node dependencies
|
||||
shell: bash
|
||||
run: yarn
|
||||
run: |
|
||||
corepack enable
|
||||
yarn
|
||||
|
||||
- name: Print rustup toolchain version
|
||||
shell: bash
|
||||
|
80
.github/workflows/publish-core.yml
vendored
80
.github/workflows/publish-core.yml
vendored
@ -1,5 +1,8 @@
|
||||
name: Publish (core)
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
env:
|
||||
DEBUG: napi:*
|
||||
APP_NAME: swc
|
||||
@ -34,8 +37,8 @@ jobs:
|
||||
- host: macos-latest
|
||||
target: x86_64-apple-darwin
|
||||
build: |
|
||||
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-apple-darwin
|
||||
cp ./bindings/target/x86_64-apple-darwin/release/swc .
|
||||
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-apple-darwin
|
||||
cp ../../bindings/target/x86_64-apple-darwin/release/swc .
|
||||
chmod +x ./swc
|
||||
yarn build --target x86_64-apple-darwin
|
||||
strip -x *.node
|
||||
@ -43,16 +46,16 @@ jobs:
|
||||
build: |
|
||||
export CARGO_PROFILE_RELEASE_LTO=false
|
||||
yarn build --target x86_64-pc-windows-msvc
|
||||
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-pc-windows-msvc
|
||||
cp ./bindings/target/x86_64-pc-windows-msvc/release/swc .
|
||||
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-pc-windows-msvc
|
||||
cp ../../bindings/target/x86_64-pc-windows-msvc/release/swc .
|
||||
target: x86_64-pc-windows-msvc
|
||||
- host: windows-latest
|
||||
# use npm to run test, because of corepack link the yarn with x64 Node.js
|
||||
build: |
|
||||
export DISABLE_PLUGIN_E2E_TESTS=true
|
||||
export CARGO_PROFILE_RELEASE_LTO=false
|
||||
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --target i686-pc-windows-msvc
|
||||
cp bindings/target/i686-pc-windows-msvc/release/swc .
|
||||
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --target i686-pc-windows-msvc
|
||||
cp ../../bindings/target/i686-pc-windows-msvc/release/swc .
|
||||
yarn build --target i686-pc-windows-msvc --no-default-features --features swc_v1
|
||||
npm run test
|
||||
target: i686-pc-windows-msvc
|
||||
@ -61,9 +64,9 @@ jobs:
|
||||
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
|
||||
build: >-
|
||||
set -e &&
|
||||
unset CC_x86_64_unknown_linux_gnu && unset CC && RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-gnu &&
|
||||
rm -rf bindings/target/target/x86_64-unknown-linux-gnu/release/.cargo-lock &&
|
||||
cp bindings/target/x86_64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
|
||||
unset CC_x86_64_unknown_linux_gnu && unset CC && RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-gnu &&
|
||||
rm -rf ../../bindings/target/target/x86_64-unknown-linux-gnu/release/.cargo-lock &&
|
||||
cp ../../bindings/target/x86_64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
|
||||
yarn build --target x86_64-unknown-linux-gnu
|
||||
- host: ubuntu-latest
|
||||
target: x86_64-unknown-linux-musl
|
||||
@ -72,9 +75,9 @@ jobs:
|
||||
build: >-
|
||||
set -e &&
|
||||
export CARGO_PROFILE_RELEASE_LTO=false &&
|
||||
RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-musl &&
|
||||
RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-musl &&
|
||||
rm -rf target/release/.cargo-lock &&
|
||||
cp bindings/target/x86_64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
|
||||
cp ../../bindings/target/x86_64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
|
||||
RUSTFLAGS='-C target-feature=+sse2 -C target-feature=-crt-static' yarn build --target x86_64-unknown-linux-musl
|
||||
- host: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
@ -84,8 +87,8 @@ jobs:
|
||||
export CXX=$(xcrun -f clang++);
|
||||
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
|
||||
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
|
||||
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-apple-darwin
|
||||
cp ./bindings/target/aarch64-apple-darwin/release/swc .
|
||||
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-apple-darwin
|
||||
cp ../../bindings/target/aarch64-apple-darwin/release/swc .
|
||||
chmod +x ./swc
|
||||
yarn build --target aarch64-apple-darwin
|
||||
- host: ubuntu-latest
|
||||
@ -95,15 +98,15 @@ jobs:
|
||||
set -e &&
|
||||
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
|
||||
rustup target add aarch64-unknown-linux-gnu &&
|
||||
RUSTFLAGS='' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-gnu &&
|
||||
cp ./bindings/target/aarch64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
|
||||
RUSTFLAGS='' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-gnu &&
|
||||
cp ../../bindings/target/aarch64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
|
||||
export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc &&
|
||||
yarn build --target aarch64-unknown-linux-gnu
|
||||
- host: ubuntu-latest
|
||||
target: armv7-unknown-linux-gnueabihf
|
||||
build: |
|
||||
export DISABLE_PLUGIN_E2E_TESTS=true
|
||||
yarn napi build --bin swc --release --target armv7-unknown-linux-gnueabihf --manifest-path ./bindings/swc_cli/Cargo.toml -x --target-dir ../release -o .
|
||||
yarn napi build --bin swc --release --target armv7-unknown-linux-gnueabihf --manifest-path ../../bindings/swc_cli/Cargo.toml -x --target-dir ../release -o .
|
||||
chmod +x ./swc
|
||||
yarn build --target armv7-unknown-linux-gnueabihf --no-default-features --features swc_v1 --use-napi-cross
|
||||
- host: ubuntu-latest
|
||||
@ -112,11 +115,11 @@ jobs:
|
||||
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
|
||||
build: >-
|
||||
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
|
||||
rustup toolchain install $(cat ./rust-toolchain) &&
|
||||
rustup toolchain install $(cat ../../rust-toolchain) &&
|
||||
rustup target add aarch64-unknown-linux-musl &&
|
||||
RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-lgcc' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-musl &&
|
||||
RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-lgcc' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-musl &&
|
||||
rm -rf target/release/.cargo-lock &&
|
||||
cp bindings/target/aarch64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
|
||||
cp ../../bindings/target/aarch64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
|
||||
env RUSTFLAGS='-C target-feature=-crt-static' yarn build --target=aarch64-unknown-linux-musl
|
||||
- host: windows-latest
|
||||
target: aarch64-pc-windows-msvc
|
||||
@ -125,8 +128,8 @@ jobs:
|
||||
export DISABLE_PLUGIN_E2E_TESTS=true
|
||||
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=256
|
||||
export CARGO_PROFILE_RELEASE_LTO=false
|
||||
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --target aarch64-pc-windows-msvc
|
||||
cp bindings/target/aarch64-pc-windows-msvc/release/swc.exe .
|
||||
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --target aarch64-pc-windows-msvc
|
||||
cp ../../bindings/target/aarch64-pc-windows-msvc/release/swc.exe .
|
||||
yarn build --target aarch64-pc-windows-msvc --no-default-features --features swc_v1
|
||||
name: stable - ${{ matrix.settings.target }} - node@20
|
||||
runs-on: ${{ matrix.settings.host }}
|
||||
@ -197,10 +200,12 @@ jobs:
|
||||
image: ${{ matrix.settings.docker }}
|
||||
options: -v ${{ env.HOME }}/.cargo/git:/root/.cargo/git -v ${{ env.HOME }}/.cargo/registry:/root/.cargo/registry -v ${{ github.workspace }}:/build -w /build
|
||||
run: >-
|
||||
cd ./packages/core &&
|
||||
corepack enable &&
|
||||
npm i -g wasm-pack &&
|
||||
${{ matrix.settings.build }}
|
||||
- name: Build
|
||||
working-directory: ./packages/core
|
||||
if: ${{ !matrix.settings.docker }}
|
||||
run: ${{ matrix.settings.build }}
|
||||
shell: bash
|
||||
@ -209,7 +214,7 @@ jobs:
|
||||
with:
|
||||
name: bindings-${{ matrix.settings.target }}
|
||||
path: |
|
||||
swc*
|
||||
packages/core/swc*
|
||||
if-no-files-found: error
|
||||
test-macOS-windows-binding:
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/ci') }}
|
||||
@ -230,6 +235,8 @@ jobs:
|
||||
runs-on: ${{ matrix.settings.host }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: corepack enable
|
||||
shell: bash
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
@ -237,18 +244,20 @@ jobs:
|
||||
cache: yarn
|
||||
architecture: x64
|
||||
- name: Install dependencies
|
||||
run: yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
|
||||
run: corepack enable && yarn install --network-timeout 300000
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: bindings-${{ matrix.settings.target }}
|
||||
path: .
|
||||
path: ./packages/core
|
||||
- name: List packages
|
||||
run: ls -R .
|
||||
shell: bash
|
||||
- name: Build TypeScript
|
||||
working-directory: ./packages/core
|
||||
run: yarn build:ts
|
||||
- name: Test bindings
|
||||
working-directory: ./packages/core
|
||||
run: yarn test
|
||||
test-linux-x64-gnu-binding:
|
||||
if: ${{ startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/ci') }}
|
||||
@ -272,12 +281,12 @@ jobs:
|
||||
node-version: ${{ matrix.node }}
|
||||
cache: yarn
|
||||
- name: Install dependencies
|
||||
run: yarn install
|
||||
run: corepack enable && yarn install
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: bindings-x86_64-unknown-linux-gnu
|
||||
path: .
|
||||
path: ./packages/core
|
||||
- name: List packages
|
||||
run: ls -R .
|
||||
shell: bash
|
||||
@ -299,6 +308,8 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: corepack enable
|
||||
shell: bash
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
@ -306,13 +317,14 @@ jobs:
|
||||
cache: yarn
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
yarn config set supportedArchitectures.libc "musl"
|
||||
yarn install
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: bindings-x86_64-unknown-linux-musl
|
||||
path: .
|
||||
path: ./packages/core
|
||||
- name: List packages
|
||||
run: ls -R .
|
||||
shell: bash
|
||||
@ -334,12 +346,13 @@ jobs:
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: bindings-aarch64-unknown-linux-musl
|
||||
path: .
|
||||
path: ./packages/core
|
||||
- name: List packages
|
||||
run: ls -R .
|
||||
shell: bash
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
yarn config set supportedArchitectures.cpu "arm64"
|
||||
yarn config set supportedArchitectures.libc "musl"
|
||||
yarn install
|
||||
@ -379,12 +392,13 @@ jobs:
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: bindings-armv7-unknown-linux-gnueabihf
|
||||
path: .
|
||||
path: ./packages/core
|
||||
- name: List packages
|
||||
run: ls -R .
|
||||
shell: bash
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
yarn config set supportedArchitectures.cpu "arm"
|
||||
yarn install
|
||||
- name: Build TypeScript
|
||||
@ -435,19 +449,20 @@ jobs:
|
||||
run: echo "NPM_TAG=nightly" >> $GITHUB_ENV
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn install
|
||||
run: corepack enable && yarn install
|
||||
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: artifacts
|
||||
path: ./packages/core/artifacts
|
||||
|
||||
- name: List binaries
|
||||
run: ls -R artifacts
|
||||
run: ls -R ./packages/core/artifacts
|
||||
shell: bash
|
||||
|
||||
- name: Move binaries
|
||||
shell: bash
|
||||
working-directory: ./packages/core
|
||||
run: |
|
||||
./scripts/cli_artifacts.sh
|
||||
ls -R ./artifacts_cli
|
||||
@ -455,6 +470,7 @@ jobs:
|
||||
|
||||
- name: List npm
|
||||
run: ls -R ./scripts/npm
|
||||
working-directory: ./packages/core
|
||||
shell: bash
|
||||
|
||||
- name: Set fallback dependencies
|
||||
|
4
.github/workflows/publish-extra-bindings.yml
vendored
4
.github/workflows/publish-extra-bindings.yml
vendored
@ -1,5 +1,9 @@
|
||||
name: Publish (extra-bindings)
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: "${{ github.event_name == 'pull_request' }}"
|
||||
|
||||
env:
|
||||
DEBUG: napi:*
|
||||
APP_NAME: swc
|
||||
|
@ -63,7 +63,6 @@ fn init_helpers() -> Arc<PathBuf> {
|
||||
}
|
||||
|
||||
let yarn = find_executable("yarn").expect("failed to find yarn");
|
||||
let npm = find_executable("npm").expect("failed to find npm");
|
||||
{
|
||||
let mut cmd = if cfg!(target_os = "windows") {
|
||||
let mut c = Command::new("cmd");
|
||||
@ -90,25 +89,6 @@ fn init_helpers() -> Arc<PathBuf> {
|
||||
assert!(status.success());
|
||||
}
|
||||
|
||||
{
|
||||
let mut cmd = if cfg!(target_os = "windows") {
|
||||
let mut c = Command::new("cmd");
|
||||
c.arg("/C").arg(&npm);
|
||||
c
|
||||
} else {
|
||||
Command::new(&npm)
|
||||
};
|
||||
cmd.current_dir(&project_root)
|
||||
.arg("install")
|
||||
.arg("--no-save")
|
||||
.arg("--no-package-lock")
|
||||
.arg("./packages/helpers");
|
||||
let status = cmd
|
||||
.status()
|
||||
.expect("failed to install helper package from root");
|
||||
assert!(status.success());
|
||||
}
|
||||
|
||||
Arc::new(helper_dir)
|
||||
});
|
||||
|
||||
|
@ -1141,7 +1141,7 @@ fn issue_8674_1() {
|
||||
|
||||
let base_url = current_dir()
|
||||
.unwrap()
|
||||
.join("../../node-swc/tests/issue-8674")
|
||||
.join("../../packages/core/tests/issue-8674")
|
||||
.canonicalize()
|
||||
.unwrap();
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
use std::{
|
||||
env, fmt,
|
||||
fmt::{Debug, Display, Formatter},
|
||||
env,
|
||||
fmt::{self, Debug, Display, Formatter},
|
||||
fs::{create_dir_all, rename, File},
|
||||
io::Write,
|
||||
path::{Component, Path, PathBuf},
|
||||
process::Command,
|
||||
str::FromStr,
|
||||
sync::RwLock,
|
||||
thread,
|
||||
@ -60,7 +61,7 @@ pub fn find_executable(name: &str) -> Option<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
let path = env::var_os("PATH").and_then(|paths| {
|
||||
let mut path = env::var_os("PATH").and_then(|paths| {
|
||||
env::split_paths(&paths)
|
||||
.filter_map(|dir| {
|
||||
let full_path = dir.join(name);
|
||||
@ -73,6 +74,28 @@ pub fn find_executable(name: &str) -> Option<PathBuf> {
|
||||
.next()
|
||||
});
|
||||
|
||||
if path.is_none() {
|
||||
// Run yarn bin $name
|
||||
|
||||
path = Command::new("yarn")
|
||||
.arg("bin")
|
||||
.arg(name)
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|output| {
|
||||
if output.status.success() {
|
||||
let path = String::from_utf8(output.stdout).ok()?;
|
||||
let path = path.trim();
|
||||
let path = PathBuf::from(path);
|
||||
if path.is_file() {
|
||||
return Some(path);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(path) = path.clone() {
|
||||
let mut locked = CACHE.write().unwrap();
|
||||
locked.insert(name.to_string(), path);
|
||||
|
20
node-swc/__tests__/env/env_test.js
vendored
20
node-swc/__tests__/env/env_test.js
vendored
@ -1,20 +0,0 @@
|
||||
const swc = require("../../../");
|
||||
const path = require("path");
|
||||
|
||||
// it("should handle browserslistrc", () => {
|
||||
// const filename = path.resolve(
|
||||
// __dirname + "/../../tests/env/default/input.js"
|
||||
// );
|
||||
// expect(swc.transformFileSync(filename).code.trim()).toContain(
|
||||
// `const a of foo`
|
||||
// );
|
||||
// });
|
||||
|
||||
it("should handle targets in env", () => {
|
||||
const filename = path.resolve(
|
||||
__dirname + "/../../tests/env/targets/input.js"
|
||||
);
|
||||
expect(swc.transformFileSync(filename).code.trim()).toContain(
|
||||
`const a of foo`
|
||||
);
|
||||
});
|
@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
it('should work', () => {
|
||||
require('../../')
|
||||
})
|
@ -1,16 +0,0 @@
|
||||
const swc = require("../../");
|
||||
|
||||
it("should detect script", () => {
|
||||
const script = swc.parseSync(`const fs = require('fs');`, { isModule: "unknown" });
|
||||
expect(script.type).toBe("Script");
|
||||
});
|
||||
|
||||
it("should default to isModule: true", () => {
|
||||
const script = swc.parseSync(`foo;`, {});
|
||||
expect(script.type).toBe("Module");
|
||||
});
|
||||
|
||||
it("should detect module", () => {
|
||||
const script = swc.parseSync(`import fs from "fs";`, { isModule: "unknown" });
|
||||
expect(script.type).toBe("Module");
|
||||
});
|
@ -1,31 +0,0 @@
|
||||
const swc = require("../../../");
|
||||
|
||||
it("should work asynchronously", async () => {
|
||||
const m = await swc.parse(`class Foo {}`);
|
||||
|
||||
expect(m.type).toBe(`Module`);
|
||||
expect(m.body).toHaveLength(1);
|
||||
expect(m.body[0].type).toBe(`ClassDeclaration`);
|
||||
});
|
||||
|
||||
it("can work synchronously", () => {
|
||||
const m = swc.parseSync(`class Foo {}`);
|
||||
|
||||
expect(m.type).toBe(`Module`);
|
||||
expect(m.body).toHaveLength(1);
|
||||
expect(m.body[0].type).toBe(`ClassDeclaration`);
|
||||
});
|
||||
|
||||
it("can be emit code back asynchronously", async () => {
|
||||
const m = await swc.parse(`class Foo {}`);
|
||||
const out = await swc.print(m);
|
||||
|
||||
expect(out.code.trim().replace("\n", "")).toBe(`class Foo {}`);
|
||||
});
|
||||
|
||||
it("can be emit code back synchronously", async () => {
|
||||
const m = await swc.parseSync(`class Foo {}`);
|
||||
const out = swc.printSync(m);
|
||||
|
||||
expect(out.code.trim().replace("\n", "")).toBe(`class Foo {}`);
|
||||
});
|
@ -1,22 +0,0 @@
|
||||
const swc = require("../../");
|
||||
|
||||
it("should handle script", () => {
|
||||
const script = swc.transformSync(`foo;`, { isModule: false });
|
||||
expect(script.code.trim()).toBe(`foo;`);
|
||||
});
|
||||
|
||||
it("should parse as script if required", () => {
|
||||
const script = swc.parseSync(`foo;`, { isModule: false });
|
||||
expect(script.type).toBe("Script");
|
||||
|
||||
const out = swc.printSync(script);
|
||||
expect(out.code.trim()).toBe(`foo;`);
|
||||
});
|
||||
|
||||
it("should parse as module if required", () => {
|
||||
const m = swc.parseSync(`foo;`);
|
||||
expect(m.type).toBe("Module");
|
||||
|
||||
const out = swc.printSync(m);
|
||||
expect(out.code.trim()).toBe(`foo;`);
|
||||
});
|
@ -1,47 +0,0 @@
|
||||
const swc = require("../../../");
|
||||
|
||||
it("should hoist methods", () => {
|
||||
const src = 'console.log("Hello"); jest.mock(); console.log("World")';
|
||||
|
||||
expect(
|
||||
swc.transformSync(src, {
|
||||
jsc: {
|
||||
transform: {
|
||||
hidden: {
|
||||
jest: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.code.trim()
|
||||
).toBe(`jest.mock();
|
||||
console.log(\"Hello\");
|
||||
console.log(\"World\");`);
|
||||
});
|
||||
|
||||
|
||||
it("should preserve calls", () => {
|
||||
const src = `class Foo {
|
||||
method() {
|
||||
super.foo()
|
||||
}
|
||||
}`;
|
||||
|
||||
expect(
|
||||
swc.transformSync(src, {
|
||||
jsc: {
|
||||
transform: {
|
||||
hidden: {
|
||||
jest: true
|
||||
}
|
||||
},
|
||||
target: 'es2019'
|
||||
}
|
||||
})
|
||||
.code.trim()
|
||||
).toBe(`class Foo {
|
||||
method() {
|
||||
super.foo();
|
||||
}
|
||||
}`);
|
||||
});
|
@ -1,29 +0,0 @@
|
||||
const swc = require('../../../');
|
||||
|
||||
it('should work without parser.syntax', () => {
|
||||
const out = swc.transformSync(`const someValue = "test" ?? "default value";`, {
|
||||
jsc: {
|
||||
parser: {
|
||||
nullishCoalescing: true,
|
||||
numericSeparator: true
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(out.map).toBeFalsy();
|
||||
});
|
||||
|
||||
|
||||
it('should work with parser.syntax', () => {
|
||||
const out = swc.transformSync(`const someValue = "test" ?? "default value";`, {
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: 'ecmascript',
|
||||
nullishCoalescing: true,
|
||||
numericSeparator: true
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
expect(out.map).toBeFalsy();
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
const swc = require('../../../');
|
||||
|
||||
|
||||
it("should handle es2019", () => {
|
||||
expect(
|
||||
swc.transformSync(`class SomeClass {
|
||||
someMethod() {}
|
||||
}
|
||||
|
||||
class OtherClass extends SomeClass {
|
||||
anotherMethod() {
|
||||
super.someMethod()
|
||||
}
|
||||
}`, {
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: "ecmascript",
|
||||
},
|
||||
target: "es2019",
|
||||
}
|
||||
})
|
||||
.code.trim()
|
||||
).toContain(`class `);
|
||||
});
|
@ -1,22 +0,0 @@
|
||||
const swc = require('../../..');
|
||||
|
||||
|
||||
it("should handle es2019", () => {
|
||||
expect(
|
||||
swc.transformSync(`
|
||||
class Foo {
|
||||
method() {
|
||||
class Foo {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {
|
||||
jsc: {
|
||||
keepClassNames: true,
|
||||
target: 'es2017',
|
||||
}
|
||||
})
|
||||
.code.trim()
|
||||
).toContain(`let Foo = class Foo {`);
|
||||
});
|
@ -1,14 +0,0 @@
|
||||
[workspace]
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "plugin_transform_schema_vtest"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.140"
|
||||
swc_core = { path = "../../../../crates/swc_core", features = ["__plugin_transform_schema_test"] }
|
File diff suppressed because it is too large
Load Diff
49
node-swc/src/binding.d.ts
vendored
49
node-swc/src/binding.d.ts
vendored
@ -1,49 +0,0 @@
|
||||
/* auto-generated by NAPI-RS */
|
||||
/* eslint-disable */
|
||||
|
||||
export class Compiler {
|
||||
constructor()
|
||||
}
|
||||
export type JsCompiler = Compiler
|
||||
|
||||
export function bundle(confItems: Buffer, signal?: AbortSignal | undefined | null): Promise<{ [index: string]: { code: string, map?: string } }>
|
||||
|
||||
export function getTargetTriple(): string
|
||||
|
||||
export function initCustomTraceSubscriber(traceOutFilePath?: string | undefined | null): void
|
||||
|
||||
export function minify(code: Buffer, opts: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
|
||||
|
||||
export function minifySync(code: Buffer, opts: Buffer): TransformOutput
|
||||
|
||||
export function parse(src: string, options: Buffer, filename?: string | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
|
||||
|
||||
export function parseFile(path: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<string>
|
||||
|
||||
export function parseFileSync(path: string, opts: Buffer): string
|
||||
|
||||
export function parseSync(src: string, opts: Buffer, filename?: string | undefined | null): string
|
||||
|
||||
export function print(programJson: string, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
|
||||
|
||||
export function printSync(program: string, options: Buffer): TransformOutput
|
||||
|
||||
export function transform(src: string, isModule: boolean, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
|
||||
|
||||
export function transformFile(src: string, isModule: boolean, options: Buffer, signal?: AbortSignal | undefined | null): Promise<TransformOutput>
|
||||
|
||||
export function transformFileSync(s: string, isModule: boolean, opts: Buffer): TransformOutput
|
||||
|
||||
export interface TransformOutput {
|
||||
code: string
|
||||
map?: string
|
||||
}
|
||||
|
||||
/** Hack for `Type Generation` */
|
||||
export interface TransformOutput {
|
||||
code: string
|
||||
map?: string
|
||||
}
|
||||
|
||||
export function transformSync(s: string, isModule: boolean, opts: Buffer): TransformOutput
|
||||
|
@ -1,354 +0,0 @@
|
||||
// prettier-ignore
|
||||
/* eslint-disable */
|
||||
/* auto-generated by NAPI-RS */
|
||||
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
let nativeBinding = null
|
||||
const loadErrors = []
|
||||
|
||||
const isMusl = () => {
|
||||
let musl = false
|
||||
if (process.platform === 'linux') {
|
||||
musl = isMuslFromFilesystem()
|
||||
if (musl === null) {
|
||||
musl = isMuslFromReport()
|
||||
}
|
||||
if (musl === null) {
|
||||
musl = isMuslFromChildProcess()
|
||||
}
|
||||
}
|
||||
return musl
|
||||
}
|
||||
|
||||
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
||||
|
||||
const isMuslFromFilesystem = () => {
|
||||
try {
|
||||
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const isMuslFromReport = () => {
|
||||
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
|
||||
if (!report) {
|
||||
return null
|
||||
}
|
||||
if (report.header && report.header.glibcVersionRuntime) {
|
||||
return false
|
||||
}
|
||||
if (Array.isArray(report.sharedObjects)) {
|
||||
if (report.sharedObjects.some(isFileMusl)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const isMuslFromChildProcess = () => {
|
||||
try {
|
||||
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
||||
} catch (e) {
|
||||
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function requireNative() {
|
||||
if (process.platform === 'android') {
|
||||
if (process.arch === 'arm64') {
|
||||
try {
|
||||
return require('./swc.android-arm64.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-android-arm64')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else if (process.arch === 'arm') {
|
||||
try {
|
||||
return require('./swc.android-arm-eabi.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-android-arm-eabi')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
||||
}
|
||||
} else if (process.platform === 'win32') {
|
||||
if (process.arch === 'x64') {
|
||||
try {
|
||||
return require('./swc.win32-x64-msvc.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-win32-x64-msvc')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else if (process.arch === 'ia32') {
|
||||
try {
|
||||
return require('./swc.win32-ia32-msvc.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-win32-ia32-msvc')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else if (process.arch === 'arm64') {
|
||||
try {
|
||||
return require('./swc.win32-arm64-msvc.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-win32-arm64-msvc')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
||||
}
|
||||
} else if (process.platform === 'darwin') {
|
||||
try {
|
||||
return require('./swc.darwin-universal.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-darwin-universal')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
if (process.arch === 'x64') {
|
||||
try {
|
||||
return require('./swc.darwin-x64.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-darwin-x64')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else if (process.arch === 'arm64') {
|
||||
try {
|
||||
return require('./swc.darwin-arm64.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-darwin-arm64')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
||||
}
|
||||
} else if (process.platform === 'freebsd') {
|
||||
if (process.arch === 'x64') {
|
||||
try {
|
||||
return require('./swc.freebsd-x64.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-freebsd-x64')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else if (process.arch === 'arm64') {
|
||||
try {
|
||||
return require('./swc.freebsd-arm64.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-freebsd-arm64')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
||||
}
|
||||
} else if (process.platform === 'linux') {
|
||||
if (process.arch === 'x64') {
|
||||
if (isMusl()) {
|
||||
try {
|
||||
return require('./swc.linux-x64-musl.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-x64-musl')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
return require('./swc.linux-x64-gnu.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-x64-gnu')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
}
|
||||
} else if (process.arch === 'arm64') {
|
||||
if (isMusl()) {
|
||||
try {
|
||||
return require('./swc.linux-arm64-musl.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-arm64-musl')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
return require('./swc.linux-arm64-gnu.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-arm64-gnu')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
}
|
||||
} else if (process.arch === 'arm') {
|
||||
try {
|
||||
return require('./swc.linux-arm-gnueabihf.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-arm-gnueabihf')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else if (process.arch === 'riscv64') {
|
||||
if (isMusl()) {
|
||||
try {
|
||||
return require('./swc.linux-riscv64-musl.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-riscv64-musl')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
return require('./swc.linux-riscv64-gnu.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-riscv64-gnu')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
}
|
||||
} else if (process.arch === 's390x') {
|
||||
try {
|
||||
return require('./swc.linux-s390x-gnu.node')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
try {
|
||||
return require('@swc/core-linux-s390x-gnu')
|
||||
} catch (e) {
|
||||
loadErrors.push(e)
|
||||
}
|
||||
|
||||
} else {
|
||||
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
||||
}
|
||||
}
|
||||
|
||||
nativeBinding = requireNative()
|
||||
|
||||
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
||||
try {
|
||||
nativeBinding = require('./swc.wasi.cjs')
|
||||
} catch (err) {
|
||||
if (process.env.NAPI_RS_FORCE_WASI) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
if (!nativeBinding) {
|
||||
try {
|
||||
nativeBinding = require('@swc/core-wasm32-wasi')
|
||||
} catch (err) {
|
||||
if (process.env.NAPI_RS_FORCE_WASI) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nativeBinding) {
|
||||
if (loadErrors.length > 0) {
|
||||
// TODO Link to documentation with potential fixes
|
||||
// - The package owner could build/publish bindings for this arch
|
||||
// - The user may need to bundle the correct files
|
||||
// - The user may need to re-install node_modules to get new packages
|
||||
throw new Error('Failed to load native binding', { cause: loadErrors })
|
||||
}
|
||||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
module.exports.Compiler = nativeBinding.Compiler
|
||||
module.exports.JsCompiler = nativeBinding.JsCompiler
|
||||
module.exports.bundle = nativeBinding.bundle
|
||||
module.exports.getTargetTriple = nativeBinding.getTargetTriple
|
||||
module.exports.initCustomTraceSubscriber = nativeBinding.initCustomTraceSubscriber
|
||||
module.exports.minify = nativeBinding.minify
|
||||
module.exports.minifySync = nativeBinding.minifySync
|
||||
module.exports.parse = nativeBinding.parse
|
||||
module.exports.parseFile = nativeBinding.parseFile
|
||||
module.exports.parseFileSync = nativeBinding.parseFileSync
|
||||
module.exports.parseSync = nativeBinding.parseSync
|
||||
module.exports.print = nativeBinding.print
|
||||
module.exports.printSync = nativeBinding.printSync
|
||||
module.exports.transform = nativeBinding.transform
|
||||
module.exports.transformFile = nativeBinding.transformFile
|
||||
module.exports.transformFileSync = nativeBinding.transformFileSync
|
||||
module.exports.transformSync = nativeBinding.transformSync
|
@ -1,479 +0,0 @@
|
||||
import { resolve } from "path";
|
||||
import type {
|
||||
Plugin,
|
||||
ParseOptions,
|
||||
Module,
|
||||
Output,
|
||||
Options,
|
||||
Script,
|
||||
Program,
|
||||
JsMinifyOptions,
|
||||
} from "@swc/types";
|
||||
export * from "@swc/types";
|
||||
import { BundleInput, compileBundleOptions } from "./spack";
|
||||
import * as assert from "assert";
|
||||
|
||||
// Allow overrides to the location of the .node binding file
|
||||
const bindingsOverride = process.env["SWC_BINARY_PATH"];
|
||||
// `@swc/core` includes d.ts for the `@swc/wasm` to provide typed fallback bindings
|
||||
// todo: fix package.json scripts
|
||||
let fallbackBindings: any;
|
||||
const bindings: typeof import('./binding') = (() => {
|
||||
let binding
|
||||
try {
|
||||
binding = !!bindingsOverride ? require(resolve(bindingsOverride)) : require('./binding')
|
||||
|
||||
// If native binding loaded successfully, it should return proper target triple constant.
|
||||
const triple = binding.getTargetTriple();
|
||||
assert.ok(triple, 'Failed to read target triple from native binary.');
|
||||
return binding;
|
||||
} catch (_) {
|
||||
// postinstall supposed to install `@swc/wasm` already
|
||||
fallbackBindings = require('@swc/wasm');
|
||||
} finally {
|
||||
return binding;
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Version of the swc binding.
|
||||
*/
|
||||
export const version: string = require("./package.json").version;
|
||||
|
||||
/**
|
||||
* @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
|
||||
*/
|
||||
export function plugins(ps: Plugin[]): Plugin {
|
||||
return mod => {
|
||||
let m = mod;
|
||||
for (const p of ps) {
|
||||
m = p(m);
|
||||
}
|
||||
return m;
|
||||
};
|
||||
}
|
||||
|
||||
export class Compiler {
|
||||
private fallbackBindingsPluginWarningDisplayed = false;
|
||||
|
||||
async minify(src: string, opts?: JsMinifyOptions): Promise<Output> {
|
||||
if (bindings) {
|
||||
return bindings.minify(toBuffer(src), toBuffer(opts ?? {}));
|
||||
} else if (fallbackBindings) {
|
||||
return fallbackBindings.minify(src, opts);
|
||||
}
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
minifySync(src: string, opts?: JsMinifyOptions): Output {
|
||||
if (bindings) {
|
||||
return bindings.minifySync(toBuffer(src), toBuffer(opts ?? {}));
|
||||
} else if (fallbackBindings) {
|
||||
return fallbackBindings.minifySync(src, opts);
|
||||
}
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
parse(
|
||||
src: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Promise<Script>;
|
||||
parse(src: string, options?: ParseOptions, filename?: string): Promise<Module>;
|
||||
async parse(src: string, options?: ParseOptions, filename?: string): Promise<Program> {
|
||||
options = options || { syntax: "ecmascript" };
|
||||
options.syntax = options.syntax || "ecmascript";
|
||||
|
||||
if (!bindings && !!fallbackBindings) {
|
||||
throw new Error('Fallback bindings does not support this interface yet.');
|
||||
} else if (!bindings) {
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
if (bindings) {
|
||||
const res = await bindings.parse(src, toBuffer(options), filename);
|
||||
return JSON.parse(res);
|
||||
} else if (fallbackBindings) {
|
||||
return fallbackBindings.parse(src, options);
|
||||
}
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
parseSync(src: string, options: ParseOptions & { isModule: false }): Script;
|
||||
parseSync(src: string, options?: ParseOptions, filename?: string): Module;
|
||||
parseSync(src: string, options?: ParseOptions, filename?: string): Program {
|
||||
options = options || { syntax: "ecmascript" };
|
||||
options.syntax = options.syntax || "ecmascript";
|
||||
|
||||
if (bindings) {
|
||||
return JSON.parse(bindings.parseSync(src, toBuffer(options), filename));
|
||||
} else if (fallbackBindings) {
|
||||
return fallbackBindings.parseSync(src, options);
|
||||
}
|
||||
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
parseFile(
|
||||
path: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Promise<Script>;
|
||||
parseFile(path: string, options?: ParseOptions): Promise<Module>;
|
||||
async parseFile(path: string, options?: ParseOptions): Promise<Program> {
|
||||
options = options || { syntax: "ecmascript" };
|
||||
options.syntax = options.syntax || "ecmascript";
|
||||
|
||||
if (!bindings && !!fallbackBindings) {
|
||||
throw new Error('Fallback bindings does not support filesystem access.');
|
||||
} else if (!bindings) {
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
const res = await bindings.parseFile(path, toBuffer(options));
|
||||
|
||||
return JSON.parse(res);
|
||||
}
|
||||
|
||||
parseFileSync(
|
||||
path: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Script;
|
||||
parseFileSync(path: string, options?: ParseOptions): Module;
|
||||
parseFileSync(path: string, options?: ParseOptions): Program {
|
||||
options = options || { syntax: "ecmascript" };
|
||||
options.syntax = options.syntax || "ecmascript";
|
||||
|
||||
if (!bindings && !!fallbackBindings) {
|
||||
throw new Error('Fallback bindings does not support filesystem access');
|
||||
} else if (!bindings) {
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
return JSON.parse(bindings.parseFileSync(path, toBuffer(options)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this method should be invoked on the compiler instance used
|
||||
* for `parse()` / `parseSync()`.
|
||||
*/
|
||||
async print(m: Program, options?: Options): Promise<Output> {
|
||||
options = options || {};
|
||||
|
||||
if (bindings) {
|
||||
return bindings.print(JSON.stringify(m), toBuffer(options))
|
||||
} else if (fallbackBindings) {
|
||||
return fallbackBindings.print(m, options);
|
||||
}
|
||||
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this method should be invoked on the compiler instance used
|
||||
* for `parse()` / `parseSync()`.
|
||||
*/
|
||||
printSync(m: Program, options?: Options): Output {
|
||||
options = options || {};
|
||||
|
||||
if (bindings) {
|
||||
return bindings.printSync(JSON.stringify(m), toBuffer(options));
|
||||
} else if (fallbackBindings) {
|
||||
return fallbackBindings.printSync(m, options);
|
||||
}
|
||||
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
async transform(src: string | Program, options?: Options): Promise<Output> {
|
||||
const isModule = typeof src !== "string";
|
||||
options = options || {};
|
||||
|
||||
if (options?.jsc?.parser) {
|
||||
options.jsc.parser.syntax = options.jsc.parser.syntax ?? 'ecmascript';
|
||||
}
|
||||
|
||||
const { plugin, ...newOptions } = options;
|
||||
|
||||
if (bindings) {
|
||||
if (plugin) {
|
||||
const m =
|
||||
typeof src === "string"
|
||||
? await this.parse(src, options?.jsc?.parser, options.filename)
|
||||
: src;
|
||||
return this.transform(plugin(m), newOptions);
|
||||
}
|
||||
|
||||
return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions))
|
||||
} else if (fallbackBindings) {
|
||||
if (plugin && !this.fallbackBindingsPluginWarningDisplayed) {
|
||||
console.warn(`Fallback bindings does not support legacy plugins, it'll be ignored.`);
|
||||
this.fallbackBindingsPluginWarningDisplayed = true;
|
||||
}
|
||||
|
||||
return fallbackBindings.transform(src, options);
|
||||
}
|
||||
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
transformSync(src: string | Program, options?: Options): Output {
|
||||
const isModule = typeof src !== "string";
|
||||
options = options || {};
|
||||
|
||||
if (options?.jsc?.parser) {
|
||||
options.jsc.parser.syntax = options.jsc.parser.syntax ?? 'ecmascript';
|
||||
}
|
||||
|
||||
const { plugin, ...newOptions } = options;
|
||||
|
||||
if (bindings) {
|
||||
if (plugin) {
|
||||
const m =
|
||||
typeof src === "string" ? this.parseSync(src, options?.jsc?.parser, options.filename) : src;
|
||||
return this.transformSync(plugin(m), newOptions);
|
||||
}
|
||||
|
||||
return bindings.transformSync(
|
||||
isModule ? JSON.stringify(src) : src,
|
||||
isModule,
|
||||
toBuffer(newOptions),
|
||||
)
|
||||
} else if (fallbackBindings) {
|
||||
if (plugin && !this.fallbackBindingsPluginWarningDisplayed) {
|
||||
console.warn(`Fallback bindings does not support legacy plugins, it'll be ignored.`);
|
||||
this.fallbackBindingsPluginWarningDisplayed = true;
|
||||
}
|
||||
return fallbackBindings.transformSync(isModule ? JSON.stringify(src) : src, options);
|
||||
}
|
||||
|
||||
throw new Error("Bindings not found");
|
||||
}
|
||||
|
||||
async transformFile(path: string, options?: Options): Promise<Output> {
|
||||
if (!bindings && !!fallbackBindings) {
|
||||
throw new Error('Fallback bindings does not support filesystem access.');
|
||||
} else if (!bindings) {
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (options?.jsc?.parser) {
|
||||
options.jsc.parser.syntax = options.jsc.parser.syntax ?? 'ecmascript';
|
||||
}
|
||||
|
||||
const { plugin, ...newOptions } = options;
|
||||
newOptions.filename = path;
|
||||
|
||||
if (plugin) {
|
||||
const m = await this.parseFile(path, options?.jsc?.parser);
|
||||
return this.transform(plugin(m), newOptions);
|
||||
}
|
||||
|
||||
return bindings.transformFile(path, false, toBuffer(newOptions))
|
||||
}
|
||||
|
||||
transformFileSync(path: string, options?: Options): Output {
|
||||
if (!bindings && !!fallbackBindings) {
|
||||
throw new Error('Fallback bindings does not support filesystem access.');
|
||||
} else if (!bindings) {
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (options?.jsc?.parser) {
|
||||
options.jsc.parser.syntax = options.jsc.parser.syntax ?? 'ecmascript';
|
||||
}
|
||||
|
||||
const { plugin, ...newOptions } = options;
|
||||
newOptions.filename = path;
|
||||
|
||||
if (plugin) {
|
||||
const m = this.parseFileSync(path, options?.jsc?.parser);
|
||||
return this.transformSync(plugin(m), newOptions);
|
||||
}
|
||||
|
||||
return bindings.transformFileSync(path, /* isModule */ false, toBuffer(newOptions));
|
||||
}
|
||||
|
||||
|
||||
async bundle(options?: BundleInput | string): Promise<{ [name: string]: Output }> {
|
||||
if (!bindings && !!fallbackBindings) {
|
||||
throw new Error('Fallback bindings does not support this interface yet.');
|
||||
} else if (!bindings) {
|
||||
throw new Error('Bindings not found.');
|
||||
}
|
||||
|
||||
const opts = await compileBundleOptions(options);
|
||||
|
||||
if (Array.isArray(opts)) {
|
||||
const all = await Promise.all(opts.map(async (opt) => {
|
||||
return this.bundle(opt)
|
||||
}));
|
||||
let obj = {} as any;
|
||||
for (const o of all) {
|
||||
obj = {
|
||||
...obj,
|
||||
...o,
|
||||
};
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
return bindings.bundle(toBuffer({
|
||||
...opts,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
const compiler = new Compiler();
|
||||
|
||||
export function parse(
|
||||
src: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Promise<Script>;
|
||||
export function parse(src: string, options?: ParseOptions): Promise<Module>;
|
||||
export function parse(src: string, options?: ParseOptions): Promise<Program> {
|
||||
return compiler.parse(src, options);
|
||||
}
|
||||
|
||||
export function parseSync(
|
||||
src: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Script;
|
||||
export function parseSync(src: string, options?: ParseOptions): Module;
|
||||
export function parseSync(src: string, options?: ParseOptions): Program {
|
||||
return compiler.parseSync(src, options);
|
||||
}
|
||||
|
||||
export function parseFile(
|
||||
path: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Promise<Script>;
|
||||
export function parseFile(
|
||||
path: string,
|
||||
options?: ParseOptions
|
||||
): Promise<Module>;
|
||||
export function parseFile(
|
||||
path: string,
|
||||
options?: ParseOptions
|
||||
): Promise<Program> {
|
||||
return compiler.parseFile(path, options);
|
||||
}
|
||||
|
||||
export function parseFileSync(
|
||||
path: string,
|
||||
options: ParseOptions & { isModule: false }
|
||||
): Script;
|
||||
export function parseFileSync(path: string, options?: ParseOptions): Module;
|
||||
export function parseFileSync(path: string, options?: ParseOptions): Program {
|
||||
return compiler.parseFileSync(path, options);
|
||||
}
|
||||
|
||||
export function print(m: Program, options?: Options): Promise<Output> {
|
||||
return compiler.print(m, options);
|
||||
}
|
||||
|
||||
export function printSync(m: Program, options?: Options): Output {
|
||||
return compiler.printSync(m, options);
|
||||
}
|
||||
|
||||
export function transform(
|
||||
src: string | Program,
|
||||
options?: Options
|
||||
): Promise<Output> {
|
||||
return compiler.transform(src, options);
|
||||
}
|
||||
|
||||
export function transformSync(
|
||||
src: string | Program,
|
||||
options?: Options
|
||||
): Output {
|
||||
return compiler.transformSync(src, options);
|
||||
}
|
||||
|
||||
export function transformFile(
|
||||
path: string,
|
||||
options?: Options
|
||||
): Promise<Output> {
|
||||
return compiler.transformFile(path, options);
|
||||
}
|
||||
|
||||
export function transformFileSync(path: string, options?: Options): Output {
|
||||
return compiler.transformFileSync(path, options);
|
||||
}
|
||||
|
||||
export function bundle(
|
||||
options?: BundleInput | string
|
||||
): Promise<{ [name: string]: Output }> {
|
||||
return compiler.bundle(options)
|
||||
}
|
||||
|
||||
export async function minify(src: string, opts?: JsMinifyOptions): Promise<Output> {
|
||||
return compiler.minify(src, opts);
|
||||
}
|
||||
|
||||
export function minifySync(src: string, opts?: JsMinifyOptions): Output {
|
||||
return compiler.minifySync(src, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure custom trace configuration runs for a process lifecycle.
|
||||
* Currently only chromium's trace event format is supported.
|
||||
* (https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview)
|
||||
*
|
||||
* This should be called before calling any binding interfaces exported in `@swc/core`, such as
|
||||
* `transform*`, or `parse*` or anything. To avoid breaking changes, each binding fn internally
|
||||
* sets default trace subscriber if not set.
|
||||
*
|
||||
* Unlike other configuration, this does not belong to individual api surface using swcrc
|
||||
* or api's parameters (`transform(..., {trace})`). This is due to current tracing subscriber
|
||||
* can be configured only once for the global scope. Calling `registerGlobalTraceConfig` multiple
|
||||
* time won't cause error, subsequent calls will be ignored.
|
||||
*
|
||||
* As name implies currently this is experimental interface may change over time without semver
|
||||
* major breaking changes. Please provide feedbacks,
|
||||
* or bug report at https://github.com/swc-project/swc/discussions.
|
||||
*/
|
||||
export function __experimental_registerGlobalTraceConfig(traceConfig: {
|
||||
type: 'traceEvent',
|
||||
fileName?: string
|
||||
}) {
|
||||
// Do not raise error if binding doesn't exists - fallback binding will not support
|
||||
// this ever.
|
||||
if (bindings) {
|
||||
if (traceConfig.type === 'traceEvent') {
|
||||
bindings.initCustomTraceSubscriber(traceConfig.fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*
|
||||
* Returns current binary's metadata to determine which binary is actually loaded.
|
||||
*
|
||||
* This is undocumented interface, does not guarantee stability across `@swc/core`'s semver
|
||||
* as internal representation may change anytime. Use it with caution.
|
||||
*/
|
||||
export function getBinaryMetadata() {
|
||||
return {
|
||||
target: bindings ? bindings?.getTargetTriple() : undefined
|
||||
};
|
||||
}
|
||||
|
||||
export const DEFAULT_EXTENSIONS = Object.freeze([
|
||||
".js",
|
||||
".jsx",
|
||||
".es6",
|
||||
".es",
|
||||
".mjs",
|
||||
".ts",
|
||||
".tsx",
|
||||
".cts",
|
||||
".mts"
|
||||
]);
|
||||
|
||||
function toBuffer(t: any): Buffer {
|
||||
return Buffer.from(JSON.stringify(t))
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
/**
|
||||
* A postinstall script runs after `@swc/core` is installed.
|
||||
*
|
||||
* It checks if corresponding optional dependencies for native binary is installed and can be loaded properly.
|
||||
* If it fails, it'll internally try to install `@swc/wasm` as fallback.
|
||||
*/
|
||||
import { existsSync } from "fs";
|
||||
import * as assert from "assert";
|
||||
import * as path from "path";
|
||||
import * as child_process from "child_process";
|
||||
import * as fs from "fs";
|
||||
|
||||
function removeRecursive(dir: string): void {
|
||||
for (const entry of fs.readdirSync(dir)) {
|
||||
const entryPath = path.join(dir, entry);
|
||||
let stats;
|
||||
try {
|
||||
stats = fs.lstatSync(entryPath);
|
||||
} catch {
|
||||
continue; // Guard against https://github.com/nodejs/node/issues/4760
|
||||
}
|
||||
if (stats.isDirectory()) removeRecursive(entryPath);
|
||||
else fs.unlinkSync(entryPath);
|
||||
}
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to validate @swc/core's native binary installation, then installs if it is not supported.
|
||||
*/
|
||||
const validateBinary = async () => {
|
||||
try {
|
||||
const { name } = require(path.resolve(process.env.INIT_CWD!, 'package.json'));
|
||||
if (name === '@swc/core') {
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: We do not take care of the case if user try to install with `--no-optional`.
|
||||
// For now, it is considered as deliberate decision.
|
||||
let binding
|
||||
try {
|
||||
binding = require('./binding');
|
||||
|
||||
// Check if binding binary actually works.
|
||||
// For the latest version, checks target triple. If it's old version doesn't have target triple, use parseSync instead.
|
||||
const triple = binding.getTargetTriple ? binding.getTargetTriple() : binding.parseSync('console.log()', Buffer.from(JSON.stringify({ syntax: "ecmascript" })));
|
||||
assert.ok(triple, 'Failed to read target triple from native binary.');
|
||||
} catch (error: any) {
|
||||
// if error is unsupported architecture, ignore to display.
|
||||
if (!error.message?.includes('Unsupported architecture')) {
|
||||
console.warn(error);
|
||||
}
|
||||
|
||||
console.warn(`@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead.`)
|
||||
}
|
||||
|
||||
if (!!binding) {
|
||||
return;
|
||||
}
|
||||
|
||||
// User choose to override the binary installation. Skip remanining validation.
|
||||
if (!!process.env["SWC_BINARY_PATH"]) {
|
||||
console.warn(
|
||||
`@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation.`)
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if top-level package.json installs @swc/wasm separately already
|
||||
let wasmBinding;
|
||||
try {
|
||||
wasmBinding = require.resolve(`@swc/wasm`);
|
||||
} catch (_) {
|
||||
|
||||
}
|
||||
|
||||
if (!!wasmBinding && existsSync(wasmBinding)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const env = { ...process.env, npm_config_global: undefined };
|
||||
const { version } = require(path.join(path.dirname(require.resolve('@swc/core')), 'package.json'));
|
||||
|
||||
// We want to place @swc/wasm next to the @swc/core as if normal installation was done,
|
||||
// but can't directly set cwd to INIT_CWD as npm seems to acquire lock to the working dir.
|
||||
// Instead, create a temporary inner and move it out.
|
||||
const coreDir = path.dirname(require.resolve('@swc/core'));
|
||||
const installDir = path.join(coreDir, 'npm-install');
|
||||
|
||||
try {
|
||||
fs.mkdirSync(installDir);
|
||||
fs.writeFileSync(path.join(installDir, 'package.json'), '{}');
|
||||
|
||||
// Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`,
|
||||
// assume & relies on system's npm installation.
|
||||
child_process.execSync(`npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@${version}`,
|
||||
{ cwd: installDir, stdio: 'pipe', env });
|
||||
|
||||
const installedBinPath = path.join(installDir, 'node_modules', `@swc/wasm`);
|
||||
// INIT_CWD is injected via npm. If it doesn't exists, can't proceed.
|
||||
fs.renameSync(installedBinPath, path.resolve(process.env.INIT_CWD!, 'node_modules', `@swc/wasm`));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
console.error(
|
||||
`Failed to install fallback @swc/wasm@${version}. @swc/core will not properly.
|
||||
Please install @swc/wasm manually, or retry whole installation.
|
||||
If there are unexpected errors, please report at https://github.com/swc-project/swc/issues`);
|
||||
} finally {
|
||||
try {
|
||||
removeRecursive(installDir);
|
||||
} catch (_) {
|
||||
// Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
validateBinary().catch((error) => {
|
||||
// for now just throw the error as-is.
|
||||
throw error;
|
||||
});
|
150
package.json
150
package.json
@ -1,86 +1,16 @@
|
||||
{
|
||||
"name": "@swc/core",
|
||||
"version": "1.5.8-nightly-20240516.2",
|
||||
"description": "Super-fast alternative for babel",
|
||||
"homepage": "https://swc.rs",
|
||||
"main": "./index.js",
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
"name": "@swc/workspace",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"./packages/*"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
},
|
||||
"napi": {
|
||||
"binaryName": "swc",
|
||||
"targets": [
|
||||
"x86_64-apple-darwin",
|
||||
"x86_64-pc-windows-msvc",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"x86_64-unknown-linux-musl",
|
||||
"i686-pc-windows-msvc",
|
||||
"armv7-unknown-linux-gnueabihf",
|
||||
"aarch64-unknown-linux-gnu",
|
||||
"aarch64-apple-darwin",
|
||||
"aarch64-unknown-linux-musl",
|
||||
"aarch64-pc-windows-msvc"
|
||||
]
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"types": "./index.d.ts",
|
||||
"scripts": {
|
||||
"changelog": "git cliff --output CHANGELOG.md",
|
||||
"setup": "husky install && git config feature.manyFiles true && node ./crates/swc_ecma_preset_env/scripts/copy-data.js",
|
||||
"postinstall": "node postinstall.js",
|
||||
"artifacts": "napi artifacts --npm-dir scripts/npm",
|
||||
"prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tag-style npm",
|
||||
"pack": "wasm-pack",
|
||||
"build:ts": "tsc -d",
|
||||
"build:wasm": "npm-run-all \"pack -- build ./bindings/binding_core_wasm --scope swc {1} -t {2} --features plugin\" --",
|
||||
"build": "tsc -d && napi build --manifest-path bindings/Cargo.toml --platform -p binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts --release -o .",
|
||||
"build:dev": "tsc -d && napi build --manifest-path bindings/Cargo.toml --platform -p binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts -o .",
|
||||
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --config ./node-swc/jest.config.js",
|
||||
"version": "napi version --npm-dir scripts/npm"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.toml": [
|
||||
"taplo format"
|
||||
],
|
||||
"*.rs": [
|
||||
"rustfmt --"
|
||||
],
|
||||
"*.json": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.js": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.ts": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.jsx": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.tsx": [
|
||||
"prettier --write"
|
||||
]
|
||||
"prepare": "husky install && git config feature.manyFiles true && node ./crates/swc_ecma_preset_env/scripts/copy-data.js",
|
||||
"build": "cd ./packages/core && yarn build",
|
||||
"build:dev": "cd ./packages/core && yarn build:dev",
|
||||
"build:ts": "cd ./packages/core && yarn build:ts",
|
||||
"test": "cd ./packages/core && yarn test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/compat-data": "^7.23.2",
|
||||
@ -93,9 +23,7 @@
|
||||
"@babel/preset-react": "^7.13.13",
|
||||
"@babel/preset-typescript": "^7.13.0",
|
||||
"@babel/types": "^7.14.0",
|
||||
"@napi-rs/cli": "^3.0.0-alpha.43",
|
||||
"@swc/core": "=1.2.220",
|
||||
"@swc/helpers": "^0.5.0",
|
||||
"@swc/helpers": "workspace:^",
|
||||
"@swc/plugin-jest": "^1.5.117",
|
||||
"@taplo/cli": "^0.5.2",
|
||||
"@types/jest": "^29.5.11",
|
||||
@ -135,41 +63,27 @@
|
||||
"ts-node": "^10.5.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@swc/helpers": "^0.5.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@swc/helpers": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/swc"
|
||||
},
|
||||
"files": [
|
||||
"CHANGELOG.md",
|
||||
"Visitor.d.ts",
|
||||
"index.d.ts",
|
||||
"spack.js",
|
||||
"util.d.ts",
|
||||
"LICENSE",
|
||||
"Visitor.js",
|
||||
"binding.d.ts",
|
||||
"index.js",
|
||||
"types.d.ts",
|
||||
"util.js",
|
||||
"README.md",
|
||||
"binding.js",
|
||||
"package.json",
|
||||
"spack.d.ts",
|
||||
"types.js",
|
||||
"postinstall.js",
|
||||
"bindings/binding_core_wasm/pkg/binding_core_wasm.d.ts"
|
||||
"lint-staged": {
|
||||
"*.toml": [
|
||||
"taplo format"
|
||||
],
|
||||
"packageManager": "yarn@4.1.1",
|
||||
"dependencies": {
|
||||
"@swc/counter": "^0.1.2",
|
||||
"@swc/types": "0.1.7"
|
||||
"*.rs": [
|
||||
"rustfmt --"
|
||||
],
|
||||
"*.json": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.js": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.ts": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.jsx": [
|
||||
"prettier --write"
|
||||
],
|
||||
"!(**/tests/**/*)*.tsx": [
|
||||
"prettier --write"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import swc from "../..";
|
||||
import swc from "..";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
20
packages/core/__tests__/env/env_test.js
vendored
Normal file
20
packages/core/__tests__/env/env_test.js
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
const swc = require("../../");
|
||||
const path = require("path");
|
||||
|
||||
// it("should handle browserslistrc", () => {
|
||||
// const filename = path.resolve(
|
||||
// __dirname + "/../tests/env/default/input.js"
|
||||
// );
|
||||
// expect(swc.transformFileSync(filename).code.trim()).toContain(
|
||||
// `const a of foo`
|
||||
// );
|
||||
// });
|
||||
|
||||
it("should handle targets in env", () => {
|
||||
const filename = path.resolve(
|
||||
__dirname + "/../../tests/env/targets/input.js"
|
||||
);
|
||||
expect(swc.transformFileSync(filename).code.trim()).toContain(
|
||||
`const a of foo`
|
||||
);
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import * as swc from '../..';
|
||||
import * as swc from '..';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
3
packages/core/__tests__/import_test.js
Normal file
3
packages/core/__tests__/import_test.js
Normal file
@ -0,0 +1,3 @@
|
||||
it("should work", () => {
|
||||
require("../");
|
||||
});
|
20
packages/core/__tests__/is_module_unknown_test.js
Normal file
20
packages/core/__tests__/is_module_unknown_test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const swc = require("../");
|
||||
|
||||
it("should detect script", () => {
|
||||
const script = swc.parseSync(`const fs = require('fs');`, {
|
||||
isModule: "unknown",
|
||||
});
|
||||
expect(script.type).toBe("Script");
|
||||
});
|
||||
|
||||
it("should default to isModule: true", () => {
|
||||
const script = swc.parseSync(`foo;`, {});
|
||||
expect(script.type).toBe("Module");
|
||||
});
|
||||
|
||||
it("should detect module", () => {
|
||||
const script = swc.parseSync(`import fs from "fs";`, {
|
||||
isModule: "unknown",
|
||||
});
|
||||
expect(script.type).toBe("Module");
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
it("should not throw when keep_fnames is on", async () => {
|
||||
async function transform() {
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
it("should output same result", async () => {
|
||||
const origin = `
|
@ -1,4 +1,4 @@
|
||||
import swc from "../..";
|
||||
import swc from "..";
|
||||
|
||||
it("should compress", async () => {
|
||||
const { code } = await swc.minify(
|
@ -1,10 +1,10 @@
|
||||
const swc = require("../../");
|
||||
const swc = require("../");
|
||||
|
||||
it("should emit _interop_require_default", () => {
|
||||
const out = swc.transformSync(`import foo from "foo"`, {
|
||||
module: {
|
||||
type: "commonjs"
|
||||
}
|
||||
type: "commonjs",
|
||||
},
|
||||
});
|
||||
expect(out.map).toBeFalsy();
|
||||
|
||||
@ -15,15 +15,13 @@ it("should emit _interop_require_default", () => {
|
||||
it("should emit _interop_require_wildcard", () => {
|
||||
const out = swc.transformSync('import * as foo from "foo"', {
|
||||
module: {
|
||||
type: "commonjs"
|
||||
}
|
||||
type: "commonjs",
|
||||
},
|
||||
});
|
||||
expect(out.map).toBeFalsy();
|
||||
|
||||
expect(out.code).toContain(`function _interop_require_wildcard`);
|
||||
expect(out.code).toContain(
|
||||
`_interop_require_wildcard(require("foo"))`
|
||||
);
|
||||
expect(out.code).toContain(`_interop_require_wildcard(require("foo"))`);
|
||||
});
|
||||
|
||||
it("should work with amd and external helpers", () => {
|
||||
@ -32,12 +30,12 @@ it("should work with amd and external helpers", () => {
|
||||
class Bar extends Foo {}`,
|
||||
{
|
||||
jsc: {
|
||||
externalHelpers: true
|
||||
externalHelpers: true,
|
||||
},
|
||||
module: {
|
||||
type: "amd",
|
||||
moduleId: "a"
|
||||
}
|
||||
moduleId: "a",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@ -48,17 +46,17 @@ it("should work with amd and external helpers", () => {
|
||||
expect(out.code).toContain(`_inherits._(Bar, Foo);`);
|
||||
});
|
||||
|
||||
it('should not require filename if no exports in umd', () => {
|
||||
it("should not require filename if no exports in umd", () => {
|
||||
const code = `console.log('test')`;
|
||||
|
||||
const out = swc.transformSync(code, {
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: 'ecmascript',
|
||||
syntax: "ecmascript",
|
||||
},
|
||||
},
|
||||
module: {
|
||||
type: 'umd',
|
||||
type: "umd",
|
||||
},
|
||||
isModule: true,
|
||||
});
|
31
packages/core/__tests__/parse/api_test.js
Normal file
31
packages/core/__tests__/parse/api_test.js
Normal file
@ -0,0 +1,31 @@
|
||||
const swc = require("../../");
|
||||
|
||||
it("should work asynchronously", async () => {
|
||||
const m = await swc.parse(`class Foo {}`);
|
||||
|
||||
expect(m.type).toBe(`Module`);
|
||||
expect(m.body).toHaveLength(1);
|
||||
expect(m.body[0].type).toBe(`ClassDeclaration`);
|
||||
});
|
||||
|
||||
it("can work synchronously", () => {
|
||||
const m = swc.parseSync(`class Foo {}`);
|
||||
|
||||
expect(m.type).toBe(`Module`);
|
||||
expect(m.body).toHaveLength(1);
|
||||
expect(m.body[0].type).toBe(`ClassDeclaration`);
|
||||
});
|
||||
|
||||
it("can be emit code back asynchronously", async () => {
|
||||
const m = await swc.parse(`class Foo {}`);
|
||||
const out = await swc.print(m);
|
||||
|
||||
expect(out.code.trim().replace("\n", "")).toBe(`class Foo {}`);
|
||||
});
|
||||
|
||||
it("can be emit code back synchronously", async () => {
|
||||
const m = await swc.parseSync(`class Foo {}`);
|
||||
const out = swc.printSync(m);
|
||||
|
||||
expect(out.code.trim().replace("\n", "")).toBe(`class Foo {}`);
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
import swc from "../..";
|
||||
import swc from "..";
|
||||
import { dirname } from "path";
|
||||
import { platform } from "os";
|
||||
import { fileURLToPath } from "url";
|
@ -1,5 +1,5 @@
|
||||
import swc from "../..";
|
||||
import Visitor from "../../Visitor";
|
||||
import swc from "..";
|
||||
import Visitor from "../src/Visitor";
|
||||
|
||||
function assertAllObjectHasTypeFiled(obj, desc = '') {
|
||||
if (Array.isArray(obj)) {
|
@ -1,4 +1,4 @@
|
||||
import swc from "../..";
|
||||
import swc from "..";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
22
packages/core/__tests__/script_test.js
Normal file
22
packages/core/__tests__/script_test.js
Normal file
@ -0,0 +1,22 @@
|
||||
const swc = require("../");
|
||||
|
||||
it("should handle script", () => {
|
||||
const script = swc.transformSync(`foo;`, { isModule: false });
|
||||
expect(script.code.trim()).toBe(`foo;`);
|
||||
});
|
||||
|
||||
it("should parse as script if required", () => {
|
||||
const script = swc.parseSync(`foo;`, { isModule: false });
|
||||
expect(script.type).toBe("Script");
|
||||
|
||||
const out = swc.printSync(script);
|
||||
expect(out.code.trim()).toBe(`foo;`);
|
||||
});
|
||||
|
||||
it("should parse as module if required", () => {
|
||||
const m = swc.parseSync(`foo;`);
|
||||
expect(m.type).toBe("Module");
|
||||
|
||||
const out = swc.printSync(m);
|
||||
expect(out.code.trim()).toBe(`foo;`);
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
const swc = require("../../../");
|
||||
const swc = require("../../");
|
||||
const path = require("path");
|
||||
|
||||
it("should handle a simple case", async () => {
|
@ -1,4 +1,4 @@
|
||||
const swc = require("../../../");
|
||||
const swc = require("../../");
|
||||
const path = require("path");
|
||||
|
||||
it("should handle minify", () => {
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
describe("when jsc.experimentalDisableBuiltinTransforms is true", () => {
|
||||
it("should preserve TypeScript", async () => {
|
48
packages/core/__tests__/transform/hidden_jest.js
Normal file
48
packages/core/__tests__/transform/hidden_jest.js
Normal file
@ -0,0 +1,48 @@
|
||||
const swc = require("../../");
|
||||
|
||||
it("should hoist methods", () => {
|
||||
const src = 'console.log("Hello"); jest.mock(); console.log("World")';
|
||||
|
||||
expect(
|
||||
swc
|
||||
.transformSync(src, {
|
||||
jsc: {
|
||||
transform: {
|
||||
hidden: {
|
||||
jest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
.code.trim()
|
||||
).toBe(`jest.mock();
|
||||
console.log(\"Hello\");
|
||||
console.log(\"World\");`);
|
||||
});
|
||||
|
||||
it("should preserve calls", () => {
|
||||
const src = `class Foo {
|
||||
method() {
|
||||
super.foo()
|
||||
}
|
||||
}`;
|
||||
|
||||
expect(
|
||||
swc
|
||||
.transformSync(src, {
|
||||
jsc: {
|
||||
transform: {
|
||||
hidden: {
|
||||
jest: true,
|
||||
},
|
||||
},
|
||||
target: "es2019",
|
||||
},
|
||||
})
|
||||
.code.trim()
|
||||
).toBe(`class Foo {
|
||||
method() {
|
||||
super.foo();
|
||||
}
|
||||
}`);
|
||||
});
|
32
packages/core/__tests__/transform/issue834_test.js
Normal file
32
packages/core/__tests__/transform/issue834_test.js
Normal file
@ -0,0 +1,32 @@
|
||||
const swc = require("../../");
|
||||
|
||||
it("should work without parser.syntax", () => {
|
||||
const out = swc.transformSync(
|
||||
`const someValue = "test" ?? "default value";`,
|
||||
{
|
||||
jsc: {
|
||||
parser: {
|
||||
nullishCoalescing: true,
|
||||
numericSeparator: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(out.map).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should work with parser.syntax", () => {
|
||||
const out = swc.transformSync(
|
||||
`const someValue = "test" ?? "default value";`,
|
||||
{
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: "ecmascript",
|
||||
nullishCoalescing: true,
|
||||
numericSeparator: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
expect(out.map).toBeFalsy();
|
||||
});
|
27
packages/core/__tests__/transform/issue846_test.js
Normal file
27
packages/core/__tests__/transform/issue846_test.js
Normal file
@ -0,0 +1,27 @@
|
||||
const swc = require("../../");
|
||||
|
||||
it("should handle es2019", () => {
|
||||
expect(
|
||||
swc
|
||||
.transformSync(
|
||||
`class SomeClass {
|
||||
someMethod() {}
|
||||
}
|
||||
|
||||
class OtherClass extends SomeClass {
|
||||
anotherMethod() {
|
||||
super.someMethod()
|
||||
}
|
||||
}`,
|
||||
{
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: "ecmascript",
|
||||
},
|
||||
target: "es2019",
|
||||
},
|
||||
}
|
||||
)
|
||||
.code.trim()
|
||||
).toContain(`class `);
|
||||
});
|
@ -1,10 +1,8 @@
|
||||
const path = require('path');
|
||||
const swc = require('../../..');
|
||||
const path = require("path");
|
||||
const swc = require("../..");
|
||||
|
||||
it('should emit source maps as inline if requested', () => {
|
||||
const filename = path.resolve(
|
||||
__dirname + "/../../tests/issue-1581/foo.ts"
|
||||
);
|
||||
it("should emit source maps as inline if requested", () => {
|
||||
const filename = path.resolve(__dirname + "/../../tests/issue-1581/foo.ts");
|
||||
// We only check if it's not empty sourcemap.
|
||||
expect(swc.transformFileSync(filename).code.trim()).not.toContain(
|
||||
`eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzdGRvdXQifQ==`
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
import { dirname, join } from "path";
|
||||
import { platform } from "os";
|
||||
import { fileURLToPath } from "url";
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
import { dirname, join } from "path";
|
||||
import { platform } from "os";
|
||||
import { fileURLToPath } from "url";
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
import { dirname, join, resolve } from "path";
|
||||
import { platform } from "os";
|
||||
import { fileURLToPath } from "url";
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
import { dirname, join } from "path";
|
||||
import { platform } from "os";
|
||||
import { fileURLToPath } from "url";
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
it("should transpile decorators", async () => {
|
||||
const source = "`${100}testing`";
|
@ -1,5 +1,5 @@
|
||||
import path from "path";
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@ -42,7 +42,7 @@ describe("jsc.paths", () => {
|
||||
});
|
||||
|
||||
it("should work with process.cwd() and relative url", async () => {
|
||||
const testDir = path.join("node-swc", "tests", "swc-path-bug-1");
|
||||
const testDir = path.join("tests", "swc-path-bug-1");
|
||||
const f = path.join(testDir, "src", "index.ts");
|
||||
console.log(f);
|
||||
expect(
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
it("should transpile decorators", async () => {
|
||||
const source = `const a = {aób: 'ó'}
|
@ -1,6 +1,6 @@
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
it("should respect jsc.minify = false", async () => {
|
||||
const { code } = await swc.transform(`
|
@ -1,4 +1,4 @@
|
||||
const swc = require("../../../");
|
||||
const swc = require("../../");
|
||||
|
||||
it("should perform dce", () => {
|
||||
const out = swc.transformSync(
|
@ -1,5 +1,5 @@
|
||||
const swc = require("../../../");
|
||||
const Visitor = require("../../../Visitor").default;
|
||||
const swc = require("../../");
|
||||
const Visitor = require("../../src/Visitor").default;
|
||||
|
||||
{
|
||||
const src = `
|
||||
@ -99,16 +99,16 @@ const Visitor = require("../../../Visitor").default;
|
||||
|
||||
it("works", () => {
|
||||
swc.transformSync(src, {
|
||||
plugin: m => m
|
||||
plugin: (m) => m,
|
||||
});
|
||||
});
|
||||
|
||||
it("works with visitor", () => {
|
||||
swc.transformSync(src, {
|
||||
plugin: m => {
|
||||
plugin: (m) => {
|
||||
let v = new Visitor();
|
||||
return v.visitProgram(m);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import swc from "../../..";
|
||||
import swc from "../..";
|
||||
|
||||
it("should respect custom transform option", async () => {
|
||||
const { code } = await swc.transform(
|
@ -1,22 +1,21 @@
|
||||
const swc = require('../../../'),
|
||||
validate = require('sourcemap-validator'),
|
||||
sourceMap = require('source-map');
|
||||
const path = require('path');
|
||||
const swc = require("../../"),
|
||||
validate = require("sourcemap-validator"),
|
||||
sourceMap = require("source-map");
|
||||
const path = require("path");
|
||||
|
||||
it('should handle sourcemap correctly', async () => {
|
||||
it("should handle sourcemap correctly", async () => {
|
||||
const raw = `
|
||||
class Foo extends Array {
|
||||
}
|
||||
console.log('foo')
|
||||
`;
|
||||
const out = swc.transformSync(raw, {
|
||||
filename: 'input.js',
|
||||
sourceMaps: true
|
||||
filename: "input.js",
|
||||
sourceMaps: true,
|
||||
});
|
||||
|
||||
|
||||
expect(out.map).toBeTruthy();
|
||||
validate(out.code, out.map, { 'input.js': raw });
|
||||
validate(out.code, out.map, { "input.js": raw });
|
||||
|
||||
// await sourceMap.SourceMapConsumer.with(JSON.parse(out.map), null, async (consumer) => {
|
||||
// consumer.eachMapping((mapping) => {
|
||||
@ -24,80 +23,77 @@ console.log('foo')
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
// // Dump output and sourcemap to file
|
||||
// // https://sokra.github.io/source-map-visualization/#custom
|
||||
|
||||
// const fs = require('fs');
|
||||
// fs.writeFileSync('./test.js', out.code);
|
||||
// fs.writeFileSync('./test.map', out.map);
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
it('should handle sourcemap correctly when parse module', async () => {
|
||||
it("should handle sourcemap correctly when parse module", async () => {
|
||||
const raw = `
|
||||
class Foo extends Array {
|
||||
}
|
||||
console.log('foo')
|
||||
`;
|
||||
const out1 = swc.transformSync(raw, {
|
||||
filename: 'input.js',
|
||||
filename: "input.js",
|
||||
sourceMaps: true,
|
||||
plugin: swc.plugins([m => m])
|
||||
plugin: swc.plugins([(m) => m]),
|
||||
});
|
||||
|
||||
|
||||
expect(out1.map).toBeTruthy();
|
||||
expect(JSON.parse(out1.map).sources).toEqual(['input.js']);
|
||||
validate(out1.code, out1.map, { 'input.js': raw });
|
||||
expect(JSON.parse(out1.map).sources).toEqual(["input.js"]);
|
||||
validate(out1.code, out1.map, { "input.js": raw });
|
||||
|
||||
const out2 = swc.transformSync(raw, {
|
||||
sourceMaps: true,
|
||||
inlineSourcesContent: true,
|
||||
plugin: swc.plugins([m => m])
|
||||
plugin: swc.plugins([(m) => m]),
|
||||
});
|
||||
|
||||
expect(out2.map).toBeTruthy();
|
||||
expect(JSON.parse(out2.map).sources).toEqual(['<anon>']);
|
||||
validate(out2.code, out2.map, { 'input.js': raw });
|
||||
})
|
||||
expect(JSON.parse(out2.map).sources).toEqual(["<anon>"]);
|
||||
validate(out2.code, out2.map, { "input.js": raw });
|
||||
});
|
||||
|
||||
it('should handle input sourcemap correctly', async () => {
|
||||
it("should handle input sourcemap correctly", async () => {
|
||||
const raw = `class Foo extends Array {}`;
|
||||
const out1 = swc.transformSync(raw, {
|
||||
filename: 'input1.js',
|
||||
filename: "input1.js",
|
||||
jsc: {
|
||||
externalHelpers: true,
|
||||
target: 'es2016',
|
||||
target: "es2016",
|
||||
},
|
||||
module: {
|
||||
type: 'commonjs'
|
||||
type: "commonjs",
|
||||
},
|
||||
sourceMaps: true,
|
||||
inlineSourcesContent: true
|
||||
inlineSourcesContent: true,
|
||||
});
|
||||
|
||||
expect(out1.map).toBeTruthy();
|
||||
validate(out1.code, out1.map, { 'input.js': raw });
|
||||
validate(out1.code, out1.map, { "input.js": raw });
|
||||
console.log(out1.code);
|
||||
|
||||
const out2 = swc.transformSync(out1.code, {
|
||||
filename: 'input2.js',
|
||||
filename: "input2.js",
|
||||
jsc: {
|
||||
externalHelpers: true,
|
||||
target: 'es3',
|
||||
target: "es3",
|
||||
},
|
||||
module: {
|
||||
type: 'commonjs'
|
||||
type: "commonjs",
|
||||
},
|
||||
sourceMaps: true,
|
||||
inlineSourcesContent: true
|
||||
inlineSourcesContent: true,
|
||||
});
|
||||
|
||||
console.log(out2.code);
|
||||
expect(out2.map).toBeTruthy();
|
||||
validate(out2.code, out2.map, { 'input2.js': out1.code });
|
||||
validate(out2.code, out2.map, { 'input.js': raw });
|
||||
validate(out2.code, out2.map, { "input2.js": out1.code });
|
||||
validate(out2.code, out2.map, { "input.js": raw });
|
||||
|
||||
// await sourceMap.SourceMapConsumer.with(JSON.parse(out1.map), null, async (consumer1) => {
|
||||
// await sourceMap.SourceMapConsumer.with(JSON.parse(out2.map), null, async (consumer2) => {
|
||||
@ -110,23 +106,23 @@ it('should handle input sourcemap correctly', async () => {
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
describe('sourceMaps: true in .swcrc', () => {
|
||||
|
||||
describe("sourceMaps: true in .swcrc", () => {
|
||||
it(`should be respected`, async () => {
|
||||
const out = await swc.transformFile(path.join(__dirname, '..', '..', 'tests', 'issue-2120', 'input.js'));
|
||||
|
||||
const out = await swc.transformFile(
|
||||
path.join(__dirname, "..", "..", "tests", "issue-2120", "input.js")
|
||||
);
|
||||
|
||||
expect(out.map).toBeTruthy();
|
||||
})
|
||||
});
|
||||
|
||||
it(`should be ignored if 'sourceMaps: false' is passed`, async () => {
|
||||
const out = await swc.transformFile(path.join(__dirname, '..', '..', 'tests', 'issue-2120', 'input.js'), { sourceMaps: false });
|
||||
|
||||
const out = await swc.transformFile(
|
||||
path.join(__dirname, "..", "..", "tests", "issue-2120", "input.js"),
|
||||
{ sourceMaps: false }
|
||||
);
|
||||
|
||||
expect(out.map).toBeUndefined();
|
||||
})
|
||||
|
||||
});
|
||||
});
|
25
packages/core/__tests__/transform/swc_node_335.js
Normal file
25
packages/core/__tests__/transform/swc_node_335.js
Normal file
@ -0,0 +1,25 @@
|
||||
const swc = require("../..");
|
||||
|
||||
it("should handle es2019", () => {
|
||||
expect(
|
||||
swc
|
||||
.transformSync(
|
||||
`
|
||||
class Foo {
|
||||
method() {
|
||||
class Foo {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
jsc: {
|
||||
keepClassNames: true,
|
||||
target: "es2017",
|
||||
},
|
||||
}
|
||||
)
|
||||
.code.trim()
|
||||
).toContain(`let Foo = class Foo {`);
|
||||
});
|
92
packages/core/binding.d.ts
vendored
Normal file
92
packages/core/binding.d.ts
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
/* auto-generated by NAPI-RS */
|
||||
/* eslint-disable */
|
||||
|
||||
export class Compiler {
|
||||
constructor();
|
||||
}
|
||||
export type JsCompiler = Compiler;
|
||||
|
||||
export function bundle(
|
||||
confItems: Buffer,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<{ [index: string]: { code: string; map?: string } }>;
|
||||
|
||||
export function getTargetTriple(): string;
|
||||
|
||||
export function initCustomTraceSubscriber(
|
||||
traceOutFilePath?: string | undefined | null
|
||||
): void;
|
||||
|
||||
export function minify(
|
||||
code: Buffer,
|
||||
opts: Buffer,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<TransformOutput>;
|
||||
|
||||
export function minifySync(code: Buffer, opts: Buffer): TransformOutput;
|
||||
|
||||
export function parse(
|
||||
src: string,
|
||||
options: Buffer,
|
||||
filename?: string | undefined | null,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<string>;
|
||||
|
||||
export function parseFile(
|
||||
path: string,
|
||||
options: Buffer,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<string>;
|
||||
|
||||
export function parseFileSync(path: string, opts: Buffer): string;
|
||||
|
||||
export function parseSync(
|
||||
src: string,
|
||||
opts: Buffer,
|
||||
filename?: string | undefined | null
|
||||
): string;
|
||||
|
||||
export function print(
|
||||
programJson: string,
|
||||
options: Buffer,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<TransformOutput>;
|
||||
|
||||
export function printSync(program: string, options: Buffer): TransformOutput;
|
||||
|
||||
export function transform(
|
||||
src: string,
|
||||
isModule: boolean,
|
||||
options: Buffer,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<TransformOutput>;
|
||||
|
||||
export function transformFile(
|
||||
src: string,
|
||||
isModule: boolean,
|
||||
options: Buffer,
|
||||
signal?: AbortSignal | undefined | null
|
||||
): Promise<TransformOutput>;
|
||||
|
||||
export function transformFileSync(
|
||||
s: string,
|
||||
isModule: boolean,
|
||||
opts: Buffer
|
||||
): TransformOutput;
|
||||
|
||||
export interface TransformOutput {
|
||||
code: string;
|
||||
map?: string;
|
||||
}
|
||||
|
||||
/** Hack for `Type Generation` */
|
||||
export interface TransformOutput {
|
||||
code: string;
|
||||
map?: string;
|
||||
}
|
||||
|
||||
export function transformSync(
|
||||
s: string,
|
||||
isModule: boolean,
|
||||
opts: Buffer
|
||||
): TransformOutput;
|
361
packages/core/binding.js
Normal file
361
packages/core/binding.js
Normal file
@ -0,0 +1,361 @@
|
||||
// prettier-ignore
|
||||
/* eslint-disable */
|
||||
/* auto-generated by NAPI-RS */
|
||||
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
let nativeBinding = null;
|
||||
const loadErrors = [];
|
||||
|
||||
const isMusl = () => {
|
||||
let musl = false;
|
||||
if (process.platform === "linux") {
|
||||
musl = isMuslFromFilesystem();
|
||||
if (musl === null) {
|
||||
musl = isMuslFromReport();
|
||||
}
|
||||
if (musl === null) {
|
||||
musl = isMuslFromChildProcess();
|
||||
}
|
||||
}
|
||||
return musl;
|
||||
};
|
||||
|
||||
const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
||||
|
||||
const isMuslFromFilesystem = () => {
|
||||
try {
|
||||
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const isMuslFromReport = () => {
|
||||
const report =
|
||||
typeof process.report.getReport === "function"
|
||||
? process.report.getReport()
|
||||
: null;
|
||||
if (!report) {
|
||||
return null;
|
||||
}
|
||||
if (report.header && report.header.glibcVersionRuntime) {
|
||||
return false;
|
||||
}
|
||||
if (Array.isArray(report.sharedObjects)) {
|
||||
if (report.sharedObjects.some(isFileMusl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const isMuslFromChildProcess = () => {
|
||||
try {
|
||||
return require("child_process")
|
||||
.execSync("ldd --version", { encoding: "utf8" })
|
||||
.includes("musl");
|
||||
} catch (e) {
|
||||
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function requireNative() {
|
||||
if (process.platform === "android") {
|
||||
if (process.arch === "arm64") {
|
||||
try {
|
||||
return require("./swc.android-arm64.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-android-arm64");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else if (process.arch === "arm") {
|
||||
try {
|
||||
return require("./swc.android-arm-eabi.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-android-arm-eabi");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(
|
||||
new Error(`Unsupported architecture on Android ${process.arch}`)
|
||||
);
|
||||
}
|
||||
} else if (process.platform === "win32") {
|
||||
if (process.arch === "x64") {
|
||||
try {
|
||||
return require("./swc.win32-x64-msvc.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-win32-x64-msvc");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else if (process.arch === "ia32") {
|
||||
try {
|
||||
return require("./swc.win32-ia32-msvc.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-win32-ia32-msvc");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else if (process.arch === "arm64") {
|
||||
try {
|
||||
return require("./swc.win32-arm64-msvc.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-win32-arm64-msvc");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(
|
||||
new Error(
|
||||
`Unsupported architecture on Windows: ${process.arch}`
|
||||
)
|
||||
);
|
||||
}
|
||||
} else if (process.platform === "darwin") {
|
||||
try {
|
||||
return require("./swc.darwin-universal.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-darwin-universal");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
|
||||
if (process.arch === "x64") {
|
||||
try {
|
||||
return require("./swc.darwin-x64.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-darwin-x64");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else if (process.arch === "arm64") {
|
||||
try {
|
||||
return require("./swc.darwin-arm64.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-darwin-arm64");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(
|
||||
new Error(`Unsupported architecture on macOS: ${process.arch}`)
|
||||
);
|
||||
}
|
||||
} else if (process.platform === "freebsd") {
|
||||
if (process.arch === "x64") {
|
||||
try {
|
||||
return require("./swc.freebsd-x64.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-freebsd-x64");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else if (process.arch === "arm64") {
|
||||
try {
|
||||
return require("./swc.freebsd-arm64.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-freebsd-arm64");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(
|
||||
new Error(
|
||||
`Unsupported architecture on FreeBSD: ${process.arch}`
|
||||
)
|
||||
);
|
||||
}
|
||||
} else if (process.platform === "linux") {
|
||||
if (process.arch === "x64") {
|
||||
if (isMusl()) {
|
||||
try {
|
||||
return require("./swc.linux-x64-musl.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-x64-musl");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return require("./swc.linux-x64-gnu.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-x64-gnu");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
}
|
||||
} else if (process.arch === "arm64") {
|
||||
if (isMusl()) {
|
||||
try {
|
||||
return require("./swc.linux-arm64-musl.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-arm64-musl");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return require("./swc.linux-arm64-gnu.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-arm64-gnu");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
}
|
||||
} else if (process.arch === "arm") {
|
||||
try {
|
||||
return require("./swc.linux-arm-gnueabihf.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-arm-gnueabihf");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else if (process.arch === "riscv64") {
|
||||
if (isMusl()) {
|
||||
try {
|
||||
return require("./swc.linux-riscv64-musl.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-riscv64-musl");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return require("./swc.linux-riscv64-gnu.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-riscv64-gnu");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
}
|
||||
} else if (process.arch === "s390x") {
|
||||
try {
|
||||
return require("./swc.linux-s390x-gnu.node");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
try {
|
||||
return require("@swc/core-linux-s390x-gnu");
|
||||
} catch (e) {
|
||||
loadErrors.push(e);
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(
|
||||
new Error(`Unsupported architecture on Linux: ${process.arch}`)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
loadErrors.push(
|
||||
new Error(
|
||||
`Unsupported OS: ${process.platform}, architecture: ${process.arch}`
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
nativeBinding = requireNative();
|
||||
|
||||
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
||||
try {
|
||||
nativeBinding = require("./swc.wasi.cjs");
|
||||
} catch (err) {
|
||||
if (process.env.NAPI_RS_FORCE_WASI) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
if (!nativeBinding) {
|
||||
try {
|
||||
nativeBinding = require("@swc/core-wasm32-wasi");
|
||||
} catch (err) {
|
||||
if (process.env.NAPI_RS_FORCE_WASI) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!nativeBinding) {
|
||||
if (loadErrors.length > 0) {
|
||||
// TODO Link to documentation with potential fixes
|
||||
// - The package owner could build/publish bindings for this arch
|
||||
// - The user may need to bundle the correct files
|
||||
// - The user may need to re-install node_modules to get new packages
|
||||
throw new Error("Failed to load native binding", { cause: loadErrors });
|
||||
}
|
||||
throw new Error(`Failed to load native binding`);
|
||||
}
|
||||
|
||||
module.exports.Compiler = nativeBinding.Compiler;
|
||||
module.exports.JsCompiler = nativeBinding.JsCompiler;
|
||||
module.exports.bundle = nativeBinding.bundle;
|
||||
module.exports.getTargetTriple = nativeBinding.getTargetTriple;
|
||||
module.exports.initCustomTraceSubscriber =
|
||||
nativeBinding.initCustomTraceSubscriber;
|
||||
module.exports.minify = nativeBinding.minify;
|
||||
module.exports.minifySync = nativeBinding.minifySync;
|
||||
module.exports.parse = nativeBinding.parse;
|
||||
module.exports.parseFile = nativeBinding.parseFile;
|
||||
module.exports.parseFileSync = nativeBinding.parseFileSync;
|
||||
module.exports.parseSync = nativeBinding.parseSync;
|
||||
module.exports.print = nativeBinding.print;
|
||||
module.exports.printSync = nativeBinding.printSync;
|
||||
module.exports.transform = nativeBinding.transform;
|
||||
module.exports.transformFile = nativeBinding.transformFile;
|
||||
module.exports.transformFileSync = nativeBinding.transformFileSync;
|
||||
module.exports.transformSync = nativeBinding.transformSync;
|
@ -0,0 +1,16 @@
|
||||
[workspace]
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "plugin_transform_schema_vtest"
|
||||
publish = false
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.140"
|
||||
swc_core = { path = "../../../../crates/swc_core", features = [
|
||||
"__plugin_transform_schema_test",
|
||||
] }
|
@ -8,7 +8,7 @@ const getPkgRoot = (() => () => {
|
||||
let ret;
|
||||
|
||||
if (!ret) {
|
||||
ret = path.resolve(__dirname, "../../");
|
||||
ret = path.resolve(__dirname, "..");
|
||||
}
|
||||
return ret;
|
||||
})();
|
103
packages/core/package.json
Normal file
103
packages/core/package.json
Normal file
@ -0,0 +1,103 @@
|
||||
{
|
||||
"name": "@swc/core",
|
||||
"version": "1.5.8-nightly-20240516.2",
|
||||
"description": "Super-fast alternative for babel",
|
||||
"homepage": "https://swc.rs",
|
||||
"main": "./src/index.js",
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
},
|
||||
"napi": {
|
||||
"binaryName": "swc",
|
||||
"targets": [
|
||||
"x86_64-apple-darwin",
|
||||
"x86_64-pc-windows-msvc",
|
||||
"x86_64-unknown-linux-gnu",
|
||||
"x86_64-unknown-linux-musl",
|
||||
"i686-pc-windows-msvc",
|
||||
"armv7-unknown-linux-gnueabihf",
|
||||
"aarch64-unknown-linux-gnu",
|
||||
"aarch64-apple-darwin",
|
||||
"aarch64-unknown-linux-musl",
|
||||
"aarch64-pc-windows-msvc"
|
||||
]
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"types": "./src/index.d.ts",
|
||||
"scripts": {
|
||||
"changelog": "git cliff --output CHANGELOG.md",
|
||||
"postinstall": "node postinstall.js",
|
||||
"artifacts": "napi artifacts --npm-dir scripts/npm",
|
||||
"prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tag-style npm",
|
||||
"pack": "wasm-pack",
|
||||
"build:ts": "tsc -d",
|
||||
"build:wasm": "npm-run-all \"pack -- build ../../bindings/binding_core_wasm --scope swc {1} -t {2} --features plugin\" --",
|
||||
"build": "tsc -d && napi build --manifest-path ../../bindings/Cargo.toml --platform -p binding_core_node --js ./binding.js --dts ./binding.d.ts --release -o .",
|
||||
"build:dev": "tsc -d && napi build --manifest-path ../../bindings/Cargo.toml --platform -p binding_core_node --js ./binding.js --dts ./binding.d.ts -o .",
|
||||
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --config ./jest.config.js",
|
||||
"version": "napi version --npm-dir scripts/npm"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@swc/helpers": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@swc/helpers": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/swc"
|
||||
},
|
||||
"files": [
|
||||
"CHANGELOG.md",
|
||||
"src/Visitor.d.ts",
|
||||
"src/index.d.ts",
|
||||
"src/spack.js",
|
||||
"src/util.d.ts",
|
||||
"LICENSE",
|
||||
"src/Visitor.js",
|
||||
"src/binding.d.ts",
|
||||
"src/index.js",
|
||||
"src/types.d.ts",
|
||||
"src/util.js",
|
||||
"README.md",
|
||||
"src/binding.js",
|
||||
"package.json",
|
||||
"src/spack.d.ts",
|
||||
"src/types.js",
|
||||
"src/postinstall.js",
|
||||
"bindings/binding_core_wasm/pkg/binding_core_wasm.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"@swc/counter": "^0.1.3",
|
||||
"@swc/types": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "^3.0.0-alpha.43",
|
||||
"cross-env": "^7.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
1
packages/core/postinstall.d.ts
vendored
Normal file
1
packages/core/postinstall.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {};
|
227
packages/core/postinstall.js
Normal file
227
packages/core/postinstall.js
Normal file
@ -0,0 +1,227 @@
|
||||
"use strict";
|
||||
var __createBinding =
|
||||
(this && this.__createBinding) ||
|
||||
(Object.create
|
||||
? function (o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (
|
||||
!desc ||
|
||||
("get" in desc
|
||||
? !m.__esModule
|
||||
: desc.writable || desc.configurable)
|
||||
) {
|
||||
desc = {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return m[k];
|
||||
},
|
||||
};
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}
|
||||
: function (o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
});
|
||||
var __setModuleDefault =
|
||||
(this && this.__setModuleDefault) ||
|
||||
(Object.create
|
||||
? function (o, v) {
|
||||
Object.defineProperty(o, "default", {
|
||||
enumerable: true,
|
||||
value: v,
|
||||
});
|
||||
}
|
||||
: function (o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar =
|
||||
(this && this.__importStar) ||
|
||||
function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null)
|
||||
for (var k in mod)
|
||||
if (
|
||||
k !== "default" &&
|
||||
Object.prototype.hasOwnProperty.call(mod, k)
|
||||
)
|
||||
__createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter =
|
||||
(this && this.__awaiter) ||
|
||||
function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) {
|
||||
return value instanceof P
|
||||
? value
|
||||
: new P(function (resolve) {
|
||||
resolve(value);
|
||||
});
|
||||
}
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) {
|
||||
try {
|
||||
step(generator.next(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
function rejected(value) {
|
||||
try {
|
||||
step(generator["throw"](value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
function step(result) {
|
||||
result.done
|
||||
? resolve(result.value)
|
||||
: adopt(result.value).then(fulfilled, rejected);
|
||||
}
|
||||
step(
|
||||
(generator = generator.apply(thisArg, _arguments || [])).next()
|
||||
);
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* A postinstall script runs after `@swc/core` is installed.
|
||||
*
|
||||
* It checks if corresponding optional dependencies for native binary is installed and can be loaded properly.
|
||||
* If it fails, it'll internally try to install `@swc/wasm` as fallback.
|
||||
*/
|
||||
const fs_1 = require("fs");
|
||||
const assert = __importStar(require("assert"));
|
||||
const path = __importStar(require("path"));
|
||||
const child_process = __importStar(require("child_process"));
|
||||
const fs = __importStar(require("fs"));
|
||||
function removeRecursive(dir) {
|
||||
for (const entry of fs.readdirSync(dir)) {
|
||||
const entryPath = path.join(dir, entry);
|
||||
let stats;
|
||||
try {
|
||||
stats = fs.lstatSync(entryPath);
|
||||
} catch (_a) {
|
||||
continue; // Guard against https://github.com/nodejs/node/issues/4760
|
||||
}
|
||||
if (stats.isDirectory()) removeRecursive(entryPath);
|
||||
else fs.unlinkSync(entryPath);
|
||||
}
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
/**
|
||||
* Trying to validate @swc/core's native binary installation, then installs if it is not supported.
|
||||
*/
|
||||
const validateBinary = () =>
|
||||
__awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a;
|
||||
try {
|
||||
const { name } = require(path.resolve(
|
||||
process.env.INIT_CWD,
|
||||
"package.json"
|
||||
));
|
||||
if (name === "@swc/core" || name === "@swc/workspace") {
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
// TODO: We do not take care of the case if user try to install with `--no-optional`.
|
||||
// For now, it is considered as deliberate decision.
|
||||
let binding;
|
||||
try {
|
||||
binding = require("./binding.js");
|
||||
// Check if binding binary actually works.
|
||||
// For the latest version, checks target triple. If it's old version doesn't have target triple, use parseSync instead.
|
||||
const triple = binding.getTargetTriple
|
||||
? binding.getTargetTriple()
|
||||
: binding.parseSync(
|
||||
"console.log()",
|
||||
Buffer.from(JSON.stringify({ syntax: "ecmascript" }))
|
||||
);
|
||||
assert.ok(
|
||||
triple,
|
||||
"Failed to read target triple from native binary."
|
||||
);
|
||||
} catch (error) {
|
||||
// if error is unsupported architecture, ignore to display.
|
||||
if (
|
||||
!((_a = error.message) === null || _a === void 0
|
||||
? void 0
|
||||
: _a.includes("Unsupported architecture"))
|
||||
) {
|
||||
console.warn(error);
|
||||
}
|
||||
console.warn(
|
||||
`@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead.`
|
||||
);
|
||||
}
|
||||
if (!!binding) {
|
||||
return;
|
||||
}
|
||||
// User choose to override the binary installation. Skip remanining validation.
|
||||
if (!!process.env["SWC_BINARY_PATH"]) {
|
||||
console.warn(
|
||||
`@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Check if top-level package.json installs @swc/wasm separately already
|
||||
let wasmBinding;
|
||||
try {
|
||||
wasmBinding = require.resolve(`@swc/wasm`);
|
||||
} catch (_) {}
|
||||
if (!!wasmBinding && (0, fs_1.existsSync)(wasmBinding)) {
|
||||
return;
|
||||
}
|
||||
const env = Object.assign(Object.assign({}, process.env), {
|
||||
npm_config_global: undefined,
|
||||
});
|
||||
const { version } = require(path.join(
|
||||
path.dirname(require.resolve("@swc/core")),
|
||||
"package.json"
|
||||
));
|
||||
// We want to place @swc/wasm next to the @swc/core as if normal installation was done,
|
||||
// but can't directly set cwd to INIT_CWD as npm seems to acquire lock to the working dir.
|
||||
// Instead, create a temporary inner and move it out.
|
||||
const coreDir = path.dirname(require.resolve("@swc/core"));
|
||||
const installDir = path.join(coreDir, "npm-install");
|
||||
try {
|
||||
fs.mkdirSync(installDir);
|
||||
fs.writeFileSync(path.join(installDir, "package.json"), "{}");
|
||||
// Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`,
|
||||
// assume & relies on system's npm installation.
|
||||
child_process.execSync(
|
||||
`npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@${version}`,
|
||||
{ cwd: installDir, stdio: "pipe", env }
|
||||
);
|
||||
const installedBinPath = path.join(
|
||||
installDir,
|
||||
"node_modules",
|
||||
`@swc/wasm`
|
||||
);
|
||||
// INIT_CWD is injected via npm. If it doesn't exists, can't proceed.
|
||||
fs.renameSync(
|
||||
installedBinPath,
|
||||
path.resolve(process.env.INIT_CWD, "node_modules", `@swc/wasm`)
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(`Failed to install fallback @swc/wasm@${version}. @swc/core will not properly.
|
||||
Please install @swc/wasm manually, or retry whole installation.
|
||||
If there are unexpected errors, please report at https://github.com/swc-project/swc/issues`);
|
||||
} finally {
|
||||
try {
|
||||
removeRecursive(installDir);
|
||||
} catch (_) {
|
||||
// Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation.
|
||||
}
|
||||
}
|
||||
});
|
||||
validateBinary().catch((error) => {
|
||||
// for now just throw the error as-is.
|
||||
throw error;
|
||||
});
|
145
packages/core/postinstall.ts
Normal file
145
packages/core/postinstall.ts
Normal file
@ -0,0 +1,145 @@
|
||||
/**
|
||||
* A postinstall script runs after `@swc/core` is installed.
|
||||
*
|
||||
* It checks if corresponding optional dependencies for native binary is installed and can be loaded properly.
|
||||
* If it fails, it'll internally try to install `@swc/wasm` as fallback.
|
||||
*/
|
||||
import { existsSync } from "fs";
|
||||
import * as assert from "assert";
|
||||
import * as path from "path";
|
||||
import * as child_process from "child_process";
|
||||
import * as fs from "fs";
|
||||
|
||||
function removeRecursive(dir: string): void {
|
||||
for (const entry of fs.readdirSync(dir)) {
|
||||
const entryPath = path.join(dir, entry);
|
||||
let stats;
|
||||
try {
|
||||
stats = fs.lstatSync(entryPath);
|
||||
} catch {
|
||||
continue; // Guard against https://github.com/nodejs/node/issues/4760
|
||||
}
|
||||
if (stats.isDirectory()) removeRecursive(entryPath);
|
||||
else fs.unlinkSync(entryPath);
|
||||
}
|
||||
fs.rmdirSync(dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trying to validate @swc/core's native binary installation, then installs if it is not supported.
|
||||
*/
|
||||
const validateBinary = async () => {
|
||||
try {
|
||||
const { name } = require(path.resolve(
|
||||
process.env.INIT_CWD!,
|
||||
"package.json"
|
||||
));
|
||||
if (name === "@swc/core" || name === "@swc/workspace") {
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: We do not take care of the case if user try to install with `--no-optional`.
|
||||
// For now, it is considered as deliberate decision.
|
||||
let binding;
|
||||
try {
|
||||
binding = require("./binding.js");
|
||||
|
||||
// Check if binding binary actually works.
|
||||
// For the latest version, checks target triple. If it's old version doesn't have target triple, use parseSync instead.
|
||||
const triple = binding.getTargetTriple
|
||||
? binding.getTargetTriple()
|
||||
: binding.parseSync(
|
||||
"console.log()",
|
||||
Buffer.from(JSON.stringify({ syntax: "ecmascript" }))
|
||||
);
|
||||
assert.ok(triple, "Failed to read target triple from native binary.");
|
||||
} catch (error: any) {
|
||||
// if error is unsupported architecture, ignore to display.
|
||||
if (!error.message?.includes("Unsupported architecture")) {
|
||||
console.warn(error);
|
||||
}
|
||||
|
||||
console.warn(
|
||||
`@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead.`
|
||||
);
|
||||
}
|
||||
|
||||
if (!!binding) {
|
||||
return;
|
||||
}
|
||||
|
||||
// User choose to override the binary installation. Skip remanining validation.
|
||||
if (!!process.env["SWC_BINARY_PATH"]) {
|
||||
console.warn(
|
||||
`@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if top-level package.json installs @swc/wasm separately already
|
||||
let wasmBinding;
|
||||
try {
|
||||
wasmBinding = require.resolve(`@swc/wasm`);
|
||||
} catch (_) {}
|
||||
|
||||
if (!!wasmBinding && existsSync(wasmBinding)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const env = { ...process.env, npm_config_global: undefined };
|
||||
const { version } = require(path.join(
|
||||
path.dirname(require.resolve("@swc/core")),
|
||||
"package.json"
|
||||
));
|
||||
|
||||
// We want to place @swc/wasm next to the @swc/core as if normal installation was done,
|
||||
// but can't directly set cwd to INIT_CWD as npm seems to acquire lock to the working dir.
|
||||
// Instead, create a temporary inner and move it out.
|
||||
const coreDir = path.dirname(require.resolve("@swc/core"));
|
||||
const installDir = path.join(coreDir, "npm-install");
|
||||
|
||||
try {
|
||||
fs.mkdirSync(installDir);
|
||||
fs.writeFileSync(path.join(installDir, "package.json"), "{}");
|
||||
|
||||
// Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`,
|
||||
// assume & relies on system's npm installation.
|
||||
child_process.execSync(
|
||||
`npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@${version}`,
|
||||
{ cwd: installDir, stdio: "pipe", env }
|
||||
);
|
||||
|
||||
const installedBinPath = path.join(
|
||||
installDir,
|
||||
"node_modules",
|
||||
`@swc/wasm`
|
||||
);
|
||||
// INIT_CWD is injected via npm. If it doesn't exists, can't proceed.
|
||||
fs.renameSync(
|
||||
installedBinPath,
|
||||
path.resolve(process.env.INIT_CWD!, "node_modules", `@swc/wasm`)
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
console.error(
|
||||
`Failed to install fallback @swc/wasm@${version}. @swc/core will not properly.
|
||||
Please install @swc/wasm manually, or retry whole installation.
|
||||
If there are unexpected errors, please report at https://github.com/swc-project/swc/issues`
|
||||
);
|
||||
} finally {
|
||||
try {
|
||||
removeRecursive(installDir);
|
||||
} catch (_) {
|
||||
// Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation.
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
validateBinary().catch((error) => {
|
||||
// for now just throw the error as-is.
|
||||
throw error;
|
||||
});
|
42
packages/core/scripts/npm/darwin-arm64/package.json
Normal file
42
packages/core/scripts/npm/darwin-arm64/package.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@swc/core-darwin-arm64",
|
||||
"version": "1.4.6",
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"main": "swc.darwin-arm64.node",
|
||||
"files": [
|
||||
"swc.darwin-arm64.node",
|
||||
"swc"
|
||||
],
|
||||
"description": "Super-fast alternative for babel",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"homepage": "https://swc.rs",
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
}
|
||||
}
|
42
packages/core/scripts/npm/darwin-x64/package.json
Normal file
42
packages/core/scripts/npm/darwin-x64/package.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@swc/core-darwin-x64",
|
||||
"version": "1.4.6",
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"main": "swc.darwin-x64.node",
|
||||
"files": [
|
||||
"swc.darwin-x64.node",
|
||||
"swc"
|
||||
],
|
||||
"description": "Super-fast alternative for babel",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"homepage": "https://swc.rs",
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
}
|
||||
}
|
42
packages/core/scripts/npm/linux-arm-gnueabihf/package.json
Normal file
42
packages/core/scripts/npm/linux-arm-gnueabihf/package.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "@swc/core-linux-arm-gnueabihf",
|
||||
"version": "1.4.6",
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"main": "swc.linux-arm-gnueabihf.node",
|
||||
"files": [
|
||||
"swc.linux-arm-gnueabihf.node",
|
||||
"swc"
|
||||
],
|
||||
"description": "Super-fast alternative for babel",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"homepage": "https://swc.rs",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
}
|
||||
}
|
45
packages/core/scripts/npm/linux-arm64-gnu/package.json
Normal file
45
packages/core/scripts/npm/linux-arm64-gnu/package.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@swc/core-linux-arm64-gnu",
|
||||
"version": "1.4.6",
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"main": "swc.linux-arm64-gnu.node",
|
||||
"files": [
|
||||
"swc.linux-arm64-gnu.node",
|
||||
"swc"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"description": "Super-fast alternative for babel",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"homepage": "https://swc.rs",
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
}
|
||||
}
|
45
packages/core/scripts/npm/linux-arm64-musl/package.json
Normal file
45
packages/core/scripts/npm/linux-arm64-musl/package.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@swc/core-linux-arm64-musl",
|
||||
"version": "1.4.6",
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"main": "swc.linux-arm64-musl.node",
|
||||
"files": [
|
||||
"swc.linux-arm64-musl.node",
|
||||
"swc"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"description": "Super-fast alternative for babel",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"homepage": "https://swc.rs",
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
}
|
||||
}
|
45
packages/core/scripts/npm/linux-x64-gnu/package.json
Normal file
45
packages/core/scripts/npm/linux-x64-gnu/package.json
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@swc/core-linux-x64-gnu",
|
||||
"version": "1.4.6",
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"main": "swc.linux-x64-gnu.node",
|
||||
"files": [
|
||||
"swc.linux-x64-gnu.node",
|
||||
"swc"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"description": "Super-fast alternative for babel",
|
||||
"keywords": [
|
||||
"swc",
|
||||
"swcpack",
|
||||
"babel",
|
||||
"typescript",
|
||||
"rust",
|
||||
"webpack",
|
||||
"tsc"
|
||||
],
|
||||
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
||||
"homepage": "https://swc.rs",
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/swc-project/swc.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/swc-project/swc/issues"
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user