mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 00:32:15 +03:00
feat(es/transforms): Add experimental output API for transforms (#9000)
**Description:** This interface will provide a way to emit some outputs from transforms. This data will be emitted back to the JS caller.
This commit is contained in:
parent
668a11d50d
commit
6fa79be081
6
.github/workflows/CI.yml
vendored
6
.github/workflows/CI.yml
vendored
@ -551,12 +551,18 @@ jobs:
|
||||
- crate: swc_trace_macro
|
||||
os: ubuntu-latest
|
||||
runner: ubuntu-latest
|
||||
- crate: swc_transform_common
|
||||
os: ubuntu-latest
|
||||
runner: ubuntu-latest
|
||||
- crate: swc_visit
|
||||
os: ubuntu-latest
|
||||
runner: ubuntu-latest
|
||||
- crate: swc_visit_macros
|
||||
os: ubuntu-latest
|
||||
runner: ubuntu-latest
|
||||
- crate: swc_x_optimizer
|
||||
os: ubuntu-latest
|
||||
runner: ubuntu-latest
|
||||
- crate: swc_xml
|
||||
os: ubuntu-latest
|
||||
runner: ubuntu-latest
|
||||
|
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -5281,6 +5281,17 @@ dependencies = [
|
||||
"syn 2.0.55",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "swc_transform_common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"better_scoped_tls",
|
||||
"once_cell",
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "swc_visit"
|
||||
version = "0.5.14"
|
||||
|
@ -22,9 +22,13 @@ members = [
|
||||
"crates/swc_timer",
|
||||
"crates/swc_xml",
|
||||
"crates/swc_x_optimizer",
|
||||
"crates/swc_transform_common",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
|
||||
[workspace.dependencies]
|
||||
# bytecheck version should be in sync with rkyv version. Do not bump individually.
|
||||
bytecheck = "0.6.10"
|
||||
|
@ -1,11 +1,11 @@
|
||||
[package]
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Debug utilities"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "dbg-swc"
|
||||
repository = "https://github.com/kdy1/dbg-swc.git"
|
||||
version = "0.93.5"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Debug utilities"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "dbg-swc"
|
||||
repository.workspace = true
|
||||
version = "0.93.5"
|
||||
|
||||
[[bin]]
|
||||
bench = false
|
||||
|
@ -1,12 +1,13 @@
|
||||
[package]
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "JsDoc parser writen in rust"
|
||||
documentation = "https://rustdoc.swc.rs/jsdoc/"
|
||||
edition = "2021"
|
||||
include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0"
|
||||
name = "jsdoc"
|
||||
version = "0.113.1"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "JsDoc parser writen in rust"
|
||||
documentation = "https://rustdoc.swc.rs/jsdoc/"
|
||||
edition = "2021"
|
||||
include = ["Cargo.toml", "src/**/*.rs"]
|
||||
license = "Apache-2.0"
|
||||
name = "jsdoc"
|
||||
repository.workspace = true
|
||||
version = "0.113.1"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
@ -1,11 +1,12 @@
|
||||
[package]
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Common logic for targetting vairous browsers"
|
||||
documentation = "https://rustdoc.swc.rs/preset_env_base/"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "preset_env_base"
|
||||
version = "0.4.13"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Common logic for targetting vairous browsers"
|
||||
documentation = "https://rustdoc.swc.rs/preset_env_base/"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "preset_env_base"
|
||||
repository.workspace = true
|
||||
version = "0.4.13"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
@ -1,13 +1,13 @@
|
||||
[package]
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "preset-env for the swc"
|
||||
documentation = "https://rustdoc.swc.rs/swc_ecma_preset_env/"
|
||||
edition = "2021"
|
||||
include = ["Cargo.toml", "src/**/*.rs", "src/**/*.json", "data/**/*.json"]
|
||||
license = "Apache-2.0"
|
||||
name = "swc_ecma_preset_env"
|
||||
repository = "https://github.com/swc-project/swc"
|
||||
version = "0.207.1"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "preset-env for the swc"
|
||||
documentation = "https://rustdoc.swc.rs/swc_ecma_preset_env/"
|
||||
edition = "2021"
|
||||
include = ["Cargo.toml", "src/**/*.rs", "src/**/*.json", "data/**/*.json"]
|
||||
license = "Apache-2.0"
|
||||
name = "swc_ecma_preset_env"
|
||||
repository.workspace = true
|
||||
version = "0.207.1"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
21
crates/swc_transform_common/Cargo.toml
Normal file
21
crates/swc_transform_common/Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
description = "Common utilities for swc transforms for any language"
|
||||
documentation = "https://rustdoc.swc.rs/swc_transform_common/"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
name = "swc_transform_common"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.1.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[dependencies]
|
||||
once_cell = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
better_scoped_tls = { version = "0.1.1", path = "../better_scoped_tls" }
|
3
crates/swc_transform_common/README.md
Normal file
3
crates/swc_transform_common/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# swc_transform_common
|
||||
|
||||
Common utilities for the author of a swc transform.
|
1
crates/swc_transform_common/src/lib.rs
Normal file
1
crates/swc_transform_common/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod output;
|
25
crates/swc_transform_common/src/output.rs
Normal file
25
crates/swc_transform_common/src/output.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use std::cell::RefCell;
|
||||
|
||||
use better_scoped_tls::scoped_tls;
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde_json::Value;
|
||||
|
||||
scoped_tls!(static OUTPUT: RefCell<FxHashMap<String, Value>>);
|
||||
|
||||
pub fn capture<Ret>(f: impl FnOnce() -> Ret) -> (Ret, FxHashMap<String, Value>) {
|
||||
let output = RefCell::new(FxHashMap::default());
|
||||
|
||||
let ret = OUTPUT.set(&output, f);
|
||||
|
||||
(ret, output.into_inner())
|
||||
}
|
||||
|
||||
pub fn emit(key: String, value: Value) {
|
||||
OUTPUT.with(|output| {
|
||||
let previous = output.borrow_mut().insert(key, value);
|
||||
|
||||
if let Some(previous) = previous {
|
||||
panic!("Key already set. Previous value: {previous:?}");
|
||||
}
|
||||
});
|
||||
}
|
@ -6,10 +6,8 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
function prepend() { while read line; do echo "${1}${line}"; done; }
|
||||
|
||||
crates=$(\
|
||||
cargo metadata --format-version 1 \
|
||||
| jq -r '.workspace_members[]' \
|
||||
| cut -f1 -d" " \
|
||||
| sort \
|
||||
cargo metadata --format-version=1 --all-features \
|
||||
| jq '.packages .[] | select(.repository == "https://github.com/swc-project/swc.git") | .name' -r\
|
||||
)
|
||||
|
||||
# yq query syntax is weird, so we have to use jq
|
||||
|
Loading…
Reference in New Issue
Block a user