Skip to content

Commit

Permalink
Merge branch 'main' into fix/remove-lightningCssMinimizerRspackPlugin…
Browse files Browse the repository at this point in the history
…-options-exclude-default-value
  • Loading branch information
chenjiahan authored Sep 11, 2024
2 parents 255fcdb + 930e351 commit 57fa4e6
Show file tree
Hide file tree
Showing 263 changed files with 10,221 additions and 1,154 deletions.
17 changes: 0 additions & 17 deletions .eslintignore

This file was deleted.

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

This file was deleted.

52 changes: 52 additions & 0 deletions .github/actions/clean/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Clean Repository

inputs:
target:
required: true
type: string

runs:
using: composite
steps:
- name: Git Clean
shell: bash
run: |
git config --system core.longpaths true
rm -rf node_modules
git clean -ffdx -e target
git reset --hard HEAD
- name: Clean Large Directories by Size
if: ${{ !contains(inputs.target, 'windows') }}
shell: bash
run: |
if [ -d "target" ]; then
TARGET_SIZE=$(du -s target | awk '{print $1}')
MAX_SIZE=$((50 * 1024 * 1024))
echo "MAX_SIZE = $MAX_SIZE"
if [ "$TARGET_SIZE" -gt "$MAX_SIZE" ]; then
echo "`target` directory size is greater than 50GB, deleting..."
rm -rf target
else
echo "`target` directory size is within limits."
fi
fi
- name: Clean Large Directories by Time
if: ${{ contains(inputs.target, 'windows') }}
shell: bash
run: |
if [ -d "target" ]; then
TARGET_CREATION_TIME=$(powershell -Command "(Get-Item 'target').CreationTime")
TWO_WEEKS_AGO=$(date -d '2 weeks ago' +%s)
echo "TARGET_CREATION_TIME = $TARGET_CREATION_TIME"
if [ "$TARGET_CREATION_TIME" -lt "$TWO_WEEKS_AGO" ]; then
echo "'target' directory is older than 2 weeks, deleting..."
rm -rf target
else
echo "'target' directory is within 2 weeks."
fi
fi
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
39 changes: 12 additions & 27 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,11 @@ jobs:
ref: ${{ inputs.ref }}
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}

- name: Git Clean
- name: Clean
if: ${{ !inputs.skipable && !startsWith(runner.name, 'GitHub Actions') }}
shell: bash
run: |
git config --system core.longpaths true
echo "rm -rf node_modules"
rm -rf node_modules
echo "git clean -ffdx -e target"
git clean -ffdx -e target
git reset --hard HEAD
uses: ./.github/actions/clean
with:
target: ${{ inputs.target }}

- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
Expand Down Expand Up @@ -225,16 +220,11 @@ jobs:
ref: ${{ inputs.ref }}
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}

- name: Git Clean
- name: Clean
if: ${{ !startsWith(runner.name, 'GitHub Actions') }}
shell: bash
run: |
git config --system core.longpaths true
echo "rm -rf node_modules"
rm -rf node_modules
echo "git clean -ffdx -e target"
git clean -ffdx -e target
git reset --hard HEAD
uses: ./.github/actions/clean
with:
target: ${{ inputs.target }}

- name: Download bindings
uses: ./.github/actions/download-artifact
Expand Down Expand Up @@ -282,16 +272,11 @@ jobs:
ref: ${{ inputs.ref }}
clean: ${{ startsWith(runner.name, 'GitHub Actions') }}

- name: Git Clean
- name: Clean
if: ${{ !inputs.skipable && !startsWith(runner.name, 'GitHub Actions') }}
shell: bash
run: |
git config --system core.longpaths true
echo "rm -rf node_modules"
rm -rf node_modules
echo "git clean -ffdx -e target"
git clean -ffdx -e target
git reset --hard HEAD
uses: ./.github/actions/clean
with:
target: ${{ inputs.target }}

- name: Download bindings
if: ${{ !inputs.skipable }}
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"tokio",
"ukey",
"Ukey"
]
],
"rust-analyzer.checkOnSave": false
}
1 change: 1 addition & 0 deletions Cargo.lock

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

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
}
}
}
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.4",
"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
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,43 @@ impl Debug for CssExtractRspackAdditionalDataPlugin {
}

#[plugin_hook(NormalModuleAdditionalData for CssExtractRspackAdditionalDataPlugin)]
async fn additional_data(&self, additional_data: &mut AdditionalData) -> Result<()> {
if !additional_data.contains::<ThreadsafeJsValueRef<Unknown>>() {
async fn additional_data(&self, additional_data: &mut Option<&mut AdditionalData>) -> Result<()> {
if !additional_data
.as_ref()
.is_some_and(|data| data.contains::<ThreadsafeJsValueRef<Unknown>>())
{
return Ok(());
}
let (tx, rx) = oneshot::channel::<AdditionalData>();
let mut old_data = std::mem::take(additional_data);
self.js_callback.call(Box::new(move |env| {
if let Some(data) = old_data.get::<ThreadsafeJsValueRef<Unknown>>()
&& let Ok(data) = data.get(env)
&& let Ok(data) = data.coerce_to_object()
&& let Ok(Some(data)) = data.get::<_, String>("css-extract-rspack-plugin")
{
let data_list: Vec<rspack_plugin_extract_css::CssExtractJsonData> = data
.split("__RSPACK_CSS_EXTRACT_SEP__")
.map(|info| {
serde_json::from_str(info)
.unwrap_or_else(|e| panic!("failed to parse CssExtractJsonData: {}", e))
})
.collect();
if let Some(mut old_data) = additional_data.as_mut().map(|data| std::mem::take(*data)) {
let (tx, rx) = oneshot::channel::<AdditionalData>();
self.js_callback.call(Box::new(move |env| {
if let Some(data) = old_data
.get::<ThreadsafeJsValueRef<Unknown>>()
.and_then(|data| data.get(env).ok())
.and_then(|data| data.coerce_to_object().ok())
.and_then(|data| data.get::<_, String>("css-extract-rspack-plugin").ok())
.flatten()
{
let data_list: Vec<rspack_plugin_extract_css::CssExtractJsonData> = data
.split("__RSPACK_CSS_EXTRACT_SEP__")
.map(|info| {
serde_json::from_str(info)
.unwrap_or_else(|e| panic!("failed to parse CssExtractJsonData: {}", e))
})
.collect();

old_data.insert(CssExtractJsonDataList(data_list));
};
tx.send(old_data)
.expect("should send `additional_data` for `CssExtractRspackAdditionalDataPlugin`");
}));
let new_data = rx
.await
.expect("should receive `additional_data` for `CssExtractRspackAdditionalDataPlugin`");
// ignore the default value here
let _ = std::mem::replace(additional_data, new_data);
old_data.insert(CssExtractJsonDataList(data_list));
};
tx.send(old_data)
.expect("should send `additional_data` for `CssExtractRspackAdditionalDataPlugin`");
}));
let new_data = rx
.await
.expect("should receive `additional_data` for `CssExtractRspackAdditionalDataPlugin`");
if let Some(data) = additional_data.as_mut() {
let _ = std::mem::replace(*data, new_data);
}
}
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions crates/rspack_binding_options/src/plugins/js_loader/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ impl TryFrom<&mut LoaderContext<RunnerContext>> for JsLoaderContext {
.to_js_module()
.expect("CompilerModuleContext::to_js_module should not fail."),
hot: cx.hot,
content: match &cx.content {
content: match cx.content() {
Some(c) => Either::B(c.to_owned().into_bytes().into()),
None => Either::A(Null),
},
additional_data: cx
.additional_data
.get::<ThreadsafeJsValueRef<Unknown>>()
.additional_data()
.and_then(|data| data.get::<ThreadsafeJsValueRef<Unknown>>())
.cloned(),
source_map: cx
.source_map
.clone()
.source_map()
.cloned()
.map(|v| v.to_json())
.transpose()
.map_err(|e| error!(e.to_string()))?
Expand Down
Loading

0 comments on commit 57fa4e6

Please sign in to comment.