Skip to content

Commit

Permalink
chore: merge origin main
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 14, 2024
2 parents c1ce16c + 3fb8f24 commit 2b1d166
Show file tree
Hide file tree
Showing 471 changed files with 32,465 additions and 2,069 deletions.
17 changes: 0 additions & 17 deletions .eslintignore

This file was deleted.

5 changes: 0 additions & 5 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/release-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ jobs:
uses: ./.github/actions/pnpm-cache

- name: Create Release Pull Request
uses: hardfist/rspack-action@rspack
# https://github.com/rspack-contrib/rspack-action
uses: rspack-contrib/rspack-action@rspack
with:
version: node ./x version ${{inputs.version || 'patch'}}
createGithubReleases: false
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ tests/plugin-test/css-extract/js

tests/plugin-test/html-plugin/js

!packages/rspack-dev-server/tests/fixtures/**/node_modules

/webpack-examples/**/dist

smoke-example
Expand Down
5 changes: 2 additions & 3 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
"noFallthroughSwitchClause": "off",
"noConfusingVoidType": "off",
"noPrototypeBuiltins": "off",
"noImplicitAnyLet": "off",
"noAssignInExpressions": "off",
"noArrayIndexKey": "off",
"noControlCharactersInRegex": "off",
"noExplicitAny": "off"
}
Expand All @@ -68,6 +66,7 @@
// --- ignore runtime code in browser
"packages/rspack/hot",
"packages/rspack-dev-server/client",
"packages/rspack-dev-server/tests",
"packages/rspack/src/container/default.runtime.js"
]
},
Expand All @@ -77,4 +76,4 @@
"clientKind": "git",
"useIgnoreFile": true
}
}
}
10 changes: 6 additions & 4 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ export interface JsLoaderContext {
/** Content maybe empty in pitching stage */
content: null | Buffer
additionalData?: any
__internal__parseMeta: Record<string, string>
sourceMap?: Buffer
cacheable: boolean
fileDependencies: Array<string>
Expand Down Expand Up @@ -1609,11 +1610,12 @@ export interface RawPathData {
}

export interface RawProgressPluginOptions {
prefix: string
profile: boolean
template: string
prefix?: string
profile?: boolean
template?: string
tick?: string | Array<string>
progressChars: string
progressChars?: string
handler?: (percent: number, msg: string, items: string[]) => void
}

export interface RawProvideOptions {
Expand Down
2 changes: 1 addition & 1 deletion crates/node_binding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rspack/binding",
"version": "1.0.3",
"version": "1.0.5",
"license": "MIT",
"description": "Node binding for rspack",
"main": "binding.js",
Expand Down
4 changes: 1 addition & 3 deletions crates/node_binding/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use std::{
},
};

use rspack_fs_node::AsyncNodeWritableFileSystem;

type CompilerInner = rspack_core::Compiler<AsyncNodeWritableFileSystem>;
type CompilerInner = rspack_core::Compiler;

/// `Compiler` struct that is `!Unpin`.
pub(crate) struct Compiler(CompilerInner, PhantomPinned);
Expand Down
6 changes: 4 additions & 2 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ impl Rspack {
let rspack = rspack_core::Compiler::new(
compiler_options,
plugins,
AsyncNodeWritableFileSystem::new(output_filesystem)
.map_err(|e| Error::from_reason(format!("Failed to create writable filesystem: {e}",)))?,
Box::new(
AsyncNodeWritableFileSystem::new(output_filesystem)
.map_err(|e| Error::from_reason(format!("Failed to create writable filesystem: {e}",)))?,
),
Some(resolver_factory),
Some(loader_resolver_factory),
);
Expand Down
11 changes: 4 additions & 7 deletions crates/node_binding/src/plugins/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,7 @@ impl CompilationAfterSeal for CompilationAfterSealTap {
#[async_trait]
impl NormalModuleFactoryBeforeResolve for NormalModuleFactoryBeforeResolveTap {
async fn run(&self, data: &mut ModuleFactoryCreateData) -> rspack_error::Result<Option<bool>> {
let dependency = data
.dependency
let dependency = data.dependencies[0]
.as_module_dependency_mut()
.expect("should be module dependency");
match self
Expand Down Expand Up @@ -1305,8 +1304,7 @@ impl NormalModuleFactoryFactorize for NormalModuleFactoryFactorizeTap {
&self,
data: &mut ModuleFactoryCreateData,
) -> rspack_error::Result<Option<BoxModule>> {
let dependency = data
.dependency
let dependency = data.dependencies[0]
.as_module_dependency_mut()
.expect("should be module dependency");
match self
Expand Down Expand Up @@ -1343,8 +1341,7 @@ impl NormalModuleFactoryResolve for NormalModuleFactoryResolveTap {
&self,
data: &mut ModuleFactoryCreateData,
) -> rspack_error::Result<Option<NormalModuleFactoryResolveResult>> {
let dependency = data
.dependency
let dependency = data.dependencies[0]
.as_module_dependency_mut()
.expect("should be module dependency");
match self
Expand Down Expand Up @@ -1487,7 +1484,7 @@ impl NormalModuleFactoryCreateModule for NormalModuleFactoryCreateModuleTap {
self
.function
.call_with_promise(JsNormalModuleFactoryCreateModuleArgs {
dependency_type: data.dependency.dependency_type().to_string(),
dependency_type: data.dependencies[0].dependency_type().to_string(),
raw_request: create_data.raw_request.clone(),
resource_resolve_data: create_data.resource_resolve_data.clone().into(),
context: data.context.to_string(),
Expand Down
7 changes: 2 additions & 5 deletions crates/rspack_binding_options/src/options/raw_builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ use self::{
raw_size_limits::RawSizeLimitsPluginOptions,
};
use crate::{
plugins::{CssExtractRspackAdditionalDataPlugin, JsLoaderRspackPlugin},
JsLoaderRunner, RawContextReplacementPluginOptions, RawDynamicEntryPluginOptions,
plugins::JsLoaderRspackPlugin, JsLoaderRunner, RawDynamicEntryPluginOptions,
RawEvalDevToolModulePluginOptions, RawExternalItemWrapper, RawExternalsPluginOptions,
RawHttpExternalsRspackPluginOptions, RawSourceMapDevToolPluginOptions, RawSplitChunksOptions,
};
Expand Down Expand Up @@ -189,7 +188,7 @@ pub struct BuiltinPlugin {
}

impl BuiltinPlugin {
pub fn append_to(self, env: Env, plugins: &mut Vec<BoxPlugin>) -> rspack_error::Result<()> {
pub fn append_to(self, _env: Env, plugins: &mut Vec<BoxPlugin>) -> rspack_error::Result<()> {
match self.name {
// webpack also have these plugins
BuiltinPluginName::DefinePlugin => {
Expand Down Expand Up @@ -481,8 +480,6 @@ impl BuiltinPlugin {
)
}
BuiltinPluginName::CssExtractRspackPlugin => {
let additional_data_plugin = CssExtractRspackAdditionalDataPlugin::new(env)?.boxed();
plugins.push(additional_data_plugin);
let plugin = rspack_plugin_extract_css::plugin::PluginCssExtract::new(
downcast_into::<RawCssExtractPluginOption>(self.options)?.into(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
use std::sync::Arc;

use derivative::Derivative;
use napi::Either;
use napi_derive::napi;
use rspack_plugin_progress::ProgressPluginOptions;
use rspack_napi::threadsafe_function::ThreadsafeFunction;
use rspack_plugin_progress::{ProgressPluginDisplayOptions, ProgressPluginOptions};

#[derive(Debug, Clone)]
#[napi(object)]
type HandlerFn = ThreadsafeFunction<(f64, String, Vec<String>), ()>;
#[derive(Derivative)]
#[derivative(Debug)]
#[napi(object, object_to_js = false)]
pub struct RawProgressPluginOptions {
// the prefix name of progress bar
pub prefix: String,
pub prefix: Option<String>,
// tells ProgressPlugin to collect profile data for progress steps.
pub profile: bool,
pub profile: Option<bool>,
// the template of progress bar
pub template: String,
pub template: Option<String>,
// the tick string sequence for spinners, if it's string then it will be split into characters
pub tick: Option<Either<String, Vec<String>>>,
// the progress characters
pub progress_chars: String,
pub progress_chars: Option<String>,
// the handler for progress event
#[derivative(Debug = "ignore")]
#[napi(ts_type = "(percent: number, msg: string, items: string[]) => void")]
pub handler: Option<HandlerFn>,
}

impl From<RawProgressPluginOptions> for ProgressPluginOptions {
fn from(value: RawProgressPluginOptions) -> Self {
Self {
prefix: value.prefix,
profile: value.profile,
template: value.template,
progress_chars: value.progress_chars,
tick_strings: value.tick.map(|tick| match tick {
Either::A(str) => str.chars().map(|c| c.to_string()).collect(),
Either::B(vec) => vec,
}),
if let Some(f) = value.handler {
Self::Handler(Arc::new(move |percent, msg, items| {
f.blocking_call_with_sync((percent, msg, items))
}))
} else {
Self::Default(ProgressPluginDisplayOptions {
prefix: value.prefix.unwrap_or_default(),
profile: value.profile.unwrap_or_default(),
template: value.template.unwrap_or(
"● {prefix:.bold} {bar:25.green/white.dim} ({percent}%) {wide_msg:.dim}".to_string(),
),
progress_chars: value.progress_chars.unwrap_or("━━".to_string()),
tick_strings: value.tick.map(|tick| match tick {
Either::A(str) => str.chars().map(|c| c.to_string()).collect(),
Either::B(vec) => vec,
}),
})
}
}
}
52 changes: 35 additions & 17 deletions crates/rspack_binding_options/src/options/raw_module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use rspack_core::{
AssetParserDataUrlOptions, AssetParserOptions, AssetResourceGeneratorOptions,
CssAutoGeneratorOptions, CssAutoParserOptions, CssGeneratorOptions, CssModuleGeneratorOptions,
CssModuleParserOptions, CssParserOptions, DescriptionData, DynamicImportFetchPriority,
DynamicImportMode, ExportPresenceMode, FuncUseCtx, GeneratorOptions,
GeneratorOptionsByModuleType, JavascriptParserOptions, JavascriptParserOrder,
JavascriptParserUrl, ModuleNoParseRule, ModuleNoParseRules, ModuleNoParseTestFn, ModuleOptions,
ModuleRule, ModuleRuleEffect, ModuleRuleEnforce, ModuleRuleUse, ModuleRuleUseLoader, ModuleType,
OverrideStrict, ParserOptions, ParserOptionsByModuleType,
DynamicImportMode, ExportPresenceMode, FuncUseCtx, GeneratorOptions, GeneratorOptionsMap,
JavascriptParserOptions, JavascriptParserOrder, JavascriptParserUrl, ModuleNoParseRule,
ModuleNoParseRules, ModuleNoParseTestFn, ModuleOptions, ModuleRule, ModuleRuleEffect,
ModuleRuleEnforce, ModuleRuleUse, ModuleRuleUseLoader, OverrideStrict, ParserOptions,
ParserOptionsMap,
};
use rspack_error::error;
use rspack_napi::regexp::{JsRegExp, JsRegExpExt};
Expand Down Expand Up @@ -203,14 +203,32 @@ impl From<RawParserOptions> for ParserOptions {
.expect("should have an \"asset\" when RawParserOptions.type is \"asset\"")
.into(),
),
"javascript" | "javascript/auto" | "javascript/dynamic" | "javascript/esm" => {
Self::Javascript(
value
.javascript
.expect("should have an \"javascript\" when RawParserOptions.type is \"javascript\"")
.into(),
)
}
"javascript" => Self::Javascript(
value
.javascript
.expect("should have an \"javascript\" when RawParserOptions.type is \"javascript\"")
.into(),
),
"javascript/auto" => Self::JavascriptAuto(
value
.javascript
.expect("should have an \"javascript\" when RawParserOptions.type is \"javascript/auto\"")
.into(),
),
"javascript/dynamic" => Self::JavascriptDynamic(
value
.javascript
.expect(
"should have an \"javascript\" when RawParserOptions.type is \"javascript/dynamic\"",
)
.into(),
),
"javascript/esm" => Self::JavascriptEsm(
value
.javascript
.expect("should have an \"javascript\" when RawParserOptions.type is \"javascript/esm\"")
.into(),
),
"css" => Self::Css(
value
.css
Expand Down Expand Up @@ -805,16 +823,16 @@ impl TryFrom<RawModuleOptions> for ModuleOptions {
.parser
.map(|x| {
x.into_iter()
.map(|(k, v)| Ok((ModuleType::from(k.as_str()), v.into())))
.collect::<std::result::Result<ParserOptionsByModuleType, rspack_error::Error>>()
.map(|(k, v)| Ok((k, v.into())))
.collect::<std::result::Result<ParserOptionsMap, rspack_error::Error>>()
})
.transpose()?,
generator: value
.generator
.map(|x| {
x.into_iter()
.map(|(k, v)| Ok((ModuleType::from(k.as_str()), v.into())))
.collect::<std::result::Result<GeneratorOptionsByModuleType, rspack_error::Error>>()
.map(|(k, v)| Ok((k, v.into())))
.collect::<std::result::Result<GeneratorOptionsMap, rspack_error::Error>>()
})
.transpose()?,
no_parse: value
Expand Down
Loading

0 comments on commit 2b1d166

Please sign in to comment.