feat(node-swc): Add cargo feature for v2 (#3019)

swc_node_bundler:
 - Add cargo features for versioned apis.

node-swc:
 - Add cargo features for versioned apis.
This commit is contained in:
Donny/강동윤 2021-12-12 22:52:58 +09:00 committed by GitHub
parent aab3326b3e
commit 017392aa5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 69 additions and 11 deletions

View File

@ -34,11 +34,11 @@ jobs:
with:
path: |
~/.cargo/
key: ${{ runner.os }}-cargo-compliation
key: ${{ runner.os }}-cargo-compiliation
- name: Install cargo hack
run: |
cargo install cargo-hack --version 0.3.11
cargo install cargo-hack --version 0.5.7
- name: Check swc_common
run: |
@ -76,6 +76,16 @@ jobs:
run: |
(cd crates/swc_bundler && cargo hack check --feature-powerset --no-dev-deps)
- name: Check node_swc
run: |
(cd crates/node && cargo check)
(cd crates/node && cargo check --no-default-features --features swc_v2)
- name: Check swc_node_bundler
run: |
(cd crates/swc_node_bundler && cargo check)
(cd crates/swc_node_bundler && cargo check --no-default-features --features swc_v2)
- name: Check swc
run: |
(cd crates/swc && cargo hack check --feature-powerset --no-dev-deps)

2
Cargo.lock generated
View File

@ -3826,7 +3826,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm"
version = "1.2.119"
version = "1.2.120"
dependencies = [
"anyhow",
"console_error_panic_hook",

View File

@ -11,6 +11,11 @@ version = "0.1.0"
[lib]
crate-type = ["cdylib"]
[features]
default = ["swc_v1"]
swc_v1 = ["swc_node_bundler/swc_v1", "swc/wrong-target"]
swc_v2 = ["swc_node_bundler/swc_v2"]
[build-dependencies]
napi-build = {version = "1"}
@ -23,7 +28,7 @@ path-clean = "0.1"
proc-macro2 = "=1.0.32"
serde = {version = "1", features = ["derive"]}
serde_json = {version = "1", features = ["unbounded_depth"]}
swc = {path = "../swc", features = ["concurrent", "wrong-target", "plugin"]}
swc = {path = "../swc", features = ["concurrent", "plugin"]}
swc_atoms = {version = "0.2.4", path = "../swc_atoms"}
swc_bundler = {path = "../swc_bundler"}
swc_common = {path = "../swc_common", features = ["sourcemap"]}

View File

@ -31,8 +31,9 @@ struct ConfigItem {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct StaticConfigItem {
#[cfg(feature = "swc_v1")]
#[serde(flatten)]
config: swc_node_bundler::config::Config,
config: swc_node_bundler::v1::Config,
}
struct BundleTask {
@ -40,6 +41,7 @@ struct BundleTask {
config: ConfigItem,
}
#[cfg(feature = "swc_v1")]
impl Task for BundleTask {
type Output = AHashMap<String, TransformOutput>;
type JsValue = JsObject;
@ -157,6 +159,21 @@ impl Task for BundleTask {
}
}
#[cfg(feature = "swc_v2")]
impl Task for BundleTask {
type Output = AHashMap<String, TransformOutput>;
type JsValue = JsObject;
fn compute(&mut self) -> napi::Result<Self::Output> {
todo!()
}
fn resolve(self, env: Env, output: Self::Output) -> napi::Result<Self::JsValue> {
todo!()
}
}
#[cfg(feature = "swc_v1")]
#[js_function(1)]
pub(crate) fn bundle(cx: CallContext) -> napi::Result<JsObject> {
let c: Arc<Compiler> = get_compiler(&cx);
@ -213,6 +230,12 @@ pub(crate) fn bundle(cx: CallContext) -> napi::Result<JsObject> {
.map(|t| t.promise_object())
}
#[cfg(feature = "swc_v2")]
#[js_function(1)]
pub(crate) fn bundle(cx: CallContext) -> napi::Result<JsObject> {
todo!()
}
struct Hook;
impl swc_bundler::Hook for Hook {

View File

@ -19,6 +19,9 @@ mod print;
mod transform;
mod util;
#[cfg(all(not(feature = "swc_v1"), not(feature = "swc_v2")))]
compile_error!("Please enable swc_v1 or swc_v2 feature");
static COMPILER: Lazy<Arc<Compiler>> = Lazy::new(|| {
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));

View File

@ -7,7 +7,7 @@ use std::{
fs::{self, create_dir_all, read_to_string, OpenOptions},
io::{self, Write},
mem::take,
path::{Path, PathBuf},
path::Path,
process::Command,
rc::Rc,
sync::{Arc, RwLock},

View File

@ -10,7 +10,10 @@ publish = false
repository = "https://github.com/swc-project/swc.git"
version = "0.0.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["swc_v1"]
swc_v1 = []
swc_v2 = []
[dependencies]
anyhow = "1"

View File

@ -6,5 +6,11 @@ extern crate test;
/// Explicit extern crate to use allocator.
extern crate swc_node_base;
pub mod config;
pub mod loaders;
#[cfg(feature = "swc_v1")]
pub mod v1;
#[cfg(feature = "swc_v2")]
pub mod v2;
#[cfg(all(not(feature = "swc_v1"), not(feature = "swc_v2")))]
compile_error!("Please enable swc_v1 or swc_v2 feature");

View File

@ -1,4 +1,4 @@
use crate::config::JsCallback;
use crate::v1::JsCallback;
use serde::Deserialize;
#[derive(Debug, Deserialize)]

View File

@ -0,0 +1 @@

View File

@ -6,11 +6,16 @@ license = "Apache-2.0"
name = "wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.2.119"
version = "1.2.120"
[lib]
crate-type = ["cdylib"]
[features]
default = ["swc_v1"]
swc_v1 = []
swc_v2 = []
[dependencies]
anyhow = "1.0.42"
console_error_panic_hook = "0.1.6"

View File

@ -15,6 +15,7 @@
"babelify",
"Babelify",
"bools",
"bors",
"bpos",
"BUILTINS",
"canonicalization",
@ -26,6 +27,7 @@
"cname",
"combinator",
"Combinator",
"compiliation",
"cond",
"Cond",
"constness",

View File

@ -1,6 +1,6 @@
{
"name": "@swc/core",
"version": "1.2.119",
"version": "1.2.120",
"description": "Super-fast alternative for babel",
"homepage": "https://swc.rs",
"main": "./index.js",