diff --git a/.vscode/settings.json b/.vscode/settings.json index 6b5e375a759f..01969be2d06e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -41,6 +41,6 @@ "threejs", "tokio", "ukey", - "Ukey" + "Ukey", ] -} +} \ No newline at end of file diff --git a/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs b/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs index 85a372d49e20..e8d35cae8b71 100644 --- a/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs +++ b/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs @@ -258,7 +258,7 @@ fn lzw_encode(input: &str) -> String { } let mut map: HashMap = HashMap::default(); let mut encoded = String::new(); - let mut phrase = input.chars().next().unwrap().to_string(); + let mut phrase = input.chars().next().expect("should have value").to_string(); let mut code = 256u16; let max_code = 0xFFFF; @@ -268,12 +268,15 @@ fn lzw_encode(input: &str) -> String { phrase = next_phrase; } else { if phrase.len() > 1 { - encoded.push(*map.get(&phrase).unwrap()); + encoded.push(*map.get(&phrase).expect("should convert to u32 correctly")); } else { encoded += &phrase; } if code <= max_code { - map.insert(next_phrase, std::char::from_u32(code as u32).unwrap()); + map.insert( + next_phrase, + std::char::from_u32(code as u32).expect("should convert to u32 correctly"), + ); code += 1; } if code > max_code { @@ -285,7 +288,7 @@ fn lzw_encode(input: &str) -> String { } if phrase.len() > 1 { - encoded.push(*map.get(&phrase).unwrap()); + encoded.push(*map.get(&phrase).expect("should have phrase")); } else { encoded += &phrase; } diff --git a/crates/rspack_plugin_css/src/runtime/mod.rs b/crates/rspack_plugin_css/src/runtime/mod.rs index 88770ab487d0..aa6b7b2dc384 100644 --- a/crates/rspack_plugin_css/src/runtime/mod.rs +++ b/crates/rspack_plugin_css/src/runtime/mod.rs @@ -133,7 +133,7 @@ for(i = 0; cc; i++) {{ {}installedChunks[chunkId] = 0; {} "#, - with_hmr.then(|| "moduleIds = [], ").unwrap_or_default(), + with_hmr.then_some("moduleIds = [], ").unwrap_or_default(), if with_compression { r#"var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = "\uffff".charCodeAt(0), phrase; for (i = 1; i < data.length; i++) { @@ -156,12 +156,15 @@ for(i = 0; cc; i++) {{ "handleCssComposes(exports, composes)\nmodule.exports = exports;" ), with_hmr - .then(|| "moduleIds.push(token); ") + .then_some("moduleIds.push(token); ") .unwrap_or_default(), with_hmr - .then(|| format!("if(target == {})", RuntimeGlobals::MODULE_FACTORIES)) + .then_some(format!( + "if(target == {})", + RuntimeGlobals::MODULE_FACTORIES + )) .unwrap_or_default(), - with_hmr.then(|| "return moduleIds;").unwrap_or_default() + with_hmr.then_some("return moduleIds;").unwrap_or_default() ), ); let load_initial_chunk_data = if initial_chunk_ids_with_css.len() > 2 { @@ -174,7 +177,7 @@ for(i = 0; cc; i++) {{ .join(","), RuntimeGlobals::MODULE_FACTORIES )) - } else if initial_chunk_ids_with_css.len() > 0 { + } else if !initial_chunk_ids_with_css.is_empty() { Cow::Owned( initial_chunk_ids_with_css .iter() diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index 2b31c0ae28c7..1643b2d4d452 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -12,8 +12,7 @@ import type { Compiler } from '@rspack/core'; import type { Compiler as Compiler_2 } from 'webpack'; import type { Configuration } from 'webpack'; import type EventEmitter from 'node:events'; -import { IBasicGlobalContext as IBasicGlobalContext_2 } from '../type'; -import { IBasicGlobalContext as IBasicGlobalContext_3 } from '../../type'; +import { IBasicGlobalContext as IBasicGlobalContext_2 } from '../../type'; import { IBasicModuleScope as IBasicModuleScope_2 } from '../../type'; import { ITestCompilerManager as ITestCompilerManager_2 } from '../type'; import type { RspackOptions } from '@rspack/core'; @@ -377,7 +376,7 @@ export class FakeDocumentWebRunner extends IMultiT // @public (undocumented) interface IWatchRunnerOptions extends IBasicRunnerOptions { + // (undocumented) + isWeb: boolean; // (undocumented) stepName: string; } @@ -1481,13 +1482,13 @@ export class WatchProcessor extends MultiTaskProcessor< } // @public (undocumented) -export class WatchRunner extends CommonJsRunner { +export class WatchRunner extends FakeDocumentWebRunner { constructor(_watchOptions: IWatchRunnerOptions); // (undocumented) - protected createGlobalContext(): IBasicGlobalContext_2; - // (undocumented) protected createModuleScope(requireFn: TRunnerRequirer, m: any, file: TBasicRunnerFile): IBasicModuleScope; // (undocumented) + run(file: string): Promise; + // (undocumented) protected _watchOptions: IWatchRunnerOptions; } diff --git a/packages/rspack-test-tools/src/case/config.ts b/packages/rspack-test-tools/src/case/config.ts index 145c97e80f3d..8298c9c126f7 100644 --- a/packages/rspack-test-tools/src/case/config.ts +++ b/packages/rspack-test-tools/src/case/config.ts @@ -11,12 +11,12 @@ export type TConfigCaseConfig = Omit< const creator = new BasicCaseCreator({ clean: true, describe: false, - testConfig: (testConfig) => { - let oldModuleScope = testConfig.moduleScope; + testConfig: testConfig => { + const oldModuleScope = testConfig.moduleScope; testConfig.moduleScope = (ms, stats) => { let res = ms; // TODO: modify runner module scope based on stats here - if (typeof oldModuleScope === 'function') { + if (typeof oldModuleScope === "function") { res = oldModuleScope(ms, stats); } return res; diff --git a/packages/rspack-test-tools/src/processor/watch.ts b/packages/rspack-test-tools/src/processor/watch.ts index 6b9dc14589cb..a081efd91830 100644 --- a/packages/rspack-test-tools/src/processor/watch.ts +++ b/packages/rspack-test-tools/src/processor/watch.ts @@ -9,6 +9,7 @@ import type { ITestEnv, TCompilerOptions } from "../type"; +import { ConfigProcessor } from "./config"; import { type IMultiTaskProcessorOptions, MultiTaskProcessor } from "./multi"; // This file is used to port step number to rspack.config.js/webpack.config.js @@ -37,7 +38,7 @@ export class WatchProcessor< constructor(protected _watchOptions: IWatchProcessorOptions) { super({ overrideOptions: WatchProcessor.overrideOptions(_watchOptions), - findBundle: () => "bundle.js", + findBundle: ConfigProcessor.findBundle, ..._watchOptions }); } diff --git a/packages/rspack-test-tools/src/runner/runner/cjs.ts b/packages/rspack-test-tools/src/runner/runner/cjs.ts index 423ca1aeb13a..a294ad0fc48d 100644 --- a/packages/rspack-test-tools/src/runner/runner/cjs.ts +++ b/packages/rspack-test-tools/src/runner/runner/cjs.ts @@ -117,7 +117,10 @@ export class CommonJsRunner< ); if (this._options.testConfig.moduleScope) { - this._options.testConfig.moduleScope(currentModuleScope, this._options.stats); + this._options.testConfig.moduleScope( + currentModuleScope, + this._options.stats + ); } if (!this._options.runInNewContext) { @@ -133,7 +136,6 @@ export class CommonJsRunner< const fn = this._options.runInNewContext ? vm.runInNewContext(code, this.globalContext!, file.path) : vm.runInThisContext(code, file.path); - fn.call( this._options.testConfig.nonEsmThis ? this._options.testConfig.nonEsmThis(modulePath) diff --git a/packages/rspack-test-tools/src/runner/runner/watch.ts b/packages/rspack-test-tools/src/runner/runner/watch.ts index f9c721a4dfc5..e1771299ce77 100644 --- a/packages/rspack-test-tools/src/runner/runner/watch.ts +++ b/packages/rspack-test-tools/src/runner/runner/watch.ts @@ -1,6 +1,5 @@ import path from "node:path"; -import FakeDocument from "../../helper/legacy/FakeDocument"; import type { ECompilerType } from "../../type"; import type { IBasicModuleScope, @@ -8,27 +7,20 @@ import type { TRunnerRequirer } from "../type"; import type { IBasicRunnerOptions } from "./basic"; -import { CommonJsRunner } from "./cjs"; +import { FakeDocumentWebRunner } from "./web/fake"; interface IWatchRunnerOptions extends IBasicRunnerOptions { stepName: string; + isWeb: boolean; } export class WatchRunner< T extends ECompilerType = ECompilerType.Rspack -> extends CommonJsRunner { - private document: any; +> extends FakeDocumentWebRunner { private state: Record = {}; constructor(protected _watchOptions: IWatchRunnerOptions) { super(_watchOptions); - this.document = new FakeDocument(_watchOptions.dist); - } - - protected createGlobalContext() { - const globalContext = super.createGlobalContext(); - globalContext.document = this.document; - return globalContext; } protected createModuleScope( @@ -43,4 +35,8 @@ export class WatchRunner< moduleScope.WATCH_STEP = this._watchOptions.stepName; return moduleScope; } + + run(file: string) { + return super.run(file); + } } diff --git a/packages/rspack-test-tools/src/runner/watch.ts b/packages/rspack-test-tools/src/runner/watch.ts index 44390911341a..82ea6e40b192 100644 --- a/packages/rspack-test-tools/src/runner/watch.ts +++ b/packages/rspack-test-tools/src/runner/watch.ts @@ -32,14 +32,21 @@ export class WatchRunnerFactory< if (!stepName) { throw new Error("Can not get watch step name from context"); } + + const isWeb = Array.isArray(compilerOptions) + ? compilerOptions.some(option => { + return option.target === "web" || option.target === "webworker"; + }) + : compilerOptions.target === "web" || + compilerOptions.target === "webworker"; + return new WatchRunner({ env, stats, name: this.name, stepName, - runInNewContext: - compilerOptions.target === "web" || - compilerOptions.target === "webworker", + runInNewContext: isWeb, + isWeb, testConfig: this.context.getTestConfig(), source: this.context.getSource(), dist: this.context.getDist(), diff --git a/packages/rspack-test-tools/src/test/creator.ts b/packages/rspack-test-tools/src/test/creator.ts index e9e61d708a8c..b87a4858ca50 100644 --- a/packages/rspack-test-tools/src/test/creator.ts +++ b/packages/rspack-test-tools/src/test/creator.ts @@ -27,7 +27,7 @@ export interface IBasicCaseCreatorOptions { temp: string | void; } ) => ITestProcessor[]; - testConfig?: (testConfig: TTestConfig) => void, + testConfig?: (testConfig: TTestConfig) => void; description?: (name: string, step: number) => string; runner?: new ( name: string, @@ -37,10 +37,10 @@ export interface IBasicCaseCreatorOptions { } export class BasicCaseCreator { - constructor(protected _options: IBasicCaseCreatorOptions) { } + constructor(protected _options: IBasicCaseCreatorOptions) {} create(name: string, src: string, dist: string, temp?: string) { - let testConfig = this.readTestConfig(src); + const testConfig = this.readTestConfig(src); if (typeof this._options.testConfig === "function") { this._options.testConfig(testConfig); } @@ -134,7 +134,7 @@ export class BasicCaseCreator { describe.skip(name, () => { it( typeof reason === "string" ? `filtered by ${reason}` : "filtered", - () => { } + () => {} ); }); } diff --git a/packages/rspack-test-tools/src/type.ts b/packages/rspack-test-tools/src/type.ts index 93993fb9db6d..fb81fd455f76 100644 --- a/packages/rspack-test-tools/src/type.ts +++ b/packages/rspack-test-tools/src/type.ts @@ -191,7 +191,10 @@ export type TTestConfig = { noTest?: boolean; beforeExecute?: () => void; afterExecute?: () => void; - moduleScope?: (ms: IBasicModuleScope, stats?: TCompilerStatsCompilation) => IBasicModuleScope; + moduleScope?: ( + ms: IBasicModuleScope, + stats?: TCompilerStatsCompilation + ) => IBasicModuleScope; findBundle?: ( index: number, options: TCompilerOptions diff --git a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap new file mode 100644 index 000000000000..c389d6412e5c --- /dev/null +++ b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap @@ -0,0 +1,480 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`config config/builtin-lightningcss-loader/basic-include exported tests should transform css correct 1`] = ` +"body { + & .-ca56f23580d7bbb484-used { + color: #00f; + } +} + +head{--webpack--909:used:-ca56f23580d7bĒ484-ĀĂ/&_368;}" +`; + +exports[`config config/builtins/css-auto exported tests css/auto can handle css module correctly 1`] = ` +Object { + "style": "-ca56f23580d7bbb484-style", +} +`; + +exports[`config config/builtins/css-modules-composes exported tests css modules composes 1`] = ` +Object { + "simple-bar": "-a7200a43b5c2530b1414-simple-bar -f27007fff641a72c371d-imported-simple", + "simple-foo": "-a7200a43b5c2530b1414-simple-foo -f27007fff641a72c371d-imported-simple", +} +`; + +exports[`config config/builtins/css-modules-composes-preprocessers exported tests css modules with css preprocessers 1`] = ` +Object { + "class": "-a7200a43b5c2530b1414-class -feb80f2fe6d30-lessClass", + "ghi": "-a7200a43b5c2530b1414-ghi", + "other": "-a7200a43b5c2530b1414-other -ebd90a48d100efd-scssClass", + "otherClassName": "-a7200a43b5c2530b1414-otherClassName globalClassName", +} +`; + +exports[`config config/builtins/css-modules-composes-sass exported tests css modules in scss 1`] = ` +Object { + "bar": "-f1f00e6e62b9a7fadb02-bar -a3b1929b59eeacf15a4-foo", +} +`; + +exports[`config config/builtins/css-modules-dedupe exported tests css modules dedupe 1`] = ` +Object { + "backButton": "-baa5c4d806a1671b-backButton -e683a459bd7b289e1b8d-secondaryButton -d8686a334ddc6bdd0-button", + "nextButton": "-baa5c4d806a1671b-nextButton -a510fa2734ece860e70-primaryButton -d8686a334ddc6bdd0-button", +} +`; + +exports[`config config/builtins/css-modules-exports-only exported tests css modules exportsOnly 1`] = ` +Object { + "simple-bar": "-a7200a43b5c2530b1414-simple-bar -f27007fff641a72c371d-imported-simple", + "simple-foo": "-a7200a43b5c2530b1414-simple-foo -f27007fff641a72c371d-imported-simple", +} +`; + +exports[`config config/builtins/css-modules-local-ident-name-hash exported tests css modules localIdentName with hash 1`] = ` +Object { + "#": "ccc05d01b5ed91e5a4d", + "##": "c16d3dd30b7cca2d412d", + "#.#.#": "c6e8935740a6209cd48e", + "#fake-id": "c053ba4f7badbc242", + "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.": "f5775dd999dc95dd350", + "-a-b-c-": "e171381fc62026ffe05b", + "-a0-34a___f": "e6419db424263d77191e", + ".": "b1061101d3ff1517822", + "123": "c6f16686ef1ceab9728", + "1a2b3c": "ea6ff32ba4e9ad9e4c71", + ":)": "c8ad14da9eacd8206f95", + ":\`(": "ab034bce3407ac44d", + ":hover": "d64a685363ea14300", + ":hover:focus:active": "f1ba6ba717fdcfbecc52", + "<><<<>><>": "a8471bf6e63738086bfa", + "

": "f4a8269a3b7c6f38759d", + "?": "d4a79a8d3ea0285a", + "@": "dba948edd127566bb", + "B&W?": "d26b7b08b3ee0fec8093", + "[attr=value]": "cf98e323da83a7ef1", + "_": "b21bb2384964fa8226c0", + "_test": "acd3c0528ed3c3330", + "className": "a20f38af3e2122251", + "f!o!o": "a4a2e3c31408bb709fb", + "f'o'o": "c1712d83c24d5b7bd9d", + "f*o*o": "f5ce693ef2ea116b05", + "f+o+o": "e3714c708c213b9e", + "f/o/o": "cd9b24dbefa12afeaba5", + "f\\\\o\\\\o": "f90fa90fb52121fce923", + "foo.bar": "a7554930d53d1d95676", + "foo/bar": "e21d87979464d92960b9", + "foo/bar/baz": "e26519aba0f8e105eb13", + "foo\\\\bar": "f93c23331183aeac60", + "foo\\\\bar\\\\baz": "aa79627c6f36d0c8f9", + "f~o~o": "f4c89337b4a84e05", + "m_x_@": "f106c601eea0160783bb", + "someId": "f7dad309581ff59a8c1", + "subClass": "f904cf1d95567c868707", + "test": "c8e76de9832d60b206c2", + "{}": "e73bdae84335b77", + "©": "d4c6ea8dbaf492a7e42e", + "“‘’”": "d3df6d853c11234b8", + "⌘⌥": "bbb74fa7684d2b07", + "☺☃": "d09672ed2a23417fa543", + "♥": "f5682d5025ab700972a0", + "𝄞♪♩♫♬": "b7e928b15b6057d2f8", + "💩": "bb34b4e107a01390e3fb", + "😍": "e5439193d7906536aeac", +} +`; + +exports[`config config/builtins/css-modules-local-ident-name-path exported tests css modules localIdentName with path 1`] = ` +Object { + "#": "./src/index__#", + "##": "./src/index__##", + "#.#.#": "./src/index__#.#.#", + "#fake-id": "./src/index__#fake-id", + "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.": "./src/index__++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.", + "-a-b-c-": "./src/index__-a-b-c-", + "-a0-34a___f": "./src/index__-a0-34a___f", + ".": "./src/index__.", + "123": "./src/index__123", + "1a2b3c": "./src/index__1a2b3c", + ":)": "./src/index__:)", + ":\`(": "./src/index__:\`(", + ":hover": "./src/index__:hover", + ":hover:focus:active": "./src/index__:hover:focus:active", + "<><<<>><>": "./src/index__<><<<>><>", + "

": "./src/index__

", + "?": "./src/index__?", + "@": "./src/index__@", + "B&W?": "./src/index__B&W?", + "[attr=value]": "./src/index__[attr=value]", + "_": "./src/index___", + "_test": "./src/index___test", + "className": "./src/index__className", + "f!o!o": "./src/index__f!o!o", + "f'o'o": "./src/index__f'o'o", + "f*o*o": "./src/index__f*o*o", + "f+o+o": "./src/index__f+o+o", + "f/o/o": "./src/index__f/o/o", + "f\\\\o\\\\o": "./src/index__f\\\\o\\\\o", + "foo.bar": "./src/index__foo.bar", + "foo/bar": "./src/index__foo/bar", + "foo/bar/baz": "./src/index__foo/bar/baz", + "foo\\\\bar": "./src/index__foo\\\\bar", + "foo\\\\bar\\\\baz": "./src/index__foo\\\\bar\\\\baz", + "f~o~o": "./src/index__f~o~o", + "m_x_@": "./src/index__m_x_@", + "someId": "./src/index__someId", + "subClass": "./src/index__subClass", + "test": "./src/index__test", + "{}": "./src/index__{}", + "©": "./src/index__©", + "“‘’”": "./src/index__“‘’”", + "⌘⌥": "./src/index__⌘⌥", + "☺☃": "./src/index__☺☃", + "♥": "./src/index__♥", + "𝄞♪♩♫♬": "./src/index__𝄞♪♩♫♬", + "💩": "./src/index__💩", + "😍": "./src/index__😍", +} +`; + +exports[`config config/builtins/css-modules-locals-convention-camelCase exported tests css modules localsConvention with camelCase 1`] = ` +Object { + "btn--info_is-disabled_1": "-a7200a43b5c2530b1414-btn--info_is-disabled_1", + "btn-info_is-disabled": "-a7200a43b5c2530b1414-btn-info_is-disabled", + "btnInfoIsDisabled": "-a7200a43b5c2530b1414-btn-info_is-disabled", + "btnInfoIsDisabled1": "-a7200a43b5c2530b1414-btn--info_is-disabled_1", + "fooBar": "-a7200a43b5c2530b1414-foo_bar", + "foo_bar": "-a7200a43b5c2530b1414-foo_bar", + "simple": "-a7200a43b5c2530b1414-simple", +} +`; + +exports[`config config/builtins/css-modules-locals-convention-camelCaseOnly exported tests css modules localsConvention with camelCaseOnly 1`] = ` +Object { + "btnInfoIsDisabled": "-a7200a43b5c2530b1414-btn-info_is-disabled", + "btnInfoIsDisabled1": "-a7200a43b5c2530b1414-btn--info_is-disabled_1", + "fooBar": "-a7200a43b5c2530b1414-foo_bar", + "simple": "-a7200a43b5c2530b1414-simple", +} +`; + +exports[`config config/builtins/css-modules-locals-convention-dashes exported tests css modules localsConvention with dashes 1`] = ` +Object { + "btn--info_is-disabled_1": "-a7200a43b5c2530b1414-btn--info_is-disabled_1", + "btn-info-is-disabled": "-a7200a43b5c2530b1414-btn-info_is-disabled", + "btn-info-is-disabled-1": "-a7200a43b5c2530b1414-btn--info_is-disabled_1", + "btn-info_is-disabled": "-a7200a43b5c2530b1414-btn-info_is-disabled", + "foo-bar": "-a7200a43b5c2530b1414-foo_bar", + "foo_bar": "-a7200a43b5c2530b1414-foo_bar", + "simple": "-a7200a43b5c2530b1414-simple", +} +`; + +exports[`config config/builtins/css-modules-pseudo exported tests css modules pseudo syntax 1`] = ` +Object { + "bar": "-a7200a43b5c2530b1414-bar", + "bav": "-a7200a43b5c2530b1414-bav", + "foo": "-a7200a43b5c2530b1414-foo", + "four": "-a7200a43b5c2530b1414-four", + "one": "-a7200a43b5c2530b1414-one", + "three": "-a7200a43b5c2530b1414-three", + "two": "-a7200a43b5c2530b1414-two", +} +`; + +exports[`config config/builtins/css-modules-simple exported tests css modules simple test 1`] = ` +Object { + "style": "-ca56f23580d7bbb484-style", +} +`; + +exports[`config config/chunk-index/available-modules-order-index exported tests should compile 1`] = ` +".m { + color: red; +} +.n { + color: blue; +} +head{--webpack--shared:&_547,Ā587;}" +`; + +exports[`config config/css/at-import-in-the-top exported tests at-import-in-the-top 1`] = ` +"@import url(\\"https://fonts.googleapis.com/css2?family=Roboto\\"); +@import url(\\"https://fonts.googleapis.com/css2?family=Inter\\"); +.c { + color: pink; +} + + + + +.a { + color: blue; +} + + + +.b { + color: red; +} + +head{--webpack--909:&_412,Ā645ą_34;}" +`; + +exports[`config config/css/export-selector exported tests should have correct css result 1`] = ` +"/* #region \\"./style.module.css?imported\\" */ +/* +- type: css/auto +*/ + + +.local {} + + + + +/* #endregion \\"./style.module.css?imported\\" */ + +head{--webpack--imported_js:foo:foo/bar:b a r/local:local/dashName:dashName/&\\\\.\\\\/style\\\\.module\\\\.css\\\\?imported;}" +`; + +exports[`config config/css/rewrite-url exported tests should rewrite the css url() 1`] = `"5d8d67b36a3d70a5cea9.png"`; + +exports[`config config/css/rewrite-url exported tests should rewrite the css url() 2`] = `"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAOCAYAAAAbvf3sAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAEWSURBVHgBjZFRSsNAEIb/3fQAOUK9gfpe6YIovjU3UE+gJ2g8gTcw3sC+itUFrW+BeAN7ATFSKAjbHWcSC+mSlszLDrvfzvzzj0LHmNpZBtBQd4Gf7fuYgHPPueoCe1DK1UsHd7Dzw+P0daQj/SC5h09OzdGktw221vZXUBlVMN0ILPd6O9yzBBXX8CBdv6kWOGa4YLivQJNjM0ia73oTLsBwJjCB5gu4i7CgbsIey5ThEcOfKziTGFOGHypJeZ7jZ/Gbst4x2/fN9h2eGTNvgk92VrDEWLNmfJXLpIYrRy5b4Fs+9v2/pL0oUncI7FuHLI6PK5lJZGoe8qXNvrry27DesoRLpLPmNkTw9yEcxPWJMR+S/AFbfpAZqxwUNQAAAABJRU5ErkJggg=="`; + +exports[`config config/css/rewrite-url-css-variables exported tests should rewrite the css url() in css variables 1`] = `"5d8d67b36a3d70a5cea9.png"`; + +exports[`config config/css/rewrite-url-css-variables exported tests should rewrite the css url() in css variables 2`] = `"5d8d67b36a3d70a5cea9.png"`; + +exports[`config config/css/rewrite-url-with-css-filename exported tests should rewrite the css url() with publicPath and ~@ prefix 1`] = `"/image/logo.5d8d67b3.png"`; + +exports[`config config/css/rewrite-url-with-css-filename exported tests should rewrite the css url() with publicPath when output.cssFilename is set 1`] = `"/image/logo.5d8d67b3.png"`; + +exports[`config config/css/urls exported tests css urls should works 1`] = ` +"/* @supports (background-image: url(\\"unknown.png\\")) { + div { + a195: url(\\"img.png\\"); + } +} */ + +div { + a13: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz; +} + +div { + a14: url(\\"data:image/svg+xml;charset=utf-8,\\"); +} + +div { + a15: url(data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20viewBox%3D%270%200%2042%2026%27%20fill%3D%27%2523007aff%27%3E%3Crect%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%271%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3Crect%20y%3D%2711%27%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%2712%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3Crect%20y%3D%2722%27%20width%3D%274%27%20height%3D%274%27%2F%3E%3Crect%20x%3D%278%27%20y%3D%2723%27%20width%3D%2734%27%20height%3D%272%27%2F%3E%3C%2Fsvg%3E); +} + +div { + a16: url('data:image/svg+xml;charset=utf-8,#filter'); +} + +div { + a17: url(\\"data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%5C%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%5C%22%3E%3Cfilter%20id%3D%5C%22filter%5C%22%3E%3CfeGaussianBlur%20in%3D%5C%22SourceAlpha%5C%22%20stdDeviation%3D%5C%220%5C%22%20%2F%3E%3CfeOffset%20dx%3D%5C%221%5C%22%20dy%3D%5C%222%5C%22%20result%3D%5C%22offsetblur%5C%22%20%2F%3E%3CfeFlood%20flood-color%3D%5C%22rgba(255%2C255%2C255%2C1)%5C%22%20%2F%3E%3CfeComposite%20in2%3D%5C%22offsetblur%5C%22%20operator%3D%5C%22in%5C%22%20%2F%3E%3CfeMerge%3E%3CfeMergeNode%20%2F%3E%3CfeMergeNode%20in%3D%5C%22SourceGraphic%5C%22%20%2F%3E%3C%2FfeMerge%3E%3C%2Ffilter%3E%3C%2Fsvg%3E%23filter\\"); +} + +div { + a18: url(#highlight); +} + +div { + a19: url(#line-marker); +} + +div { + a148: url('data:image/svg+xml,%3Csvg xmlns=\\"http://www.w3.org/2000/svg\\"%3E%3Crect width=\\"100%25\\" height=\\"100%25\\" style=\\"stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px\\" /%3E%3C/svg%3E'); + a149: url('data:image/svg+xml,%3Csvg xmlns=\\"http://www.w3.org/2000/svg\\"%3E%3Crect width=\\"100%25\\" height=\\"100%25\\" style=\\"stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px\\" /%3E%3C/svg%3E'); + a150: url('data:image/svg+xml,%3Csvg xmlns=\\"http://www.w3.org/2000/svg\\"%3E%3Crect width=\\"100%25\\" height=\\"100%25\\" style=\\"stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px\\" /%3E%3C/svg%3E'); + a151: url('data:image/svg+xml;utf8,'); + a152: url('data:image/svg+xml;utf8,'); +} + +div { + a1: url(); + a114: url(09a1a1112c577c279435.png); +} + +div { + a143: url(data:image/svg+xml;charset=UTF-8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%0A%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20width%3D%22191px%22%20height%3D%22191px%22%20viewBox%3D%220%200%20191%20191%22%20enable-background%3D%22new%200%200%20191%20191%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M95.5%2C0C42.8%2C0%2C0%2C42.8%2C0%2C95.5S42.8%2C191%2C95.5%2C191S191%2C148.2%2C191%2C95.5S148.2%2C0%2C95.5%2C0z%20M95.5%2C187.6%0A%09c-50.848%2C0-92.1-41.25-92.1-92.1c0-50.848%2C41.252-92.1%2C92.1-92.1c50.85%2C0%2C92.1%2C41.252%2C92.1%2C92.1%0A%09C187.6%2C146.35%2C146.35%2C187.6%2C95.5%2C187.6z%22%2F%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M92.9%2C10v8.6H91v-6.5c-0.1%2C0.1-0.2%2C0.2-0.4%2C0.3c-0.2%2C0.1-0.3%2C0.2-0.4%2C0.2c-0.1%2C0-0.3%2C0.1-0.5%2C0.2%0A%09%09c-0.2%2C0.1-0.3%2C0.1-0.5%2C0.1v-1.6c0.5-0.1%2C0.9-0.3%2C1.4-0.5c0.5-0.2%2C0.8-0.5%2C1.2-0.7h1.1V10z%22%2F%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M97.1%2C17.1h3.602v1.5h-5.6V18c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.6%2C0.5-0.9c0.2-0.3%2C0.5-0.5%2C0.7-0.7%0A%09%09c0.2-0.2%2C0.5-0.4%2C0.7-0.6c0.199-0.2%2C0.5-0.3%2C0.6-0.5c0.102-0.2%2C0.301-0.3%2C0.5-0.5c0.2-0.2%2C0.2-0.3%2C0.301-0.5%0A%09%09c0.101-0.2%2C0.101-0.3%2C0.101-0.5c0-0.4-0.101-0.6-0.3-0.8c-0.2-0.2-0.4-0.3-0.801-0.3c-0.699%2C0-1.399%2C0.3-2.101%2C0.9v-1.6%0A%09%09c0.7-0.5%2C1.5-0.7%2C2.5-0.7c0.399%2C0%2C0.8%2C0.1%2C1.101%2C0.2c0.301%2C0.1%2C0.601%2C0.3%2C0.899%2C0.5c0.3%2C0.2%2C0.399%2C0.5%2C0.5%2C0.8%0A%09%09c0.101%2C0.3%2C0.2%2C0.6%2C0.2%2C1s-0.102%2C0.7-0.2%2C1c-0.099%2C0.3-0.3%2C0.6-0.5%2C0.8c-0.2%2C0.2-0.399%2C0.5-0.7%2C0.7c-0.3%2C0.2-0.5%2C0.4-0.8%2C0.6%0A%09%09c-0.2%2C0.1-0.399%2C0.3-0.5%2C0.4s-0.3%2C0.3-0.5%2C0.4s-0.2%2C0.3-0.3%2C0.4C97.1%2C17%2C97.1%2C17%2C97.1%2C17.1z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M15%2C95.4c0%2C0.7-0.1%2C1.4-0.2%2C2c-0.1%2C0.6-0.4%2C1.1-0.7%2C1.5C13.8%2C99.3%2C13.4%2C99.6%2C12.9%2C99.8s-1%2C0.3-1.5%2C0.3%0A%09%09c-0.7%2C0-1.3-0.1-1.8-0.3v-1.5c0.4%2C0.3%2C1%2C0.4%2C1.6%2C0.4c0.6%2C0%2C1.1-0.2%2C1.5-0.7c0.4-0.5%2C0.5-1.1%2C0.5-1.9l0%2C0%0A%09%09C12.8%2C96.7%2C12.3%2C96.9%2C11.5%2C96.9c-0.3%2C0-0.7-0.102-1-0.2c-0.3-0.101-0.5-0.3-0.8-0.5c-0.3-0.2-0.4-0.5-0.5-0.8%0A%09%09c-0.1-0.3-0.2-0.7-0.2-1c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.7%2C0.6-0.9c0.3-0.2%2C0.6-0.5%2C0.9-0.6c0.3-0.1%2C0.8-0.2%2C1.2-0.2%0A%09%09c0.5%2C0%2C0.9%2C0.1%2C1.2%2C0.3c0.3%2C0.2%2C0.7%2C0.4%2C0.9%2C0.8s0.5%2C0.7%2C0.6%2C1.2S15%2C94.8%2C15%2C95.4z%20M13.1%2C94.4c0-0.2%2C0-0.4-0.1-0.6%0A%09%09c-0.1-0.2-0.1-0.4-0.2-0.5c-0.1-0.1-0.2-0.2-0.4-0.3c-0.2-0.1-0.3-0.1-0.5-0.1c-0.2%2C0-0.3%2C0-0.4%2C0.1s-0.3%2C0.2-0.3%2C0.3%0A%09%09c0%2C0.1-0.2%2C0.3-0.2%2C0.4c0%2C0.1-0.1%2C0.4-0.1%2C0.6c0%2C0.2%2C0%2C0.4%2C0.1%2C0.6c0.1%2C0.2%2C0.1%2C0.3%2C0.2%2C0.4c0.1%2C0.1%2C0.2%2C0.2%2C0.4%2C0.3%0A%09%09c0.2%2C0.1%2C0.3%2C0.1%2C0.5%2C0.1c0.2%2C0%2C0.3%2C0%2C0.4-0.1s0.2-0.2%2C0.3-0.3c0.1-0.1%2C0.2-0.2%2C0.2-0.4C13%2C94.7%2C13.1%2C94.6%2C13.1%2C94.4z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M176%2C99.7V98.1c0.6%2C0.4%2C1.2%2C0.602%2C2%2C0.602c0.5%2C0%2C0.8-0.102%2C1.1-0.301c0.301-0.199%2C0.4-0.5%2C0.4-0.801%0A%09%09c0-0.398-0.2-0.699-0.5-0.898c-0.3-0.2-0.8-0.301-1.3-0.301h-0.802V95h0.701c1.101%2C0%2C1.601-0.4%2C1.601-1.1c0-0.7-0.4-1-1.302-1%0A%09%09c-0.6%2C0-1.1%2C0.2-1.6%2C0.5v-1.5c0.6-0.3%2C1.301-0.4%2C2.1-0.4c0.9%2C0%2C1.5%2C0.2%2C2%2C0.6s0.701%2C0.9%2C0.701%2C1.5c0%2C1.1-0.601%2C1.8-1.701%2C2.1l0%2C0%0A%09%09c0.602%2C0.1%2C1.102%2C0.3%2C1.4%2C0.6s0.5%2C0.8%2C0.5%2C1.3c0%2C0.801-0.3%2C1.4-0.9%2C1.9c-0.6%2C0.5-1.398%2C0.7-2.398%2C0.7%0A%09%09C177.2%2C100.1%2C176.5%2C100%2C176%2C99.7z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M98.5%2C179.102c0%2C0.398-0.1%2C0.799-0.2%2C1.199C98.2%2C180.7%2C98%2C181%2C97.7%2C181.2s-0.601%2C0.5-0.9%2C0.601%0A%09%09c-0.3%2C0.1-0.7%2C0.199-1.2%2C0.199c-0.5%2C0-0.9-0.1-1.3-0.3c-0.4-0.2-0.7-0.399-0.9-0.8c-0.2-0.4-0.5-0.7-0.6-1.2%0A%09%09c-0.1-0.5-0.2-1-0.2-1.601c0-0.699%2C0.1-1.399%2C0.3-2c0.2-0.601%2C0.4-1.101%2C0.8-1.5c0.4-0.399%2C0.7-0.699%2C1.2-1c0.5-0.3%2C1-0.3%2C1.6-0.3%0A%09%09c0.6%2C0%2C1.2%2C0.101%2C1.5%2C0.199v1.5c-0.4-0.199-0.9-0.399-1.4-0.399c-0.3%2C0-0.6%2C0.101-0.8%2C0.2c-0.2%2C0.101-0.5%2C0.3-0.7%2C0.5%0A%09%09c-0.2%2C0.199-0.3%2C0.5-0.4%2C0.8c-0.1%2C0.301-0.2%2C0.7-0.2%2C1.101l0%2C0c0.4-0.601%2C1-0.8%2C1.8-0.8c0.3%2C0%2C0.7%2C0.1%2C0.9%2C0.199%0A%09%09c0.2%2C0.101%2C0.5%2C0.301%2C0.7%2C0.5c0.199%2C0.2%2C0.398%2C0.5%2C0.5%2C0.801C98.5%2C178.2%2C98.5%2C178.7%2C98.5%2C179.102z%20M96.7%2C179.2%0A%09%09c0-0.899-0.4-1.399-1.1-1.399c-0.2%2C0-0.3%2C0-0.5%2C0.1c-0.2%2C0.101-0.3%2C0.201-0.4%2C0.301c-0.1%2C0.101-0.2%2C0.199-0.2%2C0.4%0A%09%09c0%2C0.199-0.1%2C0.299-0.1%2C0.5c0%2C0.199%2C0%2C0.398%2C0.1%2C0.6s0.1%2C0.3%2C0.2%2C0.5c0.1%2C0.199%2C0.2%2C0.199%2C0.4%2C0.3c0.2%2C0.101%2C0.3%2C0.101%2C0.5%2C0.101%0A%09%09c0.2%2C0%2C0.3%2C0%2C0.5-0.101c0.2-0.101%2C0.301-0.199%2C0.301-0.3c0-0.1%2C0.199-0.301%2C0.199-0.399C96.6%2C179.7%2C96.7%2C179.4%2C96.7%2C179.2z%22%2F%3E%0A%3C%2Fg%3E%0A%3Ccircle%20fill%3D%22%23636363%22%20cx%3D%2295%22%20cy%3D%2295%22%20r%3D%227%22%2F%3E%0A%3C%2Fsvg%3E%0A) + 50% 50%/191px no-repeat; +} + +head{--webpack--120:&_13;}" +`; + +exports[`config config/library/modern-module-force-concaten step should pass 1`] = ` +" +;// CONCATENATED MODULE: ./a.js +const a = 'a' + +export { a }; +" +`; + +exports[`config config/library/modern-module-force-concaten step should pass 2`] = ` +"var __webpack_modules__ = ({ +\\"772\\": (function (module) { + +;// CONCATENATED MODULE: ./b.cjs +module.exports = 'b' + +}), + +}); +/************************************************************************/ +// The module cache +var __webpack_module_cache__ = {}; + +// The require function +function __webpack_require__(moduleId) { + +// Check if module is in cache +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +exports: {} +}); +// Execute the module function +__webpack_modules__[moduleId](module, module.exports, __webpack_require__); + +// Return the exports of the module +return module.exports; + +} + +/************************************************************************/ +// startup +// Load entry module and return exports +// This entry module is referenced by other modules so it can't be inlined +var __webpack_exports__ = __webpack_require__(\\"772\\"); +" +`; + +exports[`config config/library/modern-module-force-concaten step should pass 3`] = ` +" +;// CONCATENATED MODULE: ./c.js +const c = 'c' + +" +`; + +exports[`config config/library/modern-module-force-concaten step should pass 4`] = ` +" +;// CONCATENATED MODULE: ./d.mjs +const d = 'd' +export { d }; +" +`; + +exports[`config config/optimization/minimizer-esm-asset exported tests minimizing an asset file of esm type should success 1`] = `"console.log(import.meta.url);export const a=1;"`; + +exports[`config config/optimization/minimizer-swc-extract-comments exported tests should keep the extracted license file stable 1`] = ` +"/** + * bar + * @license MIT + */ + +/** + * baz + * @license MIT + */ + +/** + * foo + * @license MIT + */ + +/** + * relative + * @license MIT + */" +`; + +exports[`config config/plugins/chunk-modules exported tests chunk-modules 1`] = ` +Object { + "515": Object { + "entryModules": Array [], + "modules": Array [ + Object { + "context": "", + "identifier": "/async.js", + "resource": "/async.js", + }, + ], + }, + "909": Object { + "entryModules": Array [ + Object { + "context": "", + "identifier": "/index.js", + "resource": "/index.js", + }, + ], + "modules": Array [ + Object { + "context": "", + "identifier": "/index.js", + "resource": "/index.js", + }, + Object { + "identifier": "external node-commonjs \\"fs\\"", + }, + Object { + "identifier": "external node-commonjs \\"path\\"", + }, + ], + }, +} +`; + +exports[`config config/schemes/data-imports exported tests data imports 1`] = ` +".red{color: red;} +.b{color: green} +.a { color: palegreen; };;; + +.bad { + a: url(data:text/bad-base64;base64,abcd?#iefix); + b: url(\\"data:text/bad-base64;base64, abcd?#iefix\\"); +} + + /* .b{color: green} */ + + + +.class { + a: url(26a611d6d05cbb01e459.svg); + b: url(26a611d6d05cbb01e459.svg); + c: url(26a611d6d05cbb01e459); + d: url(26a611d6d05cbb01e459); +} + +head{--webpack--909:&_653,Ā47ĄĀ645ą_49Ď571;}" +`; diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/index.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/index.js index 911b88fa446f..862e3e3b50bd 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/index.js @@ -1,6 +1,11 @@ import * as styles from './index.module.css' it("should transform css correct", () => { + const fs = __non_webpack_require__('fs') + const path = __non_webpack_require__('path') + expect(styles).toHaveProperty('used'); expect('unused' in styles).toBeFalsy(); + + expect(fs.readFileSync(path.resolve(__dirname, './bundle0.css')).toString()).toMatchSnapshot() }); diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/rspack.config.js index f161e94c187b..c109717face7 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/basic-include/rspack.config.js @@ -1,5 +1,7 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { + target: 'web', + node: false, module: { parser: { 'css/auto': { @@ -9,6 +11,9 @@ module.exports = { rules: [ { test: /\.css$/, + generator: { + exportsOnly: false, + }, use: [ { loader: "builtin:lightningcss-loader", @@ -16,7 +21,7 @@ module.exports = { options: { unusedSymbols: ['unused'], targets: 'ie 10', - include: { + exclude: { nesting: true } } diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/index.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/index.js index ac370710ee9b..c543c0876dd5 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/index.js @@ -1,7 +1,7 @@ import './index.css' -const fs = require("node:fs"); -const path = require("node:path"); +const fs = __non_webpack_require__("node:fs"); +const path = __non_webpack_require__("node:path"); it("should transform CSS and add prefixes correctly", () => { const css = fs.readFileSync( diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/rspack.config.js index fb0b25a6f73a..d9de61946386 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-array/rspack.config.js @@ -1,5 +1,7 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { + target: 'web', + node: false, module: { generator: { "css/auto": { diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/index.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/index.js index 27dd41bb7eb0..1e9c974d7750 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/index.js @@ -1,7 +1,7 @@ import './index.css' -const fs = require("node:fs"); -const path = require("node:path"); +const fs = __non_webpack_require__("node:fs"); +const path = __non_webpack_require__("node:path"); it("should transform CSS and add prefixes correctly", () => { const css = fs.readFileSync( diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/rspack.config.js index 402e5a4f1337..95bcdbab3c84 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/prefixes-with-targets-string/rspack.config.js @@ -1,5 +1,7 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { + target: 'web', + node: false, module: { generator: { "css/auto": { diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/index.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/index.js index 27dd41bb7eb0..1e9c974d7750 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/index.js @@ -1,7 +1,7 @@ import './index.css' -const fs = require("node:fs"); -const path = require("node:path"); +const fs = __non_webpack_require__("node:fs"); +const path = __non_webpack_require__("node:path"); it("should transform CSS and add prefixes correctly", () => { const css = fs.readFileSync( diff --git a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/rspack.config.js index 4c19842decb5..22d3c0d7e423 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-lightningcss-loader/with-css-extract/rspack.config.js @@ -2,6 +2,8 @@ const rspack = require("@rspack/core"); /** @type {import("@rspack/core").Configuration} */ module.exports = { + target: 'web', + node: false, module: { rules: [ { diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/require-null/index.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/require-null/index.js index 29482b5183be..6ed2d01c3253 100644 --- a/packages/rspack-test-tools/tests/configCases/concatenate-modules/require-null/index.js +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/require-null/index.js @@ -1,5 +1,4 @@ import { a } from './lib'; -debugger; it("should run without `__webpack_require__(null)` error", () => { expect(a.value).toBe(42); }); diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-push.js b/packages/rspack-test-tools/tests/errorCases/error-test-push.js index 037337de0c80..77657d36b3c2 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-push.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "loc": "1:0-33", diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js index a991f4037897..2dc75ab462e1 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js @@ -24,7 +24,7 @@ module.exports = { Object { "message": " × Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], "warnings": Array [], diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js index 59eec7a025d6..6c82b9306a63 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], "warnings": Array [], diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js index 93a06c9c87bc..302fbbe02e63 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "loc": "1:0-33", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js index 4d6330591c0d..323d2e333a50 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js index 6c3a50882fa2..1b75531b0322 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js @@ -25,7 +25,7 @@ module.exports = { Object { "message": " ⚠ Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js index c5caee97b97e..e2e6f5d14c6b 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js index 81411f16cdc1..b614b5994ffd 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (packages/rspack-lite-tapable/src/index.ts:773:10)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/src/index.ts:790:3)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/src/index.ts:218:15)\\n at packages/rspack/src/Compiler.ts:613:29\\n at packages/rspack/src/Compiler.ts:660:15", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:530:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:550:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt index 05ecd1258a04..75e2a595f9d3 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 365 +- Update: main.LAST_HASH.hot-update.js, size: 209 ## Manifest @@ -23,7 +23,7 @@ ### main.LAST_HASH.hot-update.js #### Changed Modules -- ./index.css + #### Changed Runtime Modules - webpack/runtime/get_full_hash @@ -31,15 +31,7 @@ #### Changed Content ```js "use strict"; -self["webpackHotUpdatecss_test"]('main', { -"./index.css": (function (module, __unused_webpack_exports, __webpack_require__) { -module.hot.accept(); -__webpack_require__.r(module.exports = {}); - - -}), - -},function(__webpack_require__) { +self["webpackHotUpdatecss_test"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash (() => { __webpack_require__.h = function () { diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt index 3dfc7d76aa5a..10cde0fe32d1 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 357 +- Update: main.LAST_HASH.hot-update.js, size: 201 ## Manifest @@ -23,7 +23,7 @@ ### main.LAST_HASH.hot-update.js #### Changed Modules -- ./index.css + #### Changed Runtime Modules - webpack/runtime/get_full_hash @@ -31,15 +31,7 @@ #### Changed Content ```js "use strict"; -self["webpackHotUpdate"]('main', { -"./index.css": (function (module, __unused_webpack_exports, __webpack_require__) { -module.hot.accept(); -__webpack_require__.r(module.exports = {}); - - -}), - -},function(__webpack_require__) { +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash (() => { __webpack_require__.h = function () { diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt index 0a0e034a2974..759cbbec8f4a 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 481 +- Update: main.LAST_HASH.hot-update.js, size: 477 ## Manifest @@ -34,8 +34,8 @@ self["webpackHotUpdate"]('main', { "./index.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { __webpack_require__.r(module.exports = { - "btn-info_is-disabled": "./index.module.css__btn-info_is-disabled", - "btnInfoIsDisabled": "./index.module.css__btn-info_is-disabled", + "btn-info_is-enabled": "./index.module.css__btn-info_is-enabled", + "btnInfoIsEnabled": "./index.module.css__btn-info_is-enabled", }); diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js index 69dd6e9cdfe1..c9b9f020775e 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js @@ -3,7 +3,7 @@ import style from './index.module.css'; it("should store and resume css parser and generator states", (done) => { expect(style['btnInfoIsDisabled']).toBe('./index.module.css__btn-info_is-disabled'); module.hot.accept("./index.module.css", () => { - expect(style['btnInfoIsDisabled']).toBe('./index.module.css__btn-info_is-disabled'); + expect(style['btnInfoIsEnabled']).toBe('./index.module.css__btn-info_is-enabled'); done(); }); NEXT(require("../../update")(done)); diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.module.css b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.module.css index 6892dac590ac..9e1b7492a7b3 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.module.css +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.module.css @@ -4,6 +4,6 @@ --- -.btn-info_is-disabled { +.btn-info_is-enabled { color: red; } \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/test.config.js b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/test.config.js new file mode 100644 index 000000000000..5424297748be --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/test.config.js @@ -0,0 +1,3 @@ +module.exports = { + documentType: 'fake' +} diff --git a/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/index.js b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/index.js index 78aa741a604e..a497b91ee755 100644 --- a/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/index.js +++ b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/0/src/index.js @@ -1,7 +1,7 @@ require("./foo.less"); -const fs = require("fs"); -const path = require("path"); +const fs = __non_webpack_require__("fs"); +const path = __non_webpack_require__("path"); it("should detect changes for loader fileDependency which out of context", function () { const less = fs.readFileSync(path.resolve(__dirname, "bundle.css"), "utf-8"); diff --git a/packages/rspack-test-tools/tests/watchCases/context/out-of-context/rspack.config.js b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/rspack.config.js index 26f9f792a6ff..d3155078c7d3 100644 --- a/packages/rspack-test-tools/tests/watchCases/context/out-of-context/rspack.config.js +++ b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/rspack.config.js @@ -1,6 +1,11 @@ /** @type {import('@rspack/core').Configuration} */ module.exports = { entry: "./src/index", + target: 'web', + node: false, + output: { + publicPath: '/' + }, module: { rules: [ { diff --git a/packages/rspack-test-tools/tests/watchCases/context/out-of-context/test.config.js b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/test.config.js new file mode 100644 index 000000000000..933fb49f3892 --- /dev/null +++ b/packages/rspack-test-tools/tests/watchCases/context/out-of-context/test.config.js @@ -0,0 +1,6 @@ +module.exports = { + documentType: 'fake', + findBundle() { + return ['bundle.css', 'bundle.js'] + } +} diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index ef118951d2cd..4dff7c661eb9 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -5293,11 +5293,7 @@ type LogTypeEnum = (typeof LogType)[keyof typeof LogType]; // @public (undocumented) type MapOptions = { columns?: boolean; module?: boolean }; -<<<<<<< HEAD // @public -======= -// @public (undocumented) ->>>>>>> e338fc5e7 (feat: add exclude to rspack-test-tools) type Matcher = string | RegExp | (string | RegExp)[]; // @public (undocumented) diff --git a/tests/webpack-test/ConfigTestCases.template.js b/tests/webpack-test/ConfigTestCases.template.js index 8e2110bbf33b..d069052d34dc 100644 --- a/tests/webpack-test/ConfigTestCases.template.js +++ b/tests/webpack-test/ConfigTestCases.template.js @@ -473,7 +473,6 @@ const describeCases = config => { runInNewContext = true; } if (testConfig.moduleScope) { - debugger testConfig.moduleScope(baseModuleScope); } const esmContext = vm.createContext(baseModuleScope, { diff --git a/tests/webpack-test/configCases/css/named-exports-parser-options/index.js b/tests/webpack-test/configCases/css/named-exports-parser-options/index.js index e3719f3038b7..ae9c150bb901 100644 --- a/tests/webpack-test/configCases/css/named-exports-parser-options/index.js +++ b/tests/webpack-test/configCases/css/named-exports-parser-options/index.js @@ -3,7 +3,6 @@ import style2 from "./style.module.css?default" import * as style3 from "./style.module.css?named" it("should able to import with different namedExports", () => { - debugger expect(style1).toEqual(nsObj({ class: '-_style_module_css-class' })); expect(style2).toEqual(nsObj({ class: '-_style_module_css_default-class' })); expect(style3).toEqual(nsObj({ class: '-_style_module_css_named-class' })); diff --git a/tests/webpack-test/configCases/worker/worklet/index.js b/tests/webpack-test/configCases/worker/worklet/index.js index 9ee895922a72..30b6cfaf7c95 100644 --- a/tests/webpack-test/configCases/worker/worklet/index.js +++ b/tests/webpack-test/configCases/worker/worklet/index.js @@ -3,7 +3,6 @@ it("should allow to create a paintWorklet worklet", async () => { let pseudoWorklet = await CSS.paintWorklet.addModule(new URL("./worklet.js", import.meta.url)); -debugger pseudoWorklet = new pseudoWorklet(); expect(pseudoWorklet.url).not.toContain("asset-"); diff --git a/website/cspell.config.cjs b/website/cspell.config.cjs index 365c80927b8a..94f06ce574a5 100644 --- a/website/cspell.config.cjs +++ b/website/cspell.config.cjs @@ -25,4 +25,5 @@ module.exports = { caseSensitive: true, allowCompoundWords: true, enableFiletypes: ['mdx'], + words: ['srcăindexāmoduleācss'], }; diff --git a/website/docs/en/config/output.mdx b/website/docs/en/config/output.mdx index 8ad45dfccf53..e8cb2ee9cb9d 100644 --- a/website/docs/en/config/output.mdx +++ b/website/docs/en/config/output.mdx @@ -1770,16 +1770,14 @@ module.exports = { Option to set the method of loading WebAssembly Modules in workers, defaults to the value of [output.wasmLoading](#outputwasmloading). -````js title="rspack.config.js" +```js title="rspack.config.js" module.exports = { //... output: { workerWasmLoading: 'fetch', }, }; -```import { de } from 'date-fns/locale'; - -```` +``` ## output.auxiliaryComment @@ -1804,3 +1802,36 @@ Please use [`output.library.type`](#outputlibrarytype) instead as we might drop :::warning Prefer to use [`output.library.umdNamedDefine`](#outputlibraryumdnameddefine) instead. ::: + +## output.cssHeadDataCompression + + + +- **Type:** `boolean` +- **Default:** `false` for development mode, `true` for production mode + +Rspack adds some metadata in CSS to parse CSS modules, and this configuration determines whether to compress these metadata. + +For example + +```css +.local-a { + color: blue; +} + +head { + --webpack-main: a: local-a/&\.\/ src\/index\.module\.css; +} +``` + +After compress 👇 + +```css +.local-a { + color: blue; +} + +head { + --webpack-main: &\.\/ srcăindexāmoduleācss; +} +``` diff --git a/website/docs/zh/config/output.mdx b/website/docs/zh/config/output.mdx index cbdc6814f700..44b837357f3d 100644 --- a/website/docs/zh/config/output.mdx +++ b/website/docs/zh/config/output.mdx @@ -1794,3 +1794,36 @@ module.exports = { :::warning 最好使用 [`output.library.umdNamedDefine`](#outputlibraryumdnameddefine)。 ::: + +## output.cssHeadDataCompression + + + +- **类型:** `boolean` +- **默认值:** 在 development 模式下为 `false`,在 production 模式下为 `true` + +Rspack 会在 CSS 中添加一些元信息,用以解析 CSS modules,此配置决定是否压缩元信息。 + +例如 👇 + +```css +.local-a { + color: blue; +} + +head { + --webpack-main: a: local-a/&\.\/ src\/index\.module\.css; +} +``` + +压缩后 + +```css +.local-a { + color: blue; +} + +head { + --webpack-main: &\.\/ srcăindexāmoduleācss; +} +```