Skip to content

Commit

Permalink
feat: loader reuse ast
Browse files Browse the repository at this point in the history
  • Loading branch information
luhc228 committed Apr 3, 2024
1 parent b83cf31 commit a56e8b9
Show file tree
Hide file tree
Showing 15 changed files with 419 additions and 185 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/node_binding/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export interface RawTransformOptions {
outDir: string
target: string
module: 'es6' | 'commonjs'
sourcemap: boolean
aliasConfig: Record<string, string>
}
export function transform(rawOptions: RawTransformOptions): Promise<void>
26 changes: 21 additions & 5 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![deny(clippy::all)]

use std::collections::HashMap;

use pkg_core::{self, TransformOptions};

#[macro_use]
Expand All @@ -15,16 +17,30 @@ pub struct RawTransformOptions {
// The module like es6, cjs. For more detail, see swc_ecma_transforms::module.
#[napi(ts_type = "'es6' | 'commonjs'")]
pub module: String,
pub sourcemap: bool,
pub alias_config: HashMap<String, String>,
}

#[napi]
pub async fn transform(raw_options: RawTransformOptions) {
let RawTransformOptions {
src_dir,
out_dir,
input_files,
target,
module,
alias_config,
sourcemap,
} = raw_options;

let transform_options = TransformOptions {
src_dir: raw_options.src_dir,
input_files: raw_options.input_files,
out_dir: raw_options.out_dir,
target: raw_options.target,
module: raw_options.module,
src_dir,
input_files,
out_dir,
target,
module,
alias_config,
sourcemap,
};
let _ = pkg_core::transform(transform_options).await;
}
12 changes: 12 additions & 0 deletions crates/pkg_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ normalize-path = { workspace = true }
pkg_loader = { workspace = true }
pkg_loader_alias = { workspace = true }
pkg_loader_swc = { workspace = true }
swc_core = { workspace = true, features = [
"base",
"common",
"ecma_ast",
"ecma_parser",
"ecma_codegen",
"__ecma_transforms",
"__visit",
] }
swc_ecma_transforms = { version = "*" }
serde_json = { workspace = true }
swc_compiler = { workspace = true }
Loading

0 comments on commit a56e8b9

Please sign in to comment.