Skip to content

Commit

Permalink
feat: enable lightning css minimizer error recovery (#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Jul 1, 2024
1 parent 3e77471 commit 12d6df7
Show file tree
Hide file tree
Showing 40 changed files with 544 additions and 50 deletions.
6 changes: 3 additions & 3 deletions crates/rspack_plugin_lightning_css_minimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
.map_err(|e| error!(e.to_string()))?;
let warnings = warnings.read().expect("should lock");
all_warnings.write().expect("should lock").extend(
warnings
.iter()
.map(|e| Diagnostic::error("Css minimize error".to_string(), e.to_string())),
warnings.iter().map(|e| {
Diagnostic::warn("LightningCSS minimize warning".to_string(), e.to_string())
}),
);
result
};
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/case/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const creator = new BasicCaseCreator({
format: (output: string) => {
// TODO: change to stats.errorStack
// TODO: add `errorStack: false`
return output.replace(/[│\s]*at([│\s]|.)*/g, "");
return output.replace(/(│.* at ).*/g, "$1xxx");
}
})
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Object {
"browserslist": Array [
"defaults",
],
"errorRecovery": false,
"errorRecovery": true,
"removeUnusedLocalIdents": true,
"unusedSymbols": Array [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Object {
"files": Array [
"main.js",
],
"hash": "f2bc7a8c0bdc1f7b62f2",
"hash": "90a887a17a80d0e19be5",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -157,7 +157,7 @@ Object {
"errors": Array [],
"errorsCount": 0,
"filteredModules": undefined,
"hash": "ee11b48ddc40a1c0f1c4",
"hash": "c54fcee237a48276e019",
"modules": Array [
Object {
"assets": Array [],
Expand Down Expand Up @@ -287,7 +287,7 @@ Object {
"files": Array [
"main.js",
],
"hash": "e1a612615a3947e12730",
"hash": "5c934183f195b15a0942",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -623,7 +623,7 @@ Object {
"errors": Array [],
"errorsCount": 0,
"filteredModules": undefined,
"hash": "9ec361d93943966f85ad",
"hash": "c361435884d1304f092d",
"modules": Array [
Object {
"assets": Array [],
Expand Down Expand Up @@ -1321,7 +1321,7 @@ Object {
"files": Array [
"main.js",
],
"hash": "f2bc7a8c0bdc1f7b62f2",
"hash": "90a887a17a80d0e19be5",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -1421,7 +1421,7 @@ Object {
"files": Array [
"main.js",
],
"hash": "289e5d4472c8b47aba57",
"hash": "405eb59ae1d20f89b39f",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -1741,7 +1741,7 @@ exports.c = require(\\"./c?c=3\\");
"errors": Array [],
"errorsCount": 0,
"filteredModules": undefined,
"hash": "891879cb580b1ccbf8ab",
"hash": "38e04132ef7ebc852f6a",
"modules": Array [
Object {
"assets": Array [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// should not panic at crates/rspack_plugin_javascript/src/dependency/context/require_context_dependency.rs
// should not panic

require.context("./test", false, /\.test\.js$/);

Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
ERROR in ./index.js
× Resolve error: Can't resolve './test' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/cannot-resolve-context'
╭─[1:1]
1 │ // should not panic
1 │ // should not panic
2 │
3 │ require.context("./test", false, //.test/.js$/);
· ───────────────────────────────────────────────
4 │
╰────
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
ERROR in ./node_modules/some-module/a.ts
× Resolve error: Can't resolve './b.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/cannot-resolve-with-conc
× Resolve error: Can't resolve './b.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/cannot-resolve-with-concatenate-conflict/node_modules/some-module'
╭─[1:1]
1 │ export * from "./b.js";
· ────────
2 │ export * from "./c.js";
╰────

ERROR in ./node_modules/some-module/a.ts
× Resolve error: Can't resolve './c.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/cannot-resolve-with-concatenate-conflict/node_modules/some-module'
╭─[1:1]
1 │ export * from "./b.js";
2 │ export * from "./c.js";
· ────────
╰────
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
ERROR in ./node_modules/some-module/a.ts
× Resolve error: Can't resolve './b.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/cannot-resolve-with-conc
× Resolve error: Can't resolve './b.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/cannot-resolve-with-concatenate-import/node_modules/some-module'
╭────
1 │ export * from "./b.js";
· ────────
╰────
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
WARNING in ./index.css
⚠ Module parse warning:
╰─▶ ⚠ CSS parsing warning: '@import' or 'url()' with a request starts with '~' is deprec
╰─▶ ⚠ CSS parsing warning: '@import' or 'url()' with a request starts with '~' is deprecated.
╭─[1:1]
1 │ @import "~pkg";
· ───────────────
2 │
3 │ .class {
╰────
help: Remove '~' from the request.

WARNING in ./index.css
⚠ Module parse warning:
╰─▶ ⚠ CSS parsing warning: '@import' or 'url()' with a request starts with '~' is deprecated.
╭─[2:1]
2 │
3 │ .class {
4 │ background-image: url(~pkg/img.png);
· ─────────────────
5 │ }
╰────
help: Remove '~' from the request.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ ERROR in ./index.js
3 │ try {
4 │ await import("./non-exist")
· ─────────────────────
5 │ } c
5 │ } catch (err) {
6 │ errored = true
╰────
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ ERROR in ./index.js
probably because the origin is strict EcmaScript Module,
e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"'.

The extension in the request is mand
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Original file line number Diff line number Diff line change
@@ -1,3 +1,94 @@
ERROR in ./app.js
× Module parse failed:
╰─▶ × JavaScript parsing error: Untermin
╰─▶ × JavaScript parsing error: Unterminated regexp literal
╭─[2:1]
2 │ createElement() {}
3 │ };
4 │ export const App = () => <div></div>;
· ──────
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./app.js
× Module parse failed:
╰─▶ × JavaScript parsing error: Expression expected
╭─[2:1]
2 │ createElement() {}
3 │ };
4 │ export const App = () => <div></div>;
· ─
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./app.js
× Module parse failed:
╰─▶ × JavaScript parsing error: Expression expected
╭─[2:1]
2 │ createElement() {}
3 │ };
4 │ export const App = () => <div></div>;
· ─
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./app.jsx
× Module parse failed:
╰─▶ × JavaScript parsing error: Unterminated regexp literal
╭─[2:1]
2 │ createElement() {}
3 │ };
4 │ export const App = () => <div></div>;
· ──────
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./app.jsx
× Module parse failed:
╰─▶ × JavaScript parsing error: Expression expected
╭─[2:1]
2 │ createElement() {}
3 │ };
4 │ export const App = () => <div></div>;
· ─
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./app.jsx
× Module parse failed:
╰─▶ × JavaScript parsing error: Expression expected
╭─[2:1]
2 │ createElement() {}
3 │ };
4 │ export const App = () => <div></div>;
· ─
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./app.ts
× Module parse failed:
╰─▶ × JavaScript parsing error: Expected ',', got ':'
╭─[1:1]
1 │ const React = {
2 │ createElement(elm: any) {}
· ─
3 │ };
4 │ function Component<T>() {
╰────

help:
You may need an appropriate loader to handle this file type.

ERROR in ./index.js
× No parser registered for 'ts'
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ WARNING in ./index.js
3 │ try {
4 │ require("./missing-module");
· ───────────────────────────
5 │ } c
5 │ } catch (err) {
6 │ errored = true;
╰────
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ WARNING in ./locale.js
3 │ try {
4 │ locale = require('./locale/' + name);
· ───────────────────────────
5 │ } c
5 │ } catch (e) {
6 │ }
╰────
help: Found module './locale.js'. However, it's not possible to request this module without the extension
if its extension was not listed in the `resolve.extensions`. Here're some possible solutions:

1. add the extension `".js"` to `resolve.extensions` in your rspack configuration
2. use './locale.js' instead of './locale'
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
ERROR in ./index.js
× Resolve error: Can't resolve 'foo.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/prefer-rel
× Resolve error: Can't resolve 'foo.js' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/prefer-relative-resolve-suggestions'
╭────
1 │ import "foo.js"
· ────────
╰────
help: Did you mean './foo.js'?

Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).

If changing the source code is not an option, there is also a resolve options called 'preferRelative'
which tries to resolve these kind of requests in the current directory too.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,33 @@ ERROR in ./err/index.js
help: Found module '../a.txt'. However, it's not possible to request this module without the extension
if its extension was not listed in the `resolve.extensions`. Here're some possible solutions:

1. add the extension `".txt"` to `resolve.extensions` in your rspack configur
1. add the extension `".txt"` to `resolve.extensions` in your rspack configuration
2. use '../a.txt' instead of '../a'

ERROR in ./index.js
× Resolve error: Can't resolve './test' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/resolve-extensions-error'
╭─[1:1]
1 │ import './err';
2 │ import './test';
· ────────
3 │ import a from './a';
╰────
help: Found module './test/index.txt'. However, it's not possible to request this module without the extension
if its extension was not listed in the `resolve.extensions`. Here're some possible solutions:

1. add the extension `".txt"` to `resolve.extensions` in your rspack configuration
2. use './test/index.txt' instead of './test'

ERROR in ./index.js
× Resolve error: Can't resolve './a' in '<PROJECT_ROOT>/tests/diagnosticsCases/factorize/resolve-extensions-error'
╭─[1:1]
1 │ import './err';
2 │ import './test';
3 │ import a from './a';
· ─────
╰────
help: Found module './a.txt'. However, it's not possible to request this module without the extension
if its extension was not listed in the `resolve.extensions`. Here're some possible solutions:

1. add the extension `".txt"` to `resolve.extensions` in your rspack configuration
2. use './a.txt' instead of './a'
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@

.a {
color: red;
}
}

.b {
color; blue;
}

.c<>c {
color: green;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ module.exports = {
optimization: {
minimize: true,
minimizer: [
new rspack.LightningCssMinimizerRspackPlugin({
errorRecovery: true,
}),
new rspack.LightningCssMinimizerRspackPlugin(),
]
},
experiments: {
Expand Down
Loading

2 comments on commit 12d6df7

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ❌ failure
rsbuild ✅ success
compat ❌ failure
examples ❌ failure

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-07-01 273cdb9) Current Change
10000_development-mode + exec 2.27 s ± 21 ms 2.25 s ± 26 ms -0.84 %
10000_development-mode_hmr + exec 742 ms ± 6.1 ms 730 ms ± 15 ms -1.61 %
10000_production-mode + exec 3 s ± 33 ms 2.97 s ± 30 ms -0.94 %
arco-pro_development-mode + exec 1.96 s ± 63 ms 1.96 s ± 65 ms -0.42 %
arco-pro_development-mode_hmr + exec 442 ms ± 2.3 ms 440 ms ± 1.6 ms -0.49 %
arco-pro_production-mode + exec 3.62 s ± 90 ms 3.58 s ± 55 ms -1.03 %
threejs_development-mode_10x + exec 1.61 s ± 23 ms 1.61 s ± 14 ms -0.17 %
threejs_development-mode_10x_hmr + exec 817 ms ± 4.6 ms 818 ms ± 4.5 ms +0.12 %
threejs_production-mode_10x + exec 5.84 s ± 30 ms 5.8 s ± 22 ms -0.68 %

Please sign in to comment.