Skip to content

Commit

Permalink
Merge branch 'main' into fix/6078
Browse files Browse the repository at this point in the history
  • Loading branch information
hulin32 authored Apr 30, 2024
2 parents fca9853 + 42527c5 commit a1765a0
Show file tree
Hide file tree
Showing 1,169 changed files with 3,393 additions and 2,036 deletions.
4 changes: 2 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
},
{
"groupName": "npm ignored dependencies",
"matchManagers": ["npm", "sass"],
"matchPackageNames": ["@playwright/test", "react", "react-dom", "typescript", "pnpm"],
"matchManagers": ["npm"],
"matchPackageNames": ["@playwright/test", "react", "react-dom", "typescript", "pnpm", "sass"],
"enabled": false
},
{
Expand Down
28 changes: 28 additions & 0 deletions Cargo.lock

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

25 changes: 23 additions & 2 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export enum BuiltinPluginName {
IgnorePlugin = 'IgnorePlugin',
ProgressPlugin = 'ProgressPlugin',
EntryPlugin = 'EntryPlugin',
DynamicEntryPlugin = 'DynamicEntryPlugin',
ExternalsPlugin = 'ExternalsPlugin',
NodeTargetPlugin = 'NodeTargetPlugin',
ElectronTargetPlugin = 'ElectronTargetPlugin',
Expand Down Expand Up @@ -161,6 +162,7 @@ export enum BuiltinPluginName {
ModuleConcatenationPlugin = 'ModuleConcatenationPlugin',
CssModulesPlugin = 'CssModulesPlugin',
APIPlugin = 'APIPlugin',
RuntimeChunkPlugin = 'RuntimeChunkPlugin',
HttpExternalsRspackPlugin = 'HttpExternalsRspackPlugin',
CopyRspackPlugin = 'CopyRspackPlugin',
HtmlRspackPlugin = 'HtmlRspackPlugin',
Expand Down Expand Up @@ -715,7 +717,7 @@ export interface RawContainerPluginOptions {
name: string
shareScope: string
library: RawLibraryOptions
runtime?: string
runtime?: false | string
filename?: string
exposes: Array<RawExposeOptions>
enhanced: boolean
Expand Down Expand Up @@ -744,6 +746,7 @@ export interface RawCopyPattern {
priority: number
globOptions: RawCopyGlobOptions
info?: RawInfo
transform?: (input: string | Buffer, absoluteFilename: string) => string | Buffer
}

export interface RawCopyRspackPluginOptions {
Expand Down Expand Up @@ -796,9 +799,19 @@ export interface RawCssParserOptions {
namedExports?: boolean
}

export interface RawDynamicEntryPluginOptions {
context: string
entry: () => Promise<RawEntryDynamicResult[]>
}

export interface RawEntryDynamicResult {
import: Array<string>
options: RawEntryOptions
}

export interface RawEntryOptions {
name?: string
runtime?: string
runtime?: false | string
chunkLoading?: string
asyncChunks?: boolean
publicPath?: string
Expand Down Expand Up @@ -1247,6 +1260,14 @@ export interface RawRuleSetLogicalConditions {
not?: RawRuleSetCondition
}

export interface RawRuntimeChunkNameFnCtx {
name: string
}

export interface RawRuntimeChunkOptions {
name: string | ((entrypoint: { name: string }) => string)
}

export interface RawSnapshotOptions {
resolve: RawSnapshotStrategy
module: RawSnapshotStrategy
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rspack_plugin_banner = { path = "../rspack_plugin_banner" }
rspack_plugin_copy = { path = "../rspack_plugin_copy" }
rspack_plugin_css = { path = "../rspack_plugin_css" }
rspack_plugin_devtool = { path = "../rspack_plugin_devtool" }
rspack_plugin_dynamic_entry = { path = "../rspack_plugin_dynamic_entry" }
rspack_plugin_ensure_chunk_conditions = { path = "../rspack_plugin_ensure_chunk_conditions" }
rspack_plugin_entry = { path = "../rspack_plugin_entry" }
rspack_plugin_externals = { path = "../rspack_plugin_externals" }
Expand All @@ -48,6 +49,7 @@ rspack_plugin_progress = { path = "../rspack_plugin_progress" }
rspack_plugin_real_content_hash = { path = "../rspack_plugin_real_content_hash" }
rspack_plugin_remove_empty_chunks = { path = "../rspack_plugin_remove_empty_chunks" }
rspack_plugin_runtime = { path = "../rspack_plugin_runtime" }
rspack_plugin_runtime_chunk = { path = "../rspack_plugin_runtime_chunk" }
rspack_plugin_schemes = { path = "../rspack_plugin_schemes" }
rspack_plugin_split_chunks = { path = "../rspack_plugin_split_chunks" }
rspack_plugin_swc_css_minimizer = { path = "../rspack_plugin_swc_css_minimizer" }
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_options/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rspack_core::{
mod raw_builtins;
mod raw_cache;
mod raw_devtool;
mod raw_dynamic_entry;
mod raw_entry;
mod raw_experiments;
mod raw_external;
Expand All @@ -23,6 +24,7 @@ mod raw_stats;
pub use raw_builtins::*;
pub use raw_cache::*;
pub use raw_devtool::*;
pub use raw_dynamic_entry::*;
pub use raw_entry::*;
pub use raw_experiments::*;
pub use raw_external::*;
Expand Down
23 changes: 20 additions & 3 deletions crates/rspack_binding_options/src/options/raw_builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod raw_ignore;
mod raw_limit_chunk_count;
mod raw_mf;
mod raw_progress;
mod raw_runtime_chunk;
mod raw_swc_js_minimizer;
mod raw_to_be_deprecated;

Expand All @@ -28,6 +29,7 @@ use rspack_plugin_devtool::{
SourceMapDevToolModuleOptionsPluginOptions, SourceMapDevToolPlugin,
SourceMapDevToolPluginOptions,
};
use rspack_plugin_dynamic_entry::DynamicEntryPlugin;
use rspack_plugin_ensure_chunk_conditions::EnsureChunkConditionsPlugin;
use rspack_plugin_entry::EntryPlugin;
use rspack_plugin_externals::{
Expand Down Expand Up @@ -56,6 +58,7 @@ use rspack_plugin_runtime::{
enable_chunk_loading_plugin, ArrayPushCallbackChunkFormatPlugin, BundlerInfoPlugin,
ChunkPrefetchPreloadPlugin, CommonJsChunkFormatPlugin, ModuleChunkFormatPlugin, RuntimePlugin,
};
use rspack_plugin_runtime_chunk::RuntimeChunkPlugin;
use rspack_plugin_schemes::{DataUriPlugin, FileUriPlugin};
use rspack_plugin_swc_css_minimizer::SwcCssMinimizerRspackPlugin;
use rspack_plugin_swc_js_minimizer::SwcJsMinimizerRspackPlugin;
Expand All @@ -75,12 +78,13 @@ use self::{
raw_bundle_info::{RawBundlerInfoModeWrapper, RawBundlerInfoPluginOptions},
raw_css_extract::RawCssExtractPluginOption,
raw_mf::{RawConsumeSharedPluginOptions, RawContainerReferencePluginOptions, RawProvideOptions},
raw_runtime_chunk::RawRuntimeChunkOptions,
};
use crate::{
plugins::{CssExtractRspackAdditionalDataPlugin, JsLoaderResolverPlugin},
JsLoaderRunner, RawEntryPluginOptions, RawEvalDevToolModulePluginOptions, RawExternalItemWrapper,
RawExternalsPluginOptions, RawHttpExternalsRspackPluginOptions, RawSourceMapDevToolPluginOptions,
RawSplitChunksOptions,
JsLoaderRunner, RawDynamicEntryPluginOptions, RawEntryPluginOptions,
RawEvalDevToolModulePluginOptions, RawExternalItemWrapper, RawExternalsPluginOptions,
RawHttpExternalsRspackPluginOptions, RawSourceMapDevToolPluginOptions, RawSplitChunksOptions,
};

#[napi(string_enum)]
Expand All @@ -93,6 +97,7 @@ pub enum BuiltinPluginName {
IgnorePlugin,
ProgressPlugin,
EntryPlugin,
DynamicEntryPlugin,
ExternalsPlugin,
NodeTargetPlugin,
ElectronTargetPlugin,
Expand Down Expand Up @@ -141,6 +146,7 @@ pub enum BuiltinPluginName {
ModuleConcatenationPlugin,
CssModulesPlugin,
APIPlugin,
RuntimeChunkPlugin,

// rspack specific plugins
// naming format follow XxxRspackPlugin
Expand Down Expand Up @@ -201,6 +207,13 @@ impl BuiltinPlugin {
let plugin = EntryPlugin::new(context, entry_request, options).boxed();
plugins.push(plugin);
}
BuiltinPluginName::DynamicEntryPlugin => {
let plugin = DynamicEntryPlugin::new(
downcast_into::<RawDynamicEntryPluginOptions>(self.options)?.into(),
)
.boxed();
plugins.push(plugin);
}
BuiltinPluginName::ExternalsPlugin => {
let plugin_options = downcast_into::<RawExternalsPluginOptions>(self.options)?;
let externals = plugin_options
Expand Down Expand Up @@ -383,6 +396,10 @@ impl BuiltinPlugin {
}
BuiltinPluginName::CssModulesPlugin => plugins.push(CssPlugin::default().boxed()),
BuiltinPluginName::APIPlugin => plugins.push(APIPlugin::default().boxed()),
BuiltinPluginName::RuntimeChunkPlugin => plugins.push(
RuntimeChunkPlugin::new(downcast_into::<RawRuntimeChunkOptions>(self.options)?.into())
.boxed(),
),

// rspack specific plugins
BuiltinPluginName::HttpExternalsRspackPlugin => {
Expand Down
44 changes: 40 additions & 4 deletions crates/rspack_binding_options/src/options/raw_builtins/raw_copy.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use std::path::PathBuf;

use derivative::Derivative;
use napi::{bindgen_prelude::Buffer, Either};
use napi_derive::napi;
use rspack_core::rspack_sources::RawSource;
use rspack_napi::threadsafe_function::ThreadsafeFunction;
use rspack_plugin_copy::{
CopyGlobOptions, CopyPattern, CopyRspackPluginOptions, Info, Related, ToType,
CopyGlobOptions, CopyPattern, CopyRspackPluginOptions, Info, Related, ToType, Transformer,
};

#[derive(Debug, Clone)]
#[napi(object)]
type RawTransformer = ThreadsafeFunction<(Either<String, Buffer>, String), Either<String, Buffer>>;

#[derive(Derivative)]
#[derivative(Debug, Clone)]
#[napi(object, object_to_js = false)]
pub struct RawCopyPattern {
pub from: String,
pub to: Option<String>,
Expand All @@ -17,6 +24,9 @@ pub struct RawCopyPattern {
pub priority: i32,
pub glob_options: RawCopyGlobOptions,
pub info: Option<RawInfo>,
#[derivative(Debug = "ignore")]
#[napi(ts_type = "(input: string | Buffer, absoluteFilename: string) => string | Buffer")]
pub transform: Option<RawTransformer>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -47,7 +57,7 @@ pub struct RawCopyGlobOptions {
}

#[derive(Debug)]
#[napi(object)]
#[napi(object, object_to_js = false)]
pub struct RawCopyRspackPluginOptions {
pub patterns: Vec<RawCopyPattern>,
}
Expand All @@ -64,6 +74,7 @@ impl From<RawCopyPattern> for CopyPattern {
priority,
glob_options,
info,
transform,
} = value;

Self {
Expand Down Expand Up @@ -97,6 +108,31 @@ impl From<RawCopyPattern> for CopyPattern {
.collect()
}),
},
transform: transform.map(|transformer| {
Transformer::Fn(Box::new(move |input, absolute_filename| {
let f = transformer.clone();

fn convert_to_enum(input: Either<String, Buffer>) -> RawSource {
match input {
Either::A(s) => RawSource::Source(s),
Either::B(b) => RawSource::Buffer(b.to_vec()),
}
}

fn convert_to_js_type(input: RawSource) -> Either<String, Buffer> {
match input {
RawSource::Source(s) => Either::A(s),
RawSource::Buffer(b) => Either::B(b.into()),
}
}

Box::pin(async move {
f.call((convert_to_js_type(input), absolute_filename.to_owned()))
.await
.map(convert_to_enum)
})
}))
}),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ use rspack_plugin_mf::{
ContainerReferencePluginOptions, ExposeOptions, ProvideOptions, ProvideVersion, RemoteOptions,
};

use crate::RawLibraryOptions;
use crate::{RawEntryRuntime, RawEntryRuntimeWrapper, RawLibraryOptions};

#[derive(Debug)]
#[napi(object)]
pub struct RawContainerPluginOptions {
pub name: String,
pub share_scope: String,
pub library: RawLibraryOptions,
pub runtime: Option<String>,
#[napi(ts_type = "false | string")]
pub runtime: Option<RawEntryRuntime>,
pub filename: Option<String>,
pub exposes: Vec<RawExposeOptions>,
pub enhanced: bool,
Expand All @@ -27,7 +28,7 @@ impl From<RawContainerPluginOptions> for ContainerPluginOptions {
name: value.name,
share_scope: value.share_scope,
library: value.library.into(),
runtime: value.runtime,
runtime: value.runtime.map(|r| RawEntryRuntimeWrapper(r).into()),
filename: value.filename.map(|f| f.into()),
exposes: value.exposes.into_iter().map(|e| e.into()).collect(),
enhanced: value.enhanced,
Expand Down
Loading

0 comments on commit a1765a0

Please sign in to comment.