Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Oct 15, 2024
1 parent 452087b commit 874e78b
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,10 @@ export interface RawStatsOptions {
colors: boolean
}

export interface RawSwcDtsEmitRspackPluginOptions {
rootDir?: string
}

export interface RawSwcJsMinimizerOptions {
compress: any
mangle: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod raw_banner;
mod raw_bundle_info;
mod raw_copy;
mod raw_css_extract;
mod raw_swc_dts_emit;
mod raw_html;
mod raw_ignore;
mod raw_lazy_compilation;
Expand Down Expand Up @@ -86,6 +87,7 @@ pub use self::{
use self::{
raw_bundle_info::{RawBundlerInfoModeWrapper, RawBundlerInfoPluginOptions},
raw_css_extract::RawCssExtractPluginOption,
raw_swc_dts_emit::RawSwcDtsEmitRspackPluginOptions,
raw_lazy_compilation::{JsBackend, RawLazyCompilationOption},
raw_mf::{RawConsumeSharedPluginOptions, RawContainerReferencePluginOptions, RawProvideOptions},
raw_runtime_chunk::RawRuntimeChunkOptions,
Expand Down Expand Up @@ -489,7 +491,10 @@ impl BuiltinPlugin {
plugins.push(plugin);
}
BuiltinPluginName::SwcDtsEmitRspackPlugin => {
rspack_loader_swc::
let plugin = rspack_loader_swc::PluginSwcDtsEmit::new(
downcast_into::<RawSwcDtsEmitRspackPluginOptions>(self.options)?.into(),
).boxed();
plugins.push(plugin);
}
BuiltinPluginName::JsLoaderRspackPlugin => {
plugins
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use rspack_loader_swc::{SwcDtsEmitOptions};
use napi_derive::napi;

#[napi(object, object_to_js = false)]
pub struct RawSwcDtsEmitRspackPluginOptions {
pub root_dir: Option<String>,
}

impl From<RawSwcDtsEmitRspackPluginOptions> for SwcDtsEmitOptions {
fn from(value: RawSwcDtsEmitRspackPluginOptions) -> Self {
Self {
root_dir: value.root_dir.unwrap(),
}
}
}
1 change: 1 addition & 0 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ impl Module for ConcatenatedModule {
json_data: Default::default(),
top_level_declarations: Some(Default::default()),
module_concatenation_bailout: Default::default(),
parse_meta: Default::default(),
};
self.clear_diagnostics();

Expand Down
5 changes: 4 additions & 1 deletion crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rspack_sources::Source;
use rspack_util::atom::Atom;
use rspack_util::ext::{AsAny, DynHash};
use rspack_util::source_map::ModuleSourceMapConfig;
use rustc_hash::FxHashSet as HashSet;
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};

use crate::concatenated_module::ConcatenatedModule;
use crate::dependencies_block::dependencies_block_update_hash;
Expand Down Expand Up @@ -56,6 +56,8 @@ pub struct BuildInfo {
pub json_data: Option<JsonValue>,
pub top_level_declarations: Option<HashSet<Atom>>,
pub module_concatenation_bailout: Option<String>,

pub parse_meta: HashMap<String, String>,
}

impl Default for BuildInfo {
Expand All @@ -74,6 +76,7 @@ impl Default for BuildInfo {
json_data: None,
top_level_declarations: None,
module_concatenation_bailout: None,
parse_meta: HashMap::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ impl Module for NormalModule {
}

build_info.cacheable = loader_result.cacheable;
build_info.parse_meta = loader_result.parse_meta.clone();
build_info.file_dependencies = loader_result.file_dependencies;
build_info.context_dependencies = loader_result.context_dependencies;
build_info.missing_dependencies = loader_result.missing_dependencies;
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_loader_swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jsonc-parser = { version = "0.23.0", features = ["serde"] }
rspack_ast = { version = "0.1.0", path = "../rspack_ast" }
rspack_core = { version = "0.1.0", path = "../rspack_core" }
rspack_error = { version = "0.1.0", path = "../rspack_error" }
rspack_hook = { version = "0.1.0", path = "../rspack_hook" }
rspack_loader_runner = { version = "0.1.0", path = "../rspack_loader_runner" }
rspack_plugin_javascript = { version = "0.1.0", path = "../rspack_plugin_javascript" }
rspack_util = { version = "0.1.0", path = "../rspack_util" }
Expand All @@ -36,4 +37,5 @@ swc_core = { workspace = true, features = ["base", "ecma_ast", "
swc_plugin_import = { version = "0.1.5", path = "../swc_plugin_import" }
swc_typescript = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
url = "2.5.0"
2 changes: 1 addition & 1 deletion crates/rspack_loader_swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::default::Default;
use compiler::{IntoJsAst, SwcCompiler};
use options::SwcCompilerOptionsWithAdditional;
pub use options::SwcLoaderJsOptions;
pub use plugin::PluginCssExtract;
pub use plugin::{SwcDtsEmitOptions, PluginSwcDtsEmit};
use rspack_core::{rspack_sources::SourceMap, Mode, RunnerContext};
use rspack_error::{error, AnyhowError, Diagnostic, Result};
use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext};
Expand Down
76 changes: 74 additions & 2 deletions crates/rspack_loader_swc/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,81 @@
use std::sync::Arc;

use rspack_core::{
Compilation, CompilationFinishModules, CompilationParams, CompilerCompilation, Plugin,

Check failure on line 4 in crates/rspack_loader_swc/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

unused imports: `CompilationParams` and `CompilerCompilation`
PluginContext,
};
use rspack_error::Result;
use rspack_hook::{plugin, plugin_hook};

#[derive(Debug)]
pub struct SwcDtsEmitOptions {
pub root_dir: String,
}

#[plugin]
#[derive(Debug)]
pub struct PluginCssExtract {
pub(crate) options: Arc<CssExtractOptions>,
pub struct PluginSwcDtsEmit {
pub(crate) options: Arc<SwcDtsEmitOptions>,
}

impl Eq for PluginSwcDtsEmit {}

impl PartialEq for PluginSwcDtsEmit {
fn eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.options, &other.options)
}
}

const PLUGIN_NAME: &str = "rspack.SwcDtsEmitPlugin";

impl PluginSwcDtsEmit {
pub fn new(options: SwcDtsEmitOptions) -> Self {
Self::new_inner(Arc::new(options))
}
}

#[plugin_hook(CompilationFinishModules for PluginSwcDtsEmit)]
async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> {
let module_graph = compilation.get_module_graph();

for (_, a) in module_graph.modules() {
let meta = &a.build_info().expect("fuck").parse_meta;
dbg!(meta);

Check failure on line 43 in crates/rspack_loader_swc/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

the `dbg!` macro is intended as a debugging tool
}
Ok(())
}

// #[plugin_hook(CompilerCompilation for PluginSwcDtsEmit)]
// async fn compilation(
// &self,
// compilation: &mut Compilation,
// params: &mut CompilationParams,
// ) -> Result<()> {
// Ok(())
// }

impl Plugin for PluginSwcDtsEmit {
fn name(&self) -> &'static str {
PLUGIN_NAME
}

fn apply(
&self,
ctx: PluginContext<&mut rspack_core::ApplyContext>,
_options: &rspack_core::CompilerOptions,
) -> Result<()> {
// ctx
// .context
// .compiler_hooks
// .compilation
// .tap(compilation::new(self));

ctx
.context
.compilation_hooks
.finish_modules
.tap(finish_modules::new(self));

Ok(())
}
}
3 changes: 2 additions & 1 deletion packages/rspack/src/builtin-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export * from "./BundlerInfoRspackPlugin";
export * from "./ChunkPrefetchPreloadPlugin";
export * from "./CommonJsChunkFormatPlugin";
export * from "./CopyRspackPlugin";
export * from "./css-extract";
export * from "./css-extract/index";
export * from "./CssModulesPlugin";
export * from "./DataUriPlugin";
export * from "./DefinePlugin";
Expand Down Expand Up @@ -59,6 +59,7 @@ export * from "./SourceMapDevToolPlugin";
export * from "./SplitChunksPlugin";
export * from "./LightningCssMiminizerRspackPlugin";
export * from "./SwcJsMinimizerPlugin";
export * from "./swc-dts-emit/index";
export * from "./WarnCaseSensitiveModulesPlugin";
export * from "./WebWorkerTemplatePlugin";
export * from "./WorkerPlugin";
Expand Down
17 changes: 15 additions & 2 deletions packages/rspack/src/builtin-plugin/swc-dts-emit/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { BuiltinPluginName } from "@rspack/binding";
import {
BuiltinPluginName,
type RawSwcDtsEmitRspackPluginOptions
} from "@rspack/binding";
import { Compiler } from "../../Compiler";

export interface SwcDtsEmitRspackPluginOptions {}
export interface SwcDtsEmitRspackPluginOptions {
rootDir: string;
}

export class SwcDtsEmitRspackPlugin {
apply(compiler: Compiler) {
Expand All @@ -10,4 +15,12 @@ export class SwcDtsEmitRspackPlugin {
options: {}
});
}
normalizeOptions(
options: SwcDtsEmitRspackPluginOptions
): RawSwcDtsEmitRspackPluginOptions {
const normalzedOptions: RawSwcDtsEmitRspackPluginOptions = {
rootDir: options.rootDir
};
return normalzedOptions;
}
}
1 change: 1 addition & 0 deletions packages/rspack/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export { SourceMapDevToolPlugin } from "./builtin-plugin";
export { EvalSourceMapDevToolPlugin } from "./builtin-plugin";
export { EvalDevToolModulePlugin } from "./builtin-plugin";
export { CssExtractRspackPlugin } from "./builtin-plugin";
export { SwcDtsEmitRspackPlugin } from "./builtin-plugin";
export { ContextReplacementPlugin } from "./builtin-plugin";

///// Rspack Postfixed Internal Loaders /////
Expand Down

0 comments on commit 874e78b

Please sign in to comment.