Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support rspack.DllPlugin & rspack.DllReferencePlugin #8296

Merged
merged 26 commits into from
Nov 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ddc113c
feat: rewrite dll-plugin by rust
GiveMe-A-Name Oct 28, 2024
61a8386
feat: support rspack.DllReferencePlugin
GiveMe-A-Name Oct 31, 2024
7cd40f2
test: add dll plugin tests
GiveMe-A-Name Oct 31, 2024
31cf010
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Oct 31, 2024
1ac86e9
refactor: improve delegated_module code
GiveMe-A-Name Oct 31, 2024
e35cac8
docs: add dll-plugin & dll-refernce-plugin docs
GiveMe-A-Name Nov 1, 2024
68beb1a
fix: flagAllModuleAsUsedPlugin add_extra_reason
GiveMe-A-Name Nov 5, 2024
772f5c1
chore: rename some vars
GiveMe-A-Name Nov 5, 2024
8f25d29
fix: typo
GiveMe-A-Name Nov 5, 2024
23bc688
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Nov 5, 2024
e4246b0
fix: remove the unnecessary generics
GiveMe-A-Name Nov 5, 2024
43555e6
fix: typo
GiveMe-A-Name Nov 5, 2024
1f225e8
fix: cargo clippy test
GiveMe-A-Name Nov 5, 2024
0ba5e31
fix: remove unused dependency rspack_macros
GiveMe-A-Name Nov 5, 2024
45c78df
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Nov 6, 2024
2c044ec
docs: add dll & dll-reference plugin zh docs
GiveMe-A-Name Nov 6, 2024
0c05841
fix: resolved merge conflict
GiveMe-A-Name Nov 6, 2024
71811aa
fix: resolved some issues
GiveMe-A-Name Nov 8, 2024
3ac6301
chore: add some annotations
GiveMe-A-Name Nov 8, 2024
2c996a4
chore: add some annotations
GiveMe-A-Name Nov 8, 2024
3f4d02d
fix: update manifest content item exports type
GiveMe-A-Name Nov 8, 2024
a34740c
fix: update dll manifest types
GiveMe-A-Name Nov 8, 2024
7015b94
chore:update docs
GiveMe-A-Name Nov 8, 2024
7a03d0c
chore: clippy fix
GiveMe-A-Name Nov 8, 2024
d075bcc
fix: bailout use build_info.module_concatenation_bailout
GiveMe-A-Name Nov 11, 2024
c294041
Merge branch 'main' into feat/dll-plugin
GiveMe-A-Name Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: update manifest content item exports type
  • Loading branch information
GiveMe-A-Name committed Nov 8, 2024
commit 3f4d02d32c482191b8da40b20f3bf3de32c22ea1
6 changes: 3 additions & 3 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
@@ -1300,14 +1300,14 @@ export interface RawDllEntryPluginOptions {
}

export interface RawDllManifest {
content: RawDllManifestContent
content: Record<string, RawDllManifestContentItem>
name?: string
type?: string
}

export interface RawDllManifestContentItem {
buildMeta?: JsBuildMeta
exports?: Array<string>
exports?: string[] | true
id?: string
}

@@ -1318,7 +1318,7 @@ export interface RawDllReferenceAgencyPluginOptions {
scope?: string
sourceType?: string
type: string
content?: RawDllManifestContent
content?: Record<string, RawDllManifestContentItem>
manifest?: RawDllManifest
}

37 changes: 25 additions & 12 deletions crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use napi::Either;
use napi_derive::napi;
use rspack_binding_values::{JsBuildMeta, JsFilename};
use rspack_plugin_dll::{
DllEntryPluginOptions, DllManifest, DllManifestContent, DllManifestContentItem,
DllReferenceAgencyPluginOptions, LibManifestPluginOptions,
DllManifestContentItemExports, DllReferenceAgencyPluginOptions, LibManifestPluginOptions,
};
use rustc_hash::FxHashMap as HashMap;
use swc_core::atoms::Atom;
@@ -72,37 +73,49 @@
pub scope: Option<String>,
pub source_type: Option<String>,
pub r#type: String,
pub content: Option<RawDllManifestContent>,
pub content: Option<HashMap<String, RawDllManifestContentItem>>,
pub manifest: Option<RawDllManifest>,
}

type RawDllManifestContent = HashMap<String, RawDllManifestContentItem>;

#[napi(object, object_to_js = false)]
pub struct RawDllManifestContentItem {
pub build_meta: Option<JsBuildMeta>,
pub exports: Option<Vec<String>>,
#[napi(ts_type = "string[] | true")]
pub exports: Option<Either<Vec<String>, bool>>,
pub id: Option<String>,
}

impl From<RawDllManifestContentItem> for DllManifestContentItem {
fn from(value: RawDllManifestContentItem) -> Self {
Self {
build_meta: value.build_meta.map(|meta| meta.into()),
exports: value.exports.map(|exports| {
exports
let raw_exports = value.exports;

let exports = raw_exports.map(|exports| match exports {
Either::A(seq) => DllManifestContentItemExports::Vec(
seq
.into_iter()
.map(|export| Atom::from(export))

Check failure on line 96 in crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs

GitHub Actions / Rust check

redundant closure
.collect::<Vec<_>>()
}),
.collect::<Vec<_>>(),
),
Either::B(bool) => {
if bool {
DllManifestContentItemExports::True
} else {
unreachable!()
}
}
});

Self {
build_meta: value.build_meta.map(|meta| meta.into()),
exports,
id: value.id.into(),

Check failure on line 111 in crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs

GitHub Actions / Rust check

useless conversion to the same type: `std::option::Option<std::string::String>`
}
}
}

#[napi(object, object_to_js = false)]
pub struct RawDllManifest {
pub content: RawDllManifestContent,
pub content: HashMap<String, RawDllManifestContentItem>,
pub name: Option<String>,
pub r#type: Option<String>,
}
@@ -115,8 +128,8 @@
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect::<DllManifestContent>(),
name: value.name.map(|n| n.into()),

Check failure on line 131 in crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs

GitHub Actions / Rust check

useless conversion to the same type: `std::string::String`
r#type: value.r#type.into(),

Check failure on line 132 in crates/rspack_binding_options/src/options/raw_builtins/raw_dll.rs

GitHub Actions / Rust check

useless conversion to the same type: `std::option::Option<std::string::String>`
}
}
}
2 changes: 1 addition & 1 deletion crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
@@ -605,7 +605,7 @@ impl From<JsBuildMeta> for BuildMeta {
.into_iter()
.map(|export_name| {
let first = export_name
.get(0)
.first()
.expect("The buildMeta exportsFinalName item should have first value")
.clone();
let second = export_name
32 changes: 18 additions & 14 deletions crates/rspack_plugin_dll/src/dll_reference/delegated_module.rs
Original file line number Diff line number Diff line change
@@ -5,16 +5,16 @@ use rspack_collections::{Identifiable, Identifier};
use rspack_core::{
impl_module_meta_info, impl_source_map_config, module_raw, module_update_hash,
rspack_sources::{BoxSource, OriginalSource, RawSource, Source},
throw_missing_module_error_block, AsyncDependenciesBlockIdentifier, BuildContext, BuildInfo,
BuildMeta, BuildResult, CodeGenerationResult, Compilation, ConcatenationScope, Context,
DependenciesBlock, DependencyId, FactoryMeta, LibIdentOptions, Module, ModuleDependency,
throw_missing_module_error_block, AsyncDependenciesBlockIdentifier, BoxDependency, BuildContext,
BuildInfo, BuildMeta, BuildResult, CodeGenerationResult, Compilation, ConcatenationScope,
Context, DependenciesBlock, DependencyId, FactoryMeta, LibIdentOptions, Module, ModuleDependency,
ModuleType, RuntimeGlobals, RuntimeSpec, SourceType, StaticExportsDependency, StaticExportsSpec,
};
use rspack_error::{impl_empty_diagnosable_trait, Diagnostic, Result};
use rspack_util::source_map::ModuleSourceMapConfig;

use super::delegated_source_dependency::DelegatedSourceDependency;
use crate::DllManifestContentItem;
use crate::{DllManifestContentItem, DllManifestContentItemExports};

pub type SourceRequest = String;

@@ -95,17 +95,21 @@ impl Module for DelegatedModule {
_build_context: BuildContext,
_compilation: Option<&Compilation>,
) -> Result<BuildResult> {
Ok(BuildResult {
dependencies: vec![
Box::new(DelegatedSourceDependency::new(self.source_request.clone())),
Box::new(StaticExportsDependency::new(
match self.delegate_data.exports.clone() {
Some(exports) => StaticExportsSpec::Array(exports),
None => StaticExportsSpec::True,
let dependencies = vec![
Box::new(DelegatedSourceDependency::new(self.source_request.clone())),
Box::new(StaticExportsDependency::new(
match self.delegate_data.exports.clone() {
Some(exports) => match exports {
DllManifestContentItemExports::True => StaticExportsSpec::True,
DllManifestContentItemExports::Vec(vec) => StaticExportsSpec::Array(vec),
},
false,
)),
],
None => StaticExportsSpec::True,
},
false,
)) as BoxDependency,
];
Ok(BuildResult {
dependencies,
build_meta: self.delegate_data.build_meta.clone().unwrap_or_default(),
..Default::default()
})
29 changes: 27 additions & 2 deletions crates/rspack_plugin_dll/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rspack_core::{BuildMeta, LibraryType};
use rspack_util::atom::Atom;
use rustc_hash::FxHashMap as HashMap;
use serde::Serialize;
use serde::{ser::SerializeSeq, Serialize};

mod dll_entry;
mod dll_reference;
@@ -10,14 +10,39 @@ mod lib_manifest_plugin;

pub type DllManifestContent = HashMap<String, DllManifestContentItem>;

#[derive(Debug, Default, Clone)]
pub enum DllManifestContentItemExports {
#[default]
True,
Vec(Vec<Atom>),
}

impl Serialize for DllManifestContentItemExports {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
DllManifestContentItemExports::True => serializer.serialize_bool(true),
DllManifestContentItemExports::Vec(vec) => {
let mut seq = serializer.serialize_seq(Some(vec.len()))?;
for item in vec {
seq.serialize_element(item)?;
}
seq.end()
}
}
}
}

#[derive(Debug, Default, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DllManifestContentItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub build_meta: Option<BuildMeta>,

#[serde(skip_serializing_if = "Option::is_none")]
pub exports: Option<Vec<Atom>>,
pub exports: Option<DllManifestContentItemExports>,

#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
13 changes: 5 additions & 8 deletions crates/rspack_plugin_dll/src/lib_manifest_plugin.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ use rspack_error::{Error, Result};
use rspack_hook::{plugin, plugin_hook};
use rustc_hash::FxHashMap as HashMap;

use crate::{DllManifest, DllManifestContent, DllManifestContentItem};
use crate::{
DllManifest, DllManifestContent, DllManifestContentItem, DllManifestContentItemExports,
};

#[derive(Debug, Clone)]
pub struct LibManifestPluginOptions {
@@ -124,13 +126,8 @@ async fn emit(&self, compilation: &mut Compilation) -> Result<()> {
let exports_info = module_graph.get_exports_info(&module.identifier());

let provided_exports = match exports_info.get_provided_exports(&module_graph) {
ProvidedExports::Vec(vec) => {
if vec.is_empty() {
None
} else {
Some(vec)
}
}
ProvidedExports::Vec(vec) => Some(DllManifestContentItemExports::Vec(vec)),
ProvidedExports::True => Some(DllManifestContentItemExports::True),
_ => None,
};

2 changes: 1 addition & 1 deletion packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
@@ -1451,7 +1451,7 @@ export interface DllReferencePluginOptionsContent {
[k: string]: {
buildMeta?: JsBuildMeta;
exports?: string[] | true;
id: number | string;
id: string;
};
}

4 changes: 2 additions & 2 deletions packages/rspack/src/lib/DllReferencePlugin.ts
Original file line number Diff line number Diff line change
@@ -133,14 +133,14 @@ export interface DllReferencePluginOptionsContent {
/**
* Module ID.
*/
id: number | string;
id: string;
};
}

const dllReferencePluginOptionsContentItem = z.object({
buildMeta: z.custom<JsBuildMeta>().optional(),
exports: z.array(z.string()).or(z.literal(true)).optional(),
id: z.union([z.number(), z.string()])
id: z.string()
});

const dllReferencePluginOptionsContent = z.record(
2 changes: 1 addition & 1 deletion website/docs/en/plugins/webpack/dll-reference-plugin.mdx
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ type DllReferencePluginOptionsContent = {
/**
* Module ID.
*/
id: number | string;
id: string;
};
};

2 changes: 1 addition & 1 deletion website/docs/zh/plugins/webpack/dll-reference-plugin.mdx
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ type DllReferencePluginOptionsContent = {
/**
* Module ID.
*/
id: number | string;
id: string;
};
};

Loading