From 7f83deee5383c8acaac8eb4d6852fc0d39e2b109 Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Mon, 6 May 2024 10:57:39 +0800 Subject: [PATCH 001/107] docs: split plugins api (#6400) * docs: split plugins api * docs: split plugins api en * fix: dead link --- website/docs/en/api/_meta.json | 14 +- website/docs/en/api/index.mdx | 2 +- website/docs/en/api/plugin-api.mdx | 233 ----------------- website/docs/en/api/plugin-api/_meta.json | 7 + .../en/api/plugin-api/compilation-hooks.mdx | 43 ++++ .../docs/en/api/plugin-api/compiler-hooks.mdx | 143 +++++++++++ .../context-module-factory-hooks.mdx | 7 + website/docs/en/api/plugin-api/index.mdx | 5 + .../normal-module-factory-hooks.mdx | 19 ++ website/docs/en/blog/announcing-0-2.mdx | 20 +- website/docs/en/guide/features/plugin.mdx | 2 +- website/docs/zh/api/_meta.json | 14 +- website/docs/zh/api/index.mdx | 2 +- website/docs/zh/api/plugin-api.mdx | 235 ------------------ website/docs/zh/api/plugin-api/_meta.json | 7 + .../zh/api/plugin-api/compilation-hooks.mdx | 45 ++++ .../docs/zh/api/plugin-api/compiler-hooks.mdx | 143 +++++++++++ .../context-module-factory-hooks.mdx | 7 + website/docs/zh/api/plugin-api/index.mdx | 5 + .../normal-module-factory-hooks.mdx | 19 ++ website/docs/zh/blog/announcing-0-2.mdx | 20 +- website/docs/zh/guide/features/plugin.mdx | 2 +- website/theme/components/HomeFooter/index.tsx | 2 +- 23 files changed, 501 insertions(+), 495 deletions(-) delete mode 100644 website/docs/en/api/plugin-api.mdx create mode 100644 website/docs/en/api/plugin-api/_meta.json create mode 100644 website/docs/en/api/plugin-api/compilation-hooks.mdx create mode 100644 website/docs/en/api/plugin-api/compiler-hooks.mdx create mode 100644 website/docs/en/api/plugin-api/context-module-factory-hooks.mdx create mode 100644 website/docs/en/api/plugin-api/index.mdx create mode 100644 website/docs/en/api/plugin-api/normal-module-factory-hooks.mdx delete mode 100644 website/docs/zh/api/plugin-api.mdx create mode 100644 website/docs/zh/api/plugin-api/_meta.json create mode 100644 website/docs/zh/api/plugin-api/compilation-hooks.mdx create mode 100644 website/docs/zh/api/plugin-api/compiler-hooks.mdx create mode 100644 website/docs/zh/api/plugin-api/context-module-factory-hooks.mdx create mode 100644 website/docs/zh/api/plugin-api/index.mdx create mode 100644 website/docs/zh/api/plugin-api/normal-module-factory-hooks.mdx diff --git a/website/docs/en/api/_meta.json b/website/docs/en/api/_meta.json index 5c91094e9439..251ba45090ab 100644 --- a/website/docs/en/api/_meta.json +++ b/website/docs/en/api/_meta.json @@ -1 +1,13 @@ -["index", "cli", "modules", "node-api", "hmr", "loader-api", "plugin-api"] +[ + "index", + "cli", + "modules", + "node-api", + "hmr", + "loader-api", + { + "type": "dir", + "name": "plugin-api", + "label": "Plugin API" + } +] diff --git a/website/docs/en/api/index.mdx b/website/docs/en/api/index.mdx index 1d29ba8fc309..4394d4c28f11 100644 --- a/website/docs/en/api/index.mdx +++ b/website/docs/en/api/index.mdx @@ -36,4 +36,4 @@ Loaders are transformations that are applied to the source code of a module. The The plugin interface allows users to tap directly into the compilation process. Plugins can register handlers on lifecycle hooks that run at different points throughout a compilation. When each hook is executed, the plugin will have full access to the current state of the compilation. -[Learn more about the plugins!](/api/plugin-api) +[Learn more about the plugins!](/api/plugin-api/index) diff --git a/website/docs/en/api/plugin-api.mdx b/website/docs/en/api/plugin-api.mdx deleted file mode 100644 index 658a8ff7facb..000000000000 --- a/website/docs/en/api/plugin-api.mdx +++ /dev/null @@ -1,233 +0,0 @@ -import { ApiMeta, Stability } from '@components/ApiMeta'; -import WebpackLicense from '@components/webpack-license'; - - - -# Plugin API - - - -::: info Webpack Plugin API conformance -Check out [this](https://github.com/orgs/web-infra-dev/projects/9) page to see the status of Webpack Plugin API conformance. -::: - -## Compiler Hooks - -### `environment` - -`SyncHook<[]>` - -Called while preparing the compiler environment, right after initializing the plugins in the configuration file. - -### `afterEnvironment` - -`SyncHook<[]>` - -Called right after the environment hook, when the compiler environment setup is complete. - -### `afterPlugins` - -`SyncHook<[Compiler]>` - -Called after setting up initial set of internal plugins. - -### `afterResolvers` - -`SyncHook<[Compiler]>` - -Triggered after resolver setup is complete. - -### `entryOption` - -`SyncBailHook<[string, EntryNormalized]>` - -Called after the entry configuration has been processed. - -### `initialize` - -`SyncHook<[]>` - -Called when a compiler object is initialized. - -### `beforeRun` - -`AsyncSeriesHook<[Compiler]>` - -Adds a hook right before running the compiler. - -### `run` - -`AsyncSeriesHook<[Compiler]>` - -Called at the beginning of a build execution. - -### `childCompiler` - -`SyncHook[Compiler, string, number]` - -> where the version of the function type is `>=0.4.1`. - -Executed after created a childCompiler. - -### `watchRun` - -`AsyncSeriesHook<[Compiler]>` - -Executes a plugin during watch mode after a new compilation is triggered but before the compilation is actually started. - -### `compile` - -`SyncHook<[]>` - -Called right after beforeCompile, before a new compilation is created. - -### `beforeCompile` - -`AsyncSeriesHook<[]>` - -Executes a plugin after compilation parameters are created. - -### `afterCompile` - -`AsyncSeriesHook<[Compilation]>` - -Called after finishing and sealing the compilation. - -### `thisCompilation` - -`SyncHook<[Compilation]>` - -Executed while initializing the compilation, right before emitting the compilation event. - -### `compilation` - -`SyncHook<[Compilation]>` - -Runs a plugin after a compilation has been created. - -### `make` - -`AsyncParallelHook<[Compilation]>` - -Executed before the make stage. - -### `shouldEmit` - -`SyncBailHook<[Compilation]>` - -> where the version of the function type is `>=0.4.1`. - -Return a boolean telling whether to emit. - -### `emit` - -`AsyncSeriesHook<[Compilation]>` - -Executed right before emitting assets to output directory. - -### `afterEmit` - -`AsyncSeriesHook<[Compilation]>` - -Called after emitting assets to output directory. - -### `done` - -`AsyncSeriesHook` - -Executed when the compilation has completed. - -### `afterDone` - -`AsyncSeriesHook` - -Executed after `done` hook. - -### `watchClose` - -`SyncHook<[]>` - -Called when a watching compilation has stopped. - -### `failed` - -`SyncHook<[Error]>` - -Called if the compilation fails. - -## Compilation Hooks - -### `buildModule` - -`SyncHook<[JsModule]>` - -Triggered before a module build has started, can be used to modify the module (Rspack currently only support reading the module, modifying is not supported yet). - -### `processAssets` - -`AsyncSeriesHook<[CompilationAssets]>` - -Process the assets before emit. - -### `optimizeModules` - -`SyncBailHook<[JsModule[]]>` - -Called at the beginning of the module optimization phase. A plugin can tap into this hook to perform optimizations on modules. - -### `optimizeChunkModule` - -`AsyncSeriesBailHook<[JsModule[]]>` - -Called after the tree optimization, at the beginning of the chunk modules optimization. A plugin can tap into this hook to perform optimizations of chunk modules. - -### `succeedModule` - -`SyncHook<[JsModule]>` - -Executed when a module has been built successfully. - -### `finishModules` - -`AsyncSeriesHook<[JsModule[]]>` - -Called when all modules have been built without errors. - -### `chunkAsset` - -`SyncHook<[JsChunk[], string /** filename*/ ]>` - -Triggered when an asset from a chunk was added to the compilation. - -## NormalModuleFactory - -### `beforeResolve` - -`AsyncSeriesBailHook<[ResolveData]>` - -Called when a new dependency request is encountered. A dependency can be ignored by returning `false`. Otherwise, it should return `undefined` to proceed. - -### `afterResolve` - -`AsyncSeriesBailHook<[ResolveData]>` - -Called after the request is resolved. - -### `ResolveForScheme` - -`AsyncSeriesBailHook<[ResourceDataWithData]>` - -Called before a request with scheme (URI) is resolved. - -## ContextModuleFactory - -### `afterResolve` - -`AsyncSeriesBailHook<[ResolveData]>` - -Called after the requested directory resolved. diff --git a/website/docs/en/api/plugin-api/_meta.json b/website/docs/en/api/plugin-api/_meta.json new file mode 100644 index 000000000000..61c98e4028d9 --- /dev/null +++ b/website/docs/en/api/plugin-api/_meta.json @@ -0,0 +1,7 @@ +[ + "index", + "compiler-hooks", + "compilation-hooks", + "normal-module-factory-hooks", + "context-module-factory-hooks" +] diff --git a/website/docs/en/api/plugin-api/compilation-hooks.mdx b/website/docs/en/api/plugin-api/compilation-hooks.mdx new file mode 100644 index 000000000000..28bf67173fea --- /dev/null +++ b/website/docs/en/api/plugin-api/compilation-hooks.mdx @@ -0,0 +1,43 @@ +# Compilation Hooks + +## `buildModule` + +`SyncHook<[JsModule]>` + +Triggered before a module build has started, can be used to modify the module (Rspack currently only support reading the module, modifying is not supported yet). + +## `processAssets` + +`AsyncSeriesHook<[CompilationAssets]>` + +Process the assets before emit. + +## `optimizeModules` + +`SyncBailHook<[JsModule[]]>` + +Called at the beginning of the module optimization phase. A plugin can tap into this hook to perform optimizations on modules. + +## `optimizeChunkModule` + +`AsyncSeriesBailHook<[JsModule[]]>` + +Called after the tree optimization, at the beginning of the chunk modules optimization. A plugin can tap into this hook to perform optimizations of chunk modules. + +## `succeedModule` + +`SyncHook<[JsModule]>` + +Executed when a module has been built successfully. + +## `finishModules` + +`AsyncSeriesHook<[JsModule[]]>` + +Called when all modules have been built without errors. + +## `chunkAsset` + +`SyncHook<[JsChunk[], string /** filename*/ ]>` + +Triggered when an asset from a chunk was added to the compilation. diff --git a/website/docs/en/api/plugin-api/compiler-hooks.mdx b/website/docs/en/api/plugin-api/compiler-hooks.mdx new file mode 100644 index 000000000000..39d6a810371c --- /dev/null +++ b/website/docs/en/api/plugin-api/compiler-hooks.mdx @@ -0,0 +1,143 @@ +# Compiler Hooks + +## `environment` + +`SyncHook<[]>` + +Called while preparing the compiler environment, right after initializing the plugins in the configuration file. + +## `afterEnvironment` + +`SyncHook<[]>` + +Called right after the environment hook, when the compiler environment setup is complete. + +## `afterPlugins` + +`SyncHook<[Compiler]>` + +Called after setting up initial set of internal plugins. + +## `afterResolvers` + +`SyncHook<[Compiler]>` + +Triggered after resolver setup is complete. + +## `entryOption` + +`SyncBailHook<[string, EntryNormalized]>` + +Called after the entry configuration has been processed. + +## `initialize` + +`SyncHook<[]>` + +Called when a compiler object is initialized. + +## `beforeRun` + +`AsyncSeriesHook<[Compiler]>` + +Adds a hook right before running the compiler. + +## `run` + +`AsyncSeriesHook<[Compiler]>` + +Called at the beginning of a build execution. + +## `childCompiler` + +`SyncHook[Compiler, string, number]` + +> where the version of the function type is `>=0.4.1`. + +Executed after created a childCompiler. + +## `watchRun` + +`AsyncSeriesHook<[Compiler]>` + +Executes a plugin during watch mode after a new compilation is triggered but before the compilation is actually started. + +## `compile` + +`SyncHook<[]>` + +Called right after beforeCompile, before a new compilation is created. + +## `beforeCompile` + +`AsyncSeriesHook<[]>` + +Executes a plugin after compilation parameters are created. + +## `afterCompile` + +`AsyncSeriesHook<[Compilation]>` + +Called after finishing and sealing the compilation. + +## `thisCompilation` + +`SyncHook<[Compilation]>` + +Executed while initializing the compilation, right before emitting the compilation event. + +## `compilation` + +`SyncHook<[Compilation]>` + +Runs a plugin after a compilation has been created. + +## `make` + +`AsyncParallelHook<[Compilation]>` + +Executed before the make stage. + +## `shouldEmit` + +`SyncBailHook<[Compilation]>` + +> where the version of the function type is `>=0.4.1`. + +Return a boolean telling whether to emit. + +## `emit` + +`AsyncSeriesHook<[Compilation]>` + +Executed right before emitting assets to output directory. + +## `afterEmit` + +`AsyncSeriesHook<[Compilation]>` + +Called after emitting assets to output directory. + +## `done` + +`AsyncSeriesHook` + +Executed when the compilation has completed. + +## `afterDone` + +`AsyncSeriesHook` + +Executed after `done` hook. + +## `watchClose` + +`SyncHook<[]>` + +Called when a watching compilation has stopped. + +## `failed` + +`SyncHook<[Error]>` + +Called if the compilation fails. diff --git a/website/docs/en/api/plugin-api/context-module-factory-hooks.mdx b/website/docs/en/api/plugin-api/context-module-factory-hooks.mdx new file mode 100644 index 000000000000..dd52d6a7fc46 --- /dev/null +++ b/website/docs/en/api/plugin-api/context-module-factory-hooks.mdx @@ -0,0 +1,7 @@ +# ContextModuleFactory + +## `afterResolve` + +`AsyncSeriesBailHook<[ResolveData]>` + +Called after the requested directory resolved. diff --git a/website/docs/en/api/plugin-api/index.mdx b/website/docs/en/api/plugin-api/index.mdx new file mode 100644 index 000000000000..0c9552405ddd --- /dev/null +++ b/website/docs/en/api/plugin-api/index.mdx @@ -0,0 +1,5 @@ +# Compatibility Status + +Rspack is committed to being compatible with the plugins within the webpack ecosystem. We ensure that Rspack is as compatible as possible with the webpack plugin API, allowing more existing webpack plugins to be directly used in Rspack. + +You can visit [this page](https://github.com/orgs/web-infra-dev/projects/9) to learn about the current compatibility status of webpack plugin APIs. diff --git a/website/docs/en/api/plugin-api/normal-module-factory-hooks.mdx b/website/docs/en/api/plugin-api/normal-module-factory-hooks.mdx new file mode 100644 index 000000000000..e0535d118de6 --- /dev/null +++ b/website/docs/en/api/plugin-api/normal-module-factory-hooks.mdx @@ -0,0 +1,19 @@ +# NormalModuleFactory + +## `beforeResolve` + +`AsyncSeriesBailHook<[ResolveData]>` + +Called when a new dependency request is encountered. A dependency can be ignored by returning `false`. Otherwise, it should return `undefined` to proceed. + +## `afterResolve` + +`AsyncSeriesBailHook<[ResolveData]>` + +Called after the request is resolved. + +## `ResolveForScheme` + +`AsyncSeriesBailHook<[ResourceDataWithData]>` + +Called before a request with scheme (URI) is resolved. diff --git a/website/docs/en/blog/announcing-0-2.mdx b/website/docs/en/blog/announcing-0-2.mdx index 3cf812c4caf3..9bc88fe0f37d 100644 --- a/website/docs/en/blog/announcing-0-2.mdx +++ b/website/docs/en/blog/announcing-0-2.mdx @@ -24,25 +24,25 @@ New hooks for plugins have been added. Compiler hooks: -1. [beforeCompile](/api/plugin-api#beforecompile) -2. [afterCompile](/api/plugin-api#aftercompile) +1. [beforeCompile](/api/plugin-api/compiler-hooks#beforecompile) +2. [afterCompile](/api/plugin-api/compiler-hooks#aftercompile) Compilation hooks: -1. [optimizeModules](/api/plugin-api#optimizemodules) -2. [optimizeChunkModule](/api/plugin-api#optimizechunkmodules) -3. [finishModules](/api/plugin-api#finishmodules) -4. [chunkAsset](/api/plugin-api#chunkasset) +1. [optimizeModules](/api/plugin-api/compilation-hooks#optimizemodules) +2. [optimizeChunkModule](/api/plugin-api/compilation-hooks#optimizechunkmodules) +3. [finishModules](/api/plugin-api/compilation-hooks#finishmodules) +4. [chunkAsset](/api/plugin-api/compilation-hooks#chunkasset) NormalModuleFactory hooks: -1. [beforeResolve](/api/plugin-api#beforeresolve) -2. [afterResolve](/api/plugin-api#afterresolve) -3. [ResolveForScheme](/api/plugin-api#resolveforscheme) +1. [beforeResolve](/api/plugin-api/normal-module-factory-hooks#beforeresolve) +2. [afterResolve](/api/plugin-api/normal-module-factory-hooks#afterresolve) +3. [ResolveForScheme](/api/plugin-api/normal-module-factory-hooks#resolveforscheme) ContextModuleFactory hooks: -1. [beforeResolve](/api/plugin-api#beforeresolve) +1. [beforeResolve](/api/plugin-api/context-module-factory-hooks#beforeresolve) ### realContentHash diff --git a/website/docs/en/guide/features/plugin.mdx b/website/docs/en/guide/features/plugin.mdx index 131de7897977..4efa68822c55 100644 --- a/website/docs/en/guide/features/plugin.mdx +++ b/website/docs/en/guide/features/plugin.mdx @@ -6,7 +6,7 @@ If [loaders](/guide/features/loader) are the workhorse for file transformations ### Authoring plugins -The structure of a plugin is very simple: just implement an `apply` method that accepts a `Compiler` instance. It will be called when the Rspack plugin is initialized. The detailed API can be found in the [Plugin API](/api/plugin-api). +The structure of a plugin is very simple: just implement an `apply` method that accepts a `Compiler` instance. It will be called when the Rspack plugin is initialized. The detailed API can be found in the [Plugin API](/api/plugin-api/index). ```js const PLUGIN_NAME = 'MyPlugin'; diff --git a/website/docs/zh/api/_meta.json b/website/docs/zh/api/_meta.json index 5c91094e9439..020807b4e6f2 100644 --- a/website/docs/zh/api/_meta.json +++ b/website/docs/zh/api/_meta.json @@ -1 +1,13 @@ -["index", "cli", "modules", "node-api", "hmr", "loader-api", "plugin-api"] +[ + "index", + "cli", + "modules", + "node-api", + "hmr", + "loader-api", + { + "type": "dir", + "name": "plugin-api", + "label": "插件 API" + } +] diff --git a/website/docs/zh/api/index.mdx b/website/docs/zh/api/index.mdx index 46ca81b7e445..31a5f957ab35 100644 --- a/website/docs/zh/api/index.mdx +++ b/website/docs/zh/api/index.mdx @@ -36,4 +36,4 @@ Loader 用于模块源代码的转换。它们被编写为函数,接收源代 插件允许用户直接介入编译过程。插件可以在生命周期钩子上注册处理程序,这些钩子在编译过程的不同节点处运行。当钩子被执行时,插件将能完全访问当前编译的状态。 -[了解更多关于插件的信息!](/api/plugin-api) +[了解更多关于插件的信息!](/api/plugin-api/index) diff --git a/website/docs/zh/api/plugin-api.mdx b/website/docs/zh/api/plugin-api.mdx deleted file mode 100644 index 93d352906a79..000000000000 --- a/website/docs/zh/api/plugin-api.mdx +++ /dev/null @@ -1,235 +0,0 @@ -import { ApiMeta, Stability } from '@components/ApiMeta'; -import WebpackLicense from '@components/webpack-license'; - - - -# 插件 API - - - -::: info Webpack 插件 API 支持情况 -你可以查看 [这个](https://github.com/orgs/web-infra-dev/projects/9) 页面来了解目前 Webpack 插件 API 的支持情况。 -::: - -## Compiler 钩子 - -### `environment` - -`SyncHook<[]>` - -在编译器准备环境时,初始化插件之后调用。 - -### `afterEnvironment` - -`SyncHook<[]>` - -当编译器环境准备完成后,在 `environment` 钩子后直接调用。 - -### `afterPlugins` - -`SyncHook<[Compiler]>` - -在初始化内部插件完成之后调用。 - -### `afterResolvers` - -`SyncHook<[Compiler]>` - -resolver 设置完成之后触发。 - -### `entryOption` - -`SyncBailHook<[string, EntryNormalized]>` - -在处理完入口配置后调用。 - -### `initialize` - -`SyncHook<[]>` - -当编译器被初始化时调用。 - -### `beforeRun` - -`AsyncSeriesHook<[Compiler]>` - -在开始执行一次构建之前调用。 - -### `run` - -`AsyncSeriesHook<[Compiler]>` - -在开始执行一次构建时调用。 - -### `childCompiler` - -`SyncHook[Compiler, string, number]` - -> 最低版本要求为 `>=0.4.1`. - -当创建好一个 childCompiler 后执行。 - -### `watchRun` - -`AsyncSeriesHook<[Compiler]>` - -在监听模式下,开始执行一次构建时调用。 - -### `compile` - -`SyncHook<[]>` - -在一个新的 compilation 创建之前调用。 - -### `beforeCompile` - -`AsyncSeriesHook<[]>` - -在编译参数创建后执行插件。 - -### `afterCompile` - -`AsyncSeriesHook<[Compilation]>` - -在完成并封闭(seal)编译后调用。 - -### `thisCompilation` - -`SyncHook<[Compilation]>` - -创建 compilation 时调用,在触发 compilation 钩子之前调用。 - -### `compilation` - -`SyncHook<[Compilation]>` - -compilation 创建之后执行。 - -### `make` - -`AsyncParallelHook<[Compilation]>` - -make 阶段之前调用。 - -### `shouldEmit` - -`SyncBailHook<[Compilation]>` - -> 最低版本要求为 `>=0.4.1`. - -返回值为一个布尔值,用于决定是否将资源写入到磁盘中。 - -### `emit` - -`AsyncSeriesHook<[Compilation]>` - -输出产物之前执行。 - -### `afterEmit` - -`AsyncSeriesHook<[Compilation]>` - -输出产物之后执行。 - -### `done` - -`AsyncSeriesHook` - -在构建完成时执行。 - -### `afterDone` - -`AsyncSeriesHook` - -在构建完成后,`done` 钩子调用之后执行。 - -### `watchClose` - -`SyncHook<[]>` - -在监听模式下,compilation 停止时调用。 - -### `failed` - -`SyncHook<[Error]>` - -在构建失败时调用。 - -## Compilation 钩子 - -### `buildModule` - -`SyncHook<[JsModule]>` - -在模块被构建之前调用,可以用来修改模块(Rspack 目前仅支持读) - -### `processAssets` - -`AsyncSeriesHook<[CompilationAssets]>` - -在产物输出之前进行修改产物。 - -### `optimizeModules` - -`SyncBailHook<[JsModule[]]>` - -在模块优化阶段开始时调用。插件可以使用此钩子来对模块执行优化。 - -### `optimizeChunkModule` - -`AsyncSeriesBailHook<[JsModule[]]>` - -在 `afterOptimizeTree` 之后,在块模块优化的开始时调用。插件可以使用此钩子来对块模块执行优化。 - -### `succeedModule` - -`SyncHook<[JsModule]>` - -在模块成功构建后调用 - -### `finishModules` - -`AsyncSeriesHook<[JsModule[]]>` - -当所有模块都没有错误地构建完成时调用。 - -### `chunkAsset` - -`SyncHook<[JsChunk[], string /** filename*/ ]>` - -Triggered when an asset from a chunk was added to the compilation. - -当`chunk`的产物被添加到编译时触发。 - -## NormalModuleFactory - -### `beforeResolve` - -`AsyncSeriesBailHook<[ResolveData]>` - -当遇到新的依赖请求时调用。可以通过返回 `false` 来忽略依赖项。否则,应该返回 `undefined` 以继续。 - -### `afterResolve` - -`AsyncSeriesBailHook<[ResolveData]>` - -在请求被解析后调用。 - -### `ResolveForScheme` - -`AsyncSeriesBailHook<[ResourceDataWithData]>` - -在带有 scheme 的解析(URI)请求之前调用。 - -## ContextModuleFactory - -### `afterResolve` - -`AsyncSeriesBailHook<[ResolveData]>` - -在请求的目录解析后调用。 diff --git a/website/docs/zh/api/plugin-api/_meta.json b/website/docs/zh/api/plugin-api/_meta.json new file mode 100644 index 000000000000..61c98e4028d9 --- /dev/null +++ b/website/docs/zh/api/plugin-api/_meta.json @@ -0,0 +1,7 @@ +[ + "index", + "compiler-hooks", + "compilation-hooks", + "normal-module-factory-hooks", + "context-module-factory-hooks" +] diff --git a/website/docs/zh/api/plugin-api/compilation-hooks.mdx b/website/docs/zh/api/plugin-api/compilation-hooks.mdx new file mode 100644 index 000000000000..0b247d12c8c1 --- /dev/null +++ b/website/docs/zh/api/plugin-api/compilation-hooks.mdx @@ -0,0 +1,45 @@ +# Compilation 钩子 + +## `buildModule` + +`SyncHook<[JsModule]>` + +在模块被构建之前调用,可以用来修改模块(Rspack 目前仅支持读) + +## `processAssets` + +`AsyncSeriesHook<[CompilationAssets]>` + +在产物输出之前进行修改产物。 + +## `optimizeModules` + +`SyncBailHook<[JsModule[]]>` + +在模块优化阶段开始时调用。插件可以使用此钩子来对模块执行优化。 + +## `optimizeChunkModule` + +`AsyncSeriesBailHook<[JsModule[]]>` + +在 `afterOptimizeTree` 之后,在块模块优化的开始时调用。插件可以使用此钩子来对块模块执行优化。 + +## `succeedModule` + +`SyncHook<[JsModule]>` + +在模块成功构建后调用 + +## `finishModules` + +`AsyncSeriesHook<[JsModule[]]>` + +当所有模块都没有错误地构建完成时调用。 + +## `chunkAsset` + +`SyncHook<[JsChunk[], string /** filename*/ ]>` + +Triggered when an asset from a chunk was added to the compilation. + +当`chunk`的产物被添加到编译时触发。 diff --git a/website/docs/zh/api/plugin-api/compiler-hooks.mdx b/website/docs/zh/api/plugin-api/compiler-hooks.mdx new file mode 100644 index 000000000000..715830c1e31e --- /dev/null +++ b/website/docs/zh/api/plugin-api/compiler-hooks.mdx @@ -0,0 +1,143 @@ +# Compiler 钩子 + +## `environment` + +`SyncHook<[]>` + +在编译器准备环境时,初始化插件之后调用。 + +## `afterEnvironment` + +`SyncHook<[]>` + +当编译器环境准备完成后,在 `environment` 钩子后直接调用。 + +## `afterPlugins` + +`SyncHook<[Compiler]>` + +在初始化内部插件完成之后调用。 + +## `afterResolvers` + +`SyncHook<[Compiler]>` + +resolver 设置完成之后触发。 + +## `entryOption` + +`SyncBailHook<[string, EntryNormalized]>` + +在处理完入口配置后调用。 + +## `initialize` + +`SyncHook<[]>` + +当编译器被初始化时调用。 + +## `beforeRun` + +`AsyncSeriesHook<[Compiler]>` + +在开始执行一次构建之前调用。 + +## `run` + +`AsyncSeriesHook<[Compiler]>` + +在开始执行一次构建时调用。 + +## `childCompiler` + +`SyncHook[Compiler, string, number]` + +> 最低版本要求为 `>=0.4.1`. + +当创建好一个 childCompiler 后执行。 + +## `watchRun` + +`AsyncSeriesHook<[Compiler]>` + +在监听模式下,开始执行一次构建时调用。 + +## `compile` + +`SyncHook<[]>` + +在一个新的 compilation 创建之前调用。 + +## `beforeCompile` + +`AsyncSeriesHook<[]>` + +在编译参数创建后执行插件。 + +## `afterCompile` + +`AsyncSeriesHook<[Compilation]>` + +在完成并封闭(seal)编译后调用。 + +## `thisCompilation` + +`SyncHook<[Compilation]>` + +创建 compilation 时调用,在触发 compilation 钩子之前调用。 + +## `compilation` + +`SyncHook<[Compilation]>` + +compilation 创建之后执行。 + +## `make` + +`AsyncParallelHook<[Compilation]>` + +make 阶段之前调用。 + +## `shouldEmit` + +`SyncBailHook<[Compilation]>` + +> 最低版本要求为 `>=0.4.1`. + +返回值为一个布尔值,用于决定是否将资源写入到磁盘中。 + +## `emit` + +`AsyncSeriesHook<[Compilation]>` + +输出产物之前执行。 + +## `afterEmit` + +`AsyncSeriesHook<[Compilation]>` + +输出产物之后执行。 + +## `done` + +`AsyncSeriesHook` + +在构建完成时执行。 + +## `afterDone` + +`AsyncSeriesHook` + +在构建完成后,`done` 钩子调用之后执行。 + +## `watchClose` + +`SyncHook<[]>` + +在监听模式下,compilation 停止时调用。 + +## `failed` + +`SyncHook<[Error]>` + +在构建失败时调用。 diff --git a/website/docs/zh/api/plugin-api/context-module-factory-hooks.mdx b/website/docs/zh/api/plugin-api/context-module-factory-hooks.mdx new file mode 100644 index 000000000000..16481905b6b3 --- /dev/null +++ b/website/docs/zh/api/plugin-api/context-module-factory-hooks.mdx @@ -0,0 +1,7 @@ +# ContextModuleFactory 钩子 + +## `afterResolve` + +`AsyncSeriesBailHook<[ResolveData]>` + +在请求的目录解析后调用。 diff --git a/website/docs/zh/api/plugin-api/index.mdx b/website/docs/zh/api/plugin-api/index.mdx new file mode 100644 index 000000000000..6ee37ee7f86f --- /dev/null +++ b/website/docs/zh/api/plugin-api/index.mdx @@ -0,0 +1,5 @@ +# 兼容情况 + +Rspack 致力于兼容 webpack 生态中的插件。我们确保 Rspack 尽可能地去兼容 webpack 的插件 API,使更多现有的 webpack 插件能够在 Rspack 中直接使用。 + +你可以访问[这个页面](https://github.com/orgs/web-infra-dev/projects/9)来了解目前 webpack 插件 API 的兼容情况。 diff --git a/website/docs/zh/api/plugin-api/normal-module-factory-hooks.mdx b/website/docs/zh/api/plugin-api/normal-module-factory-hooks.mdx new file mode 100644 index 000000000000..7da655cf8c25 --- /dev/null +++ b/website/docs/zh/api/plugin-api/normal-module-factory-hooks.mdx @@ -0,0 +1,19 @@ +# NormalModuleFactory 钩子 + +## `beforeResolve` + +`AsyncSeriesBailHook<[ResolveData]>` + +当遇到新的依赖请求时调用。可以通过返回 `false` 来忽略依赖项。否则,应该返回 `undefined` 以继续。 + +## `afterResolve` + +`AsyncSeriesBailHook<[ResolveData]>` + +在请求被解析后调用。 + +## `ResolveForScheme` + +`AsyncSeriesBailHook<[ResourceDataWithData]>` + +在带有 scheme 的解析(URI)请求之前调用。 diff --git a/website/docs/zh/blog/announcing-0-2.mdx b/website/docs/zh/blog/announcing-0-2.mdx index 4afe093f801a..76833c22f4e7 100644 --- a/website/docs/zh/blog/announcing-0-2.mdx +++ b/website/docs/zh/blog/announcing-0-2.mdx @@ -22,25 +22,25 @@ date: 2023-06-02 13:11:00 Compiler hooks -1. [beforeCompile](/api/plugin-api#beforecompile) -2. [afterCompile](/api/plugin-api#aftercompile) +1. [beforeCompile](/api/plugin-api/compiler-hooks#beforecompile) +2. [afterCompile](/api/plugin-api/compiler-hooks#aftercompile) Compilation hooks -1. [optimizeModules](/api/plugin-api#optimizemodules) -2. [optimizeChunkModule](/api/plugin-api#optimizechunkmodules) -3. [finishModules](/api/plugin-api#finishmodules) -4. [chunkAsset](/api/plugin-api#chunkasset) +1. [optimizeModules](/api/plugin-api/compilation-hooks#optimizemodules) +2. [optimizeChunkModule](/api/plugin-api/compilation-hooks#optimizechunkmodules) +3. [finishModules](/api/plugin-api/compilation-hooks#finishmodules) +4. [chunkAsset](/api/plugin-api/compilation-hooks#chunkasset) NormalModuleFactory hooks -1. [beforeResolve](/api/plugin-api#beforeresolve) -2. [afterResolve](/api/plugin-api#afterresolve) -3. [ResolveForScheme](/api/plugin-api#resolveforscheme) +1. [beforeResolve](/api/plugin-api/normal-module-factory-hooks#beforeresolve) +2. [afterResolve](/api/plugin-api/normal-module-factory-hooks#afterresolve) +3. [ResolveForScheme](/api/plugin-api/normal-module-factory-hooks#resolveforscheme) ContextModuleFactory hooks -1. [beforeResolve](/api/plugin-api#beforeresolve) +1. [beforeResolve](/api/plugin-api/context-module-factory-hooks#beforeresolve) ### realContentHash diff --git a/website/docs/zh/guide/features/plugin.mdx b/website/docs/zh/guide/features/plugin.mdx index bc18f1cfe3ec..4cd970fe256d 100644 --- a/website/docs/zh/guide/features/plugin.mdx +++ b/website/docs/zh/guide/features/plugin.mdx @@ -7,7 +7,7 @@ ### 编写一个插件 -插件的结构非常简单,只需要实现一个 `apply` 方法,这个方法接受一个 `Compiler` 实例,并会在 Rspack 插件初始化时被调用。详细的 API 可以参考 [Plugin API](/api/plugin-api)。 +插件的结构非常简单,只需要实现一个 `apply` 方法,这个方法接受一个 `Compiler` 实例,并会在 Rspack 插件初始化时被调用。详细的 API 可以参考 [Plugin API](/api/plugin-api/index)。 ```js const PLUGIN_NAME = 'MyPlugin'; diff --git a/website/theme/components/HomeFooter/index.tsx b/website/theme/components/HomeFooter/index.tsx index ef946c432ca5..54a3df5e04f6 100644 --- a/website/theme/components/HomeFooter/index.tsx +++ b/website/theme/components/HomeFooter/index.tsx @@ -38,7 +38,7 @@ function useFooterData() { }, { title: 'Plugin API', - link: getLink('/api/plugin-api'), + link: getLink('/api/plugin-api/index'), }, { title: 'Loader API', From c79ac57399434219b3968fa6506c5beeefc77e34 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 11:48:31 +0800 Subject: [PATCH 002/107] chore(deps): update crates (#6424) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 8 ++++---- crates/rspack_hash/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08415992a13a..d6bd96522648 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -777,9 +777,9 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "debugid" @@ -4018,9 +4018,9 @@ checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" [[package]] name = "smol_str" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49" dependencies = [ "serde", ] diff --git a/crates/rspack_hash/Cargo.toml b/crates/rspack_hash/Cargo.toml index 44087b289d52..2dda0caa1d25 100644 --- a/crates/rspack_hash/Cargo.toml +++ b/crates/rspack_hash/Cargo.toml @@ -7,7 +7,7 @@ version = "0.1.0" [dependencies] -data-encoding = { version = "2.5.0" } +data-encoding = { version = "2.6.0" } md4 = "0.10.2" smol_str = { version = "*" } xxhash-rust = { workspace = true, features = ["xxh3"] } From 717e77db04ac869c0b2ffacfc81d9c67f53d24d1 Mon Sep 17 00:00:00 2001 From: Hana Date: Mon, 6 May 2024 13:24:57 +0800 Subject: [PATCH 003/107] fix: comment preserver should be placed prior to inline globals (#6423) * fix: comment preserver should be placed prior to inline globals * fix: snap * fix: f --- .../src/visitors/mod.rs | 2 +- .../preserve-all-comments-define/index.js | 14 ++++++++++++++ .../webpack.config.js | 19 +++++++++++++++++++ .../snapshot/new_treeshaking.snap.txt | 3 ++- .../snapshot/output.snap.txt | 3 ++- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/webpack.config.js diff --git a/crates/rspack_plugin_javascript/src/visitors/mod.rs b/crates/rspack_plugin_javascript/src/visitors/mod.rs index d46ac14ca691..3a0e1b1143b0 100644 --- a/crates/rspack_plugin_javascript/src/visitors/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/mod.rs @@ -62,11 +62,11 @@ pub fn run_before_pass(ast: &mut Ast, options: &CompilerOptions) -> Result<()> { let comments = program.comments.take(); { let mut pass = chain!( + dropped_comments_preserver(comments.clone()), swc_visitor::resolver(unresolved_mark, top_level_mark, false), builtins_webpack_plugin(options, unresolved_mark), swc_visitor::hygiene(false, top_level_mark), swc_visitor::fixer(Some(&comments as &dyn Comments)), - dropped_comments_preserver(comments.clone()), ); program.fold_with(&mut pass); } diff --git a/packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/index.js b/packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/index.js new file mode 100644 index 000000000000..e49a69d2c747 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/index.js @@ -0,0 +1,14 @@ +const fs = require("fs"); + +async function renderInBrowser() { + const jsx = () => {}; + const RootApp = {}; + if (process.env.__IS_REACT_18__) { + /* @__PURE__ */ jsx(RootApp, {}); + } else { + /* @__PURE__ */ jsx(RootApp, {}); + } +} +renderInBrowser(); + +it("should only contain a single pure annotation after being minimized", () => {}) diff --git a/packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/webpack.config.js b/packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/webpack.config.js new file mode 100644 index 000000000000..3f825bb97333 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/parsing/preserve-all-comments-define/webpack.config.js @@ -0,0 +1,19 @@ +const { DefinePlugin } = require("@rspack/core") + +module.exports = { + plugins: [ + new DefinePlugin({ + "process.env.__IS_REACT_18__": "true" + }), + { + apply(compiler) { + compiler.hooks.compilation.tap("Test", (compilation) => { + compilation.hooks.processAssets.tap("Test", (assets) => { + let source = assets["bundle0.js"].source(); + expect(source.match(/\/\* @__PURE__ \*\//g) || []).toHaveLength(1); + }) + }) + } + } + ] +} diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt index 9106960fa49b..02ab1e708e8f 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt @@ -30,7 +30,8 @@ exports.test = 30; { const res = __webpack_require__("./a.js"); module.exports = res; -}}), +} // export default function () {} +}), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { "use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt index d859f18d6bc5..f1622e0b6de7 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt @@ -30,7 +30,8 @@ exports.test = 30; { const res = __webpack_require__("./a.js"); module.exports = res; -}}), +} // export default function () {} +}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); From 0af97c623e8d25ce8d2ad905f6e98089be6b1061 Mon Sep 17 00:00:00 2001 From: Soon Date: Mon, 6 May 2024 13:31:31 +0800 Subject: [PATCH 004/107] fix(rspack_loader_runner): char_boundary panic when debug content (#6412) --- crates/rspack_loader_runner/src/content.rs | 5 ++++- crates/rspack_loader_runner/src/lib.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/rspack_loader_runner/src/content.rs b/crates/rspack_loader_runner/src/content.rs index 96078d10ed89..421c3aeb171d 100644 --- a/crates/rspack_loader_runner/src/content.rs +++ b/crates/rspack_loader_runner/src/content.rs @@ -87,7 +87,10 @@ impl Debug for Content { }; content - .field(ty, &s[0..usize::min(s.len(), 20)].to_owned()) + .field( + ty, + &s[0..usize::min(s.len(), s.ceil_char_boundary(20))].to_owned(), + ) .finish() } } diff --git a/crates/rspack_loader_runner/src/lib.rs b/crates/rspack_loader_runner/src/lib.rs index 1d8e3c6c40a2..a3a0987c4c76 100644 --- a/crates/rspack_loader_runner/src/lib.rs +++ b/crates/rspack_loader_runner/src/lib.rs @@ -1,4 +1,5 @@ #![feature(let_chains)] +#![feature(round_char_boundary)] mod content; mod loader; From f141e1a7e152fd0f15f36c7e67571bdd5e5c2746 Mon Sep 17 00:00:00 2001 From: jinrui Date: Mon, 6 May 2024 14:51:49 +0800 Subject: [PATCH 005/107] perf: optimize execute module (#6415) * feat: task_loop support listen task finish event * perf: optimize execute module * fix: clippy * fix: clean event before run finish module task * fix: self module FinishDeps bug * fix: hmr panic --- .../rspack_binding_values/src/compilation.rs | 13 - .../rspack_core/src/compiler/compilation.rs | 18 +- crates/rspack_core/src/compiler/hmr.rs | 10 +- crates/rspack_core/src/compiler/make/mod.rs | 37 ++- .../src/compiler/make/repair/factorize.rs | 2 +- .../src/compiler/make/repair/mod.rs | 64 +++- .../src/compiler/module_executor/ctrl.rs | 287 ++++++++++++++++++ .../src/compiler/module_executor/entry.rs | 71 +++++ .../execute.rs} | 139 ++++----- .../src/compiler/module_executor/mod.rs | 178 +++++++++++ .../src/compiler/module_executor/overwrite.rs | 92 ++++++ crates/rspack_core/src/utils/task_loop.rs | 34 ++- 12 files changed, 808 insertions(+), 137 deletions(-) create mode 100644 crates/rspack_core/src/compiler/module_executor/ctrl.rs create mode 100644 crates/rspack_core/src/compiler/module_executor/entry.rs rename crates/rspack_core/src/compiler/{module_executor.rs => module_executor/execute.rs} (69%) create mode 100644 crates/rspack_core/src/compiler/module_executor/mod.rs create mode 100644 crates/rspack_core/src/compiler/module_executor/overwrite.rs diff --git a/crates/rspack_binding_values/src/compilation.rs b/crates/rspack_binding_values/src/compilation.rs index 94b7503db835..f8ae66a72fbc 100644 --- a/crates/rspack_binding_values/src/compilation.rs +++ b/crates/rspack_binding_values/src/compilation.rs @@ -463,13 +463,6 @@ impl JsCompilation { original_module_context: Option, callback: JsFunction, ) -> Result<()> { - let options = self.0.options.clone(); - let plugin_driver = self.0.plugin_driver.clone(); - let resolver_factory = self.0.resolver_factory.clone(); - let loader_resolver_factory = self.0.loader_resolver_factory.clone(); - let cache = self.0.cache.clone(); - let dependency_factories = self.0.dependency_factories.clone(); - callbackify(env, callback, async { let module_executor = self .0 @@ -478,12 +471,6 @@ impl JsCompilation { .expect("should have module executor"); let result = module_executor .import_module( - options, - plugin_driver, - resolver_factory, - loader_resolver_factory, - cache, - dependency_factories, request, public_path, base_uri, diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 29366ac2605d..2cc3c6d47b5a 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -609,6 +609,13 @@ impl Compilation { #[instrument(name = "compilation:make", skip_all)] pub async fn make(&mut self, mut params: Vec) -> Result<()> { + // run module_executor + if let Some(module_executor) = &mut self.module_executor { + let mut module_executor = std::mem::take(module_executor); + module_executor.hook_before_make(self, ¶ms).await; + self.module_executor = Some(module_executor); + } + let make_failed_module = MakeParam::ForceBuildModules(std::mem::take(&mut self.make_failed_module)); let make_failed_dependencies = @@ -1042,13 +1049,10 @@ impl Compilation { logger.time_end(start); // sync assets to compilation from module_executor - let assets = self - .module_executor - .as_mut() - .map(|module_executor| std::mem::take(&mut module_executor.assets)) - .unwrap_or_default(); - for (filename, asset) in assets { - self.emit_asset(filename, asset) + if let Some(module_executor) = &mut self.module_executor { + let mut module_executor = std::mem::take(module_executor); + module_executor.hook_before_process_assets(self).await; + self.module_executor = Some(module_executor); } let start = logger.time("process assets"); diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index d6eca8176811..ad3868e00eca 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -9,7 +9,9 @@ use rspack_sources::Source; use rustc_hash::FxHashSet as HashSet; use super::MakeParam; -use crate::{fast_set, get_chunk_from_ukey, ChunkKind, Compilation, Compiler, RuntimeSpec}; +use crate::{ + fast_set, get_chunk_from_ukey, ChunkKind, Compilation, Compiler, ModuleExecutor, RuntimeSpec, +}; impl Compiler where @@ -73,8 +75,7 @@ where self.loader_resolver_factory.clone(), Some(records), self.cache.clone(), - // reuse module executor - std::mem::take(&mut self.compilation.module_executor), + Some(ModuleExecutor::default()), ); if let Some(state) = self.options.get_incremental_rebuild_make_state() { @@ -118,6 +119,9 @@ where new_compilation.code_splitting_cache = std::mem::take(&mut self.compilation.code_splitting_cache); + // reuse module executor + new_compilation.module_executor = std::mem::take(&mut self.compilation.module_executor); + new_compilation.has_module_import_export_change = false; } diff --git a/crates/rspack_core/src/compiler/make/mod.rs b/crates/rspack_core/src/compiler/make/mod.rs index fa0cc36356f7..e59a90ecad9b 100644 --- a/crates/rspack_core/src/compiler/make/mod.rs +++ b/crates/rspack_core/src/compiler/make/mod.rs @@ -1,5 +1,5 @@ mod cutout; -mod repair; +pub mod repair; use std::{hash::BuildHasherDefault, path::PathBuf}; @@ -19,16 +19,16 @@ use crate::{ #[derive(Debug, Default)] pub struct MakeArtifact { module_graph_partial: ModuleGraphPartial, - make_failed_dependencies: HashSet, - make_failed_module: HashSet, - diagnostics: Vec, + pub make_failed_dependencies: HashSet, + pub make_failed_module: HashSet, + pub diagnostics: Vec, entry_module_identifiers: IdentifierSet, optimize_analyze_result_map: IdentifierMap, - file_dependencies: IndexSet>, - context_dependencies: IndexSet>, - missing_dependencies: IndexSet>, - build_dependencies: IndexSet>, + pub file_dependencies: IndexSet>, + pub context_dependencies: IndexSet>, + pub missing_dependencies: IndexSet>, + pub build_dependencies: IndexSet>, has_module_graph_change: bool, } @@ -76,7 +76,7 @@ impl MakeArtifact { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum MakeParam { ModifiedFiles(HashSet), DeletedFiles(HashSet), @@ -99,10 +99,8 @@ pub async fn update_module_graph( let mut artifact = MakeArtifact::default(); compilation.swap_make_artifact(&mut artifact); artifact.move_data_from_compilation(compilation); - let mut cutout = Cutout::default(); - let build_dependencies = cutout.cutout_artifact(&mut artifact, params); - artifact = repair(compilation, artifact, build_dependencies)?; - cutout.fix_artifact(&mut artifact); + + artifact = update_module_graph_with_artifact(compilation, artifact, params).await?; // Avoid to introduce too much overhead, // until we find a better way to align with webpack hmr behavior @@ -149,3 +147,16 @@ pub async fn update_module_graph( compilation.swap_make_artifact(&mut artifact); Ok(()) } + +pub async fn update_module_graph_with_artifact( + compilation: &Compilation, + mut artifact: MakeArtifact, + params: Vec, +) -> Result { + let mut cutout = Cutout::default(); + let build_dependencies = cutout.cutout_artifact(&mut artifact, params); + artifact = repair(compilation, artifact, build_dependencies)?; + cutout.fix_artifact(&mut artifact); + + Ok(artifact) +} diff --git a/crates/rspack_core/src/compiler/make/repair/factorize.rs b/crates/rspack_core/src/compiler/make/repair/factorize.rs index fcbe67a67399..497fe759742d 100644 --- a/crates/rspack_core/src/compiler/make/repair/factorize.rs +++ b/crates/rspack_core/src/compiler/make/repair/factorize.rs @@ -147,7 +147,7 @@ pub struct ExportsInfoRelated { } #[derive(Debug)] -struct FactorizeResultTask { +pub struct FactorizeResultTask { // pub dependency: DependencyId, pub original_module_identifier: Option, /// Result will be available if [crate::ModuleFactory::create] returns `Ok`. diff --git a/crates/rspack_core/src/compiler/make/repair/mod.rs b/crates/rspack_core/src/compiler/make/repair/mod.rs index e34aa16038f5..369f60a38016 100644 --- a/crates/rspack_core/src/compiler/make/repair/mod.rs +++ b/crates/rspack_core/src/compiler/make/repair/mod.rs @@ -1,7 +1,7 @@ -mod add; -mod build; -mod factorize; -mod process_dependencies; +pub mod add; +pub mod build; +pub mod factorize; +pub mod process_dependencies; use std::{hash::BuildHasherDefault, path::PathBuf, sync::Arc}; @@ -21,14 +21,14 @@ use crate::{ NormalModuleSource, ResolverFactory, SharedPluginDriver, }; -struct MakeTaskContext { +pub struct MakeTaskContext { // compilation info - plugin_driver: SharedPluginDriver, - compiler_options: Arc, - resolver_factory: Arc, - loader_resolver_factory: Arc, - cache: Arc, - dependency_factories: HashMap>, + pub plugin_driver: SharedPluginDriver, + pub compiler_options: Arc, + pub resolver_factory: Arc, + pub loader_resolver_factory: Arc, + pub cache: Arc, + pub dependency_factories: HashMap>, // TODO move outof context logger: CompilationLogger, @@ -41,7 +41,7 @@ struct MakeTaskContext { /// Collecting all module that need to skip in tree-shaking ast modification phase // bailout_module_identifiers: IdentifierMap, // TODO change to artifact - module_graph_partial: ModuleGraphPartial, + pub module_graph_partial: ModuleGraphPartial, make_failed_dependencies: HashSet, make_failed_module: HashSet, @@ -56,7 +56,7 @@ struct MakeTaskContext { } impl MakeTaskContext { - fn new(compilation: &Compilation, artifact: MakeArtifact) -> Self { + pub fn new(compilation: &Compilation, artifact: MakeArtifact) -> Self { let logger = compilation.get_logger("rspack.Compilation"); let mut build_cache_counter = None; let mut factorize_cache_counter = None; @@ -97,7 +97,7 @@ impl MakeTaskContext { } } - fn transform_to_make_artifact(self) -> MakeArtifact { + pub fn transform_to_make_artifact(self) -> MakeArtifact { let Self { module_graph_partial, make_failed_dependencies, @@ -137,9 +137,43 @@ impl MakeTaskContext { } // TODO use module graph with make artifact - fn get_module_graph_mut(partial: &mut ModuleGraphPartial) -> ModuleGraph { + pub fn get_module_graph_mut(partial: &mut ModuleGraphPartial) -> ModuleGraph { ModuleGraph::new(vec![], Some(partial)) } + + // TODO remove it after incremental rebuild cover all stage + pub fn transform_to_temp_compilation(&mut self) -> Compilation { + let mut compilation = Compilation::new( + self.compiler_options.clone(), + self.plugin_driver.clone(), + self.resolver_factory.clone(), + self.loader_resolver_factory.clone(), + None, + self.cache.clone(), + None, + ); + compilation.dependency_factories = self.dependency_factories.clone(); + let mut make_artifact = MakeArtifact { + module_graph_partial: std::mem::take(&mut self.module_graph_partial), + file_dependencies: std::mem::take(&mut self.file_dependencies), + context_dependencies: std::mem::take(&mut self.context_dependencies), + missing_dependencies: std::mem::take(&mut self.missing_dependencies), + build_dependencies: std::mem::take(&mut self.build_dependencies), + ..Default::default() + }; + compilation.swap_make_artifact(&mut make_artifact); + compilation + } + + pub fn recovery_from_temp_compilation(&mut self, mut compilation: Compilation) { + let mut make_artifact = Default::default(); + compilation.swap_make_artifact(&mut make_artifact); + self.module_graph_partial = make_artifact.module_graph_partial; + self.file_dependencies = make_artifact.file_dependencies; + self.context_dependencies = make_artifact.context_dependencies; + self.missing_dependencies = make_artifact.missing_dependencies; + self.build_dependencies = make_artifact.build_dependencies; + } } pub fn repair( diff --git a/crates/rspack_core/src/compiler/module_executor/ctrl.rs b/crates/rspack_core/src/compiler/module_executor/ctrl.rs new file mode 100644 index 000000000000..550980dd14b0 --- /dev/null +++ b/crates/rspack_core/src/compiler/module_executor/ctrl.rs @@ -0,0 +1,287 @@ +use std::collections::VecDeque; + +use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; +use tokio::sync::mpsc::{error::TryRecvError, UnboundedReceiver}; + +use super::{ + entry::{EntryParam, EntryTask}, + execute::ExecuteTask, +}; +use crate::{ + compiler::make::repair::MakeTaskContext, + utils::task_loop::{Task, TaskResult, TaskType}, + Dependency, DependencyId, ModuleIdentifier, +}; + +#[derive(Debug)] +struct UnfinishCounter { + is_building: bool, + unfinished_child_module_count: usize, +} + +impl UnfinishCounter { + fn new() -> Self { + UnfinishCounter { + is_building: true, + unfinished_child_module_count: 0, + } + } + + fn set_unfinished_child_module_count(&mut self, count: usize) { + self.is_building = false; + self.unfinished_child_module_count = count; + } + + fn minus_one(&mut self) { + if self.is_building || self.unfinished_child_module_count == 0 { + panic!("UnfinishDepCount Error") + } + self.unfinished_child_module_count -= 1; + } + + fn is_finished(&self) -> bool { + !self.is_building && self.unfinished_child_module_count == 0 + } +} + +// send event can only use in sync task +pub enum Event { + StartBuild(ModuleIdentifier), + // origin_module_identifier and current dependency id and target_module_identifier + FinishDeps( + Option, + DependencyId, + Option, + ), + // current_module_identifier and sub dependency count + FinishModule(ModuleIdentifier, usize), + ExecuteModule(EntryParam, ExecuteTask), + Stop(), +} + +#[derive(Debug)] +pub struct CtrlTask { + pub event_receiver: UnboundedReceiver, + execute_task_map: HashMap, + running_module_map: HashMap, +} + +impl CtrlTask { + pub fn new(event_receiver: UnboundedReceiver) -> Self { + Self { + event_receiver, + execute_task_map: Default::default(), + running_module_map: Default::default(), + } + } +} + +#[async_trait::async_trait] +impl Task for CtrlTask { + fn get_task_type(&self) -> TaskType { + TaskType::Async + } + + async fn async_run(mut self: Box) -> TaskResult { + while let Some(event) = self.event_receiver.recv().await { + match event { + Event::StartBuild(module_identifier) => { + self + .running_module_map + .insert(module_identifier, UnfinishCounter::new()); + } + Event::FinishDeps(origin_module_identifier, dep_id, target_module_graph) => { + if let Some(target_module_graph) = target_module_graph { + if self.running_module_map.contains_key(&target_module_graph) + && Some(target_module_graph) != origin_module_identifier + { + continue; + } + } + + // target module finished + let Some(origin_module_identifier) = origin_module_identifier else { + // origin_module_identifier is none means entry dep + let execute_task = self + .execute_task_map + .remove(&dep_id) + .expect("should have execute task"); + return Ok(vec![Box::new(execute_task), self]); + }; + + let value = self + .running_module_map + .get_mut(&origin_module_identifier) + .expect("should have counter"); + value.minus_one(); + if value.is_finished() { + return Ok(vec![Box::new(FinishModuleTask { + ctrl_task: self, + module_identifier: origin_module_identifier, + })]); + } + } + Event::FinishModule(mid, size) => { + let value = self + .running_module_map + .get_mut(&mid) + .expect("should have counter"); + value.set_unfinished_child_module_count(size); + if value.is_finished() { + return Ok(vec![Box::new(FinishModuleTask { + ctrl_task: self, + module_identifier: mid, + })]); + } + } + Event::ExecuteModule(param, execute_task) => { + let dep_id = match ¶m { + EntryParam::DependencyId(id, _) => *id, + EntryParam::EntryDependency(dep) => *dep.id(), + }; + self.execute_task_map.insert(dep_id, execute_task); + return Ok(vec![Box::new(EntryTask { param }), self]); + } + Event::Stop() => { + return Ok(vec![]); + } + } + } + // if channel has been closed, finish this task + Ok(vec![]) + } +} + +#[derive(Debug)] +struct FinishModuleTask { + ctrl_task: Box, + module_identifier: ModuleIdentifier, +} + +impl Task for FinishModuleTask { + fn get_task_type(&self) -> TaskType { + TaskType::Sync + } + + fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + let Self { + mut ctrl_task, + module_identifier, + } = *self; + let mut res: Vec>> = vec![]; + let module_graph = MakeTaskContext::get_module_graph_mut(&mut context.module_graph_partial); + let mut queue = VecDeque::new(); + queue.push_back(module_identifier); + + // clean ctrl task events + loop { + let event = ctrl_task.event_receiver.try_recv(); + let Ok(event) = event else { + if matches!(event, Err(TryRecvError::Empty)) { + break; + } else { + panic!("clean ctrl_task event failed"); + } + }; + + match event { + Event::StartBuild(module_identifier) => { + ctrl_task + .running_module_map + .insert(module_identifier, UnfinishCounter::new()); + } + Event::FinishDeps(origin_module_identifier, dep_id, target_module_graph) => { + if let Some(target_module_graph) = target_module_graph { + if ctrl_task + .running_module_map + .contains_key(&target_module_graph) + && Some(target_module_graph) != origin_module_identifier + { + continue; + } + } + + // target module finished + let Some(origin_module_identifier) = origin_module_identifier else { + // origin_module_identifier is none means entry dep + let execute_task = ctrl_task + .execute_task_map + .remove(&dep_id) + .expect("should have execute task"); + res.push(Box::new(execute_task)); + continue; + }; + + let value = ctrl_task + .running_module_map + .get_mut(&origin_module_identifier) + .expect("should have counter"); + value.minus_one(); + if value.is_finished() { + queue.push_back(origin_module_identifier); + } + } + Event::FinishModule(mid, size) => { + let value = ctrl_task + .running_module_map + .get_mut(&mid) + .expect("should have counter"); + value.set_unfinished_child_module_count(size); + if value.is_finished() { + queue.push_back(mid); + } + } + Event::ExecuteModule(param, execute_task) => { + let dep_id = match ¶m { + EntryParam::DependencyId(id, _) => *id, + EntryParam::EntryDependency(dep) => *dep.id(), + }; + ctrl_task.execute_task_map.insert(dep_id, execute_task); + res.push(Box::new(EntryTask { param })); + } + Event::Stop() => { + return Ok(vec![]); + } + } + } + + while let Some(module_identifier) = queue.pop_front() { + ctrl_task.running_module_map.remove(&module_identifier); + + let mgm = module_graph + .module_graph_module_by_identifier(&module_identifier) + .expect("should have mgm"); + + let mut original_module_identifiers = HashSet::default(); + for connection_id in mgm.incoming_connections() { + let connection = module_graph + .connection_by_connection_id(connection_id) + .expect("should have connection"); + if let Some(original_module_identifier) = &connection.original_module_identifier { + original_module_identifiers.insert(*original_module_identifier); + } else { + // entry + let execute_task = ctrl_task + .execute_task_map + .remove(&connection.dependency_id) + .expect("should have execute task"); + res.push(Box::new(execute_task)); + } + } + + for id in original_module_identifiers { + let value = ctrl_task + .running_module_map + .get_mut(&id) + .expect("should have counter"); + value.minus_one(); + if value.is_finished() { + queue.push_back(id); + } + } + } + + res.push(ctrl_task); + Ok(res) + } +} diff --git a/crates/rspack_core/src/compiler/module_executor/entry.rs b/crates/rspack_core/src/compiler/module_executor/entry.rs new file mode 100644 index 000000000000..b3bc357d3581 --- /dev/null +++ b/crates/rspack_core/src/compiler/module_executor/entry.rs @@ -0,0 +1,71 @@ +use tokio::sync::mpsc::UnboundedSender; + +use super::ctrl::Event; +use crate::{ + compiler::make::repair::{factorize::FactorizeTask, MakeTaskContext}, + utils::task_loop::{Task, TaskResult, TaskType}, + Dependency, DependencyId, EntryDependency, ModuleProfile, +}; + +#[derive(Debug)] +pub enum EntryParam { + DependencyId(DependencyId, UnboundedSender), + EntryDependency(Box), +} + +#[derive(Debug)] +pub struct EntryTask { + pub param: EntryParam, +} + +impl Task for EntryTask { + fn get_task_type(&self) -> TaskType { + TaskType::Sync + } + + fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + let Self { param } = *self; + let mut module_graph = MakeTaskContext::get_module_graph_mut(&mut context.module_graph_partial); + + match param { + EntryParam::DependencyId(dep_id, sender) => { + if let Some(module_identifier) = module_graph.module_identifier_by_dependency_id(&dep_id) { + sender + .send(Event::FinishDeps(None, dep_id, Some(*module_identifier))) + .expect("should success"); + } else { + // no module_identifier means the factorize task not run, do nothing + } + Ok(vec![]) + } + EntryParam::EntryDependency(dep) => { + let dep_id = *dep.id(); + module_graph.add_dependency(dep.clone()); + Ok(vec![Box::new(FactorizeTask { + module_factory: context + .dependency_factories + .get(dep.dependency_type()) + .expect("should have dependency_factories") + .clone(), + original_module_identifier: None, + original_module_source: None, + issuer: None, + original_module_context: None, + dependency: dep, + dependencies: vec![dep_id], + is_entry: true, + resolve_options: None, + resolver_factory: context.resolver_factory.clone(), + loader_resolver_factory: context.loader_resolver_factory.clone(), + options: context.compiler_options.clone(), + plugin_driver: context.plugin_driver.clone(), + cache: context.cache.clone(), + current_profile: context + .compiler_options + .profile + .then(Box::::default), + })]) + } + } + } +} diff --git a/crates/rspack_core/src/compiler/module_executor.rs b/crates/rspack_core/src/compiler/module_executor/execute.rs similarity index 69% rename from crates/rspack_core/src/compiler/module_executor.rs rename to crates/rspack_core/src/compiler/module_executor/execute.rs index 0990a54e098e..7c46627f183d 100644 --- a/crates/rspack_core/src/compiler/module_executor.rs +++ b/crates/rspack_core/src/compiler/module_executor/execute.rs @@ -1,20 +1,19 @@ -use std::sync::{atomic::AtomicU32, Arc}; -use std::{hash::BuildHasherDefault, iter::once}; +use std::{iter::once, sync::atomic::AtomicU32}; -use dashmap::DashMap; use rayon::prelude::*; use rspack_error::Result; -use rspack_identifier::{Identifiable, IdentifierSet}; -use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet, FxHasher}; +use rspack_identifier::IdentifierSet; +use rustc_hash::FxHashSet as HashSet; +use tokio::{runtime::Handle, sync::oneshot::Sender}; -use crate::cache::Cache; +// use tokio::sync::Sender use crate::{ + compiler::make::repair::MakeTaskContext, + utils::task_loop::{Task, TaskResult, TaskType}, Chunk, ChunkGraph, ChunkKind, CodeGenerationDataAssetInfo, CodeGenerationDataFilename, - CodeGenerationResult, Dependency, DependencyType, EntryDependency, EntryOptions, Entrypoint, - ModuleFactory, RuntimeSpec, SourceType, + CodeGenerationResult, CompilationAsset, CompilationAssets, DependencyId, EntryOptions, + Entrypoint, RuntimeSpec, SourceType, }; -use crate::{Compilation, CompilationAsset, MakeParam}; -use crate::{CompilerOptions, Context, ResolverFactory, SharedPluginDriver}; static EXECUTE_MODULE_ID: AtomicU32 = AtomicU32::new(0); pub type ExecuteModuleId = u32; @@ -29,65 +28,38 @@ pub struct ExecuteModuleResult { pub id: ExecuteModuleId, } -#[derive(Debug, Default)] -pub struct ModuleExecutor { - pub assets: DashMap, +#[derive(Debug)] +pub struct ExecuteTask { + pub entry_dep_id: DependencyId, + pub public_path: Option, + pub base_uri: Option, + pub result_sender: Sender<(Result, CompilationAssets)>, } -impl ModuleExecutor { - #[allow(clippy::too_many_arguments)] - pub async fn import_module( - &self, - options: Arc, - plugin_driver: SharedPluginDriver, - resolver_factory: Arc, - loader_resolver_factory: Arc, - cache: Arc, - dependency_factories: HashMap>, - - request: String, - public_path: Option, - base_uri: Option, - original_module_context: Option, - ) -> Result { - let mut compilation = Compilation::new( - options, - plugin_driver, - resolver_factory, - loader_resolver_factory, - None, - cache, - None, - ); - compilation.dependency_factories = dependency_factories; +impl Task for ExecuteTask { + fn get_task_type(&self) -> TaskType { + TaskType::Sync + } - let mut mg = compilation.get_module_graph_mut(); - let dep_id = { - let dep = EntryDependency::new( - request, - original_module_context.unwrap_or(Context::from("")), - ); - let dep_id = *dep.id(); - mg.add_dependency(Box::new(dep)); - dep_id - }; + fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + let Self { + entry_dep_id, + public_path, + base_uri, + result_sender, + } = *self; - compilation - .make(vec![MakeParam::new_force_build_dep_param(dep_id, None)]) - .await?; + let mut compilation = context.transform_to_temp_compilation(); let id = EXECUTE_MODULE_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed); let mg = compilation.get_module_graph_mut(); - let module = mg - .get_module_by_dependency_id(&dep_id) + let entry_module_identifier = mg + .get_module_by_dependency_id(&entry_dep_id) .expect("should have module") .identifier(); - let mut queue = vec![module]; - let mut modules: std::collections::HashSet< - rspack_identifier::Identifier, - BuildHasherDefault, - > = HashSet::default(); + let mut queue = vec![entry_module_identifier]; + let mut modules = HashSet::default(); while let Some(m) = queue.pop() { modules.insert(m); @@ -137,7 +109,11 @@ impl ModuleExecutor { let chunk = compilation.chunk_by_ukey.add(chunk); let chunk_ukey = chunk.ukey; - chunk_graph.connect_chunk_and_entry_module(chunk.ukey, module, entrypoint.ukey); + chunk_graph.connect_chunk_and_entry_module( + chunk.ukey, + entry_module_identifier, + entrypoint.ukey, + ); entrypoint.connect_chunk(chunk); entrypoint.set_runtime_chunk(chunk.ukey); entrypoint.set_entry_point_chunk(chunk.ukey); @@ -168,14 +144,16 @@ impl ModuleExecutor { compilation.code_generation_modules(&mut None, false, modules.par_iter().copied())?; - compilation - .process_runtime_requirements( - modules.clone(), - once(chunk_ukey), - once(chunk_ukey), - compilation.plugin_driver.clone(), - ) - .await?; + Handle::current().block_on(async { + compilation + .process_runtime_requirements( + modules.clone(), + once(chunk_ukey), + once(chunk_ukey), + compilation.plugin_driver.clone(), + ) + .await + })?; let runtime_modules = compilation .chunk_graph @@ -215,7 +193,12 @@ impl ModuleExecutor { .plugin_driver .compilation_hooks .execute_module - .call(&module, &runtime_modules, &codegen_results, &id); + .call( + &entry_module_identifier, + &runtime_modules, + &codegen_results, + &id, + ); let module_graph = compilation.get_module_graph(); let mut execute_result = match exports { @@ -265,18 +248,14 @@ impl ModuleExecutor { Err(e) => Err(e), }; + let assets = std::mem::take(compilation.assets_mut()); if let Ok(ref mut result) = execute_result { - let assets = std::mem::take(compilation.assets_mut()); - for (key, value) in assets { - result.assets.insert(key.clone()); - self.assets.insert(key, value); - } + result.assets = assets.keys().cloned().collect::>(); } - - for error in compilation.get_errors() { - error.render_report(true)?; - } - - execute_result + context.recovery_from_temp_compilation(compilation); + result_sender + .send((execute_result, assets)) + .expect("should send result success"); + Ok(vec![]) } } diff --git a/crates/rspack_core/src/compiler/module_executor/mod.rs b/crates/rspack_core/src/compiler/module_executor/mod.rs new file mode 100644 index 000000000000..28344df5cc2f --- /dev/null +++ b/crates/rspack_core/src/compiler/module_executor/mod.rs @@ -0,0 +1,178 @@ +mod ctrl; +mod entry; +mod execute; +mod overwrite; + +use dashmap::mapref::entry::Entry; +use dashmap::DashMap; +pub use execute::ExecuteModuleId; +use rspack_error::Result; +use tokio::sync::{ + mpsc::{unbounded_channel, UnboundedSender}, + oneshot, +}; + +use self::{ + ctrl::{CtrlTask, Event}, + entry::EntryParam, + execute::{ExecuteModuleResult, ExecuteTask}, + overwrite::OverwriteTask, +}; +use super::make::{repair::MakeTaskContext, update_module_graph_with_artifact, MakeArtifact}; +use crate::{ + task_loop::run_task_loop_with_event, Compilation, CompilationAsset, Context, Dependency, + DependencyId, EntryDependency, MakeParam, +}; + +#[derive(Debug, Default)] +pub struct ModuleExecutor { + request_dep_map: DashMap, + make_artifact: MakeArtifact, + + event_sender: Option>, + stop_receiver: Option>, + assets: DashMap, +} + +impl ModuleExecutor { + pub async fn hook_before_make( + &mut self, + compilation: &Compilation, + global_params: &Vec, + ) { + let mut make_artifact = std::mem::take(&mut self.make_artifact); + let mut params = vec![]; + for param in global_params { + if matches!(param, MakeParam::DeletedFiles(_)) { + params.push(param.clone()); + } + if matches!(param, MakeParam::ModifiedFiles(_)) { + params.push(param.clone()); + } + } + if !make_artifact.make_failed_dependencies.is_empty() { + let deps = std::mem::take(&mut make_artifact.make_failed_dependencies); + params.push(MakeParam::ForceBuildDeps(deps)); + } + if !make_artifact.make_failed_module.is_empty() { + let modules = std::mem::take(&mut make_artifact.make_failed_module); + params.push(MakeParam::ForceBuildModules(modules)); + } + + make_artifact = if let Ok(artifact) = + update_module_graph_with_artifact(compilation, make_artifact, params).await + { + artifact + } else { + MakeArtifact::default() + }; + + let mut ctx = MakeTaskContext::new(compilation, make_artifact); + let (event_sender, event_receiver) = unbounded_channel(); + let (stop_sender, stop_receiver) = oneshot::channel(); + self.event_sender = Some(event_sender.clone()); + self.stop_receiver = Some(stop_receiver); + + tokio::spawn(async move { + let _ = run_task_loop_with_event( + &mut ctx, + vec![Box::new(CtrlTask::new(event_receiver))], + |_, task| { + Box::new(OverwriteTask { + origin_task: task, + event_sender: event_sender.clone(), + }) + }, + ); + + stop_sender + .send(ctx.transform_to_make_artifact()) + .expect("should success"); + }); + } + + pub async fn hook_before_process_assets(&mut self, compilation: &mut Compilation) { + let sender = std::mem::take(&mut self.event_sender); + sender + .expect("should have sender") + .send(Event::Stop()) + .expect("should success"); + + let stop_receiver = std::mem::take(&mut self.stop_receiver); + if let Ok(make_artifact) = stop_receiver.expect("should have receiver").await { + self.make_artifact = make_artifact; + } else { + panic!("receive make artifact failed"); + } + + let assets = std::mem::take(&mut self.assets); + for (filename, asset) in assets { + compilation.emit_asset(filename, asset); + } + + let diagnostics = std::mem::take(&mut self.make_artifact.diagnostics); + compilation.push_batch_diagnostic(diagnostics); + + compilation + .file_dependencies + .extend(self.make_artifact.file_dependencies.iter().cloned()); + compilation + .context_dependencies + .extend(self.make_artifact.context_dependencies.iter().cloned()); + compilation + .missing_dependencies + .extend(self.make_artifact.missing_dependencies.iter().cloned()); + compilation + .build_dependencies + .extend(self.make_artifact.build_dependencies.iter().cloned()); + } + + #[allow(clippy::too_many_arguments)] + pub async fn import_module( + &self, + request: String, + public_path: Option, + base_uri: Option, + original_module_context: Option, + ) -> Result { + let sender = self + .event_sender + .as_ref() + .expect("should have event sender"); + let (param, dep_id) = match self.request_dep_map.entry(request.clone()) { + Entry::Vacant(v) => { + let dep = EntryDependency::new( + request.clone(), + original_module_context.unwrap_or(Context::from("")), + ); + let dep_id = *dep.id(); + v.insert(dep_id); + (EntryParam::EntryDependency(Box::new(dep)), dep_id) + } + Entry::Occupied(v) => { + let dep_id = *v.get(); + (EntryParam::DependencyId(dep_id, sender.clone()), dep_id) + } + }; + + let (tx, rx) = oneshot::channel(); + sender + .send(Event::ExecuteModule( + param, + ExecuteTask { + entry_dep_id: dep_id, + public_path, + base_uri, + result_sender: tx, + }, + )) + .expect("should success"); + let (execute_result, assets) = rx.await.expect("should receiver success"); + + for (key, value) in assets { + self.assets.insert(key, value); + } + + execute_result + } +} diff --git a/crates/rspack_core/src/compiler/module_executor/overwrite.rs b/crates/rspack_core/src/compiler/module_executor/overwrite.rs new file mode 100644 index 000000000000..14bb424ac45b --- /dev/null +++ b/crates/rspack_core/src/compiler/module_executor/overwrite.rs @@ -0,0 +1,92 @@ +use tokio::sync::mpsc::UnboundedSender; + +use super::ctrl::Event; +use crate::{ + compiler::make::repair::{ + add::AddTask, factorize::FactorizeResultTask, process_dependencies::ProcessDependenciesTask, + MakeTaskContext, + }, + utils::task_loop::{Task, TaskResult, TaskType}, +}; + +pub struct OverwriteTask { + pub origin_task: Box>, + pub event_sender: UnboundedSender, +} + +#[async_trait::async_trait] +impl Task for OverwriteTask { + fn get_task_type(&self) -> TaskType { + self.origin_task.get_task_type() + } + + fn sync_run(self: Box, context: &mut MakeTaskContext) -> TaskResult { + let Self { + origin_task, + event_sender, + } = *self; + // process dependencies + if let Some(process_dependencies_task) = origin_task + .as_any() + .downcast_ref::() + { + let original_module_identifier = process_dependencies_task.original_module_identifier; + let res = origin_task.sync_run(context)?; + event_sender + .send(Event::FinishModule(original_module_identifier, res.len())) + .expect("should success"); + return Ok(res); + } + + // factorize result task + if let Some(factorize_result_task) = origin_task.as_any().downcast_ref::() + { + let dep_id = factorize_result_task + .dependencies + .first() + .cloned() + .expect("should have dep_id"); + let original_module_identifier = factorize_result_task.original_module_identifier; + let res = origin_task.sync_run(context)?; + if res.is_empty() { + event_sender + .send(Event::FinishDeps(original_module_identifier, dep_id, None)) + .expect("should success"); + } + return Ok(res); + } + // add task + if let Some(add_task) = origin_task.as_any().downcast_ref::() { + let dep_id = add_task + .dependencies + .first() + .cloned() + .expect("should have dep_id"); + let original_module_identifier = add_task.original_module_identifier; + let target_module_identifier = add_task.module.identifier(); + + let res = origin_task.sync_run(context)?; + if res.is_empty() { + event_sender + .send(Event::FinishDeps( + original_module_identifier, + dep_id, + Some(target_module_identifier), + )) + .expect("should success"); + } else { + event_sender + .send(Event::StartBuild(target_module_identifier)) + .expect("should success"); + } + return Ok(res); + } + + // other task + origin_task.sync_run(context) + } + + async fn async_run(self: Box) -> TaskResult { + self.origin_task.async_run().await + } +} diff --git a/crates/rspack_core/src/utils/task_loop.rs b/crates/rspack_core/src/utils/task_loop.rs index d285ef637ddf..17357deeb9dc 100644 --- a/crates/rspack_core/src/utils/task_loop.rs +++ b/crates/rspack_core/src/utils/task_loop.rs @@ -1,4 +1,5 @@ use std::{ + any::Any, collections::VecDeque, sync::{ atomic::{AtomicBool, Ordering}, @@ -7,7 +8,11 @@ use std::{ }; use rspack_error::Result; -use tokio::sync::mpsc::{self, error::TryRecvError}; +use rspack_util::ext::AsAny; +use tokio::{ + runtime::Handle, + sync::mpsc::{self, error::TryRecvError}, +}; /// Result returned by task /// @@ -26,11 +31,11 @@ pub enum TaskType { /// /// See test for more example #[async_trait::async_trait] -pub trait Task: Send { +pub trait Task: Send + Any + AsAny { /// Return the task type /// - /// return `TaskType::Sync` will run `self::sync_run` - /// return `TaskType::Async` will run `self::async_run` + /// Return `TaskType::Sync` will run `self::sync_run` + /// Return `TaskType::Async` will run `self::async_run` fn get_task_type(&self) -> TaskType; /// Sync task process @@ -50,6 +55,15 @@ pub trait Task: Send { pub fn run_task_loop( ctx: &mut Ctx, init_tasks: Vec>>, +) -> Result<()> { + run_task_loop_with_event(ctx, init_tasks, |_, task| task) +} + +/// Run task loop with event +pub fn run_task_loop_with_event( + ctx: &mut Ctx, + init_tasks: Vec>>, + before_task_run: impl Fn(&mut Ctx, Box>) -> Box>, ) -> Result<()> { // create channel to receive async task result let (tx, mut rx) = mpsc::unbounded_channel::>(); @@ -65,6 +79,7 @@ pub fn run_task_loop( } if let Some(task) = task { + let task = before_task_run(ctx, task); match task.get_task_type() { TaskType::Async => { let tx = tx.clone(); @@ -90,7 +105,16 @@ pub fn run_task_loop( } } - match rx.try_recv() { + let data = if queue.is_empty() && active_task_count != 0 { + Handle::current().block_on(async { + let res = rx.recv().await.expect("should recv success"); + Ok(res) + }) + } else { + rx.try_recv() + }; + + match data { Ok(r) => { active_task_count -= 1; // merge async task result From 80d05de4bf3b8e7058cf9bccf05b034b83b2da25 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 6 May 2024 15:01:13 +0800 Subject: [PATCH 006/107] feat: export Chunk and Module types from `@rspack/core` (#6421) types: export Chunk and Module from `@rspack/core` --- packages/rspack/etc/api.md | 6 ++++-- packages/rspack/src/exports.ts | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index c1ac24791748..e23c8e8bff99 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -970,7 +970,7 @@ type CallFn = (...args: any[]) => any; type CallFn_2 = (args: D[]) => void; // @public (undocumented) -class Chunk { +export class Chunk { constructor(chunk: JsChunk, compilation: JsCompilation); // (undocumented) static __from_binding(chunk: JsChunk, compilation: Compilation): Chunk; @@ -4920,7 +4920,7 @@ export type Mode = z.infer; const mode: z.ZodEnum<["development", "production", "none"]>; // @public (undocumented) -class Module { +export class Module { constructor(module: JsModule); // (undocumented) static __from_binding(module: JsModule): Module; @@ -7875,8 +7875,10 @@ declare namespace rspackExports { StatsModule, StatsWarnings, MultiStats, + Chunk, ChunkGroup, NormalModuleFactory, + Module, NormalModule, ModuleFilenameHelpers, Template, diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 81b62e7865cd..b7156487f7f2 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -32,10 +32,13 @@ export type { export { MultiStats } from "./MultiStats"; +export type { Chunk } from "./Chunk"; export type { ChunkGroup } from "./ChunkGroup"; export type { NormalModuleFactory } from "./NormalModuleFactory"; +export type { Module } from "./Module"; + export { NormalModule } from "./NormalModule"; // API extractor not working with some re-exports, see: https://github.com/microsoft/fluentui/issues/20694 From 81f97fb0ef88d910b4d53e0538a2275e61f80b8d Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Mon, 6 May 2024 17:56:51 +0800 Subject: [PATCH 007/107] docs: split loader docs (#6442) * docs: split loader api * docs: split loader api zh * docs: remove type decl detail in title --- website/docs/en/api/_meta.json | 6 +- website/docs/en/api/index.mdx | 2 +- website/docs/en/api/loader-api.mdx | 335 ------------------ website/docs/en/api/loader-api/_meta.json | 8 + website/docs/en/api/loader-api/context.mdx | 181 ++++++++++ website/docs/en/api/loader-api/examples.mdx | 150 ++++++++ website/docs/en/api/loader-api/index.mdx | 5 + .../api/loader-api/inline-match-resource.mdx | 52 +++ website/docs/en/api/loader-api/inline.mdx | 33 ++ .../loader-api/rspack-specific-properties.mdx | 21 ++ website/docs/en/api/plugin-api/index.mdx | 2 +- website/docs/en/blog/announcing-0-2.mdx | 2 +- website/docs/en/config/entry.mdx | 2 +- website/docs/en/config/resolve-loader.mdx | 2 +- website/docs/en/guide/features/loader.mdx | 2 +- website/docs/zh/api/_meta.json | 6 +- website/docs/zh/api/index.mdx | 2 +- website/docs/zh/api/loader-api.mdx | 321 +---------------- website/docs/zh/api/loader-api/_meta.json | 8 + website/docs/zh/api/loader-api/context.mdx | 176 +++++++++ website/docs/zh/api/loader-api/examples.mdx | 150 ++++++++ website/docs/zh/api/loader-api/index.mdx | 5 + .../api/loader-api/inline-match-resource.mdx | 51 +++ website/docs/zh/api/loader-api/inline.mdx | 33 ++ .../loader-api/rspack-specific-properties.mdx | 21 ++ website/docs/zh/api/plugin-api/index.mdx | 2 +- website/docs/zh/blog/announcing-0-2.mdx | 2 +- website/docs/zh/config/entry.mdx | 2 +- website/docs/zh/config/resolve-loader.mdx | 2 +- website/docs/zh/guide/features/loader.mdx | 2 +- website/theme/components/HomeFooter/index.tsx | 2 +- 31 files changed, 918 insertions(+), 670 deletions(-) delete mode 100644 website/docs/en/api/loader-api.mdx create mode 100644 website/docs/en/api/loader-api/_meta.json create mode 100644 website/docs/en/api/loader-api/context.mdx create mode 100644 website/docs/en/api/loader-api/examples.mdx create mode 100644 website/docs/en/api/loader-api/index.mdx create mode 100644 website/docs/en/api/loader-api/inline-match-resource.mdx create mode 100644 website/docs/en/api/loader-api/inline.mdx create mode 100644 website/docs/en/api/loader-api/rspack-specific-properties.mdx create mode 100644 website/docs/zh/api/loader-api/_meta.json create mode 100644 website/docs/zh/api/loader-api/context.mdx create mode 100644 website/docs/zh/api/loader-api/examples.mdx create mode 100644 website/docs/zh/api/loader-api/index.mdx create mode 100644 website/docs/zh/api/loader-api/inline-match-resource.mdx create mode 100644 website/docs/zh/api/loader-api/inline.mdx create mode 100644 website/docs/zh/api/loader-api/rspack-specific-properties.mdx diff --git a/website/docs/en/api/_meta.json b/website/docs/en/api/_meta.json index 251ba45090ab..1308531c1765 100644 --- a/website/docs/en/api/_meta.json +++ b/website/docs/en/api/_meta.json @@ -4,7 +4,11 @@ "modules", "node-api", "hmr", - "loader-api", + { + "type": "dir", + "name": "loader-api", + "label": "Loader API" + }, { "type": "dir", "name": "plugin-api", diff --git a/website/docs/en/api/index.mdx b/website/docs/en/api/index.mdx index 4394d4c28f11..310d616d694c 100644 --- a/website/docs/en/api/index.mdx +++ b/website/docs/en/api/index.mdx @@ -30,7 +30,7 @@ The Hot Module Replacement (HMR) improves the development experience by updating Loaders are transformations that are applied to the source code of a module. They are written as functions that accept source code as a parameter and return a new version of that code with transformations applied. -[Learn more about the loaders!](/api/loader-api) +[Learn more about the loaders!](/api/loader-api/index) ## Plugins diff --git a/website/docs/en/api/loader-api.mdx b/website/docs/en/api/loader-api.mdx deleted file mode 100644 index f819502c5081..000000000000 --- a/website/docs/en/api/loader-api.mdx +++ /dev/null @@ -1,335 +0,0 @@ -import WebpackLicense from '@components/webpack-license'; - - - -# Loader API - -Rspack loader is designed to reuse the webpack loader, it is compatible with most of the webpack loader API, the rest of the API is still being implemented, so most of the webpack loader can already run in Rspack. - -::: info Webpack Loader API conformance -Check out [this](https://github.com/orgs/web-infra-dev/projects/10) page to see the status of Webpack Loader API conformance. -::: - -## Synchronous Loaders - -Either `return` or `this.callback` can be used to return the transformed content synchronously: - -```js title="sync-loader.js" -module.exports = function (content, map, meta) { - return someSyncOperation(content); -}; -``` - -The `this.callback` method is more flexible as it allows multiple arguments to be passed as opposed to only the `content`. - -```js title="sync-loader-with-multiple-results.js" -module.exports = function (content, map, meta) { - this.callback(null, someSyncOperation(content), map, meta); - return; // always return undefined when calling callback() -}; -``` - -::: info -Rspack, internally, will convert loaders into asynchronous regardless of it's a synchronous loader for technical and performance reason. -::: - -## Asynchronous Loaders - -For asynchronous loaders, `this.async` is used to retrieve the callback function: - -```js title="async-loader.js" -module.exports = function (content, map, meta) { - var callback = this.async(); - someAsyncOperation(content, function (err, result) { - if (err) return callback(err); - callback(null, result, map, meta); - }); -}; -``` - -```js title="async-loader-with-multiple-results.js" -module.exports = function (content, map, meta) { - var callback = this.async(); - someAsyncOperation(content, function (err, result, sourceMaps, meta) { - if (err) return callback(err); - callback(null, result, sourceMaps, meta); - }); -}; -``` - -## Inline loaders - -It's possible to specify loaders in an import statement, or any equivalent "importing" method. Separate loaders from the resource with `!`. Each part is resolved relative to the current directory. - -```js -import Styles from 'style-loader!css-loader?modules!./styles.css'; -``` - -It's possible to override any loaders, preLoaders and postLoaders from the configuration by prefixing the inline import statement: - -Prefixing with `!` will disable all configured normal loaders - -```js -import Styles from '!style-loader!css-loader?modules!./styles.css'; -``` - -Prefixing with `!!` will disable all configured loaders (preLoaders, loaders, postLoaders) - -```js -import Styles from '!!style-loader!css-loader?modules!./styles.css'; -``` - -Prefixing with `-!` will disable all configured preLoaders and loaders but not postLoaders - -```js -import Styles from '-!style-loader!css-loader?modules!./styles.css'; -``` - -Options can be passed with a query parameter, e.g. `?key=value&foo=bar`, or a JSON object, e.g. `?{"key":"value","foo":"bar"}`. - -## Pitching loader - -Every loader has two stages: `Normal` and `Pitching`. -There are some instances where the loader only cares about the **metadata** -behind a request and can ignore the results of the previous loader. -The pitch method on loaders is called from **left to right** before the loaders are actually executed (from right to left). - -For the following configuration of use: - -```js title="rspack.config.js" -module.exports = { - //... - module: { - rules: [ - { - //... - use: ['a-loader', 'b-loader', 'c-loader'], - }, - ], - }, -}; -``` - -These steps would occur: - -``` -|- a-loader `pitch` - |- b-loader `pitch` - |- c-loader `pitch` - |- requested module is picked up as a dependency - |- c-loader normal execution - |- b-loader normal execution -|- a-loader normal execution -``` - -Normally, if it the loader is simple enough which only exports the normal stage hook: - -```js -module.exports = function (source) {}; -``` - -Then, the pitching stage will be skipped. - -So why might a loader take advantage of the "pitching" phase? - -First, the data passed to the pitch method is exposed in the execution phase as well under this.data and could be useful for capturing and sharing information from earlier in the cycle. - -```js -module.exports = function (content) { - return someSyncOperation(content, this.data.value); -}; - -module.exports.pitch = function (remainingRequest, precedingRequest, data) { - data.value = 42; -}; -``` - -Second, if a loader delivers a result in the pitch method, the process turns around and skips the remaining loaders. -In our example above, if the b-loaders pitch method returned something: - -```js -module.exports = function (content) { - return someSyncOperation(content); -}; - -module.exports.pitch = function (remainingRequest, precedingRequest, data) { - if (someCondition()) { - return ( - 'module.exports = require(' + - JSON.stringify('-!' + remainingRequest) + - ');' - ); - } -}; -``` - -The steps above would be shortened to: - -``` -|- a-loader `pitch` - |- b-loader `pitch` returns a module -|- a-loader normal execution -``` - -For a real world example, `style-loader` leverages the second advantage to dispatch requests. -Please visit [style-loader](https://github.com/webpack-contrib/style-loader/blob/eb06baeb3ac4e3107732a21170b0a7f358c5423f/src/index.js#L39) for details. - -## Inline match resource - -A new inline request syntax was introduced in webpack v4. Prefixing `!=!` to a request will set the matchResource for this request. -When a `matchResource` is set, it will be used to match with the module.rules instead of the original resource. This can be useful if further loaders should be applied to the resource, or if the module type needs to be changed. - -Example: - -```js title="file.js" -/* STYLE: body { background: red; } */ -console.log('yep'); -``` - -A loader could transform the file into the following file and use the matchResource to apply the user-specified CSS processing rules: - -```js title="file.js (transformed by loader)" -import './file.js.css!=!extract-style-loader/getStyles!./file.js'; -console.log('yep'); -``` - -This will add a dependency to `extract-style-loader/getStyles!./file.js` and treat the result as file.js.css. -Because `module.rules` has a rule matching /\.css$/ and it will apply to this dependency. - -The loader could look like this: - -```js title="extract-style-loader/index.js" -const getStylesLoader = require.resolve('./getStyles'); - -module.exports = function (source) { - if (STYLES_REGEXP.test(source)) { - source = source.replace(STYLES_REGEXP, ''); - return `import ${JSON.stringify( - this.utils.contextify( - this.context || this.rootContext, - `${this.resource}.css!=!${getStylesLoader}!${this.remainingRequest}`, - ), - )};${source}`; - } - return source; -}; -``` - -```js title="extract-style-loader/getStyles.js" -module.exports = function (source) { - const match = source.match(STYLES_REGEXP); - return match[0]; -}; -``` - -## 'Raw' Loader - -By default, resource files are converted to UTF-8 strings and passed to the loader. loaders can receive raw `Buffer` by setting `raw` to `true`. Each loader can pass its processing results as `String` or `Buffer`, and the Rspack compiler will convert them to and from the loader. - -```js -module.exports = function (content) { - assert(content instanceof Buffer); - // ... -}; -module.exports.raw = true; -``` - -## `this.addContextDependency(directory: string)` - -Add the directory as a dependency for the loader results so that any changes to the files in the directory can be listened to. - -## `this.addDependency(file: string)` - -Add a file as a dependency on the loader results so that any changes to them can be listened to. For example, `sass-loader`, `less-loader` use this trick to recompile when the imported style files change. - -## `this.dependency(file: string)` - -Alias of `this.addDependency(file: string)`. - -## `this.addMissingDependency(file: string)` - -Add a non-existent file as a dependency on the loader results to make them listenable. - -## `this.clearDependencies()` - -Removes all dependencies of the loader result. - -## `this.async()` - -Tells Rspack that this loader will be called asynchronously. Returns `this.callback`. - -## `this.callback(err: Error | null, content: string | Buffer, sourceMap?: SourceMap, meta?: any)` - -Tell Rspack the result of the Loader processing. - -The first parameter must be `Error` or `null`, which marks the current module as a compilation failure, the second parameter is a `string` or `Buffer`, which indicates the contents of the file after the module has been processed by the loader, the third parameter is a source map that can be processed by the loader, and the fourth parameter is ignored by Rspack and can be anything (e.g. some metadata). - -## `this.cacheable(flag: boolean = true)` - -By default, the processing results of the loader are marked as cacheable. Calling this method and passing `false` turns off the loader's ability to cache processing results. - -## `this.context` - -The directory where the current module is located. - -## `this.rootContext` - -The directory where the project is configured in config - -## `this.emitError(err: Error)` - -Emit an error. Unlike `throw` and `this.callback(err)` in the loader, it does not mark the current module as a compilation failure, it just adds an error to Rspack's Compilation and displays it on the command line at the end of this compilation. - -## `this.emitWarning(warning: Error)` - -Emit a warning. - -## `this.emitFile(name: string, content: Buffer | string, sourceMap: SourceMap)` - -Emit a file - -## `this.getOptions(schema)` - -Extracts the given loader option, accepting an optional JSON schema as an argument. - -## `this.getResolve(options: ResolveOptions): resolve` - -Create a resolver like `this.resolve`. - -## `this.resolve(context: string, request: string, callback: (err: Error | null, result: string) => void)` - -Resolve a request. - -- `context` must be the absolute path to a directory. This directory is used as the starting location for resolving. -- `request` is the request to be resolved. -- `callback` is a callback function that gives the resolved path. - -## `this.mode` - -The value of [`mode`](/config/mode) is read when webpack is run. - -The possible values are: `'production'`, `'development'`, `'none'` - -## `this.resource` - -The path string of the current module. For example `'/abc/resource.js?query#hash'`. - -## `this.resourcePath` - -The path string of the current module, excluding the query and fragment parameters. For example `'/abc/resource.js?query#hash'` in `'/abc/resource.js'`. - -## `this.resourceQuery` - -The query parameter for the path string of the current module. For example `'?query'` in `'/abc/resource.js?query#hash'`. - -## `this.resourceFragment` - -The fragment parameter of the current module's path string. For example `'#hash'` in `'/abc/resource.js?query#hash'`. - -## `this.sourceMap` - -Whether a source map should be generated. - -## `this.getLogger(name?: string)` - -Get the logger of this compilation, through which messages can be logged. diff --git a/website/docs/en/api/loader-api/_meta.json b/website/docs/en/api/loader-api/_meta.json new file mode 100644 index 000000000000..7a710dbf561a --- /dev/null +++ b/website/docs/en/api/loader-api/_meta.json @@ -0,0 +1,8 @@ +[ + "index", + "examples", + "context", + "rspack-specific-properties", + "inline", + "inline-match-resource" +] diff --git a/website/docs/en/api/loader-api/context.mdx b/website/docs/en/api/loader-api/context.mdx new file mode 100644 index 000000000000..69ea6451305c --- /dev/null +++ b/website/docs/en/api/loader-api/context.mdx @@ -0,0 +1,181 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# The Loader Context + +The loader context represents the properties that are available inside of a loader assigned to the `this` property. + +## this.addContextDependency() + +```ts +function addContextDependency(directory: string): void; +``` + +Add the directory as a dependency for the loader results so that any changes to the files in the directory can be listened to. + +## this.addDependency() + +```ts +function addDependency(file: string): void; +``` + +Add a file as a dependency on the loader results so that any changes to them can be listened to. For example, `sass-loader`, `less-loader` use this trick to recompile when the imported style files change. + +## this.dependency() + +```ts +function dependency(file: string): void; +``` + +Alias of `this.addDependency()`. + +## this.addMissingDependency() + +```ts +function addMissingDependency(file: string): void; +``` + +Add a non-existent file as a dependency on the loader results to make them listenable. + +## this.async() + +Tells Rspack that this loader will be called asynchronously. Returns `this.callback`. + +## this.cacheable() + +A function that sets the cacheable flag: + +```ts +function cacheable(flag: boolean = true): void; +``` + +By default, the processing results of the loader are marked as cacheable. Calling this method and passing `false` turns off the loader's ability to cache processing results. + +## this.callback() + +```ts +function callback( + err: Error | null, + content: string | Buffer, + sourceMap?: SourceMap, + meta?: any, +): void; +``` + +A function that can be called synchronously or asynchronously in order to return multiple results. The expected arguments are: + +1. The first parameter must be `Error` or `null`, which marks the current module as a compilation failure. +2. The second argument is a `string` or `Buffer`, which indicates the contents of the file after the module has been processed by the loader. +3. The third parameter is a source map that can be processed by the loader. +4. The fourth parameter is ignored by Rspack and can be anything (e.g. some metadata). + +## this.clearDependencies() + +```ts +function clearDependencies(): void; +``` + +Removes all dependencies of the loader result. + +## this.context + +The directory where the current module is located. + +## this.data + +A data object shared between the pitch and the normal phase. + +## this.emitError() + +```ts +function emitError(error: Error): void; +``` + +Emit an error. Unlike `throw` and `this.callback(err)` in the loader, it does not mark the current module as a compilation failure, it just adds an error to Rspack's Compilation and displays it on the command line at the end of this compilation. + +## this.emitWarning(warning: Error) + +```ts +function emitWarning(warning: Error): void; +``` + +Emit a warning. + +## this.emitFile() + +```ts +function emitFile( + name: string, + content: Buffer | string, + sourceMap: SourceMap, +): void; +``` + +Emit a file. + +## this.getOptions(schema) + +Extracts the given loader option, accepting an optional JSON schema as an argument. + +## this.getResolve() + +```ts +function getResolve(options: ResolveOptions): resolve; +``` + +Create a resolver like `this.resolve`. + +## this.resolve() + +```ts +function resolve( + context: string, + request: string, + callback: (err: Error | null, result: string) => void, +): void; +``` + +Resolve a request. + +- `context` must be the absolute path to a directory. This directory is used as the starting location for resolving. +- `request` is the request to be resolved. +- `callback` is a callback function that gives the resolved path. + +## this.mode + +The value of [`mode`](/config/mode) is read when Rspack is run. + +The possible values are: `'production'`, `'development'`, `'none'` + +## this.resource + +The path string of the current module. For example `'/abc/resource.js?query#hash'`. + +## this.resourcePath + +The path string of the current module, excluding the query and fragment parameters. For example `'/abc/resource.js?query#hash'` in `'/abc/resource.js'`. + +## this.resourceQuery + +The query parameter for the path string of the current module. For example `'?query'` in `'/abc/resource.js?query#hash'`. + +## this.resourceFragment + +The fragment parameter of the current module's path string. For example `'#hash'` in `'/abc/resource.js?query#hash'`. + +## this.rootContext + +The directory where the project is configured in config + +## this.sourceMap + +Whether a source map should be generated. + +## this.getLogger() + +```ts +function getLogger(name?: string): void; +``` + +Get the logger of this compilation, through which messages can be logged. diff --git a/website/docs/en/api/loader-api/examples.mdx b/website/docs/en/api/loader-api/examples.mdx new file mode 100644 index 000000000000..d5b9b4d88b5c --- /dev/null +++ b/website/docs/en/api/loader-api/examples.mdx @@ -0,0 +1,150 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Examples + +The following sections provide some basic examples of the different types of loaders. Note that the `map` and `meta` parameters are optional, see [`this.callback`](#thiscallbackerr-error--null-content-string--buffer-sourcemap-sourcemap-meta-any) below. + +## Synchronous Loaders + +Either `return` or `this.callback` can be used to return the transformed `content` synchronously: + +```js title="sync-loader.js" +module.exports = function (content, map, meta) { + return someSyncOperation(content); +}; +``` + +The `this.callback` method is more flexible as it allows multiple arguments to be passed as opposed to only the `content`. + +```js title="sync-loader-with-multiple-results.js" +module.exports = function (content, map, meta) { + this.callback(null, someSyncOperation(content), map, meta); + return; // always return undefined when calling callback() +}; +``` + +::: info +Rspack, internally, will convert loaders into asynchronous regardless of it's a synchronous loader for technical and performance reason. +::: + +## Asynchronous Loaders + +For asynchronous loaders, `this.async` is used to retrieve the `callback` function: + +```js title="async-loader.js" +module.exports = function (content, map, meta) { + var callback = this.async(); + someAsyncOperation(content, function (err, result) { + if (err) return callback(err); + callback(null, result, map, meta); + }); +}; +``` + +```js title="async-loader-with-multiple-results.js" +module.exports = function (content, map, meta) { + var callback = this.async(); + someAsyncOperation(content, function (err, result, sourceMaps, meta) { + if (err) return callback(err); + callback(null, result, sourceMaps, meta); + }); +}; +``` + +## 'Raw' Loader + +By default, resource files are converted to UTF-8 strings and passed to the loader. loaders can receive raw `Buffer` by setting `raw` to `true`. Each loader can pass its processing results as `String` or `Buffer`, and the Rspack compiler will convert them to and from the loader. + +```js title="raw-loader.js" +module.exports = function (content) { + assert(content instanceof Buffer); + // ... +}; +module.exports.raw = true; +``` + +## Pitching loader + +Loaders are **always** called from right to left. There are some instances where the loader only cares about the **metadata** behind a request and can ignore the results of the previous loader. The `pitch` method on loaders is called from **left to right** before the loaders are actually executed (from right to left). + +For the following configuration of `use`: + +```js title="rspack.config.js" +module.exports = { + //... + module: { + rules: [ + { + //... + use: ['a-loader', 'b-loader', 'c-loader'], + }, + ], + }, +}; +``` + +These steps would occur: + +``` +|- a-loader `pitch` + |- b-loader `pitch` + |- c-loader `pitch` + |- requested module is picked up as a dependency + |- c-loader normal execution + |- b-loader normal execution +|- a-loader normal execution +``` + +Normally, if it the loader is simple enough which only exports the normal stage hook: + +```js +module.exports = function (source) {}; +``` + +Then, the pitching stage will be skipped. + +So why might a loader take advantage of the "pitching" phase? + +First, the data passed to the pitch method is exposed in the execution phase as well under this.data and could be useful for capturing and sharing information from earlier in the cycle. + +```js +module.exports = function (content) { + return someSyncOperation(content, this.data.value); +}; + +module.exports.pitch = function (remainingRequest, precedingRequest, data) { + data.value = 42; +}; +``` + +Second, if a loader delivers a result in the pitch method, the process turns around and skips the remaining loaders. +In our example above, if the b-loaders pitch method returned something: + +```js +module.exports = function (content) { + return someSyncOperation(content); +}; + +module.exports.pitch = function (remainingRequest, precedingRequest, data) { + if (someCondition()) { + return ( + 'module.exports = require(' + + JSON.stringify('-!' + remainingRequest) + + ');' + ); + } +}; +``` + +The steps above would be shortened to: + +``` +|- a-loader `pitch` + |- b-loader `pitch` returns a module +|- a-loader normal execution +``` + +For a real world example, `style-loader` leverages the second advantage to dispatch requests. +Please visit [style-loader](https://github.com/webpack-contrib/style-loader/blob/eb06baeb3ac4e3107732a21170b0a7f358c5423f/src/index.js#L39) for details. diff --git a/website/docs/en/api/loader-api/index.mdx b/website/docs/en/api/loader-api/index.mdx new file mode 100644 index 000000000000..0bab72a38a52 --- /dev/null +++ b/website/docs/en/api/loader-api/index.mdx @@ -0,0 +1,5 @@ +# Compatibility Status + +Rspack is committed to being compatible with the loaders within the webpack ecosystem. We ensure that Rspack is as compatible as possible with the webpack loader API, allowing more existing webpack loaders to be directly used in Rspack. + +We have already made most of the webpack loader APIs compatible. You can visit [this page](https://github.com/orgs/web-infra-dev/projects/10) to learn about the current compatibility status of webpack loader APIs. diff --git a/website/docs/en/api/loader-api/inline-match-resource.mdx b/website/docs/en/api/loader-api/inline-match-resource.mdx new file mode 100644 index 000000000000..fc8b89ffd333 --- /dev/null +++ b/website/docs/en/api/loader-api/inline-match-resource.mdx @@ -0,0 +1,52 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Inline matchResource + +Prefixing `!=!` to a request will set the `matchResource` for this request. + +When a `matchResource` is set, it will be used to match with the `module.rules` instead of the original resource. This can be useful if further loaders should be applied to the resource, or if the module type needs to be changed. + +Example: + +```js title="file.js" +/* STYLE: body { background: red; } */ +console.log('yep'); +``` + +A loader could transform the file into the following file and use the `matchResource` to apply the user-specified CSS processing rules: + +```js title="file.js (transformed by loader)" +import './file.js.css!=!extract-style-loader/getStyles!./file.js'; +console.log('yep'); +``` + +This will add a dependency to `extract-style-loader/getStyles!./file.js` and treat the result as `file.js.css`. +Because `module.rules` has a rule matching `/\.css$/` and it will apply to this dependency. + +The loader could look like this: + +```js title="extract-style-loader/index.js" +const getStylesLoader = require.resolve('./getStyles'); + +module.exports = function (source) { + if (STYLES_REGEXP.test(source)) { + source = source.replace(STYLES_REGEXP, ''); + return `import ${JSON.stringify( + this.utils.contextify( + this.context || this.rootContext, + `${this.resource}.css!=!${getStylesLoader}!${this.remainingRequest}`, + ), + )};${source}`; + } + return source; +}; +``` + +```js title="extract-style-loader/getStyles.js" +module.exports = function (source) { + const match = source.match(STYLES_REGEXP); + return match[0]; +}; +``` diff --git a/website/docs/en/api/loader-api/inline.mdx b/website/docs/en/api/loader-api/inline.mdx new file mode 100644 index 000000000000..7bfbf953060f --- /dev/null +++ b/website/docs/en/api/loader-api/inline.mdx @@ -0,0 +1,33 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Inline loaders + +It's possible to specify loaders in an `import` statement, or any equivalent "importing" method. Separate loaders from the resource with `!`. Each part is resolved relative to the current directory. + +```js +import Styles from 'style-loader!css-loader?modules!./styles.css'; +``` + +It's possible to override any loaders, preLoaders and postLoaders from the configuration by prefixing the inline `import` statement: + +- Prefixing with `!` will disable all configured normal loaders + + ```js + import Styles from '!style-loader!css-loader?modules!./styles.css'; + ``` + +- Prefixing with `!!` will disable all configured loaders (preLoaders, loaders, postLoaders) + + ```js + import Styles from '!!style-loader!css-loader?modules!./styles.css'; + ``` + +- Prefixing with `-!` will disable all configured preLoaders and loaders but not postLoaders + + ```js + import Styles from '-!style-loader!css-loader?modules!./styles.css'; + ``` + +Options can be passed with a query parameter, e.g. `?key=value&foo=bar`, or a JSON object, e.g. `?{"key":"value","foo":"bar"}`. diff --git a/website/docs/en/api/loader-api/rspack-specific-properties.mdx b/website/docs/en/api/loader-api/rspack-specific-properties.mdx new file mode 100644 index 000000000000..f85a3d5fde52 --- /dev/null +++ b/website/docs/en/api/loader-api/rspack-specific-properties.mdx @@ -0,0 +1,21 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Rspack specific properties + +The loader interface provides all module relate information. However in rare cases you might need access to the compiler api itself. + +:::warning +Please note that using these Rspack specific properties will have a negative impact on your loaders compatibility. + +Therefore you should only use them as a last resort. Using them will reduce the portability of your loader. +::: + +## this.\_compilation + +Access to the current Compilation object of Rspack. + +## this.\_compiler + +Access to the current Compiler object of Rspack. diff --git a/website/docs/en/api/plugin-api/index.mdx b/website/docs/en/api/plugin-api/index.mdx index 0c9552405ddd..45fcad65f5d7 100644 --- a/website/docs/en/api/plugin-api/index.mdx +++ b/website/docs/en/api/plugin-api/index.mdx @@ -2,4 +2,4 @@ Rspack is committed to being compatible with the plugins within the webpack ecosystem. We ensure that Rspack is as compatible as possible with the webpack plugin API, allowing more existing webpack plugins to be directly used in Rspack. -You can visit [this page](https://github.com/orgs/web-infra-dev/projects/9) to learn about the current compatibility status of webpack plugin APIs. +We have already made most of the webpack plugin APIs compatible. You can visit [this page](https://github.com/orgs/web-infra-dev/projects/9) to learn about the current compatibility status of webpack plugin APIs. diff --git a/website/docs/en/blog/announcing-0-2.mdx b/website/docs/en/blog/announcing-0-2.mdx index 9bc88fe0f37d..e787e32fa51c 100644 --- a/website/docs/en/blog/announcing-0-2.mdx +++ b/website/docs/en/blog/announcing-0-2.mdx @@ -16,7 +16,7 @@ We look forward to you experiencing these new improvements in version 0.2, and w ### Loader -Version 0.2 has completed compatibility with most of the loader APIs, including: inline match resource, pitching loader, and inline loader. More APIs have further improved compatibility with webpack loaders, details of which can be found in our webpack compatibility updates [Loader API](/api/loader-api.html). +Version 0.2 has completed compatibility with most of the loader APIs, including: inline match resource, pitching loader, and inline loader. More APIs have further improved compatibility with webpack loaders, details of which can be found in our webpack compatibility updates [Loader API](/api/loader-api/index). ### Plugin Hooks diff --git a/website/docs/en/config/entry.mdx b/website/docs/en/config/entry.mdx index 9174e9d4c367..6668ad1e9233 100644 --- a/website/docs/en/config/entry.mdx +++ b/website/docs/en/config/entry.mdx @@ -207,7 +207,7 @@ The format of the chunk generated by this entry as a library, for detailed confi ## Dynamic entry -If a function is passed then it will be invoked on every [make](/api/plugin-api#make) event. +If a function is passed then it will be invoked on every [make](/api/plugin-api/compiler-hooks#make) event. > Note that the `make` event triggers when webpack starts and for every invalidation when [watching for file changes](/config/watch). diff --git a/website/docs/en/config/resolve-loader.mdx b/website/docs/en/config/resolve-loader.mdx index 05fd03270e49..cdcfb44150ba 100644 --- a/website/docs/en/config/resolve-loader.mdx +++ b/website/docs/en/config/resolve-loader.mdx @@ -40,5 +40,5 @@ require('!!amazing-loader!./amazing-file.js'); ``` ::: info Inline Loaders -The loader mentioned above uses the syntax of inline loaders. For details, please refer to [here](/api/loader-api#inline-loaders). +The loader mentioned above uses the syntax of inline loaders. For details, please refer to [here](/api/loader-api/inline). ::: diff --git a/website/docs/en/guide/features/loader.mdx b/website/docs/en/guide/features/loader.mdx index c3d3b892fe22..ffd700b4a4f1 100644 --- a/website/docs/en/guide/features/loader.mdx +++ b/website/docs/en/guide/features/loader.mdx @@ -133,7 +133,7 @@ module.exports = { }; ``` -For details, you can refer to [loader-api](/api/loader-api) +For details, you can refer to [loader-api](/api/loader-api/index) ### Using Built-in Loader diff --git a/website/docs/zh/api/_meta.json b/website/docs/zh/api/_meta.json index 020807b4e6f2..6d734059addc 100644 --- a/website/docs/zh/api/_meta.json +++ b/website/docs/zh/api/_meta.json @@ -4,7 +4,11 @@ "modules", "node-api", "hmr", - "loader-api", + { + "type": "dir", + "name": "loader-api", + "label": "Loader API" + }, { "type": "dir", "name": "plugin-api", diff --git a/website/docs/zh/api/index.mdx b/website/docs/zh/api/index.mdx index 31a5f957ab35..9ccb68c1f31a 100644 --- a/website/docs/zh/api/index.mdx +++ b/website/docs/zh/api/index.mdx @@ -30,7 +30,7 @@ Hot Module Replacement(HMR)通过在运行时更新浏览器中的模块而 Loader 用于模块源代码的转换。它们被编写为函数,接收源代码作为参数,并返回转换后的代码。 -[了解更多关于 Loader 的信息!](/api/loader-api) +[了解更多关于 Loader 的信息!](/api/loader-api/index) ## 插件 diff --git a/website/docs/zh/api/loader-api.mdx b/website/docs/zh/api/loader-api.mdx index 5384646d59f0..5672ed841f38 100644 --- a/website/docs/zh/api/loader-api.mdx +++ b/website/docs/zh/api/loader-api.mdx @@ -10,325 +10,6 @@ Rspack Loader 在设计时就是为了复用 Webpack Loader,我们已兼容了 你可以查看 [这个](https://github.com/orgs/web-infra-dev/projects/10) 页面来了解目前 Webpack Loader API 的支持情况。 ::: -## 同步 Loader - -`return` 或 `this.callback` 都可以用来同步返回转换后的内容: - -```js title="sync-loader.js" -module.exports = function (content, map, meta) { - return someSyncOperation(content); -}; -``` - -`this.callback` 方法更灵活,因为它允许传递多个参数,而不是只有 `content`。 - -```js title="sync-loader-with-multiple-results.js" -module.exports = function (content, map, meta) { - this.callback(null, someSyncOperation(content), map, meta); - return; // 调用 callback()时总是返回未定义的结果 -}; -``` - -::: info -出于技术和性能方面的考虑,Rspack 内部会将所有 Loader 转换为异步 Loader。 -::: - -## 异步 Loader - -对于异步 Loader,`this.async` 被用来获取回调函数: - -```js title="async-loader.js" -module.exports = function (content, map, meta) { - var callback = this.async(); - someAsyncOperation(content, function (err, result) { - if (err) return callback(err); - callback(null, result, map, meta); - }); -}; -``` - -```js title="async-loader-with-multiple-results.js" -module.exports = function (content, map, meta) { - var callback = this.async(); - someAsyncOperation(content, function (err, result, sourceMaps, meta) { - if (err) return callback(err); - callback(null, result, sourceMaps, meta); - }); -}; -``` - -## 内联 loader(Inline loaders) - -可以在 `import` 语句中指定 Loader,或者任何同等的 "导入"方法。用 `!` 将 Loader 从资源中分离出来。每个部分都是相对于当前目录来解析的。 - -```js -import Styles from 'style-loader!css-loader?modules!./styles.css'; -``` - -通过在 inline import 语句中加前缀,可以覆盖配置中的任何 Loader、preLoaders 和 postLoaders: - -前缀为 `!` 时将禁用所有配置的 Normal Loader - -```js -import Styles from '!style-loader!css-loader?modules!./styles.css'; -``` - -前缀为 `!!` 时将禁用所有配置的 Loader(preLoaders、loaders、postLoaders)。 - -```js -import Styles from '!!style-loader!css-loader?modules!./styles.css'; -``` - -前缀为 `-!` 时将禁用所有配置的 preLoaders 和 loaders,但不包括 postLoaders - -```js -import Styles from '-!style-loader!css-loader?modules!./styles.css'; -``` - -选项可以用查询参数来传递,例如`?key=value&foo=bar`,或者是 JSON 对象,例如`?{"key": "value", "foo": "bar"}`。 - -## Pitching loader - -每个 Loader 都有两个阶段: `normal` 和 `pitching`。 -在某些情况下,Loader 只关心一个请求背后的**metadata**,并可以忽略前一个 Loader 的返回结果。 -在 Loader 实际执行之前(从右到左),Loader 上的 `pitch` 方法从**左到右**调用。 - -对于以下使用的配置: - -```js title="rspack.config.js" -module.exports = { - //... - module: { - rules: [ - { - //... - use: ['a-loader', 'b-loader', 'c-loader'] 、 - }, - ], - }, -}; -``` - -会得到这些步骤: - -``` -|-a-loader `pitch - |- b-loader `pitch `. - |-c-loader `pitch` - |- 所请求的模块被作为依赖收集起来 - |- c-loader正常执行 - |-b-loader正常执行 -|- a-loader 正常执行 -``` - -通常情况下,如果 Loader 足够简单以至于只导出了 normal 阶段的钩子: - -```js -module.exports = function (source) {}; -``` - -那么其 pitching 阶段将被跳过。 - -那么,"pitching" 阶段对于 Loader 来说有哪些优势呢? - -首先,传递给 `pitch` 方法的数据在执行阶段也暴露在 `this.data` 下,可以用来捕获和共享 loader 生命周期中早期的信息。 - -```js -module.exports = function (content) { - return someSyncOperation(content, this.data.value); -}; - -module.exports.pitch = function (remainRequest, precedingRequest, data) { - data.value = 42; -}; -``` - -第二,如果一个 Loader 在 `pitch` 方法中提供了一个结果,整个 Loader 链路就会翻转过来,跳过其余的 normal 阶段的 Loader 。 -在我们上面的例子中,如果 b-loaders 的 `pitch` 方法返回了一些内容: - -```js -module.exports = function (content) { - return someSyncOperation(content); -}; - -module.exports.pitch = function (remainingRequest, precedingRequest, data) { - if (someCondition()) { - return ( - 'module.exports = require(' + - JSON.stringify('-!' + remainingRequest) + - ');' - ); - } -}; -``` - -上面的步骤将被缩短为: - -``` -|- a-loader `pitch` - |- b-loader `pitch`返回一个模块 -|- a-loader 正常执行 -``` - -举一个现实世界的例子,`style-loader`利用第二个优点来做请求的调度。 -请访问 [style-loader](https://github.com/webpack-contrib/style-loader/blob/eb06baeb3ac4e3107732a21170b0a7f358c5423f/src/index.js#L39) 了解详情。 - ## Inline match resource -webpack v4 中引入了一种新的内联请求语法。 在一个请求前缀 `!=!` 将为这个请求设置匹配资源。 -当`matchResource`被设置时,它将被用来与 `module.rules` 而不是原始 resource 进行匹配。当如果有更多的 Loader 应该应用到 resource 上,或者需要改变模块的类型,这可能很有用。 - -例子: - -```js title="file.js" -/*STYLE: body { background: red; } */ -console.log('yep'); -``` - -Loader 可以将该文件转化为以下文件,并使用 matchResource 来应用用户指定的 CSS 处理规则: - -```js title="file.js (transformed by loader)" -import './file.js.css!=! extract-style-loader/getStyles!./file.js'; -console.log('yep'); -``` - -这会将 `extract-style-loader/getStyles!./file.js` 作为一个依赖添加到编译流程中,并将结果作为 `file.js.css`。 -当 `module.rules` 有一个匹配 `/\.css$/` 的规则时,将会被这个 resource 命中。 - -Loader 可以是这样的: - -```js title="extract-style-loader/index.js" -const getStylesLoader = require.resolve('./getStyles'); - -module.exports = function (source) { - if (STYLES_REGEXP.test(source)) { - source = source.replace(STYLES_REGEXP, ''); - return `import ${JSON.stringify( - this.utils.contextify( - this.context || this.rootContext, - `${this.resource}.css!=!${getStylesLoader}!${this.remainingRequest}`, - ), - )};${source}`; - } - return source; -}; -``` - -```js title="extract-style-loader/getStyles.js" -module.exports = function (source) { - const match = source.match(STYLES_REGEXP); - return match[0]; -}; -``` - -## 'Raw' Loader - -默认情况下,资源文件会被转化为 UTF-8 字符串,然后传给 loader。通过设置 `raw` 为 `true`,loader 可以接收原始的 `Buffer`。每一个 loader 都可以用 `String` 或者 `Buffer` 的形式传递它的处理结果。Compiler 将会把它们在 loader 之间相互转换。 - -```js -module.exports = function (content) { - assert(content instanceof Buffer); - // ... -}; -module.exports.raw = true; -``` - -## `this.addContextDependency(directory: string)` - -添加目录作为 loader 结果的依赖,使目录中文件的任何变化可以被监听到。 - -## `this.addDependency(file: string)` - -添加一个文件作为 loader 结果的依赖,使它们的任何变化可以被监听到。例如,`sass-loader`、`less-loader` 就使用了这个技巧,当导入的样式文件发生变化时就会重新编译。 - -## `this.dependency(file: string)` - -`this.addDependency(file: string)` 的别名。 - -## `this.addMissingDependency(file: string)` - -添加一个不存在的文件作为 loader 结果的依赖项,以使它们可监听。 - -## `this.clearDependencies()` - -移除 loader 结果的所有依赖。 - -## `this.async()` - -告诉 Rspack 这个 loader 将会异步被调用。返回 `this.callback`。 - -## `this.callback(err: Error | null, content: string | Buffer, sourceMap?: SourceMap, meta?: any)` - -将 Loader 处理后的结果告诉 Rspack。 - -第一个参数必须是 `Error` 或者 `null`,会标记当前模块为编译失败,第二个参数是一个 `string` 或者 `Buffer`,表示模块被该 Loader 处理后的文件内容,第三个参数是一个可以该 Loader 处理后的 source map,第四个参数会被 Rspack 忽略,可以是任何东西(例如一些元数据)。 - -## `this.cacheable(flag: boolean = true)` - -默认情况下,loader 的处理结果会被标记为可缓存。调用这个方法然后传入 `false`,可以关闭 loader 处理结果的缓存能力。 - -## `this.context` - -当前模块所在的目录。 - -## `this.rootContext` - -config 中配置的项目所在的目录 - -## `this.emitError(err: Error)` - -发出一个错误,与在 loader 中 `throw` 和 `this.callback(err)` 不同,它不会标记当前模块为编译失败,只会在 Rspack 的 Compilation 上添加一个错误,并在此次编译结束后显示在命令行中。 - -## `this.emitWarning(warning: Error)` - -发出一个警告。 - -## `this.emitFile(name: string, content: Buffer | string, sourceMap: SourceMap)` - -产生一个文件。 - -## `this.getOptions(schema)` - -提取给定的 loader 选项,接受一个可选的 JSON schema 作为参数。 - -## `this.getResolve(options: ResolveOptions): resolve` - -创建一个类似于 `this.resolve` 的解析函数。 - -## `this.resolve(context: string, request: string, callback: (err: Error | null, result: string) => void)` - -解析一个 request。 - -- `context` 必须是一个目录的绝对路径。此目录用作解析的起始位置。 -- `request` 是要被解析的 request。 -- `callback` 是一个处理解析路径的回调函数。 - -## `this.mode` - -当 webpack 运行时读取 [mode](/config/mode) 的值 - -可能的值为:`'production'`、`'development'`、`'none'` - -## `this.resource` - -当前模块的路径字符串。比如 `'/abc/resource.js?query#hash'`。 - -## `this.resourcePath` - -当前模块的路径字符串,不包括 query 和 fragment 参数。比如 `'/abc/resource.js?query#hash'` 中的 `'/abc/resource.js'`。 - -## `this.resourceQuery` - -当前模块的路径字符串的 query 参数。比如 `'/abc/resource.js?query#hash'` 中的 `'?query'`。 - -## `this.resourceFragment` - -当前模块的路径字符串的 fragment 参数。比如 `'/abc/resource.js?query#hash'` 中的 `'#hash'`。 - -## `this.sourceMap` - -是否应该生成一个 source map。 - -## `this.getLogger(name?: string)` - -获取此次编译过程的 logger,可通过该 logger 记录消息。 +webpack v4 中引入了一种新的内联请求语法。 diff --git a/website/docs/zh/api/loader-api/_meta.json b/website/docs/zh/api/loader-api/_meta.json new file mode 100644 index 000000000000..7a710dbf561a --- /dev/null +++ b/website/docs/zh/api/loader-api/_meta.json @@ -0,0 +1,8 @@ +[ + "index", + "examples", + "context", + "rspack-specific-properties", + "inline", + "inline-match-resource" +] diff --git a/website/docs/zh/api/loader-api/context.mdx b/website/docs/zh/api/loader-api/context.mdx new file mode 100644 index 000000000000..951f47823c91 --- /dev/null +++ b/website/docs/zh/api/loader-api/context.mdx @@ -0,0 +1,176 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Loader 上下文 + +Loader 上下文表示 loader 内部可用的属性,这些属性在 loader 中通过 `this` 属性进行访问。 + +## this.addContextDependency() + +```ts +function addContextDependency(directory: string): void; +``` + +添加目录作为 loader 结果的依赖,使目录中文件的任何变化可以被监听到。 + +## this.addDependency() + +```ts +function addDependency(file: string): void; +``` + +添加一个文件作为 loader 结果的依赖,使它们的任何变化可以被监听到。例如,`sass-loader`、`less-loader` 就使用了这个技巧,当导入的样式文件发生变化时就会重新编译。 + +## this.dependency() + +```ts +function dependency(file: string): void; +``` + +`this.addDependency()` 的别名。 + +## this.addMissingDependency() + +```ts +function addMissingDependency(file: string): void; +``` + +添加一个不存在的文件作为 loader 结果的依赖项,以使它们可监听。 + +## this.async() + +告诉 Rspack 这个 loader 将会异步被调用。返回 `this.callback`。 + +## this.cacheable() + +```ts +function cacheable(flag: boolean = true): void; +``` + +默认情况下,loader 的处理结果会被标记为可缓存。调用这个方法然后传入 `false`,可以关闭 loader 处理结果的缓存能力。 + +## this.clearDependencies() + +```ts +function clearDependencies(): void; +``` + +移除 loader 结果的所有依赖。 + +## this.callback() + +```ts +function callback( + err: Error | null, + content: string | Buffer, + sourceMap?: SourceMap, + meta?: any, +): void; +``` + +将 Loader 处理后的结果告诉 Rspack。 + +第一个参数必须是 `Error` 或者 `null`,会标记当前模块为编译失败,第二个参数是一个 `string` 或者 `Buffer`,表示模块被该 Loader 处理后的文件内容,第三个参数是一个可以该 Loader 处理后的 source map,第四个参数会被 Rspack 忽略,可以是任何东西(例如一些元数据)。 + +## this.context + +当前模块所在的目录。 + +## this.data + +用于在 pitch 和 normal 阶段之间共享数据。 + +## this.emitError() + +```ts +function emitError(err: Error): void; +``` + +发出一个错误,与在 loader 中 `throw` 和 `this.callback(err)` 不同,它不会标记当前模块为编译失败,只会在 Rspack 的 Compilation 上添加一个错误,并在此次编译结束后显示在命令行中。 + +## this.emitWarning() + +```ts +function emitWarning(warning: Error): void; +``` + +发出一个警告。 + +## this.emitFile() + +```ts +function emitFile( + name: string, + content: Buffer | string, + sourceMap: SourceMap, +): void; +``` + +产生一个文件。 + +## this.getOptions(schema) + +提取给定的 loader 选项,接受一个可选的 JSON schema 作为参数。 + +## this.getResolve() + +```ts +function getResolve(options: ResolveOptions): resolve; +``` + +创建一个类似于 `this.resolve` 的解析函数。 + +## this.resolve() + +```ts +function resolve( + context: string, + request: string, + callback: (err: Error | null, result: string) => void, +): void; +``` + +解析一个 request。 + +- `context` 必须是一个目录的绝对路径。此目录用作解析的起始位置。 +- `request` 是要被解析的 request。 +- `callback` 是一个处理解析路径的回调函数。 + +## this.mode + +当 Rspack 运行时读取 [mode](/config/mode) 的值 + +可能的值为:`'production'`、`'development'`、`'none'` + +## this.resource + +当前模块的路径字符串。比如 `'/abc/resource.js?query#hash'`。 + +## this.resourcePath + +当前模块的路径字符串,不包括 query 和 fragment 参数。比如 `'/abc/resource.js?query#hash'` 中的 `'/abc/resource.js'`。 + +## this.resourceQuery + +当前模块的路径字符串的 query 参数。比如 `'/abc/resource.js?query#hash'` 中的 `'?query'`。 + +## this.resourceFragment + +当前模块的路径字符串的 fragment 参数。比如 `'/abc/resource.js?query#hash'` 中的 `'#hash'`。 + +## this.rootContext + +config 中配置的项目所在的目录 + +## this.sourceMap + +是否应该生成一个 source map。 + +## this.getLogger() + +```ts +function getLogger(name?: string): void; +``` + +获取此次编译过程的 logger,可通过该 logger 记录消息。 diff --git a/website/docs/zh/api/loader-api/examples.mdx b/website/docs/zh/api/loader-api/examples.mdx new file mode 100644 index 000000000000..adb8668c1a25 --- /dev/null +++ b/website/docs/zh/api/loader-api/examples.mdx @@ -0,0 +1,150 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# 示例 + +以下部分提供了不同类型 loader 的一些基本示例。请注意,`map` 和 `meta` 可选参数,请参见下面的 [`this.callback`](#thiscallbackerr-error--null-content-string--buffer-sourcemap-sourcemap-meta-any)。 + +## 同步 Loader + +`return` 或 `this.callback` 都可以用来同步返回转换后的内容: + +```js title="sync-loader.js" +module.exports = function (content, map, meta) { + return someSyncOperation(content); +}; +``` + +`this.callback` 方法更灵活,因为它允许传递多个参数,而不是只有 `content`。 + +```js title="sync-loader-with-multiple-results.js" +module.exports = function (content, map, meta) { + this.callback(null, someSyncOperation(content), map, meta); + return; // 调用 callback() 时总是返回未定义的结果 +}; +``` + +::: info +出于技术和性能方面的考虑,Rspack 内部会将所有 loader 转换为异步 loader。 +::: + +## 异步 Loader + +对于异步 Loader,`this.async` 被用于获取 `callback` 函数: + +```js title="async-loader.js" +module.exports = function (content, map, meta) { + var callback = this.async(); + someAsyncOperation(content, function (err, result) { + if (err) return callback(err); + callback(null, result, map, meta); + }); +}; +``` + +```js title="async-loader-with-multiple-results.js" +module.exports = function (content, map, meta) { + var callback = this.async(); + someAsyncOperation(content, function (err, result, sourceMaps, meta) { + if (err) return callback(err); + callback(null, result, sourceMaps, meta); + }); +}; +``` + +## 'Raw' Loader + +默认情况下,资源文件会被转化为 UTF-8 字符串,然后传给 loader。通过设置 `raw` 为 `true`,loader 可以接收原始的 `Buffer`。每一个 loader 都可以用 `String` 或者 `Buffer` 的形式传递它的处理结果。Compiler 将会把它们在 loader 之间相互转换。 + +```js +module.exports = function (content) { + assert(content instanceof Buffer); + // ... +}; +module.exports.raw = true; +``` + +## Pitching loader + +Loader **总是**从右向左被调用。有些情况下,loader 只关心请求背后的**元数据**,可以忽略之前 loader 的结果。在 loader 真正执行之前(从右向左),loader 上的 `pitch` 方法会从**左向右**被调用。 + +对于以下使用的配置: + +```js title="rspack.config.js" +module.exports = { + //... + module: { + rules: [ + { + //... + use: ['a-loader', 'b-loader', 'c-loader'] 、 + }, + ], + }, +}; +``` + +会得到这些步骤: + +``` +|-a-loader `pitch + |- b-loader `pitch `. + |-c-loader `pitch` + |- 所请求的模块被作为依赖收集起来 + |- c-loader正常执行 + |-b-loader正常执行 +|- a-loader 正常执行 +``` + +通常情况下,如果 loader 足够简单以至于只导出了 normal 阶段的钩子: + +```js +module.exports = function (source) {}; +``` + +那么其 pitching 阶段将被跳过。 + +那么,"pitching" 阶段对于 loader 来说有哪些优势呢? + +首先,传递给 `pitch` 方法的数据在执行阶段也暴露在 `this.data` 下,可以用来捕获和共享 loader 生命周期中早期的信息。 + +```js +module.exports = function (content) { + return someSyncOperation(content, this.data.value); +}; + +module.exports.pitch = function (remainRequest, precedingRequest, data) { + data.value = 42; +}; +``` + +第二,如果一个 loader 在 `pitch` 方法中提供了一个结果,整个 loader 链路就会翻转过来,跳过其余的 normal 阶段的 loader 。 +在我们上面的例子中,如果 b-loaders 的 `pitch` 方法返回了一些内容: + +```js +module.exports = function (content) { + return someSyncOperation(content); +}; + +module.exports.pitch = function (remainingRequest, precedingRequest, data) { + if (someCondition()) { + return ( + 'module.exports = require(' + + JSON.stringify('-!' + remainingRequest) + + ');' + ); + } +}; +``` + +上面的步骤将被缩短为: + +``` +|- a-loader `pitch` + |- b-loader `pitch`返回一个模块 +|- a-loader 正常执行 +``` + +一个实际应用的例子是 `style-loader`,它利用了第二个优势来处理请求的调度。 +请访问 [style-loader](https://github.com/webpack-contrib/style-loader/blob/eb06baeb3ac4e3107732a21170b0a7f358c5423f/src/index.js#L39) 了解详情。 diff --git a/website/docs/zh/api/loader-api/index.mdx b/website/docs/zh/api/loader-api/index.mdx new file mode 100644 index 000000000000..9da84de6b3f4 --- /dev/null +++ b/website/docs/zh/api/loader-api/index.mdx @@ -0,0 +1,5 @@ +# 兼容情况 + +Rspack 致力于兼容 webpack 生态中的 loader。我们确保 Rspack 尽可能地去兼容 webpack 的 loader API,使更多现有的 webpack loader 能够在 Rspack 中直接使用。 + +我们已兼容了大部分 webpack 的 loader API,你可以访问[这个页面](https://github.com/orgs/web-infra-dev/projects/10)来了解目前 webpack Loader API 的兼容情况。 diff --git a/website/docs/zh/api/loader-api/inline-match-resource.mdx b/website/docs/zh/api/loader-api/inline-match-resource.mdx new file mode 100644 index 000000000000..631544b4f697 --- /dev/null +++ b/website/docs/zh/api/loader-api/inline-match-resource.mdx @@ -0,0 +1,51 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# 内联 matchResource + +在一个请求前缀 `!=!` 将为这个请求设置匹配资源。 +当 `matchResource` 被设置时,它将被用来与 `module.rules` 而不是原始资源进行匹配。当如果有更多的 loader 应该应用到资源上,或者需要改变模块的类型,这可能很有用。 + +例子: + +```js title="file.js" +/*STYLE: body { background: red; } */ +console.log('yep'); +``` + +Loader 可以将该文件转化为以下文件,并使用 `matchResource` 来应用用户指定的 CSS 处理规则: + +```js title="file.js (transformed by loader)" +import './file.js.css!=! extract-style-loader/getStyles!./file.js'; +console.log('yep'); +``` + +这会将 `extract-style-loader/getStyles!./file.js` 作为一个依赖添加到编译流程中,并将结果作为 `file.js.css`。 +当 `module.rules` 有一个匹配 `/\.css$/` 的规则时,将会被这个资源命中。 + +Loader 可以是这样的: + +```js title="extract-style-loader/index.js" +const getStylesLoader = require.resolve('./getStyles'); + +module.exports = function (source) { + if (STYLES_REGEXP.test(source)) { + source = source.replace(STYLES_REGEXP, ''); + return `import ${JSON.stringify( + this.utils.contextify( + this.context || this.rootContext, + `${this.resource}.css!=!${getStylesLoader}!${this.remainingRequest}`, + ), + )};${source}`; + } + return source; +}; +``` + +```js title="extract-style-loader/getStyles.js" +module.exports = function (source) { + const match = source.match(STYLES_REGEXP); + return match[0]; +}; +``` diff --git a/website/docs/zh/api/loader-api/inline.mdx b/website/docs/zh/api/loader-api/inline.mdx new file mode 100644 index 000000000000..97aedc63e23b --- /dev/null +++ b/website/docs/zh/api/loader-api/inline.mdx @@ -0,0 +1,33 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# 内联 loader + +可以在 `import` 语句中指定 loader,或者任何同等的 "导入"方法。用 `!` 将 loader 从资源中分离出来。每个部分都是相对于当前目录来解析的。 + +```js +import Styles from 'style-loader!css-loader?modules!./styles.css'; +``` + +通过在 inline import 语句中加前缀,可以覆盖配置中的任何 loaders、preLoaders 和 postLoaders: + +前缀为 `!` 时将禁用所有配置的 Normal Loader + +```js +import Styles from '!style-loader!css-loader?modules!./styles.css'; +``` + +前缀为 `!!` 时将禁用所有配置的 loader(preLoaders、loaders、postLoaders)。 + +```js +import Styles from '!!style-loader!css-loader?modules!./styles.css'; +``` + +前缀为 `-!` 时将禁用所有配置的 preLoaders 和 loaders,但不包括 postLoaders + +```js +import Styles from '-!style-loader!css-loader?modules!./styles.css'; +``` + +选项可以用查询参数来传递,例如 `?key=value&foo=bar`,或者是 JSON 对象,例如 `?{"key": "value", "foo": "bar"}`。 diff --git a/website/docs/zh/api/loader-api/rspack-specific-properties.mdx b/website/docs/zh/api/loader-api/rspack-specific-properties.mdx new file mode 100644 index 000000000000..9096642ed3d2 --- /dev/null +++ b/website/docs/zh/api/loader-api/rspack-specific-properties.mdx @@ -0,0 +1,21 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Rspack 特有属性 + +Loader API 提供了所有模块相关的信息。然而,在极少数情况下,你可能需要访问编译器API本身。 + +:::warning 警告 +请注意,使用这些特定于 Rspack 的属性会对你的 loader 的兼容性产生负面影响。 + +因此,你应该将它们作为最后的手段使用。使用它们会降低你的 loader 的可移植性。 +::: + +## this.\_compilation + +访问Rspack当前的Compilation对象。 + +## this.\_compiler + +访问Rspack当前的Compiler对象。 diff --git a/website/docs/zh/api/plugin-api/index.mdx b/website/docs/zh/api/plugin-api/index.mdx index 6ee37ee7f86f..3a1b23724786 100644 --- a/website/docs/zh/api/plugin-api/index.mdx +++ b/website/docs/zh/api/plugin-api/index.mdx @@ -2,4 +2,4 @@ Rspack 致力于兼容 webpack 生态中的插件。我们确保 Rspack 尽可能地去兼容 webpack 的插件 API,使更多现有的 webpack 插件能够在 Rspack 中直接使用。 -你可以访问[这个页面](https://github.com/orgs/web-infra-dev/projects/9)来了解目前 webpack 插件 API 的兼容情况。 +我们已兼容了大部分 webpack 的插件 API,你可以访问[这个页面](https://github.com/orgs/web-infra-dev/projects/9)来了解目前 webpack 插件 API 的兼容情况。 diff --git a/website/docs/zh/blog/announcing-0-2.mdx b/website/docs/zh/blog/announcing-0-2.mdx index 76833c22f4e7..80016a77f2b7 100644 --- a/website/docs/zh/blog/announcing-0-2.mdx +++ b/website/docs/zh/blog/announcing-0-2.mdx @@ -14,7 +14,7 @@ date: 2023-06-02 13:11:00 ### Loader -0.2 版本完成了 loader 大部分 API 的兼容,其中包括了 inline match resource,pitching loader,inline loader 等。更多的 API 进一步提升了对 Webpack loader 的兼容性,详情可以参考下方 webpack 兼容性更新。更多信息请参考 [Loader API](/api/loader-api.html) +0.2 版本完成了 loader 大部分 API 的兼容,其中包括了 inline match resource,pitching loader,inline loader 等。更多的 API 进一步提升了对 Webpack loader 的兼容性,详情可以参考下方 webpack 兼容性更新。更多信息请参考 [Loader API](/api/loader-api/index) ### Plugin Hooks diff --git a/website/docs/zh/config/entry.mdx b/website/docs/zh/config/entry.mdx index cf94f56a08bf..f5e2dff93a73 100644 --- a/website/docs/zh/config/entry.mdx +++ b/website/docs/zh/config/entry.mdx @@ -207,7 +207,7 @@ module.exports = { ## 动态入口 -如果传入一个函数,那么它将会在每次 [make](/api/plugin-api#make) 事件中被调用。 +如果传入一个函数,那么它将会在每次 [make](/api/plugin-api/compiler-hooks#make) 事件中被调用。 > 要注意的是,`make` 事件在 webpack 启动和每当[监听文件变化](/config/watch)时都会触发。 diff --git a/website/docs/zh/config/resolve-loader.mdx b/website/docs/zh/config/resolve-loader.mdx index 3edac237c774..eb8a8d92112d 100644 --- a/website/docs/zh/config/resolve-loader.mdx +++ b/website/docs/zh/config/resolve-loader.mdx @@ -40,5 +40,5 @@ require('!!amazing-loader!./amazing-file.js'); ``` ::: info 内联 loader -上述的 loader 使用的是内联 loader 的语法,详情请参考[这里](/api/loader-api#%E5%86%85%E8%81%94-loaderinline-loaders) +上述的 loader 使用的是内联 loader 的语法,详情请参考[这里](/api/loader-api/index) ::: diff --git a/website/docs/zh/guide/features/loader.mdx b/website/docs/zh/guide/features/loader.mdx index 077c1b329a35..79c496619b3f 100644 --- a/website/docs/zh/guide/features/loader.mdx +++ b/website/docs/zh/guide/features/loader.mdx @@ -135,7 +135,7 @@ module.exports = { }; ``` -更多关于 Loader API 的信息,请参考 [loader-api](/api/loader-api) +更多关于 Loader API 的信息,请参考 [loader-api](/api/loader-api/index) ### 使用内置 Loader diff --git a/website/theme/components/HomeFooter/index.tsx b/website/theme/components/HomeFooter/index.tsx index 54a3df5e04f6..3e7f6ed80715 100644 --- a/website/theme/components/HomeFooter/index.tsx +++ b/website/theme/components/HomeFooter/index.tsx @@ -42,7 +42,7 @@ function useFooterData() { }, { title: 'Loader API', - link: getLink('/api/loader-api'), + link: getLink('/api/loader-api/index'), }, ], }, From 452363389c4b38f662fe6f345d272d84668c029f Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 6 May 2024 19:36:05 +0800 Subject: [PATCH 008/107] docs: add blogs overview page (#6446) * docs: add blogs overview page * docs: fix --- website/docs/en/_meta.json | 2 +- website/docs/en/blog/_meta.json | 1 + website/docs/en/blog/index.mdx | 79 +++++++++++++++++++++++++++++++++ website/docs/zh/_meta.json | 2 +- website/docs/zh/blog/_meta.json | 1 + website/docs/zh/blog/index.mdx | 79 +++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 website/docs/en/blog/index.mdx create mode 100644 website/docs/zh/blog/index.mdx diff --git a/website/docs/en/_meta.json b/website/docs/en/_meta.json index bdf9b798aaa9..935be1f70f43 100644 --- a/website/docs/en/_meta.json +++ b/website/docs/en/_meta.json @@ -21,7 +21,7 @@ }, { "text": "Blog", - "link": "/blog/announcing-0-6", + "link": "/blog/index", "activeMatch": "/blog" }, { diff --git a/website/docs/en/blog/_meta.json b/website/docs/en/blog/_meta.json index 3ef233484455..d8c4340d4d9b 100644 --- a/website/docs/en/blog/_meta.json +++ b/website/docs/en/blog/_meta.json @@ -1,4 +1,5 @@ [ + "index", "announcing-0-6", "announcing-0-5", "module-federation-added-to-rspack", diff --git a/website/docs/en/blog/index.mdx b/website/docs/en/blog/index.mdx new file mode 100644 index 000000000000..468d504d9962 --- /dev/null +++ b/website/docs/en/blog/index.mdx @@ -0,0 +1,79 @@ +--- +title: Overview +--- + +# Rspack Blogs + +Check here for the latest articles and release announcements about Rspack. + +## [Deep Dive into Rspack Tree Shaking](https://github.com/orgs/web-infra-dev/discussions/17) + +> April 17, 2024 + +This article primarily focuses on understanding the concept of Rspack & Webpack tree shaking. + +## [Announcing Rspack v0.6](/blog/announcing-0-6) + +> April 10, 2024 + +Rspack v0.6 is out, with built-in support for mini-css-extract-plugin and new tree-shaking enabled by default. + +## [Webpack Chunk Graph Algorithm](https://github.com/orgs/web-infra-dev/discussions/15) + +> January 12, 2024 + +This article introduces the chunk strategy of webpack. Through this article, you can understand when a chunk will be generated in the code and how to reduce the chunk size, etc. + +## [Announcing Rspack v0.5](/blog/announcing-0-5) + +> January 09, 2024 + +Rspack v0.5 is out, supporting Module Federation and removing the default SWC transformation. + +## [Module Federation added to Rspack](/blog/module-federation-added-to-rspack) + +> January 09, 2024 + +The latest Rspack 0.5.0 introduces the highly anticipated Module Federation, which is detailed in this article. + +## [Webpack CSS Order Issue](https://github.com/orgs/web-infra-dev/discussions/12) + +> November 29, 2023 + +This article shows how the CSS order problem occurs in webpack and how to solve it. + +## [Announcing Rspack v0.4](/blog/announcing-0-4) + +> November 02, 2023 + +Rspack v0.5 is out, removing support for some builtin features. + +## [Deep Dive into Top-level await](https://github.com/orgs/web-infra-dev/discussions/9) + +> October 26, 2023 + +In this article, we will take a closer look at aspects such as the specification, toolchain support, webpack runtime, and profiling of top level await. + +## [Design Trade-offs in Bundler](https://github.com/orgs/web-infra-dev/discussions/1) + +> August 30, 2023 + +This article explains why we decided to develop Rspack and what trade-offs we made during the design process. + +## [Announcing Rspack v0.3](/blog/announcing-0-3) + +> August 24, 2023 + +Rspack v0.3 is out, adding support for web workers and the builtin:swc-loader. + +## [Announcing Rspack v0.2](/blog/announcing-0-2) + +> June 02, 2023 + +Rspack v0.2 is out, introducing many new features, such as support for realContentHash, DataURI, and the ESM format, and more. + +## [Announcing Rspack v0.1](/blog/announcing-0-1) + +> March 06, 2023 + +Rspack has officially been released! diff --git a/website/docs/zh/_meta.json b/website/docs/zh/_meta.json index e26d9e81331a..de15496964ab 100644 --- a/website/docs/zh/_meta.json +++ b/website/docs/zh/_meta.json @@ -21,7 +21,7 @@ }, { "text": "博客", - "link": "/blog/announcing-0-6", + "link": "/blog/index", "activeMatch": "/blog" }, { diff --git a/website/docs/zh/blog/_meta.json b/website/docs/zh/blog/_meta.json index 3ef233484455..27dbf8224d8b 100644 --- a/website/docs/zh/blog/_meta.json +++ b/website/docs/zh/blog/_meta.json @@ -1,4 +1,5 @@ [ + "index.mdx", "announcing-0-6", "announcing-0-5", "module-federation-added-to-rspack", diff --git a/website/docs/zh/blog/index.mdx b/website/docs/zh/blog/index.mdx new file mode 100644 index 000000000000..1b4f3dbf48e2 --- /dev/null +++ b/website/docs/zh/blog/index.mdx @@ -0,0 +1,79 @@ +--- +title: 总览 +--- + +# Rspack 博客 + +在此查看有关 Rspack 的最新文章和发布公告。 + +## [Deep Dive into Rspack Tree Shaking](https://github.com/orgs/web-infra-dev/discussions/17) + +> 2024 年 4 月 17 日 + +本文主要侧重于理解 Rspack 和 Webpack 中 tree shaking 的概念。 + +## [Rspack v0.6 发布公告](/blog/announcing-0-6) + +> 2024 年 4 月 10 日 + +Rspack v0.6 版本发布,内置支持 mini-css-extract-plugin,默认开启新版 tree shaking。 + +## [Webpack Chunk Graph 策略](https://github.com/orgs/web-infra-dev/discussions/16) + +> 2024 年 1 月 12 日 + +本文介绍了 webpack 的 chunk 策略,通过这篇文章,你可以理解代码中什么时候会产生 chunk,怎样减少 chunk 体积等。 + +## [Rspack v0.5 发布公告](/blog/announcing-0-5) + +> 2024 年 1 月 9 日 + +Rspack v0.5 版本发布,支持模块联邦,移除默认的 SWC 转换。 + +## [Rspack 支持 Module Federation](/blog/module-federation-added-to-rspack) + +> 2024 年 1 月 9 日 + +最新的 Rspack 0.5.0 引入了备受期待的模块联邦功能,本文对其进行了详细介绍。 + +## [Webpack CSS 顺序问题](https://github.com/orgs/web-infra-dev/discussions/13) + +> 2023 年 11 月 29 日 + +本文介绍了 webpack 中 CSS 顺序问题是怎样产生的,以及如何解决。 + +## [Rspack v0.4 发布公告](/blog/announcing-0-4) + +> 2023 年 11 月 22 日 + +Rspack v0.4 版本发布,移除对一些内置功能的支持。 + +## [深入了解 Top-level await](https://github.com/orgs/web-infra-dev/discussions/10) + +> 2023 年 10 月 26 日 + +在本文中,我们将对 top level await 的 specification、toolchain support、webpack runtime、profiling 等方面进行深入的分析。 + +## [Bundler 的设计取舍](https://github.com/orgs/web-infra-dev/discussions/4) + +> 2023 年 8 月 30 日 + +本文介绍了我们为什么要开发 Rspack,设计过程中进行了哪些取舍。 + +## [Rspack v0.3 发布公告](/blog/announcing-0-3) + +> 2023 年 8 月 24 日 + +Rspack v0.3 版本发布,新增 web workers、builtin:swc-loader 支持。 + +## [Rspack v0.2 发布公告](/blog/announcing-0-2) + +> 2023 年 6 月 2 日 + +Rspack v0.2 版本发布,新增了诸多功能,如 realContentHash、DataURI、ESM format 的支持等。 + +## [Rspack v0.1 发布公告](/blog/announcing-0-1) + +> 2023 年 3 月 6 日 + +Rspack 正式发布了! From 3a7e6e74c5b6ace939244fd7f0df69668f5f19ce Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Mon, 6 May 2024 19:58:35 +0800 Subject: [PATCH 009/107] docs: split module methods docs (#6447) docs: split module methods --- website/docs/en/api/_meta.json | 6 +- website/docs/en/api/index.mdx | 2 +- website/docs/en/api/modules.mdx | 142 --------------- website/docs/en/api/modules/_meta.json | 1 + .../docs/en/api/modules/module-methods.mdx | 167 ++++++++++++++++++ .../docs/en/api/modules/module-variables.mdx | 57 ++++++ website/docs/zh/api/_meta.json | 6 +- website/docs/zh/api/index.mdx | 2 +- website/docs/zh/api/modules.mdx | 142 --------------- website/docs/zh/api/modules/_meta.json | 1 + .../docs/zh/api/modules/module-methods.mdx | 167 ++++++++++++++++++ .../docs/zh/api/modules/module-variables.mdx | 66 +++++++ 12 files changed, 471 insertions(+), 288 deletions(-) delete mode 100644 website/docs/en/api/modules.mdx create mode 100644 website/docs/en/api/modules/_meta.json create mode 100644 website/docs/en/api/modules/module-methods.mdx create mode 100644 website/docs/en/api/modules/module-variables.mdx delete mode 100644 website/docs/zh/api/modules.mdx create mode 100644 website/docs/zh/api/modules/_meta.json create mode 100644 website/docs/zh/api/modules/module-methods.mdx create mode 100644 website/docs/zh/api/modules/module-variables.mdx diff --git a/website/docs/en/api/_meta.json b/website/docs/en/api/_meta.json index 1308531c1765..7e278ca4d112 100644 --- a/website/docs/en/api/_meta.json +++ b/website/docs/en/api/_meta.json @@ -1,7 +1,11 @@ [ "index", "cli", - "modules", + { + "type": "dir", + "name": "modules", + "label": "Modules" + }, "node-api", "hmr", { diff --git a/website/docs/en/api/index.mdx b/website/docs/en/api/index.mdx index 310d616d694c..0a01f4b798e6 100644 --- a/website/docs/en/api/index.mdx +++ b/website/docs/en/api/index.mdx @@ -12,7 +12,7 @@ The Command Line Interface (CLI) to configure and interact with your build. It i When processing modules with rspack, it is important to understand the different module syntaxes – specifically the methods and variables – that are supported. -[Learn more about the modules!](/api/modules) +[Learn more about the modules!](/api/modules/module-methods) ## Node diff --git a/website/docs/en/api/modules.mdx b/website/docs/en/api/modules.mdx deleted file mode 100644 index e293c463a2d3..000000000000 --- a/website/docs/en/api/modules.mdx +++ /dev/null @@ -1,142 +0,0 @@ -import WebpackLicense from '@components/webpack-license'; -import { ApiMeta } from '../../../components/ApiMeta'; - - - -# Modules - -While Rspack supports multiple module syntaxes, we recommend following a single syntax for consistency and to avoid odd behaviors/bugs. - -### ES6 (Recommended) - -Rspack support ES6 module syntax natively, you can use static `import`, `export` and `import()` syntax. - -#### Magic Comments - -By adding comments to the import, we can do things such as name our chunk or select different modes. - -```js -import( - /* webpackChunkName: "my-chunk-name" */ - /* webpackPrefetch: true */ - /* webpackPreload: true */ - 'module' -); -``` - -`webpackChunkName`: A name for the new chunk. - -`webpackPrefetch`: Tells the browser that the resource is probably needed for some navigation in the future (Available since 0.4.5). - -`webpackPreload`: Tells the browser that the resource might be needed during the current navigation (Available since 0.4.5). - -### CommonJS - -Rspack is also support `CommonJS` syntax natively, you can use `require` and `module.exports` syntax. - -### DataURI Module - -Rspack supports importing DataURI modules using the `import` and `require` syntax. - -**import** - -```js -import DataURI from 'data:text/javascript,export default 42'; -``` - -**require** - -```js -require('data:text/javascript,module.exports = 42'); -``` - -In addition, Base64 encoded requests are also supported: - -```js -const { - number, - fn, -} = require('data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgcmV0dXJuICJIZWxsbyB3b3JsZCI7Cn0='); -``` - -::: tip -The DataURI module can be used as a method to implement virtual modules, such as combining with a Loader to dynamically load custom modules at runtime. -::: - -### Webpack - -Aside from the module syntaxes described above, Rspack also support some webpack-specific methods. - -#### require.context - -```ts -require.context( - (directory: String), - (includeSubdirs: Boolean) /* optional, default true */, - (filter: RegExp) /* optional, default /^\.\/.*$/, any file */, - (mode: String) /* optional, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', default 'sync' */ -); -``` - -Specify a whole group of dependencies using a path to the `directory`, an option to `includeSubdirs`, a filter for more fine grained control of the modules included, and a mode to define the way how loading will work. -If mode is set to 'lazy', the underlying modules will be loaded asynchronously. - -## Module Variables - -### module.hot (webpack-specific) - -Indicates whether or not Hot Module Replacement is enabled and provides an interface to the process. See the [HMR API page](/api/hmr) for details. - -### import.meta.webpackHot (webpack-specific) - -An alias for `module.hot`, however `import.meta.webpackHot` can be used in strict ESM while module.hot can't. - -### \_\_dirname (NodeJS) - -Depending on the configuration option `node.__dirname`: - -- false: Not defined -- mock: equal to '/' -- true: node.js \_\_dirname - If used inside an expression that is parsed by the Parser, the configuration option is treated as true. - -### \_\_resourceQuery (webpack-specific) - -The resource query of the current module. If the following require call was made, then the query string would be available in file.js. - -```ts -require('file.js?test'); -``` - -```ts title="file.js" -__resourceQuery === '?test'; -``` - -### \_\_webpack_modules\_\_ (webpack-specific) - -Access to the internal object of all modules. - -### \_\_webpack_hash\_\_ (webpack-specific) - -It provides access to the hash of the compilation. - -### \_\_webpack_public_path\_\_ (webpack-specific) - -Equals the configuration option's [`output.publicPath`](/config/output#outputpublicpath). - -### \_\_webpack_chunkname\_\_ (webpack-specific) - - - -Access to name of current chunk. - -### \_\_webpack_runtime_id\_\_ (webpack-specific) - - - -Access the runtime id of current entry. diff --git a/website/docs/en/api/modules/_meta.json b/website/docs/en/api/modules/_meta.json new file mode 100644 index 000000000000..e2ca1dde6e5d --- /dev/null +++ b/website/docs/en/api/modules/_meta.json @@ -0,0 +1 @@ +["module-methods", "module-variables"] diff --git a/website/docs/en/api/modules/module-methods.mdx b/website/docs/en/api/modules/module-methods.mdx new file mode 100644 index 000000000000..61c39a110c2f --- /dev/null +++ b/website/docs/en/api/modules/module-methods.mdx @@ -0,0 +1,167 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# Module Methods + +This section covers all methods available in code compiled with Rspack. When using Rspack to bundle your application, you can pick from a variety of module syntax styles including ES6, CommonJS. + +While Rspack supports multiple module syntaxes, we recommend following a single syntax for consistency and to avoid odd behaviors/bugs. + +## ES6 (Recommended) + +Rspack support ES6 module syntax natively, you can use static `import`, `export` and `import()` syntax. + +### import + +Statically `import` the `export`s of another module. + +```js +import MyModule from './my-module.js'; +import { NamedExport } from './other-module.js'; +``` + +You can also `import` Data URI: + +```js +import 'data:text/javascript;charset=utf-8;base64,Y29uc29sZS5sb2coJ2lubGluZSAxJyk7'; +import { + number, + fn, +} from 'data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgY29uc3QgZm4gPSAoKSA9PiAiSGVsbG8gd29ybGQiOw=='; +``` + +### export + +Export anything as a `default` or named export. + +```js +// Named exports +export var Count = 5; +export function Multiply(a, b) { + return a * b; +} + +// Default export +export default { + // Some data... +}; +``` + +### Dynamic import() + +```ts +function(path: string): Promise +``` + +Dynamically load modules. Calls to `import()` are treated as split points, meaning the requested module and its children are split out into a separate chunk. + +```js +if (module.hot) { + import('lodash').then(_ => { + // Do something with lodash (a.k.a '_')... + }); +} +``` + +:::warning +This feature relies on `Promise` internally. If you use import() with older browsers, remember to shim `Promise` using a polyfill such as [es6-promise](https://github.com/stefanpenner/es6-promise) or [promise-polyfill](https://github.com/taylorhakes/promise-polyfill). +::: + +### Dynamic expressions in import() + +It is not possible to use a fully dynamic import statement, such as `import(foo)`. Because `foo` could potentially be any path to any file in your system or project. + +The `import()` must contain at least some information about where the module is located. Bundling can be limited to a specific directory or set of files so that when you are using a dynamic expression - every module that could potentially be requested on an `import()` call is included. +For example, `import(`./locale/${language}.json`)` will cause every `.json` file in the `./locale` directory to be bundled into the new chunk. At run time, when the variable `language` has been computed, any file like `english.json` or `german.json` will be available for consumption. + +```js +// imagine we had a method to get language from cookies or other storage +const language = detectVisitorLanguage(); +import(`./locale/${language}.json`).then(module => { + // do something with the translations +}); +``` + +### Magic Comments + +Inline comments to make features work. By adding comments to the import, we can do things such as name our chunk or select different modes. For a full list of these magic comments see the code below followed by an explanation of what these comments do. + +```js +import( + /* webpackChunkName: "my-chunk-name" */ + /* webpackPrefetch: true */ + /* webpackPreload: true */ + 'module' +); +``` + +`webpackChunkName`: A name for the new chunk. + +`webpackPrefetch`: Tells the browser that the resource is probably needed for some navigation in the future (Available since 0.4.5). + +`webpackPreload`: Tells the browser that the resource might be needed during the current navigation (Available since 0.4.5). + +## CommonJS + +Rspack is also support `CommonJS` syntax natively, you can use `require` and `module.exports` methods. + +## Data URI Module + +Rspack supports importing Data URI modules using the `import` and `require` syntax. + +**import** + +```js +import DataURI from 'data:text/javascript,export default 42'; +``` + +**require** + +```js +require('data:text/javascript,module.exports = 42'); +``` + +In addition, Base64 encoded requests are also supported: + +```js +const { + number, + fn, +} = require('data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgcmV0dXJuICJIZWxsbyB3b3JsZCI7Cn0='); +``` + +::: tip +The Data URI module can be used as a method to implement virtual modules, such as combining with a Loader to dynamically load custom modules at runtime. +::: + +## Webpack + +Aside from the module syntaxes described above, Rspack also support some webpack-specific methods. + +#### require.context + +```ts +require.context( + (directory: String), + (includeSubdirs: Boolean) /* optional, default true */, + (filter: RegExp) /* optional, default /^\.\/.*$/, any file */, + (mode: String) /* optional, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', default 'sync' */ +); +``` + +Specify a whole group of dependencies using a path to the `directory`, an option to `includeSubdirs`, a `filter` for more fine grained control of the modules included, and a mode to define the way how loading will work. + +```js +const context = require.context('components', true, /\.html$/); +const componentA = context.resolve('componentA'); +``` + +If mode is set to 'lazy', the underlying modules will be loaded asynchronously. + +```js +const context = require.context('locales', true, /\.json$/, 'lazy'); +context('localeA').then(locale => { + // do something with locale +}); +``` diff --git a/website/docs/en/api/modules/module-variables.mdx b/website/docs/en/api/modules/module-variables.mdx new file mode 100644 index 000000000000..6db7d32f1954 --- /dev/null +++ b/website/docs/en/api/modules/module-variables.mdx @@ -0,0 +1,57 @@ +# Module Variables + +This section covers all **variables** available in code compiled with webpack. Modules will have access to certain data from the compilation process through `module` and other variables. + +### module.hot (webpack-specific) + +Indicates whether or not Hot Module Replacement is enabled and provides an interface to the process. See the [HMR API page](/api/hmr) for details. + +### import.meta.webpackHot (webpack-specific) + +An alias for `module.hot`, however `import.meta.webpackHot` can be used in strict ESM while `module.hot` can't. + +### \_\_dirname (NodeJS) + +Depending on the configuration option `node.__dirname`: + +- `false`: Not defined +- `mock`: equal to `'/'` +- `true`: [node.js \_\_dirname](https://nodejs.org/api/globals.html#globals_dirname) + +If used inside an expression that is parsed by the Parser, the configuration option is treated as `true`. + +### \_\_resourceQuery (webpack-specific) + +The resource query of the current module. If the following `require` call was made, then the query string would be available in `file.js`. + +```ts +require('file.js?test'); +``` + +```ts title="file.js" +__resourceQuery === '?test'; +``` + +### \_\_webpack_modules\_\_ (webpack-specific) + +Access to the internal object of all modules. + +### \_\_webpack_hash\_\_ (webpack-specific) + +It provides access to the hash of the compilation. + +### \_\_webpack_public_path\_\_ (webpack-specific) + +Equals the configuration option's [`output.publicPath`](/config/output#outputpublicpath). + +### \_\_webpack_chunkname\_\_ (webpack-specific) + + + +Access to name of current chunk. + +### \_\_webpack_runtime_id\_\_ (webpack-specific) + + + +Access the runtime id of current entry. diff --git a/website/docs/zh/api/_meta.json b/website/docs/zh/api/_meta.json index 6d734059addc..a33bd0163c8a 100644 --- a/website/docs/zh/api/_meta.json +++ b/website/docs/zh/api/_meta.json @@ -1,7 +1,11 @@ [ "index", "cli", - "modules", + { + "type": "dir", + "name": "modules", + "label": "模块" + }, "node-api", "hmr", { diff --git a/website/docs/zh/api/index.mdx b/website/docs/zh/api/index.mdx index 9ccb68c1f31a..2dcabc574f6e 100644 --- a/website/docs/zh/api/index.mdx +++ b/website/docs/zh/api/index.mdx @@ -12,7 +12,7 @@ Rspack 提供了多种界面来自定义编译过程。一些功能在不同的 在使用 Rspack 处理模块时,理解支持的不同模块语法——特别是方法和变量——是非常重要的。 -[了解更多关于模块的信息!](/api/modules) +[了解更多关于模块的信息!](/api/modules/module-methods) ## Node diff --git a/website/docs/zh/api/modules.mdx b/website/docs/zh/api/modules.mdx deleted file mode 100644 index 904263aaea22..000000000000 --- a/website/docs/zh/api/modules.mdx +++ /dev/null @@ -1,142 +0,0 @@ -import WebpackLicense from '@components/webpack-license'; -import { ApiMeta } from '../../../components/ApiMeta'; - - - -# 模块 - -虽然 Rspack 支持多种模块语法,但我们建议遵循单一的语法,以保持一致性并避免 bug。 - -### ES6 (推荐) - -Rspack 原生支持 ES6 模块语法,可以使用静态的 `import`、`export` 和 `import()` 语法。 - -#### Magic Comments - -通过在 import 中添加注释,我们可以进行诸如给 chunk 命名或选择不同模式的操作。 - -```js -import( - /* webpackChunkName: "my-chunk-name" */ - /* webpackPrefetch: true */ - /* webpackPreload: true */ - 'module' -); -``` - -`webpackChunkName`: 新 chunk 的名称。 - -`webpackPrefetch`: 告诉浏览器将来可能需要该资源来进行某些导航跳转(0.4.5 及以上版本支持)。 - -`webpackPreload`: 告诉浏览器在当前导航期间可能需要该资源(0.4.5 及以上版本支持)。 - -### CommonJS - -Rspack 也支持 `CommonJS` 语法,可以使用 `require` 和 `module.exports` 语法。 - -### DataURI 模块 - -Rspack 支持使用 `import` 和 `require` 语法导入 DataURI 模块。 - -**import** - -```js -import DataURI from 'data:text/javascript,export default 42'; -``` - -**require** - -```js -require('data:text/javascript,module.exports = 42'); -``` - -除此之外,还支持了 Base64 编码: - -```js -const { - number, - fn, -} = require('data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgcmV0dXJuICJIZWxsbyB3b3JsZCI7Cn0='); -``` - -::: tip -DataURI 模块可以被用作虚拟模块(Virtual Modules)的实现方式,如:配合 Loader 完成运行时动态加载自定义模块。 -::: - -### Webpack - -除了上述的模块语法之外,Rspack 还支持一些 Webpack 特有的方法。 - -#### require.context - -```ts -require.context( - (directory: String), - (includeSubdirs: Boolean) /*可选,默认为true */, - (filter: RegExp) /* 可选的,默认为/^\.\/.*$/ */。 - (mode: String) /* 可选的, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', 默认 'sync' */ -); -``` - -添加 `directory`、`includeSubdirs`,可以对引入的模块进行更精细控制。如果 `mode` 被设置为 `lazy`,模块将会被异步加载。 - -## 模块变量 - -### module.hot(webpack 专用) - -是否启用了热模块替换,暴露此对象并且导出一些方法,详情见 [HMR API](/api/hmr) 页面。 - -### import.meta.webpackHot(webpack 专用) - -`module.hot` 的别名,但是 `import.meta.webpackHot` 可以在严格的 ESM 中使用,而 module.hot 不能。 - -### \_\_dirname(NodeJS) - -配置选项 `node.__dirname`。 - -- `false`: 未定义 -- `mock`: 等于 `'/'` -- `true`: node.js \_\_dirname - -如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 true 处理。 - -### \_\_resourceQuery(webpack 专用) - -当前模块的资源查询(resource query)。如果进行了如下的 require 调用,那么查询字符串(query string)在 file.js 中可访问。 - -```ts -require('file.js?test'); -``` - -```ts title="file.js" -__resourceQuery === '?test'; -``` - -### \_\_webpack_modules\_\_ (webpack 专用) - -访问所有模块的内部对象。 - -### \_\_webpack_hash\_\_ (webpack 专用) - -这个变量提供对编译过程中(compilation)的 hash 信息的访问。 - -### \_\_webpack_public_path\_\_ (webpack 专用) - -等于配置选项的 [output.publicPath](/config/output#outputpublicpath)。 - -### \_\_webpack_chunkname\_\_ (webpack-specific) - - - -访问当前 chunk 的名称。 - -### \_\_webpack_runtime_id\_\_ (webpack-specific) - - - -访问当前入口的 runtime id。 diff --git a/website/docs/zh/api/modules/_meta.json b/website/docs/zh/api/modules/_meta.json new file mode 100644 index 000000000000..e2ca1dde6e5d --- /dev/null +++ b/website/docs/zh/api/modules/_meta.json @@ -0,0 +1 @@ +["module-methods", "module-variables"] diff --git a/website/docs/zh/api/modules/module-methods.mdx b/website/docs/zh/api/modules/module-methods.mdx new file mode 100644 index 000000000000..47a4d4831b40 --- /dev/null +++ b/website/docs/zh/api/modules/module-methods.mdx @@ -0,0 +1,167 @@ +import WebpackLicense from '@components/webpack-license'; + + + +# 模块方法 + +当使用 Rspack 打包应用程序时,你可以选择多种模块语法风格,包括 ES6、CommonJS。 + +尽管 Rspack 支持多种模块语法,我们建议为了保持一致性并避免奇怪的 bug,最好遵循单一的语法。 + +## ES6 (推荐) + +Rspack 原生支持 ES6 模块语法,可以使用静态的 `import`、`export` 和 `import()` 语法。 + +### import + +静态 `import` 另一个模块的 `export`。 + +```js +import MyModule from './my-module.js'; +import { NamedExport } from './other-module.js'; +``` + +你还可以 `import` Data URI: + +```js +import 'data:text/javascript;charset=utf-8;base64,Y29uc29sZS5sb2coJ2lubGluZSAxJyk7'; +import { + number, + fn, +} from 'data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgY29uc3QgZm4gPSAoKSA9PiAiSGVsbG8gd29ybGQiOw=='; +``` + +### export + +将任何内容作为默认导出或具名导出。 + +```js +// 具名导出 +export var Count = 5; +export function Multiply(a, b) { + return a * b; +} + +// 默认导出 +export default { + // Some data... +}; +``` + +### 动态 import() + +```ts +function(path: string): Promise +``` + +动态加载模块。对 `import()` 的调用被视为分割点,这意味着请求的模块及其子模块被拆分成单独的 chunk。 + +```js +if (module.hot) { + import('lodash').then(_ => { + // 使用 lodash 做些事情... + }); +} +``` + +:::warning 警告 +此功能内部依赖于 `Promise`。如果你在旧版浏览器中使用 `import()`,请记得使用类似于 [`es6-promise`](https://github.com/stefanpenner/es6-promise) 或 [`promise-polyfill`](https://github.com/taylorhakes/promise-polyfill) 的 polyfill 来模拟 `Promise`。 +::: + +### import() 中的动态表达式 + +无法使用完全动态的导入语句,例如 `import(foo)`。因为 `foo` 可能是系统或项目中任何文件的任何路径。 + +`import()` 必须至少包含一些关于模块所在位置的信息。可以将打包限制在特定目录或一组文件中,这样当你使用动态表达式时 - 在 `import()` 调用中可能被请求的每个模块都会被包括进来。 +例如,`import(./locale/${language}.json)` 会将 `./locale` 目录中的每个 `.json` 文件都被打包进新的代码块。在运行时,一旦变量 `language` 被计算出来,任何像 `english.json` 或 `german.json` 这样的文件都将可供使用。 + +```js +// 想象一下,如果我们有一种方法可以从 Cookie 或其他存储中获取语言 +const language = detectVisitorLanguage(); +import(`./locale/${language}.json`).then(module => { + // 做一些翻译相关的事情 +}); +``` + +### Magic Comments + +通过向 import 语句添加注释,我们可以执行诸如命名 chunk 或选择不同模式等操作。有关这些魔法注释的完整列表,请参见下面的代码,以及对这些注释功能的解释。 + +```js +import( + /* webpackChunkName: "my-chunk-name" */ + /* webpackPrefetch: true */ + /* webpackPreload: true */ + 'module' +); +``` + +`webpackChunkName`:新 chunk 的名称。 + +`webpackPrefetch`:告诉浏览器将来可能需要该资源来进行某些导航跳转(0.4.5 及以上版本支持)。 + +`webpackPreload`:告诉浏览器在当前导航期间可能需要该资源(0.4.5 及以上版本支持)。 + +## CommonJS + +Rspack 也支持 `CommonJS` 语法,可以使用 `require` 和 `module.exports` 语法。 + +## Data URI 模块 + +Rspack 支持使用 `import` 和 `require` 语法导入 Data URI 模块。 + +**import** + +```js +import DataURI from 'data:text/javascript,export default 42'; +``` + +**require** + +```js +require('data:text/javascript,module.exports = 42'); +``` + +除此之外,还支持了 Base64 编码: + +```js +const { + number, + fn, +} = require('data:text/javascript;charset=utf-8;base64,ZXhwb3J0IGNvbnN0IG51bWJlciA9IDQyOwpleHBvcnQgZnVuY3Rpb24gZm4oKSB7CiAgcmV0dXJuICJIZWxsbyB3b3JsZCI7Cn0='); +``` + +::: tip +Data URI 模块可以被用作虚拟模块(Virtual Modules)的实现方式,如:配合 loader 完成运行时动态加载自定义模块。 +::: + +## Webpack + +除了上述的模块方法之外,Rspack 还支持一些 webpack 特有的方法。 + +#### require.context + +```ts +require.context( + (directory: String), + (includeSubdirs: Boolean) /*可选,默认为true */, + (filter: RegExp) /* 可选的,默认为/^\.\/.*$/ */。 + (mode: String) /* 可选的, 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once', 默认 'sync' */ +); +``` + +通过 `directory`、`includeSubdirs`、`filter` 参数,可以对引入的模块进行更精细控制。 + +```js +const context = require.context('components', true, /\.html$/); +const componentA = context.resolve('componentA'); +``` + +如果 `mode` 被设置为 `lazy`,模块将会被异步加载。 + +```js +const context = require.context('locales', true, /\.json$/, 'lazy'); +context('localeA').then(locale => { + // 做一些与区域设置有关的事情 +}); +``` diff --git a/website/docs/zh/api/modules/module-variables.mdx b/website/docs/zh/api/modules/module-variables.mdx new file mode 100644 index 000000000000..556013c3876d --- /dev/null +++ b/website/docs/zh/api/modules/module-variables.mdx @@ -0,0 +1,66 @@ +import WebpackLicense from '@components/webpack-license'; +import { ApiMeta } from '../../../../components/ApiMeta'; + + + +# 模块变量 + +本节涵盖了使用 Rspack 编译代码时所有可用的变量。模块将能够通过 `module` 和其他变量访问来自编译过程的特定数据。 + +## module.hot(webpack 专用) + +是否启用了热模块替换,并提供了一些方法来处理该过程。有关详细信息,请参阅 [HMR API](/api/hmr) 页面。 + +## import.meta.webpackHot(webpack 专用) + +`module.hot` 的别名,`import.meta.webpackHot` 可以在严格的 ESM 中使用,而 module.hot 不能。 + +## \_\_dirname(NodeJS) + +依赖于配置项 [`node.__dirname`](/config/node#node__dirname)。 + +- `false`:未定义 +- `mock`:等于 `'/'` +- `true`:[node.js \_\_dirname](https://nodejs.org/api/globals.html#globals_dirname) + +如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 `true` 处理。 + +## \_\_resourceQuery(webpack 专用) + +当前模块的资源查询(resource query)。如果进行了如下的 `require` 调用,那么查询字符串(query string)在 `file.js` 中可用。 + +```ts +require('file.js?test'); +``` + +```ts title="file.js" +__resourceQuery === '?test'; +``` + +## \_\_webpack_modules\_\_ (webpack 专用) + +访问所有模块的内部对象。 + +## \_\_webpack_hash\_\_ (webpack 专用) + +提供对编译过程中(compilation)的 hash 信息的访问。 + +## \_\_webpack_public_path\_\_ (webpack 专用) + +等于配置选项的 [output.publicPath](/config/output#outputpublicpath)。 + +## \_\_webpack_chunkname\_\_ (webpack-specific) + + + +访问当前 chunk 的名称。 + +## \_\_webpack_runtime_id\_\_ (webpack-specific) + + + +访问当前入口的 runtime id。 + +```js +console.log(__webpack_runtime_id__ === 'main'); +``` From 7c68f971ee98585e9c7a7ef11ff37ebfb555bc1e Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Mon, 6 May 2024 20:10:42 +0800 Subject: [PATCH 010/107] docs: fix modules docs crash (#6449) fix: modules docs --- website/docs/en/api/modules/module-methods.mdx | 2 +- website/docs/en/api/modules/module-variables.mdx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/website/docs/en/api/modules/module-methods.mdx b/website/docs/en/api/modules/module-methods.mdx index 61c39a110c2f..c5c07e4ce128 100644 --- a/website/docs/en/api/modules/module-methods.mdx +++ b/website/docs/en/api/modules/module-methods.mdx @@ -73,7 +73,7 @@ This feature relies on `Promise` internally. If you use import() with older brow It is not possible to use a fully dynamic import statement, such as `import(foo)`. Because `foo` could potentially be any path to any file in your system or project. The `import()` must contain at least some information about where the module is located. Bundling can be limited to a specific directory or set of files so that when you are using a dynamic expression - every module that could potentially be requested on an `import()` call is included. -For example, `import(`./locale/${language}.json`)` will cause every `.json` file in the `./locale` directory to be bundled into the new chunk. At run time, when the variable `language` has been computed, any file like `english.json` or `german.json` will be available for consumption. +For example, `import(`./locale/$\{language}.json`)` will cause every `.json` file in the `./locale` directory to be bundled into the new chunk. At run time, when the variable `language` has been computed, any file like `english.json` or `german.json` will be available for consumption. ```js // imagine we had a method to get language from cookies or other storage diff --git a/website/docs/en/api/modules/module-variables.mdx b/website/docs/en/api/modules/module-variables.mdx index 6db7d32f1954..ee87d37be65c 100644 --- a/website/docs/en/api/modules/module-variables.mdx +++ b/website/docs/en/api/modules/module-variables.mdx @@ -1,3 +1,8 @@ +import WebpackLicense from '@components/webpack-license'; +import { ApiMeta } from '../../../../components/ApiMeta'; + + + # Module Variables This section covers all **variables** available in code compiled with webpack. Modules will have access to certain data from the compilation process through `module` and other variables. From 8179eec60e5c2574cf1a1bafafc5e1c5ce3f9b79 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Mon, 6 May 2024 20:26:39 +0800 Subject: [PATCH 011/107] fix(mf): __webpack_init_sharing__ with empty config (#6450) --- .../container-1-0/init-sharing-without-config/index.js | 4 ++++ .../init-sharing-without-config/webpack.config.js | 8 ++++++++ packages/rspack/src/container/ModuleFederationPluginV1.ts | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js diff --git a/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js new file mode 100644 index 000000000000..4ba156ad866b --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/index.js @@ -0,0 +1,4 @@ +it("should have single runtime chunk", () => { + __webpack_init_sharing__("default"); + expect(typeof __webpack_require__.I).toBe("function") +}); diff --git a/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js new file mode 100644 index 000000000000..3588b01b231e --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/container-1-0/init-sharing-without-config/webpack.config.js @@ -0,0 +1,8 @@ +const { ModuleFederationPluginV1: ModuleFederationPlugin } = require("@rspack/core").container; + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + plugins: [ + new ModuleFederationPlugin({}), + ] +}; diff --git a/packages/rspack/src/container/ModuleFederationPluginV1.ts b/packages/rspack/src/container/ModuleFederationPluginV1.ts index c86c9bc70858..1bcd18c4213a 100644 --- a/packages/rspack/src/container/ModuleFederationPluginV1.ts +++ b/packages/rspack/src/container/ModuleFederationPluginV1.ts @@ -9,6 +9,7 @@ import { SharePlugin, Shared } from "../sharing/SharePlugin"; import { isValidate } from "../util/validate"; import { ContainerPlugin, Exposes } from "./ContainerPlugin"; import { ContainerReferencePlugin, Remotes } from "./ContainerReferencePlugin"; +import { ShareRuntimePlugin } from "../sharing/ShareRuntimePlugin"; export interface ModuleFederationPluginV1Options { exposes?: Exposes; @@ -43,6 +44,7 @@ export class ModuleFederationPluginV1 { compiler.options.output.enabledLibraryTypes!.push(library.type); } compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => { + new ShareRuntimePlugin(this._options.enhanced).apply(compiler); if ( options.exposes && (Array.isArray(options.exposes) From f92424a863b42bba2848881a3902b4a6be00de7d Mon Sep 17 00:00:00 2001 From: hardfist Date: Tue, 7 May 2024 07:09:59 +0800 Subject: [PATCH 012/107] chore: take down diff&canary release workflow temporarily (#6455) --- .github/workflows/{diff.yml => diff.yml.bak} | 0 .github/workflows/{release-canary.yml => release-canary.yml.bak} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{diff.yml => diff.yml.bak} (100%) rename .github/workflows/{release-canary.yml => release-canary.yml.bak} (100%) diff --git a/.github/workflows/diff.yml b/.github/workflows/diff.yml.bak similarity index 100% rename from .github/workflows/diff.yml rename to .github/workflows/diff.yml.bak diff --git a/.github/workflows/release-canary.yml b/.github/workflows/release-canary.yml.bak similarity index 100% rename from .github/workflows/release-canary.yml rename to .github/workflows/release-canary.yml.bak From d2bae2ff008927ca48e6193f117575a732382fa9 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Tue, 7 May 2024 11:22:39 +0800 Subject: [PATCH 013/107] fix: consistent md4 hash in localNameIdent (#6444) * fix: consistent localNameIdent hash result with webpack * fix: consistent localNameIdent hash result with webpack * fix: consistent localNameIdent hash result with webpack * fix: consistent localNameIdent hash result with webpack --- crates/rspack_core/src/normal_module.rs | 1 + .../rspack_core/src/parser_and_generator.rs | 3 +- crates/rspack_hash/src/lib.rs | 4 +- .../src/parser_and_generator/mod.rs | 2 + crates/rspack_plugin_css/src/utils.rs | 32 +- packages/rspack-test-tools/package.json | 2 +- .../tests/__snapshots__/Config.test.js.snap | 288 +++++++++--------- .../tests/__snapshots__/StatsAPI.test.js.snap | 6 +- .../__snapshots__/StatsOutput.test.js.snap | 32 +- .../asset-simple/snapshot/output.snap.txt | 2 +- .../modules-composes/snapshot/output.snap.txt | 36 +-- .../snapshot/output.snap.txt | 4 +- .../filename/snapshot/output.snap.txt | 4 +- .../new-url-source/snapshot/output.snap.txt | 4 +- .../imports-multiple/snapshot/output.snap.txt | 4 +- .../plugin-wasm/v128/snapshot/output.snap.txt | 2 +- .../concatenate-modules/with-css/index.js | 4 +- .../css/rspack-issue-6435/a.module.css | 3 + .../css/rspack-issue-6435/index.js | 10 + .../css/rspack-issue-6435/legacy/index.css | 3 + .../css/rspack-issue-6435/style.module.css | 3 + .../css/rspack-issue-6435/webpack.config.js | 41 +++ .../skipping-mangle-css-modules/index.js | 3 +- .../chunk/asset/snapshot/web/2.snap.txt | 2 +- .../css/parser-and-generator-states/index.js | 4 +- .../snapshot/web/1.snap.txt | 6 +- .../tests/statsAPICases/basic.js | 2 +- .../tests/statsAPICases/exports.js | 2 +- .../tests/statsAPICases/to-string.js | 2 +- ...$.css => async.$048dd0ea10a262087819$.css} | 0 ...8$.css => main.$048dd0ea10a262087819$.css} | 0 .../chunkFilename-fullhash/expected/main.js | 2 +- ...js.$2faf8431c36246aaa99efe65186ef7b1$.css} | 0 ...js.$108a632b35566ba6e10f21437dc1e449$.css} | 0 ...in.$2948667d05523e0bdd4b433a8b432330$.css} | 0 ...yA.$63eb4b2b7412624c84340d8ef2383cb3$.css} | 0 ...yB.$7dc4057bc127528eb3d6e30affb70fc5$.css} | 0 ...in.$fcf981e297c26c27907740d422c8fbb8$.css} | 0 ...in.$a033229f200a2cfbacbc9213dd60155a$.css} | 0 .../expected/main.css.map | 2 +- .../devtool-source-map/expected/main.css.map | 2 +- ....$2ebc9424ae217f7031ea75743effd066$.2.css} | 0 ....$fc35cd7d3442366ea0e20c936c0d399c$.1.css} | 0 ...e55bcbc35.png => 4d3b8fdfbe46b279f223.png} | Bin .../cases/new-url/expected/main.css | 2 +- .../expected/main.css.map | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../publicpath-absolute-url/expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../publicpath-default-auto/expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../publicpath-empty-string/expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/nested/again/style.css | 2 +- .../expected/nested/style.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../publicpath-loader-auto/expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- ...4d5319600.svg => 2b438a6f1910279f8b62.svg} | 0 .../expected/main.css | 2 +- 85 files changed, 317 insertions(+), 242 deletions(-) create mode 100644 packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/a.module.css create mode 100644 packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/legacy/index.css create mode 100644 packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/style.module.css create mode 100644 packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/webpack.config.js rename plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{async.$a86b1707b4af75e0f088$.css => async.$048dd0ea10a262087819$.css} (100%) rename plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{main.$a86b1707b4af75e0f088$.css => main.$048dd0ea10a262087819$.css} (100%) rename plugin-test/css-extract/cases/content-entries-with-same-import/expected/{one_js.$34ea7e852b73f29ba7a5b065d4eec971$.css => one_js.$2faf8431c36246aaa99efe65186ef7b1$.css} (100%) rename plugin-test/css-extract/cases/content-entries-with-same-import/expected/{two_js.$1286cc6ec04dae701cfb317f9b9aa178$.css => two_js.$108a632b35566ba6e10f21437dc1e449$.css} (100%) rename plugin-test/css-extract/cases/contenthash-1/expected/{main.$e29a42ed09bda57bc430ed9ccfa30f63$.css => main.$2948667d05523e0bdd4b433a8b432330$.css} (100%) rename plugin-test/css-extract/cases/contenthash-multiple-entries/expected/{entryA.$7102da6560e321434f72cdf38a5f9e22$.css => entryA.$63eb4b2b7412624c84340d8ef2383cb3$.css} (100%) rename plugin-test/css-extract/cases/contenthash-multiple-entries/expected/{entryB.$ea9aedf549e60226448ece39da68f162$.css => entryB.$7dc4057bc127528eb3d6e30affb70fc5$.css} (100%) rename plugin-test/css-extract/cases/contenthash/expected/{1.main.$b8738e31859438bcaaf82f0e18ccb8e1$.css => 1.main.$fcf981e297c26c27907740d422c8fbb8$.css} (100%) rename plugin-test/css-extract/cases/contenthash/expected/{2.main.$22a4c275951727d855be6683d3f1b3b7$.css => 2.main.$a033229f200a2cfbacbc9213dd60155a$.css} (100%) rename plugin-test/css-extract/cases/js-hash/expected/{style.$8962f7751ac742a81f8cd8ef907bc50a$.2.css => style.$2ebc9424ae217f7031ea75743effd066$.2.css} (100%) rename plugin-test/css-extract/cases/js-hash/expected/{style.$59392d4d94762f990e9ea8dfa94f9c34$.1.css => style.$fc35cd7d3442366ea0e20c936c0d399c$.1.css} (100%) rename plugin-test/css-extract/cases/new-url/expected/{ebb93b9cb62e55bcbc35.png => 4d3b8fdfbe46b279f223.png} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url-2/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-absolute-url/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-default-auto/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-empty-string/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-function-2/expected/webpack-5/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-function/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-loader-auto/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-1/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-2/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-3/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-4/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-5/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-6/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative-7/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) rename plugin-test/css-extract/cases/publicpath-path-relative/expected/{61dc21364604d5319600.svg => 2b438a6f1910279f8b62.svg} (100%) diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index c2eccfe1ab89..c8a4d2d092a4 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -503,6 +503,7 @@ impl Module for NormalModule { .parser_and_generator .parse(ParseContext { source: original_source.clone(), + module_context: &self.context, module_identifier: self.identifier(), module_parser_options: self.parser_options.as_ref(), module_type: &self.module_type, diff --git a/crates/rspack_core/src/parser_and_generator.rs b/crates/rspack_core/src/parser_and_generator.rs index e7de0a5e2e97..e661e76c18bc 100644 --- a/crates/rspack_core/src/parser_and_generator.rs +++ b/crates/rspack_core/src/parser_and_generator.rs @@ -14,12 +14,13 @@ use crate::{ DependencyTemplate, GeneratorOptions, Module, ModuleDependency, ModuleIdentifier, ModuleType, ParserOptions, RuntimeGlobals, RuntimeSpec, SourceType, }; -use crate::{ChunkGraph, ConcatenationScope, ModuleGraph}; +use crate::{ChunkGraph, ConcatenationScope, Context, ModuleGraph}; #[derive(Derivative)] #[derivative(Debug)] pub struct ParseContext<'a> { pub source: BoxSource, + pub module_context: &'a Context, pub module_identifier: ModuleIdentifier, pub module_type: &'a ModuleType, pub module_user_request: &'a str, diff --git a/crates/rspack_hash/src/lib.rs b/crates/rspack_hash/src/lib.rs index 1ebbe5991515..d73d7c7f3808 100644 --- a/crates/rspack_hash/src/lib.rs +++ b/crates/rspack_hash/src/lib.rs @@ -78,7 +78,9 @@ impl RspackHash { pub fn with_salt(function: &HashFunction, salt: &HashSalt) -> Self { let mut this = Self::new(function); - salt.hash(&mut this); + if !matches!(salt, HashSalt::None) { + salt.hash(&mut this); + } this } diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index bd6a65c527f3..b792448ea73a 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -83,6 +83,7 @@ impl ParserAndGenerator for CssParserAndGenerator { fn parse(&mut self, parse_context: ParseContext) -> Result> { let ParseContext { source, + module_context, module_type, module_user_request, module_source_map_kind, @@ -141,6 +142,7 @@ impl ParserAndGenerator for CssParserAndGenerator { let result = swc_core::css::modules::compile( &mut stylesheet, ModulesTransformConfig::new( + module_context, resource_data, self .local_ident_name diff --git a/crates/rspack_plugin_css/src/utils.rs b/crates/rspack_plugin_css/src/utils.rs index 86a7892990b9..0a3cc3d3f1f6 100644 --- a/crates/rspack_plugin_css/src/utils.rs +++ b/crates/rspack_plugin_css/src/utils.rs @@ -1,4 +1,6 @@ -use std::{fmt::Write, hash::Hash}; +use std::fmt::Write; +use std::hash::Hasher; +use std::path::PathBuf; use heck::{ToKebabCase, ToLowerCamelCase}; use once_cell::sync::Lazy; @@ -24,6 +26,8 @@ use crate::parser_and_generator::{CssExport, CssExportsType}; pub const AUTO_PUBLIC_PATH_PLACEHOLDER: &str = "__RSPACK_PLUGIN_CSS_AUTO_PUBLIC_PATH__"; pub static AUTO_PUBLIC_PATH_PLACEHOLDER_REGEX: Lazy = Lazy::new(|| Regex::new(AUTO_PUBLIC_PATH_PLACEHOLDER).expect("Invalid regexp")); +pub static LEADING_DIGIT_REGEX: Lazy = + Lazy::new(|| Regex::new(r"^\d+").expect("Invalid regexp")); pub struct ModulesTransformConfig<'a> { resource_data: &'a ResourceData, @@ -39,6 +43,7 @@ pub struct ModulesTransformConfig<'a> { impl<'a> ModulesTransformConfig<'a> { pub fn new( + module_context: &'a Context, resource_data: &'a ResourceData, local_name_ident: &'a LocalIdentName, compiler_options: &'a CompilerOptions, @@ -53,17 +58,24 @@ impl<'a> ModulesTransformConfig<'a> { hash_salt: &output.hash_salt, unique_name: &output.unique_name, mode: &compiler_options.mode, - context: &compiler_options.context, + context: module_context, } } } impl swc_core::css::modules::TransformConfig for ModulesTransformConfig<'_> { fn new_name_for(&self, local: &Atom) -> Atom { - let relative_path = self.resource_data.resource_path.relative(self.context); + let mut relative_path = self.resource_data.resource_path.relative(self.context); + let relative_str = relative_path.to_string_lossy().to_string(); + + // abc.js => ./abc.js, align with webpack + if !relative_path.is_absolute() && !relative_str.starts_with('.') { + relative_path = PathBuf::from(format!("./{}", relative_str)); + } + let hash = { let mut hasher = RspackHash::with_salt(self.hash_function, self.hash_salt); - relative_path.hash(&mut hasher); + hasher.write(relative_path.to_string_lossy().as_bytes()); let contains_local = self .local_name_ident .template @@ -71,15 +83,12 @@ impl swc_core::css::modules::TransformConfig for ModulesTransformConfig<'_> { .map(|t| t.contains("[local]")) .unwrap_or_default(); if !contains_local { - local.hash(&mut hasher); + hasher.write(local.as_bytes()); } let hash = hasher.digest(self.hash_digest); - let hash = hash.rendered(self.hash_digest_length); - if hash.as_bytes()[0].is_ascii_digit() { - format!("_{hash}") - } else { - hash.into() - } + LEADING_DIGIT_REGEX + .replace_all(hash.rendered(self.hash_digest_length), "") + .into_owned() }; let relative_resource = make_paths_relative(self.context.as_str(), &self.resource_data.resource); @@ -120,6 +129,7 @@ impl LocalIdentNameRenderOptions<'_> { .always_ok(); s = s.replace("[local]", self.local); s = s.replace("[uniqueName]", self.unique_name); + s = ESCAPE_LOCAL_IDENT_REGEX.replace_all(&s, "_").into_owned(); s } diff --git a/packages/rspack-test-tools/package.json b/packages/rspack-test-tools/package.json index b0d048e512b8..17d6caa6a3b8 100644 --- a/packages/rspack-test-tools/package.json +++ b/packages/rspack-test-tools/package.json @@ -18,7 +18,7 @@ "dev": "tsc -b -w", "test": "sh -c 'run-s \"test:* -- $*\"' sh", "testu": "sh -c 'run-s \"test:* -- $*\"' sh -u", - "test:base": "cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.js --passWithNoTests", + "test:base": "cross-env NODE_OPTIONS=--openssl-legacy-provider NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.js --passWithNoTests", "test:hot": "cross-env RSPACK_HOT_TEST=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.hot.js --passWithNoTests", "test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --config ./jest.config.diff.js --passWithNoTests", "api-extractor": "api-extractor run --verbose", diff --git a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap index a45c95dba2b0..27283e6f2cb6 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap @@ -2,200 +2,200 @@ exports[`config config/builtins/css-auto exported tests css/auto can handle css module correctly 1`] = ` Object { - "style": "-_921b05f8c9c16ca9ea84-style", + "style": "-ca56f23580d7bbb484-style", } `; exports[`config config/builtins/css-modules-composes exported tests css modules composes 1`] = ` Object { - "simple-bar": "-_273d87445e861b3031dc-simple-bar -_9d368fc847854456bea3-imported-simple", - "simple-foo": "-_273d87445e861b3031dc-simple-foo -_9d368fc847854456bea3-imported-simple", + "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": "-_273d87445e861b3031dc-class -_11a6d6ffb863bd538fe5-lessClass", - "ghi": "-_273d87445e861b3031dc-ghi", - "other": "-_273d87445e861b3031dc-other -_1f71e04288dddc43d27d-scssClass", - "otherClassName": "-_273d87445e861b3031dc-otherClassName globalClassName", + "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": "-_735885c5e37059075f0c-bar -_3dd446eb32b4cceede74-foo", + "bar": "-f1f00e6e62b9a7fadb02-bar -a3b1929b59eeacf15a4-foo", } `; exports[`config config/builtins/css-modules-dedupe exported tests css modules dedupe 1`] = ` Object { - "backButton": "-d4f5f65e6ec5e3abc2cc-backButton -_0f182db74b24b91ce53c-secondaryButton -ed3ce9538ce4b9c8f8ab-button", - "nextButton": "-d4f5f65e6ec5e3abc2cc-nextButton -_73af08fa9da07d8b8412-primaryButton -ed3ce9538ce4b9c8f8ab-button", + "backButton": "-baa5c4d806a1671b-backButton -b2a7836182365a7a19ae-secondaryButton -f6ca8ebd9e01b-button", + "nextButton": "-baa5c4d806a1671b-nextButton -ffa91d57bfb88e0ca996-primaryButton -f6ca8ebd9e01b-button", } `; exports[`config config/builtins/css-modules-exports-only exported tests css modules exportsOnly 1`] = ` Object { - "simple-bar": "-_273d87445e861b3031dc-simple-bar -_9d368fc847854456bea3-imported-simple", - "simple-foo": "-_273d87445e861b3031dc-simple-foo -_9d368fc847854456bea3-imported-simple", + "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 { - "#": "_2d1f13069a34dadb8112", - "##": "ae8301fd6f3598539bfd", - "#.#.#": "_1c997a569a07f2420708", - "#fake-id": "d3e8bdca9f976f125db0", - "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.": "cf064fddad4f1ee12a13", - "-a-b-c-": "_3009825ac55fd922e1d4", - "-a0-34a___f": "_2470cf17671bc0f04fb9", - ".": "_45953b92c963cd9365ee", - "123": "b83ce8234973aca76caf", - "1a2b3c": "eca4a6468c54eaabda5f", - ":)": "_9cd9dacf371a665c5e39", - ":\`(": "_849c0b45e753bfe7e332", - ":hover": "_0eec8dbaeb3d52c7e318", - ":hover:focus:active": "cebbf8d9d82b804826ba", - "<><<<>><>": "d0504329c86bf6aaf83f", - "

": "_1f3da2d9abca032e8688", - "?": "d53002e1233f2049f1d4", - "@": "_3604bb5089512604fd6d", - "B&W?": "_29a1f492830adeef54f9", - "[attr=value]": "eb2787a6b2019adfdf12", - "_": "e0c21379fbaec4cf8e76", - "_test": "_701db8dd042b793cda43", - "className": "d42832db1967a6f6161f", - "f!o!o": "_1a4bc095be932bd43d82", - "f'o'o": "b419c7cea20ab4e4c57f", - "f*o*o": "bc01ebf6803f206edbdc", - "f+o+o": "a330ce191c89fbe8ef59", - "f/o/o": "a507c95c5be333d80af6", - "f\\\\o\\\\o": "_8ae0554ce544e3013a32", - "foo.bar": "abed3de09fc05d3400f8", - "foo/bar": "_57fbbed34c6039e5045b", - "foo/bar/baz": "_66e03c108771225ae79a", - "foo\\\\bar": "_48beb53984c701be5645", - "foo\\\\bar\\\\baz": "f9e76b11c67b5115ebdb", - "f~o~o": "_451cb3cda3d4bf8ea8f3", - "m_x_@": "_9a7665e6cf83142e1b3c", - "someId": "_9d834034f45a6a2c699b", - "subClass": "fe69f3ebba3ba63e167e", - "test": "b7fc104110738641f152", - "{}": "a7a93ea70d691fba54a2", - "©": "d9e5b239186637532208", - "“‘’”": "_56e0bf6b2fa8a18ff54e", - "⌘⌥": "_6f25eff10f3aecf1d2de", - "☺☃": "c00a0e3463f69bf799ae", - "♥": "_4d9b71f741c330bc24d0", - "𝄞♪♩♫♬": "a01c68c82acee141b0b9", - "💩": "e3663ae314f6186e799a", - "😍": "bfb8a2d9978df6976636", + "#": "b8b048cfa675ca7e9b4f", + "##": "a8e816d5d9b299b2c0d", + "#.#.#": "c6d1911da4c507e78", + "#fake-id": "d71ffe1702e9e5f648a4", + "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.": "f085385047c8494d66a2", + "-a-b-c-": "e171381fc62026ffe05b", + "-a0-34a___f": "e6419db424263d77191e", + ".": "e1742279a9b31ae95d46", + "123": "e3e235fe2ac5b10a03fa", + "1a2b3c": "e510ae3725659c886e", + ":)": "a7752c5da475e25c37", + ":\`(": "ec4ad64c1cd22a195fb2", + ":hover": "aabfd498fc2f10c7", + ":hover:focus:active": "ea9f2b2a3c0d8b6f20f6", + "<><<<>><>": "b9dc5ecfad4841cf835", + "

": "d66e45a3f7eba1bd2ff3", + "?": "db855a2cb1936bcecdd8", + "@": "b7c53c5c915459fb9703", + "B&W?": "b24426e6382e4f90c52", + "[attr=value]": "cebfe9ac1785240b1f84", + "_": "ffc4dae298ad4c338544", + "_test": "acd3c0528ed3c3330", + "className": "a20f38af3e2122251", + "f!o!o": "dfe9da10af7d0818e5e", + "f'o'o": "b91ad92cc62c88a93dc8", + "f*o*o": "c8706122491802a", + "f+o+o": "fb4386a15ebce1ce30f", + "f/o/o": "c6b959b8b545952c7fcf", + "f\\\\o\\\\o": "c9c9fd2189f4eef61", + "foo.bar": "fa92bf8dea4a5a2ea13", + "foo/bar": "e27d59ba2484ded530e7", + "foo/bar/baz": "fb5155c99d0c07a91", + "foo\\\\bar": "c4b0876e6a72fa1da88", + "foo\\\\bar\\\\baz": "d0641bf036f0db5b0fb7", + "f~o~o": "cb1e1a38751d777913bc", + "m_x_@": "acf01e983cc34242b09", + "someId": "f7dad309581ff59a8c1", + "subClass": "f904cf1d95567c868707", + "test": "c8e76de9832d60b206c2", + "{}": "a273624fc967254e4ad3", + "©": "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___p_", - "?": "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__😍", + "#": "__index__#", + "##": "__index__##", + "#.#.#": "__index__#_#_#", + "#fake-id": "__index__#fake-id", + "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.": "__index__++++++++++[_+++++++_++++++++++_+++_+____-]_++__+_+++++++__+++__++___+++++++++++++++___+++_------_--------__+___", + "-a-b-c-": "__index__-a-b-c-", + "-a0-34a___f": "__index__-a0-34a___f", + ".": "__index___", + "123": "__index__123", + "1a2b3c": "__index__1a2b3c", + ":)": "__index___)", + ":\`(": "__index___\`(", + ":hover": "__index___hover", + ":hover:focus:active": "__index___hover_focus_active", + "<><<<>><>": "__index___________", + "

": "__index___p_", + "?": "__index___", + "@": "__index__@", + "B&W?": "__index__B&W_", + "[attr=value]": "__index__[attr=value]", + "_": "__index___", + "_test": "__index___test", + "className": "__index__className", + "f!o!o": "__index__f!o!o", + "f'o'o": "__index__f'o'o", + "f*o*o": "__index__f_o_o", + "f+o+o": "__index__f+o+o", + "f/o/o": "__index__f_o_o", + "f\\\\o\\\\o": "__index__f_o_o", + "foo.bar": "__index__foo_bar", + "foo/bar": "__index__foo_bar", + "foo/bar/baz": "__index__foo_bar_baz", + "foo\\\\bar": "__index__foo_bar", + "foo\\\\bar\\\\baz": "__index__foo_bar_baz", + "f~o~o": "__index__f~o~o", + "m_x_@": "__index__m_x_@", + "someId": "__index__someId", + "subClass": "__index__subClass", + "test": "__index__test", + "{}": "__index__{}", + "©": "__index__©", + "“‘’”": "__index__“‘’”", + "⌘⌥": "__index__⌘⌥", + "☺☃": "__index__☺☃", + "♥": "__index__♥", + "𝄞♪♩♫♬": "__index__𝄞♪♩♫♬", + "💩": "__index__💩", + "😍": "__index__😍", } `; exports[`config config/builtins/css-modules-locals-convention-camelCase exported tests css modules localsConvention with camelCase 1`] = ` Object { - "btn--info_is-disabled_1": "-_273d87445e861b3031dc-btn--info_is-disabled_1", - "btn-info_is-disabled": "-_273d87445e861b3031dc-btn-info_is-disabled", - "btnInfoIsDisabled": "-_273d87445e861b3031dc-btn-info_is-disabled", - "btnInfoIsDisabled1": "-_273d87445e861b3031dc-btn--info_is-disabled_1", - "fooBar": "-_273d87445e861b3031dc-foo_bar", - "foo_bar": "-_273d87445e861b3031dc-foo_bar", - "simple": "-_273d87445e861b3031dc-simple", + "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": "-_273d87445e861b3031dc-btn-info_is-disabled", - "btnInfoIsDisabled1": "-_273d87445e861b3031dc-btn--info_is-disabled_1", - "fooBar": "-_273d87445e861b3031dc-foo_bar", - "simple": "-_273d87445e861b3031dc-simple", + "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": "-_273d87445e861b3031dc-btn--info_is-disabled_1", - "btn-info-is-disabled": "-_273d87445e861b3031dc-btn-info_is-disabled", - "btn-info-is-disabled-1": "-_273d87445e861b3031dc-btn--info_is-disabled_1", - "btn-info_is-disabled": "-_273d87445e861b3031dc-btn-info_is-disabled", - "foo-bar": "-_273d87445e861b3031dc-foo_bar", - "foo_bar": "-_273d87445e861b3031dc-foo_bar", - "simple": "-_273d87445e861b3031dc-simple", + "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": "-_273d87445e861b3031dc-bar", - "bav": "-_273d87445e861b3031dc-bav", - "foo": "-_273d87445e861b3031dc-foo", - "four": "-_273d87445e861b3031dc-four", - "one": "-_273d87445e861b3031dc-one", - "three": "-_273d87445e861b3031dc-three", - "two": "-_273d87445e861b3031dc-two", + "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": "-_921b05f8c9c16ca9ea84-style", + "style": "-ca56f23580d7bbb484-style", } `; @@ -245,17 +245,17 @@ exports[`config config/css/export-selector exported tests should have correct cs " `; -exports[`config config/css/rewrite-url exported tests should rewrite the css url() 1`] = `"eb587e4780c414fe3a22.png"`; +exports[`config config/css/rewrite-url exported tests should rewrite the css url() 1`] = `"95988e500e4d2ddfeeb7.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`] = `"eb587e4780c414fe3a22.png"`; +exports[`config config/css/rewrite-url-css-variables exported tests should rewrite the css url() in css variables 1`] = `"95988e500e4d2ddfeeb7.png"`; -exports[`config config/css/rewrite-url-css-variables exported tests should rewrite the css url() in css variables 2`] = `"eb587e4780c414fe3a22.png"`; +exports[`config config/css/rewrite-url-css-variables exported tests should rewrite the css url() in css variables 2`] = `"95988e500e4d2ddfeeb7.png"`; -exports[`config config/css/rewrite-url-with-css-filename exported tests should rewrite the css url() with publicPath and ~@ prefix 1`] = `"/image/logo.eb587e47.png"`; +exports[`config config/css/rewrite-url-with-css-filename exported tests should rewrite the css url() with publicPath and ~@ prefix 1`] = `"/image/logo.95988e50.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.eb587e47.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.95988e50.png"`; exports[`config config/css/urls exported tests css urls should works 1`] = ` "/* @supports (background-image: url(\\"unknown.png\\")) { @@ -302,7 +302,7 @@ div { div { a1: url(); - a114: url(ebb93b9cb62e55bcbc35.png); + a114: url(4d3b8fdfbe46b279f223.png); } div { @@ -387,10 +387,10 @@ exports[`config config/schemes/data-imports exported tests data imports 1`] = ` .class { - a: url(bd595024fc7e226eea64.svg); - b: url(bd595024fc7e226eea64.svg); - c: url(bd595024fc7e226eea64); - d: url(bd595024fc7e226eea64); + a: url(3a4d6b1f7ae9358a676b.svg); + b: url(3a4d6b1f7ae9358a676b.svg); + c: url(3a4d6b1f7ae9358a676b); + d: url(3a4d6b1f7ae9358a676b); } " diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap index 6f3f4683518b..142957a81c45 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap @@ -102,7 +102,7 @@ Object { "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "57e46af248a1c1fe076f", + "hash": "ee9a5ee8da42dac2c2aa", "logging": Object {}, "modules": Array [ Object { @@ -402,7 +402,7 @@ Object { "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "4b5e3314a79376e83a18", + "hash": "36dd148024fa89ee453a", "logging": Object {}, "modules": Array [ Object { @@ -968,7 +968,7 @@ exports.c = require(\\"./c?c=3\\"); "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "aa85e38b2dc3e3f7dbda", + "hash": "4fed4a0fec64e42d02f8", "logging": Object {}, "modules": Array [ Object { diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index f7aefb1c36a8..97114eeefb4a 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -2,8 +2,8 @@ exports[`statsOutput statsOutput/auxiliary-files-test should print correct stats for auxiliary-files-test 1`] = ` "PublicPath: auto +asset a09d8e0f399c215faa79.png 7 bytes {909} [emitted] [from: raw.png] (name: main) asset bundle.js 2.4 KiB {909} [emitted] (name: main) -asset f7f4f00355f310234f70.png 7 bytes {909} [emitted] [from: raw.png] (name: main) Entrypoint main 2.4 KiB = bundle.js chunk {909} bundle.js (main) [entry] ./raw.png [193] {909} @@ -33,7 +33,7 @@ webpack/runtime/auto_public_path {909} [no exports] [used exports unknown] -Rspack compiled successfully (ad3050f7790e51415050)" +Rspack compiled successfully (96c9a0233f5bdeaa93e8)" `; exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for builtin-swc-loader-parse-error 1`] = ` @@ -60,7 +60,7 @@ Entrypoint main 654 bytes = main.js ERROR in × Resolve error: Can't resolve './src' in 'Xdir/css-concat-error' -Rspack x.x.x compiled with 1 error in X s (6a173f34164e1af948e4)" +Rspack x.x.x compiled with 1 error in X s (8808376bbd25437de260)" `; exports[`statsOutput statsOutput/filename should print correct stats for filename 1`] = ` @@ -71,7 +71,7 @@ Entrypoint main 8.73 KiB = 909.xxxx.js runtime modules 11 modules ./index.js ./dynamic.js -Rspack x.x.x compiled successfully in X s (185b80456c181897fcd5)" +Rspack x.x.x compiled successfully in X s (a41322d0088be2cf18dc)" `; exports[`statsOutput statsOutput/hot+production should print correct stats for hot+production 1`] = ` @@ -80,7 +80,7 @@ asset main.js 32.1 KiB [emitted] (name: main) Entrypoint main 32.1 KiB = main.js runtime modules 11 modules ./index.js -Rspack x.x.x compiled successfully in X s (db903683225d0fe50e7b)" +Rspack x.x.x compiled successfully in X s (bda0662c38188eca4d63)" `; exports[`statsOutput statsOutput/ignore-plugin should print correct stats for ignore-plugin 1`] = ` @@ -133,7 +133,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s ./d.js ./e.js ./index.js - 1 chunks (Rspack x.x.x) compiled successfully in X s (0d76b7dadd0c657ad341) + 1 chunks (Rspack x.x.x) compiled successfully in X s (9343a795eebf86cac89a) 2 chunks: PublicPath: auto @@ -147,7 +147,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle2.js (main) >{76}< [entry] ./b.js ./index.js - 2 chunks (Rspack x.x.x) compiled successfully in X s (a80080d4a166d3a145b2) + 2 chunks (Rspack x.x.x) compiled successfully in X s (58d446010942300c8786) 3 chunks: PublicPath: auto @@ -163,7 +163,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle3.js (main) >{76}< [entry] ./b.js ./index.js - 3 chunks (Rspack x.x.x) compiled successfully in X s (0e854af4043d4cced12b) + 3 chunks (Rspack x.x.x) compiled successfully in X s (e1f702c28a1f7745f19e) 4 chunks: PublicPath: auto @@ -181,7 +181,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle4.js (main) >{76}< [entry] ./b.js ./index.js - 4 chunks (Rspack x.x.x) compiled successfully in X s (4525b2f4f1626b91a6f4)" + 4 chunks (Rspack x.x.x) compiled successfully in X s (799760b5db8d720723c3)" `; exports[`statsOutput statsOutput/logging-loader should print correct stats for logging-loader 1`] = ` @@ -311,7 +311,7 @@ ERROR in ./index.js ╰──── help: maybe it had cyclic aliases -Rspack x.x.x compiled with 1 error in X s (59974c3941ac297dceb3)" +Rspack x.x.x compiled with 1 error in X s (1610bb37730c587998bd)" `; exports[`statsOutput statsOutput/resolve-unexpected-exports-in-pkg-error should print correct stats for resolve-unexpected-exports-in-pkg-error 1`] = ` @@ -324,7 +324,7 @@ runtime modules 1 module ERROR in ./index.js × Invalid \\"exports\\" target \\"../../index.js\\" defined for '.' in the package config Xdir/resolve-unexpected-exports-in-pkg-error/node_modules/pkg-a/package.json -Rspack x.x.x compiled with 1 error in X s (c1888f6bacf659a49dc3)" +Rspack x.x.x compiled with 1 error in X s (b45f1a2adf9c9eae762e)" `; exports[`statsOutput statsOutput/runtime-modules should print correct stats for runtime-modules 1`] = ` @@ -347,7 +347,7 @@ Entrypoint main 1.66 KiB = main.js ./increment.js [exports: decrement, increment, incrementBy2] [only some exports used: increment] -Rspack x.x.x compiled successfully in X s (962310b17150e819242d)" +Rspack x.x.x compiled successfully in X s (9efe9f85d71294bf4e5f)" `; exports[`statsOutput statsOutput/side-effects-bailouts should print correct stats for side-effects-bailouts 1`] = ` @@ -382,7 +382,7 @@ webpack/runtime/define_property_getters {909} [no exports] [used exports unknown] -1970-04-20 12:42:42: Rspack x.x.x compiled successfully in X s (6407ed847eb679304311)" +1970-04-20 12:42:42: Rspack x.x.x compiled successfully in X s (c4f7bcbb8ec6a06a4661)" `; exports[`statsOutput statsOutput/simple-export should print correct stats for simple-export 1`] = ` @@ -391,7 +391,7 @@ asset bundle.js 1.79 KiB [emitted] (name: main) Entrypoint main 1.79 KiB = bundle.js runtime modules 3 modules ./index.js -Rspack x.x.x compiled successfully in X s (28af2d7a47e4039ec00e)" +Rspack x.x.x compiled successfully in X s (a3d8bfb29f0f2ccec405)" `; exports[`statsOutput statsOutput/simple-module-source should print correct stats for simple-module-source 1`] = ` @@ -402,7 +402,7 @@ runtime modules 3 modules orphan modules [orphan] 1 module ./raw.png ./index.js -Rspack compiled successfully (de1220b5052bdbe79250)" +Rspack compiled successfully (d0ce130488abf5f87f64)" `; exports[`statsOutput statsOutput/stats-hooks should print correct stats for stats-hooks 1`] = ` @@ -410,7 +410,7 @@ exports[`statsOutput statsOutput/stats-hooks should print correct stats for stat asset main.js 764 bytes [emitted111] (name: main) [testA: aaaaaa] Entrypoint main 764 bytes = main.js ./index.js -Rspack compiled successfully (baea1f1033101ca9fde6)" +Rspack compiled successfully (d55a67420c97eab0f0a6)" `; exports[`statsOutput statsOutput/try-require-module should print correct stats for try-require-module 1`] = ` diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/snapshot/output.snap.txt index 078cd8d499f2..6d3d378e46aa 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/snapshot/output.snap.txt @@ -40,7 +40,7 @@ function createImageElement(title, src) { module.exports = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAABIAAAAAQAAAEgAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAJagAwAEAAAAAQAAAJYAAAAA/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/CABEIAJYAlgMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAADAgQBBQAGBwgJCgv/xADDEAABAwMCBAMEBgQHBgQIBnMBAgADEQQSIQUxEyIQBkFRMhRhcSMHgSCRQhWhUjOxJGIwFsFy0UOSNIII4VNAJWMXNfCTc6JQRLKD8SZUNmSUdMJg0oSjGHDiJ0U3ZbNVdaSVw4Xy00Z2gONHVma0CQoZGigpKjg5OkhJSldYWVpnaGlqd3h5eoaHiImKkJaXmJmaoKWmp6ipqrC1tre4ubrAxMXGx8jJytDU1dbX2Nna4OTl5ufo6erz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAECAAMEBQYHCAkKC//EAMMRAAICAQMDAwIDBQIFAgQEhwEAAhEDEBIhBCAxQRMFMCIyURRABjMjYUIVcVI0gVAkkaFDsRYHYjVT8NElYMFE4XLxF4JjNnAmRVSSJ6LSCAkKGBkaKCkqNzg5OkZHSElKVVZXWFlaZGVmZ2hpanN0dXZ3eHl6gIOEhYaHiImKkJOUlZaXmJmaoKOkpaanqKmqsLKztLW2t7i5usDCw8TFxsfIycrQ09TV1tfY2drg4uPk5ebn6Onq8vP09fb3+Pn6/9sAQwAEBAQEBAQEBAQEBgYFBgYIBwcHBwgMCQkJCQkMEwwODAwODBMRFBAPEBQRHhcVFRceIh0bHSIqJSUqNDI0RERc/9sAQwEEBAQEBAQEBAQEBgYFBgYIBwcHBwgMCQkJCQkMEwwODAwODBMRFBAPEBQRHhcVFRceIh0bHSIqJSUqNDI0RERc/9oADAMBAAIRAxEAAAH3/bVttW21baKnVRdMbDMXyabbBttq22rbattq22rYHP6891zzLej5UdFzvRA89aVe25+zccNc8HqdBkL4+/baO21bbUije0vZ57JOV6PkJJbUePVfMfJK3pz94p/PvTcXZa0qziW+5y2x6Oklk98v2ttg221cY/rwez890jA3P8vfwVF6d5z7fjt9t1cu2sVN76hzbzwvdvqnMLG06fmOn5O/bbl7dtq4sBwe581d+J+2eJu7n0fyHdfP3XF9L6by9XJOOGpdM3fSch1++PfsLCv87otOn5jp/P8AV225e3bauLAcHufNXfiftvj7a0m29by49b8k9c8/0PJNt6Hn7r+Q7zm6uzr37Dzui06fmOn8/wBXbbl7dtq4yytec9LyLUVHtMWPm/r1nsvgnrlN0bN41ad/1GmNJdVA+TbpK6ss0eenbuOD0ttsujbatX2GZOOa91Ud3mc5ii7fPedDyPRcndSg26+HZ10OPRS9A63nerttj07bVttW21bbUijv9pjwvQWUdHLyV9aEV4nbl7dtq22rbattq22rbattq22rbattq22rbattq//aAAgBAQABBQL/AFXLdIQ5JSiKOdEn8/JOiNyTrk7T/wCLOO6WhokRIP5pciIxJdKV9yf/ABbsCQY7thQUPvFQSJLtkknslClkW8cSU7rt8y5LRkEd0LUgx3aVfeVyZ3Jbrj7AEmO0d1vNtbC5u7i7U7TcrmzdvuFlfuS1WnvHaqU0KiSfuSfvY7pSWYYZ3d3cO2ou9xubz71nvFzbOIwX8P0Fs5LhcjtP3v3Jf3jsuKN4gVJdbJHIJIpIV97a0nu1Q7ZZbei23YXd5c/vnafvfuS/vHZcbn/GbW+uLMxX1huibzZJoWiNci7TYwBc7zb26Zp5rhex/wCP3P752n737kv7x2XG5/xntZ7vcWruLqK2tru/ubw9tj/x+5/fO0/e/cl/eOy43P8AjPY8Nz/2j99j/wAfuf3ztP3v3Jf3jsuN/bzQXHY8Nz/2j99jt5vebn987T979yQEyx2jVcRxAXEcqbvYkLcsMsCzw3P/AGju2s7i7VbbPa2oVdsLhuBJbLQ7T979whMQknXJ3RKuNlVtdovNikS76CaXa7TY442q4RGlSlLPaK5WlhCa/dkt0SOSFcf3I51xuSXCJci5PuR2y1uOJEf8zJaJU1oUg9p/8W7RwrkcduiP+cKQoSWjIIc/+LJQpZjtEj/UC40SBUSVISkJH+q//9oACAEDEQE/Aez38X3/AHXsFmmM4zG6Bsd+bqMeH8R5/IeXN1eTLx+GP5B6f+H1X/WNhknjNwlTh66MuMv2n8/R88js6rJn23hrZ6yjyXkn8yjpxCPudTP24/l/aKevjj+3p8I2eu7kyY/pup/hS9vJ/iS8H/A5Mc8Rqcaemn1AlWHkeoPhjLcPI/rX56+7PFlmYSr7ijJi9uOT7MWXJYEq4sPVYuohPdnuV/2vIOkYykRGIJJ9A9OJ4xHF1mQHdxHGeS588gZYYfZCJIoer0H8D/go6z/HP/CXqv8AJOm/wy/2rh6vJhGz8eP1hLwx6fpOpEsuOZxiPM4kXX+Bl1cMIOPo4bR6zP4i9KTLqsJJsmYc/wDGy/7/AJeg/gf8FHWf45/4S9SCej6cgcAyv/X06L+F13/WLTowT1OGhf3Bz/xsv+/5eg/gf8FHWePD08jLN98ybEfR/WZt18bf8WuGWHpup/AfZyfl/ZL0/T5sMOthOBs4+P6/4GHQiAE+qnsH+KPxFPUbBs6aHtx/2JRmxZ/tzxqX+PH/AHy9PiOHHsJvm9ZwjkG2cbDm6Aj7sJsfkUgg0RRemy5Biz/cfthY/okmRuRsuHpcmbkCo/mXD02LDyBcvzPdlwY8w++P+f1YdJLGM8RIETjQcPRY8fM/ul/sPr//2gAIAQIRAT8B7Payfb9v4jQZRlE1IUe/Hhnl8Dj83F08MfPmX5lzfj6f/f8AZwjMVIW5eklHnHyPy9e3BDFf8z8X5Hw+H3ZZJbOnhvl+foGPxxmN2fMd/pt8RZw6jpvxj3Mf+NHz/nYTjMXE2544SLycH8/VkKPr/n19uGSERIegRjyHJKFSy48dExvmi9Nl6ecNuCo1/Z8EaSlGAMpEAD1L1GzKZZekxEbOZZBwHFijUcsvukRfL1f8X/MNY/hj/gD0X+VdT/gi5ukxZjv/AAZPScfKc/V9MY4skBlMuISBqz/Vj0k8xGTrJ7vygPwh6kCPS5gBQEC4v4WP/f0PV/xf8w1j+GP+APRyA6vqATyRGtOs/jdD/wBZdOsIHTZrNfaQ4v4WP/f0PV/xf8w1jPJmG3H9sRwZer+mx163/jXyw6nqOn4yfzcf5/2g5+ow5Z9FOExQy83xX+FydfZMOljvP+Mfwh9o5Dv6iZnL/YB9vJi5wm4/4pc2T3J7qrjWMpQNxNFxdWDxk4/qgg8gufHD3MP2/ilRQABQFBydRDH62fyDkzzyeTQ/Id2PLPGftP8AmZdTGZxEitsrLl6qc+I/aP8AY/X/AP/aAAgBAQAGPwL/AFXRPUf1NMnyfofT+f11Po/QenZH+T2orqH630n+bqouiOkfr+4j/J71B1dJPxdUmo+/VRoHSP8AF1Jqe9EirMlwsUHHyDMGdBwBUKJPydYjUejoe9UmjovQ/q+8UE9QdeKfXtQDV5Smg9GY7VIkV8PZH2+bynkr6DyH2dgEKyj/AGFcPs9GEK6Jf2VcfsLqnqH6+9V6D9b5SPur/tF0XqP1vJB/Bj6JRKuFB/CXSRdEfsJ4f6P3gmT6WP0VxH2tMyUqTX1FC/VX63Tgl/5J+7J/aPaT7HNbXsYCc1Jy4pIBpq+dYLGuuFek/IsxyoKVeh+5jBHX1PkPmXz72RKlD9r2R8h5sQRR0ixUaniaNX2dv8k/dk/tHtJ9juP92r/4M6wr6fNB9ksQ3SAmTyCvX+SWV230qPT8w/uvloQVL/ZA1fNvlaccAf4S+RYISaaV/IPl6vmTSFSvj/U0/wC61tX2dv8AJP3ZP7R7SfY7n/dq/wDg3cJX9LF6K4j5F++iGpWE/AmvCr+lV0fsD2e6f91ravs7f5J+7J/aPaT7Hc/7tX/wbuXD/wAI/cT/ALrW1fZ2/wAk/dk/tHtJ9jlMsZAVIopPkanuXD/wj9wXHLPKwUMj8fRq+zt/kn7qwP2i6y6fB4RD+4zHcIFDx8w+ZZKp/IPD7C+XMgoV6Flw/wDCPakEdR5q4JH2sSXJEi/j7I+x/Rp0+LxUKKdU9Q/W/wDJP3VLSip+D14enfpP2PlXMY+3+pqXZqzH7B4/YXDDHGTJ9Fp8nzL1eX8gez9vqxHAgUHD0dVGvcJPUP1vmY0VT71eCvV6jT1+56j0LElONP1vqP3KnpD6R9v8zVGh/U6KFO6P8nv0jT1deKvX+cooVDrH+DoRq0f5LokVdZNT6eX+oKKDCDwFP1OiRQf6s//EADMQAQADAAICAgICAwEBAAACCwERACExQVFhcYGRobHB8NEQ4fEgMEBQYHCAkKCwwNDg/9oACAEBAAE/If8A9LkP6VQsCuz5uePtf1/+flr0ubPi+l/f/wCBIj+lWcT+Ts//AC8w/B22b/sX/wCD9L/oEoHZXIGfX+ylieQ//G0IHbecfv8A0VUpO3/sw6odJTJh+Wr3gyxe3VQPMJc/TUUETp/7Lmv02IH3f4yiOn/4ZOgp4T4s8D1P7/4CUrouGI2D/LQDPJw3v+iyARZ4fi/4/PKf9lG6DhI/tWZ/pX/PRYz4bt/qkX0FzY+//wAOVP8ABsZ8t/jbwU3f9yv/AMGC+3CtPgeX3/2//FKKPsy9f7XpDl/+8e7Ay8Pyv9WeHxH9t/zPj/8AD/iPP/P0KB8DwlAR6+eLmwEFL+CpQ/yMPz7P/wAElkXXLBDYk4b9ixPrudCIOjb+v/D/AJz/AOHH/wCH/Eef+foV/n/K91KdH0dfJUqrkfl5f3Z7PLcGurGj7HX3RQwajB/n1cG3AkfAKdeUuB6HRf8AEer+v/D/AJz/AOHH/wCH/Eef+foV/k/L/sukO7L/AAxrvjBI8ieqqxlmY+fL8/8Af8R6v6/8P+c/+HH/AOH/ABHn/n6Ff5Py/wC/oN/S/p/+D/Eer+v/AA/5z/4cf/h/xHn/AJ+hXXYdoiQ+fX/f0G/pf0//AATyI4ELCNc39f8Ah/zn/wAOP/wgYqwB81naHhz9tjDU8cP91skokS/JQEbdll/wVh4Nefjz9X9Bv6X9P+T6Awn5H+lJOtzDeu33Y0Aj+X+qO8IHn6bOf0q8/wD+EZKjLyd/q5ajxcf9ZnPvo2dCPXGfK6abgLrB/Q/dyWZ1TEzPEUQIjZIHy5/hRxCiBB+Cyjr3/wBbA9R/StIka6d8/wD4p6Hqf3ezvBx/+DHH/EywhNwFpyZ/B0f/AIIv5F5fgo/Z2uf/AMhBxswvq/xllzX6f/xIn+Q4scj3P6//ADGxE6a5Kz7/ANNZVA6f+JNuv4sSn+R90AIOP/z9w/D2VF39ygxPAf8A6Z//2gAMAwEAAhEDEQAAEAAABDigAAAAABwvg5QwAAHQ1gOR/ogACa6AB62QAAKawFmNIQQAKZgEgFCQQAIAVRCMlCwAEbyvYAEwAAAAA+iAAAAAAAAAAAAAAP/EADMRAQEBAAMAAQIFBQEBAAEBCQEAESExEEFRYSBx8JGBobHRweHxMEBQYHCAkKCwwNDg/9oACAEDEQE/EPwOxD9QgIuFvk/GMmvx5v8Ai0w/1b835v1352/y+c6fzPmzyPou3+IQCCPInX4NTR1Rgne/S+6R/NWBB+Fc/kEoF9esff6XwR/k5vutbl8b0/kxgnb6D+f0i1ETjTQHZvooy5D4efkhccWdhM/jZcnwN/wH/XnAzYDVuBr+A14FfiK06ReDnL97p9P1r6+PNFiccjH2+kAPeuH1X0tKMZy/8BKWQKuq783679fwJ+tfWe46YODeG+fpPs+b4YZw3Ae2/Xfr+BNwkgmHX5fmeIzjOLj9MuSJfn3fb6QgWPPJ27HdsG+Tm/wQ5wfk5y+qwB8NC5/h82QPKE40fVoG+H/Vt/uC/h+ZU4OETEjEy5nnX22eNTtXWwv2Ffx9bE/dF/H0/FhNH4HA/m15JXh372Jn97p/Hz/P/wB//9oACAECEQE/EPwGTUdjxrImh8P43ty+a6/7Y6P6R+RfrPysdx/U/K0G/pH+ZEUTE7H8GebO4eL6Z9bgfAB+QEIM+YcfnMgVx9FPtvdvOd8XA+yx3H9T8yeufAP02XJAPJjFPr6g29T8nHw3CDR5X9zI99QZ/kH+/OQmymBPNWeQ85QPlmIo2uebzwXf7fr30v0b6WQaHPAD9/rODv8AjgFqTnK8/wAkYYGAYBnxfqH0u/2/XvpFFMIvLh8efp/y8xz0TXNU6PvfqH0u/wBj+JBHPA+CDy63v1H1soEvj1ff6zsWrbXXo9XHC8PF/kn7KE8flBO35ovx/DFlXAI/U9EP+oWIevp6/kgQCPSckxMfC8afxChB0BhbY/onP0t8/YT+fr+LTcfyuR/iYasA54+1ofxvb+f/AL//2gAIAQEAAT8Q/wD0pQ1uIxnh09vfwWXj5pBjseLHee5v27//ADx3wXf7ePutS/34/Ll/ivD8X9b+N4hOS7DDJXD0vP3YFIcmfIf/AJcCEvZ8B3Y9KZI4e3r6rKqsrr/x4b/mfH/ePIiQlyHcQ7/h2VoI4ST/APHzIQSCs45xDv8Ah23myAkr/wBD9gwYfLwXIGqwnkiaUeVF4oFjHSxPVaTIghj8D93AuyEJ9P8A3yLCN+Q4bFNxx5f480AQRJE0f/wlMB8mUML0S5IXToenX8f848iBK1CBBIAgfQHxZcpyoTwavt7aJy4vx7B9svu+ffNTgt1ET2/gz1UfCQMz6M+Jvksq0NgID2d/VRFEhMR6oKgKrABKvqz7eeNBhlaOEImfLf8A8LUiIwjCPhY5vHHh8/4aMT6JwJ8icNDk+Cgbxvo5eiy7l5Mf7r8PX/4f/v4o78Mwk88yB1P5KAaGpKfOeISPTQlZMLHwjpZkTd+p+z4vJ/hv/wCMh/hfLcU1tyh5VBuu2WAvmHHxz8Bk+LugfEPDr2Cn/wCBZgz8zmD6JfVWloAgdB5fCsvgKxdHzgUHPe30X/IeH/P8B5//ABkP8L5biG6HULQ+dPc+h8zcb8QxIiHCeBnpYQ5KcBejA/EPprZ4TQownJDtgHdPL+ARzxZ5IHtovo435wF/EHuoU8wmL0M9QfP/AD//ACHh/wA/wHn/APGQ/wAL5f8Au1BEQR5EkaWCetQeeXOpD4oNI6DUYHOS3mOqaR8puySHJefoF55/7/8A5Dw/5/gPP/4yH+F8v/4Nv+C8f/ic/wD8h4f8/wAB5/8AxkP8L5aq75ExtMmHVvr/AL/gvH/4HPPra0y3Dj1gnOTPd/yHh/z/AAHn/wDCJG0CV9AoRFdm4fo+q1xZOG+e1wJqsL5JimdiD/yp9Rk+KOETwIHbJD7SX/BeP+uaAoGR7Mn1J9VrJgwDSeZnmXoK4+UJEQOgOFNFBogP7vi7qHcMPZ39X/AeT/8AC3n0aVU6vHwqL4fn9vP3/wBmoEym/Mf2VpwMCfqL4nGq0dIwkcwHwQfbVVgYgjwAENnija4S/wAd9hno3EFqSnRxWvkFceg6P+pCDHIfl38NkO0JMIMAyc//ABRJI6eX04f5rq7Ob/fx9/8A4IuG90n25KwuDgg+SeLJ4Dhz4j/8Ea5dhw/w1sK3kaH9/wBH/wCQAgIkI6JYpuefL/Hi+DYLvwPD/wAeG/rfx/6SxnuZ+PP1cwLpwfTr+f8A8zmogElyHcy7/h5vL8QIS/rfxvnIEcfJ4LEpzQ4fNAgAEAEAf/nwpQ4M+BKhz0GHol990aI4CD/9M//Z";}), "./images/file.png": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; -module.exports = __webpack_require__.p + "7baf20ff2eb011d3.png";}), +module.exports = __webpack_require__.p + "cee6b2eecb9ff70a.png";}), "./images/file.svg": (function (module) { "use strict"; module.exports = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPgo=";}), diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt index e165812b4398..55dd6c2480c1 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt @@ -1,23 +1,23 @@ ```css title=main.css -._f_module__f-1--____33039942d115f59c__33 { +.___f_module____f-1--___af10a85c64a6b515_af1 { color: black; } -._f_module__f--____33039942d115f59c__33 {} -._d_module__d-1--____3adea2b80c7f9bb9__3a { +.___f_module____f--___af10a85c64a6b515_af1 {} +.___d_module____d-1--___a41e34edaa1ca3c_a41 { color: green; } -._d_module__d--____3adea2b80c7f9bb9__3a {} -._b_module__b-1--____42eb20d659c9bbbb__42 { +.___d_module____d--___a41e34edaa1ca3c_a41 {} +.___b_module____b-1--___eca6dd2253f6b569_eca { color: red; } -._b_module__b--____42eb20d659c9bbbb__42 {} -._style_module__chain2--____7dc7309cdb55212a__7d { +.___b_module____b--___eca6dd2253f6b569_eca {} +.___style_module____chain2--___afc435275e612570_afc { background: blue; } -._style_module__chain1--____7dc7309cdb55212a__7d { +.___style_module____chain1--___afc435275e612570_afc { background: green; } -._style_module__root-class--____7dc7309cdb55212a__7d { +.___style_module____root-class--___afc435275e612570_afc { background: red; } @@ -34,30 +34,30 @@ __webpack_require__.r(__webpack_exports__); "./b.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "b": "_b_module__b--____42eb20d659c9bbbb__42" + " " + "_b_module__b-1--____42eb20d659c9bbbb__42", - "b-1": "_b_module__b-1--____42eb20d659c9bbbb__42", + "b": "___b_module____b--___eca6dd2253f6b569_eca" + " " + "___b_module____b-1--___eca6dd2253f6b569_eca", + "b-1": "___b_module____b-1--___eca6dd2253f6b569_eca", }); }), "./d.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "d": "_d_module__d--____3adea2b80c7f9bb9__3a" + " " + "_d_module__d-1--____3adea2b80c7f9bb9__3a", - "d-1": "_d_module__d-1--____3adea2b80c7f9bb9__3a", + "d": "___d_module____d--___a41e34edaa1ca3c_a41" + " " + "___d_module____d-1--___a41e34edaa1ca3c_a41", + "d-1": "___d_module____d-1--___a41e34edaa1ca3c_a41", }); }), "./f.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "f": "_f_module__f--____33039942d115f59c__33" + " " + "_f_module__f-1--____33039942d115f59c__33", - "f-1": "_f_module__f-1--____33039942d115f59c__33", + "f": "___f_module____f--___af10a85c64a6b515_af1" + " " + "___f_module____f-1--___af10a85c64a6b515_af1", + "f-1": "___f_module____f-1--___af10a85c64a6b515_af1", }); }), "./style.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "chain1": "_style_module__chain1--____7dc7309cdb55212a__7d" + " " + "_style_module__chain2--____7dc7309cdb55212a__7d" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], - "chain2": "_style_module__chain2--____7dc7309cdb55212a__7d" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], - "root-class": "_style_module__root-class--____7dc7309cdb55212a__7d" + " " + "_style_module__chain1--____7dc7309cdb55212a__7d" + " " + "a" + " " + __webpack_require__("./b.module.css")["b"] + " " + "_style_module__chain2--____7dc7309cdb55212a__7d" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], + "chain1": "___style_module____chain1--___afc435275e612570_afc" + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], + "chain2": "___style_module____chain2--___afc435275e612570_afc" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], + "root-class": "___style_module____root-class--___afc435275e612570_afc" + " " + "___style_module____chain1--___afc435275e612570_afc" + " " + "a" + " " + __webpack_require__("./b.module.css")["b"] + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], }); }), diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/snapshot/output.snap.txt index 7801d3245c32..b038d1133eaa 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/snapshot/output.snap.txt @@ -1,5 +1,5 @@ ```css title=main.css -._style_module__foo--____7dc7309cdb55212a__7d { +.___style_module____foo--___afc435275e612570_afc { color: hotpink; } @@ -17,7 +17,7 @@ console.log(_style_module_css__WEBPACK_IMPORTED_MODULE_0__); "./style.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "foo": "_style_module__foo--____7dc7309cdb55212a__7d", + "foo": "___style_module____foo--___afc435275e612570_afc", }); }), diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/snapshot/output.snap.txt index 3768c4159d73..b38fe8fc5b72 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/snapshot/output.snap.txt @@ -1,4 +1,4 @@ -```html title=default.248cbd4291badac0.html +```html title=default.ef8306b113a7b5d7.html @@ -10,7 +10,7 @@ ``` -```html title=index.248cbd4291badac0.html +```html title=index.ef8306b113a7b5d7.html diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/snapshot/output.snap.txt index e5ec389d2555..1568a39ffe67 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/snapshot/output.snap.txt @@ -9,10 +9,10 @@ img.src = imgSrc2; }), "./react.svg": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; -module.exports = __webpack_require__.p + "ef0c5aab88bb335e.svg";}), +module.exports = __webpack_require__.p + "ef805cb3080d4db4.svg";}), "./vue.svg": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; -module.exports = __webpack_require__.p + "7908863e290b1fc6.svg";}), +module.exports = __webpack_require__.p + "adc3645d19cb2dbe.svg";}), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/snapshot/output.snap.txt index 80391e585b9d..dd02754f2da6 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/snapshot/output.snap.txt @@ -55,7 +55,7 @@ __webpack_async_result__(); "./wasm.wasm": (function (module, exports, __webpack_require__) { "use strict"; var __webpack_instantiate__ = function ([WEBPACK_IMPORTED_MODULE_0, WEBPACK_IMPORTED_MODULE_1]) { -return __webpack_require__.v(exports, module.id, "7ff106a99b84c158" , { +return __webpack_require__.v(exports, module.id, "99f401a36b8fee81" , { "./module": { "getNumber": WEBPACK_IMPORTED_MODULE_0["getNumber"] }, @@ -71,7 +71,7 @@ var WEBPACK_IMPORTED_MODULE_1 = __webpack_require__("./module2.js"); var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([WEBPACK_IMPORTED_MODULE_0, WEBPACK_IMPORTED_MODULE_1]); var [WEBPACK_IMPORTED_MODULE_0, WEBPACK_IMPORTED_MODULE_1] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__; - await __webpack_require__.v(exports, module.id, "7ff106a99b84c158" , { + await __webpack_require__.v(exports, module.id, "99f401a36b8fee81" , { "./module": { "getNumber": WEBPACK_IMPORTED_MODULE_0["getNumber"] }, diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/snapshot/output.snap.txt index af4a0c1edcea..e73655adfb58 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/snapshot/output.snap.txt @@ -13,7 +13,7 @@ __webpack_async_result__(); } catch(e) { __webpack_async_result__(e); } });}), "./v128.wasm": (function (module, exports, __webpack_require__) { "use strict"; - module.exports = __webpack_require__.v(exports, module.id, "1a19b30af21700aa" );}), + module.exports = __webpack_require__.v(exports, module.id, "83b6564dd2e8778e" );}), },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/index.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/index.js index 55e36ab9f262..44d2c13b0f01 100644 --- a/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/index.js +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/index.js @@ -4,7 +4,7 @@ test; it("should concatenate css", () => { expect(styles).toMatchObject({ - foo: "foo_css__foo", - test: "foo_css__test" + foo: "__foo_css__foo", + test: "__foo_css__test" }); }); diff --git a/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/a.module.css b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/a.module.css new file mode 100644 index 000000000000..38323d709652 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/a.module.css @@ -0,0 +1,3 @@ +.a-main { + color: green; +} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/index.js b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/index.js new file mode 100644 index 000000000000..2b3ad4f962f7 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/index.js @@ -0,0 +1,10 @@ +import * as classes from "./style.module.css"; +import legacyClasses from "./legacy/index.css"; + +const crypto = require("crypto"); +const createHash = str => crypto.createHash('md4').update(str).digest('hex').slice(0, 20).replace(/^\d+/, ""); + +it("should have consistent hash", () => { + expect(classes["container-main"]).toBe(`${createHash("./style.module.css")}-container-main`) + expect(legacyClasses["legacy-main"]).toBe(`${createHash("./index.css")}-legacy-main`) +}); diff --git a/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/legacy/index.css b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/legacy/index.css new file mode 100644 index 000000000000..d863b4d50386 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/legacy/index.css @@ -0,0 +1,3 @@ +.legacy-main { + color: blue; +} diff --git a/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/style.module.css b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/style.module.css new file mode 100644 index 000000000000..3fff4e9e7e21 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/style.module.css @@ -0,0 +1,3 @@ +.container-main { + color: red; +} diff --git a/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/webpack.config.js b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/webpack.config.js new file mode 100644 index 000000000000..6d8022bbc415 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/css/rspack-issue-6435/webpack.config.js @@ -0,0 +1,41 @@ +const path = require("path"); + +/** @type {import('@rspack/core').Configuration} */ +module.exports = { + mode: "development", + entry: "./index.js", + output: { + hashFunction: "md4", + cssFilename: "main.css" + }, + module: { + parser: { + "css/auto": { + namedExports: true, + }, + }, + generator: { + "css/auto": { + exportsConvention: "as-is", + localIdentName: "[hash]-[local]", + }, + }, + rules: [ + { + include: path.resolve(__dirname, "legacy"), + test: /\.css$/, + type: "css/module", + parser: { + namedExports: false, + }, + generator: { + exportsConvention: "camel-case", + localIdentName: "[hash]-[local]", + } + }, + ] + }, + experiments: { + css: true, + } +}; diff --git a/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/index.js b/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/index.js index fbbd4af5affd..a6d2a8a9f7d8 100644 --- a/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/index.js +++ b/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/index.js @@ -1,11 +1,10 @@ import test from "./index.module.css"; import { res } from "./lib.js"; - it("should not mangle css module", () => { res; // Using this to trigger a none provided export test.res; - expect(test.test).toBe("-_921b05f8c9c16ca9ea84-test"); + expect(test.test).toBe("-ca56f23580d7bbb484-test"); }); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/2.snap.txt index ce5e15ff5f83..a9b35f40ec2c 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/2.snap.txt @@ -38,7 +38,7 @@ module.exports = 3; }), "./raw.png": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; -module.exports = __webpack_require__.p + "f7f4f00355f310234f70.png";}), +module.exports = __webpack_require__.p + "a09d8e0f399c215faa79.png";}), },function(__webpack_require__) { // webpack/runtime/get_full_hash 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 840ed57f0da4..f3a2a8bb9eca 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 @@ -1,9 +1,9 @@ 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'); + 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['btnInfoIsDisabled']).toBe('__index_module_css__btn-info_is-disabled'); done(); }); NEXT(require("../../update")(done)); diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/1.snap.txt index 2d369a03756c..0bd69a4c7e7f 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/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: 487 +- Update: main.LAST_HASH.hot-update.js, size: 491 ## Manifest @@ -34,8 +34,8 @@ self["webpackHotUpdate"]('main', { "./index.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __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-disabled": "__index_module_css__btn-info_is-disabled", + "btnInfoIsDisabled": "__index_module_css__btn-info_is-disabled", }); }), diff --git a/packages/rspack-test-tools/tests/statsAPICases/basic.js b/packages/rspack-test-tools/tests/statsAPICases/basic.js index 0dcc23730059..7baa730c6c8c 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/basic.js +++ b/packages/rspack-test-tools/tests/statsAPICases/basic.js @@ -34,7 +34,7 @@ module.exports = { Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 entry ./fixtures/a - Rspack compiled successfully (57e46af248a1c1fe076f)" + Rspack compiled successfully (ee9a5ee8da42dac2c2aa)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/exports.js b/packages/rspack-test-tools/tests/statsAPICases/exports.js index 253d5c1e7657..a2a14e75b794 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/exports.js +++ b/packages/rspack-test-tools/tests/statsAPICases/exports.js @@ -44,7 +44,7 @@ module.exports = { ./fixtures/esm/abc.js [no exports] [no exports used] - Rspack compiled successfully (4b5e3314a79376e83a18)" + Rspack compiled successfully (36dd148024fa89ee453a)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/to-string.js b/packages/rspack-test-tools/tests/statsAPICases/to-string.js index a24991a0fe3d..eb0efed65fa9 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/to-string.js +++ b/packages/rspack-test-tools/tests/statsAPICases/to-string.js @@ -31,7 +31,7 @@ module.exports = { help: You may need an appropriate loader to handle this file type. - Rspack compiled with 1 error (3fa2fc6e23dccdd9a108)" + Rspack compiled with 1 error (2269ff26c17a6bb04d0e)" `); } }; diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$a86b1707b4af75e0f088$.css b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$048dd0ea10a262087819$.css similarity index 100% rename from plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$a86b1707b4af75e0f088$.css rename to plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$048dd0ea10a262087819$.css diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$a86b1707b4af75e0f088$.css b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$048dd0ea10a262087819$.css similarity index 100% rename from plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$a86b1707b4af75e0f088$.css rename to plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$048dd0ea10a262087819$.css diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js index a59b5770bffa..cb12f77f8ffe 100644 --- a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js +++ b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js @@ -75,7 +75,7 @@ __webpack_require__.e = function (chunkId) { // webpack/runtime/get_full_hash !function() { __webpack_require__.h = function () { - return "a86b1707b4af75e0f088"; + return "048dd0ea10a262087819"; }; }(); diff --git a/plugin-test/css-extract/cases/content-entries-with-same-import/expected/one_js.$34ea7e852b73f29ba7a5b065d4eec971$.css b/plugin-test/css-extract/cases/content-entries-with-same-import/expected/one_js.$2faf8431c36246aaa99efe65186ef7b1$.css similarity index 100% rename from plugin-test/css-extract/cases/content-entries-with-same-import/expected/one_js.$34ea7e852b73f29ba7a5b065d4eec971$.css rename to plugin-test/css-extract/cases/content-entries-with-same-import/expected/one_js.$2faf8431c36246aaa99efe65186ef7b1$.css diff --git a/plugin-test/css-extract/cases/content-entries-with-same-import/expected/two_js.$1286cc6ec04dae701cfb317f9b9aa178$.css b/plugin-test/css-extract/cases/content-entries-with-same-import/expected/two_js.$108a632b35566ba6e10f21437dc1e449$.css similarity index 100% rename from plugin-test/css-extract/cases/content-entries-with-same-import/expected/two_js.$1286cc6ec04dae701cfb317f9b9aa178$.css rename to plugin-test/css-extract/cases/content-entries-with-same-import/expected/two_js.$108a632b35566ba6e10f21437dc1e449$.css diff --git a/plugin-test/css-extract/cases/contenthash-1/expected/main.$e29a42ed09bda57bc430ed9ccfa30f63$.css b/plugin-test/css-extract/cases/contenthash-1/expected/main.$2948667d05523e0bdd4b433a8b432330$.css similarity index 100% rename from plugin-test/css-extract/cases/contenthash-1/expected/main.$e29a42ed09bda57bc430ed9ccfa30f63$.css rename to plugin-test/css-extract/cases/contenthash-1/expected/main.$2948667d05523e0bdd4b433a8b432330$.css diff --git a/plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryA.$7102da6560e321434f72cdf38a5f9e22$.css b/plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryA.$63eb4b2b7412624c84340d8ef2383cb3$.css similarity index 100% rename from plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryA.$7102da6560e321434f72cdf38a5f9e22$.css rename to plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryA.$63eb4b2b7412624c84340d8ef2383cb3$.css diff --git a/plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryB.$ea9aedf549e60226448ece39da68f162$.css b/plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryB.$7dc4057bc127528eb3d6e30affb70fc5$.css similarity index 100% rename from plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryB.$ea9aedf549e60226448ece39da68f162$.css rename to plugin-test/css-extract/cases/contenthash-multiple-entries/expected/entryB.$7dc4057bc127528eb3d6e30affb70fc5$.css diff --git a/plugin-test/css-extract/cases/contenthash/expected/1.main.$b8738e31859438bcaaf82f0e18ccb8e1$.css b/plugin-test/css-extract/cases/contenthash/expected/1.main.$fcf981e297c26c27907740d422c8fbb8$.css similarity index 100% rename from plugin-test/css-extract/cases/contenthash/expected/1.main.$b8738e31859438bcaaf82f0e18ccb8e1$.css rename to plugin-test/css-extract/cases/contenthash/expected/1.main.$fcf981e297c26c27907740d422c8fbb8$.css diff --git a/plugin-test/css-extract/cases/contenthash/expected/2.main.$22a4c275951727d855be6683d3f1b3b7$.css b/plugin-test/css-extract/cases/contenthash/expected/2.main.$a033229f200a2cfbacbc9213dd60155a$.css similarity index 100% rename from plugin-test/css-extract/cases/contenthash/expected/2.main.$22a4c275951727d855be6683d3f1b3b7$.css rename to plugin-test/css-extract/cases/contenthash/expected/2.main.$a033229f200a2cfbacbc9213dd60155a$.css diff --git a/plugin-test/css-extract/cases/devtool-source-map-from-loaders/expected/main.css.map b/plugin-test/css-extract/cases/devtool-source-map-from-loaders/expected/main.css.map index 751d41cb6863..3eb623ccfa8f 100644 --- a/plugin-test/css-extract/cases/devtool-source-map-from-loaders/expected/main.css.map +++ b/plugin-test/css-extract/cases/devtool-source-map-from-loaders/expected/main.css.map @@ -1 +1 @@ -{"version":3,"file":"main.css","sources":["webpack:///./style.css?aeac"],"sourcesContent":["body {\n background: red;\n}\n"],"names":[],"mappings":"AAAA;EACE,eAAe;AACjB"} \ No newline at end of file +{"version":3,"file":"main.css","sources":["webpack:///./style.css?86c4"],"sourcesContent":["body {\n background: red;\n}\n"],"names":[],"mappings":"AAAA;EACE,eAAe;AACjB"} \ No newline at end of file diff --git a/plugin-test/css-extract/cases/devtool-source-map/expected/main.css.map b/plugin-test/css-extract/cases/devtool-source-map/expected/main.css.map index 751d41cb6863..3eb623ccfa8f 100644 --- a/plugin-test/css-extract/cases/devtool-source-map/expected/main.css.map +++ b/plugin-test/css-extract/cases/devtool-source-map/expected/main.css.map @@ -1 +1 @@ -{"version":3,"file":"main.css","sources":["webpack:///./style.css?aeac"],"sourcesContent":["body {\n background: red;\n}\n"],"names":[],"mappings":"AAAA;EACE,eAAe;AACjB"} \ No newline at end of file +{"version":3,"file":"main.css","sources":["webpack:///./style.css?86c4"],"sourcesContent":["body {\n background: red;\n}\n"],"names":[],"mappings":"AAAA;EACE,eAAe;AACjB"} \ No newline at end of file diff --git a/plugin-test/css-extract/cases/js-hash/expected/style.$8962f7751ac742a81f8cd8ef907bc50a$.2.css b/plugin-test/css-extract/cases/js-hash/expected/style.$2ebc9424ae217f7031ea75743effd066$.2.css similarity index 100% rename from plugin-test/css-extract/cases/js-hash/expected/style.$8962f7751ac742a81f8cd8ef907bc50a$.2.css rename to plugin-test/css-extract/cases/js-hash/expected/style.$2ebc9424ae217f7031ea75743effd066$.2.css diff --git a/plugin-test/css-extract/cases/js-hash/expected/style.$59392d4d94762f990e9ea8dfa94f9c34$.1.css b/plugin-test/css-extract/cases/js-hash/expected/style.$fc35cd7d3442366ea0e20c936c0d399c$.1.css similarity index 100% rename from plugin-test/css-extract/cases/js-hash/expected/style.$59392d4d94762f990e9ea8dfa94f9c34$.1.css rename to plugin-test/css-extract/cases/js-hash/expected/style.$fc35cd7d3442366ea0e20c936c0d399c$.1.css diff --git a/plugin-test/css-extract/cases/new-url/expected/ebb93b9cb62e55bcbc35.png b/plugin-test/css-extract/cases/new-url/expected/4d3b8fdfbe46b279f223.png similarity index 100% rename from plugin-test/css-extract/cases/new-url/expected/ebb93b9cb62e55bcbc35.png rename to plugin-test/css-extract/cases/new-url/expected/4d3b8fdfbe46b279f223.png diff --git a/plugin-test/css-extract/cases/new-url/expected/main.css b/plugin-test/css-extract/cases/new-url/expected/main.css index 5a16d881ed1f..ef2c3cf185c8 100644 --- a/plugin-test/css-extract/cases/new-url/expected/main.css +++ b/plugin-test/css-extract/cases/new-url/expected/main.css @@ -3,6 +3,6 @@ body { } a { - background: url(ebb93b9cb62e55bcbc35.png); + background: url(4d3b8fdfbe46b279f223.png); } diff --git a/plugin-test/css-extract/cases/pathinfo-devtool-source-map/expected/main.css.map b/plugin-test/css-extract/cases/pathinfo-devtool-source-map/expected/main.css.map index d5dbd672e73c..d3c9dd3454e1 100644 --- a/plugin-test/css-extract/cases/pathinfo-devtool-source-map/expected/main.css.map +++ b/plugin-test/css-extract/cases/pathinfo-devtool-source-map/expected/main.css.map @@ -1 +1 @@ -{"version":3,"file":"main.css","sources":["webpack:///./style.css?aeac","webpack:///./other.css?5f00","webpack:///./extra.css?e36a"],"sourcesContent":["body {\n background: red;\n}\n","body {\n background: blue;\n}\n","body {\n background: yellow;\n}\n"],"names":[],"mappings":";;;AAAA;EACE,eAAe;AACjB;;;;;ACFA;EACE,gBAAgB;AAClB;;;;;ACFA;EACE,kBAAkB;AACpB"} \ No newline at end of file +{"version":3,"file":"main.css","sources":["webpack:///./style.css?86c4","webpack:///./other.css?264c","webpack:///./extra.css?9c40"],"sourcesContent":["body {\n background: red;\n}\n","body {\n background: blue;\n}\n","body {\n background: yellow;\n}\n"],"names":[],"mappings":";;;AAAA;EACE,eAAe;AACjB;;;;;ACFA;EACE,gBAAgB;AAClB;;;;;ACFA;EACE,kBAAkB;AACpB"} \ No newline at end of file diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/main.css b/plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/main.css index f4204456377a..f98bd63026c4 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-absolute-url-1/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(https://webpack.js.org/foo/61dc21364604d5319600.svg); + background-image: url(https://webpack.js.org/foo/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-2/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url-2/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url-2/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url-2/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/main.css b/plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/main.css index e12b7aadf2a9..d511b18bdbce 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-absolute-url-3/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(https://webpack.js.org./61dc21364604d5319600.svg); + background-image: url(https://webpack.js.org./2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/main.css b/plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/main.css index c69bae0cdbfd..2d9f549df70e 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-absolute-url-4/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(https://webpack.js.org../61dc21364604d5319600.svg); + background-image: url(https://webpack.js.org../2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/main.css b/plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/main.css index c3d161fae446..d7f2a7b5c3d6 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-absolute-url-5/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(/61dc21364604d5319600.svg); + background-image: url(/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/main.css b/plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/main.css index 749772d29aeb..66ce7f20c9d5 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-absolute-url-6/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(//cdn.example.com/assets/61dc21364604d5319600.svg); + background-image: url(//cdn.example.com/assets/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-absolute-url/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-absolute-url/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-absolute-url/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-absolute-url/expected/main.css b/plugin-test/css-extract/cases/publicpath-absolute-url/expected/main.css index d83d1fad3cba..d1bc8b5efdcb 100644 --- a/plugin-test/css-extract/cases/publicpath-absolute-url/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-absolute-url/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(https://webpack.js.org/61dc21364604d5319600.svg); + background-image: url(https://webpack.js.org/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-default-auto/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-default-auto/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-default-auto/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-default-auto/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-default-auto/expected/main.css b/plugin-test/css-extract/cases/publicpath-default-auto/expected/main.css index e1334d2985ae..afa9a79cec01 100644 --- a/plugin-test/css-extract/cases/publicpath-default-auto/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-default-auto/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(61dc21364604d5319600.svg); + background-image: url(2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-empty-string/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-empty-string/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-empty-string/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-empty-string/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-empty-string/expected/main.css b/plugin-test/css-extract/cases/publicpath-empty-string/expected/main.css index e1334d2985ae..afa9a79cec01 100644 --- a/plugin-test/css-extract/cases/publicpath-empty-string/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-empty-string/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(61dc21364604d5319600.svg); + background-image: url(2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-function-2/expected/webpack-5/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-function-2/expected/webpack-5/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-function-2/expected/webpack-5/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-function-2/expected/webpack-5/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-function/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-function/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-function/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-function/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-function/expected/nested/again/style.css b/plugin-test/css-extract/cases/publicpath-function/expected/nested/again/style.css index 1eeff1f96caf..0b24d61dbbd9 100644 --- a/plugin-test/css-extract/cases/publicpath-function/expected/nested/again/style.css +++ b/plugin-test/css-extract/cases/publicpath-function/expected/nested/again/style.css @@ -1,5 +1,5 @@ body { background: green; - background-image: url(../../61dc21364604d5319600.svg); + background-image: url(../../2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-function/expected/nested/style.css b/plugin-test/css-extract/cases/publicpath-function/expected/nested/style.css index 89722255b7b7..b4b980dfd859 100644 --- a/plugin-test/css-extract/cases/publicpath-function/expected/nested/style.css +++ b/plugin-test/css-extract/cases/publicpath-function/expected/nested/style.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(../61dc21364604d5319600.svg); + background-image: url(../2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-loader-auto/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-loader-auto/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-loader-auto/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-loader-auto/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-loader-auto/expected/main.css b/plugin-test/css-extract/cases/publicpath-loader-auto/expected/main.css index e1334d2985ae..afa9a79cec01 100644 --- a/plugin-test/css-extract/cases/publicpath-loader-auto/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-loader-auto/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(61dc21364604d5319600.svg); + background-image: url(2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-1/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-1/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-1/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-1/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-1/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-1/expected/main.css index aebe84a71224..fcd63b67dcc1 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-1/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-1/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(/static/img/../deep61dc21364604d5319600.svg); + background-image: url(/static/img/../deep2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-2/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-2/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-2/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-2/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-2/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-2/expected/main.css index 89722255b7b7..b4b980dfd859 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-2/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-2/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(../61dc21364604d5319600.svg); + background-image: url(../2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-3/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-3/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-3/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-3/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-3/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-3/expected/main.css index c3d161fae446..d7f2a7b5c3d6 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-3/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-3/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(/61dc21364604d5319600.svg); + background-image: url(/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-4/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-4/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-4/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-4/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-4/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-4/expected/main.css index 3310cbe753f5..957b734a55ce 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-4/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-4/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(./61dc21364604d5319600.svg); + background-image: url(./2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-5/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-5/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-5/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-5/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-5/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-5/expected/main.css index 392434604fc7..6a2cc5a43cf9 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-5/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-5/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(../static/61dc21364604d5319600.svg); + background-image: url(../static/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-6/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-6/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-6/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-6/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-6/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-6/expected/main.css index 77185243ce61..c41a5d803428 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-6/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-6/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(./static/61dc21364604d5319600.svg); + background-image: url(./static/2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-7/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative-7/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative-7/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative-7/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative-7/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative-7/expected/main.css index 6fdfdb4cfdf5..d65456129a53 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative-7/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative-7/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(static61dc21364604d5319600.svg); + background-image: url(static2b438a6f1910279f8b62.svg); } diff --git a/plugin-test/css-extract/cases/publicpath-path-relative/expected/61dc21364604d5319600.svg b/plugin-test/css-extract/cases/publicpath-path-relative/expected/2b438a6f1910279f8b62.svg similarity index 100% rename from plugin-test/css-extract/cases/publicpath-path-relative/expected/61dc21364604d5319600.svg rename to plugin-test/css-extract/cases/publicpath-path-relative/expected/2b438a6f1910279f8b62.svg diff --git a/plugin-test/css-extract/cases/publicpath-path-relative/expected/main.css b/plugin-test/css-extract/cases/publicpath-path-relative/expected/main.css index 281c6b8db674..1b387f017439 100644 --- a/plugin-test/css-extract/cases/publicpath-path-relative/expected/main.css +++ b/plugin-test/css-extract/cases/publicpath-path-relative/expected/main.css @@ -1,5 +1,5 @@ body { background: red; - background-image: url(/static/img/61dc21364604d5319600.svg); + background-image: url(/static/img/2b438a6f1910279f8b62.svg); } From 0f232ef41c6ede9b527109247023751d1cac93a3 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Tue, 7 May 2024 15:17:56 +0800 Subject: [PATCH 014/107] chore: add x test plugin (#6459) --- x.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/x.mjs b/x.mjs index e4861719b417..7803834afd0f 100755 --- a/x.mjs +++ b/x.mjs @@ -132,6 +132,7 @@ testCommand .action(async function () { await $`./x test unit`; }); + // x test webpack testCommand .command("webpack") @@ -140,6 +141,14 @@ testCommand await $`pnpm --filter "webpack-test" test`; }); +// x test plugin +testCommand + .command("plugin") + .description("run plugin test suites") + .action(async function () { + await $`pnpm --filter "plugin-test" test`; + }); + // x rspack / x rs const rspackCommand = program.command("rspack").alias("rs").description(` $ x rspack -- [your-rspack-cli-args...] From dda7f49c6539ee8dde6443b9b330d6fce6739b4a Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Tue, 7 May 2024 15:56:31 +0800 Subject: [PATCH 015/107] chore: remove tokens (#6460) * chore: remove tokens * chore: remove tokens --- .github/workflows/ci.yml | 4 ++-- .github/workflows/diff.yml.bak | 2 +- .github/workflows/ecosystem-ci-trigger.yml | 2 +- .github/workflows/github-issue-sync.yml | 2 +- .github/workflows/release-nightly.yml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3964200cde7f..5e829333ae5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -316,7 +316,7 @@ jobs: owner: ${{ github.repository_owner }} repo: "rspack-ecosystem-benchmark" workflow_file_name: "bench_rspack_commit.yml" - github_token: ${{ secrets.RSPACK_BOT_ACCESS_TOKEN }} + github_token: ${{ secrets.RSPACK_ACCESS_TOKEN }} ref: "main" client_payload: '{"commit_sha":"${{ github.sha }}"}' @@ -333,7 +333,7 @@ jobs: owner: ${{ github.repository_owner }} repo: "rspack-ecosystem-ci" workflow_file_name: "ecosystem-ci-from-commit.yml" - github_token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }} + github_token: ${{ secrets.RSPACK_ACCESS_TOKEN }} ref: "main" client_payload: '{"commitSHA":"${{ github.sha }}","repo":"web-infra-dev/rspack","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}' diff --git a/.github/workflows/diff.yml.bak b/.github/workflows/diff.yml.bak index ff135e318fb7..f6c3922fe94a 100644 --- a/.github/workflows/diff.yml.bak +++ b/.github/workflows/diff.yml.bak @@ -61,7 +61,7 @@ jobs: - name: Upload Report shell: bash env: - API_TOKEN_GITHUB: ${{ secrets.RSPACK_REPORT_ACCESS_TOKEN }} + API_TOKEN_GITHUB: ${{ secrets.RSPACK_ACCESS_TOKEN }} run: | cache_dir="$HOME/.cache/diff_upload" clone_dir="$cache_dir/${{ github.run_id }}" diff --git a/.github/workflows/ecosystem-ci-trigger.yml b/.github/workflows/ecosystem-ci-trigger.yml index 59ed85abb4dd..e2cc78d13c08 100644 --- a/.github/workflows/ecosystem-ci-trigger.yml +++ b/.github/workflows/ecosystem-ci-trigger.yml @@ -65,7 +65,7 @@ jobs: env: COMMENT: ${{ github.event.comment.body }} with: - github-token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }} + github-token: ${{ secrets.RSPACK_ACCESS_TOKEN }} result-encoding: string script: | const comment = process.env.COMMENT.trim() diff --git a/.github/workflows/github-issue-sync.yml b/.github/workflows/github-issue-sync.yml index f7ad3855d674..387e7607dfe6 100644 --- a/.github/workflows/github-issue-sync.yml +++ b/.github/workflows/github-issue-sync.yml @@ -19,7 +19,7 @@ jobs: # This is a Personal Access Token and it needs to have the following permissions # - "read:org": used to read the project's board # - "write:org": used to assign issues to the project's board - PROJECT_TOKEN: ${{ secrets.PROJECT_TOKEN }} + PROJECT_TOKEN: ${{ secrets.RSPACK_ACCESS_TOKEN }} # The number of the project which the issues will be synced to # You can find this in https://github.com/orgs/@ORGANIZATION/projects/ project: 12 diff --git a/.github/workflows/release-nightly.yml b/.github/workflows/release-nightly.yml index 9649e1b4e8c5..18841feda91d 100644 --- a/.github/workflows/release-nightly.yml +++ b/.github/workflows/release-nightly.yml @@ -94,7 +94,7 @@ jobs: steps: - uses: actions/github-script@v7 with: - github-token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }} + github-token: ${{ secrets.RSPACK_ACCESS_TOKEN }} script: | const result = await github.rest.actions.createWorkflowDispatch({ owner: context.repo.owner, From 094e88e4a7747eb6d5e654be8cc95fe3e6dc96bd Mon Sep 17 00:00:00 2001 From: Timeless0911 <50201324+Timeless0911@users.noreply.github.com> Date: Tue, 7 May 2024 16:09:08 +0800 Subject: [PATCH 016/107] docs: fix ApiMeta component href (#6461) --- website/components/ApiMeta.tsx | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/website/components/ApiMeta.tsx b/website/components/ApiMeta.tsx index 87050a9f4cc2..3ecaa1276552 100644 --- a/website/components/ApiMeta.tsx +++ b/website/components/ApiMeta.tsx @@ -19,29 +19,22 @@ export interface ApiMetaProps { export function ApiMeta(props: ApiMetaProps) { let lang = useLang(); + const href = `/${lang}/misc/planning/future`; return (

{props.addedVersion && ( - Added in v{props.addedVersion} + Added in v{props.addedVersion} )} {props.deprecatedVersion && ( - - Deprecated in v{props.deprecatedVersion} - + Deprecated in v{props.deprecatedVersion} )} {props.removedVersion && ( - - Removed in v{props.removedVersion} - + Removed in v{props.removedVersion} )} {props.stability && ( From 3c07aa3bc26436c849719e8756ff03fba46d7862 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 7 May 2024 17:55:23 +0800 Subject: [PATCH 017/107] perf(core): use prebundle to reduce dependencies (#6462) * perf(core): use prebundle to reduce dependencies * fix: force * fix: revert * chore: fix api.md --- .gitignore | 3 + package.json | 2 +- packages/rspack/etc/api.md | 4 +- packages/rspack/package.json | 30 +- packages/rspack/prebundle.config.mjs | 26 ++ packages/rspack/src/Compiler.ts | 7 +- packages/rspack/src/global.d.ts | 111 ------ .../rspack/src/node/NodeWatchFileSystem.ts | 6 +- packages/rspack/tsconfig.json | 26 +- pnpm-lock.yaml | 329 ++++++++++++++++-- 10 files changed, 372 insertions(+), 172 deletions(-) create mode 100644 packages/rspack/prebundle.config.mjs delete mode 100644 packages/rspack/src/global.d.ts diff --git a/.gitignore b/.gitignore index 31fd07b99910..b6d5152d3905 100644 --- a/.gitignore +++ b/.gitignore @@ -111,7 +111,10 @@ out # Nuxt.js build / generate output .nuxt + +# Dist files dist +compiled webpack-dist # Gatsby files diff --git a/package.json b/package.json index 0bd72a6b43cf..8547ac5559cc 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "x": "zx x.mjs", "dev": "pnpm --filter @rspack/cli run dev", "clean": "pnpm --filter @rspack/cli run clean", - "build:js": "pnpm --filter \"@rspack/core\" build --force && pnpm --filter \"@rspack/*\" --filter \"!@rspack/core\" build --force", + "build:js": "pnpm --filter \"@rspack/core\" build:force && pnpm --filter \"@rspack/*\" --filter \"!@rspack/core\" build --force", "build:cli:debug": "npm run build:binding:debug && npm run build:js", "build:cli:release": "npm run build:binding:release && npm run build:js", "build:cli:release:all": "pnpm --filter @rspack/binding build:release:all && npm run build:js", diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index e23c8e8bff99..f793be839a08 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -77,7 +77,7 @@ import { SyncWaterfallHook } from 'tapable'; import * as tapable from 'tapable'; import Template = require('./Template'); import { UnsetAdditionalOptions as UnsetAdditionalOptions_2 } from 'tapable'; -import type { WatchOptions as WatchOptions_2 } from 'watchpack'; +import type Watchpack from 'watchpack'; import type * as webpackDevServer from 'webpack-dev-server'; import { z } from 'zod'; @@ -1450,7 +1450,7 @@ export class Compiler { // (undocumented) running: boolean; // (undocumented) - watch(watchOptions: WatchOptions_2, handler: Callback_2): Watching; + watch(watchOptions: Watchpack.WatchOptions, handler: Callback_2): Watching; // (undocumented) watchFileSystem: WatchFileSystem; // (undocumented) diff --git a/packages/rspack/package.json b/packages/rspack/package.json index fd209991288a..4afe5403eb68 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -15,14 +15,16 @@ "./package.json": "./package.json" }, "scripts": { - "build": "tsc -b ./tsconfig.build.json", - "dev": "tsc -w", + "build": "prebundle && tsc -b ./tsconfig.build.json && tsc-alias -p tsconfig.build.json", + "build:force": "prebundle && tsc -b ./tsconfig.build.json --force && tsc-alias -p tsconfig.build.json", + "dev": "prebundle && tsc -w", "api-extractor": "api-extractor run --verbose", "api-extractor:ci": "api-extractor run --verbose || diff temp/api.md etc/api.md" }, "files": [ "dist", - "hot" + "hot", + "compiled" ], "engines": { "node": ">=16.0.0" @@ -38,27 +40,33 @@ "@rspack/core": "workspace:*", "@rspack/plugin-minify": "workspace:^", "@swc/plugin-remove-console": "1.5.121", + "@types/neo-async": "^2.6.6", "@types/watchpack": "^2.4.0", "@types/webpack-sources": "3.2.3", "@types/ws": "8.5.10", "babel-loader": "^9.1.0", "babel-plugin-import": "^1.13.5", + "browserslist": "^4.21.3", "copy-webpack-plugin": "5.1.2", "cross-env": "^7.0.3", "del": "^6.0.0", "file-loader": "^6.2.0", "glob": "^10.3.10", + "graceful-fs": "4.2.10", "html-loader": "^5.0.0", "html-webpack-plugin": "^5.5.0", "identity-obj-proxy": "3.0.0", "jest-environment-jsdom": "^29", "jest-serializer-path": "^0.1.15", "jsdom": "^24.0.0", + "json-parse-even-better-errors": "^3.0.0", "less": "4.2.0", "less-loader": "^12.0.0", + "neo-async": "2.6.2", "node-polyfill-webpack-plugin": "3.0.0", "postcss-loader": "^8.0.0", "postcss-pxtorem": "^6.0.0", + "prebundle": "^1.1.0", "pug-loader": "^2.4.0", "react-relay": "^16.0.0", "sass": "1.56.2", @@ -67,21 +75,19 @@ "source-map-loader": "^5.0.0", "styled-components": "^6.0.8", "terser": "5.27.2", - "wast-loader": "^1.11.4" + "tsc-alias": "^1.8.8", + "wast-loader": "^1.11.4", + "watchpack": "^2.4.0", + "zod": "^3.21.4", + "zod-validation-error": "1.3.1" }, "dependencies": { "@module-federation/runtime-tools": "0.1.6", "@rspack/binding": "workspace:*", - "browserslist": "^4.21.3", + "caniuse-lite": "^1.0.30001616", "enhanced-resolve": "5.12.0", - "graceful-fs": "4.2.10", - "json-parse-even-better-errors": "^3.0.0", - "neo-async": "2.6.2", "tapable": "2.2.1", - "watchpack": "^2.4.0", - "webpack-sources": "3.2.3", - "zod": "^3.21.4", - "zod-validation-error": "1.3.1" + "webpack-sources": "3.2.3" }, "peerDependencies": { "@swc/helpers": ">=0.5.1" diff --git a/packages/rspack/prebundle.config.mjs b/packages/rspack/prebundle.config.mjs new file mode 100644 index 000000000000..209d1471558b --- /dev/null +++ b/packages/rspack/prebundle.config.mjs @@ -0,0 +1,26 @@ +// @ts-check + +/** @type {import('prebundle').Config} */ +export default { + dependencies: [ + "zod", + "zod-validation-error", + "json-parse-even-better-errors", + "neo-async", + "graceful-fs", + { + name: "watchpack", + externals: { + "graceful-fs": "../graceful-fs" + } + }, + { + name: "browserslist", + ignoreDts: true, + externals: { + "caniuse-lite": "caniuse-lite", + "/^caniuse-lite(/.*)/": "caniuse-lite$1" + } + } + ] +}; diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index 92a3d872108d..6db04a18adcb 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -13,7 +13,7 @@ import fs from "fs"; import * as tapable from "tapable"; import * as liteTapable from "./lite-tapable"; import { Callback, SyncBailHook, SyncHook } from "tapable"; -import type { WatchOptions } from "watchpack"; +import type Watchpack from "watchpack"; import { getRawOptions, EntryNormalized, @@ -1054,7 +1054,10 @@ class Compiler { }); } - watch(watchOptions: WatchOptions, handler: Callback): Watching { + watch( + watchOptions: Watchpack.WatchOptions, + handler: Callback + ): Watching { if (this.running) { // @ts-expect-error return handler(new ConcurrentCompilationError()); diff --git a/packages/rspack/src/global.d.ts b/packages/rspack/src/global.d.ts deleted file mode 100644 index 6e3581a6a56a..000000000000 --- a/packages/rspack/src/global.d.ts +++ /dev/null @@ -1,111 +0,0 @@ -declare module "neo-async" { - interface QueueObject { - push(item: T): void; - drain: () => void; - error: (err: E) => void; - } - - export interface Dictionary { - [key: string]: T; - } - export type IterableCollection = T[] | Iterable | Dictionary; - - export interface ErrorCallback { - (err?: T): void; - } - export interface AsyncBooleanResultCallback { - (err?: E, truthValue?: boolean): void; - } - export interface AsyncResultCallback { - (err?: E, result?: T): void; - } - export interface AsyncResultArrayCallback { - (err?: E, results?: Array): void; - } - export interface AsyncResultObjectCallback { - (err: E | undefined, results: Dictionary): void; - } - - export interface AsyncFunction { - (callback: (err?: E, result?: T) => void): void; - } - export interface AsyncFunctionEx { - (callback: (err?: E, ...results: T[]) => void): void; - } - export interface AsyncIterator { - (item: T, callback: ErrorCallback): void; - } - export interface AsyncForEachOfIterator { - (item: T, key: number | string, callback: ErrorCallback): void; - } - export interface AsyncResultIterator { - (item: T, callback: AsyncResultCallback): void; - } - export interface AsyncMemoIterator { - (memo: R | undefined, item: T, callback: AsyncResultCallback): void; - } - export interface AsyncBooleanIterator { - (item: T, callback: AsyncBooleanResultCallback): void; - } - - export interface AsyncWorker { - (task: T, callback: ErrorCallback): void; - } - export interface AsyncVoidFunction { - (callback: ErrorCallback): void; - } - - export type AsyncAutoTasks, E> = { - [K in keyof R]: AsyncAutoTask; - }; - export type AsyncAutoTask, E> = - | AsyncAutoTaskFunctionWithoutDependencies - | (keyof R | AsyncAutoTaskFunction)[]; - export interface AsyncAutoTaskFunctionWithoutDependencies { - (cb: AsyncResultCallback | ErrorCallback): void; - } - export interface AsyncAutoTaskFunction, E> { - (results: R, cb: AsyncResultCallback | ErrorCallback): void; - } - - export function each( - arr: IterableCollection, - iterator: AsyncIterator, - callback?: ErrorCallback - ): void; - - export function eachLimit( - arr: IterableCollection, - limit: number, - iterator: AsyncIterator, - callback?: ErrorCallback - ): void; - - export function map( - arr: T[] | IterableIterator, - iterator: AsyncResultIterator, - callback?: AsyncResultArrayCallback - ): void; - export function map( - arr: Dictionary, - iterator: AsyncResultIterator, - callback?: AsyncResultArrayCallback - ): void; - - export function parallel( - tasks: Array>, - callback?: AsyncResultArrayCallback - ): void; - export function parallel( - tasks: Dictionary>, - callback?: AsyncResultObjectCallback - ): void; - - export function queue( - worker: AsyncIterator, - concurrency?: number - ): QueueObject; - - export const forEach: typeof each; - export const forEachLimit: typeof eachLimit; -} diff --git a/packages/rspack/src/node/NodeWatchFileSystem.ts b/packages/rspack/src/node/NodeWatchFileSystem.ts index d16d06a99610..35378a181931 100644 --- a/packages/rspack/src/node/NodeWatchFileSystem.ts +++ b/packages/rspack/src/node/NodeWatchFileSystem.ts @@ -9,12 +9,12 @@ */ import util from "util"; -import Watchpack, { WatchOptions } from "watchpack"; +import Watchpack from "watchpack"; import { FileSystemInfoEntry, Watcher, WatchFileSystem } from "../util/fs"; export default class NodeWatchFileSystem implements WatchFileSystem { inputFileSystem: any; - watcherOptions: WatchOptions; + watcherOptions: Watchpack.WatchOptions; watcher: Watchpack; constructor(inputFileSystem: any) { @@ -30,7 +30,7 @@ export default class NodeWatchFileSystem implements WatchFileSystem { directories: Iterable, missing: Iterable, startTime: number, - options: WatchOptions, + options: Watchpack.WatchOptions, callback: ( error: Error, fileTimeInfoEntries: Map, diff --git a/packages/rspack/tsconfig.json b/packages/rspack/tsconfig.json index 455f6f3c4396..e45a4a595fb9 100644 --- a/packages/rspack/tsconfig.json +++ b/packages/rspack/tsconfig.json @@ -3,16 +3,22 @@ "compilerOptions": { "outDir": "dist", "rootDir": "src", - "resolveJsonModule": true + "resolveJsonModule": true, + "paths": { + "zod": ["../compiled/zod"], + "neo-async": ["../compiled/neo-async"], + "watchpack": ["../compiled/watchpack"], + "graceful-fs": ["../compiled/graceful-fs"], + "browserslist": ["../compiled/browserslist"], + "zod-validation-error": ["../compiled/zod-validation-error"], + "json-parse-even-better-errors": [ + "../compiled/json-parse-even-better-errors" + ] + } }, - "include": [ - "src", - "src/**/*.json" - ], - "exclude": [ - "src/config/schema.check.js" - ], + "include": ["src", "src/**/*.json"], + "exclude": ["src/config/schema.check.js"], "ts-node": { "transpileOnly": true - }, -} \ No newline at end of file + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e1046512930..5a2f50417150 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -429,36 +429,18 @@ importers: '@swc/helpers': specifier: '>=0.5.1' version: 0.5.6 - browserslist: - specifier: ^4.21.3 - version: 4.23.0 + caniuse-lite: + specifier: ^1.0.30001616 + version: 1.0.30001616 enhanced-resolve: specifier: 5.12.0 version: 5.12.0 - graceful-fs: - specifier: 4.2.10 - version: 4.2.10 - json-parse-even-better-errors: - specifier: ^3.0.0 - version: 3.0.1 - neo-async: - specifier: 2.6.2 - version: 2.6.2 tapable: specifier: 2.2.1 version: 2.2.1 - watchpack: - specifier: ^2.4.0 - version: 2.4.1 webpack-sources: specifier: 3.2.3 version: 3.2.3 - zod: - specifier: ^3.21.4 - version: 3.22.4 - zod-validation-error: - specifier: 1.3.1 - version: 1.3.1(zod@3.22.4) devDependencies: '@rspack/core': specifier: workspace:* @@ -469,6 +451,9 @@ importers: '@swc/plugin-remove-console': specifier: 1.5.121 version: 1.5.121 + '@types/neo-async': + specifier: ^2.6.6 + version: 2.6.6 '@types/watchpack': specifier: ^2.4.0 version: 2.4.4 @@ -484,6 +469,9 @@ importers: babel-plugin-import: specifier: ^1.13.5 version: 1.13.8 + browserslist: + specifier: ^4.21.3 + version: 4.23.0 copy-webpack-plugin: specifier: 5.1.2 version: 5.1.2(webpack@5.90.1) @@ -499,6 +487,9 @@ importers: glob: specifier: ^10.3.10 version: 10.3.12 + graceful-fs: + specifier: 4.2.10 + version: 4.2.10 html-loader: specifier: ^5.0.0 version: 5.0.0(webpack@5.90.1) @@ -517,21 +508,30 @@ importers: jsdom: specifier: ^24.0.0 version: 24.0.0 + json-parse-even-better-errors: + specifier: ^3.0.0 + version: 3.0.1 less: specifier: 4.2.0 version: 4.2.0 less-loader: specifier: ^12.0.0 version: 12.2.0(@rspack/core@packages+rspack)(less@4.2.0)(webpack@5.90.1) + neo-async: + specifier: 2.6.2 + version: 2.6.2 node-polyfill-webpack-plugin: specifier: 3.0.0 version: 3.0.0(webpack@5.90.1) postcss-loader: specifier: ^8.0.0 - version: 8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@5.0.2)(webpack@5.90.1) + version: 8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@4.9.5)(webpack@5.90.1) postcss-pxtorem: specifier: ^6.0.0 version: 6.1.0(postcss@8.4.38) + prebundle: + specifier: ^1.1.0 + version: 1.1.0(typescript@4.9.5) pug-loader: specifier: ^2.4.0 version: 2.4.0(pug@2.0.4) @@ -556,9 +556,21 @@ importers: terser: specifier: 5.27.2 version: 5.27.2 + tsc-alias: + specifier: ^1.8.8 + version: 1.8.8 wast-loader: specifier: ^1.11.4 version: 1.12.1 + watchpack: + specifier: ^2.4.0 + version: 2.4.1 + zod: + specifier: ^3.21.4 + version: 3.22.4 + zod-validation-error: + specifier: 1.3.1 + version: 1.3.1(zod@3.22.4) packages/rspack-cli: dependencies: @@ -4228,6 +4240,134 @@ packages: resolution: {integrity: sha512-j7P6Rgr3mmtdkeDGTe0E/aYyWEWVtc5yFXtHCRHs28/jptDEWfaVOc5T7cblqy1XKPPfCxJc/8DwQ5YgLOZOVQ==} dev: false + /@rollup/rollup-android-arm-eabi@4.17.2: + resolution: {integrity: sha512-NM0jFxY8bB8QLkoKxIQeObCaDlJKewVlIEkuyYKm5An1tdVZ966w2+MPQ2l8LBZLjR+SgyV+nRkTIunzOYBMLQ==} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-android-arm64@4.17.2: + resolution: {integrity: sha512-yeX/Usk7daNIVwkq2uGoq2BYJKZY1JfyLTaHO/jaiSwi/lsf8fTFoQW/n6IdAsx5tx+iotu2zCJwz8MxI6D/Bw==} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-darwin-arm64@4.17.2: + resolution: {integrity: sha512-kcMLpE6uCwls023+kknm71ug7MZOrtXo+y5p/tsg6jltpDtgQY1Eq5sGfHcQfb+lfuKwhBmEURDga9N0ol4YPw==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-darwin-x64@4.17.2: + resolution: {integrity: sha512-AtKwD0VEx0zWkL0ZjixEkp5tbNLzX+FCqGG1SvOu993HnSz4qDI6S4kGzubrEJAljpVkhRSlg5bzpV//E6ysTQ==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm-gnueabihf@4.17.2: + resolution: {integrity: sha512-3reX2fUHqN7sffBNqmEyMQVj/CKhIHZd4y631duy0hZqI8Qoqf6lTtmAKvJFYa6bhU95B1D0WgzHkmTg33In0A==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm-musleabihf@4.17.2: + resolution: {integrity: sha512-uSqpsp91mheRgw96xtyAGP9FW5ChctTFEoXP0r5FAzj/3ZRv3Uxjtc7taRQSaQM/q85KEKjKsZuiZM3GyUivRg==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm64-gnu@4.17.2: + resolution: {integrity: sha512-EMMPHkiCRtE8Wdk3Qhtciq6BndLtstqZIroHiiGzB3C5LDJmIZcSzVtLRbwuXuUft1Cnv+9fxuDtDxz3k3EW2A==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-arm64-musl@4.17.2: + resolution: {integrity: sha512-NMPylUUZ1i0z/xJUIx6VUhISZDRT+uTWpBcjdv0/zkp7b/bQDF+NfnfdzuTiB1G6HTodgoFa93hp0O1xl+/UbA==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-powerpc64le-gnu@4.17.2: + resolution: {integrity: sha512-T19My13y8uYXPw/L/k0JYaX1fJKFT/PWdXiHr8mTbXWxjVF1t+8Xl31DgBBvEKclw+1b00Chg0hxE2O7bTG7GQ==} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-riscv64-gnu@4.17.2: + resolution: {integrity: sha512-BOaNfthf3X3fOWAB+IJ9kxTgPmMqPPH5f5k2DcCsRrBIbWnaJCgX2ll77dV1TdSy9SaXTR5iDXRL8n7AnoP5cg==} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-s390x-gnu@4.17.2: + resolution: {integrity: sha512-W0UP/x7bnn3xN2eYMql2T/+wpASLE5SjObXILTMPUBDB/Fg/FxC+gX4nvCfPBCbNhz51C+HcqQp2qQ4u25ok6g==} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-x64-gnu@4.17.2: + resolution: {integrity: sha512-Hy7pLwByUOuyaFC6mAr7m+oMC+V7qyifzs/nW2OJfC8H4hbCzOX07Ov0VFk/zP3kBsELWNFi7rJtgbKYsav9QQ==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-linux-x64-musl@4.17.2: + resolution: {integrity: sha512-h1+yTWeYbRdAyJ/jMiVw0l6fOOm/0D1vNLui9iPuqgRGnXA0u21gAqOyB5iHjlM9MMfNOm9RHCQ7zLIzT0x11Q==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-win32-arm64-msvc@4.17.2: + resolution: {integrity: sha512-tmdtXMfKAjy5+IQsVtDiCfqbynAQE/TQRpWdVataHmhMb9DCoJxp9vLcCBjEQWMiUYxO1QprH/HbY9ragCEFLA==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-win32-ia32-msvc@4.17.2: + resolution: {integrity: sha512-7II/QCSTAHuE5vdZaQEwJq2ZACkBpQDOmQsE6D6XUbnBHW8IAhm4eTufL6msLJorzrHDFv3CF8oCA/hSIRuZeQ==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rollup/rollup-win32-x64-msvc@4.17.2: + resolution: {integrity: sha512-TGGO7v7qOq4CYmSBVEYpI1Y5xDuCEnbVC5Vth8mOsW0gDSzxNrVERPc790IGHsrT2dQSimgMr9Ub3Y1Jci5/8w==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@rushstack/node-core-library@4.1.0(@types/node@20.12.7): resolution: {integrity: sha512-qz4JFBZJCf1YN5cAXa1dP6Mki/HrsQxc/oYGAGx29dF2cwF2YMxHoly0FBhMw3IEnxo5fMj0boVfoHVBkpkx/w==} peerDependencies: @@ -5875,6 +6015,10 @@ packages: resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} dev: true + /@types/neo-async@2.6.6: + resolution: {integrity: sha512-D22UBilfSj6IMhC5Fs6+sbZveSTgG0qPVw4mFbQaadLaU7COikojl/TJpKxX0woidAbbWJ42MJ9ANOr9ODi6Yw==} + dev: true + /@types/node-forge@1.3.11: resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==} dependencies: @@ -6076,6 +6220,11 @@ packages: dependencies: '@types/yargs-parser': 21.0.3 + /@vercel/ncc@0.38.1: + resolution: {integrity: sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==} + hasBin: true + dev: true + /@vue/compiler-core@3.2.45: resolution: {integrity: sha512-rcMj7H+PYe5wBV3iYeUgbCglC+pbpN8hBLTJvRiK2eKQiWqu+fG9F+8sW99JdL4LQi7Re178UOxn09puSXvn4A==} dependencies: @@ -7238,7 +7387,7 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001607 + caniuse-lite: 1.0.30001616 electron-to-chromium: 1.4.730 node-releases: 2.0.14 update-browserslist-db: 1.0.13(browserslist@4.23.0) @@ -7415,8 +7564,8 @@ packages: path-temp: 2.1.0 dev: true - /caniuse-lite@1.0.30001607: - resolution: {integrity: sha512-WcvhVRjXLKFB/kmOFVwELtMxyhq3iM/MvmXcyCe2PNf166c39mptscOc/45TTS96n2gpNV2z7+NakArTWZCQ3w==} + /caniuse-lite@1.0.30001616: + resolution: {integrity: sha512-RHVYKov7IcdNjVHJFNY/78RdG4oGVjbayxv8u5IO74Wv7Hlq4PnJE6mo/OjFijjVFNy5ijnCt6H3IIo4t+wfEw==} /center-align@0.1.3: resolution: {integrity: sha512-Baz3aNe2gd2LP2qk5U+sDk/m4oSuwSDcBfayTCTBoWpfIGO5XFxPmjILQII4NGiZjD6DoDI6kf7gKaxkf7s3VQ==} @@ -7772,7 +7921,6 @@ packages: engines: {node: ^12.20.0 || >=14} requiresBuild: true dev: true - optional: true /common-path-prefix@3.0.0: resolution: {integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==} @@ -8018,6 +8166,22 @@ packages: typescript: 5.0.2 dev: true + /cosmiconfig@9.0.0(typescript@4.9.5): + resolution: {integrity: sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==} + engines: {node: '>=14'} + peerDependencies: + typescript: '>=4.9.5' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + env-paths: 2.2.1 + import-fresh: 3.3.0 + js-yaml: 4.1.0 + parse-json: 5.2.0 + typescript: 4.9.5 + dev: true + /cosmiconfig@9.0.0(typescript@5.0.2): resolution: {integrity: sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==} engines: {node: '>=14'} @@ -10153,7 +10317,7 @@ packages: lodash: 4.17.21 pretty-error: 4.0.0 tapable: 2.2.1 - webpack: 5.90.1(@swc/core@1.4.0)(webpack-cli@4.10.0) + webpack: 5.90.1(webpack-cli@4.10.0) dev: true /htmlescape@1.1.1: @@ -11457,7 +11621,7 @@ packages: /json-parse-even-better-errors@3.0.1: resolution: {integrity: sha512-aatBvbL26wVUCLmbWdCpeu9iF5wOyWpagiKkInA+kfws3sWdBrTnsvN2CKcyCYyUrc7rebNBlK6+kteg7ksecg==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} - dev: false + dev: true /json-schema-traverse@0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} @@ -11597,7 +11761,7 @@ packages: dependencies: '@rspack/core': link:packages/rspack less: 4.2.0 - webpack: 5.90.1(@swc/core@1.4.0)(webpack-cli@4.10.0) + webpack: 5.90.1(webpack-cli@4.10.0) dev: true /less@4.1.3: @@ -12229,6 +12393,11 @@ packages: engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} dev: true + /mylas@2.1.13: + resolution: {integrity: sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==} + engines: {node: '>=12.0.0'} + dev: true + /mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} dependencies: @@ -12940,6 +13109,13 @@ packages: hasBin: true dev: true + /plimit-lit@1.6.1: + resolution: {integrity: sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==} + engines: {node: '>=12'} + dependencies: + queue-lit: 1.5.2 + dev: true + /point-at-length@1.1.0: resolution: {integrity: sha512-nNHDk9rNEh/91o2Y8kHLzBLNpLf80RYd2gCun9ss+V0ytRSf6XhryBTx071fesktjbachRmGuUbId+JQmzhRXw==} dependencies: @@ -13018,6 +13194,29 @@ packages: - typescript dev: true + /postcss-loader@8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@4.9.5)(webpack@5.90.1): + resolution: {integrity: sha512-0IeqyAsG6tYiDRCYKQJLAmgQr47DX6N7sFSWvQxt6AcupX8DIdmykuk/o/tx0Lze3ErGHJEp5OSRxrelC6+NdQ==} + engines: {node: '>= 18.12.0'} + peerDependencies: + '@rspack/core': 0.x || 1.x + postcss: ^7.0.0 || ^8.0.1 + webpack: ^5.0.0 + peerDependenciesMeta: + '@rspack/core': + optional: true + webpack: + optional: true + dependencies: + '@rspack/core': link:packages/rspack + cosmiconfig: 9.0.0(typescript@4.9.5) + jiti: 1.21.0 + postcss: 8.4.38 + semver: 7.6.0 + webpack: 5.90.1(webpack-cli@4.10.0) + transitivePeerDependencies: + - typescript + dev: true + /postcss-loader@8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@5.0.2)(webpack@5.90.1): resolution: {integrity: sha512-0IeqyAsG6tYiDRCYKQJLAmgQr47DX6N7sFSWvQxt6AcupX8DIdmykuk/o/tx0Lze3ErGHJEp5OSRxrelC6+NdQ==} engines: {node: '>= 18.12.0'} @@ -13129,6 +13328,17 @@ packages: picocolors: 1.0.0 source-map-js: 1.2.0 + /prebundle@1.1.0(typescript@4.9.5): + resolution: {integrity: sha512-yTfRjx0+xiveeb7kO77OcODVB8RSHMKIiVl/qferU7ZHw4Y8pycXkCAtPDViF8YDo0a8ViDpm4C1O9PFKCw1ig==} + hasBin: true + dependencies: + '@vercel/ncc': 0.38.1 + rollup: 4.17.2 + rollup-plugin-dts: 6.1.0(rollup@4.17.2)(typescript@4.9.5) + transitivePeerDependencies: + - typescript + dev: true + /prepend-http@2.0.0: resolution: {integrity: sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA==} engines: {node: '>=4'} @@ -13439,6 +13649,11 @@ packages: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} dev: true + /queue-lit@1.5.2: + resolution: {integrity: sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==} + engines: {node: '>=12'} + dev: true + /queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} dev: true @@ -14159,6 +14374,20 @@ packages: resolution: {integrity: sha512-IXgzBWvWQwE6PrDI05OvmXUIruQTcoMDzRsOd5CDvHCVLcLHMTSYvOK5Cm46kWqlV3yAbuSpBZdJ5oP5OUoStg==} dev: false + /rollup-plugin-dts@6.1.0(rollup@4.17.2)(typescript@4.9.5): + resolution: {integrity: sha512-ijSCPICkRMDKDLBK9torss07+8dl9UpY9z1N/zTeA1cIqdzMlpkV3MOOC7zukyvQfDyxa1s3Dl2+DeiP/G6DOw==} + engines: {node: '>=16'} + peerDependencies: + rollup: ^3.29.4 || ^4 + typescript: ^4.5 || ^5.0 + dependencies: + magic-string: 0.30.9 + rollup: 4.17.2 + typescript: 4.9.5 + optionalDependencies: + '@babel/code-frame': 7.24.2 + dev: true + /rollup@0.25.8: resolution: {integrity: sha512-a2S4Bh3bgrdO4BhKr2E4nZkjTvrJ2m2bWjMTzVYtoqSCn0HnuxosXnaJUHrMEziOWr3CzL9GjilQQKcyCQpJoA==} hasBin: true @@ -14168,6 +14397,32 @@ packages: source-map-support: 0.3.3 dev: false + /rollup@4.17.2: + resolution: {integrity: sha512-/9ClTJPByC0U4zNLowV1tMBe8yMEAxewtR3cUNX5BoEpGH3dQEWpJLr6CLp0fPdYRF/fzVOgvDb1zXuakwF5kQ==} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + dependencies: + '@types/estree': 1.0.5 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.17.2 + '@rollup/rollup-android-arm64': 4.17.2 + '@rollup/rollup-darwin-arm64': 4.17.2 + '@rollup/rollup-darwin-x64': 4.17.2 + '@rollup/rollup-linux-arm-gnueabihf': 4.17.2 + '@rollup/rollup-linux-arm-musleabihf': 4.17.2 + '@rollup/rollup-linux-arm64-gnu': 4.17.2 + '@rollup/rollup-linux-arm64-musl': 4.17.2 + '@rollup/rollup-linux-powerpc64le-gnu': 4.17.2 + '@rollup/rollup-linux-riscv64-gnu': 4.17.2 + '@rollup/rollup-linux-s390x-gnu': 4.17.2 + '@rollup/rollup-linux-x64-gnu': 4.17.2 + '@rollup/rollup-linux-x64-musl': 4.17.2 + '@rollup/rollup-win32-arm64-msvc': 4.17.2 + '@rollup/rollup-win32-ia32-msvc': 4.17.2 + '@rollup/rollup-win32-x64-msvc': 4.17.2 + fsevents: 2.3.3 + dev: true + /rrweb-cssom@0.6.0: resolution: {integrity: sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==} dev: true @@ -15546,6 +15801,18 @@ packages: yn: 3.1.1 dev: true + /tsc-alias@1.8.8: + resolution: {integrity: sha512-OYUOd2wl0H858NvABWr/BoSKNERw3N9GTi3rHPK8Iv4O1UyUXIrTTOAZNHsjlVpXFOhpJBVARI1s+rzwLivN3Q==} + hasBin: true + dependencies: + chokidar: 3.5.3 + commander: 9.5.0 + globby: 11.1.0 + mylas: 2.1.13 + normalize-path: 3.0.0 + plimit-lit: 1.6.1 + dev: true + /tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} dev: false @@ -16748,11 +17015,11 @@ packages: zod: ^3.18.0 dependencies: zod: 3.22.4 - dev: false + dev: true /zod@3.22.4: resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} - dev: false + dev: true /zx@7.2.3: resolution: {integrity: sha512-QODu38nLlYXg/B/Gw7ZKiZrvPkEsjPN3LQ5JFXM7h0JvwhEdPNNl+4Ao1y4+o3CLNiDUNcwzQYZ4/Ko7kKzCMA==} From b3d7acad2fc01769399356d4e93e1e213b6ad619 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Tue, 7 May 2024 18:16:41 +0800 Subject: [PATCH 018/107] chore: add tag to docs pr and release note (#6464) --- .github/pr-labeler.yml | 2 ++ .github/release.yml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/pr-labeler.yml b/.github/pr-labeler.yml index 03912b631e20..68f966524b04 100644 --- a/.github/pr-labeler.yml +++ b/.github/pr-labeler.yml @@ -6,3 +6,5 @@ - "/^perf/" "release: bug fix": - "/^fix/" +"release: document": + - "/^docs/" diff --git a/.github/release.yml b/.github/release.yml index 358a60c56aa0..e8a3c0b811a3 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -20,6 +20,9 @@ changelog: - title: Bug Fixes 🐞 labels: - "release: bug fix" + - title: Document Updates 📖 + labels: + - "release: document" - title: Other Changes labels: - "*" From 76f4c16085ce8a89bdc759adfd8f22f9f2decf54 Mon Sep 17 00:00:00 2001 From: kfll Date: Tue, 7 May 2024 18:34:53 +0800 Subject: [PATCH 019/107] fix(cli): load `@rspack/dev-server` on demand (#6370) fix(cli): load `@rspack/dev-server` on demand to prevent process.env.WEBPACK_SERVE being set on build mode --- packages/rspack-cli/src/commands/preview.ts | 2 +- packages/rspack-cli/src/commands/serve.ts | 15 +++++++++++-- .../tests/build/issue-6359/entry.js | 1 + .../tests/build/issue-6359/index.test.ts | 16 ++++++++++++++ .../tests/build/issue-6359/rspack.config.js | 22 +++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 packages/rspack-cli/tests/build/issue-6359/entry.js create mode 100644 packages/rspack-cli/tests/build/issue-6359/index.test.ts create mode 100644 packages/rspack-cli/tests/build/issue-6359/rspack.config.js diff --git a/packages/rspack-cli/src/commands/preview.ts b/packages/rspack-cli/src/commands/preview.ts index 404bac8e5654..3875a61d4e57 100644 --- a/packages/rspack-cli/src/commands/preview.ts +++ b/packages/rspack-cli/src/commands/preview.ts @@ -1,5 +1,4 @@ import type { RspackCLI } from "../rspack-cli"; -import { RspackDevServer } from "@rspack/dev-server"; import { RspackCommand, RspackPreviewCLIOptions } from "../types"; import { previewOptions } from "../utils/options"; import { @@ -26,6 +25,7 @@ export class PreviewCommand implements RspackCommand { ...options } }; + const { RspackDevServer } = await import("@rspack/dev-server"); let config = await cli.loadConfig(rspackOptions); config = await getPreviewConfig(config, options); diff --git a/packages/rspack-cli/src/commands/serve.ts b/packages/rspack-cli/src/commands/serve.ts index 0081db0c7c0a..2be261b542fc 100644 --- a/packages/rspack-cli/src/commands/serve.ts +++ b/packages/rspack-cli/src/commands/serve.ts @@ -1,5 +1,5 @@ import type { RspackCLI } from "../rspack-cli"; -import { RspackDevServer } from "@rspack/dev-server"; +import type { RspackDevServer as RspackDevServerType } from "@rspack/dev-server"; import { RspackCommand } from "../types"; import { commonOptions, @@ -22,6 +22,17 @@ export class ServeCommand implements RspackCommand { ...options } }; + /** + * webpack-dev-server will set `process.env.WEBPACK_SERVE` to true + * when its module is imported, so we have to lazy load the package + * to make sure the envvar is not set on build mode. + * when run in serve mode, we have to load the package before config + * module is imported so that the envvar `process.env.WEBPACK_SERVE` + * got in config module could be `true`. + * related issue: https://github.com/web-infra-dev/rspack/issues/6359 + */ + const { RspackDevServer } = await import("@rspack/dev-server"); + const compiler = await cli.createCompiler(rspackOptions, "serve"); if (!compiler) return; const compilers = cli.isMultipleCompiler(compiler) @@ -32,7 +43,7 @@ export class ServeCommand implements RspackCommand { ); const usedPorts: number[] = []; - const servers: RspackDevServer[] = []; + const servers: RspackDevServerType[] = []; /** * Webpack uses an Array of compilerForDevServer, diff --git a/packages/rspack-cli/tests/build/issue-6359/entry.js b/packages/rspack-cli/tests/build/issue-6359/entry.js new file mode 100644 index 000000000000..d2d81e247301 --- /dev/null +++ b/packages/rspack-cli/tests/build/issue-6359/entry.js @@ -0,0 +1 @@ +log(DEFINE_ME); diff --git a/packages/rspack-cli/tests/build/issue-6359/index.test.ts b/packages/rspack-cli/tests/build/issue-6359/index.test.ts new file mode 100644 index 000000000000..152cb5ce4163 --- /dev/null +++ b/packages/rspack-cli/tests/build/issue-6359/index.test.ts @@ -0,0 +1,16 @@ +import { readFile, run, runWatch } from "../../utils/test-utils"; +import { resolve } from "path"; + +it("should not have `process.env.WEBPACK_SERVE` set on build mode", async () => { + await run(__dirname, []); + const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8"); + + expect(mainJs).toContain("WEBPACK_SERVE="); +}); + +it("should have `process.env.WEBPACK_SERVE` set on serve mode", async () => { + await runWatch(__dirname, ["serve"], { killString: /rspack compiled/i }); + const mainJs = await readFile(resolve(__dirname, "dist/main.js"), "utf-8"); + + expect(mainJs).toContain("WEBPACK_SERVE=true"); +}); diff --git a/packages/rspack-cli/tests/build/issue-6359/rspack.config.js b/packages/rspack-cli/tests/build/issue-6359/rspack.config.js new file mode 100644 index 000000000000..ef0d639ed643 --- /dev/null +++ b/packages/rspack-cli/tests/build/issue-6359/rspack.config.js @@ -0,0 +1,22 @@ +const { WEBPACK_SERVE } = process.env; +module.exports = /** @type {import('@rspack/cli').Configuration} */ { + mode: "production", + entry: "./entry.js", + output: { clean: true }, + plugins: [ + { + apply(compiler) { + new compiler.webpack.DefinePlugin({ + DEFINE_ME: JSON.stringify( + `WEBPACK_SERVE=${WEBPACK_SERVE ?? ""}` + ) + }).apply(compiler); + } + } + ], + devServer: { + devMiddleware: { + writeToDisk: true + } + } +}; From 65224fb5fec2981134f424c439c5d67e54bafcf1 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 7 May 2024 20:05:02 +0800 Subject: [PATCH 020/107] fix: remove --force flag to fix prebundle (#6465) * fix: remove --force flag to fix prebundle * chore: fix api.md --- package.json | 2 +- packages/rspack/etc/api.md | 186 ++++++++++++++++++++++++++++++++++++- 2 files changed, 185 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8547ac5559cc..622ea0e9ebe5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "x": "zx x.mjs", "dev": "pnpm --filter @rspack/cli run dev", "clean": "pnpm --filter @rspack/cli run clean", - "build:js": "pnpm --filter \"@rspack/core\" build:force && pnpm --filter \"@rspack/*\" --filter \"!@rspack/core\" build --force", + "build:js": "pnpm --filter \"@rspack/core\" build:force && pnpm --filter \"@rspack/*\" --filter \"!@rspack/core\" build", "build:cli:debug": "npm run build:binding:debug && npm run build:js", "build:cli:release": "npm run build:binding:release && npm run build:js", "build:cli:release:all": "pnpm --filter @rspack/binding build:release:all && npm run build:js", diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index f793be839a08..f236d3dee812 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -16,11 +16,13 @@ import CacheFacade = require('./lib/CacheFacade'); import { Callback as Callback_2 } from 'tapable'; import { Compiler as Compiler_2 } from '../Compiler'; import { RawEvalDevToolModulePluginOptions as EvalDevToolModulePluginOptions } from '@rspack/binding'; +import { EventEmitter } from 'events'; import { cleanupGlobalTrace as experimental_cleanupGlobalTrace } from '@rspack/binding'; import { registerGlobalTrace as experimental_registerGlobalTrace } from '@rspack/binding'; import { exports as exports_2 } from './exports'; import type { ExternalObject } from '@rspack/binding'; import { fs } from 'fs'; +import { default as fs_2 } from 'graceful-fs'; import Hash = require('../util/hash'); import { HookMap as HookMap_2 } from 'tapable'; import { JsAssetInfo } from '@rspack/binding'; @@ -77,9 +79,7 @@ import { SyncWaterfallHook } from 'tapable'; import * as tapable from 'tapable'; import Template = require('./Template'); import { UnsetAdditionalOptions as UnsetAdditionalOptions_2 } from 'tapable'; -import type Watchpack from 'watchpack'; import type * as webpackDevServer from 'webpack-dev-server'; -import { z } from 'zod'; // @public (undocumented) const ABSOLUTE_PUBLIC_PATH = "webpack:///mini-css-extract-plugin/"; @@ -1911,6 +1911,67 @@ export type DevtoolNamespace = z.infer; // @public (undocumented) const devtoolNamespace: z.ZodString; +// @public (undocumented) +class DirectoryWatcher extends EventEmitter { + constructor(directoryPath: string, options: Watchpack.WatcherOptions); + // (undocumented) + close(): void; + // (undocumented) + createNestedWatcher(directoryPath: string): void; + // (undocumented) + directories: { + [path: string]: Watcher_2 | true; + }; + // (undocumented) + doInitialScan(): void; + // (undocumented) + files: { + [path: string]: [number, number]; + }; + // (undocumented) + getTimes(): { + [path: string]: number; + }; + // (undocumented) + initialScan: boolean; + // (undocumented) + initialScanRemoved: string[]; + // (undocumented) + nestedWatching: boolean; + // (undocumented) + onChange(filePath: string, stat: fs_2.Stats): void; + // (undocumented) + onDirectoryAdded(directoryPath: string): void; + // (undocumented) + onDirectoryUnlinked(directoryPath: string): void; + // (undocumented) + onFileAdded(filePath: string, stat: fs_2.Stats): void; + // (undocumented) + onFileUnlinked(filePath: string): void; + // (undocumented) + onWatcherError(): void; + // (undocumented) + options: Watchpack.WatcherOptions; + // (undocumented) + path: string; + // (undocumented) + refs: number; + // (undocumented) + setDirectory(directoryPath: string, exist: boolean, initial: boolean): void; + // (undocumented) + setFileTime(filePath: string, mtime: number, initial: boolean, type?: string | boolean): void; + // (undocumented) + setNestedWatching(flag: boolean): void; + // (undocumented) + watch(filePath: string, startTime: number): Watcher_2; + // (undocumented) + watcher: fs_2.FSWatcher; + // (undocumented) + watchers: { + [path: string]: Watcher_2[]; + }; +} + // @public (undocumented) export const DynamicEntryPlugin: { new (context: string, entry: EntryDynamicNormalized): { @@ -2294,6 +2355,12 @@ const entry: z.ZodUnion<[z.ZodUnion<[z.ZodRecord]>>, z.ZodUnion<[z.ZodString, z.ZodArray]>]>>]>; +// @public (undocumented) +interface Entry_2 { + safeTime: number; + timestamp: number; +} + // @public (undocumented) export type EntryDependOn = z.infer; @@ -12234,6 +12301,23 @@ interface Watcher { pause(): void; } +// @public (undocumented) +class Watcher_2 extends EventEmitter { + constructor(directoryWatcher: DirectoryWatcher, filePath: string, startTime: number); + // (undocumented) + checkStartTime(mtime: number, initial: boolean): boolean; + // (undocumented) + close(): void; + // (undocumented) + data: number; + // (undocumented) + directoryWatcher: DirectoryWatcher; + // (undocumented) + path: string; + // (undocumented) + startTime: number; +} + // @public (undocumented) interface WatcherInfo { // (undocumented) @@ -12321,6 +12405,99 @@ const watchOptions: z.ZodObject<{ stdin?: boolean | undefined; }>; +// @public (undocumented) +class Watchpack extends EventEmitter { + constructor(options: Watchpack.WatchOptions); + // (undocumented) + aggregatedChanges: Set; + // (undocumented) + aggregatedRemovals: Set; + // (undocumented) + aggregateTimeout: NodeJS.Timer; + close(): void; + collectTimeInfoEntries(fileInfoEntries: Map, directoryInfoEntries: Map): void; + // (undocumented) + _dirWatcher(item: string, watcher: Watcher_2): Watcher_2; + // (undocumented) + dirWatchers: Watcher_2[]; + // (undocumented) + _fileWatcher(file: string, watcher: Watcher_2): Watcher_2; + // (undocumented) + fileWatchers: Watcher_2[]; + getAggregated(): { + changes: Set; + removals: Set; + }; + getTimeInfoEntries(): Map; + // @deprecated + getTimes(): { + [path: string]: number; + }; + mtimes: { + [path: string]: number; + }; + // (undocumented) + on( + eventName: "change", + listener: ( + filePath: string, + modifiedTime: number, + explanation: string, + ) => void, + ): this; + // (undocumented) + on( + eventName: "remove", + listener: ( + filePath: string, + explanation: string, + ) => void, + ): this; + // (undocumented) + on( + eventName: "aggregated", + listener: ( + changes: Set, + removals: Set, + ) => void, + ): this; + // (undocumented) + _onChange(item: string, mtime: number, file?: string): void; + // (undocumented) + _onTimeout(): void; + // (undocumented) + options: Watchpack.WatchOptions; + pause(): void; + // (undocumented) + paused: boolean; + watch(options: { + files?: Iterable; + directories?: Iterable; + missing?: Iterable; + startTime?: number; + }): void; + // (undocumented) + watcherOptions: Watchpack.WatcherOptions; +} + +// @public (undocumented) +namespace Watchpack { + // (undocumented) + interface WatcherOptions { + // (undocumented) + followSymlinks?: boolean; + // (undocumented) + ignored?: string[] | string | RegExp | ((path: string) => boolean) | undefined; + // (undocumented) + poll?: boolean | number | undefined; + } + // (undocumented) + interface WatchOptions extends WatcherOptions { + // (undocumented) + aggregateTimeout?: number | undefined; + } +} + // @public (undocumented) export type WebassemblyModuleFilename = z.infer; @@ -12365,6 +12542,11 @@ export type WorkerPublicPath = z.infer; // @public (undocumented) const workerPublicPath: z.ZodString; +// @public (undocumented) +namespace z { + { type z_AnyZodObject as AnyZodObject, type z_AnyZodTuple as AnyZodTuple, type z_ArrayCardinality as ArrayCardinality, type z_ArrayKeys as ArrayKeys, type z_AssertArray as AssertArray, type z_AsyncParseReturnType as AsyncParseReturnType, type z_BRAND as BRAND, type z_CatchallInput as CatchallInput, type z_CatchallOutput as CatchallOutput, type z_CustomErrorParams as CustomErrorParams, z_DIRTY as DIRTY, type z_DenormalizedError as DenormalizedError, z_EMPTY_PATH as EMPTY_PATH, type z_Effect as Effect, type z_EnumLike as EnumLike, type z_EnumValues as EnumValues, type z_ErrorMapCtx as ErrorMapCtx, type z_FilterEnum as FilterEnum, z_INVALID as INVALID, type z_Indices as Indices, type z_InnerTypeOfFunction as InnerTypeOfFunction, type z_InputTypeOfTuple as InputTypeOfTuple, type z_InputTypeOfTupleWithRest as InputTypeOfTupleWithRest, type z_IpVersion as IpVersion, type z_IssueData as IssueData, type z_KeySchema as KeySchema, z_NEVER as NEVER, z_OK as OK, type z_ObjectPair as ObjectPair, type z_OuterTypeOfFunction as OuterTypeOfFunction, type z_OutputTypeOfTuple as OutputTypeOfTuple, type z_OutputTypeOfTupleWithRest as OutputTypeOfTupleWithRest, type z_ParseContext as ParseContext, type z_ParseInput as ParseInput, type z_ParseParams as ParseParams, type z_ParsePath as ParsePath, type z_ParsePathComponent as ParsePathComponent, type z_ParseResult as ParseResult, type z_ParseReturnType as ParseReturnType, z_ParseStatus as ParseStatus, type z_PassthroughType as PassthroughType, type z_PreprocessEffect as PreprocessEffect, type z_Primitive as Primitive, type z_ProcessedCreateParams as ProcessedCreateParams, type z_RawCreateParams as RawCreateParams, type z_RecordType as RecordType, type z_Refinement as Refinement, type z_RefinementCtx as RefinementCtx, type z_RefinementEffect as RefinementEffect, type z_SafeParseError as SafeParseError, type z_SafeParseReturnType as SafeParseReturnType, type z_SafeParseSuccess as SafeParseSuccess, type z_Scalars as Scalars, ZodType as Schema, type z_SomeZodObject as SomeZodObject, type z_StringValidation as StringValidation, type z_SuperRefinement as SuperRefinement, type z_SyncParseReturnType as SyncParseReturnType, type z_TransformEffect as TransformEffect, type z_TypeOf as TypeOf, type z_UnknownKeysParam as UnknownKeysParam, type z_Values as Values, type z_Writeable as Writeable, z_ZodAny as ZodAny, type z_ZodAnyDef as ZodAnyDef, z_ZodArray as ZodArray, type z_ZodArrayDef as ZodArrayDef, z_ZodBigInt as ZodBigInt, type z_ZodBigIntCheck as ZodBigIntCheck, type z_ZodBigIntDef as ZodBigIntDef, z_ZodBoolean as ZodBoolean, type z_ZodBooleanDef as ZodBooleanDef, z_ZodBranded as ZodBranded, type z_ZodBrandedDef as ZodBrandedDef, z_ZodCatch as ZodCatch, type z_ZodCatchDef as ZodCatchDef, type z_ZodCustomIssue as ZodCustomIssue, z_ZodDate as ZodDate, type z_ZodDateCheck as ZodDateCheck, type z_ZodDateDef as ZodDateDef, z_ZodDefault as ZodDefault, type z_ZodDefaultDef as ZodDefaultDef, z_ZodDiscriminatedUnion as ZodDiscriminatedUnion, type z_ZodDiscriminatedUnionDef as ZodDiscriminatedUnionDef, type z_ZodDiscriminatedUnionOption as ZodDiscriminatedUnionOption, z_ZodEffects as ZodEffects, type z_ZodEffectsDef as ZodEffectsDef, z_ZodEnum as ZodEnum, type z_ZodEnumDef as ZodEnumDef, z_ZodError as ZodError, type z_ZodErrorMap as ZodErrorMap, type z_ZodFirstPartySchemaTypes as ZodFirstPartySchemaTypes, z_ZodFirstPartyTypeKind as ZodFirstPartyTypeKind, type z_ZodFormattedError as ZodFormattedError, z_ZodFunction as ZodFunction, type z_ZodFunctionDef as ZodFunctionDef, z_ZodIntersection as ZodIntersection, type z_ZodIntersectionDef as ZodIntersectionDef, type z_ZodInvalidArgumentsIssue as ZodInvalidArgumentsIssue, type z_ZodInvalidDateIssue as ZodInvalidDateIssue, type z_ZodInvalidEnumValueIssue as ZodInvalidEnumValueIssue, type z_ZodInvalidIntersectionTypesIssue as ZodInvalidIntersectionTypesIssue, type z_ZodInvalidLiteralIssue as ZodInvalidLiteralIssue, type z_ZodInvalidReturnTypeIssue as ZodInvalidReturnTypeIssue, type z_ZodInvalidStringIssue as ZodInvalidStringIssue, type z_ZodInvalidTypeIssue as ZodInvalidTypeIssue, type z_ZodInvalidUnionDiscriminatorIssue as ZodInvalidUnionDiscriminatorIssue, type z_ZodInvalidUnionIssue as ZodInvalidUnionIssue, type z_ZodIssue as ZodIssue, type z_ZodIssueBase as ZodIssueBase, type z_ZodIssueCode as ZodIssueCode, type z_ZodIssueOptionalMessage as ZodIssueOptionalMessage, z_ZodLazy as ZodLazy, type z_ZodLazyDef as ZodLazyDef, z_ZodLiteral as ZodLiteral, type z_ZodLiteralDef as ZodLiteralDef, z_ZodMap as ZodMap, type z_ZodMapDef as ZodMapDef, z_ZodNaN as ZodNaN, type z_ZodNaNDef as ZodNaNDef, z_ZodNativeEnum as ZodNativeEnum, type z_ZodNativeEnumDef as ZodNativeEnumDef, z_ZodNever as ZodNever, type z_ZodNeverDef as ZodNeverDef, type z_ZodNonEmptyArray as ZodNonEmptyArray, type z_ZodNotFiniteIssue as ZodNotFiniteIssue, type z_ZodNotMultipleOfIssue as ZodNotMultipleOfIssue, z_ZodNull as ZodNull, type z_ZodNullDef as ZodNullDef, z_ZodNullable as ZodNullable, type z_ZodNullableDef as ZodNullableDef, type z_ZodNullableType as ZodNullableType, z_ZodNumber as ZodNumber, type z_ZodNumberCheck as ZodNumberCheck, type z_ZodNumberDef as ZodNumberDef, z_ZodObject as ZodObject, type z_ZodObjectDef as ZodObjectDef, z_ZodOptional as ZodOptional, type z_ZodOptionalDef as ZodOptionalDef, type z_ZodOptionalType as ZodOptionalType, type z_ZodParsedType as ZodParsedType, z_ZodPipeline as ZodPipeline, type z_ZodPipelineDef as ZodPipelineDef, z_ZodPromise as ZodPromise, type z_ZodPromiseDef as ZodPromiseDef, type z_ZodRawShape as ZodRawShape, z_ZodReadonly as ZodReadonly, type z_ZodReadonlyDef as ZodReadonlyDef, z_ZodRecord as ZodRecord, type z_ZodRecordDef as ZodRecordDef, ZodType as ZodSchema, z_ZodSet as ZodSet, type z_ZodSetDef as ZodSetDef, z_ZodString as ZodString, type z_ZodStringCheck as ZodStringCheck, type z_ZodStringDef as ZodStringDef, z_ZodSymbol as ZodSymbol, type z_ZodSymbolDef as ZodSymbolDef, type z_ZodTooBigIssue as ZodTooBigIssue, type z_ZodTooSmallIssue as ZodTooSmallIssue, ZodEffects as ZodTransformer, z_ZodTuple as ZodTuple, type z_ZodTupleDef as ZodTupleDef, type z_ZodTupleItems as ZodTupleItems, z_ZodType as ZodType, type z_ZodTypeAny as ZodTypeAny, type z_ZodTypeDef as ZodTypeDef, z_ZodUndefined as ZodUndefined, type z_ZodUndefinedDef as ZodUndefinedDef, z_ZodUnion as ZodUnion, type z_ZodUnionDef as ZodUnionDef, type z_ZodUnionOptions as ZodUnionOptions, z_ZodUnknown as ZodUnknown, type z_ZodUnknownDef as ZodUnknownDef, type z_ZodUnrecognizedKeysIssue as ZodUnrecognizedKeysIssue, z_ZodVoid as ZodVoid, type z_ZodVoidDef as ZodVoidDef, z_addIssueToContext as addIssueToContext, anyType as any, arrayType as array, type z_arrayOutputType as arrayOutputType, type z_baseObjectInputType as baseObjectInputType, type z_baseObjectOutputType as baseObjectOutputType, bigIntType as bigint, booleanType as boolean, z_coerce as coerce, z_custom as custom, dateType as date, errorMap as defaultErrorMap, type z_deoptional as deoptional, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, z_getErrorMap as getErrorMap, z_getParsedType as getParsedType, type TypeOf as infer, type z_inferFlattenedErrors as inferFlattenedErrors, type z_inferFormattedError as inferFormattedError, type z_input as input, instanceOfType as instanceof, intersectionType as intersection, z_isAborted as isAborted, z_isAsync as isAsync, z_isDirty as isDirty, z_isValid as isValid, z_late as late, lazyType as lazy, literalType as literal, z_makeIssue as makeIssue, mapType as map, type z_mergeTypes as mergeTypes, nanType as nan, nativeEnumType as nativeEnum, neverType as never, type z_noUnrecognized as noUnrecognized, nullType as null, nullableType as nullable, numberType as number, objectType as object, type z_objectInputType as objectInputType, type z_objectOutputType as objectOutputType, z_objectUtil as objectUtil, z_oboolean as oboolean, z_onumber as onumber, optionalType as optional, z_ostring as ostring, type z_output as output, pipelineType as pipeline, preprocessType as preprocess, promiseType as promise, z_quotelessJson as quotelessJson, recordType as record, setType as set, z_setErrorMap as setErrorMap, strictObjectType as strictObject, stringType as string, symbolType as symbol, effectsType as transformer, tupleType as tuple, type z_typeToFlattenedError as typeToFlattenedError, type z_typecast as typecast, undefinedType as undefined, unionType as union, unknownType as unknown, z_util as util, voidType as void }; +} + // (No @packageDocumentation comment for this package) ``` From 4c61aad69e96f0b5c828d6bcd9a980bc4f27e61e Mon Sep 17 00:00:00 2001 From: jinrui Date: Wed, 8 May 2024 11:42:52 +0800 Subject: [PATCH 021/107] fix: add trace log for module executor (#6451) --- crates/rspack_core/src/compiler/module_executor/ctrl.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/rspack_core/src/compiler/module_executor/ctrl.rs b/crates/rspack_core/src/compiler/module_executor/ctrl.rs index 550980dd14b0..f2d97e66b3e2 100644 --- a/crates/rspack_core/src/compiler/module_executor/ctrl.rs +++ b/crates/rspack_core/src/compiler/module_executor/ctrl.rs @@ -45,6 +45,7 @@ impl UnfinishCounter { } // send event can only use in sync task +#[derive(Debug)] pub enum Event { StartBuild(ModuleIdentifier), // origin_module_identifier and current dependency id and target_module_identifier @@ -84,6 +85,7 @@ impl Task for CtrlTask { async fn async_run(mut self: Box) -> TaskResult { while let Some(event) = self.event_receiver.recv().await { + tracing::info!("CtrlTask async receive {:?}", event); match event { Event::StartBuild(module_identifier) => { self @@ -176,6 +178,7 @@ impl Task for FinishModuleTask { // clean ctrl task events loop { let event = ctrl_task.event_receiver.try_recv(); + tracing::info!("CtrlTask sync receive {:?}", event); let Ok(event) = event else { if matches!(event, Err(TryRecvError::Empty)) { break; @@ -246,6 +249,7 @@ impl Task for FinishModuleTask { } while let Some(module_identifier) = queue.pop_front() { + tracing::info!("finish build module {:?}", module_identifier); ctrl_task.running_module_map.remove(&module_identifier); let mgm = module_graph From 025b32ce06dd9bc03c83ebca037a9e9da9de975e Mon Sep 17 00:00:00 2001 From: Hana Date: Wed, 8 May 2024 15:31:11 +0800 Subject: [PATCH 022/107] perf: on-demand sourcemap generation (#6443) --- Cargo.lock | 1 + .../src/options/raw_builtins/mod.rs | 2 + .../src/compiler/make/repair/build.rs | 2 +- crates/rspack_core/src/concatenated_module.rs | 2 +- crates/rspack_core/src/context_module.rs | 2 +- crates/rspack_core/src/external_module.rs | 2 +- crates/rspack_core/src/normal_module.rs | 8 ++-- crates/rspack_core/src/raw_module.rs | 2 +- crates/rspack_core/src/self_module.rs | 2 +- crates/rspack_loader_swc/src/lib.rs | 12 +++--- .../src/parser_and_generator/mod.rs | 9 ++--- crates/rspack_plugin_css/src/runtime/mod.rs | 2 +- crates/rspack_plugin_devtool/src/lib.rs | 10 ++++- .../src/css_module.rs | 2 +- .../rspack_plugin_extract_css/src/runtime.rs | 2 +- .../src/hot_module_replacement.rs | 2 +- .../src/ast/stringify.rs | 12 ++---- .../src/parser_and_generator/mod.rs | 5 +-- .../src/plugin/module_concatenation_plugin.rs | 2 +- .../src/container/container_entry_module.rs | 2 +- .../src/container/expose_runtime_module.rs | 2 +- .../src/container/fallback_module.rs | 2 +- .../module_federation_runtime_plugin.rs | 2 +- .../src/container/remote_module.rs | 2 +- .../src/container/remote_runtime_module.rs | 2 +- .../src/sharing/consume_shared_module.rs | 2 +- .../sharing/consume_shared_runtime_module.rs | 2 +- .../src/sharing/provide_shared_module.rs | 2 +- .../src/sharing/share_runtime_module.rs | 2 +- .../src/runtime_module/async_module.rs | 2 +- .../src/runtime_module/auto_public_path.rs | 2 +- .../src/runtime_module/base_uri.rs | 2 +- .../src/runtime_module/chunk_name.rs | 2 +- .../chunk_prefetch_preload_function.rs | 2 +- .../runtime_module/chunk_prefetch_startup.rs | 2 +- .../runtime_module/chunk_prefetch_trigger.rs | 2 +- .../runtime_module/chunk_preload_trigger.rs | 2 +- .../compat_get_default_export.rs | 2 +- .../create_fake_namespace_object.rs | 2 +- .../src/runtime_module/create_script_url.rs | 2 +- .../runtime_module/define_property_getters.rs | 2 +- .../src/runtime_module/ensure_chunk.rs | 2 +- .../runtime_module/export_webpack_require.rs | 2 +- .../src/runtime_module/get_chunk_filename.rs | 2 +- .../get_chunk_update_filename.rs | 2 +- .../src/runtime_module/get_full_hash.rs | 2 +- .../src/runtime_module/get_main_filename.rs | 2 +- .../get_trusted_types_policy.rs | 2 +- .../src/runtime_module/global.rs | 2 +- .../harmony_module_decorator.rs | 2 +- .../src/runtime_module/has_own_property.rs | 2 +- .../import_scripts_chunk_loading.rs | 2 +- .../src/runtime_module/jsonp_chunk_loading.rs | 2 +- .../src/runtime_module/load_script.rs | 2 +- .../runtime_module/make_namespace_object.rs | 2 +- .../runtime_module/module_chunk_loading.rs | 2 +- .../runtime_module/node_module_decorator.rs | 2 +- .../src/runtime_module/nonce.rs | 2 +- .../src/runtime_module/normal.rs | 2 +- .../src/runtime_module/on_chunk_loaded.rs | 2 +- .../src/runtime_module/public_path.rs | 2 +- .../runtime_module/readfile_chunk_loading.rs | 2 +- .../src/runtime_module/relative_url.rs | 2 +- .../require_js_chunk_loading.rs | 2 +- .../src/runtime_module/rspack_version.rs | 2 +- .../src/runtime_module/runtime_id.rs | 2 +- .../startup_chunk_dependencies.rs | 2 +- .../src/runtime_module/startup_entry_point.rs | 2 +- .../src/runtime_module/system_context.rs | 2 +- crates/rspack_plugin_wasm/src/runtime.rs | 2 +- crates/rspack_util/Cargo.toml | 1 + crates/rspack_util/src/source_map.rs | 39 ++++++++++++++++--- 72 files changed, 128 insertions(+), 95 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6bd96522648..601f33ee35d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3662,6 +3662,7 @@ dependencies = [ name = "rspack_util" version = "0.1.0" dependencies = [ + "bitflags 2.5.0", "concat-string", "dashmap", "indexmap 2.2.6", diff --git a/crates/rspack_binding_options/src/options/raw_builtins/mod.rs b/crates/rspack_binding_options/src/options/raw_builtins/mod.rs index 3a8ba6e5ae36..1b1ace1fb8a3 100644 --- a/crates/rspack_binding_options/src/options/raw_builtins/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_builtins/mod.rs @@ -355,6 +355,7 @@ impl BuiltinPlugin { plugins.push( SourceMapDevToolModuleOptionsPlugin::new(SourceMapDevToolModuleOptionsPluginOptions { module: options.module, + cheap: !options.columns, }) .boxed(), ); @@ -366,6 +367,7 @@ impl BuiltinPlugin { plugins.push( SourceMapDevToolModuleOptionsPlugin::new(SourceMapDevToolModuleOptionsPluginOptions { module: options.module, + cheap: !options.columns, }) .boxed(), ); diff --git a/crates/rspack_core/src/compiler/make/repair/build.rs b/crates/rspack_core/src/compiler/make/repair/build.rs index af4a8658c4f5..dc3f7ef84ecd 100644 --- a/crates/rspack_core/src/compiler/make/repair/build.rs +++ b/crates/rspack_core/src/compiler/make/repair/build.rs @@ -55,7 +55,7 @@ impl Task for BuildTask { resolver_factory: resolver_factory.clone(), module: module.identifier(), module_context: module.as_normal_module().and_then(|m| m.get_context()), - module_source_map_kind: module.get_source_map_kind().clone(), + module_source_map_kind: *module.get_source_map_kind(), plugin_driver: plugin_driver.clone(), cache: cache.clone(), }, diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 9545b2c0c7de..1a881c947048 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -395,7 +395,7 @@ impl ConcatenatedModule { diagnostics: Mutex::new(vec![]), cached_hash: OnceCell::default(), build_info: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } diff --git a/crates/rspack_core/src/context_module.rs b/crates/rspack_core/src/context_module.rs index ae61628f82e1..661fba4e13cc 100644 --- a/crates/rspack_core/src/context_module.rs +++ b/crates/rspack_core/src/context_module.rs @@ -198,7 +198,7 @@ impl ContextModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } diff --git a/crates/rspack_core/src/external_module.rs b/crates/rspack_core/src/external_module.rs index 628bd6f7a9c2..dab673e22c5d 100644 --- a/crates/rspack_core/src/external_module.rs +++ b/crates/rspack_core/src/external_module.rs @@ -110,7 +110,7 @@ impl ExternalModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index c8a4d2d092a4..dc094c89e3ef 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -225,7 +225,7 @@ impl NormalModule { build_meta: None, parsed: false, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } @@ -508,7 +508,7 @@ impl Module for NormalModule { module_parser_options: self.parser_options.as_ref(), module_type: &self.module_type, module_user_request: &self.user_request, - module_source_map_kind: self.get_source_map_kind().clone(), + module_source_map_kind: *self.get_source_map_kind(), loaders: &self.loaders, resource_data: &self.resource_data, compiler_options: build_context.compiler_options, @@ -755,7 +755,7 @@ impl NormalModule { return Ok(RawSource::Buffer(content.into_bytes()).boxed()); } let source_map_kind = self.get_source_map_kind(); - if !matches!(source_map_kind, SourceMapKind::None) + if source_map_kind.enabled() && let Some(source_map) = source_map { let content = content.into_string_lossy(); @@ -768,7 +768,7 @@ impl NormalModule { .boxed(), ); } - if !matches!(source_map_kind, SourceMapKind::None) + if source_map_kind.enabled() && let Content::String(content) = content { return Ok(OriginalSource::new(content, self.request()).boxed()); diff --git a/crates/rspack_core/src/raw_module.rs b/crates/rspack_core/src/raw_module.rs index 01d75b0149e1..dbec11e63462 100644 --- a/crates/rspack_core/src/raw_module.rs +++ b/crates/rspack_core/src/raw_module.rs @@ -49,7 +49,7 @@ impl RawModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } } diff --git a/crates/rspack_core/src/self_module.rs b/crates/rspack_core/src/self_module.rs index b1240fca54f0..cdaac59f82c5 100644 --- a/crates/rspack_core/src/self_module.rs +++ b/crates/rspack_core/src/self_module.rs @@ -39,7 +39,7 @@ impl SelfModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } } diff --git a/crates/rspack_loader_swc/src/lib.rs b/crates/rspack_loader_swc/src/lib.rs index 83fcff5659b9..67ede9862af1 100644 --- a/crates/rspack_loader_swc/src/lib.rs +++ b/crates/rspack_loader_swc/src/lib.rs @@ -80,9 +80,9 @@ impl Loader for SwcLoader { swc_options }; - let source_map_kind: &SourceMapKind = match swc_options.config.source_maps { - Some(SourceMapsConfig::Bool(false)) => &SourceMapKind::None, - _ => &loader_context.context.module_source_map_kind, + let source_map_kind: SourceMapKind = match swc_options.config.source_maps { + Some(SourceMapsConfig::Bool(false)) => SourceMapKind::empty(), + _ => loader_context.context.module_source_map_kind, }; let source = content.try_into_string()?; @@ -122,9 +122,9 @@ impl Loader for SwcLoader { .as_ref() .map(|v| matches!(v, OutputCharset::Ascii)), source_map_config: SourceMapConfig { - enable: !matches!(source_map_kind, SourceMapKind::None), - inline_sources_content: true, - emit_columns: matches!(source_map_kind, SourceMapKind::SourceMap), + enable: source_map_kind.source_map(), + inline_sources_content: source_map_kind.source_map(), + emit_columns: !source_map_kind.cheap(), names: Default::default(), }, inline_script: Some(false), diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index b792448ea73a..739464a5cfe9 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -18,7 +18,6 @@ use rspack_core::{ }; use rspack_core::{ModuleInitFragments, RuntimeGlobals}; use rspack_error::{IntoTWithDiagnosticArray, Result, TWithDiagnosticArray}; -use rspack_util::source_map::SourceMapKind; use rustc_hash::FxHashSet; use swc_core::{ css::{parser::parser::ParserConfig, visit::VisitWith}, @@ -156,9 +155,9 @@ impl ParserAndGenerator for CssParserAndGenerator { let (code, map) = swc_compiler.codegen( &stylesheet, SwcCssSourceMapGenConfig { - enable: !matches!(module_source_map_kind, SourceMapKind::None), - inline_sources_content: false, - emit_columns: matches!(module_source_map_kind, SourceMapKind::SourceMap), + enable: module_source_map_kind.enabled(), + inline_sources_content: module_source_map_kind.source_map(), + emit_columns: !module_source_map_kind.cheap(), }, )?; source_code = code; @@ -251,7 +250,7 @@ impl ParserAndGenerator for CssParserAndGenerator { dependencies }; - let new_source = if !matches!(module_source_map_kind, SourceMapKind::None) { + let new_source = if module_source_map_kind.enabled() { if let Some(source_map) = source_map { SourceMapSource::new(SourceMapSourceOptions { value: source_code, diff --git a/crates/rspack_plugin_css/src/runtime/mod.rs b/crates/rspack_plugin_css/src/runtime/mod.rs index 5a94b142b2e3..20ec867c0f62 100644 --- a/crates/rspack_plugin_css/src/runtime/mod.rs +++ b/crates/rspack_plugin_css/src/runtime/mod.rs @@ -21,7 +21,7 @@ impl Default for CssLoadingRuntimeModule { Self { id: Identifier::from("webpack/runtime/css_loading"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_devtool/src/lib.rs b/crates/rspack_plugin_devtool/src/lib.rs index 3259907641db..676b94e9e8b3 100644 --- a/crates/rspack_plugin_devtool/src/lib.rs +++ b/crates/rspack_plugin_devtool/src/lib.rs @@ -941,17 +941,19 @@ impl Plugin for EvalSourceMapDevToolPlugin { pub struct SourceMapDevToolModuleOptionsPluginOptions { pub module: bool, + pub cheap: bool, } #[plugin] #[derive(Debug)] pub struct SourceMapDevToolModuleOptionsPlugin { module: bool, + cheap: bool, } impl SourceMapDevToolModuleOptionsPlugin { pub fn new(options: SourceMapDevToolModuleOptionsPluginOptions) -> Self { - Self::new_inner(options.module) + Self::new_inner(options.module, options.cheap) } } @@ -962,6 +964,9 @@ async fn build_module(&self, module: &mut BoxModule) -> Result<()> { } else { module.set_source_map_kind(SourceMapKind::SimpleSourceMap); } + if self.cheap { + module.set_source_map_kind(*module.get_source_map_kind() | SourceMapKind::Cheap) + } Ok(()) } @@ -980,6 +985,9 @@ async fn runtime_module( } else { module.set_source_map_kind(SourceMapKind::SimpleSourceMap); } + if self.cheap { + module.set_source_map_kind(*module.get_source_map_kind() | SourceMapKind::Cheap) + } Ok(()) } diff --git a/crates/rspack_plugin_extract_css/src/css_module.rs b/crates/rspack_plugin_extract_css/src/css_module.rs index 1b7b61a5d04b..fbd4e364f7eb 100644 --- a/crates/rspack_plugin_extract_css/src/css_module.rs +++ b/crates/rspack_plugin_extract_css/src/css_module.rs @@ -78,7 +78,7 @@ impl CssModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: rspack_util::source_map::SourceMapKind::None, + source_map_kind: rspack_util::source_map::SourceMapKind::empty(), identifier__, filepath: dep.filepath, } diff --git a/crates/rspack_plugin_extract_css/src/runtime.rs b/crates/rspack_plugin_extract_css/src/runtime.rs index 417a2a2d2409..34179e836351 100644 --- a/crates/rspack_plugin_extract_css/src/runtime.rs +++ b/crates/rspack_plugin_extract_css/src/runtime.rs @@ -41,7 +41,7 @@ impl CssLoadingRuntimeModule { insert, loading, hmr, - source_map_kind: rspack_util::source_map::SourceMapKind::None, + source_map_kind: rspack_util::source_map::SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_hmr/src/hot_module_replacement.rs b/crates/rspack_plugin_hmr/src/hot_module_replacement.rs index 55bebb784cb6..a32d95019b59 100644 --- a/crates/rspack_plugin_hmr/src/hot_module_replacement.rs +++ b/crates/rspack_plugin_hmr/src/hot_module_replacement.rs @@ -19,7 +19,7 @@ impl Default for HotModuleReplacementRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/hot_module_replacement"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_javascript/src/ast/stringify.rs b/crates/rspack_plugin_javascript/src/ast/stringify.rs index 85b1000889ee..547b8b256037 100644 --- a/crates/rspack_plugin_javascript/src/ast/stringify.rs +++ b/crates/rspack_plugin_javascript/src/ast/stringify.rs @@ -36,9 +36,9 @@ impl CodegenOptions { pub fn new(source_map_kind: &SourceMapKind, keep_comments: Option) -> Self { Self { source_map_config: SourceMapConfig { - enable: !matches!(source_map_kind, SourceMapKind::None), - inline_sources_content: true, - emit_columns: matches!(source_map_kind, SourceMapKind::SourceMap), + enable: source_map_kind.enabled(), + inline_sources_content: source_map_kind.source_map(), + emit_columns: !source_map_kind.cheap(), names: Default::default(), }, keep_comments, @@ -92,11 +92,7 @@ pub fn print( source_map.clone(), "\n", &mut buf, - if source_map_config.enable { - Some(&mut src_map_buf) - } else { - None - }, + source_map_config.enable.then_some(&mut src_map_buf), )) as Box; if minify { diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index 25da337c08f9..dafb6997e048 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -16,7 +16,6 @@ use rspack_core::{ }; use rspack_error::miette::Diagnostic; use rspack_error::{DiagnosticExt, IntoTWithDiagnosticArray, Result, TWithDiagnosticArray}; -use rspack_util::source_map::SourceMapKind; use swc_core::common::{Span, SyntaxContext}; use swc_core::ecma::parser::{EsConfig, Syntax}; @@ -106,8 +105,8 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { allow_super_outside_method: true, ..Default::default() }); - let use_source_map = matches!(module_source_map_kind, SourceMapKind::SourceMap); - let enable_source_map = !matches!(module_source_map_kind, SourceMapKind::None); + let use_source_map = module_source_map_kind.source_map(); + let enable_source_map = module_source_map_kind.enabled(); let original_map = source.map(&MapOptions::new(use_source_map)); let source = source.source(); diff --git a/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs index 2c92e100077f..b06be0fee500 100644 --- a/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs @@ -912,7 +912,7 @@ impl ModuleConcatenationPlugin { resolver_factory: compilation.resolver_factory.clone(), module: new_module.id(), module_context: None, - module_source_map_kind: rspack_util::source_map::SourceMapKind::None, + module_source_map_kind: rspack_util::source_map::SourceMapKind::empty(), cache: compilation.cache.clone(), plugin_driver: compilation.plugin_driver.clone(), }, diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index 62895feb9229..52b98c632dda 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -59,7 +59,7 @@ impl ContainerEntryModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), enhanced, } } diff --git a/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs b/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs index de9dc3d65fcc..d87ee5c35fb7 100644 --- a/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/expose_runtime_module.rs @@ -21,7 +21,7 @@ impl ExposeRuntimeModule { Self { id: Identifier::from("webpack/runtime/initialize_exposes"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_mf/src/container/fallback_module.rs b/crates/rspack_plugin_mf/src/container/fallback_module.rs index 20eca227b524..59c85c3ec62f 100644 --- a/crates/rspack_plugin_mf/src/container/fallback_module.rs +++ b/crates/rspack_plugin_mf/src/container/fallback_module.rs @@ -52,7 +52,7 @@ impl FallbackModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } } diff --git a/crates/rspack_plugin_mf/src/container/module_federation_runtime_plugin.rs b/crates/rspack_plugin_mf/src/container/module_federation_runtime_plugin.rs index 37c38e233656..86e57fa852e6 100644 --- a/crates/rspack_plugin_mf/src/container/module_federation_runtime_plugin.rs +++ b/crates/rspack_plugin_mf/src/container/module_federation_runtime_plugin.rs @@ -22,7 +22,7 @@ impl Default for FederationRuntimeModule { Self { id: Identifier::from("module_federation/runtime"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_mf/src/container/remote_module.rs b/crates/rspack_plugin_mf/src/container/remote_module.rs index e8297b0a156e..967ead5b05d9 100644 --- a/crates/rspack_plugin_mf/src/container/remote_module.rs +++ b/crates/rspack_plugin_mf/src/container/remote_module.rs @@ -69,7 +69,7 @@ impl RemoteModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } } diff --git a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs index 00268eeef33f..42decc40523a 100644 --- a/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/container/remote_runtime_module.rs @@ -25,7 +25,7 @@ impl RemoteRuntimeModule { id: Identifier::from("webpack/runtime/remotes_loading"), chunk: None, enhanced, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs index 0181f3d471c2..726d42152060 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs @@ -78,7 +78,7 @@ impl ConsumeSharedModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } } diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs index bd47304275b6..45d8e2109628 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs @@ -25,7 +25,7 @@ impl ConsumeSharedRuntimeModule { id: Identifier::from("webpack/runtime/consumes_loading"), chunk: None, enhanced, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs b/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs index 8800dbe005d3..72b6ce7f7b92 100644 --- a/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs @@ -65,7 +65,7 @@ impl ProvideSharedModule { factory_meta: None, build_info: None, build_meta: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), } } } diff --git a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs index 66a29f795567..898a2bd0a912 100644 --- a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs @@ -26,7 +26,7 @@ impl ShareRuntimeModule { id: Identifier::from("webpack/runtime/sharing"), chunk: None, enhanced, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs b/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs index a70d6983e2b2..7bedd97a5ec8 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/async_module.rs @@ -15,7 +15,7 @@ impl Default for AsyncRuntimeModule { fn default() -> Self { AsyncRuntimeModule { id: Identifier::from("webpack/runtime/async_module"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs b/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs index 780b9cf11145..3a4a63829463 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/auto_public_path.rs @@ -21,7 +21,7 @@ impl Default for AutoPublicPathRuntimeModule { Self { id: Identifier::from("webpack/runtime/auto_public_path"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs b/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs index 2c3ae5638550..16fe64d00416 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/base_uri.rs @@ -17,7 +17,7 @@ impl Default for BaseUriRuntimeModule { BaseUriRuntimeModule { id: Identifier::from("webpack/runtime/base_uri"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs index 7ce00bbdadbd..6e07be0f3060 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_name.rs @@ -18,7 +18,7 @@ impl Default for ChunkNameRuntimeModule { Self { id: Identifier::from("webpack/runtime/chunk_name"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs index 082b0f4aa2f0..2fb1abc9c3d5 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_preload_function.rs @@ -27,7 +27,7 @@ impl ChunkPrefetchPreloadFunctionRuntimeModule { )), runtime_function, runtime_handlers, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_startup.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_startup.rs index 9b39e9123a3b..b025efa16542 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_startup.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_startup.rs @@ -21,7 +21,7 @@ impl ChunkPrefetchStartupRuntimeModule { id: Identifier::from("webpack/runtime/chunk_prefetch_startup"), startup_chunks, chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_trigger.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_trigger.rs index ed64174ab396..03e34e7d81d4 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_trigger.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_prefetch_trigger.rs @@ -22,7 +22,7 @@ impl ChunkPrefetchTriggerRuntimeModule { Self { id: Identifier::from("webpack/runtime/chunk_prefetch_trigger"), chunk_map, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/chunk_preload_trigger.rs b/crates/rspack_plugin_runtime/src/runtime_module/chunk_preload_trigger.rs index 69c887fc2e44..1d9b4dd17cd7 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/chunk_preload_trigger.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/chunk_preload_trigger.rs @@ -22,7 +22,7 @@ impl ChunkPreloadTriggerRuntimeModule { Self { id: Identifier::from("webpack/runtime/chunk_preload_trigger"), chunk_map, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs b/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs index 148ee44f8339..f4d064dad6ff 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/compat_get_default_export.rs @@ -16,7 +16,7 @@ impl Default for CompatGetDefaultExportRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/compat_get_default_export"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs index b6f26d41cb02..8d95ff9fa03d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_fake_namespace_object.rs @@ -16,7 +16,7 @@ impl Default for CreateFakeNamespaceObjectRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/create_fake_namespace_object"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs b/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs index b3f3fc21f26d..40dba3a9423b 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/create_script_url.rs @@ -16,7 +16,7 @@ impl Default for CreateScriptUrlRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/create_script_url"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs b/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs index cbc80f351b61..6b9e4a4025e9 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/define_property_getters.rs @@ -16,7 +16,7 @@ impl Default for DefinePropertyGettersRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/define_property_getters"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs b/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs index 58f3533d594d..840a81ec0184 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/ensure_chunk.rs @@ -20,7 +20,7 @@ impl Default for EnsureChunkRuntimeModule { Self { id: Identifier::from("webpack/runtime/ensure_chunk"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs b/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs index 2bcce0e2e1cd..174a306eb157 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs @@ -16,7 +16,7 @@ impl ExportWebpackRequireRuntimeModule { pub fn new() -> Self { Self { id: Identifier::from("webpack/runtime/export_webpack_runtime"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs index 3e458263c665..61c6c920f313 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_filename.rs @@ -68,7 +68,7 @@ impl GetChunkFilenameRuntimeModule { global, all_chunks: Box::new(all_chunks), filename_for_chunk: Box::new(filename_for_chunk), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs index 5608f00f4465..5b74f5dc361e 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_chunk_update_filename.rs @@ -19,7 +19,7 @@ impl Default for GetChunkUpdateFilenameRuntimeModule { Self { chunk: None, id: Identifier::from("webpack/runtime/get_chunk_update_filename"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs index 5e5339d6c093..44f16a2548fb 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_full_hash.rs @@ -16,7 +16,7 @@ impl Default for GetFullHashRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/get_full_hash"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs index 3cd18259c685..023ff079cd01 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_main_filename.rs @@ -24,7 +24,7 @@ impl GetMainFilenameRuntimeModule { id: Identifier::from(format!("webpack/runtime/get_main_filename/{content_type}")), global, filename, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs b/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs index f54047a1f4bb..df1a3b422022 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/get_trusted_types_policy.rs @@ -20,7 +20,7 @@ impl Default for GetTrustedTypesPolicyRuntimeModule { Self { id: Identifier::from("webpack/runtime/get_trusted_types_policy"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/global.rs b/crates/rspack_plugin_runtime/src/runtime_module/global.rs index 9e24eddc99fe..54365e21f61b 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/global.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/global.rs @@ -16,7 +16,7 @@ impl Default for GlobalRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/global"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/harmony_module_decorator.rs b/crates/rspack_plugin_runtime/src/runtime_module/harmony_module_decorator.rs index 3a825a87ce13..99cbf02f94bc 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/harmony_module_decorator.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/harmony_module_decorator.rs @@ -16,7 +16,7 @@ impl Default for HarmonyModuleDecoratorRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/harmony_module_decorator"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs b/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs index dbeedf71d001..ff30985bd787 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/has_own_property.rs @@ -16,7 +16,7 @@ impl Default for HasOwnPropertyRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/has_own_property"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs index 3b7b01a8b649..2f0c15e5ce70 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/import_scripts_chunk_loading.rs @@ -29,7 +29,7 @@ impl ImportScriptsChunkLoadingRuntimeModule { id: Identifier::from("webpack/runtime/import_scripts_chunk_loading"), chunk: None, with_create_script_url, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs index 14ab0d819edc..1cf67cebe005 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/jsonp_chunk_loading.rs @@ -25,7 +25,7 @@ impl Default for JsonpChunkLoadingRuntimeModule { Self { id: Identifier::from("webpack/runtime/jsonp_chunk_loading"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs index d7cf13a11f48..14cc98715945 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/load_script.rs @@ -20,7 +20,7 @@ impl LoadScriptRuntimeModule { id: Identifier::from("webpack/runtime/load_script"), unique_name, with_create_script_url, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs b/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs index c4f20caff768..53ac866c344e 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/make_namespace_object.rs @@ -16,7 +16,7 @@ impl Default for MakeNamespaceObjectRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/make_namespace_object"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs index acc975bd67ac..11b241e5b069 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs @@ -24,7 +24,7 @@ impl Default for ModuleChunkLoadingRuntimeModule { Self { id: Identifier::from("webpack/runtime/module_chunk_loading"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs b/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs index f2514b04d0d4..95640457530d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/node_module_decorator.rs @@ -16,7 +16,7 @@ impl Default for NodeModuleDecoratorRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/node_module_decorator"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs b/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs index e05e9060fc47..4e2e7d15a37f 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/nonce.rs @@ -16,7 +16,7 @@ impl Default for NonceRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/nonce"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/normal.rs b/crates/rspack_plugin_runtime/src/runtime_module/normal.rs index 0daf1e4bb88f..112ae33fb773 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/normal.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/normal.rs @@ -18,7 +18,7 @@ impl NormalRuntimeModule { Self { identifier: Identifier::from(identifier.name()), sources, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs b/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs index f5550254dc37..6a6b5e4ec2a1 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/on_chunk_loaded.rs @@ -16,7 +16,7 @@ impl Default for OnChunkLoadedRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/on_chunk_loaded"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs b/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs index e3c7fcdff3b6..cbfdc2bbef9d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/public_path.rs @@ -18,7 +18,7 @@ impl PublicPathRuntimeModule { Self { id: Identifier::from("webpack/runtime/public_path"), public_path, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs index 27ecafa975da..80cff0574d6a 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/readfile_chunk_loading.rs @@ -27,7 +27,7 @@ impl Default for ReadFileChunkLoadingRuntimeModule { Self { id: Identifier::from("webpack/runtime/readfile_chunk_loading"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs b/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs index 87efa8f77d65..a0d340d6443d 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/relative_url.rs @@ -16,7 +16,7 @@ impl Default for RelativeUrlRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/relative_url"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs b/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs index a701931d3a36..51d059a7319f 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/require_js_chunk_loading.rs @@ -27,7 +27,7 @@ impl Default for RequireChunkLoadingRuntimeModule { Self { id: Identifier::from("webpack/runtime/require_chunk_loading"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs b/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs index fea4fdbbdf78..dcdc9b8dcb19 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/rspack_version.rs @@ -18,7 +18,7 @@ impl RspackVersionRuntimeModule { Self { id: Identifier::from("webpack/runtime/rspack_version"), version, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs b/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs index ed4e94943d7b..71ac20533548 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/runtime_id.rs @@ -19,7 +19,7 @@ impl Default for RuntimeIdRuntimeModule { Self { id: Identifier::from("webpack/runtime/runtime_id"), chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs b/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs index d52c206c2681..27b1ce6cf3f8 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/startup_chunk_dependencies.rs @@ -23,7 +23,7 @@ impl StartupChunkDependenciesRuntimeModule { id: Identifier::from("webpack/runtime/startup_chunk_dependencies"), async_chunk_loading, chunk: None, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/startup_entry_point.rs b/crates/rspack_plugin_runtime/src/runtime_module/startup_entry_point.rs index 90ea19290e59..c7e285c95cda 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/startup_entry_point.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/startup_entry_point.rs @@ -18,7 +18,7 @@ impl StartupEntrypointRuntimeModule { Self { id: Identifier::from("webpack/runtime/startup_entrypoint"), async_chunk_loading, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs b/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs index 87044b16b464..bca80026225f 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/system_context.rs @@ -16,7 +16,7 @@ impl Default for SystemContextRuntimeModule { fn default() -> Self { Self { id: Identifier::from("webpack/runtime/start_entry_point"), - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_plugin_wasm/src/runtime.rs b/crates/rspack_plugin_wasm/src/runtime.rs index 742ed6888473..da292d77136c 100644 --- a/crates/rspack_plugin_wasm/src/runtime.rs +++ b/crates/rspack_plugin_wasm/src/runtime.rs @@ -27,7 +27,7 @@ impl AsyncWasmLoadingRuntimeModule { id: Identifier::from("webpack/runtime/async_wasm_loading"), supports_streaming, chunk, - source_map_kind: SourceMapKind::None, + source_map_kind: SourceMapKind::empty(), custom_source: None, } } diff --git a/crates/rspack_util/Cargo.toml b/crates/rspack_util/Cargo.toml index 537b65c33a3c..949db49ab82a 100644 --- a/crates/rspack_util/Cargo.toml +++ b/crates/rspack_util/Cargo.toml @@ -8,6 +8,7 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bitflags = { workspace = true } concat-string = { workspace = true } dashmap = { workspace = true } indexmap = { workspace = true } diff --git a/crates/rspack_util/src/source_map.rs b/crates/rspack_util/src/source_map.rs index baf4796f6417..bffad9a7584f 100644 --- a/crates/rspack_util/src/source_map.rs +++ b/crates/rspack_util/src/source_map.rs @@ -1,9 +1,36 @@ -#[derive(Debug, PartialEq, Eq, Default, Clone)] -pub enum SourceMapKind { - #[default] - None, - SourceMap, - SimpleSourceMap, +use bitflags::bitflags; + +bitflags! { + #[derive(Debug, PartialEq, Eq, Clone, Copy)] + pub struct SourceMapKind: u8 { + const SourceMap = 1 << 0; + const SimpleSourceMap = 1 << 1; + const Cheap = 1 << 2; + } +} + +impl Default for SourceMapKind { + fn default() -> Self { + SourceMapKind::empty() + } +} + +impl SourceMapKind { + pub fn enabled(&self) -> bool { + !self.is_empty() + } + + pub fn source_map(&self) -> bool { + self.contains(SourceMapKind::SourceMap) + } + + pub fn simple_source_map(&self) -> bool { + self.contains(SourceMapKind::SimpleSourceMap) + } + + pub fn cheap(&self) -> bool { + self.contains(SourceMapKind::Cheap) + } } pub trait ModuleSourceMapConfig { From 142b29503ed7bb36e6a22b2c329fd3ed2f5fd037 Mon Sep 17 00:00:00 2001 From: leimonio <1969742+leimonio@users.noreply.github.com> Date: Wed, 8 May 2024 09:02:00 +0100 Subject: [PATCH 023/107] docs: update guide plugins (#6466) --- website/docs/en/guide/features/plugin.mdx | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/website/docs/en/guide/features/plugin.mdx b/website/docs/en/guide/features/plugin.mdx index 4efa68822c55..7a0b8a9aee92 100644 --- a/website/docs/en/guide/features/plugin.mdx +++ b/website/docs/en/guide/features/plugin.mdx @@ -1,12 +1,27 @@ # Plugins -If [loaders](/guide/features/loader) are the workhorse for file transformations (preprocessing), then plugins are the workhorse for the overall Rspack build process. Most of Rspack's native implementations rely on the Rust side of the plugin system. For Node users, you don't need to worry about interoperation issues with Rust, because Rspack takes care of those details for you automatically. You can just focus on how to use the plugins. +If [loaders](/guide/features/loader) are the workhorse for file transformations (preprocessing), then plugins are the workhorse for the overall Rspack build process. Most of Rspack's native implementations rely on the Rust side of the plugin system. For Node users, you don't need to worry about compatibility issues with Rust, because Rspack takes care of those details for you automatically. You can just focus on how to use the plugins. Find out [plugins](/plugins/index) you can use with Rspack. ## Example -### Authoring plugins +### Plugin usage -The structure of a plugin is very simple: just implement an `apply` method that accepts a `Compiler` instance. It will be called when the Rspack plugin is initialized. The detailed API can be found in the [Plugin API](/api/plugin-api/index). +Here's an example of how to use the already compatible [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) in `rspack.config.js`: + +```js title="rspack.config.js" +const BundleAnalyzerPlugin = + require('webpack-bundle-analyzer').BundleAnalyzerPlugin; + +module.exports = { + plugins: [new BundleAnalyzerPlugin()], +}; +``` + +If you're looking for more Rspack plugins have a look at a great list of [supported plugins](/plugins/index) + +### Plugin creation + +As a plugin author, the structure of a plugin is very simple: just implement an `apply` method that accepts a `Compiler` instance. It will be called when the Rspack plugin is initialized. The detailed API can be found in the [Plugin API](/api/plugin-api/index). ```js const PLUGIN_NAME = 'MyPlugin'; @@ -24,22 +39,7 @@ module.exports = MyPlugin; We use CommonJS style module exports so that plugins can be imported directly using `require` in `rspack.config.js`. -### Consuming plugins - -Here's an example of how to use the already compatible [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) in `rspack.config.js`: - -```js title="rspack.config.js" -const BundleAnalyzerPlugin = - require('webpack-bundle-analyzer').BundleAnalyzerPlugin; - -module.exports = { - plugins: [new BundleAnalyzerPlugin()], -}; -``` - -Please refer to [Plugin compat](/guide/compatibility/plugin) for the list of plugins that have passed Rspack compatibility tests. - -### Type definitions +### Plugin creation with Type Definitions If you use TypeScript to write Rspack plugins, you can import `Compiler` and `RspackPluginInstance` to declare the types of your plugins: From d4454a619b98f8ee4a35cc35dc602e98deb4635a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 8 May 2024 16:05:19 +0800 Subject: [PATCH 024/107] Release Packages:0.6.4 (#6414) Reelase Packages:0.6.4 Co-authored-by: github-actions[bot] --- crates/node_binding/package.json | 2 +- npm/darwin-arm64/package.json | 2 +- npm/darwin-x64/package.json | 2 +- npm/linux-x64-gnu/package.json | 2 +- npm/win32-x64-msvc/package.json | 2 +- package.json | 2 +- packages/create-rspack/package.json | 2 +- packages/rspack-cli/package.json | 2 +- packages/rspack-dev-server/package.json | 2 +- packages/rspack-plugin-minify/package.json | 2 +- packages/rspack-plugin-react-refresh/package.json | 2 +- packages/rspack-test-tools/package.json | 2 +- packages/rspack/package.json | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 31fdbb25670e..5538d3711792 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Node binding for rspack", "main": "binding.js", diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index ea2fd8acce75..cbd00c7a39df 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-darwin-arm64", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.darwin-arm64.node", diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index d35656593af6..a78c8cae850e 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-darwin-x64", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.darwin-x64.node", diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index f6db0c8df1ba..b9b62c0cc081 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-linux-x64-gnu", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.linux-x64-gnu.node", diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index 179c1d27a720..81f7e00a0f2b 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-win32-x64-msvc", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.win32-x64-msvc.node", diff --git a/package.json b/package.json index 622ea0e9ebe5..ed6418d0f846 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monorepo", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "A Fast Rust-based web bundler", "private": true, diff --git a/packages/create-rspack/package.json b/packages/create-rspack/package.json index 4b9bec4af550..22f72940876b 100644 --- a/packages/create-rspack/package.json +++ b/packages/create-rspack/package.json @@ -1,6 +1,6 @@ { "name": "create-rspack", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "main": "index.js", "bin": { diff --git a/packages/rspack-cli/package.json b/packages/rspack-cli/package.json index c541148c37a9..e1addf502c60 100644 --- a/packages/rspack-cli/package.json +++ b/packages/rspack-cli/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/cli", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "CLI for rspack", "bin": { diff --git a/packages/rspack-dev-server/package.json b/packages/rspack-dev-server/package.json index 2087de422afc..146428af1158 100644 --- a/packages/rspack-dev-server/package.json +++ b/packages/rspack-dev-server/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/dev-server", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Development server for rspack", "main": "./dist/index.js", diff --git a/packages/rspack-plugin-minify/package.json b/packages/rspack-plugin-minify/package.json index 2ff4c7965aa6..61f760cf7415 100644 --- a/packages/rspack-plugin-minify/package.json +++ b/packages/rspack-plugin-minify/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/plugin-minify", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Minify plugin for rspack", "main": "src/index.js", diff --git a/packages/rspack-plugin-react-refresh/package.json b/packages/rspack-plugin-react-refresh/package.json index cbdae4785d27..1afbaa4edfa2 100644 --- a/packages/rspack-plugin-react-refresh/package.json +++ b/packages/rspack-plugin-react-refresh/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/plugin-react-refresh", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "React refresh plugin for rspack", "main": "dist/index.js", diff --git a/packages/rspack-test-tools/package.json b/packages/rspack-test-tools/package.json index 17d6caa6a3b8..693effe36996 100644 --- a/packages/rspack-test-tools/package.json +++ b/packages/rspack-test-tools/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/test-tools", - "version": "0.6.3", + "version": "0.6.4", "license": "MIT", "description": "Test tools for rspack", "main": "dist/index.js", diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 4afe5403eb68..306dfc35eb22 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/core", - "version": "0.6.3", + "version": "0.6.4", "webpackVersion": "5.75.0", "license": "MIT", "description": "A Fast Rust-based Web Bundler", From 1da1ba20da5a6318da09bd352aa6f0482f5585e7 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 8 May 2024 16:19:18 +0800 Subject: [PATCH 025/107] docs(html-plugin): add comparison and examples (#6471) --- .../en/plugins/rspack/html-rspack-plugin.mdx | 387 +++++++++++------- .../zh/plugins/rspack/html-rspack-plugin.mdx | 383 ++++++++++------- 2 files changed, 494 insertions(+), 276 deletions(-) diff --git a/website/docs/en/plugins/rspack/html-rspack-plugin.mdx b/website/docs/en/plugins/rspack/html-rspack-plugin.mdx index 22acbea6c3ba..fa36c5135ac1 100644 --- a/website/docs/en/plugins/rspack/html-rspack-plugin.mdx +++ b/website/docs/en/plugins/rspack/html-rspack-plugin.mdx @@ -5,147 +5,256 @@ import { ApiMeta } from '@components/ApiMeta.tsx'; -This plugin can be used to create HTML files that are associated with Rspack assets. +`rspack.HtmlRspackPlugin` is a high-performance HTML plugin implemented in Rust. You can use it to generate HTML files for Rspack projects. ```js new rspack.HtmlRspackPlugin(options); ``` -- options - - - **Type:** - - ```ts - type HtmlRspackPluginOptions = { - title?: string; - filename?: string; - template?: string; - templateContent?: string; - templateParameters?: Record; - inject?: 'head' | 'body'; - publicPath?: string; - scriptLoading?: 'blocking' | 'defer' | 'module'; - chunks?: string[]; - excludedChunks?: string[]; - sri?: 'sha256' | 'sha384' | 'sha512'; - minify?: boolean; - favicon?: string; - meta?: Record>; - }; - ``` - - - **Default:** `{}` - - `', - default: '{}', - description: 'Allows to overwrite the parameters used in the template.', - }, - { - name: '`inject`', - type: "`'head'|'body'|undefined`", - default: 'undefined', - description: 'The script and link tag inject position in `template`.', - }, - { - name: '`publicPath`', - type: '`string`', - default: "''", - description: 'The publicPath used for script and link tags.', - }, - { - name: '`scriptLoading`', - type: "`'blocking'|'defer'|'module'`", - default: "'defer'", - description: - "Modern browsers support non blocking javascript loading ('defer') to improve the page startup performance. Setting to 'module' adds attribute type='module'. This also implies 'defer', since modules are automatically deferred.", - }, - { - name: '`chunks`', - type: '`string[]|undefined`', - default: 'undefined', - description: 'Allows you to add only some chunks.', - }, - { - name: '`excludedChunks`', - type: '`string[]|undefined`', - default: 'undefined', - description: 'Allows you to skip some chunks.', - }, - { - name: '`sri`', - type: "`'sha256'|'sha384'|'sha512'|undefined`", - default: 'undefined', - description: 'The sri hash algorithm, disabled by default.', - }, - { - name: '`minify`', - type: '`boolean`', - default: 'false', - description: 'Controls whether to minify the output.', - }, - { - name: '`favicon`', - type: '`string|undefined`', - default: 'undefined', - description: 'Adds the given favicon path to the output HTML.', - }, - { - name: '`meta`', - type: '`Record>` ', - default: '{}', - description: 'Allows to inject meta-tags.', - }, - ]} - /> - -:::tip -If the configuration options provided by `rspack.HtmlRspackPlugin` cannot meet your needs, you can also directly use the community's [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin) plugin. -::: +## Comparison + +Before using `rspack.HtmlRspackPlugin`, please note that there are some differences between `rspack.HtmlRspackPlugin` and the community [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin). + +### Performance + +Because `rspack.HtmlRspackPlugin` is implemented in Rust, its build performance is significantly better than html-webpack-plugin, especially in scenarios where many HTML files are being built. + +### Features + +The features of `rspack.HtmlRspackPlugin` are a subset of `html-webpack-plugin`. To ensure the performance of the plugin, we have not implemented all the features provided by html-webpack-plugin. + +If its options do not meet your needs, you can also directly use the community [html-webpack-plugin](https://www.npmjs.com/package/html-webpack-plugin). + +## Usage + +The plugin will generate an HTML file for you that includes all your JS outputs in the head using ` + + + +``` + +If you have multiple entry points in your Rspack config, they will all be included with ` + + + +``` + +如果你的 Rspack 配置中有多个 entry points,它们的生成 ` @@ -573,7 +573,7 @@ Now the variable `MyLibrary` will be bound with the exports of your entry file, ``` -In the above example, we're passing a single entry file to `entry`, however, rspack can accept [many kinds of entry point](/config/entry), e.g., an `array`, or an `object`. +In the above example, we're passing a single entry file to `entry`, however, Rspack can accept [many kinds of entry point](/config/entry), e.g., an `array`, or an `object`. 1. If you provide an `array` as the `entry` point, only the last one in the array will be exposed. diff --git a/website/docs/en/guide/features/builtin-swc-loader.mdx b/website/docs/en/guide/features/builtin-swc-loader.mdx index 2b3fcd34d5d2..6cfee4025c83 100644 --- a/website/docs/en/guide/features/builtin-swc-loader.mdx +++ b/website/docs/en/guide/features/builtin-swc-loader.mdx @@ -129,11 +129,11 @@ The following is an introduction to some SWC configurations and Rspack specific :::warning -The `wasm` plugin is deeply coupled with the version of `SWC`, you need to choose a wasm plugin that is compatible with the corresponding version of `SWC` in order to function normally. -you can see more compatible info about how to choose right wasm plugin version in [selecting-swc-core](https://swc.rs/docs/plugin/selecting-swc-core#088x--089x). +The Wasm plugin is deeply coupled with the version of SWC, you need to choose a Wasm plugin that is compatible with the corresponding version of SWC in order to function normally. +you can see more compatible info about how to choose right Wasm plugin version in [selecting-swc-core](https://swc.rs/docs/plugin/selecting-swc-core#088x--089x). ::: -Rspack supports load `wasm` plugin in `builtin:swc-loader`, you can specify the plugin name like +Rspack supports load Wasm plugin in `builtin:swc-loader`, you can specify the plugin name like ```js module.exports = { @@ -164,7 +164,7 @@ module.exports = { }; ``` -this is an [example](https://github.com/rspack-contrib/rspack-examples/blob/d4b8aaef9915ed0f540edbe504217c3d1afe8989/rspack/builtin-swc-loader/rspack.config.js#L45) of wasm plugin usage. +this is an [example](https://github.com/rspack-contrib/rspack-examples/blob/d4b8aaef9915ed0f540edbe504217c3d1afe8989/rspack/builtin-swc-loader/rspack.config.js#L45) of Wasm plugin usage. ### rspackExperiments @@ -399,7 +399,7 @@ Each field name is the same with [@emotion/babel-plugin](https://emotion.sh/docs This option is used for: -- Automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. +- Automatically adds the label property to styles so that class names generated by CSS or styled include the name of the variable the result is assigned to. - Please note that non word characters in the variable will be removed (Eg. `iconStyles$1` will become `iconStyles1`) because `$` is not valid[CSS ClassName Selector](https://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors#449000). Each possible value for this option produces different output code: @@ -417,11 +417,11 @@ This option only works when `'autoLabel'` is set to `'dev-only'` or `'always'`. Allowed values: -- `'[local]'` - the name of the variable the result of the css or styled expression is assigned to. -- `'[filename]'` - name of the file (without extension) where css or styled expression is located. -- `'[dirname]'` - name of the directory containing the file where css or styled expression is located. +- `'[local]'` - the name of the variable the result of the CSS or styled expression is assigned to. +- `'[filename]'` - name of the file (without extension) where CSS or styled expression is located. +- `'[dirname]'` - name of the directory containing the file where CSS or styled expression is located. -This format only affects the label property of the expression, meaning that the css prefix and hash will be prepended automatically. +This format only affects the label property of the expression, meaning that the CSS prefix and hash will be prepended automatically. #### sourceMap diff --git a/website/docs/en/guide/features/dev-server.mdx b/website/docs/en/guide/features/dev-server.mdx index 47fe48175440..835d66f7ecdc 100644 --- a/website/docs/en/guide/features/dev-server.mdx +++ b/website/docs/en/guide/features/dev-server.mdx @@ -15,7 +15,7 @@ module.exports = { ``` :::warning -HMR is not working for css when `output.cssFilename` contains `[hash]` or `[contenthash]` +HMR is not working for CSS when `output.cssFilename` contains `[hash]` or `[contenthash]` ::: ### Proxy diff --git a/website/docs/en/guide/migration/webpack.mdx b/website/docs/en/guide/migration/webpack.mdx index 8b94091f0f0b..21e0e6b4d706 100644 --- a/website/docs/en/guide/migration/webpack.mdx +++ b/website/docs/en/guide/migration/webpack.mdx @@ -134,7 +134,7 @@ Rspack's [css-modules](https://github.com/css-modules/css-modules) functionality ### CssExtractPlugin -If you need some specific configurations from css-loader, you can still use style-loader + css-loader, if you want to extract css files for production, you can use Rspack builtin plugin: CssExtractRspackPlugin. +If you need some specific configurations from css-loader, you can still use style-loader + css-loader, if you want to extract CSS files for production, you can use Rspack builtin plugin: CssExtractRspackPlugin. CssExtractRspackPlugin is similar to mini-css-extract-plugin, be sure that you've already enabled `experiments.rspackFuture.newTreeshaking`, it's enabled by default after v0.6. diff --git a/website/docs/en/guide/optimization/tree-shaking.mdx b/website/docs/en/guide/optimization/tree-shaking.mdx index 81452f9f936f..9a9805a3e35d 100644 --- a/website/docs/en/guide/optimization/tree-shaking.mdx +++ b/website/docs/en/guide/optimization/tree-shaking.mdx @@ -107,7 +107,7 @@ var __webpack_modules__ = { // ... ``` -As you can see, if we don't enable the treeShaking, all the code is kept as is, except wrapping with +As you can see, if we don't enable the tree shaking, all the code is kept as is, except wrapping with some runtime code. Now, we switch to production mode and rebuild the project. In order to make the output more readable, we also turn off the `minimize` option and switch the `moduleIds` to `named`. To compare with the later chapters, we turn off `optimization.sideEffects`. @@ -131,7 +131,7 @@ const config = { module.exports = config; ``` -Rebuilding the project, the `square` function got dropped. +Rebuild the project, the `square` function got dropped. ## SideEffects diff --git a/website/docs/en/guide/tech/css.mdx b/website/docs/en/guide/tech/css.mdx index a1adc5fe5ef0..dd954da340d2 100644 --- a/website/docs/en/guide/tech/css.mdx +++ b/website/docs/en/guide/tech/css.mdx @@ -4,7 +4,7 @@ import { PackageManagerTabs } from '@theme'; CSS is a first-class citizen with Rspack. Rspack has the ability to handle CSS out-of-box, so additional configuration isn't required. -By default, files ending in `*.css` are treated as CSS module types. Files ending in `*.module.css` are treated as [CSS Modules](https://github.com/css-modules/css-modules) module types. +By default, files ending in `*.css` are treated as CSS types. Files ending in `*.module.css` are treated as [CSS Modules](https://github.com/css-modules/css-modules) module types. If you're migrating from Webpack, you can remove the `css-loader` or `style-loader` components from your configuration to use Rspack's built-in CSS processing capabilities, as described in [migration guide](/guide/migration/webpack#removing-css-loader-and-style-loader-and-mini-css-extract-plugin). diff --git a/website/docs/en/guide/tech/vue.mdx b/website/docs/en/guide/tech/vue.mdx index a509817985a8..e5140043a42c 100644 --- a/website/docs/en/guide/tech/vue.mdx +++ b/website/docs/en/guide/tech/vue.mdx @@ -106,7 +106,7 @@ module.exports = { type: 'javascript/auto', }, { - test: /\.ts$/, // add this rule when you use typescript in Vue SFC + test: /\.ts$/, // add this rule when you use TypeScript in Vue SFC loader: 'builtin:swc-loader', options: { jsc: { diff --git a/website/docs/en/misc/benchmark.mdx b/website/docs/en/misc/benchmark.mdx index f797bb0f2c1d..9877d312d279 100644 --- a/website/docs/en/misc/benchmark.mdx +++ b/website/docs/en/misc/benchmark.mdx @@ -37,7 +37,7 @@ The old Rome code base (prior to their Rust rewrite) to approximate a large Type #### Data Tested on Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz 32Core, 64GB of RAM -| mode | rspack | webpack(with swc) | webpack (with babel) | +| mode | Rspack | webpack(with swc) | webpack (with babel) | |------------------------|---------|-------------------|----------------------| | development cold start | 3.79s | 31.25s | 42.61s | | production cold start | 22.353s | 75.054s | 160.059s | @@ -73,7 +73,7 @@ Tested on Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz 32Core, 64GB of RAM - webpack + swc-loader + swc-minifier -- rspack(using swc as transpiler and swc minifier) +- Rspack (using SWC as transpiler and minifier) All the configuration in development mode keep as is except the loader which depends on the test target. diff --git a/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx b/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx index 3ac3795a8ea8..10b6b1557957 100644 --- a/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx +++ b/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx @@ -5,9 +5,9 @@ import { ApiMeta } from '@components/ApiMeta.tsx'; -Rspack currently does not support mini-css-extract-plugin, but it can be replaced with this plugin and used in conjunction with css-loader to extract css into separate files. +Rspack currently does not support mini-css-extract-plugin, but it can be replaced with this plugin and used in conjunction with css-loader to extract CSS into separate files. -If your project does not depend on css-loader, it is recommended to use the built-in css solution experiments.css of Rspack for better performance. +If your project does not depend on css-loader, it is recommended to use the built-in CSS solution experiments.css of Rspack for better performance. - options @@ -89,7 +89,7 @@ If your project does not depend on css-loader, it is recommended to use the buil type: '`string | ((linkTag: HTMLLinkElement) => void)`', default: 'undefined', description: - 'Decide how the link tag is inserted into the page. If passed as a string type,it will be regarded as dom selector,and the link tag will be inserted after element corresponding to that selector。If passed as function type,the function will be converted into a String at runtime for invocation,with link tag as parameter', + 'Decide how the link tag is inserted into the page. If passed as a string type, it will be regarded as DOM selector, and the link tag will be inserted after element corresponding to that selector. If passed as function type, the function will be converted into a String at runtime for invocation, with link tag as parameter', }, { name: '`attributes`', diff --git a/website/docs/zh/api/node-api.mdx b/website/docs/zh/api/node-api.mdx index 82cc19162631..6e8794260a75 100644 --- a/website/docs/zh/api/node-api.mdx +++ b/website/docs/zh/api/node-api.mdx @@ -47,7 +47,7 @@ rspack({}, (err, stats) => { ::: :::tip 提示 -你也可以为 rspack 函数提供一个配置数组。更多详细信息,请查看 [MultiCompiler](/api/node-api#multicompiler) 章节。 +你也可以为 rspack() 函数提供一个配置数组。更多详细信息,请查看 [MultiCompiler](/api/node-api#multicompiler) 章节。 ::: ## Compiler 实例 diff --git a/website/docs/zh/blog/announcing-0-2.mdx b/website/docs/zh/blog/announcing-0-2.mdx index 80016a77f2b7..db780ebc0d8b 100644 --- a/website/docs/zh/blog/announcing-0-2.mdx +++ b/website/docs/zh/blog/announcing-0-2.mdx @@ -159,7 +159,7 @@ module.exports = { ### node-loader -当使用 Rspack 打包如 NestJS 等 Node 应用时,一个常见的需求就是打包一些包含 addon 的库,这些库里的 native 依赖无法直接被打包进 js 里,因此需要特殊处理,Rspack 适配了 [node-loader](https://github.com/webpack-contrib/node-loader) 所以你可以使用 Rspack 去构建 node 应用了。 +当使用 Rspack 打包如 NestJS 等 Node 应用时,一个常见的需求就是打包一些包含 addon 的库,这些库里的 native 依赖无法直接被打包进 JS 里,因此需要特殊处理,Rspack 适配了 [node-loader](https://github.com/webpack-contrib/node-loader) 所以你可以使用 Rspack 去构建 node 应用了。 Rspack 适配的 webpack 的 plugin 和 loader 远不仅此,我们在 [loader-compat](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/loader-compat) 和 [plugin-compat](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/plugin) 对已经适配的 plugin 和 loader 进行了追踪,如果你发现你使用的社区 plugin 和 loader 也已经兼容,欢迎提交给我们。 ## 框架生态更新 @@ -236,7 +236,7 @@ Rspack 团队非常重视开源社区做出的宝贵贡献。我们致力于保 - [@TheLarkInn](https://github.com/TheLarkInn) 和 [@alexander-akait](https://github.com/alexander-akait) ,回答和解决了很多 Rspack 团队关于 Webpack 的疑问。 - [@zackarychapple](https://github.com/zackarychapple)、[@valorkin](https://github.com/valorkin)、[@edusperoni](https://github.com/edusperoni) 以及 [@Coly101](https://github.com/Coly010) ,帮助 Rspack 对 Angular 做了基本支持,特别是 [@zackarychapple](https://github.com/zackarychapple) 帮助我们 review 这篇发布公告的英文版本。 - [@suxin2017](https://github.com/suxin2017),在 Rspack 里支持了 System.js format,optional-dependency 等功能,并在 Windows 兼容方面做了很多贡献。 -- [@faga295](https://github.com/faga295),在 Rspack 里支持了解压代码注释功能和 rspack preview 功能。 +- [@faga295](https://github.com/faga295),在 Rspack 里支持了解压代码注释功能和 `rspack preview` 功能。 - [@lippzhang](https://github.com/lippzhang),在对齐 Webpack 行为方面做了很多贡献。 - [@HerringtonDarkholme](https://github.com/HerringtonDarkholme),允许 Rspack 使用 rspack.config.ts 作为配置文件 - [@dhruvkelawala](https://github.com/dhruvkelawala), 在 Rspack 里实现了 builtins.provide 功能 diff --git a/website/docs/zh/blog/announcing-0-3.mdx b/website/docs/zh/blog/announcing-0-3.mdx index 48e38a6f5e03..6c46b7f08d56 100644 --- a/website/docs/zh/blog/announcing-0-3.mdx +++ b/website/docs/zh/blog/announcing-0-3.mdx @@ -8,7 +8,7 @@ date: 2023-08-24 12:15:00 ## 破坏性更新 -Rspack 在 0.3 版本将 `experiments.css = true` 的情况下的 css 默认处理行为和 webpack 进行了对齐,移除了很多内置的 css 转换逻辑,这同时带来了一些 breaking change,如果你的应用之前依赖了这些转换逻辑,请注意按照下述迁移方式进行迁移。 +Rspack 在 0.3 版本将 `experiments.css = true` 的情况下的 CSS 默认处理行为和 webpack 进行了对齐,移除了很多内置的 CSS 转换逻辑,这同时带来了一些 breaking change,如果你的应用之前依赖了这些转换逻辑,请注意按照下述迁移方式进行迁移。 ### 移除 `@rspack/postcss-loader` 和 `builtins.postcss` @@ -59,7 +59,7 @@ module.exports = { }; ``` -### 移除了内置的 css autoprefixer 功能 +### 移除了内置的 CSS autoprefixer 功能 为了更好的对齐 webpack 的 CSS 处理, Rspack 从 0.3 移除了内置的 autoprefixer 功能,你可以使用 postcss-loader 来实现 autoprefixer。 @@ -121,7 +121,7 @@ new Worker(new URL('./worker.js', import.meta.url), { ### `builtin:swc-loader` 支持 -Rspack 虽然提供了很多 SWC 的编译配置选项,但是这些配置都是全局性的编译配置,业务侧如果需要不同的模块走不同的 SWC 转换逻辑则难以满足,因此 Rspack 支持 `builtin:swc-loader` 以提供更精细的 SWC 转换配置,`builtin:swc-loader` 相比于 js 版本的 [swc-loader](https://github.com/swc-project/swc-loader) 性能更优。你可以通过如下方式使用 `builtin:swc-loader` +Rspack 虽然提供了很多 SWC 的编译配置选项,但是这些配置都是全局性的编译配置,业务侧如果需要不同的模块走不同的 SWC 转换逻辑则难以满足,因此 Rspack 支持 `builtin:swc-loader` 以提供更精细的 SWC 转换配置,`builtin:swc-loader` 相比于 JS 版本的 [swc-loader](https://github.com/swc-project/swc-loader) 性能更优。你可以通过如下方式使用 `builtin:swc-loader` ```js const path = require('path'); @@ -160,7 +160,7 @@ module.exports = config; ``` 更多的示例可参考 [examples/builtin-swc-loader](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/builtin-swc-loader) -目前的 `builtin:swc-loader` 仍然有诸多限制,如不支持 wasm plugin 等,Rspack 在后续版本将继续迭代支持 `builtin:swc-loader` 的更多功能。 +目前的 `builtin:swc-loader` 仍然有诸多限制,如不支持 Wasm plugin 等,Rspack 在后续版本将继续迭代支持 `builtin:swc-loader` 的更多功能。 ### 更好的 profile 支持 diff --git a/website/docs/zh/blog/announcing-0-4.mdx b/website/docs/zh/blog/announcing-0-4.mdx index 8a4598e71414..c6eda000c874 100644 --- a/website/docs/zh/blog/announcing-0-4.mdx +++ b/website/docs/zh/blog/announcing-0-4.mdx @@ -220,7 +220,7 @@ module.exports = { ### 迁移 builtin options 到 builtin plugins -Rspack 在 v0.4.0 中废弃了部分 builtin options 并迁移至 rspack [内部插件](/config/plugins)。 +Rspack 在 v0.4.0 中废弃了部分 builtin options 并迁移至 Rspack [内部插件](/config/plugins)。 目前,rspack 的内部插件分为两类: @@ -284,4 +284,4 @@ module.exports = { }; ``` -其他内容可以直接参考 rspack [内部插件](/config/plugins)进行迁移,也可以在升级到 v0.4.0 后根据 CLI 提示完成操作。 +其他内容可以直接参考 Rspack [内部插件](/config/plugins)进行迁移,也可以在升级到 v0.4.0 后根据 CLI 提示完成操作。 diff --git a/website/docs/zh/blog/announcing-0-5.mdx b/website/docs/zh/blog/announcing-0-5.mdx index f4f80e27a8ad..1130810b31d2 100644 --- a/website/docs/zh/blog/announcing-0-5.mdx +++ b/website/docs/zh/blog/announcing-0-5.mdx @@ -149,7 +149,7 @@ module.exports = { ### 将 @swc/helpers 和 react-refresh 调整为 peerDependencies -在我们移除默认转换之前,可以通过 `target` 将您的代码降级为 es5,并通过 `builtin.react.refresh` 将 react 刷新助手代码插入到您的 react 组件中,因此我们安装了 `@swc/helpers` 和 `react-refresh` 作为 `@rspack/core` 的依赖项,以提供开箱即用的体验。但是现在我们已经移除了默认转换,并建议使用 rsbuild 来获得开箱即用的体验,因此 `@swc/helpers` 和 `react-refresh` 不再需要由 `@rspack/core` 安装,我们将它们调整为 `@rspack/core` 的 peerDependencies。 +在我们移除默认转换之前,可以通过 `target` 将您的代码降级为 es5,并通过 `builtin.react.refresh` 将 react 刷新助手代码插入到您的 react 组件中,因此我们安装了 `@swc/helpers` 和 `react-refresh` 作为 `@rspack/core` 的依赖项,以提供开箱即用的体验。但是现在我们已经移除了默认转换,并建议使用 Rsbuild 来获得开箱即用的体验,因此 `@swc/helpers` 和 `react-refresh` 不再需要由 `@rspack/core` 安装,我们将它们调整为 `@rspack/core` 的 peerDependencies。 如果您正在使用 `builtin:swc-loader` 或 `swc-loader` 的 `externalHelpers: true` 功能,现在您需要将 `@swc/helpers` 安装为项目的 dependencies。如果您正在使用 `@rspack/plugin-react-refresh`,现在您需要将 `react-refresh` 安装为项目的 devDependencies。 diff --git a/website/docs/zh/blog/announcing-0-6.mdx b/website/docs/zh/blog/announcing-0-6.mdx index 6a6854627e49..eee46f7057f5 100644 --- a/website/docs/zh/blog/announcing-0-6.mdx +++ b/website/docs/zh/blog/announcing-0-6.mdx @@ -14,7 +14,7 @@ import { PackageManagerTabs } from '@theme'; 你现在可以使用 `rspack.CssExtractRspackPlugin` 作为 `mini-css-extract-plugin` 的替代。 -这在一些场景很实用,例如当内置的 CSS 处理不能满足你的需求,有更定制化的 CSS module name 等,或者你想要使用一些依赖 css-loader 的 loader,但仍然想要将 CSS 提取成单独文件。 +这在一些场景很实用,例如当内置的 CSS 处理不能满足你的需求,有更定制化的 CSS Modules name 等,或者你想要使用一些依赖 css-loader 的 loader,但仍然想要将 CSS 提取成单独文件。 详细配置见 [CssExtractRspackPlugin](/plugins/rspack/css-extract-rspack-plugin#cssextractrspackplugin)。 @@ -60,7 +60,7 @@ Rspack 在 0.1.0 支持了基本的 tree shaking 功能,由于最初的架构 移除 `builtins.css`,请使用引入的 CSS 相关的 [`module.parser`](/config/module#moduleparsercssauto) 和 [`module.generator`](/config/module#modulegeneratorcssauto) 选项进行替代。 -同时,从 v0.6.0 版本开始,Rspack 的 experiments css 将会以 webpack 的 experiments css 为目标进行对齐,这意味着和 webpack experiments css 一样在未来将不再支持[不支持 CSS 变量的浏览器](https://caniuse.com/css-variables)。因此,对于那些需要使用尚未得到 experiments css 支持的配置,或者需要兼容老版本浏览器的项目,我们推荐迁移至 [`rspack.CssExtractRspackPlugin`](/plugins/rspack/css-extract-rspack-plugin.html)。 +同时,从 v0.6.0 版本开始,Rspack 的 `experiments.css` 将会以 webpack 的 `experiments.css` 为目标进行对齐,这意味着和 webpack `experiments.css` 一样在未来将不再支持[不支持 CSS 变量的浏览器](https://caniuse.com/css-variables)。因此,对于那些需要使用尚未得到 `experiments.css` 支持的配置,或者需要兼容老版本浏览器的项目,我们推荐迁移至 [`rspack.CssExtractRspackPlugin`](/plugins/rspack/css-extract-rspack-plugin.html)。 在 v0.6.0 中,我们引入了三种新的模块类型的 `module.generator` 和 `module.parser` 选项:`css/auto`、`css` 和 `css/module`,这些选项只有在启用 experiments.css 时才会生效,关于如何使用可查看[这个例子](https://github.com/rspack-contrib/rspack-examples/tree/main/rspack/css-parser-generator-options)。 @@ -70,7 +70,7 @@ Rspack 在 0.1.0 支持了基本的 tree shaking 功能,由于最初的架构 除此之外,还包括一些关于默认值的修改: -1. `exportsConvention` 的值从 `'asIs'`, `'camelCaseOnly'` 等变更为 `'as-is'`, `'camel-case-only'` 等,以保持与 webpack experiments css 的一致。 +1. `exportsConvention` 的值从 `'asIs'`, `'camelCaseOnly'` 等变更为 `'as-is'`, `'camel-case-only'` 等,以保持与 webpack `experiments.css` 的一致。 2. `namedExports: false` 支持同时使用默认导出(default export)、命名导出(named export)和命名空间导出(namespace export),在此之前它只支持使用默认导出: ```js @@ -97,7 +97,7 @@ Rspack 在 0.1.0 支持了基本的 tree shaking 功能,由于最初的架构 ### 当 CSS 的顺序在多个 chunk 中不一致时发出警告 -当多个 chunk 中 css 顺序不一致时会发出警告,假如你有两个 entry,entryA 和 entryB,entryA 中引入 a.css 然后引入 b.css,而 entryB 中引入 b.css 然后引入 a.css。 +当多个 chunk 中 CSS 顺序不一致时会发出警告,假如你有两个 entry,entryA 和 entryB,entryA 中引入 a.css 然后引入 b.css,而 entryB 中引入 b.css 然后引入 a.css。 当满足 splitChunks 条件时,a.css 和 b.css 会成为单独 chunk,这个 chunk 中 a.css 和 b.css 的顺序无法保证,会产生如下的警告 ```txt @@ -194,6 +194,6 @@ module.exports = { ### 升级 SWC 插件 -在 `0.6.0` 中,Rust crate `swc_core` 的版本升级到 `0.90.x`,使用到的 swc wasm 插件需要确保其使用的 `swc_core` 的版本一致性,否则可能产生无法预知的问题。 +在 `0.6.0` 中,Rust crate `swc_core` 的版本升级到 `0.90.x`,使用到的 SWC Wasm 插件需要确保其使用的 `swc_core` 的版本一致性,否则可能产生无法预知的问题。 详情请参考[文档](https://swc.rs/docs/plugin/selecting-swc-core#090x)。 diff --git a/website/docs/zh/config/builtins.mdx b/website/docs/zh/config/builtins.mdx index 92d5aca4c43d..10d6c5657119 100644 --- a/website/docs/zh/config/builtins.mdx +++ b/website/docs/zh/config/builtins.mdx @@ -298,7 +298,7 @@ type PresetEnv = type: '`string[]|undefined`', default: 'undefined', description: - '通过该配置可以使用 [browserslist query](https://github.com/browserslist/browserslist#queries) 来控制用户代码中 js 和 css 语法的降级,当此值为 undefined 时,rspack 将尝试使用[基础目录](config/context) 下的 [browserslist](https://github.com/browserslist/browserslist) 配置来进行转换。', + '通过该配置可以使用 [browserslist query](https://github.com/browserslist/browserslist#queries) 来控制用户代码中 JS 和 CSS 语法的降级,当此值为 undefined 时,rspack 将尝试使用[基础目录](config/context) 下的 [browserslist](https://github.com/browserslist/browserslist) 配置来进行转换。', }, { name: '`mode`', @@ -819,7 +819,7 @@ type BuiltinsDecorator = -此选项可以用来配置默认 css 打包策略。 +此选项可以用来配置默认 CSS 打包策略。 - **类型:** @@ -888,15 +888,11 @@ type BuiltinsCssModules = { name: '`exportsOnly`', type: '`boolean`', default: 'false', - description: '只输出 js 对象,不输出 css 文件。常在 SSR 场景下使用', + description: '只输出 JS 对象,不输出 CSS 文件。常在 SSR 场景下使用', }, ]} /> -{/* ## builtins.postcss */} - -{/* ## builtins.treeShaking */} - ## builtins.progress boolean)` - **默认值:** `undefined` -匹配的文件代码不会被 rspack 转换,包括 `module.exports`, `require`, `import` 这些模块系统相关的语法。 +匹配的文件代码不会被 Rspack 转换,包括 `module.exports`, `require`, `import` 这些模块系统相关的语法。 用来忽略那些没有外部依赖的第三方库的时候很有用,有时还能提升性能。 @@ -66,7 +66,7 @@ module.exports = { dynamicImportPreload: false, url: true, }, - // css 模块的解析器选项 + // CSS 模块的解析器选项 css: { namedExports: true, }, @@ -298,7 +298,7 @@ module.exports = { exportsOnly: false, localIdentName: '[uniqueName]-[id]-[local]', }, - // css 模块的生成器选项 + // `css` 模块的生成器选项 css: { exportsConvention: 'as-is', exportsOnly: false, @@ -509,7 +509,7 @@ module.exports = { - **类型:** `string` - **默认值:** `[uniqueName]-[id]-[local]` -自定义生成的 CSS modules 的局部类名格式,除了在[文件级别](/config/output#file-context)和[模块级别](/config/output#module-context)的替换之外,还包括 `[uniqueName]` 和 `[local]`。 +自定义生成的 CSS Modules 的局部类名格式,除了在[文件级别](/config/output#file-context)和[模块级别](/config/output#module-context)的替换之外,还包括 `[uniqueName]` 和 `[local]`。 ### module.generator.css @@ -785,9 +785,9 @@ module.exports = { - `'javascript/auto'`:JavaScript 模块,支持的模块系统:CommonJS、ESM,暂没有对 AMD 模块支持的计划。 - `'javascript/esm'`:JavaScript 模块,当作严格 ES Module 处理。 - `'javascript/dynamic'`:JavaScript 模块,当作 Script 处理。 -- `'jsx'`: 支持 jsx 的 JavaScript 模块(🚧 已废弃,详见 [experiments.rspackFuture.disableTransformByDefault](/config/experiments#experimentsrspackfuturedisabletransformbydefault))。 +- `'jsx'`: 支持 JSX 的 JavaScript 模块(🚧 已废弃,详见 [experiments.rspackFuture.disableTransformByDefault](/config/experiments#experimentsrspackfuturedisabletransformbydefault))。 - `'typescript'`:TypeScript 模块(🚧 已废弃)。 -- `'tsx'`: 支持 tsx 的 TypeScript 模块(🚧 已废弃)。 +- `'tsx'`: 支持 TSX 的 TypeScript 模块(🚧 已废弃)。 - `'css'`:CSS 模块。 - `'css/module'`:CSS Modules 模块。 - `'css/auto'`:基于文件名判断,若匹配`/\.module(s)?\.[^.]+$/`则为 CSS Modules 模块,否则为 CSS 模块。 diff --git a/website/docs/zh/config/optimization.mdx b/website/docs/zh/config/optimization.mdx index 647adfd36d7f..831433104271 100644 --- a/website/docs/zh/config/optimization.mdx +++ b/website/docs/zh/config/optimization.mdx @@ -205,7 +205,7 @@ Rspack 支持通过 `optimization.splitChunks` 配置项来对 Chunk 进行拆 ]} /> -告诉 rspack 对每个模块确定使用的导出。这取决于 `optimization.providedExports`。 +告诉 Rspack 对每个模块确定使用的导出。这取决于 `optimization.providedExports`。 `optimization.usedExports` 收集的信息被其他优化或代码生成使用,即不会为未使用的导出生成导出信息,当所有用法兼容时,导出名称会被缩短为单个字符标识符。压缩器中的死代码消除将受益于此,并且可以删除未使用的导出。 ```js title=rspack.config.js @@ -237,7 +237,7 @@ module.exports = { { defaultValue: 'false', mode: 'development' }, ]} /> -`optimization.innerGraph` 告诉 rspack 是否进行未使用导出的内部图分析。 +`optimization.innerGraph` 告诉 Rspack 是否进行未使用导出的内部图分析。 ```js title=rspack.config.js module.exports = { diff --git a/website/docs/zh/config/other-options.mdx b/website/docs/zh/config/other-options.mdx index 3c7bb2b8b608..06ca6618f976 100644 --- a/website/docs/zh/config/other-options.mdx +++ b/website/docs/zh/config/other-options.mdx @@ -2,7 +2,7 @@ import { ApiMeta } from '../../../components/ApiMeta'; # 其他配置 -这里展示了 rspack 支持的其余配置项。 +这里展示了 Rspack 支持的其余配置项。 ## bail @@ -19,7 +19,7 @@ module.exports = { }; ``` -这会强制 rspack 终止编译流程。 +这会强制 Rspack 终止编译流程。 ## ignoreWarnings diff --git a/website/docs/zh/config/output.mdx b/website/docs/zh/config/output.mdx index 0a0b581f0ddf..72ba111e3560 100644 --- a/website/docs/zh/config/output.mdx +++ b/website/docs/zh/config/output.mdx @@ -562,7 +562,7 @@ export function hello(name) { } ``` -此时,变量 `MyLibrary` 将与你的入口文件所导出的文件进行绑定,下面是如何使用 rspack 构建的库的实现: +此时,变量 `MyLibrary` 将与你的入口文件所导出的文件进行绑定,下面是如何使用 Rspack 构建的库的实现: ```html @@ -571,7 +571,7 @@ export function hello(name) { ``` -在上面的例子中,我们为 `entry` 设置了一个入口文件,然而 rspack 可以接受 [多个入口](/config/entry),例如一个 `array` 或者一个 `object`。 +在上面的例子中,我们为 `entry` 设置了一个入口文件,然而 Rspack 可以接受 [多个入口](/config/entry),例如一个 `array` 或者一个 `object`。 1. 如果你将 `entry` 设置为一个 `array`,那么只有数组中的最后一个会被暴露。 @@ -850,7 +850,7 @@ require('MyLibrary').doSomething(); 如果我们指定 `output.library.name` 为 `type: commmonjs2`,你的入口起点的返回值将会被赋值给 `module.exports.[output.library.name]`。 -在考虑 CommonJS 与 CommonJS2 之间的区别?虽然它们很相似,但是它们之间有一些细微的差别,这些差别在 rspack 的上下文中通常是不相关的。(要获取更多详细内容,请 [阅读这个 issue](https://github.com/webpack/webpack/issues/1114)。) +在考虑 CommonJS 与 CommonJS2 之间的区别?虽然它们很相似,但是它们之间有一些细微的差别,这些差别在 Rspack 的上下文中通常是不相关的。(要获取更多详细内容,请 [阅读这个 issue](https://github.com/webpack/webpack/issues/1114)。) ##### type: 'commonjs-static' @@ -1241,7 +1241,7 @@ module.exports = { - **类型:** `string` - **默认值:** 默认使用 [`output.library`](/config/output#outputlibrary) 名称或者上下文中的 package.json 的 包名称(package name), 如果两者都不存在,值为 ''。 -此选项决定了在全局环境下为防止多个 rspack 运行时 冲突所使用的唯一名称。 +此选项决定了在全局环境下为防止多个 Rspack 运行时 冲突所使用的唯一名称。 `output.uniqueName` 将用于生成唯一全局变量: diff --git a/website/docs/zh/guide/compatibility/examples.mdx b/website/docs/zh/guide/compatibility/examples.mdx index ad0f6c303706..59b9acbfc178 100644 --- a/website/docs/zh/guide/compatibility/examples.mdx +++ b/website/docs/zh/guide/compatibility/examples.mdx @@ -2,6 +2,6 @@ import { CompatibleCardList } from '@components/RspackCompatible.tsx'; # 兼容性示例 -此页面展示了 [rspack-compat](https://github.com/web-infra-dev/rspack-compat/tree/main) 的示例。这个仓库旨在体现 rspack 对 webpack 生态的兼容性,你可以点击每个插件链接,查看其支持的用法。 +此页面展示了 [rspack-compat](https://github.com/web-infra-dev/rspack-compat/tree/main) 的示例。这个仓库旨在体现 Rspack 对 webpack 生态的兼容性,你可以点击每个插件链接,查看其支持的用法。 diff --git a/website/docs/zh/guide/features/builtin-swc-loader.mdx b/website/docs/zh/guide/features/builtin-swc-loader.mdx index b84b0ba1f7c7..8824a6deb0af 100644 --- a/website/docs/zh/guide/features/builtin-swc-loader.mdx +++ b/website/docs/zh/guide/features/builtin-swc-loader.mdx @@ -129,10 +129,10 @@ export default { :::warning -wasm 插件和 swc 的版本存在一定的绑定关系,需要选择和对应 swc 版本兼容的 wasm 插件才能正常执行, [selecting-swc-core](https://swc.rs/docs/plugin/selecting-swc-core#088x--089x) 里有更多关于如何选择兼容的 wasm 插件的信息。 +Wasm 插件和 SWC 的版本存在一定的绑定关系,需要选择和对应 SWC 版本兼容的 Wasm 插件才能正常执行, [selecting-swc-core](https://swc.rs/docs/plugin/selecting-swc-core#088x--089x) 里有更多关于如何选择兼容的 Wasm 插件的信息。 ::: -Rspack 支持在 `builtin:swc-loader` 里加载 `swc` 的 `wasm` 插件, 你可以通过如下配置启用 `wasm` 插件 +Rspack 支持在 `builtin:swc-loader` 里加载 SWC 的 Wasm 插件, 你可以通过如下配置启用 Wasm 插件 ```js { @@ -161,7 +161,7 @@ Rspack 支持在 `builtin:swc-loader` 里加载 `swc` 的 `wasm` 插件, 你可 } ``` -这是 wasm 插件的一个[示例](https://github.com/rspack-contrib/rspack-examples/blob/d4b8aaef9915ed0f540edbe504217c3d1afe8989/rspack/builtin-swc-loader/rspack.config.js#L45)。 +这是 Wasm 插件的一个[示例](https://github.com/rspack-contrib/rspack-examples/blob/d4b8aaef9915ed0f540edbe504217c3d1afe8989/rspack/builtin-swc-loader/rspack.config.js#L45)。 ### rspackExperiments diff --git a/website/docs/zh/guide/migration/webpack.mdx b/website/docs/zh/guide/migration/webpack.mdx index 733c156e180a..088d7cd2c453 100644 --- a/website/docs/zh/guide/migration/webpack.mdx +++ b/website/docs/zh/guide/migration/webpack.mdx @@ -92,7 +92,7 @@ module.exports = { ### 移除 css-loader 、 style-loader 和 mini-css-extract-plugin -Rspack 内置支持了 css 模块类型 ,原生 css 模块类型内置了对 css、css hmr、css module 以及 css 提取功能的支持,这意味着你不需要再为 css 文件单独配置 css-loader、style-loader 和 mini-css-extract-plugin。 +Rspack 内置支持了 CSS 模块类型 ,原生 CSS 模块类型内置了对 CSS、CSS HMR、CSS Modules 以及 CSS 提取功能的支持,这意味着你不需要再为 CSS 文件单独配置 css-loader、style-loader 和 mini-css-extract-plugin。 ```diff -const MiniCssExtractPlugin = require("mini-css-extract-plugin"); @@ -134,7 +134,7 @@ Rspack 内置支持了 css 模块类型 ,原生 css 模块类型内置了对 c ### CssExtractPlugin -如果依赖 css-loader,例如 css-loader 提供的一些更加定制化的配置项,仍然可以使用 style-loader + css-loader 方案,如果你想要在生产环境将 css 提取成单独的文件,可以使用 Rspack 内置的 CssExtractRspackPlugin 插件。 +如果依赖 css-loader,例如 css-loader 提供的一些更加定制化的配置项,仍然可以使用 style-loader + css-loader 方案,如果你想要在生产环境将 CSS 提取成单独的文件,可以使用 Rspack 内置的 CssExtractRspackPlugin 插件。 CssExtractRspackPlugin 插件功能和配置与 mini-css-extract-plugin 类似,使用前请确保开启了 `experiments.rspackFuture.newTreeshaking`,v0.6 之后的版本默认开启。 diff --git a/website/docs/zh/guide/optimization/tree-shaking.mdx b/website/docs/zh/guide/optimization/tree-shaking.mdx index 4e68762eed1c..1db156d144c0 100644 --- a/website/docs/zh/guide/optimization/tree-shaking.mdx +++ b/website/docs/zh/guide/optimization/tree-shaking.mdx @@ -106,7 +106,8 @@ var __webpack_modules__ = { // ... ``` -正如你所看到的,如果我们不启用 treeShaking,所有代码都保持不变,只是将代码包裹了一层运行时代码。 +正如你所看到的,如果我们不启用 tree shaking,所有代码都保持不变,只是将代码包裹了一层运行时代码。 + 现在,我们切换到 `production` 模式,重新构建项目,为了让产物更加可读,我们同时关闭 `minimize` 选项 以及切换 `moduleIds` 为 `named`,为了和后面章节对比,我们关闭 `optimization.sideEffects`。 ```diff title=rspack.config.js diff --git a/website/docs/zh/guide/tech/nestjs.mdx b/website/docs/zh/guide/tech/nestjs.mdx index 497b6ab4d05c..ede1dc78b401 100644 --- a/website/docs/zh/guide/tech/nestjs.mdx +++ b/website/docs/zh/guide/tech/nestjs.mdx @@ -4,7 +4,7 @@ Rspack 不仅能用于构建前端应用,也可以用于构建 Node.js 应用 ## Native node modules -当使用 Rspack 构建 Node.js 应用时,可能会碰到一些依赖包含 Node.js native addon 依赖(.node 模块),因为 .node 无法打包进 js 产物里,因此一般需要特殊处理,通过 [node-loader](https://www.npmjs.com/package/node-loader) 可以很好的处理 addon 的打包。 +当使用 Rspack 构建 Node.js 应用时,可能会碰到一些依赖包含 Node.js native addon 依赖(.node 模块),因为 .node 无法打包进 JS 产物里,因此一般需要特殊处理,通过 [node-loader](https://www.npmjs.com/package/node-loader) 可以很好的处理 addon 的打包。 ```js title="rspack.config.js" module.exports = { diff --git a/website/docs/zh/misc/benchmark.mdx b/website/docs/zh/misc/benchmark.mdx index 482cb79284ce..75c04f30261d 100644 --- a/website/docs/zh/misc/benchmark.mdx +++ b/website/docs/zh/misc/benchmark.mdx @@ -37,7 +37,7 @@ #### 测量数据 测试于 on Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz 32Core, 64GB of RAM -| | rspack | webpack(with swc) | webpack (with babel) | +| | Rspack | webpack(with swc) | webpack (with babel) | |------------------------|---------|-------------------|----------------------| | development cold start | 3.79s | 31.25s | 42.61s | | production cold start | 22.353s | 75.054s | 160.059s | @@ -73,7 +73,7 @@ - webpack + swc-loader + swc-minifier -- rspack(使用 swc 作为 transpiler 和 swc minifier)。 +- Rspack(使用 SWC 作为 transpiler 和 SWC minifier)。 在开发模式下,所有的配置都保持原样,除了依赖于测试目标的 loader。 diff --git a/website/docs/zh/plugins/rspack/css-extract-rspack-plugin.mdx b/website/docs/zh/plugins/rspack/css-extract-rspack-plugin.mdx index d4d13627e872..3f435d9b6d01 100644 --- a/website/docs/zh/plugins/rspack/css-extract-rspack-plugin.mdx +++ b/website/docs/zh/plugins/rspack/css-extract-rspack-plugin.mdx @@ -5,9 +5,9 @@ import { ApiMeta } from '@components/ApiMeta.tsx'; -Rspack 目前不兼容 mini-css-extract-plugin,但可以使用该插件替代,和 css-loader 搭配使用,将 css 提取成单独文件。 +Rspack 目前不兼容 mini-css-extract-plugin,但可以使用该插件替代,和 css-loader 搭配使用,将 CSS 提取成单独文件。 -如果你的项目不依赖 css-loader,更推荐使用 Rspack 内置的 css 解决方案 experiments.css,性能更好。 +如果你的项目不依赖 css-loader,更推荐使用 Rspack 内置的 CSS 解决方案 `experiments.css`,性能更好。 - options @@ -72,14 +72,14 @@ Rspack 目前不兼容 mini-css-extract-plugin,但可以使用该插件替代 type: '`boolean`', default: 'false', description: - '若某些 css 在不同 chunk 中顺序有冲突,是否发出警告。例如 entryA 引入 a.css b.css,entryB 引入 b.css a.css,a.css 和 b.css 的顺序无法确定', + '若某些 CSS 在不同 chunk 中顺序有冲突,是否发出警告。例如 entryA 引入 a.css b.css,entryB 引入 b.css a.css,a.css 和 b.css 的顺序无法确定', }, { name: '`insert`', type: '`string | ((linkTag: HTMLLinkElement) => void)`', default: 'undefined', description: - '决定 link 标签怎样插入到页面,如果传入 string 类型,则会视为 dom 选择器,link 标签会插入到该选择器对应的元素后。如果传入 function 类型,则会将 function 转成字符串,在运行时进行调用,参数是 link 标签', + '决定 link 标签怎样插入到页面,如果传入 string 类型,则会视为 DOM 选择器,link 标签会插入到该选择器对应的元素后。如果传入 function 类型,则会将 function 转成字符串,在运行时进行调用,参数是 link 标签', }, { name: '`attributes`', @@ -97,13 +97,13 @@ Rspack 目前不兼容 mini-css-extract-plugin,但可以使用该插件替代 name: '`runtime`', type: '`boolean`', default: 'true', - description: '是否注入 css 加载相关的 runtime 代码', + description: '是否注入 CSS 加载相关的 runtime 代码', }, { name: '`pathinfo`', type: '`boolean`', default: 'false', - description: '产物中是否保留更详细的 css 路径信息', + description: '产物中是否保留更详细的 CSS 路径信息', }, ]} /> @@ -142,13 +142,13 @@ Rspack 目前不兼容 mini-css-extract-plugin,但可以使用该插件替代 name: '`emit`', type: '`boolean`', default: 'true', - description: '是否提取出 css 文件,设置为 false 则不会产生 css 文件', + description: '是否提取出 CSS 文件,设置为 false 则不会产生 CSS 文件', }, { name: '`esModule`', type: '`boolean`', default: 'true', - description: '是否使用 es 模块语法进行 css module 类名导出', + description: '是否使用 es 模块语法进行 CSS Modules 类名导出', }, ]} /> From 2256ce8752860a2e96a73355934d2b087d5718ea Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 13 May 2024 14:57:26 +0800 Subject: [PATCH 057/107] docs: duplicated ignoreOrder option in CssExtractPlugin (#6516) docs(CssExtractPlugin): duplicated ignoreOrder option --- .../docs/en/plugins/rspack/css-extract-rspack-plugin.mdx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx b/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx index 10b6b1557957..d1fdcca4b75d 100644 --- a/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx +++ b/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx @@ -70,19 +70,12 @@ If your project does not depend on css-loader, it is recommended to use the buil description: 'The name of the asynchronous loading CSS artifact. If not set, it will use filename; please see output.chunkFilename', }, - { - name: "'ignoreOrder'", - type: "'boolean'", - default: 'false', - description: - 'Whether to issue a warning if there are conflicts in the order of some CSS in different chunks. For example, entryA introduces a.css b.css, entryB introduces b.css a.css, and the order of a.css and b.css cannot be determined', - }, { name: '`ignoreOrder`', type: '`boolean`', default: 'false', description: - 'If there are conflicts in the order of certain CSS files in different chunks, should a warning be issued? For example, entryA imports a.css and b.css, while entryB imports b.css and a.css. The order of a.css and b.css cannot be determined.', + 'Whether to issue a warning if there are conflicts in the order of some CSS in different chunks. For example, entryA introduces a.css b.css, entryB introduces b.css a.css, and the order of a.css and b.css cannot be determined', }, { name: '`insert`', From 670e0d975911a3963dbabf046e8e1180ebfff9a5 Mon Sep 17 00:00:00 2001 From: Soon Date: Mon, 13 May 2024 15:01:34 +0800 Subject: [PATCH 058/107] chore(infra): update .nvmrc (#6517) --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index 9d14de4b8598..0a47c855ebce 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v16.18.0 \ No newline at end of file +lts/iron \ No newline at end of file From 0b62d8a919ceca994d160450aaa4b03d708a9b3f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 15:50:09 +0800 Subject: [PATCH 059/107] chore(deps): update crates (#6467) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 134 ++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f06d15f62aa2..fc5aaffc6963 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,9 +90,9 @@ checksum = "70033777eb8b5124a81a1889416543dddef2de240019b674c81285a2635a7e1e" [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" dependencies = [ "backtrace", ] @@ -122,7 +122,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -155,18 +155,18 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] name = "async-recursion" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -182,13 +182,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -219,7 +219,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -683,7 +683,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eed5fff0d93c7559121e9c72bf9c242295869396255071ff2cb1617147b608c5" dependencies = [ "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -736,7 +736,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -758,7 +758,7 @@ checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" dependencies = [ "darling_core 0.20.6", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -935,7 +935,7 @@ dependencies = [ "darling 0.20.6", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1028,7 +1028,7 @@ checksum = "fdc9cc75639b041067353b9bce2450d6847e547276c6fbe4487d7407980e07db" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1112,7 +1112,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1278,9 +1278,9 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692eaaf7f7607518dd3cef090f1474b61edc5301d8012f09579920df68b725ee" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ "hashbrown 0.14.3", ] @@ -1479,7 +1479,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1852,7 +1852,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1941,7 +1941,7 @@ dependencies = [ "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1956,7 +1956,7 @@ dependencies = [ "quote", "regex", "semver 1.0.20", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2185,9 +2185,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "path-clean" @@ -2243,7 +2243,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2309,7 +2309,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2347,7 +2347,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2370,7 +2370,7 @@ checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2461,9 +2461,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -2510,9 +2510,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -3061,7 +3061,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -3775,9 +3775,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "fc6e7ed6919cb46507fb01ff1654309219f62b4d603822501b0b80d42f6f21ef" dependencies = [ "dyn-clone", "schemars_derive", @@ -3787,14 +3787,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "185f2b7aa7e02d418e453790dde16890256bbd2bcd04b7dc5348811052b53f49" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] @@ -3847,9 +3847,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] @@ -3877,31 +3877,31 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "indexmap 2.2.6", "itoa", @@ -4116,7 +4116,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4166,7 +4166,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4423,7 +4423,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4501,7 +4501,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4657,7 +4657,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5005,7 +5005,7 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5111,7 +5111,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5309,7 +5309,7 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5386,7 +5386,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5464,7 +5464,7 @@ checksum = "91745f3561057493d2da768437c427c0e979dff7396507ae02f16c981c4a8466" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5545,7 +5545,7 @@ checksum = "ff9719b6085dd2824fd61938a881937be14b08f95e2d27c64c825a9f65e052ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5568,7 +5568,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5584,9 +5584,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" dependencies = [ "proc-macro2", "quote", @@ -5695,7 +5695,7 @@ checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5796,7 +5796,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5878,7 +5878,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -7035,5 +7035,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] From ab8c67d216336e1e45ba20faf15be4c568fd6f37 Mon Sep 17 00:00:00 2001 From: Soon Date: Mon, 13 May 2024 17:34:35 +0800 Subject: [PATCH 060/107] docs: migrate rspack dev guide to documentation site (#6515) --- website/docs/en/_meta.json | 5 + website/docs/en/contribute/_meta.json | 69 ++ .../docs/en/contribute/building/_meta.json | 1 + .../en/contribute/building/build-and-run.md | 25 + .../en/contribute/building/prerequisites.md | 32 + website/docs/en/contribute/debugging.md | 90 ++ .../docs/en/contribute/debugging/mix-debug.md | 111 +++ website/docs/en/contribute/index.mdx | 36 + website/docs/en/contribute/profiling.md | 125 +++ website/docs/en/contribute/releasing.md | 44 + website/docs/en/contribute/repro.md | 16 + website/docs/en/contribute/rspack.md | 8 + website/docs/en/contribute/rspack/loader.md | 87 ++ website/docs/en/contribute/rspack/plugin.md | 58 ++ website/docs/en/contribute/sending-pr.md | 39 + website/docs/en/contribute/testing.md | 67 ++ website/docs/en/contribute/testing/e2e.md | 81 ++ website/docs/en/contribute/webpack.md | 8 + .../docs/en/contribute/webpack/dependency.md | 571 +++++++++++++ website/docs/en/contribute/webpack/loader.md | 783 ++++++++++++++++++ .../docs/en/contribute/workflows/meetings.md | 9 + website/docs/en/contribute/workflows/misc.md | 9 + .../docs/en/contribute/workflows/releases.md | 19 + website/project-words.txt | 17 + website/rspress.config.ts | 1 + website/sortProjectWords.js | 9 + 26 files changed, 2320 insertions(+) create mode 100644 website/docs/en/contribute/_meta.json create mode 100644 website/docs/en/contribute/building/_meta.json create mode 100644 website/docs/en/contribute/building/build-and-run.md create mode 100644 website/docs/en/contribute/building/prerequisites.md create mode 100644 website/docs/en/contribute/debugging.md create mode 100644 website/docs/en/contribute/debugging/mix-debug.md create mode 100644 website/docs/en/contribute/index.mdx create mode 100644 website/docs/en/contribute/profiling.md create mode 100644 website/docs/en/contribute/releasing.md create mode 100644 website/docs/en/contribute/repro.md create mode 100644 website/docs/en/contribute/rspack.md create mode 100644 website/docs/en/contribute/rspack/loader.md create mode 100644 website/docs/en/contribute/rspack/plugin.md create mode 100644 website/docs/en/contribute/sending-pr.md create mode 100644 website/docs/en/contribute/testing.md create mode 100644 website/docs/en/contribute/testing/e2e.md create mode 100644 website/docs/en/contribute/webpack.md create mode 100644 website/docs/en/contribute/webpack/dependency.md create mode 100644 website/docs/en/contribute/webpack/loader.md create mode 100644 website/docs/en/contribute/workflows/meetings.md create mode 100644 website/docs/en/contribute/workflows/misc.md create mode 100644 website/docs/en/contribute/workflows/releases.md create mode 100644 website/sortProjectWords.js diff --git a/website/docs/en/_meta.json b/website/docs/en/_meta.json index 935be1f70f43..1417f25f822c 100644 --- a/website/docs/en/_meta.json +++ b/website/docs/en/_meta.json @@ -28,5 +28,10 @@ "text": "About", "link": "/misc/faq", "activeMatch": "/misc" + }, + { + "text": "Contribute", + "link": "/contribute/index", + "activeMatch": "/contribute" } ] diff --git a/website/docs/en/contribute/_meta.json b/website/docs/en/contribute/_meta.json new file mode 100644 index 000000000000..5eef3afaddc6 --- /dev/null +++ b/website/docs/en/contribute/_meta.json @@ -0,0 +1,69 @@ +[ + "index", + { + "type": "divider" + }, + { + "type": "section-header", + "label": "Development" + }, + { + "type": "dir", + "name": "building", + "label": "Building and running" + }, + { + "type": "dir", + "name": "testing", + "label": "Testing" + }, + { + "type": "dir", + "name": "debugging", + "label": "Debugging" + }, + { + "type": "file", + "name": "profiling", + "label": "Profiling" + }, + { + "type": "file", + "name": "releasing", + "label": "Releasing" + }, + { + "type": "divider" + }, + { + "type": "section-header", + "label": "Contribution" + }, + { + "type": "file", + "label": "Sending a Pull Request", + "name": "sending-pr" + }, + { + "type": "file", + "label": "Minimal reproducible example", + "name": "repro" + }, + { + "type": "divider" + }, + { + "type": "section-header", + "label": "Architecture" + }, + { + "type": "dir", + "label": "Rspack", + "name": "rspack" + }, + { + "type": "dir", + "label": "Webpack", + "name": "webpack" + } +] diff --git a/website/docs/en/contribute/building/_meta.json b/website/docs/en/contribute/building/_meta.json new file mode 100644 index 000000000000..d6775ac45608 --- /dev/null +++ b/website/docs/en/contribute/building/_meta.json @@ -0,0 +1 @@ +["prerequisites", "build-and-run"] diff --git a/website/docs/en/contribute/building/build-and-run.md b/website/docs/en/contribute/building/build-and-run.md new file mode 100644 index 000000000000..28a9051597bb --- /dev/null +++ b/website/docs/en/contribute/building/build-and-run.md @@ -0,0 +1,25 @@ +# How to build and run the compiler + +Please see [prerequisites](./prerequisites.md) for setting up Rust and Node.js. + +## Install Node.js dependencies + +Install Node.js dependencies via [pnpm](https://pnpm.io/). + +```bash +# enable pnpm with corepack, only available on node >= `v14.19.0` +corepack enable + +# or install pnpm directly +npm install -g pnpm@8 + +# Install dependencies +pnpm install +``` + +## Building Rspack + +- Run `cargo build` to compile Rust code. +- Run `pnpm run build:cli:debug` to compile both Node.js and Rust code. + +The built binary is located at `packages/rspack-cli/bin/rspack`. diff --git a/website/docs/en/contribute/building/prerequisites.md b/website/docs/en/contribute/building/prerequisites.md new file mode 100644 index 000000000000..d210c6ce4c98 --- /dev/null +++ b/website/docs/en/contribute/building/prerequisites.md @@ -0,0 +1,32 @@ +# Prerequisites + +## Setup Rust + +- Install Rust using [rustup](https://rustup.rs/). +- If you are using VSCode, we recommend installing the [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) extension. + +## Setup Node.js + +### Install Node.js + +We recommend using the LTS version of Node.js 16. You can check your currently used Node.js version with the following command: + +```bash +node -v +#v16.18.0 +``` + +If you do not have Node.js installed in your current environment, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install it. + +Here is an example of how to install the Node.js 16 LTS version via nvm: + +```bash +# Install the LTS version of Node.js 16 +nvm install 16 --lts + +# Make the newly installed Node.js 16 as the default version +nvm alias default 16 + +# Switch to the newly installed Node.js 16 +nvm use 16 +``` diff --git a/website/docs/en/contribute/debugging.md b/website/docs/en/contribute/debugging.md new file mode 100644 index 000000000000..21721f00e2b6 --- /dev/null +++ b/website/docs/en/contribute/debugging.md @@ -0,0 +1,90 @@ +# Debugging + +## Debugging with VSCode + +1. Install `go install github.com/go-delve/delve/cmd/dlv@latest` +2. Install VSCode extension [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) and [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) +3. build `@rspack/cli` and napi binding by run `pnpm install && pnpm -w build:cli:debug` +4. In VSCode's `Run and Debug` tab, select `debug-rspack` to start debugging the initial launch of `@rspack/cli`. This task can be configured in `.vscode/launch.json`, which launches the Node and Rust debugger together. + +## Tracing + +[`tracing`](https://crates.io/crates/tracing) is used to instrumenting Rspack. + +The supported tracing levels for + +- release builds are `INFO`, `WARN` and `ERROR` +- debug builds are `TRACE`, `DEBUG`, `INFO`, `WARN` and `ERROR` + +Use the `RSPACK_PROFILE` environment variable for displaying trace information + +```bash +RSPACK_PROFILE=TRACE=layer=logger rspack build +# filter for an event +RSPACK_PROFILE='TRACE=layer=logger&filter=rspack_core::compiler::compilation' rspack build +# with logger level +RSPACK_PROFILE='TRACE=layer=logger&filter=rspack_core::compiler::compilation=info' rspack build +# filter logs across multiple modules +RSPACK_PROFILE='TRACE=layer=logger&filter=rspack_core::compiler::compilation,rspack_core::build_chunk_graph::code_splitter' rspack build +# [fn_name] will show: +# - all functions calls to `fn_name` +# - the arguments(except for these in the `skip` list) +# - everything until this function returns +RSPACK_PROFILE='TRACE=layer=logger&filter=[build_chunk_graph]' rspack build +# compilation::chunk_asset is a custom instrument name +RSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset]' rspack build +# log a specific function by their arguments +RSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset{filename="main\.js"}]' rspack build +# It support regexp expression +RSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset{filename=".*\.js"}]' rspack build +# disable ansi color escape codes +NO_COLOR=1 RSPACK_PROFILE=TRACE=layer=logger rspack build +``` + +### `oxc_resolver` + +`oxc_resolver` emits some tracing information for debugging purposes. + +```bash +RSPACK_PROFILE='TRACE=filter=oxc_resolver=trace&layer=logger' rspack build +``` + +## rust-lldb + +`rust-lldb` can be used to get panic information from debug builds + +```bash +rust-lldb -- node /path/to/rspack build +``` + +Once it launches, press `r` for running the program. + +For example, `examples/arco-pro` crashes without any information before [this fix](https://github.com/web-infra-dev/rspack/pull/3195/files): + +``` +rspack/examples/arco-pro ❯ node ../../packages/rspack-cli/bin/rspack build +Rspack ██████████████████████░░░░░░░░░░░░░░░░░░ 56% building ./pages/welcome +zsh: bus error node ../../packages/rspack-cli/bin/rspack build +``` + +Using `rust-lldb` + +```bash +rspack/examples/arco-pro ❯ rust-lldb -- node ../../packages/rspack-cli/bin/rspack build +``` + +Press `r` and it prints: + +``` +Process 23110 stopped +* thread #10, name = 'tokio-runtime-worker', stop reason = EXC_BAD_ACCESS (code=2, address=0x70000cc66560) + frame #0: 0x0000000140d0db4b rspack.darwin-x64.node`swc_ecma_parser::parser::expr::ops::_$LT$impl$u20$swc_ecma_parser..parser..Parser$LT$I$GT$$GT$::parse_unary_expr::h29f49330a806839c(self=0x0000000000000000) at ops.rs:244 + 241 /// Parse unary expression and update expression. + 242 /// + 243 /// spec: 'UnaryExpression' +-> 244 pub(in crate::parser) fn parse_unary_expr(&mut self) -> PResult> { + 245 trace_cur!(self, parse_unary_expr); + 246 let start = cur_pos!(self); + 247 +Target 0: (node) stopped. +``` diff --git a/website/docs/en/contribute/debugging/mix-debug.md b/website/docs/en/contribute/debugging/mix-debug.md new file mode 100644 index 000000000000..6e27d79255c1 --- /dev/null +++ b/website/docs/en/contribute/debugging/mix-debug.md @@ -0,0 +1,111 @@ +# Mixed Debugging Between JavaScript and Rust + +This discussion aims to illustrate the method for mixed debugging between JavaScript and Rust. + +## Prerequisites + +To illustrate this process, I'll use an example. Let's start by introduce the environment and example I have used. + +- System: macos +- IDE: vscode +- Debugging target: `rspack build ${projectRoot}/basic` + +Firstly, you need to build rspack in debug mode. To do this, execute the following commands in the project's root directory: + +```bash +npm run build:binding:debug +npm run build:js +``` + +## Configure `launch.json` in vscode + +It's necessary to configure two debug configurations within in `.vscode/launch.json.` + +- attach for node: + +```jsonc +{ + "name": "attach:node”, + "request": "attach", // refer: https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations + "type": "node", + // `9229` is the default port of message + "port": 9229 +} +``` + +- and launch for lldb + +```jsonc +{ + "name": "launch:rust-from-node", + "request": "launch”, + "type": "lldb", // it means we use `lldb` to launch the binary file of `node` + "program": "node”, + "args": [ + "--inspect", + "--enable-source-maps", + "${workspaceFolder}/packages/rspack-cli/bin/rspack", + "build", + "-c", + "${workspaceFolder}/examples/basic/rspack.config.js", + ], + // `cwd` is just for repack find the correctly entry. + "cwd": "${workspaceFolder}/examples/basic/" +} +``` + +Next, we can utilize [compounds](https://code.visualstudio.com/docs/editor/debugging#_compound-launch-configurations) to amalgamate the two commands: + +```json +{ + "name": "mix-debug", + "configurations": ["attach:node", "launch:rust-from-node"] +} +``` + +Finally, your `launch.json` should appear as follows: + +```json +{ + "configurations": [ + { + "name": "attach:node", + "request": "attach", + "type": "node", + "port": 9229 + }, + { + "name": "launch:rust-from-node", + "request": "launch", + "type": "lldb", + "program": "node", + "args": [ + "--inspect", + "--enable-source-maps", + "${workspaceFolder}/packages/rspack-cli/bin/rspack", + "build", + "-c", + "${workspaceFolder}/examples/basic/rspack.config.js" + ], + "cwd": "${workspaceFolder}/examples/basic/" + } + ], + "compounds": [ + { + "name": "mix-debug", + "configurations": ["attach:node", "launch:rust-from-node"] + } + ] +} +``` + +## Debugging Attempt + +Next, we can introduce some breakpoints and commence debugging. + +The result appears as follows: + + diff --git a/website/docs/en/contribute/index.mdx b/website/docs/en/contribute/index.mdx new file mode 100644 index 000000000000..61e040f90fc5 --- /dev/null +++ b/website/docs/en/contribute/index.mdx @@ -0,0 +1,36 @@ +# Getting Stated + +We are grateful for your interest in contributing to Rspack! +Every single contribution counts and helps us take Rspack to the next level. + +## Asking Questions + +If you have any questions, +please do not hesitate to ask in either the [Discord](https://discord.gg/79ZZ66GH9E) support channel or on the [Github discussion board](https://github.com/web-infra-dev/rspack/discussions). + +## What should I work on? + +### Good First Issue + +If you are looking to dive into the codebase and get started, +we recommend checking out our issue list labeled with [good first issue](https://github.com/web-infra-dev/rspack/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22good+first+issue%22). +This will help you get acquainted with the project and start contributing. + +### Tracking Issue + +If you are interested in understanding our project's direction and want to work on issues that are aligned with our priorities, +our [tracking issues list](https://github.com/web-infra-dev/rspack/issues?q=is%3Aopen+label%3A%22tracking+issue%22+sort%3Aupdated-desc) +provides an overview of our progress and current goals. + +## Other ways to contribute + +We are always looking for contributors, and that goes beyond just our main repository. +Check out these other ways to get involved and start making a difference today. + +- The [documentation website](https://github.com/web-infra-dev/rspack-website) is at [web-infra-dev/rspack-website](https://github.com/web-infra-dev/rspack-website) +- This dev guide is at [web-infra-dev/rspack-dev-guide](https://github.com/web-infra-dev/rspack-dev-guide) +- Community packages is at [https://github.com/rspack-contrib](https://github.com/rspack-contrib) + +--- + +As a reminder, all contributors are expected to follow our [Code of Conduct](https://github.com/web-infra-dev/rspack/blob/main/CODE_OF_CONDUCT.md). diff --git a/website/docs/en/contribute/profiling.md b/website/docs/en/contribute/profiling.md new file mode 100644 index 000000000000..eec3ff0ec326 --- /dev/null +++ b/website/docs/en/contribute/profiling.md @@ -0,0 +1,125 @@ +# Profiling + +In this section, we'll explore how to profile Rspack for identifying bottlenecks. +By examining where Rspack spends its time, we can gain insights into how to improve performance. +Since different profilers have different strengths. It is good to use more than one. + + + +## Tracing + +[`tracing`](https://crates.io/crates/tracing) is used to instrumenting Rspack. + +The supported tracing levels for + +- release builds are `INFO`, `WARN` and `ERROR` +- debug builds are `TRACE`, `DEBUG`, `INFO`, `WARN` and `ERROR` + +Two ways to enable tracing: + +- if you are using `@rspack/cli`, you can enable it by `RSPACK_PROFILE` environment variable. +- if you are using `@rspack/core` without `@rspack/cli`, you can enable it by `experimental_registerGlobalTrace` and `experimental_cleanupGlobalTrace`, checkout [how we implement `RSPACK_PROFILE` in `@rspack/cli` with these two function](https://github.com/web-infra-dev/rspack/blob/25df2981ce1f0232ab05109c0995a249f57e2a09/packages/rspack-cli/src/utils/profile.ts#L186-L187) for more details. + +### Chrome + +[`tracing-chrome`](https://crates.io/crates/tracing-chrome) is supported for viewing tracing information graphically. + +![image](https://github.com/SyMind/rspack-dev-guide/assets/19852293/1af08ba1-a2e9-4e3e-99ab-87c1e62e067b) + +Setting the environment variable `RSPACK_PROFILE=TRACE=layer=chrome` before running Rspack, for example + +```bash +RSPACK_PROFILE=TRACE=layer=chrome rspack build +``` + +produces a trace file (`.rspack-profile-${timestamp}/trace.json`) in the current working directory. + +The JSON trace file can be viewed in either `chrome://tracing` or [ui.perfetto.dev](https://ui.perfetto.dev). + +### Terminal + +Granular tracing event values can be viewed inside the terminal via `RSPACK_PROFILE=TRACE=layer=logger`, for example + +```bash +RSPACK_PROFILE=TRACE=layer=logger rspack build +``` + +will print the options passed to Rspack as well as each individual tracing event. + +### Nodejs Profiling + +If we find that the performance bottleneck is on the JS side (e.g. js loader), then we need to further analyse the js side, and we can use Nodejs Profiling to analyse. for example + +```bash +node --cpu-prof {rspack_bin_path} -c rspack.config.js +``` + +or + +```bash +RSPACK_PROFILE=JSCPU rspack build +``` + +this will generates a cpu profile like `CPU.20230522.154658.14577.0.001.cpuprofile`, and we can use speedscope to visualize the profile, for example + +```bash +npm install -g speedscope +speedscope CPU.20230522.154658.14577.0.001.cpuprofile +``` + +## Mac Xcode Instruments + +Xcode instruments can be used to produce a CPU profile if you are on a Mac. + +![image](https://github.com/SyMind/rspack-dev-guide/assets/19852293/124e3aee-944a-4509-bb93-1c9213f026d3) + +To install Xcode Instruments, simply install the Command Line Tools: + +```bash +xcode-select --install +``` + +For normal Rust builds, [`cargo instruments`](https://github.com/cmyr/cargo-instruments) can be used as the glue +for profiling and creating the trace file. + +Since Rspack takes quite a while to build, you can use the following procedure without invoking `cargo instruments`. +It has the same effect. + +In workspace root's `Cargo.toml`, turn on debug symbols and disable symbol stripping in the `[profile.release]` section + +```toml +[profile.release] +debug = 1 # debug info with line tables only +strip = false # do not strip symbols +``` + +Then build the project + +```bash +pnpm run build:cli:release +``` + +The final binary is located at `packages/rspack-cli/bin/rspack` once the project is built. + +Under the hood, `cargo instruments` invokes the `xcrun` command, +which means we can run the following in our own project that uses Rspack. + +```bash +xcrun xctrace record --template 'Time Profile' --output . --launch -- /path/to/rspack/packages/rspack-cli/bin/rspack build +``` + +It produces the following output + +``` +Starting recording with the Time Profiler template. Launching process: rspack. +Ctrl-C to stop the recording +Target app exited, ending recording... +Recording completed. Saving output file... +Output file saved as: Launch_rspack_2023-04-24_11.32.06_9CFE3A63.trace +``` + +We can open the trace file by + +```bash +open Launch_rspack_2023-04-24_11.32.06_9CFE3A63.trace +``` diff --git a/website/docs/en/contribute/releasing.md b/website/docs/en/contribute/releasing.md new file mode 100644 index 000000000000..5be62d29229c --- /dev/null +++ b/website/docs/en/contribute/releasing.md @@ -0,0 +1,44 @@ +# Releasing + +All releases are automated through GitHub actions. + +All published releases of `@rspack/cli` can be found on the [npm versions page](https://www.npmjs.com/package/@rspack/cli?activeTab=versions). They are tagged as + +- `latest` with semver version `x.y.z` +- `nightly` +- `canary` + +## Latest Full Release + +The [full release workflow](https://github.com/web-infra-dev/rspack/actions/workflows/release.yml?query=is%3Asuccess) +is currently triggered manually every Tuesday with full release notes. + +The following 9 targets are built + +- x86_64-unknown-linux-gnu +- aarch64-unknown-linux-gnu +- x86_64-unknown-linux-musl +- aarch64-unknown-linux-musl +- i686-pc-windows-msvc +- x86_64-pc-windows-msvc +- aarch64-pc-windows-msvc +- x86_64-apple-darwin +- aarch64-apple-darwin + +## Nightly + +The [nightly release workflow](https://github.com/web-infra-dev/rspack/actions/workflows/release-nightly.yml?query=is%3Asuccess) +is triggered every day at UTC 16:00:07, which is 00:07 AM Beijing Time (offset with an odd minute to avoid cron jobs firing off at the same time). + +The nightly build fully replicates the full release build for catching errors early. + +## Canary + +Commenting on a PR with the text `!canary` triggers the [canary release workflow](https://github.com/web-infra-dev/rspack/actions/workflows/release-canary.yml?query=is%3Asuccess). +Only contributors have the permission to publish canary releases. + +The canary release only builds three targets for quicker feedback + +- aarch64-apple-darwin +- x86_64-apple-darwin +- x86_64-unknown-linux-gnu diff --git a/website/docs/en/contribute/repro.md b/website/docs/en/contribute/repro.md new file mode 100644 index 000000000000..0bb657b64dd8 --- /dev/null +++ b/website/docs/en/contribute/repro.md @@ -0,0 +1,16 @@ +# Minimal reproducible example + +The [rspack repro template](https://github.com/web-infra-dev/rspack-repro) can be used to create a minimal reproducible example. + +A minimal reproducible example (MRE) is a code that is: + +- Short +- Self-contained +- Demonstrates the problem being encountered + +An MRE is essential because it allows us to quickly understand and reproduce your issue. +This, in turn, increases the likelihood of getting a helpful and accurate response in a shorter amount of time. +It is important to note that an MRE should not include extraneous code related to unrelated functionality, +and should instead focus solely on the problem at hand. + +Please see also [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) from Stackoverflow. diff --git a/website/docs/en/contribute/rspack.md b/website/docs/en/contribute/rspack.md new file mode 100644 index 000000000000..1381652dd175 --- /dev/null +++ b/website/docs/en/contribute/rspack.md @@ -0,0 +1,8 @@ +# rspack + +This is the architecture of current rspack implementation + +# Table of Contents + +- [loader](./rspack/loader.md) +- [plugin](./rspack/plugin.md) diff --git a/website/docs/en/contribute/rspack/loader.md b/website/docs/en/contribute/rspack/loader.md new file mode 100644 index 000000000000..d59e4cf241a8 --- /dev/null +++ b/website/docs/en/contribute/rspack/loader.md @@ -0,0 +1,87 @@ +# Loader + +## Related PRs + +- [rspack#2780](https://github.com/web-infra-dev/rspack/pull/2789) +- [rspack#2808](https://github.com/web-infra-dev/rspack/pull/2808) + +The old architecture is a quite simple version, which only supports loaders for normal stage. +Pitching loader does not put into consideration. The basic concept of the old version is to +convert the normal loader to a native function which can be called from the Rust side. +Furthermore, for performance reason, Rspack also composes loaders from the JS side to +mitigate the performance issue of Node/Rust communications. + +In this new architecture, loaders will not be converted directly into native functions. +Instead, it is almost the same with how webpack's loader-runner resolves its loaders, by +leveraging the identifier. Every time Rspack wants to invoke a JS loader, the identifiers will +be passed to the handler passed by Node side to process. The implementation also keeps +the feature of composing JS loaders for performance reason. + +## Guide-level explanation + +The refactor does not introduce any other breaking changes. So it's backwards compatible. +The change of the architecture also help us to implement pitching loader with composability. + +### Pitching loader + +Pitching loader is a technique to change the loader pipeline flow. It is usually used with +inline loader syntax for creating another loader pipeline. style-loader, etc and other loaders +which might consume the evaluated result of the following loaders may use this technique. +There are other technique to achieve the same ability, but it's out of this article's topic. + +See [Pitching loader](https://webpack.js.org/api/loaders/#pitching-loader) for more detail. + +## Reference-level explanation + +### Actor of loader execution + +In the original implementation of loader, Rspack will convert the normal loaders in the first place, +then pass it to the Rust side. In the procedure of building modules, these loaders will be called directly: + +![Old architecture](https://user-images.githubusercontent.com/10465670/233357319-e80f6b32-331c-416d-b4b5-30f3e0e394bd.png) + +The loader runner is only on the Rust side and execute the loaders directly from the Rust side. +This mechanism has a strong limit for us to use webpack's loader-runner for composed loaders. + +In the new architecture, we will delegate the loader request from the Rust core to a dispatcher +located on the JS side. The dispatcher will normalize the loader and execute these using a modified +version of webpack's loader-runner: + +![image](https://user-images.githubusercontent.com/10465670/233357805-923e0a27-609d-409a-b38d-96a083613235.png) + +Loader functions for pitch or normal will not be passed to the Rust side. Instead, each JS loader has +its identifier to uniquely represent each one. If a module requests a loader for processing the module, +Rspack will pass identifier with options to the JS side to instruct the Webpack like loader-runner to +process the transform. This also reduces the complexity of writing our own loader composer. + +### Passing options + +Options will normally be converted to query, but some of the options contain fields that cannot be +serialized, Rspack will reuse the _**loader ident**_ created by webpack to uniquely identify the option +and restore it in later loading process. + +### Optimization for pitching + +As we had known before, each loader has two steps, pitch and normal. For a performance friendly +interoperability, we must reduce the communication between Rust and JS as minimum as possible. +Normally, the execution steps of loaders will look like this: + +![image](https://user-images.githubusercontent.com/10465670/233360942-7517f22e-3861-47cb-be9e-6dd5f5e02a4a.png) + +The execution order of the loaders above will looks like this: + +``` +loader-A(pitch) + loader-B(pitch) + loader-C(pitch) + loader-B(normal) +loader-A(normal) +``` + +The example above does not contain any JS loaders, but if, say, we mark these loaders registered on the +JS side: + +![image](https://user-images.githubusercontent.com/10465670/233362338-93e922f6-8812-4ca9-9d80-cf294e4f2ff8.png) + +The execution order will not change, but Rspack will compose the step 2/3/4 together for only a single +round communication. diff --git a/website/docs/en/contribute/rspack/plugin.md b/website/docs/en/contribute/rspack/plugin.md new file mode 100644 index 000000000000..7edef4d59caf --- /dev/null +++ b/website/docs/en/contribute/rspack/plugin.md @@ -0,0 +1,58 @@ +# How to write a builtin plugin + +Builtin plugin uses [rspack_macros](https://github.com/web-infra-dev/rspack/tree/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_macros) to help you avoid writing boilerplate code, you can use [cargo-expand](https://github.com/dtolnay/cargo-expand) or [rust-analyzer expand macro](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to checkout the expanded code, and for developing/testing these macro, you can starts with [rspack_macros_test](https://github.com/web-infra-dev/rspack/tree/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_macros_test). + +A simple example: + +```rust +use rspack_hook::{plugin, plugin_hook}; +use rspack_core::{Plugin, PluginContext, ApplyContext, CompilerOptions}; +use rspack_core::CompilerCompilation; +use rspack_error::Result; + +// define the plugin +#[plugin] +pub struct MyPlugin { + options: MyPluginOptions +} + +// define the plugin hook +#[plugin_hook(CompilerCompilation for MuPlugin)] +async fn compilation(&self, compilation: &mut Compilation) -> Result<()> { + // do something... +} + +// implement apply method for the plugin +impl Plugin for MyPlugin { + fn apply(&self, ctx: PluginContext<&mut ApplyContext>, _options: &mut CompilerOptions) -> Result<()> { + ctx.context.compiler_hooks.tap(compilation::new(self)) + Ok(()) + } +} +``` + +And here is [an example](https://github.com/web-infra-dev/rspack/blob/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_plugin_ignore/src/lib.rs). + +If the hook you need is not defined yet, you can define it by `rspack_hook::define_hook`, `compiler.hooks.assetEmitted` for example: + +```rust +// this will allow you define hook's arguments without limit +define_hook!(CompilerShouldEmit: AsyncSeriesBail(compilation: &mut Compilation) -> bool); +// ------------------ --------------- ----------------------------- ------- +// hook name exec kind hook arguments return value (Result>) + +#[derive(Debug, Default)] +pub struct CompilerHooks { + // ... + // and add it here + pub asset_emitted: CompilerAssetEmittedHook, +} +``` + +There are 5 kinds of exec kind: + +- AsyncSeries, return value is `Result<()>` +- AsyncSeriesBail, return value is `Result>` +- AsyncParallel, return value is `Result<()>` +- SyncSeries, return value is `Result<()>` +- SyncSeriesBail, return value is `Result>` diff --git a/website/docs/en/contribute/sending-pr.md b/website/docs/en/contribute/sending-pr.md new file mode 100644 index 000000000000..6429173cf40e --- /dev/null +++ b/website/docs/en/contribute/sending-pr.md @@ -0,0 +1,39 @@ +# Sending a Pull Request + +1. [Fork](https://help.github.com/articles/fork-a-repo/) the Rspack repository into your own GitHub account. +2. [Clone](https://help.github.com/articles/cloning-a-repository/) the repository to your local. +3. Checkout a new branch from `main`. +4. Set up the development environment, you can read the "Setup Development Environment" section below to learn about it. +5. If you've fixed a bug or added code that should be tested, then add some tests. +6. Make sure all the tests pass, you can read the "Testing" section below to learn about it. +7. Run `pnpm run lint:js` and `pnpm run lint:rs` to check the code style. +8. If you've changed some Node.js packages, you should add a new [changeset](https://github.com/changesets/changesets). Run `pnpm run changeset`, select the changed packages and add the changeset info. +9. If you've changed some Rust packages, you should add a new [changeset](https://github.com/changesets/changesets) for `@rspack/binding` package. +10. Submit the Pull Request, make sure all CI runs pass. +11. The maintainers will review your Pull Request soon. + +When submitting a Pull Request, please note the following: + +- Keep your PRs small enough, so that each PR only addresses a single issue or adds a single feature. +- Please include an appropriate description in the PR, and link related issues. + +## Format of PR titles + +The format of PR titles follow Conventional Commits. + +A example + +``` +feat(ui): Add `Button` component +^ ^ ^ +| | |__ Subject +| |_______ Scope +|____________ Type +``` + +Your PR + +- must have a `Type` +- Optionally have a `Scope` + - `Scope` should be lower case +- must have a `Subject` diff --git a/website/docs/en/contribute/testing.md b/website/docs/en/contribute/testing.md new file mode 100644 index 000000000000..69186ac499ca --- /dev/null +++ b/website/docs/en/contribute/testing.md @@ -0,0 +1,67 @@ +# Testing + +We currently have two sets of test suites, one for Rust and one for Node.js. + +## Rust Testing + +- `cargo test` will run all the rust side tests, which includes standalone tests for core functionality and plugins. +- `UPDATE=1 cargo test` will automatically update the failed snapshot + +## Node Testing + +We are maintaining two test suites for Node Testing in Rspack, Rspack Testing and Webpack Testing + +### Webpack Testing + +We copy the whole webpack test suites into [webpack-test](https://github.com/web-infra-dev/rspack/tree/main/webpack-test#progressively-migrate-webpack-test) folder to check the compatibility with webpack. If you add features or fix bugs we recommend you check whether this feature or bug is covered in webpack test suites first. If it's covered and testable in Webpack Testing, you can enable specific test case by setting return value to true in [`test.filter.js`](https://github.com/web-infra-dev/rspack/blob/80e97477483fcb912473ae339c37d5a5e247f7b1/webpack-test/cases/compile/error-hide-stack/test.filter.js#L2C33-L2C84) in this case folder to enable this case. See more details in https://github.com/web-infra-dev/rspack/blob/main/webpack-test/README.md, Please note that don't modify original test code in Webpack Testing, if you find difficulties in running test suites without modifying original code, you can copy this test code in the following \[Rspack Testing\](#Rspack Testing). + +#### Run Tests + +```sh +# In root path +./x build -a # build binding and js part +./x test webpack # run webpack test suites +``` + +### Rspack Testing + +We maintain test suites in Rspack Testing which is not coverable or need to be modified in Webpack Testing. The test suites lies in [rspack-test](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack/tests). This folder structure is similar with Webpack Testing. + +#### Run Tests + +```sh +# In root path +./x build -a +./x test js +``` + +Or only test the package that you made the changes: + +```sh +# In the Node.js package path +pnpm run build && pnpm run test +``` + +To update snapshots: + +```sh +pnpm --filter '@rspack/*' test -- -u +``` + +### Node Testing Suite Overview + +We use jest for Node.js tests, The most important test cases are the case in the `packages/rspack`. most of these cases comes from webpack https://github.com/webpack/webpack/tree/main/test because we want to make sure that Rspack can work as same as webpack. + +There are three kinds of integration cases in `@rspack/core`. + +#### case.test.ts + +Cases are used to test normal build behavior, we use these cases to test against bundler core functionality, like `entry`, `output`, `module` `resolve`, etc. it will first build your test file to test whether the input could be compiled successfully, then it will use the bundled test file to run test cases in the test file to test bundler's all kinds of behavior. + +#### configCase.test.ts + +Cases are used to test custom build behavior, you could use custom `webpack.config.js` to override default build behavior, you can use these cases to test against behavior related to specific config. + +##### statsTestCase.test.ts + +Cases are used to test your stats, By Default we will use jest's snapshot to snapshot your stats, and we **highly** recommend to **avoid** snapshot except statsCase. you can use statsCase to test behaviors like code splitting | bundle splitting, which is hard to test by just running code. diff --git a/website/docs/en/contribute/testing/e2e.md b/website/docs/en/contribute/testing/e2e.md new file mode 100644 index 000000000000..dad8aa5efe9f --- /dev/null +++ b/website/docs/en/contribute/testing/e2e.md @@ -0,0 +1,81 @@ +# E2E + +The `packages/playground` provides e2e testing feature. We use [playwright](https://github.com/Microsoft/playwright) as the e2e testing framework. + +## Cases + +The entry point of a test case is a file ending with `.test.ts`, and the parent directory of this file is the project directory. + +Here are some rules about test cases: + +- The project directory must contain `rspack.config.js` to start the dev server. +- The project directory can contain multi `*.test.ts`. +- All test cases share dependencies, so just add dependencies in `packages/playground/package.json`. +- The cases folder should contain the category folders and then is the project folders. In principle, there should be no third-level directory. + +## Fixtures + +The `fixtures` is a feature of playwright, in short it provides a variable that is generated in before{Each|All} and destroyed in after{Each|All}. More information see [test-fixtures](https://playwright.dev/docs/test-fixtures) + +Here are some rules when defining a new fixture: + +- Private fixtures should start with `_` and are used only in the current file. +- A file only provides fixtures with the same name. +- A file can only provide one option and starts with `default` +- Register fixtures in `fixtures/index.ts` and export only necessary variables and types. + +Here are some existing fixtures: + +#### pathInfo + +This fixture will generate test environment, and calculate the PathInfo. + +```ts +type PathInfo = { + // test file path + testFile: string; + // project dir + testProjectDir: string; + // temporary project directory to be copied into + tempProjectDir: string; +}; +``` + +#### rspack + +This fixture will start the rspack dev server and provide some useful methods. + +```ts +type Rspack = { + // rspack running project directory + projectDir: string; + // rspack compiler + compiler: Compiler; + // rspack dev server + devServer: DevServer; + // waiting for rspack build finish + waitingForBuild: () => Promise; + // waiting for hmr finish, the poll function is used to check + waitingForHmr: (poll: () => Promise) => Promise; +}; +``` + +#### fileAction + +This fixture will provide file change operations. + +```ts +type fileAction = { + updateFile(relativePath: string, fn: (content: string) => string): void; + deleteFile(relativePath: string): void; +}; +``` + +## How it works + +- playwright scan all test case and allocates a worker to run each case. +- `pathInfo` copy the project directory corresponding to the current case to `temp/${worker_index}`. +- `rspack` rewrite dev server port to `8000 + worker_index` and start compiler and dev server in `temp/${worker_index}`. +- run current tests. +- `rspack` close dev server and compiler. +- `pathInfo` clear `temp/${worker_index}` diff --git a/website/docs/en/contribute/webpack.md b/website/docs/en/contribute/webpack.md new file mode 100644 index 000000000000..b194b8067535 --- /dev/null +++ b/website/docs/en/contribute/webpack.md @@ -0,0 +1,8 @@ +# Webpack + +This is the architecture of webpack implementation + +# Table of Contents + +- [loader](./webpack/loader.md) +- [dependency](./webpack/dependency.md) diff --git a/website/docs/en/contribute/webpack/dependency.md b/website/docs/en/contribute/webpack/dependency.md new file mode 100644 index 000000000000..620b2f0c4e58 --- /dev/null +++ b/website/docs/en/contribute/webpack/dependency.md @@ -0,0 +1,571 @@ +> Based on _Webpack version: 5.73.0_. +> Some source code is omitted for cleaner demonstration in the example. + +# Dependency + +Explain how webpack dependency affects the compilation and what kind of problem that webpack was facing at the moment and the solution to the problem. + +## Glossary + +> What's the meaning of a word used to describe a feature? +> +> Why does the Webpack introduce this and what's the background of introducing this? What kind of problem Webpack was facing at the time? + +### High-level presentations of _Dependencies_ + +- [Dependency(fileDependency)](https://webpack.js.org/api/loaders/#thisadddependency): An existing dependency that is marked as watchable. This is the widely-used type of dependency. CSS Preprocessors like `postcss` strongly depend on this in order to mark its dependency watchable. +- [ContextDependency](https://webpack.js.org/api/loaders/#thisaddcontextdependency): Most useful for requests in which Glob and Regexp were used. For real-world usage, see [[this](https://webpack.js.org/guides/dependency-management/#require-with-expression)](https://webpack.js.org/guides/dependency-management/#require-with-expression). +- [MissingDependency](https://webpack.js.org/api/loaders/#thisaddmissingdependency): A missing dependency to mark it watchable (handles the creation of files during compilation before watchers are attached correctly.) +- [BuildDependency](https://webpack.js.org/configuration/cache/#cachebuilddependencies): Related to persistent cache. +- PresentationalDependency: Dependencies that only affect presentation are mostly used with their associated template. + +### Others + +- [LoaderContext](https://webpack.js.org/api/loaders/#the-loader-context): Context provided by Webpack _loader-runner_, which can be accessed through `this` in each loader function. +- ModuleGraph: A graph to describe the relationship between modules. + +## Guide-level explanation + +### `Dependency` + +`dependency`(`fileDependency`) stands for the file _dependency_ among `missingDependency` and `contextDependency`, etc. The created dependency will be marked as watchable, which is useful in _Hot Module Replacement_ in developer mode. + +The implicit behavior for webpack internally in the case below is to create two dependencies internally. + +```js +import foo from './foo'; +import './style.css'; +``` + +### `ContextDependency` + +`contextDependency` is mostly used in scenarios where we want to dynamic load some module in runtime. In this case, webpack cannot assure which module it will be included in the final bundle at compile time. In order to make the code runnable in runtime, webpack has to firstly create multiple bundle modules corresponding to the matching filename such as `./components/a.js` and `./components/b.js`, etc. + +```js +// index.js +import("./components" + componentName).then(...) +``` + +```js +// components/a.js +... +export default ComponentA; +``` + +```js +// components/b.js +... +export default ComponentB; +``` + +For loaders, you can access to `this.addContextDependency` in each loader function. +For plugins, you can access via `module.buildInfo.contextDependencies`. + +## Reference-level explanation + +> The abstraction of _Dependency_ of Webpack was introduced in Webpack version 0.9 with a big refactor. [Redirect to the commit](https://github.com/webpack/webpack/commit/ee01837d66a44f1dd52fd1e174a6669e0d18dd55) + +### Stakeholders of _Dependency_ + +#### High-level + +![image-20220919171608629](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663578968.png) + +#### Low-level + +![image-20220919171841624](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663579121.png) + +### How _dependencies_ affect the creation of _module graph_? + +#### Duplicated module detection + +Each module will have its own `identifier`, for `NormalModule`, you can find this in `NormalModule#identifier`. If the identifier will be duplicated if inserted in `this._module`, then webpack will directly skip the remaining build process. [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L1270-L1274) + +Basically, an `NormalModule` identifier contains these parts: + +1. `type` \[`string`\]: The module type of a module. If the type of the module is `javascript/auto`, this field can be omitted +2. `request` \[`string`\]: Request to the module. All loaders whether it's inline or matched by a config will be stringified. If _inline match resource_ exists, inline loaders will be executed before any normal-loaders after pre-loaders. A module with a different loader passed through will be treated as a different module regardless of its path. +3. `layer`: applied if provided + +#### Module resolution + +`getResolve` is a loader API on the `LoaderContext`. Loader developers can pass `dependencyType` to its `option` which indicates the category of the module dependency that will be created. Values like `esm` can be passed, then webpack will use type `esm` to resolve the dependency. + +The resolved dependencies are automatically added to the current module. This is driven by the internal plugin system of `enhanced-resolve`. Internally, `enhanced-resolve` uses plugins to handle the dependency registration like `FileExistsPlugin` [\[source\]](https://github.com/webpack/enhanced-resolve/blob/e5ff68aef5ab43b8197e864181eda3912957c526/lib/FileExistsPlugin.js#L34-L54) to detect whether a file is located on the file system or will add this file to a list of `missingDependency` and report in respect of the running mode of webpack. The collecting end of Webpack is generated by the `getResolveContext` in `NormalModule` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L513-L524) + +#### _Module dependency_ in _ModuleGraph_ + +Here's a module graph with `esm` import between modules: + +![image-20220919172119861](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663579279.png) + +The dependency type introduced by `import` or `require` is a derived dependency: _ModuleDependency_. + +A _ModuleDependency_ contains three important fields. + +1. `category`: used to describe the category of dependency. e.g. "esm" | "commonjs" +2. `request`: see the explanation above. +3. `userRequest`: Resource and its inline loader syntax will be stringified and applied, but loaders in `module.rules` will be omitted. + +It's also good to note a field we will talk about later: + +1. `assertions`: assertions in `import foo from "foo.json" assert { type: "json" }` + +More fields can be found in abstract class of _Dependency_ and _ModuleDependency_. [source: Dependency](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Dependency.js#L88) [source: ModuleDependency](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/ModuleDependency.js#L17) + +```js +// null -> index.js + +EntryDependency { + category: "esm", + request: "./index.js", + type: "entry", + _parentModule: undefined +} +``` + +```js +// index.js -> foo.js + +HarmonyImportSideEffectDependency { + category: "esm", + request: "./foo", + type: "harmony side effect evaluation", + _parentModule: NormalModule { identifier: "index.js" } +} +``` + +```js +// index.js -> bar.js + +HarmonyImportSideEffectDependency { + category: "esm", + request: "./bar", + type: "harmony side effect evaluation", + _parentModule: NormalModule { identifier: "index.js" } +} +``` + +```js +// bar.js -> foo.js +HarmonyImportSideEffectDependency { + category: "esm", + request: "./foo", + type: "harmony side effect evaluation", + _parentModule: NormalModule { identifier: "bar.js" } +} +``` + +#### Resolving a module + +_ModuleDependencies_ with different dependency category such as `esm` or `commonjs` will affect the resolving part. For ECMAScript modules, they may prefer `"module"` to `"main"`, and for _CommonJS_ modules, they may use `"main"` in `package.json`. On top of that, conditional exports are also necessary to be taken into account. [doc](https://nodejs.org/api/packages.html#conditional-exports) + +#### Different types of _module dependencies_ + +##### ESM-related derived types + +There are a few of _ModuleDependencies_ introduced in ESM imports. A full list of each derived type can be reached at [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependencyParserPlugin.js) + +###### Import + +**`HarmonyImportDependency`** + +The basic type of harmony-related _module dependencies_ are below. [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependency.js#L51) + +**`HarmonyImportSideEffectDependency`** + +```js +import { foo, bar } from './module'; +import * as module from './module'; +import foo from './module'; +import './module'; +``` + +Every import statement will come with a `HarmonyImportSideEffectDependency`, no matter how the specifiers look like. The specifier will be handled by `HarmonyImportSpecifierDependency` below. + +The field `assertions` will be stored if any import assertions exist for later consumption. +The field `category` will be used as `dependencyType` to resolve modules. + +**`HarmonyImportSpecifierDependency`** + +```js +import { foo, bar } from './module'; +import * as module from './module'; +import foo from './module'; +``` + +Example: + +```js +import { foo, bar } from './module'; + +console.log(foo, bar); +``` + +Specifier will be mapped into a specifier dependency if and only if it is used. JavaScript parser will first tag each variable [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependencyParserPlugin.js#L137), and then create corresponding dependencies on each reading of dependency. [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependencyParserPlugin.js#L189) and finally be replaced to the generated `importVar`. + +##### Export(They are not module dependencies to be actual, but I placed here for convenience) + +**`HarmonyExportHeaderDependency`** + +> PresentationalDependency + +```js +export const foo = 'foo'; +export default 'foo'; +``` + +This is a _presentational dependency_. We will take more time on this later. + +**`HarmonyExportSpecifierDependency`** + +```js +export const foo = "foo"; // `foo` is a specifier + +HarmonyExportSpecifierDependency { + id: string; + name: string; +} +``` + +**`HarmonyExportExpressionDependency`** + +```js +export default "foo"; // "foo" is an expression + +HarmonyExportExpressionDependency { + range: [number, number] // range of the expression + rangeStatement: [number, number] // range of the whole statement +} +``` + +## How _dependencies_ affect code generation + +### _Presentational dependency_ + +> A type of dependency that only affects code presentation. + +**`ConstDependency`** + +``` +ConstDependency { + expression: string + range: [number, number] + runtimeRequirements: Set | null +} +``` + +You can think of the passed `expression` as a `replacement` for the corresponding `range`. For the real world example, you can directly refer to _Constant Folding_. + +### _Template_ + +Remember the fact that Webpack is an architecture wrapped around source code modifications. _Template_ is the solution that helps Webpack to do the real patch on the source code. Each dependency has its associated _template_ which affects a part of the code generation scoped per dependency. In other words, the effect of each _template_ is strictly scoped to its associated dependency. + +![image-20220919173300220](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663579980.png) + +There are three types of modification: + +- `source` +- `fragments` +- `runtimeRequirements` + +A boilerplate of the dependency template looks like this: + +```js +class SomeDependency {} + +SomeDependency.Template = class SomeDependencyTemplate { + /** + * @param {Dependency} dependency the dependency for which the template should be applied + * @param {ReplaceSource} source the current replace source which can be modified + * @param {DependencyTemplateContext} templateContext the context object + * @returns {void} + */ + apply(dependency, source, templateContext) { + // do code mod here + } +}; +``` + +There are three parameters in the function signature: + +- dependency: The associated dependency of this template +- source: The source code represent in `ReplaceSource`, which can be used to replace a snippet of code with a new one, given the start and end position +- templateContext: A context of template, which stores the corresponding `module`, `InitFragments`, `moduleGraph`, `runtimeRequirements`, etc. (not important in this section) + +#### `Source` + +Again, given an example of [`ConstDependency`](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/ConstDependency.js#L20), even if you don't have an idea what it is, it doesn't matter. We will cover this in the later sections. + +The associated template modifies the code with `Source`(`ReplaceSource` to be more specific): + +```js +ConstDependency.Template = class ConstDependencyTemplate extends ( + NullDependency.Template +) { + apply(dependency, source, templateContext) { + const dep = /** @type {ConstDependency} */ (dependency); + + // not necessary code is removed for clearer demonstration + + if (dep.runtimeRequirements) { + for (const req of dep.runtimeRequirements) { + templateContext.runtimeRequirements.add(req); + } + } + + source.replace(dep.range[0], dep.range[1] - 1, dep.expression); + } +}; +``` + +#### `runtimeRequirements` + +As you can see from the `Source` section above, there is another modification we talked about: `runtimeRequirements`, It adds +runtime requirements for the current `compilation`. We will explain more in the later sections. + +#### `Fragments` + +Essentially, a [_fragment_](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js) is a pair of code snippet that to be wrapped around each _module_ source. Note the wording "wrap", it could contain two parts `content` and `endContent` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js#L69). To make it more illustrative, see this: + +image + +The order of the fragment comes from two parts: + +1. The stage of a fragment: if the stage of two fragments is different, then it will be replaced corresponding to the order define by the stage +2. If two fragments share the same order, then it will be replaced in [position](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js#L41) order. + [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js#L153-L159) + +**A real-world example** + +```js +import { foo } from './foo'; + +foo(); +``` + +Given the example above, here's the code to generate a dependency that replaces `import` statement with `__webpack_require__`. + +```js +// some code is omitted for cleaner demonstration +parser.hooks.import.tap( + 'HarmonyImportDependencyParserPlugin', + (statement, source) => { + const clearDep = new ConstDependency('', statement.range); + clearDep.loc = statement.loc; + parser.state.module.addPresentationalDependency(clearDep); + + const sideEffectDep = new HarmonyImportSideEffectDependency(source); + sideEffectDep.loc = statement.loc; + parser.state.module.addDependency(sideEffectDep); + + return true; + }, +); +``` + +Webpack will create two dependencies `ConstDependency` and `HarmonyImportSideEffectDependency` while parsing [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyImportDependencyParserPlugin.js#L110-L132). + +Let me focus on `HarmonyImportSideEffectDependency` more, since it uses `Fragment` to do some patch. + +```js +// some code is omitted for cleaner demonstration +HarmonyImportSideEffectDependency.Template = class HarmonyImportSideEffectDependencyTemplate extends ( + HarmonyImportDependency.Template +) { + apply(dependency, source, templateContext) { + super.apply(dependency, source, templateContext); + } +}; +``` + +As you can see in its associated _template_ [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyImportSideEffectDependency.js#L59), the modification to the code is made via its superclass `HarmonyImportDependency.Template` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyImportDependency.js#L244). + +```js +// some code is omitted for cleaner demonstration +HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends ( + ModuleDependency.Template +) { + apply(dependency, source, templateContext) { + const dep = /** @type {HarmonyImportDependency} */ (dependency); + const { module, chunkGraph, moduleGraph, runtime } = templateContext; + + const referencedModule = connection && connection.module; + + const moduleKey = referencedModule + ? referencedModule.identifier() + : dep.request; + const key = `harmony import ${moduleKey}`; + + // 1 + const importStatement = dep.getImportStatement(false, templateContext); + // 2 + templateContext.initFragments.push( + new ConditionalInitFragment( + importStatement[0] + importStatement[1], + InitFragment.STAGE_HARMONY_IMPORTS, + dep.sourceOrder, + key, + // omitted for cleaner code + ), + ); + } +}; +``` + +As you can see from the simplified source code above, the actual patch made to the generated code is via `templateContext.initFragments`(2). The import statement generated from dependency looks like this. + +```js +/* harmony import */ var _foo__WEBPACK_IMPORTED_MODULE_0__ = + __webpack_require__(/*! ./foo */ './src/foo.js'); //(1) +``` + +Note, the real require statement is generated via _initFragments_, `ConditionalInitFragment` to be specific. Don't be afraid of the naming, for more information you can see the [background](https://github.com/webpack/webpack/pull/11802) of this _fragment_, which let's webpack to change it from `InitFragment` to `ConditionalInitFragment`. + +**How does webpack solve the compatibility issue?** + +For ESM modules, webpack will additionally call a helper to define `_esModule` on exports as an hint: + +```js +__webpack_require__.r(__webpack_exports__); +``` + +The call of a helper is always placed ahead of any `require` statements. Probably you have already get this as the stage of `STAGE_HARMONY_EXPORTS` has high priority than `STAGE_HARMONY_IMPORTS`. Again, this is achieved via `initFragments`. The logic of the compatibility helper is defined in [this](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyCompatibilityDependency.js) file, you can check it out. + +### Runtime + +Runtime generation is based on the previously collected `runtimeRequirements` in different dependency templates and is done after the code generation of each module. Note: it's not after the `renderManifest`, but it's after the code generation of each module. + +![image-20220919173829765](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663580309.png)In the first iteration of collection, Sets of `runtimeRequirements` are collected from the module's code generation results and added to each `ChunkGraphModule`. + +In the second iteration of collection, the collected `runtimeRequirements` are already stored in `ChunkGraphModule`, so Webpack again collects them from there and stores the runtimes required by each chunk of `ChunkGraphChunk`. It's kind of the hoisting procedure of the required runtimes. + +Finally, also known as the third iteration of collection, Webpack hoists `runtimeRequirements` from those chunks that are referenced by the entry chunk and get it hoisted on the `ChunkGraphChunk` using a different field named `runtimeRequirementsInTree` which indicates not only does it contains the runtime requirements by the chunk but also it's children runtime requirements. + +![image-20220919174132772](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663580492.png) + +The referenced source code you can be found it [here](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L3379) and these steps are basically done in `processRuntimeRequirements`. This let me recall the linking procedure of a rollup-like bundler. Anyway, after this procedure, we can finally generate _runtime modules_. Actually, I lied here, huge thanks to the hook system of Webpack, the creation of _runtime modules_ is done in this method via calls to `runtimeRequirementInTree`[\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L3498). No doubt, this is all done in the `seal` step. After that, webpack will process each chunk and create a few code generation jobs, and finally, emit assets. + +### _Hot module replacement_ + +Changes made via _hot module replacement_ is mostly come from `HotModuleReplacementPlugin`. + +Given the code below: + +```js +if (module.hot) { + module.hot.accept(...) +} +``` + +Webpack will replace expressions like `module.hot` and `module.hot.accept`, etc with `ConstDependency` as the _presentationalDependency_ as I previously talked about. [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/HotModuleReplacementPlugin.js#L97-L101) + +With the help of a simple expression replacement is not enough, the plugin also introduce additional runtime modules for each entries. [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/HotModuleReplacementPlugin.js#L736-L748) + +The plugin is quite complicated, and you should definitely checkout what it actually does, but for things related to dependency, it's enough. + +## How _dependencies_ affect production optimizations + +### Constant folding + +> The logic is defined in ConstPlugin : [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/ConstPlugin.js#L135) + +_Constant folding_ is a technique that used as an optimization for optimization. For example: + +**Source** + +```js +if (process.env.NODE_ENV === "development") { + ... +} else { + ... +} +``` + +**Generated** + +```js +if (true) { + ... +} +``` + +With mode set to `"development"`, webpack will "fold" the expression `process.env.NODE_ENV === "development"` into an expression of `"true"` as you can see for the code generation result. + +In the `make` procedure of webpack, Webpack internally uses an `JavaScriptParser` for JavaScript parsing. If an `ifStatement` is encountered, Webpack creates a corresponding `ConstDependency`. Essentially, for the `ifStatement`, the `ConstDependency` looks like this : + +```js +ConstDependency { + expression: "true", + range: [start, end] // range to replace +} +``` + +It's almost the same with `else` branch, if there is no _side effects_(refer to source code for more detail), Webpack will create another `ConstDependency` with `expression` set to `""`, which in the end removes the `else` branch. + +In the `seal` procedure of Webpack, the record of the dependency will be applied to the original source code and generate the final result as you may have already seen above. + +### Tree shaking & DCE + +Tree-shaking is a technique of a bundle-wise DCE(dead code elimination). In the following content, I will use tree-shaking as a wording for bundle-wise and DCE for module-wise code elimination. (I know it's not quite appropriate, but you get the point) + +Here's an example: + +```js +// webpack configuration +module.exports = { + optimization: { + usedExports: true, + }, +}; +``` + +![image-20220919182656468](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663583216.png) + +![image-20220919190553215](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663585553.png) + +![image-20220919190925073](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663585765.png) + +As you can see from the red square, the `initFragment` is generated based on the usage of the exported symbol in the `HarmonyExportSpecifierDependency` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyExportSpecifierDependency.js#L91-L107) + +If `foo` is used in the graph, then the generated result will be this: + +```js +/* harmony export */ __webpack_require__.d(__webpack_exports__, { + /* harmony export */ foo: function () { + return /* binding */ foo; + }, + /* harmony export */ +}); +const foo = 'foo'; +``` + +In the example above, the `foo` is not used, so it will be excluded in the code generation of the template of `HarmonyExportSpecifierDependency` and it will be dead-code-eliminated in later steps. For terser plugin, it eliminates all unreachable code in `processAssets` [\[source\]](https://github.com/webpack-contrib/terser-webpack-plugin/blob/580f59c5d223a31c4a9c658a6f9bb1e59b3defa6/src/index.js#L836). + +## Things related to Persistent cache + +_TODO_ + +## Wrap it up! + +Let's wrap everything up in a simple example! Isn't it exciting? + +![image-20220919223228146](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663597948.png) + +Given a module graph that contains three modules, the entry point of this bundle is `index.js`. To not make this example too complicated, we use normal import statements to reference each module (i.e: only one chunk that bundles everything will be created). + +### `Make` + +![image-20220919223558327](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663598158.png) + +### Dependencies after `make` + +![image-20220919223720739](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663598240.png) + +### `seal` + +![image-20220920180915326](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220920_1663668558.png) + +# References + +_TODO_ diff --git a/website/docs/en/contribute/webpack/loader.md b/website/docs/en/contribute/webpack/loader.md new file mode 100644 index 000000000000..6ba95de5083a --- /dev/null +++ b/website/docs/en/contribute/webpack/loader.md @@ -0,0 +1,783 @@ +> Based on _Webpack version: 5.73.0_. + +# Loader + +Explain how webpack loader works. Even though it's a little bit long and tedious, It's still a teeny-tiny peek at the loader system of Webpack. + +# Glossary + +> What's the meaning of a word used to describe a feature? +> +> Why does the Webpack introduce this and what's the background of introducing this? What kind of problem Webpack was facing at the time? + +## Request Related + +```javascript +import Styles from '!style-loader!css-loader?modules!./styles.css'; +``` + +- [Inline loader syntax](https://webpack.js.org/concepts/loaders/#inline): The syntax that chains the loader together within the specifier, followed by the file requested. e.g. `!style-loader!css-loader?modules!./style.css` +- `request`: The request with _inline loader syntax_ retained. Webpack will convert relative URLs and module requests to absolute URLs for loaders and files requested. e.g. `!full-path-to-the-loader-separated-with-exclamation-mark!full-path-to-styles.css` + +## Resource Related + +```javascript +import foo from './index.js?vue=true&style#some-fragment'; +``` + +- [`resource`](https://webpack.js.org/api/loaders/#thisresource): The absolute path to the requested file with `query` and `fragment` retained but inline loader syntax removed. e.g. `absolute-path-to-index-js.js?vue=true&style#some-fragment` +- [`resourcePath`](https://webpack.js.org/api/loaders/#thisresourcepath): The absolute path to the requested file only. e.g. `absolute-path-to-index-js.js` +- [`resourceQuery`](https://webpack.js.org/api/loaders/#thisresourcequery): Query with question mark `?` included. e.g. `?vue=true&style` +- [`resourceFragment`](https://webpack.js.org/api/loaders/#thisresourcefragment): e.g. `#some-fragment` +- inline match resource: + + - Used to redirect the `module.rules` to another, which is able to adjust the loader chain. We will cover this later. + - Ref: [related PR](https://github.com/webpack/webpack/pull/7462) [Webpack Doc1](https://webpack.js.org/api/loaders/#thisimportmodule) [Webpack Doc2](https://webpack.js.org/api/loaders/#inline-matchresource) + +- `virtualResource`: + - The proposed solution to support asset type changing(A sugar to inline matchResource, which can also affect the asset filename generation) + - See more: [the background of this property](https://github.com/webpack/webpack/issues/14851) + +## Others but also important to note + +- Virtual Module: A kind of module that does not locate in the real file system. But you can still import it. To create a virtual module, you need to follow the [spec](https://www.ietf.org/rfc/rfc2397.txt) and it's also worth noting that Node.js and Webpack both support it under the scheme of `data:`. Also known as, `data:` import. [Doc to Node.js](https://nodejs.org/api/esm.html#data-imports) +- [Module types](https://webpack.js.org/concepts/modules/#supported-module-types) with native support: Webpack supports the following module types native: `'javascript/auto'` |` 'javascript/dynamic'` | `'javascript/esm'` | `'json'` | `'webassembly/sync'` | `'webassembly/async'` | `'asset'` | `'asset/source'` | `'asset/resource'` | `'asset/inline'`, for those types you can use it **without a loader**. From webpack version 4.0+, webpack can understand more than `javascript` alone. + +# Guide-level explanation + +## Loader configuration + +The way that webpack controls what kind of module that each loader would apply is based on `module.rules` + +```javascript +const MiniExtractCssPlugin = require('mini-extract-css-plugin'); + +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + use: ['vue-loader'], + }, + { + test: /\.css$/, + use: [MiniExtractCssPlugin.loader, 'css-loader'], + }, + ], + }, + plugins: [new MiniExtractCssPlugin()], +}; +``` + +Here is a simple option for the configuration of `vue-loader`. `module.rules[number].test` is a part rule to test **whether a rule should be applied**. For `vue-loader` alone, It's kind of confusing how webpack pass the result to the rule of `css`, we will cover this later. But for now, It's good to notice **there is not only a `test` option alone to test if a rule should be applied**. You can find it [here](https://webpack.js.org/configuration/module/#rule) for full conditions supported. Here're some examples of other conditions you can use. + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, // of course, test if the file extension match `vue`. + scheme: 'data', // if the specifier of a request starts with `data:` + resourceQuery: '?raw', // if the `resourceQuery` matches then the rule will be applied. For this example, it's a great idea to apply a `raw-loader` here. + type: 'css', // use webpack's native resource handling for css + }, + ], + }, +}; +``` + +## Examples + +### Vue(1 to n) + +In a single file component(SFC) of Vue, there are commonly three blocks or more blocks([custom blocks](https://vue-loader.vuejs.org/guide/custom-blocks.html#example)) contained. The basic idea of implementing this loader is to convert it into JavaScript / CSS and let webpack handle the chunk generation(e.g. Style should be generated into a separate `.css` file) + +```vue + + + + + +``` + +⬇️⬇️⬇️⬇️⬇️⬇️ + +`Vue-loader` will firstly turn into the `*.vue` file into something like that. + +```javascript +import 'script-path-to-vue-sfc'; +import 'template-path-to-vue-sfc'; +import 'style-path-to-vue-sfc'; +``` + +You may find it weird how webpack handles these imports and build the transformed code. But if I change the code a little bit, you will find the idea. + +```javascript +import 'script:path-to-vue-sfc'; +import 'template:path-to-vue-sfc'; +import 'style:path-to-vue-sfc'; +``` + +and if we tweak the configuration a little bit to this, webpack will know exactly how to work with these import statements. + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + use: ['vue-loader'], + }, + { + scheme: 'script', + use: ['apply-your-javascript-loader', 'vue-script-extract-loader'], + }, + { + scheme: 'template', + use: ['apply-your-javascript-loader', 'vue-template-extract-loader'], + }, + { + scheme: 'style', + use: ['apply-your-style-loader', 'vue-style-extract-loader'], + }, + ], + }, +}; +``` + +We added a few loaders to handle the splitting. I know it's still kind of weird here, but please stick with me and we will find a better way out. + +- vue-script-extract-loader: extract the `script` block from a SFC file. +- vue-style-extract-loader: extract the `style` block from a SFC file. +- vue-template-extract-loader: extract the `template` block from a SFC file and convert it into JavaScript. + +You will find it's really noisy only to transform a `*.vue` file, four loaders were introduced and I believe none of you would like to separate a simple loader into four. It's a real bummer! It will be great to use a single loader `vue-loader` alone. The current vue loader implementation uses resourceQuery to handle this. But how? + +#### Loader optimizations I + +We know that webpack uses a few conditions to handle whether a rule should be applied. Even with `rule.test` alone, the `this.resourceQuery` is still available to `loaderContext` which developer could access it with `this` in any loader function(Don't worry if you still don't catch this. You will understand this after). Based on that, we change the `rule` to this: + +```javascript +module.exports = { + module: { + rules: [ + { + test: /.vue$/, + use: ['vue-loader'], + }, + ], + }, +}; +``` + +This indicates "If an import specifier is encountered, please pass me to vue-loader"! If you remember the import transformation above, we could adjust the transformation a little bit to this: + +**Before** + +```javascript +import 'script-path-to-vue-sfc'; +import 'template-path-to-vue-sfc'; +import 'style-path-to-vue-sfc'; +``` + +**After** + +```javascript +import 'path-to-vue-sfc.vue?script=true'; +import 'path-to-vue-sfc.vue?template=true'; +import 'path-to-vue-sfc.vue?style=true'; +``` + +These requests will match the `test: /.vue$/` above flawlessly and in the loader we can handle like this: + +```javascript +// pseudo code only for proofing of the concept +const compiler = require("some-vue-template-compiler") + +const loader = function(source) { + const { + resourceQuery /* ?script=true or something else */, + resourcePath /* path-to-vue-sfc.vue */ + } = this + + if (resourceQuery === "?script=true") { + return compiler.giveMeCodeofScriptBlock(this.resourcePath) // javascript code + } else if (resourceQuery === "?template=true") { + return compiler.giveMeCodeofTemplateBlock(this.resourcePath) // javascript code + } else if (resourceQuery === "?style=true") { + return compiler.giveMeCodeofStyleBlock(this.resourcePath) // style code + } else { + return ` + import `${this.resourcePath}?script=true`; + import `${this.resourcePath}?template=true`; + import `${this.resourcePath}?style=true`; + ` + } +} + +module.exports = loader +``` + +You can see the loader for the example above will be used for four times. + +1. Encounter a `*.vue` file, transform the code to a few import statements +2. For each import statement introduced in the first transformation, the loader will be used again as they share the same extension `vue`. + +Is this the end? No! Even if you wrote the code like this, it will still fail to load. + +1. For CSS: You haven't tell webpack a way to handle the CSS, remember the CSS part is required to go through the `css-loader` and then `mini-css-extract`(if you want to generate CSS for chunk) or `style-loader`(if you want to append it directly to the DOM). After all, you have to make the result of style to pass these loaders. +2. For JS: You haven't transformed the code to any transpilers, It will be failed if your runtime doesn't support the syntax(maybe in TypeScript for example) and webpack internal acorn compiler does not have the ability to help you with that. + +**Pass the code to the corresponding loaders** + +We tweak the configuration a little bit again. + +```javascript +module.exports = { + module: { + rules: [ + { + test: /.vue$/, + use: ['vue-loader'], + }, + { + test: /.css$/, + use: [MiniCssExtractPlugin.loader, 'css-loader'], + }, + { + test: /.js$/, + use: ['babel-loader'], + }, + ], + }, +}; +``` + +It looks a bit more like the "normal" Webpack configuration. Note that the `rule.test` is based on the file extension, so `vue-loader` did a little bit of hack here. + +```javascript +// pseudo code only for proofing of the concept +const compiler = require("some-vue-template-compiler") + +const loader = function(source) { + const { + resourceQuery /* ?script=true or something else */, + resourcePath /* path-to-vue-sfc.vue */ + } = this + + if (resourceQuery === "?script=true") { + const code = compiler.giveMeCodeofScriptBlock(this.resourcePath) // javascript code + this.resourcePath += ".js" + return code + } else if (resourceQuery === "?template=true") { + const code = compiler.giveMeCodeofTemplateBlock(this.resourcePath) // javascript code + this.resourcePath += ".js" + return code + } else if (resourceQuery === "?style=true") { + const code = compiler.giveMeCodeofStyleBlock(this.resourcePath) // style code + this.resourcePath += ".css" // based on the `lang` in each script, the extension will be set accordingly. + return code + } else { + return ` + import `${this.resourcePath}?script=true`; + import `${this.resourcePath}?template=true`; + import `${this.resourcePath}?style=true`; + ` + } +} + +module.exports = loader +``` + +Webpack uses `resourcePath` to match a `module.rules`. So this hack will let webpack treat blocks accordingly as if they are real files with extensions of `js` | `css` |`...` . + +Finally! But this is only a proof of concept, for the real implementation. You should definitely check out the [`vue-loader`](https://github.com/vuejs/vue-loader) yourself. + +#### Loader Optimization II + +Well done! We implemented a simple and rudimentary version of `vue-loader`. However, the real painful part of this implementation is hacking the extension to match the configuration. But since almost every user would have other `js` | `css` files included in the project, so vue team decide to use this kind of strategy to reuse the user configuration. + +Except for hacking the extension, webpack then provided a more legit way to handle this kind of **rule matching problem** which is known as **_inline match resource_** (We covered it in the glossary part). + +**inline match resource** + +Webpack can do almost anything with an import specifier like the loader chaining we covered in the glossary part. _Inline source match_ is another case. By taking the advantage of it, you can force an import statement to go through a `module.rules` by introducing the `!=!` syntax. For example, if we want to force a `css` file to go through a `less` loader, it will be look like this: + +```javascript +module.exports = { + module: { + rules: [ + { + test: /.less$/, + use: ['style-loader', 'css-loader', 'less-loader'], + }, + ], + }, +}; +``` + +```javascript +// This import should be converted with a loader + +// treat the file as `less` +import './index.css.less!=!./index.css'; +``` + +The slice before the `!=!` is a way to modify the extension of a single file and force it to match the `module.rules` and this transformation is often done in a loader, or you will make your application code specialized for Webpack only. + +After going through the basic example, let's see how we're going to optimize out the hack used in `vue-loader`. + +```javascript +// pseudo code only for proofing of the concept +const compiler = require("some-vue-template-compiler") + +const loader = function(source) { + const { + resourceQuery /* ?script=true or something else */, + resourcePath /* path-to-vue-sfc.vue */ + } = this + + if (resourceQuery === "?vue=true&script=true") { + return compiler.giveMeCodeofScriptBlock(this.resourcePath) // javascript code + } else if (resourceQuery === "?vue=true&template=true") { + return compiler.giveMeCodeofTemplateBlock(this.resourcePath) // javascript code + } else if (resourceQuery === "?vue=true&style=true") { + return compiler.giveMeCodeofStyleBlock(this.resourcePath) // style code + } else { + return ` + import `${this.resourcePath}.js!=!${this.resourcePath}?vue=true&script=true`; + import `${this.resourcePath}.js!=!${this.resourcePath}?vue=true&template=true`; + import `${this.resourcePath}.css!=!${this.resourcePath}?vue=true&style=true`; + ` + } +} + +module.exports = loader +``` + +Webpack will internally use the match resource part(before `!=!`) as the data to match loaders. In order to let `vue-loader` match the resource. We have two options: + +1. Loose test +2. _Inline loader syntax_ + +**1. Loose test** + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.vue/, // original: `/\.vue$/`, we removed the `$` to allow resources with `.vue` included to match this rule. + use: ['vue-loader'], + }, + ], + }, +}; +``` + +We removed the `$` to allow resources with `.vue` included matching this rule. Personally speaking, this is not a good idea, because a loose match might cause mismatches. + +**2. Inline loader syntax** + +```javascript +// vue-loader/index.js + +module.exports = function() { + // ... code omitted + return ` + import `${this.resourcePath}.js!=!${__filename}!${this.resourcePath}?vue=true&script=true`; + import `${this.resourcePath}.js!=!${__filename}!${this.resourcePath}?vue=true&template=true`; + import `${this.resourcePath}.css!=!${__filename}!${this.resourcePath}?vue=true&style=true`; + ` +} +``` + +This technique is to take advantage of the **_inline loader syntax_** to force the loader to go through the vue loader. This tackles down the tangible mismatching ideally and we can still retain the test regex `/\.vue$/` as-is. + +#### Final art and conclusion + +**Configuration** + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + use: ['vue-loader'], + }, + // ... other rules for js, or css, etc. + ], + }, +}; +``` + +**Loader** + +```javascript +// pseudo code only for proofing of the concept +const compiler = require("some-vue-template-compiler") + +const loader = function(source) { + const { + resourceQuery /* ?script=true or something else */, + resourcePath /* path-to-vue-sfc.vue */ + } = this + + if (resourceQuery === "?vue=true&script=true") { + return compiler.giveMeCodeofScriptBlock(resourcePath) // javascript code + } else if (resourceQuery === "?vue=true&template=true") { + return compiler.giveMeCodeofTemplateBlock(resourcePath) // javascript code + } else if (resourceQuery === "?vue=true&style=true") { + return compiler.giveMeCodeofStyleBlock(resourcePath) // style code + } else { + return ` + import `${this.resourcePath}.js!=!${__filename}!${resourcePath}?vue=true&script=true`; + import `${this.resourcePath}.js!=!${__filename}!${resourcePath}?vue=true&template=true`; + import `${this.resourcePath}.css!=!${__filename}!${resourcePath}?vue=true&style=true`; + ` + } +} + +module.exports = loader +``` + +**Conclusion** + +Vue-loader is quite complex. The basic needs of the loader are: + +1. Separate a `*.vue` file request into a number of parts. For each block, explicitly change the resource matching mechanism (using **_inline match resource_**). The killer _inline match resource_ not only gives us great composability with user-defined loaders, but also the ability to interact with webpack supported native types, and we will cover this part late. +2. When requesting the `vue-loader` again for a block, the code of each block is returned and let webpack handle the changed matched resource(e.g. `./App.vue.css`) with user-defined loaders (Webpack did this internally). + +### Use natively supported module types + +We know that webpack only supports `JavaScript` in the old time, from the version of `4.0.0`+([changelog](https://github.com/webpack/webpack/releases/tag/v4.0.0)) + +#### Simplified pre-processor's configuration + +> With the experimental support of CSS. A.K.A webpack knows how to handle CSS files natively. + +**Before** + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.less$/, + use: ['style-loader', 'css-loader', 'less-loader'], + type: 'javascript/auto', // this field is a implicit one, if not defined, it will be set to `"javascript/auto"` + }, + ], + }, +}; +``` + +**After** + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.less$/, + use: ['less-loader'], + type: 'css', + }, + ], + }, + experiments: { + css: true, + }, +}; +``` + +With `experiments.css` on, webpack can experimentally understand the parsing and generating of `css` files which gets rid of `css-loader` and `style-loader`. For the full list of natively supported `Rule.type`, you can find it [here](https://webpack.js.org/configuration/module/#ruletype). + +#### Asset modules + +> From _webpack 4.0.0+_, assets are supported natively + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.(png|jpg)/, + type: 'asset', + }, + ], + }, +}; +``` + +`Rule.type === "asset"` indicates the asset will be automatically tested whether it's going to be inlined or emitted as a file on the real file system. The possible options are: `'asset'` | `'asset/source'` | `'asset/resource'` | `'asset/inline'` + +### Svgr + +Webpack loader will read the source to a UTF-8 string by default. For SVG files, this would fit the webpack load defaults. + +```javascript +// Proof of concept of svgr-loader +module.exports = function (source) { + if (this.resourceQuery === '?svgr=true') { + // the real transform part + let { code } = svgrTransformer.transform(source); + return code; + } + return `require("${this.resourcePath}.jsx!=!${__filename}!${this.resourcePath}?svgr=true")`; // the request part +}; +``` + +Again here we use double-pass to firstly convert each request to the request part with _inline match resource_, and do the real request with query `?svgr=true`, and let _inline match resource_ handle the `jsx` conversion. Before that, we have to call a third-party `jsx` transformer, could be _ESBuild_ for example, for which we cannot reuse other `module.rules` set by the user-side. _Inline match resource_ saved our pain again! + +### Scheme imports + +> Supported in _Webpack version 5.38.0_, doc: [Rule.scheme](https://webpack.js.org/configuration/module/#rulescheme) + +```javascript +// JavaScript +import x from 'data:text/javascript,export default 42'; +console.log('x:', x); +``` + +```css +/* CSS */ +@import ('data:text/css, body { background: #fff; }'); +``` + +Webpack handles `data:` imports for JavaScript internally. + +### Asset transform and rename + +> [**Asset**](https://webpack.js.org/guides/asset-management/): This is a general term for the images, fonts, media, and any other kind of files that are typically used in websites and other applications. These typically end up as individual files within the [output](https://webpack.js.org/glossary/#o) but can also be inlined via things like the [style-loader](https://webpack.js.org/loaders/style-loader) or [url-loader](https://webpack.js.org/loaders/url-loader). +> +> _Originally posted at Webpack [Glossary](https://webpack.js.org/glossary/#a)_ + +#### Default resource reading override + +Asset could be formatted in both text(`*.svg`) or binary (`*.png` / `*.jpg`). For loaders, webpack provides you an option [`raw`](https://webpack.js.org/api/loaders/#raw-loader) to override the default and built-in resource reading strategy from UTF-8 `string` to `Buffer`: + +```javascript +module.exports = function (source /* Buffer */) { + // loader implementation +}; + +module.exports.raw = true; +``` + +#### Transform and rename + +Image there is a need to transform an asset formatted with `png` to `jpg`. There is two abilities that webpack needs to support: + +1. Handle the asset with `raw` content, or a `Buffer`. We can simply override the default resource reading behavior by exporting `raw`(covered before). +2. Change the filename, and reuse the loader for both `png` and `jpg` + +##### Configuration + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.png/, + use: ["png-to-jpg-loader"] // some png to jpg loader, we will implement this + }, + { + test: /\.jpg/, + use: ["jpg-optimizer"] // some jpg optimizer, we will not covert this, + type: "asset/resource" + } + ] + } +} +``` + +1. Rule1: For files with extension `png`, we want to use a `png` to `jpg` loader, which will be covered in this article. +2. Rule2: + 1. For files with extension `jpg`, we want to use a third-party `jpg-optimizer`, which will not be covered in this article. + 2. `type: "asset/resource"`: As soon as all the loaders have gone through, we want webpack to emit the file as an external resource on the file system regardless of the file size(`type: "asset"` will automatically detect the size of an asset to determine whether an asset will be inline-included for dynamically imported from file system). +3. For those `jpg` files converted from `png`, we want them to apply with the `jpg-optimizer` too(i.e. reuse the loaders defined in `module.rules`) + +##### Loader + +```javascript +module.exports = function (source) { + if (this.resourceQuery === '?pngToJPG=true') { + return pngToJpg.transform(source); + } + + return `require("${this.resourcePath}.jpg!=!${__filename}${this.resourcePath}?pngToJPG=true")`; +}; + +module.exports.raw = true; +``` + +We use double-pass again, firstly we convert the extension to `.jpg` which will apply the matched rules(in this case `test: /\.jpg/`), after the transformation of `png-to-jpg-loader`. Generated asset module filename will be based on the _inline match resource_, which is `xxxx.jpg` in this case. + +### AST reuse + +Webpack provides a way to pass metadata(the forth parameter) among the chaining loaders [doc](https://webpack.js.org/api/loaders/#thiscallback). The most commonly used value is `webpackAST` which accepts an `ESTree` compatible(webpack internally uses `acorn`) AST, which hugely improves the performance since webpack instead of parsing the returned code to AST again, **will directly use the AST(`webpackAST`) returned from a loader**(But **the work of a complete walking of an AST can not be omitted** as it's necessary for webpack for do some analysis for its dependencies and will be only done once, so it is not a big overhead.) + +```javascript +module.exports = function (source) { + let ast = AcornParser.parse(source, { + // options + }); + + this.callback(null, '', null, { + webpackAST: ast, + }); +}; +``` + +Good to note that only `ESTree` is compatible, so you cannot pass a CSS AST, or webpack will complain with `"webpackAst is unexpected for the CssParser"`. It will be ok if you don't get this, let's move to the reference-level explanation for analysis in-depth. + +## Reference-level explanation + +This is the reference-level explanation part of webpack's internal loader implementation. + +### Loader composability + +> If you don't quite get this concept, you may refer to the Glossary and _Example_ part of the Guide-level explanation first and pick up this as soon as you finished. + +The high-level idea of previously talked _inline match resource_ is to let **loader developers** to customize the behavior of matching to match the pre-defined `module.rules`. It's an API to write composable loaders. But what does composition mean? For those users who are familiar with React hooks and Vue composable APIs, you may get this faster. Actually, webpack provides a lot of ways to help loader developers and users do the composition. + +#### User-defined loader flows + +```javascript +module.exports = { + module: { + rules: [ + { + test: /\.js$/, + use: ['babel-loader'], + type: 'javascript/auto', + }, + { + test: /\.svg$/, + use: ['svgr-loader', 'svgo-loader'], + }, + ], + }, +}; +``` + +Webpack users can take the advantage of `module.rules[number].use` with a loader list for each request that matches the corresponding conditions. Note that I use the wording of `request,` not the `file` , which can include a request to `data:text/javascript` not the files on the real file system only. (In Parcel bundler, it's called [_pipelines_](https://parceljs.org/features/plugins/#pipelines), but this will not be covered in this article.) + +Apparently, user-declared loader flow is not able to cover up every case that a loader wants. You can see from the previous examples, `vue-loader` wants to split a file into many blocks, and remain the reference to it. `svgr-loader` wants to do the transformation first and let other loaders deal with the `jsx`. `svg-loader` wants to use the internal ability of `Asset Module` to let Webpack decide whether an asset is inlined or emitted to the real file system. and there are more to come... Based on the complexity of the loader, Webpack also provides a syntax to allow loader implementors to do the composition by themselves. + +#### The syntax for loader composition + +##### Inline loader syntax (Chaining loaders) + +> Supported from _webpack v1_ [chaining-loaders](https://webpack.js.org/migrate/3/#chaining-loaders) +> +> It's possible to specify loaders in an `import` statement, or any [equivalent "importing" method](https://webpack.js.org/api/module-methods). Separate loaders from the resource with `!`. Each part is resolved relative to the current directory. [doc](https://webpack.js.org/concepts/loaders/#inline) + +```javascript +import Styles from '!style-loader!css-loader?modules!./styles.css'; +``` + +The _inline loader syntax_ executes each loader for each request from right to left. Webpack handles the interaction with user-defined loaders carefully. So by default, the user-defined normal loader will be executed prior to the inline loaders, you can disable this behavior by prefixing `!` , (full reference could be found here [doc](https://webpack.js.org/concepts/loaders/#inline)). + +The custom specifier is parsed before the `module.rules` as the _inline loader syntax_ interferes the user-defined loaders(See the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModuleFactory.js#L390-L403)). Then, webpack will get the `module.rules` combined with the required conditions to calculate the matching rule set (See the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModuleFactory.js#L493-L510)). + +At the moment, you cannot change the matching behavior with the syntax, loaders are always matched with the provided _resourcePath_, etc, which leads to a bunch of hack code in the implementations of loaders (see this [code snippet](https://github.com/vuejs/vue-loader/blob/e9314347d75a1b0e54f971272d23a669fc3e6965/src/select.ts#L31) in `vue-loader`). The possibilities for changing the matching behavior leaves to the later-coming _inline match resource_. + +Nevertheless, the architecture of Loader at this moment is sound and solid. Another good example is the implementation-nonrelative filter(i.e. the filtering logic of _Loader_ is not declared in the loader itself), which is the fundamental root of loader composition, or the implementor will do a lot of hacks. (It's way too dirty to talk about here, but you can take the rollup [svgr](https://github.com/gregberge/svgr/blob/1dbc3e2c2027253b3b81b92fd4eb09a4aa8ae25e/packages/rollup/src/index.ts#L52) plugin as a reference) + +In conclusion, _inline loader syntax_ gives us a chance to control the loader flow with user-defined rules. + +##### Inline match resource + +To extend the matching ability, _inline match resource_ enables loader implementors to reuse some of the user-defined configurations with more flexibilities. + +On top of the previous example, webpack also provides a way to make use of the natively-supported _module types_. + +```javascript +// For module type `css` to work, you need to enable `experiments.css` +import './style.less.webpack[css]!=path-to-less-loader!./style.less'; +``` + +```javascript +// webpack.config.js +module.exports = { + experiments: { + css: true, + }, +}; +``` + +Given the configuration above, the overview of the complete flow will be like this: + +1. Webpack: Parse the specifier of the import and create the loader for the current request +2. Webpack: Merge the result from the second step with a user-defined `module.rules` in `webpack.config`, in this case is `[]` +3. Webpack: load `style.less` as UTF-8 string +4. Less-loader: Accept the UTF-8 string as the first parameter of the loader function and transform it to the content of `css`. +5. Webpack: Call the registered native `CSS` parser, and later at the code generation step the registered native `CSS` generator generates the result. + +For _asset modules_, you can also use this: + +```javascript +import './logo.png.jpg.webpack[asset/resource]!=path-to-loaders!./logo.png'; +``` + +The first part, also known as `matchResource` will be used as a part of the `filename` of the final code generation. (See the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/asset/AssetGenerator.js#L293-L348)) + +### Performance optimizations + +Before moving on to the detailed implementations, here's some glossary to support your understanding the architecture as a whole. + +#### Glossary + +- `NormalModuleFactory`: A factory used to create a `NormalModule`, which basically exposes a `create` method. +- `NormalModule`: A module in Webpack most of the time is a `NormalModule`, but with different implementations of `parser`/ `generator` / `Module Type`, the module could be almost any kind, and also exposes a `build` method. For example, a `NormalModule` with JavaScript parser, JavaScript generator, and `type ===javascript/auto` will be regarded as a module with JavaScript-related functionalities. Also, good to note that a module may not exist on the real file system, taking `data:` for example. + +#### The module creation workflow + +> This will only introduce a slice of webpack's internal implementation from **the Loader's perspective**, for more you should directly refer to the source code. + +When an import statement is detected, webpack will initialize a module creation. Based on the type of _Dependency_ (an abstraction of webpack, it's not important here), webpack can find the linked _ModuleFactory_(The abstraction class), in most cases, the derived factory is `NormalModuleFactory`, which exposes a `create` method. + +##### Prepare data needed for module creation + +The `NormalModuleFactory#create` is used to provide enough information to create a real `NormalModule`, and create the `NormalModule`. In the `create` method, webpack basically does these things(some non-loader related stuff will be omitted): + +- Resolve loaders from request: resolve the request, parse inline loader syntax: This contains _inline match resource_, _inline loader syntax_. +- Do the analysis on the parsed loader syntax, to decide whether a user-defined `normal/post/pre` loader is going to be included. [doc](https://webpack.js.org/concepts/loaders/#inline) +- Resolve Resource: resolve resource to the absolute path, fragments, queries, etc(These stuff are also provided in `LoaderContext`). For the full source code you may refer to [this](https://github.com/webpack/webpack/blob/main/lib/NormalModuleFactory.js#L653-L678) +- Use the resolved resource data to match `module.rules` defined in the configuration, and get the matched rules. This is also a part of the module creation data. +- Do some special logic with _inline match resource_, since match resource ends like `.webpack[css]` would change `Rule.type`. Also store the match resource data, since it might affect the filename generation for _asset modules_. + +##### Create a module based on the prepared data + +After the data needed for module creation is prepared, `NormalModuleFactory` will `new NormalModule` with the data provided. It contains basically every that a `NormalModule` needs (see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L271-L287)). Most importantly, the `loaders`. It contains every loader parsed and ordered from the `create` step. + +#### The module build step + +The module build step is kind of clear. Webpack will invoke the `build` method for each `NormalModule` instance, which invokes `loader-runner`(see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L819)) to go through every loader that was analyzed from the create step. It's clear to **know that the composition of loaders is happening on the same module**. + +#### A peek of the support of _Module Types_ + +As far as this article goes, It might be getting a little bit tedious. But have you ever wondered how webpack supports these _module types_ natively? I think It's still worth telling you about it to get a more complete understanding of the AST optimizations. For the support of JavaScript, webpack's JavaScript plugin will register different types of parser and generators for each _module types_, which will be used as the `parser` / `generator` to a `NormalModule` (see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/javascript/JavascriptModulesPlugin.js#L202-L231)). + +#### Reusing AST in Webpack + +Based on the parser and generator we introduced before, webpack did a little hack around the fourth parameter of `this.callback` (from _loaderContext_), with `webpackAST`, after each loader call, the `webpackAST` will be stored in the context of loader, and passed again to the next loader. Finally, the AST will be passed to the `parser`(It could be any type, based on the _module type_, but webpack makes it a JavaScript only for AST) (see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L1087)). + +Here's an issue about trying to use SWC 's AST to get rid of the time sensitive code parsing from Acorn Parser, but they are facing some AST compatibility issues and performance issues about the overhead of interop with native code(Rust). + +## References + +- loader plugin api design (Analysis) [#315](https://github.com/speedy-js/rspack/discussions/315) + +- RFC-011 Supports `data:text/javascript` protocol [#457](https://github.com/speedy-js/rspack/discussions/457) + +- Webpack: `matchResource` with natively-supported module types [doc](https://webpack.js.org/api/loaders/#thisimportmodule) + +- Webpack: Loader context [doc](https://webpack.js.org/api/loaders/#the-loader-context) + +- Webpack: Module rules [doc](https://webpack.js.org/configuration/module/#rule) + +- SWC-loader for performance optimizations [issue](https://github.com/webpack/webpack/issues/13425#issuecomment-1013560170) diff --git a/website/docs/en/contribute/workflows/meetings.md b/website/docs/en/contribute/workflows/meetings.md new file mode 100644 index 000000000000..b8cfa9cbb54d --- /dev/null +++ b/website/docs/en/contribute/workflows/meetings.md @@ -0,0 +1,9 @@ +# Meetings + +## Tuesday meeting + +1. Go through the [iteration plan](https://github.com/web-infra-dev/rspack/milestones) + +## Thursday meeting + +1. Go through any topics that need [to be discussed](https://github.com/web-infra-dev/rspack/issues?q=is%3Aopen+label%3A%22to+be+discussed%22+sort%3Aupdated-desc) diff --git a/website/docs/en/contribute/workflows/misc.md b/website/docs/en/contribute/workflows/misc.md new file mode 100644 index 000000000000..c1ac3ff74b72 --- /dev/null +++ b/website/docs/en/contribute/workflows/misc.md @@ -0,0 +1,9 @@ +# Misc + +## "need documentation" label + +This is used for reminding ourselves to update the Rspack website for a new feature. + +When a PR is merged with the "need documentation" label, +[rspack-bot](https://github.com/rspack-bot) will create a corresponding PR +in the [rspack-website](https://github.com/web-infra-dev/rspack-website) repo. diff --git a/website/docs/en/contribute/workflows/releases.md b/website/docs/en/contribute/workflows/releases.md new file mode 100644 index 000000000000..e3cc252c4977 --- /dev/null +++ b/website/docs/en/contribute/workflows/releases.md @@ -0,0 +1,19 @@ +# Releases + +- `0.1.0` -> `0.1.1` is a patch release. + +- `0.1.0` -> `0.2.0` is a minor release. + +- `0.1.0` -> `1.0.0` is a major release. + +See details at [semver.org](https://semver.org/) + +## Release Cycle + +- Patch releases are released Tuesday per week. + +- Minor releases are released as needed. + +- Major releases are released as needed. + +See [milestones](https://github.com/web-infra-dev/rspack/milestones?direction=asc&sort=title&state=open) to follow our release plan. diff --git a/website/project-words.txt b/website/project-words.txt index de1276fad4bf..4783a036a874 100644 --- a/website/project-words.txt +++ b/website/project-words.txt @@ -1,6 +1,8 @@ +aarch ahabhgk alexander-akait analysable +ansi antd ɑrespæk behaviour @@ -16,11 +18,14 @@ bvanjoi chakra chenjiahan commmonjs +cpuprofile cssextractrspackplugin +darwin devongovett devserverhot dhruvkelawala disabletransformbydefault +ecma edusperoni esbuild evanw @@ -43,9 +48,13 @@ jantimon JavaScript jerrykingxyz jkzing +JSCPU jscpuprofile lingyucoder +linux lippzhang +lldb +LLDB magic-akari memfs modulegeneratorassetdataurl @@ -63,9 +72,11 @@ moduleparsercssauto moduleparsercssautonamedexports moduleparsercssmodule monaco +msvc myorg myrspackapp mysecretkey +napi NAPI NAPI-RS nativizing @@ -96,6 +107,7 @@ Rspress ruleoneof ruleparserdataurlcondition Rust +rustup sanyuan Shenzhen sockjs @@ -103,6 +115,7 @@ sokra solidjs spdy statoscope +struct suxin2017 svgr swccssminimizerplugin @@ -113,6 +126,7 @@ swcpack tailwind tailwindcss Terser +tokio tuchg typeofs TypeScript @@ -122,6 +136,9 @@ vant viktoriialurie weapp Webpack +xcode +xcrun +xctrace Xeon XKKCNZZNJD xstyled diff --git a/website/rspress.config.ts b/website/rspress.config.ts index de5e75a35586..fedeb24ae904 100644 --- a/website/rspress.config.ts +++ b/website/rspress.config.ts @@ -22,6 +22,7 @@ export default defineConfig({ globalStyles: path.join(__dirname, 'theme', 'index.css'), markdown: { checkDeadLinks: true, + highlightLanguages: [['rs', 'rust']], }, route: { cleanUrls: true, diff --git a/website/sortProjectWords.js b/website/sortProjectWords.js new file mode 100644 index 000000000000..433411aafdc5 --- /dev/null +++ b/website/sortProjectWords.js @@ -0,0 +1,9 @@ +const fs = require('fs'); +const words = fs + .readFileSync('./project-words.txt', { encoding: 'utf-8' }) + .split('\n') + .filter(Boolean); + +const sortedWords = words.sort((a, b) => a.localeCompare(b)); + +fs.writeFileSync('./project-words.txt', sortedWords.join('\n') + '\n'); From 8b712b129851afcb058df5868adc101ed5a43cd4 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 13 May 2024 18:59:35 +0800 Subject: [PATCH 061/107] docs: reorganize the structure of dev guide (#6518) * docs: reorganize the structure of dev guide * docs: remove webpack related doc --- website/docs/en/contribute/_meta.json | 62 +- .../en/contribute/architecture/_meta.json | 1 + .../builtin-plugin.md} | 2 +- .../rspack-loader.md} | 2 +- .../docs/en/contribute/building/_meta.json | 1 - .../docs/en/contribute/debugging/mix-debug.md | 111 --- .../docs/en/contribute/development/_meta.json | 1 + .../building.md} | 4 +- .../contribute/{ => development}/debugging.md | 112 +++ .../prerequisites.md | 0 .../contribute/{ => development}/profiling.md | 0 .../contribute/{ => development}/releasing.md | 0 .../contribute/{ => development}/testing.md | 82 ++ website/docs/en/contribute/index.mdx | 59 +- website/docs/en/contribute/repro.md | 16 - website/docs/en/contribute/rspack.md | 8 - website/docs/en/contribute/sending-pr.md | 39 - website/docs/en/contribute/testing/e2e.md | 81 -- website/docs/en/contribute/webpack.md | 8 - .../docs/en/contribute/webpack/dependency.md | 571 ------------- website/docs/en/contribute/webpack/loader.md | 783 ------------------ .../docs/en/contribute/workflows/meetings.md | 9 - website/docs/en/contribute/workflows/misc.md | 9 - .../docs/en/contribute/workflows/releases.md | 19 - 24 files changed, 261 insertions(+), 1719 deletions(-) create mode 100644 website/docs/en/contribute/architecture/_meta.json rename website/docs/en/contribute/{rspack/plugin.md => architecture/builtin-plugin.md} (98%) rename website/docs/en/contribute/{rspack/loader.md => architecture/rspack-loader.md} (99%) delete mode 100644 website/docs/en/contribute/building/_meta.json delete mode 100644 website/docs/en/contribute/debugging/mix-debug.md create mode 100644 website/docs/en/contribute/development/_meta.json rename website/docs/en/contribute/{building/build-and-run.md => development/building.md} (80%) rename website/docs/en/contribute/{ => development}/debugging.md (58%) rename website/docs/en/contribute/{building => development}/prerequisites.md (100%) rename website/docs/en/contribute/{ => development}/profiling.md (100%) rename website/docs/en/contribute/{ => development}/releasing.md (100%) rename website/docs/en/contribute/{ => development}/testing.md (55%) delete mode 100644 website/docs/en/contribute/repro.md delete mode 100644 website/docs/en/contribute/rspack.md delete mode 100644 website/docs/en/contribute/sending-pr.md delete mode 100644 website/docs/en/contribute/testing/e2e.md delete mode 100644 website/docs/en/contribute/webpack.md delete mode 100644 website/docs/en/contribute/webpack/dependency.md delete mode 100644 website/docs/en/contribute/webpack/loader.md delete mode 100644 website/docs/en/contribute/workflows/meetings.md delete mode 100644 website/docs/en/contribute/workflows/misc.md delete mode 100644 website/docs/en/contribute/workflows/releases.md diff --git a/website/docs/en/contribute/_meta.json b/website/docs/en/contribute/_meta.json index 5eef3afaddc6..3b29e61c3dcd 100644 --- a/website/docs/en/contribute/_meta.json +++ b/website/docs/en/contribute/_meta.json @@ -1,69 +1,13 @@ [ "index", - { - "type": "divider" - }, - { - "type": "section-header", - "label": "Development" - }, - { - "type": "dir", - "name": "building", - "label": "Building and running" - }, { "type": "dir", - "name": "testing", - "label": "Testing" + "name": "development", + "label": "Development" }, { "type": "dir", - "name": "debugging", - "label": "Debugging" - }, - { - "type": "file", - "name": "profiling", - "label": "Profiling" - }, - { - "type": "file", - "name": "releasing", - "label": "Releasing" - }, - { - "type": "divider" - }, - { - "type": "section-header", - "label": "Contribution" - }, - { - "type": "file", - "label": "Sending a Pull Request", - "name": "sending-pr" - }, - { - "type": "file", - "label": "Minimal reproducible example", - "name": "repro" - }, - { - "type": "divider" - }, - { - "type": "section-header", + "name": "architecture", "label": "Architecture" - }, - { - "type": "dir", - "label": "Rspack", - "name": "rspack" - }, - { - "type": "dir", - "label": "Webpack", - "name": "webpack" } ] diff --git a/website/docs/en/contribute/architecture/_meta.json b/website/docs/en/contribute/architecture/_meta.json new file mode 100644 index 000000000000..e4a3fe0cabda --- /dev/null +++ b/website/docs/en/contribute/architecture/_meta.json @@ -0,0 +1 @@ +["builtin-plugin", "rspack-loader"] diff --git a/website/docs/en/contribute/rspack/plugin.md b/website/docs/en/contribute/architecture/builtin-plugin.md similarity index 98% rename from website/docs/en/contribute/rspack/plugin.md rename to website/docs/en/contribute/architecture/builtin-plugin.md index 7edef4d59caf..87f7e47fb86c 100644 --- a/website/docs/en/contribute/rspack/plugin.md +++ b/website/docs/en/contribute/architecture/builtin-plugin.md @@ -1,4 +1,4 @@ -# How to write a builtin plugin +# Builtin Plugin Builtin plugin uses [rspack_macros](https://github.com/web-infra-dev/rspack/tree/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_macros) to help you avoid writing boilerplate code, you can use [cargo-expand](https://github.com/dtolnay/cargo-expand) or [rust-analyzer expand macro](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to checkout the expanded code, and for developing/testing these macro, you can starts with [rspack_macros_test](https://github.com/web-infra-dev/rspack/tree/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_macros_test). diff --git a/website/docs/en/contribute/rspack/loader.md b/website/docs/en/contribute/architecture/rspack-loader.md similarity index 99% rename from website/docs/en/contribute/rspack/loader.md rename to website/docs/en/contribute/architecture/rspack-loader.md index d59e4cf241a8..7b9f47e96954 100644 --- a/website/docs/en/contribute/rspack/loader.md +++ b/website/docs/en/contribute/architecture/rspack-loader.md @@ -1,4 +1,4 @@ -# Loader +# Rspack Loader ## Related PRs diff --git a/website/docs/en/contribute/building/_meta.json b/website/docs/en/contribute/building/_meta.json deleted file mode 100644 index d6775ac45608..000000000000 --- a/website/docs/en/contribute/building/_meta.json +++ /dev/null @@ -1 +0,0 @@ -["prerequisites", "build-and-run"] diff --git a/website/docs/en/contribute/debugging/mix-debug.md b/website/docs/en/contribute/debugging/mix-debug.md deleted file mode 100644 index 6e27d79255c1..000000000000 --- a/website/docs/en/contribute/debugging/mix-debug.md +++ /dev/null @@ -1,111 +0,0 @@ -# Mixed Debugging Between JavaScript and Rust - -This discussion aims to illustrate the method for mixed debugging between JavaScript and Rust. - -## Prerequisites - -To illustrate this process, I'll use an example. Let's start by introduce the environment and example I have used. - -- System: macos -- IDE: vscode -- Debugging target: `rspack build ${projectRoot}/basic` - -Firstly, you need to build rspack in debug mode. To do this, execute the following commands in the project's root directory: - -```bash -npm run build:binding:debug -npm run build:js -``` - -## Configure `launch.json` in vscode - -It's necessary to configure two debug configurations within in `.vscode/launch.json.` - -- attach for node: - -```jsonc -{ - "name": "attach:node”, - "request": "attach", // refer: https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations - "type": "node", - // `9229` is the default port of message - "port": 9229 -} -``` - -- and launch for lldb - -```jsonc -{ - "name": "launch:rust-from-node", - "request": "launch”, - "type": "lldb", // it means we use `lldb` to launch the binary file of `node` - "program": "node”, - "args": [ - "--inspect", - "--enable-source-maps", - "${workspaceFolder}/packages/rspack-cli/bin/rspack", - "build", - "-c", - "${workspaceFolder}/examples/basic/rspack.config.js", - ], - // `cwd` is just for repack find the correctly entry. - "cwd": "${workspaceFolder}/examples/basic/" -} -``` - -Next, we can utilize [compounds](https://code.visualstudio.com/docs/editor/debugging#_compound-launch-configurations) to amalgamate the two commands: - -```json -{ - "name": "mix-debug", - "configurations": ["attach:node", "launch:rust-from-node"] -} -``` - -Finally, your `launch.json` should appear as follows: - -```json -{ - "configurations": [ - { - "name": "attach:node", - "request": "attach", - "type": "node", - "port": 9229 - }, - { - "name": "launch:rust-from-node", - "request": "launch", - "type": "lldb", - "program": "node", - "args": [ - "--inspect", - "--enable-source-maps", - "${workspaceFolder}/packages/rspack-cli/bin/rspack", - "build", - "-c", - "${workspaceFolder}/examples/basic/rspack.config.js" - ], - "cwd": "${workspaceFolder}/examples/basic/" - } - ], - "compounds": [ - { - "name": "mix-debug", - "configurations": ["attach:node", "launch:rust-from-node"] - } - ] -} -``` - -## Debugging Attempt - -Next, we can introduce some breakpoints and commence debugging. - -The result appears as follows: - - diff --git a/website/docs/en/contribute/development/_meta.json b/website/docs/en/contribute/development/_meta.json new file mode 100644 index 000000000000..148d67a6f179 --- /dev/null +++ b/website/docs/en/contribute/development/_meta.json @@ -0,0 +1 @@ +["prerequisites", "building", "testing", "debugging", "profiling", "releasing"] diff --git a/website/docs/en/contribute/building/build-and-run.md b/website/docs/en/contribute/development/building.md similarity index 80% rename from website/docs/en/contribute/building/build-and-run.md rename to website/docs/en/contribute/development/building.md index 28a9051597bb..012d92dfd752 100644 --- a/website/docs/en/contribute/building/build-and-run.md +++ b/website/docs/en/contribute/development/building.md @@ -1,6 +1,6 @@ -# How to build and run the compiler +# Building -Please see [prerequisites](./prerequisites.md) for setting up Rust and Node.js. +Please see [prerequisites](./prerequisites) for setting up Rust and Node.js. ## Install Node.js dependencies diff --git a/website/docs/en/contribute/debugging.md b/website/docs/en/contribute/development/debugging.md similarity index 58% rename from website/docs/en/contribute/debugging.md rename to website/docs/en/contribute/development/debugging.md index 21721f00e2b6..60aa89f661b1 100644 --- a/website/docs/en/contribute/debugging.md +++ b/website/docs/en/contribute/development/debugging.md @@ -88,3 +88,115 @@ Process 23110 stopped 247 Target 0: (node) stopped. ``` + +## Mixed Debug + +This section aims to illustrate the method for mixed debugging between JavaScript and Rust. + +### Prerequisites + +To illustrate this process, I'll use an example. Let's start by introduce the environment and example I have used. + +- System: macos +- IDE: vscode +- Debugging target: `rspack build ${projectRoot}/basic` + +Firstly, you need to build rspack in debug mode. To do this, execute the following commands in the project's root directory: + +```bash +npm run build:binding:debug +npm run build:js +``` + +### Configure `launch.json` in vscode + +It's necessary to configure two debug configurations within in `.vscode/launch.json.` + +- attach for node: + +```jsonc +{ + "name": "attach:node”, + "request": "attach", // refer: https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations + "type": "node", + // `9229` is the default port of message + "port": 9229 +} +``` + +- and launch for lldb + +```jsonc +{ + "name": "launch:rust-from-node", + "request": "launch”, + "type": "lldb", // it means we use `lldb` to launch the binary file of `node` + "program": "node”, + "args": [ + "--inspect", + "--enable-source-maps", + "${workspaceFolder}/packages/rspack-cli/bin/rspack", + "build", + "-c", + "${workspaceFolder}/examples/basic/rspack.config.js", + ], + // `cwd` is just for repack find the correctly entry. + "cwd": "${workspaceFolder}/examples/basic/" +} +``` + +Next, we can utilize [compounds](https://code.visualstudio.com/docs/editor/debugging#_compound-launch-configurations) to amalgamate the two commands: + +```json +{ + "name": "mix-debug", + "configurations": ["attach:node", "launch:rust-from-node"] +} +``` + +Finally, your `launch.json` should appear as follows: + +```json +{ + "configurations": [ + { + "name": "attach:node", + "request": "attach", + "type": "node", + "port": 9229 + }, + { + "name": "launch:rust-from-node", + "request": "launch", + "type": "lldb", + "program": "node", + "args": [ + "--inspect", + "--enable-source-maps", + "${workspaceFolder}/packages/rspack-cli/bin/rspack", + "build", + "-c", + "${workspaceFolder}/examples/basic/rspack.config.js" + ], + "cwd": "${workspaceFolder}/examples/basic/" + } + ], + "compounds": [ + { + "name": "mix-debug", + "configurations": ["attach:node", "launch:rust-from-node"] + } + ] +} +``` + +### Debugging Attempt + +Next, we can introduce some breakpoints and commence debugging. + +The result appears as follows: + + diff --git a/website/docs/en/contribute/building/prerequisites.md b/website/docs/en/contribute/development/prerequisites.md similarity index 100% rename from website/docs/en/contribute/building/prerequisites.md rename to website/docs/en/contribute/development/prerequisites.md diff --git a/website/docs/en/contribute/profiling.md b/website/docs/en/contribute/development/profiling.md similarity index 100% rename from website/docs/en/contribute/profiling.md rename to website/docs/en/contribute/development/profiling.md diff --git a/website/docs/en/contribute/releasing.md b/website/docs/en/contribute/development/releasing.md similarity index 100% rename from website/docs/en/contribute/releasing.md rename to website/docs/en/contribute/development/releasing.md diff --git a/website/docs/en/contribute/testing.md b/website/docs/en/contribute/development/testing.md similarity index 55% rename from website/docs/en/contribute/testing.md rename to website/docs/en/contribute/development/testing.md index 69186ac499ca..675ab1b5b9ea 100644 --- a/website/docs/en/contribute/testing.md +++ b/website/docs/en/contribute/development/testing.md @@ -65,3 +65,85 @@ Cases are used to test custom build behavior, you could use custom `webpack.conf ##### statsTestCase.test.ts Cases are used to test your stats, By Default we will use jest's snapshot to snapshot your stats, and we **highly** recommend to **avoid** snapshot except statsCase. you can use statsCase to test behaviors like code splitting | bundle splitting, which is hard to test by just running code. + +## E2E + +The `packages/playground` provides e2e testing feature. We use [playwright](https://github.com/Microsoft/playwright) as the e2e testing framework. + +### Cases + +The entry point of a test case is a file ending with `.test.ts`, and the parent directory of this file is the project directory. + +Here are some rules about test cases: + +- The project directory must contain `rspack.config.js` to start the dev server. +- The project directory can contain multi `*.test.ts`. +- All test cases share dependencies, so just add dependencies in `packages/playground/package.json`. +- The cases folder should contain the category folders and then is the project folders. In principle, there should be no third-level directory. + +### Fixtures + +The `fixtures` is a feature of playwright, in short it provides a variable that is generated in before{Each|All} and destroyed in after{Each|All}. More information see [test-fixtures](https://playwright.dev/docs/test-fixtures) + +Here are some rules when defining a new fixture: + +- Private fixtures should start with `_` and are used only in the current file. +- A file only provides fixtures with the same name. +- A file can only provide one option and starts with `default` +- Register fixtures in `fixtures/index.ts` and export only necessary variables and types. + +Here are some existing fixtures: + +#### pathInfo + +This fixture will generate test environment, and calculate the PathInfo. + +```ts +type PathInfo = { + // test file path + testFile: string; + // project dir + testProjectDir: string; + // temporary project directory to be copied into + tempProjectDir: string; +}; +``` + +#### rspack + +This fixture will start the rspack dev server and provide some useful methods. + +```ts +type Rspack = { + // rspack running project directory + projectDir: string; + // rspack compiler + compiler: Compiler; + // rspack dev server + devServer: DevServer; + // waiting for rspack build finish + waitingForBuild: () => Promise; + // waiting for hmr finish, the poll function is used to check + waitingForHmr: (poll: () => Promise) => Promise; +}; +``` + +#### fileAction + +This fixture will provide file change operations. + +```ts +type fileAction = { + updateFile(relativePath: string, fn: (content: string) => string): void; + deleteFile(relativePath: string): void; +}; +``` + +### How it works + +- playwright scan all test case and allocates a worker to run each case. +- `pathInfo` copy the project directory corresponding to the current case to `temp/${worker_index}`. +- `rspack` rewrite dev server port to `8000 + worker_index` and start compiler and dev server in `temp/${worker_index}`. +- run current tests. +- `rspack` close dev server and compiler. +- `pathInfo` clear `temp/${worker_index}` diff --git a/website/docs/en/contribute/index.mdx b/website/docs/en/contribute/index.mdx index 61e040f90fc5..2f98f9a399a5 100644 --- a/website/docs/en/contribute/index.mdx +++ b/website/docs/en/contribute/index.mdx @@ -1,4 +1,4 @@ -# Getting Stated +# Overview We are grateful for your interest in contributing to Rspack! Every single contribution counts and helps us take Rspack to the next level. @@ -8,6 +8,23 @@ Every single contribution counts and helps us take Rspack to the next level. If you have any questions, please do not hesitate to ask in either the [Discord](https://discord.gg/79ZZ66GH9E) support channel or on the [Github discussion board](https://github.com/web-infra-dev/rspack/discussions). +## Minimal reproduction + +The [rspack repro template](https://github.com/web-infra-dev/rspack-repro) can be used to create a minimal reproducible example. + +A minimal reproducible example (MRE) is a code that is: + +- Short +- Self-contained +- Demonstrates the problem being encountered + +An MRE is essential because it allows us to quickly understand and reproduce your issue. +This, in turn, increases the likelihood of getting a helpful and accurate response in a shorter amount of time. +It is important to note that an MRE should not include extraneous code related to unrelated functionality, +and should instead focus solely on the problem at hand. + +Please see also [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) from Stack Overflow. + ## What should I work on? ### Good First Issue @@ -22,6 +39,46 @@ If you are interested in understanding our project's direction and want to work our [tracking issues list](https://github.com/web-infra-dev/rspack/issues?q=is%3Aopen+label%3A%22tracking+issue%22+sort%3Aupdated-desc) provides an overview of our progress and current goals. +## Sending pull request + +1. [Fork](https://help.github.com/articles/fork-a-repo/) the Rspack repository into your own GitHub account. +2. [Clone](https://help.github.com/articles/cloning-a-repository/) the repository to your local. +3. Checkout a new branch from `main`. +4. Set up the development environment, you can read the "Setup Development Environment" section below to learn about it. +5. If you've fixed a bug or added code that should be tested, then add some tests. +6. Make sure all the tests pass, you can read the "Testing" section below to learn about it. +7. Run `pnpm run lint:js` and `pnpm run lint:rs` to check the code style. +8. If you've changed some Node.js packages, you should add a new [changeset](https://github.com/changesets/changesets). Run `pnpm run changeset`, select the changed packages and add the changeset info. +9. If you've changed some Rust packages, you should add a new [changeset](https://github.com/changesets/changesets) for `@rspack/binding` package. +10. Submit the Pull Request, make sure all CI runs pass. +11. The maintainers will review your Pull Request soon. + +When submitting a Pull Request, please note the following: + +- Keep your PRs small enough, so that each PR only addresses a single issue or adds a single feature. +- Please include an appropriate description in the PR, and link related issues. + +### Format of PR titles + +The format of PR titles follow Conventional Commits. + +A example + +``` +feat(ui): Add `Button` component +^ ^ ^ +| | |__ Subject +| |_______ Scope +|____________ Type +``` + +Your PR + +- must have a `Type` +- Optionally have a `Scope` + - `Scope` should be lower case +- must have a `Subject` + ## Other ways to contribute We are always looking for contributors, and that goes beyond just our main repository. diff --git a/website/docs/en/contribute/repro.md b/website/docs/en/contribute/repro.md deleted file mode 100644 index 0bb657b64dd8..000000000000 --- a/website/docs/en/contribute/repro.md +++ /dev/null @@ -1,16 +0,0 @@ -# Minimal reproducible example - -The [rspack repro template](https://github.com/web-infra-dev/rspack-repro) can be used to create a minimal reproducible example. - -A minimal reproducible example (MRE) is a code that is: - -- Short -- Self-contained -- Demonstrates the problem being encountered - -An MRE is essential because it allows us to quickly understand and reproduce your issue. -This, in turn, increases the likelihood of getting a helpful and accurate response in a shorter amount of time. -It is important to note that an MRE should not include extraneous code related to unrelated functionality, -and should instead focus solely on the problem at hand. - -Please see also [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) from Stackoverflow. diff --git a/website/docs/en/contribute/rspack.md b/website/docs/en/contribute/rspack.md deleted file mode 100644 index 1381652dd175..000000000000 --- a/website/docs/en/contribute/rspack.md +++ /dev/null @@ -1,8 +0,0 @@ -# rspack - -This is the architecture of current rspack implementation - -# Table of Contents - -- [loader](./rspack/loader.md) -- [plugin](./rspack/plugin.md) diff --git a/website/docs/en/contribute/sending-pr.md b/website/docs/en/contribute/sending-pr.md deleted file mode 100644 index 6429173cf40e..000000000000 --- a/website/docs/en/contribute/sending-pr.md +++ /dev/null @@ -1,39 +0,0 @@ -# Sending a Pull Request - -1. [Fork](https://help.github.com/articles/fork-a-repo/) the Rspack repository into your own GitHub account. -2. [Clone](https://help.github.com/articles/cloning-a-repository/) the repository to your local. -3. Checkout a new branch from `main`. -4. Set up the development environment, you can read the "Setup Development Environment" section below to learn about it. -5. If you've fixed a bug or added code that should be tested, then add some tests. -6. Make sure all the tests pass, you can read the "Testing" section below to learn about it. -7. Run `pnpm run lint:js` and `pnpm run lint:rs` to check the code style. -8. If you've changed some Node.js packages, you should add a new [changeset](https://github.com/changesets/changesets). Run `pnpm run changeset`, select the changed packages and add the changeset info. -9. If you've changed some Rust packages, you should add a new [changeset](https://github.com/changesets/changesets) for `@rspack/binding` package. -10. Submit the Pull Request, make sure all CI runs pass. -11. The maintainers will review your Pull Request soon. - -When submitting a Pull Request, please note the following: - -- Keep your PRs small enough, so that each PR only addresses a single issue or adds a single feature. -- Please include an appropriate description in the PR, and link related issues. - -## Format of PR titles - -The format of PR titles follow Conventional Commits. - -A example - -``` -feat(ui): Add `Button` component -^ ^ ^ -| | |__ Subject -| |_______ Scope -|____________ Type -``` - -Your PR - -- must have a `Type` -- Optionally have a `Scope` - - `Scope` should be lower case -- must have a `Subject` diff --git a/website/docs/en/contribute/testing/e2e.md b/website/docs/en/contribute/testing/e2e.md deleted file mode 100644 index dad8aa5efe9f..000000000000 --- a/website/docs/en/contribute/testing/e2e.md +++ /dev/null @@ -1,81 +0,0 @@ -# E2E - -The `packages/playground` provides e2e testing feature. We use [playwright](https://github.com/Microsoft/playwright) as the e2e testing framework. - -## Cases - -The entry point of a test case is a file ending with `.test.ts`, and the parent directory of this file is the project directory. - -Here are some rules about test cases: - -- The project directory must contain `rspack.config.js` to start the dev server. -- The project directory can contain multi `*.test.ts`. -- All test cases share dependencies, so just add dependencies in `packages/playground/package.json`. -- The cases folder should contain the category folders and then is the project folders. In principle, there should be no third-level directory. - -## Fixtures - -The `fixtures` is a feature of playwright, in short it provides a variable that is generated in before{Each|All} and destroyed in after{Each|All}. More information see [test-fixtures](https://playwright.dev/docs/test-fixtures) - -Here are some rules when defining a new fixture: - -- Private fixtures should start with `_` and are used only in the current file. -- A file only provides fixtures with the same name. -- A file can only provide one option and starts with `default` -- Register fixtures in `fixtures/index.ts` and export only necessary variables and types. - -Here are some existing fixtures: - -#### pathInfo - -This fixture will generate test environment, and calculate the PathInfo. - -```ts -type PathInfo = { - // test file path - testFile: string; - // project dir - testProjectDir: string; - // temporary project directory to be copied into - tempProjectDir: string; -}; -``` - -#### rspack - -This fixture will start the rspack dev server and provide some useful methods. - -```ts -type Rspack = { - // rspack running project directory - projectDir: string; - // rspack compiler - compiler: Compiler; - // rspack dev server - devServer: DevServer; - // waiting for rspack build finish - waitingForBuild: () => Promise; - // waiting for hmr finish, the poll function is used to check - waitingForHmr: (poll: () => Promise) => Promise; -}; -``` - -#### fileAction - -This fixture will provide file change operations. - -```ts -type fileAction = { - updateFile(relativePath: string, fn: (content: string) => string): void; - deleteFile(relativePath: string): void; -}; -``` - -## How it works - -- playwright scan all test case and allocates a worker to run each case. -- `pathInfo` copy the project directory corresponding to the current case to `temp/${worker_index}`. -- `rspack` rewrite dev server port to `8000 + worker_index` and start compiler and dev server in `temp/${worker_index}`. -- run current tests. -- `rspack` close dev server and compiler. -- `pathInfo` clear `temp/${worker_index}` diff --git a/website/docs/en/contribute/webpack.md b/website/docs/en/contribute/webpack.md deleted file mode 100644 index b194b8067535..000000000000 --- a/website/docs/en/contribute/webpack.md +++ /dev/null @@ -1,8 +0,0 @@ -# Webpack - -This is the architecture of webpack implementation - -# Table of Contents - -- [loader](./webpack/loader.md) -- [dependency](./webpack/dependency.md) diff --git a/website/docs/en/contribute/webpack/dependency.md b/website/docs/en/contribute/webpack/dependency.md deleted file mode 100644 index 620b2f0c4e58..000000000000 --- a/website/docs/en/contribute/webpack/dependency.md +++ /dev/null @@ -1,571 +0,0 @@ -> Based on _Webpack version: 5.73.0_. -> Some source code is omitted for cleaner demonstration in the example. - -# Dependency - -Explain how webpack dependency affects the compilation and what kind of problem that webpack was facing at the moment and the solution to the problem. - -## Glossary - -> What's the meaning of a word used to describe a feature? -> -> Why does the Webpack introduce this and what's the background of introducing this? What kind of problem Webpack was facing at the time? - -### High-level presentations of _Dependencies_ - -- [Dependency(fileDependency)](https://webpack.js.org/api/loaders/#thisadddependency): An existing dependency that is marked as watchable. This is the widely-used type of dependency. CSS Preprocessors like `postcss` strongly depend on this in order to mark its dependency watchable. -- [ContextDependency](https://webpack.js.org/api/loaders/#thisaddcontextdependency): Most useful for requests in which Glob and Regexp were used. For real-world usage, see [[this](https://webpack.js.org/guides/dependency-management/#require-with-expression)](https://webpack.js.org/guides/dependency-management/#require-with-expression). -- [MissingDependency](https://webpack.js.org/api/loaders/#thisaddmissingdependency): A missing dependency to mark it watchable (handles the creation of files during compilation before watchers are attached correctly.) -- [BuildDependency](https://webpack.js.org/configuration/cache/#cachebuilddependencies): Related to persistent cache. -- PresentationalDependency: Dependencies that only affect presentation are mostly used with their associated template. - -### Others - -- [LoaderContext](https://webpack.js.org/api/loaders/#the-loader-context): Context provided by Webpack _loader-runner_, which can be accessed through `this` in each loader function. -- ModuleGraph: A graph to describe the relationship between modules. - -## Guide-level explanation - -### `Dependency` - -`dependency`(`fileDependency`) stands for the file _dependency_ among `missingDependency` and `contextDependency`, etc. The created dependency will be marked as watchable, which is useful in _Hot Module Replacement_ in developer mode. - -The implicit behavior for webpack internally in the case below is to create two dependencies internally. - -```js -import foo from './foo'; -import './style.css'; -``` - -### `ContextDependency` - -`contextDependency` is mostly used in scenarios where we want to dynamic load some module in runtime. In this case, webpack cannot assure which module it will be included in the final bundle at compile time. In order to make the code runnable in runtime, webpack has to firstly create multiple bundle modules corresponding to the matching filename such as `./components/a.js` and `./components/b.js`, etc. - -```js -// index.js -import("./components" + componentName).then(...) -``` - -```js -// components/a.js -... -export default ComponentA; -``` - -```js -// components/b.js -... -export default ComponentB; -``` - -For loaders, you can access to `this.addContextDependency` in each loader function. -For plugins, you can access via `module.buildInfo.contextDependencies`. - -## Reference-level explanation - -> The abstraction of _Dependency_ of Webpack was introduced in Webpack version 0.9 with a big refactor. [Redirect to the commit](https://github.com/webpack/webpack/commit/ee01837d66a44f1dd52fd1e174a6669e0d18dd55) - -### Stakeholders of _Dependency_ - -#### High-level - -![image-20220919171608629](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663578968.png) - -#### Low-level - -![image-20220919171841624](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663579121.png) - -### How _dependencies_ affect the creation of _module graph_? - -#### Duplicated module detection - -Each module will have its own `identifier`, for `NormalModule`, you can find this in `NormalModule#identifier`. If the identifier will be duplicated if inserted in `this._module`, then webpack will directly skip the remaining build process. [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L1270-L1274) - -Basically, an `NormalModule` identifier contains these parts: - -1. `type` \[`string`\]: The module type of a module. If the type of the module is `javascript/auto`, this field can be omitted -2. `request` \[`string`\]: Request to the module. All loaders whether it's inline or matched by a config will be stringified. If _inline match resource_ exists, inline loaders will be executed before any normal-loaders after pre-loaders. A module with a different loader passed through will be treated as a different module regardless of its path. -3. `layer`: applied if provided - -#### Module resolution - -`getResolve` is a loader API on the `LoaderContext`. Loader developers can pass `dependencyType` to its `option` which indicates the category of the module dependency that will be created. Values like `esm` can be passed, then webpack will use type `esm` to resolve the dependency. - -The resolved dependencies are automatically added to the current module. This is driven by the internal plugin system of `enhanced-resolve`. Internally, `enhanced-resolve` uses plugins to handle the dependency registration like `FileExistsPlugin` [\[source\]](https://github.com/webpack/enhanced-resolve/blob/e5ff68aef5ab43b8197e864181eda3912957c526/lib/FileExistsPlugin.js#L34-L54) to detect whether a file is located on the file system or will add this file to a list of `missingDependency` and report in respect of the running mode of webpack. The collecting end of Webpack is generated by the `getResolveContext` in `NormalModule` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L513-L524) - -#### _Module dependency_ in _ModuleGraph_ - -Here's a module graph with `esm` import between modules: - -![image-20220919172119861](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663579279.png) - -The dependency type introduced by `import` or `require` is a derived dependency: _ModuleDependency_. - -A _ModuleDependency_ contains three important fields. - -1. `category`: used to describe the category of dependency. e.g. "esm" | "commonjs" -2. `request`: see the explanation above. -3. `userRequest`: Resource and its inline loader syntax will be stringified and applied, but loaders in `module.rules` will be omitted. - -It's also good to note a field we will talk about later: - -1. `assertions`: assertions in `import foo from "foo.json" assert { type: "json" }` - -More fields can be found in abstract class of _Dependency_ and _ModuleDependency_. [source: Dependency](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Dependency.js#L88) [source: ModuleDependency](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/ModuleDependency.js#L17) - -```js -// null -> index.js - -EntryDependency { - category: "esm", - request: "./index.js", - type: "entry", - _parentModule: undefined -} -``` - -```js -// index.js -> foo.js - -HarmonyImportSideEffectDependency { - category: "esm", - request: "./foo", - type: "harmony side effect evaluation", - _parentModule: NormalModule { identifier: "index.js" } -} -``` - -```js -// index.js -> bar.js - -HarmonyImportSideEffectDependency { - category: "esm", - request: "./bar", - type: "harmony side effect evaluation", - _parentModule: NormalModule { identifier: "index.js" } -} -``` - -```js -// bar.js -> foo.js -HarmonyImportSideEffectDependency { - category: "esm", - request: "./foo", - type: "harmony side effect evaluation", - _parentModule: NormalModule { identifier: "bar.js" } -} -``` - -#### Resolving a module - -_ModuleDependencies_ with different dependency category such as `esm` or `commonjs` will affect the resolving part. For ECMAScript modules, they may prefer `"module"` to `"main"`, and for _CommonJS_ modules, they may use `"main"` in `package.json`. On top of that, conditional exports are also necessary to be taken into account. [doc](https://nodejs.org/api/packages.html#conditional-exports) - -#### Different types of _module dependencies_ - -##### ESM-related derived types - -There are a few of _ModuleDependencies_ introduced in ESM imports. A full list of each derived type can be reached at [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependencyParserPlugin.js) - -###### Import - -**`HarmonyImportDependency`** - -The basic type of harmony-related _module dependencies_ are below. [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependency.js#L51) - -**`HarmonyImportSideEffectDependency`** - -```js -import { foo, bar } from './module'; -import * as module from './module'; -import foo from './module'; -import './module'; -``` - -Every import statement will come with a `HarmonyImportSideEffectDependency`, no matter how the specifiers look like. The specifier will be handled by `HarmonyImportSpecifierDependency` below. - -The field `assertions` will be stored if any import assertions exist for later consumption. -The field `category` will be used as `dependencyType` to resolve modules. - -**`HarmonyImportSpecifierDependency`** - -```js -import { foo, bar } from './module'; -import * as module from './module'; -import foo from './module'; -``` - -Example: - -```js -import { foo, bar } from './module'; - -console.log(foo, bar); -``` - -Specifier will be mapped into a specifier dependency if and only if it is used. JavaScript parser will first tag each variable [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependencyParserPlugin.js#L137), and then create corresponding dependencies on each reading of dependency. [\[source\]](https://github.com/webpack/webpack/blob/86a8bd9618c4677e94612ff7cbdf69affeba1268/lib/dependencies/HarmonyImportDependencyParserPlugin.js#L189) and finally be replaced to the generated `importVar`. - -##### Export(They are not module dependencies to be actual, but I placed here for convenience) - -**`HarmonyExportHeaderDependency`** - -> PresentationalDependency - -```js -export const foo = 'foo'; -export default 'foo'; -``` - -This is a _presentational dependency_. We will take more time on this later. - -**`HarmonyExportSpecifierDependency`** - -```js -export const foo = "foo"; // `foo` is a specifier - -HarmonyExportSpecifierDependency { - id: string; - name: string; -} -``` - -**`HarmonyExportExpressionDependency`** - -```js -export default "foo"; // "foo" is an expression - -HarmonyExportExpressionDependency { - range: [number, number] // range of the expression - rangeStatement: [number, number] // range of the whole statement -} -``` - -## How _dependencies_ affect code generation - -### _Presentational dependency_ - -> A type of dependency that only affects code presentation. - -**`ConstDependency`** - -``` -ConstDependency { - expression: string - range: [number, number] - runtimeRequirements: Set | null -} -``` - -You can think of the passed `expression` as a `replacement` for the corresponding `range`. For the real world example, you can directly refer to _Constant Folding_. - -### _Template_ - -Remember the fact that Webpack is an architecture wrapped around source code modifications. _Template_ is the solution that helps Webpack to do the real patch on the source code. Each dependency has its associated _template_ which affects a part of the code generation scoped per dependency. In other words, the effect of each _template_ is strictly scoped to its associated dependency. - -![image-20220919173300220](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663579980.png) - -There are three types of modification: - -- `source` -- `fragments` -- `runtimeRequirements` - -A boilerplate of the dependency template looks like this: - -```js -class SomeDependency {} - -SomeDependency.Template = class SomeDependencyTemplate { - /** - * @param {Dependency} dependency the dependency for which the template should be applied - * @param {ReplaceSource} source the current replace source which can be modified - * @param {DependencyTemplateContext} templateContext the context object - * @returns {void} - */ - apply(dependency, source, templateContext) { - // do code mod here - } -}; -``` - -There are three parameters in the function signature: - -- dependency: The associated dependency of this template -- source: The source code represent in `ReplaceSource`, which can be used to replace a snippet of code with a new one, given the start and end position -- templateContext: A context of template, which stores the corresponding `module`, `InitFragments`, `moduleGraph`, `runtimeRequirements`, etc. (not important in this section) - -#### `Source` - -Again, given an example of [`ConstDependency`](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/ConstDependency.js#L20), even if you don't have an idea what it is, it doesn't matter. We will cover this in the later sections. - -The associated template modifies the code with `Source`(`ReplaceSource` to be more specific): - -```js -ConstDependency.Template = class ConstDependencyTemplate extends ( - NullDependency.Template -) { - apply(dependency, source, templateContext) { - const dep = /** @type {ConstDependency} */ (dependency); - - // not necessary code is removed for clearer demonstration - - if (dep.runtimeRequirements) { - for (const req of dep.runtimeRequirements) { - templateContext.runtimeRequirements.add(req); - } - } - - source.replace(dep.range[0], dep.range[1] - 1, dep.expression); - } -}; -``` - -#### `runtimeRequirements` - -As you can see from the `Source` section above, there is another modification we talked about: `runtimeRequirements`, It adds -runtime requirements for the current `compilation`. We will explain more in the later sections. - -#### `Fragments` - -Essentially, a [_fragment_](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js) is a pair of code snippet that to be wrapped around each _module_ source. Note the wording "wrap", it could contain two parts `content` and `endContent` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js#L69). To make it more illustrative, see this: - -image - -The order of the fragment comes from two parts: - -1. The stage of a fragment: if the stage of two fragments is different, then it will be replaced corresponding to the order define by the stage -2. If two fragments share the same order, then it will be replaced in [position](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js#L41) order. - [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/InitFragment.js#L153-L159) - -**A real-world example** - -```js -import { foo } from './foo'; - -foo(); -``` - -Given the example above, here's the code to generate a dependency that replaces `import` statement with `__webpack_require__`. - -```js -// some code is omitted for cleaner demonstration -parser.hooks.import.tap( - 'HarmonyImportDependencyParserPlugin', - (statement, source) => { - const clearDep = new ConstDependency('', statement.range); - clearDep.loc = statement.loc; - parser.state.module.addPresentationalDependency(clearDep); - - const sideEffectDep = new HarmonyImportSideEffectDependency(source); - sideEffectDep.loc = statement.loc; - parser.state.module.addDependency(sideEffectDep); - - return true; - }, -); -``` - -Webpack will create two dependencies `ConstDependency` and `HarmonyImportSideEffectDependency` while parsing [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyImportDependencyParserPlugin.js#L110-L132). - -Let me focus on `HarmonyImportSideEffectDependency` more, since it uses `Fragment` to do some patch. - -```js -// some code is omitted for cleaner demonstration -HarmonyImportSideEffectDependency.Template = class HarmonyImportSideEffectDependencyTemplate extends ( - HarmonyImportDependency.Template -) { - apply(dependency, source, templateContext) { - super.apply(dependency, source, templateContext); - } -}; -``` - -As you can see in its associated _template_ [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyImportSideEffectDependency.js#L59), the modification to the code is made via its superclass `HarmonyImportDependency.Template` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyImportDependency.js#L244). - -```js -// some code is omitted for cleaner demonstration -HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends ( - ModuleDependency.Template -) { - apply(dependency, source, templateContext) { - const dep = /** @type {HarmonyImportDependency} */ (dependency); - const { module, chunkGraph, moduleGraph, runtime } = templateContext; - - const referencedModule = connection && connection.module; - - const moduleKey = referencedModule - ? referencedModule.identifier() - : dep.request; - const key = `harmony import ${moduleKey}`; - - // 1 - const importStatement = dep.getImportStatement(false, templateContext); - // 2 - templateContext.initFragments.push( - new ConditionalInitFragment( - importStatement[0] + importStatement[1], - InitFragment.STAGE_HARMONY_IMPORTS, - dep.sourceOrder, - key, - // omitted for cleaner code - ), - ); - } -}; -``` - -As you can see from the simplified source code above, the actual patch made to the generated code is via `templateContext.initFragments`(2). The import statement generated from dependency looks like this. - -```js -/* harmony import */ var _foo__WEBPACK_IMPORTED_MODULE_0__ = - __webpack_require__(/*! ./foo */ './src/foo.js'); //(1) -``` - -Note, the real require statement is generated via _initFragments_, `ConditionalInitFragment` to be specific. Don't be afraid of the naming, for more information you can see the [background](https://github.com/webpack/webpack/pull/11802) of this _fragment_, which let's webpack to change it from `InitFragment` to `ConditionalInitFragment`. - -**How does webpack solve the compatibility issue?** - -For ESM modules, webpack will additionally call a helper to define `_esModule` on exports as an hint: - -```js -__webpack_require__.r(__webpack_exports__); -``` - -The call of a helper is always placed ahead of any `require` statements. Probably you have already get this as the stage of `STAGE_HARMONY_EXPORTS` has high priority than `STAGE_HARMONY_IMPORTS`. Again, this is achieved via `initFragments`. The logic of the compatibility helper is defined in [this](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyCompatibilityDependency.js) file, you can check it out. - -### Runtime - -Runtime generation is based on the previously collected `runtimeRequirements` in different dependency templates and is done after the code generation of each module. Note: it's not after the `renderManifest`, but it's after the code generation of each module. - -![image-20220919173829765](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663580309.png)In the first iteration of collection, Sets of `runtimeRequirements` are collected from the module's code generation results and added to each `ChunkGraphModule`. - -In the second iteration of collection, the collected `runtimeRequirements` are already stored in `ChunkGraphModule`, so Webpack again collects them from there and stores the runtimes required by each chunk of `ChunkGraphChunk`. It's kind of the hoisting procedure of the required runtimes. - -Finally, also known as the third iteration of collection, Webpack hoists `runtimeRequirements` from those chunks that are referenced by the entry chunk and get it hoisted on the `ChunkGraphChunk` using a different field named `runtimeRequirementsInTree` which indicates not only does it contains the runtime requirements by the chunk but also it's children runtime requirements. - -![image-20220919174132772](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663580492.png) - -The referenced source code you can be found it [here](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L3379) and these steps are basically done in `processRuntimeRequirements`. This let me recall the linking procedure of a rollup-like bundler. Anyway, after this procedure, we can finally generate _runtime modules_. Actually, I lied here, huge thanks to the hook system of Webpack, the creation of _runtime modules_ is done in this method via calls to `runtimeRequirementInTree`[\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L3498). No doubt, this is all done in the `seal` step. After that, webpack will process each chunk and create a few code generation jobs, and finally, emit assets. - -### _Hot module replacement_ - -Changes made via _hot module replacement_ is mostly come from `HotModuleReplacementPlugin`. - -Given the code below: - -```js -if (module.hot) { - module.hot.accept(...) -} -``` - -Webpack will replace expressions like `module.hot` and `module.hot.accept`, etc with `ConstDependency` as the _presentationalDependency_ as I previously talked about. [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/HotModuleReplacementPlugin.js#L97-L101) - -With the help of a simple expression replacement is not enough, the plugin also introduce additional runtime modules for each entries. [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/HotModuleReplacementPlugin.js#L736-L748) - -The plugin is quite complicated, and you should definitely checkout what it actually does, but for things related to dependency, it's enough. - -## How _dependencies_ affect production optimizations - -### Constant folding - -> The logic is defined in ConstPlugin : [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/ConstPlugin.js#L135) - -_Constant folding_ is a technique that used as an optimization for optimization. For example: - -**Source** - -```js -if (process.env.NODE_ENV === "development") { - ... -} else { - ... -} -``` - -**Generated** - -```js -if (true) { - ... -} -``` - -With mode set to `"development"`, webpack will "fold" the expression `process.env.NODE_ENV === "development"` into an expression of `"true"` as you can see for the code generation result. - -In the `make` procedure of webpack, Webpack internally uses an `JavaScriptParser` for JavaScript parsing. If an `ifStatement` is encountered, Webpack creates a corresponding `ConstDependency`. Essentially, for the `ifStatement`, the `ConstDependency` looks like this : - -```js -ConstDependency { - expression: "true", - range: [start, end] // range to replace -} -``` - -It's almost the same with `else` branch, if there is no _side effects_(refer to source code for more detail), Webpack will create another `ConstDependency` with `expression` set to `""`, which in the end removes the `else` branch. - -In the `seal` procedure of Webpack, the record of the dependency will be applied to the original source code and generate the final result as you may have already seen above. - -### Tree shaking & DCE - -Tree-shaking is a technique of a bundle-wise DCE(dead code elimination). In the following content, I will use tree-shaking as a wording for bundle-wise and DCE for module-wise code elimination. (I know it's not quite appropriate, but you get the point) - -Here's an example: - -```js -// webpack configuration -module.exports = { - optimization: { - usedExports: true, - }, -}; -``` - -![image-20220919182656468](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663583216.png) - -![image-20220919190553215](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663585553.png) - -![image-20220919190925073](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663585765.png) - -As you can see from the red square, the `initFragment` is generated based on the usage of the exported symbol in the `HarmonyExportSpecifierDependency` [\[source\]](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/dependencies/HarmonyExportSpecifierDependency.js#L91-L107) - -If `foo` is used in the graph, then the generated result will be this: - -```js -/* harmony export */ __webpack_require__.d(__webpack_exports__, { - /* harmony export */ foo: function () { - return /* binding */ foo; - }, - /* harmony export */ -}); -const foo = 'foo'; -``` - -In the example above, the `foo` is not used, so it will be excluded in the code generation of the template of `HarmonyExportSpecifierDependency` and it will be dead-code-eliminated in later steps. For terser plugin, it eliminates all unreachable code in `processAssets` [\[source\]](https://github.com/webpack-contrib/terser-webpack-plugin/blob/580f59c5d223a31c4a9c658a6f9bb1e59b3defa6/src/index.js#L836). - -## Things related to Persistent cache - -_TODO_ - -## Wrap it up! - -Let's wrap everything up in a simple example! Isn't it exciting? - -![image-20220919223228146](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663597948.png) - -Given a module graph that contains three modules, the entry point of this bundle is `index.js`. To not make this example too complicated, we use normal import statements to reference each module (i.e: only one chunk that bundles everything will be created). - -### `Make` - -![image-20220919223558327](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663598158.png) - -### Dependencies after `make` - -![image-20220919223720739](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220919_1663598240.png) - -### `seal` - -![image-20220920180915326](https://raw.githubusercontent.com/h-a-n-a/static/main/2022/09/upgit_20220920_1663668558.png) - -# References - -_TODO_ diff --git a/website/docs/en/contribute/webpack/loader.md b/website/docs/en/contribute/webpack/loader.md deleted file mode 100644 index 6ba95de5083a..000000000000 --- a/website/docs/en/contribute/webpack/loader.md +++ /dev/null @@ -1,783 +0,0 @@ -> Based on _Webpack version: 5.73.0_. - -# Loader - -Explain how webpack loader works. Even though it's a little bit long and tedious, It's still a teeny-tiny peek at the loader system of Webpack. - -# Glossary - -> What's the meaning of a word used to describe a feature? -> -> Why does the Webpack introduce this and what's the background of introducing this? What kind of problem Webpack was facing at the time? - -## Request Related - -```javascript -import Styles from '!style-loader!css-loader?modules!./styles.css'; -``` - -- [Inline loader syntax](https://webpack.js.org/concepts/loaders/#inline): The syntax that chains the loader together within the specifier, followed by the file requested. e.g. `!style-loader!css-loader?modules!./style.css` -- `request`: The request with _inline loader syntax_ retained. Webpack will convert relative URLs and module requests to absolute URLs for loaders and files requested. e.g. `!full-path-to-the-loader-separated-with-exclamation-mark!full-path-to-styles.css` - -## Resource Related - -```javascript -import foo from './index.js?vue=true&style#some-fragment'; -``` - -- [`resource`](https://webpack.js.org/api/loaders/#thisresource): The absolute path to the requested file with `query` and `fragment` retained but inline loader syntax removed. e.g. `absolute-path-to-index-js.js?vue=true&style#some-fragment` -- [`resourcePath`](https://webpack.js.org/api/loaders/#thisresourcepath): The absolute path to the requested file only. e.g. `absolute-path-to-index-js.js` -- [`resourceQuery`](https://webpack.js.org/api/loaders/#thisresourcequery): Query with question mark `?` included. e.g. `?vue=true&style` -- [`resourceFragment`](https://webpack.js.org/api/loaders/#thisresourcefragment): e.g. `#some-fragment` -- inline match resource: - - - Used to redirect the `module.rules` to another, which is able to adjust the loader chain. We will cover this later. - - Ref: [related PR](https://github.com/webpack/webpack/pull/7462) [Webpack Doc1](https://webpack.js.org/api/loaders/#thisimportmodule) [Webpack Doc2](https://webpack.js.org/api/loaders/#inline-matchresource) - -- `virtualResource`: - - The proposed solution to support asset type changing(A sugar to inline matchResource, which can also affect the asset filename generation) - - See more: [the background of this property](https://github.com/webpack/webpack/issues/14851) - -## Others but also important to note - -- Virtual Module: A kind of module that does not locate in the real file system. But you can still import it. To create a virtual module, you need to follow the [spec](https://www.ietf.org/rfc/rfc2397.txt) and it's also worth noting that Node.js and Webpack both support it under the scheme of `data:`. Also known as, `data:` import. [Doc to Node.js](https://nodejs.org/api/esm.html#data-imports) -- [Module types](https://webpack.js.org/concepts/modules/#supported-module-types) with native support: Webpack supports the following module types native: `'javascript/auto'` |` 'javascript/dynamic'` | `'javascript/esm'` | `'json'` | `'webassembly/sync'` | `'webassembly/async'` | `'asset'` | `'asset/source'` | `'asset/resource'` | `'asset/inline'`, for those types you can use it **without a loader**. From webpack version 4.0+, webpack can understand more than `javascript` alone. - -# Guide-level explanation - -## Loader configuration - -The way that webpack controls what kind of module that each loader would apply is based on `module.rules` - -```javascript -const MiniExtractCssPlugin = require('mini-extract-css-plugin'); - -module.exports = { - module: { - rules: [ - { - test: /\.vue$/, - use: ['vue-loader'], - }, - { - test: /\.css$/, - use: [MiniExtractCssPlugin.loader, 'css-loader'], - }, - ], - }, - plugins: [new MiniExtractCssPlugin()], -}; -``` - -Here is a simple option for the configuration of `vue-loader`. `module.rules[number].test` is a part rule to test **whether a rule should be applied**. For `vue-loader` alone, It's kind of confusing how webpack pass the result to the rule of `css`, we will cover this later. But for now, It's good to notice **there is not only a `test` option alone to test if a rule should be applied**. You can find it [here](https://webpack.js.org/configuration/module/#rule) for full conditions supported. Here're some examples of other conditions you can use. - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.vue$/, // of course, test if the file extension match `vue`. - scheme: 'data', // if the specifier of a request starts with `data:` - resourceQuery: '?raw', // if the `resourceQuery` matches then the rule will be applied. For this example, it's a great idea to apply a `raw-loader` here. - type: 'css', // use webpack's native resource handling for css - }, - ], - }, -}; -``` - -## Examples - -### Vue(1 to n) - -In a single file component(SFC) of Vue, there are commonly three blocks or more blocks([custom blocks](https://vue-loader.vuejs.org/guide/custom-blocks.html#example)) contained. The basic idea of implementing this loader is to convert it into JavaScript / CSS and let webpack handle the chunk generation(e.g. Style should be generated into a separate `.css` file) - -```vue - - - - - -``` - -⬇️⬇️⬇️⬇️⬇️⬇️ - -`Vue-loader` will firstly turn into the `*.vue` file into something like that. - -```javascript -import 'script-path-to-vue-sfc'; -import 'template-path-to-vue-sfc'; -import 'style-path-to-vue-sfc'; -``` - -You may find it weird how webpack handles these imports and build the transformed code. But if I change the code a little bit, you will find the idea. - -```javascript -import 'script:path-to-vue-sfc'; -import 'template:path-to-vue-sfc'; -import 'style:path-to-vue-sfc'; -``` - -and if we tweak the configuration a little bit to this, webpack will know exactly how to work with these import statements. - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.vue$/, - use: ['vue-loader'], - }, - { - scheme: 'script', - use: ['apply-your-javascript-loader', 'vue-script-extract-loader'], - }, - { - scheme: 'template', - use: ['apply-your-javascript-loader', 'vue-template-extract-loader'], - }, - { - scheme: 'style', - use: ['apply-your-style-loader', 'vue-style-extract-loader'], - }, - ], - }, -}; -``` - -We added a few loaders to handle the splitting. I know it's still kind of weird here, but please stick with me and we will find a better way out. - -- vue-script-extract-loader: extract the `script` block from a SFC file. -- vue-style-extract-loader: extract the `style` block from a SFC file. -- vue-template-extract-loader: extract the `template` block from a SFC file and convert it into JavaScript. - -You will find it's really noisy only to transform a `*.vue` file, four loaders were introduced and I believe none of you would like to separate a simple loader into four. It's a real bummer! It will be great to use a single loader `vue-loader` alone. The current vue loader implementation uses resourceQuery to handle this. But how? - -#### Loader optimizations I - -We know that webpack uses a few conditions to handle whether a rule should be applied. Even with `rule.test` alone, the `this.resourceQuery` is still available to `loaderContext` which developer could access it with `this` in any loader function(Don't worry if you still don't catch this. You will understand this after). Based on that, we change the `rule` to this: - -```javascript -module.exports = { - module: { - rules: [ - { - test: /.vue$/, - use: ['vue-loader'], - }, - ], - }, -}; -``` - -This indicates "If an import specifier is encountered, please pass me to vue-loader"! If you remember the import transformation above, we could adjust the transformation a little bit to this: - -**Before** - -```javascript -import 'script-path-to-vue-sfc'; -import 'template-path-to-vue-sfc'; -import 'style-path-to-vue-sfc'; -``` - -**After** - -```javascript -import 'path-to-vue-sfc.vue?script=true'; -import 'path-to-vue-sfc.vue?template=true'; -import 'path-to-vue-sfc.vue?style=true'; -``` - -These requests will match the `test: /.vue$/` above flawlessly and in the loader we can handle like this: - -```javascript -// pseudo code only for proofing of the concept -const compiler = require("some-vue-template-compiler") - -const loader = function(source) { - const { - resourceQuery /* ?script=true or something else */, - resourcePath /* path-to-vue-sfc.vue */ - } = this - - if (resourceQuery === "?script=true") { - return compiler.giveMeCodeofScriptBlock(this.resourcePath) // javascript code - } else if (resourceQuery === "?template=true") { - return compiler.giveMeCodeofTemplateBlock(this.resourcePath) // javascript code - } else if (resourceQuery === "?style=true") { - return compiler.giveMeCodeofStyleBlock(this.resourcePath) // style code - } else { - return ` - import `${this.resourcePath}?script=true`; - import `${this.resourcePath}?template=true`; - import `${this.resourcePath}?style=true`; - ` - } -} - -module.exports = loader -``` - -You can see the loader for the example above will be used for four times. - -1. Encounter a `*.vue` file, transform the code to a few import statements -2. For each import statement introduced in the first transformation, the loader will be used again as they share the same extension `vue`. - -Is this the end? No! Even if you wrote the code like this, it will still fail to load. - -1. For CSS: You haven't tell webpack a way to handle the CSS, remember the CSS part is required to go through the `css-loader` and then `mini-css-extract`(if you want to generate CSS for chunk) or `style-loader`(if you want to append it directly to the DOM). After all, you have to make the result of style to pass these loaders. -2. For JS: You haven't transformed the code to any transpilers, It will be failed if your runtime doesn't support the syntax(maybe in TypeScript for example) and webpack internal acorn compiler does not have the ability to help you with that. - -**Pass the code to the corresponding loaders** - -We tweak the configuration a little bit again. - -```javascript -module.exports = { - module: { - rules: [ - { - test: /.vue$/, - use: ['vue-loader'], - }, - { - test: /.css$/, - use: [MiniCssExtractPlugin.loader, 'css-loader'], - }, - { - test: /.js$/, - use: ['babel-loader'], - }, - ], - }, -}; -``` - -It looks a bit more like the "normal" Webpack configuration. Note that the `rule.test` is based on the file extension, so `vue-loader` did a little bit of hack here. - -```javascript -// pseudo code only for proofing of the concept -const compiler = require("some-vue-template-compiler") - -const loader = function(source) { - const { - resourceQuery /* ?script=true or something else */, - resourcePath /* path-to-vue-sfc.vue */ - } = this - - if (resourceQuery === "?script=true") { - const code = compiler.giveMeCodeofScriptBlock(this.resourcePath) // javascript code - this.resourcePath += ".js" - return code - } else if (resourceQuery === "?template=true") { - const code = compiler.giveMeCodeofTemplateBlock(this.resourcePath) // javascript code - this.resourcePath += ".js" - return code - } else if (resourceQuery === "?style=true") { - const code = compiler.giveMeCodeofStyleBlock(this.resourcePath) // style code - this.resourcePath += ".css" // based on the `lang` in each script, the extension will be set accordingly. - return code - } else { - return ` - import `${this.resourcePath}?script=true`; - import `${this.resourcePath}?template=true`; - import `${this.resourcePath}?style=true`; - ` - } -} - -module.exports = loader -``` - -Webpack uses `resourcePath` to match a `module.rules`. So this hack will let webpack treat blocks accordingly as if they are real files with extensions of `js` | `css` |`...` . - -Finally! But this is only a proof of concept, for the real implementation. You should definitely check out the [`vue-loader`](https://github.com/vuejs/vue-loader) yourself. - -#### Loader Optimization II - -Well done! We implemented a simple and rudimentary version of `vue-loader`. However, the real painful part of this implementation is hacking the extension to match the configuration. But since almost every user would have other `js` | `css` files included in the project, so vue team decide to use this kind of strategy to reuse the user configuration. - -Except for hacking the extension, webpack then provided a more legit way to handle this kind of **rule matching problem** which is known as **_inline match resource_** (We covered it in the glossary part). - -**inline match resource** - -Webpack can do almost anything with an import specifier like the loader chaining we covered in the glossary part. _Inline source match_ is another case. By taking the advantage of it, you can force an import statement to go through a `module.rules` by introducing the `!=!` syntax. For example, if we want to force a `css` file to go through a `less` loader, it will be look like this: - -```javascript -module.exports = { - module: { - rules: [ - { - test: /.less$/, - use: ['style-loader', 'css-loader', 'less-loader'], - }, - ], - }, -}; -``` - -```javascript -// This import should be converted with a loader - -// treat the file as `less` -import './index.css.less!=!./index.css'; -``` - -The slice before the `!=!` is a way to modify the extension of a single file and force it to match the `module.rules` and this transformation is often done in a loader, or you will make your application code specialized for Webpack only. - -After going through the basic example, let's see how we're going to optimize out the hack used in `vue-loader`. - -```javascript -// pseudo code only for proofing of the concept -const compiler = require("some-vue-template-compiler") - -const loader = function(source) { - const { - resourceQuery /* ?script=true or something else */, - resourcePath /* path-to-vue-sfc.vue */ - } = this - - if (resourceQuery === "?vue=true&script=true") { - return compiler.giveMeCodeofScriptBlock(this.resourcePath) // javascript code - } else if (resourceQuery === "?vue=true&template=true") { - return compiler.giveMeCodeofTemplateBlock(this.resourcePath) // javascript code - } else if (resourceQuery === "?vue=true&style=true") { - return compiler.giveMeCodeofStyleBlock(this.resourcePath) // style code - } else { - return ` - import `${this.resourcePath}.js!=!${this.resourcePath}?vue=true&script=true`; - import `${this.resourcePath}.js!=!${this.resourcePath}?vue=true&template=true`; - import `${this.resourcePath}.css!=!${this.resourcePath}?vue=true&style=true`; - ` - } -} - -module.exports = loader -``` - -Webpack will internally use the match resource part(before `!=!`) as the data to match loaders. In order to let `vue-loader` match the resource. We have two options: - -1. Loose test -2. _Inline loader syntax_ - -**1. Loose test** - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.vue/, // original: `/\.vue$/`, we removed the `$` to allow resources with `.vue` included to match this rule. - use: ['vue-loader'], - }, - ], - }, -}; -``` - -We removed the `$` to allow resources with `.vue` included matching this rule. Personally speaking, this is not a good idea, because a loose match might cause mismatches. - -**2. Inline loader syntax** - -```javascript -// vue-loader/index.js - -module.exports = function() { - // ... code omitted - return ` - import `${this.resourcePath}.js!=!${__filename}!${this.resourcePath}?vue=true&script=true`; - import `${this.resourcePath}.js!=!${__filename}!${this.resourcePath}?vue=true&template=true`; - import `${this.resourcePath}.css!=!${__filename}!${this.resourcePath}?vue=true&style=true`; - ` -} -``` - -This technique is to take advantage of the **_inline loader syntax_** to force the loader to go through the vue loader. This tackles down the tangible mismatching ideally and we can still retain the test regex `/\.vue$/` as-is. - -#### Final art and conclusion - -**Configuration** - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.vue$/, - use: ['vue-loader'], - }, - // ... other rules for js, or css, etc. - ], - }, -}; -``` - -**Loader** - -```javascript -// pseudo code only for proofing of the concept -const compiler = require("some-vue-template-compiler") - -const loader = function(source) { - const { - resourceQuery /* ?script=true or something else */, - resourcePath /* path-to-vue-sfc.vue */ - } = this - - if (resourceQuery === "?vue=true&script=true") { - return compiler.giveMeCodeofScriptBlock(resourcePath) // javascript code - } else if (resourceQuery === "?vue=true&template=true") { - return compiler.giveMeCodeofTemplateBlock(resourcePath) // javascript code - } else if (resourceQuery === "?vue=true&style=true") { - return compiler.giveMeCodeofStyleBlock(resourcePath) // style code - } else { - return ` - import `${this.resourcePath}.js!=!${__filename}!${resourcePath}?vue=true&script=true`; - import `${this.resourcePath}.js!=!${__filename}!${resourcePath}?vue=true&template=true`; - import `${this.resourcePath}.css!=!${__filename}!${resourcePath}?vue=true&style=true`; - ` - } -} - -module.exports = loader -``` - -**Conclusion** - -Vue-loader is quite complex. The basic needs of the loader are: - -1. Separate a `*.vue` file request into a number of parts. For each block, explicitly change the resource matching mechanism (using **_inline match resource_**). The killer _inline match resource_ not only gives us great composability with user-defined loaders, but also the ability to interact with webpack supported native types, and we will cover this part late. -2. When requesting the `vue-loader` again for a block, the code of each block is returned and let webpack handle the changed matched resource(e.g. `./App.vue.css`) with user-defined loaders (Webpack did this internally). - -### Use natively supported module types - -We know that webpack only supports `JavaScript` in the old time, from the version of `4.0.0`+([changelog](https://github.com/webpack/webpack/releases/tag/v4.0.0)) - -#### Simplified pre-processor's configuration - -> With the experimental support of CSS. A.K.A webpack knows how to handle CSS files natively. - -**Before** - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.less$/, - use: ['style-loader', 'css-loader', 'less-loader'], - type: 'javascript/auto', // this field is a implicit one, if not defined, it will be set to `"javascript/auto"` - }, - ], - }, -}; -``` - -**After** - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.less$/, - use: ['less-loader'], - type: 'css', - }, - ], - }, - experiments: { - css: true, - }, -}; -``` - -With `experiments.css` on, webpack can experimentally understand the parsing and generating of `css` files which gets rid of `css-loader` and `style-loader`. For the full list of natively supported `Rule.type`, you can find it [here](https://webpack.js.org/configuration/module/#ruletype). - -#### Asset modules - -> From _webpack 4.0.0+_, assets are supported natively - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.(png|jpg)/, - type: 'asset', - }, - ], - }, -}; -``` - -`Rule.type === "asset"` indicates the asset will be automatically tested whether it's going to be inlined or emitted as a file on the real file system. The possible options are: `'asset'` | `'asset/source'` | `'asset/resource'` | `'asset/inline'` - -### Svgr - -Webpack loader will read the source to a UTF-8 string by default. For SVG files, this would fit the webpack load defaults. - -```javascript -// Proof of concept of svgr-loader -module.exports = function (source) { - if (this.resourceQuery === '?svgr=true') { - // the real transform part - let { code } = svgrTransformer.transform(source); - return code; - } - return `require("${this.resourcePath}.jsx!=!${__filename}!${this.resourcePath}?svgr=true")`; // the request part -}; -``` - -Again here we use double-pass to firstly convert each request to the request part with _inline match resource_, and do the real request with query `?svgr=true`, and let _inline match resource_ handle the `jsx` conversion. Before that, we have to call a third-party `jsx` transformer, could be _ESBuild_ for example, for which we cannot reuse other `module.rules` set by the user-side. _Inline match resource_ saved our pain again! - -### Scheme imports - -> Supported in _Webpack version 5.38.0_, doc: [Rule.scheme](https://webpack.js.org/configuration/module/#rulescheme) - -```javascript -// JavaScript -import x from 'data:text/javascript,export default 42'; -console.log('x:', x); -``` - -```css -/* CSS */ -@import ('data:text/css, body { background: #fff; }'); -``` - -Webpack handles `data:` imports for JavaScript internally. - -### Asset transform and rename - -> [**Asset**](https://webpack.js.org/guides/asset-management/): This is a general term for the images, fonts, media, and any other kind of files that are typically used in websites and other applications. These typically end up as individual files within the [output](https://webpack.js.org/glossary/#o) but can also be inlined via things like the [style-loader](https://webpack.js.org/loaders/style-loader) or [url-loader](https://webpack.js.org/loaders/url-loader). -> -> _Originally posted at Webpack [Glossary](https://webpack.js.org/glossary/#a)_ - -#### Default resource reading override - -Asset could be formatted in both text(`*.svg`) or binary (`*.png` / `*.jpg`). For loaders, webpack provides you an option [`raw`](https://webpack.js.org/api/loaders/#raw-loader) to override the default and built-in resource reading strategy from UTF-8 `string` to `Buffer`: - -```javascript -module.exports = function (source /* Buffer */) { - // loader implementation -}; - -module.exports.raw = true; -``` - -#### Transform and rename - -Image there is a need to transform an asset formatted with `png` to `jpg`. There is two abilities that webpack needs to support: - -1. Handle the asset with `raw` content, or a `Buffer`. We can simply override the default resource reading behavior by exporting `raw`(covered before). -2. Change the filename, and reuse the loader for both `png` and `jpg` - -##### Configuration - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.png/, - use: ["png-to-jpg-loader"] // some png to jpg loader, we will implement this - }, - { - test: /\.jpg/, - use: ["jpg-optimizer"] // some jpg optimizer, we will not covert this, - type: "asset/resource" - } - ] - } -} -``` - -1. Rule1: For files with extension `png`, we want to use a `png` to `jpg` loader, which will be covered in this article. -2. Rule2: - 1. For files with extension `jpg`, we want to use a third-party `jpg-optimizer`, which will not be covered in this article. - 2. `type: "asset/resource"`: As soon as all the loaders have gone through, we want webpack to emit the file as an external resource on the file system regardless of the file size(`type: "asset"` will automatically detect the size of an asset to determine whether an asset will be inline-included for dynamically imported from file system). -3. For those `jpg` files converted from `png`, we want them to apply with the `jpg-optimizer` too(i.e. reuse the loaders defined in `module.rules`) - -##### Loader - -```javascript -module.exports = function (source) { - if (this.resourceQuery === '?pngToJPG=true') { - return pngToJpg.transform(source); - } - - return `require("${this.resourcePath}.jpg!=!${__filename}${this.resourcePath}?pngToJPG=true")`; -}; - -module.exports.raw = true; -``` - -We use double-pass again, firstly we convert the extension to `.jpg` which will apply the matched rules(in this case `test: /\.jpg/`), after the transformation of `png-to-jpg-loader`. Generated asset module filename will be based on the _inline match resource_, which is `xxxx.jpg` in this case. - -### AST reuse - -Webpack provides a way to pass metadata(the forth parameter) among the chaining loaders [doc](https://webpack.js.org/api/loaders/#thiscallback). The most commonly used value is `webpackAST` which accepts an `ESTree` compatible(webpack internally uses `acorn`) AST, which hugely improves the performance since webpack instead of parsing the returned code to AST again, **will directly use the AST(`webpackAST`) returned from a loader**(But **the work of a complete walking of an AST can not be omitted** as it's necessary for webpack for do some analysis for its dependencies and will be only done once, so it is not a big overhead.) - -```javascript -module.exports = function (source) { - let ast = AcornParser.parse(source, { - // options - }); - - this.callback(null, '', null, { - webpackAST: ast, - }); -}; -``` - -Good to note that only `ESTree` is compatible, so you cannot pass a CSS AST, or webpack will complain with `"webpackAst is unexpected for the CssParser"`. It will be ok if you don't get this, let's move to the reference-level explanation for analysis in-depth. - -## Reference-level explanation - -This is the reference-level explanation part of webpack's internal loader implementation. - -### Loader composability - -> If you don't quite get this concept, you may refer to the Glossary and _Example_ part of the Guide-level explanation first and pick up this as soon as you finished. - -The high-level idea of previously talked _inline match resource_ is to let **loader developers** to customize the behavior of matching to match the pre-defined `module.rules`. It's an API to write composable loaders. But what does composition mean? For those users who are familiar with React hooks and Vue composable APIs, you may get this faster. Actually, webpack provides a lot of ways to help loader developers and users do the composition. - -#### User-defined loader flows - -```javascript -module.exports = { - module: { - rules: [ - { - test: /\.js$/, - use: ['babel-loader'], - type: 'javascript/auto', - }, - { - test: /\.svg$/, - use: ['svgr-loader', 'svgo-loader'], - }, - ], - }, -}; -``` - -Webpack users can take the advantage of `module.rules[number].use` with a loader list for each request that matches the corresponding conditions. Note that I use the wording of `request,` not the `file` , which can include a request to `data:text/javascript` not the files on the real file system only. (In Parcel bundler, it's called [_pipelines_](https://parceljs.org/features/plugins/#pipelines), but this will not be covered in this article.) - -Apparently, user-declared loader flow is not able to cover up every case that a loader wants. You can see from the previous examples, `vue-loader` wants to split a file into many blocks, and remain the reference to it. `svgr-loader` wants to do the transformation first and let other loaders deal with the `jsx`. `svg-loader` wants to use the internal ability of `Asset Module` to let Webpack decide whether an asset is inlined or emitted to the real file system. and there are more to come... Based on the complexity of the loader, Webpack also provides a syntax to allow loader implementors to do the composition by themselves. - -#### The syntax for loader composition - -##### Inline loader syntax (Chaining loaders) - -> Supported from _webpack v1_ [chaining-loaders](https://webpack.js.org/migrate/3/#chaining-loaders) -> -> It's possible to specify loaders in an `import` statement, or any [equivalent "importing" method](https://webpack.js.org/api/module-methods). Separate loaders from the resource with `!`. Each part is resolved relative to the current directory. [doc](https://webpack.js.org/concepts/loaders/#inline) - -```javascript -import Styles from '!style-loader!css-loader?modules!./styles.css'; -``` - -The _inline loader syntax_ executes each loader for each request from right to left. Webpack handles the interaction with user-defined loaders carefully. So by default, the user-defined normal loader will be executed prior to the inline loaders, you can disable this behavior by prefixing `!` , (full reference could be found here [doc](https://webpack.js.org/concepts/loaders/#inline)). - -The custom specifier is parsed before the `module.rules` as the _inline loader syntax_ interferes the user-defined loaders(See the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModuleFactory.js#L390-L403)). Then, webpack will get the `module.rules` combined with the required conditions to calculate the matching rule set (See the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModuleFactory.js#L493-L510)). - -At the moment, you cannot change the matching behavior with the syntax, loaders are always matched with the provided _resourcePath_, etc, which leads to a bunch of hack code in the implementations of loaders (see this [code snippet](https://github.com/vuejs/vue-loader/blob/e9314347d75a1b0e54f971272d23a669fc3e6965/src/select.ts#L31) in `vue-loader`). The possibilities for changing the matching behavior leaves to the later-coming _inline match resource_. - -Nevertheless, the architecture of Loader at this moment is sound and solid. Another good example is the implementation-nonrelative filter(i.e. the filtering logic of _Loader_ is not declared in the loader itself), which is the fundamental root of loader composition, or the implementor will do a lot of hacks. (It's way too dirty to talk about here, but you can take the rollup [svgr](https://github.com/gregberge/svgr/blob/1dbc3e2c2027253b3b81b92fd4eb09a4aa8ae25e/packages/rollup/src/index.ts#L52) plugin as a reference) - -In conclusion, _inline loader syntax_ gives us a chance to control the loader flow with user-defined rules. - -##### Inline match resource - -To extend the matching ability, _inline match resource_ enables loader implementors to reuse some of the user-defined configurations with more flexibilities. - -On top of the previous example, webpack also provides a way to make use of the natively-supported _module types_. - -```javascript -// For module type `css` to work, you need to enable `experiments.css` -import './style.less.webpack[css]!=path-to-less-loader!./style.less'; -``` - -```javascript -// webpack.config.js -module.exports = { - experiments: { - css: true, - }, -}; -``` - -Given the configuration above, the overview of the complete flow will be like this: - -1. Webpack: Parse the specifier of the import and create the loader for the current request -2. Webpack: Merge the result from the second step with a user-defined `module.rules` in `webpack.config`, in this case is `[]` -3. Webpack: load `style.less` as UTF-8 string -4. Less-loader: Accept the UTF-8 string as the first parameter of the loader function and transform it to the content of `css`. -5. Webpack: Call the registered native `CSS` parser, and later at the code generation step the registered native `CSS` generator generates the result. - -For _asset modules_, you can also use this: - -```javascript -import './logo.png.jpg.webpack[asset/resource]!=path-to-loaders!./logo.png'; -``` - -The first part, also known as `matchResource` will be used as a part of the `filename` of the final code generation. (See the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/asset/AssetGenerator.js#L293-L348)) - -### Performance optimizations - -Before moving on to the detailed implementations, here's some glossary to support your understanding the architecture as a whole. - -#### Glossary - -- `NormalModuleFactory`: A factory used to create a `NormalModule`, which basically exposes a `create` method. -- `NormalModule`: A module in Webpack most of the time is a `NormalModule`, but with different implementations of `parser`/ `generator` / `Module Type`, the module could be almost any kind, and also exposes a `build` method. For example, a `NormalModule` with JavaScript parser, JavaScript generator, and `type ===javascript/auto` will be regarded as a module with JavaScript-related functionalities. Also, good to note that a module may not exist on the real file system, taking `data:` for example. - -#### The module creation workflow - -> This will only introduce a slice of webpack's internal implementation from **the Loader's perspective**, for more you should directly refer to the source code. - -When an import statement is detected, webpack will initialize a module creation. Based on the type of _Dependency_ (an abstraction of webpack, it's not important here), webpack can find the linked _ModuleFactory_(The abstraction class), in most cases, the derived factory is `NormalModuleFactory`, which exposes a `create` method. - -##### Prepare data needed for module creation - -The `NormalModuleFactory#create` is used to provide enough information to create a real `NormalModule`, and create the `NormalModule`. In the `create` method, webpack basically does these things(some non-loader related stuff will be omitted): - -- Resolve loaders from request: resolve the request, parse inline loader syntax: This contains _inline match resource_, _inline loader syntax_. -- Do the analysis on the parsed loader syntax, to decide whether a user-defined `normal/post/pre` loader is going to be included. [doc](https://webpack.js.org/concepts/loaders/#inline) -- Resolve Resource: resolve resource to the absolute path, fragments, queries, etc(These stuff are also provided in `LoaderContext`). For the full source code you may refer to [this](https://github.com/webpack/webpack/blob/main/lib/NormalModuleFactory.js#L653-L678) -- Use the resolved resource data to match `module.rules` defined in the configuration, and get the matched rules. This is also a part of the module creation data. -- Do some special logic with _inline match resource_, since match resource ends like `.webpack[css]` would change `Rule.type`. Also store the match resource data, since it might affect the filename generation for _asset modules_. - -##### Create a module based on the prepared data - -After the data needed for module creation is prepared, `NormalModuleFactory` will `new NormalModule` with the data provided. It contains basically every that a `NormalModule` needs (see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L271-L287)). Most importantly, the `loaders`. It contains every loader parsed and ordered from the `create` step. - -#### The module build step - -The module build step is kind of clear. Webpack will invoke the `build` method for each `NormalModule` instance, which invokes `loader-runner`(see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L819)) to go through every loader that was analyzed from the create step. It's clear to **know that the composition of loaders is happening on the same module**. - -#### A peek of the support of _Module Types_ - -As far as this article goes, It might be getting a little bit tedious. But have you ever wondered how webpack supports these _module types_ natively? I think It's still worth telling you about it to get a more complete understanding of the AST optimizations. For the support of JavaScript, webpack's JavaScript plugin will register different types of parser and generators for each _module types_, which will be used as the `parser` / `generator` to a `NormalModule` (see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/javascript/JavascriptModulesPlugin.js#L202-L231)). - -#### Reusing AST in Webpack - -Based on the parser and generator we introduced before, webpack did a little hack around the fourth parameter of `this.callback` (from _loaderContext_), with `webpackAST`, after each loader call, the `webpackAST` will be stored in the context of loader, and passed again to the next loader. Finally, the AST will be passed to the `parser`(It could be any type, based on the _module type_, but webpack makes it a JavaScript only for AST) (see the [source code](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L1087)). - -Here's an issue about trying to use SWC 's AST to get rid of the time sensitive code parsing from Acorn Parser, but they are facing some AST compatibility issues and performance issues about the overhead of interop with native code(Rust). - -## References - -- loader plugin api design (Analysis) [#315](https://github.com/speedy-js/rspack/discussions/315) - -- RFC-011 Supports `data:text/javascript` protocol [#457](https://github.com/speedy-js/rspack/discussions/457) - -- Webpack: `matchResource` with natively-supported module types [doc](https://webpack.js.org/api/loaders/#thisimportmodule) - -- Webpack: Loader context [doc](https://webpack.js.org/api/loaders/#the-loader-context) - -- Webpack: Module rules [doc](https://webpack.js.org/configuration/module/#rule) - -- SWC-loader for performance optimizations [issue](https://github.com/webpack/webpack/issues/13425#issuecomment-1013560170) diff --git a/website/docs/en/contribute/workflows/meetings.md b/website/docs/en/contribute/workflows/meetings.md deleted file mode 100644 index b8cfa9cbb54d..000000000000 --- a/website/docs/en/contribute/workflows/meetings.md +++ /dev/null @@ -1,9 +0,0 @@ -# Meetings - -## Tuesday meeting - -1. Go through the [iteration plan](https://github.com/web-infra-dev/rspack/milestones) - -## Thursday meeting - -1. Go through any topics that need [to be discussed](https://github.com/web-infra-dev/rspack/issues?q=is%3Aopen+label%3A%22to+be+discussed%22+sort%3Aupdated-desc) diff --git a/website/docs/en/contribute/workflows/misc.md b/website/docs/en/contribute/workflows/misc.md deleted file mode 100644 index c1ac3ff74b72..000000000000 --- a/website/docs/en/contribute/workflows/misc.md +++ /dev/null @@ -1,9 +0,0 @@ -# Misc - -## "need documentation" label - -This is used for reminding ourselves to update the Rspack website for a new feature. - -When a PR is merged with the "need documentation" label, -[rspack-bot](https://github.com/rspack-bot) will create a corresponding PR -in the [rspack-website](https://github.com/web-infra-dev/rspack-website) repo. diff --git a/website/docs/en/contribute/workflows/releases.md b/website/docs/en/contribute/workflows/releases.md deleted file mode 100644 index e3cc252c4977..000000000000 --- a/website/docs/en/contribute/workflows/releases.md +++ /dev/null @@ -1,19 +0,0 @@ -# Releases - -- `0.1.0` -> `0.1.1` is a patch release. - -- `0.1.0` -> `0.2.0` is a minor release. - -- `0.1.0` -> `1.0.0` is a major release. - -See details at [semver.org](https://semver.org/) - -## Release Cycle - -- Patch releases are released Tuesday per week. - -- Minor releases are released as needed. - -- Major releases are released as needed. - -See [milestones](https://github.com/web-infra-dev/rspack/milestones?direction=asc&sort=title&state=open) to follow our release plan. From e2b13ff101c6bcdc3092ede93aae2d2b64aa95ff Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 13 May 2024 19:35:38 +0800 Subject: [PATCH 062/107] docs: update outdated links and contents in dev guide (#6520) --- CONTRIBUTING.md | 9 ++++---- website/components/RandomMemberList.tsx | 2 +- website/docs/en/blog/announcing-0-4.mdx | 4 ++-- website/docs/en/config/experiments.mdx | 3 +-- .../contribute/architecture/builtin-plugin.md | 2 +- .../contribute/architecture/rspack-loader.md | 2 +- .../en/contribute/development/building.md | 7 ++----- .../en/contribute/development/debugging.md | 2 +- .../contribute/development/prerequisites.md | 20 +++++++++--------- website/docs/en/contribute/index.mdx | 21 +++++++++---------- website/docs/en/misc/planning/future.mdx | 2 +- website/docs/zh/blog/announcing-0-2.mdx | 2 +- website/docs/zh/blog/announcing-0-4.mdx | 4 ++-- website/docs/zh/config/experiments.mdx | 2 +- 14 files changed, 38 insertions(+), 44 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb8b4ccde4a3..fe6a2826cb2b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,22 +2,21 @@ Thank you for your interest in contributing to Rspack! There are many ways to contribute, and we appreciate all of them. -## About the [rspack-dev-guide] +## About the dev guide -Before starting your contribution, please take a moment and read the [rspack-dev-guide]. +Before starting your contribution, please take a moment and read the [dev guide](https://rspack.dev/contribute/). The development guide is a set of guidelines and instructions that help contributors understand how to work on Rspack. It covers everything from setting up the development environment to coding style and testing guidelines. The Rspack team believe that creating a development guide for Rspack is a great way to build a good relationship with the open source community. + By providing clarity and consistency, lowering barriers to entry, building trust, and encouraging collaboration, we can create a strong and thriving open source project that people will want to contribute to. ## Getting help -If you have any questions, -please do not hesitate to ask in either the [Discord][discord] support channel or on the [Github discussion board][github-discussion]. +If you have any questions, please do not hesitate to ask in either the [Discord][discord] support channel or on the [Github discussion board][github-discussion]. -[rspack-dev-guide]: https://web-infra-dev.github.io/rspack-dev-guide/ [discord]: https://discord.gg/79ZZ66GH9E [github-discussion]: https://github.com/web-infra-dev/rspack/discussions diff --git a/website/components/RandomMemberList.tsx b/website/components/RandomMemberList.tsx index d6a054b87f88..04d753fc8270 100644 --- a/website/components/RandomMemberList.tsx +++ b/website/components/RandomMemberList.tsx @@ -201,7 +201,7 @@ export const RandomContributorsList = () => { id: 'Boshen', avatar: 'https://avatars.githubusercontent.com/u/1430279?s=120&v=4', x: 'https://twitter.com/boshen_c', - desc: 'Rspack / Creator of Oxc', + desc: 'Rspack contributor / Creator of Oxc', }, ]; diff --git a/website/docs/en/blog/announcing-0-4.mdx b/website/docs/en/blog/announcing-0-4.mdx index 8d94e14b8538..3d84592cf9f4 100644 --- a/website/docs/en/blog/announcing-0-4.mdx +++ b/website/docs/en/blog/announcing-0-4.mdx @@ -183,9 +183,9 @@ In order to full migrate to Webpack's split chunks implementation, these fields ### Enable newResolver by default -[oxc_resolver](https://crates.io/crates/oxc_resolver) is now enabled by default. +New resolver is now enabled by default. -`oxc_resolver` is a module resolver written in Rust provided by the [oxc project](https://github.com/oxc-project/oxc). The new resolver has passed all of [enhanced-resolve](https://www.npmjs.com/package/enhanced-resolve)'s test suite. It is 5 times faster than previous implementation, and 28 times faster than enhanced-resolve. +The new resolver has passed all of [enhanced-resolve](https://www.npmjs.com/package/enhanced-resolve)'s test suite. It is 5 times faster than previous implementation, and 28 times faster than enhanced-resolve. The new resolver can be configured to read `tsconfig.json`'s `compilerOptions.paths` and `references` field and provides better support for nested path alias. See API [resolve.tsConfig](/config/resolve#resolvetsconfig) for details. diff --git a/website/docs/en/config/experiments.mdx b/website/docs/en/config/experiments.mdx index c3d78e958d8f..a0aeba64a50c 100644 --- a/website/docs/en/config/experiments.mdx +++ b/website/docs/en/config/experiments.mdx @@ -261,8 +261,7 @@ Used to control whether to enable Rspack future default options, check out the d - **Enabled by Default in Version:** v0.4.0 - **Removed in Version:** v0.5.0 -This feature enables the new resolver implementation provided by [oxc](https://github.com/web-infra-dev/oxc), -which is 5 times faster than the previous resolver implementation. +This feature enables the new resolver implementation. ```js title="rspack.config.js" module.exports = { diff --git a/website/docs/en/contribute/architecture/builtin-plugin.md b/website/docs/en/contribute/architecture/builtin-plugin.md index 87f7e47fb86c..7676619f6c46 100644 --- a/website/docs/en/contribute/architecture/builtin-plugin.md +++ b/website/docs/en/contribute/architecture/builtin-plugin.md @@ -1,4 +1,4 @@ -# Builtin Plugin +# Builtin plugin Builtin plugin uses [rspack_macros](https://github.com/web-infra-dev/rspack/tree/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_macros) to help you avoid writing boilerplate code, you can use [cargo-expand](https://github.com/dtolnay/cargo-expand) or [rust-analyzer expand macro](https://rust-analyzer.github.io/manual.html#expand-macro-recursively) to checkout the expanded code, and for developing/testing these macro, you can starts with [rspack_macros_test](https://github.com/web-infra-dev/rspack/tree/7cc39cc4bb6f73791a5bcb175137ffd84b105da5/crates/rspack_macros_test). diff --git a/website/docs/en/contribute/architecture/rspack-loader.md b/website/docs/en/contribute/architecture/rspack-loader.md index 7b9f47e96954..6fbb78d23e45 100644 --- a/website/docs/en/contribute/architecture/rspack-loader.md +++ b/website/docs/en/contribute/architecture/rspack-loader.md @@ -1,4 +1,4 @@ -# Rspack Loader +# Rspack loader ## Related PRs diff --git a/website/docs/en/contribute/development/building.md b/website/docs/en/contribute/development/building.md index 012d92dfd752..4da71b963735 100644 --- a/website/docs/en/contribute/development/building.md +++ b/website/docs/en/contribute/development/building.md @@ -7,14 +7,11 @@ Please see [prerequisites](./prerequisites) for setting up Rust and Node.js. Install Node.js dependencies via [pnpm](https://pnpm.io/). ```bash -# enable pnpm with corepack, only available on node >= `v14.19.0` +# enable pnpm with corepack corepack enable -# or install pnpm directly -npm install -g pnpm@8 - # Install dependencies -pnpm install +pnpm i ``` ## Building Rspack diff --git a/website/docs/en/contribute/development/debugging.md b/website/docs/en/contribute/development/debugging.md index 60aa89f661b1..ba2315dc8ccd 100644 --- a/website/docs/en/contribute/development/debugging.md +++ b/website/docs/en/contribute/development/debugging.md @@ -41,7 +41,7 @@ RSPACK_PROFILE='TRACE=layer=logger&filter=[compilation:chunk_asset{filename=".*\ NO_COLOR=1 RSPACK_PROFILE=TRACE=layer=logger rspack build ``` -### `oxc_resolver` +### Resolver `oxc_resolver` emits some tracing information for debugging purposes. diff --git a/website/docs/en/contribute/development/prerequisites.md b/website/docs/en/contribute/development/prerequisites.md index d210c6ce4c98..850600dbfae8 100644 --- a/website/docs/en/contribute/development/prerequisites.md +++ b/website/docs/en/contribute/development/prerequisites.md @@ -1,5 +1,7 @@ # Prerequisites +Rspack is built using [Rust](https://rust-lang.org/) and [NAPI-RS](https://napi.rs/), then released as [Node.js](https://nodejs.org/) packages. + ## Setup Rust - Install Rust using [rustup](https://rustup.rs/). @@ -9,24 +11,22 @@ ### Install Node.js -We recommend using the LTS version of Node.js 16. You can check your currently used Node.js version with the following command: +We recommend using the LTS version of Node.js 20. + +Check the current Node.js version with the following command: ```bash node -v -#v16.18.0 ``` If you do not have Node.js installed in your current environment, you can use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install it. -Here is an example of how to install the Node.js 16 LTS version via nvm: +Here is an example of how to install via nvm: ```bash -# Install the LTS version of Node.js 16 -nvm install 16 --lts - -# Make the newly installed Node.js 16 as the default version -nvm alias default 16 +# Install Node.js LTS +nvm install 20 --lts -# Switch to the newly installed Node.js 16 -nvm use 16 +# Switch to Node.js LTS +nvm use 20 ``` diff --git a/website/docs/en/contribute/index.mdx b/website/docs/en/contribute/index.mdx index 2f98f9a399a5..5655d32f118e 100644 --- a/website/docs/en/contribute/index.mdx +++ b/website/docs/en/contribute/index.mdx @@ -8,7 +8,7 @@ Every single contribution counts and helps us take Rspack to the next level. If you have any questions, please do not hesitate to ask in either the [Discord](https://discord.gg/79ZZ66GH9E) support channel or on the [Github discussion board](https://github.com/web-infra-dev/rspack/discussions). -## Minimal reproduction +### Minimal reproduction The [rspack repro template](https://github.com/web-infra-dev/rspack-repro) can be used to create a minimal reproducible example. @@ -23,7 +23,7 @@ This, in turn, increases the likelihood of getting a helpful and accurate respon It is important to note that an MRE should not include extraneous code related to unrelated functionality, and should instead focus solely on the problem at hand. -Please see also [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) from Stack Overflow. +> Please see also [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) from Stack Overflow. ## What should I work on? @@ -44,14 +44,12 @@ provides an overview of our progress and current goals. 1. [Fork](https://help.github.com/articles/fork-a-repo/) the Rspack repository into your own GitHub account. 2. [Clone](https://help.github.com/articles/cloning-a-repository/) the repository to your local. 3. Checkout a new branch from `main`. -4. Set up the development environment, you can read the "Setup Development Environment" section below to learn about it. +4. Set up the development environment, you can read the [Prerequisites](/contribute/development/prerequisites) section to learn about it. 5. If you've fixed a bug or added code that should be tested, then add some tests. -6. Make sure all the tests pass, you can read the "Testing" section below to learn about it. +6. Make sure all the tests pass, you can read the [Testing](/contribute/development/testing) section below to learn about it. 7. Run `pnpm run lint:js` and `pnpm run lint:rs` to check the code style. -8. If you've changed some Node.js packages, you should add a new [changeset](https://github.com/changesets/changesets). Run `pnpm run changeset`, select the changed packages and add the changeset info. -9. If you've changed some Rust packages, you should add a new [changeset](https://github.com/changesets/changesets) for `@rspack/binding` package. -10. Submit the Pull Request, make sure all CI runs pass. -11. The maintainers will review your Pull Request soon. +8. Submit the Pull Request, make sure all CI runs pass. +9. The maintainers will review your Pull Request soon. When submitting a Pull Request, please note the following: @@ -82,11 +80,12 @@ Your PR ## Other ways to contribute We are always looking for contributors, and that goes beyond just our main repository. + Check out these other ways to get involved and start making a difference today. -- The [documentation website](https://github.com/web-infra-dev/rspack-website) is at [web-infra-dev/rspack-website](https://github.com/web-infra-dev/rspack-website) -- This dev guide is at [web-infra-dev/rspack-dev-guide](https://github.com/web-infra-dev/rspack-dev-guide) -- Community packages is at [https://github.com/rspack-contrib](https://github.com/rspack-contrib) +- The documentation site is at [web-infra-dev/rspack/website](https://github.com/web-infra-dev/rspack/tree/main/website) +- The community packages are at [github.com/rspack-contrib](https://github.com/rspack-contrib) +- Welcome to add Rspack related projects to [awesome-rspack](https://github.com/web-infra-dev/awesome-rspack) --- diff --git a/website/docs/en/misc/planning/future.mdx b/website/docs/en/misc/planning/future.mdx index 969c2fd43b0b..d3cef0a6d89e 100644 --- a/website/docs/en/misc/planning/future.mdx +++ b/website/docs/en/misc/planning/future.mdx @@ -1,6 +1,6 @@ import { DeprecationTable } from '@components/DeprecationTable'; -# Future behavior & deprecation +# Future behavior ## Breaking Changes diff --git a/website/docs/zh/blog/announcing-0-2.mdx b/website/docs/zh/blog/announcing-0-2.mdx index db780ebc0d8b..b1fb506221f0 100644 --- a/website/docs/zh/blog/announcing-0-2.mdx +++ b/website/docs/zh/blog/announcing-0-2.mdx @@ -210,7 +210,7 @@ Rspack 0.2 已经完成了对 vue-loader 的兼容。对于 Vue3 项目,你可 ## 开发指南 Rspack 团队非常重视开源社区做出的宝贵贡献。我们致力于保持开放的态度,努力在每一步都让开源社区参与进来。 -这就是为什么我们目前正在制作一份全面的[开发指南](https://web-infra-dev.github.io/rspack-dev-guide/),为贡献者提供 Rspack 所有的开发文档。 +这就是为什么我们目前正在制作一份全面的[开发指南](https://rspack.dev/contribute/),为贡献者提供 Rspack 所有的开发文档。 当前版本的指南包含构建、测试、调试和分析 Rspack 的所有必要资料。此外,它还包括贡献流程,例如如何创建最小的[可重现示例](https://github.com/web-infra-dev/rspack-repro)。 将来,该指南还会概述 Rspack 的整体架构,使贡献者能够深入了解该项目的内部工作原理。 diff --git a/website/docs/zh/blog/announcing-0-4.mdx b/website/docs/zh/blog/announcing-0-4.mdx index c6eda000c874..198f444c04cc 100644 --- a/website/docs/zh/blog/announcing-0-4.mdx +++ b/website/docs/zh/blog/announcing-0-4.mdx @@ -167,9 +167,9 @@ module.exports = { ### 默认启用新的解析器 -[oxc_resolver](https://crates.io/crates/oxc_resolver) 现在默认启用。 +新版 resolver 现在默认启用。 -`oxc_resolver` 是由 [oxc 项目](https://github.com/oxc-project/oxc) 提供的用 Rust 编写的模块解析器。新解析器已通过了 [enhanced-resolve](https://www.npmjs.com/package/enhanced-resolve) 的所有测试套件。它比以前的实现快 5 倍,比 enhanced-resolve 快 28 倍。 +新解析器已通过了 [enhanced-resolve](https://www.npmjs.com/package/enhanced-resolve) 的所有测试套件。它比以前的实现快 5 倍,比 enhanced-resolve 快 28 倍。 新解析器可以配置为读取 `tsconfig.json` 的 `compilerOptions.paths` 和 `references` 字段,对 monorepo 的嵌套 alias 提供了内置支持。有关详细信息,请参阅 API [resolve.tsConfig](/config/resolve#resolvetsconfig)。 diff --git a/website/docs/zh/config/experiments.mdx b/website/docs/zh/config/experiments.mdx index dc9e380f3242..4b99175660b3 100644 --- a/website/docs/zh/config/experiments.mdx +++ b/website/docs/zh/config/experiments.mdx @@ -269,7 +269,7 @@ module.exports = { - **移除版本:** v0.5.0 -该功能将会开启 [oxc](https://github.com/web-infra-dev/oxc) 提供的 resolver,新的实现比旧版的 resolver 快了 5 倍。 +该功能将会开启新版 resolver,新的实现比旧版的 resolver 快了 5 倍。 ```js title="rspack.config.js" module.exports = { From 06e98c9e93b4944b9a560efba45af0eee75c44b1 Mon Sep 17 00:00:00 2001 From: kfll Date: Tue, 14 May 2024 11:45:03 +0800 Subject: [PATCH 063/107] fix(minimizer): resolve error in minimizing esm asset file (#6521) * fix: minimize js asset from a module package well * test: issue 6513 * style: fix clippy error --- crates/rspack_plugin_swc_js_minimizer/src/lib.rs | 12 ++++++++---- crates/rspack_plugin_swc_js_minimizer/src/minify.rs | 6 ++++-- .../tests/__snapshots__/Config.test.js.snap | 2 ++ .../optimization/minimizer-esm-asset/index.js | 8 ++++++++ .../minimizer-esm-asset/pkg/package.json | 3 +++ .../optimization/minimizer-esm-asset/pkg/pkg.js | 3 +++ .../minimizer-esm-asset/webpack.config.js | 8 ++++++++ 7 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/package.json create mode 100644 packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/pkg.js create mode 100644 packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/webpack.config.js diff --git a/crates/rspack_plugin_swc_js_minimizer/src/lib.rs b/crates/rspack_plugin_swc_js_minimizer/src/lib.rs index f42a94eb4e81..a5ef81dc63d1 100644 --- a/crates/rspack_plugin_swc_js_minimizer/src/lib.rs +++ b/crates/rspack_plugin_swc_js_minimizer/src/lib.rs @@ -226,11 +226,15 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> { let input_source_map = original_source.map(&MapOptions::default()); let is_module = if let Some(module) = self.options.module { - module + Some(module) } else if let Some(module) = original.info.javascript_module { - module + Some(module) + } else if filename.ends_with(".mjs") { + Some(true) + } else if filename.ends_with(".cjs") { + Some(false) } else { - filename.ends_with(".mjs") + None }; let js_minify_options = JsMinifyOptions { @@ -362,7 +366,7 @@ pub struct JsMinifyOptions { pub ecma: TerserEcmaVersion, pub keep_class_names: bool, pub keep_fn_names: bool, - pub module: bool, + pub module: Option, pub safari10: bool, pub toplevel: bool, pub source_map: BoolOrDataConfig, diff --git a/crates/rspack_plugin_swc_js_minimizer/src/minify.rs b/crates/rspack_plugin_swc_js_minimizer/src/minify.rs index 965b207d3c93..552317f7001f 100644 --- a/crates/rspack_plugin_swc_js_minimizer/src/minify.rs +++ b/crates/rspack_plugin_swc_js_minimizer/src/minify.rs @@ -151,7 +151,7 @@ pub fn minify( // top_level defaults to true if module is true // https://github.com/swc-project/swc/issues/2254 - if opts.module { + if opts.module.unwrap_or(false) { if let Some(opts) = &mut min_opts.compress { if opts.top_level.is_none() { opts.top_level = Some(TopLevelOptions { functions: true }); @@ -174,7 +174,9 @@ pub fn minify( decorators_before_export: true, ..Default::default() }), - IsModule::Bool(opts.module), + opts + .module + .map_or_else(|| IsModule::Unknown, IsModule::Bool), Some(&comments), ) .map_err(|errs| { diff --git a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap index 642191121590..e7f800dfc9a7 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap @@ -313,6 +313,8 @@ div { " `; +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 diff --git a/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/index.js b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/index.js new file mode 100644 index 000000000000..2b060c4ab6d9 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/index.js @@ -0,0 +1,8 @@ +import { fileURLToPath } from "node:url"; +import { readFileSync } from "node:fs"; + +it("minimizing an asset file of esm type should success", () => { + const worker = new URL("./pkg/pkg.js", import.meta.url); + const minifiedContent = readFileSync(fileURLToPath(worker), "utf-8"); + expect(minifiedContent).toMatchSnapshot(); +}); diff --git a/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/package.json b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/package.json new file mode 100644 index 000000000000..3dbc1ca591c0 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/pkg.js b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/pkg.js new file mode 100644 index 000000000000..447b1f814e5a --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/pkg/pkg.js @@ -0,0 +1,3 @@ +console.log(import.meta.url); + +export const a = 1; diff --git a/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/webpack.config.js b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/webpack.config.js new file mode 100644 index 000000000000..85bf9ae77036 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/optimization/minimizer-esm-asset/webpack.config.js @@ -0,0 +1,8 @@ +/** + * @type {import("@rspack/core").Configuration} + */ +module.exports = { + optimization: { + minimize: true + } +} From 7477a30480126c88d0eaf9acbb9f21d575c11e16 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Tue, 14 May 2024 14:32:20 +0800 Subject: [PATCH 064/107] test: add type of defaults cases (#6524) --- packages/rspack-test-tools/etc/api.md | 16 +++++++++++-- .../rspack-test-tools/src/case/defaults.ts | 24 +++++++++++++++---- .../src/processor/defaults.ts | 5 +++- .../rspack-test-tools/tests/Defaults.test.js | 2 +- .../tests/compilerCases/single-file.js | 20 ++++++++-------- .../cache/cache-filesystem-dev.js | 1 + .../defaultsCases/cache/cache-filesystem.js | 1 + .../tests/defaultsCases/cache/cache.js | 1 + .../tests/defaultsCases/cache/non-root.js | 1 + .../defaultsCases/config/array-defaults.js | 1 + .../defaultsCases/config/browserslist.js | 1 + .../defaultsCases/config/records-path.js | 1 + .../defaultsCases/experiments/async-wasm.js | 1 + .../defaultsCases/experiments/both-wasm.js | 1 + .../experiments/future-defaults-with-css.js | 1 + .../experiments/future-defaults.js | 17 ++++++------- .../experiments/output-module.js | 1 + .../defaultsCases/experiments/sync-wasm.js | 1 + .../tests/defaultsCases/filename/const.js | 1 + .../tests/defaultsCases/filename/function.js | 1 + .../tests/defaultsCases/library/library.js | 1 + .../defaultsCases/library/name-placeholder.js | 1 + .../library/name-root-placeholder.js | 1 + .../defaultsCases/library/placeholder.js | 1 + .../defaultsCases/library/root-placeholder.js | 1 + .../tests/defaultsCases/mode/development.js | 1 + .../tests/defaultsCases/mode/empty.js | 1 + .../tests/defaultsCases/mode/none.js | 1 + .../tests/defaultsCases/mode/production.js | 1 + .../tests/defaultsCases/mode/undefined.js | 1 + .../optimization/multi-runtime-chunk.js | 1 + .../optimization/single-runtime-chunk.js | 1 + .../optimization/true-runtime-chunk.js | 1 + .../defaultsCases/output/ecma-version.js | 1 + .../tests/defaultsCases/output/unique-name.js | 1 + .../tests/defaultsCases/stats/stats-false.js | 1 + .../tests/defaultsCases/stats/stats-string.js | 1 + .../tests/defaultsCases/stats/stats.js | 1 + .../defaultsCases/target_/electron-main.js | 1 + .../defaultsCases/target_/electron-preload.js | 1 + .../tests/defaultsCases/target_/node.js | 1 + .../tests/defaultsCases/target_/webworker.js | 1 + 42 files changed, 94 insertions(+), 26 deletions(-) diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index b6c2a216e46c..a6beaecc3106 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -84,7 +84,7 @@ export function createCompilerCase(name: string, src: string, dist: string, test export function createConfigCase(name: string, src: string, dist: string): void; // @public (undocumented) -export function createDefaultsCase(src: string): void; +export function createDefaultsCase(name: string, src: string): void; // @public (undocumented) export function createDiagnosticCase(name: string, src: string, dist: string): void; @@ -160,6 +160,13 @@ export function describeByWalk(testFile: string, createCase: (name: string, src: absoluteDist?: boolean; }): void; +// @public (undocumented) +class Diff { + constructor(value: string); + // (undocumented) + value: string; +} + // @public (undocumented) export class DiffComparator { constructor(options: IDiffComparatorOptions); @@ -382,7 +389,7 @@ export interface IDefaultsConfigProcessorOptions { // (undocumented) cwd?: string; // (undocumented) - diff: (diff: any, defaults: any) => Promise; + diff: (diff: jest.JestMatchers, defaults: jest.JestMatchers>) => Promise; // (undocumented) name: string; // (undocumented) @@ -1076,6 +1083,11 @@ export type TCompilerStatsCompilation = T extends ECompilerType.Rspack ? Stat // @public (undocumented) export type TCompilerTypeId = ECompilerType.Rspack | ECompilerType.Webpack | "common"; +// @public (undocumented) +export type TDefaultsCaseConfig = Omit & { + description: string; +}; + // @public (undocumented) export type TDiffStats = { root: string; diff --git a/packages/rspack-test-tools/src/case/defaults.ts b/packages/rspack-test-tools/src/case/defaults.ts index 397fd7a39d8c..b24ce4179292 100644 --- a/packages/rspack-test-tools/src/case/defaults.ts +++ b/packages/rspack-test-tools/src/case/defaults.ts @@ -1,7 +1,17 @@ import { TestContext } from "../test/context"; import path from "path"; import { ITestEnv, ITestProcessor } from "../type"; -import { DefaultsConfigTaskProcessor } from "../processor"; +import { + DefaultsConfigTaskProcessor, + IDefaultsConfigProcessorOptions +} from "../processor"; + +export type TDefaultsCaseConfig = Omit< + IDefaultsConfigProcessorOptions, + "name" +> & { + description: string; +}; const srcDir = path.resolve(__dirname, "../../tests/fixtures"); const distDir = path.resolve(__dirname, "../../tests/js/defaults"); @@ -23,9 +33,15 @@ async function run(name: string, processor: ITestProcessor) { } } -export function createDefaultsCase(src: string) { - const caseConfig = require(src); +export function createDefaultsCase(name: string, src: string) { + const caseConfig = require(src) as TDefaultsCaseConfig; it(`should generate the correct defaults from ${caseConfig.description}`, async () => { - await run(caseConfig.name, new DefaultsConfigTaskProcessor(caseConfig)); + await run( + name, + new DefaultsConfigTaskProcessor({ + name, + ...caseConfig + }) + ); }); } diff --git a/packages/rspack-test-tools/src/processor/defaults.ts b/packages/rspack-test-tools/src/processor/defaults.ts index 8492529a59a1..f2496b4eaaed 100644 --- a/packages/rspack-test-tools/src/processor/defaults.ts +++ b/packages/rspack-test-tools/src/processor/defaults.ts @@ -42,7 +42,10 @@ export interface IDefaultsConfigProcessorOptions { options?: (context: ITestContext) => TCompilerOptions; cwd?: string; name: string; - diff: (diff: any, defaults: any) => Promise; + diff: ( + diff: jest.JestMatchers, + defaults: jest.JestMatchers> + ) => Promise; } export class DefaultsConfigTaskProcessor extends SimpleTaskProcessor { diff --git a/packages/rspack-test-tools/tests/Defaults.test.js b/packages/rspack-test-tools/tests/Defaults.test.js index fd7fdddb763a..9cb95be9031d 100644 --- a/packages/rspack-test-tools/tests/Defaults.test.js +++ b/packages/rspack-test-tools/tests/Defaults.test.js @@ -19,7 +19,7 @@ describe("Base Defaults Snapshot", () => { }); describeByWalk(__filename, (name, src, dist) => { - createDefaultsCase(src); + createDefaultsCase(name, src); }, { type: "file", }); diff --git a/packages/rspack-test-tools/tests/compilerCases/single-file.js b/packages/rspack-test-tools/tests/compilerCases/single-file.js index 639d486d76a1..bc592fdbcb98 100644 --- a/packages/rspack-test-tools/tests/compilerCases/single-file.js +++ b/packages/rspack-test-tools/tests/compilerCases/single-file.js @@ -36,15 +36,15 @@ module.exports = { async check() { expect(error).toBeTruthy(); expect(error.toString()).toMatchInlineSnapshot(` - "Error: × Empty dependency: Expected a non-empty request - ╭─[1:1] - 1 │ module.exports = function b() { - 2 │ /* eslint-disable node/no-missing-require */ require(\\"\\"); - · ─────────── - 3 │ return \\"This is an empty dependency\\"; - 4 │ }; - ╰──── - " - `); + "Error: × Empty dependency: Expected a non-empty request + ╭─[1:1] + 1 │ module.exports = function b() { + 2 │ /* eslint-disable node/no-missing-require */ require(\\"\\"); + · ─────────── + 3 │ return \\"This is an empty dependency\\"; + 4 │ }; + ╰──── + " + `); } }; diff --git a/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem-dev.js b/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem-dev.js index 232b2c909fe9..adb4640f1481 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem-dev.js +++ b/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem-dev.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "cache filesystem development", options: () => ({ mode: "development", cache: { type: "filesystem" } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem.js b/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem.js index 7f3f71c870f5..20295cf28c99 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem.js +++ b/packages/rspack-test-tools/tests/defaultsCases/cache/cache-filesystem.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "cache filesystem", options: () => ({ cache: { type: "filesystem" } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/cache/cache.js b/packages/rspack-test-tools/tests/defaultsCases/cache/cache.js index 04458e4daa01..86e075b802df 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/cache/cache.js +++ b/packages/rspack-test-tools/tests/defaultsCases/cache/cache.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "cache true", options: () => ({ cache: true }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/cache/non-root.js b/packages/rspack-test-tools/tests/defaultsCases/cache/non-root.js index 3fb48b53ca99..070b094f825a 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/cache/non-root.js +++ b/packages/rspack-test-tools/tests/defaultsCases/cache/non-root.js @@ -1,4 +1,5 @@ const path = require("path"); +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "non-root directory", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/config/array-defaults.js b/packages/rspack-test-tools/tests/defaultsCases/config/array-defaults.js index 685aab6977f7..928770235ceb 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/config/array-defaults.js +++ b/packages/rspack-test-tools/tests/defaultsCases/config/array-defaults.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "array defaults", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js b/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js index dccb149ec2d1..dd5286072e3f 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js +++ b/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js @@ -1,4 +1,5 @@ const path = require("path"); +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "browserslist", options: context => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/config/records-path.js b/packages/rspack-test-tools/tests/defaultsCases/config/records-path.js index baa842748134..d7e3100208c4 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/config/records-path.js +++ b/packages/rspack-test-tools/tests/defaultsCases/config/records-path.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "records", options: () => ({ recordsPath: "some-path" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/async-wasm.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/async-wasm.js index 30e3474439b4..bd02a28f9a67 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/async-wasm.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/async-wasm.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "async wasm", options: () => ({ experiments: { asyncWebAssembly: true } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/both-wasm.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/both-wasm.js index d19325e7ccc0..c85b6351a687 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/both-wasm.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/both-wasm.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "both wasm", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js index 2a1f24f22417..c4a2087cab19 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "experiments.futureDefaults w/ experiments.css disabled", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults.js index 3cb23e15eab5..9b15f1a2f20d 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults.js @@ -1,12 +1,13 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { - description: "experiments.futureDefaults", - options: () => ({ - experiments: { - futureDefaults: true - } - }), - diff: e => - e.toMatchInlineSnapshot(` + description: "experiments.futureDefaults", + options: () => ({ + experiments: { + futureDefaults: true + } + }), + diff: e => + e.toMatchInlineSnapshot(` - Expected + Received diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js index e1d43a5776ae..7abe74e79755 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "output module", options: () => ({ experiments: { outputModule: true } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/sync-wasm.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/sync-wasm.js index 2388653043ac..7f4c5819fb16 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/sync-wasm.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/sync-wasm.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "sync wasm", options: () => ({ experiments: { syncWebAssembly: true } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/filename/const.js b/packages/rspack-test-tools/tests/defaultsCases/filename/const.js index 39df5e82fea3..ad743b4030b0 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/filename/const.js +++ b/packages/rspack-test-tools/tests/defaultsCases/filename/const.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "const filename", options: () => ({ output: { filename: "bundle.js" } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/filename/function.js b/packages/rspack-test-tools/tests/defaultsCases/filename/function.js index 55d9c945c487..8eb12e24bd71 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/filename/function.js +++ b/packages/rspack-test-tools/tests/defaultsCases/filename/function.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "function filename", options: () => ({ output: { filename: () => "bundle.js" } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/library/library.js b/packages/rspack-test-tools/tests/defaultsCases/library/library.js index d309541a49da..270873a35f0a 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/library/library.js +++ b/packages/rspack-test-tools/tests/defaultsCases/library/library.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "library", options: () => ({ output: { library: ["myLib", "awesome"] } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/library/name-placeholder.js b/packages/rspack-test-tools/tests/defaultsCases/library/name-placeholder.js index b6dfd56abfd6..d620651a67e2 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/library/name-placeholder.js +++ b/packages/rspack-test-tools/tests/defaultsCases/library/name-placeholder.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "library.name contains [name] placeholder", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/library/name-root-placeholder.js b/packages/rspack-test-tools/tests/defaultsCases/library/name-root-placeholder.js index c7c992ade4a3..a8106373b32e 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/library/name-root-placeholder.js +++ b/packages/rspack-test-tools/tests/defaultsCases/library/name-root-placeholder.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "library.name.root contains escaped placeholder", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/library/placeholder.js b/packages/rspack-test-tools/tests/defaultsCases/library/placeholder.js index 21bc64406ab2..791758d7764a 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/library/placeholder.js +++ b/packages/rspack-test-tools/tests/defaultsCases/library/placeholder.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "library contains [name] placeholder", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/library/root-placeholder.js b/packages/rspack-test-tools/tests/defaultsCases/library/root-placeholder.js index 0c55c11d6bdd..c158f4786388 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/library/root-placeholder.js +++ b/packages/rspack-test-tools/tests/defaultsCases/library/root-placeholder.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "library.name.root contains [name] placeholder", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/development.js b/packages/rspack-test-tools/tests/defaultsCases/mode/development.js index ce1bf4ec7694..21e77726c78a 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/development.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/development.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "development", options: () => ({ mode: "development" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/empty.js b/packages/rspack-test-tools/tests/defaultsCases/mode/empty.js index 1df5f24aed28..a6bf6e1e77d7 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/empty.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/empty.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "empty config", options: () => ({}), diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/none.js b/packages/rspack-test-tools/tests/defaultsCases/mode/none.js index 59f95c3f8db2..4b3fe8610865 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/none.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/none.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "none mode", options: () => ({ mode: "none" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/production.js b/packages/rspack-test-tools/tests/defaultsCases/mode/production.js index 5b1bbc752979..da347f9187a9 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/production.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/production.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "production", options: () => ({ mode: "production" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js b/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js index d54fd1c441e6..f5dbbf6f6d94 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "no mode provided", options: () => ({ mode: undefined }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/optimization/multi-runtime-chunk.js b/packages/rspack-test-tools/tests/defaultsCases/optimization/multi-runtime-chunk.js index bf7681088f40..af278618c3fa 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/optimization/multi-runtime-chunk.js +++ b/packages/rspack-test-tools/tests/defaultsCases/optimization/multi-runtime-chunk.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "multiple runtimeChunk", options: () => ({ optimization: { runtimeChunk: "multiple" } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/optimization/single-runtime-chunk.js b/packages/rspack-test-tools/tests/defaultsCases/optimization/single-runtime-chunk.js index f5ffcf651cc8..19f3d4c03568 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/optimization/single-runtime-chunk.js +++ b/packages/rspack-test-tools/tests/defaultsCases/optimization/single-runtime-chunk.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "single runtimeChunk", options: () => ({ optimization: { runtimeChunk: "single" } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/optimization/true-runtime-chunk.js b/packages/rspack-test-tools/tests/defaultsCases/optimization/true-runtime-chunk.js index 22a8575ed8f5..f415f15c9188 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/optimization/true-runtime-chunk.js +++ b/packages/rspack-test-tools/tests/defaultsCases/optimization/true-runtime-chunk.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "true runtimeChunk", options: () => ({ optimization: { runtimeChunk: true } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/output/ecma-version.js b/packages/rspack-test-tools/tests/defaultsCases/output/ecma-version.js index 61cd34d58101..3f47d1be621e 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/output/ecma-version.js +++ b/packages/rspack-test-tools/tests/defaultsCases/output/ecma-version.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "ecmaVersion", options: () => ({ output: { ecmaVersion: 2020 } }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/output/unique-name.js b/packages/rspack-test-tools/tests/defaultsCases/output/unique-name.js index cac825a266fa..0f1b9e1e55a1 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/output/unique-name.js +++ b/packages/rspack-test-tools/tests/defaultsCases/output/unique-name.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "uniqueName", options: () => ({ diff --git a/packages/rspack-test-tools/tests/defaultsCases/stats/stats-false.js b/packages/rspack-test-tools/tests/defaultsCases/stats/stats-false.js index 01c6b676c15b..7c0c14bc472c 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/stats/stats-false.js +++ b/packages/rspack-test-tools/tests/defaultsCases/stats/stats-false.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "stats false", options: () => ({ stats: false }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/stats/stats-string.js b/packages/rspack-test-tools/tests/defaultsCases/stats/stats-string.js index bf27a0965200..ffd9092c8cad 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/stats/stats-string.js +++ b/packages/rspack-test-tools/tests/defaultsCases/stats/stats-string.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "stats string", options: () => ({ stats: "minimal" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/stats/stats.js b/packages/rspack-test-tools/tests/defaultsCases/stats/stats.js index a618ac51376c..ee46ef39e865 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/stats/stats.js +++ b/packages/rspack-test-tools/tests/defaultsCases/stats/stats.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "stats true", options: () => ({ stats: true }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js index 4c6583ef75a4..d256483984dd 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "target electron-main", options: () => ({ target: "electron-main" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js index accac388d3d9..2938c13cb88c 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "target electron-preload", options: () => ({ target: "electron-preload" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/node.js b/packages/rspack-test-tools/tests/defaultsCases/target_/node.js index cebe03fbb651..ec7655bbc442 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/node.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/node.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "target node", options: () => ({ target: "node" }), diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js b/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js index a6d79f9043c3..a70fb15e1c3a 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js @@ -1,3 +1,4 @@ +/** @type {import('../../..').TDefaultsCaseConfig} */ module.exports = { description: "target webworker", options: () => ({ target: "webworker" }), From 4c3953fe7d49bb92c92ad15bac605f975648a95d Mon Sep 17 00:00:00 2001 From: jinrui Date: Tue, 14 May 2024 15:34:31 +0800 Subject: [PATCH 065/107] refactor: make `make_artifact` as raw data (#6526) * fix: remove compilation.entry_module_identifiers * feat: compilaiton.*_dependencies only save temp deps --- .../rspack_binding_values/src/compilation.rs | 12 +-- .../rspack_core/src/compiler/compilation.rs | 74 ++++++++++++++++++- crates/rspack_core/src/compiler/hmr.rs | 13 ---- crates/rspack_core/src/compiler/make/mod.rs | 45 ++--------- .../src/compiler/module_executor/mod.rs | 19 +---- .../rspack_core/src/tree_shaking/optimizer.rs | 8 +- .../src/plugin/side_effects_flag_plugin.rs | 7 +- 7 files changed, 89 insertions(+), 89 deletions(-) diff --git a/crates/rspack_binding_values/src/compilation.rs b/crates/rspack_binding_values/src/compilation.rs index f8ae66a72fbc..eacd7f673141 100644 --- a/crates/rspack_binding_values/src/compilation.rs +++ b/crates/rspack_binding_values/src/compilation.rs @@ -279,8 +279,7 @@ impl JsCompilation { pub fn get_file_dependencies(&self) -> Vec { self .0 - .file_dependencies - .iter() + .file_dependencies() .map(|i| i.to_string_lossy().to_string()) .collect() } @@ -289,8 +288,7 @@ impl JsCompilation { pub fn get_context_dependencies(&self) -> Vec { self .0 - .context_dependencies - .iter() + .context_dependencies() .map(|i| i.to_string_lossy().to_string()) .collect() } @@ -299,8 +297,7 @@ impl JsCompilation { pub fn get_missing_dependencies(&self) -> Vec { self .0 - .missing_dependencies - .iter() + .missing_dependencies() .map(|i| i.to_string_lossy().to_string()) .collect() } @@ -309,8 +306,7 @@ impl JsCompilation { pub fn get_build_dependencies(&self) -> Vec { self .0 - .build_dependencies - .iter() + .build_dependencies() .map(|i| i.to_string_lossy().to_string()) .collect() } diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index fdc891c257e5..fd6cffe6b86d 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -157,7 +157,6 @@ pub struct Compilation { pub loader_resolver_factory: Arc, pub named_chunks: HashMap, pub(crate) named_chunk_groups: HashMap, - pub entry_module_identifiers: IdentifierSet, /// Collecting all used export symbol pub used_symbol_ref: HashSet, /// Collecting all module that need to skip in tree-shaking ast modification phase @@ -247,7 +246,6 @@ impl Compilation { loader_resolver_factory, named_chunks: Default::default(), named_chunk_groups: Default::default(), - entry_module_identifiers: IdentifierSet::default(), used_symbol_ref: HashSet::default(), bailout_module_identifiers: IdentifierMap::default(), @@ -316,6 +314,74 @@ impl Compilation { } } + pub fn file_dependencies(&self) -> impl Iterator { + self + .make_artifact + .file_dependencies + .files() + .chain( + self + .module_executor + .as_ref() + .expect("should have module_executor") + .make_artifact + .file_dependencies + .files(), + ) + .chain(&self.file_dependencies) + } + + pub fn context_dependencies(&self) -> impl Iterator { + self + .make_artifact + .context_dependencies + .files() + .chain( + self + .module_executor + .as_ref() + .expect("should have module_executor") + .make_artifact + .context_dependencies + .files(), + ) + .chain(&self.context_dependencies) + } + + pub fn missing_dependencies(&self) -> impl Iterator { + self + .make_artifact + .missing_dependencies + .files() + .chain( + self + .module_executor + .as_ref() + .expect("should have module_executor") + .make_artifact + .missing_dependencies + .files(), + ) + .chain(&self.missing_dependencies) + } + + pub fn build_dependencies(&self) -> impl Iterator { + self + .make_artifact + .build_dependencies + .files() + .chain( + self + .module_executor + .as_ref() + .expect("should have module_executor") + .make_artifact + .build_dependencies + .files(), + ) + .chain(&self.build_dependencies) + } + // TODO move out from compilation pub fn get_import_var(&self, dep_id: &DependencyId) -> String { let module_graph = self.get_module_graph(); @@ -898,8 +964,8 @@ impl Compilation { result } - pub fn entry_modules(&self) -> impl Iterator { - self.entry_module_identifiers.clone().into_iter() + pub fn entry_modules(&self) -> IdentifierSet { + self.make_artifact.entry_module_identifiers.clone() } pub fn entrypoint_by_name(&self, name: &str) -> &Entrypoint { diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index 30679f3915b3..377050391cab 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -96,19 +96,6 @@ where new_compilation.global_entry = std::mem::take(&mut self.compilation.global_entry); new_compilation.lazy_visit_modules = std::mem::take(&mut self.compilation.lazy_visit_modules); - new_compilation.file_dependencies = std::mem::take(&mut self.compilation.file_dependencies); - new_compilation.context_dependencies = - std::mem::take(&mut self.compilation.context_dependencies); - new_compilation.missing_dependencies = - std::mem::take(&mut self.compilation.missing_dependencies); - new_compilation.build_dependencies = - std::mem::take(&mut self.compilation.build_dependencies); - // tree shaking usage start - new_compilation.entry_module_identifiers = - std::mem::take(&mut self.compilation.entry_module_identifiers); - new_compilation.bailout_module_identifiers = - std::mem::take(&mut self.compilation.bailout_module_identifiers); - // tree shaking usage end // seal stage used new_compilation.code_splitting_cache = diff --git a/crates/rspack_core/src/compiler/make/mod.rs b/crates/rspack_core/src/compiler/make/mod.rs index 9eadcb2621e6..ad4a4ba7c674 100644 --- a/crates/rspack_core/src/compiler/make/mod.rs +++ b/crates/rspack_core/src/compiler/make/mod.rs @@ -18,20 +18,20 @@ use crate::{ #[derive(Debug, Default)] pub struct MakeArtifact { - pub module_graph_partial: ModuleGraphPartial, + // should be reset when make pub make_failed_dependencies: HashSet, pub make_failed_module: HashSet, pub diagnostics: Vec, + pub has_module_graph_change: bool, + pub module_graph_partial: ModuleGraphPartial, entry_dependencies: HashSet, - entry_module_identifiers: IdentifierSet, + pub entry_module_identifiers: IdentifierSet, pub optimize_analyze_result_map: IdentifierMap, pub file_dependencies: FileCounter, pub context_dependencies: FileCounter, pub missing_dependencies: FileCounter, pub build_dependencies: FileCounter, - - pub has_module_graph_change: bool, } impl MakeArtifact { @@ -50,34 +50,6 @@ impl MakeArtifact { &mut self.module_graph_partial } - // TODO remove it - fn move_data_from_compilation(&mut self, compilation: &mut Compilation) { - self.entry_module_identifiers = std::mem::take(&mut compilation.entry_module_identifiers); - // self.file_dependencies = std::mem::take(&mut compilation.file_dependencies); - // self.context_dependencies = std::mem::take(&mut compilation.context_dependencies); - // self.missing_dependencies = std::mem::take(&mut compilation.missing_dependencies); - // self.build_dependencies = std::mem::take(&mut compilation.build_dependencies); - } - - // TODO remove it - fn move_data_to_compilation(&mut self, compilation: &mut Compilation) { - compilation.entry_module_identifiers = std::mem::take(&mut self.entry_module_identifiers); - compilation - .file_dependencies - .extend(self.file_dependencies.files().cloned()); - compilation - .context_dependencies - .extend(self.context_dependencies.files().cloned()); - compilation - .missing_dependencies - .extend(self.missing_dependencies.files().cloned()); - compilation - .build_dependencies - .extend(self.build_dependencies.files().cloned()); - - compilation.push_batch_diagnostic(std::mem::take(&mut self.diagnostics)); - } - fn revoke_modules(&mut self, ids: HashSet) -> Vec { let mut module_graph = ModuleGraph::new(vec![], Some(&mut self.module_graph_partial)); let mut res = vec![]; @@ -150,8 +122,6 @@ pub fn make_module_graph( artifact.diagnostics = Default::default(); artifact.has_module_graph_change = false; - artifact.move_data_from_compilation(compilation); - artifact = update_module_graph_with_artifact(compilation, artifact, params)?; if compilation.options.builtins.tree_shaking.enable() { @@ -159,7 +129,7 @@ pub fn make_module_graph( compilation.bailout_module_identifiers = calc_bailout_module_identifiers(&module_graph); } - artifact.move_data_to_compilation(compilation); + compilation.push_batch_diagnostic(std::mem::take(&mut artifact.diagnostics)); Ok(artifact) } @@ -169,7 +139,6 @@ pub async fn update_module_graph( ) -> Result<()> { let mut artifact = MakeArtifact::default(); compilation.swap_make_artifact(&mut artifact); - artifact.move_data_from_compilation(compilation); artifact = update_module_graph_with_artifact(compilation, artifact, params)?; @@ -178,7 +147,7 @@ pub async fn update_module_graph( compilation.bailout_module_identifiers = calc_bailout_module_identifiers(&module_graph); } - artifact.move_data_to_compilation(compilation); + compilation.push_batch_diagnostic(std::mem::take(&mut artifact.diagnostics)); compilation.swap_make_artifact(&mut artifact); Ok(()) } @@ -192,10 +161,10 @@ pub fn update_module_graph_with_artifact( let build_dependencies = cutout.cutout_artifact(&mut artifact, params); artifact = repair(compilation, artifact, build_dependencies)?; cutout.fix_artifact(&mut artifact); - Ok(artifact) } +// TODO remove after remove old_treeshaking fn calc_bailout_module_identifiers(module_graph: &ModuleGraph) -> IdentifierMap { // Avoid to introduce too much overhead, // until we find a better way to align with webpack hmr behavior diff --git a/crates/rspack_core/src/compiler/module_executor/mod.rs b/crates/rspack_core/src/compiler/module_executor/mod.rs index 0bfce4182fb5..3415a80aaab9 100644 --- a/crates/rspack_core/src/compiler/module_executor/mod.rs +++ b/crates/rspack_core/src/compiler/module_executor/mod.rs @@ -29,7 +29,7 @@ use crate::{ #[derive(Debug, Default)] pub struct ModuleExecutor { request_dep_map: DashMap, - make_artifact: MakeArtifact, + pub make_artifact: MakeArtifact, event_sender: Option>, stop_receiver: Option>, @@ -40,9 +40,7 @@ impl ModuleExecutor { pub async fn hook_before_make(&mut self, compilation: &Compilation) { let mut make_artifact = std::mem::take(&mut self.make_artifact); let mut params = vec![]; - if !compilation.modified_files.is_empty() { - params.push(MakeParam::ModifiedFiles(compilation.modified_files.clone())); - } + params.push(MakeParam::ModifiedFiles(compilation.modified_files.clone())); if !compilation.removed_files.is_empty() { params.push(MakeParam::RemovedFiles(compilation.removed_files.clone())); } @@ -107,19 +105,6 @@ impl ModuleExecutor { let diagnostics = std::mem::take(&mut self.make_artifact.diagnostics); compilation.push_batch_diagnostic(diagnostics); - - compilation - .file_dependencies - .extend(self.make_artifact.file_dependencies.files().cloned()); - compilation - .context_dependencies - .extend(self.make_artifact.context_dependencies.files().cloned()); - compilation - .missing_dependencies - .extend(self.make_artifact.missing_dependencies.files().cloned()); - compilation - .build_dependencies - .extend(self.make_artifact.build_dependencies.files().cloned()); } #[allow(clippy::too_many_arguments)] diff --git a/crates/rspack_core/src/tree_shaking/optimizer.rs b/crates/rspack_core/src/tree_shaking/optimizer.rs index a51070d46177..880f454044f8 100644 --- a/crates/rspack_core/src/tree_shaking/optimizer.rs +++ b/crates/rspack_core/src/tree_shaking/optimizer.rs @@ -143,7 +143,7 @@ impl<'a> CodeSizeOptimizer<'a> { let forced_side_effects = !side_effects_options || self .compilation - .entry_module_identifiers + .entry_modules() .contains(&analyze_result.module_identifier); // side_effects: true if forced_side_effects @@ -430,7 +430,7 @@ impl<'a> CodeSizeOptimizer<'a> { side_effects_free: self.side_effects_free_modules.contains(&module_identifier), is_entry: self .compilation - .entry_module_identifiers + .entry_modules() .contains(&module_identifier), module_identifier, }; @@ -590,9 +590,9 @@ impl<'a> CodeSizeOptimizer<'a> { mut side_effect_map: IdentifierMap, ) -> IdentifierSet { // normalize side_effects, there are two kinds of `side_effects` one from configuration and another from analyze ast - for entry_module_ident in self.compilation.entry_module_identifiers.iter() { + for entry_module_ident in self.compilation.entry_modules() { Self::normalize_side_effects( - *entry_module_ident, + entry_module_ident, &self.compilation.get_module_graph(), &mut IdentifierSet::default(), &mut side_effect_map, diff --git a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs index cb4f10946527..9f4fc0095f40 100644 --- a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs @@ -549,7 +549,7 @@ async fn nmf_module( #[plugin_hook(CompilationOptimizeDependencies for SideEffectsFlagPlugin)] fn optimize_dependencies(&self, compilation: &mut Compilation) -> Result> { - let entries = compilation.entry_modules().collect::>(); + let entries = compilation.entry_modules(); let level_order_module_identifier = get_level_order_module_ids(&compilation.get_module_graph(), entries); for module_identifier in level_order_module_identifier { @@ -693,10 +693,7 @@ impl Plugin for SideEffectsFlagPlugin { } } -fn get_level_order_module_ids( - mg: &ModuleGraph, - entries: Vec, -) -> Vec { +fn get_level_order_module_ids(mg: &ModuleGraph, entries: IdentifierSet) -> Vec { let mut res = vec![]; let mut visited = IdentifierSet::default(); for entry in entries { From 7200a768afe7b14a924798e97524679a4c5ac35e Mon Sep 17 00:00:00 2001 From: jinrui Date: Tue, 14 May 2024 15:50:59 +0800 Subject: [PATCH 066/107] fix: make entry add include dependencies (#6527) * fix: make entry add include dependency * fix: compilation.*entries memory leak --- crates/rspack_core/src/compiler/hmr.rs | 2 -- crates/rspack_core/src/compiler/make/mod.rs | 4 ++-- crates/rspack_core/src/options/entry.rs | 9 +++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/rspack_core/src/compiler/hmr.rs b/crates/rspack_core/src/compiler/hmr.rs index 377050391cab..80fcf7c7b918 100644 --- a/crates/rspack_core/src/compiler/hmr.rs +++ b/crates/rspack_core/src/compiler/hmr.rs @@ -92,8 +92,6 @@ where self .compilation .swap_make_artifact_with_compilation(&mut new_compilation); - new_compilation.entries = std::mem::take(&mut self.compilation.entries); - new_compilation.global_entry = std::mem::take(&mut self.compilation.global_entry); new_compilation.lazy_visit_modules = std::mem::take(&mut self.compilation.lazy_visit_modules); diff --git a/crates/rspack_core/src/compiler/make/mod.rs b/crates/rspack_core/src/compiler/make/mod.rs index ad4a4ba7c674..6b89df5386f6 100644 --- a/crates/rspack_core/src/compiler/make/mod.rs +++ b/crates/rspack_core/src/compiler/make/mod.rs @@ -97,8 +97,8 @@ pub fn make_module_graph( compilation .entries .values() - .flat_map(|item| &item.dependencies) - .chain(&compilation.global_entry.dependencies) + .flat_map(|item| item.all_dependencies()) + .chain(compilation.global_entry.all_dependencies()) .cloned() .collect(), )); diff --git a/crates/rspack_core/src/options/entry.rs b/crates/rspack_core/src/options/entry.rs index 33b81867aeb2..497a3cca635c 100644 --- a/crates/rspack_core/src/options/entry.rs +++ b/crates/rspack_core/src/options/entry.rs @@ -23,3 +23,12 @@ pub struct EntryData { pub include_dependencies: Vec, pub options: EntryOptions, } + +impl EntryData { + pub fn all_dependencies(&self) -> impl Iterator { + self + .dependencies + .iter() + .chain(self.include_dependencies.iter()) + } +} From c9bc42d8ec709cac4ad087a9648d8594a22d1717 Mon Sep 17 00:00:00 2001 From: Fy <1114550440@qq.com> Date: Tue, 14 May 2024 16:43:23 +0800 Subject: [PATCH 067/107] fix: make code-splitting deterministic (#6508) --- .../src/build_chunk_graph/code_splitter.rs | 125 ++++++++++++++---- .../make/cutout/has_module_graph_change.rs | 32 ++++- crates/rspack_core/src/exports_info.rs | 2 +- .../plugin/flag_dependency_exports_plugin.rs | 11 +- .../src/module_group.rs | 32 +++-- .../src/plugin/module_group.rs | 19 ++- 6 files changed, 162 insertions(+), 59 deletions(-) diff --git a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs index 4dbac5afb603..56d145b0f49a 100644 --- a/crates/rspack_core/src/build_chunk_graph/code_splitter.rs +++ b/crates/rspack_core/src/build_chunk_graph/code_splitter.rs @@ -1,5 +1,5 @@ use std::cell::RefCell; -use std::hash::BuildHasherDefault; +use std::hash::{BuildHasherDefault, Hash}; use std::sync::Arc; use indexmap::{IndexMap, IndexSet}; @@ -28,15 +28,15 @@ pub struct ChunkGroupInfo { pub min_available_modules_init: bool, pub available_modules_to_be_merged: Vec, - pub skipped_items: HashSet, + pub skipped_items: IndexSet, pub skipped_module_connections: IndexSet<(ModuleIdentifier, Vec), BuildHasherDefault>, // set of children chunk groups, that will be revisited when available_modules shrink - pub children: HashSet, + pub children: IndexSet, // set of chunk groups that are the source for min_available_modules - pub available_sources: HashSet, + pub available_sources: IndexSet, // set of chunk groups which depend on the this chunk group as available_source - pub available_children: HashSet, + pub available_children: IndexSet, // set of modules available including modules from this chunk group // A derived attribute, therefore utilizing interior mutability to manage updates @@ -114,11 +114,78 @@ impl From> for OptionalRuntimeSpec { type CgiUkey = Ukey; -type BlockModulesRuntimeMap = HashMap< +type BlockModulesRuntimeMap = IndexMap< OptionalRuntimeSpec, - HashMap)>>, + IndexMap< + DependenciesBlockIdentifier, + Vec<(ModuleIdentifier, ConnectionState, Vec)>, + >, >; +// Queue is used to debug code-splitting, +// we store every op. +// #[derive(Default)] +// struct Queue { +// inner: Vec, +// records: Vec, +// } + +// impl Queue { +// fn push(&mut self, item: QueueAction) { +// self.inner.push(item); +// } + +// fn len(&self) -> usize { +// self.inner.len() +// } + +// fn reverse(&mut self) { +// self.inner.reverse(); +// } + +// fn is_empty(&self) -> bool { +// self.inner.is_empty() +// } + +// fn pop(&mut self) -> Option { +// let item = self.inner.pop(); +// if let Some(item) = &item { +// let res = match item { +// QueueAction::AddAndEnterEntryModule(item) => { +// format!("add_enter_entry: {}", item.module) +// } +// QueueAction::AddAndEnterModule(item) => { +// format!("add_enter: {}|{:?}", item.module, item.orig) +// } +// QueueAction::_EnterModule(_) => todo!(), +// QueueAction::ProcessBlock(item) => { +// format!("process_block: {:?}", item.block) +// } +// QueueAction::ProcessEntryBlock(item) => { +// format!("process_entry_block: {:?}", item.block,) +// } +// QueueAction::LeaveModule(item) => { +// format!("leave: {}", item.module,) +// } +// }; + +// let cwd = std::env::current_dir() +// .unwrap() +// .parent() +// .unwrap() +// .parent() +// .unwrap() +// .to_string_lossy() +// .to_string(); +// self +// .records +// .push(LOC_RE.replace(&res, "").replace(&cwd, "").to_string()); +// } + +// item +// } +// } + pub(super) struct CodeSplitter<'me> { chunk_group_info_map: HashMap, chunk_group_infos: Database, @@ -130,10 +197,10 @@ pub(super) struct CodeSplitter<'me> { next_chunk_group_index: u32, queue: Vec, queue_delayed: Vec, - queue_connect: HashMap>, - chunk_groups_for_combining: HashSet, - outdated_chunk_group_info: HashSet, - chunk_groups_for_merging: HashSet, + queue_connect: IndexMap>, + chunk_groups_for_combining: IndexSet, + outdated_chunk_group_info: IndexSet, + chunk_groups_for_merging: IndexSet, block_chunk_groups: HashMap, named_chunk_groups: HashMap, named_async_entrypoints: HashMap, @@ -239,10 +306,14 @@ impl<'me> CodeSplitter<'me> { fn prepare_input_entrypoints_and_modules( &mut self, - ) -> Result>> { - let mut input_entrypoints_and_modules: HashMap> = - HashMap::default(); - let mut assign_depths_map = HashMap::default(); + ) -> Result>> { + let mut input_entrypoints_and_modules: IndexMap> = + IndexMap::default(); + let mut assign_depths_map: std::collections::HashMap< + rspack_identifier::Identifier, + usize, + BuildHasherDefault, + > = HashMap::default(); let entries = self.compilation.entries.clone(); for (name, entry_data) in entries { @@ -389,7 +460,7 @@ impl<'me> CodeSplitter<'me> { self.compilation.get_module_graph_mut().set_depth(k, v); } - let mut runtime_chunks = HashSet::default(); + let mut runtime_chunks = IndexSet::::default(); let mut runtime_errors = vec![]; for (name, entry_data) in &self.compilation.entries { let options = &entry_data.options; @@ -545,7 +616,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on // This means no module is added until other sets are merged into // this min_available_modules (by the parent entrypoints) let chunk_group_info = self.chunk_group_infos.expect_get_mut(cgi); - chunk_group_info.skipped_items = HashSet::from_iter(modules); + chunk_group_info.skipped_items = IndexSet::from_iter(modules); self.chunk_groups_for_combining.insert(*cgi); } else { // The application may start here: We start with an empty list of available modules @@ -666,7 +737,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on .copied() .collect::>(); - let mut visited = HashSet::default(); + let mut visited = IndexSet::default(); for root in blocks { let mut ctx = (0, 0, Default::default()); @@ -702,8 +773,8 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on &mut self, module_identifier: ModuleIdentifier, runtime: &RuntimeSpec, - visited: &mut HashSet, - ctx: &mut (usize, usize, HashMap), + visited: &mut IndexSet, + ctx: &mut (usize, usize, IndexMap), ) { let block_modules = self.get_block_modules(module_identifier.into(), Some(runtime)); if visited.contains(&module_identifier) { @@ -1230,7 +1301,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on ) -> Vec<(ModuleIdentifier, ConnectionState, Vec)> { if let Some(modules) = self .block_modules_runtime_map - .get(&runtime.cloned().into()) + .get::(&runtime.cloned().into()) .and_then(|map| map.get(&module)) { return modules.clone(); @@ -1238,7 +1309,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on self.extract_block_modules(module.get_root_block(self.compilation), runtime); self .block_modules_runtime_map - .get(&runtime.cloned().into()) + .get::(&runtime.cloned().into()) .and_then(|map| map.get(&module)) .unwrap_or_else(|| { panic!("block_modules_map.get({module:?}) must not empty after extract_block_modules") @@ -1321,7 +1392,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on } fn process_connect_queue(&mut self) { - for (chunk_group_info_ukey, targets) in self.queue_connect.drain() { + for (chunk_group_info_ukey, targets) in self.queue_connect.drain(..) { let chunk_group_info = self .chunk_group_infos .expect_get_mut(&chunk_group_info_ukey); @@ -1374,7 +1445,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on fn process_outdated_chunk_group_info(&mut self) { // Revisit skipped elements - for chunk_group_info_ukey in self.outdated_chunk_group_info.drain() { + for chunk_group_info_ukey in self.outdated_chunk_group_info.drain(..) { let cgi = self .chunk_group_infos .expect_get_mut(&chunk_group_info_ukey); @@ -1399,7 +1470,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on } for m in &enter_modules { - cgi.skipped_items.remove(m); + cgi.skipped_items.shift_remove(m); self .queue @@ -1482,7 +1553,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on }) }); - let mut min_available_modules_mappings = HashMap::default(); + let mut min_available_modules_mappings = IndexMap::::default(); for info_ukey in &self.chunk_groups_for_combining { let info = self.chunk_group_infos.expect_get(info_ukey); let mut available_modules = BigUint::from(0u32); @@ -1506,7 +1577,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on } fn process_chunk_groups_for_merging(&mut self) { - for info_ukey in self.chunk_groups_for_merging.drain() { + for info_ukey in self.chunk_groups_for_merging.drain(..) { let cgi = self.chunk_group_infos.expect_get_mut(&info_ukey); let mut changed = false; diff --git a/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs b/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs index 9a308dafb052..32cfda663932 100644 --- a/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs +++ b/crates/rspack_core/src/compiler/make/cutout/has_module_graph_change.rs @@ -6,27 +6,33 @@ use crate::{AsyncDependenciesBlockIdentifier, GroupOptions, ModuleGraph, ModuleI #[derive(Debug, Default, Eq, PartialEq)] struct ModuleDeps { // child module identifier of current module - child_modules: HashSet, + child_modules: Vec, // blocks in current module - module_blocks: HashSet<(AsyncDependenciesBlockIdentifier, Option)>, + module_blocks: Vec<(AsyncDependenciesBlockIdentifier, Option)>, } impl ModuleDeps { fn from_module(module_graph: &ModuleGraph, module_identifier: &ModuleIdentifier) -> Self { let mut res = Self::default(); - for connection in module_graph.get_outgoing_connections(module_identifier) { - res.child_modules.insert(*connection.module_identifier()); - } let module = module_graph .module_by_identifier(module_identifier) .expect("should have module"); + + let deps = module + .get_dependencies() + .iter() + .filter_map(|dep_id| module_graph.connection_by_dependency(dep_id)) + .map(|conn| *conn.module_identifier()) + .collect::>(); + + res.child_modules = remove_dup(deps); for block_id in module.get_blocks() { let block = module_graph .block_by_id(block_id) .expect("should have block"); res .module_blocks - .insert((*block_id, block.get_group_options().cloned())); + .push((*block_id, block.get_group_options().cloned())); } res @@ -74,3 +80,17 @@ impl HasModuleGraphChange { } } } + +fn remove_dup(items: Vec) -> Vec { + let mut new_items = vec![]; + let mut s = HashSet::default(); + + for item in items { + if !s.contains(&item) { + new_items.push(item); + s.insert(item); + } + } + + new_items +} diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index 0de9e63bf209..0d87f919346e 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -1771,7 +1771,7 @@ impl ExportInfo { key, ExportInfoTargetValue { connection: connection_inner_dep_id, - export: Some(export_name.cloned().unwrap_or_default()), + export: export_name.cloned(), priority: normalized_priority, }, ); diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs index 3a3e09077304..3692a800f879 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs @@ -1,5 +1,6 @@ use std::collections::hash_map::Entry; +use indexmap::IndexMap; use itertools::Itertools; use rspack_core::{ ApplyContext, BuildMetaExportsType, Compilation, CompilationFinishModules, CompilerOptions, @@ -81,8 +82,8 @@ impl<'a> FlagDependencyExportsProxy<'a> { while let Some(module_id) = q.dequeue() { self.changed = false; self.current_module_id = module_id; - let mut exports_specs_from_dependencies: HashMap = - HashMap::default(); + let mut exports_specs_from_dependencies: IndexMap = + IndexMap::default(); self.process_dependencies_block(&module_id, &mut exports_specs_from_dependencies); let exports_info_id = self.mg.get_exports_info(&module_id).id; for (dep_id, exports_spec) in exports_specs_from_dependencies.into_iter() { @@ -105,7 +106,7 @@ impl<'a> FlagDependencyExportsProxy<'a> { pub fn process_dependencies_block( &self, module_identifier: &ModuleIdentifier, - exports_specs_from_dependencies: &mut HashMap, + exports_specs_from_dependencies: &mut IndexMap, ) -> Option<()> { let block = &**self.mg.module_by_identifier(module_identifier)?; self.process_dependencies_block_inner(block, exports_specs_from_dependencies) @@ -114,7 +115,7 @@ impl<'a> FlagDependencyExportsProxy<'a> { fn process_dependencies_block_inner( &self, block: &B, - exports_specs_from_dependencies: &mut HashMap, + exports_specs_from_dependencies: &mut IndexMap, ) -> Option<()> { for dep_id in block.get_dependencies().iter() { let dep = self @@ -150,7 +151,7 @@ impl<'a> FlagDependencyExportsProxy<'a> { &self, dep_id: DependencyId, exports_specs: Option, - exports_specs_from_dependencies: &mut HashMap, + exports_specs_from_dependencies: &mut IndexMap, ) -> Option<()> { // this is why we can bubble here. https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/FlagDependencyExportsPlugin.js#L140 let exports_specs = exports_specs?; diff --git a/crates/rspack_plugin_split_chunks/src/module_group.rs b/crates/rspack_plugin_split_chunks/src/module_group.rs index fd81c3ece832..c6303ed1c609 100644 --- a/crates/rspack_plugin_split_chunks/src/module_group.rs +++ b/crates/rspack_plugin_split_chunks/src/module_group.rs @@ -102,20 +102,15 @@ pub(crate) fn compare_entries(a: &ModuleGroup, b: &ModuleGroup) -> f64 { return diff_count; } - // // 3. by size reduction - // let a_size_reduce = total_size(&a.sizes) * (a.chunks.len() - 1) as f64; - // let b_size_reduce = total_size(&b.sizes) * (b.chunks.len() - 1) as f64; - // let diff_size_reduce = a_size_reduce - b_size_reduce; - // if diff_size_reduce != 0f64 { - // return diff_size_reduce; - // } - // 4. by cache group index - let index_diff = b.cache_group_index as f64 - a.cache_group_index as f64; - if index_diff != 0f64 { - return index_diff; + // 3. by size reduction + let a_size_reduce = total_size(&a.sizes) * (a.chunks.len() - 1) as f64; + let b_size_reduce = total_size(&b.sizes) * (b.chunks.len() - 1) as f64; + let diff_size_reduce = a_size_reduce - b_size_reduce; + if diff_size_reduce != 0f64 { + return diff_size_reduce; } - // 5. by number of modules (to be able to compare by identifier) + // 4. by number of modules (to be able to compare by identifier) let modules_a_len = a.modules.len(); let modules_b_len = b.modules.len(); let diff = modules_a_len as f64 - modules_b_len as f64; @@ -130,7 +125,7 @@ pub(crate) fn compare_entries(a: &ModuleGroup, b: &ModuleGroup) -> f64 { loop { match (modules_a.pop(), modules_b.pop()) { - (None, None) => return 0f64, + (None, None) => break, (Some(a), Some(b)) => { let res = a.cmp(b); if !res.is_eq() { @@ -140,4 +135,15 @@ pub(crate) fn compare_entries(a: &ModuleGroup, b: &ModuleGroup) -> f64 { _ => unreachable!(), } } + + // 5. by cache group index + b.cache_group_index as f64 - a.cache_group_index as f64 +} + +fn total_size(sizes: &SplitChunkSizes) -> f64 { + let mut size = 0f64; + for ty_size in sizes.0.values() { + size += ty_size; + } + size } diff --git a/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs b/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs index 148b57ea163b..c57e14bed1d0 100644 --- a/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs +++ b/crates/rspack_plugin_split_chunks/src/plugin/module_group.rs @@ -121,6 +121,10 @@ impl SplitChunksPlugin { .chunk_graph .get_module_chunks(module.identifier()); + if belong_to_chunks.is_empty() { + return Ok(()); + } + let chunks_key = Self::get_key(belong_to_chunks.iter()); let mut temp = Vec::with_capacity(self.cache_groups.len()); @@ -153,21 +157,24 @@ impl SplitChunksPlugin { ); } - temp.push((idx, is_match)); + temp.push(is_match); } let mut chunk_key_to_string = HashMap::::default(); - temp.sort_by(|a, b| a.0.cmp(&b.0)); let filtered = self .cache_groups .iter() .enumerate() - .filter(|(index, _)| temp[*index].1); + .filter(|(index, _)| temp[*index]); for (cache_group_index, (idx, cache_group)) in filtered.enumerate() { let combs = get_combination(chunks_key); for chunk_combination in combs { + if chunk_combination.is_empty() { + continue; + } + // Filter by `splitChunks.cacheGroups.{cacheGroup}.minChunks` if chunk_combination.len() < cache_group.min_chunks as usize { tracing::trace!( @@ -252,9 +259,8 @@ impl SplitChunksPlugin { }; let key: String = if let Some(cache_group_name) = &chunk_name { let mut key = - String::with_capacity(cache_group.key.len() + " name:".len() + cache_group_name.len()); + String::with_capacity(cache_group.key.len() + cache_group_name.len()); key.push_str(&cache_group.key); - key.push_str(" name:"); key.push_str(cache_group_name); key } else { @@ -269,9 +275,8 @@ impl SplitChunksPlugin { }, }; let mut key = - String::with_capacity(cache_group.key.len() + " chunks:".len() + selected_chunks_key.len()); + String::with_capacity(cache_group.key.len() + selected_chunks_key.len()); key.push_str(&cache_group.key); - key.push_str(" chunks:"); key.push_str(&selected_chunks_key); key }; From b1db56cb60065800e9fb9834309e2d350dfa3182 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 14 May 2024 16:44:10 +0800 Subject: [PATCH 068/107] docs: rename Node.js API to JavaScript API (#6529) --- website/docs/en/api/_meta.json | 2 +- website/docs/en/api/index.mdx | 4 ++-- .../api/{node-api.mdx => javascript-api.mdx} | 22 +++++++++---------- website/docs/en/config/stats.mdx | 2 +- website/docs/zh/api/_meta.json | 2 +- website/docs/zh/api/index.mdx | 6 ++--- .../api/{node-api.mdx => javascript-api.mdx} | 22 +++++++++---------- website/docs/zh/config/stats.mdx | 2 +- website/theme/components/HomeFooter/index.tsx | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) rename website/docs/en/api/{node-api.mdx => javascript-api.mdx} (86%) rename website/docs/zh/api/{node-api.mdx => javascript-api.mdx} (85%) diff --git a/website/docs/en/api/_meta.json b/website/docs/en/api/_meta.json index 7e278ca4d112..c222d4a1a71b 100644 --- a/website/docs/en/api/_meta.json +++ b/website/docs/en/api/_meta.json @@ -6,7 +6,7 @@ "name": "modules", "label": "Modules" }, - "node-api", + "javascript-api", "hmr", { "type": "dir", diff --git a/website/docs/en/api/index.mdx b/website/docs/en/api/index.mdx index 0a01f4b798e6..95a6617e9e20 100644 --- a/website/docs/en/api/index.mdx +++ b/website/docs/en/api/index.mdx @@ -14,11 +14,11 @@ When processing modules with rspack, it is important to understand the different [Learn more about the modules!](/api/modules/module-methods) -## Node +## JavaScript API While most users can get away with using the CLI along with a configuration file, more fine-grained control of the compilation can be achieved via the Node interface. This includes passing multiple configurations, programmatically running or watching, and collecting stats. -[Learn more about the Node API!](/api/node-api) +[Learn more about the JavaScript API!](/api/javascript-api) ## Hot Module Replacement diff --git a/website/docs/en/api/node-api.mdx b/website/docs/en/api/javascript-api.mdx similarity index 86% rename from website/docs/en/api/node-api.mdx rename to website/docs/en/api/javascript-api.mdx index 1425fbf82578..c2135db9ad4a 100644 --- a/website/docs/en/api/node-api.mdx +++ b/website/docs/en/api/javascript-api.mdx @@ -3,27 +3,27 @@ import { ApiMeta, Stability } from '@components/ApiMeta.tsx'; -# Node.js API +# JavaScript API -Rspack provides a Node.js API which can be used directly in Node.js runtime. +Rspack provides a set of JavaScript APIs to be used in JavaScript runtimes like Node.js or Bun. -The Node.js API is useful in scenarios in which you need to customize the build or development process since all the reporting and error handling must be done manually and webpack only does the compiling part. For this reason the [`stats`](/config/stats) configuration options will not have any effect in the `rspack()` call. +The JavaScript API is useful in scenarios in which you need to customize the build or development process since all the reporting and error handling must be done manually and webpack only does the compiling part. For this reason the [`stats`](/config/stats) configuration options will not have any effect in the `rspack()` call. :::tip -`@rspack/core` is designed based on Webpack's Node.js API to ensure functional consistency and a similar user experience. +`@rspack/core` is designed based on Webpack's JavaScript API to ensure functional consistency and a similar user experience. ::: ## Installation -To start using the Rspack Node.js API, first install `@rspack/core` if you haven’t yet: +To start using the Rspack JavaScript API, first install `@rspack/core` if you haven’t yet: ```bash npm install --save-dev @rspack/core ``` -Then require the `@rspack/core` module in your Node.js script: +Then require the `@rspack/core` module in your JavaScript file: -```bash +```js title="build.js" import rspack from '@rspack/core'; ``` @@ -43,11 +43,11 @@ rspack({}, (err, stats) => { ``` :::tip -The `err` object will not include compilation errors. Those must be handled separately using `stats.hasErrors()`, which will be covered in detail in the [Error Handling](/api/node-api#error-handling) section of this guide. The `err` object will only contain rspack-related issues, such as misconfiguration, etc. +The `err` object will not include compilation errors. Those must be handled separately using `stats.hasErrors()`, which will be covered in detail in the [Error Handling](/api/javascript-api#error-handling) section of this guide. The `err` object will only contain rspack-related issues, such as misconfiguration, etc. ::: :::tip -You can provide the `rspack` function with an array of configurations. See the [MultiCompiler](/api/node-api#multicompiler) section below for more information. +You can provide the `rspack` function with an array of configurations. See the [MultiCompiler](/api/javascript-api#multicompiler) section below for more information. ::: ## Compiler Instance @@ -149,7 +149,7 @@ watching.invalidate(); ## Stats Object -The `stats` object that is passed as a second argument of the [`rspack()`](/api/node-api#rspack) callback, is a good source of information about the code compilation process. It includes: +The `stats` object that is passed as a second argument of the [`rspack()`](/api/javascript-api#rspack) callback, is a good source of information about the code compilation process. It includes: - Errors and Warnings (if any) - Timings @@ -228,7 +228,7 @@ rspack( ## MultiCompiler -The `MultiCompiler` module allows Rspack to run multiple configurations in separate compilers. If the `options` parameter in the Rspack's NodeJS api is an array of options, Rspack applies separate compilers and calls the callback after all compilers have been executed. +The `MultiCompiler` module allows Rspack to run multiple configurations in separate compilers. If the `options` parameter in the Rspack's JavaScript API is an array of options, Rspack applies separate compilers and calls the callback after all compilers have been executed. ```js import rspack from '@rspack/core'; diff --git a/website/docs/en/config/stats.mdx b/website/docs/en/config/stats.mdx index f37d3c1dd261..60d163100a63 100644 --- a/website/docs/en/config/stats.mdx +++ b/website/docs/en/config/stats.mdx @@ -10,7 +10,7 @@ Generate packaging information that can be used to analyze module dependencies a :::info Output JSON file of stats - Using `@rspack/cli`, `rspack build --json stats.json`. -- Using rspack's Node.js API, `stats.toJson(options)`、`stats.toString(options)`. +- Using Rspack's JavaScript API, `stats.toJson(options)`、`stats.toString(options)`. ::: diff --git a/website/docs/zh/api/_meta.json b/website/docs/zh/api/_meta.json index a33bd0163c8a..678f662e4dca 100644 --- a/website/docs/zh/api/_meta.json +++ b/website/docs/zh/api/_meta.json @@ -6,7 +6,7 @@ "name": "modules", "label": "模块" }, - "node-api", + "javascript-api", "hmr", { "type": "dir", diff --git a/website/docs/zh/api/index.mdx b/website/docs/zh/api/index.mdx index 2dcabc574f6e..9d411f403fef 100644 --- a/website/docs/zh/api/index.mdx +++ b/website/docs/zh/api/index.mdx @@ -14,11 +14,11 @@ Rspack 提供了多种界面来自定义编译过程。一些功能在不同的 [了解更多关于模块的信息!](/api/modules/module-methods) -## Node +## JavaScript API -虽然大多数用户可以通过命令行界面(CLI)和配置文件来进行操作,但通过 Node 接口可以实现对编译过程更为细致的控制。这包括传递多个配置、以编程方式运行或监控,以及收集统计信息。 +虽然大多数用户可以通过命令行界面(CLI)和配置文件来进行操作,但通过 JavaScript API 可以实现对编译过程更为细致的控制。这包括传递多个配置、以编程方式运行或监控,以及收集统计信息。 -[了解更多关于 Node API 的信息!](/api/node-api) +[了解更多关于 JavaScript API 的信息!](/api/javascript-api) ## Hot Module Replacement diff --git a/website/docs/zh/api/node-api.mdx b/website/docs/zh/api/javascript-api.mdx similarity index 85% rename from website/docs/zh/api/node-api.mdx rename to website/docs/zh/api/javascript-api.mdx index 6e8794260a75..57e703fd71ee 100644 --- a/website/docs/zh/api/node-api.mdx +++ b/website/docs/zh/api/javascript-api.mdx @@ -3,27 +3,27 @@ import { ApiMeta, Stability } from '@components/ApiMeta.tsx'; -# Node.js API +# JavaScript API -Rspack 提供了 Node.js API,可以在 Node.js 运行时下直接使用。 +Rspack 提供了一组 JavaScript API,可在 Node.js 或 Bun 等 JavaScript 运行时中使用。 -当你需要自定义构建或开发流程时,Node.js API 非常有用,因为此时所有的报告和错误处理都必须自行实现,Rspack 仅仅负责编译的部分。所以 [`stats`](/config/stats) 配置选项不会在 `rspack()` 调用中生效。 +当你需要自定义构建或开发流程时,JavaScript API 非常有用,因为此时所有的报告和错误处理都必须自行实现,Rspack 仅仅负责编译的部分。所以 [`stats`](/config/stats) 配置选项不会在 `rspack()` 调用中生效。 :::tip 提示 -`@rspack/core` 是基于 Webpack Node.js API 设计的,旨在提供一致的功能和相似的使用体验。 +`@rspack/core` 是基于 Webpack JavaScript API 设计的,旨在提供一致的功能和相似的使用体验。 ::: ## 安装 -开始使用 Rspack 的 Node.js API 之前,首先你需要安装 `@rspack/core`: +开始使用 Rspack 的 JavaScript API 之前,首先你需要安装 `@rspack/core`: ```bash npm install --save-dev @rspack/core ``` -在 Node.js 文件中,引入 `@rspack/core` 模块: +在 JavaScript 文件中,引入 `@rspack/core` 模块: -```bash +```js title="build.js" import rspack from '@rspack/core'; ``` @@ -43,11 +43,11 @@ rspack({}, (err, stats) => { ``` :::tip 提示 -`err` 对象**不包含**编译错误,必须使用 `stats.hasErrors()` 单独处理,文档的[错误处理](/api/node-api#错误处理)将对这部分进行详细介绍。`err` 对象只包含 Rspack 相关的问题,例如配置错误等。 +`err` 对象**不包含**编译错误,必须使用 `stats.hasErrors()` 单独处理,文档的[错误处理](/api/javascript-api#错误处理)将对这部分进行详细介绍。`err` 对象只包含 Rspack 相关的问题,例如配置错误等。 ::: :::tip 提示 -你也可以为 rspack() 函数提供一个配置数组。更多详细信息,请查看 [MultiCompiler](/api/node-api#multicompiler) 章节。 +你也可以为 rspack() 函数提供一个配置数组。更多详细信息,请查看 [MultiCompiler](/api/javascript-api#multicompiler) 章节。 ::: ## Compiler 实例 @@ -149,7 +149,7 @@ watching.invalidate(); ## Stats 对象 -`stats` 对象会被作为 [`rspack()`](/api/node-api#rspack) 回调函数的第二个参数传递,可以通过它获取到代码编译过程中的有用信息,包括: +`stats` 对象会被作为 [`rspack()`](/api/javascript-api#rspack) 回调函数的第二个参数传递,可以通过它获取到代码编译过程中的有用信息,包括: - 错误和警告(如果有的话) - 计时信息 @@ -228,7 +228,7 @@ rspack( ## MultiCompiler -`MultiCompiler` 模块可以让 Rspack 同时执行多个配置。如果传给 Rspack 的 Node.js API 的 `options` 参数,该参数由是由多个配置对象构成的数组,Rspack 会相应地创建多个 compiler 实例,并且在所有 compiler 执行完毕后调用 `callback` 方法。 +`MultiCompiler` 模块可以让 Rspack 同时执行多个配置。如果传给 Rspack 的 JavaScript API 的 `options` 参数,该参数由是由多个配置对象构成的数组,Rspack 会相应地创建多个 compiler 实例,并且在所有 compiler 执行完毕后调用 `callback` 方法。 ```js import rspack from '@rspack/core'; diff --git a/website/docs/zh/config/stats.mdx b/website/docs/zh/config/stats.mdx index 8d5c0cd1e5b5..884f8a0ad0eb 100644 --- a/website/docs/zh/config/stats.mdx +++ b/website/docs/zh/config/stats.mdx @@ -10,7 +10,7 @@ import WebpackLicense from '@components/webpack-license'; :::info 输出打包信息的 JSON 文件 - 使用 `@rspack/cli`,`rspack build --json stats.json`。 -- 通过 Rspack 的 Node.js API,`stats.toJson(options)`、`stats.toString(options)`。 +- 通过 Rspack 的 JavaScript API,`stats.toJson(options)`、`stats.toString(options)`。 ::: diff --git a/website/theme/components/HomeFooter/index.tsx b/website/theme/components/HomeFooter/index.tsx index 353ed9bbcb69..c2bef643ca72 100644 --- a/website/theme/components/HomeFooter/index.tsx +++ b/website/theme/components/HomeFooter/index.tsx @@ -46,7 +46,7 @@ function useFooterData() { }, { title: 'JavaScript API', - link: getLink('/api/node-api'), + link: getLink('/api/javascript-api'), }, ], }, From f4b669a0661dcf454f68ae57298ff6bccf5a2540 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 14 May 2024 18:44:02 +0800 Subject: [PATCH 069/107] feat: deprecate `Compiler` and `MultiCompiler` API (#6448) --- crates/node_binding/binding.d.ts | 10 +- crates/rspack_fs_node/src/node.rs | 10 +- .../tests/build/issue-6359/rspack.config.js | 6 +- packages/rspack-dev-server/src/middleware.ts | 4 +- .../tests/normalizeOptions.test.ts | 4 +- packages/rspack-test-tools/etc/api.md | 2 + .../src/processor/snapshot.ts | 2 +- .../src/processor/stats-api.ts | 4 +- .../tests/errorCases/error-test-shift.js | 60 +- .../tests/errorCases/error-test-splice-1.js | 52 +- .../tests/errorCases/warning-test-push.js | 4 +- .../tests/errorCases/warning-test-shift.js | 4 +- .../tests/errorCases/warning-test-splice-1.js | 4 +- .../tests/errorCases/warning-test-splice-2.js | 4 +- .../tests/legacy-test/Output.test.js | 2 +- .../tests/statsAPICases/cache-disabled.js | 2 +- .../tests/statsAPICases/cache-enabled.js | 2 +- .../tests/statsAPICases/child-compiler.js | 1 + .../tests/statsAPICases/placeholders.js | 2 +- packages/rspack/etc/api.md | 195 ++- packages/rspack/src/ChunkGroup.ts | 13 +- packages/rspack/src/Compilation.ts | 1 - packages/rspack/src/Compiler.ts | 1241 +++++++++-------- packages/rspack/src/MultiCompiler.ts | 35 +- packages/rspack/src/Watching.ts | 5 +- .../src/builtin-plugin/SplitChunksPlugin.ts | 2 +- packages/rspack/src/config/adapterRuleUse.ts | 5 +- packages/rspack/src/exports.ts | 2 + packages/rspack/src/fileSystem.ts | 90 +- packages/rspack/src/loader-runner/index.ts | 22 +- packages/rspack/src/logging/Logger.ts | 2 +- .../rspack/src/node/NodeEnvironmentPlugin.ts | 2 +- packages/rspack/src/util/fs.ts | 206 +++ packages/rspack/src/util/index.ts | 9 + 34 files changed, 1181 insertions(+), 828 deletions(-) diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index a109fc6fa179..bb6d35b6e9c2 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -1435,10 +1435,10 @@ export interface RegisterJsTaps { export function runBuiltinLoader(builtin: string, options: string | undefined | null, loaderContext: JsLoaderContext): Promise export interface ThreadsafeNodeFS { - writeFile: (name: string, content: Buffer) => void - removeFile: (name: string) => void - mkdir: (name: string) => void - mkdirp: (name: string) => string | void - removeDirAll: (name: string) => string | void + writeFile: (name: string, content: Buffer) => Promise | void + removeFile: (name: string) => Promise | void + mkdir: (name: string) => Promise | void + mkdirp: (name: string) => Promise | string | void + removeDirAll: (name: string) => Promise | string | void } diff --git a/crates/rspack_fs_node/src/node.rs b/crates/rspack_fs_node/src/node.rs index ad934d5067da..823aa0224882 100644 --- a/crates/rspack_fs_node/src/node.rs +++ b/crates/rspack_fs_node/src/node.rs @@ -61,15 +61,15 @@ cfg_async! { #[napi(object, object_to_js = false, js_name = "ThreadsafeNodeFS")] pub struct ThreadsafeNodeFS { - #[napi(ts_type = "(name: string, content: Buffer) => void")] + #[napi(ts_type = "(name: string, content: Buffer) => Promise | void")] pub write_file: ThreadsafeFunction<(String, Buffer), ()>, - #[napi(ts_type = "(name: string) => void")] + #[napi(ts_type = "(name: string) => Promise | void")] pub remove_file: ThreadsafeFunction, - #[napi(ts_type = "(name: string) => void")] + #[napi(ts_type = "(name: string) => Promise | void")] pub mkdir: ThreadsafeFunction, - #[napi(ts_type = "(name: string) => string | void")] + #[napi(ts_type = "(name: string) => Promise | string | void")] pub mkdirp: ThreadsafeFunction>, - #[napi(ts_type = "(name: string) => string | void")] + #[napi(ts_type = "(name: string) => Promise | string | void")] pub remove_dir_all: ThreadsafeFunction>, } } diff --git a/packages/rspack-cli/tests/build/issue-6359/rspack.config.js b/packages/rspack-cli/tests/build/issue-6359/rspack.config.js index ef0d639ed643..0327f8f30cae 100644 --- a/packages/rspack-cli/tests/build/issue-6359/rspack.config.js +++ b/packages/rspack-cli/tests/build/issue-6359/rspack.config.js @@ -1,8 +1,12 @@ +const path = require("path"); const { WEBPACK_SERVE } = process.env; module.exports = /** @type {import('@rspack/cli').Configuration} */ { mode: "production", entry: "./entry.js", - output: { clean: true }, + output: { + clean: true, + path: path.resolve(__dirname, "dist") + }, plugins: [ { apply(compiler) { diff --git a/packages/rspack-dev-server/src/middleware.ts b/packages/rspack-dev-server/src/middleware.ts index d31d00cc9011..b1d236701459 100644 --- a/packages/rspack-dev-server/src/middleware.ts +++ b/packages/rspack-dev-server/src/middleware.ts @@ -37,14 +37,14 @@ export function getRspackMemoryAssets( : // @ts-expect-error path.slice(1); const buffer = - compiler.getAsset(filename) ?? + compiler._lastCompilation?.getAsset(filename) ?? (() => { const { index } = rdm.context.options; const indexValue = typeof index === "undefined" || typeof index === "boolean" ? "index.html" : index; - return compiler.getAsset(filename + indexValue); + return compiler._lastCompilation?.getAsset(filename + indexValue); })(); if (!buffer) { return next(); diff --git a/packages/rspack-dev-server/tests/normalizeOptions.test.ts b/packages/rspack-dev-server/tests/normalizeOptions.test.ts index b8e5a14e4384..d4915b2b9aff 100644 --- a/packages/rspack-dev-server/tests/normalizeOptions.test.ts +++ b/packages/rspack-dev-server/tests/normalizeOptions.test.ts @@ -79,7 +79,7 @@ describe("normalize options snapshot", () => { }); const server = new RspackDevServer({}, compiler); await server.start(); - const hmrPlugins = compiler.builtinPlugins.filter( + const hmrPlugins = compiler.__internal__builtinPlugins.filter( p => p.name === "HotModuleReplacementPlugin" ); expect(hmrPlugins.length).toBe(1); @@ -149,7 +149,7 @@ async function getAdditionEntries( const server = new RspackDevServer(serverConfig, compiler); await server.start(); - const entries = compiler.builtinPlugins + const entries = compiler.__internal__builtinPlugins .filter(p => p.name === "EntryPlugin") .map(p => p.options) .reduce((acc, cur: any) => { diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index a6beaecc3106..87fad2910948 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -633,6 +633,8 @@ export interface IStatsAPITaskProcessorOptions { // (undocumented) check?: (stats: TCompilerStats, compiler: TCompiler) => Promise; // (undocumented) + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; + // (undocumented) compilerType: T; // (undocumented) cwd?: string; diff --git a/packages/rspack-test-tools/src/processor/snapshot.ts b/packages/rspack-test-tools/src/processor/snapshot.ts index d8c5a47b64dc..eebaf05006b8 100644 --- a/packages/rspack-test-tools/src/processor/snapshot.ts +++ b/packages/rspack-test-tools/src/processor/snapshot.ts @@ -46,7 +46,7 @@ export class SnapshotProcessor< ); } const compilation = - (c as RspackCompiler).compilation || + (c as RspackCompiler)._lastCompilation || ( c as WebpackCompiler & { _lastCompilation: WebpackCompilation; diff --git a/packages/rspack-test-tools/src/processor/stats-api.ts b/packages/rspack-test-tools/src/processor/stats-api.ts index a98d7e76e10d..6091094691e2 100644 --- a/packages/rspack-test-tools/src/processor/stats-api.ts +++ b/packages/rspack-test-tools/src/processor/stats-api.ts @@ -16,6 +16,7 @@ export interface IStatsAPITaskProcessorOptions { name: string; cwd?: string; compilerType: T; + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; build?: (context: ITestContext, compiler: TCompiler) => Promise; check?: (stats: TCompilerStats, compiler: TCompiler) => Promise; } @@ -28,7 +29,8 @@ export class StatsAPITaskProcessor< options: _statsAPIOptions.options, build: _statsAPIOptions.build, compilerType: _statsAPIOptions.compilerType, - name: _statsAPIOptions.name + name: _statsAPIOptions.name, + compiler: _statsAPIOptions.compiler }); } 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 d76f96cbfeeb..13d8caa0c71c 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js @@ -1,33 +1,33 @@ /** @type {import('../..').TErrorCaseConfig} */ module.exports = { - description: "Testing proxy methods on errors: test shift&unshift", - options() { - return { - entry: "./resolve-fail-esm", - plugins: [ - compiler => { - compiler.hooks.afterCompile.tap( - "test shift and unshift", - compilation => { - compilation.errors.shift(); - compilation.errors.unshift("test unshift"); - } - ); - } - ] - }; - }, - async check(diagnostics) { - expect(diagnostics).toMatchInlineSnapshot(` - Object { - "errors": Array [ - Object { - "formatted": " × test unshift\\n", - "message": " × test unshift\\n", - }, - ], - "warnings": Array [], - } - `); - } + description: "Testing proxy methods on errors: test shift&unshift", + options() { + return { + entry: "./resolve-fail-esm", + plugins: [ + compiler => { + compiler.hooks.afterCompile.tap( + "test shift and unshift", + compilation => { + compilation.errors.shift(); + compilation.errors.unshift("test unshift"); + } + ); + } + ] + }; + }, + async check(diagnostics) { + expect(diagnostics).toMatchInlineSnapshot(` + Object { + "errors": Array [ + Object { + "formatted": " × test unshift\\n", + "message": " × test unshift\\n", + }, + ], + "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 8c12c33cc9b4..27769318b47a 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 @@ -1,29 +1,29 @@ /** @type {import('../..').TErrorCaseConfig} */ module.exports = { - description: "Testing proxy methods on errors: test splice 1", - options() { - return { - entry: "./resolve-fail-esm", - plugins: [ - compiler => { - compiler.hooks.afterCompile.tap("test splice", compilation => { - compilation.errors.splice(0, 1, "test splice"); - }); - } - ] - }; - }, - async check(diagnostics) { - expect(diagnostics).toMatchInlineSnapshot(` - Object { - "errors": Array [ - Object { - "formatted": " × test splice\\n", - "message": " × test splice\\n", - }, - ], - "warnings": Array [], - } - `); - } + description: "Testing proxy methods on errors: test splice 1", + options() { + return { + entry: "./resolve-fail-esm", + plugins: [ + compiler => { + compiler.hooks.afterCompile.tap("test splice", compilation => { + compilation.errors.splice(0, 1, "test splice"); + }); + } + ] + }; + }, + async check(diagnostics) { + expect(diagnostics).toMatchInlineSnapshot(` + Object { + "errors": Array [ + Object { + "formatted": " × test splice\\n", + "message": " × test splice\\n", + }, + ], + "warnings": Array [], + } + `); + } }; 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 a13ba23db6a4..4c0c5b655cf5 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js @@ -19,8 +19,8 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", - "message": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", + "formatted": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, Object { "formatted": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: 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 ed239f1456cc..13469964ac88 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js @@ -23,8 +23,8 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", - "message": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", + "formatted": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, ], } 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 f1b86d309858..78ce130bbbfa 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 @@ -19,8 +19,8 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", - "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", + "formatted": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, ], } 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 016b2f215cd4..3e9eed58e778 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 @@ -19,8 +19,8 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", - "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:419:41\\n │ at packages/rspack/dist/Compiler.js:751:65\\n", + "formatted": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", + "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, Object { "formatted": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: 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/legacy-test/Output.test.js b/packages/rspack-test-tools/tests/legacy-test/Output.test.js index 411f5c328085..4361e3df2d23 100644 --- a/packages/rspack-test-tools/tests/legacy-test/Output.test.js +++ b/packages/rspack-test-tools/tests/legacy-test/Output.test.js @@ -52,7 +52,7 @@ describe("Output", () => { }); it("should be cleared the build directory", done => { - const outputDist = "dist/output"; + const outputDist = path.resolve(__dirname, "../js/legacy-test/output-clear-build-directory"); compile( "./a", { diff --git a/packages/rspack-test-tools/tests/statsAPICases/cache-disabled.js b/packages/rspack-test-tools/tests/statsAPICases/cache-disabled.js index e8ec58e1e6b3..d2f4dfcd7fc4 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/cache-disabled.js +++ b/packages/rspack-test-tools/tests/statsAPICases/cache-disabled.js @@ -33,7 +33,7 @@ module.exports = { }); }, async check(_, compiler) { - const stats = new Stats(compiler.compilation).toString({ + const stats = new Stats(compiler._lastCompilation).toString({ all: false, logging: "verbose" }); diff --git a/packages/rspack-test-tools/tests/statsAPICases/cache-enabled.js b/packages/rspack-test-tools/tests/statsAPICases/cache-enabled.js index 124b761be5ca..d892d550cf41 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/cache-enabled.js +++ b/packages/rspack-test-tools/tests/statsAPICases/cache-enabled.js @@ -34,7 +34,7 @@ module.exports = { }); }, async check(_, compiler) { - const stats = new Stats(compiler.compilation).toString({ + const stats = new Stats(compiler._lastCompilation).toString({ all: false, logging: "verbose" }); diff --git a/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js b/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js index cbb5acf74df2..388f580381ca 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js +++ b/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js @@ -1,3 +1,4 @@ +const { createFsFromVolume, Volume } = require("memfs") let statsJson; class TestPlugin { diff --git a/packages/rspack-test-tools/tests/statsAPICases/placeholders.js b/packages/rspack-test-tools/tests/statsAPICases/placeholders.js index fd2e0a108b4e..7f0a0bc6783b 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/placeholders.js +++ b/packages/rspack-test-tools/tests/statsAPICases/placeholders.js @@ -4,7 +4,7 @@ class TestPlugin { apply(compiler) { compiler.hooks.thisCompilation.tap("custom", compilation => { compilation.hooks.optimizeModules.tap("test plugin", () => { - stats = compiler.compilation.getStats().toJson({}); + stats = compiler._lastCompilation.getStats().toJson({}); }); }); } diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index cecb6bc98647..ecfb427ec69c 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -19,10 +19,9 @@ import { RawEvalDevToolModulePluginOptions as EvalDevToolModulePluginOptions } f import { EventEmitter } from 'events'; import { cleanupGlobalTrace as experimental_cleanupGlobalTrace } from '@rspack/binding'; import { registerGlobalTrace as experimental_registerGlobalTrace } from '@rspack/binding'; -import { exports as exports_2 } from './exports'; import type { ExternalObject } from '@rspack/binding'; -import { fs } from 'fs'; -import { default as fs_2 } from 'graceful-fs'; +import fs from 'graceful-fs'; +import { fs as fs_2 } from 'fs'; import Hash = require('../util/hash'); import { HookMap as HookMap_2 } from 'tapable'; import { JsAssetInfo } from '@rspack/binding'; @@ -65,7 +64,6 @@ import { RawSourceMapDevToolPluginOptions } from '@rspack/binding'; import { RawSwcJsMinimizerRspackPluginOptions } from '@rspack/binding'; import { ResolveRequest } from 'enhanced-resolve'; import ResolverFactory = require('./ResolverFactory'); -import { rspack as rspack_3 } from './rspack'; import { RspackOptionsNormalized as RspackOptionsNormalized_2 } from '.'; import { Source } from 'webpack-sources'; import { SyncBailHook as SyncBailHook_2 } from 'tapable'; @@ -99,9 +97,6 @@ export type AmdContainer = z.infer; // @public (undocumented) const amdContainer: z.ZodString; -// @public (undocumented) -type Any = any; - // @public (undocumented) type Append = { 0: [U]; @@ -1176,23 +1171,21 @@ export interface CompilationParams { // @public (undocumented) export class Compiler { constructor(context: string, options: RspackOptionsNormalized); + // @internal + get __internal__builtinPlugins(): binding.BuiltinPlugin[]; // (undocumented) __internal__getModuleExecutionResult(id: number): any; // @internal __internal__rebuild(modifiedFiles?: ReadonlySet, removedFiles?: ReadonlySet, callback?: (error: Error | null) => void): void; // (undocumented) __internal__registerBuiltinPlugin(plugin: binding.BuiltinPlugin): void; - // (undocumented) - builtinPlugins: binding.BuiltinPlugin[]; + // @internal + get __internal__ruleSet(): RuleSetCompiler; // (undocumented) cache: Cache_2; // (undocumented) close(callback: (error?: Error | null) => void): void; // (undocumented) - compilation?: Compilation; - // (undocumented) - compilationParams?: CompilationParams; - // (undocumented) compile(callback: Callback_2): void; // (undocumented) compilerPath: string; @@ -1205,11 +1198,11 @@ export class Compiler { // (undocumented) fileTimestamps?: ReadonlyMap; // (undocumented) - getAsset(name: string): Buffer | null; + fsStartTime?: number; // (undocumented) getCache(name: string): CacheFacade; // (undocumented) - getInfrastructureLogger(name: string | Function): Logger; + getInfrastructureLogger(name: string | (() => string)): Logger; // (undocumented) hooks: { done: tapable.AsyncSeriesHook; @@ -1245,6 +1238,8 @@ export class Compiler { // (undocumented) idle: boolean; // (undocumented) + get immutablePaths(): never; + // (undocumented) infrastructureLogger: any; // (undocumented) inputFileSystem: any; @@ -1253,13 +1248,17 @@ export class Compiler { // (undocumented) isChild(): boolean; // (undocumented) + get _lastCompilation(): Compilation | undefined; + // (undocumented) + get managedPaths(): never; + // (undocumented) modifiedFiles?: ReadonlySet; // (undocumented) name?: string; // (undocumented) options: RspackOptionsNormalized; // (undocumented) - outputFileSystem: fs; + outputFileSystem: OutputFileSystem | null; // (undocumented) outputPath: string; // (undocumented) @@ -1267,32 +1266,33 @@ export class Compiler { // (undocumented) purgeInputFileSystem(): void; // (undocumented) + records: Record; + // (undocumented) + get recordsInputPath(): never; + // (undocumented) + get recordsOutputPath(): never; + // (undocumented) removedFiles?: ReadonlySet; // (undocumented) resolverFactory: ResolverFactory; // (undocumented) root: Compiler; // (undocumented) - ruleSet: RuleSetCompiler; - // (undocumented) run(callback: Callback_2): void; // (undocumented) - runAsChild(callback: any): void; + runAsChild(callback: (err?: null | Error, entries?: Chunk[], compilation?: Compilation) => any): void; // (undocumented) running: boolean; // (undocumented) watch(watchOptions: Watchpack.WatchOptions, handler: Callback_2): Watching; // (undocumented) - watchFileSystem: WatchFileSystem; + watchFileSystem: WatchFileSystem | null; // (undocumented) watching?: Watching; // (undocumented) watchMode: boolean; // (undocumented) - webpack: rspack_3 & exports_2 & { - rspack: rspack_3 & exports_2 & any; - webpack: rspack_3 & exports_2 & any; - }; + webpack: typeof rspack; } // @public (undocumented) @@ -1742,13 +1742,13 @@ class DirectoryWatcher extends EventEmitter { // (undocumented) nestedWatching: boolean; // (undocumented) - onChange(filePath: string, stat: fs_2.Stats): void; + onChange(filePath: string, stat: fs.Stats): void; // (undocumented) onDirectoryAdded(directoryPath: string): void; // (undocumented) onDirectoryUnlinked(directoryPath: string): void; // (undocumented) - onFileAdded(filePath: string, stat: fs_2.Stats): void; + onFileAdded(filePath: string, stat: fs.Stats): void; // (undocumented) onFileUnlinked(filePath: string): void; // (undocumented) @@ -1768,7 +1768,7 @@ class DirectoryWatcher extends EventEmitter { // (undocumented) watch(filePath: string, startTime: number): Watcher_2; // (undocumented) - watcher: fs_2.FSWatcher; + watcher: fs.FSWatcher; // (undocumented) watchers: { [path: string]: Watcher_2[]; @@ -3837,6 +3837,26 @@ const htmlRspackPluginOptions: z.ZodObject<{ meta?: Record> | undefined; }>; +// @public (undocumented) +interface IDirent { + // (undocumented) + isBlockDevice: () => boolean; + // (undocumented) + isCharacterDevice: () => boolean; + // (undocumented) + isDirectory: () => boolean; + // (undocumented) + isFIFO: () => boolean; + // (undocumented) + isFile: () => boolean; + // (undocumented) + isSocket: () => boolean; + // (undocumented) + isSymbolicLink: () => boolean; + // (undocumented) + name: string | Buffer; +} + // @public (undocumented) type IfSet = X extends UnsetAdditionalOptions ? {} : X; @@ -3910,6 +3930,60 @@ const infrastructureLogging: z.ZodObject<{ // @public (undocumented) type InnerCallback = (error?: E | null | false, result?: T) => void; +// @public (undocumented) +interface IStats { + // (undocumented) + atime: Date; + // (undocumented) + atimeMs: number | bigint; + // (undocumented) + birthtime: Date; + // (undocumented) + birthtimeMs: number | bigint; + // (undocumented) + blksize: number | bigint; + // (undocumented) + blocks: number | bigint; + // (undocumented) + ctime: Date; + // (undocumented) + ctimeMs: number | bigint; + // (undocumented) + dev: number | bigint; + // (undocumented) + gid: number | bigint; + // (undocumented) + ino: number | bigint; + // (undocumented) + isBlockDevice: () => boolean; + // (undocumented) + isCharacterDevice: () => boolean; + // (undocumented) + isDirectory: () => boolean; + // (undocumented) + isFIFO: () => boolean; + // (undocumented) + isFile: () => boolean; + // (undocumented) + isSocket: () => boolean; + // (undocumented) + isSymbolicLink: () => boolean; + // (undocumented) + mode: number | bigint; + // (undocumented) + mtime: Date; + // (undocumented) + mtimeMs: number | bigint; + // (undocumented) + nlink: number | bigint; + // (undocumented) + rdev: number | bigint; + // (undocumented) + size: number | bigint; + // (undocumented) + uid: number | bigint; +} + // @public (undocumented) interface JavaScript { // (undocumented) @@ -4382,7 +4456,7 @@ export interface LoaderContext { // (undocumented) clearDependencies(): void; // (undocumented) - _compilation: Compiler["compilation"]; + _compilation: Compilation; // (undocumented) _compiler: Compiler; // (undocumented) @@ -4532,7 +4606,7 @@ export interface LogEntry { } // @public (undocumented) -type LogFunction = (type: LogTypeEnum, args?: any[]) => void; +type LogFunction = (type: LogTypeEnum, args: any[]) => void; // @public (undocumented) class Logger { @@ -5391,8 +5465,6 @@ export class MultiCompiler { // (undocumented) compilers: Compiler[]; // (undocumented) - context: string; - // (undocumented) dependencies: WeakMap; // (undocumented) getInfrastructureLogger(name: string): Logger_2; @@ -5401,40 +5473,28 @@ export class MultiCompiler { done: SyncHook_2; invalid: MultiHook>; run: MultiHook>; - watchClose: SyncHook_2; - watchRun: MultiHook; - infrastructureLog: MultiHook; + watchClose: SyncHook_2<[]>; + watchRun: MultiHook>; + infrastructureLog: MultiHook>; }; // (undocumented) - infrastructureLogger: Any; - // (undocumented) get inputFileSystem(): void; set inputFileSystem(value: void); // (undocumented) - get intermediateFileSystem(): any; - set intermediateFileSystem(value: any); - // (undocumented) - name: string; + get intermediateFileSystem(): void; + set intermediateFileSystem(value: void); // (undocumented) - get options(): RspackOptionsNormalized_2[] & { - parallelism?: number | undefined; - }; + get options(): RspackOptionsNormalized_2[] & MultiCompilerOptions; // (undocumented) - _options: { - parallelism?: number; - }; + _options: MultiCompilerOptions; // (undocumented) - get outputFileSystem(): fs; - set outputFileSystem(value: fs); + get outputFileSystem(): fs_2; + set outputFileSystem(value: fs_2); // (undocumented) get outputPath(): string; // (undocumented) purgeInputFileSystem(): void; // (undocumented) - resolverFactory: ResolverFactory; - // (undocumented) - root: Compiler; - // (undocumented) run(callback: Callback_2): void; // (undocumented) running: boolean; @@ -5447,10 +5507,6 @@ export class MultiCompiler { // (undocumented) get watchFileSystem(): WatchFileSystem; set watchFileSystem(value: WatchFileSystem); - // (undocumented) - watching: Watching; - // (undocumented) - watchMode: boolean; } // @public (undocumented) @@ -6564,6 +6620,32 @@ const output: z.ZodObject<{ devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; }>; +// @public (undocumented) +export interface OutputFileSystem { + // (undocumented) + dirname?: (arg0: string) => string; + // (undocumented) + join?: (arg0: string, arg1: string) => string; + // (undocumented) + lstat?: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: IStats) => void) => void; + // (undocumented) + mkdir: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException) => void) => void; + // (undocumented) + readdir: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: (string | Buffer)[] | IDirent[]) => void) => void; + // (undocumented) + readFile: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: string | Buffer) => void) => void; + // (undocumented) + relative?: (arg0: string, arg1: string) => string; + // (undocumented) + rmdir: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException) => void) => void; + // (undocumented) + stat: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: IStats) => void) => void; + // (undocumented) + unlink: (arg0: string, arg1: (arg0?: null | NodeJS.ErrnoException) => void) => void; + // (undocumented) + writeFile: (arg0: string, arg1: string | Buffer, arg2: (arg0?: null | NodeJS.ErrnoException) => void) => void; +} + // @public (undocumented) export type OutputModule = z.infer; @@ -7492,6 +7574,7 @@ declare namespace rspackExports { sources, config, util, + OutputFileSystem, experimental_registerGlobalTrace, experimental_cleanupGlobalTrace, EntryOptionPlugin, diff --git a/packages/rspack/src/ChunkGroup.ts b/packages/rspack/src/ChunkGroup.ts index b44f7dda5309..c0bdc8fb1205 100644 --- a/packages/rspack/src/ChunkGroup.ts +++ b/packages/rspack/src/ChunkGroup.ts @@ -3,6 +3,7 @@ import { type JsChunkGroup, type JsCompilation } from "@rspack/binding"; + import { Chunk } from "./Chunk"; export class ChunkGroup { @@ -40,6 +41,12 @@ export class ChunkGroup { }); } + get chunks(): Chunk[] { + return this.#inner.chunks.map(c => + Chunk.__from_binding(c, this.#inner_compilation) + ); + } + get index(): number | undefined { return this.#inner.index; } @@ -48,12 +55,6 @@ export class ChunkGroup { return this.#inner.name; } - get chunks(): Chunk[] { - return this.#inner.chunks.map(c => - Chunk.__from_binding(c, this.#inner_compilation) - ); - } - __internal_inner_ukey() { return this.#inner.__inner_ukey; } diff --git a/packages/rspack/src/Compilation.ts b/packages/rspack/src/Compilation.ts index 6568262fd25c..7e2d3350cca5 100644 --- a/packages/rspack/src/Compilation.ts +++ b/packages/rspack/src/Compilation.ts @@ -814,7 +814,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si const logEntry: LogEntry = { time: Date.now(), type, - // @ts-expect-error args, // @ts-expect-error trace diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index bf9084bb6d50..08913452108c 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -27,7 +27,7 @@ import { Compilation, CompilationParams } from "./Compilation"; import { ContextModuleFactory } from "./ContextModuleFactory"; import ResolverFactory = require("./ResolverFactory"); import ConcurrentCompilationError from "./error/ConcurrentCompilationError"; -import { createThreadsafeNodeFSFromRaw } from "./fileSystem"; +import { ThreadsafeWritableNodeFS } from "./fileSystem"; import Cache = require("./lib/Cache"); import CacheFacade = require("./lib/CacheFacade"); import { Logger } from "./logging/Logger"; @@ -35,7 +35,7 @@ import { NormalModuleCreateData, NormalModuleFactory } from "./NormalModuleFactory"; -import { WatchFileSystem } from "./util/fs"; +import { OutputFileSystem, WatchFileSystem } from "./util/fs"; import { checkVersion } from "./util/bindingVersionCheck"; import { Watching } from "./Watching"; import { @@ -57,6 +57,8 @@ import { canInherentFromParent } from "./builtin-plugin/base"; import ExecuteModulePlugin from "./ExecuteModulePlugin"; import { Chunk } from "./Chunk"; import { Source } from "webpack-sources"; +import { unsupported } from "./util"; +import { makePathsRelative } from "./util/identifier"; export interface AssetEmittedInfo { content: Buffer; @@ -68,39 +70,20 @@ export interface AssetEmittedInfo { class Compiler { #instance?: binding.Rspack; + #initial: boolean; + + #compilation?: Compilation; + #compilationParams?: CompilationParams; + + #builtinPlugins: binding.BuiltinPlugin[]; + + #moduleExecutionResultsMap: Map; + + #nonSkippableRegisters: binding.RegisterJsTapKind[]; + #registers?: binding.RegisterJsTaps; + + #ruleSet: RuleSetCompiler; - webpack = rspack; - compilation?: Compilation; - compilationParams?: CompilationParams; - // TODO: remove this after remove rebuild on the rust side. - #initial: boolean = true; - builtinPlugins: binding.BuiltinPlugin[]; - root: Compiler; - running: boolean; - idle: boolean; - resolverFactory: ResolverFactory; - infrastructureLogger: any; - watching?: Watching; - outputPath!: string; - name?: string; - inputFileSystem: any; - outputFileSystem: typeof import("fs"); - ruleSet: RuleSetCompiler; - // @ts-expect-error - watchFileSystem: WatchFileSystem; - intermediateFileSystem: any; - // @ts-expect-error - watchMode: boolean; - context: string; - cache: Cache; - compilerPath: string; - modifiedFiles?: ReadonlySet; - removedFiles?: ReadonlySet; - fileTimestamps?: ReadonlyMap; - contextTimestamps?: ReadonlyMap< - string, - FileSystemInfoEntry | "ignore" | null - >; hooks: { done: tapable.AsyncSeriesHook; afterDone: tapable.SyncHook; @@ -132,28 +115,50 @@ class Compiler { finishMake: liteTapable.AsyncSeriesHook<[Compilation]>; entryOption: tapable.SyncBailHook<[string, EntryNormalized], any>; }; - options: RspackOptionsNormalized; - #disabledHooks: string[]; - #nonSkippableRegisters: binding.RegisterJsTapKind[]; - #registers?: binding.RegisterJsTaps; + + webpack: typeof rspack; + name?: string; parentCompilation?: Compilation; + root: Compiler; + outputPath: string; - #moduleExecutionResultsMap: Map; + running: boolean; + idle: boolean; + resolverFactory: ResolverFactory; + infrastructureLogger: any; + watching?: Watching; + + inputFileSystem: any; + intermediateFileSystem: any; + outputFileSystem: OutputFileSystem | null; + watchFileSystem: WatchFileSystem | null; + + records: Record; + modifiedFiles?: ReadonlySet; + removedFiles?: ReadonlySet; + fileTimestamps?: ReadonlyMap; + contextTimestamps?: ReadonlyMap< + string, + FileSystemInfoEntry | "ignore" | null + >; + fsStartTime?: number; + + watchMode: boolean; + context: string; + cache: Cache; + compilerPath: string; + options: RspackOptionsNormalized; constructor(context: string, options: RspackOptionsNormalized) { - this.outputFileSystem = fs; - this.options = options; - this.cache = new Cache(); - this.compilerPath = ""; - this.builtinPlugins = []; - this.root = this; - this.ruleSet = new RuleSetCompiler(); - this.running = false; - this.idle = false; - this.context = context; - this.resolverFactory = new ResolverFactory(); - this.modifiedFiles = undefined; - this.removedFiles = undefined; + this.#initial = true; + + this.#builtinPlugins = []; + + this.#nonSkippableRegisters = []; + this.#moduleExecutionResultsMap = new Map(); + + this.#ruleSet = new RuleSetCompiler(); + this.hooks = { initialize: new SyncHook([]), shouldEmit: new liteTapable.SyncBailHook(["compilation"]), @@ -194,16 +199,71 @@ class Compiler { finishMake: new liteTapable.AsyncSeriesHook(["compilation"]), entryOption: new tapable.SyncBailHook(["context", "entry"]) }; - this.modifiedFiles = undefined; - this.removedFiles = undefined; - this.#disabledHooks = []; - this.#nonSkippableRegisters = []; - this.#moduleExecutionResultsMap = new Map(); + + this.webpack = rspack; + this.root = this; + this.outputPath = ""; + + this.inputFileSystem = null; + this.intermediateFileSystem = null; + this.outputFileSystem = null; + this.watchFileSystem = null; + + this.records = {}; + + this.resolverFactory = new ResolverFactory(); + this.options = options; + this.context = context; + this.cache = new Cache(); + + this.compilerPath = ""; + + this.running = false; + + this.idle = false; + + this.watchMode = false; new JsLoaderRspackPlugin(this).apply(this); new ExecuteModulePlugin().apply(this); } + get recordsInputPath() { + return unsupported("Compiler.recordsInputPath"); + } + + get recordsOutputPath() { + return unsupported("Compiler.recordsOutputPath"); + } + + get managedPaths() { + return unsupported("Compiler.managedPaths"); + } + + get immutablePaths() { + return unsupported("Compiler.immutablePaths"); + } + + get _lastCompilation() { + return this.#compilation; + } + + /** + * Note: This is not a webpack public API, maybe removed in future. + * @internal + */ + get __internal__builtinPlugins() { + return this.#builtinPlugins; + } + + /** + * Note: This is not a webpack public API, maybe removed in future. + * @internal + */ + get __internal__ruleSet() { + return this.#ruleSet; + } + /** * @param name - cache name * @returns the cache facade instance @@ -216,6 +276,447 @@ class Compiler { ); } + /** + * @param name - name of the logger, or function called once to get the logger name + * @returns a logger with that name + */ + getInfrastructureLogger(name: string | (() => string)) { + if (!name) { + throw new TypeError( + "Compiler.getInfrastructureLogger(name) called without a name" + ); + } + return new Logger( + (type, args) => { + if (typeof name === "function") { + name = name(); + if (!name) { + throw new TypeError( + "Compiler.getInfrastructureLogger(name) called with a function not returning a name" + ); + } + } else { + if ( + this.hooks.infrastructureLog.call(name, type, args) === undefined + ) { + if (this.infrastructureLogger !== undefined) { + this.infrastructureLogger(name, type, args); + } + } + } + }, + (childName): any => { + if (typeof name === "function") { + if (typeof childName === "function") { + // @ts-expect-error + return this.getInfrastructureLogger(_ => { + if (typeof name === "function") { + name = name(); + if (!name) { + throw new TypeError( + "Compiler.getInfrastructureLogger(name) called with a function not returning a name" + ); + } + } + if (typeof childName === "function") { + childName = childName(); + if (!childName) { + throw new TypeError( + "Logger.getChildLogger(name) called with a function not returning a name" + ); + } + } + return `${name}/${childName}`; + }); + } else { + return this.getInfrastructureLogger(() => { + if (typeof name === "function") { + name = name(); + if (!name) { + throw new TypeError( + "Compiler.getInfrastructureLogger(name) called with a function not returning a name" + ); + } + } + return `${name}/${childName}`; + }); + } + } else { + if (typeof childName === "function") { + return this.getInfrastructureLogger(() => { + if (typeof childName === "function") { + childName = childName(); + if (!childName) { + throw new TypeError( + "Logger.getChildLogger(name) called with a function not returning a name" + ); + } + } + return `${name}/${childName}`; + }); + } else { + return this.getInfrastructureLogger(`${name}/${childName}`); + } + } + } + ); + } + + /** + * @param watchOptions - the watcher's options + * @param handler - signals when the call finishes + * @returns a compiler watcher + */ + watch( + watchOptions: Watchpack.WatchOptions, + handler: Callback + ): Watching { + if (this.running) { + // @ts-expect-error + return handler(new ConcurrentCompilationError()); + } + this.running = true; + this.watchMode = true; + // @ts-expect-error + this.watching = new Watching(this, watchOptions, handler); + return this.watching; + } + + /** + * @param callback - signals when the call finishes + */ + run(callback: Callback) { + if (this.running) { + return callback(new ConcurrentCompilationError()); + } + const startTime = Date.now(); + this.running = true; + const doRun = () => { + // @ts-expect-error + const finalCallback = (err, stats?) => { + this.idle = true; + this.cache.beginIdle(); + this.idle = true; + this.running = false; + if (err) { + this.hooks.failed.call(err); + } + if (callback) { + callback(err, stats); + } + this.hooks.afterDone.call(stats); + }; + this.hooks.beforeRun.callAsync(this, err => { + if (err) { + return finalCallback(err); + } + this.hooks.run.callAsync(this, err => { + if (err) { + return finalCallback(err); + } + + this.compile(err => { + if (err) { + return finalCallback(err); + } + this.#compilation!.startTime = startTime; + this.#compilation!.endTime = Date.now(); + const stats = new Stats(this.#compilation!); + this.hooks.done.callAsync(stats, err => { + if (err) { + return finalCallback(err); + } else { + return finalCallback(null, stats); + } + }); + }); + }); + }); + }; + + if (this.idle) { + this.cache.endIdle(err => { + if (err) return callback(err); + + this.idle = false; + doRun(); + }); + } else { + doRun(); + } + } + + runAsChild( + callback: ( + err?: null | Error, + entries?: Chunk[], + compilation?: Compilation + ) => any + ) { + const finalCallback = ( + err: Error | null, + entries?: Chunk[], + compilation?: Compilation + ) => { + try { + callback(err, entries, compilation); + } catch (e) { + const err = new Error(`compiler.runAsChild callback error: ${e}`); + // err.details = e.stack; + this.parentCompilation!.errors.push(err); + // TODO: remove once this works + console.log(e); + } + }; + + this.compile((err, compilation) => { + if (err) { + return finalCallback(err); + } + + assertNotNill(compilation); + + this.parentCompilation!.children.push(compilation); + for (const { name, source, info } of compilation.getAssets()) { + // Do not emit asset if source is not available. + // Webpack will emit it anyway. + if (source) { + this.parentCompilation!.emitAsset(name, source, info); + } + } + + const entries = []; + for (const ep of compilation.entrypoints.values()) { + entries.push(...ep.chunks); + } + + return finalCallback(null, entries, compilation); + }); + } + + purgeInputFileSystem() { + if (this.inputFileSystem && this.inputFileSystem.purge) { + this.inputFileSystem.purge(); + } + } + + /** + * @param compilation - the compilation + * @param compilerName - the compiler's name + * @param compilerIndex - the compiler's index + * @param outputOptions - the output options + * @param plugins - the plugins to apply + * @returns a child compiler + */ + createChildCompiler( + compilation: Compilation, + compilerName: string, + compilerIndex: number, + outputOptions: OutputNormalized, + plugins: RspackPluginInstance[] + ): Compiler { + const options: RspackOptionsNormalized = { + ...this.options, + output: { + ...this.options.output, + ...outputOptions + }, + // TODO: check why we need to have builtins otherwise this.#instance will fail to initialize Rspack + builtins: this.options.builtins + }; + applyRspackOptionsDefaults(options); + const childCompiler = new Compiler(this.context, options); + childCompiler.name = compilerName; + childCompiler.outputPath = this.outputPath; + childCompiler.inputFileSystem = this.inputFileSystem; + childCompiler.outputFileSystem = null; + childCompiler.resolverFactory = this.resolverFactory; + childCompiler.modifiedFiles = this.modifiedFiles; + childCompiler.removedFiles = this.removedFiles; + childCompiler.fileTimestamps = this.fileTimestamps; + childCompiler.contextTimestamps = this.contextTimestamps; + childCompiler.fsStartTime = this.fsStartTime; + childCompiler.cache = this.cache; + childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`; + + const relativeCompilerName = makePathsRelative( + this.context, + compilerName, + this.root + ); + if (!this.records[relativeCompilerName]) { + this.records[relativeCompilerName] = []; + } + if (this.records[relativeCompilerName][compilerIndex]) { + childCompiler.records = this.records[relativeCompilerName][compilerIndex]; + } else { + this.records[relativeCompilerName].push((childCompiler.records = {})); + } + + childCompiler.parentCompilation = compilation; + childCompiler.root = this.root; + if (Array.isArray(plugins)) { + for (const plugin of plugins) { + if (plugin) { + plugin.apply(childCompiler); + } + } + } + + childCompiler.#builtinPlugins = [ + ...childCompiler.#builtinPlugins, + ...this.#builtinPlugins.filter( + plugin => plugin.canInherentFromParent === true + ) + ]; + + for (const name in this.hooks) { + if (canInherentFromParent(name as keyof Compiler["hooks"])) { + //@ts-ignore + if (childCompiler.hooks[name]) { + //@ts-ignore + childCompiler.hooks[name].taps = this.hooks[name].taps.slice(); + } + } + } + + compilation.hooks.childCompiler.call( + childCompiler, + compilerName, + compilerIndex + ); + + return childCompiler; + } + + isChild() { + const isRoot = this.root === this; + return !isRoot; + } + + compile(callback: Callback) { + const startTime = Date.now(); + const params = this.#newCompilationParams(); + this.hooks.beforeCompile.callAsync(params, (err: any) => { + if (err) { + return callback(err); + } + this.hooks.compile.call(params); + this.#resetThisCompilation(); + + this.#build(err => { + if (err) { + return callback(err); + } + this.#compilation!.startTime = startTime; + this.#compilation!.endTime = Date.now(); + this.hooks.afterCompile.callAsync(this.#compilation!, err => { + if (err) { + return callback(err); + } + return callback(null, this.#compilation); + }); + }); + }); + } + + close(callback: (error?: Error | null) => void) { + if (this.watching) { + // When there is still an active watching, close this #initial + this.watching.close(() => { + this.close(callback); + }); + return; + } + this.hooks.shutdown.callAsync(err => { + if (err) return callback(err); + this.cache.shutdown(callback); + }); + } + + #build(callback?: (error: Error | null) => void) { + this.#getInstance((error, instance) => { + if (error) { + return callback?.(error); + } + if (!this.#initial) { + instance!.rebuild( + Array.from(this.modifiedFiles || []), + Array.from(this.removedFiles || []), + error => { + if (error) { + return callback?.(error); + } + callback?.(null); + } + ); + return; + } + this.#initial = false; + instance!.build(error => { + if (error) { + return callback?.(error); + } + callback?.(null); + }); + }); + } + + /** + * Note: This is not a webpack public API, maybe removed in future. + * @internal + */ + __internal__rebuild( + modifiedFiles?: ReadonlySet, + removedFiles?: ReadonlySet, + callback?: (error: Error | null) => void + ) { + this.#getInstance((error, instance) => { + if (error) { + return callback?.(error); + } + instance!.rebuild( + Array.from(modifiedFiles || []), + Array.from(removedFiles || []), + error => { + if (error) { + return callback?.(error); + } + callback?.(null); + } + ); + }); + } + + #createCompilation(native: binding.JsCompilation): Compilation { + const compilation = new Compilation(this, native); + compilation.name = this.name; + this.#compilation = compilation; + return compilation; + } + + #resetThisCompilation() { + // reassign new compilation in thisCompilation + this.#compilation = undefined; + // ensure thisCompilation must call + this.hooks.thisCompilation.intercept({ + call: () => {} + }); + } + + #newCompilationParams(): CompilationParams { + const normalModuleFactory = new NormalModuleFactory(); + this.hooks.normalModuleFactory.call(normalModuleFactory); + const contextModuleFactory = new ContextModuleFactory(); + this.hooks.contextModuleFactory.call(contextModuleFactory); + const params = { + normalModuleFactory, + contextModuleFactory + }; + this.#compilationParams = params; + return params; + } + /** * Lazy initialize instance so it could access the changed options */ @@ -246,42 +747,42 @@ class Compiler { binding.RegisterJsTapKind.CompilerThisCompilation, () => this.hooks.thisCompilation, queried => (native: binding.JsCompilation) => { - if (this.compilation === undefined) { + if (this.#compilation === undefined) { this.#createCompilation(native); } - queried.call(this.compilation!, this.compilationParams!); + queried.call(this.#compilation!, this.#compilationParams!); } ), registerCompilerCompilationTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerCompilation, () => this.hooks.compilation, queried => () => - queried.call(this.compilation!, this.compilationParams!) + queried.call(this.#compilation!, this.#compilationParams!) ), registerCompilerMakeTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerMake, () => this.hooks.make, - queried => async () => await queried.promise(this.compilation!) + queried => async () => await queried.promise(this.#compilation!) ), registerCompilerFinishMakeTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerFinishMake, () => this.hooks.finishMake, - queried => async () => await queried.promise(this.compilation!) + queried => async () => await queried.promise(this.#compilation!) ), registerCompilerShouldEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerShouldEmit, () => this.hooks.shouldEmit, - queried => () => queried.call(this.compilation!) + queried => () => queried.call(this.#compilation!) ), registerCompilerEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerEmit, () => this.hooks.emit, - queried => async () => await queried.promise(this.compilation!) + queried => async () => await queried.promise(this.#compilation!) ), registerCompilerAfterEmitTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerAfterEmit, () => this.hooks.afterEmit, - queried => async () => await queried.promise(this.compilation!) + queried => async () => await queried.promise(this.#compilation!) ), registerCompilerAssetEmittedTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilerAssetEmitted, @@ -293,7 +794,7 @@ class Compiler { outputPath }: binding.JsAssetEmittedArgs) => { return queried.promise(filename, { - compilation: this.compilation!, + compilation: this.#compilation!, targetPath, outputPath, get source() { @@ -307,13 +808,13 @@ class Compiler { ), registerCompilationRuntimeModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationRuntimeModule, - () => this.compilation!.hooks.runtimeModule, + () => this.#compilation!.hooks.runtimeModule, queried => ({ module, chunk }: binding.JsRuntimeModuleArg) => { const originSource = module.source?.source; queried.call( module, - Chunk.__from_binding(chunk, this.compilation!) + Chunk.__from_binding(chunk, this.#compilation!) ); const newSource = module.source?.source; if (newSource && newSource !== originSource) { @@ -324,25 +825,25 @@ class Compiler { ), registerCompilationBuildModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationBuildModule, - () => this.compilation!.hooks.buildModule, + () => this.#compilation!.hooks.buildModule, queired => (m: binding.JsModule) => queired.call(Module.__from_binding(m)) ), registerCompilationStillValidModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationStillValidModule, - () => this.compilation!.hooks.stillValidModule, + () => this.#compilation!.hooks.stillValidModule, queired => (m: binding.JsModule) => queired.call(Module.__from_binding(m)) ), registerCompilationSucceedModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationSucceedModule, - () => this.compilation!.hooks.succeedModule, + () => this.#compilation!.hooks.succeedModule, queired => (m: binding.JsModule) => queired.call(Module.__from_binding(m)) ), registerCompilationExecuteModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationExecuteModule, - () => this.compilation!.hooks.executeModule, + () => this.#compilation!.hooks.executeModule, queried => ({ entry, @@ -416,66 +917,67 @@ class Compiler { ), registerCompilationFinishModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationFinishModules, - () => this.compilation!.hooks.finishModules, - queried => async () => await queried.promise(this.compilation!.modules) + () => this.#compilation!.hooks.finishModules, + queried => async () => await queried.promise(this.#compilation!.modules) ), registerCompilationOptimizeModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationOptimizeModules, - () => this.compilation!.hooks.optimizeModules, - queried => () => queried.call(this.compilation!.modules) + () => this.#compilation!.hooks.optimizeModules, + queried => () => queried.call(this.#compilation!.modules) ), registerCompilationAfterOptimizeModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationAfterOptimizeModules, - () => this.compilation!.hooks.afterOptimizeModules, - queried => () => queried.call(this.compilation!.modules) + () => this.#compilation!.hooks.afterOptimizeModules, + queried => () => queried.call(this.#compilation!.modules) ), registerCompilationOptimizeTreeTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationOptimizeTree, - () => this.compilation!.hooks.optimizeTree, + () => this.#compilation!.hooks.optimizeTree, queried => async () => await queried.promise( - this.compilation!.chunks, - this.compilation!.modules + this.#compilation!.chunks, + this.#compilation!.modules ) ), registerCompilationOptimizeChunkModulesTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationOptimizeChunkModules, - () => this.compilation!.hooks.optimizeChunkModules, + () => this.#compilation!.hooks.optimizeChunkModules, queried => async () => await queried.promise( - this.compilation!.chunks, - this.compilation!.modules + this.#compilation!.chunks, + this.#compilation!.modules ) ), registerCompilationChunkAssetTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationChunkAsset, - () => this.compilation!.hooks.chunkAsset, + () => this.#compilation!.hooks.chunkAsset, queried => ({ chunk, filename }: binding.JsChunkAssetArgs) => queried.call( - Chunk.__from_binding(chunk, this.compilation!), + Chunk.__from_binding(chunk, this.#compilation!), filename ) ), registerCompilationProcessAssetsTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationProcessAssets, - () => this.compilation!.hooks.processAssets, - queried => async () => await queried.promise(this.compilation!.assets) + () => this.#compilation!.hooks.processAssets, + queried => async () => await queried.promise(this.#compilation!.assets) ), registerCompilationAfterProcessAssetsTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationAfterProcessAssets, - () => this.compilation!.hooks.afterProcessAssets, - queried => () => queried.call(this.compilation!.assets) + () => this.#compilation!.hooks.afterProcessAssets, + queried => () => queried.call(this.#compilation!.assets) ), registerCompilationAfterSealTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.CompilationAfterSeal, - () => this.compilation!.hooks.afterSeal, + () => this.#compilation!.hooks.afterSeal, queried => async () => await queried.promise() ), registerNormalModuleFactoryBeforeResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryBeforeResolve, - () => this.compilationParams!.normalModuleFactory.hooks.beforeResolve, + () => + this.#compilationParams!.normalModuleFactory.hooks.beforeResolve, queried => async (resolveData: binding.JsBeforeResolveArgs) => { const normalizedResolveData: ResolveData = { request: resolveData.request, @@ -494,7 +996,7 @@ class Compiler { this.#createHookMapRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryResolveForScheme, () => - this.compilationParams!.normalModuleFactory.hooks.resolveForScheme, + this.#compilationParams!.normalModuleFactory.hooks.resolveForScheme, queried => async (args: binding.JsResolveForSchemeArgs) => { const ret = await queried .for(args.scheme) @@ -504,7 +1006,7 @@ class Compiler { ), registerNormalModuleFactoryAfterResolveTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryAfterResolve, - () => this.compilationParams!.normalModuleFactory.hooks.afterResolve, + () => this.#compilationParams!.normalModuleFactory.hooks.afterResolve, queried => async (arg: binding.JsAfterResolveData) => { const data: ResolveData = { request: arg.request, @@ -520,286 +1022,75 @@ class Compiler { ), registerNormalModuleFactoryCreateModuleTaps: this.#createHookRegisterTaps( binding.RegisterJsTapKind.NormalModuleFactoryCreateModule, - () => this.compilationParams!.normalModuleFactory.hooks.createModule, + () => this.#compilationParams!.normalModuleFactory.hooks.createModule, queried => async (args: binding.JsNormalModuleFactoryCreateModuleArgs) => { const data: NormalModuleCreateData = { ...args, - settings: {} - }; - await queried.promise(data, {}); - } - ), - registerContextModuleFactoryBeforeResolveTaps: - this.#createHookRegisterTaps( - binding.RegisterJsTapKind.ContextModuleFactoryBeforeResolve, - () => - this.compilationParams!.contextModuleFactory.hooks.beforeResolve, - queried => - async ( - bindingData: - | false - | binding.JsContextModuleFactoryBeforeResolveData - ) => { - return queried.promise(bindingData); - } - ), - registerContextModuleFactoryAfterResolveTaps: - this.#createHookRegisterTaps( - binding.RegisterJsTapKind.ContextModuleFactoryAfterResolve, - () => this.compilationParams!.contextModuleFactory.hooks.afterResolve, - queried => - async ( - bindingData: - | false - | binding.JsContextModuleFactoryAfterResolveData - ) => { - const data = bindingData - ? ({ - resource: bindingData.resource, - regExp: bindingData.regExp - ? new RegExp(bindingData.regExp) - : undefined, - request: bindingData.request, - context: bindingData.context, - // TODO: Dependencies are not fully supported yet; this is a placeholder to prevent errors in moment-locales-webpack-plugin. - dependencies: [] - } satisfies ContextModuleFactoryAfterResolveResult) - : false; - const ret = await queried.promise(data); - const result = ret - ? ({ - resource: ret.resource, - context: ret.context, - request: ret.request, - regExp: ret.regExp?.toString() - } satisfies binding.JsContextModuleFactoryAfterResolveData) - : false; - return result; - } - ) - }; - - this.#instance = new instanceBinding.Rspack( - rawOptions, - this.builtinPlugins, - this.#registers, - createThreadsafeNodeFSFromRaw(this.outputFileSystem) - ); - - callback(null, this.#instance); - } - - createChildCompiler( - compilation: Compilation, - compilerName: string, - compilerIndex: number, - outputOptions: OutputNormalized, - plugins: RspackPluginInstance[] - ): Compiler { - const options: RspackOptionsNormalized = { - ...this.options, - output: { - ...this.options.output, - ...outputOptions - }, - // TODO: check why we need to have builtins otherwise this.#instance will fail to initialize Rspack - builtins: this.options.builtins - }; - applyRspackOptionsDefaults(options); - const childCompiler = new Compiler(this.context, options); - childCompiler.name = compilerName; - childCompiler.outputPath = this.outputPath; - childCompiler.inputFileSystem = this.inputFileSystem; - // childCompiler.outputFileSystem = null; - childCompiler.resolverFactory = this.resolverFactory; - childCompiler.modifiedFiles = this.modifiedFiles; - childCompiler.removedFiles = this.removedFiles; - // childCompiler.fileTimestamps = this.fileTimestamps; - // childCompiler.contextTimestamps = this.contextTimestamps; - // childCompiler.fsStartTime = this.fsStartTime; - childCompiler.cache = this.cache; - childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`; - // childCompiler._backCompat = this._backCompat; - - // const relativeCompilerName = makePathsRelative( - // this.context, - // compilerName, - // this.root - // ); - // if (!this.records[relativeCompilerName]) { - // this.records[relativeCompilerName] = []; - // } - // if (this.records[relativeCompilerName][compilerIndex]) { - // childCompiler.records = this.records[relativeCompilerName][compilerIndex]; - // } else { - // this.records[relativeCompilerName].push((childCompiler.records = {})); - // } - - childCompiler.parentCompilation = compilation; - childCompiler.root = this.root; - if (Array.isArray(plugins)) { - for (const plugin of plugins) { - if (plugin) { - plugin.apply(childCompiler); - } - } - } - - childCompiler.builtinPlugins = [ - ...childCompiler.builtinPlugins, - ...this.builtinPlugins.filter( - plugin => plugin.canInherentFromParent === true - ) - ]; - - for (const name in this.hooks) { - if (canInherentFromParent(name as keyof Compiler["hooks"])) { - //@ts-ignore - if (childCompiler.hooks[name]) { - //@ts-ignore - childCompiler.hooks[name].taps = this.hooks[name].taps.slice(); - } - } - } - - compilation.hooks.childCompiler.call( - childCompiler, - compilerName, - compilerIndex - ); - - return childCompiler; - } - - runAsChild(callback: any) { - const finalCallback = ( - err: Error | null, - entries?: any, - compilation?: Compilation - ) => { - try { - callback(err, entries, compilation); - } catch (e) { - const err = new Error(`compiler.runAsChild callback error: ${e}`); - // err.details = e.stack; - this.parentCompilation!.errors.push(err); - // TODO: remove once this works - console.log(e); - } - }; - - this.compile((err, compilation) => { - if (err) { - return finalCallback(err); - } - - assertNotNill(compilation); - - this.parentCompilation!.children.push(compilation); - for (const { name, source, info } of compilation.getAssets()) { - // Do not emit asset if source is not available. - // Webpack will emit it anyway. - if (source) { - this.parentCompilation!.emitAsset(name, source, info); - } - } - - const entries = []; - for (const ep of compilation.entrypoints.values()) { - entries.push(...ep.getFiles()); - } - - return finalCallback(null, entries, compilation); - }); - } - - isChild(): boolean { - const isRoot = this.root === this; - return !isRoot; - } - - getInfrastructureLogger(name: string | Function) { - if (!name) { - throw new TypeError( - "Compiler.getInfrastructureLogger(name) called without a name" - ); - } - return new Logger( - (type, args) => { - if (typeof name === "function") { - name = name(); - if (!name) { - throw new TypeError( - "Compiler.getInfrastructureLogger(name) called with a function not returning a name" - ); - } - } else { - if ( - // @ts-expect-error - this.hooks.infrastructureLog.call(name, type, args) === undefined - ) { - if (this.infrastructureLogger !== undefined) { - this.infrastructureLogger(name, type, args); - } - } - } - }, - (childName): any => { - if (typeof name === "function") { - if (typeof childName === "function") { - // @ts-expect-error - return this.getInfrastructureLogger(_ => { - if (typeof name === "function") { - name = name(); - if (!name) { - throw new TypeError( - "Compiler.getInfrastructureLogger(name) called with a function not returning a name" - ); - } - } - if (typeof childName === "function") { - childName = childName(); - if (!childName) { - throw new TypeError( - "Logger.getChildLogger(name) called with a function not returning a name" - ); - } - } - return `${name}/${childName}`; - }); - } else { - return this.getInfrastructureLogger(() => { - if (typeof name === "function") { - name = name(); - if (!name) { - throw new TypeError( - "Compiler.getInfrastructureLogger(name) called with a function not returning a name" - ); - } - } - return `${name}/${childName}`; - }); - } - } else { - if (typeof childName === "function") { - return this.getInfrastructureLogger(() => { - if (typeof childName === "function") { - childName = childName(); - if (!childName) { - throw new TypeError( - "Logger.getChildLogger(name) called with a function not returning a name" - ); - } - } - return `${name}/${childName}`; - }); - } else { - return this.getInfrastructureLogger(`${name}/${childName}`); + settings: {} + }; + await queried.promise(data, {}); } - } - } + ), + registerContextModuleFactoryBeforeResolveTaps: + this.#createHookRegisterTaps( + binding.RegisterJsTapKind.ContextModuleFactoryBeforeResolve, + () => + this.#compilationParams!.contextModuleFactory.hooks.beforeResolve, + queried => + async ( + bindingData: + | false + | binding.JsContextModuleFactoryBeforeResolveData + ) => { + return queried.promise(bindingData); + } + ), + registerContextModuleFactoryAfterResolveTaps: + this.#createHookRegisterTaps( + binding.RegisterJsTapKind.ContextModuleFactoryAfterResolve, + () => + this.#compilationParams!.contextModuleFactory.hooks.afterResolve, + queried => + async ( + bindingData: + | false + | binding.JsContextModuleFactoryAfterResolveData + ) => { + const data = bindingData + ? ({ + resource: bindingData.resource, + regExp: bindingData.regExp + ? new RegExp(bindingData.regExp) + : undefined, + request: bindingData.request, + context: bindingData.context, + // TODO: Dependencies are not fully supported yet; this is a placeholder to prevent errors in moment-locales-webpack-plugin. + dependencies: [] + } satisfies ContextModuleFactoryAfterResolveResult) + : false; + const ret = await queried.promise(data); + const result = ret + ? ({ + resource: ret.resource, + context: ret.context, + request: ret.request, + regExp: ret.regExp?.toString() + } satisfies binding.JsContextModuleFactoryAfterResolveData) + : false; + return result; + } + ) + }; + + this.#instance = new instanceBinding.Rspack( + rawOptions, + this.#builtinPlugins, + this.#registers, + ThreadsafeWritableNodeFS.__into_binding(this.outputFileSystem!) ); + + callback(null, this.#instance); } #updateNonSkippableRegisters() { @@ -905,220 +1196,8 @@ class Compiler { return getTaps; } - run(callback: Callback) { - if (this.running) { - return callback(new ConcurrentCompilationError()); - } - const startTime = Date.now(); - this.running = true; - const doRun = () => { - // @ts-expect-error - const finalCallback = (err, stats?) => { - this.idle = true; - this.cache.beginIdle(); - this.idle = true; - this.running = false; - if (err) { - this.hooks.failed.call(err); - } - if (callback) { - callback(err, stats); - } - this.hooks.afterDone.call(stats); - }; - this.hooks.beforeRun.callAsync(this, err => { - if (err) { - return finalCallback(err); - } - this.hooks.run.callAsync(this, err => { - if (err) { - return finalCallback(err); - } - - this.compile(err => { - if (err) { - return finalCallback(err); - } - this.compilation!.startTime = startTime; - this.compilation!.endTime = Date.now(); - const stats = new Stats(this.compilation!); - this.hooks.done.callAsync(stats, err => { - if (err) { - return finalCallback(err); - } else { - return finalCallback(null, stats); - } - }); - }); - }); - }); - }; - - if (this.idle) { - this.cache.endIdle(err => { - if (err) return callback(err); - - this.idle = false; - doRun(); - }); - } else { - doRun(); - } - } - #build(callback?: (error: Error | null) => void) { - this.#getInstance((error, instance) => { - if (error) { - return callback?.(error); - } - if (!this.#initial) { - instance!.rebuild( - Array.from(this.modifiedFiles || []), - Array.from(this.removedFiles || []), - error => { - if (error) { - return callback?.(error); - } - callback?.(null); - } - ); - return; - } - this.#initial = false; - instance!.build(error => { - if (error) { - return callback?.(error); - } - callback?.(null); - }); - }); - } - - /** - * * Note: This is not a webpack public API, maybe removed in future. - * @internal - */ - __internal__rebuild( - modifiedFiles?: ReadonlySet, - removedFiles?: ReadonlySet, - callback?: (error: Error | null) => void - ) { - this.#getInstance((error, instance) => { - if (error) { - return callback?.(error); - } - instance!.rebuild( - Array.from(modifiedFiles || []), - Array.from(removedFiles || []), - error => { - if (error) { - return callback?.(error); - } - callback?.(null); - } - ); - }); - } - - #createCompilation(native: binding.JsCompilation): Compilation { - const compilation = new Compilation(this, native); - compilation.name = this.name; - this.compilation = compilation; - return compilation; - } - - #resetThisCompilation() { - // reassign new compilation in thisCompilation - this.compilation = undefined; - // ensure thisCompilation must call - this.hooks.thisCompilation.intercept({ - call: () => {} - }); - } - - #newCompilationParams(): CompilationParams { - const normalModuleFactory = new NormalModuleFactory(); - this.hooks.normalModuleFactory.call(normalModuleFactory); - const contextModuleFactory = new ContextModuleFactory(); - this.hooks.contextModuleFactory.call(contextModuleFactory); - const params = { - normalModuleFactory, - contextModuleFactory - }; - this.compilationParams = params; - return params; - } - - compile(callback: Callback) { - const startTime = Date.now(); - const params = this.#newCompilationParams(); - this.hooks.beforeCompile.callAsync(params, (err: any) => { - if (err) { - return callback(err); - } - this.hooks.compile.call(params); - this.#resetThisCompilation(); - - this.#build(err => { - if (err) { - return callback(err); - } - this.compilation!.startTime = startTime; - this.compilation!.endTime = Date.now(); - this.hooks.afterCompile.callAsync(this.compilation!, err => { - if (err) { - return callback(err); - } - return callback(null, this.compilation); - }); - }); - }); - } - - watch( - watchOptions: Watchpack.WatchOptions, - handler: Callback - ): Watching { - if (this.running) { - // @ts-expect-error - return handler(new ConcurrentCompilationError()); - } - this.running = true; - this.watchMode = true; - // @ts-expect-error - this.watching = new Watching(this, watchOptions, handler); - return this.watching; - } - - purgeInputFileSystem() { - if (this.inputFileSystem && this.inputFileSystem.purge) { - this.inputFileSystem.purge(); - } - } - - close(callback: (error?: Error | null) => void) { - if (this.watching) { - // When there is still an active watching, close this #initial - this.watching.close(() => { - this.close(callback); - }); - return; - } - this.hooks.shutdown.callAsync(err => { - if (err) return callback(err); - this.cache.shutdown(callback); - }); - } - - getAsset(name: string) { - let source = this.compilation!.__internal__getAssetSource(name); - if (!source) { - return null; - } - return source.buffer(); - } - __internal__registerBuiltinPlugin(plugin: binding.BuiltinPlugin) { - this.builtinPlugins.push(plugin); + this.#builtinPlugins.push(plugin); } __internal__getModuleExecutionResult(id: number) { diff --git a/packages/rspack/src/MultiCompiler.ts b/packages/rspack/src/MultiCompiler.ts index e4545087273b..e8defa8213b6 100644 --- a/packages/rspack/src/MultiCompiler.ts +++ b/packages/rspack/src/MultiCompiler.ts @@ -9,10 +9,14 @@ */ import { Compiler, RspackOptions, Stats } from "."; -import ResolverFactory = require("./ResolverFactory"); import { WatchFileSystem } from "./util/fs"; -import { Watching } from "./Watching"; -import { AsyncSeriesHook, Callback, MultiHook, SyncHook } from "tapable"; +import { + AsyncSeriesHook, + Callback, + MultiHook, + SyncBailHook, + SyncHook +} from "tapable"; import MultiStats from "./MultiStats"; import asyncLib from "neo-async"; import ArrayQueue from "./util/ArrayQueue"; @@ -20,8 +24,6 @@ import ConcurrentCompilationError from "./error/ConcurrentCompilationError"; import MultiWatching from "./MultiWatching"; import { WatchOptions } from "./config"; -type Any = any; - interface Node { compiler: Compiler; children: Node[]; @@ -49,31 +51,18 @@ export type MultiRspackOptions = ReadonlyArray & MultiCompilerOptions; export class MultiCompiler { - // @ts-expect-error - context: string; compilers: Compiler[]; dependencies: WeakMap; hooks: { done: SyncHook; invalid: MultiHook>; run: MultiHook>; - watchClose: SyncHook; - watchRun: MultiHook; - infrastructureLog: MultiHook; + watchClose: SyncHook<[]>; + watchRun: MultiHook>; + infrastructureLog: MultiHook>; }; - // @ts-expect-error - name: string; - infrastructureLogger: Any; - _options: { parallelism?: number }; - // @ts-expect-error - root: Compiler; - // @ts-expect-error - resolverFactory: ResolverFactory; + _options: MultiCompilerOptions; running: boolean; - // @ts-expect-error - watching: Watching; - // @ts-expect-error - watchMode: boolean; constructor( compilers: Compiler[] | Record, @@ -190,7 +179,7 @@ export class MultiCompiler { } } - set intermediateFileSystem(value: any) { + set intermediateFileSystem(value) { for (const compiler of this.compilers) { compiler.intermediateFileSystem = value; } diff --git a/packages/rspack/src/Watching.ts b/packages/rspack/src/Watching.ts index d743771720ce..7d5d66df6c93 100644 --- a/packages/rspack/src/Watching.ts +++ b/packages/rspack/src/Watching.ts @@ -75,7 +75,8 @@ export class Watching { missing: Iterable ) { this.pausedWatcher = undefined; - this.watcher = this.compiler.watchFileSystem.watch( + // SAFETY: `watchFileSystem` is expected to be initialized. + this.watcher = this.compiler.watchFileSystem!.watch( files, dirs, missing, @@ -275,7 +276,7 @@ export class Watching { const onCompile = (err: Error | null) => { if (err) return this._done(err, null); // if (this.invalid) return this._done(null); - this._done(null, this.compiler.compilation!); + this._done(null, this.compiler._lastCompilation!); }; this.compiler.compile(onCompile); diff --git a/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts b/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts index 5ffd87cdd48b..750238ffb3ce 100644 --- a/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts @@ -78,7 +78,7 @@ function toRawSplitChunksOptions( chunks( Chunk.__from_binding( chunk, - compiler.compilation!.__internal_getInner() + compiler._lastCompilation!.__internal_getInner() ) ); } else { diff --git a/packages/rspack/src/config/adapterRuleUse.ts b/packages/rspack/src/config/adapterRuleUse.ts index bf443acaee7c..2003cd9e1dc7 100644 --- a/packages/rspack/src/config/adapterRuleUse.ts +++ b/packages/rspack/src/config/adapterRuleUse.ts @@ -18,6 +18,7 @@ import { resolveReact, resolveRelay } from "../builtin-loader"; +import { Compilation } from "../Compilation"; const BUILTIN_LOADER_PREFIX = "builtin:"; @@ -154,7 +155,7 @@ export interface LoaderContext { query: string | OptionsType; data: unknown; _compiler: Compiler; - _compilation: Compiler["compilation"]; + _compilation: Compilation; /** * Internal field for interoperability. * Do not use this in anywhere else. @@ -313,7 +314,7 @@ function resolveStringifyLoaders( if (use.options && typeof use.options === "object") { if (!ident) ident = "[[missing ident]]"; - compiler.ruleSet.references.set(ident, use.options); + compiler.__internal__ruleSet.references.set(ident, use.options); } return obj.path + obj.query + obj.fragment; diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 1ed69d78c8dd..45a210c421a4 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -81,6 +81,8 @@ import { createHash } from "./util/createHash"; import { cachedCleverMerge as cleverMerge } from "./util/cleverMerge"; export const util = { createHash, cleverMerge }; +export { type OutputFileSystem } from "./util/fs"; + export { registerGlobalTrace as experimental_registerGlobalTrace, cleanupGlobalTrace as experimental_cleanupGlobalTrace diff --git a/packages/rspack/src/fileSystem.ts b/packages/rspack/src/fileSystem.ts index 9d1743a76256..2f455593ce27 100644 --- a/packages/rspack/src/fileSystem.ts +++ b/packages/rspack/src/fileSystem.ts @@ -1,66 +1,40 @@ import util from "util"; -import { join } from "path"; +import { ThreadsafeNodeFS } from "@rspack/binding"; + import { memoizeFn } from "./util/memoize"; +import { OutputFileSystem, rmrf, mkdirp } from "./util/fs"; -export interface ThreadsafeWritableNodeFS { - writeFile: (...args: any[]) => any; - removeFile: (...args: any[]) => any; - mkdir: (...args: any[]) => any; - mkdirp: (...args: any[]) => any; - removeDirAll: (...args: any[]) => any; -} +const NOOP_FILESYSTEM: ThreadsafeNodeFS = { + writeFile() {}, + removeFile() {}, + mkdir() {}, + mkdirp() {}, + removeDirAll() {} +}; -function createThreadsafeNodeFSFromRaw( - fs: typeof import("fs") -): ThreadsafeWritableNodeFS { - let writeFile = memoizeFn(() => util.promisify(fs.writeFile.bind(fs))); - let removeFile = memoizeFn(() => util.promisify(fs.unlink.bind(fs))); - let mkdir = memoizeFn(() => util.promisify(fs.mkdir.bind(fs))); - return { - writeFile, - removeFile, - mkdir, - mkdirp: dir => { - return mkdir(dir, { - recursive: true - }); - }, - removeDirAll: dir => { - // memfs don't support rmSync - return rmrfBuild(fs)(dir); - } - }; -} +class ThreadsafeWritableNodeFS implements ThreadsafeNodeFS { + writeFile!: (name: string, content: Buffer) => Promise | void; + removeFile!: (name: string) => Promise | void; + mkdir!: (name: string) => Promise | void; + mkdirp!: (name: string) => Promise | string | void; + removeDirAll!: (name: string) => Promise | string | void; -const rmrfBuild = (fs: typeof import("fs")) => { - async function exists(path: string) { - try { - await util.promisify(fs.access.bind(fs))(path); - return true; - } catch { - return false; + constructor(fs?: OutputFileSystem) { + if (!fs) { + // This happens when located in a child compiler. + Object.assign(this, NOOP_FILESYSTEM); + return; } + this.writeFile = memoizeFn(() => util.promisify(fs.writeFile.bind(fs))); + this.removeFile = memoizeFn(() => util.promisify(fs.unlink.bind(fs))); + this.mkdir = memoizeFn(() => util.promisify(fs.mkdir.bind(fs))); + this.mkdirp = memoizeFn(() => util.promisify(mkdirp.bind(null, fs))); + this.removeDirAll = memoizeFn(() => util.promisify(rmrf.bind(null, fs))); } - const rmrf = async (dir: string) => { - if (await exists(dir)) { - const files = await util.promisify(fs.readdir.bind(fs))(dir); - await Promise.all( - files - .map(f => join(dir, f)) - .map(async filePath => { - if ( - (await util.promisify(fs.lstat.bind(fs))(filePath)).isDirectory() - ) { - await rmrf(filePath); - } else { - await util.promisify(fs.unlink.bind(fs))(filePath); - } - }) - ); - await util.promisify(fs.rmdir.bind(fs))(dir); - } - }; - return rmrf; -}; -export { createThreadsafeNodeFSFromRaw }; + static __into_binding(fs?: OutputFileSystem) { + return new this(fs); + } +} + +export { ThreadsafeWritableNodeFS }; diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index 69bf0f64d10b..3edf00fc0f42 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -193,7 +193,7 @@ export async function runLoaders( "provide an 'ident' property for referenced loader options." ); } - obj.options = compiler.ruleSet.references.get(ident); + obj.options = compiler.__internal__ruleSet.references.get(ident); if (obj.options === undefined) { throw new Error( `Invalid ident("${ident}") is provided by referenced loader` @@ -250,7 +250,7 @@ export async function runLoaders( if (!callback) { return new Promise((resolve, reject) => { compiler - .compilation!.__internal_getInner() + ._lastCompilation!.__internal_getInner() .importModule( request, options.publicPath, @@ -281,7 +281,7 @@ export async function runLoaders( }); } return compiler - .compilation!.__internal_getInner() + ._lastCompilation!.__internal_getInner() .importModule( request, options.publicPath, @@ -461,7 +461,7 @@ export async function runLoaders( }; }; loaderContext.getLogger = function getLogger(name) { - return compiler.compilation!.getLogger( + return compiler._lastCompilation!.getLogger( [name, resource].filter(Boolean).join("|") ); }; @@ -470,7 +470,7 @@ export async function runLoaders( const title = "Module Error"; const message = error instanceof Error ? concatErrorMsgAndStack(error) : error; - compiler.compilation!.pushDiagnostic( + compiler._lastCompilation!.pushDiagnostic( "error", title, `${message}\n(from: ${stringifyLoaderObject( @@ -482,7 +482,7 @@ export async function runLoaders( const title = "Module Warning"; const message = warning instanceof Error ? concatErrorMsgAndStack(warning) : warning; - compiler.compilation!.pushDiagnostic( + compiler._lastCompilation!.pushDiagnostic( "warning", title, `${message}\n(from: ${stringifyLoaderObject( @@ -492,7 +492,7 @@ export async function runLoaders( }; loaderContext.__internal__pushNativeDiagnostics = function __internal__pushNativeDiagnostics(diagnostics) { - compiler.compilation!.__internal__pushNativeDiagnostics(diagnostics); + compiler._lastCompilation!.__internal__pushNativeDiagnostics(diagnostics); }; loaderContext.emitFile = function emitFile( name, @@ -530,7 +530,7 @@ export async function runLoaders( } assetFilenames.push(name), // @ts-expect-error - compiler.compilation.emitAsset(name, source, assetInfo); + compiler._lastCompilation.emitAsset(name, source, assetInfo); }; loaderContext.fs = compiler.inputFileSystem; @@ -556,7 +556,7 @@ export async function runLoaders( }, createHash: type => { return createHash( - type || compiler.compilation!.outputOptions.hashFunction + type || compiler._lastCompilation!.outputOptions.hashFunction ); } }; @@ -590,7 +590,7 @@ export async function runLoaders( return missingDependencies.slice(); }; loaderContext._compiler = compiler; - loaderContext._compilation = compiler.compilation; + loaderContext._compilation = compiler._lastCompilation!; loaderContext.getOptions = function () { const loader = getCurrentLoader(loaderContext); let options = loader?.options; @@ -615,7 +615,7 @@ export async function runLoaders( return options; }; - let compilation: Compilation | undefined = compiler.compilation; + let compilation: Compilation | undefined = compiler._lastCompilation; let step = 0; while (compilation) { NormalModule.getCompilationHooks(compilation).loader.call(loaderContext); diff --git a/packages/rspack/src/logging/Logger.ts b/packages/rspack/src/logging/Logger.ts index f291c0f03f84..eb72b37d4694 100644 --- a/packages/rspack/src/logging/Logger.ts +++ b/packages/rspack/src/logging/Logger.ts @@ -45,7 +45,7 @@ const LOG_SYMBOL = Symbol("webpack logger raw log method"); const TIMERS_SYMBOL = Symbol("webpack logger times"); const TIMERS_AGGREGATES_SYMBOL = Symbol("webpack logger aggregated times"); -export type LogFunction = (type: LogTypeEnum, args?: any[]) => void; +export type LogFunction = (type: LogTypeEnum, args: any[]) => void; export type GetChildLogger = (name: string | (() => string)) => Logger; export class Logger { diff --git a/packages/rspack/src/node/NodeEnvironmentPlugin.ts b/packages/rspack/src/node/NodeEnvironmentPlugin.ts index 87b3aaa2fb38..20379e50c27f 100644 --- a/packages/rspack/src/node/NodeEnvironmentPlugin.ts +++ b/packages/rspack/src/node/NodeEnvironmentPlugin.ts @@ -49,7 +49,7 @@ export default class NodeEnvironmentPlugin { ); compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => { if (compiler.inputFileSystem === inputFileSystem) { - (compiler as any).fsStartTime = Date.now(); + compiler.fsStartTime = Date.now(); inputFileSystem.purge(); } }); diff --git a/packages/rspack/src/util/fs.ts b/packages/rspack/src/util/fs.ts index a9b8781410d0..c957cb397c8d 100644 --- a/packages/rspack/src/util/fs.ts +++ b/packages/rspack/src/util/fs.ts @@ -1,3 +1,16 @@ +/** + * The following code is modified based on + * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/fs.js + * + * MIT Licensed + * Author Tobias Koppers @sokra + * Copyright (c) JS Foundation and other contributors + * https://github.com/webpack/webpack/blob/main/LICENSE + */ + +import path from "path"; +import assert from "assert"; + import { WatchOptions } from "../config"; export interface Watcher { @@ -17,6 +30,199 @@ export interface WatcherInfo { contextTimeInfoEntries: Map; // get info about directories } +interface IDirent { + isFile: () => boolean; + isDirectory: () => boolean; + isBlockDevice: () => boolean; + isCharacterDevice: () => boolean; + isSymbolicLink: () => boolean; + isFIFO: () => boolean; + isSocket: () => boolean; + name: string | Buffer; +} + +interface IStats { + isFile: () => boolean; + isDirectory: () => boolean; + isBlockDevice: () => boolean; + isCharacterDevice: () => boolean; + isSymbolicLink: () => boolean; + isFIFO: () => boolean; + isSocket: () => boolean; + dev: number | bigint; + ino: number | bigint; + mode: number | bigint; + nlink: number | bigint; + uid: number | bigint; + gid: number | bigint; + rdev: number | bigint; + size: number | bigint; + blksize: number | bigint; + blocks: number | bigint; + atimeMs: number | bigint; + mtimeMs: number | bigint; + ctimeMs: number | bigint; + birthtimeMs: number | bigint; + atime: Date; + mtime: Date; + ctime: Date; + birthtime: Date; +} + +export interface OutputFileSystem { + writeFile: ( + arg0: string, + arg1: string | Buffer, + arg2: (arg0?: null | NodeJS.ErrnoException) => void + ) => void; + mkdir: ( + arg0: string, + arg1: (arg0?: null | NodeJS.ErrnoException) => void + ) => void; + readdir: ( + arg0: string, + arg1: ( + arg0?: null | NodeJS.ErrnoException, + arg1?: (string | Buffer)[] | IDirent[] + ) => void + ) => void; + rmdir: ( + arg0: string, + arg1: (arg0?: null | NodeJS.ErrnoException) => void + ) => void; + unlink: ( + arg0: string, + arg1: (arg0?: null | NodeJS.ErrnoException) => void + ) => void; + stat: ( + arg0: string, + arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: IStats) => void + ) => void; + lstat?: ( + arg0: string, + arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: IStats) => void + ) => void; + readFile: ( + arg0: string, + arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: string | Buffer) => void + ) => void; + join?: (arg0: string, arg1: string) => string; + relative?: (arg0: string, arg1: string) => string; + dirname?: (arg0: string) => string; +} + +export function rmrf( + fs: OutputFileSystem, + p: string, + callback: (err?: Error | null) => void +) { + fs.stat(p, (err, stats) => { + if (err) { + if (err.code === "ENOENT") { + return callback(); + } + return callback(err); + } + if (stats!.isDirectory()) { + fs.readdir(p, (err, files) => { + if (err) { + return callback(err); + } + let count = files!.length; + if (count === 0) { + fs.rmdir(p, callback); + } else { + files!.forEach(file => { + assert(typeof file === "string"); + const fullPath = join(fs, p, file); + rmrf(fs, fullPath, err => { + if (err) { + return callback(err); + } + count--; + if (count === 0) { + fs.rmdir(p, callback); + } + }); + }); + } + }); + } else { + fs.unlink(p, callback); + } + }); +} + +const join = (fs: OutputFileSystem, rootPath: string, filename: string) => { + if (fs && fs.join) { + return fs.join(rootPath, filename); + } else if (path.posix.isAbsolute(rootPath)) { + return path.posix.join(rootPath, filename); + } else if (path.win32.isAbsolute(rootPath)) { + return path.win32.join(rootPath, filename); + } else { + throw new Error( + `${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system` + ); + } +}; + +const dirname = (fs: OutputFileSystem, absPath: string) => { + if (fs && fs.dirname) { + return fs.dirname(absPath); + } else if (path.posix.isAbsolute(absPath)) { + return path.posix.dirname(absPath); + } else if (path.win32.isAbsolute(absPath)) { + return path.win32.dirname(absPath); + } else { + throw new Error( + `${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system` + ); + } +}; + +export const mkdirp = ( + fs: OutputFileSystem, + p: string, + callback: (error?: Error) => void +) => { + fs.mkdir(p, err => { + if (err) { + if (err.code === "ENOENT") { + const dir = dirname(fs, p); + if (dir === p) { + callback(err); + return; + } + mkdirp(fs, dir, err => { + if (err) { + callback(err); + return; + } + fs.mkdir(p, err => { + if (err) { + if (err.code === "EEXIST") { + callback(); + return; + } + callback(err); + return; + } + callback(); + }); + }); + return; + } else if (err.code === "EEXIST") { + callback(); + return; + } + callback(err); + return; + } + callback(); + }); +}; + export interface FileSystemInfoEntry { safeTime: number; timestamp?: number; diff --git a/packages/rspack/src/util/index.ts b/packages/rspack/src/util/index.ts index a7f60dfd726f..eb709ae1fa55 100644 --- a/packages/rspack/src/util/index.ts +++ b/packages/rspack/src/util/index.ts @@ -126,6 +126,7 @@ const getDeprecationStatus = () => { }; const yellow = (content: string) => `\u001b[1m\u001b[33m${content}\u001b[39m\u001b[22m`; + export const deprecatedWarn = ( content: string, enable = getDeprecationStatus() @@ -140,3 +141,11 @@ export const deprecatedWarn = ( ); } }; + +export const unsupported = (name: string, issue?: string) => { + let s = `${name} is not supported by rspack.`; + if (issue) { + s += ` Please refer to issue ${issue} for more information.`; + } + throw new Error(s); +}; From 57940932145e3b4219e92cb08401fc847b502959 Mon Sep 17 00:00:00 2001 From: hardfist Date: Tue, 14 May 2024 18:45:23 +0800 Subject: [PATCH 070/107] docs: update documentation contribution (#5993) * chore: update documentation contribution * chore: skip ci when change document --------- Co-authored-by: neverland --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe6a2826cb2b..9b3ca549174a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,10 @@ The Rspack team believe that creating a development guide for Rspack is a great By providing clarity and consistency, lowering barriers to entry, building trust, and encouraging collaboration, we can create a strong and thriving open source project that people will want to contribute to. +## Documentation Contribution + +See [documentation](./website/README.md). + ## Getting help If you have any questions, please do not hesitate to ask in either the [Discord][discord] support channel or on the [Github discussion board][github-discussion]. From 51fed21ac260fec20a972f03e8b6e3db5a970931 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 14 May 2024 19:02:50 +0800 Subject: [PATCH 071/107] feat: deprecate `Compilation` API (#6505) cache --- crates/node_binding/binding.d.ts | 2 - crates/rspack_binding_values/src/stats.rs | 4 - crates/rspack_core/src/stats.rs | 8 - .../tests/errorCases/error-map.js | 1 - .../tests/errorCases/error-test-push.js | 2 - .../tests/errorCases/error-test-shift.js | 1 - .../tests/errorCases/error-test-splice-1.js | 1 - .../tests/errorCases/error-test-splice-2.js | 2 - .../tests/errorCases/resolve-fail-esm.js | 1 - .../tests/errorCases/warning-map.js | 1 - .../tests/errorCases/warning-test-push.js | 2 - .../tests/errorCases/warning-test-shift.js | 1 - .../tests/errorCases/warning-test-splice-1.js | 1 - .../tests/errorCases/warning-test-splice-2.js | 2 - packages/rspack/etc/api.md | 19 +- packages/rspack/src/Compilation.ts | 352 +++++++----------- packages/rspack/src/Module.ts | 6 +- packages/rspack/src/loader-runner/index.ts | 4 +- packages/rspack/src/util/createSource.ts | 77 ---- packages/rspack/src/util/index.ts | 21 +- packages/rspack/src/util/source.ts | 79 ++++ 21 files changed, 236 insertions(+), 351 deletions(-) delete mode 100644 packages/rspack/src/util/createSource.ts create mode 100644 packages/rspack/src/util/source.ts diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index bb6d35b6e9c2..8784603778d9 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -501,7 +501,6 @@ export interface JsStatsChunkGroupAsset { export interface JsStatsError { message: string - formatted: string moduleIdentifier?: string moduleName?: string moduleId?: string @@ -573,7 +572,6 @@ export interface JsStatsOptimizationBailout { export interface JsStatsWarning { message: string - formatted: string moduleIdentifier?: string moduleName?: string moduleId?: string diff --git a/crates/rspack_binding_values/src/stats.rs b/crates/rspack_binding_values/src/stats.rs index 5e5a678490d5..2071ee7dae29 100644 --- a/crates/rspack_binding_values/src/stats.rs +++ b/crates/rspack_binding_values/src/stats.rs @@ -14,7 +14,6 @@ use super::{JsCompilation, ToJsCompatSource}; #[derive(Debug)] pub struct JsStatsError { pub message: String, - pub formatted: String, pub module_identifier: Option, pub module_name: Option, pub module_id: Option, @@ -24,7 +23,6 @@ impl From for JsStatsError { fn from(stats: rspack_core::StatsError) -> Self { Self { message: stats.message, - formatted: stats.formatted, module_identifier: stats.module_identifier, module_name: stats.module_name, module_id: stats.module_id, @@ -35,7 +33,6 @@ impl From for JsStatsError { #[napi(object)] pub struct JsStatsWarning { pub message: String, - pub formatted: String, pub module_identifier: Option, pub module_name: Option, pub module_id: Option, @@ -45,7 +42,6 @@ impl From for JsStatsWarning { fn from(stats: rspack_core::StatsWarning) -> Self { Self { message: stats.message, - formatted: stats.formatted, module_identifier: stats.module_identifier, module_name: stats.module_name, module_id: stats.module_id, diff --git a/crates/rspack_core/src/stats.rs b/crates/rspack_core/src/stats.rs index 5c2c51f06e93..400506b1a3a6 100644 --- a/crates/rspack_core/src/stats.rs +++ b/crates/rspack_core/src/stats.rs @@ -339,9 +339,6 @@ impl Stats<'_> { message: diagnostic_displayer .emit_diagnostic(d) .expect("should print diagnostics"), - formatted: diagnostic_displayer - .emit_diagnostic(d) - .expect("should print diagnostics"), module_identifier: module_identifier.map(|i| i.to_string()), module_name, module_id: module_id.flatten(), @@ -369,9 +366,6 @@ impl Stats<'_> { message: diagnostic_displayer .emit_diagnostic(d) .expect("should print diagnostics"), - formatted: diagnostic_displayer - .emit_diagnostic(d) - .expect("should print diagnostics"), module_identifier: module_identifier.map(|i| i.to_string()), module_name, module_id: module_id.flatten(), @@ -703,7 +697,6 @@ fn get_stats_module_name_and_id( #[derive(Debug)] pub struct StatsError { pub message: String, - pub formatted: String, pub module_identifier: Option, pub module_name: Option, pub module_id: Option, @@ -712,7 +705,6 @@ pub struct StatsError { #[derive(Debug)] pub struct StatsWarning { pub message: String, - pub formatted: String, pub module_identifier: Option, pub module_name: Option, pub module_id: Option, diff --git a/packages/rspack-test-tools/tests/errorCases/error-map.js b/packages/rspack-test-tools/tests/errorCases/error-map.js index bae713d499a9..aab080b11fac 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-map.js +++ b/packages/rspack-test-tools/tests/errorCases/error-map.js @@ -23,7 +23,6 @@ module.exports = { expect(errors).toMatchInlineSnapshot(` Array [ Object { - "formatted": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "index": 0, "message": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "moduleId": "./resolve-fail-esm/index.js", 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 8675f18ac200..9fa7c69fb58d 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-push.js @@ -18,11 +18,9 @@ module.exports = { Object { "errors": Array [ Object { - "formatted": " × test push\\n", "message": " × test push\\n", }, Object { - "formatted": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "message": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "moduleId": "./resolve-fail-esm/index.js", "moduleIdentifier": "javascript/esm|packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js", 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 13d8caa0c71c..c985435585b2 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js @@ -22,7 +22,6 @@ module.exports = { Object { "errors": Array [ Object { - "formatted": " × test unshift\\n", "message": " × test unshift\\n", }, ], 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 27769318b47a..abf90bb2866b 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 @@ -18,7 +18,6 @@ module.exports = { Object { "errors": Array [ Object { - "formatted": " × test splice\\n", "message": " × test splice\\n", }, ], 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 172ef138b13e..5dfa9d2c273c 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 @@ -18,11 +18,9 @@ module.exports = { Object { "errors": Array [ Object { - "formatted": " × test splice\\n", "message": " × test splice\\n", }, Object { - "formatted": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "message": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "moduleId": "./resolve-fail-esm/index.js", "moduleIdentifier": "javascript/esm|packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js", diff --git a/packages/rspack-test-tools/tests/errorCases/resolve-fail-esm.js b/packages/rspack-test-tools/tests/errorCases/resolve-fail-esm.js index 417d37a30363..e9732f71ee2f 100644 --- a/packages/rspack-test-tools/tests/errorCases/resolve-fail-esm.js +++ b/packages/rspack-test-tools/tests/errorCases/resolve-fail-esm.js @@ -11,7 +11,6 @@ module.exports = { Object { "errors": Array [ Object { - "formatted": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "message": " × Resolve error: Can't resolve './answer' in 'packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm'\\n ╭────\\n 1 │ import { answer } from './answer';\\n · ──────────\\n ╰────\\n help: Did you mean './answer.js'?\\n \\n The request './answer' failed to resolve only because it was resolved as fully specified,\\n probably because the origin is strict EcmaScript Module,\\n e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '\\"type\\": \\"module\\"'.\\n \\n The extension in the request is mandatory for it to be fully specified.\\n Add the extension to the request.\\n", "moduleId": "./resolve-fail-esm/index.js", "moduleIdentifier": "javascript/esm|packages/rspack-test-tools/tests/fixtures/errors/resolve-fail-esm/index.js", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-map.js b/packages/rspack-test-tools/tests/errorCases/warning-map.js index b5fdaccdadca..0049c9b00467 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-map.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-map.js @@ -23,7 +23,6 @@ module.exports = { expect(warnings).toMatchInlineSnapshot(` Array [ Object { - "formatted": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", "index": 0, "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", "moduleId": "./require.main.require.js", 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 4c0c5b655cf5..3f62d546e1bf 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js @@ -19,11 +19,9 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", "message": " ⚠ Error: test push\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, Object { - "formatted": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", "moduleId": "./require.main.require.js", "moduleIdentifier": "packages/rspack-test-tools/tests/fixtures/errors/require.main.require.js", 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 13469964ac88..64eff878a9a6 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js @@ -23,7 +23,6 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", "message": " ⚠ Error: test unshift\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, ], 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 78ce130bbbfa..01291fdd17a9 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 @@ -19,7 +19,6 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, ], 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 3e9eed58e778..3599acd99b19 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 @@ -19,11 +19,9 @@ module.exports = { "errors": Array [], "warnings": Array [ Object { - "formatted": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", "message": " ⚠ Error: test splice\\n │ at packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41\\n │ at Hook.eval [as callAsync] (eval at create (node_modules/tapable/lib/HookCodeFactory.js:33:10), :9:1)\\n │ at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (node_modules/tapable/lib/Hook.js:18:14)\\n │ at packages/rspack/dist/Compiler.js:466:41\\n │ at packages/rspack/dist/Compiler.js:533:65\\n", }, Object { - "formatted": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Module parse failed: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", "moduleId": "./require.main.require.js", "moduleIdentifier": "packages/rspack-test-tools/tests/fixtures/errors/require.main.require.js", diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index ecfb427ec69c..5e0d2845148b 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -35,7 +35,6 @@ import { JsModule } from '@rspack/binding'; import { JsPathData } from '@rspack/binding'; import type { JsRuntimeModule } from '@rspack/binding'; import { JsStats } from '@rspack/binding'; -import type { JsStatsChunk } from '@rspack/binding'; import { JsStatsError } from '@rspack/binding'; import { JsStatsWarning } from '@rspack/binding'; import { libCacheFacade } from './lib/CacheFacade'; @@ -957,21 +956,19 @@ export class Compilation { // @internal __internal__deleteAssetSource(filename: string): void; // @internal - __internal__findJsModule(identifier: string, modules: Map): JsModule | undefined; - // @internal __internal__getAssetFilenames(): string[]; // @internal __internal__getAssetSource(filename: string): Source | void; // @internal - __internal__getAssociatedModules(chunk: JsStatsChunk): any[] | undefined; - // @internal __internal__getChunks(): Chunk[]; // @internal __internal__getModules(): JsModule[]; // @internal __internal__hasAsset(name: string): boolean; - // (undocumented) - __internal__pushNativeDiagnostics(diagnostics: ExternalObject): void; + // @internal + __internal__pushDiagnostic(severity: "error" | "warning", title: string, message: string): void; + // @internal + __internal__pushNativeDiagnostics(diagnostics: ExternalObject<"Diagnostic[]">): void; // @internal __internal__setAssetSource(filename: string, source: Source): void; // (undocumented) @@ -1022,7 +1019,7 @@ export class Compilation { endTime?: number; get entrypoints(): ReadonlyMap; // (undocumented) - get errors(): any; + get errors(): JsStatsError[]; // (undocumented) fileDependencies: { [Symbol.iterator](): Generator; @@ -1037,12 +1034,12 @@ export class Compilation { // (undocumented) get fullHash(): string | null; // (undocumented) - getAsset(name: string): Asset | void; + getAsset(name: string): Readonly | void; // (undocumented) getAssetPath(filename: Filename, data?: PathData): string; // (undocumented) getAssetPathWithInfo(filename: Filename, data?: PathData): PathWithInfo; - getAssets(): Readonly[]; + getAssets(): ReadonlyArray; // (undocumented) getCache(name: string): libCacheFacade; // (undocumented) @@ -1140,8 +1137,6 @@ export class Compilation { // (undocumented) static PROCESS_ASSETS_STAGE_SUMMARIZE: number; // (undocumented) - pushDiagnostic(severity: "error" | "warning", title: string, message: string): void; - // (undocumented) rebuildModule(m: Module, f: (err: Error, m: Module) => void): void; // (undocumented) _rebuildModuleCaller: MergeCaller<[string, (err: Error, m: Module) => void]>; diff --git a/packages/rspack/src/Compilation.ts b/packages/rspack/src/Compilation.ts index 7e2d3350cca5..cbf7faf09ea1 100644 --- a/packages/rspack/src/Compilation.ts +++ b/packages/rspack/src/Compilation.ts @@ -13,15 +13,14 @@ import { Source } from "webpack-sources"; import type { ExternalObject, JsAssetInfo, - JsChunk, JsCompatSource, JsCompilation, JsModule, JsRuntimeModule, - JsStatsChunk, JsStatsError, JsPathData, - JsStatsWarning + JsStatsWarning, + JsDiagnostic } from "@rspack/binding"; import { @@ -35,7 +34,6 @@ import { import * as liteTapable from "./lite-tapable"; import { ContextModuleFactory } from "./ContextModuleFactory"; import ResolverFactory = require("./ResolverFactory"); -import { ChunkGroup } from "./ChunkGroup"; import { Compiler } from "./Compiler"; import ErrorHelpers from "./ErrorHelpers"; import { LogType, Logger } from "./logging/Logger"; @@ -49,8 +47,8 @@ import { } from "./Stats"; import { StatsFactory } from "./stats/StatsFactory"; import { StatsPrinter } from "./stats/StatsPrinter"; -import { concatErrorMsgAndStack, isJsStatsError, toJsAssetInfo } from "./util"; -import { createRawFromSource, createSourceFromRaw } from "./util/createSource"; +import { concatErrorMsgAndStack, toJsAssetInfo } from "./util"; +import { JsSource } from "./util/source"; import { createFakeCompilationDependencies } from "./util/fake"; import MergeCaller from "./util/MergeCaller"; import { memoizeValue } from "./util/memoize"; @@ -104,6 +102,7 @@ type CreateStatsOptionsContext = KnownCreateStatsOptionsContext & export class Compilation { #inner: JsCompilation; + #cachedAssets: Record; hooks: { processAssets: liteTapable.AsyncSeriesHook; @@ -134,17 +133,18 @@ export class Compilation { runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk], void>; afterSeal: liteTapable.AsyncSeriesHook<[], void>; }; - options: RspackOptionsNormalized; - outputOptions: OutputNormalized; + name?: string; + startTime?: number; + endTime?: number; compiler: Compiler; + resolverFactory: ResolverFactory; inputFileSystem: any; + options: RspackOptionsNormalized; + outputOptions: OutputNormalized; logging: Map; - name?: string; - childrenCounters: Record = {}; - startTime?: number; - endTime?: number; - children: Compilation[] = []; + childrenCounters: Record; + children: Compilation[]; chunkGraph: ChunkGraph; fileSystemInfo = { createSnapshot() { @@ -154,14 +154,12 @@ export class Compilation { }; constructor(compiler: Compiler, inner: JsCompilation) { - this.name = undefined; - this.startTime = undefined; - this.endTime = undefined; + this.#inner = inner; + this.#cachedAssets = this.#createCachedAssets(); const processAssetsHook = new liteTapable.AsyncSeriesHook([ "assets" ]); - const createProcessAssetsHook = ( name: string, stage: number, @@ -246,9 +244,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si this.options = compiler.options; this.outputOptions = compiler.options.output; this.logging = new Map(); + this.childrenCounters = {}; + this.children = []; this.chunkGraph = new ChunkGraph(this); - this.#inner = inner; - // Cache the current NormalModuleHooks } get currentNormalModuleHooks() { @@ -265,10 +263,55 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** * Get a map of all assets. - * - * Source: [assets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L1008-L1009) */ get assets(): Record { + return this.#cachedAssets; + } + + /** + * Get a map of all entrypoints. + */ + get entrypoints(): ReadonlyMap { + return new Map( + Object.entries(this.#inner.entrypoints).map(([n, e]) => [ + n, + Entrypoint.__from_binding(e, this.#inner) + ]) + ); + } + + get modules() { + return memoizeValue(() => { + return this.__internal__getModules().map(item => + Module.__from_binding(item) + ); + }); + } + + // FIXME: Webpack returns a `Set` + get chunks() { + return memoizeValue(() => { + return this.__internal__getChunks(); + }); + } + + /** + * Get the named chunks. + * + * Note: This is a proxy for webpack internal API, only method `get` is supported now. + */ + get namedChunks(): Map> { + return { + get: (property: unknown) => { + if (typeof property === "string") { + const chunk = this.#inner.getNamedChunk(property) || undefined; + return chunk && Chunk.__from_binding(chunk, this.#inner); + } + } + } as Map>; + } + + #createCachedAssets() { return new Proxy( {}, { @@ -277,14 +320,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si return this.__internal__getAssetSource(property); } }, - set: (target, p, newValue, receiver) => { + set: (_, p, newValue) => { if (typeof p === "string") { this.__internal__setAssetSource(p, newValue); return true; } return false; }, - deleteProperty: (target, p) => { + deleteProperty: (_, p) => { if (typeof p === "string") { this.__internal__deleteAssetSource(p); return true; @@ -312,18 +355,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si ); } - /** - * Get a map of all entrypoints. - */ - get entrypoints(): ReadonlyMap { - return new Map( - Object.entries(this.#inner.entrypoints).map(([n, e]) => [ - n, - Entrypoint.__from_binding(e, this.#inner) - ]) - ); - } - getCache(name: string) { return this.compiler.getCache(name); } @@ -445,9 +476,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** * Update an existing asset. Trying to update an asset that doesn't exist will throw an error. * - * See: [Compilation.updateAsset](https://webpack.js.org/api/compilation-object/#updateasset) - * Source: [updateAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4320) - * * FIXME: *AssetInfo* may be undefined in update fn for webpack impl, but still not implemented in rspack */ updateAsset( @@ -465,12 +493,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si compatNewSourceOrFunction = function newSourceFunction( source: JsCompatSource ) { - return createRawFromSource( - newSourceOrFunction(createSourceFromRaw(source)) + return JsSource.__to_binding( + newSourceOrFunction(JsSource.__from_binding(source)) ); }; } else { - compatNewSourceOrFunction = createRawFromSource(newSourceOrFunction); + compatNewSourceOrFunction = JsSource.__to_binding(newSourceOrFunction); } this.#inner.updateAsset( @@ -487,9 +515,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** * Emit an not existing asset. Trying to emit an asset that already exists will throw an error. * - * See: [Compilation.emitAsset](https://webpack.js.org/api/compilation-object/#emitasset) - * Source: [emitAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4239) - * * @param file - file name * @param source - asset source * @param assetInfo - extra asset information @@ -497,7 +522,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si emitAsset(filename: string, source: Source, assetInfo?: AssetInfo) { this.#inner.emitAsset( filename, - createRawFromSource(source), + JsSource.__to_binding(source), toJsAssetInfo(assetInfo) ); } @@ -512,11 +537,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si /** * Get an array of Asset - * - * See: [Compilation.getAssets](https://webpack.js.org/api/compilation-object/#getassets) - * Source: [getAssets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4448) */ - getAssets(): Readonly[] { + getAssets(): ReadonlyArray { const assets = this.#inner.getAssets(); return assets.map(asset => { @@ -526,7 +548,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si }); } - getAsset(name: string): Asset | void { + getAsset(name: string): Readonly | void { const asset = this.#inner.getAsset(name); if (!asset) { return; @@ -536,7 +558,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si }) as Asset; } - pushDiagnostic( + /** + * Note: This is not a webpack public API, maybe removed in future. + * + * @internal + */ + __internal__pushDiagnostic( severity: "error" | "warning", title: string, message: string @@ -544,14 +571,21 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si this.#inner.pushDiagnostic(severity, title, message); } - __internal__pushNativeDiagnostics(diagnostics: ExternalObject) { + /** + * Note: This is not a webpack public API, maybe removed in future. + * + * @internal + */ + __internal__pushNativeDiagnostics( + diagnostics: ExternalObject<"Diagnostic[]"> + ) { this.#inner.pushNativeDiagnostics(diagnostics); } - get errors() { + get errors(): JsStatsError[] { const inner = this.#inner; type ErrorType = Error | JsStatsError | string; - const errors = inner.getStats().getErrors() as any; + const errors = inner.getStats().getErrors(); const proxyMethod = [ { method: "push", @@ -562,21 +596,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si ) { for (let i = 0; i < errs.length; i++) { const error = errs[i]; - if (isJsStatsError(error)) { - inner.pushDiagnostic( - "error", - "Error", - concatErrorMsgAndStack(error) - ); - } else if (typeof error === "string") { - inner.pushDiagnostic("error", "Error", error); - } else { - inner.pushDiagnostic( - "error", - error.name, - concatErrorMsgAndStack(error) - ); - } + inner.pushDiagnostic( + "error", + error instanceof Error ? error.name : "Error", + concatErrorMsgAndStack(error) + ); } return Reflect.apply(target, thisArg, errs); } @@ -606,25 +630,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si errs: ErrorType[] ) { const errList = errs.map(error => { - if (isJsStatsError(error)) { - return { - severity: "error" as const, - title: "Error", - message: concatErrorMsgAndStack(error) - }; - } else if (typeof error === "string") { - return { - severity: "error" as const, - title: "Error", - message: error - }; - } else { - return { - severity: "error" as const, - title: error.name, - message: concatErrorMsgAndStack(error) - }; - } + return { + severity: "error", + title: error instanceof Error ? error.name : "Error", + message: concatErrorMsgAndStack(error) + } satisfies JsDiagnostic; }); inner.spliceDiagnostic(0, 0, errList); return Reflect.apply(target, thisArg, errs); @@ -638,25 +648,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si [startIdx, delCount, ...errors]: [number, number, ...ErrorType[]] ) { const errList = errors.map(error => { - if (isJsStatsError(error)) { - return { - severity: "error" as const, - title: "Error", - message: concatErrorMsgAndStack(error) - }; - } else if (typeof error === "string") { - return { - severity: "error" as const, - title: "Error", - message: error - }; - } else { - return { - severity: "error" as const, - title: error.name, - message: concatErrorMsgAndStack(error) - }; - } + return { + severity: "error", + title: error instanceof Error ? error.name : "Error", + message: concatErrorMsgAndStack(error) + } satisfies JsDiagnostic; }); inner.spliceDiagnostic(startIdx, startIdx + delCount, errList); return Reflect.apply(target, thisArg, [ @@ -676,7 +672,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si return errors; } - get warnings() { + get warnings(): JsStatsWarning[] { const inner = this.#inner; type WarnType = Error | JsStatsWarning; const processWarningsHook = this.hooks.processWarnings; @@ -694,7 +690,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si const warn = warns[i]; inner.pushDiagnostic( "warning", - isJsStatsError(warn) ? "Warning" : warn.name, + warn instanceof Error ? warn.name : "Warning", concatErrorMsgAndStack(warn) ); } @@ -728,10 +724,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si warns = processWarningsHook.call(warns as any); const warnList = warns.map(warn => { return { - severity: "warning" as const, - title: isJsStatsError(warn) ? "Warning" : warn.name, + severity: "warning", + title: warn instanceof Error ? warn.name : "Warning", message: concatErrorMsgAndStack(warn) - }; + } satisfies JsDiagnostic; }); inner.spliceDiagnostic(0, 0, warnList); return Reflect.apply(target, thisArg, warns); @@ -747,10 +743,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si warns = processWarningsHook.call(warns as any); const warnList = warns.map(warn => { return { - severity: "warning" as const, - title: isJsStatsError(warn) ? "Warning" : warn.name, + severity: "warning", + title: warn instanceof Error ? warn.name : "Warning", message: concatErrorMsgAndStack(warn) - }; + } satisfies JsDiagnostic; }); inner.spliceDiagnostic(startIdx, startIdx + delCount, warnList); return Reflect.apply(target, thisArg, [ @@ -915,107 +911,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si d => this.#inner.addBuildDependencies(d) ); - get modules() { - return memoizeValue(() => { - return this.__internal__getModules().map(item => - Module.__from_binding(item) - ); - }); - } - - // FIXME: This is not aligned with Webpack. - get chunks() { - return memoizeValue(() => { - return this.__internal__getChunks(); - }); - } - - /** - * Get the named chunks. - * - * Note: This is a proxy for webpack internal API, only method `get` is supported now. - */ - get namedChunks(): Map> { - return { - get: (property: unknown) => { - if (typeof property === "string") { - const chunk = this.#inner.getNamedChunk(property); - return chunk && Chunk.__from_binding(chunk, this.#inner); - } - } - } as Map>; - } - - /** - * Get the associated `modules` of an given chunk. - * - * Note: This is not a webpack public API, maybe removed in future. - * - * @internal - */ - __internal__getAssociatedModules(chunk: JsStatsChunk): any[] | undefined { - const modules = this.__internal__getModules(); - const moduleMap: Map = new Map(); - for (const module of modules) { - moduleMap.set(module.moduleIdentifier, module); - } - return chunk.modules?.flatMap(chunkModule => { - const jsModule = this.__internal__findJsModule( - chunkModule.issuer ?? chunkModule.identifier, - moduleMap - ); - return { - ...jsModule - // dependencies: chunkModule.reasons?.flatMap(jsReason => { - // let jsOriginModule = this.__internal__findJsModule( - // jsReason.moduleIdentifier ?? "", - // moduleMap - // ); - // return { - // ...jsReason, - // originModule: jsOriginModule - // }; - // }) - }; - }); - } - - /** - * Find a modules in an array. - * - * Note: This is not a webpack public API, maybe removed in future. - * - * @internal - */ - __internal__findJsModule( - identifier: string, - modules: Map - ): JsModule | undefined { - return modules.get(identifier); - } - - /** - * - * Note: This is not a webpack public API, maybe removed in future. - * - * @internal - */ - __internal__getModules(): JsModule[] { - return this.#inner.getModules(); - } - - /** - * - * Note: This is not a webpack public API, maybe removed in future. - * - * @internal - */ - __internal__getChunks(): Chunk[] { - return this.#inner - .getChunks() - .map(c => Chunk.__from_binding(c, this.#inner)); - } - getStats() { return new Stats(this); } @@ -1054,6 +949,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si }, 10 ); + rebuildModule(m: Module, f: (err: Error, m: Module) => void) { this._rebuildModuleCaller.push([m.identifier(), f]); } @@ -1070,7 +966,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si if (!rawSource) { return; } - return createSourceFromRaw(rawSource); + return JsSource.__from_binding(rawSource); } /** @@ -1081,7 +977,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si * @internal */ __internal__setAssetSource(filename: string, source: Source) { - this.#inner.setAssetSource(filename, createRawFromSource(source)); + this.#inner.setAssetSource(filename, JsSource.__to_binding(source)); } /** @@ -1117,6 +1013,26 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si return this.#inner.hasAsset(name); } + /** + * Note: This is not a webpack public API, maybe removed in future. + * + * @internal + */ + __internal__getModules(): JsModule[] { + return this.#inner.getModules(); + } + + /** + * Note: This is not a webpack public API, maybe removed in future. + * + * @internal + */ + __internal__getChunks(): Chunk[] { + return this.#inner + .getChunks() + .map(c => Chunk.__from_binding(c, this.#inner)); + } + __internal_getInner() { return this.#inner; } diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index 303eee73fc81..67b05badd7b2 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -5,7 +5,7 @@ import { JsModule } from "@rspack/binding"; import { Source } from "webpack-sources"; -import { createSourceFromRaw } from "./util/createSource"; +import { JsSource } from "./util/source"; export type ResourceData = { resource: string; @@ -69,7 +69,9 @@ export class Module { get originalSource(): Source | null { if (this._originalSource) return this._originalSource; if (this.#inner.originalSource) { - this._originalSource = createSourceFromRaw(this.#inner.originalSource); + this._originalSource = JsSource.__from_binding( + this.#inner.originalSource + ); return this._originalSource; } else { return null; diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index 3edf00fc0f42..d1b6e59b6518 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -470,7 +470,7 @@ export async function runLoaders( const title = "Module Error"; const message = error instanceof Error ? concatErrorMsgAndStack(error) : error; - compiler._lastCompilation!.pushDiagnostic( + compiler._lastCompilation!.__internal__pushDiagnostic( "error", title, `${message}\n(from: ${stringifyLoaderObject( @@ -482,7 +482,7 @@ export async function runLoaders( const title = "Module Warning"; const message = warning instanceof Error ? concatErrorMsgAndStack(warning) : warning; - compiler._lastCompilation!.pushDiagnostic( + compiler._lastCompilation!.__internal__pushDiagnostic( "warning", title, `${message}\n(from: ${stringifyLoaderObject( diff --git a/packages/rspack/src/util/createSource.ts b/packages/rspack/src/util/createSource.ts deleted file mode 100644 index 07900b54d1a3..000000000000 --- a/packages/rspack/src/util/createSource.ts +++ /dev/null @@ -1,77 +0,0 @@ -import type { JsCompatSource } from "@rspack/binding"; - -import { RawSource, CompatSource, Source } from "webpack-sources"; -import { isNil } from "./index"; - -function createSourceFromRaw(source: JsCompatSource): Source { - if (source.isRaw) { - return new RawSource( - // @ts-expect-error: webpack-sources can accept buffer as source, see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/RawSource.js#L12 - source.isBuffer ? source.source : source.source.toString("utf-8") - ); - } - - if (!source.map) { - return new RawSource(source.source.toString("utf-8")); - } - - return new CompatSource({ - source() { - return source.source.toString("utf-8"); - }, - buffer() { - return source.source; - }, - map(_) { - if (source.map) { - return JSON.parse(source.map.toString("utf-8")); - } - - return null; - } - }); -} - -function createRawFromSource(source: Source): JsCompatSource { - const sourceSource = source.source(); - const isBuffer = Buffer.isBuffer(sourceSource); - - if (source instanceof RawSource) { - return { - source: source.buffer(), - isRaw: true, - isBuffer - }; - } - - const buffer = - source.buffer?.() ?? - (isBuffer - ? sourceSource - : sourceSource instanceof ArrayBuffer - ? arrayBufferToBuffer(sourceSource) - : Buffer.from(sourceSource)); - const map = JSON.stringify( - source.map?.({ - columns: true - }) - ); - - return { - source: buffer, - map: isNil(map) ? map : Buffer.from(map), - isRaw: false, - isBuffer - }; -} - -function arrayBufferToBuffer(ab: ArrayBuffer) { - const buf = Buffer.alloc(ab.byteLength); - const view = new Uint8Array(ab); - for (let i = 0; i < buf.length; ++i) { - buf[i] = view[i]; - } - return buf; -} - -export { createSourceFromRaw, createRawFromSource }; diff --git a/packages/rspack/src/util/index.ts b/packages/rspack/src/util/index.ts index eb709ae1fa55..5883eaf099d7 100644 --- a/packages/rspack/src/util/index.ts +++ b/packages/rspack/src/util/index.ts @@ -70,17 +70,16 @@ export function isJsStatsError(err: any): err is JsStatsError { return !(err instanceof Error) && err.formatted; } -export function concatErrorMsgAndStack(err: Error | JsStatsError): string { - // deduplicate the error if message is already shown in the stack - //@ts-ignore - const stackStartPrefix = err.name ? `${err.name}: ` : "Error: "; - return isJsStatsError(err) - ? err.formatted - : err.stack - ? err.stack.startsWith(`${stackStartPrefix}${err.message}`) - ? `${err.stack}` - : `${err.message}\n${err.stack}` - : `${err.message}`; +export function concatErrorMsgAndStack( + err: Error | JsStatsError | string +): string { + if (typeof err === "string") { + return err; + } + if ("stack" in err) { + return err.stack || err.message; + } + return err.message; } export function indent(str: string, prefix: string) { diff --git a/packages/rspack/src/util/source.ts b/packages/rspack/src/util/source.ts new file mode 100644 index 000000000000..0b596f6abba6 --- /dev/null +++ b/packages/rspack/src/util/source.ts @@ -0,0 +1,79 @@ +import type { JsCompatSource } from "@rspack/binding"; + +import { RawSource, CompatSource, Source } from "webpack-sources"; +import { isNil } from "./index"; + +class JsSource extends Source { + static __from_binding(source: JsCompatSource): Source { + if (source.isRaw) { + return new RawSource( + // @ts-expect-error: webpack-sources can accept buffer as source, see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/RawSource.js#L12 + source.isBuffer ? source.source : source.source.toString("utf-8") + ); + } + + if (!source.map) { + return new RawSource(source.source.toString("utf-8")); + } + + return new CompatSource({ + source() { + return source.source.toString("utf-8"); + }, + buffer() { + return source.source; + }, + map(_) { + if (source.map) { + return JSON.parse(source.map.toString("utf-8")); + } + + return null; + } + }); + } + + static __to_binding(source: Source) { + const sourceSource = source.source(); + const isBuffer = Buffer.isBuffer(sourceSource); + + if (source instanceof RawSource) { + return { + source: source.buffer(), + isRaw: true, + isBuffer + }; + } + + const buffer = + source.buffer?.() ?? + (isBuffer + ? sourceSource + : sourceSource instanceof ArrayBuffer + ? arrayBufferToBuffer(sourceSource) + : Buffer.from(sourceSource)); + const map = JSON.stringify( + source.map?.({ + columns: true + }) + ); + + return { + source: buffer, + map: isNil(map) ? map : Buffer.from(map), + isRaw: false, + isBuffer + }; + } +} + +function arrayBufferToBuffer(ab: ArrayBuffer) { + const buf = Buffer.alloc(ab.byteLength); + const view = new Uint8Array(ab); + for (let i = 0; i < buf.length; ++i) { + buf[i] = view[i]; + } + return buf; +} + +export { JsSource }; From 1037718ffd1b39c274787cc08ce6bbf3afd76022 Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Tue, 14 May 2024 19:16:51 +0800 Subject: [PATCH 072/107] docs: complete the dev server docs (#6530) * docs: dev server zh docs * docs: dev serve en doc * fix: change webpack to rspack * fix: zh warning --- website/docs/en/config/dev-server.mdx | 911 +++++++++++++++++++++++++- website/docs/zh/config/dev-server.mdx | 909 ++++++++++++++++++++++++- website/project-words.txt | 4 + 3 files changed, 1765 insertions(+), 59 deletions(-) diff --git a/website/docs/en/config/dev-server.mdx b/website/docs/en/config/dev-server.mdx index 9a4888ae8ea0..295d8dd038fe 100644 --- a/website/docs/en/config/dev-server.mdx +++ b/website/docs/en/config/dev-server.mdx @@ -2,11 +2,11 @@ import WebpackLicense from '@components/webpack-license'; -# devServer +# DevServer -Used to configure the behavior of `@rspack/dev-server`. +This page describes the options that affect the behavior of `@rspack/dev-server` (short: dev-server), which facilitates rapid application development. -- **Type:** `Object` +- **Type:** `object` :::tip If the current application does not depend on `@rspack/dev-server`, then the devServer config will have no effect. @@ -21,100 +21,527 @@ For example, Rspack CLI depends on `@rspack/dev-server` by default, so the devSe This option allows you to allowlist services that are allowed to access the dev server. +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + allowedHosts: [ + 'host.com', + 'subdomain.host.com', + 'subdomain2.host.com', + 'host2.com', + ], + }, +}; +``` + +Mimicking Django's `ALLOWED_HOSTS`, a value beginning with `.` can be used as a subdomain wildcard. `.host.com` will match `host.com`, `www.host.com`, and any other subdomain of `host.com`. + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + // this achieves the same effect as the first example + // with the bonus of not having to update your config + // if new subdomains need to access the dev server + allowedHosts: ['.host.com', 'host2.com'], + }, +}; +``` + +When set to `'all'` this option bypasses host checking. **THIS IS NOT RECOMMENDED** as apps that do not check the host are vulnerable to DNS rebinding attacks. + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + allowedHosts: 'all', + }, +}; +``` + +When set to `'auto'` this option always allows `localhost`, [`host`](#devserverhost), and [`client.webSocketURL.hostname`](#websocketurl): + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + allowedHosts: 'auto', + }, +}; +``` + ## devServer.client -- **Type:** `Object` +- **Type:** `object` ### logging - **Type:** `'log' | 'info' | 'warn' | 'error' | 'none' | 'verbose'` - **Default:** `'info'` -The client's log level. +Allows to set log level in the browser, e.g. before reloading, before an error or when Hot Module Replacement is enabled. + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + logging: 'info', + }, + }, +}; +``` ### overlay -- **Type:** `boolean | Object` +- **Type:** `boolean | object` - **Default:** `true` -Whether to report errors on the client's screen when a compilation error occurs. +Shows a full-screen overlay in the browser when there are compiler errors or warnings. + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + overlay: true, + }, + }, +}; +``` + +You can provide an object with the following properties for more granular control: + +| Property | Explanation | +| --------------- | ------------------------ | +| `errors` | compilation errors | +| `runtimeErrors` | unhandled runtime errors | +| `warnings` | compilation warnings | + +All properties are optional and default to `true` when not provided. + +For example, to disable compilation warnings, you can provide the following configuration: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + overlay: { + errors: true, + warnings: false, + runtimeErrors: true, + }, + }, + }, +}; +``` + +To filter based on the thrown error, you can pass a function that accepts an `error` parameter and returns a boolean. + +For example, to ignore errors thrown by [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort): + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + overlay: { + runtimeErrors: error => { + if (error instanceof DOMException && error.name === 'AbortError') { + return false; + } + return true; + }, + }, + }, + }, +}; +``` + +:::warning +The function will not have access to the variables declared in the outer scope within the configuration file. +::: ### progress - **Type:** `boolean` - **Default:** `true` -Whether or not to show the progress of compilation on the client. +Prints compilation progress in percentage in the browser. + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + progress: true, + }, + }, +}; +``` ### reconnect - **Type:** `boolean | number` - **Default:** `true` -The number of times the development server will reconnect to the client. `true` means unlimited number of times. +Tells dev-server the number of times it should try to reconnect the client. When `true` it will try to reconnect unlimited times. + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + reconnect: true, + }, + }, +}; +``` + +When set to `false` it will not try to reconnect. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + reconnect: false, + }, + }, +}; +``` + +You can also specify the exact number of times the client should try to reconnect. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + reconnect: 5, + }, + }, +}; +``` ### webSocketTransport - **Type:** `'ws' | 'sockjs'` - **Default:** `ws` -The transfer method between the client and the development server. +This option allows us either to choose the current `devServer` transport mode for clients individually or to provide custom client implementation. This allows specifying how the browser or other client communicates with the `devServer`. + +:::tip +Providing `'ws'` or `'sockjs'` to [`webSocketServer`](#devserverwebsocketserver) is a shortcut to setting both `devServer.client.webSocketTransport` and `devServer.webSocketServer` to the given value. +::: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketTransport: 'ws', + }, + webSocketServer: 'ws', + }, +}; +``` + +:::tip +When providing a custom client and server implementation make sure that they are compatible with one another to communicate successfully. +::: + +To create a custom client implementation, create a class that extends BaseClient. + +Using path to `CustomClient.js`, a custom WebSocket client implementation, along with the compatible `'ws'` server: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketTransport: require.resolve('./CustomClient'), + }, + webSocketServer: 'ws', + }, +}; +``` + +Using custom, compatible WebSocket client and server implementations: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketTransport: require.resolve('./CustomClient'), + }, + webSocketServer: require.resolve('./CustomServer'), + }, +}; +``` ### webSocketURL - **Type:** `string | object` - **Default:** `{}` -URL of the ws server. +This option allows specifying URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketURL: 'ws://0.0.0.0:8080/ws', + }, + }, +}; +``` + +You can also specify an object with the following properties: + +- `hostname`: Tells clients connected to devServer to use the provided hostname. +- `pathname`: Tells clients connected to devServer to use the provided path to connect. +- `password`: Tells clients connected to devServer to use the provided password to authenticate. +- `port`: Tells clients connected to devServer to use the provided port. +- `protocol`: Tells clients connected to devServer to use the provided protocol. +- `username`: Tells clients connected to devServer to use the provided username to authenticate. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketURL: { + hostname: '0.0.0.0', + pathname: '/ws', + password: 'dev-server', + port: 8080, + protocol: 'ws', + username: 'rspack', + }, + }, + }, +}; +``` + +:::tip +To get `protocol`/`hostname`/`port` from browser use `webSocketURL: 'auto://0.0.0.0:0/ws'`. +::: ## devServer.compress - **Type:** `boolean` - **Default:** `true` -Whether to enable gzip compression. +Enable [gzip compression](https://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/) for everything served: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + compress: true, + }, +}; +``` ## devServer.devMiddleware - **Type:** `object` - **Default:** `{}` -Control the behavior of the rspack-dev-middleware. +Provide options to [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) which handles Rspack assets. + +```javascript title="rspack.config.js" +module.exports = { + devServer: { + devMiddleware: { + index: true, + mimeTypes: { phtml: 'text/html' }, + publicPath: '/publicPathForDevServe', + serverSideRender: true, + writeToDisk: true, + }, + }, +}; +``` ## devServer.headers - **Type:** `array | function | object` - **Default:** `undefined` -Add response headers. +Adds headers to all responses: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + headers: { + 'X-Custom-Foo': 'bar', + }, + }, +}; +``` + +You can also pass an array: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + headers: [ + { + key: 'X-Custom', + value: 'foo', + }, + { + key: 'Y-Custom', + value: 'bar', + }, + ], + }, +}; +``` + +You can also pass a function: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + headers: () => { + return { 'X-Bar': ['key1=value1', 'key2=value2'] }; + }, + }, +}; +``` ## devServer.historyApiFallback - **Type:** `boolean | object` - **Default:** `false` -Underhanded logic when a 404 page is requested. +When using the [HTML5 History API](https://developer.mozilla.org/en-US/docs/Web/API/History), the `index.html` page will likely have to be served in place of any `404` responses. Enable `devServer.historyApiFallback` by setting it to `true`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + historyApiFallback: true, + }, +}; +``` + +By providing an object this behavior can be controlled further using options like `rewrites`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + historyApiFallback: { + rewrites: [ + { from: /^\/$/, to: '/views/landing.html' }, + { from: /^\/subpage/, to: '/views/subpage.html' }, + { from: /./, to: '/views/404.html' }, + ], + }, + }, +}; +``` + +When using dots in your path (common with Angular), you may need to use the `disableDotRule`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + historyApiFallback: { + disableDotRule: true, + }, + }, +}; +``` + +For more options and information, see the [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback) documentation. ## devServer.host - **Type:** `'local-ip' | 'local-ipv4' | 'local-ipv6' | string` - **Default:** `'local-ip'` -The address of the development server. +Specify a host to use. If you want your server to be accessible externally, specify it like this: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + host: '0.0.0.0', + }, +}; +``` + +### local-ip + +Specifying `local-ip` as host will try to resolve the host option as your local `IPv4` address if available, if `IPv4` is not available it will try to resolve your local `IPv6` address. + +### local-ipv4 + +Specifying `local-ipv4` as host will try to resolve the host option as your local `IPv4` address. + +### local-ipv6 + +Specifying local-ipv6 as host will try to resolve the host option as your local IPv6 address. ## devServer.hot - **Type:** `boolean` - **Default:** `true` -Whether to enable hot updates. +Enable Rspack's Hot Module Replacement feature: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + hot: true, + }, +}; +``` + +To enable Hot Module Replacement without page refresh as a fallback in case of build failures, use `hot: 'only'`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + hot: 'only', + }, +}; +``` ## devServer.liveReload - **Type:** `boolean` - **Default:** `true` -Whether or not to reload the page. This configuration item is turned off when hot is turned on. +By default, the dev-server will reload/refresh the page when file changes are detected. [`devServer.hot`](#devserverhot) option must be disabled or [`devServer.watchFiles`](#devserverwatchfiles) option must be enabled in order for `liveReload` to take effect. Disable `devServer.liveReload` by setting it to `false`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + liveReload: false, + }, +}; +``` + +:::tip +Live reloading works only with web related [targets](/config/target) like `web`, `webworker`, `electron-renderer` and `node-webkit`. +::: ## devServer.magicHtml @@ -125,57 +552,485 @@ Whether the path corresponds to the product one by one. ## devServer.onListening -- **Type:** `function` +- **Type:** `function (devServer)` -Callback when devServer establishes a connection to the port. +Provides the ability to execute a custom function when @rspack/dev-server starts listening for connections on a port. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + onListening: function (devServer) { + if (!devServer) { + throw new Error('@rspack/dev-server is not defined'); + } + + const port = devServer.server.address().port; + console.log('Listening on port:', port); + }, + }, +}; +``` ## devServer.open - **Type:** `boolean | string | object | [string, object]` - **Default:** `true` -Whether to open the browser when devServer starts. +Tells dev-server to open the browser after server had been started. Set it to `true` to open your default browser. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + open: true, + }, +}; +``` + +To open a specified page in a browser: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + open: ['/my-page'], + }, +}; +``` + +To open multiple specified pages in browser: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + open: ['/my-page', '/another-page'], + }, +}; +``` + +Provide browser name to use instead of the default one: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + open: { + app: { + name: 'google-chrome', + }, + }, + }, +}; +``` + +The object accepts all [open](https://www.npmjs.com/package/open) options: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + open: { + target: ['first.html', 'http://localhost:8080/second.html'], + app: { + name: 'google-chrome', + arguments: ['--incognito', '--new-window'], + }, + }, + }, +}; +``` + +:::tip +The browser application name is platform-dependent. Don't hard code it in reusable modules. For example, `'Chrome'` is `'Google Chrome'` on macOS, `'google-chrome'` on Linux, and `'chrome'` on Windows. +::: ## devServer.port - **Type:** `'auto' | string | number` - **Default:** `[]` -Used to configure the port number. +Specify a port number to listen for requests on: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + port: 8080, + }, +}; +``` + +`port` option can't be `null` or an empty string, to automatically use a free port please use `port: 'auto'`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + port: 'auto', + }, +}; +``` ## devServer.proxy - **Type:** `object | [object, function]` -Configure proxy, can be used to solve cross-domain issues, etc. +Proxying some URLs can be useful when you have a separate API backend development server and you want to send API requests on the same domain. + +The dev-server makes use of the powerful [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) package. Check out its [documentation](https://github.com/chimurai/http-proxy-middleware#options) for more advanced usages. Note that some of `http-proxy-middleware`'s features do not require a `target` key, e.g. its `router` feature, but you will still need to include a `target` key in your configuration here, otherwise `@rspack/dev-server` won't pass it along to `http-proxy-middleware`. + +With a backend on `localhost:3000`, you can use this to enable proxying: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + }, + ], + }, +}; +``` + +A request to `/api/users` will now proxy the request to `http://localhost:3000/api/users`. + +If you don't want `/api` to be passed along, we need to rewrite the path: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + pathRewrite: { '^/api': '' }, + }, + ], + }, +}; +``` + +A backend server running on HTTPS with an invalid certificate will not be accepted by default. If you want to, modify your configuration like this: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + secure: false, + }, + ], + }, +}; +``` + +Sometimes you don't want to proxy everything. It is possible to bypass the proxy based on the return value of a function. + +In the function, you get access to the request, response, and proxy options. + +- Return `null` or `undefined` to continue processing the request with proxy. +- Return `false` to produce a 404 error for the request. +- Return a path to serve from, instead of continuing to proxy the request. + +E.g. for a browser request, you want to serve an HTML page, but for an API request, you want to proxy it. You could do something like this: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + bypass: function (req, res, proxyOptions) { + if (req.headers.accept.indexOf('html') !== -1) { + console.log('Skipping proxy for browser request.'); + return '/index.html'; + } + }, + }, + ], + }, +}; +``` + +If you want to proxy multiple, specific paths to the same target, you can use an array of one or more objects with a `context` property: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/auth', '/api'], + target: 'http://localhost:3000', + }, + ], + }, +}; +``` + +Note that requests to root won't be proxied by default. To enable root proxying, the [`devMiddleware.index`](#devserverdevmiddleware) option should be specified as a falsy value: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + devMiddleware: { + index: false, // specify to enable root proxying + }, + proxy: [ + { + context: () => true, + target: 'http://localhost:1234', + }, + ], + }, +}; +``` + +The origin of the host header is kept when proxying by default, you can set `changeOrigin` to `true` to override this behaviour. It is useful in some cases like using [name-based virtual hosted sites](https://en.wikipedia.org/wiki/Virtual_hosting#Name-based). + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + changeOrigin: true, + }, + ], + }, +}; +``` ## devServer.server - **Type:** `'http' | 'https' | 'spdy' | string | object` - **Default:** `'http'` -Configuration items for the server. +Allows to set server and options (by default 'http'). + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + server: 'http', + }, +}; +``` + +To serve over `HTTPS` with a self-signed certificate: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + server: 'https', + }, +}; +``` + +To serve over `HTTP/2` using [spdy](https://www.npmjs.com/package/spdy) with a self-signed certificate: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + server: 'spdy', + }, +}; +``` + +Use the object syntax to provide your own certificate: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + server: { + type: 'https', + options: { + ca: './path/to/server.pem', + pfx: './path/to/server.pfx', + key: './path/to/server.key', + cert: './path/to/server.crt', + passphrase: '@rspack/dev-server', + requestCert: true, + }, + }, + }, +}; +``` + +It also allows you to set additional [TLS options](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) like `minVersion` and you can directly pass the contents of respective files: + +```javascript title="rspack.config.js" +const fs = require('fs'); +const path = require('path'); + +module.exports = { + //... + devServer: { + server: { + type: 'https', + options: { + minVersion: 'TLSv1.1', + key: fs.readFileSync(path.join(__dirname, './server.key')), + pfx: fs.readFileSync(path.join(__dirname, './server.pfx')), + cert: fs.readFileSync(path.join(__dirname, './server.crt')), + ca: fs.readFileSync(path.join(__dirname, './ca.pem')), + passphrase: '@rspack/dev-server', + requestCert: true, + }, + }, + }, +}; +``` ## devServer.setupMiddlewares - **Type:** `function (middlewares, devServer)` -Custom middleware. +Provides the ability to execute a custom function and apply custom middleware(s). + +```javascript title="rspack.config.js" +module.exports = { + // ... + devServer: { + setupMiddlewares: (middlewares, devServer) => { + if (!devServer) { + throw new Error('@rspack/dev-server is not defined'); + } + + devServer.app.get('/setup-middleware/some/path', (_, response) => { + response.send('setup-middlewares option GET'); + }); + + // Use the `unshift` method if you want to run a middleware before all other middlewares + // or when you are migrating from the `onBeforeSetupMiddleware` option + middlewares.unshift({ + name: 'first-in-array', + // `path` is optional + path: '/foo/path', + middleware: (req, res) => { + res.send('Foo!'); + }, + }); + + // Use the `push` method if you want to run a middleware after all other middlewares + // or when you are migrating from the `onAfterSetupMiddleware` option + middlewares.push({ + name: 'hello-world-test-one', + // `path` is optional + path: '/foo/bar', + middleware: (req, res) => { + res.send('Foo Bar!'); + }, + }); + + middlewares.push((req, res) => { + res.send('Hello World!'); + }); + + return middlewares; + }, + }, +}; +``` ## devServer.static - **Type:** `boolean | string | object | [string, object]` -Used to configure whether to enable static servers from some directories (default is 'public'). +This option allows configuring options for serving static files from the directory (by default 'public' directory). To disable set it to `false`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + static: false, + }, +}; +``` + +To watch a single directory: + +```js title="rspack.config.js" +module.exports = { + // ... + devServer: { + static: ['assets'], + }, +}; +``` + +To watch multiple static directories: + +```js title="rspack.config.js" +module.exports = { + // ... + devServer: { + static: ['assets', 'css'], + }, +}; +``` ## devServer.watchFiles - **Type:** `string | object | [string, object]` -Listens for changes to a series of files. +This option allows you to configure a list of globs/directories/files to watch for file changes. For example: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + watchFiles: ['src/**/*.php', 'public/**/*'], + }, +}; +``` + +It is possible to configure advanced options for watching files. See the [`chokidar`](https://github.com/paulmillr/chokidar) documentation for the possible options. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + watchFiles: { + paths: ['src/**/*.php', 'public/**/*'], + options: { + usePolling: false, + }, + }, + }, +}; +``` ## devServer.webSocketServer - **Type:** `false | 'sockjs' | 'ws'` -Used to configure the type of web socket server. +This option allows us either to choose the current web-socket server or to provide custom web-socket server implementation. + +The current default mode is `'ws'`. This mode uses [`ws`](https://www.npmjs.com/package/ws) as a server, and native WebSockets on the client. + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + webSocketServer: 'ws', + }, +}; +``` diff --git a/website/docs/zh/config/dev-server.mdx b/website/docs/zh/config/dev-server.mdx index 83886e73431c..49781a376cd0 100644 --- a/website/docs/zh/config/dev-server.mdx +++ b/website/docs/zh/config/dev-server.mdx @@ -2,119 +2,535 @@ import WebpackLicense from '@components/webpack-license'; -# devServer +# DevServer -开发服务器:该选项用于配置 `@rspack/dev-server` 的行为。 +该选项用于配置 [`@rspack/dev-server`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-dev-server) 的行为,用于快速开发应用程序。 -- **类型:** `Object` +- **类型:** `object` :::tip -如果当前应用没有依赖 `@rspack/dev-server`,那么 devServer 配置将不会生效。 +如果你的应用未依赖 `@rspack/dev-server`,那么 devServer 配置将不起作用。 -比如,Rspack CLI 默认依赖了 `@rspack/dev-server`,因此在 Rspack CLI 项目里可以使用 devServer 配置。而 Rsbuild 自行实现了 dev server,并提供了单独的 "server" 配置,所以 Rsbuild 项目不能使用 devServer 配置。 +例如,Rspack CLI 默认依赖 `@rspack/dev-server`,因此在使用 Rspack CLI 的项目里可以使用 devServer 配置。而 Rsbuild 自行实现了开发服务器,并提供了单独的 "server" 配置,所以 Rsbuild 项目不能使用 devServer 配置。 ::: ## devServer.allowedHosts -- **类型:** `string | string[] | 'all' | 'auto'` +- **类型:** `'all' | 'auto' | string[]` - **默认值:** `'auto'` -允许访问 devServer 的白名单。 +该选项允许你设置允许访问开发服务器的白名单。 + +```js title="rspack.config.js" +module.exports = { + // ... + devServer: { + allowedHosts: [ + 'host.com', + 'subdomain.host.com', + 'subdomain2.host.com', + 'host2.com', + ], + }, +}; +``` + +模仿 Django 的 `ALLOWED_HOSTS` 配置,以点(.)开头的值可用作子域名的通配符。`.host.com` 将会匹配 `host.com`、`www.host.com` 以及 `host.com` 的任何其他子域名。 + +```js title="rspack.config.js" +module.exports = { + // ... + devServer: { + // 这能达到和第一个示例相同的效果 + // 额外的好处是如果新的子域名需要访问开发服务器 + // 不需要更新你的配置 + allowedHosts: ['.host.com', 'host2.com'], + }, +}; +``` + +当设置为 `'all'` 时,此选项会绕过主机检查。**不建议这么做**,因为不进行主机检查的应用容易受到 DNS 重绑定攻击的威胁。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + allowedHosts: 'all', + }, +}; +``` + +当设置为 `'auto'` 时,此选项总是允许 `localhost`、[`host`](#devserverhost) 和 [`client.webSocketURL.hostname`](#websocketurl): + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + allowedHosts: 'auto', + }, +}; +``` ## devServer.client -- **类型:** `Object` +- **类型:** `object` ### logging - **类型:** `'log' | 'info' | 'warn' | 'error' | 'none' | 'verbose'` - **默认值:** `'info'` -客户端的日志等级。 +设置在浏览器中日志级别,例如,在重新加载之前、出现错误之前或启用热模块替换时。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + logging: 'info', + }, + }, +}; +``` ### overlay -- **类型:** `boolean | Object` +- **类型:** `boolean | object` - **默认值:** `true` -当发生编译错误时是否在客户端的屏幕上报错。 +当编译器出现错误或警告时,在浏览器中显示一个全屏遮罩。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + overlay: true, + }, + }, +}; +``` + +你可以传入一个对象进行更细致的控制,该对象包含以下属性: + +| 属性 | 解释 | +| ------------- | ------------------ | +| errors | 编译错误 | +| runtimeErrors | 未处理的运行时错误 | +| warnings | 编译警告 | + +所有属性都是可选的,如果未提供,则默认为 `true`。 + +例如,要禁用编译警告,可以提供以下配置: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + overlay: { + errors: true, + warnings: false, + runtimeErrors: true, + }, + }, + }, +}; +``` + +要根据抛出的错误进行过滤,你可以传递一个接受 `error` 参数并返回布尔值的函数。 + +例如,要忽略由 [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) 抛出的错误: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + overlay: { + runtimeErrors: error => { + if (error instanceof DOMException && error.name === 'AbortError') { + return false; + } + return true; + }, + }, + }, + }, +}; +``` + +:::warning 警告 +在配置文件中,`runtimeErrors` 函数无法访问外部作用域中声明的变量。 +::: ### progress - **类型:** `boolean` - **默认值:** `true` -是否在客户端上显示编译进度。 +在浏览器中以百分比的形式打印编译进度。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + progress: true, + }, + }, +}; +``` ### reconnect - **类型:** `boolean | number` - **默认值:** `true` -开发服务器重新连接客户端的次数。`true` 表示不限次数。 +客户端应尝试重新连接的次数。当设置为 `true` 时,将尝试无限次重连。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + reconnect: true, + }, + }, +}; +``` + +当设置为 `false` 时,将不进行尝试重新连接。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + reconnect: false, + }, + }, +}; +``` + +你也可以指定客户端应尝试重新连接的确切次数。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + reconnect: 5, + }, + }, +}; +``` ### webSocketTransport - **类型:** `'ws' | 'sockjs'` - **默认值:** `ws` -客户端与开发服务器的传输方式。 +此选项允许我们为客户端单独选择当前的开发服务器传输模式,或提供自定义的客户端实现。这使得可以指定浏览器或其他客户端如何与开发服务器进行通信。 + +:::tip 提示 +设置 [`webSocketServer`](#devserverwebsocketserver) 为 `'ws'` 或 `'sockjs'` 是将 `devServer.client.webSocketTransport` 和 `devServer.webSocketServer` 同时设置为给定值的快捷方式。 +::: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketTransport: 'ws', + }, + webSocketServer: 'ws', + }, +}; +``` + +:::tip 提示 +当提供自定义的客户端和服务器实现时,请确保它们相互之间兼容,以便能够成功通信。 +::: + +要创建自定义客户端实现,请创建一个继承 `BaseClient` 的类。 + +使用路径引用 `CustomClient.js`,一个自定义的 WebSocket 客户端实现,以及与之兼容的 `'ws'` 服务器: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketTransport: require.resolve('./CustomClient'), + }, + webSocketServer: 'ws', + }, +}; +``` + +使用自定义、兼容的 WebSocket 客户端和服务器实现: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketTransport: require.resolve('./CustomClient'), + }, + webSocketServer: require.resolve('./CustomServer'), + }, +}; +``` ### webSocketURL - **类型:** `string | object` - **默认值:** `{}` -ws 服务器的 URL. +此选项允许指定 WebSocket 服务器的 URL(在代理开发服务器时很有用,因为客户端脚本不知道要连接到哪里)。 + +你还可以指定一个带有以下属性的对象: + +- `hostname`:告诉连接到开发服务器的客户端要使用的主机名。 +- `pathname`:告诉连接到开发服务器的客户端要使用的路径。 +- `password`:告诉连接到开发服务器的客户端要使用的密码进行认证。 +- `port`:告诉连接到开发服务器的客户端要使用的端口。 +- `protocol`:告诉连接到开发服务器的客户端要使用的协议。 +- `username`:告诉连接到开发服务器的客户端要使用的用户名进行认证。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + client: { + webSocketURL: { + hostname: '0.0.0.0', + pathname: '/ws', + password: 'dev-server', + port: 8080, + protocol: 'ws', + username: 'rspack', + }, + }, + }, +}; +``` + +:::tip 提示 +要从浏览器获取`协议`/`主机名`/`端口`,请使用 `webSocketURL: 'auto://0.0.0.0:0/ws'`。 +::: ## devServer.compress - **类型:** `boolean` - **默认值:** `true` -是否启用 gzip 压缩。 +启用 [gzip 压缩](https://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/)服务上的所有内容: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + compress: true, + }, +}; +``` ## devServer.devMiddleware - **类型:** `object` - **默认值:** `{}` -控制 rspack-dev-middleware 的行为。 +提供选项给 [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware),它用于处理 Rspack 的静态资源。 + +```ts +module.exports = { + devServer: { + devMiddleware: { + index: true, + mimeTypes: { phtml: 'text/html' }, + publicPath: '/publicPathForDevServe', + serverSideRender: true, + writeToDisk: true, + }, + }, +}; +``` ## devServer.headers - **类型:** `array | function | object` - **默认值:** `undefined` -增加响应头。 +为所有响应添加自定义 HTTP 头: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + headers: { + 'X-Custom-Foo': 'bar', + }, + }, +}; +``` + +你也可以传递数组: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + headers: [ + { + key: 'X-Custom', + value: 'foo', + }, + { + key: 'Y-Custom', + value: 'bar', + }, + ], + }, +}; +``` + +你也可以传递方法: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + headers: () => { + return { 'X-Bar': ['key1=value1', 'key2=value2'] }; + }, + }, +}; +``` ## devServer.historyApiFallback - **类型:** `boolean | object` - **默认值:** `false` -当请求 404 页面时的兜底逻辑。 +当使用 [HTML5 History API](https://developer.mozilla.org/en-US/docs/Web/API/History) 时,`index.html` 页面需要代替任何 `404` 响应被返回。通过将 `devServer.historyApiFallback` 设置为 `true` 来启用此功能: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + historyApiFallback: true, + }, +}; +``` + +通过传入对象,可以使用如 `rewrites` 等选项进一步控制此行为: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + historyApiFallback: { + rewrites: [ + { from: /^\/$/, to: '/views/landing.html' }, + { from: /^\/subpage/, to: '/views/subpage.html' }, + { from: /./, to: '/views/404.html' }, + ], + }, + }, +}; +``` + +当在路径中使用点(Angular 中常见)时,可能需要使用 `disableDotRule`: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + historyApiFallback: { + disableDotRule: true, + }, + }, +}; +``` + +有关更多选项和信息,请查看 [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback) 文档。 ## devServer.host - **类型:** `'local-ip' | 'local-ipv4' | 'local-ipv6' | string` - **默认值:** `'local-ip'` -开发服务器的地址。 +指定要使用的主机名。如果你希望服务器可以从外部访问,请像这样设置: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + host: '0.0.0.0', + }, +}; +``` + +### local-ip + +将 host 指定为 `local-ip` 会尝试将 host 选项解析为你的本地 `IPv4` 地址(如果可用),如果 `IPv4` 不可用,将尝试解析你的本地 `IPv6` 地址。 + +### local-ipv4 + +将 host 指定为 `local-ipv4` 会尝试将 host 选项解析为你的本地 `IPv4` 地址。 + +### local-ipv6 + +将 host 指定为 `local-ipv6` 会尝试将 host 选项解析为你的本地 `IPv6` 地址。 ## devServer.hot - **类型:** `boolean` - **默认值:** `true` -是否开启热更新。 +开启热更新: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + hot: true, + }, +}; +``` + +为了在构建失败的情况下启用热模块替换,同时不刷新页面作为备选方案,请使用 `hot: 'only'`: + +```javascript title="rspack.config.js" +module.exports = { + //... + devServer: { + hot: 'only', + }, +}; +``` ## devServer.liveReload - **类型:** `boolean` - **默认值:** `true` -是否重新加载页面。当开启 hot 时候该配置项会被关闭。 +默认情况下,当检测到文件变化时,开发服务器会重新加载/刷新页面。必须禁用 [`devServer.hot`](#devserverhot) 选项或启用 [`devServer.watchFiles`](#devserverwatchfiles) 选项,`liveReload` 才会生效。通过将 `devServer.liveReload` 设置为 `false` 来禁用它: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + liveReload: false, + }, +}; +``` + +:::tip 提示 +实时重新加载仅适用于与 web 相关的 [targets](/config/target),如 `web`、`webworker`、`electron-renderer` 和 `node-webkit`。 +::: ## devServer.magicHtml @@ -125,42 +541,404 @@ ws 服务器的 URL. ## devServer.onListening -- **类型:** `function` +- **类型:** `function (devServer)` + +提供在开发服务器开始在端口上监听连接时,执行自定义函数的能力: -当 devServer 与端口建立连接时的回调。 +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + onListening: function (devServer) { + if (!devServer) { + throw new Error('@rspack/dev-server 未定义'); + } + + const port = devServer.server.address().port; + console.log('正在监听端口:', port); + }, + }, +}; +``` ## devServer.open - **类型:** `boolean | string | object | [string, object]` - **默认值:** `true` -当 devServer 启动时是否打开浏览器。 +告诉开发服务器启动之后打开浏览器。设置为 `true` 以打开默认浏览器。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + open: true, + }, +}; +``` + +在浏览器中打开指定页面: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + open: ['/my-page'], + }, +}; +``` + +在浏览器中打开多个指定页面: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + open: ['/my-page', '/another-page'], + }, +}; +``` + +提供一个浏览器名称来替代默认的浏览器: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + open: { + app: { + name: 'google-chrome', + }, + }, + }, +}; +``` + +所有可用的 [open](https://www.npmjs.com/package/open) 选项: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + open: { + target: ['first.html', 'http://localhost:8080/second.html'], + app: { + name: 'google-chrome', + arguments: ['--incognito', '--new-window'], + }, + }, + }, +}; +``` + +:::tip 提示 +浏览器应用名称依赖于平台。在可复用的模块中不要硬编码它。例如,macOS 上是 `'Google Chrome'`,Linux 上是 `'google-chrome'`,而 Windows 上是 `'chrome'`。 +::: ## devServer.port - **类型:** `'auto' | string | number` - **默认值:** `[]` -用于配置端口号。 +指定要监听请求的端口号: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + port: 8080, + }, +}; +``` + +`port` 选项不能为 `null` 或为空字符串,要自动使用空闲端口,请使用 `port: 'auto'`。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + port: 'auto', + }, +}; +``` ## devServer.proxy - **类型:** `object | [object, function]` -配置代理,可用于解决跨域问题等。 +当你有一个单独的 API 后端开发服务器,且希望在同一个域上发送 API 请求时,代理 URL 可能会很有用。 + +开发服务器使用了强大的 [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) 包。查看其[文档](https://github.com/chimurai/http-proxy-middleware#options)了解更多高级用法。 +请注意,`http-proxy-middleware` 的一些功能不需要 target 选项,例如其 `router` 功能,但你在这里的配置中仍然需要包含 `target` 选项,否则开发服务器不会将其传递给 `http-proxy-middleware`。 + +如果你有一个运行在 `localhost:3000` 的后端,你可以使用以下配置来启用代理: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + }, + ], + }, +}; +``` + +现在,对 `/api/users` 的请求将会代理到 `http://localhost:3000/api/users`。 + +如果你不希望将 `/api` 传递,我们需要重写路径: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + pathRewrite: { '^/api': '' }, + }, + ], + }, +}; +``` + +默认情况下,带有无效证书的 HTTPS 后端服务器将不被接受。如果你愿意,可以像下面这样修改你的配置: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + secure: false, + }, + ], + }, +}; +``` + +有时你不希望代理所有内容。可以根据函数的返回值来绕过代理。 + +在该函数中,你可以访问请求、响应和代理选项。 + +- 返回 `null` 或 `undefined` 继续使用代理处理请求。 +- 返回 `false` 对请求产生一个 404 错误。 +- 返回一个路径以从该路径服务内容,而不是继续代理请求。 + +例如,对于浏览器请求,你希望服务一个 HTML 页面,但对于 API 请求,你希望将它代理。你可以这样做: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + bypass: function (req, res, proxyOptions) { + if (req.headers.accept.indexOf('html') !== -1) { + console.log('Skipping proxy for browser request.'); + return '/index.html'; + } + }, + }, + ], + }, +}; +``` + +如果你想要将多个、特定的路径代理到相同的目标,你可以使用一个或多个带有 `context` 属性的对象的数组: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/auth', '/api'], + target: 'http://localhost:3000', + }, + ], + }, +}; +``` + +请注意,默认不会代理对根目录的请求。要启用根代理,应将 `devMiddleware.index` 选项指定为 falsy 值: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + devMiddleware: { + index: false, // 启用根代理 + }, + proxy: [ + { + context: () => true, + target: 'http://localhost:1234', + }, + ], + }, +}; +``` + +在默认情况下会保留代理时的 host 头部的原始值,你可以将 `changeOrigin` 设置为 `true` 来改变这一行为。这在某些情况下很有用,例如使用[基于名称的虚拟主机](https://en.wikipedia.org/wiki/Virtual_hosting#Name-based)。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + proxy: [ + { + context: ['/api'], + target: 'http://localhost:3000', + changeOrigin: true, + }, + ], + }, +}; +``` ## devServer.server - **类型:** `'http' | 'https' | 'spdy' | string | object` - **默认值:** `'http'` -服务器的配置项。 +用于设置服务器(默认为“http”): + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + server: 'http', + }, +}; +``` + +使用自签名证书通过 `HTTPS` 提供服务: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + server: 'https', + }, +}; +``` + +通过 [spdy](https://www.npmjs.com/package/spdy) 使用自签名证书提供 `HTTP/2` 服务: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + server: 'spdy', + }, +}; +``` + +传递对象提供你自己的证书: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + server: { + type: 'https', + options: { + ca: './path/to/server.pem', + pfx: './path/to/server.pfx', + key: './path/to/server.key', + cert: './path/to/server.crt', + passphrase: '@rspack/dev-server', + requestCert: true, + }, + }, + }, +}; +``` + +它还允许你设置其他 [TLS 选项](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options),如 `minVersion`,并且你可以直接传递相应文件的内容: + +```js title="rspack.config.js" +const fs = require('fs'); +const path = require('path'); + +module.exports = { + //... + devServer: { + server: { + type: 'https', + options: { + minVersion: 'TLSv1.1', + key: fs.readFileSync(path.join(__dirname, './server.key')), + pfx: fs.readFileSync(path.join(__dirname, './server.pfx')), + cert: fs.readFileSync(path.join(__dirname, './server.crt')), + ca: fs.readFileSync(path.join(__dirname, './ca.pem')), + passphrase: '@rspack/dev-server', + requestCert: true, + }, + }, + }, +}; +``` ## devServer.setupMiddlewares - **类型:** `function (middlewares, devServer)` -自定义中间件。 +提供执行自定义函数和应用自定义中间件的能力。 + +```js title="rspack.config.js" +module.exports = { + // ... + devServer: { + setupMiddlewares: (middlewares, devServer) => { + if (!devServer) { + throw new Error('@rspack/dev-server is not defined'); + } + + devServer.app.get('/setup-middleware/some/path', (_, response) => { + response.send('setup-middlewares option GET'); + }); + + // Use the `unshift` method if you want to run a middleware before all other middlewares + // or when you are migrating from the `onBeforeSetupMiddleware` option + middlewares.unshift({ + name: 'first-in-array', + // `path` is optional + path: '/foo/path', + middleware: (req, res) => { + res.send('Foo!'); + }, + }); + + // Use the `push` method if you want to run a middleware after all other middlewares + // or when you are migrating from the `onAfterSetupMiddleware` option + middlewares.push({ + name: 'hello-world-test-one', + // `path` is optional + path: '/foo/bar', + middleware: (req, res) => { + res.send('Foo Bar!'); + }, + }); + + middlewares.push((req, res) => { + res.send('Hello World!'); + }); + + return middlewares; + }, + }, +}; +``` ## devServer.static @@ -168,14 +946,83 @@ ws 服务器的 URL. 用于配置是否从一些目录(默认为 'public')启用静态服务器。 +此选项允许配置从目录获取静态文件(默认是 'public' 目录)。要禁用请将其设置为 `false`: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + static: false, + }, +}; +``` + +要监听单个目录: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + static: ['assets'], + }, +}; +``` + +要监听多个静态目录: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + static: ['assets', 'css'], + }, +}; +``` + ## devServer.watchFiles - **类型:** `string | object | [string, object]` -监听一系列文件的变化。 +该选项允许你配置一个列表监视文件变化,可以是通配符、目录和文件。例如: + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + watchFiles: ['src/**/*.php', 'public/**/*'], + }, +}; +``` + +你还可以为文件监控配置更多选项。有关的选项,请参阅 [`chokidar`](https://github.com/paulmillr/chokidar) 文档。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + watchFiles: { + paths: ['src/**/*.php', 'public/**/*'], + options: { + usePolling: false, + }, + }, + }, +}; +``` ## devServer.webSocketServer - **类型:** `false | 'sockjs' | 'ws'` -用于配置 Web Socket 服务器的类型。 +此选项允许我们选择当前的 web-socket 服务器或提供自定义的 web-socket 服务器实现。 + +当前的默认模式是 `'ws'`。此模式在服务器端使用 [`ws`](https://www.npmjs.com/package/ws) 库,并在客户端使用原生 WebSockets。 + +```js title="rspack.config.js" +module.exports = { + //... + devServer: { + webSocketServer: 'ws', + }, +}; +``` diff --git a/website/project-words.txt b/website/project-words.txt index 4783a036a874..596675a6ee5e 100644 --- a/website/project-words.txt +++ b/website/project-words.txt @@ -145,3 +145,7 @@ xstyled Zack Zack Jackson zackarychapple +devserverwebsocketserver +devserverdevmiddleware +proxying +proxied From ae03277b4bb8e49f351fece6aa2419e50cdd8856 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 14 May 2024 19:21:02 +0800 Subject: [PATCH 073/107] feat: export types of CSS extract plugin (#6528) * feat: export types of CSS extract plugin * chore: update api.md * chore: fix prettier --- packages/rspack/etc/api.md | 60 ++++++++++++------- .../src/builtin-plugin/css-extract/index.ts | 12 ++-- .../src/builtin-plugin/css-extract/loader.ts | 6 +- packages/rspack/src/exports.ts | 4 ++ 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 5e0d2845148b..95b0beee356c 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -1559,21 +1559,53 @@ export type CssChunkFilename = z.infer; // @public (undocumented) const cssChunkFilename: z.ZodUnion<[z.ZodString, z.ZodFunction, z.ZodOptional>], z.ZodUnknown>, z.ZodString>]>; +// @public (undocumented) +export interface CssExtractRspackLoaderOptions { + // (undocumented) + emit?: boolean; + // (undocumented) + esModule?: boolean; + // (undocumented) + layer?: boolean; + // (undocumented) + publicPath?: string | ((resourcePath: string, context: string) => string); +} + // @public (undocumented) export class CssExtractRspackPlugin { - constructor(options?: PluginOptions); + constructor(options?: CssExtractRspackPluginOptions); // (undocumented) apply(compiler: Compiler): void; // (undocumented) static loader: string; // (undocumented) - normalizeOptions(options: PluginOptions): RawCssExtractPluginOption; + normalizeOptions(options: CssExtractRspackPluginOptions): RawCssExtractPluginOption; // (undocumented) - options: PluginOptions; + options: CssExtractRspackPluginOptions; // (undocumented) static pluginName: string; } +// @public (undocumented) +export interface CssExtractRspackPluginOptions { + // (undocumented) + attributes?: Record; + // (undocumented) + chunkFilename?: string; + // (undocumented) + filename?: string; + // (undocumented) + ignoreOrder?: boolean; + // (undocumented) + insert?: string | ((linkTag: HTMLLinkElement) => void); + // (undocumented) + linkType?: string | "text/css" | false; + // (undocumented) + pathinfo?: boolean; + // (undocumented) + runtime?: boolean; +} + // @public (undocumented) export type CssFilename = z.infer; @@ -7255,26 +7287,6 @@ type PluginImportConfig = { // @public (undocumented) type PluginImportOptions = PluginImportConfig[] | undefined; -// @public (undocumented) -interface PluginOptions { - // (undocumented) - attributes?: Record; - // (undocumented) - chunkFilename?: string; - // (undocumented) - filename?: string; - // (undocumented) - ignoreOrder?: boolean; - // (undocumented) - insert?: string | ((linkTag: HTMLLinkElement) => void); - // (undocumented) - linkType?: string | "text/css" | false; - // (undocumented) - pathinfo?: boolean; - // (undocumented) - runtime?: boolean; -} - // @public (undocumented) export type Plugins = z.infer; @@ -7643,6 +7655,8 @@ declare namespace rspackExports { EvalDevToolModulePlugin, EvalDevToolModulePluginOptions, CssExtractRspackPlugin, + CssExtractRspackPluginOptions, + CssExtractRspackLoaderOptions, SwcLoaderOptions, SwcLoaderEnvConfig, SwcLoaderJscConfig, diff --git a/packages/rspack/src/builtin-plugin/css-extract/index.ts b/packages/rspack/src/builtin-plugin/css-extract/index.ts index 0b0e9e60e47d..f9975e759144 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/index.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/index.ts @@ -7,7 +7,9 @@ export * from "./loader"; const DEFAULT_FILENAME = "[name].css"; const LOADER_PATH = require.resolve("./loader"); -export interface PluginOptions { +export type { CssExtractRspackLoaderOptions } from "./loader"; + +export interface CssExtractRspackPluginOptions { filename?: string; chunkFilename?: string; ignoreOrder?: boolean; @@ -24,9 +26,9 @@ export class CssExtractRspackPlugin { static pluginName: string = "css-extract-rspack-plugin"; static loader: string = LOADER_PATH; - options: PluginOptions; + options: CssExtractRspackPluginOptions; - constructor(options?: PluginOptions) { + constructor(options?: CssExtractRspackPluginOptions) { this.options = options || {}; } @@ -56,7 +58,9 @@ export class CssExtractRspackPlugin { }); } - normalizeOptions(options: PluginOptions): RawCssExtractPluginOption { + normalizeOptions( + options: CssExtractRspackPluginOptions + ): RawCssExtractPluginOption { let chunkFilename = options.chunkFilename; if (!chunkFilename) { diff --git a/packages/rspack/src/builtin-plugin/css-extract/loader.ts b/packages/rspack/src/builtin-plugin/css-extract/loader.ts index f756e3e905df..b51663b984f6 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/loader.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/loader.ts @@ -26,7 +26,7 @@ interface DependencyDescription { filepath: string; } -export interface LoaderOptions { +export interface CssExtractRspackLoaderOptions { publicPath?: string | ((resourcePath: string, context: string) => string); emit?: boolean; esModule?: boolean; @@ -39,7 +39,7 @@ function hotLoader( content: string, context: { loaderContext: LoaderContext; - options: LoaderOptions; + options: CssExtractRspackLoaderOptions; locals: Record; } ) { @@ -102,7 +102,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { return; } - const options = this.getOptions(schema) as LoaderOptions; + const options = this.getOptions(schema) as CssExtractRspackLoaderOptions; const emit = typeof options.emit !== "undefined" ? options.emit : true; const callback = this.async(); const filepath = this.resourcePath; diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 45a210c421a4..5f74748e0329 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -259,6 +259,10 @@ export { EvalDevToolModulePlugin } from "./builtin-plugin"; export type { EvalDevToolModulePluginOptions } from "./builtin-plugin"; export { CssExtractRspackPlugin } from "./builtin-plugin"; +export type { + CssExtractRspackPluginOptions, + CssExtractRspackLoaderOptions +} from "./builtin-plugin"; ///// Rspack Postfixed Internal Loaders ///// export type { From ecbd5248337abb223a592311d95fd792a5ae1522 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Tue, 14 May 2024 19:25:04 +0800 Subject: [PATCH 074/107] test: add type of hook cases (#6531) * test: add type of hook cases * test: add type of hook cases --- packages/rspack-test-tools/etc/api.md | 17 +++++++++--- packages/rspack-test-tools/src/case/hook.ts | 27 +++++++++++++------ .../rspack-test-tools/src/processor/hook.ts | 25 ++++++++++++----- .../basic/test.js | 9 +------ .../update-asset/hooks.snap.txt | 4 +-- .../update-asset/output.snap.txt | 2 +- .../update-asset/test.js | 27 ++++++++++++++----- .../compiler#assetEmitted/basic/test.js | 8 ++---- .../duplicate/test.js | 9 +------ .../request/test.js | 9 +------ .../resource/test.js | 9 +------ 11 files changed, 82 insertions(+), 64 deletions(-) diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index 87fad2910948..a691d47c7c70 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -303,13 +303,15 @@ export class HookCasesContext extends TestContext { // @public (undocumented) export class HookTaskProcessor extends SnapshotProcessor { - constructor(hookOptions: IHookProcessorOptions); + constructor(_hookOptions: IHookProcessorOptions); // (undocumented) check(env: ITestEnv, context: HookCasesContext): Promise; // (undocumented) + compiler(context: ITestContext): Promise; + // (undocumented) config(context: ITestContext): Promise; // (undocumented) - protected hookOptions: IHookProcessorOptions; + protected _hookOptions: IHookProcessorOptions; } // @public (undocumented) @@ -497,7 +499,11 @@ export interface IFormatCodeOptions { } // @public (undocumented) -interface IHookProcessorOptions extends ISnapshotProcessorOptions { +export interface IHookProcessorOptions extends ISnapshotProcessorOptions { + // (undocumented) + check?: (context: ITestContext) => Promise; + // (undocumented) + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; // (undocumented) options?: (context: ITestContext) => TCompilerOptions; } @@ -1185,6 +1191,11 @@ export type TFileCompareResult = TCompareResult & { modules: Partial>; }; +// @public (undocumented) +export type THookCaseConfig = Omit, "name" | "compilerType" | "runable"> & { + description: string; +}; + // @public (undocumented) export type THotStepRuntimeData = { javascript: THotStepRuntimeLangData; diff --git a/packages/rspack-test-tools/src/case/hook.ts b/packages/rspack-test-tools/src/case/hook.ts index a712a77c124d..d06d989d8aee 100644 --- a/packages/rspack-test-tools/src/case/hook.ts +++ b/packages/rspack-test-tools/src/case/hook.ts @@ -1,17 +1,30 @@ import path from "path"; import { getSimpleProcessorRunner } from "../test/simple"; -import { HookCasesContext, HookTaskProcessor } from "../processor"; +import { + HookCasesContext, + HookTaskProcessor, + IHookProcessorOptions +} from "../processor"; import { BasicRunnerFactory } from "../runner"; -import { ECompilerType, TCompilerOptions } from "../type"; +import { ECompilerType } from "../type"; import createLazyTestEnv from "../helper/legacy/createLazyTestEnv"; +export type THookCaseConfig = Omit< + IHookProcessorOptions, + "name" | "compilerType" | "runable" +> & { + description: string; +}; + export function createHookCase( name: string, src: string, dist: string, source: string ) { - const caseConfig = require(path.join(src, "test.js")); + const caseConfig: Partial = require( + path.join(src, "test.js") + ); const testName = path.basename( name.slice(0, name.indexOf(path.extname(name))) ); @@ -25,19 +38,17 @@ export function createHookCase( }) }); - it(caseConfig.description, async () => { + it(caseConfig.description!, async () => { await runner( name, new HookTaskProcessor({ name, compilerType: ECompilerType.Rspack, - findBundle: function ( - i: number, - options: TCompilerOptions - ) { + findBundle: function () { return ["main.js"]; }, snapshot: path.join(src, "output.snap.txt"), + runable: true, ...caseConfig }) ); diff --git a/packages/rspack-test-tools/src/processor/hook.ts b/packages/rspack-test-tools/src/processor/hook.ts index 5feba8c37d5e..e1ec1e8730a5 100644 --- a/packages/rspack-test-tools/src/processor/hook.ts +++ b/packages/rspack-test-tools/src/processor/hook.ts @@ -3,6 +3,7 @@ import { ECompilerType, ITestContext, ITestEnv, + TCompiler, TCompilerOptions } from "../type"; import { Source } from "webpack-sources"; @@ -174,14 +175,16 @@ export class HookCasesContext extends TestContext { } } -interface IHookProcessorOptions +export interface IHookProcessorOptions extends ISnapshotProcessorOptions { options?: (context: ITestContext) => TCompilerOptions; + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; + check?: (context: ITestContext) => Promise; } export class HookTaskProcessor extends SnapshotProcessor { constructor( - protected hookOptions: IHookProcessorOptions + protected _hookOptions: IHookProcessorOptions ) { super({ defaultOptions: context => { @@ -205,21 +208,31 @@ export class HookTaskProcessor extends SnapshotProcessor { } }; }, - ...hookOptions, - runable: true + ..._hookOptions }); } async config(context: ITestContext): Promise { await super.config(context); const compiler = this.getCompiler(context); - if (typeof this.hookOptions.options === "function") { - compiler.mergeOptions(this.hookOptions.options(context)); + if (typeof this._hookOptions.options === "function") { + compiler.mergeOptions(this._hookOptions.options(context)); + } + } + + async compiler(context: ITestContext): Promise { + await super.compiler(context); + if (typeof this._hookOptions.compiler === "function") { + const compiler = this.getCompiler(context); + await this._hookOptions.compiler(context, compiler.getCompiler()!); } } async check(env: ITestEnv, context: HookCasesContext) { await (context as any).collectSnapshots(); await super.check(env, context); + if (typeof this._hookOptions.check === "function") { + await this._hookOptions.check(context); + } } } diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/test.js b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/test.js index 52c1437e8971..e419b1121506 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/test.js +++ b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/test.js @@ -1,7 +1,4 @@ -const { createFsFromVolume, Volume } = require("memfs"); - -const outputFileSystem = createFsFromVolume(new Volume()); - +/** @type {import("../../../..").THookCaseConfig} */ module.exports = { description: "should call afterProcessAssets correctly", options(context) { @@ -24,8 +21,4 @@ module.exports = { ] }; }, - async compiler(context, compiler) { - compiler.outputFileSystem = outputFileSystem; - }, - async check() {} }; diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt index 1b64502e79b6..ce3e4e04406c 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt @@ -5,7 +5,7 @@ ```javascript Array [ Object { - "main.js": (function() { + "main.1e610dc4781566449f96.js": (function() { var __webpack_modules__ = { "600": (function (module) { module.exports = "This is hook"; @@ -50,7 +50,7 @@ undefined ```javascript Array [ Object { - "main.js": // UPDATED + "main.1e610dc4781566449f96.js": // UPDATED (function() { var __webpack_modules__ = { "600": (function (module) { diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt index 998e86530c0b..2bb46a3aa1ba 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt @@ -1,4 +1,4 @@ -```js title=main.js +```js title=main.72cf2b1eb9f1ef5c7d0a.js // UPDATED (function() { var __webpack_modules__ = { diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/test.js b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/test.js index a6e42c4970c9..8a20f4992021 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/test.js +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/test.js @@ -1,12 +1,18 @@ -const { createFsFromVolume, Volume } = require("memfs"); - -const outputFileSystem = createFsFromVolume(new Volume()); let contentHashes = []; +let files = []; +/** @type {import("../../../..").THookCaseConfig} */ module.exports = { description: "should emit assets correctly", + findBundle() { + return files; + }, + options(context) { return { + output: { + filename: '[name].[contenthash].js' + }, plugins: [ function plugin(compiler) { compiler.hooks.compilation.tap("test", compilation => { @@ -39,14 +45,23 @@ module.exports = { }); }) ); + + compilation.hooks.afterProcessAssets.tap( + { + name: "test", + stage: + compiler.webpack.Compilation + .PROCESS_ASSETS_STAGE_OPTIMIZE_HASH + }, + (assets) => { + files.push(...Object.keys(assets)); + } + ); }); } ] }; }, - async compiler(context, compiler) { - compiler.outputFileSystem = outputFileSystem; - }, async check() { contentHashes.forEach(hash => { expect(hash.length).toBeGreaterThan(0); diff --git a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/test.js b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/test.js index a76160fc81c4..1e703fe14ff2 100644 --- a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/test.js +++ b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/test.js @@ -1,9 +1,8 @@ const assert = require("assert"); -const { createFsFromVolume, Volume } = require("memfs"); - -const outputFileSystem = createFsFromVolume(new Volume()); let hasMainJs = false; + +/** @type {import("../../../..").THookCaseConfig} */ module.exports = { description: "should work with assetEmitted", options(context) { @@ -24,9 +23,6 @@ module.exports = { ] }; }, - async compiler(context, compiler) { - compiler.outputFileSystem = outputFileSystem; - }, async check() { expect(hasMainJs).toBeTruthy(); } diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js index 51f28814c281..5009bad4ed10 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js @@ -1,7 +1,4 @@ -const { createFsFromVolume, Volume } = require("memfs"); - -const outputFileSystem = createFsFromVolume(new Volume()); - +/** @type {import("../../../..").THookCaseConfig} */ module.exports = { description: "should work with duplicate", options(context) { @@ -38,8 +35,4 @@ module.exports = { ] }; }, - async compiler(context, compiler) { - compiler.outputFileSystem = outputFileSystem; - }, - async check() {} }; diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/test.js b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/test.js index 53e8eb6a32eb..aeed8971ff1f 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/test.js +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/test.js @@ -1,7 +1,4 @@ -const { createFsFromVolume, Volume } = require("memfs"); - -const outputFileSystem = createFsFromVolume(new Volume()); - +/** @type {import("../../../..").THookCaseConfig} */ module.exports = { description: "should work with request", options(context) { @@ -36,8 +33,4 @@ module.exports = { ] }; }, - async compiler(context, compiler) { - compiler.outputFileSystem = outputFileSystem; - }, - async check() {} }; diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/test.js b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/test.js index a6c6a770afe5..ea7974c81cc2 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/test.js +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/test.js @@ -1,7 +1,4 @@ -const { createFsFromVolume, Volume } = require("memfs"); - -const outputFileSystem = createFsFromVolume(new Volume()); - +/** @type {import("../../../..").THookCaseConfig} */ module.exports = { description: "should work with resource", options(context) { @@ -31,8 +28,4 @@ module.exports = { ] }; }, - async compiler(context, compiler) { - compiler.outputFileSystem = outputFileSystem; - }, - async check() {} }; From 9b0c6601e7d593b4a73c8e481d436ac360983c9c Mon Sep 17 00:00:00 2001 From: Gengkun Date: Tue, 14 May 2024 20:29:17 +0800 Subject: [PATCH 075/107] refactor: remove browserField (#6535) --- packages/rspack/etc/api.md | 3 --- packages/rspack/src/config/zod.ts | 15 --------------- website/docs/en/config/resolve.mdx | 2 +- website/docs/zh/config/resolve.mdx | 2 +- 4 files changed, 2 insertions(+), 20 deletions(-) diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 95b0beee356c..1d5bbbfcd2a0 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -565,7 +565,6 @@ interface BaseModuleConfig { // @public (undocumented) const baseResolveOptions: z.ZodObject<{ alias: z.ZodOptional, z.ZodString]>, z.ZodArray]>, "many">]>>>; - browserField: z.ZodEffects, boolean | undefined, boolean | undefined>; conditionNames: z.ZodOptional>; extensions: z.ZodOptional>; fallback: z.ZodOptional, z.ZodString]>, z.ZodArray]>, "many">]>>>; @@ -597,7 +596,6 @@ const baseResolveOptions: z.ZodObject<{ roots: z.ZodOptional>; }, "strict", z.ZodTypeAny, { alias?: Record | undefined; - browserField?: boolean | undefined; conditionNames?: string[] | undefined; extensions?: string[] | undefined; fallback?: Record | undefined; @@ -623,7 +621,6 @@ const baseResolveOptions: z.ZodObject<{ roots?: string[] | undefined; }, { alias?: Record | undefined; - browserField?: boolean | undefined; conditionNames?: string[] | undefined; extensions?: string[] | undefined; fallback?: Record | undefined; diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index d3392e692cd6..05fdadf971b0 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -386,21 +386,6 @@ export type ResolveTsconfig = z.infer; const baseResolveOptions = z.strictObject({ alias: resolveAlias.optional(), - /** - * This is `aliasField: ["browser"]` in webpack, because no one - * uses aliasField other than "browser". ---@bvanjoi - */ - browserField: z - .boolean() - .optional() - .refine(val => { - if (val !== undefined) { - deprecatedWarn( - `'resolve.browserField' has been deprecated, and will be removed in 0.6.0. Please use 'resolve.aliasField' instead.` - ); - } - return true; - }), conditionNames: z.array(z.string()).optional(), extensions: z.array(z.string()).optional(), fallback: resolveAlias.optional(), diff --git a/website/docs/en/config/resolve.mdx b/website/docs/en/config/resolve.mdx index 47593f1956ce..3f4e539d1b77 100644 --- a/website/docs/en/config/resolve.mdx +++ b/website/docs/en/config/resolve.mdx @@ -37,7 +37,7 @@ Define a field, such as `browser`, that should be parsed in accordance with [thi ## resolve.browserField - + - **Type:** `boolean` - **Default:** `true` diff --git a/website/docs/zh/config/resolve.mdx b/website/docs/zh/config/resolve.mdx index 70dd9aac5069..682ca0ecdd85 100644 --- a/website/docs/zh/config/resolve.mdx +++ b/website/docs/zh/config/resolve.mdx @@ -37,7 +37,7 @@ import { ApiMeta } from '../../../components/ApiMeta'; ## resolve.browserField - + - **类型:** `boolean` - **默认值:** `true` From 3ee5df76e77dcb477f29f7343822a390be524f18 Mon Sep 17 00:00:00 2001 From: Hana Date: Tue, 14 May 2024 23:58:33 +0800 Subject: [PATCH 076/107] chore: add eslint for import order sorting (#6539) * chore: add eslint for import order sorting * chore: ci * chore: api --- .eslintignore | 7 + .github/workflows/ci.yml | 15 +- eslint.config.mjs | 36 ++ lint-staged.config.mjs | 1 + package.json | 7 +- .../create-rspack/template-vue/src/main.js | 4 +- packages/rspack-cli/src/commands/build.ts | 3 +- packages/rspack-cli/src/commands/preview.ts | 11 +- packages/rspack-cli/src/commands/serve.ts | 5 +- packages/rspack-cli/src/index.ts | 2 +- packages/rspack-cli/src/rspack-cli.ts | 39 +- packages/rspack-cli/src/types.ts | 3 +- packages/rspack-cli/src/utils/crossImport.ts | 1 + packages/rspack-cli/src/utils/findConfig.ts | 1 + packages/rspack-cli/src/utils/isEsmFile.ts | 1 + packages/rspack-cli/src/utils/loadConfig.ts | 11 +- packages/rspack-cli/src/utils/profile.ts | 14 +- packages/rspack-dev-server/src/config.ts | 2 +- packages/rspack-dev-server/src/middleware.ts | 8 +- packages/rspack-dev-server/src/server.ts | 10 +- .../rspack-plugin-react-refresh/src/index.ts | 3 +- packages/rspack-test-tools/jest.d.ts | 1 - .../rspack-test-tools/src/case/builtin.ts | 3 +- .../rspack-test-tools/src/case/compiler.ts | 2 +- .../rspack-test-tools/src/case/defaults.ts | 5 +- packages/rspack-test-tools/src/case/diff.ts | 5 +- packages/rspack-test-tools/src/case/error.ts | 4 +- packages/rspack-test-tools/src/case/hash.ts | 2 +- packages/rspack-test-tools/src/case/hook.ts | 5 +- .../rspack-test-tools/src/case/hot-step.ts | 4 +- packages/rspack-test-tools/src/case/hot.ts | 4 +- packages/rspack-test-tools/src/case/index.ts | 16 +- packages/rspack-test-tools/src/case/normal.ts | 3 +- .../rspack-test-tools/src/case/stats-api.ts | 4 +- packages/rspack-test-tools/src/case/watch.ts | 3 +- .../src/compare/comparator.ts | 7 +- .../rspack-test-tools/src/compare/compare.ts | 7 +- .../src/compare/format-code.ts | 3 +- .../rspack-test-tools/src/compare/index.ts | 6 +- packages/rspack-test-tools/src/compiler.ts | 3 +- .../rspack-test-tools/src/helper/directory.ts | 1 + .../rspack-test-tools/src/helper/index.ts | 4 +- .../src/helper/legacy/createFakeWorker.js | 1 - .../src/helper/read-config-file.ts | 3 +- packages/rspack-test-tools/src/index.ts | 16 +- .../src/plugin/webpack-diff-config-plugin.ts | 1 + .../rspack-test-tools/src/processor/basic.ts | 5 +- .../src/processor/builtin.ts | 5 +- .../rspack-test-tools/src/processor/config.ts | 7 +- .../src/processor/defaults.ts | 7 +- .../src/processor/diagnostic.ts | 9 +- .../rspack-test-tools/src/processor/diff.ts | 17 +- .../rspack-test-tools/src/processor/error.ts | 13 +- .../rspack-test-tools/src/processor/hook.ts | 11 +- .../src/processor/hot-step.ts | 11 +- .../rspack-test-tools/src/processor/hot.ts | 5 +- .../rspack-test-tools/src/processor/index.ts | 22 +- .../rspack-test-tools/src/processor/multi.ts | 3 +- .../rspack-test-tools/src/processor/normal.ts | 5 +- .../src/processor/snapshot.ts | 9 +- .../src/processor/stats-api.ts | 7 +- .../rspack-test-tools/src/processor/stats.ts | 9 +- .../src/processor/treeshaking.ts | 2 +- .../rspack-test-tools/src/processor/watch.ts | 9 +- .../src/reporter/diff-html.ts | 5 +- .../src/reporter/diff-stats.ts | 5 +- .../rspack-test-tools/src/reporter/index.ts | 2 +- .../rspack-test-tools/src/runner/basic.ts | 2 +- .../rspack-test-tools/src/runner/hot-step.ts | 1 + packages/rspack-test-tools/src/runner/hot.ts | 1 + .../rspack-test-tools/src/runner/index.ts | 4 +- .../src/runner/runner/basic.ts | 5 +- .../src/runner/runner/cjs.ts | 5 +- .../src/runner/runner/esm.ts | 5 +- .../src/runner/runner/normal.ts | 5 +- .../src/runner/runner/watch.ts | 7 +- .../src/runner/runner/web/fake.ts | 17 +- .../src/runner/runner/web/jsdom.ts | 13 +- .../rspack-test-tools/src/runner/watch.ts | 2 +- .../rspack-test-tools/src/test/context.ts | 9 +- .../rspack-test-tools/src/test/creator.ts | 11 +- packages/rspack-test-tools/src/test/tester.ts | 8 +- packages/rspack-test-tools/src/type.ts | 7 +- packages/rspack/etc/api.md | 490 +++++++++--------- .../scripts/check-documentation-coverage.mjs | 6 +- packages/rspack/src/Chunk.ts | 3 +- packages/rspack/src/ChunkGraph.ts | 1 + packages/rspack/src/Compilation.ts | 39 +- packages/rspack/src/Compiler.ts | 44 +- packages/rspack/src/Entrypoint.ts | 3 +- packages/rspack/src/ExecuteModulePlugin.ts | 3 +- packages/rspack/src/Module.ts | 1 + packages/rspack/src/MultiCompiler.ts | 13 +- packages/rspack/src/MultiStats.ts | 2 +- packages/rspack/src/MultiWatching.ts | 3 +- packages/rspack/src/NormalModule.ts | 1 + packages/rspack/src/NormalModuleFactory.ts | 3 +- packages/rspack/src/Stats.ts | 7 +- packages/rspack/src/Watching.ts | 3 +- .../rspack/src/builtin-loader/swc/index.ts | 22 +- .../rspack/src/builtin-loader/swc/relay.ts | 2 +- .../rspack/src/builtin-loader/swc/types.ts | 4 +- .../rspack/src/builtin-plugin/APIPlugin.ts | 1 + .../ArrayPushCallbackChunkFormatPlugin.ts | 1 + .../src/builtin-plugin/AssetModulesPlugin.ts | 1 + .../AsyncWebAssemblyModulesPlugin.ts | 1 + .../rspack/src/builtin-plugin/BannerPlugin.ts | 3 +- .../builtin-plugin/BundlerInfoRspackPlugin.ts | 1 + .../ChunkPrefetchPreloadPlugin.ts | 1 + .../CommonJsChunkFormatPlugin.ts | 1 + .../src/builtin-plugin/CopyRspackPlugin.ts | 1 + .../src/builtin-plugin/CssModulesPlugin.ts | 1 + .../src/builtin-plugin/DataUriPlugin.ts | 1 + .../rspack/src/builtin-plugin/DefinePlugin.ts | 1 + .../DeterministicChunkIdsPlugin.ts | 1 + .../DeterministicModuleIdsPlugin.ts | 1 + .../src/builtin-plugin/DynamicEntryPlugin.ts | 3 +- .../builtin-plugin/ElectronTargetPlugin.ts | 1 + .../EnableChunkLoadingPlugin.ts | 1 + .../src/builtin-plugin/EnableLibraryPlugin.ts | 3 +- .../builtin-plugin/EnableWasmLoadingPlugin.ts | 1 + .../EnsureChunkConditionsPlugin.ts | 1 + .../rspack/src/builtin-plugin/EntryPlugin.ts | 9 +- .../builtin-plugin/EvalDevToolModulePlugin.ts | 1 + .../EvalSourceMapDevToolPlugin.ts | 1 + .../src/builtin-plugin/ExternalsPlugin.ts | 3 +- .../src/builtin-plugin/FileUriPlugin.ts | 1 + .../FlagDependencyExportsPlugin.ts | 1 + .../FlagDependencyUsagePlugin.ts | 1 + .../HotModuleReplacementPlugin.ts | 3 +- .../src/builtin-plugin/HtmlRspackPlugin.ts | 5 +- .../HttpExternalsRspackPlugin.ts | 1 + .../rspack/src/builtin-plugin/IgnorePlugin.ts | 1 + .../builtin-plugin/InferAsyncModulesPlugin.ts | 1 + .../builtin-plugin/JavascriptModulesPlugin.ts | 1 + .../builtin-plugin/JsLoaderRspackPlugin.ts | 5 +- .../src/builtin-plugin/JsonModulesPlugin.ts | 1 + .../builtin-plugin/LimitChunkCountPlugin.ts | 1 + .../src/builtin-plugin/MangleExportsPlugin.ts | 1 + .../MergeDuplicateChunksPlugin.ts | 1 + .../builtin-plugin/ModuleChunkFormatPlugin.ts | 1 + .../ModuleConcatenationPlugin.ts | 1 + .../src/builtin-plugin/NamedChunkIdsPlugin.ts | 1 + .../builtin-plugin/NamedModuleIdsPlugin.ts | 1 + .../src/builtin-plugin/NodeTargetPlugin.ts | 1 + .../src/builtin-plugin/ProgressPlugin.ts | 1 + .../src/builtin-plugin/ProvidePlugin.ts | 1 + .../builtin-plugin/RealContentHashPlugin.ts | 1 + .../builtin-plugin/RemoveEmptyChunksPlugin.ts | 1 + .../src/builtin-plugin/RuntimeChunkPlugin.ts | 1 + .../src/builtin-plugin/RuntimePlugin.ts | 1 + .../builtin-plugin/SideEffectsFlagPlugin.ts | 1 + .../src/builtin-plugin/SizeLimitsPlugin.ts | 3 +- .../builtin-plugin/SourceMapDevToolPlugin.ts | 1 + .../src/builtin-plugin/SplitChunksPlugin.ts | 11 +- .../builtin-plugin/SwcCssMinimizerPlugin.ts | 1 + .../builtin-plugin/SwcJsMinimizerPlugin.ts | 1 + .../WarnCaseSensitiveModulesPlugin.ts | 1 + .../builtin-plugin/WebWorkerTemplatePlugin.ts | 1 + .../rspack/src/builtin-plugin/WorkerPlugin.ts | 5 +- packages/rspack/src/builtin-plugin/base.ts | 1 + .../src/builtin-plugin/css-extract/index.ts | 1 + .../src/builtin-plugin/css-extract/loader.ts | 6 +- .../src/builtin-plugin/css-extract/utils.ts | 3 +- packages/rspack/src/builtin-plugin/index.ts | 90 ++-- packages/rspack/src/config/adapter.ts | 89 ++-- packages/rspack/src/config/adapterRuleUse.ts | 6 +- packages/rspack/src/config/defaults.ts | 21 +- packages/rspack/src/config/index.ts | 4 +- packages/rspack/src/config/normalization.ts | 103 ++-- packages/rspack/src/config/zod.ts | 9 +- .../rspack/src/container/ContainerPlugin.ts | 17 +- .../src/container/ContainerReferencePlugin.ts | 9 +- .../src/container/ModuleFederationPlugin.ts | 6 +- .../src/container/ModuleFederationPluginV1.ts | 8 +- .../ModuleFederationRuntimePlugin.ts | 1 + packages/rspack/src/exports.ts | 138 ++--- packages/rspack/src/fileSystem.ts | 4 +- packages/rspack/src/index.ts | 2 +- packages/rspack/src/lib/EntryOptionPlugin.ts | 1 + .../src/lib/NormalModuleReplacementPlugin.ts | 3 +- packages/rspack/src/loader-runner/index.ts | 16 +- .../rspack/src/logging/createConsoleLogger.ts | 18 +- .../rspack/src/node/NodeEnvironmentPlugin.ts | 7 +- .../rspack/src/node/NodeTemplatePlugin.ts | 2 +- .../rspack/src/node/NodeWatchFileSystem.ts | 1 + packages/rspack/src/node/nodeConsole.ts | 7 +- packages/rspack/src/rspack.ts | 26 +- packages/rspack/src/rspackOptionsApply.ts | 78 +-- .../rspack/src/sharing/ConsumeSharedPlugin.ts | 9 +- .../rspack/src/sharing/ProvideSharedPlugin.ts | 7 +- .../rspack/src/sharing/ShareRuntimePlugin.ts | 5 +- .../src/stats/DefaultStatsFactoryPlugin.ts | 42 +- packages/rspack/src/stats/StatsFactory.ts | 7 +- packages/rspack/src/stats/StatsPrinter.ts | 7 +- .../rspack/src/stats/statsFactoryUtils.ts | 10 +- packages/rspack/src/util/comparators.ts | 1 + packages/rspack/src/util/fs.ts | 2 +- packages/rspack/src/util/source.ts | 2 +- pnpm-lock.yaml | 417 +++++++++++++-- scripts/debug/launch.mjs | 3 +- scripts/release/publish.mjs | 3 +- webpack-test/helpers/createFakeWorker.js | 2 +- .../helpers/supportsRequireInModule.js | 2 +- website/components/i18n/index.ts | 2 +- website/rspress.config.ts | 7 +- website/theme/i18n/index.ts | 3 +- x.mjs | 10 +- 208 files changed, 1522 insertions(+), 1013 deletions(-) create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore index df1b16d3c74b..d33b1da22b85 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,12 @@ **/tests **/fixtures +**/dist crates/rspack_plugin_css/webpack_css_cases_to_be_migrated crates/rspack_plugin_mf +crates/rspack_plugin_extract_css/src/runtime +packages/rspack/compiled +packages/rspack-dev-server/client +packages/rspack-plugin-react-refresh/client packages/playground packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts packages/rspack-test-tools/template @@ -13,3 +18,5 @@ diffcases scripts/test/diff.cjs scripts/test/binary-path.cjs plugin-test +benchcases +scripts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e829333ae5f..082edd6730d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - uses: dorny/paths-filter@v3 id: filter with: - predicate-quantifier: 'every' + predicate-quantifier: "every" filters: | changed: - "!**/*.md" @@ -176,6 +176,10 @@ jobs: if: steps.changes.outputs.src == 'true' run: pnpm run lint:js + - name: Eslint + if: steps.changes.outputs.src == 'true' + run: pnpm run eslint:js + - name: Prettier if: steps.changes.outputs.src == 'true' run: pnpm run format-ci:js @@ -357,14 +361,7 @@ jobs: failure_notification: name: Failure Notification needs: - [ - test-linux, - test-windows, - test-mac, - rust_check, - rust_test, - run_benchmark - ] + [test-linux, test-windows, test-mac, rust_check, rust_test, run_benchmark] if: ${{ failure() && !cancelled() && github.ref_name == 'main' && github.repository_owner == 'web-infra-dev' }} runs-on: ubuntu-latest steps: diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000000..8608a3653e0c --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,36 @@ +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +import tsParser from "@typescript-eslint/parser"; +import oxlint from "eslint-plugin-oxlint"; +import simpleImportSort from "eslint-plugin-simple-import-sort"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const ignores = readFileSync(path.resolve(__dirname, ".eslintignore"), "utf-8") + .split(/\r?\n/) + .filter(item => { + return !item.startsWith("#") && !item.startsWith("//") && item.trim(); + }); + +export default [ + { + files: ["**/*.ts", "**/*.mts", "**/*.cts"], + languageOptions: { + parser: tsParser + } + }, + { + plugins: { + "simple-import-sort": simpleImportSort + }, + rules: { + "simple-import-sort/imports": "error", + "simple-import-sort/exports": "error" + } + }, + oxlint.configs["flat/recommended"], // oxlint should be the last one + { + ignores + } +]; diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index 917f1beb2ed6..e54bd75f98d5 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -4,6 +4,7 @@ export default { "*.toml": "npx @taplo/cli format", "*.{ts,js,cts,cjs,mts,mjs}": () => [ "pnpm run lint:js", + "pnpm eslint --report-unused-disable-directives-severity off --cache --fix", "pnpm run api-extractor:ci" ] }; diff --git a/package.json b/package.json index 935c6a32b81c..ac70a630b9ad 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "format-ci:toml": "npx @taplo/cli format --check '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'", "format:toml": "npx @taplo/cli format '.cargo/*.toml' './crates/**/Cargo.toml' './Cargo.toml'", "lint:js": "oxlint --deny-warnings -c .eslintrc.json", + "eslint:js": "eslint --report-unused-disable-directives-severity off --cache", "lint:rs": "node ./scripts/check_rust_dependency.cjs", "build:binding:debug": "pnpm --filter @rspack/binding run build:debug", "build:binding:release": "pnpm --filter @rspack/binding run build:release", @@ -57,8 +58,12 @@ "@types/jest": "29.5.12", "@types/node": "20.12.7", "@types/rimraf": "3.0.2", + "@typescript-eslint/parser": "^7.9.0", "commander": "12.0.0", "cross-env": "^7.0.3", + "eslint": "^9.2.0", + "eslint-plugin-oxlint": "^0.2.9", + "eslint-plugin-simple-import-sort": "^12.1.0", "filenamify": "^4.3.0", "husky": "^9.0.0", "is-ci": "3.0.1", @@ -66,7 +71,7 @@ "jest-environment-node": "29.7.0", "lint-staged": "^15.0.0", "npm-run-all": "4.1.5", - "oxlint": "0.2.16", + "oxlint": "0.3.4", "prettier": "3.2.5", "prettier-2": "npm:prettier@2.8.8", "rimraf": "3.0.2", diff --git a/packages/create-rspack/template-vue/src/main.js b/packages/create-rspack/template-vue/src/main.js index 3c9bfeb788cc..dc42bbf15d19 100644 --- a/packages/create-rspack/template-vue/src/main.js +++ b/packages/create-rspack/template-vue/src/main.js @@ -1,5 +1,7 @@ -import { createApp } from "vue"; import "./style.css"; + +import { createApp } from "vue"; + import App from "./App.vue"; createApp(App).mount("#app"); diff --git a/packages/rspack-cli/src/commands/build.ts b/packages/rspack-cli/src/commands/build.ts index 4d063c18b90d..e476c8cf645d 100644 --- a/packages/rspack-cli/src/commands/build.ts +++ b/packages/rspack-cli/src/commands/build.ts @@ -1,4 +1,6 @@ +import { MultiStats, Stats } from "@rspack/core"; import * as fs from "fs"; + import type { RspackCLI } from "../rspack-cli"; import { RspackCommand } from "../types"; import { @@ -6,7 +8,6 @@ import { ensureEnvObject, setBuiltinEnvArg } from "../utils/options"; -import { MultiStats, Stats } from "@rspack/core"; export class BuildCommand implements RspackCommand { async apply(cli: RspackCLI): Promise { diff --git a/packages/rspack-cli/src/commands/preview.ts b/packages/rspack-cli/src/commands/preview.ts index 3875a61d4e57..9d391faf71b8 100644 --- a/packages/rspack-cli/src/commands/preview.ts +++ b/packages/rspack-cli/src/commands/preview.ts @@ -1,14 +1,15 @@ -import type { RspackCLI } from "../rspack-cli"; -import { RspackCommand, RspackPreviewCLIOptions } from "../types"; -import { previewOptions } from "../utils/options"; import { DevServer, + MultiRspackOptions, rspack, - RspackOptions, - MultiRspackOptions + RspackOptions } from "@rspack/core"; import path from "path"; +import type { RspackCLI } from "../rspack-cli"; +import { RspackCommand, RspackPreviewCLIOptions } from "../types"; +import { previewOptions } from "../utils/options"; + const defaultRoot = "dist"; export class PreviewCommand implements RspackCommand { async apply(cli: RspackCLI): Promise { diff --git a/packages/rspack-cli/src/commands/serve.ts b/packages/rspack-cli/src/commands/serve.ts index 2be261b542fc..88b8ab6cf73d 100644 --- a/packages/rspack-cli/src/commands/serve.ts +++ b/packages/rspack-cli/src/commands/serve.ts @@ -1,12 +1,13 @@ -import type { RspackCLI } from "../rspack-cli"; +import { Compiler, DevServer } from "@rspack/core"; import type { RspackDevServer as RspackDevServerType } from "@rspack/dev-server"; + +import type { RspackCLI } from "../rspack-cli"; import { RspackCommand } from "../types"; import { commonOptions, ensureEnvObject, setBuiltinEnvArg } from "../utils/options"; -import { Compiler, DevServer } from "@rspack/core"; export class ServeCommand implements RspackCommand { async apply(cli: RspackCLI): Promise { diff --git a/packages/rspack-cli/src/index.ts b/packages/rspack-cli/src/index.ts index 64d35df36e0e..8d453527c9d3 100644 --- a/packages/rspack-cli/src/index.ts +++ b/packages/rspack-cli/src/index.ts @@ -1,2 +1,2 @@ +export { defineConfig, definePlugin, RspackCLI } from "./rspack-cli"; export * from "./types"; -export { RspackCLI, defineConfig, definePlugin } from "./rspack-cli"; diff --git a/packages/rspack-cli/src/rspack-cli.ts b/packages/rspack-cli/src/rspack-cli.ts index 386c3791287b..2f7421bda9a1 100644 --- a/packages/rspack-cli/src/rspack-cli.ts +++ b/packages/rspack-cli/src/rspack-cli.ts @@ -1,31 +1,32 @@ +import type { RspackPluginFunction, RspackPluginInstance } from "@rspack/core"; +import { + Compiler, + MultiCompiler, + MultiRspackOptions, + MultiStats, + rspack, + RspackOptions, + Stats +} from "@rspack/core"; +import * as rspackCore from "@rspack/core"; +import path from "path"; import semver from "semver"; -import { hideBin } from "yargs/helpers"; -import yargs from "yargs"; import util from "util"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; + +import { BuildCommand } from "./commands/build"; +import { PreviewCommand } from "./commands/preview"; +import { ServeCommand } from "./commands/serve"; import { RspackBuildCLIOptions, RspackCLIColors, RspackCLILogger, RspackCLIOptions } from "./types"; -import { BuildCommand } from "./commands/build"; -import { ServeCommand } from "./commands/serve"; -import { PreviewCommand } from "./commands/preview"; -import { - RspackOptions, - MultiCompiler, - rspack, - MultiRspackOptions, - Stats, - MultiStats, - Compiler -} from "@rspack/core"; -import { normalizeEnv } from "./utils/options"; -import { LoadedRspackConfig, loadRspackConfig } from "./utils/loadConfig"; import findConfig from "./utils/findConfig"; -import type { RspackPluginInstance, RspackPluginFunction } from "@rspack/core"; -import * as rspackCore from "@rspack/core"; -import path from "path"; +import { LoadedRspackConfig, loadRspackConfig } from "./utils/loadConfig"; +import { normalizeEnv } from "./utils/options"; type Command = "serve" | "build"; diff --git a/packages/rspack-cli/src/types.ts b/packages/rspack-cli/src/types.ts index b9466ad44c5a..3e632201828f 100644 --- a/packages/rspack-cli/src/types.ts +++ b/packages/rspack-cli/src/types.ts @@ -1,6 +1,7 @@ +import type { DevServer } from "@rspack/core"; import { Colorette } from "colorette"; + import { RspackCLI } from "./rspack-cli"; -import type { DevServer } from "@rspack/core"; export type { Configuration } from "@rspack/core"; export interface IRspackCLI { diff --git a/packages/rspack-cli/src/utils/crossImport.ts b/packages/rspack-cli/src/utils/crossImport.ts index dcd63b72766e..7b9b00519375 100644 --- a/packages/rspack-cli/src/utils/crossImport.ts +++ b/packages/rspack-cli/src/utils/crossImport.ts @@ -1,4 +1,5 @@ import { pathToFileURL } from "url"; + import isEsmFile from "./isEsmFile"; /** diff --git a/packages/rspack-cli/src/utils/findConfig.ts b/packages/rspack-cli/src/utils/findConfig.ts index 8866722d1469..d89a808d935f 100644 --- a/packages/rspack-cli/src/utils/findConfig.ts +++ b/packages/rspack-cli/src/utils/findConfig.ts @@ -1,4 +1,5 @@ import fs from "fs"; + import { DEFAULT_EXTENSIONS } from "../constants"; /** diff --git a/packages/rspack-cli/src/utils/isEsmFile.ts b/packages/rspack-cli/src/utils/isEsmFile.ts index 029f7dea34c2..600b9d8107b2 100644 --- a/packages/rspack-cli/src/utils/isEsmFile.ts +++ b/packages/rspack-cli/src/utils/isEsmFile.ts @@ -1,4 +1,5 @@ import path from "path"; + import readPackageUp from "./readPackageUp"; const isEsmFile = (filePath: string, cwd = process.cwd()) => { diff --git a/packages/rspack-cli/src/utils/loadConfig.ts b/packages/rspack-cli/src/utils/loadConfig.ts index c2331767e7b7..d217b9dc9370 100644 --- a/packages/rspack-cli/src/utils/loadConfig.ts +++ b/packages/rspack-cli/src/utils/loadConfig.ts @@ -1,13 +1,14 @@ -import path from "path"; +import { MultiRspackOptions, RspackOptions } from "@rspack/core"; import fs from "fs"; +import interpret from "interpret"; +import path from "path"; +import rechoir from "rechoir"; + import { RspackCLIOptions } from "../types"; -import { RspackOptions, MultiRspackOptions } from "@rspack/core"; +import crossImport from "./crossImport"; import findConfig from "./findConfig"; -import rechoir from "rechoir"; -import interpret from "interpret"; import isEsmFile from "./isEsmFile"; import isTsFile from "./isTsFile"; -import crossImport from "./crossImport"; interface RechoirError extends Error { failures: RechoirError[]; diff --git a/packages/rspack-cli/src/utils/profile.ts b/packages/rspack-cli/src/utils/profile.ts index de3d1fe949df..96558aa422ad 100644 --- a/packages/rspack-cli/src/utils/profile.ts +++ b/packages/rspack-cli/src/utils/profile.ts @@ -31,16 +31,16 @@ The full syntax, remember update this when you change something in this file. */ -import inspector from "inspector"; -import fs from "fs"; -import path from "path"; -import { URLSearchParams } from "url"; import { - experimental_registerGlobalTrace as registerGlobalTrace, + type Compiler, experimental_cleanupGlobalTrace as cleanupGlobalTrace, - RspackOptions, - type Compiler + experimental_registerGlobalTrace as registerGlobalTrace, + RspackOptions } from "@rspack/core"; +import fs from "fs"; +import inspector from "inspector"; +import path from "path"; +import { URLSearchParams } from "url"; type JSCPUProfileOptionsOutput = string; type JSCPUProfileOptions = { diff --git a/packages/rspack-dev-server/src/config.ts b/packages/rspack-dev-server/src/config.ts index 4229962d6838..779d65e58b6c 100644 --- a/packages/rspack-dev-server/src/config.ts +++ b/packages/rspack-dev-server/src/config.ts @@ -1,5 +1,5 @@ -import WebpackDevServer from "webpack-dev-server"; import type { DevServer } from "@rspack/core"; +import WebpackDevServer from "webpack-dev-server"; export type { DevServer }; diff --git a/packages/rspack-dev-server/src/middleware.ts b/packages/rspack-dev-server/src/middleware.ts index b1d236701459..62d3a52410e2 100644 --- a/packages/rspack-dev-server/src/middleware.ts +++ b/packages/rspack-dev-server/src/middleware.ts @@ -1,11 +1,11 @@ -import { extname } from "path"; -import type { IncomingMessage } from "http"; import type { Compiler } from "@rspack/core"; -import wdm from "webpack-dev-middleware"; +import crypto from "crypto"; import type { RequestHandler, Response } from "express"; +import type { IncomingMessage } from "http"; import mime from "mime-types"; +import { extname } from "path"; import { parse } from "url"; -import crypto from "crypto"; +import wdm from "webpack-dev-middleware"; function etag(buf: any) { const hash = crypto.createHash("sha256").update(buf).digest("hex"); diff --git a/packages/rspack-dev-server/src/server.ts b/packages/rspack-dev-server/src/server.ts index 80de20e2ea23..e222fa9e3578 100644 --- a/packages/rspack-dev-server/src/server.ts +++ b/packages/rspack-dev-server/src/server.ts @@ -8,14 +8,16 @@ * https://github.com/webpack/webpack-dev-server/blob/b0f15ace0123c125d5870609ef4691c141a6d187/LICENSE */ import path from "node:path"; + import { Compiler, MultiCompiler } from "@rspack/core"; -import type { Socket } from "net"; import type { FSWatcher } from "chokidar"; -import rdm from "webpack-dev-middleware"; -import type { Server } from "http"; import fs from "fs"; +import type { Server } from "http"; +import type { Socket } from "net"; +import rdm from "webpack-dev-middleware"; import WebpackDevServer from "webpack-dev-server"; -import type { ResolvedDevServer, DevServer } from "./config"; + +import type { DevServer, ResolvedDevServer } from "./config"; import { applyDevServerPatch } from "./patch"; applyDevServerPatch(); diff --git a/packages/rspack-plugin-react-refresh/src/index.ts b/packages/rspack-plugin-react-refresh/src/index.ts index 45811aaf6bfd..be534e3c414d 100644 --- a/packages/rspack-plugin-react-refresh/src/index.ts +++ b/packages/rspack-plugin-react-refresh/src/index.ts @@ -1,5 +1,6 @@ -import path from "path"; import type { Compiler } from "@rspack/core"; +import path from "path"; + import { normalizeOptions, type PluginOptions } from "./options"; export type { PluginOptions }; diff --git a/packages/rspack-test-tools/jest.d.ts b/packages/rspack-test-tools/jest.d.ts index ed02cd195f82..661aaf27828a 100644 --- a/packages/rspack-test-tools/jest.d.ts +++ b/packages/rspack-test-tools/jest.d.ts @@ -8,7 +8,6 @@ declare interface FileMatcherOptions { declare global { namespace jest { - // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Matchers { toMatchFileSnapshot: ( filename?: string, diff --git a/packages/rspack-test-tools/src/case/builtin.ts b/packages/rspack-test-tools/src/case/builtin.ts index 029230c6fb69..bdf9cf2c0dfb 100644 --- a/packages/rspack-test-tools/src/case/builtin.ts +++ b/packages/rspack-test-tools/src/case/builtin.ts @@ -1,9 +1,10 @@ +import path from "path"; + import { IRspackBuiltinProcessorOptions, RspackBuiltinProcessor } from "../processor"; import { BasicCaseCreator } from "../test/creator"; -import path from "path"; const FILTERS: Record< string, diff --git a/packages/rspack-test-tools/src/case/compiler.ts b/packages/rspack-test-tools/src/case/compiler.ts index 29c4268f6e51..2a80419cd997 100644 --- a/packages/rspack-test-tools/src/case/compiler.ts +++ b/packages/rspack-test-tools/src/case/compiler.ts @@ -1,6 +1,6 @@ -import { ECompilerType } from "../type"; import { ISimpleProcessorOptions, SimpleTaskProcessor } from "../processor"; import { getSimpleProcessorRunner } from "../test/simple"; +import { ECompilerType } from "../type"; export type TCompilerCaseConfig = Omit< ISimpleProcessorOptions, diff --git a/packages/rspack-test-tools/src/case/defaults.ts b/packages/rspack-test-tools/src/case/defaults.ts index b24ce4179292..6920e40eaf61 100644 --- a/packages/rspack-test-tools/src/case/defaults.ts +++ b/packages/rspack-test-tools/src/case/defaults.ts @@ -1,10 +1,11 @@ -import { TestContext } from "../test/context"; import path from "path"; -import { ITestEnv, ITestProcessor } from "../type"; + import { DefaultsConfigTaskProcessor, IDefaultsConfigProcessorOptions } from "../processor"; +import { TestContext } from "../test/context"; +import { ITestEnv, ITestProcessor } from "../type"; export type TDefaultsCaseConfig = Omit< IDefaultsConfigProcessorOptions, diff --git a/packages/rspack-test-tools/src/case/diff.ts b/packages/rspack-test-tools/src/case/diff.ts index e784ac59eb66..6b19eb12e574 100644 --- a/packages/rspack-test-tools/src/case/diff.ts +++ b/packages/rspack-test-tools/src/case/diff.ts @@ -1,10 +1,11 @@ -import path from "path"; import fs from "fs-extra"; +import path from "path"; import rimraf from "rimraf"; + import createLazyTestEnv from "../helper/legacy/createLazyTestEnv"; import { DiffProcessor, IDiffProcessorOptions } from "../processor"; -import { ECompareResultType, TModuleCompareResult } from "../type"; import { Tester } from "../test/tester"; +import { ECompareResultType, TModuleCompareResult } from "../type"; const DEFAULT_CASE_CONFIG: Partial = { webpackPath: require.resolve("webpack"), diff --git a/packages/rspack-test-tools/src/case/error.ts b/packages/rspack-test-tools/src/case/error.ts index acdcfdf0fbff..f4f11bb37423 100644 --- a/packages/rspack-test-tools/src/case/error.ts +++ b/packages/rspack-test-tools/src/case/error.ts @@ -1,6 +1,6 @@ -import { ECompilerType } from "../type"; -import { getSimpleProcessorRunner } from "../test/simple"; import { ErrorTaskProcessor, IErrorTaskProcessorOptions } from "../processor"; +import { getSimpleProcessorRunner } from "../test/simple"; +import { ECompilerType } from "../type"; let addedSerializer = false; diff --git a/packages/rspack-test-tools/src/case/hash.ts b/packages/rspack-test-tools/src/case/hash.ts index 7f4ec5d36786..fefa114bdfc7 100644 --- a/packages/rspack-test-tools/src/case/hash.ts +++ b/packages/rspack-test-tools/src/case/hash.ts @@ -1,6 +1,6 @@ -import { ECompilerType, ITester, TTestConfig } from "../type"; import { RspackHashProcessor } from "../processor"; import { BasicCaseCreator } from "../test/creator"; +import { ECompilerType, ITester, TTestConfig } from "../type"; class HashCaseCreator extends BasicCaseCreator { protected describe( name: string, diff --git a/packages/rspack-test-tools/src/case/hook.ts b/packages/rspack-test-tools/src/case/hook.ts index d06d989d8aee..296c1bedd195 100644 --- a/packages/rspack-test-tools/src/case/hook.ts +++ b/packages/rspack-test-tools/src/case/hook.ts @@ -1,13 +1,14 @@ import path from "path"; -import { getSimpleProcessorRunner } from "../test/simple"; + +import createLazyTestEnv from "../helper/legacy/createLazyTestEnv"; import { HookCasesContext, HookTaskProcessor, IHookProcessorOptions } from "../processor"; import { BasicRunnerFactory } from "../runner"; +import { getSimpleProcessorRunner } from "../test/simple"; import { ECompilerType } from "../type"; -import createLazyTestEnv from "../helper/legacy/createLazyTestEnv"; export type THookCaseConfig = Omit< IHookProcessorOptions, diff --git a/packages/rspack-test-tools/src/case/hot-step.ts b/packages/rspack-test-tools/src/case/hot-step.ts index 5c86e5269fd7..680cc6fdd4c9 100644 --- a/packages/rspack-test-tools/src/case/hot-step.ts +++ b/packages/rspack-test-tools/src/case/hot-step.ts @@ -1,7 +1,7 @@ import { RspackHotStepProcessor } from "../processor/hot-step"; -import { ECompilerType, TCompilerOptions } from "../type"; -import { BasicCaseCreator } from "../test/creator"; import { HotStepRunnerFactory } from "../runner"; +import { BasicCaseCreator } from "../test/creator"; +import { ECompilerType, TCompilerOptions } from "../type"; type TTarget = TCompilerOptions["target"]; diff --git a/packages/rspack-test-tools/src/case/hot.ts b/packages/rspack-test-tools/src/case/hot.ts index 8e55e748a9e5..9466253c1327 100644 --- a/packages/rspack-test-tools/src/case/hot.ts +++ b/packages/rspack-test-tools/src/case/hot.ts @@ -1,7 +1,7 @@ import { RspackHotProcessor } from "../processor/hot"; -import { ECompilerType, TCompilerOptions } from "../type"; -import { BasicCaseCreator } from "../test/creator"; import { HotRunnerFactory } from "../runner"; +import { BasicCaseCreator } from "../test/creator"; +import { ECompilerType, TCompilerOptions } from "../type"; type TTarget = TCompilerOptions["target"]; diff --git a/packages/rspack-test-tools/src/case/index.ts b/packages/rspack-test-tools/src/case/index.ts index 07625264bf02..61400941f61d 100644 --- a/packages/rspack-test-tools/src/case/index.ts +++ b/packages/rspack-test-tools/src/case/index.ts @@ -1,16 +1,16 @@ +export * from "./builtin"; +export * from "./compiler"; export * from "./config"; +export * from "./defaults"; export * from "./diagnostic"; export * from "./diff"; +export * from "./error"; export * from "./hash"; +export * from "./hook"; export * from "./hot"; +export * from "./hot-step"; export * from "./normal"; +export * from "./stats-api"; export * from "./stats-output"; -export * from "./watch"; export * from "./treeshaking"; -export * from "./defaults"; -export * from "./builtin"; -export * from "./hot-step"; -export * from "./compiler"; -export * from "./stats-api"; -export * from "./error"; -export * from "./hook"; +export * from "./watch"; diff --git a/packages/rspack-test-tools/src/case/normal.ts b/packages/rspack-test-tools/src/case/normal.ts index 0f5a80df82b9..7f1155513ff0 100644 --- a/packages/rspack-test-tools/src/case/normal.ts +++ b/packages/rspack-test-tools/src/case/normal.ts @@ -1,7 +1,8 @@ import path from "path"; + import { RspackNormalProcessor } from "../processor/normal"; -import { BasicCaseCreator } from "../test/creator"; import { NormalRunnerFactory } from "../runner"; +import { BasicCaseCreator } from "../test/creator"; const creator = new BasicCaseCreator({ clean: true, diff --git a/packages/rspack-test-tools/src/case/stats-api.ts b/packages/rspack-test-tools/src/case/stats-api.ts index ddcf6b84c646..83ef28f4aec7 100644 --- a/packages/rspack-test-tools/src/case/stats-api.ts +++ b/packages/rspack-test-tools/src/case/stats-api.ts @@ -1,9 +1,9 @@ -import { ECompilerType } from "../type"; -import { getSimpleProcessorRunner } from "../test/simple"; import { IStatsAPITaskProcessorOptions, StatsAPITaskProcessor } from "../processor"; +import { getSimpleProcessorRunner } from "../test/simple"; +import { ECompilerType } from "../type"; let addedSerializer = false; diff --git a/packages/rspack-test-tools/src/case/watch.ts b/packages/rspack-test-tools/src/case/watch.ts index b11f6b942b2c..6a8208e97610 100644 --- a/packages/rspack-test-tools/src/case/watch.ts +++ b/packages/rspack-test-tools/src/case/watch.ts @@ -1,11 +1,12 @@ import fs from "fs"; import path from "path"; + import { RspackWatchProcessor, RspackWatchStepProcessor } from "../processor/watch"; -import { BasicCaseCreator } from "../test/creator"; import { WatchRunnerFactory } from "../runner"; +import { BasicCaseCreator } from "../test/creator"; const creator = new BasicCaseCreator({ clean: true, diff --git a/packages/rspack-test-tools/src/compare/comparator.ts b/packages/rspack-test-tools/src/compare/comparator.ts index b8b103fab31e..094fa723fa85 100644 --- a/packages/rspack-test-tools/src/compare/comparator.ts +++ b/packages/rspack-test-tools/src/compare/comparator.ts @@ -1,9 +1,10 @@ +import deepmerge from "deepmerge"; +import path from "path"; + import { ITestReporter, TCompareModules } from "../type"; -import { IFormatCodeOptions } from "./format-code"; import { compareFile } from "./compare"; +import { IFormatCodeOptions } from "./format-code"; import { replaceRuntimeModuleName } from "./replace-runtime-module-name"; -import path from "path"; -import deepmerge from "deepmerge"; export interface IDiffComparatorOptions { rspackDist: string; diff --git a/packages/rspack-test-tools/src/compare/compare.ts b/packages/rspack-test-tools/src/compare/compare.ts index dc00b4342d8f..86b8cc6a9e4c 100644 --- a/packages/rspack-test-tools/src/compare/compare.ts +++ b/packages/rspack-test-tools/src/compare/compare.ts @@ -1,8 +1,7 @@ +import fs from "fs-extra"; import { diffLinesRaw, diffStringsUnified } from "jest-diff"; -import { IFormatCodeOptions, formatCode } from "./format-code"; -import { replaceRuntimeModuleName } from "./replace-runtime-module-name"; + import { parseModules } from "../helper"; -import fs from "fs-extra"; import { ECompareResultType, TCompareModules, @@ -10,6 +9,8 @@ import { TFileCompareResult, TModuleCompareResult } from "../type"; +import { formatCode, IFormatCodeOptions } from "./format-code"; +import { replaceRuntimeModuleName } from "./replace-runtime-module-name"; export interface ICompareOptions { modules?: TCompareModules; diff --git a/packages/rspack-test-tools/src/compare/format-code.ts b/packages/rspack-test-tools/src/compare/format-code.ts index 64822995a06b..aedb949b0f71 100644 --- a/packages/rspack-test-tools/src/compare/format-code.ts +++ b/packages/rspack-test-tools/src/compare/format-code.ts @@ -1,7 +1,8 @@ -import { parse } from "@babel/parser"; import generate from "@babel/generator"; +import { parse } from "@babel/parser"; import traverse, { NodePath } from "@babel/traverse"; import * as T from "@babel/types"; + import { replaceModuleArgument } from "./replace-module-argument"; export interface IFormatCodeOptions { diff --git a/packages/rspack-test-tools/src/compare/index.ts b/packages/rspack-test-tools/src/compare/index.ts index 1d6b984e68ab..16f349af196a 100644 --- a/packages/rspack-test-tools/src/compare/index.ts +++ b/packages/rspack-test-tools/src/compare/index.ts @@ -1,5 +1,5 @@ +export * from "./comparator"; +export * from "./compare"; +export * from "./format-code"; export * from "./replace-module-argument"; export * from "./replace-runtime-module-name"; -export * from "./format-code"; -export * from "./compare"; -export * from "./comparator"; diff --git a/packages/rspack-test-tools/src/compiler.ts b/packages/rspack-test-tools/src/compiler.ts index 6d1a3e0f20ab..4cccd33ed202 100644 --- a/packages/rspack-test-tools/src/compiler.ts +++ b/packages/rspack-test-tools/src/compiler.ts @@ -1,4 +1,6 @@ import EventEmitter from "events"; +import merge from "webpack-merge"; + import { ECompilerType, ITestCompilerManager, @@ -7,7 +9,6 @@ import { TCompilerOptions, TCompilerStats } from "./type"; -import merge from "webpack-merge"; export const enum ECompilerEvent { Build = "build", diff --git a/packages/rspack-test-tools/src/helper/directory.ts b/packages/rspack-test-tools/src/helper/directory.ts index a616861ced35..b0f37248d4d0 100644 --- a/packages/rspack-test-tools/src/helper/directory.ts +++ b/packages/rspack-test-tools/src/helper/directory.ts @@ -1,5 +1,6 @@ import fs from "fs"; import path from "path"; + import { escapeSep } from "."; export const isDirectory = (p: string) => fs.lstatSync(p).isDirectory(); diff --git a/packages/rspack-test-tools/src/helper/index.ts b/packages/rspack-test-tools/src/helper/index.ts index 31c86ee38217..480f957642df 100644 --- a/packages/rspack-test-tools/src/helper/index.ts +++ b/packages/rspack-test-tools/src/helper/index.ts @@ -1,4 +1,4 @@ -export * from "./read-config-file"; -export * from "./parse-modules"; export * from "./directory"; +export * from "./parse-modules"; +export * from "./read-config-file"; export * from "./win"; diff --git a/packages/rspack-test-tools/src/helper/legacy/createFakeWorker.js b/packages/rspack-test-tools/src/helper/legacy/createFakeWorker.js index 511ab572c095..17c4507d7d9e 100644 --- a/packages/rspack-test-tools/src/helper/legacy/createFakeWorker.js +++ b/packages/rspack-test-tools/src/helper/legacy/createFakeWorker.js @@ -61,7 +61,6 @@ self.postMessage = data => { }; require(${JSON.stringify(path.resolve(outputDirectory, file))}); `; - // eslint-disable-next-line n/no-unsupported-features/node-builtins this.worker = new (require("worker_threads").Worker)(workerBootstrap, { eval: true }); diff --git a/packages/rspack-test-tools/src/helper/read-config-file.ts b/packages/rspack-test-tools/src/helper/read-config-file.ts index c003bcd18a86..678db88b6a19 100644 --- a/packages/rspack-test-tools/src/helper/read-config-file.ts +++ b/packages/rspack-test-tools/src/helper/read-config-file.ts @@ -1,6 +1,7 @@ -import { ECompilerType, TCompilerOptions } from "../type"; import fs from "fs-extra"; +import { ECompilerType, TCompilerOptions } from "../type"; + export function readConfigFile( files: string[] ): TCompilerOptions[] { diff --git a/packages/rspack-test-tools/src/index.ts b/packages/rspack-test-tools/src/index.ts index fa3f76eb5755..1494bc9852d0 100644 --- a/packages/rspack-test-tools/src/index.ts +++ b/packages/rspack-test-tools/src/index.ts @@ -1,11 +1,11 @@ -export * from "./type"; -export * from "./test/tester"; -export * from "./test/context"; -export * from "./test/simple"; -export * from "./processor"; -export * from "./reporter"; +export * from "./case"; export * from "./compare"; -export * from "./plugin"; export * from "./helper"; +export * from "./plugin"; +export * from "./processor"; +export * from "./reporter"; export * from "./runner"; -export * from "./case"; +export * from "./test/context"; +export * from "./test/simple"; +export * from "./test/tester"; +export * from "./type"; diff --git a/packages/rspack-test-tools/src/plugin/webpack-diff-config-plugin.ts b/packages/rspack-test-tools/src/plugin/webpack-diff-config-plugin.ts index 2a0133b48cb0..fafb9db5f92d 100644 --- a/packages/rspack-test-tools/src/plugin/webpack-diff-config-plugin.ts +++ b/packages/rspack-test-tools/src/plugin/webpack-diff-config-plugin.ts @@ -1,4 +1,5 @@ import { Compiler, WebpackOptionsNormalized } from "webpack"; + import { WebpackModulePlaceholderPlugin } from "./webpack-module-placeholder-plugin"; const PLUGIN_NAME = "WebpackDiffConfigPlugin"; diff --git a/packages/rspack-test-tools/src/processor/basic.ts b/packages/rspack-test-tools/src/processor/basic.ts index 6899385648ed..bcf54976203a 100644 --- a/packages/rspack-test-tools/src/processor/basic.ts +++ b/packages/rspack-test-tools/src/processor/basic.ts @@ -1,3 +1,6 @@ +import fs from "fs"; +import path from "path"; + import { readConfigFile } from "../helper"; import checkArrayExpectation from "../helper/legacy/checkArrayExpectation"; import { @@ -8,8 +11,6 @@ import { ITestRunner, TCompilerOptions } from "../type"; -import fs from "fs"; -import path from "path"; export interface IBasicProcessorOptions< T extends ECompilerType = ECompilerType.Rspack diff --git a/packages/rspack-test-tools/src/processor/builtin.ts b/packages/rspack-test-tools/src/processor/builtin.ts index 21a9f6822cea..cc642bc24a67 100644 --- a/packages/rspack-test-tools/src/processor/builtin.ts +++ b/packages/rspack-test-tools/src/processor/builtin.ts @@ -1,7 +1,8 @@ -import { ECompilerType, ITestContext, TCompilerOptions } from "../type"; +import { rspack } from "@rspack/core"; import fs from "fs-extra"; import { merge } from "webpack-merge"; -import { rspack } from "@rspack/core"; + +import { ECompilerType, ITestContext, TCompilerOptions } from "../type"; import { ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot"; export interface IRspackBuiltinProcessorOptions { diff --git a/packages/rspack-test-tools/src/processor/config.ts b/packages/rspack-test-tools/src/processor/config.ts index a0af127fd44b..1c998b698a93 100644 --- a/packages/rspack-test-tools/src/processor/config.ts +++ b/packages/rspack-test-tools/src/processor/config.ts @@ -1,3 +1,7 @@ +import fs from "fs"; +import path from "path"; + +import { parseResource } from "../helper/legacy/parseResource"; import { ECompilerType, ITestContext, @@ -5,9 +9,6 @@ import { TTestConfig } from "../type"; import { MultiTaskProcessor } from "./multi"; -import path from "path"; -import fs from "fs"; -import { parseResource } from "../helper/legacy/parseResource"; export interface IRspackConfigProcessorOptions { name: string; diff --git a/packages/rspack-test-tools/src/processor/defaults.ts b/packages/rspack-test-tools/src/processor/defaults.ts index f2496b4eaaed..85d2d39916e1 100644 --- a/packages/rspack-test-tools/src/processor/defaults.ts +++ b/packages/rspack-test-tools/src/processor/defaults.ts @@ -1,12 +1,13 @@ -import { SimpleTaskProcessor } from "./simple"; +import { diff as jestDiff } from "jest-diff"; +import stripAnsi from "strip-ansi"; + import { ECompilerType, ITestContext, ITestEnv, TCompilerOptions } from "../type"; -import { diff as jestDiff } from "jest-diff"; -import stripAnsi from "strip-ansi"; +import { SimpleTaskProcessor } from "./simple"; const CURRENT_CWD = process.cwd(); diff --git a/packages/rspack-test-tools/src/processor/diagnostic.ts b/packages/rspack-test-tools/src/processor/diagnostic.ts index 756c8af547d2..3af432e3e990 100644 --- a/packages/rspack-test-tools/src/processor/diagnostic.ts +++ b/packages/rspack-test-tools/src/processor/diagnostic.ts @@ -1,3 +1,8 @@ +import assert from "assert"; +import fs from "fs"; +import path from "path"; + +import { escapeEOL } from "../helper"; import { ECompilerType, ITestContext, @@ -5,10 +10,6 @@ import { TCompilerOptions } from "../type"; import { BasicTaskProcessor } from "./basic"; -import assert from "assert"; -import path from "path"; -import fs from "fs"; -import { escapeEOL } from "../helper"; const serializer = require("jest-serializer-path"); const normalizePaths = serializer.normalizePaths; const rspackPath = path.resolve(__dirname, "../../../rspack"); diff --git a/packages/rspack-test-tools/src/processor/diff.ts b/packages/rspack-test-tools/src/processor/diff.ts index df3530e2ba6c..44ef1b905bc3 100644 --- a/packages/rspack-test-tools/src/processor/diff.ts +++ b/packages/rspack-test-tools/src/processor/diff.ts @@ -1,3 +1,12 @@ +import path from "path"; + +import { readConfigFile } from ".."; +import { + compareFile, + IFormatCodeOptions, + replaceRuntimeModuleName +} from "../compare"; +import { RspackDiffConfigPlugin, WebpackDiffConfigPlugin } from "../plugin"; import { ECompilerType, ITestContext, @@ -8,15 +17,7 @@ import { TFileCompareResult, TModuleCompareResult } from "../type"; -import path from "path"; -import { - IFormatCodeOptions, - compareFile, - replaceRuntimeModuleName -} from "../compare"; -import { RspackDiffConfigPlugin, WebpackDiffConfigPlugin } from "../plugin"; import { BasicTaskProcessor } from "./basic"; -import { readConfigFile } from ".."; export interface IDiffProcessorOptions extends IFormatCodeOptions { webpackPath: string; diff --git a/packages/rspack-test-tools/src/processor/error.ts b/packages/rspack-test-tools/src/processor/error.ts index 9574cb6bdc9d..09ebfc2d744d 100644 --- a/packages/rspack-test-tools/src/processor/error.ts +++ b/packages/rspack-test-tools/src/processor/error.ts @@ -1,4 +1,9 @@ -import { SimpleTaskProcessor } from "./simple"; +import { StatsError, StatsWarnings } from "@rspack/core"; +import fs from "fs"; +import path from "path"; +import prettyFormat from "pretty-format"; +import merge from "webpack-merge"; + import { ECompilerType, ITestContext, @@ -6,11 +11,7 @@ import { TCompiler, TCompilerOptions } from "../type"; -import fs from "fs"; -import path from "path"; -import prettyFormat from "pretty-format"; -import { StatsError, StatsWarnings } from "@rspack/core"; -import merge from "webpack-merge"; +import { SimpleTaskProcessor } from "./simple"; type TStatsDiagnostics = { errors: StatsError[]; diff --git a/packages/rspack-test-tools/src/processor/hook.ts b/packages/rspack-test-tools/src/processor/hook.ts index e1ec1e8730a5..1870c2c307a7 100644 --- a/packages/rspack-test-tools/src/processor/hook.ts +++ b/packages/rspack-test-tools/src/processor/hook.ts @@ -1,4 +1,10 @@ +import { Compilation, Compiler } from "@rspack/core"; +import { getSerializers } from "jest-snapshot"; import path from "path"; +import { format as prettyFormat, PrettyFormatOptions } from "pretty-format"; +import { Source } from "webpack-sources"; + +import { TestContext, TTestContextOptions } from "../test/context"; import { ECompilerType, ITestContext, @@ -6,11 +12,6 @@ import { TCompiler, TCompilerOptions } from "../type"; -import { Source } from "webpack-sources"; -import { Compilation, Compiler } from "@rspack/core"; -import { format as prettyFormat, PrettyFormatOptions } from "pretty-format"; -import { getSerializers } from "jest-snapshot"; -import { TTestContextOptions, TestContext } from "../test/context"; import { ISnapshotProcessorOptions, SnapshotProcessor } from "./snapshot"; const pathSerializer = require("jest-serializer-path"); diff --git a/packages/rspack-test-tools/src/processor/hot-step.ts b/packages/rspack-test-tools/src/processor/hot-step.ts index 9c9f7b22e477..c2b0acb6e346 100644 --- a/packages/rspack-test-tools/src/processor/hot-step.ts +++ b/packages/rspack-test-tools/src/processor/hot-step.ts @@ -1,3 +1,9 @@ +import { StatsCompilation } from "@rspack/core"; +import fs from "fs-extra"; +import path from "path"; + +import { escapeEOL, escapeSep } from "../helper"; +import { THotStepRuntimeData } from "../runner"; import { ECompilerType, ITestContext, @@ -5,16 +11,11 @@ import { TCompilerOptions, TCompilerStats } from "../type"; -import path from "path"; -import { StatsCompilation } from "@rspack/core"; import { IRspackHotProcessorOptions, RspackHotProcessor, TUpdateOptions } from "./hot"; -import fs from "fs-extra"; -import { THotStepRuntimeData } from "../runner"; -import { escapeEOL, escapeSep } from "../helper"; const escapeLocalName = (str: string) => str.split(/[-<>:"/|?*.]/).join("_"); diff --git a/packages/rspack-test-tools/src/processor/hot.ts b/packages/rspack-test-tools/src/processor/hot.ts index e6b1acb85ed5..b8fce316fcc1 100644 --- a/packages/rspack-test-tools/src/processor/hot.ts +++ b/packages/rspack-test-tools/src/processor/hot.ts @@ -1,3 +1,6 @@ +import { rspack } from "@rspack/core"; +import path from "path"; + import { ECompilerType, ITestContext, @@ -6,8 +9,6 @@ import { TCompilerOptions } from "../type"; import { BasicTaskProcessor, IBasicProcessorOptions } from "./basic"; -import path from "path"; -import { rspack } from "@rspack/core"; export interface IRspackHotProcessorOptions { name: string; diff --git a/packages/rspack-test-tools/src/processor/index.ts b/packages/rspack-test-tools/src/processor/index.ts index 65f3ded77ecf..3a5e991531db 100644 --- a/packages/rspack-test-tools/src/processor/index.ts +++ b/packages/rspack-test-tools/src/processor/index.ts @@ -1,17 +1,17 @@ -export * from "./multi"; -export * from "./diff"; export * from "./basic"; +export * from "./builtin"; export * from "./config"; +export * from "./defaults"; export * from "./diagnostic"; -export * from "./hot"; +export * from "./diff"; +export * from "./error"; export * from "./hash"; -export * from "./stats"; -export * from "./watch"; +export * from "./hook"; +export * from "./hot"; +export * from "./hot-step"; +export * from "./multi"; export * from "./simple"; -export * from "./defaults"; -export * from "./stats-api"; export * from "./snapshot"; -export * from "./builtin"; -export * from "./hot-step"; -export * from "./hook"; -export * from "./error"; +export * from "./stats"; +export * from "./stats-api"; +export * from "./watch"; diff --git a/packages/rspack-test-tools/src/processor/multi.ts b/packages/rspack-test-tools/src/processor/multi.ts index 34de601b2268..c7b721cbca31 100644 --- a/packages/rspack-test-tools/src/processor/multi.ts +++ b/packages/rspack-test-tools/src/processor/multi.ts @@ -1,3 +1,5 @@ +import { merge } from "webpack-merge"; + import { readConfigFile } from "../helper"; import { ECompilerType, @@ -7,7 +9,6 @@ import { TCompilerOptions } from "../type"; import { BasicTaskProcessor } from "./basic"; -import { merge } from "webpack-merge"; export interface IMultiTaskProcessorOptions< T extends ECompilerType = ECompilerType.Rspack diff --git a/packages/rspack-test-tools/src/processor/normal.ts b/packages/rspack-test-tools/src/processor/normal.ts index bb3cded0e9da..6eeecfaa8a4d 100644 --- a/packages/rspack-test-tools/src/processor/normal.ts +++ b/packages/rspack-test-tools/src/processor/normal.ts @@ -1,3 +1,6 @@ +import fs from "fs"; +import path from "path"; + import { ECompilerType, ITestContext, @@ -7,8 +10,6 @@ import { TTestConfig } from "../type"; import { BasicTaskProcessor } from "./basic"; -import path from "path"; -import fs from "fs"; export interface IRspackNormalProcessorOptions { name: string; diff --git a/packages/rspack-test-tools/src/processor/snapshot.ts b/packages/rspack-test-tools/src/processor/snapshot.ts index eebaf05006b8..51665df80722 100644 --- a/packages/rspack-test-tools/src/processor/snapshot.ts +++ b/packages/rspack-test-tools/src/processor/snapshot.ts @@ -1,13 +1,14 @@ -import { BasicTaskProcessor, IBasicProcessorOptions } from "./basic"; -import { ECompilerType, ITestContext, ITestEnv } from "../type"; -import path from "path"; -import fs from "fs-extra"; import { type Compiler as RspackCompiler } from "@rspack/core"; +import fs from "fs-extra"; +import path from "path"; import { type Compilation as WebpackCompilation, type Compiler as WebpackCompiler } from "webpack"; + import { escapeEOL } from "../helper"; +import { ECompilerType, ITestContext, ITestEnv } from "../type"; +import { BasicTaskProcessor, IBasicProcessorOptions } from "./basic"; declare var global: { updateSnapshot: boolean; diff --git a/packages/rspack-test-tools/src/processor/stats-api.ts b/packages/rspack-test-tools/src/processor/stats-api.ts index 6091094691e2..80e13cdb7821 100644 --- a/packages/rspack-test-tools/src/processor/stats-api.ts +++ b/packages/rspack-test-tools/src/processor/stats-api.ts @@ -1,4 +1,6 @@ -import { SimpleTaskProcessor } from "./simple"; +import fs from "fs"; +import { createFsFromVolume, Volume } from "memfs"; + import { ECompilerType, ITestContext, @@ -7,8 +9,7 @@ import { TCompilerOptions, TCompilerStats } from "../type"; -import { createFsFromVolume, Volume } from "memfs"; -import fs from "fs"; +import { SimpleTaskProcessor } from "./simple"; const serializer = require("jest-serializer-path"); export interface IStatsAPITaskProcessorOptions { diff --git a/packages/rspack-test-tools/src/processor/stats.ts b/packages/rspack-test-tools/src/processor/stats.ts index 8bc92447178e..57da57de53a9 100644 --- a/packages/rspack-test-tools/src/processor/stats.ts +++ b/packages/rspack-test-tools/src/processor/stats.ts @@ -1,6 +1,11 @@ /* eslint-disable no-control-regex */ import { Compiler, Stats } from "@rspack/core"; +import fs from "fs"; +import path from "path"; + +import { escapeEOL } from "../helper"; +import captureStdio from "../helper/legacy/captureStdio"; import { ECompilerType, ITestContext, @@ -9,10 +14,6 @@ import { TTestConfig } from "../type"; import { MultiTaskProcessor } from "./multi"; -import fs from "fs"; -import path from "path"; -import captureStdio from "../helper/legacy/captureStdio"; -import { escapeEOL } from "../helper"; export interface IRspackStatsProcessorOptions { name: string; diff --git a/packages/rspack-test-tools/src/processor/treeshaking.ts b/packages/rspack-test-tools/src/processor/treeshaking.ts index 4293b72bcab2..c48c105fe7b8 100644 --- a/packages/rspack-test-tools/src/processor/treeshaking.ts +++ b/packages/rspack-test-tools/src/processor/treeshaking.ts @@ -1,6 +1,6 @@ import { ECompilerType, ITestContext, TCompilerOptions } from "../type"; -import { SnapshotProcessor } from "./snapshot"; import { RspackBuiltinProcessor } from "./builtin"; +import { SnapshotProcessor } from "./snapshot"; export interface IRspackTreeShakingProcessorOptions { name: string; diff --git a/packages/rspack-test-tools/src/processor/watch.ts b/packages/rspack-test-tools/src/processor/watch.ts index 72c28ae5330c..46a9302642ee 100644 --- a/packages/rspack-test-tools/src/processor/watch.ts +++ b/packages/rspack-test-tools/src/processor/watch.ts @@ -1,3 +1,8 @@ +import fs from "fs"; +import path from "path"; + +import { ECompilerEvent } from "../compiler"; +import copyDiff from "../helper/legacy/copyDiff"; import { ECompilerType, ITestContext, @@ -7,10 +12,6 @@ import { TTestConfig } from "../type"; import { MultiTaskProcessor } from "./multi"; -import path from "path"; -import fs from "fs"; -import copyDiff from "../helper/legacy/copyDiff"; -import { ECompilerEvent } from "../compiler"; // This file is used to port step number to webpack.config.js const currentWatchStepModulePath = path.resolve( diff --git a/packages/rspack-test-tools/src/reporter/diff-html.ts b/packages/rspack-test-tools/src/reporter/diff-html.ts index 8913332107ea..adc8eab10747 100644 --- a/packages/rspack-test-tools/src/reporter/diff-html.ts +++ b/packages/rspack-test-tools/src/reporter/diff-html.ts @@ -1,11 +1,12 @@ +import fs from "fs-extra"; +import path from "path"; + import { ITestReporter, TDiffStats, TDiffStatsItem, TModuleCompareResult } from "../type"; -import fs from "fs-extra"; -import path from "path"; const VIEWER_DIR = path.join(__dirname, "../../template"); const DIFF_STATS_PLACEHOLDER = "$$RSPACK_DIFF_STATS_PLACEHOLDER$$"; diff --git a/packages/rspack-test-tools/src/reporter/diff-stats.ts b/packages/rspack-test-tools/src/reporter/diff-stats.ts index 198bae5457c9..12664e17668c 100644 --- a/packages/rspack-test-tools/src/reporter/diff-stats.ts +++ b/packages/rspack-test-tools/src/reporter/diff-stats.ts @@ -1,11 +1,12 @@ +import csvToMarkdown from "csv-to-markdown-table"; +import fs from "fs-extra"; + import { ECompareResultType, ECompilerType, ITestReporter, TModuleCompareResult } from "../type"; -import fs from "fs-extra"; -import csvToMarkdown from "csv-to-markdown-table"; export interface IDiffStatsReporterOptions { header?: string[]; diff --git a/packages/rspack-test-tools/src/reporter/index.ts b/packages/rspack-test-tools/src/reporter/index.ts index 5daa95de9cbd..7d9823b58a07 100644 --- a/packages/rspack-test-tools/src/reporter/index.ts +++ b/packages/rspack-test-tools/src/reporter/index.ts @@ -1,2 +1,2 @@ -export * from "./diff-stats"; export * from "./diff-html"; +export * from "./diff-stats"; diff --git a/packages/rspack-test-tools/src/runner/basic.ts b/packages/rspack-test-tools/src/runner/basic.ts index 639e06d7a87e..3a2c78aea2b6 100644 --- a/packages/rspack-test-tools/src/runner/basic.ts +++ b/packages/rspack-test-tools/src/runner/basic.ts @@ -7,8 +7,8 @@ import { TCompilerStatsCompilation, TRunnerFactory } from "../type"; -import { WebRunner } from "./runner/web"; import { EsmRunner } from "./runner/esm"; +import { WebRunner } from "./runner/web"; export class BasicRunnerFactory implements TRunnerFactory diff --git a/packages/rspack-test-tools/src/runner/hot-step.ts b/packages/rspack-test-tools/src/runner/hot-step.ts index 984bed5f9731..b3e42a546aa9 100644 --- a/packages/rspack-test-tools/src/runner/hot-step.ts +++ b/packages/rspack-test-tools/src/runner/hot-step.ts @@ -1,4 +1,5 @@ import { StatsCompilation } from "@rspack/core"; + import { ECompilerType, ITestEnv, diff --git a/packages/rspack-test-tools/src/runner/hot.ts b/packages/rspack-test-tools/src/runner/hot.ts index e80f1c82778a..66ec7f6004b5 100644 --- a/packages/rspack-test-tools/src/runner/hot.ts +++ b/packages/rspack-test-tools/src/runner/hot.ts @@ -1,4 +1,5 @@ import { StatsCompilation } from "@rspack/core"; + import checkArrayExpectation from "../helper/legacy/checkArrayExpectation"; import { ECompilerType, diff --git a/packages/rspack-test-tools/src/runner/index.ts b/packages/rspack-test-tools/src/runner/index.ts index 28b4235edb89..3b1ed25aab9f 100644 --- a/packages/rspack-test-tools/src/runner/index.ts +++ b/packages/rspack-test-tools/src/runner/index.ts @@ -1,7 +1,7 @@ export * from "./basic"; export * from "./hot"; export * from "./hot-step"; +export * from "./multiple"; export * from "./normal"; -export * from "./watch"; export * from "./type"; -export * from "./multiple"; +export * from "./watch"; diff --git a/packages/rspack-test-tools/src/runner/runner/basic.ts b/packages/rspack-test-tools/src/runner/runner/basic.ts index 4d684efce1e6..2503d5aa66ae 100644 --- a/packages/rspack-test-tools/src/runner/runner/basic.ts +++ b/packages/rspack-test-tools/src/runner/runner/basic.ts @@ -1,3 +1,6 @@ +import fs from "fs"; +import path from "path"; + import { ECompilerType, ITestEnv, @@ -6,8 +9,6 @@ import { TCompilerStatsCompilation, TTestConfig } from "../../type"; -import path from "path"; -import fs from "fs"; import { IBasicGlobalContext, IBasicModuleScope, diff --git a/packages/rspack-test-tools/src/runner/runner/cjs.ts b/packages/rspack-test-tools/src/runner/runner/cjs.ts index f67193334233..2a8f16d2b91f 100644 --- a/packages/rspack-test-tools/src/runner/runner/cjs.ts +++ b/packages/rspack-test-tools/src/runner/runner/cjs.ts @@ -1,6 +1,7 @@ -import { ECompilerType } from "../../type"; -import vm from "vm"; import path from "path"; +import vm from "vm"; + +import { ECompilerType } from "../../type"; import { IBasicGlobalContext, IBasicModuleScope, diff --git a/packages/rspack-test-tools/src/runner/runner/esm.ts b/packages/rspack-test-tools/src/runner/runner/esm.ts index d35df9c3df32..0f965b41264f 100644 --- a/packages/rspack-test-tools/src/runner/runner/esm.ts +++ b/packages/rspack-test-tools/src/runner/runner/esm.ts @@ -1,8 +1,9 @@ -import { ECompilerType } from "../../type"; -import vm, { SourceTextModule } from "vm"; import path from "path"; import { fileURLToPath, pathToFileURL } from "url"; +import vm, { SourceTextModule } from "vm"; + import asModule from "../../helper/legacy/asModule"; +import { ECompilerType } from "../../type"; import { EEsmMode, TRunnerRequirer } from "../type"; import { CommonJsRunner } from "./cjs"; diff --git a/packages/rspack-test-tools/src/runner/runner/normal.ts b/packages/rspack-test-tools/src/runner/runner/normal.ts index 32b2cc1c0bd5..6b40c5e8d411 100644 --- a/packages/rspack-test-tools/src/runner/runner/normal.ts +++ b/packages/rspack-test-tools/src/runner/runner/normal.ts @@ -1,7 +1,8 @@ +import { URL } from "url"; + import { ECompilerType } from "../../type"; -import { EsmRunner } from "./esm"; import { IBasicModuleScope, TBasicRunnerFile, TRunnerRequirer } from "../type"; -import { URL } from "url"; +import { EsmRunner } from "./esm"; export class NormalRunner< T extends ECompilerType = ECompilerType.Rspack diff --git a/packages/rspack-test-tools/src/runner/runner/watch.ts b/packages/rspack-test-tools/src/runner/runner/watch.ts index ba9310b7f449..2af8c0b2d6c4 100644 --- a/packages/rspack-test-tools/src/runner/runner/watch.ts +++ b/packages/rspack-test-tools/src/runner/runner/watch.ts @@ -1,8 +1,9 @@ -import { ECompilerType } from "../../type"; -import { IBasicRunnerOptions } from "./basic"; -import { IBasicModuleScope, TBasicRunnerFile, TRunnerRequirer } from "../type"; import path from "path"; + import FakeDocument from "../../helper/legacy/FakeDocument"; +import { ECompilerType } from "../../type"; +import { IBasicModuleScope, TBasicRunnerFile, TRunnerRequirer } from "../type"; +import { IBasicRunnerOptions } from "./basic"; import { CommonJsRunner } from "./cjs"; interface IWatchRunnerOptions diff --git a/packages/rspack-test-tools/src/runner/runner/web/fake.ts b/packages/rspack-test-tools/src/runner/runner/web/fake.ts index 5f98ec8bb5e3..6b7f6011d1f1 100644 --- a/packages/rspack-test-tools/src/runner/runner/web/fake.ts +++ b/packages/rspack-test-tools/src/runner/runner/web/fake.ts @@ -1,13 +1,14 @@ -import { ECompilerType } from "../../../type"; -import { IBasicRunnerOptions } from "../basic"; -import { TBasicRunnerFile, TRunnerRequirer } from "../../type"; -import FakeDocument, { FakeElement } from "../../../helper/legacy/FakeDocument"; -import CurrentScript from "../../../helper/legacy/currentScript"; -import createFakeWorker from "../../../helper/legacy/createFakeWorker"; -import path from "path"; import fs from "fs"; -import urlToRelativePath from "../../../helper/legacy/urlToRelativePath"; +import path from "path"; + +import createFakeWorker from "../../../helper/legacy/createFakeWorker"; +import CurrentScript from "../../../helper/legacy/currentScript"; import EventSource from "../../../helper/legacy/EventSourceForNode"; +import FakeDocument, { FakeElement } from "../../../helper/legacy/FakeDocument"; +import urlToRelativePath from "../../../helper/legacy/urlToRelativePath"; +import { ECompilerType } from "../../../type"; +import { TBasicRunnerFile, TRunnerRequirer } from "../../type"; +import { IBasicRunnerOptions } from "../basic"; import { CommonJsRunner } from "../cjs"; export class FakeDocumentWebRunner< diff --git a/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts b/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts index aa663de2abad..f26c45a7e549 100644 --- a/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts +++ b/packages/rspack-test-tools/src/runner/runner/web/jsdom.ts @@ -1,14 +1,15 @@ -import { ECompilerType } from "../../../type"; -import { IBasicRunnerOptions } from "../basic"; -import { JSDOM, VirtualConsole, ResourceLoader } from "jsdom"; -import { TRunnerRequirer } from "../../type"; -import createFakeWorker from "../../../helper/legacy/createFakeWorker"; import fs from "fs"; +import { JSDOM, ResourceLoader, VirtualConsole } from "jsdom"; import path from "path"; + +import { escapeSep } from "../../../helper"; +import createFakeWorker from "../../../helper/legacy/createFakeWorker"; import EventSource from "../../../helper/legacy/EventSourceForNode"; import urlToRelativePath from "../../../helper/legacy/urlToRelativePath"; +import { ECompilerType } from "../../../type"; +import { TRunnerRequirer } from "../../type"; +import { IBasicRunnerOptions } from "../basic"; import { CommonJsRunner } from "../cjs"; -import { escapeSep } from "../../../helper"; export class JSDOMWebRunner< T extends ECompilerType = ECompilerType.Rspack diff --git a/packages/rspack-test-tools/src/runner/watch.ts b/packages/rspack-test-tools/src/runner/watch.ts index c81788e023c8..d55fe0c1f981 100644 --- a/packages/rspack-test-tools/src/runner/watch.ts +++ b/packages/rspack-test-tools/src/runner/watch.ts @@ -5,8 +5,8 @@ import { TCompilerOptions, TCompilerStatsCompilation } from "../type"; -import { WatchRunner } from "./runner/watch"; import { BasicRunnerFactory } from "./basic"; +import { WatchRunner } from "./runner/watch"; export class WatchRunnerFactory< T extends ECompilerType diff --git a/packages/rspack-test-tools/src/test/context.ts b/packages/rspack-test-tools/src/test/context.ts index 5bff707dde11..84090abc111a 100644 --- a/packages/rspack-test-tools/src/test/context.ts +++ b/packages/rspack-test-tools/src/test/context.ts @@ -1,14 +1,15 @@ +import path from "path"; + import { TestCompilerManager } from "../compiler"; import { - ITestCompilerManager, ECompilerType, + ITestCompilerManager, ITestContext, ITesterConfig, ITestRunner, - TTestConfig, - TRunnerFactory + TRunnerFactory, + TTestConfig } from "../type"; -import path from "path"; export type TTestContextOptions = Omit; diff --git a/packages/rspack-test-tools/src/test/creator.ts b/packages/rspack-test-tools/src/test/creator.ts index c8f884e326a2..3d2ed325319e 100644 --- a/packages/rspack-test-tools/src/test/creator.ts +++ b/packages/rspack-test-tools/src/test/creator.ts @@ -1,16 +1,17 @@ +import fs from "fs"; +import path from "path"; +import rimraf from "rimraf"; + +import createLazyTestEnv from "../helper/legacy/createLazyTestEnv"; import { ECompilerType, ITestContext, - ITestProcessor, ITester, + ITestProcessor, TRunnerFactory, TTestConfig } from "../type"; -import fs from "fs"; -import path from "path"; -import rimraf from "rimraf"; import { Tester } from "./tester"; -import createLazyTestEnv from "../helper/legacy/createLazyTestEnv"; export interface IBasicCaseCreatorOptions { clean?: boolean; diff --git a/packages/rspack-test-tools/src/test/tester.ts b/packages/rspack-test-tools/src/test/tester.ts index 1a3a86871ee2..9983797c2225 100644 --- a/packages/rspack-test-tools/src/test/tester.ts +++ b/packages/rspack-test-tools/src/test/tester.ts @@ -1,11 +1,11 @@ -import { TestContext } from "./context"; import { + ITestContext, + ITestEnv, ITester, ITesterConfig, - ITestContext, - ITestProcessor, - ITestEnv + ITestProcessor } from "../type"; +import { TestContext } from "./context"; export class Tester implements ITester { private context: ITestContext; diff --git a/packages/rspack-test-tools/src/type.ts b/packages/rspack-test-tools/src/type.ts index 0c3521ace537..0938e9f17cc8 100644 --- a/packages/rspack-test-tools/src/type.ts +++ b/packages/rspack-test-tools/src/type.ts @@ -1,17 +1,18 @@ import { - RspackOptions, Compiler as RspackCompiler, + RspackOptions, Stats as RspackStats, StatsCompilation as RspackStatsCompilation } from "@rspack/core"; +import EventEmitter from "events"; import type { - Configuration as WebpackOptions, Compiler as WebpackCompiler, + Configuration as WebpackOptions, Stats as WebpackStats, StatsCompilation as WebpackStatsCompilation } from "webpack"; + import { IBasicModuleScope, TRunnerRequirer } from "./runner/type"; -import EventEmitter from "events"; export interface ITestContext { getSource(sub?: string): string; diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 1d5bbbfcd2a0..0b91499bbf33 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -165,11 +165,11 @@ const assetGeneratorDataUrl: z.ZodUnion<[z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; -}, { filename: string; +}, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>; // @public (undocumented) @@ -180,11 +180,11 @@ const assetGeneratorDataUrlFunction: z.ZodFunction], z.ZodUnknown>, z.ZodString>; // @public (undocumented) @@ -220,11 +220,11 @@ const assetGeneratorOptions: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; emit: z.ZodOptional; filename: z.ZodOptional; @@ -234,8 +234,8 @@ const assetGeneratorOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -245,8 +245,8 @@ const assetGeneratorOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -274,27 +274,27 @@ const assetInlineGeneratorOptions: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, "strict", z.ZodTypeAny, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }>; @@ -470,7 +470,7 @@ export const BannerPlugin: { }): { name: BuiltinPluginName; _options: RawBannerPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -1288,10 +1288,10 @@ export class Compiler { } // @public (undocumented) -type Compiler_3 = Compiler_2; +type Compiler_3 = any; // @public (undocumented) -type Compiler_4 = any; +type Compiler_4 = Compiler_2; // @public (undocumented) type Compiler_5 = any; @@ -1436,7 +1436,7 @@ class ContainerReferencePlugin extends RspackBuiltinPlugin { name: BuiltinPluginName; // (undocumented) _options: { - remoteType: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs"; + remoteType: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs"; remotes: [string, { external: string[]; shareScope: string; @@ -1495,7 +1495,7 @@ export const CopyRspackPlugin: { new (copy: CopyRspackPluginOptions): { name: BuiltinPluginName; _options: RawCopyRspackPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -1695,7 +1695,7 @@ export const DefinePlugin: { new (define: DefinePluginOptions): { name: BuiltinPluginName; _options: Record; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -1804,7 +1804,7 @@ export const DynamicEntryPlugin: { new (context: string, entry: EntryDynamicNormalized): { name: BuiltinPluginName; _options: RawDynamicEntryPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -1824,7 +1824,7 @@ const ElectronTargetPlugin: { new (context?: string | undefined): { name: BuiltinPluginName; _options: string; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -1855,7 +1855,7 @@ const EnableChunkLoadingPlugin: { new (type: any): { name: BuiltinPluginName; _options: any; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -1897,7 +1897,7 @@ const EnableWasmLoadingPlugin: { new (type: any): { name: BuiltinPluginName; _options: any; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -2525,7 +2525,7 @@ export const EntryPlugin: { new (context: string, entry: string, options?: string | EntryOptions | undefined): { name: BuiltinPluginName; _options: RawEntryPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -2698,7 +2698,7 @@ const entryUnnamed: z.ZodUnion<[z.ZodString, z.ZodArray]>; // @public export class EnvironmentPlugin { constructor(...keys: any[]); - apply(compiler: Compiler_5): void; + apply(compiler: Compiler_3): void; // (undocumented) defaultValues: any; // (undocumented) @@ -2716,7 +2716,7 @@ export const EvalDevToolModulePlugin: { new (options: EvalDevToolModulePluginOptions): { name: BuiltinPluginName; _options: EvalDevToolModulePluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -2729,7 +2729,7 @@ export const EvalSourceMapDevToolPlugin: { new (options: SourceMapDevToolPluginOptions): { name: BuiltinPluginName; _options: RawSourceMapDevToolPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -2987,7 +2987,7 @@ export const ExternalsPlugin: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; - }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { + }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; @@ -2995,14 +2995,14 @@ export const ExternalsPlugin: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; - }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { + }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; }, ...args_1: unknown[]) => Promise>))[]): { name: BuiltinPluginName; _options: RawExternalsPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -3142,11 +3142,11 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; emit: z.ZodOptional; filename: z.ZodOptional; @@ -3156,8 +3156,8 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3167,8 +3167,8 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3188,27 +3188,27 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, "strict", z.ZodTypeAny, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }>>; "asset/resource": z.ZodOptional string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3278,8 +3278,8 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -3307,8 +3307,8 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3319,8 +3319,8 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -3363,11 +3363,11 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; emit: z.ZodOptional; filename: z.ZodOptional; @@ -3377,8 +3377,8 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3388,8 +3388,8 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3409,27 +3409,27 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, "strict", z.ZodTypeAny, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }>>; "asset/resource": z.ZodOptional string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3499,8 +3499,8 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -3528,8 +3528,8 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -3540,8 +3540,8 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -3804,7 +3804,7 @@ export const HtmlRspackPlugin: { } | undefined): { name: BuiltinPluginName; _options: RawHtmlRspackPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -3889,7 +3889,7 @@ export const IgnorePlugin: { new (options: IgnorePluginOptions): { name: BuiltinPluginName; _options: RawIgnorePluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -3940,14 +3940,14 @@ const infrastructureLogging: z.ZodObject<{ colors?: boolean | undefined; console?: Console | undefined; debug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; - level?: "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + level?: "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; stream?: NodeJS.WritableStream | undefined; }, { appendOnly?: boolean | undefined; colors?: boolean | undefined; console?: Console | undefined; debug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; - level?: "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + level?: "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; stream?: NodeJS.WritableStream | undefined; }>; @@ -4424,7 +4424,7 @@ const LimitChunkCountPlugin: { new (options: LimitChunkCountOptions): { name: BuiltinPluginName; _options: RawLimitChunkCountPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -4598,7 +4598,7 @@ interface LoaderObject { // @public export class LoaderOptionsPlugin { constructor(options?: LoaderOptionsPluginOptions); - apply(compiler: Compiler_3): void; + apply(compiler: Compiler_4): void; // (undocumented) options: any; } @@ -4609,7 +4609,7 @@ type LoaderOptionsPluginOptions = any; // @public export class LoaderTargetPlugin { constructor(target: string); - apply(compiler: Compiler_4): void; + apply(compiler: Compiler_5): void; // (undocumented) target: string; } @@ -5072,11 +5072,11 @@ const moduleOptions: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; emit: z.ZodOptional; filename: z.ZodOptional; @@ -5086,8 +5086,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -5097,8 +5097,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -5118,27 +5118,27 @@ const moduleOptions: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, "strict", z.ZodTypeAny, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }>>; "asset/resource": z.ZodOptional string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -5208,8 +5208,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -5237,8 +5237,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -5249,8 +5249,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -5331,8 +5331,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -5343,8 +5343,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -5425,8 +5425,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -5437,8 +5437,8 @@ const moduleOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -5657,7 +5657,7 @@ const NodeTargetPlugin: { new (): { name: BuiltinPluginName; _options: undefined; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -5761,7 +5761,7 @@ const optimization: z.ZodObject<{ type: z.ZodOptional]>>; idHint: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5778,7 +5778,7 @@ const optimization: z.ZodObject<{ type?: string | RegExp | undefined; idHint?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5805,14 +5805,14 @@ const optimization: z.ZodObject<{ maxInitialSize: z.ZodOptional; automaticNameDelimiter: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -5821,7 +5821,7 @@ const optimization: z.ZodObject<{ }>>; hidePathInfo: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5831,7 +5831,7 @@ const optimization: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5851,7 +5851,7 @@ const optimization: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -5860,7 +5860,7 @@ const optimization: z.ZodObject<{ } | undefined; hidePathInfo?: boolean | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5870,7 +5870,7 @@ const optimization: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5890,7 +5890,7 @@ const optimization: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -5930,10 +5930,10 @@ const optimization: z.ZodObject<{ moduleIds?: "named" | "deterministic" | undefined; chunkIds?: "named" | "deterministic" | undefined; minimize?: boolean | undefined; - minimizer?: (false | "" | 0 | "..." | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; + minimizer?: (false | "" | 0 | RspackPluginInstance | "..." | RspackPluginFunction | null | undefined)[] | undefined; mergeDuplicateChunks?: boolean | undefined; splitChunks?: false | { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5943,7 +5943,7 @@ const optimization: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -5963,7 +5963,7 @@ const optimization: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -5985,16 +5985,16 @@ const optimization: z.ZodObject<{ concatenateModules?: boolean | undefined; innerGraph?: boolean | undefined; usedExports?: boolean | "global" | undefined; - mangleExports?: boolean | "size" | "deterministic" | undefined; + mangleExports?: boolean | "deterministic" | "size" | undefined; nodeEnv?: string | false | undefined; }, { moduleIds?: "named" | "deterministic" | undefined; chunkIds?: "named" | "deterministic" | undefined; minimize?: boolean | undefined; - minimizer?: (false | "" | 0 | "..." | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; + minimizer?: (false | "" | 0 | RspackPluginInstance | "..." | RspackPluginFunction | null | undefined)[] | undefined; mergeDuplicateChunks?: boolean | undefined; splitChunks?: false | { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6004,7 +6004,7 @@ const optimization: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6024,7 +6024,7 @@ const optimization: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -6046,7 +6046,7 @@ const optimization: z.ZodObject<{ concatenateModules?: boolean | undefined; innerGraph?: boolean | undefined; usedExports?: boolean | "global" | undefined; - mangleExports?: boolean | "size" | "deterministic" | undefined; + mangleExports?: boolean | "deterministic" | "size" | undefined; nodeEnv?: string | false | undefined; }>; @@ -6101,7 +6101,7 @@ const optimizationSplitChunksCacheGroup: z.ZodObject<{ type: z.ZodOptional]>>; idHint: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6118,7 +6118,7 @@ const optimizationSplitChunksCacheGroup: z.ZodObject<{ type?: string | RegExp | undefined; idHint?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6174,7 +6174,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ type: z.ZodOptional]>>; idHint: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6191,7 +6191,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ type?: string | RegExp | undefined; idHint?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6218,14 +6218,14 @@ const optimizationSplitChunksOptions: z.ZodObject<{ maxInitialSize: z.ZodOptional; automaticNameDelimiter: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -6234,7 +6234,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ }>>; hidePathInfo: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6244,7 +6244,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6264,7 +6264,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -6273,7 +6273,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ } | undefined; hidePathInfo?: boolean | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6283,7 +6283,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -6303,7 +6303,7 @@ const optimizationSplitChunksOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -7307,7 +7307,7 @@ export const ProgressPlugin: { new (progress?: ProgressPluginArgument): { name: BuiltinPluginName; _options: RawProgressPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -7321,7 +7321,7 @@ export const ProvidePlugin: { new (provide: ProvidePluginOptions): { name: BuiltinPluginName; _options: Record; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -7543,34 +7543,34 @@ abstract class RspackBuiltinPlugin implements RspackPluginInstance { declare namespace rspackExports { export { - version, rspackVersion, - Compiler, - Compilation, + version, Asset, AssetInfo, Assets, - LogEntry, CompilationParams, - MultiCompiler, + LogEntry, + Compilation, + Compiler, MultiCompilerOptions, MultiRspackOptions, + MultiCompiler, RspackOptionsApply, RspackOptionsApply as WebpackOptionsApply, + Chunk, + ChunkGroup, + Module, + MultiStats, + NormalModule, + NormalModuleFactory, RuntimeGlobals, - Stats, - StatsCompilation, StatsAsset, StatsChunk, + StatsCompilation, StatsError, StatsModule, StatsWarnings, - MultiStats, - Chunk, - ChunkGroup, - NormalModuleFactory, - Module, - NormalModule, + Stats, ModuleFilenameHelpers, Template, WebpackError, @@ -7578,28 +7578,28 @@ declare namespace rspackExports { sources, config, util, + EntryOptionPlugin, OutputFileSystem, - experimental_registerGlobalTrace, experimental_cleanupGlobalTrace, - EntryOptionPlugin, - BannerPlugin, + experimental_registerGlobalTrace, BannerPluginArgument, + ProvidePluginOptions, + DefinePluginOptions, + ProgressPluginArgument, + EntryOptions, + BannerPlugin, IgnorePlugin, IgnorePluginOptions, ProvidePlugin, - ProvidePluginOptions, DefinePlugin, - DefinePluginOptions, ProgressPlugin, - ProgressPluginArgument, EntryPlugin, - EntryOptions, DynamicEntryPlugin, ExternalsPlugin, HotModuleReplacementPlugin, + EnvironmentPlugin, LoaderOptionsPlugin, LoaderTargetPlugin, - EnvironmentPlugin, NormalModuleReplacementPlugin, node, electron, @@ -7612,56 +7612,64 @@ declare namespace rspackExports { ModuleFederationPluginV1Options, ContainerPluginOptions, Exposes, + ExposesConfig, ExposesItem, ExposesItems, ExposesObject, - ExposesConfig, ContainerReferencePluginOptions, Remotes, + RemotesConfig, RemotesItem, RemotesItems, RemotesObject, - RemotesConfig, container, - ProvideSharedPluginOptions, - Provides, - ProvidesConfig, - ProvidesItem, - ProvidesObject, - ConsumeSharedPluginOptions, Consumes, ConsumesConfig, + ConsumeSharedPluginOptions, ConsumesItem, ConsumesObject, - SharePluginOptions, + Provides, + ProvidesConfig, + ProvideSharedPluginOptions, + ProvidesItem, + ProvidesObject, Shared, SharedConfig, SharedItem, SharedObject, + SharePluginOptions, sharing, - HtmlRspackPlugin, HtmlRspackPluginOptions, - SwcJsMinimizerRspackPlugin, SwcJsMinimizerRspackPluginOptions, + CopyRspackPluginOptions, + SourceMapDevToolPluginOptions, + EvalDevToolModulePluginOptions, + CssExtractRspackLoaderOptions, + CssExtractRspackPluginOptions, + HtmlRspackPlugin, + SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin, CopyRspackPlugin, - CopyRspackPluginOptions, SourceMapDevToolPlugin, EvalSourceMapDevToolPlugin, - SourceMapDevToolPluginOptions, EvalDevToolModulePlugin, - EvalDevToolModulePluginOptions, CssExtractRspackPlugin, - CssExtractRspackPluginOptions, - CssExtractRspackLoaderOptions, - SwcLoaderOptions, SwcLoaderEnvConfig, + SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, + SwcLoaderOptions, SwcLoaderParserConfig, - SwcLoaderEsParserConfig, - SwcLoaderTsParserConfig, SwcLoaderTransformConfig, + SwcLoaderTsParserConfig, + getRawLibrary, + getRawChunkLoading, + LoaderContext, + LoaderDefinition, + LoaderDefinitionFunction, + getRawOptions, + applyRspackOptionsDefaults, + applyRspackOptionsBaseDefaults, getNormalizedRspackOptions, EntryDynamicNormalized, EntryNormalized, @@ -7824,15 +7832,7 @@ declare namespace rspackExports { Builtins, rspackOptions, RspackOptions, - Configuration, - applyRspackOptionsDefaults, - applyRspackOptionsBaseDefaults, - getRawLibrary, - getRawChunkLoading, - LoaderContext, - LoaderDefinition, - LoaderDefinitionFunction, - getRawOptions + Configuration } } @@ -8590,14 +8590,14 @@ export const rspackOptions: z.ZodObject<{ colors?: boolean | undefined; console?: Console | undefined; debug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; - level?: "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + level?: "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; stream?: NodeJS.WritableStream | undefined; }, { appendOnly?: boolean | undefined; colors?: boolean | undefined; console?: Console | undefined; debug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; - level?: "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + level?: "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; stream?: NodeJS.WritableStream | undefined; }>>; cache: z.ZodOptional; @@ -8675,7 +8675,7 @@ export const rspackOptions: z.ZodObject<{ orphanModules: z.ZodOptional; }, "strict", z.ZodTypeAny, { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -8700,7 +8700,7 @@ export const rspackOptions: z.ZodObject<{ modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -8711,7 +8711,7 @@ export const rspackOptions: z.ZodObject<{ orphanModules?: boolean | undefined; }, { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -8736,7 +8736,7 @@ export const rspackOptions: z.ZodObject<{ modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -8820,7 +8820,7 @@ export const rspackOptions: z.ZodObject<{ type: z.ZodOptional]>>; idHint: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -8837,7 +8837,7 @@ export const rspackOptions: z.ZodObject<{ type?: string | RegExp | undefined; idHint?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -8864,14 +8864,14 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize: z.ZodOptional; automaticNameDelimiter: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -8880,7 +8880,7 @@ export const rspackOptions: z.ZodObject<{ }>>; hidePathInfo: z.ZodOptional; }, "strict", z.ZodTypeAny, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -8890,7 +8890,7 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -8910,7 +8910,7 @@ export const rspackOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -8919,7 +8919,7 @@ export const rspackOptions: z.ZodObject<{ } | undefined; hidePathInfo?: boolean | undefined; }, { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -8929,7 +8929,7 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -8949,7 +8949,7 @@ export const rspackOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -8989,10 +8989,10 @@ export const rspackOptions: z.ZodObject<{ moduleIds?: "named" | "deterministic" | undefined; chunkIds?: "named" | "deterministic" | undefined; minimize?: boolean | undefined; - minimizer?: (false | "" | 0 | "..." | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; + minimizer?: (false | "" | 0 | RspackPluginInstance | "..." | RspackPluginFunction | null | undefined)[] | undefined; mergeDuplicateChunks?: boolean | undefined; splitChunks?: false | { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -9002,7 +9002,7 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -9022,7 +9022,7 @@ export const rspackOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -9044,16 +9044,16 @@ export const rspackOptions: z.ZodObject<{ concatenateModules?: boolean | undefined; innerGraph?: boolean | undefined; usedExports?: boolean | "global" | undefined; - mangleExports?: boolean | "size" | "deterministic" | undefined; + mangleExports?: boolean | "deterministic" | "size" | undefined; nodeEnv?: string | false | undefined; }, { moduleIds?: "named" | "deterministic" | undefined; chunkIds?: "named" | "deterministic" | undefined; minimize?: boolean | undefined; - minimizer?: (false | "" | 0 | "..." | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; + minimizer?: (false | "" | 0 | RspackPluginInstance | "..." | RspackPluginFunction | null | undefined)[] | undefined; mergeDuplicateChunks?: boolean | undefined; splitChunks?: false | { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -9063,7 +9063,7 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -9083,7 +9083,7 @@ export const rspackOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -9105,7 +9105,7 @@ export const rspackOptions: z.ZodObject<{ concatenateModules?: boolean | undefined; innerGraph?: boolean | undefined; usedExports?: boolean | "global" | undefined; - mangleExports?: boolean | "size" | "deterministic" | undefined; + mangleExports?: boolean | "deterministic" | "size" | undefined; nodeEnv?: string | false | undefined; }>>; resolve: z.ZodOptional>; @@ -9353,11 +9353,11 @@ export const rspackOptions: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; emit: z.ZodOptional; filename: z.ZodOptional; @@ -9367,8 +9367,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -9378,8 +9378,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -9399,27 +9399,27 @@ export const rspackOptions: z.ZodObject<{ content: z.ZodString; filename: z.ZodString; }, "strict", z.ZodTypeAny, { - filename: string; content: string; - }, { filename: string; + }, { content: string; + filename: string; }>], z.ZodUnknown>, z.ZodString>]>>; }, "strict", z.ZodTypeAny, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }, { dataUrl?: { encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; }>>; "asset/resource": z.ZodOptional string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -9489,8 +9489,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -9518,8 +9518,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -9530,8 +9530,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -9612,8 +9612,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -9624,8 +9624,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -9706,8 +9706,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -9718,8 +9718,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -9897,7 +9897,7 @@ export const rspackOptions: z.ZodObject<{ devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; } | undefined; - target?: false | "async-node" | "web" | "webworker" | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "browserslist" | "node" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("async-node" | "web" | "webworker" | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "browserslist" | "node" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined; + target?: false | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined; mode?: "none" | "development" | "production" | undefined; experiments?: { lazyCompilation?: boolean | undefined; @@ -9919,7 +9919,7 @@ export const rspackOptions: z.ZodObject<{ context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; - }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { + }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; @@ -9927,12 +9927,12 @@ export const rspackOptions: z.ZodObject<{ context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; - }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { + }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; }, ...args_1: unknown[]) => Promise>))[] | undefined; - externalsType?: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined; + externalsType?: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined; externalsPresets?: { node?: boolean | undefined; web?: boolean | undefined; @@ -9947,7 +9947,7 @@ export const rspackOptions: z.ZodObject<{ colors?: boolean | undefined; console?: Console | undefined; debug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; - level?: "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + level?: "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; stream?: NodeJS.WritableStream | undefined; } | undefined; cache?: boolean | undefined; @@ -9967,9 +9967,9 @@ export const rspackOptions: z.ZodObject<{ stdin?: boolean | undefined; } | undefined; watch?: boolean | undefined; - stats?: boolean | "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | { + stats?: boolean | "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -9994,7 +9994,7 @@ export const rspackOptions: z.ZodObject<{ modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -10018,10 +10018,10 @@ export const rspackOptions: z.ZodObject<{ moduleIds?: "named" | "deterministic" | undefined; chunkIds?: "named" | "deterministic" | undefined; minimize?: boolean | undefined; - minimizer?: (false | "" | 0 | "..." | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; + minimizer?: (false | "" | 0 | RspackPluginInstance | "..." | RspackPluginFunction | null | undefined)[] | undefined; mergeDuplicateChunks?: boolean | undefined; splitChunks?: false | { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -10031,7 +10031,7 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -10051,7 +10051,7 @@ export const rspackOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -10073,7 +10073,7 @@ export const rspackOptions: z.ZodObject<{ concatenateModules?: boolean | undefined; innerGraph?: boolean | undefined; usedExports?: boolean | "global" | undefined; - mangleExports?: boolean | "size" | "deterministic" | undefined; + mangleExports?: boolean | "deterministic" | "size" | undefined; nodeEnv?: string | false | undefined; } | undefined; resolve?: ResolveOptions | undefined; @@ -10138,8 +10138,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -10150,8 +10150,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -10319,7 +10319,7 @@ export const rspackOptions: z.ZodObject<{ devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; } | undefined; - target?: false | "async-node" | "web" | "webworker" | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "browserslist" | "node" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("async-node" | "web" | "webworker" | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "browserslist" | "node" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined; + target?: false | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined; mode?: "none" | "development" | "production" | undefined; experiments?: { lazyCompilation?: boolean | undefined; @@ -10341,7 +10341,7 @@ export const rspackOptions: z.ZodObject<{ context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; - }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { + }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; @@ -10349,12 +10349,12 @@ export const rspackOptions: z.ZodObject<{ context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; - }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { + }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record | undefined, args_2: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: { context?: string | undefined; dependencyType?: string | undefined; request?: string | undefined; }, ...args_1: unknown[]) => Promise>))[] | undefined; - externalsType?: "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined; + externalsType?: "promise" | "commonjs" | "umd" | "amd" | "module" | "global" | "jsonp" | "import" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd2" | "system" | "script" | "node-commonjs" | undefined; externalsPresets?: { node?: boolean | undefined; web?: boolean | undefined; @@ -10369,7 +10369,7 @@ export const rspackOptions: z.ZodObject<{ colors?: boolean | undefined; console?: Console | undefined; debug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; - level?: "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + level?: "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; stream?: NodeJS.WritableStream | undefined; } | undefined; cache?: boolean | undefined; @@ -10389,9 +10389,9 @@ export const rspackOptions: z.ZodObject<{ stdin?: boolean | undefined; } | undefined; watch?: boolean | undefined; - stats?: boolean | "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | { + stats?: boolean | "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -10416,7 +10416,7 @@ export const rspackOptions: z.ZodObject<{ modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -10440,10 +10440,10 @@ export const rspackOptions: z.ZodObject<{ moduleIds?: "named" | "deterministic" | undefined; chunkIds?: "named" | "deterministic" | undefined; minimize?: boolean | undefined; - minimizer?: (false | "" | 0 | "..." | RspackPluginInstance | RspackPluginFunction | null | undefined)[] | undefined; + minimizer?: (false | "" | 0 | RspackPluginInstance | "..." | RspackPluginFunction | null | undefined)[] | undefined; mergeDuplicateChunks?: boolean | undefined; splitChunks?: false | { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -10453,7 +10453,7 @@ export const rspackOptions: z.ZodObject<{ maxInitialSize?: number | undefined; automaticNameDelimiter?: string | undefined; cacheGroups?: Record boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; defaultSizeTypes?: string[] | undefined; minChunks?: number | undefined; name?: string | false | ((args_0: Module | undefined, ...args_1: unknown[]) => unknown) | undefined; @@ -10473,7 +10473,7 @@ export const rspackOptions: z.ZodObject<{ maxAsyncRequests?: number | undefined; maxInitialRequests?: number | undefined; fallbackCacheGroup?: { - chunks?: RegExp | "async" | "all" | "initial" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; + chunks?: RegExp | "async" | "initial" | "all" | ((args_0: Chunk, ...args_1: unknown[]) => boolean) | undefined; minSize?: number | undefined; maxSize?: number | undefined; maxAsyncSize?: number | undefined; @@ -10495,7 +10495,7 @@ export const rspackOptions: z.ZodObject<{ concatenateModules?: boolean | undefined; innerGraph?: boolean | undefined; usedExports?: boolean | "global" | undefined; - mangleExports?: boolean | "size" | "deterministic" | undefined; + mangleExports?: boolean | "deterministic" | "size" | undefined; nodeEnv?: string | false | undefined; } | undefined; resolve?: ResolveOptions | undefined; @@ -10560,8 +10560,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; emit?: boolean | undefined; filename?: string | undefined; @@ -10572,8 +10572,8 @@ export const rspackOptions: z.ZodObject<{ encoding?: false | "base64" | undefined; mimetype?: string | undefined; } | ((args_0: { - filename: string; content: string; + filename: string; }, ...args_1: unknown[]) => string) | undefined; } | undefined; "asset/resource"?: { @@ -10828,7 +10828,7 @@ const RuntimeChunkPlugin: { new (options: RawRuntimeChunkOptions): { name: BuiltinPluginName; _options: RawRuntimeChunkOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -11059,7 +11059,7 @@ export const SourceMapDevToolPlugin: { new (options: SourceMapDevToolPluginOptions): { name: BuiltinPluginName; _options: RawSourceMapDevToolPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -11204,7 +11204,7 @@ const statsOptions: z.ZodObject<{ orphanModules: z.ZodOptional; }, "strict", z.ZodTypeAny, { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -11229,7 +11229,7 @@ const statsOptions: z.ZodObject<{ modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -11240,7 +11240,7 @@ const statsOptions: z.ZodObject<{ orphanModules?: boolean | undefined; }, { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -11265,7 +11265,7 @@ const statsOptions: z.ZodObject<{ modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -11345,7 +11345,7 @@ const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["none", "errors-only", "err orphanModules: z.ZodOptional; }, "strict", z.ZodTypeAny, { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -11370,7 +11370,7 @@ const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["none", "errors-only", "err modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -11381,7 +11381,7 @@ const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["none", "errors-only", "err orphanModules?: boolean | undefined; }, { all?: boolean | undefined; - preset?: "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | undefined; + preset?: "none" | "normal" | "verbose" | "errors-only" | "errors-warnings" | undefined; assets?: boolean | undefined; chunks?: boolean | undefined; modules?: boolean | undefined; @@ -11406,7 +11406,7 @@ const statsValue: z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["none", "errors-only", "err modulesSpace?: number | undefined; nestedModules?: boolean | undefined; source?: boolean | undefined; - logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined; + logging?: boolean | "error" | "warn" | "info" | "log" | "none" | "verbose" | undefined; loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; loggingTrace?: boolean | undefined; runtimeModules?: boolean | undefined; @@ -11451,7 +11451,7 @@ export const SwcCssMinimizerRspackPlugin: { new (options?: any): { name: BuiltinPluginName; _options: undefined; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -11462,7 +11462,7 @@ export const SwcJsMinimizerRspackPlugin: { new (options?: SwcJsMinimizerRspackPluginOptions | undefined): { name: BuiltinPluginName; _options: RawSwcJsMinimizerRspackPluginOptions; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; @@ -12128,7 +12128,7 @@ const WebWorkerTemplatePlugin: { new (): { name: BuiltinPluginName; _options: undefined; - affectedHooks: "done" | "compilation" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; + affectedHooks: "done" | "make" | "compile" | "emit" | "afterEmit" | "invalid" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined; raw(): BuiltinPlugin; apply(compiler: Compiler_2): void; }; diff --git a/packages/rspack/scripts/check-documentation-coverage.mjs b/packages/rspack/scripts/check-documentation-coverage.mjs index cba965a55de8..ac84dc57d0a5 100644 --- a/packages/rspack/scripts/check-documentation-coverage.mjs +++ b/packages/rspack/scripts/check-documentation-coverage.mjs @@ -1,7 +1,7 @@ -import { ApiModel, ApiItemKind } from "@microsoft/api-extractor-model"; -import { fileURLToPath } from "url"; -import { dirname, resolve, extname, basename, join } from "path"; +import { ApiItemKind,ApiModel } from "@microsoft/api-extractor-model"; import { readdirSync, readFileSync } from "fs"; +import { basename, dirname, extname, join,resolve } from "path"; +import { fileURLToPath } from "url"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); diff --git a/packages/rspack/src/Chunk.ts b/packages/rspack/src/Chunk.ts index 53602c55f896..0f68f11fc301 100644 --- a/packages/rspack/src/Chunk.ts +++ b/packages/rspack/src/Chunk.ts @@ -9,9 +9,10 @@ import { type JsChunk, type JsCompilation } from "@rspack/binding"; + +import { Compilation } from "."; import { ChunkGroup } from "./ChunkGroup"; import { compareChunkGroupsByIndex } from "./util/comparators"; -import { Compilation } from "."; export class Chunk { #inner: JsChunk; diff --git a/packages/rspack/src/ChunkGraph.ts b/packages/rspack/src/ChunkGraph.ts index 043dc293827c..5e286756508a 100644 --- a/packages/rspack/src/ChunkGraph.ts +++ b/packages/rspack/src/ChunkGraph.ts @@ -4,6 +4,7 @@ import { __chunk_graph_inner_get_chunk_modules, __chunk_graph_inner_get_chunk_modules_iterable_by_source_type } from "@rspack/binding"; + import { Chunk } from "./Chunk"; import { Compilation } from "./Compilation"; import { Module } from "./Module"; diff --git a/packages/rspack/src/Compilation.ts b/packages/rspack/src/Compilation.ts index cbf7faf09ea1..d2a0b3987b83 100644 --- a/packages/rspack/src/Compilation.ts +++ b/packages/rspack/src/Compilation.ts @@ -7,55 +7,54 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ -import * as tapable from "tapable"; -import { Source } from "webpack-sources"; - import type { ExternalObject, JsAssetInfo, JsCompatSource, JsCompilation, + JsDiagnostic, JsModule, + JsPathData, JsRuntimeModule, JsStatsError, - JsPathData, - JsStatsWarning, - JsDiagnostic + JsStatsWarning } from "@rspack/binding"; +import * as tapable from "tapable"; +import { Source } from "webpack-sources"; import { - RspackOptionsNormalized, - StatsOptions, + Filename, OutputNormalized, - StatsValue, + RspackOptionsNormalized, RspackPluginInstance, - Filename + StatsOptions, + StatsValue } from "./config"; -import * as liteTapable from "./lite-tapable"; import { ContextModuleFactory } from "./ContextModuleFactory"; +import * as liteTapable from "./lite-tapable"; import ResolverFactory = require("./ResolverFactory"); +import { Chunk } from "./Chunk"; +import { ChunkGraph } from "./ChunkGraph"; import { Compiler } from "./Compiler"; +import { Entrypoint } from "./Entrypoint"; import ErrorHelpers from "./ErrorHelpers"; -import { LogType, Logger } from "./logging/Logger"; +import { Logger, LogType } from "./logging/Logger"; +import { CodeGenerationResult, Module } from "./Module"; import { NormalModule } from "./NormalModule"; import { NormalModuleFactory } from "./NormalModuleFactory"; import { - Stats, normalizeFilter, normalizeStatsPreset, - optionsOrFallback + optionsOrFallback, + Stats } from "./Stats"; import { StatsFactory } from "./stats/StatsFactory"; import { StatsPrinter } from "./stats/StatsPrinter"; import { concatErrorMsgAndStack, toJsAssetInfo } from "./util"; -import { JsSource } from "./util/source"; import { createFakeCompilationDependencies } from "./util/fake"; -import MergeCaller from "./util/MergeCaller"; import { memoizeValue } from "./util/memoize"; -import { Chunk } from "./Chunk"; -import { CodeGenerationResult, Module } from "./Module"; -import { ChunkGraph } from "./ChunkGraph"; -import { Entrypoint } from "./Entrypoint"; +import MergeCaller from "./util/MergeCaller"; +import { JsSource } from "./util/source"; export type AssetInfo = Partial & Record; export type Assets = Record; diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index 08913452108c..da76aebc3ac6 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -8,57 +8,59 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ import * as binding from "@rspack/binding"; -import { rspack } from "./index"; import fs from "fs"; import * as tapable from "tapable"; -import * as liteTapable from "./lite-tapable"; import { Callback, SyncBailHook, SyncHook } from "tapable"; import type Watchpack from "watchpack"; + +import { Compilation, CompilationParams } from "./Compilation"; import { - getRawOptions, EntryNormalized, + getRawOptions, OutputNormalized, RspackOptionsNormalized, RspackPluginInstance } from "./config"; +import { ContextModuleFactory } from "./ContextModuleFactory"; +import { rspack } from "./index"; +import * as liteTapable from "./lite-tapable"; import { RuleSetCompiler } from "./RuleSetCompiler"; import { Stats } from "./Stats"; -import { Compilation, CompilationParams } from "./Compilation"; -import { ContextModuleFactory } from "./ContextModuleFactory"; import ResolverFactory = require("./ResolverFactory"); import ConcurrentCompilationError from "./error/ConcurrentCompilationError"; import { ThreadsafeWritableNodeFS } from "./fileSystem"; import Cache = require("./lib/Cache"); import CacheFacade = require("./lib/CacheFacade"); -import { Logger } from "./logging/Logger"; -import { - NormalModuleCreateData, - NormalModuleFactory -} from "./NormalModuleFactory"; -import { OutputFileSystem, WatchFileSystem } from "./util/fs"; -import { checkVersion } from "./util/bindingVersionCheck"; -import { Watching } from "./Watching"; +import { Source } from "webpack-sources"; + import { - JsLoaderRspackPlugin, - deprecated_resolveBuiltins + deprecated_resolveBuiltins, + JsLoaderRspackPlugin } from "./builtin-plugin"; +import { canInherentFromParent } from "./builtin-plugin/base"; +import { Chunk } from "./Chunk"; import { applyRspackOptionsDefaults } from "./config/defaults"; -import { assertNotNill } from "./util/assertNotNil"; +import ExecuteModulePlugin from "./ExecuteModulePlugin"; import { FileSystemInfoEntry } from "./FileSystemInfo"; -import { RuntimeGlobals } from "./RuntimeGlobals"; import { tryRunOrWebpackError } from "./lib/HookWebpackError"; +import { Logger } from "./logging/Logger"; import { CodeGenerationResult, ContextModuleFactoryAfterResolveResult, Module, ResolveData } from "./Module"; -import { canInherentFromParent } from "./builtin-plugin/base"; -import ExecuteModulePlugin from "./ExecuteModulePlugin"; -import { Chunk } from "./Chunk"; -import { Source } from "webpack-sources"; +import { + NormalModuleCreateData, + NormalModuleFactory +} from "./NormalModuleFactory"; +import { RuntimeGlobals } from "./RuntimeGlobals"; import { unsupported } from "./util"; +import { assertNotNill } from "./util/assertNotNil"; +import { checkVersion } from "./util/bindingVersionCheck"; +import { OutputFileSystem, WatchFileSystem } from "./util/fs"; import { makePathsRelative } from "./util/identifier"; +import { Watching } from "./Watching"; export interface AssetEmittedInfo { content: Buffer; diff --git a/packages/rspack/src/Entrypoint.ts b/packages/rspack/src/Entrypoint.ts index 690215428085..93fd2b858b74 100644 --- a/packages/rspack/src/Entrypoint.ts +++ b/packages/rspack/src/Entrypoint.ts @@ -3,8 +3,9 @@ import { type JsChunkGroup, type JsCompilation } from "@rspack/binding"; -import { ChunkGroup } from "./ChunkGroup"; + import { Chunk } from "./Chunk"; +import { ChunkGroup } from "./ChunkGroup"; export class Entrypoint extends ChunkGroup { static __from_binding(chunk: JsChunkGroup, compilation: JsCompilation) { diff --git a/packages/rspack/src/ExecuteModulePlugin.ts b/packages/rspack/src/ExecuteModulePlugin.ts index 1697dae23df0..9ce8a188789b 100644 --- a/packages/rspack/src/ExecuteModulePlugin.ts +++ b/packages/rspack/src/ExecuteModulePlugin.ts @@ -1,6 +1,7 @@ +import vm from "node:vm"; + import { RuntimeGlobals } from "."; import type { Compiler } from "./Compiler"; -import vm from "node:vm"; export default class ExecuteModulePlugin { constructor() {} diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index 67b05badd7b2..3f18dc072b06 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -5,6 +5,7 @@ import { JsModule } from "@rspack/binding"; import { Source } from "webpack-sources"; + import { JsSource } from "./util/source"; export type ResourceData = { diff --git a/packages/rspack/src/MultiCompiler.ts b/packages/rspack/src/MultiCompiler.ts index e8defa8213b6..374f3819ceaa 100644 --- a/packages/rspack/src/MultiCompiler.ts +++ b/packages/rspack/src/MultiCompiler.ts @@ -8,8 +8,7 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ -import { Compiler, RspackOptions, Stats } from "."; -import { WatchFileSystem } from "./util/fs"; +import asyncLib from "neo-async"; import { AsyncSeriesHook, Callback, @@ -17,12 +16,14 @@ import { SyncBailHook, SyncHook } from "tapable"; -import MultiStats from "./MultiStats"; -import asyncLib from "neo-async"; -import ArrayQueue from "./util/ArrayQueue"; + +import { Compiler, RspackOptions, Stats } from "."; +import { WatchOptions } from "./config"; import ConcurrentCompilationError from "./error/ConcurrentCompilationError"; +import MultiStats from "./MultiStats"; import MultiWatching from "./MultiWatching"; -import { WatchOptions } from "./config"; +import ArrayQueue from "./util/ArrayQueue"; +import { WatchFileSystem } from "./util/fs"; interface Node { compiler: Compiler; diff --git a/packages/rspack/src/MultiStats.ts b/packages/rspack/src/MultiStats.ts index aaaecf3b8641..220db670a99f 100644 --- a/packages/rspack/src/MultiStats.ts +++ b/packages/rspack/src/MultiStats.ts @@ -9,8 +9,8 @@ */ import { KnownCreateStatsOptionsContext } from "./Compilation"; -import { StatsCompilation } from "./stats/statsFactoryUtils"; import { Stats } from "./Stats"; +import { StatsCompilation } from "./stats/statsFactoryUtils"; import { indent } from "./util"; import * as identifierUtils from "./util/identifier"; diff --git a/packages/rspack/src/MultiWatching.ts b/packages/rspack/src/MultiWatching.ts index baae12c50bd7..9cca17e22254 100644 --- a/packages/rspack/src/MultiWatching.ts +++ b/packages/rspack/src/MultiWatching.ts @@ -8,9 +8,10 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ +import asyncLib from "neo-async"; + import { MultiCompiler } from "./MultiCompiler"; import { Watching } from "./Watching"; -import asyncLib from "neo-async"; class MultiWatching { watchings: Watching[]; diff --git a/packages/rspack/src/NormalModule.ts b/packages/rspack/src/NormalModule.ts index 5ceb0171f351..e008cfee8570 100644 --- a/packages/rspack/src/NormalModule.ts +++ b/packages/rspack/src/NormalModule.ts @@ -1,5 +1,6 @@ import { AsyncSeriesBailHook, HookMap, SyncHook } from "tapable"; import util from "util"; + import { Compilation } from "./Compilation"; import { LoaderContext } from "./config"; diff --git a/packages/rspack/src/NormalModuleFactory.ts b/packages/rspack/src/NormalModuleFactory.ts index 3dbf0bba0fdc..9d94163343ab 100644 --- a/packages/rspack/src/NormalModuleFactory.ts +++ b/packages/rspack/src/NormalModuleFactory.ts @@ -1,6 +1,7 @@ +import type * as binding from "@rspack/binding"; import { AsyncSeriesBailHook, HookMap } from "tapable"; + import * as liteTapable from "./lite-tapable"; -import type * as binding from "@rspack/binding"; import { ResolveData, ResourceDataWithData } from "./Module"; export type NormalModuleCreateData = diff --git a/packages/rspack/src/Stats.ts b/packages/rspack/src/Stats.ts index ee9d52c57938..7855b6ea3cf5 100644 --- a/packages/rspack/src/Stats.ts +++ b/packages/rspack/src/Stats.ts @@ -8,16 +8,17 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ import type * as binding from "@rspack/binding"; + import { Compilation, FilterItemTypes } from "."; -import { StatsValue, StatsOptions } from "./config"; +import { StatsOptions, StatsValue } from "./config"; import type { StatsCompilation } from "./stats/statsFactoryUtils"; export type { - StatsCompilation, StatsAsset, StatsChunk, - StatsModule, + StatsCompilation, StatsError, + StatsModule, StatsWarnings } from "./stats/statsFactoryUtils"; diff --git a/packages/rspack/src/Watching.ts b/packages/rspack/src/Watching.ts index 7d5d66df6c93..0dc67476d3b9 100644 --- a/packages/rspack/src/Watching.ts +++ b/packages/rspack/src/Watching.ts @@ -7,12 +7,13 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ +import assert from "assert"; import { Callback } from "tapable"; + import type { Compilation, Compiler } from "."; import { Stats } from "."; import { WatchOptions } from "./config"; import { FileSystemInfoEntry, Watcher } from "./util/fs"; -import assert from "assert"; export class Watching { watcher?: Watcher; diff --git a/packages/rspack/src/builtin-loader/swc/index.ts b/packages/rspack/src/builtin-loader/swc/index.ts index b5af988b0969..8320912be243 100644 --- a/packages/rspack/src/builtin-loader/swc/index.ts +++ b/packages/rspack/src/builtin-loader/swc/index.ts @@ -1,22 +1,18 @@ -export { resolveEmotion } from "./emotion"; export type { EmotionOptions } from "./emotion"; - -export { resolveReact } from "./react"; +export { resolveEmotion } from "./emotion"; +export type { PluginImportOptions } from "./pluginImport"; +export { resolvePluginImport } from "./pluginImport"; export type { ReactOptions } from "./react"; - -export { resolveRelay } from "./relay"; +export { resolveReact } from "./react"; export type { RelayOptions } from "./relay"; - -export { resolvePluginImport } from "./pluginImport"; -export type { PluginImportOptions } from "./pluginImport"; - +export { resolveRelay } from "./relay"; export type { - SwcLoaderOptions, SwcLoaderEnvConfig, + SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, + SwcLoaderOptions, SwcLoaderParserConfig, - SwcLoaderEsParserConfig, - SwcLoaderTsParserConfig, - SwcLoaderTransformConfig + SwcLoaderTransformConfig, + SwcLoaderTsParserConfig } from "./types"; diff --git a/packages/rspack/src/builtin-loader/swc/relay.ts b/packages/rspack/src/builtin-loader/swc/relay.ts index 617bee971b2c..11d4129ee6e0 100644 --- a/packages/rspack/src/builtin-loader/swc/relay.ts +++ b/packages/rspack/src/builtin-loader/swc/relay.ts @@ -1,5 +1,5 @@ -import path from "path"; import type { RawRelayConfig } from "@rspack/binding"; +import path from "path"; type RelayOptions = boolean | RawRelayConfig | undefined; diff --git a/packages/rspack/src/builtin-loader/swc/types.ts b/packages/rspack/src/builtin-loader/swc/types.ts index 6dc14d9a0da8..efcfe0222800 100644 --- a/packages/rspack/src/builtin-loader/swc/types.ts +++ b/packages/rspack/src/builtin-loader/swc/types.ts @@ -2,10 +2,10 @@ * Some types are modified from https://github.com/swc-project/swc/blob/16a38851/packages/types/index.ts#L647 * license at https://github.com/swc-project/swc/blob/main/LICENSE */ -import type { ReactOptions } from "./react"; -import type { RelayOptions } from "./relay"; import type { EmotionOptions } from "./emotion"; import type { PluginImportOptions } from "./pluginImport"; +import type { ReactOptions } from "./react"; +import type { RelayOptions } from "./relay"; export type StyledComponentsOptions = { displayName?: boolean; diff --git a/packages/rspack/src/builtin-plugin/APIPlugin.ts b/packages/rspack/src/builtin-plugin/APIPlugin.ts index bba832d1f4b1..a663b722172d 100644 --- a/packages/rspack/src/builtin-plugin/APIPlugin.ts +++ b/packages/rspack/src/builtin-plugin/APIPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const APIPlugin = create(BuiltinPluginName.APIPlugin, () => {}); diff --git a/packages/rspack/src/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.ts b/packages/rspack/src/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.ts index b4adcc116c9e..50ea5717e5a4 100644 --- a/packages/rspack/src/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const ArrayPushCallbackChunkFormatPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/AssetModulesPlugin.ts b/packages/rspack/src/builtin-plugin/AssetModulesPlugin.ts index 8670c866a1d0..25c4f16b0194 100644 --- a/packages/rspack/src/builtin-plugin/AssetModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/AssetModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const AssetModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/AsyncWebAssemblyModulesPlugin.ts b/packages/rspack/src/builtin-plugin/AsyncWebAssemblyModulesPlugin.ts index ca668bfb854c..6807a19d1ded 100644 --- a/packages/rspack/src/builtin-plugin/AsyncWebAssemblyModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/AsyncWebAssemblyModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const AsyncWebAssemblyModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/BannerPlugin.ts b/packages/rspack/src/builtin-plugin/BannerPlugin.ts index a3a61d14a736..4e00af4cc736 100644 --- a/packages/rspack/src/builtin-plugin/BannerPlugin.ts +++ b/packages/rspack/src/builtin-plugin/BannerPlugin.ts @@ -1,9 +1,10 @@ -import { z } from "zod"; import { BuiltinPluginName, JsChunk, RawBannerPluginOptions } from "@rspack/binding"; +import { z } from "zod"; + import { create } from "./base"; const rule = z.string().or(z.instanceof(RegExp)); diff --git a/packages/rspack/src/builtin-plugin/BundlerInfoRspackPlugin.ts b/packages/rspack/src/builtin-plugin/BundlerInfoRspackPlugin.ts index aa47ca873660..a8d0c331b6a6 100644 --- a/packages/rspack/src/builtin-plugin/BundlerInfoRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/BundlerInfoRspackPlugin.ts @@ -2,6 +2,7 @@ import { BuiltinPluginName, RawBundlerInfoPluginOptions } from "@rspack/binding"; + import { create } from "./base"; export type BundleInfoOptions = { diff --git a/packages/rspack/src/builtin-plugin/ChunkPrefetchPreloadPlugin.ts b/packages/rspack/src/builtin-plugin/ChunkPrefetchPreloadPlugin.ts index 266b00cd7732..d030f2819bba 100644 --- a/packages/rspack/src/builtin-plugin/ChunkPrefetchPreloadPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ChunkPrefetchPreloadPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const ChunkPrefetchPreloadPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/CommonJsChunkFormatPlugin.ts b/packages/rspack/src/builtin-plugin/CommonJsChunkFormatPlugin.ts index 80477cd74202..5f13212b3d6a 100644 --- a/packages/rspack/src/builtin-plugin/CommonJsChunkFormatPlugin.ts +++ b/packages/rspack/src/builtin-plugin/CommonJsChunkFormatPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const CommonJsChunkFormatPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/CopyRspackPlugin.ts b/packages/rspack/src/builtin-plugin/CopyRspackPlugin.ts index d2e13ac26da9..595690f450bb 100644 --- a/packages/rspack/src/builtin-plugin/CopyRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/CopyRspackPlugin.ts @@ -3,6 +3,7 @@ import { RawCopyPattern, RawCopyRspackPluginOptions } from "@rspack/binding"; + import { create } from "./base"; export type CopyRspackPluginOptions = { diff --git a/packages/rspack/src/builtin-plugin/CssModulesPlugin.ts b/packages/rspack/src/builtin-plugin/CssModulesPlugin.ts index e9ad8da95c87..ff8ece51dca5 100644 --- a/packages/rspack/src/builtin-plugin/CssModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/CssModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const CssModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/DataUriPlugin.ts b/packages/rspack/src/builtin-plugin/DataUriPlugin.ts index 0e2828285f01..7af35c662c42 100644 --- a/packages/rspack/src/builtin-plugin/DataUriPlugin.ts +++ b/packages/rspack/src/builtin-plugin/DataUriPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const DataUriPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/DefinePlugin.ts b/packages/rspack/src/builtin-plugin/DefinePlugin.ts index 357d09d2788b..44821fbff184 100644 --- a/packages/rspack/src/builtin-plugin/DefinePlugin.ts +++ b/packages/rspack/src/builtin-plugin/DefinePlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export type DefinePluginOptions = Record; diff --git a/packages/rspack/src/builtin-plugin/DeterministicChunkIdsPlugin.ts b/packages/rspack/src/builtin-plugin/DeterministicChunkIdsPlugin.ts index 8a3c88736998..c10786716ac4 100644 --- a/packages/rspack/src/builtin-plugin/DeterministicChunkIdsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/DeterministicChunkIdsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const DeterministicChunkIdsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/DeterministicModuleIdsPlugin.ts b/packages/rspack/src/builtin-plugin/DeterministicModuleIdsPlugin.ts index 93a8c4117413..d626d4d99a83 100644 --- a/packages/rspack/src/builtin-plugin/DeterministicModuleIdsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/DeterministicModuleIdsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const DeterministicModuleIdsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/DynamicEntryPlugin.ts b/packages/rspack/src/builtin-plugin/DynamicEntryPlugin.ts index 38837aee72e4..3fafce543f99 100644 --- a/packages/rspack/src/builtin-plugin/DynamicEntryPlugin.ts +++ b/packages/rspack/src/builtin-plugin/DynamicEntryPlugin.ts @@ -2,9 +2,10 @@ import { BuiltinPluginName, RawDynamicEntryPluginOptions } from "@rspack/binding"; -import { create } from "./base"; + import { EntryDynamicNormalized } from "../config"; import EntryOptionPlugin from "../lib/EntryOptionPlugin"; +import { create } from "./base"; import { getRawEntryOptions } from "./EntryPlugin"; export const DynamicEntryPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/ElectronTargetPlugin.ts b/packages/rspack/src/builtin-plugin/ElectronTargetPlugin.ts index 05b26cfe9414..966b4e50603a 100644 --- a/packages/rspack/src/builtin-plugin/ElectronTargetPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ElectronTargetPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const ElectronTargetPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/EnableChunkLoadingPlugin.ts b/packages/rspack/src/builtin-plugin/EnableChunkLoadingPlugin.ts index fe26ce965bb3..a66f3f8f5d2b 100644 --- a/packages/rspack/src/builtin-plugin/EnableChunkLoadingPlugin.ts +++ b/packages/rspack/src/builtin-plugin/EnableChunkLoadingPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const EnableChunkLoadingPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/EnableLibraryPlugin.ts b/packages/rspack/src/builtin-plugin/EnableLibraryPlugin.ts index f01ea2fb238d..2b3508d8c32d 100644 --- a/packages/rspack/src/builtin-plugin/EnableLibraryPlugin.ts +++ b/packages/rspack/src/builtin-plugin/EnableLibraryPlugin.ts @@ -1,6 +1,7 @@ import { BuiltinPlugin, BuiltinPluginName } from "@rspack/binding"; -import { RspackBuiltinPlugin, createBuiltinPlugin } from "./base"; + import { Compiler, LibraryType } from ".."; +import { createBuiltinPlugin, RspackBuiltinPlugin } from "./base"; const enabledTypes = new WeakMap(); diff --git a/packages/rspack/src/builtin-plugin/EnableWasmLoadingPlugin.ts b/packages/rspack/src/builtin-plugin/EnableWasmLoadingPlugin.ts index 61976bb03085..d23e54ea4a46 100644 --- a/packages/rspack/src/builtin-plugin/EnableWasmLoadingPlugin.ts +++ b/packages/rspack/src/builtin-plugin/EnableWasmLoadingPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const EnableWasmLoadingPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/EnsureChunkConditionsPlugin.ts b/packages/rspack/src/builtin-plugin/EnsureChunkConditionsPlugin.ts index ecb383255d18..38029d590e9a 100644 --- a/packages/rspack/src/builtin-plugin/EnsureChunkConditionsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/EnsureChunkConditionsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const EnsureChunkConditionsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/EntryPlugin.ts b/packages/rspack/src/builtin-plugin/EntryPlugin.ts index 3162f6ab4972..b08b50d33731 100644 --- a/packages/rspack/src/builtin-plugin/EntryPlugin.ts +++ b/packages/rspack/src/builtin-plugin/EntryPlugin.ts @@ -3,17 +3,18 @@ import { RawEntryOptions, RawEntryPluginOptions } from "@rspack/binding"; -import { create } from "./base"; + import { ChunkLoading, EntryRuntime, FilenameTemplate, - LibraryOptions, - PublicPath, getRawChunkLoading, - getRawLibrary + getRawLibrary, + LibraryOptions, + PublicPath } from "../config"; import { isNil } from "../util"; +import { create } from "./base"; export type EntryOptions = { name?: string; diff --git a/packages/rspack/src/builtin-plugin/EvalDevToolModulePlugin.ts b/packages/rspack/src/builtin-plugin/EvalDevToolModulePlugin.ts index 830053f6242f..b2da80ab3e7f 100644 --- a/packages/rspack/src/builtin-plugin/EvalDevToolModulePlugin.ts +++ b/packages/rspack/src/builtin-plugin/EvalDevToolModulePlugin.ts @@ -2,6 +2,7 @@ import { BuiltinPluginName, RawEvalDevToolModulePluginOptions } from "@rspack/binding"; + import { create } from "./base"; export type { RawEvalDevToolModulePluginOptions as EvalDevToolModulePluginOptions }; diff --git a/packages/rspack/src/builtin-plugin/EvalSourceMapDevToolPlugin.ts b/packages/rspack/src/builtin-plugin/EvalSourceMapDevToolPlugin.ts index 9008a69bd51a..40d39b29d6ff 100644 --- a/packages/rspack/src/builtin-plugin/EvalSourceMapDevToolPlugin.ts +++ b/packages/rspack/src/builtin-plugin/EvalSourceMapDevToolPlugin.ts @@ -2,6 +2,7 @@ import { BuiltinPluginName, RawSourceMapDevToolPluginOptions } from "@rspack/binding"; + import { create } from "./base"; import { SourceMapDevToolPluginOptions } from "./SourceMapDevToolPlugin"; diff --git a/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts b/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts index 00f2b777fb1f..d150c81def5b 100644 --- a/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts @@ -1,6 +1,7 @@ import { BuiltinPluginName, RawExternalsPluginOptions } from "@rspack/binding"; -import { create } from "./base"; + import { ExternalItem, ExternalItemValue, Externals } from ".."; +import { create } from "./base"; export const ExternalsPlugin = create( BuiltinPluginName.ExternalsPlugin, diff --git a/packages/rspack/src/builtin-plugin/FileUriPlugin.ts b/packages/rspack/src/builtin-plugin/FileUriPlugin.ts index 73a35eaddc6d..0bf57631ba0a 100644 --- a/packages/rspack/src/builtin-plugin/FileUriPlugin.ts +++ b/packages/rspack/src/builtin-plugin/FileUriPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const FileUriPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/FlagDependencyExportsPlugin.ts b/packages/rspack/src/builtin-plugin/FlagDependencyExportsPlugin.ts index 51b8965c9919..8c7fe2e5d5a7 100644 --- a/packages/rspack/src/builtin-plugin/FlagDependencyExportsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/FlagDependencyExportsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const FlagDependencyExportsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/FlagDependencyUsagePlugin.ts b/packages/rspack/src/builtin-plugin/FlagDependencyUsagePlugin.ts index c6077a4a14ec..ea4f4253ec37 100644 --- a/packages/rspack/src/builtin-plugin/FlagDependencyUsagePlugin.ts +++ b/packages/rspack/src/builtin-plugin/FlagDependencyUsagePlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const FlagDependencyUsagePlugin = create( diff --git a/packages/rspack/src/builtin-plugin/HotModuleReplacementPlugin.ts b/packages/rspack/src/builtin-plugin/HotModuleReplacementPlugin.ts index 90f8e86d3f2b..b069939c37fa 100644 --- a/packages/rspack/src/builtin-plugin/HotModuleReplacementPlugin.ts +++ b/packages/rspack/src/builtin-plugin/HotModuleReplacementPlugin.ts @@ -1,6 +1,7 @@ import { BuiltinPlugin, BuiltinPluginName } from "@rspack/binding"; + import { Compiler } from "../Compiler"; -import { RspackBuiltinPlugin, createBuiltinPlugin } from "./base"; +import { createBuiltinPlugin, RspackBuiltinPlugin } from "./base"; export class HotModuleReplacementPlugin extends RspackBuiltinPlugin { name = BuiltinPluginName.HotModuleReplacementPlugin; diff --git a/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts b/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts index 84f5f0a00bb1..debf28554add 100644 --- a/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts @@ -1,7 +1,8 @@ -import { z } from "zod"; import { BuiltinPluginName, RawHtmlRspackPluginOptions } from "@rspack/binding"; -import { create } from "./base"; +import { z } from "zod"; + import { validate } from "../util/validate"; +import { create } from "./base"; const htmlRspackPluginOptions = z.strictObject({ filename: z.string().optional(), diff --git a/packages/rspack/src/builtin-plugin/HttpExternalsRspackPlugin.ts b/packages/rspack/src/builtin-plugin/HttpExternalsRspackPlugin.ts index 4a1ec9addebc..e162d8270e38 100644 --- a/packages/rspack/src/builtin-plugin/HttpExternalsRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/HttpExternalsRspackPlugin.ts @@ -2,6 +2,7 @@ import { BuiltinPluginName, RawHttpExternalsRspackPluginOptions } from "@rspack/binding"; + import { create } from "./base"; export const HttpExternalsRspackPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/IgnorePlugin.ts b/packages/rspack/src/builtin-plugin/IgnorePlugin.ts index 319a7f85b76c..56e9a5c007c2 100644 --- a/packages/rspack/src/builtin-plugin/IgnorePlugin.ts +++ b/packages/rspack/src/builtin-plugin/IgnorePlugin.ts @@ -1,5 +1,6 @@ import { BuiltinPluginName, RawIgnorePluginOptions } from "@rspack/binding"; import { z } from "zod"; + import { validate } from "../util/validate"; import { create } from "./base"; diff --git a/packages/rspack/src/builtin-plugin/InferAsyncModulesPlugin.ts b/packages/rspack/src/builtin-plugin/InferAsyncModulesPlugin.ts index 89af2f172ee3..ac8104e1c1d8 100644 --- a/packages/rspack/src/builtin-plugin/InferAsyncModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/InferAsyncModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const InferAsyncModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts b/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts index 4dd829247d33..308665f1f2a3 100644 --- a/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const JavascriptModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/JsLoaderRspackPlugin.ts b/packages/rspack/src/builtin-plugin/JsLoaderRspackPlugin.ts index 97ec1d0169e3..e2de082fe93e 100644 --- a/packages/rspack/src/builtin-plugin/JsLoaderRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/JsLoaderRspackPlugin.ts @@ -1,7 +1,8 @@ import { BuiltinPluginName } from "@rspack/binding"; -import { create } from "./base"; -import { runLoaders } from "../loader-runner"; + import { Compiler } from "../Compiler"; +import { runLoaders } from "../loader-runner"; +import { create } from "./base"; export const JsLoaderRspackPlugin = create( BuiltinPluginName.JsLoaderRspackPlugin, diff --git a/packages/rspack/src/builtin-plugin/JsonModulesPlugin.ts b/packages/rspack/src/builtin-plugin/JsonModulesPlugin.ts index f97b3c9b93fd..31cb748551b1 100644 --- a/packages/rspack/src/builtin-plugin/JsonModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/JsonModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const JsonModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/LimitChunkCountPlugin.ts b/packages/rspack/src/builtin-plugin/LimitChunkCountPlugin.ts index 561676f90772..9c40370cda02 100644 --- a/packages/rspack/src/builtin-plugin/LimitChunkCountPlugin.ts +++ b/packages/rspack/src/builtin-plugin/LimitChunkCountPlugin.ts @@ -2,6 +2,7 @@ import { BuiltinPluginName, RawLimitChunkCountPluginOptions } from "@rspack/binding"; + import { create } from "./base"; export type LimitChunkCountOptions = { diff --git a/packages/rspack/src/builtin-plugin/MangleExportsPlugin.ts b/packages/rspack/src/builtin-plugin/MangleExportsPlugin.ts index 73e3574675ec..1add03c58cff 100644 --- a/packages/rspack/src/builtin-plugin/MangleExportsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/MangleExportsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const MangleExportsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/MergeDuplicateChunksPlugin.ts b/packages/rspack/src/builtin-plugin/MergeDuplicateChunksPlugin.ts index 00b8e439e31d..c5cf0a8f4f37 100644 --- a/packages/rspack/src/builtin-plugin/MergeDuplicateChunksPlugin.ts +++ b/packages/rspack/src/builtin-plugin/MergeDuplicateChunksPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const MergeDuplicateChunksPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/ModuleChunkFormatPlugin.ts b/packages/rspack/src/builtin-plugin/ModuleChunkFormatPlugin.ts index e770b1fb9f36..b4f8fa9bf744 100644 --- a/packages/rspack/src/builtin-plugin/ModuleChunkFormatPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ModuleChunkFormatPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const ModuleChunkFormatPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/ModuleConcatenationPlugin.ts b/packages/rspack/src/builtin-plugin/ModuleConcatenationPlugin.ts index fccd839299c9..afea7544f56e 100644 --- a/packages/rspack/src/builtin-plugin/ModuleConcatenationPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ModuleConcatenationPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const ModuleConcatenationPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/NamedChunkIdsPlugin.ts b/packages/rspack/src/builtin-plugin/NamedChunkIdsPlugin.ts index 7bbf9b0599ef..a52a7222e1f8 100644 --- a/packages/rspack/src/builtin-plugin/NamedChunkIdsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/NamedChunkIdsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const NamedChunkIdsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/NamedModuleIdsPlugin.ts b/packages/rspack/src/builtin-plugin/NamedModuleIdsPlugin.ts index 6c71f707dddf..42067b4b25b6 100644 --- a/packages/rspack/src/builtin-plugin/NamedModuleIdsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/NamedModuleIdsPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const NamedModuleIdsPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/NodeTargetPlugin.ts b/packages/rspack/src/builtin-plugin/NodeTargetPlugin.ts index dc6918c8c4ae..bfdcc9cc3742 100644 --- a/packages/rspack/src/builtin-plugin/NodeTargetPlugin.ts +++ b/packages/rspack/src/builtin-plugin/NodeTargetPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const NodeTargetPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/ProgressPlugin.ts b/packages/rspack/src/builtin-plugin/ProgressPlugin.ts index 0766a51ebbeb..2a56938c108c 100644 --- a/packages/rspack/src/builtin-plugin/ProgressPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ProgressPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName, RawProgressPluginOptions } from "@rspack/binding"; + import { create } from "./base"; export type ProgressPluginArgument = diff --git a/packages/rspack/src/builtin-plugin/ProvidePlugin.ts b/packages/rspack/src/builtin-plugin/ProvidePlugin.ts index b513bce407ee..e703e0a1933e 100644 --- a/packages/rspack/src/builtin-plugin/ProvidePlugin.ts +++ b/packages/rspack/src/builtin-plugin/ProvidePlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export type ProvidePluginOptions = Record; diff --git a/packages/rspack/src/builtin-plugin/RealContentHashPlugin.ts b/packages/rspack/src/builtin-plugin/RealContentHashPlugin.ts index 47c75dad6afd..9031184df87e 100644 --- a/packages/rspack/src/builtin-plugin/RealContentHashPlugin.ts +++ b/packages/rspack/src/builtin-plugin/RealContentHashPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const RealContentHashPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/RemoveEmptyChunksPlugin.ts b/packages/rspack/src/builtin-plugin/RemoveEmptyChunksPlugin.ts index 7b4e8e983d11..decbcb8bfcc2 100644 --- a/packages/rspack/src/builtin-plugin/RemoveEmptyChunksPlugin.ts +++ b/packages/rspack/src/builtin-plugin/RemoveEmptyChunksPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const RemoveEmptyChunksPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/RuntimeChunkPlugin.ts b/packages/rspack/src/builtin-plugin/RuntimeChunkPlugin.ts index 53e4fa81cf98..a733d192e397 100644 --- a/packages/rspack/src/builtin-plugin/RuntimeChunkPlugin.ts +++ b/packages/rspack/src/builtin-plugin/RuntimeChunkPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName, RawRuntimeChunkOptions } from "@rspack/binding"; + import { create } from "./base"; export type RuntimeChunkPluginOptions = RawRuntimeChunkOptions; diff --git a/packages/rspack/src/builtin-plugin/RuntimePlugin.ts b/packages/rspack/src/builtin-plugin/RuntimePlugin.ts index 17ea32a367d1..5a638e3141cb 100644 --- a/packages/rspack/src/builtin-plugin/RuntimePlugin.ts +++ b/packages/rspack/src/builtin-plugin/RuntimePlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const RuntimePlugin = create( diff --git a/packages/rspack/src/builtin-plugin/SideEffectsFlagPlugin.ts b/packages/rspack/src/builtin-plugin/SideEffectsFlagPlugin.ts index cdec0b5c7152..a7c673bb6395 100644 --- a/packages/rspack/src/builtin-plugin/SideEffectsFlagPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SideEffectsFlagPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const SideEffectsFlagPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/SizeLimitsPlugin.ts b/packages/rspack/src/builtin-plugin/SizeLimitsPlugin.ts index 1eeb5f837e3f..dd051e1ea78b 100644 --- a/packages/rspack/src/builtin-plugin/SizeLimitsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SizeLimitsPlugin.ts @@ -1,6 +1,7 @@ import { BuiltinPluginName, RawSizeLimitsPluginOptions } from "@rspack/binding"; -import { create } from "./base"; + import { Performance } from ".."; +import { create } from "./base"; export const SizeLimitsPlugin = create( BuiltinPluginName.SizeLimitsPlugin, diff --git a/packages/rspack/src/builtin-plugin/SourceMapDevToolPlugin.ts b/packages/rspack/src/builtin-plugin/SourceMapDevToolPlugin.ts index eb1e04401a51..996e79e2f991 100644 --- a/packages/rspack/src/builtin-plugin/SourceMapDevToolPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SourceMapDevToolPlugin.ts @@ -2,6 +2,7 @@ import { BuiltinPluginName, RawSourceMapDevToolPluginOptions } from "@rspack/binding"; + import { matchObject } from "../lib/ModuleFilenameHelpers"; import { create } from "./base"; diff --git a/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts b/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts index 750238ffb3ce..510341e63c9e 100644 --- a/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts @@ -1,7 +1,3 @@ -import assert from "assert"; -import { type OptimizationSplitChunksOptions } from "../config/zod"; -import { RspackBuiltinPlugin, createBuiltinPlugin } from "./base"; -import { Compiler } from "../Compiler"; import { BuiltinPlugin, BuiltinPluginName, @@ -10,8 +6,13 @@ import { RawCacheGroupOptions, RawSplitChunksOptions } from "@rspack/binding"; -import { Module } from "../Module"; +import assert from "assert"; + import { Chunk } from "../Chunk"; +import { Compiler } from "../Compiler"; +import { type OptimizationSplitChunksOptions } from "../config/zod"; +import { Module } from "../Module"; +import { createBuiltinPlugin, RspackBuiltinPlugin } from "./base"; export class SplitChunksPlugin extends RspackBuiltinPlugin { name = BuiltinPluginName.SplitChunksPlugin; diff --git a/packages/rspack/src/builtin-plugin/SwcCssMinimizerPlugin.ts b/packages/rspack/src/builtin-plugin/SwcCssMinimizerPlugin.ts index 61b2c8b92436..75ddb11fb146 100644 --- a/packages/rspack/src/builtin-plugin/SwcCssMinimizerPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SwcCssMinimizerPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const SwcCssMinimizerRspackPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts b/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts index 35437cbb4c13..93ee6a98fea5 100644 --- a/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts @@ -3,6 +3,7 @@ import { RawExtractComments, RawSwcJsMinimizerRspackPluginOptions } from "@rspack/binding"; + import { create } from "./base"; type MinifyCondition = string | RegExp; diff --git a/packages/rspack/src/builtin-plugin/WarnCaseSensitiveModulesPlugin.ts b/packages/rspack/src/builtin-plugin/WarnCaseSensitiveModulesPlugin.ts index 4be8664c3df9..4f2092461b8c 100644 --- a/packages/rspack/src/builtin-plugin/WarnCaseSensitiveModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/WarnCaseSensitiveModulesPlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const WarnCaseSensitiveModulesPlugin = create( diff --git a/packages/rspack/src/builtin-plugin/WebWorkerTemplatePlugin.ts b/packages/rspack/src/builtin-plugin/WebWorkerTemplatePlugin.ts index 35d532b1c9fa..12d1f900d26c 100644 --- a/packages/rspack/src/builtin-plugin/WebWorkerTemplatePlugin.ts +++ b/packages/rspack/src/builtin-plugin/WebWorkerTemplatePlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "./base"; export const WebWorkerTemplatePlugin = create( diff --git a/packages/rspack/src/builtin-plugin/WorkerPlugin.ts b/packages/rspack/src/builtin-plugin/WorkerPlugin.ts index 0848a0d37ebf..516e6606f4f1 100644 --- a/packages/rspack/src/builtin-plugin/WorkerPlugin.ts +++ b/packages/rspack/src/builtin-plugin/WorkerPlugin.ts @@ -1,12 +1,13 @@ import { BuiltinPlugin, BuiltinPluginName } from "@rspack/binding"; -import { RspackBuiltinPlugin, createBuiltinPlugin } from "./base"; + +import { Compiler } from "../Compiler"; import { ChunkLoading, OutputModule, WasmLoading, WorkerPublicPath } from "../config"; -import { Compiler } from "../Compiler"; +import { createBuiltinPlugin, RspackBuiltinPlugin } from "./base"; import { EnableChunkLoadingPlugin } from "./EnableChunkLoadingPlugin"; import { EnableWasmLoadingPlugin } from "./EnableWasmLoadingPlugin"; diff --git a/packages/rspack/src/builtin-plugin/base.ts b/packages/rspack/src/builtin-plugin/base.ts index 9d076e25d0c5..e756cf7da6d9 100644 --- a/packages/rspack/src/builtin-plugin/base.ts +++ b/packages/rspack/src/builtin-plugin/base.ts @@ -1,4 +1,5 @@ import * as binding from "@rspack/binding"; + import { Compiler, RspackPluginInstance } from ".."; type AffectedHooks = keyof Compiler["hooks"]; diff --git a/packages/rspack/src/builtin-plugin/css-extract/index.ts b/packages/rspack/src/builtin-plugin/css-extract/index.ts index f9975e759144..f22e27191580 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/index.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/index.ts @@ -1,4 +1,5 @@ import type { RawCssExtractPluginOption } from "@rspack/binding"; + import { Compiler } from "../.."; import { MODULE_TYPE } from "./loader"; diff --git a/packages/rspack/src/builtin-plugin/css-extract/loader.ts b/packages/rspack/src/builtin-plugin/css-extract/loader.ts index b51663b984f6..19788187b0d6 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/loader.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/loader.ts @@ -1,9 +1,9 @@ -import schema from "./loader-options.json"; -import { CssExtractRspackPlugin } from "./index"; import path from "path"; -import { stringifyLocal, stringifyRequest } from "./utils"; import type { LoaderContext, LoaderDefinition } from "../.."; +import { CssExtractRspackPlugin } from "./index"; +import schema from "./loader-options.json"; +import { stringifyLocal, stringifyRequest } from "./utils"; export const MODULE_TYPE = "css/mini-extract"; export const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__"; diff --git a/packages/rspack/src/builtin-plugin/css-extract/utils.ts b/packages/rspack/src/builtin-plugin/css-extract/utils.ts index 2d52f19f0fa3..c321932ff196 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/utils.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/utils.ts @@ -1,6 +1,7 @@ -import { LoaderContext } from "../.."; import path from "path"; +import { LoaderContext } from "../.."; + export function isAbsolutePath(str: string) { return path.posix.isAbsolute(str) || path.win32.isAbsolute(str); } diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index c9c99cd55d63..4e8c7222b31a 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -1,69 +1,67 @@ +export * from "./APIPlugin"; +export * from "./ArrayPushCallbackChunkFormatPlugin"; +export * from "./AssetModulesPlugin"; +export * from "./AsyncWebAssemblyModulesPlugin"; +export * from "./BannerPlugin"; export { RspackBuiltinPlugin } from "./base"; - +export * from "./BundlerInfoRspackPlugin"; +export * from "./ChunkPrefetchPreloadPlugin"; +export * from "./CommonJsChunkFormatPlugin"; +export * from "./CopyRspackPlugin"; +export * from "./css-extract"; +export * from "./CssModulesPlugin"; +export * from "./DataUriPlugin"; export * from "./DefinePlugin"; -export * from "./ProvidePlugin"; -export * from "./BannerPlugin"; -export * from "./IgnorePlugin"; -export * from "./ProgressPlugin"; -export * from "./EntryPlugin"; +export * from "./DeterministicChunkIdsPlugin"; +export * from "./DeterministicModuleIdsPlugin"; export * from "./DynamicEntryPlugin"; -export * from "./ExternalsPlugin"; -export * from "./NodeTargetPlugin"; export * from "./ElectronTargetPlugin"; -export * from "./HttpExternalsRspackPlugin"; export * from "./EnableChunkLoadingPlugin"; export * from "./EnableLibraryPlugin"; export * from "./EnableWasmLoadingPlugin"; -export * from "./ChunkPrefetchPreloadPlugin"; -export * from "./ArrayPushCallbackChunkFormatPlugin"; -export * from "./CommonJsChunkFormatPlugin"; -export * from "./ModuleChunkFormatPlugin"; +export * from "./EnsureChunkConditionsPlugin"; +export * from "./EntryPlugin"; +export * from "./EvalDevToolModulePlugin"; +export * from "./EvalSourceMapDevToolPlugin"; +export * from "./ExternalsPlugin"; +export * from "./FileUriPlugin"; +export * from "./FlagDependencyExportsPlugin"; +export * from "./FlagDependencyUsagePlugin"; export * from "./HotModuleReplacementPlugin"; -export * from "./WebWorkerTemplatePlugin"; -export * from "./WorkerPlugin"; +export * from "./HtmlRspackPlugin"; +export * from "./HttpExternalsRspackPlugin"; +export * from "./IgnorePlugin"; +export * from "./InferAsyncModulesPlugin"; +export * from "./JavascriptModulesPlugin"; +export * from "./JsLoaderRspackPlugin"; +export * from "./JsonModulesPlugin"; export * from "./LimitChunkCountPlugin"; +export * from "./MangleExportsPlugin"; export * from "./MergeDuplicateChunksPlugin"; -export * from "./SplitChunksPlugin"; -export * from "./NamedModuleIdsPlugin"; -export * from "./DeterministicModuleIdsPlugin"; +export * from "./ModuleChunkFormatPlugin"; +export * from "./ModuleConcatenationPlugin"; export * from "./NamedChunkIdsPlugin"; -export * from "./DeterministicChunkIdsPlugin"; +export * from "./NamedModuleIdsPlugin"; +export * from "./NodeTargetPlugin"; +export * from "./ProgressPlugin"; +export * from "./ProvidePlugin"; export * from "./RealContentHashPlugin"; export * from "./RemoveEmptyChunksPlugin"; -export * from "./EnsureChunkConditionsPlugin"; -export * from "./WarnCaseSensitiveModulesPlugin"; -export * from "./DataUriPlugin"; -export * from "./FileUriPlugin"; +export * from "./RuntimeChunkPlugin"; export * from "./RuntimePlugin"; -export * from "./JsonModulesPlugin"; -export * from "./InferAsyncModulesPlugin"; -export * from "./JavascriptModulesPlugin"; -export * from "./AsyncWebAssemblyModulesPlugin"; -export * from "./AssetModulesPlugin"; -export * from "./SourceMapDevToolPlugin"; -export * from "./EvalSourceMapDevToolPlugin"; -export * from "./EvalDevToolModulePlugin"; export * from "./SideEffectsFlagPlugin"; -export * from "./FlagDependencyExportsPlugin"; -export * from "./FlagDependencyUsagePlugin"; -export * from "./MangleExportsPlugin"; -export * from "./BundlerInfoRspackPlugin"; -export * from "./ModuleConcatenationPlugin"; -export * from "./CssModulesPlugin"; -export * from "./APIPlugin"; -export * from "./RuntimeChunkPlugin"; export * from "./SizeLimitsPlugin"; - -export * from "./HtmlRspackPlugin"; -export * from "./CopyRspackPlugin"; -export * from "./SwcJsMinimizerPlugin"; +export * from "./SourceMapDevToolPlugin"; +export * from "./SplitChunksPlugin"; export * from "./SwcCssMinimizerPlugin"; - -export * from "./JsLoaderRspackPlugin"; -export * from "./css-extract"; +export * from "./SwcJsMinimizerPlugin"; +export * from "./WarnCaseSensitiveModulesPlugin"; +export * from "./WebWorkerTemplatePlugin"; +export * from "./WorkerPlugin"; ///// DEPRECATED ///// import { RawBuiltins } from "@rspack/binding"; + import { RspackOptionsNormalized } from ".."; function resolveTreeShaking( diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 4b450c6d8e55..d2490f9cee54 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -1,79 +1,80 @@ import type { - RawModuleRule, - RawOptions, - RawRuleSetCondition, - RawRuleSetLogicalConditions, - RawGeneratorOptions, RawAssetGeneratorOptions, - RawParserOptions, - RawAssetParserOptions, - RawAssetParserDataUrl, RawAssetInlineGeneratorOptions, + RawAssetParserDataUrl, + RawAssetParserOptions, RawAssetResourceGeneratorOptions, - RawModuleRuleUses, + RawCssAutoGeneratorOptions, + RawCssAutoParserOptions, + RawCssGeneratorOptions, + RawCssModuleGeneratorOptions, + RawCssModuleParserOptions, + RawCssParserOptions, RawFuncUseCtx, - RawRspackFuture, + RawGeneratorOptions, + RawJavascriptParserOptions, RawLibraryName, RawLibraryOptions, + RawModuleRule, RawModuleRuleUse, - RawCssParserOptions, - RawCssAutoParserOptions, - RawCssModuleParserOptions, - RawCssGeneratorOptions, - RawCssAutoGeneratorOptions, - RawCssModuleGeneratorOptions, - RawJavascriptParserOptions + RawModuleRuleUses, + RawOptions, + RawParserOptions, + RawRspackFuture, + RawRuleSetCondition, + RawRuleSetLogicalConditions } from "@rspack/binding"; import assert from "assert"; + import { Compiler } from "../Compiler"; import { normalizeStatsPreset } from "../Stats"; import { isNil } from "../util"; import { parseResource } from "../util/identifier"; import { ComposeJsUseOptions, - LoaderContext, createRawModuleRuleUses, + LoaderContext, LoaderDefinition, LoaderDefinitionFunction } from "./adapterRuleUse"; import { + ExperimentsNormalized, + ModuleOptionsNormalized, + OutputNormalized, + RspackOptionsNormalized +} from "./normalization"; +import { + AssetGeneratorDataUrl, + AssetGeneratorOptions, + AssetInlineGeneratorOptions, + AssetParserDataUrl, + AssetParserOptions, + AssetResourceGeneratorOptions, + ChunkLoading, CrossOriginLoading, + CssAutoGeneratorOptions, + CssAutoParserOptions, + CssGeneratorOptions, + CssModuleGeneratorOptions, + CssModuleParserOptions, + CssParserOptions, + EntryRuntime, + GeneratorOptionsByModuleType, + JavascriptParserOptions, + LibraryName, LibraryOptions, Node, Optimization, + ParserOptionsByModuleType, Resolve, + RspackFutureOptions, RuleSetCondition, RuleSetLogicalConditions, RuleSetRule, SnapshotOptions, StatsValue, - Target, - AssetGeneratorDataUrl, - AssetGeneratorOptions, - AssetInlineGeneratorOptions, - AssetResourceGeneratorOptions, - AssetParserDataUrl, - AssetParserOptions, - ParserOptionsByModuleType, - GeneratorOptionsByModuleType, - RspackFutureOptions, - JavascriptParserOptions, - LibraryName, - EntryRuntime, - ChunkLoading, - CssParserOptions, - CssAutoParserOptions, - CssModuleParserOptions, - CssGeneratorOptions, - CssAutoGeneratorOptions, - CssModuleGeneratorOptions + Target } from "./zod"; -import { - ExperimentsNormalized, - ModuleOptionsNormalized, - OutputNormalized, - RspackOptionsNormalized -} from "./normalization"; export type { LoaderContext, LoaderDefinition, LoaderDefinitionFunction }; diff --git a/packages/rspack/src/config/adapterRuleUse.ts b/packages/rspack/src/config/adapterRuleUse.ts index 2003cd9e1dc7..b9df6cff83b6 100644 --- a/packages/rspack/src/config/adapterRuleUse.ts +++ b/packages/rspack/src/config/adapterRuleUse.ts @@ -9,9 +9,6 @@ import { ResolveRequest } from "enhanced-resolve"; import { Compiler } from "../Compiler"; import { Logger } from "../logging/Logger"; import Hash = require("../util/hash"); -import { Mode, Resolve, RuleSetUseItem, RuleSetLoaderWithOptions } from "./zod"; -import { parsePathQueryFragment } from "../loader-runner"; -import { isNil } from "../util"; import { resolveEmotion, resolvePluginImport, @@ -19,6 +16,9 @@ import { resolveRelay } from "../builtin-loader"; import { Compilation } from "../Compilation"; +import { parsePathQueryFragment } from "../loader-runner"; +import { isNil } from "../util"; +import { Mode, Resolve, RuleSetLoaderWithOptions, RuleSetUseItem } from "./zod"; const BUILTIN_LOADER_PREFIX = "builtin:"; diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 7ef138877ab5..1c47851fbe21 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -11,8 +11,16 @@ import assert from "assert"; import fs from "fs"; import path from "path"; + import { isNil } from "../util"; import { cleverMerge } from "../util/cleverMerge"; +import { + EntryDescriptionNormalized, + EntryNormalized, + ExperimentsNormalized, + OutputNormalized, + RspackOptionsNormalized +} from "./normalization"; import { getDefaultTarget, getTargetProperties, @@ -33,18 +41,11 @@ import type { RuleSetRules, SnapshotOptions } from "./zod"; -import { - EntryDescriptionNormalized, - EntryNormalized, - ExperimentsNormalized, - OutputNormalized, - RspackOptionsNormalized -} from "./normalization"; import Template = require("../Template"); -import { assertNotNill } from "../util/assertNotNil"; -import { ASSET_MODULE_TYPE } from "../ModuleTypeConstants"; -import { SwcJsMinimizerRspackPlugin } from "../builtin-plugin/SwcJsMinimizerPlugin"; import { SwcCssMinimizerRspackPlugin } from "../builtin-plugin/SwcCssMinimizerPlugin"; +import { SwcJsMinimizerRspackPlugin } from "../builtin-plugin/SwcJsMinimizerPlugin"; +import { ASSET_MODULE_TYPE } from "../ModuleTypeConstants"; +import { assertNotNill } from "../util/assertNotNil"; export const applyRspackOptionsDefaults = ( options: RspackOptionsNormalized diff --git a/packages/rspack/src/config/index.ts b/packages/rspack/src/config/index.ts index 9c9dac3ac3c9..c5ff5087d5d3 100644 --- a/packages/rspack/src/config/index.ts +++ b/packages/rspack/src/config/index.ts @@ -1,4 +1,4 @@ +export * from "./adapter"; +export * from "./defaults"; export * from "./normalization"; export * from "./zod"; -export * from "./defaults"; -export * from "./adapter"; diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 54e6e23e5458..a65f78e60222 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -9,78 +9,79 @@ */ import assert from "assert"; + import type { Compilation } from "../Compilation"; import type { + AssetModuleFilename, + Bail, + Builtins, + CacheOptions, + ChunkFilename, + ChunkLoading, + ChunkLoadingGlobal, + Clean, Context, + CrossOriginLoading, + CssChunkFilename, + CssFilename, Dependencies, - Node, + DevServer, DevTool, + DevtoolFallbackModuleFilenameTemplate, + DevtoolModuleFilenameTemplate, + DevtoolNamespace, + EnabledLibraryTypes, + EnabledWasmLoadingTypes, + EntryFilename, + EntryRuntime, EntryStatic, Externals, ExternalsPresets, ExternalsType, + Filename, + GeneratorOptionsByModuleType, + GlobalObject, + HashDigest, + HashDigestLength, + HashFunction, + HashSalt, + HotUpdateChunkFilename, + HotUpdateGlobal, + HotUpdateMainFilename, + Iife, + ImportFunctionName, InfrastructureLogging, LibraryOptions, Mode, Name, - OptimizationRuntimeChunk, - Resolve, - Target, - SnapshotOptions, - CacheOptions, - StatsValue, + Node, + NoParseOption, Optimization, + OptimizationRuntimeChunk, + OutputModule, + ParserOptionsByModuleType, + Path, Performance, Plugins, - Watch, - WatchOptions, - DevServer, Profile, - Bail, - Builtins, - EntryRuntime, - ChunkLoading, PublicPath, - EntryFilename, - Path, - Clean, - Filename, - ChunkFilename, - CrossOriginLoading, - CssFilename, - CssChunkFilename, - HotUpdateMainFilename, - HotUpdateChunkFilename, - AssetModuleFilename, - UniqueName, - ChunkLoadingGlobal, - EnabledLibraryTypes, - OutputModule, + Resolve, + RspackFutureOptions, + RspackOptions, + RuleSetRules, + ScriptType, + SnapshotOptions, + SourceMapFilename, + StatsValue, StrictModuleErrorHandling, - GlobalObject, - ImportFunctionName, - Iife, + Target, + TrustedTypes, + UniqueName, WasmLoading, - EnabledWasmLoadingTypes, + Watch, + WatchOptions, WebassemblyModuleFilename, - TrustedTypes, - SourceMapFilename, - HashDigest, - HashDigestLength, - HashFunction, - HashSalt, - WorkerPublicPath, - RuleSetRules, - ParserOptionsByModuleType, - GeneratorOptionsByModuleType, - RspackFutureOptions, - HotUpdateGlobal, - ScriptType, - NoParseOption, - DevtoolNamespace, - DevtoolModuleFilenameTemplate, - DevtoolFallbackModuleFilenameTemplate, - RspackOptions + WorkerPublicPath } from "./zod"; export const getNormalizedRspackOptions = ( diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index 05fdadf971b0..4df41a676c99 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -1,12 +1,13 @@ -import { RawFuncUseCtx, JsAssetInfo } from "@rspack/binding"; +import { JsAssetInfo, RawFuncUseCtx } from "@rspack/binding"; +import type * as webpackDevServer from "webpack-dev-server"; import { z } from "zod"; + import { Compilation, Compiler } from ".."; import type { Builtins as BuiltinsType } from "../builtin-plugin"; -import type * as webpackDevServer from "webpack-dev-server"; -import { deprecatedWarn } from "../util"; -import { Module } from "../Module"; import { Chunk } from "../Chunk"; import { PathData } from "../Compilation"; +import { Module } from "../Module"; +import { deprecatedWarn } from "../util"; //#region Name const name = z.string(); diff --git a/packages/rspack/src/container/ContainerPlugin.ts b/packages/rspack/src/container/ContainerPlugin.ts index 81500abfd9d3..736c75af0747 100644 --- a/packages/rspack/src/container/ContainerPlugin.ts +++ b/packages/rspack/src/container/ContainerPlugin.ts @@ -1,22 +1,23 @@ import { - RawContainerPluginOptions, BuiltinPlugin, - BuiltinPluginName + BuiltinPluginName, + RawContainerPluginOptions } from "@rspack/binding"; + import { - RspackBuiltinPlugin, - createBuiltinPlugin + createBuiltinPlugin, + RspackBuiltinPlugin } from "../builtin-plugin/base"; +import { Compiler } from "../Compiler"; import { EntryRuntime, FilenameTemplate, - LibraryOptions, - getRawLibrary + getRawLibrary, + LibraryOptions } from "../config"; -import { isNil } from "../util"; import { parseOptions } from "../container/options"; -import { Compiler } from "../Compiler"; import { ShareRuntimePlugin } from "../sharing/ShareRuntimePlugin"; +import { isNil } from "../util"; export type ContainerPluginOptions = { exposes: Exposes; diff --git a/packages/rspack/src/container/ContainerReferencePlugin.ts b/packages/rspack/src/container/ContainerReferencePlugin.ts index b8dad83555f0..62c0c518b879 100644 --- a/packages/rspack/src/container/ContainerReferencePlugin.ts +++ b/packages/rspack/src/container/ContainerReferencePlugin.ts @@ -3,15 +3,16 @@ import { BuiltinPluginName, RawContainerReferencePluginOptions } from "@rspack/binding"; + import { - RspackBuiltinPlugin, - createBuiltinPlugin + createBuiltinPlugin, + RspackBuiltinPlugin } from "../builtin-plugin/base"; -import { Compiler } from "../Compiler"; import { ExternalsPlugin } from "../builtin-plugin/ExternalsPlugin"; +import { Compiler } from "../Compiler"; import { ExternalsType } from "../config"; -import { parseOptions } from "./options"; import { ShareRuntimePlugin } from "../sharing/ShareRuntimePlugin"; +import { parseOptions } from "./options"; export type ContainerReferencePluginOptions = { remoteType: ExternalsType; diff --git a/packages/rspack/src/container/ModuleFederationPlugin.ts b/packages/rspack/src/container/ModuleFederationPlugin.ts index b359483b0513..cfc5c5c2f1c5 100644 --- a/packages/rspack/src/container/ModuleFederationPlugin.ts +++ b/packages/rspack/src/container/ModuleFederationPlugin.ts @@ -1,9 +1,9 @@ -import { ExternalsType, externalsType } from "../config"; import { Compiler } from "../Compiler"; -import { type ModuleFederationPluginV1Options } from "./ModuleFederationPluginV1"; -import { parseOptions } from "./options"; +import { ExternalsType, externalsType } from "../config"; import { isValidate } from "../util/validate"; +import { type ModuleFederationPluginV1Options } from "./ModuleFederationPluginV1"; import { ModuleFederationRuntimePlugin } from "./ModuleFederationRuntimePlugin"; +import { parseOptions } from "./options"; export interface ModuleFederationPluginOptions extends Omit { diff --git a/packages/rspack/src/container/ModuleFederationPluginV1.ts b/packages/rspack/src/container/ModuleFederationPluginV1.ts index 1bcd18c4213a..af60680dda78 100644 --- a/packages/rspack/src/container/ModuleFederationPluginV1.ts +++ b/packages/rspack/src/container/ModuleFederationPluginV1.ts @@ -1,15 +1,15 @@ import { Compiler } from "../Compiler"; import { - LibraryOptions, EntryRuntime, ExternalsType, - externalsType + externalsType, + LibraryOptions } from "../config"; -import { SharePlugin, Shared } from "../sharing/SharePlugin"; +import { Shared, SharePlugin } from "../sharing/SharePlugin"; +import { ShareRuntimePlugin } from "../sharing/ShareRuntimePlugin"; import { isValidate } from "../util/validate"; import { ContainerPlugin, Exposes } from "./ContainerPlugin"; import { ContainerReferencePlugin, Remotes } from "./ContainerReferencePlugin"; -import { ShareRuntimePlugin } from "../sharing/ShareRuntimePlugin"; export interface ModuleFederationPluginV1Options { exposes?: Exposes; diff --git a/packages/rspack/src/container/ModuleFederationRuntimePlugin.ts b/packages/rspack/src/container/ModuleFederationRuntimePlugin.ts index cf022c781281..68c9390044e9 100644 --- a/packages/rspack/src/container/ModuleFederationRuntimePlugin.ts +++ b/packages/rspack/src/container/ModuleFederationRuntimePlugin.ts @@ -1,4 +1,5 @@ import { BuiltinPluginName } from "@rspack/binding"; + import { create } from "../builtin-plugin/base"; export const ModuleFederationRuntimePlugin = create( diff --git a/packages/rspack/src/exports.ts b/packages/rspack/src/exports.ts index 5f74748e0329..c27039ec9b5c 100644 --- a/packages/rspack/src/exports.ts +++ b/packages/rspack/src/exports.ts @@ -1,45 +1,37 @@ const { version: rspackVersion, webpackVersion } = require("../package.json"); -export { webpackVersion as version, rspackVersion }; +export { rspackVersion, webpackVersion as version }; -export { Compiler } from "./Compiler"; - -export { Compilation } from "./Compilation"; export type { Asset, AssetInfo, Assets, - LogEntry, - CompilationParams + CompilationParams, + LogEntry } from "./Compilation"; - -export { MultiCompiler } from "./MultiCompiler"; +export { Compilation } from "./Compilation"; +export { Compiler } from "./Compiler"; export type { MultiCompilerOptions, MultiRspackOptions } from "./MultiCompiler"; +export { MultiCompiler } from "./MultiCompiler"; import { RspackOptionsApply } from "./rspackOptionsApply"; export { RspackOptionsApply, RspackOptionsApply as WebpackOptionsApply }; +export type { Chunk } from "./Chunk"; +export type { ChunkGroup } from "./ChunkGroup"; +export type { Module } from "./Module"; +export { MultiStats } from "./MultiStats"; +export { NormalModule } from "./NormalModule"; +export type { NormalModuleFactory } from "./NormalModuleFactory"; export { RuntimeGlobals } from "./RuntimeGlobals"; - -export { Stats } from "./Stats"; export type { - StatsCompilation, StatsAsset, StatsChunk, + StatsCompilation, StatsError, StatsModule, StatsWarnings } from "./Stats"; - -export { MultiStats } from "./MultiStats"; - -export type { Chunk } from "./Chunk"; -export type { ChunkGroup } from "./ChunkGroup"; - -export type { NormalModuleFactory } from "./NormalModuleFactory"; - -export type { Module } from "./Module"; - -export { NormalModule } from "./NormalModule"; +export { Stats } from "./Stats"; // API extractor not working with some re-exports, see: https://github.com/microsoft/fluentui/issues/20694 import * as ModuleFilenameHelpers from "./lib/ModuleFilenameHelpers"; @@ -57,8 +49,8 @@ const sources = require("webpack-sources"); // use require to avoid wrong types, export { sources }; import { - getNormalizedRspackOptions, - applyRspackOptionsDefaults + applyRspackOptionsDefaults, + getNormalizedRspackOptions } from "./config"; // Explicitly define this type to avoid type inference and type expansion. @@ -77,54 +69,40 @@ export const config: Config = { export type * from "./config"; -import { createHash } from "./util/createHash"; import { cachedCleverMerge as cleverMerge } from "./util/cleverMerge"; +import { createHash } from "./util/createHash"; export const util = { createHash, cleverMerge }; +export { default as EntryOptionPlugin } from "./lib/EntryOptionPlugin"; export { type OutputFileSystem } from "./util/fs"; - export { - registerGlobalTrace as experimental_registerGlobalTrace, - cleanupGlobalTrace as experimental_cleanupGlobalTrace + cleanupGlobalTrace as experimental_cleanupGlobalTrace, + registerGlobalTrace as experimental_registerGlobalTrace } from "@rspack/binding"; -export { default as EntryOptionPlugin } from "./lib/EntryOptionPlugin"; - ///// Internal Plugins ///// -export { BannerPlugin } from "./builtin-plugin"; export type { BannerPluginArgument } from "./builtin-plugin"; - +export type { ProvidePluginOptions } from "./builtin-plugin"; +export type { DefinePluginOptions } from "./builtin-plugin"; +export type { ProgressPluginArgument } from "./builtin-plugin"; +export type { EntryOptions } from "./builtin-plugin"; +export { BannerPlugin } from "./builtin-plugin"; export { IgnorePlugin, type IgnorePluginOptions } from "./builtin-plugin"; - export { ProvidePlugin } from "./builtin-plugin"; -export type { ProvidePluginOptions } from "./builtin-plugin"; - export { DefinePlugin } from "./builtin-plugin"; -export type { DefinePluginOptions } from "./builtin-plugin"; - export { ProgressPlugin } from "./builtin-plugin"; -export type { ProgressPluginArgument } from "./builtin-plugin"; - export { EntryPlugin } from "./builtin-plugin"; -export type { EntryOptions } from "./builtin-plugin"; - export { DynamicEntryPlugin } from "./builtin-plugin"; - export { ExternalsPlugin } from "./builtin-plugin"; - export { HotModuleReplacementPlugin } from "./builtin-plugin"; - +export { EnvironmentPlugin } from "./lib/EnvironmentPlugin"; export { LoaderOptionsPlugin } from "./lib/LoaderOptionsPlugin"; - export { LoaderTargetPlugin } from "./lib/LoaderTargetPlugin"; - -export { EnvironmentPlugin } from "./lib/EnvironmentPlugin"; - export { NormalModuleReplacementPlugin } from "./lib/NormalModuleReplacementPlugin"; -import NodeTemplatePlugin from "./node/NodeTemplatePlugin"; import { NodeTargetPlugin } from "./builtin-plugin"; import NodeEnvironmentPlugin from "./node/NodeEnvironmentPlugin"; +import NodeTemplatePlugin from "./node/NodeTemplatePlugin"; interface Node { NodeTargetPlugin: typeof NodeTargetPlugin; NodeTemplatePlugin: typeof NodeTemplatePlugin; @@ -189,18 +167,18 @@ import { ContainerReferencePlugin } from "./container/ContainerReferencePlugin"; export type { ContainerPluginOptions, Exposes, + ExposesConfig, ExposesItem, ExposesItems, - ExposesObject, - ExposesConfig + ExposesObject } from "./container/ContainerPlugin"; export type { ContainerReferencePluginOptions, Remotes, + RemotesConfig, RemotesItem, RemotesItems, - RemotesObject, - RemotesConfig + RemotesObject } from "./container/ContainerReferencePlugin"; export const container = { ContainerPlugin, @@ -209,29 +187,29 @@ export const container = { ModuleFederationPluginV1 }; -import { ProvideSharedPlugin } from "./sharing/ProvideSharedPlugin"; import { ConsumeSharedPlugin } from "./sharing/ConsumeSharedPlugin"; +import { ProvideSharedPlugin } from "./sharing/ProvideSharedPlugin"; import { SharePlugin } from "./sharing/SharePlugin"; export type { - ProvideSharedPluginOptions, - Provides, - ProvidesConfig, - ProvidesItem, - ProvidesObject -} from "./sharing/ProvideSharedPlugin"; -export type { - ConsumeSharedPluginOptions, Consumes, ConsumesConfig, + ConsumeSharedPluginOptions, ConsumesItem, ConsumesObject } from "./sharing/ConsumeSharedPlugin"; export type { - SharePluginOptions, + Provides, + ProvidesConfig, + ProvideSharedPluginOptions, + ProvidesItem, + ProvidesObject +} from "./sharing/ProvideSharedPlugin"; +export type { Shared, SharedConfig, SharedItem, - SharedObject + SharedObject, + SharePluginOptions } from "./sharing/SharePlugin"; export const sharing = { ProvideSharedPlugin, @@ -240,38 +218,32 @@ export const sharing = { }; ///// Rspack Postfixed Internal Plugins ///// -export { HtmlRspackPlugin } from "./builtin-plugin"; export type { HtmlRspackPluginOptions } from "./builtin-plugin"; - -export { SwcJsMinimizerRspackPlugin } from "./builtin-plugin"; export type { SwcJsMinimizerRspackPluginOptions } from "./builtin-plugin"; - +export type { CopyRspackPluginOptions } from "./builtin-plugin"; +export type { SourceMapDevToolPluginOptions } from "./builtin-plugin"; +export type { EvalDevToolModulePluginOptions } from "./builtin-plugin"; +export type { + CssExtractRspackLoaderOptions, + CssExtractRspackPluginOptions +} from "./builtin-plugin"; +export { HtmlRspackPlugin } from "./builtin-plugin"; +export { SwcJsMinimizerRspackPlugin } from "./builtin-plugin"; export { SwcCssMinimizerRspackPlugin } from "./builtin-plugin"; - export { CopyRspackPlugin } from "./builtin-plugin"; -export type { CopyRspackPluginOptions } from "./builtin-plugin"; - export { SourceMapDevToolPlugin } from "./builtin-plugin"; export { EvalSourceMapDevToolPlugin } from "./builtin-plugin"; -export type { SourceMapDevToolPluginOptions } from "./builtin-plugin"; - export { EvalDevToolModulePlugin } from "./builtin-plugin"; -export type { EvalDevToolModulePluginOptions } from "./builtin-plugin"; - export { CssExtractRspackPlugin } from "./builtin-plugin"; -export type { - CssExtractRspackPluginOptions, - CssExtractRspackLoaderOptions -} from "./builtin-plugin"; ///// Rspack Postfixed Internal Loaders ///// export type { - SwcLoaderOptions, SwcLoaderEnvConfig, + SwcLoaderEsParserConfig, SwcLoaderJscConfig, SwcLoaderModuleConfig, + SwcLoaderOptions, SwcLoaderParserConfig, - SwcLoaderEsParserConfig, - SwcLoaderTsParserConfig, - SwcLoaderTransformConfig + SwcLoaderTransformConfig, + SwcLoaderTsParserConfig } from "./builtin-loader/swc/index"; diff --git a/packages/rspack/src/fileSystem.ts b/packages/rspack/src/fileSystem.ts index 2f455593ce27..e031bcedbd25 100644 --- a/packages/rspack/src/fileSystem.ts +++ b/packages/rspack/src/fileSystem.ts @@ -1,8 +1,8 @@ -import util from "util"; import { ThreadsafeNodeFS } from "@rspack/binding"; +import util from "util"; +import { mkdirp, OutputFileSystem, rmrf } from "./util/fs"; import { memoizeFn } from "./util/memoize"; -import { OutputFileSystem, rmrf, mkdirp } from "./util/fs"; const NOOP_FILESYSTEM: ThreadsafeNodeFS = { writeFile() {}, diff --git a/packages/rspack/src/index.ts b/packages/rspack/src/index.ts index 2c2fb3205208..50f0d932aee9 100644 --- a/packages/rspack/src/index.ts +++ b/packages/rspack/src/index.ts @@ -1,5 +1,5 @@ -import { rspack as rspackFn } from "./rspack"; import * as rspackExports from "./exports"; +import { rspack as rspackFn } from "./rspack"; // add exports on rspack() function type Rspack = typeof rspackFn & typeof rspackExports & { rspack: Rspack; webpack: Rspack }; diff --git a/packages/rspack/src/lib/EntryOptionPlugin.ts b/packages/rspack/src/lib/EntryOptionPlugin.ts index 4c596fae117a..9e7ff8e4a8c1 100644 --- a/packages/rspack/src/lib/EntryOptionPlugin.ts +++ b/packages/rspack/src/lib/EntryOptionPlugin.ts @@ -9,6 +9,7 @@ */ import assert from "assert"; + import { Compiler, EntryDescriptionNormalized, EntryNormalized } from ".."; import { DynamicEntryPlugin, diff --git a/packages/rspack/src/lib/NormalModuleReplacementPlugin.ts b/packages/rspack/src/lib/NormalModuleReplacementPlugin.ts index 478fa98c8aa5..ee8eae38099c 100644 --- a/packages/rspack/src/lib/NormalModuleReplacementPlugin.ts +++ b/packages/rspack/src/lib/NormalModuleReplacementPlugin.ts @@ -4,9 +4,10 @@ * Original Author Tobias Koppers @sokra */ +import * as NodePath from "node:path"; + import { Compiler } from "../Compiler"; import { ResolveData } from "../Module"; -import * as NodePath from "node:path"; type ModuleReplacer = (createData: ResolveData) => void; diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index d1b6e59b6518..f92c0298392c 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -16,23 +16,24 @@ import { SourceMapSource } from "webpack-sources"; -import { Compiler } from "../Compiler"; -import { NormalModule } from "../NormalModule"; import { Compilation } from "../Compilation"; +import { Compiler } from "../Compiler"; import { - LoaderContext, - LoaderObject, isUseSimpleSourceMap, - isUseSourceMap + isUseSourceMap, + LoaderContext, + LoaderObject } from "../config/adapterRuleUse"; +import { NormalModule } from "../NormalModule"; import { concatErrorMsgAndStack, isNil, serializeObject, + stringifyLoaderObject, toBuffer, - toObject, - stringifyLoaderObject + toObject } from "../util"; +import { createHash } from "../util/createHash"; import { absolutify, contextify, @@ -40,7 +41,6 @@ import { parseResourceWithoutFragment } from "../util/identifier"; import { memoize } from "../util/memoize"; -import { createHash } from "../util/createHash"; import loadLoader = require("./loadLoader"); const querystring = require("node:querystring"); diff --git a/packages/rspack/src/logging/createConsoleLogger.ts b/packages/rspack/src/logging/createConsoleLogger.ts index 2e84184b5e61..0bb9bc79181b 100644 --- a/packages/rspack/src/logging/createConsoleLogger.ts +++ b/packages/rspack/src/logging/createConsoleLogger.ts @@ -115,9 +115,8 @@ export = ({ level = "info", debug = false, console }: any) => { switch (type) { case LogType.debug: if (!debug) return; - // eslint-disable-next-line node/no-unsupported-features/node-builtins + if (typeof console.debug === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.debug(...labeledArgs()); } else { console.log(...labeledArgs()); @@ -146,9 +145,7 @@ export = ({ level = "info", debug = false, console }: any) => { case LogType.groupCollapsed: if (!debug && loglevel > LogLevel.log) return; if (!debug && loglevel > LogLevel.verbose) { - // eslint-disable-next-line node/no-unsupported-features/node-builtins if (typeof console.groupCollapsed === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.groupCollapsed(...labeledArgs()); } else { console.log(...labeledArgs()); @@ -158,9 +155,8 @@ export = ({ level = "info", debug = false, console }: any) => { // falls through case LogType.group: if (!debug && loglevel > LogLevel.log) return; - // eslint-disable-next-line node/no-unsupported-features/node-builtins + if (typeof console.group === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.group(...labeledArgs()); } else { console.log(...labeledArgs()); @@ -168,9 +164,8 @@ export = ({ level = "info", debug = false, console }: any) => { break; case LogType.groupEnd: if (!debug && loglevel > LogLevel.log) return; - // eslint-disable-next-line node/no-unsupported-features/node-builtins + if (typeof console.groupEnd === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.groupEnd(); } break; @@ -186,24 +181,19 @@ export = ({ level = "info", debug = false, console }: any) => { break; } case LogType.profile: - // eslint-disable-next-line node/no-unsupported-features/node-builtins if (typeof console.profile === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.profile(...labeledArgs()); } break; case LogType.profileEnd: - // eslint-disable-next-line node/no-unsupported-features/node-builtins if (typeof console.profileEnd === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.profileEnd(...labeledArgs()); } break; case LogType.clear: if (!debug && loglevel > LogLevel.log) return; - // eslint-disable-next-line node/no-unsupported-features/node-builtins + if (typeof console.clear === "function") { - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.clear(); } break; diff --git a/packages/rspack/src/node/NodeEnvironmentPlugin.ts b/packages/rspack/src/node/NodeEnvironmentPlugin.ts index 20379e50c27f..88672660016e 100644 --- a/packages/rspack/src/node/NodeEnvironmentPlugin.ts +++ b/packages/rspack/src/node/NodeEnvironmentPlugin.ts @@ -10,11 +10,12 @@ // @ts-expect-error import CachedInputFileSystem from "enhanced-resolve/lib/CachedInputFileSystem"; import fs from "graceful-fs"; + +import type { Compiler } from ".."; +import type { InfrastructureLogging } from "../config"; import createConsoleLogger from "../logging/createConsoleLogger"; -import NodeWatchFileSystem from "./NodeWatchFileSystem"; import nodeConsole from "./nodeConsole"; -import type { InfrastructureLogging } from "../config"; -import type { Compiler } from ".."; +import NodeWatchFileSystem from "./NodeWatchFileSystem"; export interface NodeEnvironmentPluginOptions { infrastructureLogging: InfrastructureLogging; diff --git a/packages/rspack/src/node/NodeTemplatePlugin.ts b/packages/rspack/src/node/NodeTemplatePlugin.ts index c9f64bb76536..c0f2d2da3ba2 100644 --- a/packages/rspack/src/node/NodeTemplatePlugin.ts +++ b/packages/rspack/src/node/NodeTemplatePlugin.ts @@ -8,11 +8,11 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ -import { Compiler } from "../Compiler"; import { CommonJsChunkFormatPlugin, EnableChunkLoadingPlugin } from "../builtin-plugin"; +import { Compiler } from "../Compiler"; export type NodeTemplatePluginOptions = { asyncChunkLoading?: boolean }; diff --git a/packages/rspack/src/node/NodeWatchFileSystem.ts b/packages/rspack/src/node/NodeWatchFileSystem.ts index 35378a181931..26c66c89625d 100644 --- a/packages/rspack/src/node/NodeWatchFileSystem.ts +++ b/packages/rspack/src/node/NodeWatchFileSystem.ts @@ -10,6 +10,7 @@ import util from "util"; import Watchpack from "watchpack"; + import { FileSystemInfoEntry, Watcher, WatchFileSystem } from "../util/fs"; export default class NodeWatchFileSystem implements WatchFileSystem { diff --git a/packages/rspack/src/node/nodeConsole.ts b/packages/rspack/src/node/nodeConsole.ts index 9e8c2c8d15b7..3b5401efc387 100644 --- a/packages/rspack/src/node/nodeConsole.ts +++ b/packages/rspack/src/node/nodeConsole.ts @@ -112,19 +112,18 @@ export = ({ colors, appendOnly, stream }) => { else if (currentIndent.length >= 2) currentIndent = currentIndent.slice(0, currentIndent.length - 2); }, - // eslint-disable-next-line node/no-unsupported-features/node-builtins + // @ts-expect-error profile: console.profile && (name => console.profile(name)), - // eslint-disable-next-line node/no-unsupported-features/node-builtins + // @ts-expect-error profileEnd: console.profileEnd && (name => console.profileEnd(name)), clear: !appendOnly && - // eslint-disable-next-line node/no-unsupported-features/node-builtins console.clear && (() => { clearStatusMessage(); - // eslint-disable-next-line node/no-unsupported-features/node-builtins + console.clear(); writeStatusMessage(); }), diff --git a/packages/rspack/src/rspack.ts b/packages/rspack/src/rspack.ts index 64d33f0ec51e..aa496915fd32 100644 --- a/packages/rspack/src/rspack.ts +++ b/packages/rspack/src/rspack.ts @@ -7,28 +7,28 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ +import assert from "assert"; +import { Callback } from "tapable"; +import util from "util"; + +import { Compiler } from "./Compiler"; import { - getNormalizedRspackOptions, - RspackOptions, applyRspackOptionsBaseDefaults, applyRspackOptionsDefaults, - RspackPluginFunction, - rspackOptions + getNormalizedRspackOptions, + RspackOptions, + rspackOptions, + RspackPluginFunction } from "./config"; -import { Compiler } from "./Compiler"; -import { Stats } from "./Stats"; -import util from "util"; - -import { RspackOptionsApply } from "./rspackOptionsApply"; -import NodeEnvironmentPlugin from "./node/NodeEnvironmentPlugin"; import { MultiCompiler, MultiCompilerOptions, MultiRspackOptions } from "./MultiCompiler"; -import { Callback } from "tapable"; import MultiStats from "./MultiStats"; -import assert from "assert"; +import NodeEnvironmentPlugin from "./node/NodeEnvironmentPlugin"; +import { RspackOptionsApply } from "./rspackOptionsApply"; +import { Stats } from "./Stats"; import { asArray, isNil } from "./util"; import { validate } from "./util/validate"; @@ -157,5 +157,5 @@ function rspack( } // deliberately alias rspack as webpack -export { rspack, createCompiler, createMultiCompiler, Stats, MultiStats }; +export { createCompiler, createMultiCompiler, MultiStats, rspack, Stats }; export default rspack; diff --git a/packages/rspack/src/rspackOptionsApply.ts b/packages/rspack/src/rspackOptionsApply.ts index 9b606bad933a..0ed88eef1804 100644 --- a/packages/rspack/src/rspackOptionsApply.ts +++ b/packages/rspack/src/rspackOptionsApply.ts @@ -7,68 +7,68 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ +import assert from "assert"; +import fs from "graceful-fs"; + import { - RspackOptionsNormalized, Compiler, OptimizationRuntimeChunkNormalized, + RspackOptionsNormalized, RspackPluginFunction } from "."; -import fs from "graceful-fs"; - -import { DefaultStatsFactoryPlugin } from "./stats/DefaultStatsFactoryPlugin"; -import { DefaultStatsPrinterPlugin } from "./stats/DefaultStatsPrinterPlugin"; -import { cleverMerge } from "./util/cleverMerge"; -import assert from "assert"; -import IgnoreWarningsPlugin from "./lib/ignoreWarningsPlugin"; -import EntryOptionPlugin from "./lib/EntryOptionPlugin"; import { + APIPlugin, ArrayPushCallbackChunkFormatPlugin, + AssetModulesPlugin, + AsyncWebAssemblyModulesPlugin, + BundlerInfoRspackPlugin, + ChunkPrefetchPreloadPlugin, CommonJsChunkFormatPlugin, + CssModulesPlugin, + DataUriPlugin, + DefinePlugin, + DeterministicChunkIdsPlugin, + DeterministicModuleIdsPlugin, ElectronTargetPlugin, EnableChunkLoadingPlugin, EnableLibraryPlugin, EnableWasmLoadingPlugin, + EnsureChunkConditionsPlugin, + EvalDevToolModulePlugin, + EvalSourceMapDevToolPlugin, ExternalsPlugin, + FileUriPlugin, + FlagDependencyExportsPlugin, + FlagDependencyUsagePlugin, HttpExternalsRspackPlugin, - ModuleChunkFormatPlugin, - NodeTargetPlugin, - DefinePlugin, + InferAsyncModulesPlugin, + JavascriptModulesPlugin, + JsLoaderRspackPlugin, + JsonModulesPlugin, + MangleExportsPlugin, MergeDuplicateChunksPlugin, - SplitChunksPlugin, - ChunkPrefetchPreloadPlugin, - NamedModuleIdsPlugin, - DeterministicModuleIdsPlugin, + ModuleChunkFormatPlugin, + ModuleConcatenationPlugin, NamedChunkIdsPlugin, - DeterministicChunkIdsPlugin, + NamedModuleIdsPlugin, + NodeTargetPlugin, RealContentHashPlugin, RemoveEmptyChunksPlugin, - EnsureChunkConditionsPlugin, - WarnCaseSensitiveModulesPlugin, - DataUriPlugin, - FileUriPlugin, - JavascriptModulesPlugin, - JsonModulesPlugin, - AsyncWebAssemblyModulesPlugin, + RuntimeChunkPlugin, RuntimePlugin, - InferAsyncModulesPlugin, - WorkerPlugin, - EvalSourceMapDevToolPlugin, - SourceMapDevToolPlugin, - AssetModulesPlugin, - MangleExportsPlugin, - FlagDependencyExportsPlugin, - FlagDependencyUsagePlugin, SideEffectsFlagPlugin, SizeLimitsPlugin, - BundlerInfoRspackPlugin, - ModuleConcatenationPlugin, - EvalDevToolModulePlugin, - JsLoaderRspackPlugin, - CssModulesPlugin, - APIPlugin, - RuntimeChunkPlugin + SourceMapDevToolPlugin, + SplitChunksPlugin, + WarnCaseSensitiveModulesPlugin, + WorkerPlugin } from "./builtin-plugin"; +import EntryOptionPlugin from "./lib/EntryOptionPlugin"; +import IgnoreWarningsPlugin from "./lib/ignoreWarningsPlugin"; +import { DefaultStatsFactoryPlugin } from "./stats/DefaultStatsFactoryPlugin"; +import { DefaultStatsPrinterPlugin } from "./stats/DefaultStatsPrinterPlugin"; import { assertNotNill } from "./util/assertNotNil"; +import { cleverMerge } from "./util/cleverMerge"; export class RspackOptionsApply { constructor() {} diff --git a/packages/rspack/src/sharing/ConsumeSharedPlugin.ts b/packages/rspack/src/sharing/ConsumeSharedPlugin.ts index 295580c1a265..7ddbcad760e1 100644 --- a/packages/rspack/src/sharing/ConsumeSharedPlugin.ts +++ b/packages/rspack/src/sharing/ConsumeSharedPlugin.ts @@ -3,14 +3,15 @@ import { BuiltinPluginName, RawConsumeSharedPluginOptions } from "@rspack/binding"; -import { Compiler } from "../Compiler"; + import { - RspackBuiltinPlugin, - createBuiltinPlugin + createBuiltinPlugin, + RspackBuiltinPlugin } from "../builtin-plugin/base"; +import { Compiler } from "../Compiler"; import { parseOptions } from "../container/options"; -import { isRequiredVersion } from "./utils"; import { ShareRuntimePlugin } from "./ShareRuntimePlugin"; +import { isRequiredVersion } from "./utils"; export type ConsumeSharedPluginOptions = { consumes: Consumes; diff --git a/packages/rspack/src/sharing/ProvideSharedPlugin.ts b/packages/rspack/src/sharing/ProvideSharedPlugin.ts index f3d0c7aca61b..56a9272fd570 100644 --- a/packages/rspack/src/sharing/ProvideSharedPlugin.ts +++ b/packages/rspack/src/sharing/ProvideSharedPlugin.ts @@ -3,12 +3,13 @@ import { BuiltinPluginName, RawProvideOptions } from "@rspack/binding"; + import { - RspackBuiltinPlugin, - createBuiltinPlugin + createBuiltinPlugin, + RspackBuiltinPlugin } from "../builtin-plugin/base"; -import { parseOptions } from "../container/options"; import { Compiler } from "../Compiler"; +import { parseOptions } from "../container/options"; import { ShareRuntimePlugin } from "./ShareRuntimePlugin"; export type ProvideSharedPluginOptions = { diff --git a/packages/rspack/src/sharing/ShareRuntimePlugin.ts b/packages/rspack/src/sharing/ShareRuntimePlugin.ts index 76c1e096d824..da44123adb00 100644 --- a/packages/rspack/src/sharing/ShareRuntimePlugin.ts +++ b/packages/rspack/src/sharing/ShareRuntimePlugin.ts @@ -1,7 +1,8 @@ import { BuiltinPlugin, BuiltinPluginName } from "@rspack/binding"; + import { - RspackBuiltinPlugin, - createBuiltinPlugin + createBuiltinPlugin, + RspackBuiltinPlugin } from "../builtin-plugin/base"; import { Compiler } from "../Compiler"; diff --git a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts index 64f832dbd667..91f8a2fa8d59 100644 --- a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts +++ b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts @@ -7,40 +7,40 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ -import { compareSelect, compareIds as _compareIds } from "../util/comparators"; -import { makePathsRelative } from "../util/identifier"; import * as util from "node:util"; + import type { Compiler } from "../Compiler"; import type { StatsOptions } from "../config"; -import type { GroupConfig } from "../util/smartGrouping"; - -import type { StatsFactory, KnownStatsFactoryContext } from "./StatsFactory"; import { - iterateConfig, - spaceLimited, - moduleGroup, - countWithChildren, - sortByField, - assetGroup, - resolveStatsMillisecond -} from "./statsFactoryUtils"; + getLogTypeBitFlag, + getLogTypesBitFlag, + LogType, + LogTypeEnum +} from "../logging/Logger"; +import { compareIds as _compareIds, compareSelect } from "../util/comparators"; +import { makePathsRelative } from "../util/identifier"; +import type { GroupConfig } from "../util/smartGrouping"; +import type { KnownStatsFactoryContext, StatsFactory } from "./StatsFactory"; import type { KnownStatsAsset, - KnownStatsModule, KnownStatsChunkGroup, + KnownStatsLoggingEntry, + KnownStatsModule, + NormalizedStatsOptions, SimpleExtractors, StatsAsset, StatsChunk, - NormalizedStatsOptions, - KnownStatsLoggingEntry, StatsProfile } from "./statsFactoryUtils"; import { - LogType, - getLogTypesBitFlag, - getLogTypeBitFlag, - LogTypeEnum -} from "../logging/Logger"; + assetGroup, + countWithChildren, + iterateConfig, + moduleGroup, + resolveStatsMillisecond, + sortByField, + spaceLimited +} from "./statsFactoryUtils"; const compareIds = _compareIds as (a: T, b: T) => -1 | 0 | 1; const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/; diff --git a/packages/rspack/src/stats/StatsFactory.ts b/packages/rspack/src/stats/StatsFactory.ts index ac36a4603c80..f9313dd165fe 100644 --- a/packages/rspack/src/stats/StatsFactory.ts +++ b/packages/rspack/src/stats/StatsFactory.ts @@ -7,11 +7,12 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ +import { JsStats, JsStatsError, JsStatsWarning } from "@rspack/binding"; import { HookMap, SyncBailHook, SyncWaterfallHook } from "tapable"; -import { concatComparators, Comparator } from "../util/comparators"; -import { smartGrouping, GroupConfig } from "../util/smartGrouping"; + import type { Compilation } from "../Compilation"; -import { JsStats, JsStatsError, JsStatsWarning } from "@rspack/binding"; +import { Comparator, concatComparators } from "../util/comparators"; +import { GroupConfig, smartGrouping } from "../util/smartGrouping"; export type KnownStatsFactoryContext = { type: string; diff --git a/packages/rspack/src/stats/StatsPrinter.ts b/packages/rspack/src/stats/StatsPrinter.ts index 9b4736a35679..92faaf17bc54 100644 --- a/packages/rspack/src/stats/StatsPrinter.ts +++ b/packages/rspack/src/stats/StatsPrinter.ts @@ -7,15 +7,16 @@ * Copyright (c) JS Foundation and other contributors * https://github.com/webpack/webpack/blob/main/LICENSE */ -import type { Hook, AsArray } from "tapable"; +import type { AsArray, Hook } from "tapable"; import { HookMap, SyncBailHook, SyncWaterfallHook } from "tapable"; + import type { StatsAsset, StatsChunk, StatsChunkGroup, + StatsCompilation, StatsModule, - StatsModuleReason, - StatsCompilation + StatsModuleReason } from "./statsFactoryUtils"; type PrintedElement = { diff --git a/packages/rspack/src/stats/statsFactoryUtils.ts b/packages/rspack/src/stats/statsFactoryUtils.ts index 8629dbefcc7b..afaf61e0e579 100644 --- a/packages/rspack/src/stats/statsFactoryUtils.ts +++ b/packages/rspack/src/stats/statsFactoryUtils.ts @@ -1,12 +1,12 @@ import * as binding from "@rspack/binding"; + +import type { Compilation } from "../Compilation"; +import type { StatsOptions } from "../config"; import { type Comparator, - compareSelect, - compareIds + compareIds, + compareSelect } from "../util/comparators"; -import type { Compilation } from "../Compilation"; -import type { StatsOptions } from "../config"; - import type { StatsFactory, StatsFactoryContext } from "./StatsFactory"; export type KnownStatsChunkGroup = binding.JsStatsChunkGroup; diff --git a/packages/rspack/src/util/comparators.ts b/packages/rspack/src/util/comparators.ts index 6c0541bf6d19..c3436435eb66 100644 --- a/packages/rspack/src/util/comparators.ts +++ b/packages/rspack/src/util/comparators.ts @@ -9,6 +9,7 @@ */ import type { JsStatsChunk as Chunk } from "@rspack/binding"; + import { ChunkGroup } from "../ChunkGroup"; export type Comparator = (arg0: T, arg1: T) => -1 | 0 | 1; diff --git a/packages/rspack/src/util/fs.ts b/packages/rspack/src/util/fs.ts index c957cb397c8d..a51fa637eae6 100644 --- a/packages/rspack/src/util/fs.ts +++ b/packages/rspack/src/util/fs.ts @@ -8,8 +8,8 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ -import path from "path"; import assert from "assert"; +import path from "path"; import { WatchOptions } from "../config"; diff --git a/packages/rspack/src/util/source.ts b/packages/rspack/src/util/source.ts index 0b596f6abba6..8fa08be0e2ab 100644 --- a/packages/rspack/src/util/source.ts +++ b/packages/rspack/src/util/source.ts @@ -1,6 +1,6 @@ import type { JsCompatSource } from "@rspack/binding"; +import { CompatSource, RawSource, Source } from "webpack-sources"; -import { RawSource, CompatSource, Source } from "webpack-sources"; import { isNil } from "./index"; class JsSource extends Source { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a2f50417150..99c370bdc971 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,12 +29,24 @@ importers: '@types/rimraf': specifier: 3.0.2 version: 3.0.2 + '@typescript-eslint/parser': + specifier: ^7.9.0 + version: 7.9.0(eslint@9.2.0)(typescript@5.0.2) commander: specifier: 12.0.0 version: 12.0.0 cross-env: specifier: ^7.0.3 version: 7.0.3 + eslint: + specifier: ^9.2.0 + version: 9.2.0 + eslint-plugin-oxlint: + specifier: ^0.2.9 + version: 0.2.9 + eslint-plugin-simple-import-sort: + specifier: ^12.1.0 + version: 12.1.0(eslint@9.2.0) filenamify: specifier: ^4.3.0 version: 4.3.0 @@ -57,8 +69,8 @@ importers: specifier: 4.1.5 version: 4.1.5 oxlint: - specifier: 0.2.16 - version: 0.2.16 + specifier: 0.3.4 + version: 0.3.4 prettier: specifier: 3.2.5 version: 3.2.5 @@ -2926,6 +2938,43 @@ packages: dev: false optional: true + /@eslint-community/eslint-utils@4.4.0(eslint@9.2.0): + resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 + dependencies: + eslint: 9.2.0 + eslint-visitor-keys: 3.4.3 + dev: true + + /@eslint-community/regexpp@4.10.0: + resolution: {integrity: sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==} + engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + dev: true + + /@eslint/eslintrc@3.0.2: + resolution: {integrity: sha512-wV19ZEGEMAC1eHgrS7UQPqsdEiCIbTKTasEfcXAigzoXICcqZSjBZEHlZwNVvKg6UBCjSlos84XiLqsRJnIcIg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + ajv: 6.12.6 + debug: 4.3.4 + espree: 10.0.1 + globals: 14.0.0 + ignore: 5.3.1 + import-fresh: 3.3.0 + js-yaml: 4.1.0 + minimatch: 3.1.2 + strip-json-comments: 3.1.1 + transitivePeerDependencies: + - supports-color + dev: true + + /@eslint/js@9.2.0: + resolution: {integrity: sha512-ESiIudvhoYni+MdsI8oD7skpprZ89qKocwRM2KEvhhBJ9nl5MRh7BXU5GTod7Mdygq+AUl+QzId6iWJKR/wABA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + /@fastify/busboy@2.1.1: resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==} engines: {node: '>=14'} @@ -2936,6 +2985,31 @@ packages: engines: {node: '>=12.20'} dev: true + /@humanwhocodes/config-array@0.13.0: + resolution: {integrity: sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==} + engines: {node: '>=10.10.0'} + dependencies: + '@humanwhocodes/object-schema': 2.0.3 + debug: 4.3.4 + minimatch: 3.1.2 + transitivePeerDependencies: + - supports-color + dev: true + + /@humanwhocodes/module-importer@1.0.1: + resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} + engines: {node: '>=12.22'} + dev: true + + /@humanwhocodes/object-schema@2.0.3: + resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} + dev: true + + /@humanwhocodes/retry@0.2.4: + resolution: {integrity: sha512-Ttl/jHpxfS3st5sxwICYfk4pOH0WrLI1SpW283GgQL7sCWU7EHIOhX4b4fkIxr3tkfzwg8+FNojtzsIEE7Ecgg==} + engines: {node: '>=18.18'} + dev: true + /@icons/material@0.2.4(react@17.0.2): resolution: {integrity: sha512-QPcGmICAPbGLGb6F/yNf/KzKqvFx8z5qx3D1yFqVAjoFmXK35EgyW+cJ57Te3CNsmzblwtzakLGFqHPqrfb4Tw==} peerDependencies: @@ -3813,64 +3887,64 @@ packages: '@octokit/openapi-types': 22.0.0 dev: true - /@oxlint/darwin-arm64@0.2.16: - resolution: {integrity: sha512-yYTfmb1cFs/PFyHYSdfi0Yj6MlhllJfhSb8v5ZlzLIJw6qSH28kqIFx8fXVG//PlWBaPpAwjL/DvNxYewLgJYA==} + /@oxlint/darwin-arm64@0.3.4: + resolution: {integrity: sha512-MRoL9iN981B0gXRSHYlXu4NRqgObtl6JaHzOJemmOTnj3H7T9zO7V47+bQk7bWARKClRN7Fzy9IuDFPDqNneTQ==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /@oxlint/darwin-x64@0.2.16: - resolution: {integrity: sha512-MZnCmzw9li0ZLesl7VAKyz4qfEQ6KXrXj5fzR91Pb+Nd4hQcwqtp7gn9N2iY9GpI0M7VzLC1sEzw8jcqT4u7VA==} + /@oxlint/darwin-x64@0.3.4: + resolution: {integrity: sha512-G+GZhDRgrKPRlccIsaXTLlJsdcI+VRgeqMY9kQsWP0GKs3kMkE+oMXIP1/W7rrCLFKEvPDhTEVzWrlnO1sdh1g==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /@oxlint/linux-arm64-gnu@0.2.16: - resolution: {integrity: sha512-esLZ6pDm7x8HWAS2FdaO25i+JN6GniuPPRqP+PevmVoiRscnGlDtRH3ttZW6WefAxCNTAqmsVtUUNp2GY9vA2g==} + /@oxlint/linux-arm64-gnu@0.3.4: + resolution: {integrity: sha512-zWrWLxK1itpFxZBffpT+wskBVmKotaYLmtBvIgr/TrPCsxXQE5Ofvh8/siTds8Q5rhgCAEEdwPijJoNotK8lQQ==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@oxlint/linux-arm64-musl@0.2.16: - resolution: {integrity: sha512-wI+DonxPSJCSCC+GbpG+BkMeiHf70Hvavr+2bQZS3lIwkh41YY3dmFHiETrs0KIrJSk0KEZhbJsVUAKczYOqAQ==} + /@oxlint/linux-arm64-musl@0.3.4: + resolution: {integrity: sha512-aDKg7Q/YYmhA7p29FaOUGkCd6jAZppEdsAM4N+p6+fnL/ZUV/HBQ2GIqGYIH2yCc1oWk7N5CdtrGvMLeR21E6w==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /@oxlint/linux-x64-gnu@0.2.16: - resolution: {integrity: sha512-9FBJ6JnQvfPzx54jQbY1YzgPBN7CQ66YEuH5AgR2Y/Tqqp+hML7a5iViZjyBKNUVbce0kyUtwi5vDzRMLa293w==} + /@oxlint/linux-x64-gnu@0.3.4: + resolution: {integrity: sha512-AVh/ddjdu+kQyeSvhOo1F/qU62StDNliBv2C43k/tspZmRej8oo8Te1wfD95jG9dOwD04/rZiCZw+eOOzxWpHw==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@oxlint/linux-x64-musl@0.2.16: - resolution: {integrity: sha512-MTrzNvhyYmJIZkanlPcH9eXlYv8Bn6TUz08nfQSKDa62qaE+zmIzL0fSMMUD00W7AUuFZYlgtztQMsBqEmwzXg==} + /@oxlint/linux-x64-musl@0.3.4: + resolution: {integrity: sha512-CEktyu/jrszF8hhwB2lyHvMoXYkW2OXvNJ+t+xndpX1FCcK5Oo1rxQuvYhNJv8u6d+aR32aNAyT7GgNhi1LPoQ==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /@oxlint/win32-arm64@0.2.16: - resolution: {integrity: sha512-A8KBa9kezFmKxxM9diemQAokEDt3hiVmKoNiryFOoREdXDslHgwLmVt53FUIn4C9qSD8IwUQUNCJ42Fo1tnYlw==} + /@oxlint/win32-arm64@0.3.4: + resolution: {integrity: sha512-BLhBnI09n+s14TKRA4w6OrUx5GTtVde2lGjdIvnb4uNL7XaD5N9HqRlLKQdRgJo7dbK9PWCoqHovRORSznOgrg==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /@oxlint/win32-x64@0.2.16: - resolution: {integrity: sha512-6tDk2LtK2eSp8ErPaSHrgl7qN7+BE8/nJhJ/Wepg02uYK0ZOFcU4b72PpD0UwFCqHILSxtH1vXshRjrBeSfqoA==} + /@oxlint/win32-x64@0.3.4: + resolution: {integrity: sha512-MRLiStH88hIKHJ4+VzsD8eEmcJuNsfpzwCu7ndnBzdI7q7ujkSecNPdjxtSiNxoFTRDTJT5F48+vesXCHehwXg==} cpu: [x64] os: [win32] requiresBuild: true @@ -6220,6 +6294,70 @@ packages: dependencies: '@types/yargs-parser': 21.0.3 + /@typescript-eslint/parser@7.9.0(eslint@9.2.0)(typescript@5.0.2): + resolution: {integrity: sha512-qHMJfkL5qvgQB2aLvhUSXxbK7OLnDkwPzFalg458pxQgfxKDfT1ZDbHQM/I6mDIf/svlMkj21kzKuQ2ixJlatQ==} + engines: {node: ^18.18.0 || >=20.0.0} + peerDependencies: + eslint: ^8.56.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/scope-manager': 7.9.0 + '@typescript-eslint/types': 7.9.0 + '@typescript-eslint/typescript-estree': 7.9.0(typescript@5.0.2) + '@typescript-eslint/visitor-keys': 7.9.0 + debug: 4.3.4 + eslint: 9.2.0 + typescript: 5.0.2 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/scope-manager@7.9.0: + resolution: {integrity: sha512-ZwPK4DeCDxr3GJltRz5iZejPFAAr4Wk3+2WIBaj1L5PYK5RgxExu/Y68FFVclN0y6GGwH8q+KgKRCvaTmFBbgQ==} + engines: {node: ^18.18.0 || >=20.0.0} + dependencies: + '@typescript-eslint/types': 7.9.0 + '@typescript-eslint/visitor-keys': 7.9.0 + dev: true + + /@typescript-eslint/types@7.9.0: + resolution: {integrity: sha512-oZQD9HEWQanl9UfsbGVcZ2cGaR0YT5476xfWE0oE5kQa2sNK2frxOlkeacLOTh9po4AlUT5rtkGyYM5kew0z5w==} + engines: {node: ^18.18.0 || >=20.0.0} + dev: true + + /@typescript-eslint/typescript-estree@7.9.0(typescript@5.0.2): + resolution: {integrity: sha512-zBCMCkrb2YjpKV3LA0ZJubtKCDxLttxfdGmwZvTqqWevUPN0FZvSI26FalGFFUZU/9YQK/A4xcQF9o/VVaCKAg==} + engines: {node: ^18.18.0 || >=20.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 7.9.0 + '@typescript-eslint/visitor-keys': 7.9.0 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + minimatch: 9.0.4 + semver: 7.6.0 + ts-api-utils: 1.3.0(typescript@5.0.2) + typescript: 5.0.2 + transitivePeerDependencies: + - supports-color + dev: true + + /@typescript-eslint/visitor-keys@7.9.0: + resolution: {integrity: sha512-iESPx2TNLDNGQLyjKhUvIKprlP49XNEK+MvIf9nIO7ZZaZdbnfWKHnXAgufpxqfA0YryH8XToi4+CjBgVnFTSQ==} + engines: {node: ^18.18.0 || >=20.0.0} + dependencies: + '@typescript-eslint/types': 7.9.0 + eslint-visitor-keys: 3.4.3 + dev: true + /@vercel/ncc@0.38.1: resolution: {integrity: sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==} hasBin: true @@ -6559,6 +6697,14 @@ packages: dependencies: acorn: 8.11.3 + /acorn-jsx@5.3.2(acorn@8.11.3): + resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} + peerDependencies: + acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 + dependencies: + acorn: 8.11.3 + dev: true + /acorn-node@1.8.2: resolution: {integrity: sha512-8mt+fslDufLYntIoPAaIMUe/lrbrehIiwmR3t2k9LljIzoigEPF27eLk2hy8zSGzmR/ogr7zbRKINMo1u0yh5A==} dependencies: @@ -8717,6 +8863,10 @@ packages: engines: {node: '>=4.0.0'} dev: true + /deep-is@0.1.4: + resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} + dev: true + /deepmerge@4.3.1: resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} engines: {node: '>=0.10.0'} @@ -9309,6 +9459,18 @@ packages: source-map: 0.6.1 dev: true + /eslint-plugin-oxlint@0.2.9: + resolution: {integrity: sha512-K3aILcHVSSbjJ5W7YxdbMLmoB9G4GHdbDXl9qlPwuWF69BVV2e7/Bpy9osLT+bylv8Y+J6WltsqwXL/Z7sxMgA==} + dev: true + + /eslint-plugin-simple-import-sort@12.1.0(eslint@9.2.0): + resolution: {integrity: sha512-Y2fqAfC11TcG/WP3TrI1Gi3p3nc8XJyEOJYHyEPEGI/UAgNx6akxxlX74p7SbAQdLcgASKhj8M0GKvH3vq/+ig==} + peerDependencies: + eslint: '>=5.0.0' + dependencies: + eslint: 9.2.0 + dev: true + /eslint-scope@5.1.1: resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} engines: {node: '>=8.0.0'} @@ -9316,6 +9478,67 @@ packages: esrecurse: 4.3.0 estraverse: 4.3.0 + /eslint-scope@8.0.1: + resolution: {integrity: sha512-pL8XjgP4ZOmmwfFE8mEhSxA7ZY4C+LWyqjQ3o4yWkkmD0qcMT9kkW3zWHOczhWcjTSgqycYAgwSlXvZltv65og==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + esrecurse: 4.3.0 + estraverse: 5.3.0 + dev: true + + /eslint-visitor-keys@3.4.3: + resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + + /eslint-visitor-keys@4.0.0: + resolution: {integrity: sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + + /eslint@9.2.0: + resolution: {integrity: sha512-0n/I88vZpCOzO+PQpt0lbsqmn9AsnsJAQseIqhZFI8ibQT0U1AkEKRxA3EVMos0BoHSXDQvCXY25TUjB5tr8Og==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + hasBin: true + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@9.2.0) + '@eslint-community/regexpp': 4.10.0 + '@eslint/eslintrc': 3.0.2 + '@eslint/js': 9.2.0 + '@humanwhocodes/config-array': 0.13.0 + '@humanwhocodes/module-importer': 1.0.1 + '@humanwhocodes/retry': 0.2.4 + '@nodelib/fs.walk': 1.2.8 + ajv: 6.12.6 + chalk: 4.1.2 + cross-spawn: 7.0.3 + debug: 4.3.4 + escape-string-regexp: 4.0.0 + eslint-scope: 8.0.1 + eslint-visitor-keys: 4.0.0 + espree: 10.0.1 + esquery: 1.5.0 + esutils: 2.0.3 + fast-deep-equal: 3.1.3 + file-entry-cache: 8.0.0 + find-up: 5.0.0 + glob-parent: 6.0.2 + ignore: 5.3.1 + imurmurhash: 0.1.4 + is-glob: 4.0.3 + is-path-inside: 3.0.3 + json-stable-stringify-without-jsonify: 1.0.1 + levn: 0.4.1 + lodash.merge: 4.6.2 + minimatch: 3.1.2 + natural-compare: 1.4.0 + optionator: 0.9.4 + strip-ansi: 6.0.1 + text-table: 0.2.0 + transitivePeerDependencies: + - supports-color + dev: true + /esniff@2.0.1: resolution: {integrity: sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==} engines: {node: '>=0.10'} @@ -9326,11 +9549,27 @@ packages: type: 2.7.2 dev: true + /espree@10.0.1: + resolution: {integrity: sha512-MWkrWZbJsL2UwnjxTX3gG8FneachS/Mwg7tdGXce011sJd5b0JG54vat5KHnfSBODZ3Wvzd2WnjxyzsRoVv+ww==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + acorn: 8.11.3 + acorn-jsx: 5.3.2(acorn@8.11.3) + eslint-visitor-keys: 4.0.0 + dev: true + /esprima@4.0.1: resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} engines: {node: '>=4'} hasBin: true + /esquery@1.5.0: + resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} + engines: {node: '>=0.10'} + dependencies: + estraverse: 5.3.0 + dev: true + /esrecurse@4.3.0: resolution: {integrity: sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==} engines: {node: '>=4.0'} @@ -9556,6 +9795,10 @@ packages: /fast-json-stable-stringify@2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} + /fast-levenshtein@2.0.6: + resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} + dev: true + /fast-safe-stringify@2.1.1: resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} dev: true @@ -9629,6 +9872,13 @@ packages: escape-string-regexp: 1.0.5 dev: true + /file-entry-cache@8.0.0: + resolution: {integrity: sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==} + engines: {node: '>=16.0.0'} + dependencies: + flat-cache: 4.0.1 + dev: true + /file-loader@6.2.0(webpack@5.90.1): resolution: {integrity: sha512-qo3glqyTa61Ytg4u73GultjHGjdRyig3tG6lPtyX/jOEJvHif9uB0/OCI2Kif6ctF3caQTW2G5gym21oAsI4pw==} engines: {node: '>= 10.13.0'} @@ -9719,6 +9969,14 @@ packages: locate-path: 5.0.0 path-exists: 4.0.0 + /find-up@5.0.0: + resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} + engines: {node: '>=10'} + dependencies: + locate-path: 6.0.0 + path-exists: 4.0.0 + dev: true + /find-up@6.3.0: resolution: {integrity: sha512-v2ZsoEuVHYy8ZIlYqwPe/39Cy+cFDzp4dXPaxNvkEuouymu+2Jbz0PxpKarJHYJTmv2HWT3O382qY8l4jMWthw==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -9727,6 +9985,18 @@ packages: path-exists: 5.0.0 dev: true + /flat-cache@4.0.1: + resolution: {integrity: sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==} + engines: {node: '>=16'} + dependencies: + flatted: 3.3.1 + keyv: 4.5.4 + dev: true + + /flatted@3.3.1: + resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} + dev: true + /flush-write-stream@1.1.1: resolution: {integrity: sha512-3Z4XhFZ3992uIq0XOqb9AreonueSYphE6oYbpt5+3u06JWklbsPkNv3ZKkP9Bz/r+1MWCaMoSQ28P85+1Yc77w==} dependencies: @@ -10026,6 +10296,11 @@ packages: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} engines: {node: '>=4'} + /globals@14.0.0: + resolution: {integrity: sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==} + engines: {node: '>=18'} + dev: true + /globalthis@1.0.3: resolution: {integrity: sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA==} engines: {node: '>= 0.4'} @@ -10317,7 +10592,7 @@ packages: lodash: 4.17.21 pretty-error: 4.0.0 tapable: 2.2.1 - webpack: 5.90.1(webpack-cli@4.10.0) + webpack: 5.90.1(@swc/core@1.4.0)(webpack-cli@4.10.0) dev: true /htmlescape@1.1.1: @@ -11611,6 +11886,10 @@ packages: resolution: {integrity: sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ==} dev: true + /json-buffer@3.0.1: + resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==} + dev: true + /json-parse-better-errors@1.0.2: resolution: {integrity: sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==} dev: true @@ -11629,6 +11908,10 @@ packages: /json-schema-traverse@1.0.0: resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} + /json-stable-stringify-without-jsonify@1.0.1: + resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} + dev: true + /json-stringify-safe@5.0.1: resolution: {integrity: sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==} dev: true @@ -11687,6 +11970,12 @@ packages: json-buffer: 3.0.0 dev: true + /keyv@4.5.4: + resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} + dependencies: + json-buffer: 3.0.1 + dev: true + /kind-of@3.2.2: resolution: {integrity: sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==} engines: {node: '>=0.10.0'} @@ -11761,7 +12050,7 @@ packages: dependencies: '@rspack/core': link:packages/rspack less: 4.2.0 - webpack: 5.90.1(webpack-cli@4.10.0) + webpack: 5.90.1(@swc/core@1.4.0)(webpack-cli@4.10.0) dev: true /less@4.1.3: @@ -11804,6 +12093,14 @@ packages: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} engines: {node: '>=6'} + /levn@0.4.1: + resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} + engines: {node: '>= 0.8.0'} + dependencies: + prelude-ls: 1.2.1 + type-check: 0.4.0 + dev: true + /lilconfig@2.1.0: resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==} engines: {node: '>=10'} @@ -11928,6 +12225,13 @@ packages: dependencies: p-locate: 4.1.0 + /locate-path@6.0.0: + resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} + engines: {node: '>=10'} + dependencies: + p-locate: 5.0.0 + dev: true + /locate-path@7.2.0: resolution: {integrity: sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -11963,6 +12267,10 @@ packages: resolution: {integrity: sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==} dev: true + /lodash.merge@4.6.2: + resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} + dev: true + /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} @@ -12684,6 +12992,18 @@ packages: hasBin: true dev: false + /optionator@0.9.4: + resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==} + engines: {node: '>= 0.8.0'} + dependencies: + deep-is: 0.1.4 + fast-levenshtein: 2.0.6 + levn: 0.4.1 + prelude-ls: 1.2.1 + type-check: 0.4.0 + word-wrap: 1.2.5 + dev: true + /ora@5.4.1: resolution: {integrity: sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==} engines: {node: '>=10'} @@ -12708,19 +13028,19 @@ packages: engines: {node: '>=0.10.0'} dev: true - /oxlint@0.2.16: - resolution: {integrity: sha512-u9Laceg6qjlvR2T7LliIe8vLjE2eUl6oypHvuIAhP7YtTYoTB4//SqQ9yMqKD41uorQVOj851Ge/vcZFtK9fAw==} + /oxlint@0.3.4: + resolution: {integrity: sha512-xvBvleMnsQUI33YRJT09UudNI96cvIM/QQ/LjH0a1+YyXg10PkZJt/36cwErBeHqjSXG0ErE4d0htW7zVUFnkA==} engines: {node: '>=14.*'} hasBin: true optionalDependencies: - '@oxlint/darwin-arm64': 0.2.16 - '@oxlint/darwin-x64': 0.2.16 - '@oxlint/linux-arm64-gnu': 0.2.16 - '@oxlint/linux-arm64-musl': 0.2.16 - '@oxlint/linux-x64-gnu': 0.2.16 - '@oxlint/linux-x64-musl': 0.2.16 - '@oxlint/win32-arm64': 0.2.16 - '@oxlint/win32-x64': 0.2.16 + '@oxlint/darwin-arm64': 0.3.4 + '@oxlint/darwin-x64': 0.3.4 + '@oxlint/linux-arm64-gnu': 0.3.4 + '@oxlint/linux-arm64-musl': 0.3.4 + '@oxlint/linux-x64-gnu': 0.3.4 + '@oxlint/linux-x64-musl': 0.3.4 + '@oxlint/win32-arm64': 0.3.4 + '@oxlint/win32-x64': 0.3.4 dev: true /p-cancelable@1.1.0: @@ -12784,6 +13104,13 @@ packages: dependencies: p-limit: 2.3.0 + /p-locate@5.0.0: + resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==} + engines: {node: '>=10'} + dependencies: + p-limit: 3.1.0 + dev: true + /p-locate@6.0.0: resolution: {integrity: sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -13339,6 +13666,11 @@ packages: - typescript dev: true + /prelude-ls@1.2.1: + resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} + engines: {node: '>= 0.8.0'} + dev: true + /prepend-http@2.0.0: resolution: {integrity: sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA==} engines: {node: '>=4'} @@ -15569,6 +15901,10 @@ packages: glob: 7.2.3 minimatch: 3.1.2 + /text-table@0.2.0: + resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} + dev: true + /thenify-all@1.6.0: resolution: {integrity: sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==} engines: {node: '>=0.8'} @@ -15732,6 +16068,15 @@ packages: escape-string-regexp: 1.0.5 dev: true + /ts-api-utils@1.3.0(typescript@5.0.2): + resolution: {integrity: sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==} + engines: {node: '>=16'} + peerDependencies: + typescript: '>=4.2.0' + dependencies: + typescript: 5.0.2 + dev: true + /ts-interface-checker@0.1.13: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} dev: true @@ -15841,6 +16186,13 @@ packages: resolution: {integrity: sha512-ZW/lVMRabETuYCd9O9ZvMhAh8GslSqaUjxmK/JLPCh6l73CvLBiuXswj/+7LdnWOgYsQ130FqLzFz5aGT4I3Ug==} dev: true + /type-check@0.4.0: + resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} + engines: {node: '>= 0.8.0'} + dependencies: + prelude-ls: 1.2.1 + dev: true + /type-detect@4.0.8: resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==} engines: {node: '>=4'} @@ -16798,6 +17150,11 @@ packages: resolution: {integrity: sha512-P+6vtWyuDw+MB01X7UeF8TaHBvbCovf4HPEMF/SV7BdDc1SMTiBy13SRD71lQh4ExFTG1d/WNzDGDCyOKSMblw==} dev: false + /word-wrap@1.2.5: + resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} + engines: {node: '>=0.10.0'} + dev: true + /wordwrap@0.0.2: resolution: {integrity: sha512-xSBsCeh+g+dinoBv3GAOWM4LcVVO68wLXRanibtBSdUvkGWQRGeE9P7IwU9EmDDi4jA6L44lz15CGMwdw9N5+Q==} engines: {node: '>=0.4.0'} diff --git a/scripts/debug/launch.mjs b/scripts/debug/launch.mjs index bc7c99fd8bf2..fb0dd7eb63b7 100644 --- a/scripts/debug/launch.mjs +++ b/scripts/debug/launch.mjs @@ -1,6 +1,7 @@ -import chalk from "chalk"; import { fileURLToPath } from "node:url"; +import chalk from "chalk"; + const { yellow } = chalk; const __dirname = path.dirname(fileURLToPath(import.meta.url)); diff --git a/scripts/release/publish.mjs b/scripts/release/publish.mjs index 5d38a2b289c5..1aa1e4adca7b 100644 --- a/scripts/release/publish.mjs +++ b/scripts/release/publish.mjs @@ -1,8 +1,9 @@ -import { getLastVersion } from "./version.mjs"; import * as core from "@actions/core"; import * as path from "path"; import { fileURLToPath } from "url"; +import { getLastVersion } from "./version.mjs"; + const __filename = path.resolve(fileURLToPath(import.meta.url)); const __dirname = path.dirname(__filename); diff --git a/webpack-test/helpers/createFakeWorker.js b/webpack-test/helpers/createFakeWorker.js index 2c83da730c88..7bdcc7f43265 100644 --- a/webpack-test/helpers/createFakeWorker.js +++ b/webpack-test/helpers/createFakeWorker.js @@ -58,7 +58,7 @@ self.postMessage = data => { }; require(${JSON.stringify(path.resolve(outputDirectory, file))}); `; - // eslint-disable-next-line node/no-unsupported-features/node-builtins + this.worker = new (require("worker_threads").Worker)(workerBootstrap, { eval: true }); diff --git a/webpack-test/helpers/supportsRequireInModule.js b/webpack-test/helpers/supportsRequireInModule.js index b4e563a06861..b4a9ae26555a 100644 --- a/webpack-test/helpers/supportsRequireInModule.js +++ b/webpack-test/helpers/supportsRequireInModule.js @@ -1,4 +1,4 @@ module.exports = function supportsRequireInModule() { - // eslint-disable-next-line node/no-unsupported-features/node-builtins + return !!require("module").createRequire; }; diff --git a/website/components/i18n/index.ts b/website/components/i18n/index.ts index d0a5e3e0a2fb..cce61f8c8a5d 100644 --- a/website/components/i18n/index.ts +++ b/website/components/i18n/index.ts @@ -1,2 +1,2 @@ -export { default as zh } from './zh.json'; export { default as en } from './en.json'; +export { default as zh } from './zh.json'; diff --git a/website/rspress.config.ts b/website/rspress.config.ts index fedeb24ae904..91c043c4e8b6 100644 --- a/website/rspress.config.ts +++ b/website/rspress.config.ts @@ -1,9 +1,10 @@ import path from 'node:path'; -import { defineConfig } from 'rspress/config'; + import { pluginRss } from '@rspress/plugin-rss'; -import { pluginFontOpenSans } from 'rspress-plugin-font-open-sans'; -import { pluginOpenGraph } from 'rsbuild-plugin-open-graph'; import { pluginGoogleAnalytics } from 'rsbuild-plugin-google-analytics'; +import { pluginOpenGraph } from 'rsbuild-plugin-open-graph'; +import { defineConfig } from 'rspress/config'; +import { pluginFontOpenSans } from 'rspress-plugin-font-open-sans'; const PUBLISH_URL = 'https://rspack.dev'; const COPYRIGHT = '© 2022-present ByteDance Inc. All Rights Reserved.'; diff --git a/website/theme/i18n/index.ts b/website/theme/i18n/index.ts index 13ce8434980b..cf5f9447d465 100644 --- a/website/theme/i18n/index.ts +++ b/website/theme/i18n/index.ts @@ -1,4 +1,5 @@ -import { withBase, useLang } from 'rspress/runtime'; +import { useLang, withBase } from 'rspress/runtime'; + import { EN_US } from './enUS'; import { ZH_CN } from './zhCN'; diff --git a/x.mjs b/x.mjs index 7803834afd0f..a6a6d8d34833 100755 --- a/x.mjs +++ b/x.mjs @@ -1,13 +1,15 @@ #!/usr/bin/env zx import "zx/globals"; + import { Command } from "commander"; -import { version_handler } from "./scripts/release/version.mjs"; -import { publish_handler } from "./scripts/release/publish.mjs"; + import { - launchRspackCli, - launchJestWithArgs + launchJestWithArgs, + launchRspackCli } from "./scripts/debug/launch.mjs"; +import { publish_handler } from "./scripts/release/publish.mjs"; +import { version_handler } from "./scripts/release/version.mjs"; process.env.CARGO_TERM_COLOR = "always"; // Assume every terminal that using zx supports color process.env.FORCE_COLOR = 3; // Fix zx losing color output in subprocesses From 5d7c22700c4985dcd781bf673b48dccc7f397cec Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Wed, 15 May 2024 10:55:39 +0800 Subject: [PATCH 077/107] test: use @rspack/core as config type (#6538) --- .../tests/configCases/asset/issue-3307/webpack.config.js | 2 +- .../tests/configCases/asset/rename-asset/webpack.config.js | 2 +- .../configCases/asset/rspack-issue-2283/webpack.config.js | 2 +- .../minify-extract-comments-with-query/webpack.config.js | 2 +- .../configCases/builtins/minify-with-query/webpack.config.js | 2 +- .../available-modules-order-index/webpack.config.js | 4 +--- .../configCases/compilation/rebuild-module/webpack.config.js | 2 +- .../concatenate-modules/with-css/webpack.config.js | 2 +- .../module-federation-with-shareScope/webpack.config.js | 2 +- .../context-module/critical-warning/webpack.config.js | 2 +- .../webpack.config.js | 2 +- .../css/css-cross-origin-loading/webpack.config.js | 2 +- .../tests/configCases/css/export-selector/webpack.config.js | 2 +- .../externals/non-amd-externals-amd/webpack.config.js | 2 +- .../configCases/hooks/after-process-assets/webpack.config.js | 2 +- .../hooks/after-resolve-resource/webpack.config.js | 2 +- .../tests/configCases/hooks/after-seal/webpack.config.js | 2 +- .../configCases/hooks/asset-emitted-buffer/webpack.config.js | 2 +- .../tests/configCases/hooks/asset-emitted/webpack.config.js | 2 +- .../tests/configCases/hooks/before-resolve/webpack.config.js | 2 +- .../tests/configCases/hooks/build-module/webpack.config.js | 2 +- .../tests/configCases/hooks/check-asset/webpack.config.js | 2 +- .../compat-path-data-chunk-contenthash/webpack.config.js | 2 +- .../configCases/hooks/compilation-hooks/webpack.config.js | 2 +- .../hooks/compitable-errors-object/webpack.config.js | 2 +- .../hooks/context-module-after-resolve/webpack.config.js | 2 +- .../hooks/context-module-before-resolve/webpack.config.js | 2 +- .../tests/configCases/hooks/entryOption/webpack.config.js | 2 +- .../tests/configCases/hooks/interceptor/webpack.config.js | 2 +- .../configCases/hooks/rspack-issue-5571/webpack.config.js | 2 +- .../tests/configCases/hooks/runtime-module/webpack.config.js | 2 +- .../tests/configCases/hooks/should-emit-1/webpack.config.js | 2 +- .../tests/configCases/hooks/should-emit-2/webpack.config.js | 2 +- .../configCases/hooks/stillValidModule/webpack.config.js | 2 +- .../tests/configCases/hooks/succeedModule/webpack.config.js | 2 +- .../tests/configCases/library/_amd-require/webpack.config.js | 2 +- .../tests/configCases/library/array-this/webpack.config.js | 2 +- .../tests/configCases/library/commonjs/webpack.config.js | 2 +- .../library/duplicate-module-library/webpack.config.js | 2 +- .../tests/configCases/library/esm-external/webpack.config.js | 2 +- .../tests/configCases/library/esmodule/webpack.config.js | 2 +- .../tests/configCases/library/umd-external/webpack.config.js | 2 +- .../library/umd-named-define-runtime-chunk/webpack.config.js | 2 +- .../configCases/library/umd-named-define/webpack.config.js | 2 +- .../skipping-mangle-css-modules/webpack.config.js | 2 +- .../output-module/single-runtime/webpack.config.js | 2 +- .../tests/configCases/output/chunk-filename/webpack.config.js | 2 +- .../tests/configCases/output/script-type/webpack.config.js | 2 +- .../configCases/plugins/swc-js-minifier/webpack.config.js | 2 +- .../configCases/resolve/rspack-issue-4432/webpack.config.js | 2 +- .../tests/configCases/schemes/data-imports/webpack.config.js | 2 +- .../relative-source-maps-by-loader/webpack.config.js | 2 +- .../configCases/source-map/resource-path/webpack.config.js | 2 +- .../source-map/source-map-loader/webpack.config.js | 2 +- .../disable-reuse-existing-chunk-simple/webpack.config.js | 2 +- .../reuse-existing-chunk-simple/webpack.config.js | 2 +- .../webpack.config.js | 2 +- .../tree-shaking/asset-is-dep-of-css-source/webpack.config.js | 2 +- .../tests/configCases/tree-shaking/assets1/webpack.config.js | 2 +- .../tree-shaking/commonjs-reexport-interop/webpack.config.js | 2 +- .../tree-shaking/export-default-alias/webpack.config.js | 2 +- .../export-star-of-external-module/webpack.config.js | 2 +- .../tree-shaking/import-by-name-json/webpack.config.js | 2 +- .../tree-shaking/inner-graph-static-block/webpack.config.js | 2 +- .../configCases/tree-shaking/issue-5782/webpack.config.js | 2 +- .../tree-shaking/json-empty-array/webpack.config.js | 2 +- .../tree-shaking/member-expr-computed-prop/webpack.config.js | 2 +- .../multiple-same-export-side-effect/webpack.config.js | 2 +- .../multiple-same-import-side-effect/webpack.config.js | 2 +- .../tests/configCases/tree-shaking/new-url/webpack.config.js | 2 +- .../side-effects-disabled-active/webpack.config.js | 2 +- .../tree-shaking/side-effects-rule/webpack.config.js | 2 +- .../used-exports/used-exports-global/webpack.config.js | 2 +- .../used-exports/used-exports-true/webpack.config.js | 2 +- .../tests/hashCases/full-hash/webpack.config.js | 2 +- .../tests/hashCases/package-path-change/webpack.config.js | 2 +- .../hashCases/provided-dependency-order/webpack.config.js | 2 +- .../tests/hashCases/real-content-hash/webpack.config.js | 2 +- .../runtime-jsonp-chunk-loading/cross-origin/rspack.config.js | 2 +- .../cross-origin/webpack.config.js | 2 +- .../runtime-jsonp-chunk-loading/script-type/rspack.config.js | 2 +- .../runtime-jsonp-chunk-loading/script-type/webpack.config.js | 2 +- .../with-prefetch/rspack.config.js | 2 +- .../with-prefetch/webpack.config.js | 2 +- .../runtime-jsonp-chunk-loading/with-preload/rspack.config.js | 2 +- .../with-preload/webpack.config.js | 2 +- .../runtimeDiffCases/runtime-prefetch/basic/rspack.config.js | 2 +- .../runtimeDiffCases/runtime-prefetch/basic/webpack.config.js | 2 +- .../runtime-prefetch/dynamic-import-prefetch/rspack.config.js | 2 +- .../dynamic-import-prefetch/webpack.config.js | 2 +- .../runtime-prefetch/no-startup/rspack.config.js | 2 +- .../runtime-prefetch/no-startup/webpack.config.js | 2 +- .../runtimeDiffCases/runtime-preload/basic/rspack.config.js | 2 +- .../runtimeDiffCases/runtime-preload/basic/webpack.config.js | 2 +- .../runtime-preload/dynamic-import-preload/rspack.config.js | 2 +- .../runtime-preload/dynamic-import-preload/webpack.config.js | 2 +- .../statsOutputCases/auxiliary-files-test/webpack.config.js | 2 +- .../optimization-runtime-chunk-multiple/webpack.config.js | 2 +- .../optimization-runtime-chunk-true/webpack.config.js | 2 +- .../statsOutputCases/performance-disabled/webpack.config.js | 2 +- .../statsOutputCases/performance-error/webpack.config.js | 2 +- .../statsOutputCases/performance-no-hints/webpack.config.js | 2 +- .../statsOutputCases/prefetch-preload-mixed/webpack.config.js | 2 +- .../tests/statsOutputCases/runtime-modules/webpack.config.js | 2 +- .../runtime-specific-exports/webpack.config.js | 2 +- .../statsOutputCases/simple-module-source/webpack.config.js | 2 +- 106 files changed, 106 insertions(+), 108 deletions(-) diff --git a/packages/rspack-test-tools/tests/configCases/asset/issue-3307/webpack.config.js b/packages/rspack-test-tools/tests/configCases/asset/issue-3307/webpack.config.js index 2437fc138d80..5dcc150209a8 100644 --- a/packages/rspack-test-tools/tests/configCases/asset/issue-3307/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/asset/issue-3307/webpack.config.js @@ -1,5 +1,5 @@ /** - * @type {import('@rspack/cli').Configuration} + * @type {import('@rspack/core').Configuration} */ module.exports = { context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/asset/rename-asset/webpack.config.js b/packages/rspack-test-tools/tests/configCases/asset/rename-asset/webpack.config.js index 1f12c5235ed8..74550b70130e 100644 --- a/packages/rspack-test-tools/tests/configCases/asset/rename-asset/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/asset/rename-asset/webpack.config.js @@ -19,7 +19,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import('@rspack/core').Configuration}*/ module.exports = { context: __dirname, output: { diff --git a/packages/rspack-test-tools/tests/configCases/asset/rspack-issue-2283/webpack.config.js b/packages/rspack-test-tools/tests/configCases/asset/rspack-issue-2283/webpack.config.js index b819402a2dc9..74553cee5669 100644 --- a/packages/rspack-test-tools/tests/configCases/asset/rspack-issue-2283/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/asset/rspack-issue-2283/webpack.config.js @@ -2,7 +2,7 @@ const assert = require("assert"); const fs = require("fs"); /** - * @type {import('@rspack/cli').Configuration} + * @type {import('@rspack/core').Configuration} */ module.exports = { context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/builtins/minify-extract-comments-with-query/webpack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/minify-extract-comments-with-query/webpack.config.js index e3ec6355242a..059012ea4e4e 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/minify-extract-comments-with-query/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/minify-extract-comments-with-query/webpack.config.js @@ -1,6 +1,6 @@ const { rspack } = require("@rspack/core"); -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { output: { filename: 'bundle0.js?hash=[contenthash]' diff --git a/packages/rspack-test-tools/tests/configCases/builtins/minify-with-query/webpack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/minify-with-query/webpack.config.js index f751e96bac58..bde4a97fdc14 100644 --- a/packages/rspack-test-tools/tests/configCases/builtins/minify-with-query/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/builtins/minify-with-query/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { module: { generator: { diff --git a/packages/rspack-test-tools/tests/configCases/chunk-index/available-modules-order-index/webpack.config.js b/packages/rspack-test-tools/tests/configCases/chunk-index/available-modules-order-index/webpack.config.js index 20512eaa264c..3141d5a74778 100644 --- a/packages/rspack-test-tools/tests/configCases/chunk-index/available-modules-order-index/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/chunk-index/available-modules-order-index/webpack.config.js @@ -1,6 +1,4 @@ -/** @typedef {import("../../../../types").Compilation} Compilation */ -/** @typedef {import("../../../../types").Module} Module */ -/** @type {import("../../../../types").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: { main: "./main.js" diff --git a/packages/rspack-test-tools/tests/configCases/compilation/rebuild-module/webpack.config.js b/packages/rspack-test-tools/tests/configCases/compilation/rebuild-module/webpack.config.js index c3777c5ff48e..69616593c788 100644 --- a/packages/rspack-test-tools/tests/configCases/compilation/rebuild-module/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/compilation/rebuild-module/webpack.config.js @@ -35,7 +35,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { module: { rules: [ diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/webpack.config.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/webpack.config.js index bf67464c65d8..8f49975e1622 100644 --- a/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/with-css/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import("@rspack/cli").Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "development", entry: { diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/webpack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/webpack.config.js index 32107ab4118b..ceb31cc529b9 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/module-federation-with-shareScope/webpack.config.js @@ -25,7 +25,7 @@ const commonMF = { shareScope: "test-scope" }; -/** @type {import("../../../../types").Configuration[]} */ +/** @type {import("@rspack/core").Configuration[]} */ module.exports = [ { ...common, diff --git a/packages/rspack-test-tools/tests/configCases/context-module/critical-warning/webpack.config.js b/packages/rspack-test-tools/tests/configCases/context-module/critical-warning/webpack.config.js index 0a31832df5d2..0f3729b75f9b 100644 --- a/packages/rspack-test-tools/tests/configCases/context-module/critical-warning/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/context-module/critical-warning/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { module: { parser: { diff --git a/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading-use-credentials/webpack.config.js b/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading-use-credentials/webpack.config.js index e9c5288a0480..ef597805abf6 100644 --- a/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading-use-credentials/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading-use-credentials/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { crossOriginLoading: "use-credentials", diff --git a/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading/webpack.config.js b/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading/webpack.config.js index 9aa6f4cdca34..5b1ab7e9a75a 100644 --- a/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/css/css-cross-origin-loading/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { crossOriginLoading: "anonymous", diff --git a/packages/rspack-test-tools/tests/configCases/css/export-selector/webpack.config.js b/packages/rspack-test-tools/tests/configCases/css/export-selector/webpack.config.js index f01113fe0dc8..1e208aea67c5 100644 --- a/packages/rspack-test-tools/tests/configCases/css/export-selector/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/css/export-selector/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { module: { generator: { diff --git a/packages/rspack-test-tools/tests/configCases/externals/non-amd-externals-amd/webpack.config.js b/packages/rspack-test-tools/tests/configCases/externals/non-amd-externals-amd/webpack.config.js index 867515c11c1d..305eba340fd1 100644 --- a/packages/rspack-test-tools/tests/configCases/externals/non-amd-externals-amd/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/externals/non-amd-externals-amd/webpack.config.js @@ -1,5 +1,5 @@ const webpack = require("@rspack/core"); -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { libraryTarget: "amd" diff --git a/packages/rspack-test-tools/tests/configCases/hooks/after-process-assets/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/after-process-assets/webpack.config.js index 5e0b14efa9ac..9dd88d8aec08 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/after-process-assets/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/after-process-assets/webpack.config.js @@ -21,7 +21,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/webpack.config.js index aff0cb467078..6b335c4b3afa 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/webpack.config.js @@ -1,6 +1,6 @@ const pluginName = "plugin"; -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = [ { context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/hooks/after-seal/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/after-seal/webpack.config.js index 734bdcfaed7c..82551f6b44b3 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/after-seal/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/after-seal/webpack.config.js @@ -29,7 +29,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted-buffer/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted-buffer/webpack.config.js index f8b49ed6d763..4310130fa69b 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted-buffer/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted-buffer/webpack.config.js @@ -29,7 +29,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted/webpack.config.js index cabf8acbb1b9..3be1fcd5af7c 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/asset-emitted/webpack.config.js @@ -18,7 +18,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/before-resolve/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/before-resolve/webpack.config.js index bed4ef344586..d5dbb6c53c67 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/before-resolve/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/before-resolve/webpack.config.js @@ -46,7 +46,7 @@ class Plugin { ); } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/hooks/build-module/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/build-module/webpack.config.js index 5d06d626ccf1..ef8407ba5d90 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/build-module/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/build-module/webpack.config.js @@ -16,7 +16,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/check-asset/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/check-asset/webpack.config.js index 3170c68bbb01..79eb001986d0 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/check-asset/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/check-asset/webpack.config.js @@ -18,7 +18,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/hooks/compat-path-data-chunk-contenthash/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/compat-path-data-chunk-contenthash/webpack.config.js index 55d3d5cec5df..ee5b93122fbf 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/compat-path-data-chunk-contenthash/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/compat-path-data-chunk-contenthash/webpack.config.js @@ -21,7 +21,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/compilation-hooks/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/compilation-hooks/webpack.config.js index 3097f1fdd7cc..f4833ac8cf61 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/compilation-hooks/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/compilation-hooks/webpack.config.js @@ -31,7 +31,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/hooks/compitable-errors-object/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/compitable-errors-object/webpack.config.js index 942441c9f866..bfadae71043a 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/compitable-errors-object/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/compitable-errors-object/webpack.config.js @@ -10,7 +10,7 @@ class ErrorPlugin { } } /** - * @type {import('@rspack/cli').Configuration} + * @type {import("@rspack/core").Configuration} */ module.exports = { stats: "errors-warnings", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/context-module-after-resolve/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/context-module-after-resolve/webpack.config.js index fecb54b3ef17..457d8501a09e 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/context-module-after-resolve/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/context-module-after-resolve/webpack.config.js @@ -14,7 +14,7 @@ class Plugin { ); } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, entry: "./index.js", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/webpack.config.js index fcc5a341e339..dfb8bfdac3f6 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/context-module-before-resolve/webpack.config.js @@ -15,7 +15,7 @@ class Plugin { ); } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, entry: "./index.js", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/entryOption/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/entryOption/webpack.config.js index e9303576298c..3da68acc36df 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/entryOption/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/entryOption/webpack.config.js @@ -16,7 +16,7 @@ class MyEntryOptionPlugin { } } -/** @type {import('@rspack/cli').Configuration} */ +/** @type {import("@rspack/core").Configuration} */ const config = { context: __dirname, mode: "development", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/interceptor/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/interceptor/webpack.config.js index ec000c0f5ef6..21b48f3f3b67 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/interceptor/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/interceptor/webpack.config.js @@ -34,7 +34,7 @@ class InterceptPlugin { } } -/** @type {import('@rspack/cli').Configuration} */ +/** @type {import("@rspack/core").Configuration} */ const config = { plugins: [new InterceptPlugin()] }; diff --git a/packages/rspack-test-tools/tests/configCases/hooks/rspack-issue-5571/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/rspack-issue-5571/webpack.config.js index ad024ada5b26..f1d85138cb78 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/rspack-issue-5571/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/rspack-issue-5571/webpack.config.js @@ -25,7 +25,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { target: "web", mode: "development", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/runtime-module/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/runtime-module/webpack.config.js index 4ff962394282..1588ef465be8 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/runtime-module/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/runtime-module/webpack.config.js @@ -14,7 +14,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { entry: { main: "./index.js", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/should-emit-1/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/should-emit-1/webpack.config.js index ea400f21a93c..ead4d9ffc40f 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/should-emit-1/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/should-emit-1/webpack.config.js @@ -15,7 +15,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, plugins: [new Plugin()] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/should-emit-2/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/should-emit-2/webpack.config.js index e3a8655da16d..d3c02794107f 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/should-emit-2/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/should-emit-2/webpack.config.js @@ -32,7 +32,7 @@ class Plugin { } } -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { plugins: [new Plugin()] }; diff --git a/packages/rspack-test-tools/tests/configCases/hooks/stillValidModule/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/stillValidModule/webpack.config.js index 733d44985643..6a8b46f3e8a7 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/stillValidModule/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/stillValidModule/webpack.config.js @@ -1,6 +1,6 @@ const MyStillValidModulePlugin = require("./plugins/MyStillValidModulePlugin"); -/** @type {import('@rspack/cli').Configuration} */ +/** @type {import("@rspack/core").Configuration} */ const config = { context: __dirname, mode: "development", diff --git a/packages/rspack-test-tools/tests/configCases/hooks/succeedModule/webpack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/succeedModule/webpack.config.js index 5610d2c6d757..feb96252c738 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/succeedModule/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/succeedModule/webpack.config.js @@ -1,6 +1,6 @@ const MySucceedModulePlugin = require("./plugins/MySucceedModulePlugin"); -/** @type {import('@rspack/cli').Configuration} */ +/** @type {import("@rspack/core").Configuration} */ const config = { context: __dirname, mode: "development", diff --git a/packages/rspack-test-tools/tests/configCases/library/_amd-require/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/_amd-require/webpack.config.js index 2a1ee22ff915..415b7b7736fc 100644 --- a/packages/rspack-test-tools/tests/configCases/library/_amd-require/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/_amd-require/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { libraryTarget: "amd-require" diff --git a/packages/rspack-test-tools/tests/configCases/library/array-this/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/array-this/webpack.config.js index 27f3531ab58d..e76b87f14f73 100644 --- a/packages/rspack-test-tools/tests/configCases/library/array-this/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/array-this/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/configCases/library/commonjs/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/commonjs/webpack.config.js index 9d14309b0b23..eee51071e841 100644 --- a/packages/rspack-test-tools/tests/configCases/library/commonjs/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/commonjs/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { libraryTarget: "commonjs" diff --git a/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/webpack.config.js index 0aec1881351b..c4e556fe896e 100644 --- a/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/duplicate-module-library/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { library: { diff --git a/packages/rspack-test-tools/tests/configCases/library/esm-external/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/esm-external/webpack.config.js index 3219bb10b4df..de66ba757b28 100644 --- a/packages/rspack-test-tools/tests/configCases/library/esm-external/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/esm-external/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "development", output: { diff --git a/packages/rspack-test-tools/tests/configCases/library/esmodule/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/esmodule/webpack.config.js index f4eacf7f6055..d9299672742c 100644 --- a/packages/rspack-test-tools/tests/configCases/library/esmodule/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/esmodule/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { libraryTarget: "module", diff --git a/packages/rspack-test-tools/tests/configCases/library/umd-external/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/umd-external/webpack.config.js index 65ebfc247ce1..3986a5ef7afd 100644 --- a/packages/rspack-test-tools/tests/configCases/library/umd-external/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/umd-external/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { libraryTarget: "umd", diff --git a/packages/rspack-test-tools/tests/configCases/library/umd-named-define-runtime-chunk/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/umd-named-define-runtime-chunk/webpack.config.js index 84ca122c89c4..36493684289f 100644 --- a/packages/rspack-test-tools/tests/configCases/library/umd-named-define-runtime-chunk/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/umd-named-define-runtime-chunk/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: { main: { diff --git a/packages/rspack-test-tools/tests/configCases/library/umd-named-define/webpack.config.js b/packages/rspack-test-tools/tests/configCases/library/umd-named-define/webpack.config.js index 187aa4fdce3d..40ec26482713 100644 --- a/packages/rspack-test-tools/tests/configCases/library/umd-named-define/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/umd-named-define/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { libraryTarget: "umd", diff --git a/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/webpack.config.js b/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/webpack.config.js index d9b40f80fa39..f72d66c7196a 100644 --- a/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/mangle-exports/skipping-mangle-css-modules/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import("@rspack/cli").Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { experiments: { css: true, diff --git a/packages/rspack-test-tools/tests/configCases/output-module/single-runtime/webpack.config.js b/packages/rspack-test-tools/tests/configCases/output-module/single-runtime/webpack.config.js index fb31f326f189..2cf2888a3273 100644 --- a/packages/rspack-test-tools/tests/configCases/output-module/single-runtime/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/output-module/single-runtime/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { output: { filename: "[name].mjs", diff --git a/packages/rspack-test-tools/tests/configCases/output/chunk-filename/webpack.config.js b/packages/rspack-test-tools/tests/configCases/output/chunk-filename/webpack.config.js index d23623f99faa..4b3b891cb6bf 100644 --- a/packages/rspack-test-tools/tests/configCases/output/chunk-filename/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/output/chunk-filename/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: "./index.js", target: "node", diff --git a/packages/rspack-test-tools/tests/configCases/output/script-type/webpack.config.js b/packages/rspack-test-tools/tests/configCases/output/script-type/webpack.config.js index 7fbce7ea7a9b..305ac791a791 100644 --- a/packages/rspack-test-tools/tests/configCases/output/script-type/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/output/script-type/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = [ { entry: "./a", diff --git a/packages/rspack-test-tools/tests/configCases/plugins/swc-js-minifier/webpack.config.js b/packages/rspack-test-tools/tests/configCases/plugins/swc-js-minifier/webpack.config.js index f9685048944c..627c9eecba3e 100644 --- a/packages/rspack-test-tools/tests/configCases/plugins/swc-js-minifier/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/plugins/swc-js-minifier/webpack.config.js @@ -1,6 +1,6 @@ const { SwcJsMinimizerRspackPlugin } = require("@rspack/core"); -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: { main: ["./index.js"], diff --git a/packages/rspack-test-tools/tests/configCases/resolve/rspack-issue-4432/webpack.config.js b/packages/rspack-test-tools/tests/configCases/resolve/rspack-issue-4432/webpack.config.js index 7cd55a91d0f1..739d2e175b9b 100644 --- a/packages/rspack-test-tools/tests/configCases/resolve/rspack-issue-4432/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/resolve/rspack-issue-4432/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import('@rspack/cli').Configuration} */ +/** @type {import("@rspack/core").Configuration} */ const config = { entry: { main: "./index.js" diff --git a/packages/rspack-test-tools/tests/configCases/schemes/data-imports/webpack.config.js b/packages/rspack-test-tools/tests/configCases/schemes/data-imports/webpack.config.js index f8505edbd08f..d81d7cfa8c5a 100644 --- a/packages/rspack-test-tools/tests/configCases/schemes/data-imports/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/schemes/data-imports/webpack.config.js @@ -14,7 +14,7 @@ class Plugin { }); } } -/** @type {import('@rspack/cli').Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { module: { generator: { diff --git a/packages/rspack-test-tools/tests/configCases/source-map/relative-source-maps-by-loader/webpack.config.js b/packages/rspack-test-tools/tests/configCases/source-map/relative-source-maps-by-loader/webpack.config.js index c0a285cd11bc..3aaf4896b9e7 100644 --- a/packages/rspack-test-tools/tests/configCases/source-map/relative-source-maps-by-loader/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/source-map/relative-source-maps-by-loader/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "development", node: { diff --git a/packages/rspack-test-tools/tests/configCases/source-map/resource-path/webpack.config.js b/packages/rspack-test-tools/tests/configCases/source-map/resource-path/webpack.config.js index 08bcd6ec51d1..4fae8b31a3d7 100644 --- a/packages/rspack-test-tools/tests/configCases/source-map/resource-path/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/source-map/resource-path/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { node: { __dirname: false, diff --git a/packages/rspack-test-tools/tests/configCases/source-map/source-map-loader/webpack.config.js b/packages/rspack-test-tools/tests/configCases/source-map/source-map-loader/webpack.config.js index d6ef708a9c4d..93781f5119bc 100644 --- a/packages/rspack-test-tools/tests/configCases/source-map/source-map-loader/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/source-map/source-map-loader/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { node: { __dirname: false, diff --git a/packages/rspack-test-tools/tests/configCases/split-chunks/disable-reuse-existing-chunk-simple/webpack.config.js b/packages/rspack-test-tools/tests/configCases/split-chunks/disable-reuse-existing-chunk-simple/webpack.config.js index 904946f015cb..44bef54c265b 100644 --- a/packages/rspack-test-tools/tests/configCases/split-chunks/disable-reuse-existing-chunk-simple/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/split-chunks/disable-reuse-existing-chunk-simple/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "node", entry: "./index.js", diff --git a/packages/rspack-test-tools/tests/configCases/split-chunks/reuse-existing-chunk-simple/webpack.config.js b/packages/rspack-test-tools/tests/configCases/split-chunks/reuse-existing-chunk-simple/webpack.config.js index 8e2de8091904..bcfe218566c4 100644 --- a/packages/rspack-test-tools/tests/configCases/split-chunks/reuse-existing-chunk-simple/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/split-chunks/reuse-existing-chunk-simple/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "node", entry: "./index.js", diff --git a/packages/rspack-test-tools/tests/configCases/split-chunks/should-not-reuse-existing-chunk-simple-if-cache-group-name-specified/webpack.config.js b/packages/rspack-test-tools/tests/configCases/split-chunks/should-not-reuse-existing-chunk-simple-if-cache-group-name-specified/webpack.config.js index bfcfbefe2718..dcfab6bda42d 100644 --- a/packages/rspack-test-tools/tests/configCases/split-chunks/should-not-reuse-existing-chunk-simple-if-cache-group-name-specified/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/split-chunks/should-not-reuse-existing-chunk-simple-if-cache-group-name-specified/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "node", entry: "./index.js", diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/webpack.config.js index 1f544afbbd49..07954d6bfbd1 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/asset-is-dep-of-css-source/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/webpack.config.js index 1f544afbbd49..07954d6bfbd1 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/assets1/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/webpack.config.js index 7a6ca4963ed1..5a59ca6bfab1 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/commonjs-reexport-interop/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "production", context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/webpack.config.js index b3c452282e7f..818dc5b62450 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-default-alias/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "production", context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/webpack.config.js index 317ccd59b02a..7caf80a5dd19 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/export-star-of-external-module/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/webpack.config.js index 8f15cf4f94b3..7ec51493cb01 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/import-by-name-json/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "production", context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/webpack.config.js index 7a6ca4963ed1..5a59ca6bfab1 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/inner-graph-static-block/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "production", context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/webpack.config.js index f2d0e8903b97..177c33b34b1f 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/issue-5782/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, experiments: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/webpack.config.js index f2d0e8903b97..177c33b34b1f 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/json-empty-array/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, experiments: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/webpack.config.js index 691bcc13874f..37a6000837d4 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/member-expr-computed-prop/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, builtins: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/webpack.config.js index bba2e37c26b9..154b79c4b067 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-export-side-effect/webpack.config.js @@ -1,6 +1,6 @@ const { DefinePlugin } = require("@rspack/core"); -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, builtins: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/webpack.config.js index bba2e37c26b9..154b79c4b067 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/multiple-same-import-side-effect/webpack.config.js @@ -1,6 +1,6 @@ const { DefinePlugin } = require("@rspack/core"); -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, builtins: { diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/webpack.config.js index 462c9888a99c..b3ad2a660c86 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/new-url/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "development", context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-disabled-active/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-disabled-active/webpack.config.js index bdea17cda458..ae39a9286c1f 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-disabled-active/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-disabled-active/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { module: { rules: [ diff --git a/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/webpack.config.js b/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/webpack.config.js index 6232d21d8c78..0189ba7dcca1 100644 --- a/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/tree-shaking/side-effects-rule/webpack.config.js @@ -1,4 +1,4 @@ -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { context: __dirname, module: { diff --git a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/webpack.config.js b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/webpack.config.js index d36d95676d0b..ce8bb78da91d 100644 --- a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-global/webpack.config.js @@ -1,5 +1,5 @@ const path = require("path"); -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "production", context: __dirname, diff --git a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/webpack.config.js b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/webpack.config.js index 3ea2bc333335..15715a138347 100644 --- a/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/used-exports/used-exports-true/webpack.config.js @@ -1,5 +1,5 @@ const path = require("path"); -/**@type {import('@rspack/cli').Configuration}*/ +/**@type {import("@rspack/core").Configuration}*/ module.exports = { mode: "production", context: __dirname, diff --git a/packages/rspack-test-tools/tests/hashCases/full-hash/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/full-hash/webpack.config.js index 4b750959a158..3671698f1d13 100644 --- a/packages/rspack-test-tools/tests/hashCases/full-hash/webpack.config.js +++ b/packages/rspack-test-tools/tests/hashCases/full-hash/webpack.config.js @@ -20,7 +20,7 @@ function config(subpath, realContentHash = false) { }; } -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = [ config("version0"), config("version0-copy"), diff --git a/packages/rspack-test-tools/tests/hashCases/package-path-change/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/package-path-change/webpack.config.js index 1a47639171f2..136962742d46 100644 --- a/packages/rspack-test-tools/tests/hashCases/package-path-change/webpack.config.js +++ b/packages/rspack-test-tools/tests/hashCases/package-path-change/webpack.config.js @@ -19,7 +19,7 @@ function config(subpath, realContentHash = false) { }; } -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = [ config("version0"), config("version0-copy"), diff --git a/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/webpack.config.js index da811ea4cd5c..1f4ea1af0e54 100644 --- a/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/webpack.config.js +++ b/packages/rspack-test-tools/tests/hashCases/provided-dependency-order/webpack.config.js @@ -18,7 +18,7 @@ function config(subpath, realContentHash = false) { }; } -/** @type {import("../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = [ config("a"), config("b"), diff --git a/packages/rspack-test-tools/tests/hashCases/real-content-hash/webpack.config.js b/packages/rspack-test-tools/tests/hashCases/real-content-hash/webpack.config.js index cbbbe978dfd0..f0b31e41bebf 100644 --- a/packages/rspack-test-tools/tests/hashCases/real-content-hash/webpack.config.js +++ b/packages/rspack-test-tools/tests/hashCases/real-content-hash/webpack.config.js @@ -24,7 +24,7 @@ const base = { stats: "normal" }; -/** @type {import("../../../").Configuration[]} */ +/** @type {import("@rspack/core").Configuration[]} */ module.exports = [ { ...base, diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/rspack.config.js index 0b05607d3d3b..59eb3a92a44f 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/webpack.config.js index 0b05607d3d3b..59eb3a92a44f 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/cross-origin/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/rspack.config.js index a7bec5630f02..efe78c7da0f3 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/webpack.config.js index a7bec5630f02..efe78c7da0f3 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/script-type/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/rspack.config.js index 5f05c564fff0..58f925f7a167 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/webpack.config.js index 5f05c564fff0..58f925f7a167 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-prefetch/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/rspack.config.js index 5f05c564fff0..58f925f7a167 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/webpack.config.js index 5f05c564fff0..58f925f7a167 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-jsonp-chunk-loading/with-preload/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/rspack.config.js index 19d03fc867d7..efb414999c18 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/webpack.config.js index 19d03fc867d7..efb414999c18 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/basic/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/rspack.config.js index 5275d0e0b8ea..5b2e537752dc 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/webpack.config.js index 5275d0e0b8ea..5b2e537752dc 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/dynamic-import-prefetch/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/rspack.config.js index 278595dee8c4..efb414999c18 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/webpack.config.js index 19d03fc867d7..efb414999c18 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-prefetch/no-startup/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/rspack.config.js index 9f62a57127a6..7dc0ac9171c9 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/webpack.config.js index 19d03fc867d7..efb414999c18 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/basic/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/rspack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/rspack.config.js index 9f62a57127a6..7dc0ac9171c9 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/rspack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/rspack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/webpack.config.js b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/webpack.config.js index 9f62a57127a6..7dc0ac9171c9 100644 --- a/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/webpack.config.js +++ b/packages/rspack-test-tools/tests/runtimeDiffCases/runtime-preload/dynamic-import-preload/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { target: "web", output: { diff --git a/packages/rspack-test-tools/tests/statsOutputCases/auxiliary-files-test/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/auxiliary-files-test/webpack.config.js index be3f12371ff3..a7c62eb1b5fd 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/auxiliary-files-test/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/auxiliary-files-test/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "production", entry: "./index", diff --git a/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-multiple/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-multiple/webpack.config.js index 21c13bfa2edc..42ef70465bca 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-multiple/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-multiple/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "development", entry: { diff --git a/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-true/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-true/webpack.config.js index fa45c958798b..b345c8d3199f 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-true/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/optimization-runtime-chunk-true/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "development", entry: { diff --git a/packages/rspack-test-tools/tests/statsOutputCases/performance-disabled/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/performance-disabled/webpack.config.js index 49d1699527ff..3fa660ef7efb 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/performance-disabled/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/performance-disabled/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "production", entry: "./index", diff --git a/packages/rspack-test-tools/tests/statsOutputCases/performance-error/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/performance-error/webpack.config.js index 2a53b9837262..678f23ed07bc 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/performance-error/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/performance-error/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "production", entry: "./index", diff --git a/packages/rspack-test-tools/tests/statsOutputCases/performance-no-hints/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/performance-no-hints/webpack.config.js index 793fe03db687..81f405ee7139 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/performance-no-hints/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/performance-no-hints/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "production", entry: "./index", diff --git a/packages/rspack-test-tools/tests/statsOutputCases/prefetch-preload-mixed/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/prefetch-preload-mixed/webpack.config.js index d864bc6af946..35433caef09e 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/prefetch-preload-mixed/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/prefetch-preload-mixed/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { mode: "production", entry: "./index", diff --git a/packages/rspack-test-tools/tests/statsOutputCases/runtime-modules/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/runtime-modules/webpack.config.js index c9f324c85b74..55fb6038017a 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/runtime-modules/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/runtime-modules/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: "./index", mode: "development", diff --git a/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/webpack.config.js index abe26973d823..5d2038e880e3 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/runtime-specific-exports/webpack.config.js @@ -1,5 +1,5 @@ -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: "./example.js", optimization: { diff --git a/packages/rspack-test-tools/tests/statsOutputCases/simple-module-source/webpack.config.js b/packages/rspack-test-tools/tests/statsOutputCases/simple-module-source/webpack.config.js index e04585e31557..8b6037c1fdcc 100644 --- a/packages/rspack-test-tools/tests/statsOutputCases/simple-module-source/webpack.config.js +++ b/packages/rspack-test-tools/tests/statsOutputCases/simple-module-source/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("../../../dist").Configuration} */ +/** @type {import("@rspack/core").Configuration} */ module.exports = { entry: "./index", mode: "production", From 0ec146e1674885541d9a71289b024f4dc03f5181 Mon Sep 17 00:00:00 2001 From: gaoyuan <9aoyuao@gmail.com> Date: Wed, 15 May 2024 11:06:44 +0800 Subject: [PATCH 078/107] docs: list workbox & react-refresh webpack plugin compatibility status (#6543) --- .../components/CommunityCompatibleTable.tsx | 19 ++++++++++++++++++- website/components/i18n/en.json | 4 +++- website/components/i18n/zh.json | 4 +++- website/project-words.txt | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/website/components/CommunityCompatibleTable.tsx b/website/components/CommunityCompatibleTable.tsx index 06e53acac068..ef01348ba3e0 100644 --- a/website/components/CommunityCompatibleTable.tsx +++ b/website/components/CommunityCompatibleTable.tsx @@ -134,6 +134,23 @@ export const CommunityPluginCompatibleTable: React.FC = () => { status: CompatibleStatus.NotCompatible, description: i18n[lang]['webpack-virtual-modules-desc'], }, + { + name: 'node-polyfill-webpack-plugin', + url: 'https://www.npmjs.com/package/node-polyfill-webpack-plugin', + status: CompatibleStatus.Compatible, + }, + { + name: 'workbox-webpack-plugin', + url: 'https://www.npmjs.com/package/workbox-webpack-plugin', + status: CompatibleStatus.NotCompatible, + description: i18n[lang]['workbox-webpack-plugin-desc'], + }, + { + name: '@pmmmwh/react-refresh-webpack-plugin', + url: 'https://www.npmjs.com/package/@pmmmwh/react-refresh-webpack-plugin', + status: CompatibleStatus.NotCompatible, + description: i18n[lang]['react-refresh-webpack-plugin-desc'], + }, { name: '@sentry/webpack-plugin', url: 'https://www.npmjs.com/package/@sentry/webpack-plugin', @@ -163,7 +180,7 @@ export const CommunityPluginCompatibleTable: React.FC = () => { }, ]} body={pluginList - .sort((a, b) => b.status - a.status) + .sort((a, b) => b.status - a.status || a.name.localeCompare(b.name)) .map(({ name, url, status, description }) => { const { symbol, en, zh } = SUPPORT_STATUS_LOCALIZED[status]; const statusText = `${symbol} ${lang === 'zh' ? zh : en}`; diff --git a/website/components/i18n/en.json b/website/components/i18n/en.json index bb14bdc42a16..f6b560ee862e 100644 --- a/website/components/i18n/en.json +++ b/website/components/i18n/en.json @@ -13,5 +13,7 @@ "case-sensitive-paths-webpack-plugin-desc": "`useBeforeEmitHook` option not supported", "resolve-plugin-un-support-desc": "`resolve.plugins` option not supported", "webpack-virtual-modules-desc": "Use [rspack-plugin-virtual-module](https://github.com/rspack-contrib/rspack-plugins/tree/main/packages/plugin-virtual-module) instead", - "webpack-manifest-plugin-desc": "Use [rspack-manifest-plugin](https://github.com/rspack-contrib/rspack-manifest-plugin) instead" + "webpack-manifest-plugin-desc": "Use [rspack-manifest-plugin](https://github.com/rspack-contrib/rspack-manifest-plugin) instead", + "workbox-webpack-plugin-desc": "Use [@aaroon/workbox-rspack-plugin](https://github.com/Clarkkkk/workbox-rspack-plugin) instead", + "react-refresh-webpack-plugin-desc": "Use [@rspack/plugin-react-refresh](/guide/tech/react#rspackplugin-react-refresh) instead" } diff --git a/website/components/i18n/zh.json b/website/components/i18n/zh.json index 4ddf2ce8cb89..87921fba9aab 100644 --- a/website/components/i18n/zh.json +++ b/website/components/i18n/zh.json @@ -13,5 +13,7 @@ "case-sensitive-paths-webpack-plugin-desc": "不支持 `useBeforeEmitHook` 选项", "resolve-plugin-un-support-desc": "不支持 `resolve.plugins`", "webpack-virtual-modules-desc": "使用 [rspack-plugin-virtual-module](https://github.com/rspack-contrib/rspack-plugins/tree/main/packages/plugin-virtual-module) 替代", - "webpack-manifest-plugin-desc": "使用 [rspack-manifest-plugin](https://github.com/rspack-contrib/rspack-manifest-plugin) 替代" + "webpack-manifest-plugin-desc": "使用 [rspack-manifest-plugin](https://github.com/rspack-contrib/rspack-manifest-plugin) 替代", + "workbox-webpack-plugin-desc": "使用 [@aaroon/workbox-rspack-plugin](https://github.com/Clarkkkk/workbox-rspack-plugin) 替代", + "react-refresh-webpack-plugin-desc": "使用 [@rspack/plugin-react-refresh](/guide/tech/react#rspackplugin-react-refresh) 替代" } diff --git a/website/project-words.txt b/website/project-words.txt index 596675a6ee5e..1e789bab68ee 100644 --- a/website/project-words.txt +++ b/website/project-words.txt @@ -149,3 +149,4 @@ devserverwebsocketserver devserverdevmiddleware proxying proxied +pmmmwh From 231c64e5552c04a22a162768c8cffec2da5ba512 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Wed, 15 May 2024 11:26:37 +0800 Subject: [PATCH 079/107] ci: renovate lark trigger (#6542) --- .github/workflows/issue-pr-trigger.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/issue-pr-trigger.yml b/.github/workflows/issue-pr-trigger.yml index 3d14c3599f56..23b3eb0cc2a3 100644 --- a/.github/workflows/issue-pr-trigger.yml +++ b/.github/workflows/issue-pr-trigger.yml @@ -16,7 +16,7 @@ jobs: node-version: '20' - name: Check if triggered by project member id: check_member - if: github.event.sender.type == 'User' + if: github.event.sender.type == 'User' && github.actor != 'renovate' run: | SENDER=${{ github.event.sender.login }} TEAMS_FILE="./.github/teams.yml" From ea2947e6195cffbe244d6000b8cb9b7da2f4c679 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Wed, 15 May 2024 11:34:44 +0800 Subject: [PATCH 080/107] chore: remove new split chunks options (#6536) --- Cargo.lock | 1 - Cargo.toml | 1 - crates/node_binding/binding.d.ts | 1 - crates/rspack_binding_options/Cargo.toml | 1 - crates/rspack_binding_options/src/options/mod.rs | 8 ++------ .../src/options/raw_experiments.rs | 1 - .../src/options/raw_optimization.rs | 3 --- crates/rspack_core/src/options/experiments.rs | 1 - .../tests/__snapshots__/Defaults.test.js.snap | 1 - packages/rspack/etc/api.md | 10 ---------- packages/rspack/src/config/adapter.ts | 7 ++----- packages/rspack/src/config/defaults.ts | 1 - packages/rspack/src/config/normalization.ts | 1 - packages/rspack/src/config/zod.ts | 14 -------------- 14 files changed, 4 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc5aaffc6963..838a5a085672 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2773,7 +2773,6 @@ name = "rspack_binding_options" version = "0.1.0" dependencies = [ "async-trait", - "better_scoped_tls", "derivative", "glob", "napi-derive", diff --git a/Cargo.toml b/Cargo.toml index 2f7b8a0aaa80..94a717b4af5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ anyhow = { version = "1.0.81", features = ["backtrace"] } async-recursion = { version = "1.1.0" } async-scoped = { version = "0.9.0" } async-trait = { version = "0.1.79" } -better_scoped_tls = { version = "0.1.1" } bitflags = { version = "2.5.0" } concat-string = "1.0.1" dashmap = { version = "5.5.3" } diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 8784603778d9..28b248b5b378 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -843,7 +843,6 @@ export interface RawEvalDevToolModulePluginOptions { } export interface RawExperiments { - newSplitChunks: boolean topLevelAwait: boolean rspackFuture: RawRspackFuture } diff --git a/crates/rspack_binding_options/Cargo.toml b/crates/rspack_binding_options/Cargo.toml index ec70509c9ae2..c4f2ec697cb2 100644 --- a/crates/rspack_binding_options/Cargo.toml +++ b/crates/rspack_binding_options/Cargo.toml @@ -11,7 +11,6 @@ plugin = ["rspack_loader_swc/plugin"] [dependencies] async-trait = { workspace = true } -better_scoped_tls = { workspace = true } derivative = { workspace = true } glob = { workspace = true } napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] } diff --git a/crates/rspack_binding_options/src/options/mod.rs b/crates/rspack_binding_options/src/options/mod.rs index 494bdf41fb6d..d572c9603d0a 100644 --- a/crates/rspack_binding_options/src/options/mod.rs +++ b/crates/rspack_binding_options/src/options/mod.rs @@ -1,7 +1,7 @@ use napi_derive::napi; use rspack_core::{ CacheOptions, CompilerOptions, Context, Experiments, IncrementalRebuild, - IncrementalRebuildMakeState, ModuleOptions, Optimization, OutputOptions, Target, TreeShaking, + IncrementalRebuildMakeState, ModuleOptions, OutputOptions, Target, TreeShaking, }; mod raw_builtins; @@ -82,14 +82,10 @@ impl TryFrom for CompilerOptions { }, emit_asset: true, }, - new_split_chunks: value.experiments.new_split_chunks, top_level_await: value.experiments.top_level_await, rspack_future: value.experiments.rspack_future.into(), }; - let optimization: Optimization = IS_ENABLE_NEW_SPLIT_CHUNKS - .set(&experiments.new_split_chunks, || { - value.optimization.try_into() - })?; + let optimization = value.optimization.try_into()?; let stats = value.stats.into(); let snapshot = value.snapshot.into(); let node = value.node.map(|n| n.into()); diff --git a/crates/rspack_binding_options/src/options/raw_experiments.rs b/crates/rspack_binding_options/src/options/raw_experiments.rs index 203162b047a0..9a249f885e70 100644 --- a/crates/rspack_binding_options/src/options/raw_experiments.rs +++ b/crates/rspack_binding_options/src/options/raw_experiments.rs @@ -10,7 +10,6 @@ pub struct RawRspackFuture { #[derive(Debug, Default)] #[napi(object)] pub struct RawExperiments { - pub new_split_chunks: bool, pub top_level_await: bool, pub rspack_future: RawRspackFuture, } diff --git a/crates/rspack_binding_options/src/options/raw_optimization.rs b/crates/rspack_binding_options/src/options/raw_optimization.rs index 3c722c8c8d37..2a6d38534c2c 100644 --- a/crates/rspack_binding_options/src/options/raw_optimization.rs +++ b/crates/rspack_binding_options/src/options/raw_optimization.rs @@ -1,9 +1,6 @@ -use better_scoped_tls::scoped_tls; use napi_derive::napi; use rspack_core::{MangleExportsOption, Optimization, SideEffectOption, UsedExportsOption}; -scoped_tls!(pub(crate) static IS_ENABLE_NEW_SPLIT_CHUNKS: bool); - #[derive(Debug, Default)] #[napi(object)] pub struct RawOptimizationOptions { diff --git a/crates/rspack_core/src/options/experiments.rs b/crates/rspack_core/src/options/experiments.rs index 43f3338fb749..57fffa39fb4e 100644 --- a/crates/rspack_core/src/options/experiments.rs +++ b/crates/rspack_core/src/options/experiments.rs @@ -29,7 +29,6 @@ pub struct RspackFuture { #[derive(Debug, Default)] pub struct Experiments { pub incremental_rebuild: IncrementalRebuild, - pub new_split_chunks: bool, pub top_level_await: bool, pub rspack_future: RspackFuture, } diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index 2a8bd6ada728..e3d977104839 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -20,7 +20,6 @@ Object { "asyncWebAssembly": false, "css": true, "lazyCompilation": false, - "newSplitChunks": true, "rspackFuture": Object { "bundlerInfo": Object { "force": false, diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 0b91499bbf33..a65dbc07dd01 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -2767,7 +2767,6 @@ const experiments: z.ZodObject<{ asyncWebAssembly: z.ZodOptional; outputModule: z.ZodOptional; topLevelAwait: z.ZodOptional; - newSplitChunks: z.ZodEffects, boolean | undefined, boolean | undefined>; css: z.ZodOptional; futureDefaults: z.ZodOptional; rspackFuture: z.ZodOptional; outputModule: z.ZodOptional; topLevelAwait: z.ZodOptional; - newSplitChunks: z.ZodEffects, boolean | undefined, boolean | undefined>; css: z.ZodOptional; futureDefaults: z.ZodOptional; rspackFuture: z.ZodOptional { D(experiments, "lazyCompilation", false); D(experiments, "asyncWebAssembly", false); - D(experiments, "newSplitChunks", true); D(experiments, "css", true); // we not align with webpack about the default value for better DX D(experiments, "topLevelAwait", true); diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index a65f78e60222..1fbb86c8f905 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -502,7 +502,6 @@ export interface ExperimentsNormalized { lazyCompilation?: boolean; asyncWebAssembly?: boolean; outputModule?: boolean; - newSplitChunks?: boolean; topLevelAwait?: boolean; css?: boolean; futureDefaults?: boolean; diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index 4df41a676c99..d45448785879 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -1192,20 +1192,6 @@ const experiments = z.strictObject({ asyncWebAssembly: z.boolean().optional(), outputModule: z.boolean().optional(), topLevelAwait: z.boolean().optional(), - newSplitChunks: z - .boolean() - .optional() - .refine(val => { - if (val === false) { - deprecatedWarn( - `'experiments.newSplitChunks = ${JSON.stringify( - val - )}' has been deprecated, please switch to 'experiments.newSplitChunks = true' to use webpack's behavior. - See the discussion here (https://github.com/web-infra-dev/rspack/discussions/4168)` - ); - } - return true; - }), css: z.boolean().optional(), futureDefaults: z.boolean().optional(), rspackFuture: rspackFutureOptions.optional() From 6be397875e9a35b8291e714d2ba7332bf2f9b291 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Wed, 15 May 2024 11:39:32 +0800 Subject: [PATCH 081/107] refactor: align js render bootstrap (#6534) --- Cargo.lock | 1 + crates/rspack_plugin_javascript/Cargo.toml | 1 + .../src/plugin/mod.rs | 462 ++++++++++++------ .../tests/__snapshots__/StatsAPI.test.js.snap | 6 +- .../__snapshots__/StatsOutput.test.js.snap | 96 ++-- .../variant/snapshot/output.snap.txt | 2 +- .../basic/hooks.snap.txt | 29 +- .../basic/output.snap.txt | 29 +- .../update-asset/hooks.snap.txt | 62 ++- .../update-asset/output.snap.txt | 31 +- .../basic/hooks.snap.txt | 173 ++++--- .../basic/output.snap.txt | 29 +- .../duplicate/output.snap.txt | 29 +- .../request/output.snap.txt | 29 +- .../resource/output.snap.txt | 29 +- .../tests/statsAPICases/basic.js | 2 +- .../tests/statsAPICases/exports.js | 2 +- .../tests/statsAPICases/to-string.js | 2 +- ...$.css => async.$dec0863f5e812ee7cadd$.css} | 0 ...9$.css => main.$dec0863f5e812ee7cadd$.css} | 0 .../chunkFilename-fullhash/expected/main.js | 34 +- .../expected/main.js | 29 +- .../expected/main.mjs | 29 +- .../cases/es-named-export/expected/main.js | 29 +- .../expected/main.js | 29 +- .../expected/main.js | 29 +- .../cases/export-only-locals/expected/main.js | 29 +- .../css-extract/cases/hmr/expected/main.js | 60 ++- .../cases/insert-function/expected/main.js | 32 +- .../cases/insert-string/expected/main.js | 32 +- .../cases/insert-undefined/expected/main.js | 32 +- .../multiple-compiler/expected/one-main.js | 29 +- .../multiple-compiler/expected/two-main.js | 29 +- .../cases/new-url/expected/main.js | 32 +- .../cases/no-runtime/expected/main.js | 32 +- .../cases/runtime/expected/runtime~main.js | 30 +- .../StatsTestCases.basictest.js.snap | 42 +- 37 files changed, 933 insertions(+), 639 deletions(-) rename plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{async.$048dd0ea10a262087819$.css => async.$dec0863f5e812ee7cadd$.css} (100%) rename plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{main.$048dd0ea10a262087819$.css => main.$dec0863f5e812ee7cadd$.css} (100%) diff --git a/Cargo.lock b/Cargo.lock index 838a5a085672..5fafe08d93e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3338,6 +3338,7 @@ dependencies = [ "bitflags 2.5.0", "dashmap", "indexmap 2.2.6", + "indoc", "itertools", "linked_hash_set", "num-bigint", diff --git a/crates/rspack_plugin_javascript/Cargo.toml b/crates/rspack_plugin_javascript/Cargo.toml index ad81ff50f5ba..32410fa9c7ea 100644 --- a/crates/rspack_plugin_javascript/Cargo.toml +++ b/crates/rspack_plugin_javascript/Cargo.toml @@ -10,6 +10,7 @@ async-trait = { workspace = true } bitflags = { workspace = true } dashmap = { workspace = true } indexmap = { workspace = true } +indoc = { workspace = true } itertools = { workspace = true } linked_hash_set = { workspace = true } num-bigint = { version = "0.4.4" } diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index 0c87696e2539..c6fb0e25b39a 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -9,17 +9,20 @@ mod mangle_exports_plugin; pub mod module_concatenation_plugin; mod side_effects_flag_plugin; +use std::borrow::Cow; use std::hash::Hash; pub use drive::*; pub use flag_dependency_exports_plugin::*; pub use flag_dependency_usage_plugin::*; +use indoc::indoc; pub use mangle_exports_plugin::*; pub use module_concatenation_plugin::*; use once_cell::sync::Lazy; use rspack_core::rspack_sources::{BoxSource, ConcatSource, RawSource, SourceExt}; use rspack_core::{ - render_init_fragments, ChunkRenderContext, ChunkUkey, Compilation, CompilationId, RuntimeGlobals, + basic_function, render_init_fragments, ChunkRenderContext, ChunkUkey, Compilation, CompilationId, + RuntimeGlobals, }; use rspack_error::Result; use rspack_hash::RspackHash; @@ -62,158 +65,190 @@ impl JsPlugin { COMPILATION_DRIVES_MAP.entry(compilation.id()).or_default() } - pub fn render_require(&self, chunk_ukey: &ChunkUkey, compilation: &Compilation) -> BoxSource { + pub fn render_require(&self, chunk_ukey: &ChunkUkey, compilation: &Compilation) -> String { let runtime_requirements = compilation .chunk_graph .get_chunk_runtime_requirements(chunk_ukey); let strict_module_error_handling = compilation.options.output.strict_module_error_handling; - let mut sources = ConcatSource::default(); + let mut sources: Vec> = Vec::new(); - sources.add(RawSource::from( - r#"// Check if module is in cache + sources.push( + indoc! {r#" + // Check if module is in cache var cachedModule = __webpack_module_cache__[moduleId]; if (cachedModule !== undefined) { - "#, - )); + "#} + .into(), + ); if strict_module_error_handling { - sources.add(RawSource::from( - "if (cachedModule.error !== undefined) throw cachedModule.error;", - )); + sources.push("if (cachedModule.error !== undefined) throw cachedModule.error;".into()); } - sources.add(RawSource::from( - r#"return cachedModule.exports; - } - // Create a new module (and put it into the cache) - var module = (__webpack_module_cache__[moduleId] = { - "#, - )); + sources.push( + indoc! {r#" + return cachedModule.exports; + } + // Create a new module (and put it into the cache) + var module = (__webpack_module_cache__[moduleId] = { + "#} + .into(), + ); if runtime_requirements.contains(RuntimeGlobals::MODULE_ID) { - sources.add(RawSource::from("id: moduleId,\n")); + sources.push("id: moduleId,\n".into()); } if runtime_requirements.contains(RuntimeGlobals::MODULE_LOADED) { - sources.add(RawSource::from("loaded: false,\n")); + sources.push("loaded: false,\n".into()); } - sources.add(RawSource::from( - r#" exports: {} - }); - // Execute the module function - "#, - )); + sources.push("exports: {}\n".into()); + sources.push( + indoc! {r#" + }); + // Execute the module function + "#} + .into(), + ); - let module_execution = match runtime_requirements + let module_execution = if runtime_requirements .contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) { - true => RawSource::from( - r#"var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ }; - __webpack_require__.i.forEach(function(handler) { handler(execOptions); }); - module = execOptions.module; - if (!execOptions.factory) { - console.error("undefined factory", moduleId) - } - execOptions.factory.call(module.exports, module, module.exports, execOptions.require); - "#, - ), - false => { - if runtime_requirements.contains(RuntimeGlobals::THIS_AS_EXPORTS) { - RawSource::from( - "__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n", - ) - } else { - RawSource::from( - "__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n", - ) + indoc!{r#" + var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ }; + __webpack_require__.i.forEach(function(handler) { handler(execOptions); }); + module = execOptions.module; + if (!execOptions.factory) { + console.error("undefined factory", moduleId) } - } + execOptions.factory.call(module.exports, module, module.exports, execOptions.require); + "#}.into() + } else if runtime_requirements.contains(RuntimeGlobals::THIS_AS_EXPORTS) { + "__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n".into() + } else { + "__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n".into() }; if strict_module_error_handling { - sources.add(RawSource::from("try {\n")); - sources.add(module_execution); - sources.add(RawSource::from( - r#"} catch (e) { - module.error = e; - throw e; - } - "#, - )); + sources.push("try {\n".into()); + sources.push(module_execution); + sources.push("} catch (e) {".into()); + sources.push("module.error = e;\nthrow e;".into()); + sources.push("}".into()); } else { - sources.add(module_execution); + sources.push(module_execution); } if runtime_requirements.contains(RuntimeGlobals::MODULE_LOADED) { - sources.add(RawSource::from( - "// Flag the module as loaded \n module.loaded = true;\n", - )); + sources.push("// Flag the module as loaded\nmodule.loaded = true;".into()); } - sources.add(RawSource::from( - "// Return the exports of the module\n return module.exports;\n", - )); + sources.push("// Return the exports of the module\nreturn module.exports;".into()); - sources.boxed() + sources.join("") } pub fn render_bootstrap( &self, chunk_ukey: &ChunkUkey, compilation: &Compilation, - ) -> (BoxSource, BoxSource) { + ) -> RenderBootstrapResult { let runtime_requirements = compilation .chunk_graph .get_chunk_runtime_requirements(chunk_ukey); let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey); let module_factories = runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES); - // let require_function = runtime_requirements.contains(RuntimeGlobals::REQUIRE); + let require_function = runtime_requirements.contains(RuntimeGlobals::REQUIRE); + let module_cache = runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE); let intercept_module_execution = runtime_requirements.contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION); - // let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE); - // let use_require = require_function || intercept_module_execution || module_used; - let mut header = ConcatSource::default(); + let module_used = runtime_requirements.contains(RuntimeGlobals::MODULE); + let require_scope_used = runtime_requirements.contains(RuntimeGlobals::REQUIRE_SCOPE); + let use_require = require_function || intercept_module_execution || module_used; + let mut header: Vec> = Vec::new(); + let mut startup: Vec> = Vec::new(); + let mut allow_inline_startup = true; if is_diff_mode() { - header.add(RawSource::from( - "\n/************************************************************************/\n", - )); + header.push( + "\n/************************************************************************/\n".into(), + ); } - header.add(RawSource::from( - "// The module cache\n var __webpack_module_cache__ = {};\n", - )); - header.add(RawSource::from( - "function __webpack_require__(moduleId) {\n", - )); - header.add(self.render_require(chunk_ukey, compilation)); - header.add(RawSource::from("\n}\n")); + if allow_inline_startup && module_factories { + startup.push("// module factories are used so entry inlining is disabled".into()); + allow_inline_startup = false; + } + if allow_inline_startup && module_cache { + startup.push("// module cache are used so entry inlining is disabled".into()); + allow_inline_startup = false; + } + if allow_inline_startup && intercept_module_execution { + startup.push("// module execution is intercepted so entry inlining is disabled".into()); + allow_inline_startup = false; + } + + if use_require || module_cache { + header.push("// The module cache\nvar __webpack_module_cache__ = {};\n".into()); + } + + if use_require { + header.push( + format!( + "// The require function\nfunction {}(moduleId) {{\n", + RuntimeGlobals::REQUIRE + ) + .into(), + ); + header.push(self.render_require(chunk_ukey, compilation).into()); + header.push("\n}\n".into()); + } else if require_scope_used { + header.push( + format!( + "// The require scope\nvar {} = {{}};\n", + RuntimeGlobals::REQUIRE + ) + .into(), + ); + } if module_factories || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) { - header.add(RawSource::from( - "// expose the modules object (__webpack_modules__)\n __webpack_require__.m = __webpack_modules__;\n", - )); + header.push( + format!( + "// expose the modules object (__webpack_modules__)\n{} = __webpack_modules__;\n", + RuntimeGlobals::MODULE_FACTORIES + ) + .into(), + ); } if runtime_requirements.contains(RuntimeGlobals::MODULE_CACHE) { - header.add(RawSource::from( - "// expose the module cache\n __webpack_require__.c = __webpack_module_cache__;\n", - )); + header.push( + format!( + "// expose the module cache\n{} = __webpack_module_cache__;\n", + RuntimeGlobals::MODULE_CACHE + ) + .into(), + ); } if intercept_module_execution { - header.add(RawSource::from( - "// expose the module execution interceptor\n __webpack_require__.i = [];\n", - )); + header.push( + format!( + "// expose the module execution interceptor\n{} = [];\n", + RuntimeGlobals::INTERCEPT_MODULE_EXECUTION + ) + .into(), + ); } - let mut startup = vec![]; - if !runtime_requirements.contains(RuntimeGlobals::STARTUP_NO_DEFAULT) { if chunk.has_entry_module(&compilation.chunk_graph) { + let mut buf2: Vec> = Vec::new(); + buf2.push("// Load entry module and return exports".into()); let entries = compilation .chunk_graph .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey); @@ -231,6 +266,50 @@ impl JsPlugin { .to_string() }) .collect::>(); + if allow_inline_startup && !chunk_ids.is_empty() { + buf2.push("// This entry module depends on other loaded chunks and execution need to be delayed".into()); + allow_inline_startup = false; + } + if allow_inline_startup && { + let module_graph = compilation.get_module_graph(); + module_graph + .get_incoming_connections_by_origin_module(module) + .iter() + .any(|(origin_module, connections)| { + if let Some(origin_module) = origin_module { + connections + .iter() + .any(|c| c.is_target_active(&module_graph, Some(&chunk.runtime))) + && compilation + .chunk_graph + .get_module_runtimes(*origin_module, &compilation.chunk_by_ukey) + .into_values() + .any(|runtime| runtime.intersection(&chunk.runtime).count() > 0) + } else { + false + } + }) + } { + buf2.push( + "// This entry module is referenced by other modules so it can't be inlined".into(), + ); + allow_inline_startup = false; + } + if allow_inline_startup { + // TODO: topLevelDeclarations and inlineInRuntimeBailout + allow_inline_startup = false; + } + let entry_runtime_requirements = compilation + .chunk_graph + .get_module_runtime_requirements(*module, &chunk.runtime); + if allow_inline_startup + && let Some(entry_runtime_requirements) = entry_runtime_requirements + && entry_runtime_requirements.contains(RuntimeGlobals::MODULE) + { + allow_inline_startup = false; + buf2.push("// This entry module used 'module' so it can't be inlined".into()); + } + let module_id = compilation .get_module_graph() .module_graph_module_by_identifier(module) @@ -242,84 +321,135 @@ impl JsPlugin { } if !chunk_ids.is_empty() { - startup.push(format!( - "{}{}(undefined, {} , function() {{ return __webpack_require__({module_id_expr}) }});", - if i + 1 == entries.len() { - "var __webpack_exports__ = " - } else { - "" - }, - RuntimeGlobals::ON_CHUNKS_LOADED, - stringify_array(&chunk_ids) - )); - } - /* if use_require */ - else { - startup.push(format!( - "{}__webpack_require__({module_id_expr});", - if i + 1 == entries.len() { - "var __webpack_exports__ = " - } else { - "" - }, - )) + buf2.push( + format!( + "{}{}(undefined, {}, function() {{ return {}({module_id_expr}) }});", + if i + 1 == entries.len() { + format!("var {} = ", RuntimeGlobals::EXPORTS) + } else { + "".to_string() + }, + RuntimeGlobals::ON_CHUNKS_LOADED, + stringify_array(&chunk_ids), + RuntimeGlobals::REQUIRE + ) + .into(), + ); + } else if use_require { + buf2.push( + format!( + "{}{}({module_id_expr});", + if i + 1 == entries.len() { + format!("var {} = ", RuntimeGlobals::EXPORTS) + } else { + "".to_string() + }, + RuntimeGlobals::REQUIRE + ) + .into(), + ) + } else { + let should_exec = i + 1 == entries.len(); + if should_exec { + buf2.push(format!("var {} = {{}}", RuntimeGlobals::EXPORTS).into()); + } + if require_scope_used { + buf2.push( + format!( + "__webpack_modules__[{module_id_expr}](0, {}, {});", + if should_exec { + RuntimeGlobals::EXPORTS.name() + } else { + "{}" + }, + RuntimeGlobals::REQUIRE + ) + .into(), + ); + } else if let Some(entry_runtime_requirements) = entry_runtime_requirements + && entry_runtime_requirements.contains(RuntimeGlobals::EXPORTS) + { + buf2.push( + format!( + "__webpack_modules__[{module_id_expr}](0, {});", + if should_exec { + RuntimeGlobals::EXPORTS.name() + } else { + "{}" + } + ) + .into(), + ); + } else { + buf2.push(format!("__webpack_modules__[{module_id_expr}]();").into()); + } } - // else { - // startup.push(format!("__webpack_modules__[{module_id_expr}]();")) - // } } if runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED) { - startup.push(format!( - "__webpack_exports__ = {}(__webpack_exports__);", - RuntimeGlobals::ON_CHUNKS_LOADED - )); + buf2.push( + format!( + "__webpack_exports__ = {}(__webpack_exports__);", + RuntimeGlobals::ON_CHUNKS_LOADED + ) + .into(), + ); } if runtime_requirements.contains(RuntimeGlobals::STARTUP) { - header.add(RawSource::from(format!( - r#"// the startup function - {} = function(){{ - {} - return __webpack_exports__; - }}; - "#, - RuntimeGlobals::STARTUP, - std::mem::take(&mut startup).join("\n") - ))); - startup.push("// run startup".to_string()); - startup.push(format!( - "var __webpack_exports__ = {}();", - RuntimeGlobals::STARTUP - )); + allow_inline_startup = false; + header.push( + format!( + "// the startup function\n{} = {}\n", + RuntimeGlobals::STARTUP, + basic_function( + "", + &format!("{}\nreturn {}", buf2.join("\n"), RuntimeGlobals::EXPORTS) + ) + ) + .into(), + ); + startup.push("// run startup".into()); + startup.push( + format!( + "var {} = {}();", + RuntimeGlobals::EXPORTS, + RuntimeGlobals::STARTUP + ) + .into(), + ); + } else { + startup.push("// startup".into()); + startup.push(buf2.join("\n").into()); } } else if runtime_requirements.contains(RuntimeGlobals::STARTUP) { - header.add(RawSource::from(format!( - r#"// the startup function - // It's empty as no entry modules are in this chunk - {} = function(){{}}; - "#, - RuntimeGlobals::STARTUP - ))); + header.push( + format!( + "// the startup function\n// It's empty as no entry modules are in this chunk\n{} = function(){{}};", + RuntimeGlobals::STARTUP + ) + .into(), + ); } } else if runtime_requirements.contains(RuntimeGlobals::STARTUP) { - header.add(RawSource::from(format!( - r#"// the startup function - // It's empty as some runtime module handles the default behavior - {} = function(){{}}; - "#, - RuntimeGlobals::STARTUP - ))); - startup.push("// run startup".to_string()); - startup.push(format!( - "var __webpack_exports__ = {}();", - RuntimeGlobals::STARTUP - )); + header.push( + format!( + "// the startup function\n// It's empty as some runtime module handles the default behavior\n{} = function(){{}};", + RuntimeGlobals::STARTUP + ) + .into(), + ); + startup.push("// run startup".into()); + startup.push(format!("var __webpack_exports__ = {}();", RuntimeGlobals::STARTUP).into()); } if is_diff_mode() { - header.add(RawSource::from( - "\n/************************************************************************/\n", - )); + header.push( + "\n/************************************************************************/\n".into(), + ); + } + RenderBootstrapResult { + header: RawSource::from(header.join("\n")).boxed(), + startup: RawSource::from(startup.join("\n")).boxed(), + allow_inline_startup, } - (header.boxed(), RawSource::from(startup.join("\n")).boxed()) } pub async fn render_main( @@ -332,8 +462,12 @@ impl JsPlugin { let runtime_requirements = compilation .chunk_graph .get_tree_runtime_requirements(chunk_ukey); + let RenderBootstrapResult { + header, + startup, + allow_inline_startup: _, + } = self.render_bootstrap(chunk_ukey, compilation); let (module_source, chunk_init_fragments) = render_chunk_modules(compilation, chunk_ukey)?; - let (header, startup) = self.render_bootstrap(chunk_ukey, compilation); let mut sources = ConcatSource::default(); sources.add(RawSource::from("var __webpack_modules__ = ")); sources.add(module_source); @@ -437,9 +571,14 @@ impl JsPlugin { hasher: &mut RspackHash, ) { // sample hash use content - let (header, startup) = self.render_bootstrap(chunk_ukey, compilation); + let RenderBootstrapResult { + header, + startup, + allow_inline_startup, + } = self.render_bootstrap(chunk_ukey, compilation); header.hash(hasher); startup.hash(hasher); + allow_inline_startup.hash(hasher); } } @@ -448,3 +587,10 @@ pub struct ExtractedCommentsInfo { pub source: BoxSource, pub comments_file_name: String, } + +#[derive(Debug)] +pub struct RenderBootstrapResult { + header: BoxSource, + startup: BoxSource, + allow_inline_startup: bool, +} diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap index 142957a81c45..60621d14ca84 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap @@ -102,7 +102,7 @@ Object { "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "ee9a5ee8da42dac2c2aa", + "hash": "bca12e9a78756a7efe53", "logging": Object {}, "modules": Array [ Object { @@ -402,7 +402,7 @@ Object { "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "36dd148024fa89ee453a", + "hash": "d58eb30bef2d7c671efc", "logging": Object {}, "modules": Array [ Object { @@ -968,7 +968,7 @@ exports.c = require(\\"./c?c=3\\"); "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "4fed4a0fec64e42d02f8", + "hash": "d7135bcf6947c43df947", "logging": Object {}, "modules": Array [ Object { diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index 30fc4ae9cac6..0e6f67f07adc 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -3,8 +3,8 @@ exports[`statsOutput statsOutput/auxiliary-files-test should print correct stats for auxiliary-files-test 1`] = ` "PublicPath: auto asset a09d8e0f399c215faa79.png 7 bytes {909} [emitted] [from: raw.png] (name: main) -asset bundle.js 2.4 KiB {909} [emitted] (name: main) -Entrypoint main 2.4 KiB = bundle.js +asset bundle.js 2.41 KiB {909} [emitted] (name: main) +Entrypoint main 2.41 KiB = bundle.js chunk {909} bundle.js (main) [entry] ./raw.png [193] {909} [no exports] @@ -33,7 +33,7 @@ webpack/runtime/auto_public_path {909} [no exports] [used exports unknown] -Rspack compiled successfully (96c9a0233f5bdeaa93e8)" +Rspack compiled successfully (3004b4b12fa2d8cfc296)" `; exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for builtin-swc-loader-parse-error 1`] = ` @@ -55,23 +55,23 @@ Rspack compiled with 1 error" exports[`statsOutput statsOutput/css-concat-error should print correct stats for css-concat-error 1`] = ` "PublicPath: auto -asset main.js 654 bytes [emitted] (name: main) -Entrypoint main 654 bytes = main.js +asset main.js 51 bytes [emitted] (name: main) +Entrypoint main 51 bytes = main.js ERROR in × Resolve error: Can't resolve './src' in 'Xdir/css-concat-error' -Rspack x.x.x compiled with 1 error in X s (8808376bbd25437de260)" +Rspack x.x.x compiled with 1 error in X s (14590012531235fdfcfb)" `; exports[`statsOutput statsOutput/filename should print correct stats for filename 1`] = ` "PublicPath: auto asset 521.xxxx.js 335 bytes [emitted] -asset 909.xxxx.js 8.73 KiB [emitted] (name: main) -Entrypoint main 8.73 KiB = 909.xxxx.js +asset 909.xxxx.js 8.74 KiB [emitted] (name: main) +Entrypoint main 8.74 KiB = 909.xxxx.js runtime modules 11 modules ./index.js ./dynamic.js -Rspack x.x.x compiled successfully in X s (a41322d0088be2cf18dc)" +Rspack x.x.x compiled successfully in X s (68af0b9e034af568f652)" `; exports[`statsOutput statsOutput/hot+production should print correct stats for hot+production 1`] = ` @@ -80,7 +80,7 @@ asset main.js 32.1 KiB [emitted] (name: main) Entrypoint main 32.1 KiB = main.js runtime modules 11 modules ./index.js -Rspack x.x.x compiled successfully in X s (bda0662c38188eca4d63)" +Rspack x.x.x compiled successfully in X s (bb432299572e60c344f6)" `; exports[`statsOutput statsOutput/ignore-plugin should print correct stats for ignore-plugin 1`] = ` @@ -125,15 +125,15 @@ Rspack compiled with 2 errors" exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct stats for limit-chunk-count-plugin 1`] = ` "1 chunks: PublicPath: auto - asset bundle1.js 3.5 KiB [emitted] (name: main) - Entrypoint main 3.5 KiB = bundle1.js + asset bundle1.js 3.51 KiB [emitted] (name: main) + Entrypoint main 3.51 KiB = bundle1.js chunk bundle1.js (main) <{909}> >{909}< [entry] ./b.js ./c.js ./d.js ./e.js ./index.js - 1 chunks (Rspack x.x.x) compiled successfully in X s (9343a795eebf86cac89a) + 1 chunks (Rspack x.x.x) compiled successfully in X s (7d08f247384080310cc5) 2 chunks: PublicPath: auto @@ -147,7 +147,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle2.js (main) >{76}< [entry] ./b.js ./index.js - 2 chunks (Rspack x.x.x) compiled successfully in X s (58d446010942300c8786) + 2 chunks (Rspack x.x.x) compiled successfully in X s (535e73efb0959a050d83) 3 chunks: PublicPath: auto @@ -163,7 +163,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle3.js (main) >{76}< [entry] ./b.js ./index.js - 3 chunks (Rspack x.x.x) compiled successfully in X s (e1f702c28a1f7745f19e) + 3 chunks (Rspack x.x.x) compiled successfully in X s (b3d9890d88975ac30dd7) 4 chunks: PublicPath: auto @@ -181,7 +181,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle4.js (main) >{76}< [entry] ./b.js ./index.js - 4 chunks (Rspack x.x.x) compiled successfully in X s (799760b5db8d720723c3)" + 4 chunks (Rspack x.x.x) compiled successfully in X s (ea15c057f924da088c91)" `; exports[`statsOutput statsOutput/logging-loader should print correct stats for logging-loader 1`] = ` @@ -206,7 +206,7 @@ Rspack compiled with 1 error" `; exports[`statsOutput statsOutput/named-chunk-group should print correct stats for named-chunk-group 1`] = ` -"Entrypoint main 8.72 KiB = main.js +"Entrypoint main 8.73 KiB = main.js Chunk Group cimanyd 335 bytes = cimanyd.js" `; @@ -222,8 +222,8 @@ Rspack compiled with 1 error" `; exports[`statsOutput statsOutput/optimization-runtime-chunk should print correct stats for optimization-runtime-chunk 1`] = ` -"Entrypoint e1 3.81 KiB = e1~runtime.js 3.48 KiB e1.js 336 bytes -Entrypoint e2 3.81 KiB = e2~runtime.js 3.48 KiB e2.js 336 bytes +"Entrypoint e1 3.77 KiB = e1~runtime.js 3.44 KiB e1.js 336 bytes +Entrypoint e2 3.77 KiB = e2~runtime.js 3.44 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e1~runtime.js (e1~runtime) [initial] chunk e2.js (e2) [entry] @@ -231,8 +231,8 @@ chunk e2~runtime.js (e2~runtime) [initial]" `; exports[`statsOutput statsOutput/optimization-runtime-chunk-multiple should print correct stats for optimization-runtime-chunk-multiple 1`] = ` -"Entrypoint e1 3.81 KiB = runtime~e1.js 3.48 KiB e1.js 336 bytes -Entrypoint e2 3.81 KiB = runtime~e2.js 3.48 KiB e2.js 336 bytes +"Entrypoint e1 3.77 KiB = runtime~e1.js 3.44 KiB e1.js 336 bytes +Entrypoint e2 3.77 KiB = runtime~e2.js 3.44 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e2.js (e2) [entry] chunk runtime~e1.js (runtime~e1) [initial] @@ -240,16 +240,16 @@ chunk runtime~e2.js (runtime~e2) [initial]" `; exports[`statsOutput statsOutput/optimization-runtime-chunk-single should print correct stats for optimization-runtime-chunk-single 1`] = ` -"Entrypoint e1 3.81 KiB = runtime.js 3.48 KiB e1.js 336 bytes -Entrypoint e2 3.81 KiB = runtime.js 3.48 KiB e2.js 336 bytes +"Entrypoint e1 3.77 KiB = runtime.js 3.44 KiB e1.js 336 bytes +Entrypoint e2 3.77 KiB = runtime.js 3.44 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e2.js (e2) [entry] chunk runtime.js (runtime) [initial]" `; exports[`statsOutput statsOutput/optimization-runtime-chunk-true should print correct stats for optimization-runtime-chunk-true 1`] = ` -"Entrypoint e1 3.81 KiB = runtime~e1.js 3.48 KiB e1.js 336 bytes -Entrypoint e2 3.81 KiB = runtime~e2.js 3.48 KiB e2.js 336 bytes +"Entrypoint e1 3.77 KiB = runtime~e1.js 3.44 KiB e1.js 336 bytes +Entrypoint e2 3.77 KiB = runtime~e2.js 3.44 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e2.js (e2) [entry] chunk runtime~e1.js (runtime~e1) [initial] @@ -306,11 +306,11 @@ runtime modules 12 modules ./index.js ERROR in × asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ main.js (303.319 KiB) + │ main.js (303.329 KiB) ERROR in × entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (303.319 KiB) + │ main (303.329 KiB) │ main.js @@ -356,8 +356,8 @@ exports[`statsOutput statsOutput/reasons should print correct stats for reasons exports[`statsOutput statsOutput/resolve-overflow-error should print correct stats for resolve-overflow-error 1`] = ` "PublicPath: auto -asset main.js 1.02 KiB [emitted] (name: main) -Entrypoint main 1.02 KiB = main.js +asset main.js 496 bytes [emitted] (name: main) +Entrypoint main 496 bytes = main.js ./index.js ERROR in ./index.js @@ -369,20 +369,20 @@ ERROR in ./index.js ╰──── help: maybe it had cyclic aliases -Rspack x.x.x compiled with 1 error in X s (1610bb37730c587998bd)" +Rspack x.x.x compiled with 1 error in X s (7f61f2ab4619ed37875a)" `; exports[`statsOutput statsOutput/resolve-unexpected-exports-in-pkg-error should print correct stats for resolve-unexpected-exports-in-pkg-error 1`] = ` "PublicPath: auto -asset bundle.js 1.46 KiB [emitted] (name: main) -Entrypoint main 1.46 KiB = bundle.js +asset bundle.js 1.02 KiB [emitted] (name: main) +Entrypoint main 1.02 KiB = bundle.js runtime modules 1 module ./index.js ERROR in ./index.js × Invalid \\"exports\\" target \\"../../index.js\\" defined for '.' in the package config Xdir/resolve-unexpected-exports-in-pkg-error/node_modules/pkg-a/package.json -Rspack x.x.x compiled with 1 error in X s (b45f1a2adf9c9eae762e)" +Rspack x.x.x compiled with 1 error in X s (1bd27b416654b26e67b4)" `; exports[`statsOutput statsOutput/runtime-modules should print correct stats for runtime-modules 1`] = ` @@ -394,8 +394,8 @@ webpack/runtime/define_property_getters" exports[`statsOutput statsOutput/runtime-specific-exports should print correct stats for runtime-specific-exports 1`] = ` "PublicPath: auto -asset main.js 1.66 KiB [emitted] (name: main) -Entrypoint main 1.66 KiB = main.js +asset main.js 1.67 KiB [emitted] (name: main) +Entrypoint main 1.67 KiB = main.js ./math.js [exports: add, multiply] [only some exports used: add] @@ -405,13 +405,13 @@ Entrypoint main 1.66 KiB = main.js ./increment.js [exports: decrement, increment, incrementBy2] [only some exports used: increment] -Rspack x.x.x compiled successfully in X s (9efe9f85d71294bf4e5f)" +Rspack x.x.x compiled successfully in X s (e07c3d56fbd8ae9f84a7)" `; exports[`statsOutput statsOutput/side-effects-bailouts should print correct stats for side-effects-bailouts 1`] = ` "PublicPath: auto -asset main.js 1.68 KiB {909} [emitted] (name: main) -Entrypoint main 1.68 KiB = main.js +asset main.js 1.69 KiB {909} [emitted] (name: main) +Entrypoint main 1.69 KiB = main.js chunk {909} main.js (main) [entry] ./lib.js [467] {909} [exports: test] @@ -440,35 +440,35 @@ webpack/runtime/define_property_getters {909} [no exports] [used exports unknown] -1970-04-20 12:42:42: Rspack x.x.x compiled successfully in X s (c4f7bcbb8ec6a06a4661)" +1970-04-20 12:42:42: Rspack x.x.x compiled successfully in X s (e404d96f2e8e100824bc)" `; exports[`statsOutput statsOutput/simple-export should print correct stats for simple-export 1`] = ` "PublicPath: auto -asset bundle.js 1.79 KiB [emitted] (name: main) -Entrypoint main 1.79 KiB = bundle.js +asset bundle.js 1.35 KiB [emitted] (name: main) +Entrypoint main 1.35 KiB = bundle.js runtime modules 3 modules ./index.js -Rspack x.x.x compiled successfully in X s (a3d8bfb29f0f2ccec405)" +Rspack x.x.x compiled successfully in X s (d1bbc9fbb95041999c16)" `; exports[`statsOutput statsOutput/simple-module-source should print correct stats for simple-module-source 1`] = ` "PublicPath: auto -asset bundle.js 1.94 KiB [emitted] (name: main) -Entrypoint main 1.94 KiB = bundle.js +asset bundle.js 1.95 KiB [emitted] (name: main) +Entrypoint main 1.95 KiB = bundle.js runtime modules 3 modules orphan modules [orphan] 1 module ./raw.png ./index.js -Rspack compiled successfully (d0ce130488abf5f87f64)" +Rspack compiled successfully (4b30a8086cf4ac46bff6)" `; exports[`statsOutput statsOutput/stats-hooks should print correct stats for stats-hooks 1`] = ` "PublicPath: auto -asset main.js 764 bytes [emitted111] (name: main) [testA: aaaaaa] -Entrypoint main 764 bytes = main.js +asset main.js 217 bytes [emitted111] (name: main) [testA: aaaaaa] +Entrypoint main 217 bytes = main.js ./index.js -Rspack compiled successfully (d55a67420c97eab0f0a6)" +Rspack compiled successfully (2c363b6b7beda4d45ccc)" `; exports[`statsOutput statsOutput/try-require-module should print correct stats for try-require-module 1`] = ` diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt index 555134baee28..4a373210ab61 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt @@ -4,7 +4,7 @@ Rspack App - + diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt index bf41505eb9c0..9824b7f0d220 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt @@ -13,23 +13,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() , diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt index 42bc8be1db1c..e48d5b063301 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt @@ -7,23 +7,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt index ce3e4e04406c..ee39beb23ed6 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt @@ -5,7 +5,7 @@ ```javascript Array [ Object { - "main.1e610dc4781566449f96.js": (function() { + "main.de1e38a3841970a36482.js": (function() { var __webpack_modules__ = { "600": (function (module) { module.exports = "This is hook"; @@ -13,23 +13,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() , @@ -50,7 +55,7 @@ undefined ```javascript Array [ Object { - "main.1e610dc4781566449f96.js": // UPDATED + "main.de1e38a3841970a36482.js": // UPDATED (function() { var __webpack_modules__ = { "600": (function (module) { @@ -59,23 +64,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() , diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt index 2bb46a3aa1ba..d78c52a08834 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt @@ -1,4 +1,4 @@ -```js title=main.72cf2b1eb9f1ef5c7d0a.js +```js title=main.cb18450578c7263b2f4e.js // UPDATED (function() { var __webpack_modules__ = { @@ -8,23 +8,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() diff --git a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt index 3ded78c8dacc..a20a92f123aa 100644 --- a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt @@ -139,7 +139,6 @@ Array [ 104, 101, 10, - 32, 118, 97, 114, @@ -175,6 +174,31 @@ Array [ 125, 59, 10, + 10, + 47, + 47, + 32, + 84, + 104, + 101, + 32, + 114, + 101, + 113, + 117, + 105, + 114, + 101, + 32, + 102, + 117, + 110, + 99, + 116, + 105, + 111, + 110, + 10, 102, 117, 110, @@ -216,6 +240,7 @@ Array [ 32, 123, 10, + 10, 47, 47, 32, @@ -247,14 +272,6 @@ Array [ 104, 101, 10, - 32, - 32, - 32, - 32, - 32, - 32, - 32, - 32, 118, 97, 114, @@ -310,14 +327,6 @@ Array [ 93, 59, 10, - 32, - 32, - 32, - 32, - 32, - 32, - 32, - 32, 105, 102, 32, @@ -352,12 +361,6 @@ Array [ 32, 123, 10, - 32, - 32, - 32, - 32, - 32, - 32, 114, 101, 116, @@ -387,20 +390,8 @@ Array [ 115, 59, 10, - 32, - 32, - 32, - 32, - 32, - 32, 125, 10, - 32, - 32, - 32, - 32, - 32, - 32, 47, 47, 32, @@ -452,12 +443,6 @@ Array [ 101, 41, 10, - 32, - 32, - 32, - 32, - 32, - 32, 118, 97, 114, @@ -511,13 +496,6 @@ Array [ 32, 123, 10, - 32, - 32, - 32, - 32, - 32, - 32, - 32, 101, 120, 112, @@ -530,22 +508,10 @@ Array [ 123, 125, 10, - 32, - 32, - 32, - 32, - 32, - 32, 125, 41, 59, 10, - 32, - 32, - 32, - 32, - 32, - 32, 47, 47, 32, @@ -577,12 +543,6 @@ Array [ 111, 110, 10, - 32, - 32, - 32, - 32, - 32, - 32, 95, 95, 119, @@ -695,7 +655,6 @@ Array [ 108, 101, 10, - 32, 114, 101, 116, @@ -722,6 +681,57 @@ Array [ 10, 125, 10, + 47, + 47, + 32, + 115, + 116, + 97, + 114, + 116, + 117, + 112, + 10, + 47, + 47, + 32, + 76, + 111, + 97, + 100, + 32, + 101, + 110, + 116, + 114, + 121, + 32, + 109, + 111, + 100, + 117, + 108, + 101, + 32, + 97, + 110, + 100, + 32, + 114, + 101, + 116, + 117, + 114, + 110, + 32, + 101, + 120, + 112, + 111, + 114, + 116, + 115, + 10, 118, 97, 114, @@ -793,23 +803,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() , diff --git a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt index 42bc8be1db1c..e48d5b063301 100644 --- a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt @@ -7,23 +7,28 @@ module.exports = "This is hook"; } // The module cache - var __webpack_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__); +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; +return module.exports; } +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("600"); })() diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt index 9a7dd8d4de03..55851dde92b9 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt @@ -35,21 +35,24 @@ module.exports = require('fs')}), } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/compat_get_default_export @@ -84,6 +87,8 @@ __webpack_require__.o = function (obj, prop) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./duplicate.js"); })() diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt index ea5c061ed3a8..21ae69b8b57d 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt @@ -30,21 +30,24 @@ module.exports = require('fs')}), } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/compat_get_default_export @@ -79,6 +82,8 @@ __webpack_require__.o = function (obj, prop) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./request.js"); })() diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt index 5fa694508f35..5e1c8434afb2 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt @@ -30,21 +30,24 @@ module.exports = require('fs')}), } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/compat_get_default_export @@ -79,6 +82,8 @@ __webpack_require__.o = function (obj, prop) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./resource.js"); })() diff --git a/packages/rspack-test-tools/tests/statsAPICases/basic.js b/packages/rspack-test-tools/tests/statsAPICases/basic.js index 7baa730c6c8c..e5ea9a211aa4 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/basic.js +++ b/packages/rspack-test-tools/tests/statsAPICases/basic.js @@ -34,7 +34,7 @@ module.exports = { Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 entry ./fixtures/a - Rspack compiled successfully (ee9a5ee8da42dac2c2aa)" + Rspack compiled successfully (bca12e9a78756a7efe53)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/exports.js b/packages/rspack-test-tools/tests/statsAPICases/exports.js index a2a14e75b794..f06c8e391eb3 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/exports.js +++ b/packages/rspack-test-tools/tests/statsAPICases/exports.js @@ -44,7 +44,7 @@ module.exports = { ./fixtures/esm/abc.js [no exports] [no exports used] - Rspack compiled successfully (36dd148024fa89ee453a)" + Rspack compiled successfully (d58eb30bef2d7c671efc)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/to-string.js b/packages/rspack-test-tools/tests/statsAPICases/to-string.js index eb0efed65fa9..adebc8a04308 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/to-string.js +++ b/packages/rspack-test-tools/tests/statsAPICases/to-string.js @@ -31,7 +31,7 @@ module.exports = { help: You may need an appropriate loader to handle this file type. - Rspack compiled with 1 error (2269ff26c17a6bb04d0e)" + Rspack compiled with 1 error (6343e7b6958312d248a1)" `); } }; diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$048dd0ea10a262087819$.css b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$dec0863f5e812ee7cadd$.css similarity index 100% rename from plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$048dd0ea10a262087819$.css rename to plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$dec0863f5e812ee7cadd$.css diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$048dd0ea10a262087819$.css b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$dec0863f5e812ee7cadd$.css similarity index 100% rename from plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$048dd0ea10a262087819$.css rename to plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$dec0863f5e812ee7cadd$.css diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js index cb12f77f8ffe..2fe31e2f2742 100644 --- a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js +++ b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js @@ -16,25 +16,29 @@ __webpack_require__.r(__webpack_exports__); } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/ensure_chunk !function() { __webpack_require__.f = {}; @@ -75,7 +79,7 @@ __webpack_require__.e = function (chunkId) { // webpack/runtime/get_full_hash !function() { __webpack_require__.h = function () { - return "048dd0ea10a262087819"; + return "dec0863f5e812ee7cadd"; }; }(); @@ -386,5 +390,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( ); }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js b/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js index 2a1b8867493c..f1a87a9a8bdf 100644 --- a/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js +++ b/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js @@ -22,21 +22,24 @@ console.log((0, _style_css__WEBPACK_IMPORTED_MODULE_0__.cnA)(), (0, _style_css__ } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/define_property_getters @@ -67,5 +70,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs b/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs index 0577c595d48e..0ebd8c2813aa 100644 --- a/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs +++ b/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs @@ -28,21 +28,24 @@ console.log({ } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/define_property_getters @@ -73,4 +76,6 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); \ No newline at end of file diff --git a/plugin-test/css-extract/cases/es-named-export/expected/main.js b/plugin-test/css-extract/cases/es-named-export/expected/main.js index 9843f6f6d0ad..2c4ccc5a8bdd 100644 --- a/plugin-test/css-extract/cases/es-named-export/expected/main.js +++ b/plugin-test/css-extract/cases/es-named-export/expected/main.js @@ -29,21 +29,24 @@ console.log({ } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/define_property_getters @@ -74,5 +77,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js b/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js index e5e837b00c78..1c3281cda431 100644 --- a/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js +++ b/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js @@ -28,21 +28,24 @@ console.log({ } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/define_property_getters @@ -73,5 +76,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js b/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js index b521a3b49b8e..5d0d61ff4c6d 100644 --- a/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js +++ b/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js @@ -21,21 +21,24 @@ console.log({ } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/make_namespace_object @@ -49,5 +52,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/export-only-locals/expected/main.js b/plugin-test/css-extract/cases/export-only-locals/expected/main.js index b521a3b49b8e..5d0d61ff4c6d 100644 --- a/plugin-test/css-extract/cases/export-only-locals/expected/main.js +++ b/plugin-test/css-extract/cases/export-only-locals/expected/main.js @@ -21,21 +21,24 @@ console.log({ } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/make_namespace_object @@ -49,5 +52,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/hmr/expected/main.js b/plugin-test/css-extract/cases/hmr/expected/main.js index 6712eb5b0945..4bfd959b9a8e 100644 --- a/plugin-test/css-extract/cases/hmr/expected/main.js +++ b/plugin-test/css-extract/cases/hmr/expected/main.js @@ -224,41 +224,44 @@ if (true) { } // The module cache - var __webpack_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) { - if (cachedModule.error !== undefined) throw cachedModule.error;return cachedModule.exports; - } - // Create a new module (and put it into the cache) - var module = (__webpack_module_cache__[moduleId] = { - id: moduleId, - exports: {} - }); - // Execute the module function - try { +var cachedModule = __webpack_module_cache__[moduleId]; +if (cachedModule !== undefined) { +if (cachedModule.error !== undefined) throw cachedModule.error;return cachedModule.exports; +} +// Create a new module (and put it into the cache) +var module = (__webpack_module_cache__[moduleId] = { +id: moduleId, +exports: {} +}); +// Execute the module function +try { var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ }; - __webpack_require__.i.forEach(function(handler) { handler(execOptions); }); - module = execOptions.module; - if (!execOptions.factory) { - console.error("undefined factory", moduleId) - } - execOptions.factory.call(module.exports, module, module.exports, execOptions.require); - } catch (e) { - module.error = e; - throw e; - } - // Return the exports of the module - return module.exports; +__webpack_require__.i.forEach(function(handler) { handler(execOptions); }); +module = execOptions.module; +if (!execOptions.factory) { + console.error("undefined factory", moduleId) +} +execOptions.factory.call(module.exports, module, module.exports, execOptions.require); +} catch (e) {module.error = e; +throw e;}// Return the exports of the module +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; + // expose the module cache - __webpack_require__.c = __webpack_module_cache__; +__webpack_require__.c = __webpack_module_cache__; + // expose the module execution interceptor - __webpack_require__.i = []; +__webpack_require__.i = []; // webpack/runtime/get mini-css chunk filename !function() { // This function allow to reference chunks @@ -1385,5 +1388,8 @@ __webpack_require__.hmrM = function () { }; }(); +// module cache are used so entry inlining is disabled +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.css?6fbf"); })() diff --git a/plugin-test/css-extract/cases/insert-function/expected/main.js b/plugin-test/css-extract/cases/insert-function/expected/main.js index fcc5809d4e83..50b56531d56e 100644 --- a/plugin-test/css-extract/cases/insert-function/expected/main.js +++ b/plugin-test/css-extract/cases/insert-function/expected/main.js @@ -7,25 +7,29 @@ __webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__. } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/ensure_chunk !function() { __webpack_require__.f = {}; @@ -371,5 +375,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( ); }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./src/index.js"); })() diff --git a/plugin-test/css-extract/cases/insert-string/expected/main.js b/plugin-test/css-extract/cases/insert-string/expected/main.js index 016b356153f6..14d77728cfc2 100644 --- a/plugin-test/css-extract/cases/insert-string/expected/main.js +++ b/plugin-test/css-extract/cases/insert-string/expected/main.js @@ -7,25 +7,29 @@ __webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__. } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/ensure_chunk !function() { __webpack_require__.f = {}; @@ -367,5 +371,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( ); }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./src/index.js"); })() diff --git a/plugin-test/css-extract/cases/insert-undefined/expected/main.js b/plugin-test/css-extract/cases/insert-undefined/expected/main.js index 5367068a8238..748a0d12e3de 100644 --- a/plugin-test/css-extract/cases/insert-undefined/expected/main.js +++ b/plugin-test/css-extract/cases/insert-undefined/expected/main.js @@ -7,25 +7,29 @@ __webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__. } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/ensure_chunk !function() { __webpack_require__.f = {}; @@ -370,5 +374,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( ); }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./src/index.js"); })() diff --git a/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js b/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js index aeb0d87f6bfc..fd17bcaa4b8e 100644 --- a/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js +++ b/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js @@ -15,21 +15,24 @@ __webpack_require__.r(__webpack_exports__); } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/make_namespace_object @@ -43,5 +46,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js b/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js index aeb0d87f6bfc..fd17bcaa4b8e 100644 --- a/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js +++ b/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js @@ -15,21 +15,24 @@ __webpack_require__.r(__webpack_exports__); } // The module cache - var __webpack_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__); +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; +return module.exports; } // webpack/runtime/make_namespace_object @@ -43,5 +46,7 @@ __webpack_require__.r = function(exports) { }; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/new-url/expected/main.js b/plugin-test/css-extract/cases/new-url/expected/main.js index 4b16ff146e0c..1c66df2ab3cb 100644 --- a/plugin-test/css-extract/cases/new-url/expected/main.js +++ b/plugin-test/css-extract/cases/new-url/expected/main.js @@ -13,25 +13,29 @@ console.log(myURL); } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/has_own_property !function() { __webpack_require__.o = function (obj, prop) { @@ -60,5 +64,7 @@ __webpack_require__.b = document.baseURI || self.location.href; var installedChunks = {"main": 0,}; }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/no-runtime/expected/main.js b/plugin-test/css-extract/cases/no-runtime/expected/main.js index bce48185d9ae..d3607377bed3 100644 --- a/plugin-test/css-extract/cases/no-runtime/expected/main.js +++ b/plugin-test/css-extract/cases/no-runtime/expected/main.js @@ -16,25 +16,29 @@ __webpack_require__.e(/* import() | async */ "async").then(__webpack_require__.b } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/ensure_chunk !function() { __webpack_require__.f = {}; @@ -277,5 +281,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( ); }(); +// startup +// Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.js"); })() diff --git a/plugin-test/css-extract/cases/runtime/expected/runtime~main.js b/plugin-test/css-extract/cases/runtime/expected/runtime~main.js index 2a851967614d..4e4a2382285d 100644 --- a/plugin-test/css-extract/cases/runtime/expected/runtime~main.js +++ b/plugin-test/css-extract/cases/runtime/expected/runtime~main.js @@ -3,25 +3,29 @@ var __webpack_modules__ = { } // The module cache - var __webpack_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__); +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; +return module.exports; } + // expose the modules object (__webpack_modules__) - __webpack_require__.m = __webpack_modules__; +__webpack_require__.m = __webpack_modules__; // webpack/runtime/create_fake_namespace_object !function() { var getProto = Object.getPrototypeOf ? function(obj) { return Object.getPrototypeOf(obj); } : function(obj) { return obj.__proto__ }; diff --git a/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap b/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap index 1d379ee61e47..04f3d7f31d33 100644 --- a/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap @@ -7,16 +7,16 @@ Entrypoint main 294 KiB = warning.pro-web.js ./index.js WARNING in ⚠ asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ warning.pro-web.js (293.709 KiB) + │ warning.pro-web.js (293.719 KiB) WARNING in ⚠ entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (293.709 KiB) + │ main (293.719 KiB) │ warning.pro-web.js WARNING in ⚠ Rspack performance recommendations:You can limit the size of your bundles by using import() to lazy load some parts of your application. │ For more info visit https://www.rspack.dev/guide/optimization/code-splitting -Rspack x.x.x compiled with 3 warnings in X s (f5892cac8944423c4fd1) +Rspack x.x.x compiled with 3 warnings in X s (fdcda4a05775a95633ca) PublicPath: auto asset warning.pro-webworker.js 294 KiB [emitted] (name: main) @@ -24,40 +24,40 @@ Entrypoint main 294 KiB = warning.pro-webworker.js ./index.js WARNING in ⚠ asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ warning.pro-webworker.js (293.709 KiB) + │ warning.pro-webworker.js (293.719 KiB) WARNING in ⚠ entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (293.709 KiB) + │ main (293.719 KiB) │ warning.pro-webworker.js WARNING in ⚠ Rspack performance recommendations:You can limit the size of your bundles by using import() to lazy load some parts of your application. │ For more info visit https://www.rspack.dev/guide/optimization/code-splitting -Rspack x.x.x compiled with 3 warnings in X s (f5892cac8944423c4fd1) +Rspack x.x.x compiled with 3 warnings in X s (fdcda4a05775a95633ca) PublicPath: (none) asset no-warning.pro-node.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.pro-node.js ./index.js -Rspack x.x.x compiled successfully in X s (f5892cac8944423c4fd1) +Rspack x.x.x compiled successfully in X s (fdcda4a05775a95633ca) PublicPath: auto asset no-warning.dev-web.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.dev-web.js ./index.js -Rspack x.x.x compiled successfully in X s (cca1ff20fc67941570c3) +Rspack x.x.x compiled successfully in X s (451db70fa838cd6e895d) PublicPath: (none) asset no-warning.dev-node.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.dev-node.js ./index.js -Rspack x.x.x compiled successfully in X s (cca1ff20fc67941570c3) +Rspack x.x.x compiled successfully in X s (451db70fa838cd6e895d) PublicPath: auto asset no-warning.dev-web-with-limit-set.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.dev-web-with-limit-set.js ./index.js -Rspack x.x.x compiled successfully in X s (cca1ff20fc67941570c3) +Rspack x.x.x compiled successfully in X s (451db70fa838cd6e895d) PublicPath: (none) asset warning.pro-node-with-hints-set.js 294 KiB [emitted] (name: main) @@ -65,24 +65,24 @@ Entrypoint main 294 KiB = warning.pro-node-with-hints-set.js ./index.js WARNING in ⚠ asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ warning.pro-node-with-hints-set.js (293.709 KiB) + │ warning.pro-node-with-hints-set.js (293.719 KiB) WARNING in ⚠ entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (293.709 KiB) + │ main (293.719 KiB) │ warning.pro-node-with-hints-set.js WARNING in ⚠ Rspack performance recommendations:You can limit the size of your bundles by using import() to lazy load some parts of your application. │ For more info visit https://www.rspack.dev/guide/optimization/code-splitting -Rspack x.x.x compiled with 3 warnings in X s (f5892cac8944423c4fd1)" +Rspack x.x.x compiled with 3 warnings in X s (fdcda4a05775a95633ca)" `; exports[`StatsTestCases should print correct stats for performance-no-async-chunks-shown 1`] = ` "PublicPath: auto asset main.js 294 KiB [emitted] (name: main) -asset sec.js 1.02 KiB [emitted] (name: sec) +asset sec.js 1.03 KiB [emitted] (name: sec) Entrypoint main 294 KiB = main.js -Entrypoint sec 1.02 KiB = sec.js +Entrypoint sec 1.03 KiB = sec.js ./a.js ./b.js ./c.js @@ -92,12 +92,12 @@ Entrypoint sec 1.02 KiB = sec.js WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance. Assets: - main.js (293.910 KiB) + main.js (293.920 KiB) WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance. Entrypoints: - main (293.910 KiB) + main (293.920 KiB) main.js @@ -121,15 +121,15 @@ Entrypoint sec 294 KiB = sec.js ERROR in × asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance. Assets: - main.js (293.830 KiB) - sec.js (293.830 KiB) + main.js (293.840 KiB) + sec.js (293.840 KiB) ERROR in × entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance. Entrypoints: - main (293.830 KiB) + main (293.840 KiB) main.js - sec (293.830 KiB) + sec (293.840 KiB) sec.js From fd00d87f7e9601db14e87c83e2601b9c9ce1ece2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 11:46:44 +0800 Subject: [PATCH 082/107] chore(deps): update crates (#6541) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 88 +++++++++++++++++++--------- crates/rspack_plugin_wasm/Cargo.toml | 2 +- 2 files changed, 60 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fafe08d93e6..4f19f45ff721 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -971,6 +971,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.0.1" @@ -1070,12 +1079,13 @@ dependencies = [ [[package]] name = "futures-concurrency" -version = "7.5.0" +version = "7.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b590a729e1cbaf9ae3ec294143ea034d93cbb1de01c884d04bcd0af8b613d02" +checksum = "51ee14e256b9143bfafbf2fddeede6f396650bacf95d06fc1b3f2b503df129a0" dependencies = [ "bitvec", "futures-core", + "futures-lite", "pin-project", "slab", "smallvec", @@ -1104,6 +1114,21 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -2022,11 +2047,10 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", "serde", @@ -2040,19 +2064,18 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -2160,6 +2183,12 @@ dependencies = [ "typescript_tsconfig_json", ] +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "parking_lot" version = "0.12.1" @@ -2259,9 +2288,9 @@ dependencies = [ [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", "indexmap 2.2.6", @@ -3603,7 +3632,7 @@ dependencies = [ "rspack_util", "serde_json", "swc_core", - "wasmparser 0.202.0", + "wasmparser 0.207.0", ] [[package]] @@ -4033,9 +4062,9 @@ checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" [[package]] name = "smol_str" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49" +checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" dependencies = [ "serde", ] @@ -5623,7 +5652,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", - "fastrand", + "fastrand 2.0.1", "redox_syscall 0.3.5", "rustix", "windows-sys 0.48.0", @@ -5641,9 +5670,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -5680,18 +5709,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", @@ -5943,13 +5972,12 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.91" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad7eb6319ebadebca3dacf1f85a93bc54b73dd81b9036795f73de7ddfe27d5a" +checksum = "33a5f13f11071020bb12de7a16b925d2d58636175c20c11dc5f96cb64bb6c9b3" dependencies = [ "dissimilar", "glob", - "once_cell", "serde", "serde_derive", "serde_json", @@ -6058,9 +6086,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "unicode-xid" @@ -6687,11 +6715,13 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.202.0" +version = "0.207.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6998515d3cf3f8b980ef7c11b29a9b1017d4cf86b99ae93b546992df9931413" +checksum = "e19bb9f8ab07616da582ef8adb24c54f1424c7ec876720b7da9db8ec0626c92c" dependencies = [ + "ahash 0.8.11", "bitflags 2.5.0", + "hashbrown 0.14.3", "indexmap 2.2.6", "semver 1.0.20", ] diff --git a/crates/rspack_plugin_wasm/Cargo.toml b/crates/rspack_plugin_wasm/Cargo.toml index 961648724471..d68ea5165c90 100644 --- a/crates/rspack_plugin_wasm/Cargo.toml +++ b/crates/rspack_plugin_wasm/Cargo.toml @@ -19,4 +19,4 @@ rspack_identifier = { path = "../rspack_identifier" } rspack_util = { path = "../rspack_util" } serde_json = { workspace = true } swc_core = { workspace = true, features = ["__ecma"] } -wasmparser = "0.202.0" +wasmparser = "0.207.0" From 2a13e49dc4c346a449dcadae17f4d9c8e8b8aa9f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 15 May 2024 12:26:15 +0800 Subject: [PATCH 083/107] chore(deps): update swc (#6540) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 54 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 12 ++++++------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f19f45ff721..260be033c1c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -254,15 +254,15 @@ dependencies = [ [[package]] name = "base64" -version = "0.13.1" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64" -version = "0.21.7" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64-simd" @@ -4081,9 +4081,9 @@ dependencies = [ [[package]] name = "sourcemap" -version = "8.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf0b8c0d9d32f81aa0ab2b68ab634d9bbce287423606656fddb456ac8601aec3" +checksum = "208d40b9e8cad9f93613778ea295ed8f3c2b1824217c6cfc7219d3f6f45b96d4" dependencies = [ "base64-simd 0.7.0", "bitvec", @@ -4206,9 +4206,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.96.11" +version = "0.96.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8733aac9489a2e65780c2cd51a4f138f3645e4046fe20ab34a85261812759b2" +checksum = "2d7e14a22b6bf299ed8c2072e719c27324be5060a39b2bd70e62ad2a9505fe71" dependencies = [ "Inflector", "once_cell", @@ -4295,9 +4295,9 @@ dependencies = [ [[package]] name = "swc" -version = "0.274.1" +version = "0.275.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "272cae2cabb898bcf0dd9effc66255bc50cdf9360d2ed63cdecce4f3d3d5fa34" +checksum = "2ac38cd938ce20693b58b26a5d1926a46074db09cf90a251d83cf17cdaea6031" dependencies = [ "anyhow", "base64 0.21.7", @@ -4407,9 +4407,9 @@ dependencies = [ [[package]] name = "swc_compiler_base" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "273a2125d0223f80ce7de0bc17fc706dbaf6c65da83deea2203574eb7ce42281" +checksum = "754058388d4f51df61f9aced73dfca96d81fed1c0a46583dc7b3da07688af80d" dependencies = [ "anyhow", "base64 0.21.7", @@ -4457,9 +4457,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.91.4" +version = "0.92.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928db865b085ffb7fb4b41eefebb9a49223f2130e7acaf994131cebabff2eca9" +checksum = "d047aa3506175f1dbaca493341d533eacbeb60d1393d49c0ffd9d3ff63aaa4c3" dependencies = [ "swc", "swc_atoms", @@ -4640,9 +4640,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.113.1" +version = "0.113.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cae9f905b3485ab348bf9009f71852f27c560d28a0d1f1ec69f0640b86eb1adc" +checksum = "dc1690cc0c9ab60b44ac0225ba1e231ac532f7ba1d754df761c6ee607561afae" dependencies = [ "bitflags 2.5.0", "bytecheck", @@ -4941,9 +4941,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.193.3" +version = "0.194.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7b29710862eb0266dc7bf3360ceac33d6af6b999b89906db9e5b6aefa857c2" +checksum = "4dbee669d44953537b6dcaad4a07aa00034fb9eabe4974b5b60acdd1fa9ce209" dependencies = [ "arrayvec", "indexmap 2.2.6", @@ -5308,11 +5308,11 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.72.9" +version = "0.72.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136f11895d7d6a6a82e35095391339bcc288baa7a6b88e858c36e0dcd323d60c" +checksum = "4b454c1b99da4da9aab3731ab34d7582d2eab96e47670d0c62711053886ef7e2" dependencies = [ - "base64 0.13.1", + "base64 0.22.1", "byteorder", "fxhash", "once_cell", @@ -5368,9 +5368,9 @@ dependencies = [ [[package]] name = "swc_html" -version = "0.138.1" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41773ed770e894c8a0ad38f3b7705b22c24e3884db18d761bb60098de535c4a6" +checksum = "1611b6560f1460e5724388bcdd7adf524757a912f2b95148b561b2a057b8ab81" dependencies = [ "swc_html_ast", "swc_html_codegen", @@ -5420,9 +5420,9 @@ dependencies = [ [[package]] name = "swc_html_minifier" -version = "0.135.1" +version = "0.136.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd0aa7d09c5fc72d9f7319bf9a4eeaf7084695fe85e3ff71976ae3d50f485b3" +checksum = "d1466b1ee81f45371fe5523876c561f3148c7e0fd126380d566d2577a38f16e3" dependencies = [ "once_cell", "serde", @@ -6049,9 +6049,9 @@ checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" [[package]] name = "unicode-id-start" -version = "1.1.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f73150333cb58412db36f2aca8f2875b013049705cc77b94ded70a1ab1f5da" +checksum = "02aebfa694eccbbbffdd92922c7de136b9fe764396d2f10e21bce1681477cfc1" [[package]] name = "unicode-ident" diff --git a/Cargo.toml b/Cargo.toml index 94a717b4af5e..a50a17258d32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,14 +54,14 @@ tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls" # Must be pinned with the same swc versions rkyv = { version = "=0.7.44" } # synced with swc wasm plugin -styled_components = { version = "=0.96.11" } +styled_components = { version = "=0.96.15" } swc_config = { version = "=0.1.13" } -swc_core = { version = "0.91.4", default-features = false } -swc_ecma_minifier = { version = "0.193.3", default-features = false } -swc_emotion = { version = "=0.72.9" } +swc_core = { version = "0.92.0", default-features = false } +swc_ecma_minifier = { version = "0.194.0", default-features = false } +swc_emotion = { version = "=0.72.13" } swc_error_reporters = { version = "=0.17.20" } -swc_html = { version = "=0.138.1" } -swc_html_minifier = { version = "=0.135.1" } +swc_html = { version = "=0.139.0" } +swc_html_minifier = { version = "=0.136.0" } swc_node_comments = { version = "=0.20.20" } [profile.dev] From 2c0872812841c6cd4782d2154018f7b68f7f0fb5 Mon Sep 17 00:00:00 2001 From: dalaoshu <165626830+shulaoda@users.noreply.github.com> Date: Wed, 15 May 2024 12:29:05 +0800 Subject: [PATCH 084/107] feat: improve diagnostics if expressions passed into `DefinePlugin` are failed to parse (#6382) * feat: improve diagnostics if expressions passed into DefinePlugin are failed to parse * chore: add DefinePlugin test and snapshots * chore: update help message and snapshots --- Cargo.lock | 1 + .../src/parser_and_generator/mod.rs | 2 +- .../src/visitors/mod.rs | 17 ++++-- crates/rspack_swc_visitors/Cargo.toml | 1 + crates/rspack_swc_visitors/src/define.rs | 61 +++++++++++++------ .../define_plugin_warning/index.js | 0 .../define_plugin_warning/stats.err | 1 + .../define_plugin_warning/webpack.config.js | 9 +++ 8 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/index.js create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/stats.err create mode 100644 packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/webpack.config.js diff --git a/Cargo.lock b/Cargo.lock index 260be033c1c3..d1c2850a9404 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3685,6 +3685,7 @@ version = "0.1.0" dependencies = [ "once_cell", "regex", + "rspack_error", "serde", "styled_components", "swc_core", diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index dafb6997e048..d581c82fe174 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -151,7 +151,7 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { .0 }; - run_before_pass(&mut ast, compiler_options)?; + run_before_pass(&mut ast, compiler_options, &mut diagnostics)?; let output: crate::TransformOutput = crate::ast::stringify( &ast, diff --git a/crates/rspack_plugin_javascript/src/visitors/mod.rs b/crates/rspack_plugin_javascript/src/visitors/mod.rs index 3a0e1b1143b0..a039e6786e2c 100644 --- a/crates/rspack_plugin_javascript/src/visitors/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/mod.rs @@ -4,6 +4,7 @@ pub mod swc_visitor; use rspack_ast::javascript::Ast; use rspack_core::CompilerOptions; +use rspack_error::miette::Diagnostic; use rspack_error::{AnyhowError, Result}; use swc_core::common::comments::Comments; use swc_core::common::{chain, Mark}; @@ -16,10 +17,14 @@ pub use self::JavascriptParser; /// Webpack builtin plugins /// - `define`: a port of `DefinePlugin` -fn builtins_webpack_plugin(options: &CompilerOptions, unresolved_mark: Mark) -> impl Fold + '_ { +fn builtins_webpack_plugin<'a>( + options: &'a CompilerOptions, + unresolved_mark: Mark, + diagnostics: &'a mut Vec>, +) -> impl Fold + 'a { chain!( Optional::new( - rspack_swc_visitors::define(&options.builtins.define), + rspack_swc_visitors::define(&options.builtins.define, diagnostics), !options.builtins.define.is_empty() ), Optional::new( @@ -53,7 +58,11 @@ fn builtins_webpack_plugin_define_optimizer(unresolved_mark: Mark) -> impl Fold } #[allow(clippy::too_many_arguments)] -pub fn run_before_pass(ast: &mut Ast, options: &CompilerOptions) -> Result<()> { +pub fn run_before_pass( + ast: &mut Ast, + options: &CompilerOptions, + diagnostics: &mut Vec>, +) -> Result<()> { let cm = ast.get_context().source_map.clone(); ast .transform_with_handler(cm.clone(), |_handler, program, context| { @@ -64,7 +73,7 @@ pub fn run_before_pass(ast: &mut Ast, options: &CompilerOptions) -> Result<()> { let mut pass = chain!( dropped_comments_preserver(comments.clone()), swc_visitor::resolver(unresolved_mark, top_level_mark, false), - builtins_webpack_plugin(options, unresolved_mark), + builtins_webpack_plugin(options, unresolved_mark, diagnostics), swc_visitor::hygiene(false, top_level_mark), swc_visitor::fixer(Some(&comments as &dyn Comments)), ); diff --git a/crates/rspack_swc_visitors/Cargo.toml b/crates/rspack_swc_visitors/Cargo.toml index 486586828530..9ec212497a9a 100644 --- a/crates/rspack_swc_visitors/Cargo.toml +++ b/crates/rspack_swc_visitors/Cargo.toml @@ -10,6 +10,7 @@ version = "0.1.0" [dependencies] once_cell = { workspace = true } regex = { workspace = true } +rspack_error = { path = "../rspack_error" } serde = { workspace = true, features = ["derive"] } styled_components = { workspace = true } swc_core = { workspace = true, features = [ diff --git a/crates/rspack_swc_visitors/src/define.rs b/crates/rspack_swc_visitors/src/define.rs index edc2da19560c..977bc7e85871 100644 --- a/crates/rspack_swc_visitors/src/define.rs +++ b/crates/rspack_swc_visitors/src/define.rs @@ -1,8 +1,10 @@ use std::collections::HashMap; use std::sync::Arc; +use rspack_error::miette::{Diagnostic, Severity}; +use rspack_error::TraceableError; use swc_core::common::collections::AHashMap; -use swc_core::common::FileName; +use swc_core::common::{FileName, Spanned}; use swc_core::ecma::ast::EsVersion; use swc_core::ecma::parser::{parse_file_as_expr, EsConfig, Syntax}; use swc_core::ecma::transforms::optimization::inline_globals2; @@ -12,35 +14,54 @@ use swc_core::ecma::visit::Fold; pub type Define = HashMap; pub type RawDefine = Define; -pub fn define(opts: &Define) -> impl Fold { +pub fn define( + opts: &Define, + diagnostics: &mut Vec>, +) -> impl Fold { let cm: Arc = Default::default(); let defs = opts .iter() - .map(|(target, replacement)| { - let target = { - let fm = cm.new_source_file(FileName::Anon, target.clone()); - parse_file_as_expr( + .filter_map(|(target, replacement)| { + let mut parse_expr = |text: &String| { + let fm = cm.new_source_file(FileName::Anon, text.clone()); + let result = parse_file_as_expr( &fm, Syntax::Es(EsConfig::default()), EsVersion::EsNext, None, &mut vec![], - ) - .unwrap_or_else(|_| panic!("builtins.define: Failed to parse {:?}", target)) - }; - let replacement = { - let fm = cm.new_source_file(FileName::Anon, replacement.clone()); - parse_file_as_expr( - &fm, - Syntax::Es(EsConfig::default()), - EsVersion::EsNext, - None, - &mut vec![], - ) - .unwrap_or_else(|_| panic!("builtins.define: Failed to parse {:?}", target)) + ); + + if let Err(err) = &result { + let span = err.span(); + + // Push the error to diagnostics + diagnostics.push(Box::new( + TraceableError::from_source_file( + &fm, + span.lo.0.saturating_sub(1) as usize, + span.hi.0.saturating_sub(1) as usize, + "DefinePlugin warning".into(), + format!("failed to parse {:?}", text), + ) + .with_help(Some( + "Consider wrapping it with `JSON.stringify(...)` if a string is expected.", + )) + .with_severity(Severity::Warning), + )); + } + + result }; - (NodeIgnoringSpan::owned(*target), *replacement) + let target = parse_expr(target); + let replacement = parse_expr(replacement); + + if let (Ok(target), Ok(replacement)) = (target, replacement) { + Some((NodeIgnoringSpan::owned(*target), *replacement)) + } else { + None + } }) .collect::>(); diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/index.js b/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/index.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/stats.err b/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/stats.err new file mode 100644 index 000000000000..054036898b91 --- /dev/null +++ b/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/stats.err @@ -0,0 +1 @@ +WARNING in ./index.js⚠ Module parse warning:╰─▶ ⚠ DefinePlugin warning: failed to parse "😄"╭────1 😄· ▲╰────help: Consider wrapping it with `JSON.stringify(...)` if a string is expected. \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/webpack.config.js b/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/webpack.config.js new file mode 100644 index 000000000000..17f32dba7ef4 --- /dev/null +++ b/packages/rspack-test-tools/tests/diagnosticsCases/module-parse-failed/define_plugin_warning/webpack.config.js @@ -0,0 +1,9 @@ +const { rspack } = require("@rspack/core"); + +module.exports = { + plugins: [ + new rspack.DefinePlugin({ + "__DEV__": "😄" + }) + ], +} From c9771b07b2c5d2385af065d67cbd0a6e2457c047 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Wed, 15 May 2024 12:50:09 +0800 Subject: [PATCH 085/107] feat: support cjs css with css esModule generator options (#6376) --- Cargo.lock | 150 +++++++++--------- crates/node_binding/binding.d.ts | 3 + .../src/options/raw_module/mod.rs | 6 + crates/rspack_core/src/options/module.rs | 3 + .../src/parser_and_generator/mod.rs | 49 +++--- .../src/plugin/impl_plugin_for_css_plugin.rs | 3 + crates/rspack_plugin_css/src/utils.rs | 12 +- .../tests/__snapshots__/Defaults.test.js.snap | 3 + .../modules-composes/snapshot/output.snap.txt | 10 +- .../variant/snapshot/output.snap.txt | 2 +- .../experiments/future-defaults-with-css.js | 20 +-- packages/rspack/etc/api.md | 94 +++++++++++ packages/rspack/src/config/adapter.ts | 6 +- packages/rspack/src/config/defaults.ts | 3 + packages/rspack/src/config/zod.ts | 12 +- .../css/cjs-module-syntax/index.js | 12 ++ .../css/cjs-module-syntax/style.module.css | 3 + .../css/cjs-module-syntax/test.config.js | 10 ++ .../css/cjs-module-syntax/webpack.config.js | 31 ++++ website/docs/en/config/module.mdx | 53 +++++++ website/docs/zh/config/module.mdx | 53 +++++++ website/project-words.txt | 16 ++ 22 files changed, 434 insertions(+), 120 deletions(-) create mode 100644 webpack-test/configCases/css/cjs-module-syntax/index.js create mode 100644 webpack-test/configCases/css/cjs-module-syntax/style.module.css create mode 100644 webpack-test/configCases/css/cjs-module-syntax/test.config.js create mode 100644 webpack-test/configCases/css/cjs-module-syntax/webpack.config.js diff --git a/Cargo.lock b/Cargo.lock index d1c2850a9404..eee748dfae29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,9 +90,9 @@ checksum = "70033777eb8b5124a81a1889416543dddef2de240019b674c81285a2635a7e1e" [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" dependencies = [ "backtrace", ] @@ -122,7 +122,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -155,18 +155,18 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] name = "async-recursion" -version = "1.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -182,13 +182,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.80" +version = "0.1.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -219,7 +219,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -683,7 +683,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eed5fff0d93c7559121e9c72bf9c242295869396255071ff2cb1617147b608c5" dependencies = [ "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -736,7 +736,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -758,7 +758,7 @@ checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" dependencies = [ "darling_core 0.20.6", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -935,7 +935,7 @@ dependencies = [ "darling 0.20.6", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -1037,7 +1037,7 @@ checksum = "fdc9cc75639b041067353b9bce2450d6847e547276c6fbe4487d7407980e07db" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -1137,7 +1137,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -1303,9 +1303,9 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.9.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" +checksum = "692eaaf7f7607518dd3cef090f1474b61edc5301d8012f09579920df68b725ee" dependencies = [ "hashbrown 0.14.3", ] @@ -1504,7 +1504,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -1877,7 +1877,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -1966,7 +1966,7 @@ dependencies = [ "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -1981,7 +1981,7 @@ dependencies = [ "quote", "regex", "semver 1.0.20", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -2214,9 +2214,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.15" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "path-clean" @@ -2272,7 +2272,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -2338,7 +2338,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -2376,7 +2376,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -2399,7 +2399,7 @@ checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -2490,9 +2490,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -2539,9 +2539,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -3089,7 +3089,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -3805,9 +3805,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.19" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6e7ed6919cb46507fb01ff1654309219f62b4d603822501b0b80d42f6f21ef" +checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" dependencies = [ "dyn-clone", "schemars_derive", @@ -3817,14 +3817,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.19" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185f2b7aa7e02d418e453790dde16890256bbd2bcd04b7dc5348811052b53f49" +checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.63", + "syn 1.0.109", ] [[package]] @@ -3877,9 +3877,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.201" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] @@ -3907,31 +3907,31 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] name = "serde_derive_internals" -version = "0.29.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 1.0.109", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "indexmap 2.2.6", "itoa", @@ -4146,7 +4146,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -4196,7 +4196,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -4453,7 +4453,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -4531,7 +4531,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -4567,9 +4567,9 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.29.35" +version = "0.29.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a367c7ec6afd24bb3fcc2df95a2adf5d7462367d5b13afd8e43a7beba44358" +checksum = "b20af192df5adddac04293b5072cc00befa2d6818a9fc90ac6f5c2c49e82dd1c" dependencies = [ "rustc-hash", "serde", @@ -4687,7 +4687,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -4852,9 +4852,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2022" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb9ab1987e7f9959e31f4a5f9c617ad640a01d8c3c6f02293ad2835adac7790" +checksum = "8d4a8a9fde6f96316e8b0792a72baa209277e0ce3050b476ee3ab408ec579a2d" dependencies = [ "swc_atoms", "swc_common", @@ -5035,7 +5035,7 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5060,9 +5060,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.138.1" +version = "0.138.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6511cbe8c60eced9a8e77b66aadbda26424f14a1662c68c17aeb73ac78ad83c2" +checksum = "eddb95c2bdad1c9c29edf35712e1e0f9b9ddc1cdb5ba2d582fd93468cb075a03" dependencies = [ "better_scoped_tls", "bitflags 2.5.0", @@ -5141,14 +5141,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] name = "swc_ecma_transforms_module" -version = "0.181.1" +version = "0.181.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92496bb7806b5c6602bcb08a9c09c61b12232a44da605f9e50e27ecffb603822" +checksum = "477b6ac686dc1e4ab1af5cc6e8417facca0d4e71ce27df0e759c94d8c365c8e2" dependencies = [ "Inflector", "anyhow", @@ -5339,7 +5339,7 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5416,7 +5416,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5494,7 +5494,7 @@ checksum = "91745f3561057493d2da768437c427c0e979dff7396507ae02f16c981c4a8466" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5575,7 +5575,7 @@ checksum = "ff9719b6085dd2824fd61938a881937be14b08f95e2d27c64c825a9f65e052ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5598,7 +5598,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5614,9 +5614,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -5725,7 +5725,7 @@ checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5826,7 +5826,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -5908,7 +5908,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] [[package]] @@ -7066,5 +7066,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.58", ] diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 28b248b5b378..1701083285a6 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -772,6 +772,7 @@ export interface RawCssAutoGeneratorOptions { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" exportsOnly?: boolean localIdentName?: string + esModule?: boolean } export interface RawCssAutoParserOptions { @@ -792,12 +793,14 @@ export interface RawCssExtractPluginOption { export interface RawCssGeneratorOptions { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" exportsOnly?: boolean + esModule?: boolean } export interface RawCssModuleGeneratorOptions { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" exportsOnly?: boolean localIdentName?: string + esModule?: boolean } export interface RawCssModuleParserOptions { diff --git a/crates/rspack_binding_options/src/options/raw_module/mod.rs b/crates/rspack_binding_options/src/options/raw_module/mod.rs index 68c9613e93f4..b96b92eb1709 100644 --- a/crates/rspack_binding_options/src/options/raw_module/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_module/mod.rs @@ -622,6 +622,7 @@ pub struct RawCssGeneratorOptions { #[napi(ts_type = r#""as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only""#)] pub exports_convention: Option, pub exports_only: Option, + pub es_module: Option, } impl From for CssGeneratorOptions { @@ -629,6 +630,7 @@ impl From for CssGeneratorOptions { Self { exports_convention: value.exports_convention.map(|n| n.into()), exports_only: value.exports_only, + es_module: value.es_module, } } } @@ -640,6 +642,7 @@ pub struct RawCssAutoGeneratorOptions { pub exports_convention: Option, pub exports_only: Option, pub local_ident_name: Option, + pub es_module: Option, } impl From for CssAutoGeneratorOptions { @@ -648,6 +651,7 @@ impl From for CssAutoGeneratorOptions { exports_convention: value.exports_convention.map(|n| n.into()), exports_only: value.exports_only, local_ident_name: value.local_ident_name.map(|n| n.into()), + es_module: value.es_module, } } } @@ -659,6 +663,7 @@ pub struct RawCssModuleGeneratorOptions { pub exports_convention: Option, pub exports_only: Option, pub local_ident_name: Option, + pub es_module: Option, } impl From for CssModuleGeneratorOptions { @@ -667,6 +672,7 @@ impl From for CssModuleGeneratorOptions { exports_convention: value.exports_convention.map(|n| n.into()), exports_only: value.exports_only, local_ident_name: value.local_ident_name.map(|n| n.into()), + es_module: value.es_module, } } } diff --git a/crates/rspack_core/src/options/module.rs b/crates/rspack_core/src/options/module.rs index e4a811e4f2cf..042690a5ad8c 100644 --- a/crates/rspack_core/src/options/module.rs +++ b/crates/rspack_core/src/options/module.rs @@ -337,6 +337,7 @@ impl From for DataUrlEncoding { pub struct CssGeneratorOptions { pub exports_convention: Option, pub exports_only: Option, + pub es_module: Option, } #[derive(Debug, Clone, MergeFrom)] @@ -344,6 +345,7 @@ pub struct CssAutoGeneratorOptions { pub exports_convention: Option, pub exports_only: Option, pub local_ident_name: Option, + pub es_module: Option, } #[derive(Debug, Clone, MergeFrom)] @@ -351,6 +353,7 @@ pub struct CssModuleGeneratorOptions { pub exports_convention: Option, pub exports_only: Option, pub local_ident_name: Option, + pub es_module: Option, } #[derive(Debug, Clone, MergeFrom)] diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index 3d629ee08c9e..88bd3e78e0bb 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -60,6 +60,7 @@ pub struct CssParserAndGenerator { pub exports_only: bool, pub named_exports: bool, pub exports: Option, + pub es_module: bool, } impl ParserAndGenerator for CssParserAndGenerator { @@ -180,7 +181,6 @@ impl ParserAndGenerator for CssParserAndGenerator { exports.insert(key, vec![value]); } - exports.sort_keys(); let normalized_exports = IndexMap::from_iter( exports .iter() @@ -342,30 +342,39 @@ impl ParserAndGenerator for CssParserAndGenerator { )?; } return Ok(concate_source.boxed()); - } else if let Some(exports) = &self.exports { - css_modules_exports_to_string( - exports, - module, - generate_context.compilation, - generate_context.runtime_requirements, - )? - } else if generate_context.compilation.options.dev_server.hot { - format!( - "module.hot.accept();\n{}(module.exports = {{}});\n", - RuntimeGlobals::MAKE_NAMESPACE_OBJECT - ) } else { - format!( - "{}(module.exports = {{}})\n", - RuntimeGlobals::MAKE_NAMESPACE_OBJECT - ) + let (ns_obj, left, right) = if self.es_module { + (RuntimeGlobals::MAKE_NAMESPACE_OBJECT.name(), "(", ")") + } else { + ("", "", "") + }; + if let Some(exports) = &self.exports { + css_modules_exports_to_string( + exports, + module, + generate_context.compilation, + generate_context.runtime_requirements, + ns_obj, + left, + right, + )? + } else if generate_context.compilation.options.dev_server.hot { + format!( + "module.hot.accept();\n{}{}module.exports = {{}}{};\n", + ns_obj, left, right + ) + } else { + format!("{}{}module.exports = {{}}{};\n", ns_obj, left, right) + } }; generate_context .runtime_requirements .insert(RuntimeGlobals::MODULE); - generate_context - .runtime_requirements - .insert(RuntimeGlobals::MAKE_NAMESPACE_OBJECT); + if self.es_module { + generate_context + .runtime_requirements + .insert(RuntimeGlobals::MAKE_NAMESPACE_OBJECT); + } Ok(RawSource::from(exports).boxed()) } _ => panic!( 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 905d9def8422..975c3a973f3d 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 @@ -343,6 +343,7 @@ impl Plugin for CssPlugin { local_ident_name: None, exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), + es_module: g.es_module.expect("should have es_module"), }) as Box }), ); @@ -367,6 +368,7 @@ impl Plugin for CssPlugin { ), exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), + es_module: g.es_module.expect("should have es_module"), }) as Box }), ); @@ -391,6 +393,7 @@ impl Plugin for CssPlugin { ), exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), + es_module: g.es_module.expect("should have es_module"), }) as Box }), ); diff --git a/crates/rspack_plugin_css/src/utils.rs b/crates/rspack_plugin_css/src/utils.rs index b1c1db395a31..84afab2e7c81 100644 --- a/crates/rspack_plugin_css/src/utils.rs +++ b/crates/rspack_plugin_css/src/utils.rs @@ -177,11 +177,11 @@ pub fn css_modules_exports_to_string( module: &dyn rspack_core::Module, compilation: &Compilation, runtime_requirements: &mut RuntimeGlobals, + ns_obj: &str, + left: &str, + right: &str, ) -> Result { - let mut code = format!( - "{}(module.exports = {{\n", - RuntimeGlobals::MAKE_NAMESPACE_OBJECT - ); + let mut code = format!("{}{}module.exports = {{\n", ns_obj, left); let module_graph = compilation.get_module_graph(); for (key, elements) in exports { let content = elements @@ -221,7 +221,9 @@ pub fn css_modules_exports_to_string( writeln!(code, " {}: {},", item, content).map_err(|e| error!(e.to_string()))?; } } - code += "});\n"; + code += "}"; + code += right; + code += ";\n"; Ok(code) } diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index e3d977104839..d14213080346 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -147,15 +147,18 @@ Object { ], "generator": Object { "css": Object { + "esModule": true, "exportsConvention": "as-is", "exportsOnly": false, }, "css/auto": Object { + "esModule": true, "exportsConvention": "as-is", "exportsOnly": false, "localIdentName": "[uniqueName]-[id]-[local]", }, "css/module": Object { + "esModule": true, "exportsConvention": "as-is", "exportsOnly": false, "localIdentName": "[uniqueName]-[id]-[local]", diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt index 55dd6c2480c1..2ee5aa2f544d 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt @@ -34,30 +34,30 @@ __webpack_require__.r(__webpack_exports__); "./b.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "b": "___b_module____b--___eca6dd2253f6b569_eca" + " " + "___b_module____b-1--___eca6dd2253f6b569_eca", "b-1": "___b_module____b-1--___eca6dd2253f6b569_eca", + "b": "___b_module____b--___eca6dd2253f6b569_eca" + " " + "___b_module____b-1--___eca6dd2253f6b569_eca", }); }), "./d.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "d": "___d_module____d--___a41e34edaa1ca3c_a41" + " " + "___d_module____d-1--___a41e34edaa1ca3c_a41", "d-1": "___d_module____d-1--___a41e34edaa1ca3c_a41", + "d": "___d_module____d--___a41e34edaa1ca3c_a41" + " " + "___d_module____d-1--___a41e34edaa1ca3c_a41", }); }), "./f.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "f": "___f_module____f--___af10a85c64a6b515_af1" + " " + "___f_module____f-1--___af10a85c64a6b515_af1", "f-1": "___f_module____f-1--___af10a85c64a6b515_af1", + "f": "___f_module____f--___af10a85c64a6b515_af1" + " " + "___f_module____f-1--___af10a85c64a6b515_af1", }); }), "./style.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; __webpack_require__.r(module.exports = { - "chain1": "___style_module____chain1--___afc435275e612570_afc" + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], "chain2": "___style_module____chain2--___afc435275e612570_afc" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], - "root-class": "___style_module____root-class--___afc435275e612570_afc" + " " + "___style_module____chain1--___afc435275e612570_afc" + " " + "a" + " " + __webpack_require__("./b.module.css")["b"] + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], + "chain1": "___style_module____chain1--___afc435275e612570_afc" + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "e" + " " + "c" + " " + __webpack_require__("./f.module.css")["f"] + " " + __webpack_require__("./d.module.css")["d"], + "root-class": "___style_module____chain2--___afc435275e612570_afc" + " " + "___style_module____root-class--___afc435275e612570_afc" + " " + "___style_module____chain1--___afc435275e612570_afc" + " " + "e" + " " + "c" + " " + "a" + " " + __webpack_require__("./f.module.css")["f"] + " " + __webpack_require__("./d.module.css")["d"] + " " + __webpack_require__("./b.module.css")["b"], }); }), diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt index 4a373210ab61..03a08613df70 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt @@ -4,7 +4,7 @@ Rspack App - + diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js index c4a2087cab19..bcd3f9e268a3 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js @@ -25,7 +25,8 @@ module.exports = { - }, - "test": /\\.css$/i, - "type": "css/auto", - @@ ... @@ + - }, + - Object { - "mimetype": "text/css+module", - "resolve": Object { - "fullySpecified": true, @@ -38,22 +39,24 @@ module.exports = { - "resolve": Object { - "fullySpecified": true, - "preferRelative": true, - - }, + @@ ... @@ - "type": "css", - }, - - Object { @@ ... @@ - "generator": Object { - "css": Object { + - "esModule": true, - "exportsConvention": "as-is", - "exportsOnly": false, - }, - "css/auto": Object { + - "esModule": true, - "exportsConvention": "as-is", - "exportsOnly": false, - "localIdentName": "[uniqueName]-[id]-[local]", - }, - "css/module": Object { + - "esModule": true, - "exportsConvention": "as-is", - "exportsOnly": false, - "localIdentName": "[uniqueName]-[id]-[local]", @@ -61,16 +64,15 @@ module.exports = { - }, + "generator": Object {}, @@ ... @@ - - }, - - }, - "css": Object { - "namedExports": true, - @@ ... @@ + - }, - "css/auto": Object { - "namedExports": true, - }, - "css/module": Object { - "namedExports": true, + - }, @@ ... @@ - "css", @@ ... @@ @@ -79,6 +81,7 @@ module.exports = { + "hashDigestLength": 16, + "hashFunction": "xxhash64", @@ ... @@ + - "...", - ], - }, - "css-import": Object { @@ -86,14 +89,13 @@ module.exports = { - "webpack", - "production", - "style", - @@ ... @@ + - ], - "extensions": Array [ - ".css", - ], - "mainFields": Array [ - "style", - - "...", - - ], + @@ ... @@ - "mainFiles": Array [], - "preferRelative": true, `) diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index a65dbc07dd01..256352df669b 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -1528,14 +1528,17 @@ const cssAutoGeneratorOptions: z.ZodObject<{ exportsConvention: z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>; // @public (undocumented) @@ -1609,6 +1612,12 @@ export type CssFilename = z.infer; // @public (undocumented) const cssFilename: z.ZodUnion<[z.ZodString, z.ZodFunction, z.ZodOptional>], z.ZodUnknown>, z.ZodString>]>; +// @public (undocumented) +export type CssGeneratorEsModule = z.infer; + +// @public (undocumented) +const cssGeneratorEsModule: z.ZodBoolean; + // @public (undocumented) export type CssGeneratorExportsConvention = z.infer; @@ -1634,12 +1643,15 @@ export type CssGeneratorOptions = z.infer; const cssGeneratorOptions: z.ZodObject<{ exportsConvention: z.ZodOptional>; exportsOnly: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }>; // @public (undocumented) @@ -1650,14 +1662,17 @@ const cssModuleGeneratorOptions: z.ZodObject<{ exportsConvention: z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>; // @public (undocumented) @@ -3222,38 +3237,47 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ css: z.ZodOptional>; exportsOnly: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }>>; "css/auto": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; "css/module": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -3285,16 +3309,19 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }, { asset?: { @@ -3326,16 +3353,19 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }>, z.ZodRecord>]>; @@ -3443,38 +3473,47 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ css: z.ZodOptional>; exportsOnly: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }>>; "css/auto": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; "css/module": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -3506,16 +3545,19 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }, { asset?: { @@ -3547,16 +3589,19 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }>; @@ -5152,38 +5197,47 @@ const moduleOptions: z.ZodObject<{ css: z.ZodOptional>; exportsOnly: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }>>; "css/auto": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; "css/module": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -5215,16 +5269,19 @@ const moduleOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }, { asset?: { @@ -5256,16 +5313,19 @@ const moduleOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }>, z.ZodRecord>]>>; noParse: z.ZodOptional]>, z.ZodFunction, z.ZodBoolean>]>, z.ZodArray]>, z.ZodFunction, z.ZodBoolean>]>, "many">]>>; @@ -5350,16 +5410,19 @@ const moduleOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; } | undefined; noParse?: string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; @@ -5444,16 +5507,19 @@ const moduleOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; } | undefined; noParse?: string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; @@ -7780,6 +7846,7 @@ declare namespace rspackExports { CssGeneratorExportsConvention, CssGeneratorExportsOnly, CssGeneratorLocalIdentName, + CssGeneratorEsModule, CssGeneratorOptions, CssAutoGeneratorOptions, CssModuleGeneratorOptions, @@ -9430,38 +9497,47 @@ export const rspackOptions: z.ZodObject<{ css: z.ZodOptional>; exportsOnly: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; }>>; "css/auto": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; "css/module": z.ZodOptional>; exportsOnly: z.ZodOptional; localIdentName: z.ZodOptional; + esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }, { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; }>>; }, "strict", z.ZodTypeAny, { asset?: { @@ -9493,16 +9569,19 @@ export const rspackOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }, { asset?: { @@ -9534,16 +9613,19 @@ export const rspackOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; }>, z.ZodRecord>]>>; noParse: z.ZodOptional]>, z.ZodFunction, z.ZodBoolean>]>, z.ZodArray]>, z.ZodFunction, z.ZodBoolean>]>, "many">]>>; @@ -9628,16 +9710,19 @@ export const rspackOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; } | undefined; noParse?: string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; @@ -9722,16 +9807,19 @@ export const rspackOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; } | undefined; noParse?: string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; @@ -10153,16 +10241,19 @@ export const rspackOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; } | undefined; noParse?: string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; @@ -10574,16 +10665,19 @@ export const rspackOptions: z.ZodObject<{ css?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; + esModule?: boolean | undefined; } | undefined; "css/auto"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; "css/module"?: { exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; localIdentName?: string | undefined; + esModule?: boolean | undefined; } | undefined; } | undefined; noParse?: string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined; diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 460b9479cb9e..6c2537364f1e 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -766,7 +766,8 @@ function getRawCssGeneratorOptions( ): RawCssGeneratorOptions { return { exportsConvention: options.exportsConvention, - exportsOnly: options.exportsOnly + exportsOnly: options.exportsOnly, + esModule: options.esModule }; } @@ -776,7 +777,8 @@ function getRawCssAutoOrModuleGeneratorOptions( return { localIdentName: options.localIdentName, exportsConvention: options.exportsConvention, - exportsOnly: options.exportsOnly + exportsOnly: options.exportsOnly, + esModule: options.esModule }; } diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 75afd6f2fdc8..2bcfb96717ce 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -321,6 +321,7 @@ const applyModuleDefaults = ( !targetProperties || !targetProperties.document ); D(module.generator["css"], "exportsConvention", "as-is"); + D(module.generator["css"], "esModule", true); F(module.generator, "css/auto", () => ({})); assertNotNill(module.generator["css/auto"]); @@ -335,6 +336,7 @@ const applyModuleDefaults = ( "localIdentName", "[uniqueName]-[id]-[local]" ); + D(module.generator["css/auto"], "esModule", true); F(module.generator, "css/module", () => ({})); assertNotNill(module.generator["css/module"]); @@ -349,6 +351,7 @@ const applyModuleDefaults = ( "localIdentName", "[uniqueName]-[id]-[local]" ); + D(module.generator["css/module"], "esModule", true); } A(module, "defaultRules", () => { diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index d45448785879..faed9b4e2d15 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -657,23 +657,29 @@ export type CssGeneratorLocalIdentName = z.infer< typeof cssGeneratorLocalIdentName >; +const cssGeneratorEsModule = z.boolean(); +export type CssGeneratorEsModule = z.infer; + const cssGeneratorOptions = z.strictObject({ exportsConvention: cssGeneratorExportsConvention.optional(), - exportsOnly: cssGeneratorExportsOnly.optional() + exportsOnly: cssGeneratorExportsOnly.optional(), + esModule: cssGeneratorEsModule.optional() }); export type CssGeneratorOptions = z.infer; const cssAutoGeneratorOptions = z.strictObject({ exportsConvention: cssGeneratorExportsConvention.optional(), exportsOnly: cssGeneratorExportsOnly.optional(), - localIdentName: cssGeneratorLocalIdentName.optional() + localIdentName: cssGeneratorLocalIdentName.optional(), + esModule: cssGeneratorEsModule.optional() }); export type CssAutoGeneratorOptions = z.infer; const cssModuleGeneratorOptions = z.strictObject({ exportsConvention: cssGeneratorExportsConvention.optional(), exportsOnly: cssGeneratorExportsOnly.optional(), - localIdentName: cssGeneratorLocalIdentName.optional() + localIdentName: cssGeneratorLocalIdentName.optional(), + esModule: cssGeneratorEsModule.optional() }); export type CssModuleGeneratorOptions = z.infer< typeof cssModuleGeneratorOptions diff --git a/webpack-test/configCases/css/cjs-module-syntax/index.js b/webpack-test/configCases/css/cjs-module-syntax/index.js new file mode 100644 index 000000000000..a2218ae96fe4 --- /dev/null +++ b/webpack-test/configCases/css/cjs-module-syntax/index.js @@ -0,0 +1,12 @@ +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +it("should able to require the css module as commonjs", () => { + const style = require("./style.module.css"); + console.log(style) + const interoperatedStyle = _interopRequireDefault(require("./style.module.css")); + + expect(style).toEqual({ foo: '-__style_module_css-foo' }); + expect(style).not.toEqual(nsObj({ foo: '-__style_module_css-foo' })); + expect(style.__esModule).toEqual(undefined); + expect(interoperatedStyle.default.foo).toEqual("-__style_module_css-foo"); +}); diff --git a/webpack-test/configCases/css/cjs-module-syntax/style.module.css b/webpack-test/configCases/css/cjs-module-syntax/style.module.css new file mode 100644 index 000000000000..cedf0a6d1f17 --- /dev/null +++ b/webpack-test/configCases/css/cjs-module-syntax/style.module.css @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/webpack-test/configCases/css/cjs-module-syntax/test.config.js b/webpack-test/configCases/css/cjs-module-syntax/test.config.js new file mode 100644 index 000000000000..d8b1cd2e6ed3 --- /dev/null +++ b/webpack-test/configCases/css/cjs-module-syntax/test.config.js @@ -0,0 +1,10 @@ +module.exports = { + moduleScope(scope) { + if (scope.document) { + const link = scope.document.createElement("link"); + link.rel = "stylesheet"; + link.href = "bundle0.css"; + scope.document.head.appendChild(link); + } + } +}; diff --git a/webpack-test/configCases/css/cjs-module-syntax/webpack.config.js b/webpack-test/configCases/css/cjs-module-syntax/webpack.config.js new file mode 100644 index 000000000000..c99de4b1ee84 --- /dev/null +++ b/webpack-test/configCases/css/cjs-module-syntax/webpack.config.js @@ -0,0 +1,31 @@ +/** @type {import("../../../../").Configuration} */ +module.exports = [ + { + target: "web", + mode: "development", + module: { + generator: { + "css/auto": { + esModule: false + } + } + }, + experiments: { + css: true + } + }, + { + target: "node", + mode: "development", + module: { + generator: { + "css/auto": { + esModule: false + } + } + }, + experiments: { + css: true + } + } +]; diff --git a/website/docs/en/config/module.mdx b/website/docs/en/config/module.mdx index 173ca0a21f58..845e71204ba2 100644 --- a/website/docs/en/config/module.mdx +++ b/website/docs/en/config/module.mdx @@ -511,6 +511,47 @@ Avoid generating and loading a stylesheet and only embed exports from CSS into o Customize the format of the local class names generated for CSS modules, besides the substitutions at [File-level](/config/output#file-context) and [Module-level](/config/output#module-context), also include `[uniqueName]` and `[local]`. +#### module.generator["css/auto"].esModule + + + +- **Type:** `boolean` +- **Default:** `true` + +Whether to add `__esModule` to the exports of CSS; if added, it will be treated as an ES Module during esm-cjs interop, otherwise, it will be treated as a CommonJS Module. + +For example, when using the cjs output from a third-party component library, it is sometimes necessary to add this configuration to ensure correct esm-cjs interop, to obtain the correct exports (this can be used in conjunction with [Rule.test](#ruletest) and other matching conditions to add it only for that particular component library). + +The original source code of the third-party component library: + +```js +import style from './style.css'; +export function Button() { + return ; +} +``` + +The cjs format output published by the third-party component library: + +```js +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.Button = Button; +var _style = _interopRequireDefault(require('./style.css')); +var _jsxRuntime = require('react/jsx-runtime'); +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +function Button() { + return /*#__PURE__*/ (0, _jsxRuntime.jsx)('button', { + className: _style['default'].btn, // <-- Note: After passing through _interopRequireDefault, this need to access default here. + }); +} +``` + ### module.generator.css Generator options for `css` modules. @@ -531,6 +572,12 @@ Same as [`module.generator["css/auto"].exportsConvention`](#modulegeneratorcssau Same as [`module.generator["css/auto"].exportsOnly`](#modulegeneratorcssautoexportsonly). +#### module.generator.css.esModule + + + +Same as [`module.generator["css/auto"].esModule`](#modulegeneratorcssautoesmodule). + ### module.generator["css/module"] Generator options for `css/module` modules. @@ -557,6 +604,12 @@ Same as [`module.generator["css/auto"].exportsOnly`](#modulegeneratorcssautoexpo Same as [`module.generator["css/auto"].localIdentName`](#modulegeneratorcssautolocalidentname). +#### module.generator["css/module"].esModule + + + +Same as [`module.generator["css/auto"].esModule`](#modulegeneratorcssautoesmodule). + ## module.rules - **Type:** `Rule[]` diff --git a/website/docs/zh/config/module.mdx b/website/docs/zh/config/module.mdx index d8dc15e7da2d..7f01b76c49d7 100644 --- a/website/docs/zh/config/module.mdx +++ b/website/docs/zh/config/module.mdx @@ -511,6 +511,47 @@ module.exports = { 自定义生成的 CSS Modules 的局部类名格式,除了在[文件级别](/config/output#file-context)和[模块级别](/config/output#module-context)的替换之外,还包括 `[uniqueName]` 和 `[local]`。 +#### module.generator["css/auto"].esModule + + + +- **类型:** `boolean` +- **默认值:** `true` + +是否为 CSS 的导出添加 `__esModule`,如果添加则会在 esm-cjs interop 时当作 ES Module,否则当作 CommonJS Module。 + +比如在使用第三方组件库的 cjs 产物时,有时需要添加该配置确保 esm-cjs interop 正确,以拿到正确的导出(可配合 [Rule.test](#ruletest) 等匹配条件只为该组件库添加)。 + +组件库源码: + +```js +import style from './style.css'; +export function Button() { + return ; +} +``` + +组件库发布的 cjs 产物: + +```js +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.Button = Button; +var _style = _interopRequireDefault(require('./style.css')); +var _jsxRuntime = require('react/jsx-runtime'); +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +function Button() { + return /*#__PURE__*/ (0, _jsxRuntime.jsx)('button', { + className: _style['default'].btn, // <-- 注意:这里经过 _interopRequireDefault 后需要访问 default + }); +} +``` + ### module.generator.css `css` 模块的生成器选项。 @@ -531,6 +572,12 @@ module.exports = { 和 [`module.generator["css/auto"].exportsOnly`](#modulegeneratorcssautoexportsonly) 一样。 +#### module.generator.css.esModule + + + +和 [`module.generator["css/auto"].esModule`](#modulegeneratorcssautoesmodule) 一样。 + ### module.generator["css/module"] `css/module` 模块的生成器选项。 @@ -557,6 +604,12 @@ module.exports = { 和 [`module.generator["css/auto"].localIdentName`](#modulegeneratorcssautolocalidentname) 一样。 +#### module.generator["css/module"].esModule + + + +和 [`module.generator["css/auto"].esModule`](#modulegeneratorcssautoesmodule) 一样。 + ## module.rules - **类型:** `Rule[]` diff --git a/website/project-words.txt b/website/project-words.txt index 1e789bab68ee..7bde8482dd67 100644 --- a/website/project-words.txt +++ b/website/project-words.txt @@ -150,3 +150,19 @@ devserverdevmiddleware proxying proxied pmmmwh +moduleparsercssauto +moduleparsercss +moduleparsercssmodule +modulegeneratorcssauto +modulegeneratorcss +modulegeneratorcssmodule +moduleparsercssautonamedexports +modulegeneratorassetdataurl +modulegeneratorassetdataurlencoding +modulegeneratorassetdataurlmimetype +modulegeneratorcssautoexportsconvention +modulegeneratorcssautoexportsonly +modulegeneratorcssautolocalidentname +modulegeneratorcssautoesmodule +cssextractrspackplugin +mysecretkey From 6087cbb21acde7c9e488863e01338f5aa9f541a8 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Wed, 15 May 2024 13:27:30 +0800 Subject: [PATCH 086/107] chore: revert cargo lock to fix ci (#6544) --- Cargo.lock | 150 +++++++++--------- .../modules-composes/snapshot/output.snap.txt | 4 +- 2 files changed, 77 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eee748dfae29..d1c2850a9404 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,9 +90,9 @@ checksum = "70033777eb8b5124a81a1889416543dddef2de240019b674c81285a2635a7e1e" [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" dependencies = [ "backtrace", ] @@ -122,7 +122,7 @@ dependencies = [ "argh_shared", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -155,18 +155,18 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] name = "async-recursion" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30c5ef0ede93efbf733c1a727f3b6b5a1060bbedd5600183e66f6e4be4af0ec5" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -182,13 +182,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -219,7 +219,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -683,7 +683,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eed5fff0d93c7559121e9c72bf9c242295869396255071ff2cb1617147b608c5" dependencies = [ "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -736,7 +736,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -758,7 +758,7 @@ checksum = "c5a91391accf613803c2a9bf9abccdbaa07c54b4244a5b64883f9c3c137c86be" dependencies = [ "darling_core 0.20.6", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -935,7 +935,7 @@ dependencies = [ "darling 0.20.6", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1037,7 +1037,7 @@ checksum = "fdc9cc75639b041067353b9bce2450d6847e547276c6fbe4487d7407980e07db" dependencies = [ "proc-macro2", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1137,7 +1137,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1303,9 +1303,9 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692eaaf7f7607518dd3cef090f1474b61edc5301d8012f09579920df68b725ee" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ "hashbrown 0.14.3", ] @@ -1504,7 +1504,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1877,7 +1877,7 @@ checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1966,7 +1966,7 @@ dependencies = [ "napi-derive-backend", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1981,7 +1981,7 @@ dependencies = [ "quote", "regex", "semver 1.0.20", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2214,9 +2214,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "path-clean" @@ -2272,7 +2272,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2338,7 +2338,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2376,7 +2376,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2399,7 +2399,7 @@ checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2490,9 +2490,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] @@ -2539,9 +2539,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -3089,7 +3089,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -3805,9 +3805,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "fc6e7ed6919cb46507fb01ff1654309219f62b4d603822501b0b80d42f6f21ef" dependencies = [ "dyn-clone", "schemars_derive", @@ -3817,14 +3817,14 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "185f2b7aa7e02d418e453790dde16890256bbd2bcd04b7dc5348811052b53f49" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] @@ -3877,9 +3877,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] @@ -3907,31 +3907,31 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.63", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "indexmap 2.2.6", "itoa", @@ -4146,7 +4146,7 @@ dependencies = [ "pmutil", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4196,7 +4196,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4453,7 +4453,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4531,7 +4531,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4567,9 +4567,9 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.29.36" +version = "0.29.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b20af192df5adddac04293b5072cc00befa2d6818a9fc90ac6f5c2c49e82dd1c" +checksum = "33a367c7ec6afd24bb3fcc2df95a2adf5d7462367d5b13afd8e43a7beba44358" dependencies = [ "rustc-hash", "serde", @@ -4687,7 +4687,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -4852,9 +4852,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2022" -version = "0.5.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d4a8a9fde6f96316e8b0792a72baa209277e0ce3050b476ee3ab408ec579a2d" +checksum = "5fb9ab1987e7f9959e31f4a5f9c617ad640a01d8c3c6f02293ad2835adac7790" dependencies = [ "swc_atoms", "swc_common", @@ -5035,7 +5035,7 @@ dependencies = [ "swc_ecma_ast", "swc_ecma_parser", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5060,9 +5060,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.138.2" +version = "0.138.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eddb95c2bdad1c9c29edf35712e1e0f9b9ddc1cdb5ba2d582fd93468cb075a03" +checksum = "6511cbe8c60eced9a8e77b66aadbda26424f14a1662c68c17aeb73ac78ad83c2" dependencies = [ "better_scoped_tls", "bitflags 2.5.0", @@ -5141,14 +5141,14 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] name = "swc_ecma_transforms_module" -version = "0.181.2" +version = "0.181.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "477b6ac686dc1e4ab1af5cc6e8417facca0d4e71ce27df0e759c94d8c365c8e2" +checksum = "92496bb7806b5c6602bcb08a9c09c61b12232a44da605f9e50e27ecffb603822" dependencies = [ "Inflector", "anyhow", @@ -5339,7 +5339,7 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5416,7 +5416,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5494,7 +5494,7 @@ checksum = "91745f3561057493d2da768437c427c0e979dff7396507ae02f16c981c4a8466" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5575,7 +5575,7 @@ checksum = "ff9719b6085dd2824fd61938a881937be14b08f95e2d27c64c825a9f65e052ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5598,7 +5598,7 @@ dependencies = [ "proc-macro2", "quote", "swc_macros_common", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5614,9 +5614,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" dependencies = [ "proc-macro2", "quote", @@ -5725,7 +5725,7 @@ checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5826,7 +5826,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -5908,7 +5908,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -7066,5 +7066,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt index 2ee5aa2f544d..25f6074eeedf 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt @@ -56,8 +56,8 @@ __webpack_require__.r(module.exports = { "use strict"; __webpack_require__.r(module.exports = { "chain2": "___style_module____chain2--___afc435275e612570_afc" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], - "chain1": "___style_module____chain1--___afc435275e612570_afc" + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "e" + " " + "c" + " " + __webpack_require__("./f.module.css")["f"] + " " + __webpack_require__("./d.module.css")["d"], - "root-class": "___style_module____chain2--___afc435275e612570_afc" + " " + "___style_module____root-class--___afc435275e612570_afc" + " " + "___style_module____chain1--___afc435275e612570_afc" + " " + "e" + " " + "c" + " " + "a" + " " + __webpack_require__("./f.module.css")["f"] + " " + __webpack_require__("./d.module.css")["d"] + " " + __webpack_require__("./b.module.css")["b"], + "chain1": "___style_module____chain1--___afc435275e612570_afc" + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], + "root-class": "___style_module____root-class--___afc435275e612570_afc" + " " + "___style_module____chain1--___afc435275e612570_afc" + " " + "a" + " " + __webpack_require__("./b.module.css")["b"] + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], }); }), From f65aae400dc7eeea27b94c53ecf9c95690a92de4 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Wed, 15 May 2024 14:11:27 +0800 Subject: [PATCH 087/107] test: remove old treeshaking (#6537) * test: remove old tree shaking * test: remove old tree shaking * test: remove old tree shaking --- .../rspack-test-tools/src/case/treeshaking.ts | 14 +- .../src/processor/treeshaking.ts | 35 ++-- .../snapshot/output.snap.txt | 46 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../webpack.config.js} | 1 - .../snapshot/output.snap.txt | 38 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../webpack.config.js} | 1 - .../basic/snapshot/output.snap.txt | 34 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../webpack.config.js} | 1 - .../bb/snapshot/output.snap.txt | 46 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js => bb/webpack.config.js} | 1 - .../snapshot/output.snap.txt | 50 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 44 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../cjs-tree-shaking-basic/test.config.js | 11 -- .../cjs-tree-shaking-basic/webpack.config.js | 10 + .../class-extend/snapshot/output.snap.txt | 44 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../class-extend/test.config.js | 11 -- .../class-extend/webpack.config.js | 10 + .../snapshot/output.snap.txt | 31 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 18 -- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 0 .../context-module/snapshot/output.snap.txt | 56 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../context-module/test.config.js | 11 -- .../context-module/webpack.config.js | 10 + .../snapshot/output.snap.txt | 57 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../default_export/snapshot/output.snap.txt | 54 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 33 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 42 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 21 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 43 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 40 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 99 ---------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../export-star-chain/test.config.js | 11 -- .../export-star-chain/webpack.config.js | 10 + .../export_star/snapshot/output.snap.txt | 60 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../export_star/test.config.js | 8 - .../export_star/webpack.config.js | 7 + .../export_star2/snapshot/output.snap.txt | 56 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../export_star2/test.config.js | 8 - .../export_star2/webpack.config.js | 7 + .../snapshot/output.snap.txt | 55 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 16 -- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 35 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 23 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../import-as-default/test.config.js | 11 -- .../import-as-default/webpack.config.js | 10 + .../snapshot/output.snap.txt | 39 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 28 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 35 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../import-star-as-and-export/test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 37 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 60 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../issue-4637/snapshot/output.snap.txt | 69 ------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../issue-4637/test.config.js | 11 -- .../issue-4637/webpack.config.js | 10 + .../issues_3198/snapshot/output.snap.txt | 25 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 0 .../snapshot/output.snap.txt | 41 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 41 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 33 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 33 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 57 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 39 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../named_export_alias/test.config.js | 11 -- .../named_export_alias/webpack.config.js | 10 + .../snapshot/output.snap.txt | 76 -------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../nested-import-3/snapshot/output.snap.txt | 40 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../nested-import-3/test.config.js | 11 -- .../nested-import-3/webpack.config.js | 10 + .../nested-import-4/snapshot/output.snap.txt | 36 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../nested-import-4/test.config.js | 11 -- .../nested-import-4/webpack.config.js | 10 + .../snapshot/output.snap.txt | 32 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../prune-bailout-module/test.config.js | 11 -- .../prune-bailout-module/webpack.config.js | 10 + .../snapshot/output.snap.txt | 39 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../react-redux-like/snapshot/output.snap.txt | 56 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../react-redux-like/test.config.js | 11 -- .../react-redux-like/webpack.config.js | 10 + .../snapshot/output.snap.txt | 58 ------ ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../reexport-all-as/snapshot/output.snap.txt | 44 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 34 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../reexport_default_as/test.config.js | 8 - .../reexport_default_as/webpack.config.js | 7 + .../snapshot/output.snap.txt | 40 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../reexport_entry_elimination/test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 36 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../rename-export-from-import/test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 33 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 31 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 39 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 32 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 65 ------- ...eshaking.snap.txt => treeshaking.snap.txt} | 2 + .../test.config.js | 8 - .../webpack.config.js | 7 + .../snapshot/output.snap.txt | 28 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../rollup-unused-var/test.config.js | 8 - .../rollup-unused-var/webpack.config.js | 7 + .../snapshot/output.snap.txt | 38 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 27 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 46 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 37 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../side-effects-prune/test.config.js | 11 -- .../side-effects-prune/webpack.config.js | 10 + .../side-effects-two/snapshot/output.snap.txt | 40 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../side-effects-two/test.config.js | 11 -- .../side-effects-two/webpack.config.js | 10 + .../snapshot/output.snap.txt | 49 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../simple-namespace-access/test.config.js | 8 - .../simple-namespace-access/webpack.config.js | 7 + .../static-class/snapshot/output.snap.txt | 47 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../static-class/test.config.js | 11 -- .../static-class/webpack.config.js | 10 + .../snapshot/output.snap.txt | 40 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../transitive-bailout/test.config.js | 11 -- .../transitive-bailout/webpack.config.js | 10 + .../snapshot/output.snap.txt | 32 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 36 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 50 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 8 +- .../tree-shaking-interop/test.config.js | 8 - .../tree-shaking-interop/webpack.config.js | 7 + .../snapshot/output.snap.txt | 49 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../tree-shaking-lazy-import/test.config.js | 8 - .../webpack.config.js | 7 + .../ts-target-es5/snapshot/output.snap.txt | 19 -- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 32 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../unused-class-rename/test.config.js | 11 -- .../unused-class-rename/webpack.config.js | 10 + .../snapshot/output.snap.txt | 45 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../var-function-expr/test.config.js | 11 -- .../var-function-expr/webpack.config.js | 10 + .../snapshot/output.snap.txt | 176 ------------------ ...eshaking.snap.txt => treeshaking.snap.txt} | 22 ++- .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 102 ---------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../webpack-inner-graph-switch/test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 95 ---------- ...eshaking.snap.txt => treeshaking.snap.txt} | 4 +- .../{test.config.js => webpack.config.js} | 1 - .../snapshot/output.snap.txt | 134 ------------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 40 ---- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 50 ----- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 96 ---------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 104 ----------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../snapshot/output.snap.txt | 86 --------- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../test.config.js | 11 -- .../webpack.config.js | 10 + .../with-assets/snapshot/output.snap.txt | 31 --- ...eshaking.snap.txt => treeshaking.snap.txt} | 0 .../{test.config.js => webpack.config.js} | 1 - 290 files changed, 506 insertions(+), 4390 deletions(-) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/{basic/test.config.js => array-side-effects/webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/{array-side-effects/test.config.js => assign-with-side-effects/webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/{bb/test.config.js => basic/webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/{assign-with-side-effects/test.config.js => bb/webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/class-extend/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/class-extend/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/{test.config.js => webpack.config.js} (82%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/{test.config.js => webpack.config.js} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/context-module/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/context-module/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/{test.config.js => webpack.config.js} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/default_export/{test.config.js => webpack.config.js} (82%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/{test.config.js => webpack.config.js} (82%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/{test.config.js => webpack.config.js} (82%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/{test.config.js => webpack.config.js} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star2/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star2/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/{test.config.js => webpack.config.js} (88%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/{test.config.js => webpack.config.js} (88%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-as-default/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-as-default/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/{test.config.js => webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/{test.config.js => webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/issue-4637/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/issue-4637/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/issues_3198/{test.config.js => webpack.config.js} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/{test.config.js => webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/{test.config.js => webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/{test.config.js => webpack.config.js} (91%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/{test.config.js => webpack.config.js} (91%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/{test.config.js => webpack.config.js} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/{test.config.js => webpack.config.js} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (97%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/{test.config.js => webpack.config.js} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/{test.config.js => webpack.config.js} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/static-class/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/static-class/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (90%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/{test.config.js => webpack.config.js} (88%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (92%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/{test.config.js => webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (95%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/{test.config.js => webpack.config.js} (86%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/test.config.js create mode 100644 packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/webpack.config.js delete mode 100644 packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/output.snap.txt rename packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/{new_treeshaking.snap.txt => treeshaking.snap.txt} (100%) rename packages/rspack-test-tools/tests/treeShakingCases/with-assets/{test.config.js => webpack.config.js} (91%) diff --git a/packages/rspack-test-tools/src/case/treeshaking.ts b/packages/rspack-test-tools/src/case/treeshaking.ts index 6abbc6c7f6a3..54f137ae3c29 100644 --- a/packages/rspack-test-tools/src/case/treeshaking.ts +++ b/packages/rspack-test-tools/src/case/treeshaking.ts @@ -5,22 +5,12 @@ const creator = new BasicCaseCreator({ clean: true, describe: false, description(name, step) { - if (step === 0) { - return `${name} with builtin.treeShaking should match snapshot`; - } else { - return `${name} with newTreeshaking should match snapshot`; - } + return `${name} with newTreeshaking should match snapshot`; }, steps: ({ name }) => [ new RspackTreeShakingProcessor({ name, - snapshot: "output.snap.txt", - type: "builtin" - }), - new RspackTreeShakingProcessor({ - name, - snapshot: "new_treeshaking.snap.txt", - type: "new" + snapshot: "treeshaking.snap.txt" }) ] }); diff --git a/packages/rspack-test-tools/src/processor/treeshaking.ts b/packages/rspack-test-tools/src/processor/treeshaking.ts index c48c105fe7b8..858d299a2169 100644 --- a/packages/rspack-test-tools/src/processor/treeshaking.ts +++ b/packages/rspack-test-tools/src/processor/treeshaking.ts @@ -5,7 +5,6 @@ import { SnapshotProcessor } from "./snapshot"; export interface IRspackTreeShakingProcessorOptions { name: string; snapshot: string; - type: "new" | "builtin"; } export class RspackTreeShakingProcessor extends SnapshotProcessor { @@ -13,36 +12,24 @@ export class RspackTreeShakingProcessor extends SnapshotProcessor - ) => { - options.target = options.target || ["web", "es2022"]; - if (type === "new") { - options.optimization ??= {}; - options.optimization.providedExports = true; - options.optimization.innerGraph = true; - options.optimization.usedExports = true; - - options.builtins ??= {}; - options.builtins.treeShaking = false; - } else { - options.experiments ??= {}; - options.experiments.rspackFuture ??= {}; - options.experiments.rspackFuture.newTreeshaking = false; - } - }; + static overrideOptions( + context: ITestContext, + options: TCompilerOptions + ) { + options.target = options.target || ["web", "es2022"]; + options.optimization ??= {}; + options.optimization.providedExports = true; + options.optimization.innerGraph = true; + options.optimization.usedExports = true; } } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/output.snap.txt deleted file mode 100644 index 977816bacc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/output.snap.txt +++ /dev/null @@ -1,46 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - app: function() { return app; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -function app() {} -app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0__.result; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); -/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/a.js"); - - -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - result: function() { return result; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -}), -"./src/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.app; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/basic/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/basic/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/webpack.config.js index 8757218ddc00..a375a3cb6a91 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/basic/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/output.snap.txt deleted file mode 100644 index f24d5a731656..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/output.snap.txt +++ /dev/null @@ -1,38 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - app: function() { return app; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -function app() {} -app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0__.result; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.app)(); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - result: function() { return result; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/webpack.config.js index 8757218ddc00..a375a3cb6a91 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/output.snap.txt deleted file mode 100644 index 8d3ec0ffa19a..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/output.snap.txt +++ /dev/null @@ -1,34 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - answer: function() { return answer; } -}); -const answer = 103330; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -_lib__WEBPACK_IMPORTED_MODULE_0__.answer; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - answer: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__.answer; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/bb/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/basic/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/bb/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/basic/webpack.config.js index 8757218ddc00..a375a3cb6a91 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/bb/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/basic/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/output.snap.txt deleted file mode 100644 index f9ad3a71183f..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/output.snap.txt +++ /dev/null @@ -1,46 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./b.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - -const a = 3; -_b_js__WEBPACK_IMPORTED_MODULE_0__.d; - -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - d: function() { return d; } -}); -const d = 3; -const c = 100; -}), -"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - ccc: function() { return ccc; } -}); -const ccc = 30; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); - -_a_js__WEBPACK_IMPORTED_MODULE_0__.ccc; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/bb/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/bb/webpack.config.js index 8757218ddc00..a375a3cb6a91 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/bb/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/output.snap.txt deleted file mode 100644 index ddb8f009d39e..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/output.snap.txt +++ /dev/null @@ -1,50 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./antd/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - locales: function() { return locales; } -}); -/* harmony import */var _locale_zh__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./locale_zh.js"); - -const locales = { - zh_CN: _locale_zh__WEBPACK_IMPORTED_MODULE_0__["default"] -}; - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); -/* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./antd/index.js"); - -_antd_index__WEBPACK_IMPORTED_MODULE_0__.locales.zh_CN; -function test() {} -}), -"./locale_zh.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _zh_locale__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./zh_locale.js"); - -/* harmony default export */ __webpack_exports__["default"] = (_zh_locale__WEBPACK_IMPORTED_MODULE_0__["default"]); -}), -"./zh_locale.js": (function (__unused_webpack_module, exports) { -"use strict"; -Object.defineProperty(exports, "__esModule", ({ - value: true -})); -exports["default"] = void 0; -/* eslint-disable no-template-curly-in-string */ var _default = {}; -exports["default"] = _default; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/output.snap.txt deleted file mode 100644 index 9defb1ebbade..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/output.snap.txt +++ /dev/null @@ -1,44 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - answer: function() { return answer; } -}); - -const answer = 42; -}), -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - myanswer: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__.myanswer; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -__webpack_require__("./answer.js"); -(0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)(); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - myanswer: function() { return myanswer; } -}); -const myanswer = "anyser"; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/output.snap.txt deleted file mode 100644 index 0c2d789d8c19..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/output.snap.txt +++ /dev/null @@ -1,44 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - v: function() { return v; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -class Lib extends /* "./lib" unused */null { -} -function foo() { - return { - OriginLib: /* "./lib" unused */null - }; -} -const v = _lib__WEBPACK_IMPORTED_MODULE_0__.value; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.v; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - value: function() { return value; } -}); -class Lib { -} -const value = 1; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/output.snap.txt deleted file mode 100644 index eadd8fc2ff50..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/output.snap.txt +++ /dev/null @@ -1,31 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const a = "bar"; -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const a = "foo"; -const b = "foo"; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/webpack.config.js similarity index 82% rename from packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/webpack.config.js index 2e39e83cf16c..dc0e5942a3a9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/webpack.config.js @@ -1,6 +1,5 @@ module.exports = { builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/output.snap.txt deleted file mode 100644 index 2fbbfaa38db4..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/output.snap.txt +++ /dev/null @@ -1,18 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); - -function test() { - /* "./lib.js" unused */null; -} -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/webpack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/webpack.config.js diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/output.snap.txt deleted file mode 100644 index dc595aead565..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/output.snap.txt +++ /dev/null @@ -1,56 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./child/child/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - value: function() { return value; } -}); -const value = "dynamic"; -}), -"./child/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - value: function() { return value; } -}); -const value = "dynamic"; -}), -"./child sync recursive ^\\.\\/.*\\.js$": (function (module, __unused_webpack_exports, __webpack_require__) { -var map = { - "./child/index.js": "./child/child/index.js", - "./index.js": "./child/index.js" -}; - - -function webpackContext(req) { - var id = webpackContextResolve(req); - return __webpack_require__(id); -} -function webpackContextResolve(req) { - if(!__webpack_require__.o(map, req)) { - var e = new Error("Cannot find module '" + req + "'"); - e.code = 'MODULE_NOT_FOUND'; - throw e; - } - return map[req]; -} -webpackContext.keys = function webpackContextKeys() { - return Object.keys(map); -}; -webpackContext.resolve = webpackContextResolve; -module.exports = webpackContext; -webpackContext.id = "./child sync recursive ^\\.\\/.*\\.js$"; -}), -"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -let a = "index"; -__webpack_require__("./child sync recursive ^\\.\\/.*\\.js$")(`./${a}.js`); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/context-module/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/context-module/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/context-module/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/context-module/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/output.snap.txt deleted file mode 100644 index bbda29a0c2cd..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/output.snap.txt +++ /dev/null @@ -1,57 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./src/App.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/containers/index.js"); - -const { PlatformProvider } = _containers__WEBPACK_IMPORTED_MODULE_0__.containers; -const Index = ()=>{ - console.log("PlatformProvider", PlatformProvider); - return "something"; -}; -/* harmony default export */ __webpack_exports__["default"] = (Index); -}), -"./src/containers/containers.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/containers/platform-container/index.js"); -__webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - - -}), -"./src/containers/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - containers: function() { return _containers__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/containers/containers.js"); - - -}), -"./src/containers/platform-container/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - PlatformProvider: function() { return PlatformProvider; }, - usePlatform: function() { return usePlatform; } -}); -const usePlatform = 3; -const PlatformProvider = 1000; -}), -"./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _App__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/App.js"); - -(0, _App__WEBPACK_IMPORTED_MODULE_0__["default"])(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./src/index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/webpack.config.js similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/webpack.config.js index 731e7857cc8f..98c0058e2ecd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/webpack.config.js @@ -8,7 +8,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/output.snap.txt deleted file mode 100644 index 827e87cd9de2..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/output.snap.txt +++ /dev/null @@ -1,54 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - answer: function() { return answer; } -}); -const answer = 103330; // export default answer; -}), -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return result; }, - render: function() { return render; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -function render() { - function test() { - const container = document.getElementById("root"); - container.innerHTML = `adddd333:${_lib__WEBPACK_IMPORTED_MODULE_0__.secret}:${_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer}`; - } -} -function result() {} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.render)(_app__WEBPACK_IMPORTED_MODULE_0__["default"]); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - myanswer: function() { return myanswer; }, - secret: function() { return secret; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); - -const secret = "888"; -const myanswer = _answer__WEBPACK_IMPORTED_MODULE_0__.answer, result = 20000; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/default_export/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/default_export/webpack.config.js similarity index 82% rename from packages/rspack-test-tools/tests/treeShakingCases/default_export/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/default_export/webpack.config.js index 2e39e83cf16c..dc0e5942a3a9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/default_export/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/default_export/webpack.config.js @@ -1,6 +1,5 @@ module.exports = { builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/output.snap.txt deleted file mode 100644 index 890f32bdbc1b..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/output.snap.txt +++ /dev/null @@ -1,33 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const a = "bar"; -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -const a = "foo"; - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -console.log(_foo__WEBPACK_IMPORTED_MODULE_0__.a); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/webpack.config.js similarity index 82% rename from packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/webpack.config.js index 2e39e83cf16c..dc0e5942a3a9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/webpack.config.js @@ -1,6 +1,5 @@ module.exports = { builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/output.snap.txt deleted file mode 100644 index d60bf9f51990..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/output.snap.txt +++ /dev/null @@ -1,42 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const a = "bar"; -}), -"./baz.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = "baz"; -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _baz__WEBPACK_IMPORTED_MODULE_0__.a; } -}); -/* harmony import */var _baz__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./baz.js"); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -console.log(_foo__WEBPACK_IMPORTED_MODULE_0__.a); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/webpack.config.js similarity index 82% rename from packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/webpack.config.js index 2e39e83cf16c..dc0e5942a3a9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/webpack.config.js @@ -1,6 +1,5 @@ module.exports = { builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/output.snap.txt deleted file mode 100644 index 8839b0b46ea7..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/output.snap.txt +++ /dev/null @@ -1,21 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -var _lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -/*#__PURE__*/ (_lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (_lib__WEBPACK_IMPORTED_MODULE_0___namespace_cache = __webpack_require__.t(_lib__WEBPACK_IMPORTED_MODULE_0__, 2))); -}), -"./lib.js": (function (__unused_webpack_module, exports) { -exports.a = 100000; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/output.snap.txt deleted file mode 100644 index 2720bd231b0c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/output.snap.txt +++ /dev/null @@ -1,43 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); -__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); - -_answer__WEBPACK_IMPORTED_MODULE_0__.filter; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - filter: function() { return _test_js__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); -const a = 3; - - -}), -"./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - result: function() { return result; } -}); -const result = ""; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/output.snap.txt deleted file mode 100644 index 738e725c560f..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/output.snap.txt +++ /dev/null @@ -1,40 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./src/answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - formatNumber: function() { return _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/plugin/formatNumber.js"); - - -}), -"./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/answer.js"); - -console.log(_answer__WEBPACK_IMPORTED_MODULE_0__); -}), -"./src/plugin/formatNumber.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return formatNumber_default; } -}); -function formatNumber(config) {} -const plugin = (cls)=>{ - cls.prototype.formatNumber = formatNumber; -}; -var formatNumber_default = plugin; - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./src/index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/webpack.config.js similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/webpack.config.js index 731e7857cc8f..98c0058e2ecd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/webpack.config.js @@ -8,7 +8,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/output.snap.txt deleted file mode 100644 index 8bad4b70d69a..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/output.snap.txt +++ /dev/null @@ -1,99 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./something/index.js"); -__webpack_require__.es(_something__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - - -}), -"./colors/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - red: function() { return red; } -}); -const red = "red"; -}), -"./colors/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - blue: function() { return blue; } -}); -const blue = "blue"; -}), -"./colors/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./colors/result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./colors/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./colors/a.js"); -__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./colors/b.js"); -__webpack_require__.es(_b__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./colors/c.js"); -__webpack_require__.es(_c__WEBPACK_IMPORTED_MODULE_2__, __webpack_exports__); - - - -}), -"./colors/result.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - result: function() { return result; } -}); -const result = "ssss"; -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Layout.js"); -__webpack_require__.es(_Layout__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); - -_export__WEBPACK_IMPORTED_MODULE_0__.Colors; -_export__WEBPACK_IMPORTED_MODULE_0__.Something; -}), -"./something/Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Something: function() { return Something; } -}); -class Something { -} -}), -"./something/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Colors: function() { return _colors_index__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _colors_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./colors/index.js"); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./something/Something.js"); -__webpack_require__.es(_Something__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/output.snap.txt deleted file mode 100644 index b562c870ee75..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/output.snap.txt +++ /dev/null @@ -1,60 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - bar: function() { return _foo__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -function b() {} - - -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -const a = 3; -const foo = 3; - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -_foo__WEBPACK_IMPORTED_MODULE_0__.bar.a; -(0, _foo__WEBPACK_IMPORTED_MODULE_0__.c)(); -}), -"./result.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - c: function() { return c; } -}); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -const c = 103330; - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export_star/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export_star/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/export_star/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/output.snap.txt deleted file mode 100644 index 059c33557200..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/output.snap.txt +++ /dev/null @@ -1,56 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -function b() {} - - -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -const a = 3; - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_2__, __webpack_exports__); - - - -}), -"./result.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -const c = 103330; - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/output.snap.txt deleted file mode 100644 index b9a9b1080108..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/output.snap.txt +++ /dev/null @@ -1,55 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return b; } -}); -/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -function b() {} - - -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); -__webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -const a = 3; -const b = 3; - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); - -(0, _bar_js__WEBPACK_IMPORTED_MODULE_0__.b)(); -}), -"./result.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); -const c = 103330; -const b = 103330; - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/output.snap.txt deleted file mode 100644 index 158e5a992472..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/output.snap.txt +++ /dev/null @@ -1,16 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); - -console.log("something"); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/webpack.config.js similarity index 88% rename from packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/webpack.config.js index 6eaacb6ba181..c85d327322f1 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/output.snap.txt deleted file mode 100644 index 5c678024b67d..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/output.snap.txt +++ /dev/null @@ -1,35 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -__webpack_require__("./source/index.js"); -console.log("something"); -}), -"./source/index.js": (function (module) { -class Response { - /** - * @param {CompiledMode} mode - */ constructor(mode){ - // eslint-disable-next-line no-undefined - if (mode.data === undefined) mode.data = {}; - this.data = mode.data; - this.isMatchIgnored = false; - } - ignoreMatch() { - this.isMatchIgnored = true; - } -} -function test() { - let res = new Response(); - return res; -} -const result = test(); -module.exports = result; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/webpack.config.js similarity index 88% rename from packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/webpack.config.js index 6eaacb6ba181..c85d327322f1 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/output.snap.txt deleted file mode 100644 index cdf98b5707f8..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/output.snap.txt +++ /dev/null @@ -1,23 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -var a = 1; -/* harmony default export */ __webpack_exports__["default"] = (a); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__["default"]; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/output.snap.txt deleted file mode 100644 index d5dc3d9bcc28..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/output.snap.txt +++ /dev/null @@ -1,39 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - aaa: function() { return _app__WEBPACK_IMPORTED_MODULE_1__; }, - routes: function() { return routes; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./app.js"); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1__); - - -const routes = { - answer: _answer__WEBPACK_IMPORTED_MODULE_0__.something -}; -}), -"./answer.js": (function () { -}), -"./app.js": (function () { -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); - -_a_js__WEBPACK_IMPORTED_MODULE_0__.routes; -_a_js__WEBPACK_IMPORTED_MODULE_0__.aaa.result; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/output.snap.txt deleted file mode 100644 index 101cb962c558..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/output.snap.txt +++ /dev/null @@ -1,28 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - app: function() { return app; } -}); -const app = "app"; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -function a() { - _app__WEBPACK_IMPORTED_MODULE_0__.app.app?.a; -} -a(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/webpack.config.js index 705373817f53..0b04baaf2117 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'production'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/output.snap.txt deleted file mode 100644 index 79d50e2f3848..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/output.snap.txt +++ /dev/null @@ -1,35 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - app: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.app; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 20000; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/output.snap.txt deleted file mode 100644 index 8ff4552ed0e3..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/output.snap.txt +++ /dev/null @@ -1,37 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return Something; } -}); -class Something { -} -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Sider: function() { return _Something__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Something.js"); - - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); - -(0, _export__WEBPACK_IMPORTED_MODULE_0__.Sider)(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/output.snap.txt deleted file mode 100644 index 1c6f1344859a..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/output.snap.txt +++ /dev/null @@ -1,60 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - c: function() { return c; } -}); -const c = "a"; -}), -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const a = "bar"; -const c = "bar"; -}), -"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - -const a = 3; -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return b; } -}); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -const a = "foo"; -const b = "foo"; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./c.js"); -// require("./c.js"); - -_c_js__WEBPACK_IMPORTED_MODULE_0__.a; -_c_js__WEBPACK_IMPORTED_MODULE_0__.b; -_c_js__WEBPACK_IMPORTED_MODULE_0__.c; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/webpack.config.js index d8493e607c4b..24d478b1c3e0 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: false }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/output.snap.txt deleted file mode 100644 index 46b991950427..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/output.snap.txt +++ /dev/null @@ -1,69 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"../../../../../node_modules/@swc/helpers/esm/_create_class.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return _create_class; } -}); -function _defineProperties(target, props) { - for(var i = 0; i < props.length; i++){ - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } -} -function _create_class(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; -} - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./util.js"); - -}), -"./util.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../../../../../node_modules/@swc/helpers/esm/_create_class.js"); - -var ConsoleExporterWeb; -ConsoleExporterWeb = function() { - "use strict"; - function ConsoleExporterWeb() { - this.stoped = false; - } - (0, _swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_0__._)(ConsoleExporterWeb, [ - { - key: "export", - value: function _export(evts, cb) { - if (this.stoped) return; - evts.forEach(adaptToBrowserConsole); - if (cb) cb(ExportResult.SUCCESS); - } - }, - { - key: "shutdown", - value: function shutdown() { - this.stoped = true; - } - } - ]); - return ConsoleExporterWeb; -}(); -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (ConsoleExporterWeb); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/output.snap.txt deleted file mode 100644 index 96ada11a2004..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/output.snap.txt +++ /dev/null @@ -1,25 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); - -_test__WEBPACK_IMPORTED_MODULE_0__.obj.test = 1; -}), -"./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - obj: function() { return obj; } -}); -const obj = {}; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/webpack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/issues_3198/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/issues_3198/webpack.config.js diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/output.snap.txt deleted file mode 100644 index 645365e14a23..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/output.snap.txt +++ /dev/null @@ -1,41 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - defaults: function() { return defaults; } -}); -const defaults = { - test: 1000 -}; -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Something: function() { return Something; } -}); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Layout.js"); - -function callit() { - _Layout__WEBPACK_IMPORTED_MODULE_0__.defaults.test; -} -var Sider = callit(); -var Something = 20000; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); - -(0, _export__WEBPACK_IMPORTED_MODULE_0__.Something)(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/webpack.config.js index d8493e607c4b..24d478b1c3e0 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: false }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/output.snap.txt deleted file mode 100644 index f0d9538f820d..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/output.snap.txt +++ /dev/null @@ -1,41 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - defaults: function() { return defaults; } -}); -const defaults = { - test: 1000 -}; -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Something: function() { return Something; } -}); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Layout.js"); - -class Test { - test = _Layout__WEBPACK_IMPORTED_MODULE_0__.defaults.test + 20000; -} -var Sider = new Test(); -var Something = 333; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); - -(0, _export__WEBPACK_IMPORTED_MODULE_0__.Something)(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/webpack.config.js index d8493e607c4b..24d478b1c3e0 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: false }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/output.snap.txt deleted file mode 100644 index 1e96b5746da0..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/output.snap.txt +++ /dev/null @@ -1,33 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 3; -}), -"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const c = 300; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); - - - -_a_js__WEBPACK_IMPORTED_MODULE_0__.a; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/webpack.config.js similarity index 91% rename from packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/webpack.config.js index cf3a7af96646..50d1b5c71f62 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/output.snap.txt deleted file mode 100644 index 54508b2d88ca..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/output.snap.txt +++ /dev/null @@ -1,33 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 3; -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const b = 30; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); - - - -_a_js__WEBPACK_IMPORTED_MODULE_0__.a; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/webpack.config.js similarity index 91% rename from packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/webpack.config.js index a03de12a7010..cfc125c28e40 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/output.snap.txt deleted file mode 100644 index cd6f4a80b31f..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/output.snap.txt +++ /dev/null @@ -1,57 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return Layout; } -}); -function Layout() {} -}), -"./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return something; } -}); -function something() {} -}), -"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - cccc: function() { return cccc; } -}); -function cccc() {} -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - cccc: function() { return _c__WEBPACK_IMPORTED_MODULE_2__.cccc; } -}); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Layout.js"); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./Something.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./c.js"); - - -var L = _Layout__WEBPACK_IMPORTED_MODULE_0__["default"]; -L.something = _Something__WEBPACK_IMPORTED_MODULE_1__.something; - -var LL = L; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); - -(0, _export__WEBPACK_IMPORTED_MODULE_0__.cccc)(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/output.snap.txt deleted file mode 100644 index f07c2b9d5f1d..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/output.snap.txt +++ /dev/null @@ -1,39 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return something; } -}); -function something() {} -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return a; } -}); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Something.js"); - - -var a = function test() { - _Something__WEBPACK_IMPORTED_MODULE_0__.something; -}; - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); - -_export__WEBPACK_IMPORTED_MODULE_0__["default"]; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/output.snap.txt deleted file mode 100644 index 78352eb04969..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/output.snap.txt +++ /dev/null @@ -1,76 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = { - a: "" -}; -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return b; } -}); -const b = { - b: "" -}; -}), -"./enum-old.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__.a; }, - b: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.b; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); - - -}), -"./enum.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _enum_old__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./enum-old.js"); -__webpack_require__.es(_enum_old__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -console.log(_lib__WEBPACK_IMPORTED_MODULE_0__.getDocPermissionTextSendMe); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - getDocPermissionTextSendMe: function() { return getDocPermissionTextSendMe; } -}); -/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./enum.js"); - -function Record() {} -const code2CreateChatDocPermission = { - 1: _enum_js__WEBPACK_IMPORTED_MODULE_0__.a.a -}; -function getDocPermissionTextSendMe() {} -class Doc extends Record({}) { - isSheet() { - return this.type === _enum_js__WEBPACK_IMPORTED_MODULE_0__.b.b; - } -} -Doc.fromJS = (data)=>new Doc(data); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/output.snap.txt deleted file mode 100644 index 53ae0f4fe71a..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/output.snap.txt +++ /dev/null @@ -1,40 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 103330; -const b = 103330; -}), -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); -__webpack_require__.es(_answer__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -_lib__WEBPACK_IMPORTED_MODULE_0__.a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); -__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/output.snap.txt deleted file mode 100644 index a7a41e69c7db..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/output.snap.txt +++ /dev/null @@ -1,36 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 103330; -const b = 103330; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -_lib__WEBPACK_IMPORTED_MODULE_0__.Lib.a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Lib: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/output.snap.txt deleted file mode 100644 index 026e5257b5db..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/output.snap.txt +++ /dev/null @@ -1,32 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony default export */ __webpack_exports__["default"] = (300); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -_lib__WEBPACK_IMPORTED_MODULE_0__.a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a_js__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); - - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/output.snap.txt deleted file mode 100644 index 7fa18a871471..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/output.snap.txt +++ /dev/null @@ -1,39 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - answer: function() { return answer; } -}); -const answer = 103330; -}), -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); - -function res() { - _answer__WEBPACK_IMPORTED_MODULE_0__.answer; -} -const a = 3; -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (res()); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.a; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/output.snap.txt deleted file mode 100644 index 8b0f7c209587..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/output.snap.txt +++ /dev/null @@ -1,56 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Provider: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; }, - useSelector: function() { return _selector_js__WEBPACK_IMPORTED_MODULE_1__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); -/* harmony import */var _selector_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./selector.js"); - - - -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); -__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -function batch() {} - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -_foo__WEBPACK_IMPORTED_MODULE_0__.Provider; -_foo__WEBPACK_IMPORTED_MODULE_0__.useSelector; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -function Provider() {} -/* harmony default export */ __webpack_exports__["default"] = (Provider); -}), -"./selector.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return useSelector; } -}); -function useSelector() { - return ""; -} -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/output.snap.txt deleted file mode 100644 index 77a392850e34..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/output.snap.txt +++ /dev/null @@ -1,58 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./package/autogen/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; }, - aa: function() { return _aa__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _aa__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/aa.js"); - -function a() {} -function dddd() {} - -}), -"./package/autogen/aa.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - aa: function() { return aa; } -}); -const aa = 3; -const cc = 3; -}), -"./package/autogen/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/a.js"); - - - -}), -"./package/src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/index.js"); -__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/src/index.js"); - -_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.a; -_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.aa.aa; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./src/index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/webpack.config.js similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/webpack.config.js index 731e7857cc8f..98c0058e2ecd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/webpack.config.js @@ -8,7 +8,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/output.snap.txt deleted file mode 100644 index 5b86e4ae6db5..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/output.snap.txt +++ /dev/null @@ -1,44 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./package/autogen/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -function a() {} -function dddd() {} -}), -"./package/autogen/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/a.js"); - - - -}), -"./package/src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/index.js"); -__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), -"./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/src/index.js"); - -_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.a; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./src/index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/webpack.config.js similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/webpack.config.js index 731e7857cc8f..98c0058e2ecd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/webpack.config.js @@ -8,7 +8,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/output.snap.txt deleted file mode 100644 index d2d7de502c70..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/output.snap.txt +++ /dev/null @@ -1,34 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return test; } -}); -function test() {} -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Select: function() { return _bar__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -(0, _foo__WEBPACK_IMPORTED_MODULE_0__.Select)(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/output.snap.txt deleted file mode 100644 index 9b7fb4c5d50d..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/output.snap.txt +++ /dev/null @@ -1,40 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return _b_js__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./b.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); - - -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./c.js"); - -/* harmony default export */ __webpack_exports__["default"] = (2000 + _c_js__WEBPACK_IMPORTED_MODULE_0__["default"]); -}), -"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony default export */ __webpack_exports__["default"] = (10); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); - -_a_js__WEBPACK_IMPORTED_MODULE_0__.b; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/output.snap.txt deleted file mode 100644 index 03dc701c9849..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/output.snap.txt +++ /dev/null @@ -1,36 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - q: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__.question; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.q; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - question: function() { return question; } -}); -const answer = "1"; -const question = "2"; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/output.snap.txt deleted file mode 100644 index 2c0134c5cd08..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/output.snap.txt +++ /dev/null @@ -1,33 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - bar: function() { return bar; } -}); -var foo = function() { - return 42; -}; -/* harmony default export */ __webpack_exports__["default"] = (foo); -function bar() { - return contrivedExample(foo); -} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -var answer = (0, _foo__WEBPACK_IMPORTED_MODULE_0__["default"])(); -var somethingElse = (0, _foo__WEBPACK_IMPORTED_MODULE_0__.bar)(); -console.log(answer); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/output.snap.txt deleted file mode 100644 index ae122b9ad1a5..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/output.snap.txt +++ /dev/null @@ -1,31 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -var Foo = function() { - console.log("side effect"); - this.isFoo = true; -}; -/* harmony default export */ __webpack_exports__["default"] = (Foo); -Foo.prototype = { - answer: function() { - return 42; - } -}; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -var foo = new _foo__WEBPACK_IMPORTED_MODULE_0__["default"](); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/output.snap.txt deleted file mode 100644 index 4aa2f1cae325..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/output.snap.txt +++ /dev/null @@ -1,39 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./dead.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { - return "dead"; -} -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } -}); -/* harmony import */var _dead__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dead.js"); - -/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { - return "foo"; -} -function foodead() { - return "foo" + /* "./dead" unused */null(); -} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -assert.equal((0, _foo__WEBPACK_IMPORTED_MODULE_0__["default"])(), "foo"); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/output.snap.txt deleted file mode 100644 index ba625e987e82..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/output.snap.txt +++ /dev/null @@ -1,32 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - foo: function() { return foo; } -}); -var foo = { - value: 1 -}; -function mutate(obj) { - obj.value += 1; - return obj; -} -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (mutate(foo)); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -assert.equal(_foo__WEBPACK_IMPORTED_MODULE_0__.foo.value, 2); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/output.snap.txt deleted file mode 100644 index 847adc1dbbf4..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/output.snap.txt +++ /dev/null @@ -1,65 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _stuff__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./stuff.js"); - -(0, _stuff__WEBPACK_IMPORTED_MODULE_0__.bar)(); -var f = (0, _stuff__WEBPACK_IMPORTED_MODULE_0__.baz)(); -f(); -function getClass() { - class MyClass { - } - class UnusedInnerClass1 { - } - return MyClass; -} -class UnusedClass { -} -console.log(getClass().name); -}), -"./stuff.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - bar: function() { return bar; }, - baz: function() { return Baz; } -}); -function foo() { - console.log("outer foo"); -} -function bar() { - console.log("outer bar"); -} -function bog() { - console.log("outer bog"); -} -function boo() { - console.log("outer boo"); -} -function Baz() { - function foo() { - console.log("inner foo"); - } - function bar() { - console.log("inner bar"); - } - function bog() { - console.log("inner bog"); - } - function boo() { - console.log("inner boo"); - } - return bar(), bog; -} - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/treeshaking.snap.txt similarity index 97% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/treeshaking.snap.txt index e0033e6b9662..45e47af113ac 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/treeshaking.snap.txt @@ -13,6 +13,8 @@ function getClass() { class UnusedInnerClass1 { } return MyClass; + class UnusedInnerClass2 { + } } class UnusedClass { } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/output.snap.txt deleted file mode 100644 index f1b66f903d07..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/output.snap.txt +++ /dev/null @@ -1,28 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - foo: function() { return foo; } -}); -var foo = "lol"; -var bar = "wut"; -var baz = bar || foo; - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); - -console.log(_foo_js__WEBPACK_IMPORTED_MODULE_0__.foo); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/output.snap.txt deleted file mode 100644 index 0636b0ed08fe..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/output.snap.txt +++ /dev/null @@ -1,38 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {} -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/webpack.config.js similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/webpack.config.js index f6fba51540fc..e91759eba46e 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/webpack.config.js @@ -5,7 +5,6 @@ module.exports = { } }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/output.snap.txt deleted file mode 100644 index 1e2f9dee8413..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/output.snap.txt +++ /dev/null @@ -1,27 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return b; } -}); - -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (/* "./lib" unused */null); -const b = 1; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.b; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/output.snap.txt deleted file mode 100644 index 2a24824210fb..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/output.snap.txt +++ /dev/null @@ -1,46 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); -/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/a.js"); - - -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {} -}), -"./src/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = ((()=>{ - console.log(""); -})); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/webpack.config.js similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/webpack.config.js index 143d7c8f05ae..996176d825a6 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/webpack.config.js @@ -5,7 +5,6 @@ module.exports = { } }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/output.snap.txt deleted file mode 100644 index b8fe5582c6fb..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/output.snap.txt +++ /dev/null @@ -1,37 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); -__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - - // export { - // result as test - // } -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); // a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return something; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/output.snap.txt deleted file mode 100644 index ea542e724085..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/output.snap.txt +++ /dev/null @@ -1,40 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - - // export { - // result as test - // } -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {} -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/output.snap.txt deleted file mode 100644 index 3d688d607816..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/output.snap.txt +++ /dev/null @@ -1,49 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _maths_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./maths.js"); -/* TREE-SHAKING */ -console.log(_maths_js__WEBPACK_IMPORTED_MODULE_0__.xxx.test); -console.log(_maths_js__WEBPACK_IMPORTED_MODULE_0__.square); -}), -"./maths.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - square: function() { return square; }, - xxx: function() { return _test_js__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); -// maths.js -// This function isn't used anywhere, so -// Rollup excludes it from the bundle... -function square(x) { - return x * x; -} -// This function gets included -function cube(x) { - // rewrite this as `square( x ) * x` - // and see what happens! - return x * x * x; -} - -}), -"./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); -function test() {} -function ccc() {} -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/output.snap.txt deleted file mode 100644 index 07f9f437fae8..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/output.snap.txt +++ /dev/null @@ -1,47 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./b.js"); - -class Test { - static c = (0, _b_js__WEBPACK_IMPORTED_MODULE_0__.bb)(); - static test() { - _b_js__WEBPACK_IMPORTED_MODULE_0__.bb; - } -} -class Result { - static test() { - /* "./b.js" unused */null; - } -} -const a = 3; -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - bb: function() { return bb; } -}); -const bb = 2; -const cc = 3; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); - -_a_js__WEBPACK_IMPORTED_MODULE_0__.a; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/static-class/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/static-class/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/static-class/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/static-class/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/static-class/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/static-class/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/output.snap.txt deleted file mode 100644 index 07c1134f6417..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/output.snap.txt +++ /dev/null @@ -1,40 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; }, - b: function() { return b; } -}); -const a = 3; -const b = 3; -}), -"./answer.js": (function (__unused_webpack_module, exports, __webpack_require__) { -const res = __webpack_require__("./lib.js"); -exports.test = function() { - res; -}; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); - -_answer__WEBPACK_IMPORTED_MODULE_0__.test; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/output.snap.txt deleted file mode 100644 index da1cf29ad124..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/output.snap.txt +++ /dev/null @@ -1,32 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./side-effects.js"); -/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_0__); - - -const a = 3; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.a; -}), -"./side-effects.js": (function () { -console.log("side effect"); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/output.snap.txt deleted file mode 100644 index 937772ef7b30..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/output.snap.txt +++ /dev/null @@ -1,36 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./ b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return b; } -}); -const b = 3; -}), -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 3; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./ b.js"); - - -_a_js__WEBPACK_IMPORTED_MODULE_0__.a; -_b_js__WEBPACK_IMPORTED_MODULE_1__.b; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt deleted file mode 100644 index f1622e0b6de7..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/output.snap.txt +++ /dev/null @@ -1,50 +0,0 @@ -```js title=bar_js.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["bar_js"], { -"./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return test; } -}); -function test() {} -}), - -}]); -``` - -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -__webpack_require__.e(/* import() */ "bar_js").then(__webpack_require__.bind(__webpack_require__, "./bar.js")).then((mod)=>{ - console.log(mod); -}); -const a = "a"; -exports.test = 30; -}), -"./foo.js": (function (module, __unused_webpack_exports, __webpack_require__) { -{ - const res = __webpack_require__("./a.js"); - module.exports = res; -} // export default function () {} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foo__WEBPACK_IMPORTED_MODULE_0__); - -_foo__WEBPACK_IMPORTED_MODULE_0___default()(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/treeshaking.snap.txt similarity index 90% rename from packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/treeshaking.snap.txt index 02ab1e708e8f..5922aaa4befd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/new_treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/treeshaking.snap.txt @@ -26,10 +26,16 @@ __webpack_require__.e(/* import() */ "bar_js").then(__webpack_require__.bind(__w const a = "a"; exports.test = 30; }), +"./b.js": (function (module) { +module.exports = a = "b"; +}), "./foo.js": (function (module, __unused_webpack_exports, __webpack_require__) { -{ +if (process.env.NODE_ENV !== "production") { const res = __webpack_require__("./a.js"); module.exports = res; +} else { + const c = __webpack_require__("./b.js"); + module.exports = c; } // export default function () {} }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/output.snap.txt deleted file mode 100644 index cb8d2a5ac86b..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/output.snap.txt +++ /dev/null @@ -1,49 +0,0 @@ -```js title=lib_js.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["lib_js"], { -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); - -function myanswer() { - _test__WEBPACK_IMPORTED_MODULE_0__["default"]; -} -/* harmony default export */ __webpack_exports__["default"] = (myanswer); -}), -"./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -function test() {} -/* harmony default export */ __webpack_exports__["default"] = (test); -}), - -}]); -``` - -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - answer: function() { return answer; } -}); -const answer = 30; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -const a = test(()=>__webpack_require__.e(/* import() */ "lib_js").then(__webpack_require__.bind(__webpack_require__, "./lib.js"))); -(0, _app__WEBPACK_IMPORTED_MODULE_0__.answer)(); -a; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/test.config.js deleted file mode 100644 index 2e39e83cf16c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/test.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/webpack.config.js new file mode 100644 index 000000000000..dc0e5942a3a9 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/webpack.config.js @@ -0,0 +1,7 @@ +module.exports = { + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/output.snap.txt deleted file mode 100644 index 29c82cc830db..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/output.snap.txt +++ /dev/null @@ -1,19 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); -async function test() {} -test(); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/webpack.config.js similarity index 88% rename from packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/webpack.config.js index 5510e7de052d..e3d61c921ecf 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/webpack.config.js @@ -4,7 +4,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/output.snap.txt deleted file mode 100644 index 8875d15ac642..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/output.snap.txt +++ /dev/null @@ -1,32 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); -function test() {} -class Cls { - constructor(){} -} -if (__AAA__) { - const __Cls = Cls; - __Cls.prototype.aaa = function(a, b) {}; -} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -_app__WEBPACK_IMPORTED_MODULE_0__.test; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/output.snap.txt deleted file mode 100644 index 29749a67e8a4..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/output.snap.txt +++ /dev/null @@ -1,45 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - app: function() { return app; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); - -var app = function() { - _lib__WEBPACK_IMPORTED_MODULE_0__.result; -}; -var app2 = ()=>{ - /* "./lib" unused */null; -}; -var app4 = (0, _lib__WEBPACK_IMPORTED_MODULE_0__.something)("app4"), app5 = 10000; -var app3 = (0, _lib__WEBPACK_IMPORTED_MODULE_0__.something)("app3"); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); - -(0, _app__WEBPACK_IMPORTED_MODULE_0__.app)(); -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - result: function() { return result; }, - something: function() { return something; } -}); -const secret = "888"; -const result = 20000; -const something = function() {}; -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/output.snap.txt deleted file mode 100644 index bc7178287e5c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/output.snap.txt +++ /dev/null @@ -1,176 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return abc; } -}); -/* harmony import */var _dep_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?a"); - -function abc() { - return _dep_a__WEBPACK_IMPORTED_MODULE_0__.x; -} -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?b"); - -function abc() { - return /* "./dep?b" unused */null; -} -}), -"./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?c"); - -function abc() { - return _dep_c__WEBPACK_IMPORTED_MODULE_0__.x; -} -abc(); -}), -"./d.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return def; } -}); -/* harmony import */var _dep_d__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?d"); - -class def { - method() { - return _dep_d__WEBPACK_IMPORTED_MODULE_0__.x; - } -} -}), -"./dep.js?a": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return x; } -}); -const x = "x"; -/* harmony default export */ __webpack_exports__["default"] = (true); -}), -"./dep.js?b": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const x = "x"; -/* harmony default export */ __webpack_exports__["default"] = (false); -}), -"./dep.js?c": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return x; } -}); -const x = "x"; -/* harmony default export */ __webpack_exports__["default"] = (true); -}), -"./dep.js?d": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return x; } -}); -const x = "x"; -/* harmony default export */ __webpack_exports__["default"] = (true); -}), -"./dep.js?e": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -const x = "x"; -/* harmony default export */ __webpack_exports__["default"] = (false); -}), -"./dep.js?f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return x; } -}); -const x = "x"; -/* harmony default export */ __webpack_exports__["default"] = (true); -}), -"./e.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?e"); - -class def { - method() { - return /* "./dep?e" unused */null; - } -} -}), -"./f.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _dep_f__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?f"); - -class def { - method() { - return _dep_f__WEBPACK_IMPORTED_MODULE_0__.x; - } -} -new def().method(); -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./c.js"); -/* harmony import */var _d__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./d.js"); -/* harmony import */var _e__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./e.js"); -/* harmony import */var _f__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./f.js"); -/* harmony import */var _dep_a__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./dep.js?a"); -/* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("./dep.js?b"); -/* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__("./dep.js?c"); -/* harmony import */var _dep_d__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__("./dep.js?d"); -/* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__("./dep.js?e"); -/* harmony import */var _dep_f__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__("./dep.js?f"); - - - - - - - - - - - - -it("should generate valid code", ()=>{ - expect((0, _a__WEBPACK_IMPORTED_MODULE_0__["default"])()).toBe("x"); - expect(new _d__WEBPACK_IMPORTED_MODULE_3__["default"]().method()).toBe("x"); -}); -it("a should be used", ()=>{ - expect(_dep_a__WEBPACK_IMPORTED_MODULE_6__["default"]).toBe(true); -}); -it("b should be unused", ()=>{ - expect(_dep_b__WEBPACK_IMPORTED_MODULE_7__["default"]).toBe(false); -}); -it("c should be used", ()=>{ - expect(_dep_c__WEBPACK_IMPORTED_MODULE_8__["default"]).toBe(true); -}); -it("d should be used", ()=>{ - expect(_dep_d__WEBPACK_IMPORTED_MODULE_9__["default"]).toBe(true); -}); -it("e should be unused", ()=>{ - expect(_dep_e__WEBPACK_IMPORTED_MODULE_10__["default"]).toBe(false); -}); -it("f should be used", ()=>{ - expect(_dep_f__WEBPACK_IMPORTED_MODULE_11__["default"]).toBe(true); -}); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/treeshaking.snap.txt similarity index 92% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/treeshaking.snap.txt index 827a20d0b72a..2d8fdac9437a 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/treeshaking.snap.txt @@ -137,18 +137,22 @@ it("should generate valid code", ()=>{ it("a should be used", ()=>{ expect(_dep_a__WEBPACK_IMPORTED_MODULE_6__["default"]).toBe(true); }); -it("b should be unused", ()=>{ - expect(_dep_b__WEBPACK_IMPORTED_MODULE_7__["default"]).toBe(false); -}); +if (process.env.NODE_ENV === "production") { + it("b should be unused", ()=>{ + expect(_dep_b__WEBPACK_IMPORTED_MODULE_7__["default"]).toBe(false); + }); +} it("c should be used", ()=>{ expect(_dep_c__WEBPACK_IMPORTED_MODULE_8__["default"]).toBe(true); }); -it("d should be used", ()=>{ - expect(_dep_d__WEBPACK_IMPORTED_MODULE_9__["default"]).toBe(true); -}); -it("e should be unused", ()=>{ - expect(_dep_e__WEBPACK_IMPORTED_MODULE_10__["default"]).toBe(false); -}); +if (process.env.NODE_ENV === "production") { + it("d should be used", ()=>{ + expect(_dep_d__WEBPACK_IMPORTED_MODULE_9__["default"]).toBe(true); + }); + it("e should be unused", ()=>{ + expect(_dep_e__WEBPACK_IMPORTED_MODULE_10__["default"]).toBe(false); + }); +} it("f should be used", ()=>{ expect(_dep_f__WEBPACK_IMPORTED_MODULE_11__["default"]).toBe(true); }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/webpack.config.js index 705373817f53..0b04baaf2117 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: true }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'production'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/output.snap.txt deleted file mode 100644 index 953098a5583c..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/output.snap.txt +++ /dev/null @@ -1,102 +0,0 @@ -```js title=chunk_js.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["chunk_js"], { -"./chunk.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _some_module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./some-module.js"); - -}), - -}]); -``` - -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./import-module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); -/* harmony import */var _module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./module.js"); - -function test() { - (0, _module__WEBPACK_IMPORTED_MODULE_0__["default"])({ - type: "inline" - }); -} -}), -"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -it("should generate correct code when pure expressions are in dead branches", ()=>{ - __webpack_require__("./import-module.js")/* .test */.test(); - return Promise.all([ - Promise.resolve(/* import() */ ).then(__webpack_require__.bind(__webpack_require__, "./some-module.js")), - __webpack_require__.e(/* import() */ "chunk_js").then(__webpack_require__.bind(__webpack_require__, "./chunk.js")) - ]); -}); -}), -"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _some_module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./some-module.js"); - -function getType(obj) { - return obj.type; -} -// Local functions -function doSomethingWithBlock(obj) { - return _some_module__WEBPACK_IMPORTED_MODULE_0__.Block.doSomething(obj); -} -function doSomethingWithInline(obj) { - return _some_module__WEBPACK_IMPORTED_MODULE_0__.Inline.doSomething(obj); -} -function doSomethingWithDocument(obj) { - return _some_module__WEBPACK_IMPORTED_MODULE_0__.Document.doSomething(obj); -} -// Exported functions -function doSomething(obj) { - const type = getType(obj); - switch(type){ - case "document": - return doSomethingWithDocument(obj); - case "block": - return doSomethingWithBlock(obj); - case "inline": - return doSomethingWithInline(obj); - default: - throw new Error(); - } -} -function useDocument(obj) { - return doSomethingWithDocument(obj); -} - -/* harmony default export */ __webpack_exports__["default"] = (doSomething); -}), -"./some-module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Block: function() { return Block; }, - Document: function() { return Document; }, - Inline: function() { return Inline; } -}); -class Block { - static doSomething() {} -} -class Inline { - static doSomething() {} -} -class Document { - static doSomething() {} -} - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/output.snap.txt deleted file mode 100644 index be1450bac130..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/output.snap.txt +++ /dev/null @@ -1,95 +0,0 @@ -```js title=chunk_js.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["chunk_js"], { -"./chunk.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./inner.js"); - -}), - -}]); -``` - -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./inner.js"); -/* harmony import */var _module__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./module.js"); - - -it("export should be unused when only unused functions use it", ()=>{ - expect((0, _module__WEBPACK_IMPORTED_MODULE_1__.y)("a")).toBe("okBAA"); - expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportAUsed).toBe(true); - expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportBUsed).toBe(true); - expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportCUsed).toBe(false); - return __webpack_require__.e(/* import() */ "chunk_js").then(__webpack_require__.bind(__webpack_require__, "./chunk.js")); -}); -}), -"./inner.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - A: function() { return A; }, - B: function() { return B; }, - exportAUsed: function() { return exportAUsed; }, - exportBUsed: function() { return exportBUsed; }, - exportCUsed: function() { return exportCUsed; } -}); -function A(s) { - return s + "A"; -} -function B(s) { - return s + "B"; -} -function C(s) { - return s + "C"; -} -const exportAUsed = true; -const exportBUsed = true; -const exportCUsed = false; -}), -"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - y: function() { return y; } -}); -/* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./inner.js"); - -function x(type) { - switch(type){ - case "a": - return withA("b"); - case "b": - return withB("c"); - case "c": - return "ok"; - } -} -function y(v) { - return withA(v); -} -function withA(v) { - const value = x(v); - return (0, _inner__WEBPACK_IMPORTED_MODULE_0__.A)(value); -} -function withB(v) { - const value = x(v); - return (0, _inner__WEBPACK_IMPORTED_MODULE_0__.B)(value); -} -function withC(v) { - const value = x(v); - return /* "./inner" unused */null(value); -} - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/treeshaking.snap.txt similarity index 95% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/treeshaking.snap.txt index bb30cb6890be..9e632248eebc 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/new_treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/treeshaking.snap.txt @@ -22,7 +22,9 @@ it("export should be unused when only unused functions use it", ()=>{ expect((0, _module__WEBPACK_IMPORTED_MODULE_1__.y)("a")).toBe("okBAA"); expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportAUsed).toBe(true); expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportBUsed).toBe(true); - expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportCUsed).toBe(false); + if (process.env.NODE_ENV === "production") { + expect(_inner__WEBPACK_IMPORTED_MODULE_0__.exportCUsed).toBe(false); + } return __webpack_require__.e(/* import() */ "chunk_js").then(__webpack_require__.bind(__webpack_require__, "./chunk.js")); }); }), diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/webpack.config.js similarity index 86% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/webpack.config.js index ad2d9901ad01..71786dedbf52 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/webpack.config.js @@ -3,7 +3,6 @@ module.exports = { sideEffects: false }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'production'" } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/output.snap.txt deleted file mode 100644 index d6c9dc8ed819..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/output.snap.txt +++ /dev/null @@ -1,134 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./module.js"); - -it("should be able to handle circular referenced", ()=>{ - expect((0, _module__WEBPACK_IMPORTED_MODULE_0__.x)()).toEqual([ - _module__WEBPACK_IMPORTED_MODULE_0__.y, - _module__WEBPACK_IMPORTED_MODULE_0__.z - ]); - const [_a, b, c, d] = (0, _module__WEBPACK_IMPORTED_MODULE_0__.a)(); - expect(b()).toEqual([ - _module__WEBPACK_IMPORTED_MODULE_0__.a, - b, - c, - d - ]); - expect(c()).toEqual([ - _module__WEBPACK_IMPORTED_MODULE_0__.a, - b, - c, - d - ]); - expect(d()).toEqual([ - _module__WEBPACK_IMPORTED_MODULE_0__.a, - b, - c, - d - ]); - const [f2, f4] = (0, _module__WEBPACK_IMPORTED_MODULE_0__.f3)(); - const [f1, _f3] = f2(); - expect(_f3).toBe(_module__WEBPACK_IMPORTED_MODULE_0__.f3); - expect((0, _module__WEBPACK_IMPORTED_MODULE_0__.f3)()).toEqual(f1()); - expect(f2()).toEqual(f4()); -}); -}), -"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; }, - f3: function() { return f3; }, - x: function() { return x; }, - y: function() { return y; }, - z: function() { return z; } -}); -function x() { - return [ - y, - z - ]; -} -function y() { - return [ - x, - z - ]; -} -function z() { - return [ - x, - y - ]; -} - -function a() { - return [ - a, - b, - c, - d - ]; -} -function b() { - return [ - a, - b, - c, - d - ]; -} -function c() { - return [ - a, - b, - c, - d - ]; -} -function d() { - return [ - a, - b, - c, - d - ]; -} - -function f1() { - return [ - f2, - f4 - ]; -} -function f2() { - return [ - f1, - f3 - ]; -} -function f3() { - return [ - f2, - f4 - ]; -} -function f4() { - return [ - f1, - f3 - ]; -} - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/output.snap.txt deleted file mode 100644 index 698d36d9ee6e..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/output.snap.txt +++ /dev/null @@ -1,40 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -it("should be able to load package without side effects where modules are unused", ()=>{ - __webpack_require__("./module.js"); -}); -}), -"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - test: function() { return test; } -}); -/* harmony import */var _package__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/index.js"); - -/* harmony default export */ __webpack_exports__["default"] = (_package__WEBPACK_IMPORTED_MODULE_0__.a); -function test() {} -}), -"./package/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); - -function a() { - return 42; -} -function b() { - return /* "./unusedModule" unused */null; -} -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/output.snap.txt deleted file mode 100644 index 00d7e09b6d4d..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/output.snap.txt +++ /dev/null @@ -1,50 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./import-module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./module.js"); - -expect(_module__WEBPACK_IMPORTED_MODULE_0__.ok).toBe(true); -expect(_module__WEBPACK_IMPORTED_MODULE_0__.ok2).toBe(true); -}), -"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -it("should not threat globals as pure", ()=>{ - __webpack_require__("./import-module.js"); -}); -}), -"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - ok: function() { return ok; }, - ok2: function() { return ok2; } -}); -try { - var x = NOT_DEFINED; - var y = x; - var ok = false; -} catch (e) { - var yep = true; - var ok = yep; -} -try { - const b = a; - var c = b; - const a = 42; - var ok2 = false; - eval(""); -} // TODO terser has a bug and incorrectly remove this code, eval opts out -catch (e) { - var ok2 = true; -} - -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/output.snap.txt deleted file mode 100644 index d2ee8c9f5473..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/output.snap.txt +++ /dev/null @@ -1,96 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package1/script.js"); -/* harmony import */var _package1_script2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./package1/script2.js"); -/* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./package2/script.js"); - - - -it("should load module correctly", ()=>{ - __webpack_require__("./module.js"); -}); -// if (process.env.NODE_ENV === "production") { -it("default export should be unused", ()=>{ - expect(_package1_script__WEBPACK_IMPORTED_MODULE_0__.exportDefaultUsed).toBe(false); - expect(_package1_script2__WEBPACK_IMPORTED_MODULE_1__.exportDefaultUsed).toBe(false); -}); -// } -it("default export should be used", ()=>{ - expect(_package2_script__WEBPACK_IMPORTED_MODULE_2__.exportDefaultUsed).toBe(true); -}); -}), -"./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - mod: function() { return mod; } -}); -/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package1/script.js"); -/* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./package2/script.js"); - - -const mod = _package2_script__WEBPACK_IMPORTED_MODULE_1__["default"]; -}), -"./package1/script.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - exportDefaultUsed: function() { return exportDefaultUsed; } -}); -/* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package1/script1.js"); -__webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (/* "./script1" unused */null); - -const exportDefaultUsed = false; -}), -"./package1/script1.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _script2__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package1/script2.js"); -__webpack_require__.es(_script2__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -/* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (1); -}), -"./package1/script2.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - exportDefaultUsed: function() { return exportDefaultUsed; } -}); - -/* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { - return /* "./script3" unused */null; -} - -const exportDefaultUsed = false; -}), -"./package2/script.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - exportDefaultUsed: function() { return exportDefaultUsed; } -}); -/* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package2/script1.js"); -__webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -/* harmony default export */ __webpack_exports__["default"] = (_script1__WEBPACK_IMPORTED_MODULE_0__["default"]); - -const exportDefaultUsed = true; -}), -"./package2/script1.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony default export */ __webpack_exports__["default"] = (1); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/output.snap.txt deleted file mode 100644 index 3560e7a25a7d..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/output.snap.txt +++ /dev/null @@ -1,104 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"../node_modules/pmodule/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -var a = "a"; -var b = "b"; -var c = "c"; - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("a.js"); -}), -"../node_modules/pmodule/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return x; }, - z: function() { return _c__WEBPACK_IMPORTED_MODULE_0__.z; } -}); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/c.js"); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -var x = "x"; -var y = "y"; - - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_1__.track)("b.js"); -}), -"../node_modules/pmodule/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - z: function() { return z; } -}); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -var z = "z"; - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("c.js"); -}), -"../node_modules/pmodule/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.x; }, - z: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.z; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/a.js"); -__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/b.js"); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/tracker.js"); - - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_2__.track)("index.js"); -/* harmony default export */ __webpack_exports__["default"] = ("def"); -}), -"../node_modules/pmodule/tracker.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - log: function() { return log; }, - track: function() { return track; } -}); -function track(file) { - log.push(file); - log.sort(); -} -var log = []; -function reset() { - log.length = 0; -} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/index.js"); - - - -pmodule__WEBPACK_IMPORTED_MODULE_1__["default"].should.be.eql("def"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.a.should.be.eql("a"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.x.should.be.eql("x"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.z.should.be.eql("z"); -pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__.log.should.be.eql([ - "a.js", - "b.js", - "c.js", - "index.js" -]); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/output.snap.txt deleted file mode 100644 index d588e5b63923..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/output.snap.txt +++ /dev/null @@ -1,86 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"../node_modules/pmodule/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return x; }, - z: function() { return _c__WEBPACK_IMPORTED_MODULE_0__.z; } -}); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/c.js"); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -var x = "x"; -var y = "y"; - - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_1__.track)("b.js"); -}), -"../node_modules/pmodule/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - z: function() { return z; } -}); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -var z = "z"; - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("c.js"); -}), -"../node_modules/pmodule/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - x: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.x; }, - z: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.z; } -}); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/b.js"); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/tracker.js"); - - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_2__.track)("index.js"); -/* harmony default export */ __webpack_exports__["default"] = ("def"); -}), -"../node_modules/pmodule/tracker.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - log: function() { return log; }, - track: function() { return track; } -}); -function track(file) { - log.push(file); - log.sort(); -} -var log = []; -function reset() { - log.length = 0; -} -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../node_modules/pmodule/tracker.js"); -/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/index.js"); - - - -pmodule__WEBPACK_IMPORTED_MODULE_1__["default"].should.be.eql("def"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.x.should.be.eql("x"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.z.should.be.eql("z"); -pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__.log.should.be.eql([ - "b.js", - "c.js", - "index.js" -]); -}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/test.config.js deleted file mode 100644 index 8757218ddc00..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/test.config.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - optimization: { - sideEffects: true - }, - builtins: { - treeShaking: true, - define: { - "process.env.NODE_ENV": "'development'" - } - } -}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/webpack.config.js b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/webpack.config.js new file mode 100644 index 000000000000..a375a3cb6a91 --- /dev/null +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + optimization: { + sideEffects: true + }, + builtins: { + define: { + "process.env.NODE_ENV": "'development'" + } + } +}; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/output.snap.txt deleted file mode 100644 index 4a59df8fe2aa..000000000000 --- a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/output.snap.txt +++ /dev/null @@ -1,31 +0,0 @@ -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return a; } -}); -const a = 3; -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _a_svg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./a.svg"); - - -_a_js__WEBPACK_IMPORTED_MODULE_0__.a; -_a_svg__WEBPACK_IMPORTED_MODULE_1__; -}), -"./a.svg": (function (module) { -"use strict"; -module.exports = "data:image/svg+xml;base64,";}), - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/new_treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/new_treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/test.config.js b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/webpack.config.js similarity index 91% rename from packages/rspack-test-tools/tests/treeShakingCases/with-assets/test.config.js rename to packages/rspack-test-tools/tests/treeShakingCases/with-assets/webpack.config.js index ba1bd06a61ff..0a59503585e9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/test.config.js +++ b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/webpack.config.js @@ -11,7 +11,6 @@ module.exports = { ] }, builtins: { - treeShaking: true, define: { "process.env.NODE_ENV": "'development'" } From 3d1adf7fc8b3477f092cc19a9cea6974935a4f2c Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Wed, 15 May 2024 14:26:02 +0800 Subject: [PATCH 088/107] docs: improve plugins docs (#6545) * docs: improve NormalModuleReplacementPlugin docs * docs: improve ModuleFederationPlugin docs * docs: improve SplitChunksPlugin docs * docs: improve SourceMapDevToolPlugin * doc: fix en in zh doc * docs: improve ProgressPlugin doc * doc: improve IgnorePlugin doc * doc: improve BannerPlugin * fix --- .../rspack/css-extract-rspack-plugin.mdx | 2 - .../docs/en/plugins/webpack/banner-plugin.mdx | 168 +++++++------- .../docs/en/plugins/webpack/ignore-plugin.mdx | 2 +- .../webpack/module-federation-plugin.mdx | 209 ++++++++++-------- .../normal-module-replacement-plugin.mdx | 8 +- .../en/plugins/webpack/progress-plugin.mdx | 42 +--- .../webpack/source-map-dev-tool-plugin.mdx | 102 +++++++-- .../plugins/webpack/split-chunks-plugin.mdx | 10 +- .../rspack/css-extract-rspack-plugin.mdx | 2 - .../docs/zh/plugins/webpack/banner-plugin.mdx | 166 +++++++------- .../docs/zh/plugins/webpack/ignore-plugin.mdx | 2 +- .../webpack/module-federation-plugin.mdx | 209 ++++++++++-------- .../normal-module-replacement-plugin.mdx | 8 +- .../zh/plugins/webpack/progress-plugin.mdx | 42 +--- .../webpack/source-map-dev-tool-plugin.mdx | 100 +++++++-- .../plugins/webpack/split-chunks-plugin.mdx | 10 +- 16 files changed, 617 insertions(+), 465 deletions(-) diff --git a/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx b/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx index d1fdcca4b75d..e2a54fef4c6f 100644 --- a/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx +++ b/website/docs/en/plugins/rspack/css-extract-rspack-plugin.mdx @@ -34,8 +34,6 @@ If your project does not depend on css-loader, it is recommended to use the buil Plugin Configuration - {' '} -
; - type BannerPluginOptions = { - banner: BannerContent; - entryOnly?: boolean; - footer?: boolean; - raw?: boolean; - test?: BannerRules; - include?: BannerRules; - exclude?: BannerRules; - }; - export type BannerPluginArgument = BannerContent | BannerPluginOptions; - ``` +```ts +type BannerContent = string; +type BannerRules = string | RegExp | Array; +type BannerPluginOptions = { + banner: BannerContent; + entryOnly?: boolean; + footer?: boolean; + raw?: boolean; + test?: BannerRules; + include?: BannerRules; + exclude?: BannerRules; +}; +type BannerPluginArgument = BannerContent | BannerPluginOptions; +``` - - **Default:** `undefined` +- **Default:** `undefined` - {' '} +
-
+## Examples -Add a banner to the top or bottom of each chunk file. +Add a banner to the bottom of each chunk file. ```ts title="rspack.config.js" module.exports = { diff --git a/website/docs/en/plugins/webpack/ignore-plugin.mdx b/website/docs/en/plugins/webpack/ignore-plugin.mdx index 9eccf7b91284..d7d903476cc0 100644 --- a/website/docs/en/plugins/webpack/ignore-plugin.mdx +++ b/website/docs/en/plugins/webpack/ignore-plugin.mdx @@ -4,7 +4,7 @@ import { ApiMeta } from '@components/ApiMeta.tsx'; -This plugin will prevent the generation of modules for import or require calls matching the regular expressions. +This plugin will prevent the generation of modules for `import` or `require` calls matching the regular expressions. ```js new rspack.IgnorePlugin(options); diff --git a/website/docs/en/plugins/webpack/module-federation-plugin.mdx b/website/docs/en/plugins/webpack/module-federation-plugin.mdx index 00b876a81d93..37f5772fc949 100644 --- a/website/docs/en/plugins/webpack/module-federation-plugin.mdx +++ b/website/docs/en/plugins/webpack/module-federation-plugin.mdx @@ -6,91 +6,124 @@ import { ApiMeta, Stability } from '@components/ApiMeta.tsx'; This plugin implements [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced). -- implementation - - Type: `string` - - Usage: Provide a path as the implementation for Module Federation 1.5 runtime, which defaults to [@module-federation/runtime-tools](https://github.com/module-federation/universe/tree/main/packages/runtime-tools). -- runtimePlugins - - Type: `string[]` - - Usage: Provide the plugin required to run Module Federation 1.5, which can extend the behavior and capabilities of Module Federation. -- name - - Type: `string` - - Usage: Define the unique name exposed to other containers in the current build. This name will exist as a global variable for the remote container. -- filename - - Type: `string` - - Usage: Specify the filename of the remote container entry file. Other containers will load the exposed modules through this file. -- runtime - - Type: `string | false` - - Usage: Define the runtime chunk for remote container entry. -- library - - Type: [`LibraryOptions`](/config/output#outputlibrary) - - Usage: Define the output format of remote container entry. The default libraryType is "var". -- shareScope - - Type: `string` - - Usage: Define the namespace for shared dependencies in the current container. By configuring share scopes between different containers, the sharing behavior of modules can be controlled, including determining which modules are shared between different containers. The default share scope is `"default"`. -- remoteType - - Type: [`ExternalsType`](/config/externals#externalstype) - - Usage: Defines how to load remote containers, defaulting to `"script"`, which loads via the ` + + + + diff --git a/packages/create-rspack/template-vue-ts/src/assets/rspack.svg b/packages/create-rspack/template-vue-ts/src/assets/rspack.svg new file mode 100644 index 000000000000..00788a954370 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/src/assets/rspack.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/create-rspack/template-vue-ts/src/assets/vue.svg b/packages/create-rspack/template-vue-ts/src/assets/vue.svg new file mode 100644 index 000000000000..770e9d333ee7 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/src/assets/vue.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/create-rspack/template-vue-ts/src/components/HelloWorld.vue b/packages/create-rspack/template-vue-ts/src/components/HelloWorld.vue new file mode 100644 index 000000000000..ef002e511151 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/src/components/HelloWorld.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/packages/create-rspack/template-vue-ts/src/main.ts b/packages/create-rspack/template-vue-ts/src/main.ts new file mode 100644 index 000000000000..dc42bbf15d19 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/src/main.ts @@ -0,0 +1,7 @@ +import "./style.css"; + +import { createApp } from "vue"; + +import App from "./App.vue"; + +createApp(App).mount("#app"); diff --git a/packages/create-rspack/template-vue-ts/src/shims-vue.d.ts b/packages/create-rspack/template-vue-ts/src/shims-vue.d.ts new file mode 100644 index 000000000000..201809da0917 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/src/shims-vue.d.ts @@ -0,0 +1,6 @@ +declare module "*.vue" { + import { DefineComponent } from "vue"; + // biome-ignore lint/complexity/noBannedTypes: reason + const component: DefineComponent<{}, {}, any>; + export default component; +} diff --git a/packages/create-rspack/template-vue-ts/src/style.css b/packages/create-rspack/template-vue-ts/src/style.css new file mode 100644 index 000000000000..a566a347d0d5 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/src/style.css @@ -0,0 +1,90 @@ +:root { + font-family: Inter, Avenir, Helvetica, Arial, sans-serif; + font-size: 16px; + line-height: 24px; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + -webkit-text-size-adjust: 100%; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +.card { + padding: 2em; +} + +#app { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; + text-align: center; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/packages/create-rspack/template-vue-ts/tsconfig.json b/packages/create-rspack/template-vue-ts/tsconfig.json new file mode 100644 index 000000000000..da4bef77a8e2 --- /dev/null +++ b/packages/create-rspack/template-vue-ts/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "ES2020", + "lib": [ + "DOM", + "ES2020" + ], + "module": "CommonJS", + "jsx": "preserve", + "jsxImportSource": "vue", + "strict": true, + "skipLibCheck": true, + "isolatedModules": true, + "resolveJsonModule": true, + "useDefineForClassFields": true + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac70b9bbbd27..8b9c55a4ac67 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -367,6 +367,28 @@ importers: specifier: ^17.2.2 version: 17.4.2(vue@3.2.45)(webpack@5.90.1) + packages/create-rspack/template-vue-ts: + dependencies: + vue: + specifier: 3.4.21 + version: 3.4.21(typescript@5.4.2) + devDependencies: + '@rspack/cli': + specifier: workspace:* + version: link:../../rspack-cli + '@rspack/core': + specifier: workspace:* + version: link:../../rspack + ts-node: + specifier: ^10.9.2 + version: 10.9.2(@types/node@20.12.7)(typescript@5.4.2) + typescript: + specifier: ^5.3.3 + version: 5.4.2 + vue-loader: + specifier: ^17.2.2 + version: 17.4.2(vue@3.4.21)(webpack@5.90.1) + packages/playground: devDependencies: '@babel/core': @@ -537,13 +559,13 @@ importers: version: 3.0.0(webpack@5.90.1) postcss-loader: specifier: ^8.0.0 - version: 8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@4.9.5)(webpack@5.90.1) + version: 8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@5.4.2)(webpack@5.90.1) postcss-pxtorem: specifier: ^6.0.0 version: 6.1.0(postcss@8.4.38) prebundle: specifier: ^1.1.0 - version: 1.1.0(typescript@4.9.5) + version: 1.1.0(typescript@5.4.2) pug-loader: specifier: ^2.4.0 version: 2.4.0(pug@2.0.4) @@ -6379,7 +6401,6 @@ packages: entities: 4.5.0 estree-walker: 2.0.2 source-map-js: 1.2.0 - dev: true /@vue/compiler-dom@3.2.45: resolution: {integrity: sha512-tyYeUEuKqqZO137WrZkpwfPCdiiIeXYCcJ8L4gWz9vqaxzIQRccTSwSWZ/Axx5YR2z+LvpUbmPNXxuBU45lyRw==} @@ -6392,7 +6413,6 @@ packages: dependencies: '@vue/compiler-core': 3.4.21 '@vue/shared': 3.4.21 - dev: true /@vue/compiler-sfc@3.2.45: resolution: {integrity: sha512-1jXDuWah1ggsnSAOGsec8cFjT/K6TMZ0sPL3o3d84Ft2AYZi2jWJgRMjw4iaK0rBfA89L5gw427H4n1RZQBu6Q==} @@ -6420,7 +6440,6 @@ packages: magic-string: 0.30.9 postcss: 8.4.38 source-map-js: 1.2.0 - dev: true /@vue/compiler-ssr@3.2.45: resolution: {integrity: sha512-6BRaggEGqhWht3lt24CrIbQSRD5O07MTmd+LjAn5fJj568+R9eUD2F7wMQJjX859seSlrYog7sUtrZSd7feqrQ==} @@ -6433,7 +6452,6 @@ packages: dependencies: '@vue/compiler-dom': 3.4.21 '@vue/shared': 3.4.21 - dev: true /@vue/reactivity-transform@3.2.45: resolution: {integrity: sha512-BHVmzYAvM7vcU5WmuYqXpwaBHjsS8T63jlKGWVtHxAHIoMIlmaMyurUSEs1Zcg46M4AYT5MtB1U274/2aNzjJQ==} @@ -6453,7 +6471,6 @@ packages: resolution: {integrity: sha512-UhenImdc0L0/4ahGCyEzc/pZNwVgcglGy9HVzJ1Bq2Mm9qXOpP8RyNTjookw/gOCUlXSEtuZ2fUg5nrHcoqJcw==} dependencies: '@vue/shared': 3.4.21 - dev: true /@vue/runtime-core@3.2.45: resolution: {integrity: sha512-gzJiTA3f74cgARptqzYswmoQx0fIA+gGYBfokYVhF8YSXjWTUA2SngRzZRku2HbGbjzB6LBYSbKGIaK8IW+s0A==} @@ -6466,7 +6483,6 @@ packages: dependencies: '@vue/reactivity': 3.4.21 '@vue/shared': 3.4.21 - dev: true /@vue/runtime-dom@3.2.45: resolution: {integrity: sha512-cy88YpfP5Ue2bDBbj75Cb4bIEZUMM/mAkDMfqDTpUYVgTf/kuQ2VQ8LebuZ8k6EudgH8pYhsGWHlY0lcxlvTwA==} @@ -6481,7 +6497,6 @@ packages: '@vue/runtime-core': 3.4.21 '@vue/shared': 3.4.21 csstype: 3.1.3 - dev: true /@vue/server-renderer@3.2.45(vue@3.2.45): resolution: {integrity: sha512-ebiMq7q24WBU1D6uhPK//2OTR1iRIyxjF5iVq/1a5I1SDMDyDu4Ts6fJaMnjrvD3MqnaiFkKQj+LKAgz5WIK3g==} @@ -6499,15 +6514,13 @@ packages: dependencies: '@vue/compiler-ssr': 3.4.21 '@vue/shared': 3.4.21 - vue: 3.4.21(typescript@5.0.2) - dev: true + vue: 3.4.21(typescript@5.4.2) /@vue/shared@3.2.45: resolution: {integrity: sha512-Ewzq5Yhimg7pSztDV+RH1UDKBzmtqieXQlpTVm2AwraoRL/Rks96mvd8Vgi7Lj+h+TH8dv7mXD3FRZR3TUvbSg==} /@vue/shared@3.4.21: resolution: {integrity: sha512-PuJe7vDIi6VYSinuEbUIQgMIRZGgM8e4R+G+/dQTk0X1NEdvgvvgv7m+rfmDH1gZzyA1OjjoWskvHlfRNfQf3g==} - dev: true /@webassemblyjs/ast@1.12.1: resolution: {integrity: sha512-EKfMUOPRRUTy5UII4qJDGPpqfwjOmZ5jeGFwid9mnoqIFK+e0vqoi1qH56JpmZSzEL53jKnNzScdmftJyG5xWg==} @@ -8312,7 +8325,7 @@ packages: typescript: 5.0.2 dev: true - /cosmiconfig@9.0.0(typescript@4.9.5): + /cosmiconfig@9.0.0(typescript@5.0.2): resolution: {integrity: sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==} engines: {node: '>=14'} peerDependencies: @@ -8325,10 +8338,10 @@ packages: import-fresh: 3.3.0 js-yaml: 4.1.0 parse-json: 5.2.0 - typescript: 4.9.5 + typescript: 5.0.2 dev: true - /cosmiconfig@9.0.0(typescript@5.0.2): + /cosmiconfig@9.0.0(typescript@5.4.2): resolution: {integrity: sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==} engines: {node: '>=14'} peerDependencies: @@ -8341,7 +8354,7 @@ packages: import-fresh: 3.3.0 js-yaml: 4.1.0 parse-json: 5.2.0 - typescript: 5.0.2 + typescript: 5.4.2 dev: true /create-ecdh@4.0.4: @@ -9253,7 +9266,6 @@ packages: /entities@4.5.0: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} - dev: true /env-paths@2.2.1: resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==} @@ -12354,7 +12366,6 @@ packages: engines: {node: '>=12'} dependencies: '@jridgewell/sourcemap-codec': 1.4.15 - dev: true /make-dir@2.1.0: resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==} @@ -13521,7 +13532,7 @@ packages: - typescript dev: true - /postcss-loader@8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@4.9.5)(webpack@5.90.1): + /postcss-loader@8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@5.0.2)(webpack@5.90.1): resolution: {integrity: sha512-0IeqyAsG6tYiDRCYKQJLAmgQr47DX6N7sFSWvQxt6AcupX8DIdmykuk/o/tx0Lze3ErGHJEp5OSRxrelC6+NdQ==} engines: {node: '>= 18.12.0'} peerDependencies: @@ -13535,16 +13546,16 @@ packages: optional: true dependencies: '@rspack/core': link:packages/rspack - cosmiconfig: 9.0.0(typescript@4.9.5) + cosmiconfig: 9.0.0(typescript@5.0.2) jiti: 1.21.0 postcss: 8.4.38 semver: 7.6.0 - webpack: 5.90.1(webpack-cli@4.10.0) + webpack: 5.90.1(@swc/core@1.4.0)(webpack-cli@4.10.0) transitivePeerDependencies: - typescript dev: true - /postcss-loader@8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@5.0.2)(webpack@5.90.1): + /postcss-loader@8.1.1(@rspack/core@packages+rspack)(postcss@8.4.38)(typescript@5.4.2)(webpack@5.90.1): resolution: {integrity: sha512-0IeqyAsG6tYiDRCYKQJLAmgQr47DX6N7sFSWvQxt6AcupX8DIdmykuk/o/tx0Lze3ErGHJEp5OSRxrelC6+NdQ==} engines: {node: '>= 18.12.0'} peerDependencies: @@ -13558,11 +13569,11 @@ packages: optional: true dependencies: '@rspack/core': link:packages/rspack - cosmiconfig: 9.0.0(typescript@5.0.2) + cosmiconfig: 9.0.0(typescript@5.4.2) jiti: 1.21.0 postcss: 8.4.38 semver: 7.6.0 - webpack: 5.90.1(@swc/core@1.4.0)(webpack-cli@4.10.0) + webpack: 5.90.1(webpack-cli@4.10.0) transitivePeerDependencies: - typescript dev: true @@ -13655,13 +13666,13 @@ packages: picocolors: 1.0.0 source-map-js: 1.2.0 - /prebundle@1.1.0(typescript@4.9.5): + /prebundle@1.1.0(typescript@5.4.2): resolution: {integrity: sha512-yTfRjx0+xiveeb7kO77OcODVB8RSHMKIiVl/qferU7ZHw4Y8pycXkCAtPDViF8YDo0a8ViDpm4C1O9PFKCw1ig==} hasBin: true dependencies: '@vercel/ncc': 0.38.1 rollup: 4.17.2 - rollup-plugin-dts: 6.1.0(rollup@4.17.2)(typescript@4.9.5) + rollup-plugin-dts: 6.1.0(rollup@4.17.2)(typescript@5.4.2) transitivePeerDependencies: - typescript dev: true @@ -14706,7 +14717,7 @@ packages: resolution: {integrity: sha512-IXgzBWvWQwE6PrDI05OvmXUIruQTcoMDzRsOd5CDvHCVLcLHMTSYvOK5Cm46kWqlV3yAbuSpBZdJ5oP5OUoStg==} dev: false - /rollup-plugin-dts@6.1.0(rollup@4.17.2)(typescript@4.9.5): + /rollup-plugin-dts@6.1.0(rollup@4.17.2)(typescript@5.4.2): resolution: {integrity: sha512-ijSCPICkRMDKDLBK9torss07+8dl9UpY9z1N/zTeA1cIqdzMlpkV3MOOC7zukyvQfDyxa1s3Dl2+DeiP/G6DOw==} engines: {node: '>=16'} peerDependencies: @@ -14715,7 +14726,7 @@ packages: dependencies: magic-string: 0.30.9 rollup: 4.17.2 - typescript: 4.9.5 + typescript: 5.4.2 optionalDependencies: '@babel/code-frame': 7.24.2 dev: true @@ -16173,6 +16184,37 @@ packages: yn: 3.1.1 dev: true + /ts-node@10.9.2(@types/node@20.12.7)(typescript@5.4.2): + resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} + hasBin: true + peerDependencies: + '@swc/core': '>=1.2.50' + '@swc/wasm': '>=1.2.50' + '@types/node': '*' + typescript: '>=2.7' + peerDependenciesMeta: + '@swc/core': + optional: true + '@swc/wasm': + optional: true + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.11 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 20.12.7 + acorn: 8.11.3 + acorn-walk: 8.3.2 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.4.2 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + dev: true + /tsc-alias@1.8.8: resolution: {integrity: sha512-OYUOd2wl0H858NvABWr/BoSKNERw3N9GTi3rHPK8Iv4O1UyUXIrTTOAZNHsjlVpXFOhpJBVARI1s+rzwLivN3Q==} hasBin: true @@ -16325,7 +16367,6 @@ packages: resolution: {integrity: sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==} engines: {node: '>=14.17'} hasBin: true - dev: true /ua-parser-js@1.0.37: resolution: {integrity: sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ==} @@ -16689,7 +16730,7 @@ packages: dependencies: chalk: 4.1.2 hash-sum: 2.0.0 - vue: 3.4.21(typescript@5.0.2) + vue: 3.4.21(typescript@5.4.2) watchpack: 2.4.1 webpack: 5.90.1(webpack-cli@4.10.0) dev: true @@ -16719,6 +16760,21 @@ packages: typescript: 5.0.2 dev: true + /vue@3.4.21(typescript@5.4.2): + resolution: {integrity: sha512-5hjyV/jLEIKD/jYl4cavMcnzKwjMKohureP8ejn3hhEjwhWIhWeuzL2kJAjzl/WyVsgPY56Sy4Z40C3lVshxXA==} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@vue/compiler-dom': 3.4.21 + '@vue/compiler-sfc': 3.4.21 + '@vue/runtime-dom': 3.4.21 + '@vue/server-renderer': 3.4.21(vue@3.4.21) + '@vue/shared': 3.4.21 + typescript: 5.4.2 + /w3c-xmlserializer@4.0.0: resolution: {integrity: sha512-d+BFHzbiCx6zGfz0HyQ6Rg69w9k19nviJspaj4yNscGjrHu94sVP+aRm75yEbCh+r2/yR+7q6hux9LVtbuTGBw==} engines: {node: '>=14'} From 9572d63b4981fa514ea6b96802074f98da554e51 Mon Sep 17 00:00:00 2001 From: quininer Date: Thu, 16 May 2024 12:50:14 +0800 Subject: [PATCH 096/107] perf: improve determine_export_assignments (#6431) * perf: improve determine_export_assignments * Use .chain instead of .clone + .push * eliminate Atom drop by avoiding redundant Atom clone * Remove IndexSet and insert directly into Vec. * perf: improve determine_export_assignments (2) * eliminate Atom clone * rewrite collect hidden_exports * Fix clippy * Fix fmt * perf: improve determine_export_assignments (3) * Use indexmap again * Use usize::from --- ...ny_export_imported_specifier_dependency.rs | 62 +++++++++---------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs index 53e96934fafe..6b243914c3e2 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs @@ -309,14 +309,13 @@ impl HarmonyExportImportedSpecifierDependency { let hidden_exports = self .discover_active_exports_from_other_star_exports(module_graph) .map(|other_star_exports| { - let mut hide_exports = HashSet::default(); - for i in 0..other_star_exports.names_slice { - hide_exports.insert(other_star_exports.names[i].clone()); - } - for e in ignored_exports.iter() { - hide_exports.remove(e); - } - hide_exports + other_star_exports + .names + .into_iter() + .take(other_star_exports.names_slice) + .filter(|name| !ignored_exports.contains(name)) + .cloned() + .collect::>() }); if !no_extra_exports && !no_extra_imports { return StarReexportsInfo { @@ -419,10 +418,10 @@ impl HarmonyExportImportedSpecifierDependency { } } - pub fn discover_active_exports_from_other_star_exports( + pub fn discover_active_exports_from_other_star_exports<'a>( &self, - module_graph: &ModuleGraph, - ) -> Option { + module_graph: &'a ModuleGraph, + ) -> Option> { if let Some(other_star_exports) = &self.other_star_exports { if other_star_exports.is_empty() { return None; @@ -435,7 +434,7 @@ impl HarmonyExportImportedSpecifierDependency { let all_star_exports = self.all_star_exports(module_graph); if !all_star_exports.is_empty() { let (names, dependency_indices) = - determine_export_assignments(module_graph, all_star_exports.clone(), None); + determine_export_assignments(module_graph, all_star_exports, None); return Some(DiscoverActiveExportsFromOtherStarExportsRet { names, @@ -447,7 +446,7 @@ impl HarmonyExportImportedSpecifierDependency { if let Some(other_star_exports) = &self.other_star_exports { let (names, dependency_indices) = - determine_export_assignments(module_graph, other_star_exports.clone(), Some(self.id)); + determine_export_assignments(module_graph, other_star_exports, Some(self.id)); return Some(DiscoverActiveExportsFromOtherStarExportsRet { names, names_slice: dependency_indices[i - 1], @@ -829,8 +828,8 @@ impl HarmonyExportImportedSpecifierDependency { } #[derive(Debug)] -pub struct DiscoverActiveExportsFromOtherStarExportsRet { - names: Vec, +pub struct DiscoverActiveExportsFromOtherStarExportsRet<'a> { + names: Vec<&'a Atom>, names_slice: usize, pub dependency_indices: Vec, pub dependency_index: usize, @@ -1350,39 +1349,34 @@ pub struct StarReexportsInfo { } /// return (names, dependency_indices) -fn determine_export_assignments( - module_graph: &ModuleGraph, - mut dependencies: Vec, +fn determine_export_assignments<'a>( + module_graph: &'a ModuleGraph, + dependencies: &[DependencyId], additional_dependency: Option, -) -> (Vec, Vec) { - if let Some(additional_dependency) = additional_dependency { - dependencies.push(additional_dependency); - } - +) -> (Vec<&'a Atom>, Vec) { // https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/dependencies/HarmonyExportImportedSpecifierDependency.js#L109 // js `Set` keep the insertion order, use `IndexSet` to align there behavior - let mut names: IndexSet> = IndexSet::default(); - let mut dependency_indices = vec![]; + let mut names: IndexSet<&Atom, BuildHasherDefault> = IndexSet::default(); + let mut dependency_indices = + Vec::with_capacity(dependencies.len() + usize::from(additional_dependency.is_some())); - for dependency in dependencies.iter() { - dependency_indices.push(names.len()); + for dependency in dependencies.iter().chain(additional_dependency.iter()) { if let Some(module_identifier) = module_graph.module_identifier_by_dependency_id(dependency) { let exports_info = module_graph.get_exports_info(module_identifier); for export_info_id in exports_info.exports.values() { let export_info = module_graph.get_export_info_by_id(export_info_id); // SAFETY: This is safe because a real export can't export empty string - let export_info_name = export_info.name.clone().unwrap_or_default(); + let export_info_name = export_info.name.as_ref().expect("export name is empty"); if matches!(export_info.provided, Some(ExportInfoProvided::True)) - && &export_info_name != "default" - && !names.contains(&export_info_name) + && export_info_name != "default" + && !names.contains(export_info_name) { - names.insert(export_info_name.clone()); - let cur_len = dependency_indices.len(); - dependency_indices[cur_len - 1] = names.len(); + names.insert(export_info_name); } } } + dependency_indices.push(names.len()); } - (names.into_iter().collect::>(), dependency_indices) + (names.into_iter().collect(), dependency_indices) } From 27042bb42e3a6f8c2dd6b9b43c984715efeff433 Mon Sep 17 00:00:00 2001 From: gaoyuan <9aoyuao@gmail.com> Date: Thu, 16 May 2024 15:07:02 +0800 Subject: [PATCH 097/107] ci: support release beta version (#6558) CI: support release beta version --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bf769e9a8836..510e0384528b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,6 +12,7 @@ on: - canary - nightly - latest + - beta dry_run: type: boolean description: "DryRun release" From ea6507ee9bf9c28806ff8c367dcc0a7373a5af6b Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Thu, 16 May 2024 16:54:33 +0800 Subject: [PATCH 098/107] test: move normal case with rspack.config.js (#6561) * test: move normal case with rspack.config.js * test: move normal case with rspack.config.js --- .../{normalCases => configCases}/chunks/_import/index.js | 0 .../chunks/_import/rspack.config.js | 0 .../tests/{normalCases => configCases}/chunks/_import/two.js | 0 .../cjs-tree-shaking/cjs-interop/a.js | 0 .../cjs-tree-shaking/cjs-interop/b.js | 0 .../cjs-tree-shaking/cjs-interop/index.js | 0 .../cjs-tree-shaking/cjs-interop/package.json | 0 .../cjs-tree-shaking/cjs-interop/rspack.config.js | 0 .../cjs-tree-shaking/export-require-bailout/index.js | 0 .../cjs-tree-shaking/export-require-bailout/package.json | 0 .../cjs-tree-shaking/export-require-bailout/reexport.js | 0 .../cjs-tree-shaking/export-require-bailout/rspack.config.js | 0 .../cjs-tree-shaking/export-require-bailout/value.js | 0 .../child/child/index.js | 0 .../child/index.js | 0 .../context-module-cjs-require-binary-expression/index.js | 0 .../rspack.config.js | 0 .../resolve/axios-0.27.2/index.js | 0 .../resolve/axios-0.27.2/node_modules/axios-demo/index.js | 0 .../axios-0.27.2/node_modules/axios-demo/lib/adapters/http.js | 0 .../axios-0.27.2/node_modules/axios-demo/lib/adapters/xhr.js | 0 .../resolve/axios-0.27.2/node_modules/axios-demo/lib/axios.js | 0 .../node_modules/axios-demo/lib/defaults/index.js | 0 .../resolve/axios-0.27.2/node_modules/axios-demo/package.json | 0 .../resolve/axios-0.27.2}/rspack.config.js | 4 +++- .../resolve/browser-field/index.js | 0 .../browser-field/node_modules/ignoring-module/file.js | 0 .../browser-field/node_modules/ignoring-module/index.js | 0 .../browser-field/node_modules/ignoring-module/package.json | 0 .../resolve/browser-field/node_modules/new-module/index.js | 0 .../resolve/browser-field/node_modules/new-module/inner.js | 0 .../resolve/browser-field/node_modules/recursive-file/a.js | 0 .../resolve/browser-field/node_modules/recursive-file/b.js | 0 .../resolve/browser-field/node_modules/recursive-file/c.js | 0 .../resolve/browser-field/node_modules/recursive-file/d.js | 0 .../browser-field/node_modules/recursive-file/package.json | 0 .../browser-field/node_modules/recursive-module/index.js | 0 .../browser-field/node_modules/recursive-module/package.json | 0 .../browser-field/node_modules/replacing-file1/file.js | 0 .../browser-field/node_modules/replacing-file1/index.js | 0 .../browser-field/node_modules/replacing-file1/new-file.js | 0 .../browser-field/node_modules/replacing-file1/package.json | 0 .../browser-field/node_modules/replacing-file2/file.js | 0 .../browser-field/node_modules/replacing-file2/index.js | 0 .../browser-field/node_modules/replacing-file2/package.json | 0 .../browser-field/node_modules/replacing-file3/file.js | 0 .../browser-field/node_modules/replacing-file3/index.js | 0 .../browser-field/node_modules/replacing-file3/package.json | 0 .../browser-field/node_modules/replacing-file4/dir/file.js | 0 .../browser-field/node_modules/replacing-file4/dir/index.js | 0 .../node_modules/replacing-file4/dir/new-file.js | 0 .../browser-field/node_modules/replacing-file4/index.js | 0 .../browser-field/node_modules/replacing-file4/package.json | 0 .../browser-field/node_modules/replacing-module1/index.js | 0 .../browser-field/node_modules/replacing-module1/package.json | 0 .../browser-field/node_modules/replacing-module2/index.js | 0 .../browser-field/node_modules/replacing-module2/package.json | 0 .../browser-field/node_modules/replacing-module3/index.js | 0 .../browser-field/node_modules/replacing-module3/package.json | 0 .../browser-field/node_modules/replacing-module4/index.js | 0 .../browser-field/node_modules/replacing-module4/module.js | 0 .../browser-field/node_modules/replacing-module4/package.json | 0 .../resolve/browser-field/node_modules/wrong-module.js | 0 .../resolve/browser-field}/rspack.config.js | 0 64 files changed, 3 insertions(+), 1 deletion(-) rename packages/rspack-test-tools/tests/{normalCases => configCases}/chunks/_import/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/chunks/_import/rspack.config.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/chunks/_import/two.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/cjs-interop/a.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/cjs-interop/b.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/cjs-interop/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/cjs-interop/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/cjs-interop/rspack.config.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/export-require-bailout/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/export-require-bailout/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/export-require-bailout/reexport.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/export-require-bailout/rspack.config.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/cjs-tree-shaking/export-require-bailout/value.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/context/context-module-cjs-require-binary-expression/child/child/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/context/context-module-cjs-require-binary-expression/child/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/context/context-module-cjs-require-binary-expression/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/context/context-module-cjs-require-binary-expression/rspack.config.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/node_modules/axios-demo/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/http.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/xhr.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/node_modules/axios-demo/lib/axios.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/node_modules/axios-demo/lib/defaults/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/axios-0.27.2/node_modules/axios-demo/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases/resolve/browser-field => configCases/resolve/axios-0.27.2}/rspack.config.js (63%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/ignoring-module/file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/ignoring-module/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/ignoring-module/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/new-module/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/new-module/inner.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-file/a.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-file/b.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-file/c.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-file/d.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-file/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-module/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/recursive-module/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file1/file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file1/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file1/new-file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file1/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file2/file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file2/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file2/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file3/file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file3/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file3/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file4/dir/file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file4/dir/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file4/dir/new-file.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file4/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-file4/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module1/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module1/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module2/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module2/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module3/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module3/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module4/index.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module4/module.js (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/replacing-module4/package.json (100%) rename packages/rspack-test-tools/tests/{normalCases => configCases}/resolve/browser-field/node_modules/wrong-module.js (100%) rename packages/rspack-test-tools/tests/{normalCases/resolve/axios-0.27.2 => configCases/resolve/browser-field}/rspack.config.js (100%) diff --git a/packages/rspack-test-tools/tests/normalCases/chunks/_import/index.js b/packages/rspack-test-tools/tests/configCases/chunks/_import/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/chunks/_import/index.js rename to packages/rspack-test-tools/tests/configCases/chunks/_import/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/chunks/_import/rspack.config.js b/packages/rspack-test-tools/tests/configCases/chunks/_import/rspack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/chunks/_import/rspack.config.js rename to packages/rspack-test-tools/tests/configCases/chunks/_import/rspack.config.js diff --git a/packages/rspack-test-tools/tests/normalCases/chunks/_import/two.js b/packages/rspack-test-tools/tests/configCases/chunks/_import/two.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/chunks/_import/two.js rename to packages/rspack-test-tools/tests/configCases/chunks/_import/two.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/a.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/a.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/a.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/a.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/b.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/b.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/b.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/b.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/index.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/index.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/package.json b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/package.json rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/rspack.config.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/rspack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/cjs-interop/rspack.config.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/cjs-interop/rspack.config.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/index.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/index.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/package.json b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/package.json rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/reexport.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/reexport.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/reexport.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/reexport.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/rspack.config.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/rspack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/rspack.config.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/rspack.config.js diff --git a/packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/value.js b/packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/value.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/cjs-tree-shaking/export-require-bailout/value.js rename to packages/rspack-test-tools/tests/configCases/cjs-tree-shaking/export-require-bailout/value.js diff --git a/packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/child/child/index.js b/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/child/child/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/child/child/index.js rename to packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/child/child/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/child/index.js b/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/child/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/child/index.js rename to packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/child/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/index.js b/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/index.js rename to packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/rspack.config.js b/packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/rspack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/context/context-module-cjs-require-binary-expression/rspack.config.js rename to packages/rspack-test-tools/tests/configCases/context/context-module-cjs-require-binary-expression/rspack.config.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/index.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/index.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/http.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/http.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/http.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/http.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/xhr.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/xhr.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/xhr.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/adapters/xhr.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/axios.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/axios.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/axios.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/axios.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/defaults/index.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/defaults/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/defaults/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/lib/defaults/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/package.json b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/node_modules/axios-demo/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/node_modules/axios-demo/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/rspack.config.js b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/rspack.config.js similarity index 63% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/rspack.config.js rename to packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/rspack.config.js index c5b1ad9fdbbc..87f813bc6ca0 100644 --- a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/resolve/axios-0.27.2/rspack.config.js @@ -1,4 +1,6 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { - target: "web" + resolve: { + aliasFields: ["browser"] + } }; diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/ignoring-module/file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/ignoring-module/file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/ignoring-module/file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/ignoring-module/file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/ignoring-module/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/ignoring-module/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/ignoring-module/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/ignoring-module/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/ignoring-module/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/ignoring-module/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/ignoring-module/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/ignoring-module/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/new-module/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/new-module/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/new-module/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/new-module/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/new-module/inner.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/new-module/inner.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/new-module/inner.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/new-module/inner.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/a.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/a.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/a.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/a.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/b.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/b.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/b.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/b.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/c.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/c.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/c.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/c.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/d.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/d.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/d.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/d.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-file/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-file/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-module/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-module/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-module/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-module/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-module/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-module/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/recursive-module/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/recursive-module/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/new-file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/new-file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/new-file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/new-file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file1/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file1/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file2/file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file2/file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file2/file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file2/file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file2/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file2/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file2/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file2/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file2/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file2/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file2/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file2/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file3/file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file3/file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file3/file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file3/file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file3/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file3/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file3/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file3/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file3/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file3/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file3/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file3/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/dir/file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/dir/file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/dir/file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/dir/file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/dir/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/dir/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/dir/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/dir/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/dir/new-file.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/dir/new-file.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/dir/new-file.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/dir/new-file.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-file4/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-file4/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module1/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module1/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module1/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module1/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module1/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module1/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module1/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module1/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module2/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module2/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module2/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module2/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module2/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module2/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module2/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module2/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module3/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module3/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module3/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module3/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module3/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module3/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module3/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module3/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module4/index.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module4/index.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module4/index.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module4/index.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module4/module.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module4/module.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module4/module.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module4/module.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module4/package.json b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module4/package.json similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/replacing-module4/package.json rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/replacing-module4/package.json diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/wrong-module.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/wrong-module.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/browser-field/node_modules/wrong-module.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/node_modules/wrong-module.js diff --git a/packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/rspack.config.js b/packages/rspack-test-tools/tests/configCases/resolve/browser-field/rspack.config.js similarity index 100% rename from packages/rspack-test-tools/tests/normalCases/resolve/axios-0.27.2/rspack.config.js rename to packages/rspack-test-tools/tests/configCases/resolve/browser-field/rspack.config.js From 4709d0b69b7859d6975c95920194d54f130b1b51 Mon Sep 17 00:00:00 2001 From: gaoyuan <9aoyuao@gmail.com> Date: Thu, 16 May 2024 17:06:17 +0800 Subject: [PATCH 099/107] release: v0.7.0-beta.0 (#6559) chore: release 0.7.0-beta.0 --- crates/node_binding/package.json | 2 +- npm/darwin-arm64/package.json | 4 ++-- npm/darwin-x64/package.json | 4 ++-- npm/linux-x64-gnu/package.json | 4 ++-- npm/win32-x64-msvc/package.json | 2 +- package.json | 4 ++-- packages/create-rspack/package.json | 2 +- packages/rspack-cli/package.json | 2 +- packages/rspack-dev-server/package.json | 4 ++-- packages/rspack-plugin-minify/package.json | 2 +- packages/rspack-plugin-react-refresh/package.json | 2 +- packages/rspack-test-tools/package.json | 4 ++-- packages/rspack/package.json | 4 ++-- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/node_binding/package.json b/crates/node_binding/package.json index 78227e3566e0..93022ba30eab 100644 --- a/crates/node_binding/package.json +++ b/crates/node_binding/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Node binding for rspack", "main": "binding.js", diff --git a/npm/darwin-arm64/package.json b/npm/darwin-arm64/package.json index edc6a99d5dc4..f40a2a9ad235 100644 --- a/npm/darwin-arm64/package.json +++ b/npm/darwin-arm64/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-darwin-arm64", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.darwin-arm64.node", @@ -22,4 +22,4 @@ "cpu": [ "arm64" ] -} \ No newline at end of file +} diff --git a/npm/darwin-x64/package.json b/npm/darwin-x64/package.json index c582a09b2509..42f97086f353 100644 --- a/npm/darwin-x64/package.json +++ b/npm/darwin-x64/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-darwin-x64", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.darwin-x64.node", @@ -22,4 +22,4 @@ "cpu": [ "x64" ] -} \ No newline at end of file +} diff --git a/npm/linux-x64-gnu/package.json b/npm/linux-x64-gnu/package.json index 0b7c6c1fbaef..1a616595d655 100644 --- a/npm/linux-x64-gnu/package.json +++ b/npm/linux-x64-gnu/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-linux-x64-gnu", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.linux-x64-gnu.node", @@ -25,4 +25,4 @@ "libc": [ "glibc" ] -} \ No newline at end of file +} diff --git a/npm/win32-x64-msvc/package.json b/npm/win32-x64-msvc/package.json index a9c7bbf4aa55..859c12cd22c9 100644 --- a/npm/win32-x64-msvc/package.json +++ b/npm/win32-x64-msvc/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/binding-win32-x64-msvc", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Node binding for rspack", "main": "rspack.win32-x64-msvc.node", diff --git a/package.json b/package.json index ac70a630b9ad..b8bd3d9c5446 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monorepo", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "A Fast Rust-based web bundler", "private": true, @@ -82,4 +82,4 @@ "why-is-node-running": "2.2.2" }, "packageManager": "pnpm@8.14.3" -} \ No newline at end of file +} diff --git a/packages/create-rspack/package.json b/packages/create-rspack/package.json index 87d14d840fb6..f36e04c518bc 100644 --- a/packages/create-rspack/package.json +++ b/packages/create-rspack/package.json @@ -1,6 +1,6 @@ { "name": "create-rspack", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "main": "index.js", "bin": { diff --git a/packages/rspack-cli/package.json b/packages/rspack-cli/package.json index e529cee981cf..166398dff03a 100644 --- a/packages/rspack-cli/package.json +++ b/packages/rspack-cli/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/cli", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "CLI for rspack", "bin": { diff --git a/packages/rspack-dev-server/package.json b/packages/rspack-dev-server/package.json index f3e24739ef10..1e84d00c6a8b 100644 --- a/packages/rspack-dev-server/package.json +++ b/packages/rspack-dev-server/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/dev-server", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Development server for rspack", "main": "./dist/index.js", @@ -53,4 +53,4 @@ "peerDependencies": { "@rspack/core": "*" } -} \ No newline at end of file +} diff --git a/packages/rspack-plugin-minify/package.json b/packages/rspack-plugin-minify/package.json index 9cb6633ded17..fe10637e6f86 100644 --- a/packages/rspack-plugin-minify/package.json +++ b/packages/rspack-plugin-minify/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/plugin-minify", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Minify plugin for rspack", "main": "src/index.js", diff --git a/packages/rspack-plugin-react-refresh/package.json b/packages/rspack-plugin-react-refresh/package.json index ed83b74c4876..1cb8b0ca2423 100644 --- a/packages/rspack-plugin-react-refresh/package.json +++ b/packages/rspack-plugin-react-refresh/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/plugin-react-refresh", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "React refresh plugin for rspack", "main": "dist/index.js", diff --git a/packages/rspack-test-tools/package.json b/packages/rspack-test-tools/package.json index 8ece7ce0de1c..6b83f2e02cf5 100644 --- a/packages/rspack-test-tools/package.json +++ b/packages/rspack-test-tools/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/test-tools", - "version": "0.6.5", + "version": "0.7.0-beta.0", "license": "MIT", "description": "Test tools for rspack", "main": "dist/index.js", @@ -81,4 +81,4 @@ "react-dom": "18.0.0", "react-refresh": "0.14.0" } -} \ No newline at end of file +} diff --git a/packages/rspack/package.json b/packages/rspack/package.json index fa9bd214ede9..f588debfacd2 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -1,6 +1,6 @@ { "name": "@rspack/core", - "version": "0.6.5", + "version": "0.7.0-beta.0", "webpackVersion": "5.75.0", "license": "MIT", "description": "A Fast Rust-based Web Bundler", @@ -98,4 +98,4 @@ "optional": true } } -} \ No newline at end of file +} From abea2bd7decd6e5b948ee3c69aa4081a5734db2c Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Thu, 16 May 2024 17:52:33 +0800 Subject: [PATCH 100/107] test: snapshot directory should be __snapshots__ (#6564) --- .../src/processor/hot-step.ts | 2 +- .../src/processor/snapshot.ts | 2 +- .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../output.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../plugins/banner/snapshot/web/0.snap.txt | 12 ---- .../plugins/banner/snapshot/web/1.snap.txt | 55 ------------------- .../plugins/banner/snapshot/web/2.snap.txt | 55 ------------------- .../plugins/banner/snapshot/web/3.snap.txt | 55 ------------------- .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/0.snap.txt | 0 .../web/1.snap.txt | 0 .../web/2.snap.txt | 0 .../web/3.snap.txt | 0 .../web/4.snap.txt | 0 .../web/5.snap.txt | 0 .../web/6.snap.txt | 0 .../web/7.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 .../treeshaking.snap.txt | 0 287 files changed, 2 insertions(+), 179 deletions(-) rename packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/at-charset/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import-in-the-middle/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/default-options/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/http_import/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/multiple-entry/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/nested/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/output-iife/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/shared-import/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async-load-css/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-commonjs-syntax/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-es-module-syntax/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-multiple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-css/simple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/title/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-constant_folding/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/issuse_2960/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/magic_comment/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-inline/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/provide/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-javascript/simple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/rspack/code-splitting/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/rspack/static-import/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/intersection/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/self-import/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/samples/simple/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/{snapshot => __snapshots__}/output.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/asset/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/asset/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/asset/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/asset/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/issue-4476/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/context/request-position/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/context/request-position/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/css-modules/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/css-modules/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/css/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/css/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/decline/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/decline/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/events/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/events/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/self-decline/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/self-decline/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/unaccepted/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/errors/unaccepted/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-import/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-import/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/hash/hot-index/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/hash/hot-index/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/hash/hot-index/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/hash/hot-index/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/{snapshot => __snapshots__}/web/3.snap.txt (100%) delete mode 100644 packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/0.snap.txt delete mode 100644 packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/1.snap.txt delete mode 100644 packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/2.snap.txt delete mode 100644 packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/3.snap.txt rename packages/rspack-test-tools/tests/hotCases/plugins/html/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/plugins/html/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/accept/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/accept/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/circular/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/circular/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/disable/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/disable/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/disable/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/disable/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/enable/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/enable/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/enable/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/source-map/enable/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/status/accept/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/status/accept/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/status/check/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/status/check/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/0.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/1.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/2.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/3.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/4.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/5.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/6.snap.txt (100%) rename packages/rspack-test-tools/tests/hotCases/worker/issue-5597/{snapshot => __snapshots__}/web/7.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/basic/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/bb/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/class-extend/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/context-module/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/default_export/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export_star/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export_star2/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/import-as-default/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/issue-4637/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/issues_3198/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/static-class/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) rename packages/rspack-test-tools/tests/treeShakingCases/with-assets/{snapshot => __snapshots__}/treeshaking.snap.txt (100%) diff --git a/packages/rspack-test-tools/src/processor/hot-step.ts b/packages/rspack-test-tools/src/processor/hot-step.ts index c2b0acb6e346..7b5e481779c2 100644 --- a/packages/rspack-test-tools/src/processor/hot-step.ts +++ b/packages/rspack-test-tools/src/processor/hot-step.ts @@ -149,7 +149,7 @@ export class RspackHotStepProcessor extends RspackHotProcessor { const lastHash = this.hashes[this.hashes.length - 1]; const snapshotPath = context.getSource( - `snapshot/${compilerOptions.target}/${step}.snap.txt` + `__snapshots__/${compilerOptions.target}/${step}.snap.txt` ); const title = `Case ${this._options.name}: Step ${step}`; const hotUpdateFile: Array<{ diff --git a/packages/rspack-test-tools/src/processor/snapshot.ts b/packages/rspack-test-tools/src/processor/snapshot.ts index 51665df80722..a47025416697 100644 --- a/packages/rspack-test-tools/src/processor/snapshot.ts +++ b/packages/rspack-test-tools/src/processor/snapshot.ts @@ -71,7 +71,7 @@ export class SnapshotProcessor< ? this._snapshotOptions.snapshot : path.resolve( context.getSource(), - `./snapshot/${this._snapshotOptions.snapshot}` + `./__snapshots__/${this._snapshotOptions.snapshot}` ); if (!fs.existsSync(snapshotPath) || global.updateSnapshot) { diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/at-charset/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/at-charset/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/at-charset/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/at-charset/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import-in-the-middle/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import-in-the-middle/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import-in-the-middle/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import-in-the-middle/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/at-import/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/default-options/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/default-options/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/default-options/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/default-options/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/http_import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/http_import/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/http_import/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/http_import/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/multiple-entry/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/multiple-entry/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/multiple-entry/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/multiple-entry/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/nested/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/nested/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/nested/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/nested/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/output-iife/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/output-iife/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/output-iife/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/output-iife/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/shared-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/shared-import/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/shared-import/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/shared-import/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async-load-css/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async-load-css/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async-load-css/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async-load-css/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-async/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-commonjs-syntax/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-commonjs-syntax/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-commonjs-syntax/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-commonjs-syntax/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-es-module-syntax/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-es-module-syntax/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-es-module-syntax/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-es-module-syntax/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-multiple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-multiple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-multiple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-multiple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-css/simple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-css/simple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/basic/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/chunks/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/favicon/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/filename/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/inject/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/meta/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/minify/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/mpa/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/public-path/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/template+templateParameters/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/templateContent+templateParameters/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/title/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/title/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/title/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/title/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-constant_folding/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-constant_folding/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-constant_folding/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-constant_folding/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/issuse_2960/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/issuse_2960/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/issuse_2960/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/issuse_2960/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/magic_comment/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/magic_comment/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/magic_comment/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/magic_comment/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-inline/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-inline/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-inline/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-inline/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/new-url-source/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/provide/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/provide/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/provide/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/simple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/simple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-javascript/simple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-javascript/simple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/rspack/code-splitting/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/rspack/code-splitting/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/rspack/code-splitting/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/rspack/code-splitting/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/rspack/static-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/rspack/static-import/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/rspack/static-import/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/rspack/static-import/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/intersection/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/intersection/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/intersection/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/intersection/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/self-import/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/self-import/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/self-import/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/self-import/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/simple/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/simple/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/samples/simple/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/samples/simple/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/swc-loader/esm/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/snapshot/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/__snapshots__/output.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/snapshot/output.snap.txt rename to packages/rspack-test-tools/tests/builtinCases/swc-loader/ts/__snapshots__/output.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/asset/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/issue-4476/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/issue-4476/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/issue-4476/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/issue-4476/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/context/request-position/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/context/request-position/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/context/request-position/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/context/request-position/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-modules/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/css-modules/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-modules/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/css-modules/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/css/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/css/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/decline/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/decline/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/decline/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/decline/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/events/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/events/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/events/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/events/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/self-decline/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/self-decline/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/self-decline/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/self-decline/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/unaccepted/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/errors/unaccepted/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-import/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-import/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/hash/hot-index/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/0.snap.txt deleted file mode 100644 index 941fd73cf3d0..000000000000 --- a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/0.snap.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Case banner: Step 0 - -## Changed Files -- file.js - -## Asset Files -- Bundle: bundle.js - -## Manifest - - -## Update \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/1.snap.txt deleted file mode 100644 index a27e04564bd6..000000000000 --- a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/1.snap.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Case banner: Step 1 - -## Changed Files -- file.js - -## Asset Files -- Bundle: bundle.js -- Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 550 - -## Manifest - -### main.LAST_HASH.hot-update.json - -```json -{"c":["main"],"r":[],"m":[]} -``` - - -## Update - - -### main.LAST_HASH.hot-update.js - -#### Changed Modules -- ./file.js - -#### Changed Runtime Modules -- webpack/runtime/get_full_hash - -#### Changed Content -```js -global.bannerIndex = typeof global.bannerIndex === 'number' ? global.bannerIndex + 1 : 0; -self["webpackHotUpdate"]('main', { -"./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - value: function() { return value; } -}); -const value = 1; -}), - -},function(__webpack_require__) { -// webpack/runtime/get_full_hash -!function() { -__webpack_require__.h = function () { - return "CURRENT_HASH"; -}; - -}(); - -} -); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/2.snap.txt deleted file mode 100644 index 7756b6242ca2..000000000000 --- a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/2.snap.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Case banner: Step 2 - -## Changed Files -- file.js - -## Asset Files -- Bundle: bundle.js -- Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 550 - -## Manifest - -### main.LAST_HASH.hot-update.json - -```json -{"c":["main"],"r":[],"m":[]} -``` - - -## Update - - -### main.LAST_HASH.hot-update.js - -#### Changed Modules -- ./file.js - -#### Changed Runtime Modules -- webpack/runtime/get_full_hash - -#### Changed Content -```js -global.bannerIndex = typeof global.bannerIndex === 'number' ? global.bannerIndex + 1 : 0; -self["webpackHotUpdate"]('main', { -"./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - value: function() { return value; } -}); -const value = 2; -}), - -},function(__webpack_require__) { -// webpack/runtime/get_full_hash -!function() { -__webpack_require__.h = function () { - return "CURRENT_HASH"; -}; - -}(); - -} -); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/3.snap.txt deleted file mode 100644 index a53a5186ec98..000000000000 --- a/packages/rspack-test-tools/tests/hotCases/plugins/banner/snapshot/web/3.snap.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Case banner: Step 3 - -## Changed Files -- file.js - -## Asset Files -- Bundle: bundle.js -- Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 550 - -## Manifest - -### main.LAST_HASH.hot-update.json - -```json -{"c":["main"],"r":[],"m":[]} -``` - - -## Update - - -### main.LAST_HASH.hot-update.js - -#### Changed Modules -- ./file.js - -#### Changed Runtime Modules -- webpack/runtime/get_full_hash - -#### Changed Content -```js -global.bannerIndex = typeof global.bannerIndex === 'number' ? global.bannerIndex + 1 : 0; -self["webpackHotUpdate"]('main', { -"./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - value: function() { return value; } -}); -const value = 3; -}), - -},function(__webpack_require__) { -// webpack/runtime/get_full_hash -!function() { -__webpack_require__.h = function () { - return "CURRENT_HASH"; -}; - -}(); - -} -); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/html/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/plugins/html/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/html/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/plugins/html/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/accept/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/accept/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/accept/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/accept/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/circular/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/circular/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/circular/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/circular/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/disable/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/source-map/enable/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/status/accept/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/status/accept/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/status/accept/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/status/accept/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/status/check/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/status/check/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/status/check/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/status/check/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/0.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/0.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/0.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/1.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/2.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/3.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/4.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/4.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/5.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/5.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/6.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/6.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/7.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/hotCases/worker/issue-5597/snapshot/web/7.snap.txt rename to packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/basic/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/basic/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/basic/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/bb/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/bb/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/bb/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/cjs-export-computed-property/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/class-extend/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/class-extend/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/context-module/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/context-module/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/default_export/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/default_export/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/default_export/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-all-from-side-effects-free-commonjs/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export_star/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export_star2/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export_star2/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-required/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-as-default/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-as-default/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-export-all-as-a-empty-module/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/issue-4637/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/issue-4637/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/issues_3198/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/issues_3198/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/static-class/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/static-class/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/static-class/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/transitive-bailout/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/transitive_side_effects_when_analyze/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-no-side-effects/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-try-globals/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt diff --git a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/__snapshots__/treeshaking.snap.txt similarity index 100% rename from packages/rspack-test-tools/tests/treeShakingCases/with-assets/snapshot/treeshaking.snap.txt rename to packages/rspack-test-tools/tests/treeShakingCases/with-assets/__snapshots__/treeshaking.snap.txt From ad90ce06d125486d0becc06a2cb5ae221d1d3321 Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Thu, 16 May 2024 19:46:59 +0800 Subject: [PATCH 101/107] docs: remove canary comment release in contribute guide (#6566) --- .github/workflows/release-canary.yml | 2 -- website/docs/en/contribute/development/releasing.md | 11 ----------- 2 files changed, 13 deletions(-) diff --git a/.github/workflows/release-canary.yml b/.github/workflows/release-canary.yml index 34ac9b0ddc0c..cfa1ea5f977b 100644 --- a/.github/workflows/release-canary.yml +++ b/.github/workflows/release-canary.yml @@ -1,5 +1,3 @@ -# Release Canary by comment with "!canary" - name: Release Canary on: diff --git a/website/docs/en/contribute/development/releasing.md b/website/docs/en/contribute/development/releasing.md index 5be62d29229c..ec63bf5ac996 100644 --- a/website/docs/en/contribute/development/releasing.md +++ b/website/docs/en/contribute/development/releasing.md @@ -31,14 +31,3 @@ The [nightly release workflow](https://github.com/web-infra-dev/rspack/actions/w is triggered every day at UTC 16:00:07, which is 00:07 AM Beijing Time (offset with an odd minute to avoid cron jobs firing off at the same time). The nightly build fully replicates the full release build for catching errors early. - -## Canary - -Commenting on a PR with the text `!canary` triggers the [canary release workflow](https://github.com/web-infra-dev/rspack/actions/workflows/release-canary.yml?query=is%3Asuccess). -Only contributors have the permission to publish canary releases. - -The canary release only builds three targets for quicker feedback - -- aarch64-apple-darwin -- x86_64-apple-darwin -- x86_64-unknown-linux-gnu From 96d98de568856585c3e87be1508c3347e33a194a Mon Sep 17 00:00:00 2001 From: Gengkun Date: Thu, 16 May 2024 22:58:23 +0800 Subject: [PATCH 102/107] chore: remove exportsConvention for css generator (#6555) * chore: remove exportsConvention for css generator * doc * fix --- crates/node_binding/binding.d.ts | 1 - .../src/options/raw_module/mod.rs | 3 -- crates/rspack_core/src/options/module.rs | 1 - .../src/parser_and_generator/mod.rs | 8 +++-- .../src/plugin/impl_plugin_for_css_plugin.rs | 18 ++++++------ .../tests/__snapshots__/Defaults.test.js.snap | 1 - .../experiments/future-defaults-with-css.js | 6 ++-- packages/rspack/etc/api.md | 29 ------------------- packages/rspack/src/config/adapter.ts | 1 - packages/rspack/src/config/defaults.ts | 1 - packages/rspack/src/config/zod.ts | 1 - website/docs/en/config/module.mdx | 6 ++-- website/docs/zh/config/module.mdx | 6 ++-- 13 files changed, 25 insertions(+), 57 deletions(-) diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 1701083285a6..ff4fe47d1517 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -791,7 +791,6 @@ export interface RawCssExtractPluginOption { } export interface RawCssGeneratorOptions { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" exportsOnly?: boolean esModule?: boolean } diff --git a/crates/rspack_binding_options/src/options/raw_module/mod.rs b/crates/rspack_binding_options/src/options/raw_module/mod.rs index b96b92eb1709..6c4094db46e0 100644 --- a/crates/rspack_binding_options/src/options/raw_module/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_module/mod.rs @@ -619,8 +619,6 @@ impl From for AssetGeneratorDataUrlOptions { #[derive(Debug, Default)] #[napi(object)] pub struct RawCssGeneratorOptions { - #[napi(ts_type = r#""as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only""#)] - pub exports_convention: Option, pub exports_only: Option, pub es_module: Option, } @@ -628,7 +626,6 @@ pub struct RawCssGeneratorOptions { impl From for CssGeneratorOptions { fn from(value: RawCssGeneratorOptions) -> Self { Self { - exports_convention: value.exports_convention.map(|n| n.into()), exports_only: value.exports_only, es_module: value.es_module, } diff --git a/crates/rspack_core/src/options/module.rs b/crates/rspack_core/src/options/module.rs index 042690a5ad8c..3f77bb6f7f64 100644 --- a/crates/rspack_core/src/options/module.rs +++ b/crates/rspack_core/src/options/module.rs @@ -335,7 +335,6 @@ impl From for DataUrlEncoding { #[derive(Debug, Clone, MergeFrom)] pub struct CssGeneratorOptions { - pub exports_convention: Option, pub exports_only: Option, pub es_module: Option, } diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index 88bd3e78e0bb..ebb1874527ff 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -55,7 +55,7 @@ pub type CssExportsType = IndexMap, Vec>; #[derive(Debug)] pub struct CssParserAndGenerator { - pub convention: CssExportsConvention, + pub convention: Option, pub local_ident_name: Option, pub exports_only: bool, pub named_exports: bool, @@ -172,7 +172,9 @@ impl ParserAndGenerator for CssParserAndGenerator { Default::default(), )?; - if let Some(exports) = &mut exports { + if let Some(exports) = &mut exports + && let Some(convention) = &self.convention + { let mut exports_analyzer = ExportsAnalyzer::new(&source_code); new_stylesheet_ast.visit_with(&mut exports_analyzer); presentational_dependencies = Some(exports_analyzer.presentation_deps); @@ -185,7 +187,7 @@ impl ParserAndGenerator for CssParserAndGenerator { exports .iter() .map(|(name, elements)| { - let mut names = export_locals_convention(name, &self.convention); + let mut names = export_locals_convention(name, convention); names.sort_unstable(); names.dedup(); (names, stringify_css_modules_exports_elements(elements)) 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 975c3a973f3d..de96a6d555fa 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 @@ -337,9 +337,7 @@ impl Plugin for CssPlugin { .expect("should have CssGeneratorOptions"); Box::new(CssParserAndGenerator { exports: None, - convention: g - .exports_convention - .expect("should have exports_convention"), + convention: None, local_ident_name: None, exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), @@ -358,9 +356,10 @@ impl Plugin for CssPlugin { .expect("should have CssModuleGeneratorOptions"); Box::new(CssParserAndGenerator { exports: None, - convention: g - .exports_convention - .expect("should have exports_convention"), + convention: Some( + g.exports_convention + .expect("should have exports_convention"), + ), local_ident_name: Some( g.local_ident_name .clone() @@ -383,9 +382,10 @@ impl Plugin for CssPlugin { .expect("should have CssAutoGeneratorOptions"); Box::new(CssParserAndGenerator { exports: None, - convention: g - .exports_convention - .expect("should have exports_convention"), + convention: Some( + g.exports_convention + .expect("should have exports_convention"), + ), local_ident_name: Some( g.local_ident_name .clone() diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index d14213080346..19ea6668e45d 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -148,7 +148,6 @@ Object { "generator": Object { "css": Object { "esModule": true, - "exportsConvention": "as-is", "exportsOnly": false, }, "css/auto": Object { diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js index bcd3f9e268a3..484f56ed00e5 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/future-defaults-with-css.js @@ -46,7 +46,6 @@ module.exports = { - "generator": Object { - "css": Object { - "esModule": true, - - "exportsConvention": "as-is", - "exportsOnly": false, - }, - "css/auto": Object { @@ -64,15 +63,16 @@ module.exports = { - }, + "generator": Object {}, @@ ... @@ + - }, + - }, - "css": Object { - "namedExports": true, - }, - "css/auto": Object { - "namedExports": true, - - }, + @@ ... @@ - "css/module": Object { - "namedExports": true, - - }, @@ ... @@ - "css", @@ ... @@ diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 256352df669b..8ab79f2de853 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -1641,15 +1641,12 @@ export type CssGeneratorOptions = z.infer; // @public (undocumented) const cssGeneratorOptions: z.ZodObject<{ - exportsConvention: z.ZodOptional>; exportsOnly: z.ZodOptional; esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }>; @@ -3235,15 +3232,12 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ publicPath?: string | undefined; }>>; css: z.ZodOptional>; exportsOnly: z.ZodOptional; esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }>>; @@ -3307,7 +3301,6 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -3351,7 +3344,6 @@ const generatorOptionsByModuleType: z.ZodUnion<[z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -3471,15 +3463,12 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ publicPath?: string | undefined; }>>; css: z.ZodOptional>; exportsOnly: z.ZodOptional; esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }>>; @@ -3543,7 +3532,6 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -3587,7 +3575,6 @@ const generatorOptionsByModuleTypeKnown: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -5195,15 +5182,12 @@ const moduleOptions: z.ZodObject<{ publicPath?: string | undefined; }>>; css: z.ZodOptional>; exportsOnly: z.ZodOptional; esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }>>; @@ -5267,7 +5251,6 @@ const moduleOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -5311,7 +5294,6 @@ const moduleOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -5408,7 +5390,6 @@ const moduleOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -5505,7 +5486,6 @@ const moduleOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -9495,15 +9475,12 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; }>>; css: z.ZodOptional>; exportsOnly: z.ZodOptional; esModule: z.ZodOptional; }, "strict", z.ZodTypeAny, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }, { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; }>>; @@ -9567,7 +9544,6 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -9611,7 +9587,6 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -9708,7 +9683,6 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -9805,7 +9779,6 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -10239,7 +10212,6 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; @@ -10663,7 +10635,6 @@ export const rspackOptions: z.ZodObject<{ publicPath?: string | undefined; } | undefined; css?: { - exportsConvention?: "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only" | undefined; exportsOnly?: boolean | undefined; esModule?: boolean | undefined; } | undefined; diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index 6c2537364f1e..c08ef1a36703 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -765,7 +765,6 @@ function getRawCssGeneratorOptions( options: CssGeneratorOptions ): RawCssGeneratorOptions { return { - exportsConvention: options.exportsConvention, exportsOnly: options.exportsOnly, esModule: options.esModule }; diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 2bcfb96717ce..0965b578a3ba 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -320,7 +320,6 @@ const applyModuleDefaults = ( "exportsOnly", !targetProperties || !targetProperties.document ); - D(module.generator["css"], "exportsConvention", "as-is"); D(module.generator["css"], "esModule", true); F(module.generator, "css/auto", () => ({})); diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index faed9b4e2d15..ff1735b52455 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -661,7 +661,6 @@ const cssGeneratorEsModule = z.boolean(); export type CssGeneratorEsModule = z.infer; const cssGeneratorOptions = z.strictObject({ - exportsConvention: cssGeneratorExportsConvention.optional(), exportsOnly: cssGeneratorExportsOnly.optional(), esModule: cssGeneratorEsModule.optional() }); diff --git a/website/docs/en/config/module.mdx b/website/docs/en/config/module.mdx index 845e71204ba2..8ee7e87b365a 100644 --- a/website/docs/en/config/module.mdx +++ b/website/docs/en/config/module.mdx @@ -297,17 +297,19 @@ module.exports = { exportsConvention: 'as-is', exportsOnly: false, localIdentName: '[uniqueName]-[id]-[local]', + esModule: true, }, // Generator options for `css` modules css: { - exportsConvention: 'as-is', exportsOnly: false, + esModule: true, }, // Generator options for css/module modules 'css/module': { exportsConvention: 'as-is', exportsOnly: false, localIdentName: '[uniqueName]-[id]-[local]', + esModule: true, }, }, }, @@ -562,7 +564,7 @@ This configuration will only take effect when `experiments.css = true`. #### module.generator.css.exportsConvention - + Same as [`module.generator["css/auto"].exportsConvention`](#modulegeneratorcssautoexportsconvention). diff --git a/website/docs/zh/config/module.mdx b/website/docs/zh/config/module.mdx index 7f01b76c49d7..c4d2926ed7f9 100644 --- a/website/docs/zh/config/module.mdx +++ b/website/docs/zh/config/module.mdx @@ -297,17 +297,19 @@ module.exports = { exportsConvention: 'as-is', exportsOnly: false, localIdentName: '[uniqueName]-[id]-[local]', + esModule: true, }, // `css` 模块的生成器选项 css: { - exportsConvention: 'as-is', exportsOnly: false, + esModule: true, }, // css/module 模块的生成器选项 'css/module': { exportsConvention: 'as-is', exportsOnly: false, localIdentName: '[uniqueName]-[id]-[local]', + esModule: true, }, }, }, @@ -562,7 +564,7 @@ function Button() { #### module.generator.css.exportsConvention - + 和 [`module.generator["css/auto"].exportsConvention`](#modulegeneratorcssautoexportsconvention) 一样。 From be7b3826f39e5d0af66b70e4fd7e41c65679cc0d Mon Sep 17 00:00:00 2001 From: harpsealjs Date: Fri, 17 May 2024 11:54:10 +0800 Subject: [PATCH 103/107] docs: new testing guide (#6519) * docs: new testing guide * docs: new testing guide * docs: new testing guide * docs: new testing guide * docs: new testing guide --------- Co-authored-by: neverland --- packages/rspack-test-tools/etc/api.md | 2 - .../src/processor/stats-api.ts | 1 - webpack-test/README.md | 37 +- .../docs/en/contribute/development/_meta.json | 11 +- .../contribute/development/testing-rspack.mdx | 405 ++++++++++++++++++ .../development/testing-webpack.mdx | 61 +++ .../docs/en/contribute/development/testing.md | 149 ------- .../en/contribute/development/testing.mdx | 77 ++++ .../contribute/development/testing-rspack.mdx | 403 +++++++++++++++++ .../development/testing-webpack.mdx | 62 +++ .../zh/contribute/development/testing.mdx | 77 ++++ 11 files changed, 1121 insertions(+), 164 deletions(-) create mode 100644 website/docs/en/contribute/development/testing-rspack.mdx create mode 100644 website/docs/en/contribute/development/testing-webpack.mdx delete mode 100644 website/docs/en/contribute/development/testing.md create mode 100644 website/docs/en/contribute/development/testing.mdx create mode 100644 website/docs/zh/contribute/development/testing-rspack.mdx create mode 100644 website/docs/zh/contribute/development/testing-webpack.mdx create mode 100644 website/docs/zh/contribute/development/testing.mdx diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index 433b52fcee8d..362cb398e5a1 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -643,8 +643,6 @@ export interface IStatsAPITaskProcessorOptions { // (undocumented) compilerType: T; // (undocumented) - cwd?: string; - // (undocumented) name: string; // (undocumented) options?: (context: ITestContext) => TCompilerOptions; diff --git a/packages/rspack-test-tools/src/processor/stats-api.ts b/packages/rspack-test-tools/src/processor/stats-api.ts index 80e13cdb7821..eff1096b4689 100644 --- a/packages/rspack-test-tools/src/processor/stats-api.ts +++ b/packages/rspack-test-tools/src/processor/stats-api.ts @@ -15,7 +15,6 @@ const serializer = require("jest-serializer-path"); export interface IStatsAPITaskProcessorOptions { options?: (context: ITestContext) => TCompilerOptions; name: string; - cwd?: string; compilerType: T; compiler?: (context: ITestContext, compiler: TCompiler) => Promise; build?: (context: ITestContext, compiler: TCompiler) => Promise; diff --git a/webpack-test/README.md b/webpack-test/README.md index 365c90d06195..3dae78ab2363 100644 --- a/webpack-test/README.md +++ b/webpack-test/README.md @@ -1,46 +1,54 @@ ->**Note** +>**Note** > This package is heavily based on [webpack/test](https://github.com/webpack/webpack/tree/main/test) -# Progressively migrate webpack test +# Progressively migrate webpack test -Originally, we use this formula to calculate the compatibility `passedTestCaseCount / totalTestCount`, totalTestCount = passedTestCaseCount + failedTestCount + skippedTestCount , but sometimes it maybe hard to compatible with all webpack test cases for some reasons (e.g. performance, legacy feature that we don't want to support), we need a method to skip these tests that we will not support. Thus, we adjust the original formula to `(passedTestCaseCount + willNotSupportTestCount) / totalTestCount`. +Originally, we use this formula to calculate the compatibility `passedTestCaseCount / totalTestCount`, totalTestCount = passedTestCaseCount + failedTestCount + skippedTestCount , but sometimes it maybe hard to compatible with all webpack test cases for some reasons (e.g. performance, legacy feature that we don't want to support), we need a method to skip these tests that we will not support. Thus, we adjust the original formula to `(passedTestCaseCount + willNotSupportTestCount) / totalTestCount`. -Currently, we use a `test.filter.js` under each failed test case directory to skip failed test case, using this method could let us migrate webpack test case progressively without affect the real compatibility (Because this method will not influence the real `passedTestCaseCount`). +Currently, we use a `test.filter.js` under each failed test case directory to skip failed test case, using this method could let us migrate webpack test case progressively without affect the real compatibility (Because this method will not influence the real `passedTestCaseCount`). e.g. + ```js -// test.fitler.js +// test.filter.js module.exports = () => { return false; // false means this testcase is skipped for now, but maybe we will support in the future, `-1` means this test case we don't want to compatible with, this related to `willNotSupportTest`. } ``` -When you find that we have passed some failed testcases which is skipped for now, you could change the `test.filter.js` to + +When you find that we have passed some failed testcases which is skipped for now, you could change the `test.filter.js` to + ```js module.exports = () => { return true } ``` + or delete the `test.filter.js` +# Welcome to the webpack test suite -# Welcome to the webpack test suite!!!! Every pull request that you submit to webpack (besides README and spelling corrections in comments) requires tests that are created. But don't give up hope!!! Although our tests may appear complex and overwhelming, once you become familiar with the test suite and structure, adding and creating tests will be fun and beneficial as you work inside the codebase! ❤ ## tl;dr + Run all tests (this automatically runs the setup): + ```sh pnpm test ``` Run an individual suite: + ```sh pnpm jest ConfigTestCases ``` Watch mode: + ```sh pnpm jest --watch ConfigTestCases ``` @@ -48,16 +56,20 @@ pnpm jest --watch ConfigTestCases See also: [Jest CLI docs](https://jestjs.io/docs/cli) ## Test suite overview + We use Jest for our tests. For more information on Jest you can visit their [homepage](https://jestjs.io/)! ### Class Tests + All test files can be found in *.test.js. There are many tests that simply test APIs of a specific class/file (such as `Compiler`, `Errors`, Integration, `Parser`, `RuleSet`, Validation). If the feature you are contributing involves one of those classes, then best to start there to understand the structure. ### xCases + In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding *.test.js files. #### cases (`TestCases.test.js`) 1 + Cases are a set of general purpose tests that will run against a variety of permutations of webpack configurations. When you are making a general purpose change that doesn't require you to have a special configuration, you would likely add your tests here. Inside of the `./test/cases` directory you will find tests are broken into thematic sub directories. Take a moment to explore the different options. To add a new case, create a new directory inside of the top level test groups, and then add an `index.js` file (and any other supporting files). @@ -65,11 +77,13 @@ To add a new case, create a new directory inside of the top level test groups, a By default this file will be the entry point for the test suite and you can add your `it()`'s there. This will also become bundled so that node env support happens as well. #### configCases (`ConfigTestCases.basictest.js`) 1 + If you are trying to solve a bug which is reproducible when x and y properties are used together in a config, then configCases is the place to be!!!! In addition to an `index.js`, these configCases require a `webpack.config.js` is located inside of your test suite. This will run this specific config through `webpack` just as you were building individually. They will use the same loading/bundling technique of your `it()` tests, however you now have a more specific config use cases that you can write even before you start coding. #### statsCases (`StatsTestCases.basictest.js`) + Stats cases are similar to configCases except specifically focusing on the `expected` output of your stats. Instead of writing to the console, however the output of stats will be written to disk. By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run, runner is checking output using jest's awesome snapshot functionality. @@ -83,6 +97,7 @@ Please follow the approach described below: ```javascript import("./someModule"); ``` + * don't forget the `webpack.config.js` * run the test * jest will automatically add the output from your test code to `StatsTestCases.test.js.snap` and you can always check your results there @@ -91,16 +106,16 @@ import("./someModule"); You can read more about SnapShot testing [right here](https://jestjs.io/docs/snapshot-testing) ## Questions? Comments? -If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on! +If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on! ## Footnotes -1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow Node.js' timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions. +1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow Node.js' timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a `test.filter.js` file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the `./helpers` folder to find a list of the versions. ## Credits Thanks to: -- [The webpack team and community](https://webpack.js.org/) for creating a great bundler and ecosystem from which we draw a lot of inspiration. -- [@sokra](https://github.com/sokra) for the great work on the [webpack](https://github.com/webpack/webpack) project. +* [The webpack team and community](https://webpack.js.org/) for creating a great bundler and ecosystem from which we draw a lot of inspiration. +* [@sokra](https://github.com/sokra) for the great work on the [webpack](https://github.com/webpack/webpack) project. diff --git a/website/docs/en/contribute/development/_meta.json b/website/docs/en/contribute/development/_meta.json index 148d67a6f179..73c545f91175 100644 --- a/website/docs/en/contribute/development/_meta.json +++ b/website/docs/en/contribute/development/_meta.json @@ -1 +1,10 @@ -["prerequisites", "building", "testing", "debugging", "profiling", "releasing"] +[ + "prerequisites", + "building", + "testing", + "testing-webpack", + "testing-rspack", + "debugging", + "profiling", + "releasing" +] diff --git a/website/docs/en/contribute/development/testing-rspack.mdx b/website/docs/en/contribute/development/testing-rspack.mdx new file mode 100644 index 000000000000..a7daaac9078e --- /dev/null +++ b/website/docs/en/contribute/development/testing-rspack.mdx @@ -0,0 +1,405 @@ +# Testing Rspack + +Rspack's test cases include the following: + +- Rspack core test cases are stored in the `packages/rspack-test-tools/tests` folder and will run the test cases by simulating the build process. In general, test cases should be added in this folder. +- Test cases for other Rspack packages are stored in the `packages/{name}/tests` folder and should only be added or modified when modifying that package. + +## Running Tests + +You can run these test cases in the following ways: + +- Run `./x test unit` or `pnpm run test:unit` from the root directory. +- Or run `npm run test` from the `packages/rspack-test-tools` directory. +- To update snapshots, run `npm run test -- -u` from the `packages/rspack-test-tools` directory. +- To pass specific jest cli arguments, run `npm run test -- {args}` from the `packages/rspack-test-tools` directory. + +## Directory Structure + +The structure of the `packages/rspack-test-tools/tests` folder is as follows: + +```bash +. +├── js # Used to store build artifacts and temporary files +├── __snapshots__ # Used to store test snapshots +├── {Name}.test.js # Entry for normal testing +├── {Name}.hottest.js # Entry for hot snapshot testing +├── {Name}.difftest.js # Entry for diff testing +├── {name}Cases # Directory to store test cases +└── fixtures # General test files +``` + +The `{Name}.test.js` is the entry file for tests, which will walk the `{name}Cases` folder and run cases in it. Therefore, when you need to add or modify test cases, add them to the relevant `{name}Cases` folder based on the type of testing. + +## Test Types + +The existing test types are: + +- [Normal](#normal): Used to test core build processes without configuration changes. This type is used when testing does not require adding `rspack.config.js`. +- [Config](#config): Used to test build configuration options. If your test needs specific configuration added through `rspack.config.js` to run and does not fit other scenarios, use this test type. +- [Hot](#hot): Used to test whether Hot Module Replacement (HMR) runs correctly. This type includes HotNode with a fixed `target=async-node`, HotWeb with a fixed `target=web`, and HotWorker with a fixed `target=webworker`. +- [HotSnapshot](#hotsnapshot): Used to test whether HMR can generate correct intermediate artifacts. This test type shares test cases with the Hot type and generates snapshots for incremental artifacts for each HMR. +- [Watch](#watch): Used to test incremental compilation after modifying files in Watch mode. +- [StatsOutput](#statsoutput): Used to test the console output log after the build ends. +- [StatsAPI](#stats-api): Used to test the Stats object generated after the build ends. +- [Diagnostic](#diagnostic): Used to test the formatted output information for warnings/errors generated during the build process. +- [Hash](#hash): Used to test whether hash generation works correctly. +- [Compiler](#compiler): Used to test Compiler/Compilation object APIs. +- [Defaults](#defaults): Used to test the interaction between configuration options. +- [Error](#error): Used to test the interaction between `compilation.errors` and `compilation.warnings`. +- [Hook](#hook): Used to test various hook functionalities. +- [TreeShaking](#treeshaking): Used to test Tree Shaking-related features. +- [Builtin](#builtin): Used to test plugins with built-in native implementations. + +Please prioritize adding test cases within the above test types. + +{/* If there are no suitable types, please follow the guidelines for [adding new test types](./test-advanced). */} + +## Normal + +| Test Entry | `tests/Normal.test.js` | +| --------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/normalCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/normalCases) | +| Output Directory | `tests/js/normal` | +| Default Configuration | [NormalProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/normal.ts#L35) | +| Run Output | `Yes` | + +The writing of the case is the same as a regular rspack project, but it does not include the `rspack.config.js` file and will use the provided configuration for building. + +## Config + +| Test Entry | `tests/Config.test.js` | +| --------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/configCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/configCases) | +| Output Directory | `tests/js/config` | +| Default Configuration | [ConfigProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/config.ts#L51) | +| Run Output | `Yes` | + +This test case is similar to a regular rspack project. You can specify the build configuration by adding a `rspack.config.js` and control various behaviors during testing by adding a `test.config.js`. The structure of the `test.config.js` file is as follows: + +```typescript {16-20} title="test.config.js" +type TConfigCaseConfig = { + noTest?: boolean; // Do not run the test output and end the test + beforeExecute?: () => void; // Callback before running the output + afterExecute?: () => void; // Callback after running the output + moduleScope?: (ms: IBasicModuleScope) => IBasicModuleScope; // Module context variables when running the output + findBundle?: ( + // Function for obtaining output when running the output, can control the output at a finer granularity + index: number, // Compiler index in multi-compiler scenario + options: TCompilerOptions, // Build configuration object + ) => string | string[]; + bundlePath?: string[]; // Output file name when running the output (prior to findBundle) + nonEsmThis?: (p: string | string[]) => Object; // this object during CJS output runtime, defaults to current module's module.exports if not specified + modules?: Record; // Pre-added modules when running the output, will be prioritized when required + timeout?: number; // Timeout for the test case +}; + +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Hot + +| Test Entry | `Hot{Target}.test.js` | +| --------------------- | --------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/hotCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hotCases) | +| Output Directory | `tests/js/hot-{target}` | +| Default Configuration | [HotProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/hot.ts#L86) | +| Run Output | `Yes` | + +This test case is similar to a regular rspack project. You can specify the build configuration by adding a `rspack.config.js`, but you also need to add a `changed-file.js` in the case directory to specify the files that have changed, as shown below: + +```js title="changed-file.js" +const path = require('path'); +module.exports = [ + path.resolve(__dirname, './file.js'), // file.js has changed and triggers hot update +]; +``` + +And also, within the file that has changed, use `---` to separate the code before and after the change: + +```js file.js title="file.js" +module.exports = 1; // Initial build +--- +module.exports = 2; // First hot update +--- +module.exports = 3; // Second hot update +``` + +In the test case code, use the `NEXT` method to control the timing of file changes and add test code within it: + +```js title="index.js" +import value from './file'; + +it('should hot update', done => { + expect(value).toBe(1); + // Use packages/rspack-test-tools/tests/hotCases/update.js to trigger update + NEXT( + require('../../update')(done, true, () => { + expect(value).toBe(2); + NEXT( + require('../../update')(done, true, () => { + expect(value).toBe(3); + done(); + }), + ); + }), + ); +}); + +module.hot.accept('./file'); +``` + +## HotSnapshot + +| Test Entry | `HotSnapshot.hottest.js` | +| --------------------- | --------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/hotCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hotCases) | +| Output Directory | `tests/js/hot-snapshot` | +| Default Configuration | Same as [Hot](#hot) | +| Run Output | `Yes` | + +Uses the same test cases as `Hot{Target}`, and generates a `__snapshots__/{target}/{step}.snap.txt` file in the case folder to perform snapshot testing on the incremental artifacts of each HMR. + +The snapshot structure is as follows: + +- **Changed Files**: Source code files that trigger this HMR build +- **Asset Files**: Artifact files of this HMR build +- **Manifest**: Contents of the `hot-update.json` metadata file for this HMR build, where: + - `"c"`: Id of the chunks to be updated in this HMR + - `"r"`: Id of the chunks to be removed in this HMR + - `"m"`: Id of the modules to be removed in this HMR +- **Update**: Information about the `hot-update.js` patch file for this HMR build, including: + - **Changed Modules**: List of modules included in the patch + - **Changed Runtime Modules**: List of runtime modules included in the patch + - **Changed Content**: Snapshot of the patch code + +## Watch + +| Entry File | `Watch.test.js` | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/watchCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/watchCases) | +| Output Directory | `tests/js/watch` | +| Default Configuration | [WatchProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/watch.ts#L99) | +| Run Output | `Yes` | + +As the Watch build needs to be performed in multiple steps, you can specify the build configuration by adding a `rspack.config.js`. The directory structure of its cases is special and will use incrementing numbers to represent change batches: + +```bash +. +├── 0 # WATCH_STEP=0, initial code for the case +├── 1 # WATCH_STEP=1, diff files for the first change +├── 2 # WATCH_STEP=2, diff files for the second change +└── rspack.config.js +``` + +In the test code, you can use the `WATCH_STEP` variable to get the current batch number of changes. + +## StatsOutput + +| Test Entry | `StatsOutput.test.js` | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/statsOutputCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/statsOutputCases) | +| Output Directory | `tests/js/statsOutput` | +| Default Configuration | [StatsProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/stats.ts#L190) | +| Run Output | `No` | + +The writing of the cases is the same as in a regular rspack project. After running, the console output information will be captured in snapshots and stored in `rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap`. + +:::info Tip +As some StatsOutput test cases contain hashes, when you modify the output code, please use the `-u` parameter to update the snapshots for these cases. +::: + +## Stats API + +| Entry File | `StatsAPI.test.js` | +| --------------------- | ----------------------------------------------------------------------------------------------------------------- | +| Case Directory | `tests/statsAPICases` | +| Output Directory | `None` | +| Default Configuration | [`None`](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/stats-api.ts) | +| Run Output | `No` | + +This test uses `rspack-test-tools/tests/fixtures` as the source code for the build, so the test case is written as a single file. Its structure is as follows: + +```js {8-11} title="{case}.js" +type TStatsAPICaseConfig = { + description: string; // Case description + options?: (context: ITestContext) => TCompilerOptions; // Case build configuration + build?: (context: ITestContext, compiler: TCompiler) => Promise; // Case build method + check?: (stats: TCompilerStats, compiler: TCompiler) => Promise; // Function to check the stats for the case +} + +/** @type {import('../..').TStatsAPICaseConfig} */ +module.exports = { + // ... +} +``` + +## Diagnostic + +| Entry File | `Diagnostics.test.js` | +| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/diagnosticsCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/diagnosticsCases) | +| Output Directory | `tests/js/diagnostics` | +| Default Configuration | [DiagnosticProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/diagnostic.ts#L71) | +| Run Output | `No` | + +This test case is similar to a typical rspack project and can specify build configurations by adding a `rspack.config.js`. Additionally, it will add a `stats.err` file in the case directory to store snapshots of warnings/errors. To refresh, use the `-u` parameter. + +## Hash + +| Entry File | `Hash.test.js` | +| --------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/hashCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hashCases) | +| Output Directory | None | +| Default Configuration | [HashProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/hash.ts#L53) | +| Run Output | No | + +This test case is similar to a typical rspack project, but it will add a `test.config.js` file in the case directory and specify a `validate()` method to check the hash information in the `stats` object after the build is complete: + +```javascript {5-8} title="test.config.js" +type THashCaseConfig = { + validate?: (stats: TCompilerStats) => void; +}; + +/** @type {import('../..').THashCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Compiler + +| Entry File | `Compiler.test.js` | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/compilerCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/compilerCases) | +| Output Directory | None | +| Default Configuration | [None](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/simple.ts) | +| Run Output | No | + +This test uses `rspack-test-tools/tests/fixtures` as the source code for the build, so the test case is written as a single file. Its structure is as follows: + +```javascript {9-12} title="{case.js}" +interface TCompilerCaseConfig { + description: string; // Description of the test case + options?: (context: ITestContext) => TCompilerOptions; // Test case build configuration + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; // How the compiler is created for the test case + build?: (context: ITestContext, compiler: TCompiler) => Promise; // Build method for the test case + check?: (context: ITestContext, compiler: TCompiler, stats: TCompilerStats) => Promise; // Check function for the test case +} + +/** @type {import('../..').TCompilerCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Defaults + +| Entry File | `Defaults.test.js` | +| --------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/defaultCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/defaultCases) | +| Output Directory | None | +| Default Configuration | [None](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/defaults.ts) | +| Run Output | No | + +This test does not execute real builds; it only generates build configurations and observes the differences from the default configuration. The basic default configuration will be snapshot and stored in `rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap`. + +This test uses `rspack-test-tools/tests/fixtures` as the source code for the build, so the test case is written as a single file. Its structure is as follows: + +```javascript {8-11} title="{case}.js" +interface TDefaultsCaseConfig { + description: string; // Description of the test case + cwd?: string; // process.cwd for generating the build configuration of the test case, default is the `rspack-test-tools` directory + options?: (context: ITestContext) => TCompilerOptions; // Test case build configuration + diff: (diff: jest.JestMatchers, defaults: jest.JestMatchers>) => Promise; // Differences from the default configuration +} + +/** @type {import('../..').TDefaultsCaseConfig} */ +module.exports = { + // ... +}; +``` + +The details for the Error test are as follows: + +## Error + +| Entry File | `Error.test.js` | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | [`tests/errorCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/errorCases) | +| Output Directory | None | +| Default Configuration | [ErrorProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/error.ts#L84) | +| Run Output | No | + +This test uses `rspack-test-tools/tests/fixtures` as the source code for the build, so the test case is written as a single file. Its structure is as follows: + +```javascript {8-11} title="{case}.js" +interface TErrorCaseConfig { + description: string; // Description of the test case + options?: (options: TCompilerOptions, context: ITestContext) => TCompilerOptions; // Test case configuration + build?: (context: ITestContext, compiler: TCompiler) => Promise; // Test case build method + check?: (stats: TStatsDiagnostics) => Promise; // Function to check the test case +} + +/** @type {import('../..').TErrorCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Hook + +| Entry File | `Hook.test.js` | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------ | +| Case Directory | [`tests/hookCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hookCases) | +| Output Directory | None | +| Default Configuration | [HookProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/hook.ts#L190) | +| Run Output | No | + +This test records the input and output of the hook and stores it in the snapshot `hooks.snap.txt`. The snapshot of the final product code is stored in `output.snap.txt`. + +This test uses `rspack-test-tools/tests/fixtures` as the source code for the build, so the test case is written as a single file. Its structure is as follows: + +```javascript {8-11} title="{case}/test.js" +interface THookCaseConfig { + description: string; // Description of the test case + options?: (options: TCompilerOptions, context: ITestContext) => TCompilerOptions; // Test case configuration + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; // Callback after creating the compiler instance + check?: (context: ITestContext) => Promise; // Callback after the build is completed +} + +/** @type {import("../../../..").THookCaseConfig} */ +module.exports = { + // ... +}; +``` + +## TreeShaking + +| Entry File | `TreeShaking.test.js` | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | `tests/treeShakingCases` | +| Output Directory | `tests/js/treeShaking` | +| Default Configuration | [TreeShakingProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/treeshaking.ts#L19) | +| Run Output | No | + +In this test case, the configuration is similar to a regular rspack project. You can specify the build configuration by adding a `rspack.config.js`, but the final product is snapshot and stored in `__snapshots__/treeshaking.snap.txt`. + +## Builtin + +| Entry File | `Builtin.test.js` | +| --------------------- | ----------------------------------------------------------------------------------------------------------------------------- | +| Case Directory | `tests/builtinCases` | +| Output Directory | `tests/js/builtin` | +| Default Configuration | [BuiltinProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/builtin.ts#L27) | +| Run Output | No | + +This test case is similar to a regular rspack project, and you can specify the build configuration by adding a `rspack.config.js`. However, depending on the directory, different snapshots of the products will be generated and stored in `__snapshots__/output.snap.txt`: + +- **plugin-css**: Snapshots of files with a `.css` extension +- **plugin-css-modules**: Snapshots of files with `.css` and `.js` extensions +- **plugin-html**: Snapshots of files with `.html` extension +- **Other**: Snapshots of files with `.js` extension diff --git a/website/docs/en/contribute/development/testing-webpack.mdx b/website/docs/en/contribute/development/testing-webpack.mdx new file mode 100644 index 000000000000..dc13665bf0dc --- /dev/null +++ b/website/docs/en/contribute/development/testing-webpack.mdx @@ -0,0 +1,61 @@ +# Testing Webpack + +## Testing Webpack Cases + +> **Note**: The `rspack/webpack-test` is heavily based on [webpack/test](https://github.com/webpack/webpack/tree/main/test) + +### Progressively migrate webpack test + +Originally, we use this formula to calculate the compatibility `passedTestCaseCount / totalTestCount`, totalTestCount = passedTestCaseCount + failedTestCount + skippedTestCount , but sometimes it maybe hard to compatible with all webpack test cases for some reasons (e.g. performance, legacy feature that we don't want to support), we need a method to skip these tests that we will not support. Thus, we adjust the original formula to `(passedTestCaseCount + willNotSupportTestCount) / totalTestCount`. + +Currently, we use a `test.filter.js` under each failed test case directory to skip failed test case, using this method could let us migrate webpack test case progressively without affect the real compatibility (Because this method will not influence the real `passedTestCaseCount`). + +e.g. + +```js +// test.filter.js +module.exports = () => { + return false; // false means this testcase is skipped for now, but maybe we will support in the future, `-1` means this test case we don't want to compatible with, this related to `willNotSupportTest`. +}; +``` + +When you find that we have passed some failed testcases which is skipped for now, you could change the `test.filter.js` to + +```js +module.exports = () => { + return true; +}; +``` + +or delete the `test.filter.js` + +## Testing Webpack Plugins Cases + +Based on implementation differences and performance considerations, Rspack will integrate some Webpack plugins internally. The test suite for the plugins will also be copied to the `plugin-test` folder for testing plugin compatibility. + +Therefore, in order to maintain consistency with the original repository, it is not recommended to modify these test cases, except in the following scenarios: + +- When a new Webpack plugin is integrated into Rspack, the test cases for that plugin need to be copied. +- When there are differences between the artifacts of Rspack and Webpack (e.g., different hashes), some test cases may need modification. + +In scenarios other than those mentioned above, please follow the [Rspack Testing](./testing-rspack) guidelines for adding test cases. + +### Running Tests + +You can run these test cases in the following ways: + +- Run `./x test plugin` or `pnpm run test:plugin` in the root directory. +- Or run `npm run test` in the `rspack/plugin-test` directory. +- To update snapshots, run `npm run test -- -u` in the `plugin-test` directory. +- To pass specific jest cli parameters, run `npm run test -- {args}` in the `plugin-test` directory. + +### Adding Test Cases + +1. Create a `plugin-test/{plugin-name}` folder and copy the test cases for that plugin into the folder. +2. Adapt the test configuration in `plugin-test/jest.config.js`. If there are special configurations, follow the process below: + 1. Create `plugin-test/jest.{plugin-name}.config.js`, import `jest.config.js`, and modify it based on that. + 2. Add the `test:{plugin-name}` command to the `scripts` property of `plugin-test/package.json`. + 3. If snapshot testing is included, use the `global.updateSnapshot` to determine whether to update the snapshot. +3. Update License information: + 1. Add a `plugin-test/{plugin-name}/README.md` file and include the License information from the source repository of the test cases. + 2. Update the `plugin-test/README.md` file to include the link and credits information from the source repository of the test cases. diff --git a/website/docs/en/contribute/development/testing.md b/website/docs/en/contribute/development/testing.md deleted file mode 100644 index 675ab1b5b9ea..000000000000 --- a/website/docs/en/contribute/development/testing.md +++ /dev/null @@ -1,149 +0,0 @@ -# Testing - -We currently have two sets of test suites, one for Rust and one for Node.js. - -## Rust Testing - -- `cargo test` will run all the rust side tests, which includes standalone tests for core functionality and plugins. -- `UPDATE=1 cargo test` will automatically update the failed snapshot - -## Node Testing - -We are maintaining two test suites for Node Testing in Rspack, Rspack Testing and Webpack Testing - -### Webpack Testing - -We copy the whole webpack test suites into [webpack-test](https://github.com/web-infra-dev/rspack/tree/main/webpack-test#progressively-migrate-webpack-test) folder to check the compatibility with webpack. If you add features or fix bugs we recommend you check whether this feature or bug is covered in webpack test suites first. If it's covered and testable in Webpack Testing, you can enable specific test case by setting return value to true in [`test.filter.js`](https://github.com/web-infra-dev/rspack/blob/80e97477483fcb912473ae339c37d5a5e247f7b1/webpack-test/cases/compile/error-hide-stack/test.filter.js#L2C33-L2C84) in this case folder to enable this case. See more details in https://github.com/web-infra-dev/rspack/blob/main/webpack-test/README.md, Please note that don't modify original test code in Webpack Testing, if you find difficulties in running test suites without modifying original code, you can copy this test code in the following \[Rspack Testing\](#Rspack Testing). - -#### Run Tests - -```sh -# In root path -./x build -a # build binding and js part -./x test webpack # run webpack test suites -``` - -### Rspack Testing - -We maintain test suites in Rspack Testing which is not coverable or need to be modified in Webpack Testing. The test suites lies in [rspack-test](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack/tests). This folder structure is similar with Webpack Testing. - -#### Run Tests - -```sh -# In root path -./x build -a -./x test js -``` - -Or only test the package that you made the changes: - -```sh -# In the Node.js package path -pnpm run build && pnpm run test -``` - -To update snapshots: - -```sh -pnpm --filter '@rspack/*' test -- -u -``` - -### Node Testing Suite Overview - -We use jest for Node.js tests, The most important test cases are the case in the `packages/rspack`. most of these cases comes from webpack https://github.com/webpack/webpack/tree/main/test because we want to make sure that Rspack can work as same as webpack. - -There are three kinds of integration cases in `@rspack/core`. - -#### case.test.ts - -Cases are used to test normal build behavior, we use these cases to test against bundler core functionality, like `entry`, `output`, `module` `resolve`, etc. it will first build your test file to test whether the input could be compiled successfully, then it will use the bundled test file to run test cases in the test file to test bundler's all kinds of behavior. - -#### configCase.test.ts - -Cases are used to test custom build behavior, you could use custom `webpack.config.js` to override default build behavior, you can use these cases to test against behavior related to specific config. - -##### statsTestCase.test.ts - -Cases are used to test your stats, By Default we will use jest's snapshot to snapshot your stats, and we **highly** recommend to **avoid** snapshot except statsCase. you can use statsCase to test behaviors like code splitting | bundle splitting, which is hard to test by just running code. - -## E2E - -The `packages/playground` provides e2e testing feature. We use [playwright](https://github.com/Microsoft/playwright) as the e2e testing framework. - -### Cases - -The entry point of a test case is a file ending with `.test.ts`, and the parent directory of this file is the project directory. - -Here are some rules about test cases: - -- The project directory must contain `rspack.config.js` to start the dev server. -- The project directory can contain multi `*.test.ts`. -- All test cases share dependencies, so just add dependencies in `packages/playground/package.json`. -- The cases folder should contain the category folders and then is the project folders. In principle, there should be no third-level directory. - -### Fixtures - -The `fixtures` is a feature of playwright, in short it provides a variable that is generated in before{Each|All} and destroyed in after{Each|All}. More information see [test-fixtures](https://playwright.dev/docs/test-fixtures) - -Here are some rules when defining a new fixture: - -- Private fixtures should start with `_` and are used only in the current file. -- A file only provides fixtures with the same name. -- A file can only provide one option and starts with `default` -- Register fixtures in `fixtures/index.ts` and export only necessary variables and types. - -Here are some existing fixtures: - -#### pathInfo - -This fixture will generate test environment, and calculate the PathInfo. - -```ts -type PathInfo = { - // test file path - testFile: string; - // project dir - testProjectDir: string; - // temporary project directory to be copied into - tempProjectDir: string; -}; -``` - -#### rspack - -This fixture will start the rspack dev server and provide some useful methods. - -```ts -type Rspack = { - // rspack running project directory - projectDir: string; - // rspack compiler - compiler: Compiler; - // rspack dev server - devServer: DevServer; - // waiting for rspack build finish - waitingForBuild: () => Promise; - // waiting for hmr finish, the poll function is used to check - waitingForHmr: (poll: () => Promise) => Promise; -}; -``` - -#### fileAction - -This fixture will provide file change operations. - -```ts -type fileAction = { - updateFile(relativePath: string, fn: (content: string) => string): void; - deleteFile(relativePath: string): void; -}; -``` - -### How it works - -- playwright scan all test case and allocates a worker to run each case. -- `pathInfo` copy the project directory corresponding to the current case to `temp/${worker_index}`. -- `rspack` rewrite dev server port to `8000 + worker_index` and start compiler and dev server in `temp/${worker_index}`. -- run current tests. -- `rspack` close dev server and compiler. -- `pathInfo` clear `temp/${worker_index}` diff --git a/website/docs/en/contribute/development/testing.mdx b/website/docs/en/contribute/development/testing.mdx new file mode 100644 index 000000000000..1c51858e035f --- /dev/null +++ b/website/docs/en/contribute/development/testing.mdx @@ -0,0 +1,77 @@ +# Testing + +Because Rspack uses a mix of Rust and Node.js code, different testing strategies are used for each. + +## Rust Testing + +:::info Tip +Rust test cases are only suitable for unit testing. To test the complete build process, please add Node.js test cases. +::: + +### Running Rust Tests + +You can run the Rust code's test cases using `./x test rust` or `cargo test`. + +### Writing Rust Tests + +Test cases are written within the Rust code. For example: + +```rust +fn add(a: u8, b: u8) -> u8 { + a + b +} + +#[test] +fn test_add() { + assert_eq!(add(1, 2), 3); +} +``` + +> For more information, please refer to: [Rust: How to Write Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) + +## Node.js Testing + +Node.js testing provides three test suites: + +- **Webpack Testing**: Running Webpack test cases using Rspack +- **Webpack Plugin Testing**: Running test cases of native supported plugins using Rspack +- **Rspack Testing**: Running test cases of Rspack itself + +### Webpack Testing + +Rspack copied the whole Webpack test suite to the `webpack-test` folder to check the compatibility of webpack. If you need to add new test cases, it is recommended to first check if the case has been exists in this folder. You can enable a test case by removing the `test.filter.js` file or modifying its return value to `true`. + +You can run Webpack tests by running `./x test webpack` or `pnpm run test:webpack` at the root folder. + +:::warning Notice +If you encounter any problems, please do not modify the original code of the Webpack test cases. You can copy it and follow the [Rspack Testing](./testing-rspack) to create new test cases in `packages/rspack-test-tools/tests`. +::: + +> For more details, please refer to: [Webpack Testing](./testing-webpack#testing-webpack-cases). + +### Rspack Testing + +Rspack's test cases are stored in the `packages/rspack-test-tools/tests` folder, including unique test cases and cases that require modification for Webpack and Webpack plugins. + +You can run Rspack tests by running `./x test unit` or `pnpm run test:unit` at the root folder. + +You can also go to the `packages/rspack-test-tools` folder and run `npm run test` to run test cases and add some arguments: + +- **When refreshing test snapshots is needed**: Add `-u`, like `npm run test -- -u` +- **When filtering test cases is needed**: Add `-t`, like `npm run test -- -t config/asset` to only run test cases from the `packages/rspack-test-tools/configCases/asset` folder (`config` will be automatically mapped to `configCases`, and other folders work similarly). Pattern matching supports regex, see [jest](https://jestjs.io/docs/cli#--testnamepatternregex) for details. + +> For more details, please refer to: [Rspack Testing](./testing-rspack). + +### Webpack Plugin Testing + +Due to implementation differences and performance considerations, Rspack will internally support some Webpack plugins. Similarly, the test suites for these plugins are copied to the `plugin-test` folder to test the compatibility of the plugins. + +You can run Webpack plugin tests by running `./x test plugin` or `pnpm run test:plugin` at the root folder. + +:::warning Notice +In most cases, even if you modify the functionality of the corresponding plugin, you only need to follow [Rspack Testing](./testing-rspack) to add new test cases. + +Only when you native implement a new Webpack plugin and need to copy its test cases, you can add them to this suite. +::: + +> For more details, please refer to: [Webpack Plugin Testing](./testing-webpack#testing-webpack-plugins-cases). diff --git a/website/docs/zh/contribute/development/testing-rspack.mdx b/website/docs/zh/contribute/development/testing-rspack.mdx new file mode 100644 index 000000000000..2213878ac2c4 --- /dev/null +++ b/website/docs/zh/contribute/development/testing-rspack.mdx @@ -0,0 +1,403 @@ +# Rspack 测试 + +Rspack 的测试用例包括如下: + +- Rspack 核心测试用例,存放在 `packages/rspack-test-tools/tests` 文件夹下,会通过模拟构建流程以运行测试用例。通常情况下,都在此文件夹下添加测试用例。 +- Rspack 其他包的测试用例,存放在 `packages/{name}/tests` 文件夹下,仅当修改对应包时添加/修改。 + +## 运行测试 + +可以通过如下方式运行这些测试用例: + +- 根目录下运行 `./x test unit` 或 `pnpm run test:unit`。 +- 或在 `packages/rspack-test-tools` 目录下运行 `npm run test`。 +- 如需更新 snapshot,在 `packages/rspack-test-tools` 目录下运行 `npm run test -- -u`。 +- 如需传入特定 jest cli 参数,在 `packages/rspack-test-tools` 目录下运行 `npm run test -- {args}`。 + +## 目录规范 + +文件夹 `packages/rspack-test-tools/tests` 的结构如下所示: + +```bash +. +├── js #用于存放构建生成的产物和临时文件 +├── __snapshots__ #用于存放测试快照 +├── {Name}.test.js #常规测试的入口 +├── {Name}.hottest.js #热更新流程测试入口 +├── {Name}.difftest.js #产物对比测试入口 +├── {name}Cases #测试用例存放目录 +└── fixtures #通用测试文件 +``` + +`{Name}.test.js` 作为测试的入口文件,会遍历 `{name}Cases` 并运行其中的用例。因此当您需要添加/修改测试用例时,请根据需要测试的功能类型在相应的 `{name}Cases` 文件夹下添加用例。 + +## 测试类型 + +目前已有的测试类型有: + +- [Normal](#normal):用于测试配置无关的核心构建流程。当您的测试无需添加 `rspack.config.js` 时可使用此测试类型。 +- [Config](#config):用于测试构建配置项。如果你的测试需要通过 `rspack.config.js` 添加特定配置才可以运行时,且不符合其他场景时可使用此测试类型。 +- [Hot](#hot):用于测试 Hot Module Replacement(HMR)是否正确运行。HotNode 会固定使用 `target=async-node`,HotWeb 会固定使用 `target=web`,HotWorker 会固定使用 `target=webworker`。 +- [HotSnapshot](#hotsnapshot):用于测试 Hot Module Replacement(HMR) 能否生成正确的中间产物。与[Hot](#Hot)类型测试共用测试用例。 +- [Watch](#watch):用于测试 Watch 模式下修改文件后的增量编译。 +- [StatsOutput](#statsoutput):用于测试构建结束后控制台输出的日志。 +- [StatsAPI](#stats-api):用于测试构建结束后生成的 Stats 对象。 +- [Diagnostic](#diagnostic):用于测试构建过程中产生的警告/错误的格式化输出信息。 +- [Hash](#hash):用于测试 Hash 能否正确生成。 +- [Compiler](#compiler):用于测试 Compiler/Compilation 对象的 API。 +- [Defaults](#defaults):用于测试配置项之间的联动。 +- [Error](#error):用于测试 `compilation.errors` 和 `compilation.warnings` 的互操作。 +- [Hook](#hook):用于测试各种 hook 能否正确工作。 +- [TreeShaking](#treeshaking):用于测试 Tree Shaking 相关功能。 +- [Builtin](#builtin):用于测试内置原生实现的插件。 + +请优先在以上测试类型中添加用例。{/* 如果没有符合的类型,请按照[添加测试类型](./test-advanced)添加新类型。 */} + +## Normal + +| 测试入口 | `tests/Normal.test.js` | +| -------- | --------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/normalCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/normalCases) | +| 产物目录 | `tests/js/normal` | +| 默认配置 | [NormalProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/normal.ts#L35) | +| 产物运行 | `是` | + +用例的编写与常规的 rspack 项目相同,但不包含 `rspack.config.js` 文件,会使用固定的配置构建。 + +## Config + +| 测试入口 | `tests/Config.test.js` | +| -------- | --------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/configCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/configCases) | +| 产物目录 | `tests/js/config` | +| 默认配置 | [ConfigProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/config.ts#L51) | +| 产物运行 | `是` | + +此测试用例与常规的 rspack 项目相同,可通过添加 `rspack.config.js` 来指定构建配置,并可通过添加 `test.config.js` 来控制测试运行时的各种行为,其结构如下: + +```typescript {16-20} title="test.config.js" +type TConfigCaseConfig = { + noTest?: boolean; // 不运行测试产物并结束测试 + beforeExecute?: () => void; // 运行产物前回调 + afterExecute?: () => void; // 运行产物后回调 + moduleScope?: (ms: IBasicModuleScope) => IBasicModuleScope; // 运行产物时的模块上下文变量 + findBundle?: ( + // 运行产物时的产物获取函数,可以更细粒度的控制产物 + index: number, // muli compiler 场景时的 compiler 序号 + options: TCompilerOptions, // 构建配置对象 + ) => string | string[]; + bundlePath?: string[]; // 运行产物时的产物文件名称(优先级低于 findBundle) + nonEsmThis?: (p: string | string[]) => Object; // CJS 产物运行时的 this 对象,若不指定则默认为当前模块的 module.exports + modules?: Record; // 运行产物时预先添加的模块,require 时会优先从此处读取 + timeout?: number; // 用例的超时时间 +}; + +/** @type {import("../../../..").TConfigCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Hot + +| 测试入口 | `Hot{Target}.test.js` | +| -------- | --------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/hotCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hotCases) | +| 产物目录 | `tests/js/hot-{target}` | +| 默认配置 | [HotProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/hot.ts#L86) | +| 产物运行 | `是` | + +此测试用例与常规的 rspack 项目相同,可通过添加 `rspack.config.js` 来指定构建配置,但需要额外在用例目录下添加 `changed-file.js` 来指定变更的文件,如下所示: + +```js title="changed-file.js" +const path = require('path'); +module.exports = [ + path.resolve(__dirname, './file.js'), // file.js 变化并触发热更新 +]; +``` + +对应的在变更的文件内通过 `---` 分割变更前后的代码: + +```js file.js title="file.js" +module.exports = 1; // 初始构建 +--- +module.exports = 2; // 首次热更新 +--- +module.exports = 3; // 第二次热更新 +``` + +在用例的代码中,通过 `NEXT` 方法控制文件变更时机,并在其中添加测试代码: + +```js title="index.js" +import value from './file'; + +it('should hot update', done => { + expect(value).toBe(1); + // 使用 packages/rspack-test-tools/tests/hotCases/update.js 触发更新 + NEXT( + require('../../update')(done, true, () => { + expect(value).toBe(2); + NEXT( + require('../../update')(done, true, () => { + expect(value).toBe(3); + done(); + }), + ); + }), + ); +}); + +module.hot.accept('./file'); +``` + +## HotSnapshot + +| 测试入口 | `HotSnapshot.hottest.js` | +| -------- | --------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/hotCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hotCases) | +| 产物目录 | `tests/js/hot-snapshot` | +| 默认配置 | 与 Hot 相同 | +| 产物运行 | `是` | + +与 `Hot{Target}` 测试使用相同的测试用例。并在用例文件夹下生成 `__snapshots__/{target}/{step}.snap.txt` 文件,用于对每一次 HMR 的增量产物进行 snapshot 测试。 + +Snapshot 结构如下: + +- **Changed Files**:引发本次 HMR 构建的源码文件 +- **Asset Files**:本次 HMR 构建的产物文件 +- **Manifest**:本次 HMR 构建的 `hot-update.json` 元数据文件内容,其中 + - `"c"`:本次 HMR 需要更新的 chunk 的 id + - `"r"`:本次 HMR 需要移除的 chunk 的 id + - `"m"`:本次 HMR 需要移除的 module 的 id +- **Update**:本次 HMR 构建的 `hot-update.js` 补丁文件信息,其中: + - **Changed Modules**:补丁中包含的模块列表 + - **Changed Runtime Modules**:补丁中包含的 runtime 模块列表 + - **Changed Content**:补丁代码的快照 + +## Watch + +| 入口文件 | `Watch.test.js` | +| -------- | ------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/watchCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/watchCases) | +| 产物目录 | `tests/js/watch` | +| 默认配置 | [WatchProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/watch.ts#L99) | +| 产物运行 | `是` | + +由于 Watch 构建需要分多步进行,可通过添加 `rspack.config.js` 来指定构建配置。其用例的目录结构较为特殊,会以自增的数字表示变更批次: + +```bash title="用例目录" +. +├── 0 # WATCH_STEP=0,用例初始代码 +├── 1 # WATCH_STEP=1,第一次变更的差异文件 +├── 2 # WATCH_STEP=2,第二次变更的差异文件 +└── rspack.config.js +``` + +同时在测试的代码中,可以通过 `WATCH_STEP` 变量获取当前的变更批次数字。 + +## StatsOutput + +| 测试入口 | `StatsOutput.test.js` | +| -------- | ------------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/statsOutputCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/statsOutputCases) | +| 产物目录 | `tests/js/statsOutput` | +| 默认配置 | [StatsProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/stats.ts#L190) | +| 产物运行 | `否` | + +用例的编写与常规的 rspack 项目相同,运行后会将控制台输出信息生成快照并存放在 `rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap` 中。 + +:::info Tip +由于部分 StatsOutput 测试用例包含 hash。因此当你修改了产物代码时,请通过 `-u` 参数刷新这些用例的快照。 +::: + +## Stats API + +| 入口文件 | `StatsAPI.test.js` | +| -------- | --------------------------------------------------------------------------------------------------------------- | +| 用例目录 | `tests/statsAPICases` | +| 产物目录 | `无` | +| 默认配置 | [`无`](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/stats-api.ts) | +| 产物运行 | `否` | + +此测试固定使用 `rspack-test-tools/tests/fixtures` 作为构建的源码,因此用例以单文件编写,其输出结构如下: + +```js {8-11} title="{case}.js" +type TStatsAPICaseConfig = { + description: string; // 用例描述 + options?: (context: ITestContext) => TCompilerOptions; // 用例构建配置 + build?: (context: ITestContext, compiler: TCompiler) => Promise; // 用例构建方式 + check?: (stats: TCompilerStats, compiler: TCompiler) => Promise; // 用例的 stats 检测函数 +} + +/** @type {import('../..').TStatsAPICaseConfig} */ +module.exports = { + // ... +} +``` + +## Diagnostic + +| 入口文件 | `Diagnostics.test.js` | +| -------- | ----------------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/diagnosticsCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/diagnosticsCases) | +| 产物目录 | `tests/js/diagnostics` | +| 默认配置 | [DiagnosticProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/diagnostic.ts#L71) | +| 产物运行 | `否` | + +此测试用例与常规的 rspack 项目相同,可通过添加 `rspack.config.js` 来指定构建配置,但额外会在用例目录下添加 `stats.err` 文件用于存储警告/错误的快照,如需刷新请使用 `-u` 参数。 + +## Hash + +| 入口文件 | `Hash.test.js` | +| -------- | ----------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/hashCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hashCases) | +| 产物目录 | `无` | +| 默认配置 | [HashProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/hash.ts#L53) | +| 产物运行 | `否` | + +此测试用例与常规的 rspack 项目相同,但额外会在用例目录下添加 `test.config.js` 文件,并指定 `validate()` 方法用于在构建结束后检测 stats 对象中的 hash 信息: + +```js {5-8} title="test.config.js" +type THashCaseConfig = { + validate?: (stats: TCompilerStats) => void; +}; + +/** @type {import('../..').THashCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Compiler + +| 入口文件 | `Compiler.test.js` | +| -------- | ------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/compilerCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/compilerCases) | +| 产物目录 | `无` | +| 默认配置 | [`无`](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/simple.ts) | +| 产物运行 | `否` | + +此测试固定使用 `rspack-test-tools/tests/fixtures` 作为构建的源码,因此用例以单文件编写,其输出结构如下: + +```js {9-12} title="{case.js}" +interface TCompilerCaseConfig { + description: string; // 用例描述 + options?: (context: ITestContext) => TCompilerOptions; // 用例构建配置 + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; // 用例 compiler 创建方式 + build?: (context: ITestContext, compiler: TCompiler) => Promise; // 用例构建方式 + check?: (context: ITestContext, compiler: TCompiler, stats: TCompilerStats) => Promise; // 用例的检测函数 +} + +/** @type {import('../..').TCompilerCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Defaults + +| 入口文件 | `Defaults.test.js` | +| -------- | ----------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/defaultCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/defaultCases) | +| 产物目录 | `无` | +| 默认配置 | [`无`](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/defaults.ts) | +| 产物运行 | `否` | + +此测试不会执行真实的构建,仅会生成构建配置并观察与默认配置的差异。基础的默认配置会生成快照并存放在 `rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap` 中。 + +此测试固定使用 `rspack-test-tools/tests/fixtures` 作为构建的源码,因此用例以单文件编写,其输出结构如下: + +```js {8-11} title="{case}.js" +interface TDefaultsCaseConfig { + description: string; // 用例描述 + cwd?: string; // 用例的生成构建配置时的 process.cwd,默认为 `rspack-test-tools` 目录 + options?: (context: ITestContext) => TCompilerOptions; // 用例构建配置 + diff: (diff: jest.JestMatchers, defaults: jest.JestMatchers>) => Promise; // 与默认配置之间的差异 +} + +/** @type {import('../..').TDefaultsCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Error + +| 入口文件 | `Error.test.js` | +| -------- | ------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | [`tests/errorCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/errorCases) | +| 产物目录 | `无` | +| 默认配置 | [ErrorProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/error.ts#L84) | +| 产物运行 | `否` | + +此测试的用例固定使用 `rspack-test-tools/tests/fixtures` 作为构建的源码,因此测试用例以特定的配置结构编写: + +```js {8-11} title="{case}.js" +interface TErrorCaseConfig { + description: string; // 用例描述 + options?: (options: TCompilerOptions, context: ITestContext) => TCompilerOptions; // 用例配置 + build?: (context: ITestContext, compiler: TCompiler) => Promise; // 用例构建方式 + check?: (stats: TStatsDiagnostics) => Promise; // 用例的检测函数 +} + +/** @type {import('../..').TErrorCaseConfig} */ +module.exports = { + // ... +}; +``` + +## Hook + +| 入口文件 | `Hook.test.js` | +| -------- | ------------------------------------------------------------------------------------------------------------------------ | +| 用例目录 | [`tests/hookCases`](https://github.com/web-infra-dev/rspack/tree/main/packages/rspack-test-tools/tests/hookCases) | +| 产物目录 | `无` | +| 默认配置 | [HookProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/hook.ts#L190) | +| 产物运行 | `否` | + +会记录 hook 的出入参并存放在快照 `hooks.snap.txt` 中,最终产物代码的快照存放在 `output.snap.txt` 中。 + +此测试的用例固定使用 `rspack-test-tools/tests/fixtures` 作为构建的源码,因此测试用例以特定的配置结构编写: + +```js {8-11} title="{case}/test.js" +interface THookCaseConfig { + description: string; // 用例描述 + options?: (options: TCompilerOptions, context: ITestContext) => TCompilerOptions; // 用例配置 + compiler?: (context: ITestContext, compiler: TCompiler) => Promise; // 创建 compiler 实例后回调 + check?: (context: ITestContext) => Promise; // 构建完成后回调 +} + +/** @type {import("../../../..").THookCaseConfig} */ +module.exports = { + // ... +}; +``` + +## TreeShaking + +| 入口文件 | `TreeShaking.test.js` | +| -------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | `tests/treeShakingCases` | +| 产物目录 | `tests/js/treeShaking` | +| 默认配置 | [TreeShakingProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/treeshaking.ts#L19) | +| 产物运行 | `否` | + +此测试用例与常规的 rspack 项目相同,可通过添加 `rspack.config.js` 来指定构建配置,但会将最终产物生成快照并存放在 `__snapshots__/treeshaking.snap.txt` 中。 + +## Builtin + +| 入口文件 | `Builtin.test.js` | +| -------- | ----------------------------------------------------------------------------------------------------------------------------- | +| 用例目录 | `tests/builtinCases` | +| 产物目录 | `tests/js/builtin` | +| 默认配置 | [BuiltinProcessor](https://github.com/web-infra-dev/rspack/blob/main/packages/rspack-test-tools/src/processor/builtin.ts#L27) | +| 产物运行 | `否` | + +此测试用例与常规的 rspack 项目相同,可通过添加 `rspack.config.js` 来指定构建配置。 + +但根据目录的不同,会将不同的产物生成快照并存放在 `__snapshots__/output.snap.txt` 中: + +- **plugin-css**:将 `.css` 后缀文件生成快照 +- **plugin-css-modules**:将 `.css` 和 `.js` 后缀文件生成快照 +- **plugin-html**:将 `.html` 后缀文件生成快照 +- **其他**:将 `.js` 后缀文件生成快照 diff --git a/website/docs/zh/contribute/development/testing-webpack.mdx b/website/docs/zh/contribute/development/testing-webpack.mdx new file mode 100644 index 000000000000..dde7b28b4794 --- /dev/null +++ b/website/docs/zh/contribute/development/testing-webpack.mdx @@ -0,0 +1,62 @@ +# Webpack 测试 + +## 运行 Webpack 用例 + +> **注意**: `rspack/webpack-test` 完全基于 [webpack/test](https://github.com/webpack/webpack/tree/main/test) + +### **持续迁移 webpack 测试** + +在迁移 webpack 测试的过程中,我们使用以下公式来计算兼容性:`passedTestCaseCount / totalTestCount`,其中 `totalTestCount = passedTestCaseCount + failedTestCount + skippedTestCount`。 + +但是有时由于一些原因(例如性能、部分历史遗留功能),可能很难与所有的 webpack 测试用例保持兼容。因此,我们需要一种方法来跳过这些不希望支持的测试用例。我们将原始公式调整为 `(passedTestCaseCount + willNotSupportTestCount) / totalTestCount`。 + +目前,可在用例目录下添加 `test.filter.js` 文件,用于跳过失败的测试用例。使得我们可以逐步迁移 webpack 测试用例,而不影响实际的兼容性(因为这种方法不影响真实的 `passedTestCaseCount`)。 + +例如: + +```javascript title="test.filter.js" +module.exports = () => { + return false; // false 表示当前测试用例暂时被跳过,但也许我们将来会支持它;-1 表示我们不希望兼容这个测试用例,这与 `willNotSupportTest` 相关。 +}; +``` + +如果您发现测试用例已可以通过,那么将 `test.filter.js` 更改为: + +```javascript title="test.filter.js" +module.exports = () => { + return true; +}; +``` + +或者直接删除 `test.filter.js` 文件。 + +## 运行 Webpack 插件用例 + +基于实现差异和性能考虑,Rspack 会将部分 Webpack 生态插件内置。同样会将插件的测试套件复制到 `plugin-test` 文件夹下,用于测试插件的兼容性。 + +因此,为了保持这些测试用例与其原仓库的一致性,不建议对测试用例进行修改,仅当如下场景满足时可变更: + +- 在 Rspack 中内置了新的 Webpack 生态插件,此时需要复制该插件的用例。 +- 因 Rspack 与 Webpack 的产物差异(如 hash 不同),需要修改部分用例。 + +非以上场景时,请遵循 [Rspack 测试](./testing-rspack) 添加测试用例 + +### 运行测试 + +可以通过如下方式运行这些测试用例: + +- 根目录下运行 `./x test plugin` 或 `pnpm run test:plugin`。 +- 或在 `plugin-test` 目录下运行 `npm run test`。 +- 如需更新 snapshot,在 `plugin-test` 目录下运行 `npm run test -- -u`。 +- 如需传入特定 jest cli 参数,在 `plugin-test` 目录下运行 `npm run test -- {args}`。 + +### 添加用例 + +1. 建立 `plugin-test/{插件名}` 文件夹,并将该插件的测试用例复制到该文件夹中。 +2. 适配 `plugin-test/jest.config.js` 中的测试配置,如有特殊配置遵循如下流程: + 1. 建立 `plugin-test/jest.{plugin-name}.config.js`,引入 `jest.config.js` 并在其基础上修改。 + 2. 在 `plugin-test/package.json` 的 `scripts` 中添加 `test:{plugin-name}` 命令 + 3. 如包含 snapshot 测试,使用 `global.updateSnapshot` 全局变量判断是否刷新 snapshot +3. 更新 License 信息: + 1. 添加 `plugin-test/{插件名}/README.md` 文件,添加测试用例来源仓库的 License 信息。 + 2. 更新 `plugin-test/README.md` 文件,添加测试用例来源仓库的链接和感谢信息。 diff --git a/website/docs/zh/contribute/development/testing.mdx b/website/docs/zh/contribute/development/testing.mdx new file mode 100644 index 000000000000..c42ecbf766ef --- /dev/null +++ b/website/docs/zh/contribute/development/testing.mdx @@ -0,0 +1,77 @@ +# 测试 + +由于 Rspack 使用 Rust + TypeScript 代码混合编写,因此会针对两者使用不同的测试方案。 + +## Rust 测试 + +:::info Tip +Rust 测试仅适用于原子功能的单元测试,无法测试完整构建流程。如需测试完整构建流程,请编写 Node 测试用例 +::: + +### 运行 Rust 测试 + +通过 `./x test rust` 或者 `cargo test` 可运行 Rust 代码中的测试用例。 + +### 编写 Rust 测试 + +用例编写在 Rust 代码内部,用于对当前文件内的函数提供单元测试。如: + +```rust +fn add(a: u8, b: u8) -> u8 { + a + b +} + +#[test] +fn test_add() { + assert_eq!(add(1, 2), 3); +} +``` + +> 更多信息请参考:[Rust: How to Write Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) + +## Node 测试 + +Node 测试提供了三组测试套件: + +- **Webpack 测试**:使用 Rspack 运行 Webpack 的测试用例 +- **Webpack Plugin 测试**:使用 Rspack 运行部分内置支持的 Webpack 插件的测试用例 +- **Rspack 测试**:运行 Rspack 自身的测试用例 + +### Webpack 测试 + +Rspack 将整个 Webpack 测试套件拷贝到 `webpack-test` 文件夹中,用于检查 webpack 的兼容性。 如果您需要添加新的用例,建议首先在这个文件夹下查找相应的用例是否存在。移除文件夹中的 `test.filter.js` 或修改其返回值为 `true` 即可启用该用例。 + +通过在根文件夹下运行 `./x test webpack` 或 `pnpm run test:webpack` 即可运行 Webpack 测试。 + +:::warning 注意 +如果您遇到问题,请不要修改 Webpack 用例的原始代码。你可以拷贝用例代码,并遵循 [Rspack 测试](./testing-rspack) 来创建新的用例。 +::: + +> 更多细节请参考:[Webpack 测试](./testing-webpack)。 + +### Rspack 测试 + +Rspack 的测试用例存放在在 `packages/rspack-test-tools/tests` 文件夹下,包括独有的测试用例,以及需要修改的 Webpack 和 Webpack 插件的用例。 + +通过在根文件夹下运行 `./x test unit` 或 `pnpm run test:unit` 即可运行 Rspack 测试。 + +也可以进入 `packages/rspack-test-tools` 文件夹并运行 `npm run test` 来运行测试用例,并且对测试流程进行更精细的控制: + +- **需要刷新测试快照时**:添加 `-u` 参数,如 `npm run test -- -u` +- **需要过滤测试用例时**:添加 `-t` 参数,如 `npm run test -- -t config/asset` 即可仅运行 `packages/rspack-test-tools/configCases/asset` 文件夹下的用例(`config` 会自动映射到 `configCases`,其他文件夹类似)。匹配支持正则,详见 [jest](https://jestjs.io/docs/cli#--testnamepatternregex) + +> 更多细节请参考:[Rspack 测试](./testing-rspack) + +### Webpack 插件测试 + +基于实现差异和性能考虑,Rspack 会将部分 Webpack 生态插件内置。同样会将插件的测试套件拷贝到 `plugin-test` 文件夹下,用于测试插件的兼容性。 + +通过在根文件夹下运行 `./x test plugin` 或 `pnpm run test:plugin` 即可运行 Webpack 插件测试。 + +:::warning 注意 +通常情况下,即使您修改了对应插件的功能,也仅需要遵循 [Rspack 测试](./testing-rspack) 来添加新的用例。 + +仅当您内置实现了新的 Webpack 插件并需要拷贝它的测试用例时,可将用例添加到此测试中。 +::: + +> 更多细节请参考:[Webpack 插件测试](./testing-webpack)。 From 3b67e0d7dad4bb019b2b14a0da1dc6b7c41310fb Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 17 May 2024 11:54:51 +0800 Subject: [PATCH 104/107] fix: change the data URI type in ModuleFederationPlugin (#6567) fix(mf): change the data URI type --- packages/rspack/src/container/ModuleFederationPlugin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rspack/src/container/ModuleFederationPlugin.ts b/packages/rspack/src/container/ModuleFederationPlugin.ts index cfc5c5c2f1c5..aa6841533547 100644 --- a/packages/rspack/src/container/ModuleFederationPlugin.ts +++ b/packages/rspack/src/container/ModuleFederationPlugin.ts @@ -186,6 +186,6 @@ function getDefaultEntryRuntime( )}`, compiler.webpack.Template.getFunctionContent(require("./default.runtime")) ].join("\n"); - // use "application/node" to use moduleType "javascript/auto" - return `data:application/node,${content}`; + // use "data:text/javascript" to use moduleType "javascript/auto" + return `data:text/javascript,${content}`; } From dfa01cf014446feb24aaa3bd6cbf393a64f3af83 Mon Sep 17 00:00:00 2001 From: jinrui Date: Fri, 17 May 2024 13:59:45 +0800 Subject: [PATCH 105/107] fix: module_executor keep make_failed_module (#6565) * fix: module_executor keep make_failed_module * test: add css recovery test * fix: ci --- .../src/compiler/make/repair/mod.rs | 8 ++-- .../src/compiler/module_executor/mod.rs | 1 + .../css/recovery/__snapshots__/web/0.snap.txt | 12 +++++ .../css/recovery/__snapshots__/web/2.snap.txt | 46 +++++++++++++++++++ .../hotCases/css/recovery/changed-file.js | 6 +++ .../tests/hotCases/css/recovery/index.css | 9 ++++ .../tests/hotCases/css/recovery/index.js | 14 ++++++ .../hotCases/css/recovery/rspack.config.js | 29 ++++++++++++ 8 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/0.snap.txt create mode 100644 packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt create mode 100644 packages/rspack-test-tools/tests/hotCases/css/recovery/changed-file.js create mode 100644 packages/rspack-test-tools/tests/hotCases/css/recovery/index.css create mode 100644 packages/rspack-test-tools/tests/hotCases/css/recovery/index.js create mode 100644 packages/rspack-test-tools/tests/hotCases/css/recovery/rspack.config.js diff --git a/crates/rspack_core/src/compiler/make/repair/mod.rs b/crates/rspack_core/src/compiler/make/repair/mod.rs index 42962f6966a6..31abb45d92ea 100644 --- a/crates/rspack_core/src/compiler/make/repair/mod.rs +++ b/crates/rspack_core/src/compiler/make/repair/mod.rs @@ -67,10 +67,10 @@ impl MakeTaskContext { // factorize_timer: logger.time_aggregate("module factorize task"), // build_timer: logger.time_aggregate("module build task"), module_graph_partial: artifact.module_graph_partial, - // ignore make_failed_xxx and diagnostics - make_failed_dependencies: Default::default(), - make_failed_module: Default::default(), - diagnostics: Default::default(), + + make_failed_dependencies: artifact.make_failed_dependencies, + make_failed_module: artifact.make_failed_module, + diagnostics: artifact.diagnostics, entry_dependencies: artifact.entry_dependencies, entry_module_identifiers: artifact.entry_module_identifiers, diff --git a/crates/rspack_core/src/compiler/module_executor/mod.rs b/crates/rspack_core/src/compiler/module_executor/mod.rs index 3415a80aaab9..927000542849 100644 --- a/crates/rspack_core/src/compiler/module_executor/mod.rs +++ b/crates/rspack_core/src/compiler/module_executor/mod.rs @@ -52,6 +52,7 @@ impl ModuleExecutor { let modules = std::mem::take(&mut make_artifact.make_failed_module); params.push(MakeParam::ForceBuildModules(modules)); } + make_artifact.diagnostics = Default::default(); make_artifact = if let Ok(artifact) = update_module_graph_with_artifact(compilation, make_artifact, params) { diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/0.snap.txt new file mode 100644 index 000000000000..ed715bc59fe0 --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/0.snap.txt @@ -0,0 +1,12 @@ +# Case recovery: Step 0 + +## Changed Files +- index.css + +## Asset Files +- Bundle: bundle.js + +## Manifest + + +## Update \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt new file mode 100644 index 000000000000..a3f288dbbd59 --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt @@ -0,0 +1,46 @@ +# Case recovery: Step 2 + +## Changed Files +- index.css + +## Asset Files +- Bundle: bundle.js +- Manifest: main.LAST_HASH.hot-update.json, size: 28 +- Update: main.LAST_HASH.hot-update.js, size: 201 + +## Manifest + +### main.LAST_HASH.hot-update.json + +```json +{"c":["main"],"r":[],"m":[]} +``` + + +## Update + + +### main.LAST_HASH.hot-update.js + +#### Changed Modules + + +#### Changed Runtime Modules +- webpack/runtime/get_full_hash + +#### Changed Content +```js +self["webpackHotUpdate"]('main', { + +},function(__webpack_require__) { +// webpack/runtime/get_full_hash +!function() { +__webpack_require__.h = function () { + return "CURRENT_HASH"; +}; + +}(); + +} +); +``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/changed-file.js b/packages/rspack-test-tools/tests/hotCases/css/recovery/changed-file.js new file mode 100644 index 000000000000..bdff8d634cbc --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/changed-file.js @@ -0,0 +1,6 @@ +// TODO: remove this file after cache. +const path = require('path'); + +module.exports = [ + path.resolve(__dirname, './index.css') +] diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/index.css b/packages/rspack-test-tools/tests/hotCases/css/recovery/index.css new file mode 100644 index 000000000000..d71595507d90 --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/index.css @@ -0,0 +1,9 @@ +body { + background-color: red; +} +--- +body {} {} {@} +--- +body { + background-color: yellow; +} diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/index.js b/packages/rspack-test-tools/tests/hotCases/css/recovery/index.js new file mode 100644 index 000000000000..c8295366634d --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/index.js @@ -0,0 +1,14 @@ +import "./index.css"; + +it("css recovery", done => { + NEXT( + require("../../update")( + err => { + expect(String(err)).toContain("Module build failed"); + NEXT(require("../../update")(done, true, () => done())); + }, + true, + () => done() + ) + ); +}); diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/rspack.config.js b/packages/rspack-test-tools/tests/hotCases/css/recovery/rspack.config.js new file mode 100644 index 000000000000..cf562915a5dc --- /dev/null +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/rspack.config.js @@ -0,0 +1,29 @@ +const { CssExtractRspackPlugin } = require("@rspack/core"); + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + entry: "./index.js", + mode: "development", + devtool: false, + module: { + rules: [ + { + test: /\.css$/, + use: [ + { + loader: CssExtractRspackPlugin.loader + }, + "css-loader" + ] + } + ] + }, + experiments: { + css: false + }, + plugins: [ + new CssExtractRspackPlugin({ + filename: "[name].css" + }) + ] +}; From ed8ec0c540ede638671562f9a08b36ca026b8254 Mon Sep 17 00:00:00 2001 From: jinrui Date: Fri, 17 May 2024 18:59:43 +0800 Subject: [PATCH 106/107] fix: finish_module_task skip self reference connection (#6570) --- crates/rspack_core/src/compiler/module_executor/ctrl.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/rspack_core/src/compiler/module_executor/ctrl.rs b/crates/rspack_core/src/compiler/module_executor/ctrl.rs index f2d97e66b3e2..a5047ba3dc9c 100644 --- a/crates/rspack_core/src/compiler/module_executor/ctrl.rs +++ b/crates/rspack_core/src/compiler/module_executor/ctrl.rs @@ -262,7 +262,10 @@ impl Task for FinishModuleTask { .connection_by_connection_id(connection_id) .expect("should have connection"); if let Some(original_module_identifier) = &connection.original_module_identifier { - original_module_identifiers.insert(*original_module_identifier); + // skip self reference + if original_module_identifier != &module_identifier { + original_module_identifiers.insert(*original_module_identifier); + } } else { // entry let execute_task = ctrl_task From 549ab6122b258bbac530a893854b761f681cc899 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Sat, 18 May 2024 09:28:11 +0800 Subject: [PATCH 107/107] feat: inline entry modules (#6554) --- crates/node_binding/binding.d.ts | 5 + .../src/options/raw_output.rs | 20 +- .../src/code_generation_results.rs | 17 +- crates/rspack_core/src/concatenated_module.rs | 41 +- crates/rspack_core/src/external_module.rs | 3 +- crates/rspack_core/src/module.rs | 2 + crates/rspack_core/src/options/output.rs | 12 + crates/rspack_core/src/runtime_module.rs | 2 +- crates/rspack_plugin_devtool/src/lib.rs | 8 + .../common_js_self_reference_dependency.rs | 4 + .../common_js_exports_parse_plugin.rs | 7 +- .../src/parser_plugin/drive.rs | 11 + .../javascript_meta_info_plugin.rs | 29 ++ .../src/parser_plugin/mod.rs | 2 + .../src/parser_plugin/trait.rs | 4 + .../src/plugin/drive.rs | 80 ++++ .../src/plugin/impl_plugin_for_js_plugin.rs | 4 +- .../src/plugin/mod.rs | 394 ++++++++++++++---- .../rspack_plugin_javascript/src/runtime.rs | 237 ++++++----- .../src/visitors/dependency/parser/mod.rs | 10 +- .../src/visitors/scope_info.rs | 14 + .../src/assign_library_plugin.rs | 64 ++- .../src/umd_library_plugin.rs | 13 +- .../src/container/container_entry_module.rs | 2 + .../src/common_js_chunk_format.rs | 19 +- .../runtime_module/export_webpack_require.rs | 2 +- .../src/plugin/rspack-diff-config-plugin.ts | 15 + .../tests/__snapshots__/Defaults.test.js.snap | 16 + .../tests/__snapshots__/StatsAPI.test.js.snap | 98 ++++- .../__snapshots__/StatsOutput.test.js.snap | 117 +++--- .../__snapshots__/output.snap.txt | 3 +- .../__snapshots__/output.snap.txt | 5 +- .../__snapshots__/output.snap.txt | 3 +- .../__snapshots__/output.snap.txt | 6 +- .../__snapshots__/output.snap.txt | 3 +- .../variant/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 3 +- .../hashbang/__snapshots__/output.snap.txt | 3 +- .../simple/__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 4 +- .../v128/__snapshots__/output.snap.txt | 3 +- .../__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 4 +- .../cycle-entry/__snapshots__/output.snap.txt | 2 +- .../__snapshots__/output.snap.txt | 4 +- .../__snapshots__/output.snap.txt | 2 +- .../simple/__snapshots__/output.snap.txt | 2 +- .../builtin-swc-loader/source-map/index.js | 5 +- .../css-loader/css-modules-classname/index.js | 2 +- .../configCases/library/amd-named/index.js | 2 +- .../library/array-this/rspack.config.js | 5 +- .../source-map/source-map/index.js | 5 +- .../defaultsCases/config/browserslist.js | 31 ++ .../experiments/output-module.js | 8 + .../defaultsCases/target_/electron-main.js | 3 + .../defaultsCases/target_/electron-preload.js | 3 + .../tests/defaultsCases/target_/node.js | 3 + .../tests/defaultsCases/target_/webworker.js | 3 + .../basic/hooks.snap.txt | 13 +- .../basic/output.snap.txt | 13 +- .../update-asset/hooks.snap.txt | 28 +- .../update-asset/output.snap.txt | 15 +- .../basic/hooks.snap.txt | 275 +++++++++++- .../basic/output.snap.txt | 13 +- .../duplicate/output.snap.txt | 78 ++-- .../request/output.snap.txt | 68 +-- .../resource/output.snap.txt | 68 +-- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 15 +- .../__snapshots__/web/1.snap.txt | 15 +- .../chunk/asset/__snapshots__/web/1.snap.txt | 6 +- .../chunk/asset/__snapshots__/web/2.snap.txt | 6 +- .../chunk/asset/__snapshots__/web/3.snap.txt | 6 +- .../__snapshots__/web/1.snap.txt | 10 +- .../__snapshots__/web/1.snap.txt | 11 +- .../__snapshots__/web/2.snap.txt | 11 +- .../__snapshots__/web/3.snap.txt | 11 +- .../multi-chunk/__snapshots__/web/1.snap.txt | 18 +- .../multi-chunk/__snapshots__/web/2.snap.txt | 18 +- .../multi-chunk/__snapshots__/web/3.snap.txt | 18 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../css-modules/__snapshots__/web/1.snap.txt | 8 +- .../css/css/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../issue-10174/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 12 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../decline/__snapshots__/web/1.snap.txt | 8 +- .../events/__snapshots__/web/1.snap.txt | 14 +- .../self-decline/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/2.snap.txt | 8 +- .../__snapshots__/web/3.snap.txt | 9 +- .../unaccepted/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../module-hot/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 6 +- .../__snapshots__/web/1.snap.txt | 6 +- .../auto-import/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 6 +- .../hot-index/__snapshots__/web/1.snap.txt | 8 +- .../hot-index/__snapshots__/web/2.snap.txt | 8 +- .../hot-index/__snapshots__/web/3.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/2.snap.txt | 8 +- .../__snapshots__/web/3.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 11 +- .../__snapshots__/web/2.snap.txt | 11 +- .../__snapshots__/web/3.snap.txt | 11 +- .../plugins/html/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/3.snap.txt | 12 +- .../accept/__snapshots__/web/1.snap.txt | 6 +- .../bubble-async/__snapshots__/web/1.snap.txt | 11 +- .../__snapshots__/web/1.snap.txt | 6 +- .../circular/__snapshots__/web/1.snap.txt | 9 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/2.snap.txt | 13 +- .../__snapshots__/web/3.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 9 +- .../__snapshots__/web/2.snap.txt | 13 +- .../hmr-circular/__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 10 +- .../__snapshots__/web/1.snap.txt | 8 +- .../__snapshots__/web/1.snap.txt | 6 +- .../__snapshots__/web/1.snap.txt | 6 +- .../__snapshots__/web/1.snap.txt | 6 +- .../__snapshots__/web/1.snap.txt | 6 +- .../__snapshots__/web/1.snap.txt | 6 +- .../__snapshots__/web/2.snap.txt | 6 +- .../__snapshots__/web/3.snap.txt | 6 +- .../disable/__snapshots__/web/1.snap.txt | 8 +- .../disable/__snapshots__/web/2.snap.txt | 8 +- .../disable/__snapshots__/web/3.snap.txt | 8 +- .../enable/__snapshots__/web/1.snap.txt | 8 +- .../enable/__snapshots__/web/2.snap.txt | 8 +- .../enable/__snapshots__/web/3.snap.txt | 8 +- .../accept/__snapshots__/web/1.snap.txt | 6 +- .../status/check/__snapshots__/web/1.snap.txt | 8 +- .../used-exports/__snapshots__/web/1.snap.txt | 8 +- .../issue-5597/__snapshots__/web/1.snap.txt | 32 +- .../issue-5597/__snapshots__/web/2.snap.txt | 32 +- .../issue-5597/__snapshots__/web/3.snap.txt | 32 +- .../issue-5597/__snapshots__/web/4.snap.txt | 32 +- .../issue-5597/__snapshots__/web/5.snap.txt | 32 +- .../issue-5597/__snapshots__/web/6.snap.txt | 32 +- .../issue-5597/__snapshots__/web/7.snap.txt | 32 +- .../tests/statsAPICases/basic.js | 12 +- .../tests/statsAPICases/child-compiler.js | 8 +- .../tests/statsAPICases/exports.js | 6 +- .../tests/statsAPICases/ids.js | 2 +- .../tests/statsAPICases/to-string.js | 6 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../basic/__snapshots__/treeshaking.snap.txt | 3 +- .../bb/__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 8 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 6 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 5 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 6 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 4 +- .../__snapshots__/treeshaking.snap.txt | 14 +- .../__snapshots__/treeshaking.snap.txt | 2 +- .../__snapshots__/treeshaking.snap.txt | 6 +- .../__snapshots__/treeshaking.snap.txt | 3 +- .../__snapshots__/treeshaking.snap.txt | 8 +- .../__snapshots__/treeshaking.snap.txt | 7 +- .../__snapshots__/treeshaking.snap.txt | 6 +- .../__snapshots__/treeshaking.snap.txt | 4 +- packages/rspack/etc/api.md | 242 +++++++++++ packages/rspack/src/config/adapter.ts | 4 +- .../src/config/browserslistTargetHandler.js | 67 ++- packages/rspack/src/config/defaults.ts | 34 ++ packages/rspack/src/config/normalization.ts | 5 +- packages/rspack/src/config/target.js | 92 ++-- packages/rspack/src/config/zod.ts | 21 +- plugin-test/copy-plugin/build/main.js | 2 +- ...$.css => async.$98438b00a876a2cbe211$.css} | 0 .../chunkFilename-fullhash/expected/async.js | 2 +- ...d$.css => main.$98438b00a876a2cbe211$.css} | 0 .../chunkFilename-fullhash/expected/main.js | 80 ++-- .../expected/main.js | 48 ++- .../expected/main.mjs | 52 +-- .../cases/es-named-export/expected/main.js | 56 +-- .../expected/main.js | 54 +-- .../expected/main.js | 46 +- .../cases/export-only-locals/expected/main.js | 46 +- .../css-extract/cases/hmr/expected/main.js | 71 ++-- .../cases/insert-function/expected/main.js | 63 +-- .../expected/src_inject_css.js | 2 +- .../cases/insert-string/expected/main.js | 63 +-- .../insert-string/expected/src_inject_css.js | 2 +- .../cases/insert-undefined/expected/main.js | 63 +-- .../expected/src_inject_css.js | 2 +- .../multiple-compiler/expected/one-main.js | 36 +- .../multiple-compiler/expected/two-main.js | 36 +- .../cases/new-url/expected/main.js | 39 +- .../cases/no-runtime/expected/async.js | 2 +- .../cases/no-runtime/expected/main.js | 66 +-- .../cases/runtime/expected/runtime~main.js | 58 +-- .../StatsTestCases.basictest.js.snap | 42 +- .../library/0-create-library/test.filter.js | 1 - .../1-use-library/node_modules/external.js | 1 + .../library/1-use-library/test.filter.js | 2 +- 265 files changed, 2913 insertions(+), 1678 deletions(-) create mode 100644 crates/rspack_plugin_javascript/src/parser_plugin/javascript_meta_info_plugin.rs rename plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{async.$dec0863f5e812ee7cadd$.css => async.$98438b00a876a2cbe211$.css} (100%) rename plugin-test/css-extract/cases/chunkFilename-fullhash/expected/{main.$dec0863f5e812ee7cadd$.css => main.$98438b00a876a2cbe211$.css} (100%) delete mode 100644 webpack-test/configCases/library/0-create-library/test.filter.js create mode 100644 webpack-test/configCases/library/1-use-library/node_modules/external.js diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index ff4fe47d1517..6112f732e4fd 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -838,6 +838,10 @@ export interface RawEntryPluginOptions { options: RawEntryOptions } +export interface RawEnvironment { + arrowFunction?: boolean +} + export interface RawEvalDevToolModulePluginOptions { namespace?: string moduleFilenameTemplate?: string | ((info: RawModuleFilenameTemplateFnCtx) => string) @@ -1150,6 +1154,7 @@ export interface RawOutputOptions { workerWasmLoading: string workerPublicPath: string scriptType: "module" | "text/javascript" | "false" + environment: RawEnvironment } export interface RawParserOptions { diff --git a/crates/rspack_binding_options/src/options/raw_output.rs b/crates/rspack_binding_options/src/options/raw_output.rs index c1b79836ae35..16de218a0047 100644 --- a/crates/rspack_binding_options/src/options/raw_output.rs +++ b/crates/rspack_binding_options/src/options/raw_output.rs @@ -2,8 +2,8 @@ use napi::Either; use napi_derive::napi; use rspack_binding_values::JsFilename; use rspack_core::{ - CrossOriginLoading, LibraryCustomUmdObject, LibraryName, LibraryNonUmdObject, LibraryOptions, - PathInfo, + CrossOriginLoading, Environment, LibraryCustomUmdObject, LibraryName, LibraryNonUmdObject, + LibraryOptions, PathInfo, }; use rspack_core::{LibraryAuxiliaryComment, OutputOptions, TrustedTypes}; @@ -141,6 +141,20 @@ impl From for CrossOriginLoading { } } +#[derive(Debug, Clone)] +#[napi(object)] +pub struct RawEnvironment { + pub arrow_function: Option, +} + +impl From for Environment { + fn from(value: RawEnvironment) -> Self { + Self { + arrow_function: value.arrow_function, + } + } +} + #[derive(Debug)] #[napi(object, object_to_js = false)] pub struct RawOutputOptions { @@ -184,6 +198,7 @@ pub struct RawOutputOptions { pub worker_public_path: String, #[napi(ts_type = r#""module" | "text/javascript" | "false""#)] pub script_type: String, + pub environment: RawEnvironment, } impl TryFrom for OutputOptions { @@ -232,6 +247,7 @@ impl TryFrom for OutputOptions { worker_wasm_loading: value.worker_wasm_loading.as_str().into(), worker_public_path: value.worker_public_path, script_type: value.script_type, + environment: value.environment.into(), }) } } diff --git a/crates/rspack_core/src/code_generation_results.rs b/crates/rspack_core/src/code_generation_results.rs index 3bfd0dc53b5a..f9a2da878c02 100644 --- a/crates/rspack_core/src/code_generation_results.rs +++ b/crates/rspack_core/src/code_generation_results.rs @@ -7,7 +7,7 @@ use anymap::CloneAny; use rspack_hash::{HashDigest, HashFunction, HashSalt, RspackHash, RspackHashDigest}; use rspack_identifier::IdentifierMap; use rspack_sources::BoxSource; -use rustc_hash::FxHashMap as HashMap; +use rustc_hash::{FxHashMap as HashMap, FxHashSet}; use serde::Serialize; use crate::{ @@ -68,6 +68,21 @@ impl CodeGenerationDataAssetInfo { } } +#[derive(Clone, Debug)] +pub struct CodeGenerationDataTopLevelDeclarations { + inner: FxHashSet, +} + +impl CodeGenerationDataTopLevelDeclarations { + pub fn new(inner: FxHashSet) -> Self { + Self { inner } + } + + pub fn inner(&self) -> &FxHashSet { + &self.inner + } +} + #[derive(Debug, Default, Clone)] pub struct CodeGenerationData { inner: anymap::Map, diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 1a881c947048..f8eebeb9e21d 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -35,13 +35,13 @@ use crate::{ reserved_names::RESERVED_NAMES, returning_function, runtime_condition_expression, subtract_runtime_condition, AsyncDependenciesBlockIdentifier, BoxDependency, BuildContext, BuildInfo, BuildMeta, BuildMetaDefaultObject, BuildMetaExportsType, BuildResult, - ChunkInitFragments, CodeGenerationResult, Compilation, ConcatenatedModuleIdent, - ConcatenationScope, ConnectionId, ConnectionState, Context, DependenciesBlock, DependencyId, - DependencyTemplate, ErrorSpan, ExportInfoId, ExportInfoProvided, ExportsArgument, ExportsType, - FactoryMeta, IdentCollector, LibIdentOptions, Module, ModuleDependency, ModuleGraph, - ModuleGraphConnection, ModuleIdentifier, ModuleType, Resolve, RuntimeCondition, RuntimeGlobals, - RuntimeSpec, SourceType, SpanExt, Template, UsageState, UsedName, DEFAULT_EXPORT, - NAMESPACE_OBJECT_EXPORT, + ChunkInitFragments, CodeGenerationDataTopLevelDeclarations, CodeGenerationResult, Compilation, + ConcatenatedModuleIdent, ConcatenationScope, ConnectionId, ConnectionState, Context, + DependenciesBlock, DependencyId, DependencyTemplate, ErrorSpan, ExportInfoId, ExportInfoProvided, + ExportsArgument, ExportsType, FactoryMeta, IdentCollector, LibIdentOptions, Module, + ModuleDependency, ModuleGraph, ModuleGraphConnection, ModuleIdentifier, ModuleType, Resolve, + RuntimeCondition, RuntimeGlobals, RuntimeSpec, SourceType, SpanExt, Template, UsageState, + UsedName, DEFAULT_EXPORT, NAMESPACE_OBJECT_EXPORT, }; #[derive(Debug)] @@ -550,6 +550,7 @@ impl Module for ConcatenatedModule { all_star_exports: Default::default(), need_create_require: Default::default(), json_data: Default::default(), + top_level_declarations: Some(Default::default()), module_concatenation_bailout: Default::default(), }; self.clear_diagnostics(); @@ -599,6 +600,17 @@ impl Module for ConcatenatedModule { } // release guard ASAP drop(diagnostics_guard); + + // populate topLevelDeclarations + if let Some(module_build_info) = module.build_info() { + if let Some(decls) = &module_build_info.top_level_declarations + && let Some(top_level_declarations) = &mut build_info.top_level_declarations + { + top_level_declarations.extend(decls.iter().cloned()); + } else { + build_info.top_level_declarations = None; + } + } } self.set_build_info(build_info); // return a dummy result is enough, since we don't build the ConcatenatedModule in make phase @@ -650,6 +662,7 @@ impl Module for ConcatenatedModule { } let mut all_used_names = HashSet::from_iter(RESERVED_NAMES.iter().map(|item| item.to_string())); + let mut top_level_declarations: HashSet = HashSet::default(); for module in modules_with_info.iter() { let ModuleInfoOrReference::Concatenated(m) = module else { @@ -727,6 +740,7 @@ impl Module for ConcatenatedModule { // dbg!(&name, &new_name); all_used_names.insert(new_name.clone()); info.internal_names.insert(name.clone(), new_name.clone()); + top_level_declarations.insert(new_name.as_str().into()); // Update source let source = info.source.as_mut().expect("should have source"); @@ -746,6 +760,7 @@ impl Module for ConcatenatedModule { // Handle the case when the name is not already used all_used_names.insert(name.to_string()); info.internal_names.insert(name.clone(), name.to_string()); + top_level_declarations.insert(name.to_string()); } } @@ -764,7 +779,8 @@ impl Module for ConcatenatedModule { if let Some(namespace_object_name) = namespace_object_name { all_used_names.insert(namespace_object_name.clone()); - info.namespace_object_name = Some(namespace_object_name); + info.namespace_object_name = Some(namespace_object_name.clone()); + top_level_declarations.insert(namespace_object_name); } // dbg!(info.module, &info.internal_names); } @@ -774,6 +790,7 @@ impl Module for ConcatenatedModule { let external_name = Self::find_new_name("", &all_used_names, None, &readable_identifier); all_used_names.insert(external_name.clone()); info.name = Some(external_name.as_str().into()); + top_level_declarations.insert(external_name.as_str().into()); } } // Handle additional logic based on module build meta @@ -786,6 +803,7 @@ impl Module for ConcatenatedModule { ); all_used_names.insert(external_name_interop.as_str().into()); info.set_interop_namespace_object_name(Some(external_name_interop.as_str().into())); + top_level_declarations.insert(external_name_interop.as_str().into()); } if exports_type == Some(BuildMetaExportsType::Default) @@ -799,6 +817,7 @@ impl Module for ConcatenatedModule { ); all_used_names.insert(external_name_interop.as_str().into()); info.set_interop_namespace_object2_name(Some(external_name_interop.as_str().into())); + top_level_declarations.insert(external_name_interop.as_str().into()); } if matches!( @@ -809,6 +828,7 @@ impl Module for ConcatenatedModule { Self::find_new_name("default", &all_used_names, None, &readable_identifier); all_used_names.insert(external_name_interop.clone()); info.set_interop_default_access_name(Some(external_name_interop.as_str().into())); + top_level_declarations.insert(external_name_interop.as_str().into()); } } @@ -1253,6 +1273,11 @@ impl Module for ConcatenatedModule { code_generation_result.add(SourceType::JavaScript, CachedSource::new(result).boxed()); code_generation_result.chunk_init_fragments = chunk_init_fragments; code_generation_result.runtime_requirements = runtime_requirements; + code_generation_result + .data + .insert(CodeGenerationDataTopLevelDeclarations::new( + top_level_declarations, + )); Ok(code_generation_result) } diff --git a/crates/rspack_core/src/external_module.rs b/crates/rspack_core/src/external_module.rs index dab673e22c5d..9a3e985cbcac 100644 --- a/crates/rspack_core/src/external_module.rs +++ b/crates/rspack_core/src/external_module.rs @@ -7,7 +7,7 @@ use rspack_hash::RspackHash; use rspack_identifier::{Identifiable, Identifier}; use rspack_macros::impl_source_map_config; use rspack_util::source_map::SourceMapKind; -use rustc_hash::FxHashMap as HashMap; +use rustc_hash::{FxHashMap as HashMap, FxHashSet}; use serde::Serialize; use crate::{ @@ -389,6 +389,7 @@ impl Module for ExternalModule { let build_info = BuildInfo { hash: Some(hasher.digest(&build_context.compiler_options.output.hash_digest)), + top_level_declarations: Some(FxHashSet::default()), ..Default::default() }; diff --git a/crates/rspack_core/src/module.rs b/crates/rspack_core/src/module.rs index ebe8ef63a406..23ad9e33c7a6 100644 --- a/crates/rspack_core/src/module.rs +++ b/crates/rspack_core/src/module.rs @@ -51,6 +51,7 @@ pub struct BuildInfo { pub all_star_exports: Vec, pub need_create_require: bool, pub json_data: Option, + pub top_level_declarations: Option>, pub module_concatenation_bailout: Option, } @@ -69,6 +70,7 @@ impl Default for BuildInfo { all_star_exports: Vec::default(), need_create_require: false, json_data: None, + top_level_declarations: None, module_concatenation_bailout: None, } } diff --git a/crates/rspack_core/src/options/output.rs b/crates/rspack_core/src/options/output.rs index a0323b2fb49b..fc4c63bb3e66 100644 --- a/crates/rspack_core/src/options/output.rs +++ b/crates/rspack_core/src/options/output.rs @@ -61,6 +61,7 @@ pub struct OutputOptions { pub worker_wasm_loading: WasmLoading, pub worker_public_path: String, pub script_type: String, + pub environment: Environment, } impl From<&OutputOptions> for RspackHash { @@ -380,3 +381,14 @@ pub struct LibraryCustomUmdObject { pub commonjs: Option, pub root: Option>, } + +#[derive(Debug)] +pub struct Environment { + pub arrow_function: Option, +} + +impl Environment { + pub fn supports_arrow_function(&self) -> bool { + self.arrow_function.unwrap_or_default() + } +} diff --git a/crates/rspack_core/src/runtime_module.rs b/crates/rspack_core/src/runtime_module.rs index 4a05f20cd970..6331da19484d 100644 --- a/crates/rspack_core/src/runtime_module.rs +++ b/crates/rspack_core/src/runtime_module.rs @@ -18,7 +18,7 @@ pub trait RuntimeModule: Module + CustomSourceRuntimeModule { } // if wrap iife fn should_isolate(&self) -> bool { - false + true } fn generate_with_custom( diff --git a/crates/rspack_plugin_devtool/src/lib.rs b/crates/rspack_plugin_devtool/src/lib.rs index 676b94e9e8b3..f0f4439a42e6 100644 --- a/crates/rspack_plugin_devtool/src/lib.rs +++ b/crates/rspack_plugin_devtool/src/lib.rs @@ -888,6 +888,10 @@ impl JavascriptModulesPluginPlugin for EvalSourceMapDevToolJavascriptModulesPlug EVAL_SOURCE_MAP_DEV_TOOL_PLUGIN_NAME.hash(&mut args.hasher); Ok(()) } + + fn inline_in_runtime_bailout(&self) -> Option { + Some("the eval-source-map devtool is used.".to_string()) + } } const EVAL_SOURCE_MAP_DEV_TOOL_PLUGIN_NAME: &str = "rspack.EvalSourceMapDevToolPlugin"; @@ -1106,6 +1110,10 @@ impl JavascriptModulesPluginPlugin for EvalDevToolModuleJavascriptModulesPluginP EVAL_DEV_TOOL_MODULE_PLUGIN_NAME.hash(&mut args.hasher); Ok(()) } + + fn inline_in_runtime_bailout(&self) -> Option { + Some("the eval devtool is used.".to_string()) + } } const EVAL_DEV_TOOL_MODULE_PLUGIN_NAME: &str = "rspack.EvalDevToolModulePlugin"; diff --git a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_self_reference_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_self_reference_dependency.rs index 94e4b84bf2e7..195016df793a 100644 --- a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_self_reference_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_self_reference_dependency.rs @@ -44,6 +44,10 @@ impl Dependency for CommonJsSelfReferenceDependency { fn dependency_type(&self) -> &DependencyType { &DependencyType::CjsSelfReference } + + fn resource_identifier(&self) -> Option<&str> { + Some("self") + } } impl ModuleDependency for CommonJsSelfReferenceDependency { diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs index 81efc47530c2..249494a825bc 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/common_js_exports_parse_plugin.rs @@ -403,12 +403,7 @@ impl JavascriptParserPlugin for CommonJsExportsParserPlugin { } if remaining.is_empty() { - // exports = {}; - // module.exports = {}; - // this = {}; - parser.bailout(); - parser.walk_expression(&assign_expr.right); - return Some(true); + return None; } parser.enable(); diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs b/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs index 401eccaf6dae..0dc0ba1c03bb 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/drive.rs @@ -57,6 +57,17 @@ impl JavascriptParserPlugin for JavaScriptParserPluginDrive { None } + fn finish(&self, parser: &mut JavascriptParser) -> Option { + for plugin in &self.plugins { + let res = plugin.finish(parser); + // `SyncBailHook` + if res.is_some() { + return res; + } + } + None + } + fn pre_module_declaration( &self, parser: &mut JavascriptParser, diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/javascript_meta_info_plugin.rs b/crates/rspack_plugin_javascript/src/parser_plugin/javascript_meta_info_plugin.rs new file mode 100644 index 000000000000..3c5dfdad2514 --- /dev/null +++ b/crates/rspack_plugin_javascript/src/parser_plugin/javascript_meta_info_plugin.rs @@ -0,0 +1,29 @@ +use rustc_hash::FxHashSet; + +use super::JavascriptParserPlugin; +use crate::visitors::JavascriptParser; + +pub struct JavascriptMetaInfoPlugin; + +impl JavascriptParserPlugin for JavascriptMetaInfoPlugin { + fn finish(&self, parser: &mut JavascriptParser) -> Option { + if parser.build_info.top_level_declarations.is_none() { + parser.build_info.top_level_declarations = Some(FxHashSet::default()); + } + let variables: Vec<_> = parser + .get_all_variables_from_current_scope() + .map(|(name, _)| name.to_string()) + .collect(); + for name in variables { + if parser.get_free_info_from_variable(&name).is_none() { + parser + .build_info + .top_level_declarations + .as_mut() + .expect("must have value") + .insert(name); + } + } + None + } +} diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs b/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs index d8fd01f719e2..a75c6f20b8d5 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/mod.rs @@ -16,6 +16,7 @@ mod import_meta_context_dependency_parser_plugin; mod import_meta_plugin; mod import_parser_plugin; mod initialize_evaluating; +mod javascript_meta_info_plugin; mod node_stuff_plugin; mod provide; mod require_context_dependency_parser_plugin; @@ -43,6 +44,7 @@ pub(crate) use self::import_meta_context_dependency_parser_plugin::ImportMetaCon pub(crate) use self::import_meta_plugin::ImportMetaPlugin; pub(crate) use self::import_parser_plugin::ImportParserPlugin; pub(crate) use self::initialize_evaluating::InitializeEvaluating; +pub(crate) use self::javascript_meta_info_plugin::JavascriptMetaInfoPlugin; pub(crate) use self::node_stuff_plugin::NodeStuffPlugin; pub(crate) use self::provide::ProviderPlugin; pub(crate) use self::r#const::{is_logic_op, ConstPlugin}; diff --git a/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs b/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs index eea4117d6ebf..bd8ca3ac8c9c 100644 --- a/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs +++ b/crates/rspack_plugin_javascript/src/parser_plugin/trait.rs @@ -298,6 +298,10 @@ pub trait JavascriptParserPlugin { fn named_export(&self, _parser: &mut JavascriptParser, _expr: &NamedExport) -> Option { None } + + fn finish(&self, _parser: &mut JavascriptParser) -> Option { + None + } } pub type BoxJavascriptParserPlugin = Box; diff --git a/crates/rspack_plugin_javascript/src/plugin/drive.rs b/crates/rspack_plugin_javascript/src/plugin/drive.rs index c9bf2eaa30ab..96220c3085e8 100644 --- a/crates/rspack_plugin_javascript/src/plugin/drive.rs +++ b/crates/rspack_plugin_javascript/src/plugin/drive.rs @@ -32,6 +32,27 @@ pub trait JavascriptModulesPluginPlugin { fn js_chunk_hash(&self, _args: &mut JsChunkHashArgs) -> PluginJsChunkHashHookOutput { Ok(()) } + + fn inline_in_runtime_bailout(&self) -> Option { + None + } + + fn embed_in_runtime_bailout( + &self, + _compilation: &Compilation, + _module: &BoxModule, + _chunk: &Chunk, + ) -> Result> { + Ok(None) + } + + fn strict_runtime_bailout( + &self, + _compilation: &Compilation, + _chunk_ukey: &ChunkUkey, + ) -> Result> { + Ok(None) + } } #[derive(Debug)] @@ -127,6 +148,29 @@ impl JavascriptModulesPluginPlug fn js_chunk_hash(&self, args: &mut JsChunkHashArgs) -> PluginJsChunkHashHookOutput { self.deref().js_chunk_hash(args) } + + fn inline_in_runtime_bailout(&self) -> Option { + self.deref().inline_in_runtime_bailout() + } + + fn embed_in_runtime_bailout( + &self, + compilation: &Compilation, + module: &BoxModule, + chunk: &Chunk, + ) -> Result> { + self + .deref() + .embed_in_runtime_bailout(compilation, module, chunk) + } + + fn strict_runtime_bailout( + &self, + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + ) -> Result> { + self.deref().strict_runtime_bailout(compilation, chunk_ukey) + } } #[derive(Default)] @@ -194,4 +238,40 @@ impl JavascriptModulesPluginPluginDrive { } Ok(args) } + + pub fn inline_in_runtime_bailout(&self) -> Option { + for plugin in &self.plugins { + if let Some(reason) = plugin.inline_in_runtime_bailout() { + return Some(reason); + } + } + None + } + + pub fn embed_in_runtime_bailout( + &self, + compilation: &Compilation, + module: &BoxModule, + chunk: &Chunk, + ) -> Result> { + for plugin in &self.plugins { + if let Some(reason) = plugin.embed_in_runtime_bailout(compilation, module, chunk)? { + return Ok(Some(reason)); + } + } + Ok(None) + } + + pub fn strict_runtime_bailout( + &self, + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + ) -> Result> { + for plugin in &self.plugins { + if let Some(reason) = plugin.strict_runtime_bailout(compilation, chunk_ukey)? { + return Ok(Some(reason)); + } + } + Ok(None) + } } diff --git a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs index e9fbcda923fd..3d524d04620f 100644 --- a/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/impl_plugin_for_js_plugin.rs @@ -227,7 +227,7 @@ async fn render_manifest( ) -> Result<()> { let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey); let source = if matches!(chunk.kind, ChunkKind::HotUpdate) { - self.render_chunk_impl(compilation, chunk_ukey).await? + self.render_chunk(compilation, chunk_ukey).await? } else if chunk.has_runtime(&compilation.chunk_group_by_ukey) { self.render_main(compilation, chunk_ukey).await? } else { @@ -239,7 +239,7 @@ async fn render_manifest( return Ok(()); } - self.render_chunk_impl(compilation, chunk_ukey).await? + self.render_chunk(compilation, chunk_ukey).await? }; let filename_template = get_js_chunk_filename_template( diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index c6fb0e25b39a..7da9517af1ed 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -21,17 +21,19 @@ pub use module_concatenation_plugin::*; use once_cell::sync::Lazy; use rspack_core::rspack_sources::{BoxSource, ConcatSource, RawSource, SourceExt}; use rspack_core::{ - basic_function, render_init_fragments, ChunkRenderContext, ChunkUkey, Compilation, CompilationId, - RuntimeGlobals, + basic_function, render_init_fragments, ChunkInitFragments, ChunkRenderContext, ChunkUkey, + CodeGenerationDataTopLevelDeclarations, Compilation, CompilationId, ExportsArgument, + RuntimeGlobals, SourceType, }; use rspack_error::Result; use rspack_hash::RspackHash; use rspack_hook::plugin; -use rspack_util::diff_mode::is_diff_mode; use rspack_util::fx_hash::{BuildFxHasher, FxDashMap}; pub use side_effects_flag_plugin::*; -use crate::runtime::{render_chunk_modules, render_iife, render_runtime_modules, stringify_array}; +use crate::runtime::{ + render_chunk_modules, render_module, render_runtime_modules, stringify_array, +}; static COMPILATION_DRIVES_MAP: Lazy> = Lazy::new(Default::default); @@ -65,7 +67,7 @@ impl JsPlugin { COMPILATION_DRIVES_MAP.entry(compilation.id()).or_default() } - pub fn render_require(&self, chunk_ukey: &ChunkUkey, compilation: &Compilation) -> String { + pub fn render_require(&self, chunk_ukey: &ChunkUkey, compilation: &Compilation) -> Vec> { let runtime_requirements = compilation .chunk_graph .get_chunk_runtime_requirements(chunk_ukey); @@ -77,8 +79,7 @@ impl JsPlugin { indoc! {r#" // Check if module is in cache var cachedModule = __webpack_module_cache__[moduleId]; - if (cachedModule !== undefined) { - "#} + if (cachedModule !== undefined) {"#} .into(), ); @@ -91,27 +92,20 @@ impl JsPlugin { return cachedModule.exports; } // Create a new module (and put it into the cache) - var module = (__webpack_module_cache__[moduleId] = { - "#} + var module = (__webpack_module_cache__[moduleId] = {"#} .into(), ); if runtime_requirements.contains(RuntimeGlobals::MODULE_ID) { - sources.push("id: moduleId,\n".into()); + sources.push("id: moduleId,".into()); } if runtime_requirements.contains(RuntimeGlobals::MODULE_LOADED) { - sources.push("loaded: false,\n".into()); + sources.push("loaded: false,".into()); } - sources.push("exports: {}\n".into()); - sources.push( - indoc! {r#" - }); - // Execute the module function - "#} - .into(), - ); + sources.push("exports: {}".into()); + sources.push("});\n// Execute the module function".into()); let module_execution = if runtime_requirements .contains(RuntimeGlobals::INTERCEPT_MODULE_EXECUTION) @@ -147,7 +141,7 @@ impl JsPlugin { sources.push("// Return the exports of the module\nreturn module.exports;".into()); - sources.join("") + sources } pub fn render_bootstrap( @@ -171,12 +165,6 @@ impl JsPlugin { let mut startup: Vec> = Vec::new(); let mut allow_inline_startup = true; - if is_diff_mode() { - header.push( - "\n/************************************************************************/\n".into(), - ); - } - if allow_inline_startup && module_factories { startup.push("// module factories are used so entry inlining is disabled".into()); allow_inline_startup = false; @@ -202,7 +190,7 @@ impl JsPlugin { ) .into(), ); - header.push(self.render_require(chunk_ukey, compilation).into()); + header.extend(self.render_require(chunk_ukey, compilation)); header.push("\n}\n".into()); } else if require_scope_used { header.push( @@ -295,8 +283,33 @@ impl JsPlugin { ); allow_inline_startup = false; } - if allow_inline_startup { - // TODO: topLevelDeclarations and inlineInRuntimeBailout + if allow_inline_startup && { + let codegen = compilation + .code_generation_results + .get(module, Some(&chunk.runtime)); + let module_graph = compilation.get_module_graph(); + let top_level_decls = codegen + .data + .get::() + .map(|d| d.inner()) + .or_else(|| { + module_graph + .module_by_identifier(module) + .and_then(|m| m.build_info()) + .and_then(|build_info| build_info.top_level_declarations.as_ref()) + }); + top_level_decls.is_none() + } { + buf2.push("// This entry module doesn't tell about it's top-level declarations so it can't be inlined".into()); + allow_inline_startup = false; + } + if allow_inline_startup + && let Some(bailout) = { + let drive = JsPlugin::get_compilation_drives(compilation); + drive.inline_in_runtime_bailout() + } + { + buf2.push(format!("// This entry module can't be inlined because {bailout}").into()); allow_inline_startup = false; } let entry_runtime_requirements = compilation @@ -398,7 +411,7 @@ impl JsPlugin { allow_inline_startup = false; header.push( format!( - "// the startup function\n{} = {}\n", + "// the startup function\n{} = {};\n", RuntimeGlobals::STARTUP, basic_function( "", @@ -440,14 +453,10 @@ impl JsPlugin { startup.push("// run startup".into()); startup.push(format!("var __webpack_exports__ = {}();", RuntimeGlobals::STARTUP).into()); } - if is_diff_mode() { - header.push( - "\n/************************************************************************/\n".into(), - ); - } + RenderBootstrapResult { - header: RawSource::from(header.join("\n")).boxed(), - startup: RawSource::from(startup.join("\n")).boxed(), + header, + startup, allow_inline_startup, } } @@ -459,47 +468,227 @@ impl JsPlugin { ) -> Result { let drive = Self::get_compilation_drives(compilation); let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey); + let supports_arrow_function = compilation + .options + .output + .environment + .supports_arrow_function(); let runtime_requirements = compilation .chunk_graph .get_tree_runtime_requirements(chunk_ukey); + let mut chunk_init_fragments = ChunkInitFragments::default(); + let iife = compilation.options.output.iife; + let mut all_strict = compilation.options.output.module; let RenderBootstrapResult { header, startup, - allow_inline_startup: _, + allow_inline_startup, } = self.render_bootstrap(chunk_ukey, compilation); - let (module_source, chunk_init_fragments) = render_chunk_modules(compilation, chunk_ukey)?; + let module_graph = &compilation.get_module_graph(); + let all_modules = compilation.chunk_graph.get_chunk_modules_by_source_type( + chunk_ukey, + SourceType::JavaScript, + module_graph, + ); + let has_entry_modules = chunk.has_entry_module(&compilation.chunk_graph); + let inlined_modules = if allow_inline_startup && has_entry_modules { + Some( + compilation + .chunk_graph + .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey), + ) + } else { + None + }; let mut sources = ConcatSource::default(); - sources.add(RawSource::from("var __webpack_modules__ = ")); - sources.add(module_source); - sources.add(RawSource::from("\n")); - sources.add(header); - sources.add(render_runtime_modules(compilation, chunk_ukey)?); - if chunk.has_entry_module(&compilation.chunk_graph) { - let last_entry_module = compilation - .chunk_graph - .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey) + if iife { + sources.add(RawSource::from(if supports_arrow_function { + "(() => { // webpackBootstrap\n" + } else { + "(function() { // webpackBootstrap\n" + })); + } + if !all_strict + && all_modules.iter().all(|m| { + let build_info = m + .build_info() + .expect("should have build_info in render_main"); + build_info.strict + }) + { + if let Some(strict_bailout) = drive.strict_runtime_bailout(compilation, chunk_ukey)? { + sources.add(RawSource::from(format!( + "// runtime can't be in strict mode because {strict_bailout}.\n" + ))); + } else { + all_strict = true; + sources.add(RawSource::from("\"use strict\";\n")); + } + } + let chunk_modules = if let Some(inlined_modules) = inlined_modules { + all_modules + .into_iter() + .filter(|m| !inlined_modules.contains_key(&m.identifier())) + .collect() + } else { + all_modules + }; + let chunk_modules_result = + render_chunk_modules(compilation, chunk_ukey, chunk_modules, all_strict)?; + let has_chunk_modules_result = chunk_modules_result.is_some(); + if has_chunk_modules_result + || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES) + || runtime_requirements.contains(RuntimeGlobals::MODULE_FACTORIES_ADD_ONLY) + || runtime_requirements.contains(RuntimeGlobals::REQUIRE) + { + let chunk_modules_source = + if let Some((chunk_modules_source, fragments)) = chunk_modules_result { + chunk_init_fragments.extend(fragments); + chunk_modules_source + } else { + RawSource::from("{}").boxed() + }; + sources.add(RawSource::from("var __webpack_modules__ = (")); + sources.add(chunk_modules_source); + sources.add(RawSource::from(");\n")); + sources.add(RawSource::from( + "/************************************************************************/\n", + )); + } + if !header.is_empty() { + let mut header = header.join("\n"); + header.push('\n'); + sources.add(RawSource::from(header)); + sources.add(RawSource::from( + "/************************************************************************/\n", + )); + } + + if compilation + .chunk_graph + .has_chunk_runtime_modules(chunk_ukey) + { + sources.add(render_runtime_modules(compilation, chunk_ukey)?); + sources.add(RawSource::from( + "/************************************************************************/\n", + )); + } + if let Some(inlined_modules) = inlined_modules { + let last_entry_module = inlined_modules .keys() .last() .expect("should have last entry module"); + let mut startup_sources = ConcatSource::default(); + startup_sources.add(RawSource::from(format!( + "var {} = {{}};\n", + RuntimeGlobals::EXPORTS + ))); + for (m_identifier, _) in inlined_modules { + let m = module_graph + .module_by_identifier(m_identifier) + .expect("should have module"); + let Some((rendered_module, fragments, additional_fragments)) = + render_module(compilation, chunk_ukey, m, all_strict, false)? + else { + continue; + }; + chunk_init_fragments.extend(fragments); + chunk_init_fragments.extend(additional_fragments); + let inner_strict = !all_strict && m.build_info().expect("should have build_info").strict; + let module_runtime_requirements = compilation + .chunk_graph + .get_module_runtime_requirements(*m_identifier, &chunk.runtime); + let exports = module_runtime_requirements + .map(|r| r.contains(RuntimeGlobals::EXPORTS)) + .unwrap_or_default(); + let exports_argument = m.get_exports_argument(); + let webpack_exports_argument = matches!(exports_argument, ExportsArgument::WebpackExports); + let webpack_exports = exports && webpack_exports_argument; + let iife: Option> = if inner_strict { + Some("it need to be in strict mode.".into()) + } else if inlined_modules.len() > 1 { + Some("it need to be isolated against other entry modules.".into()) + } else if has_chunk_modules_result { + Some("it need to be isolated against other modules in the chunk.".into()) + } else if exports && !webpack_exports { + Some(format!("it uses a non-standard name for the exports ({exports_argument}).").into()) + } else { + drive + .embed_in_runtime_bailout(compilation, m, chunk)? + .map(|s| s.into()) + }; + let footer; + if let Some(iife) = iife { + startup_sources.add(RawSource::from(format!( + "// This entry need to be wrapped in an IIFE because {iife}\n" + ))); + if supports_arrow_function { + startup_sources.add(RawSource::from("(() => {\n")); + footer = "\n})();\n\n"; + } else { + startup_sources.add(RawSource::from("!function() {\n")); + footer = "\n}();\n"; + } + if inner_strict { + startup_sources.add(RawSource::from("\"use strict\";\n")); + } + } else { + footer = "\n"; + } + if exports { + if m_identifier != last_entry_module { + startup_sources.add(RawSource::from(format!("var {exports_argument} = {{}};\n"))); + } else if !webpack_exports_argument { + startup_sources.add(RawSource::from(format!( + "var {exports_argument} = {};\n", + RuntimeGlobals::EXPORTS + ))); + } + } + startup_sources.add(rendered_module); + startup_sources.add(RawSource::from(footer)); + } + if runtime_requirements.contains(RuntimeGlobals::ON_CHUNKS_LOADED) { + startup_sources.add(RawSource::from(format!( + "{} = {}({});\n", + RuntimeGlobals::EXPORTS, + RuntimeGlobals::ON_CHUNKS_LOADED, + RuntimeGlobals::EXPORTS, + ))); + } if let Some(source) = drive.render_startup(RenderJsStartupArgs { compilation, chunk: chunk_ukey, module: *last_entry_module, - source: startup, + source: startup_sources.boxed(), })? { sources.add(source); } - if runtime_requirements.contains(RuntimeGlobals::RETURN_EXPORTS_FROM_RUNTIME) { - sources.add(RawSource::from("return __webpack_exports__;\n")); + } else if let Some(last_entry_module) = compilation + .chunk_graph + .get_chunk_entry_modules_with_chunk_group_iterable(chunk_ukey) + .keys() + .last() + { + if let Some(source) = drive.render_startup(RenderJsStartupArgs { + compilation, + chunk: chunk_ukey, + module: *last_entry_module, + source: RawSource::from(startup.join("\n") + "\n").boxed(), + })? { + sources.add(source); } } - let mut final_source = if compilation.options.output.iife { - render_iife(sources.boxed()) - } else { - sources.boxed() - }; - final_source = render_init_fragments( - final_source, + if has_entry_modules + && runtime_requirements.contains(RuntimeGlobals::RETURN_EXPORTS_FROM_RUNTIME) + { + sources.add(RawSource::from("return __webpack_exports__;\n")); + } + if iife { + sources.add(RawSource::from("})()\n")); + } + let mut final_source = render_init_fragments( + sources.boxed(), chunk_init_fragments, &mut ChunkRenderContext {}, )?; @@ -508,44 +697,77 @@ impl JsPlugin { chunk: chunk_ukey, source: &final_source, })? { - return Ok(source); - } - Ok(final_source) + final_source = source; + }; + Ok(if iife { + ConcatSource::new([final_source, RawSource::from(";").boxed()]).boxed() + } else { + final_source + }) } - #[inline] - pub async fn render_chunk_impl( + pub async fn render_chunk( &self, compilation: &Compilation, chunk_ukey: &ChunkUkey, ) -> Result { let drive = Self::get_compilation_drives(compilation); - let (module_source, chunk_init_fragments) = render_chunk_modules(compilation, chunk_ukey)?; - let source = drive + let module_graph = &compilation.get_module_graph(); + let is_module = compilation.options.output.module; + let mut all_strict = compilation.options.output.module; + let chunk_modules = compilation.chunk_graph.get_chunk_modules_by_source_type( + chunk_ukey, + SourceType::JavaScript, + module_graph, + ); + let mut sources = ConcatSource::default(); + if !all_strict + && chunk_modules.iter().all(|m| { + let build_info = m + .build_info() + .expect("should have build_info in render_main"); + build_info.strict + }) + { + if let Some(strict_bailout) = drive.strict_runtime_bailout(compilation, chunk_ukey)? { + sources.add(RawSource::from(format!( + "// runtime can't be in strict mode because {strict_bailout}.\n" + ))); + } else { + sources.add(RawSource::from("\"use strict\";\n")); + all_strict = true; + } + } + let (chunk_modules_source, chunk_init_fragments) = + render_chunk_modules(compilation, chunk_ukey, chunk_modules, all_strict)? + .unwrap_or_else(|| (RawSource::from("{}").boxed(), Vec::new())); + let chunk_modules_source = drive .render_chunk(RenderJsChunkArgs { compilation, chunk_ukey, - module_source, + module_source: chunk_modules_source, }) .await? .expect("should run render_chunk hook"); - let source_with_fragments = - render_init_fragments(source, chunk_init_fragments, &mut ChunkRenderContext {})?; - Ok( - ConcatSource::new([ - if let Some(source) = drive.render(RenderJsArgs { - compilation, - chunk: chunk_ukey, - source: &source_with_fragments, - })? { - source - } else { - source_with_fragments - }, - RawSource::from(";").boxed(), - ]) - .boxed(), - ) + let source_with_fragments = render_init_fragments( + chunk_modules_source, + chunk_init_fragments, + &mut ChunkRenderContext {}, + )?; + let chunk_modules_source = if let Some(source) = drive.render(RenderJsArgs { + compilation, + chunk: chunk_ukey, + source: &source_with_fragments, + })? { + source + } else { + source_with_fragments + }; + sources.add(chunk_modules_source); + if !is_module { + sources.add(RawSource::from(";")); + } + Ok(sources.boxed()) } #[inline] @@ -589,8 +811,8 @@ pub struct ExtractedCommentsInfo { } #[derive(Debug)] -pub struct RenderBootstrapResult { - header: BoxSource, - startup: BoxSource, +pub struct RenderBootstrapResult<'a> { + header: Vec>, + startup: Vec>, allow_inline_startup: bool, } diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 1c49d68ec653..043778d2db0f 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -13,16 +13,9 @@ use crate::{JsPlugin, RenderJsModuleContentArgs}; pub fn render_chunk_modules( compilation: &Compilation, chunk_ukey: &ChunkUkey, -) -> Result<(BoxSource, ChunkInitFragments)> { - let drive = JsPlugin::get_compilation_drives(compilation); - let module_graph = &compilation.get_module_graph(); - let ordered_modules = compilation.chunk_graph.get_chunk_modules_by_source_type( - chunk_ukey, - SourceType::JavaScript, - module_graph, - ); - let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey); - + ordered_modules: Vec<&BoxModule>, + all_strict: bool, +) -> Result> { let include_module_ids = &compilation.include_module_ids; let mut module_code_array = ordered_modules @@ -31,43 +24,15 @@ pub fn render_chunk_modules( compilation.options.is_new_tree_shaking() || include_module_ids.contains(&module.identifier()) }) .filter_map(|module| { - let code_gen_result = compilation - .code_generation_results - .get(&module.identifier(), Some(&chunk.runtime)); - if let Some(origin_source) = code_gen_result.get(&SourceType::JavaScript) { - let render_module_result = drive - .render_module_content(RenderJsModuleContentArgs { - compilation, - module, - module_source: origin_source.clone(), - chunk_init_fragments: ChunkInitFragments::default(), - }) - .expect("render_module_content failed"); - - let runtime_requirements = compilation - .chunk_graph - .get_module_runtime_requirements(module.identifier(), &chunk.runtime); - - Some(( - module.identifier(), - render_module( - render_module_result.module_source, - module, - runtime_requirements, - compilation - .chunk_graph - .get_module_id(module.identifier()) - .as_ref() - .expect("should have module id"), - ), - &code_gen_result.chunk_init_fragments, - render_module_result.chunk_init_fragments, - )) - } else { - None - } + render_module(compilation, chunk_ukey, module, all_strict, true) + .transpose() + .map(|result| result.map(|(s, f, a)| (module.identifier(), s, f, a))) }) - .collect::>(); + .collect::>>()?; + + if module_code_array.is_empty() { + return Ok(None); + } module_code_array.sort_unstable_by_key(|(module_identifier, _, _, _)| *module_identifier); @@ -83,7 +48,7 @@ pub fn render_chunk_modules( let module_sources: Vec<_> = module_code_array .into_iter() .map(|(_, source, _, _)| source) - .collect::>()?; + .collect(); let module_sources = module_sources .into_par_iter() .fold(ConcatSource::default, |mut output, source| { @@ -97,72 +62,109 @@ pub fn render_chunk_modules( sources.add(ConcatSource::new(module_sources)); sources.add(RawSource::from("\n}")); - Ok((sources.boxed(), chunk_init_fragments)) + Ok(Some((sources.boxed(), chunk_init_fragments))) } -fn render_module( - source: BoxSource, +pub fn render_module( + compilation: &Compilation, + chunk_ukey: &ChunkUkey, module: &BoxModule, - runtime_requirements: Option<&RuntimeGlobals>, - module_id: &str, -) -> Result { - let need_module = runtime_requirements.is_some_and(|r| r.contains(RuntimeGlobals::MODULE)); - let need_exports = runtime_requirements.is_some_and(|r| r.contains(RuntimeGlobals::EXPORTS)); - let need_require = runtime_requirements.is_some_and(|r| { - r.contains(RuntimeGlobals::REQUIRE) || r.contains(RuntimeGlobals::REQUIRE_SCOPE) - }); + all_strict: bool, + factory: bool, +) -> Result> { + let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey); + let code_gen_result = compilation + .code_generation_results + .get(&module.identifier(), Some(&chunk.runtime)); + let Some(origin_source) = code_gen_result.get(&SourceType::JavaScript) else { + return Ok(None); + }; + let drive = JsPlugin::get_compilation_drives(compilation); + let mut sources = ConcatSource::default(); + let render_module_result = drive + .render_module_content(RenderJsModuleContentArgs { + compilation, + module, + module_source: origin_source.clone(), + chunk_init_fragments: ChunkInitFragments::default(), + }) + .expect("render_module_content failed"); - let mut args = Vec::new(); - if need_module || need_exports || need_require { - let module_argument = module.get_module_argument(); - args.push(if need_module { - module_argument.to_string() - } else { - format!("__unused_webpack_{module_argument}") - }); - } + if factory { + let runtime_requirements = compilation + .chunk_graph + .get_module_runtime_requirements(module.identifier(), &chunk.runtime); - if need_exports || need_require { - let exports_argument = module.get_exports_argument(); - args.push(if need_exports { - exports_argument.to_string() - } else { - format!("__unused_webpack_{exports_argument}") + let need_module = runtime_requirements.is_some_and(|r| r.contains(RuntimeGlobals::MODULE)); + let need_exports = runtime_requirements.is_some_and(|r| r.contains(RuntimeGlobals::EXPORTS)); + let need_require = runtime_requirements.is_some_and(|r| { + r.contains(RuntimeGlobals::REQUIRE) || r.contains(RuntimeGlobals::REQUIRE_SCOPE) }); - } - if need_require { - args.push(RuntimeGlobals::REQUIRE.to_string()); - } - let mut sources = ConcatSource::new([ - RawSource::from(serde_json::to_string(module_id).map_err(|e| error!(e.to_string()))?), - RawSource::from(": "), - ]); - if is_diff_mode() { - sources.add(RawSource::from(format!( - "\n{}\n", - to_normal_comment(&format!("start::{}", module.identifier())) - ))); - } - sources.add(RawSource::from(format!( - "(function ({}) {{\n", - args.join(", ") - ))); - if let Some(build_info) = &module.build_info() - && build_info.strict - { - sources.add(RawSource::from("\"use strict\";\n")); - } - sources.add(source); - sources.add(RawSource::from("})")); - if is_diff_mode() { + + let mut args = Vec::new(); + if need_module || need_exports || need_require { + let module_argument = module.get_module_argument(); + args.push(if need_module { + module_argument.to_string() + } else { + format!("__unused_webpack_{module_argument}") + }); + } + + if need_exports || need_require { + let exports_argument = module.get_exports_argument(); + args.push(if need_exports { + exports_argument.to_string() + } else { + format!("__unused_webpack_{exports_argument}") + }); + } + if need_require { + args.push(RuntimeGlobals::REQUIRE.to_string()); + } + let module_id = compilation + .chunk_graph + .get_module_id(module.identifier()) + .as_deref() + .expect("should have module_id in render_module"); + sources.add(RawSource::from( + serde_json::to_string(&module_id).map_err(|e| error!(e.to_string()))?, + )); + sources.add(RawSource::from(": ")); + if is_diff_mode() { + sources.add(RawSource::from(format!( + "\n{}\n", + to_normal_comment(&format!("start::{}", module.identifier())) + ))); + } sources.add(RawSource::from(format!( - "\n{}\n", - to_normal_comment(&format!("end::{}", module.identifier())) + "(function ({}) {{\n", + args.join(", ") ))); + if let Some(build_info) = &module.build_info() + && build_info.strict + && !all_strict + { + sources.add(RawSource::from("\"use strict\";\n")); + } + sources.add(render_module_result.module_source); + sources.add(RawSource::from("})")); + if is_diff_mode() { + sources.add(RawSource::from(format!( + "\n{}\n", + to_normal_comment(&format!("end::{}", module.identifier())) + ))); + } + sources.add(RawSource::from(",\n")); + } else { + sources.add(render_module_result.module_source); } - sources.add(RawSource::from(",\n")); - Ok(sources.boxed()) + Ok(Some(( + sources.boxed(), + code_gen_result.chunk_init_fragments.clone(), + render_module_result.chunk_init_fragments, + ))) } pub fn render_chunk_runtime_modules( @@ -213,16 +215,29 @@ pub fn render_runtime_modules( } else { sources.add(RawSource::from(format!("// {}\n", module.identifier()))); } - if !module.should_isolate() { - sources.add(RawSource::from("!function() {\n")); + let supports_arrow_function = compilation + .options + .output + .environment + .supports_arrow_function(); + if module.should_isolate() { + sources.add(RawSource::from(if supports_arrow_function { + "(() => {\n" + } else { + "!function() {\n" + })); } if module.cacheable() { sources.add(source.clone()); } else { sources.add(module.generate_with_custom(compilation)?); } - if !module.should_isolate() { - sources.add(RawSource::from("\n}();\n")); + if module.should_isolate() { + sources.add(RawSource::from(if supports_arrow_function { + "\n})();\n" + } else { + "\n}();\n" + })); } if is_diff_mode() { sources.add(RawSource::from(format!( @@ -257,11 +272,3 @@ pub fn stringify_array(vec: &[String]) -> String { .join(", ") ) } - -pub fn render_iife(content: BoxSource) -> BoxSource { - let mut sources = ConcatSource::default(); - sources.add(RawSource::from("(function() {\n")); - sources.add(content); - sources.add(RawSource::from("\n})()\n")); - sources.boxed() -} diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs index bfbe9725ed52..da84c4bdc66e 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/parser/mod.rs @@ -222,6 +222,7 @@ impl<'parser> JavascriptParser<'parser> { let mut plugins: Vec = Vec::with_capacity(32); plugins.push(Box::new(parser_plugin::InitializeEvaluating)); + plugins.push(Box::new(parser_plugin::JavascriptMetaInfoPlugin)); plugins.push(Box::new(parser_plugin::CheckVarDeclaratorIdent)); plugins.push(Box::new(parser_plugin::ConstPlugin)); plugins.push(Box::new( @@ -361,6 +362,13 @@ impl<'parser> JavascriptParser<'parser> { }) } + pub fn get_all_variables_from_current_scope( + &self, + ) -> impl Iterator { + let scope = self.definitions_db.expect_get_scope(&self.definitions); + scope.variables() + } + fn define_variable(&mut self, name: String) { let definitions = self.definitions; if let Some(variable_info) = self.get_variable_info(&name) @@ -642,7 +650,7 @@ impl<'parser> JavascriptParser<'parser> { } }; } - // TODO: `hooks.finish.call` + self.plugin_drive.clone().finish(self); } fn set_strict(&mut self, value: bool) { diff --git a/crates/rspack_plugin_javascript/src/visitors/scope_info.rs b/crates/rspack_plugin_javascript/src/visitors/scope_info.rs index 92b02c76680e..0095d7b74183 100644 --- a/crates/rspack_plugin_javascript/src/visitors/scope_info.rs +++ b/crates/rspack_plugin_javascript/src/visitors/scope_info.rs @@ -244,3 +244,17 @@ pub struct ScopeInfo { map: FxHashMap, pub is_strict: bool, } + +impl ScopeInfo { + pub fn variable_map(&self) -> &FxHashMap { + &self.map + } + + pub fn variables(&self) -> impl Iterator { + self + .map + .iter() + .filter(|(_, &info_id)| info_id != VariableInfo::TOMBSTONE) + .map(|(name, info_id)| (name.as_str(), info_id)) + } +} diff --git a/crates/rspack_plugin_library/src/assign_library_plugin.rs b/crates/rspack_plugin_library/src/assign_library_plugin.rs index 55fe45a863bb..f67a9a60c215 100644 --- a/crates/rspack_plugin_library/src/assign_library_plugin.rs +++ b/crates/rspack_plugin_library/src/assign_library_plugin.rs @@ -5,9 +5,10 @@ use once_cell::sync::Lazy; use regex::Regex; use rspack_core::tree_shaking::webpack_ext::ExportInfoExt; use rspack_core::{ - get_entry_runtime, property_access, ApplyContext, ChunkUkey, CompilationFinishModules, - CompilationParams, CompilerCompilation, CompilerOptions, EntryData, FilenameTemplate, - LibraryExport, LibraryName, LibraryNonUmdObject, UsageState, + get_entry_runtime, property_access, ApplyContext, BoxModule, ChunkUkey, + CodeGenerationDataTopLevelDeclarations, CompilationFinishModules, CompilationParams, + CompilerCompilation, CompilerOptions, EntryData, FilenameTemplate, LibraryExport, LibraryName, + LibraryNonUmdObject, UsageState, }; use rspack_core::{ rspack_sources::{ConcatSource, RawSource, SourceExt}, @@ -265,6 +266,63 @@ impl JavascriptModulesPluginPlugin for AssignLibraryJavascriptModulesPluginPlugi } Ok(()) } + + fn embed_in_runtime_bailout( + &self, + compilation: &Compilation, + module: &BoxModule, + chunk: &Chunk, + ) -> Result> { + let Some(options) = self.get_options_for_chunk(compilation, &chunk.ukey)? else { + return Ok(None); + }; + let codegen = compilation + .code_generation_results + .get(&module.identifier(), Some(&chunk.runtime)); + let top_level_decls = codegen + .data + .get::() + .map(|d| d.inner()) + .or_else(|| { + module + .build_info() + .and_then(|build_info| build_info.top_level_declarations.as_ref()) + }); + if let Some(top_level_decls) = top_level_decls { + let full_name = self.get_resolved_full_name(&options, compilation, chunk); + if let Some(base) = full_name.first() + && top_level_decls.contains(base) + { + return Ok(Some(format!( + "it declares '{base}' on top-level, which conflicts with the current library output." + ))); + } + return Ok(None); + } + Ok(Some( + "it doesn't tell about top level declarations.".to_string(), + )) + } + + fn strict_runtime_bailout( + &self, + compilation: &Compilation, + chunk_ukey: &ChunkUkey, + ) -> Result> { + let Some(options) = self.get_options_for_chunk(compilation, chunk_ukey)? else { + return Ok(None); + }; + if self.options.declare + || matches!(self.options.prefix, Prefix::Global) + || !self.options.prefix.is_empty() + || options.name.is_none() + { + return Ok(None); + } + Ok(Some( + "a global variable is assign and maybe created".to_string(), + )) + } } #[plugin] diff --git a/crates/rspack_plugin_library/src/umd_library_plugin.rs b/crates/rspack_plugin_library/src/umd_library_plugin.rs index 291cedf39876..a6c304e9a022 100644 --- a/crates/rspack_plugin_library/src/umd_library_plugin.rs +++ b/crates/rspack_plugin_library/src/umd_library_plugin.rs @@ -103,6 +103,11 @@ impl JavascriptModulesPluginPlugin for UmdLibraryJavascriptModulesPluginPlugin { let Some(options) = self.get_options_for_chunk(compilation, args.chunk) else { return Ok(None); }; + let supports_arrow_function = compilation + .options + .output + .environment + .supports_arrow_function(); let chunk = args.chunk(); let module_graph = compilation.get_module_graph(); let modules = compilation @@ -225,11 +230,15 @@ impl JavascriptModulesPluginPlugin for UmdLibraryJavascriptModulesPluginPlugin { {} {define} {factory} - }})({}, function({}) {{ + }})({}, {} {{ return ", get_auxiliary_comment("amd", auxiliary_comment), compilation.options.output.global_object, - external_arguments(&externals, compilation) + if supports_arrow_function { + format!("({}) =>", external_arguments(&externals, compilation)) + } else { + format!("function({})", external_arguments(&externals, compilation)) + }, ))); source.add(args.source.clone()); source.add(RawSource::from("\n})")); diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index 52b98c632dda..1361437ad63a 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -16,6 +16,7 @@ use rspack_error::{impl_empty_diagnosable_trait, Diagnostic, Result}; use rspack_hash::RspackHash; use rspack_identifier::{Identifiable, Identifier}; use rspack_util::source_map::SourceMapKind; +use rustc_hash::FxHashSet; use super::{ container_exposed_dependency::ContainerExposedDependency, container_plugin::ExposeOptions, @@ -160,6 +161,7 @@ impl Module for ContainerEntryModule { build_info: BuildInfo { hash: Some(hash), strict: true, + top_level_declarations: Some(FxHashSet::default()), ..Default::default() }, build_meta: BuildMeta { diff --git a/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs b/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs index 9e212b9ac180..fe8d44be24de 100644 --- a/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs +++ b/crates/rspack_plugin_runtime/src/common_js_chunk_format.rs @@ -9,11 +9,12 @@ use rspack_core::{ }; use rspack_error::Result; use rspack_hook::{plugin, plugin_hook}; -use rspack_plugin_javascript::runtime::{render_chunk_runtime_modules, render_iife}; +use rspack_plugin_javascript::runtime::render_chunk_runtime_modules; use rspack_plugin_javascript::{ JavascriptModulesPluginPlugin, JsChunkHashArgs, JsPlugin, PluginJsChunkHashHookOutput, PluginRenderJsChunkHookOutput, RenderJsChunkArgs, RenderJsStartupArgs, }; +use rspack_util::json_stringify; use crate::{ generate_entry_startup, get_chunk_output_name, get_relative_path, get_runtime_chunk_output_name, @@ -78,9 +79,12 @@ impl JavascriptModulesPluginPlugin for CommonJsChunkFormatJavascriptModulesPlugi if chunk.has_entry_module(&args.compilation.chunk_graph) { let runtime_chunk_output_name = get_runtime_chunk_output_name(args)?; sources.add(RawSource::from(format!( - "var {} = require('{}');\n", + "// load runtime\nvar {} = require({});\n", RuntimeGlobals::REQUIRE, - get_relative_path(&base_chunk_output_name, &runtime_chunk_output_name) + json_stringify(&get_relative_path( + &base_chunk_output_name, + &runtime_chunk_output_name + )) ))); sources.add(RawSource::from(format!( "{}(exports)\n", @@ -105,7 +109,14 @@ impl JavascriptModulesPluginPlugin for CommonJsChunkFormatJavascriptModulesPlugi })? { sources.add(s); } - return Ok(Some(render_iife(sources.boxed()))); + return Ok(Some( + ConcatSource::new([ + RawSource::from("(function() {\n").boxed(), + sources.boxed(), + RawSource::from("\n})()").boxed(), + ]) + .boxed(), + )); } Ok(Some(sources.boxed())) } diff --git a/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs b/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs index 174a306eb157..b6622c613e82 100644 --- a/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs +++ b/crates/rspack_plugin_runtime/src/runtime_module/export_webpack_require.rs @@ -32,6 +32,6 @@ impl RuntimeModule for ExportWebpackRequireRuntimeModule { } fn should_isolate(&self) -> bool { - true + false } } diff --git a/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts b/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts index 3b5a16d52264..907a6c8b54a2 100644 --- a/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts +++ b/packages/rspack-test-tools/src/plugin/rspack-diff-config-plugin.ts @@ -29,6 +29,21 @@ export class RspackDiffConfigPlugin implements RspackPluginInstance { options.optimization.moduleIds = "named"; options.optimization.mangleExports = false; + options.output ??= {}; + + options.output.environment ??= {}; + options.output.environment.arrowFunction = false; + options.output.environment.bigIntLiteral = false; + options.output.environment.const = false; + options.output.environment.destructuring = false; + options.output.environment.dynamicImport = false; + options.output.environment.dynamicImportInWorker = false; + options.output.environment.forOf = false; + options.output.environment.globalThis = false; + options.output.environment.module = false; + options.output.environment.optionalChaining = false; + options.output.environment.templateLiteral = false; + options.experiments ??= {}; options.experiments.rspackFuture ??= {}; diff --git a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap index 19ea6668e45d..3f1bfb0aecae 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Defaults.test.js.snap @@ -308,6 +308,22 @@ Object { "enabledWasmLoadingTypes": Array [ "fetch", ], + "environment": Object { + "arrowFunction": true, + "asyncFunction": true, + "bigIntLiteral": undefined, + "const": true, + "destructuring": true, + "document": true, + "dynamicImport": undefined, + "dynamicImportInWorker": undefined, + "forOf": true, + "globalThis": undefined, + "module": undefined, + "nodePrefixForCoreModules": true, + "optionalChaining": true, + "templateLiteral": true, + }, "filename": "[name].js", "globalObject": "self", "hashDigest": "hex", diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap index 60621d14ca84..113e2bff91f9 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap @@ -16,7 +16,7 @@ Object { "hotModuleReplacement": false, }, "name": "main.js", - "size": 211, + "size": 207, "type": "asset", }, ], @@ -65,6 +65,13 @@ Object { "type": "entry", "userRequest": "./fixtures/a", }, + Object { + "moduleId": "585", + "moduleIdentifier": "/tests/fixtures/a.js", + "moduleName": "./fixtures/a.js", + "type": "cjs self exports reference", + "userRequest": "self", + }, ], "size": 59, "source": "module.exports = function a() { @@ -72,7 +79,7 @@ Object { }; ", "type": "module", - "usedExports": Array [], + "usedExports": null, }, ], "names": Array [ @@ -89,10 +96,10 @@ Object { "assets": Array [ Object { "name": "main.js", - "size": 211, + "size": 207, }, ], - "assetsSize": 211, + "assetsSize": 207, "chunks": Array [ "909", ], @@ -102,7 +109,7 @@ Object { "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "bca12e9a78756a7efe53", + "hash": "d64955662040c788c943", "logging": Object {}, "modules": Array [ Object { @@ -132,6 +139,13 @@ Object { "type": "entry", "userRequest": "./fixtures/a", }, + Object { + "moduleId": "585", + "moduleIdentifier": "/tests/fixtures/a.js", + "moduleName": "./fixtures/a.js", + "type": "cjs self exports reference", + "userRequest": "self", + }, ], "size": 59, "source": "module.exports = function a() { @@ -139,7 +153,7 @@ Object { }; ", "type": "module", - "usedExports": Array [], + "usedExports": null, }, ], "namedChunkGroups": Object { @@ -147,10 +161,10 @@ Object { "assets": Array [ Object { "name": "main.js", - "size": 211, + "size": 207, }, ], - "assetsSize": 211, + "assetsSize": 207, "chunks": Array [ "909", ], @@ -180,7 +194,7 @@ Object { "hotModuleReplacement": false, }, "name": "main.js", - "size": 784, + "size": 720, "type": "asset", }, ], @@ -389,10 +403,10 @@ Object { "assets": Array [ Object { "name": "main.js", - "size": 784, + "size": 720, }, ], - "assetsSize": 784, + "assetsSize": 720, "chunks": Array [ "909", ], @@ -402,7 +416,7 @@ Object { "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "d58eb30bef2d7c671efc", + "hash": "c0db196ceebe2a004f20", "logging": Object {}, "modules": Array [ Object { @@ -649,10 +663,10 @@ Object { "assets": Array [ Object { "name": "main.js", - "size": 784, + "size": 720, }, ], - "assetsSize": 784, + "assetsSize": 720, "chunks": Array [ "909", ], @@ -682,7 +696,7 @@ Object { "hotModuleReplacement": false, }, "name": "main.js", - "size": 211, + "size": 207, "type": "asset", }, ], @@ -747,7 +761,7 @@ Object { "hotModuleReplacement": false, }, "name": "main.js", - "size": 378, + "size": 352, "type": "asset", }, ], @@ -800,6 +814,13 @@ Object { "orphan": false, "providedExports": Array [], "reasons": Array [ + Object { + "moduleId": "585", + "moduleIdentifier": "/tests/fixtures/a.js", + "moduleName": "./fixtures/a.js", + "type": "cjs self exports reference", + "userRequest": "self", + }, Object { "moduleId": "432", "moduleIdentifier": "/tests/fixtures/c.js?c=3", @@ -842,6 +863,13 @@ Object { "orphan": false, "providedExports": Array [], "reasons": Array [ + Object { + "moduleId": "958", + "moduleIdentifier": "/tests/fixtures/a.js?a=1", + "moduleName": "./fixtures/a.js?a=1", + "type": "cjs self exports reference", + "userRequest": "self", + }, Object { "moduleId": "919", "moduleIdentifier": "/tests/fixtures/abc-query.js", @@ -891,6 +919,13 @@ Object { "type": "cjs export require", "userRequest": "./c?c=3", }, + Object { + "moduleId": "432", + "moduleIdentifier": "/tests/fixtures/c.js?c=3", + "moduleName": "./fixtures/c.js?c=3", + "type": "cjs self exports reference", + "userRequest": "self", + }, ], "size": 79, "source": "module.exports = function b() { @@ -955,10 +990,10 @@ exports.c = require(\\"./c?c=3\\"); "assets": Array [ Object { "name": "main.js", - "size": 378, + "size": 352, }, ], - "assetsSize": 378, + "assetsSize": 352, "chunks": Array [ "909", ], @@ -968,7 +1003,7 @@ exports.c = require(\\"./c?c=3\\"); "errors": Array [], "errorsCount": 0, "filteredModules": undefined, - "hash": "d7135bcf6947c43df947", + "hash": "9cdb43d7a78e4c33a99a", "logging": Object {}, "modules": Array [ Object { @@ -1002,6 +1037,13 @@ exports.c = require(\\"./c?c=3\\"); "orphan": false, "providedExports": Array [], "reasons": Array [ + Object { + "moduleId": "585", + "moduleIdentifier": "/tests/fixtures/a.js", + "moduleName": "./fixtures/a.js", + "type": "cjs self exports reference", + "userRequest": "self", + }, Object { "moduleId": "432", "moduleIdentifier": "/tests/fixtures/c.js?c=3", @@ -1044,6 +1086,13 @@ exports.c = require(\\"./c?c=3\\"); "orphan": false, "providedExports": Array [], "reasons": Array [ + Object { + "moduleId": "958", + "moduleIdentifier": "/tests/fixtures/a.js?a=1", + "moduleName": "./fixtures/a.js?a=1", + "type": "cjs self exports reference", + "userRequest": "self", + }, Object { "moduleId": "919", "moduleIdentifier": "/tests/fixtures/abc-query.js", @@ -1093,6 +1142,13 @@ exports.c = require(\\"./c?c=3\\"); "type": "cjs export require", "userRequest": "./c?c=3", }, + Object { + "moduleId": "432", + "moduleIdentifier": "/tests/fixtures/c.js?c=3", + "moduleName": "./fixtures/c.js?c=3", + "type": "cjs self exports reference", + "userRequest": "self", + }, ], "size": 79, "source": "module.exports = function b() { @@ -1148,10 +1204,10 @@ exports.c = require(\\"./c?c=3\\"); "assets": Array [ Object { "name": "main.js", - "size": 378, + "size": 352, }, ], - "assetsSize": 378, + "assetsSize": 352, "chunks": Array [ "909", ], diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index 0e6f67f07adc..e1ca012926c4 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -3,8 +3,8 @@ exports[`statsOutput statsOutput/auxiliary-files-test should print correct stats for auxiliary-files-test 1`] = ` "PublicPath: auto asset a09d8e0f399c215faa79.png 7 bytes {909} [emitted] [from: raw.png] (name: main) -asset bundle.js 2.41 KiB {909} [emitted] (name: main) -Entrypoint main 2.41 KiB = bundle.js +asset bundle.js 2.58 KiB {909} [emitted] (name: main) +Entrypoint main 2.58 KiB = bundle.js chunk {909} bundle.js (main) [entry] ./raw.png [193] {909} [no exports] @@ -33,7 +33,7 @@ webpack/runtime/auto_public_path {909} [no exports] [used exports unknown] -Rspack compiled successfully (3004b4b12fa2d8cfc296)" +Rspack compiled successfully (ecb93a91f44e8655019a)" `; exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for builtin-swc-loader-parse-error 1`] = ` @@ -55,32 +55,32 @@ Rspack compiled with 1 error" exports[`statsOutput statsOutput/css-concat-error should print correct stats for css-concat-error 1`] = ` "PublicPath: auto -asset main.js 51 bytes [emitted] (name: main) -Entrypoint main 51 bytes = main.js +asset main.js 49 bytes [emitted] (name: main) +Entrypoint main 49 bytes = main.js ERROR in × Resolve error: Can't resolve './src' in 'Xdir/css-concat-error' -Rspack x.x.x compiled with 1 error in X s (14590012531235fdfcfb)" +Rspack x.x.x compiled with 1 error in X s (ab49ea8e12ee2eaedeac)" `; exports[`statsOutput statsOutput/filename should print correct stats for filename 1`] = ` "PublicPath: auto asset 521.xxxx.js 335 bytes [emitted] -asset 909.xxxx.js 8.74 KiB [emitted] (name: main) -Entrypoint main 8.74 KiB = 909.xxxx.js +asset 909.xxxx.js 8.78 KiB [emitted] (name: main) +Entrypoint main 8.78 KiB = 909.xxxx.js runtime modules 11 modules ./index.js ./dynamic.js -Rspack x.x.x compiled successfully in X s (68af0b9e034af568f652)" +Rspack x.x.x compiled successfully in X s (1441f057611125a5f036)" `; exports[`statsOutput statsOutput/hot+production should print correct stats for hot+production 1`] = ` "PublicPath: auto -asset main.js 32.1 KiB [emitted] (name: main) -Entrypoint main 32.1 KiB = main.js +asset main.js 32.3 KiB [emitted] (name: main) +Entrypoint main 32.3 KiB = main.js runtime modules 11 modules ./index.js -Rspack x.x.x compiled successfully in X s (bb432299572e60c344f6)" +Rspack x.x.x compiled successfully in X s (4a3dde925f48823cbd0d)" `; exports[`statsOutput statsOutput/ignore-plugin should print correct stats for ignore-plugin 1`] = ` @@ -125,21 +125,21 @@ Rspack compiled with 2 errors" exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct stats for limit-chunk-count-plugin 1`] = ` "1 chunks: PublicPath: auto - asset bundle1.js 3.51 KiB [emitted] (name: main) - Entrypoint main 3.51 KiB = bundle1.js + asset bundle1.js 3.69 KiB [emitted] (name: main) + Entrypoint main 3.69 KiB = bundle1.js chunk bundle1.js (main) <{909}> >{909}< [entry] ./b.js ./c.js ./d.js ./e.js ./index.js - 1 chunks (Rspack x.x.x) compiled successfully in X s (7d08f247384080310cc5) + 1 chunks (Rspack x.x.x) compiled successfully in X s (777d79960f54c02a411f) 2 chunks: PublicPath: auto asset 76.bundle2.js 495 bytes [emitted] (name: c) - asset bundle2.js 10.1 KiB [emitted] (name: main) - Entrypoint main 10.1 KiB = bundle2.js + asset bundle2.js 10.3 KiB [emitted] (name: main) + Entrypoint main 10.3 KiB = bundle2.js chunk 76.bundle2.js (c) <{76}> <{909}> >{76}< ./c.js ./d.js @@ -147,14 +147,14 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle2.js (main) >{76}< [entry] ./b.js ./index.js - 2 chunks (Rspack x.x.x) compiled successfully in X s (535e73efb0959a050d83) + 2 chunks (Rspack x.x.x) compiled successfully in X s (8032657b6d1236128b3e) 3 chunks: PublicPath: auto asset 345.bundle3.js 182 bytes [emitted] asset 76.bundle3.js 389 bytes [emitted] (name: c) - asset bundle3.js 10.1 KiB [emitted] (name: main) - Entrypoint main 10.1 KiB = bundle3.js + asset bundle3.js 10.3 KiB [emitted] (name: main) + Entrypoint main 10.3 KiB = bundle3.js chunk 345.bundle3.js <{76}> ./d.js ./e.js @@ -163,15 +163,15 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle3.js (main) >{76}< [entry] ./b.js ./index.js - 3 chunks (Rspack x.x.x) compiled successfully in X s (b3d9890d88975ac30dd7) + 3 chunks (Rspack x.x.x) compiled successfully in X s (38f4a0a213dd867cba24) 4 chunks: PublicPath: auto asset 697.bundle4.js 128 bytes [emitted] asset 753.bundle4.js 128 bytes [emitted] asset 76.bundle4.js 389 bytes [emitted] (name: c) - asset bundle4.js 10.1 KiB [emitted] (name: main) - Entrypoint main 10.1 KiB = bundle4.js + asset bundle4.js 10.3 KiB [emitted] (name: main) + Entrypoint main 10.3 KiB = bundle4.js chunk 697.bundle4.js <{76}> ./e.js chunk 753.bundle4.js <{76}> @@ -181,7 +181,7 @@ exports[`statsOutput statsOutput/limit-chunk-count-plugin should print correct s chunk bundle4.js (main) >{76}< [entry] ./b.js ./index.js - 4 chunks (Rspack x.x.x) compiled successfully in X s (ea15c057f924da088c91)" + 4 chunks (Rspack x.x.x) compiled successfully in X s (b301d29aba57cb3237c3)" `; exports[`statsOutput statsOutput/logging-loader should print correct stats for logging-loader 1`] = ` @@ -198,15 +198,15 @@ exports[`statsOutput statsOutput/minify-error should print correct stats for min ╭─[1:1] 1 │ const a {} · ─ - 2 │ (function() { - 3 │ var __webpack_modules__ = { + 2 │ (() => { // webpackBootstrap + 3 │ var __webpack_exports__ = {}; ╰──── Rspack compiled with 1 error" `; exports[`statsOutput statsOutput/named-chunk-group should print correct stats for named-chunk-group 1`] = ` -"Entrypoint main 8.73 KiB = main.js +"Entrypoint main 8.77 KiB = main.js Chunk Group cimanyd 335 bytes = cimanyd.js" `; @@ -222,8 +222,8 @@ Rspack compiled with 1 error" `; exports[`statsOutput statsOutput/optimization-runtime-chunk should print correct stats for optimization-runtime-chunk 1`] = ` -"Entrypoint e1 3.77 KiB = e1~runtime.js 3.44 KiB e1.js 336 bytes -Entrypoint e2 3.77 KiB = e2~runtime.js 3.44 KiB e2.js 336 bytes +"Entrypoint e1 4.01 KiB = e1~runtime.js 3.68 KiB e1.js 336 bytes +Entrypoint e2 4.01 KiB = e2~runtime.js 3.68 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e1~runtime.js (e1~runtime) [initial] chunk e2.js (e2) [entry] @@ -231,8 +231,8 @@ chunk e2~runtime.js (e2~runtime) [initial]" `; exports[`statsOutput statsOutput/optimization-runtime-chunk-multiple should print correct stats for optimization-runtime-chunk-multiple 1`] = ` -"Entrypoint e1 3.77 KiB = runtime~e1.js 3.44 KiB e1.js 336 bytes -Entrypoint e2 3.77 KiB = runtime~e2.js 3.44 KiB e2.js 336 bytes +"Entrypoint e1 4.01 KiB = runtime~e1.js 3.68 KiB e1.js 336 bytes +Entrypoint e2 4.01 KiB = runtime~e2.js 3.68 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e2.js (e2) [entry] chunk runtime~e1.js (runtime~e1) [initial] @@ -240,16 +240,16 @@ chunk runtime~e2.js (runtime~e2) [initial]" `; exports[`statsOutput statsOutput/optimization-runtime-chunk-single should print correct stats for optimization-runtime-chunk-single 1`] = ` -"Entrypoint e1 3.77 KiB = runtime.js 3.44 KiB e1.js 336 bytes -Entrypoint e2 3.77 KiB = runtime.js 3.44 KiB e2.js 336 bytes +"Entrypoint e1 4.01 KiB = runtime.js 3.68 KiB e1.js 336 bytes +Entrypoint e2 4.01 KiB = runtime.js 3.68 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e2.js (e2) [entry] chunk runtime.js (runtime) [initial]" `; exports[`statsOutput statsOutput/optimization-runtime-chunk-true should print correct stats for optimization-runtime-chunk-true 1`] = ` -"Entrypoint e1 3.77 KiB = runtime~e1.js 3.44 KiB e1.js 336 bytes -Entrypoint e2 3.77 KiB = runtime~e2.js 3.44 KiB e2.js 336 bytes +"Entrypoint e1 4.01 KiB = runtime~e1.js 3.68 KiB e1.js 336 bytes +Entrypoint e2 4.01 KiB = runtime~e2.js 3.68 KiB e2.js 336 bytes chunk e1.js (e1) [entry] chunk e2.js (e2) [entry] chunk runtime~e1.js (runtime~e1) [initial] @@ -306,11 +306,11 @@ runtime modules 12 modules ./index.js ERROR in × asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ main.js (303.329 KiB) + │ main.js (303.486 KiB) ERROR in × entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (303.329 KiB) + │ main (303.486 KiB) │ main.js @@ -349,6 +349,7 @@ chunk main.js (main) >{74}< >{751}< >{76}< (prefetch: {74} {751} {76}) [entry]" exports[`statsOutput statsOutput/reasons should print correct stats for reasons 1`] = ` "./a.js + cjs self exports reference self cjs require ./a ./index.js entry ./index" @@ -356,8 +357,8 @@ exports[`statsOutput statsOutput/reasons should print correct stats for reasons exports[`statsOutput statsOutput/resolve-overflow-error should print correct stats for resolve-overflow-error 1`] = ` "PublicPath: auto -asset main.js 496 bytes [emitted] (name: main) -Entrypoint main 496 bytes = main.js +asset main.js 378 bytes [emitted] (name: main) +Entrypoint main 378 bytes = main.js ./index.js ERROR in ./index.js @@ -369,20 +370,20 @@ ERROR in ./index.js ╰──── help: maybe it had cyclic aliases -Rspack x.x.x compiled with 1 error in X s (7f61f2ab4619ed37875a)" +Rspack x.x.x compiled with 1 error in X s (e320e5265f17893abcb2)" `; exports[`statsOutput statsOutput/resolve-unexpected-exports-in-pkg-error should print correct stats for resolve-unexpected-exports-in-pkg-error 1`] = ` "PublicPath: auto -asset bundle.js 1.02 KiB [emitted] (name: main) -Entrypoint main 1.02 KiB = bundle.js +asset bundle.js 945 bytes [emitted] (name: main) +Entrypoint main 945 bytes = bundle.js runtime modules 1 module ./index.js ERROR in ./index.js × Invalid \\"exports\\" target \\"../../index.js\\" defined for '.' in the package config Xdir/resolve-unexpected-exports-in-pkg-error/node_modules/pkg-a/package.json -Rspack x.x.x compiled with 1 error in X s (1bd27b416654b26e67b4)" +Rspack x.x.x compiled with 1 error in X s (65e45aeef39f4464d5f7)" `; exports[`statsOutput statsOutput/runtime-modules should print correct stats for runtime-modules 1`] = ` @@ -394,8 +395,8 @@ webpack/runtime/define_property_getters" exports[`statsOutput statsOutput/runtime-specific-exports should print correct stats for runtime-specific-exports 1`] = ` "PublicPath: auto -asset main.js 1.67 KiB [emitted] (name: main) -Entrypoint main 1.67 KiB = main.js +asset main.js 1.79 KiB [emitted] (name: main) +Entrypoint main 1.79 KiB = main.js ./math.js [exports: add, multiply] [only some exports used: add] @@ -405,13 +406,13 @@ Entrypoint main 1.67 KiB = main.js ./increment.js [exports: decrement, increment, incrementBy2] [only some exports used: increment] -Rspack x.x.x compiled successfully in X s (e07c3d56fbd8ae9f84a7)" +Rspack x.x.x compiled successfully in X s (a74012a3fffb51e812fe)" `; exports[`statsOutput statsOutput/side-effects-bailouts should print correct stats for side-effects-bailouts 1`] = ` "PublicPath: auto -asset main.js 1.69 KiB {909} [emitted] (name: main) -Entrypoint main 1.69 KiB = main.js +asset main.js 1.86 KiB {909} [emitted] (name: main) +Entrypoint main 1.86 KiB = main.js chunk {909} main.js (main) [entry] ./lib.js [467] {909} [exports: test] @@ -440,35 +441,35 @@ webpack/runtime/define_property_getters {909} [no exports] [used exports unknown] -1970-04-20 12:42:42: Rspack x.x.x compiled successfully in X s (e404d96f2e8e100824bc)" +1970-04-20 12:42:42: Rspack x.x.x compiled successfully in X s (60c70856f42105a844ca)" `; exports[`statsOutput statsOutput/simple-export should print correct stats for simple-export 1`] = ` "PublicPath: auto -asset bundle.js 1.35 KiB [emitted] (name: main) -Entrypoint main 1.35 KiB = bundle.js +asset bundle.js 1.25 KiB [emitted] (name: main) +Entrypoint main 1.25 KiB = bundle.js runtime modules 3 modules ./index.js -Rspack x.x.x compiled successfully in X s (d1bbc9fbb95041999c16)" +Rspack x.x.x compiled successfully in X s (2291cf9010086b87df21)" `; exports[`statsOutput statsOutput/simple-module-source should print correct stats for simple-module-source 1`] = ` "PublicPath: auto -asset bundle.js 1.95 KiB [emitted] (name: main) -Entrypoint main 1.95 KiB = bundle.js +asset bundle.js 2.1 KiB [emitted] (name: main) +Entrypoint main 2.1 KiB = bundle.js runtime modules 3 modules orphan modules [orphan] 1 module ./raw.png ./index.js -Rspack compiled successfully (4b30a8086cf4ac46bff6)" +Rspack compiled successfully (bf8a828b2158bcb51e2e)" `; exports[`statsOutput statsOutput/stats-hooks should print correct stats for stats-hooks 1`] = ` "PublicPath: auto -asset main.js 217 bytes [emitted111] (name: main) [testA: aaaaaa] -Entrypoint main 217 bytes = main.js +asset main.js 99 bytes [emitted111] (name: main) [testA: aaaaaa] +Entrypoint main 99 bytes = main.js ./index.js -Rspack compiled successfully (2c363b6b7beda4d45ccc)" +Rspack compiled successfully (f4dda9cb00eba2407136)" `; exports[`statsOutput statsOutput/try-require-module should print correct stats for try-require-module 1`] = ` diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt index a0d3be034489..cc1227d924f4 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _images_file_svg__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./images/file.svg"); @@ -30,7 +30,6 @@ function createImageElement(title, src) { }); }), "./images/file.svg": (function (module) { -"use strict"; module.exports = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPgo=";}), },function(__webpack_require__) { diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt index 6d3d378e46aa..8e422c156048 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _images_file_png__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./images/file.png"); /* harmony import */var _images_file_jpg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./images/file.jpg"); @@ -36,13 +36,10 @@ function createImageElement(title, src) { }); }), "./images/file.jpg": (function (module) { -"use strict"; module.exports = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAABIAAAAAQAAAEgAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAAJagAwAEAAAAAQAAAJYAAAAA/+0AOFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAAOEJJTQQlAAAAAAAQ1B2M2Y8AsgTpgAmY7PhCfv/CABEIAJYAlgMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAADAgQBBQAGBwgJCgv/xADDEAABAwMCBAMEBgQHBgQIBnMBAgADEQQSIQUxEyIQBkFRMhRhcSMHgSCRQhWhUjOxJGIwFsFy0UOSNIII4VNAJWMXNfCTc6JQRLKD8SZUNmSUdMJg0oSjGHDiJ0U3ZbNVdaSVw4Xy00Z2gONHVma0CQoZGigpKjg5OkhJSldYWVpnaGlqd3h5eoaHiImKkJaXmJmaoKWmp6ipqrC1tre4ubrAxMXGx8jJytDU1dbX2Nna4OTl5ufo6erz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAECAAMEBQYHCAkKC//EAMMRAAICAQMDAwIDBQIFAgQEhwEAAhEDEBIhBCAxQRMFMCIyURRABjMjYUIVcVI0gVAkkaFDsRYHYjVT8NElYMFE4XLxF4JjNnAmRVSSJ6LSCAkKGBkaKCkqNzg5OkZHSElKVVZXWFlaZGVmZ2hpanN0dXZ3eHl6gIOEhYaHiImKkJOUlZaXmJmaoKOkpaanqKmqsLKztLW2t7i5usDCw8TFxsfIycrQ09TV1tfY2drg4uPk5ebn6Onq8vP09fb3+Pn6/9sAQwAEBAQEBAQEBAQEBgYFBgYIBwcHBwgMCQkJCQkMEwwODAwODBMRFBAPEBQRHhcVFRceIh0bHSIqJSUqNDI0RERc/9sAQwEEBAQEBAQEBAQEBgYFBgYIBwcHBwgMCQkJCQkMEwwODAwODBMRFBAPEBQRHhcVFRceIh0bHSIqJSUqNDI0RERc/9oADAMBAAIRAxEAAAH3/bVttW21baKnVRdMbDMXyabbBttq22rbattq22rYHP6891zzLej5UdFzvRA89aVe25+zccNc8HqdBkL4+/baO21bbUije0vZ57JOV6PkJJbUePVfMfJK3pz94p/PvTcXZa0qziW+5y2x6Oklk98v2ttg221cY/rwez890jA3P8vfwVF6d5z7fjt9t1cu2sVN76hzbzwvdvqnMLG06fmOn5O/bbl7dtq4sBwe581d+J+2eJu7n0fyHdfP3XF9L6by9XJOOGpdM3fSch1++PfsLCv87otOn5jp/P8AV225e3bauLAcHufNXfiftvj7a0m29by49b8k9c8/0PJNt6Hn7r+Q7zm6uzr37Dzui06fmOn8/wBXbbl7dtq4yytec9LyLUVHtMWPm/r1nsvgnrlN0bN41ad/1GmNJdVA+TbpK6ss0eenbuOD0ttsujbatX2GZOOa91Ud3mc5ii7fPedDyPRcndSg26+HZ10OPRS9A63nerttj07bVttW21bbUijv9pjwvQWUdHLyV9aEV4nbl7dtq22rbattq22rbattq22rbattq22rbattq//aAAgBAQABBQL/AFXLdIQ5JSiKOdEn8/JOiNyTrk7T/wCLOO6WhokRIP5pciIxJdKV9yf/ABbsCQY7thQUPvFQSJLtkknslClkW8cSU7rt8y5LRkEd0LUgx3aVfeVyZ3Jbrj7AEmO0d1vNtbC5u7i7U7TcrmzdvuFlfuS1WnvHaqU0KiSfuSfvY7pSWYYZ3d3cO2ou9xubz71nvFzbOIwX8P0Fs5LhcjtP3v3Jf3jsuKN4gVJdbJHIJIpIV97a0nu1Q7ZZbei23YXd5c/vnafvfuS/vHZcbn/GbW+uLMxX1huibzZJoWiNci7TYwBc7zb26Zp5rhex/wCP3P752n737kv7x2XG5/xntZ7vcWruLqK2tru/ubw9tj/x+5/fO0/e/cl/eOy43P8AjPY8Nz/2j99j/wAfuf3ztP3v3Jf3jsuN/bzQXHY8Nz/2j99jt5vebn987T979yQEyx2jVcRxAXEcqbvYkLcsMsCzw3P/AGju2s7i7VbbPa2oVdsLhuBJbLQ7T979whMQknXJ3RKuNlVtdovNikS76CaXa7TY442q4RGlSlLPaK5WlhCa/dkt0SOSFcf3I51xuSXCJci5PuR2y1uOJEf8zJaJU1oUg9p/8W7RwrkcduiP+cKQoSWjIIc/+LJQpZjtEj/UC40SBUSVISkJH+q//9oACAEDEQE/Aez38X3/AHXsFmmM4zG6Bsd+bqMeH8R5/IeXN1eTLx+GP5B6f+H1X/WNhknjNwlTh66MuMv2n8/R88js6rJn23hrZ6yjyXkn8yjpxCPudTP24/l/aKevjj+3p8I2eu7kyY/pup/hS9vJ/iS8H/A5Mc8Rqcaemn1AlWHkeoPhjLcPI/rX56+7PFlmYSr7ijJi9uOT7MWXJYEq4sPVYuohPdnuV/2vIOkYykRGIJJ9A9OJ4xHF1mQHdxHGeS588gZYYfZCJIoer0H8D/go6z/HP/CXqv8AJOm/wy/2rh6vJhGz8eP1hLwx6fpOpEsuOZxiPM4kXX+Bl1cMIOPo4bR6zP4i9KTLqsJJsmYc/wDGy/7/AJeg/gf8FHWf45/4S9SCej6cgcAyv/X06L+F13/WLTowT1OGhf3Bz/xsv+/5eg/gf8FHWePD08jLN98ybEfR/WZt18bf8WuGWHpup/AfZyfl/ZL0/T5sMOthOBs4+P6/4GHQiAE+qnsH+KPxFPUbBs6aHtx/2JRmxZ/tzxqX+PH/AHy9PiOHHsJvm9ZwjkG2cbDm6Aj7sJsfkUgg0RRemy5Biz/cfthY/okmRuRsuHpcmbkCo/mXD02LDyBcvzPdlwY8w++P+f1YdJLGM8RIETjQcPRY8fM/ul/sPr//2gAIAQIRAT8B7Payfb9v4jQZRlE1IUe/Hhnl8Dj83F08MfPmX5lzfj6f/f8AZwjMVIW5eklHnHyPy9e3BDFf8z8X5Hw+H3ZZJbOnhvl+foGPxxmN2fMd/pt8RZw6jpvxj3Mf+NHz/nYTjMXE2544SLycH8/VkKPr/n19uGSERIegRjyHJKFSy48dExvmi9Nl6ecNuCo1/Z8EaSlGAMpEAD1L1GzKZZekxEbOZZBwHFijUcsvukRfL1f8X/MNY/hj/gD0X+VdT/gi5ukxZjv/AAZPScfKc/V9MY4skBlMuISBqz/Vj0k8xGTrJ7vygPwh6kCPS5gBQEC4v4WP/f0PV/xf8w1j+GP+APRyA6vqATyRGtOs/jdD/wBZdOsIHTZrNfaQ4v4WP/f0PV/xf8w1jPJmG3H9sRwZer+mx163/jXyw6nqOn4yfzcf5/2g5+ow5Z9FOExQy83xX+FydfZMOljvP+Mfwh9o5Dv6iZnL/YB9vJi5wm4/4pc2T3J7qrjWMpQNxNFxdWDxk4/qgg8gufHD3MP2/ilRQABQFBydRDH62fyDkzzyeTQ/Id2PLPGftP8AmZdTGZxEitsrLl6qc+I/aP8AY/X/AP/aAAgBAQAGPwL/AFXRPUf1NMnyfofT+f11Po/QenZH+T2orqH630n+bqouiOkfr+4j/J71B1dJPxdUmo+/VRoHSP8AF1Jqe9EirMlwsUHHyDMGdBwBUKJPydYjUejoe9UmjovQ/q+8UE9QdeKfXtQDV5Smg9GY7VIkV8PZH2+bynkr6DyH2dgEKyj/AGFcPs9GEK6Jf2VcfsLqnqH6+9V6D9b5SPur/tF0XqP1vJB/Bj6JRKuFB/CXSRdEfsJ4f6P3gmT6WP0VxH2tMyUqTX1FC/VX63Tgl/5J+7J/aPaT7HNbXsYCc1Jy4pIBpq+dYLGuuFek/IsxyoKVeh+5jBHX1PkPmXz72RKlD9r2R8h5sQRR0ixUaniaNX2dv8k/dk/tHtJ9juP92r/4M6wr6fNB9ksQ3SAmTyCvX+SWV230qPT8w/uvloQVL/ZA1fNvlaccAf4S+RYISaaV/IPl6vmTSFSvj/U0/wC61tX2dv8AJP3ZP7R7SfY7n/dq/wDg3cJX9LF6K4j5F++iGpWE/AmvCr+lV0fsD2e6f91ravs7f5J+7J/aPaT7Hc/7tX/wbuXD/wAI/cT/ALrW1fZ2/wAk/dk/tHtJ9jlMsZAVIopPkanuXD/wj9wXHLPKwUMj8fRq+zt/kn7qwP2i6y6fB4RD+4zHcIFDx8w+ZZKp/IPD7C+XMgoV6Flw/wDCPakEdR5q4JH2sSXJEi/j7I+x/Rp0+LxUKKdU9Q/W/wDJP3VLSip+D14enfpP2PlXMY+3+pqXZqzH7B4/YXDDHGTJ9Fp8nzL1eX8gez9vqxHAgUHD0dVGvcJPUP1vmY0VT71eCvV6jT1+56j0LElONP1vqP3KnpD6R9v8zVGh/U6KFO6P8nv0jT1deKvX+cooVDrH+DoRq0f5LokVdZNT6eX+oKKDCDwFP1OiRQf6s//EADMQAQADAAICAgICAwEBAAACCwERACExQVFhcYGRobHB8NEQ4fEgMEBQYHCAkKCwwNDg/9oACAEBAAE/If8A9LkP6VQsCuz5uePtf1/+flr0ubPi+l/f/wCBIj+lWcT+Ts//AC8w/B22b/sX/wCD9L/oEoHZXIGfX+ylieQ//G0IHbecfv8A0VUpO3/sw6odJTJh+Wr3gyxe3VQPMJc/TUUETp/7Lmv02IH3f4yiOn/4ZOgp4T4s8D1P7/4CUrouGI2D/LQDPJw3v+iyARZ4fi/4/PKf9lG6DhI/tWZ/pX/PRYz4bt/qkX0FzY+//wAOVP8ABsZ8t/jbwU3f9yv/AMGC+3CtPgeX3/2//FKKPsy9f7XpDl/+8e7Ay8Pyv9WeHxH9t/zPj/8AD/iPP/P0KB8DwlAR6+eLmwEFL+CpQ/yMPz7P/wAElkXXLBDYk4b9ixPrudCIOjb+v/D/AJz/AOHH/wCH/Eef+foV/n/K91KdH0dfJUqrkfl5f3Z7PLcGurGj7HX3RQwajB/n1cG3AkfAKdeUuB6HRf8AEer+v/D/AJz/AOHH/wCH/Eef+foV/k/L/sukO7L/AAxrvjBI8ieqqxlmY+fL8/8Af8R6v6/8P+c/+HH/AOH/ABHn/n6Ff5Py/wC/oN/S/p/+D/Eer+v/AA/5z/4cf/h/xHn/AJ+hXXYdoiQ+fX/f0G/pf0//AATyI4ELCNc39f8Ah/zn/wAOP/wgYqwB81naHhz9tjDU8cP91skokS/JQEbdll/wVh4Nefjz9X9Bv6X9P+T6Awn5H+lJOtzDeu33Y0Aj+X+qO8IHn6bOf0q8/wD+EZKjLyd/q5ajxcf9ZnPvo2dCPXGfK6abgLrB/Q/dyWZ1TEzPEUQIjZIHy5/hRxCiBB+Cyjr3/wBbA9R/StIka6d8/wD4p6Hqf3ezvBx/+DHH/EywhNwFpyZ/B0f/AIIv5F5fgo/Z2uf/AMhBxswvq/xllzX6f/xIn+Q4scj3P6//ADGxE6a5Kz7/ANNZVA6f+JNuv4sSn+R90AIOP/z9w/D2VF39ygxPAf8A6Z//2gAMAwEAAhEDEQAAEAAABDigAAAAABwvg5QwAAHQ1gOR/ogACa6AB62QAAKawFmNIQQAKZgEgFCQQAIAVRCMlCwAEbyvYAEwAAAAA+iAAAAAAAAAAAAAAP/EADMRAQEBAAMAAQIFBQEBAAEBCQEAESExEEFRYSBx8JGBobHRweHxMEBQYHCAkKCwwNDg/9oACAEDEQE/EPwOxD9QgIuFvk/GMmvx5v8Ai0w/1b835v1352/y+c6fzPmzyPou3+IQCCPInX4NTR1Rgne/S+6R/NWBB+Fc/kEoF9esff6XwR/k5vutbl8b0/kxgnb6D+f0i1ETjTQHZvooy5D4efkhccWdhM/jZcnwN/wH/XnAzYDVuBr+A14FfiK06ReDnL97p9P1r6+PNFiccjH2+kAPeuH1X0tKMZy/8BKWQKuq783679fwJ+tfWe46YODeG+fpPs+b4YZw3Ae2/Xfr+BNwkgmHX5fmeIzjOLj9MuSJfn3fb6QgWPPJ27HdsG+Tm/wQ5wfk5y+qwB8NC5/h82QPKE40fVoG+H/Vt/uC/h+ZU4OETEjEy5nnX22eNTtXWwv2Ffx9bE/dF/H0/FhNH4HA/m15JXh372Jn97p/Hz/P/wB//9oACAECEQE/EPwGTUdjxrImh8P43ty+a6/7Y6P6R+RfrPysdx/U/K0G/pH+ZEUTE7H8GebO4eL6Z9bgfAB+QEIM+YcfnMgVx9FPtvdvOd8XA+yx3H9T8yeufAP02XJAPJjFPr6g29T8nHw3CDR5X9zI99QZ/kH+/OQmymBPNWeQ85QPlmIo2uebzwXf7fr30v0b6WQaHPAD9/rODv8AjgFqTnK8/wAkYYGAYBnxfqH0u/2/XvpFFMIvLh8efp/y8xz0TXNU6PvfqH0u/wBj+JBHPA+CDy63v1H1soEvj1ff6zsWrbXXo9XHC8PF/kn7KE8flBO35ovx/DFlXAI/U9EP+oWIevp6/kgQCPSckxMfC8afxChB0BhbY/onP0t8/YT+fr+LTcfyuR/iYasA54+1ofxvb+f/AL//2gAIAQEAAT8Q/wD0pQ1uIxnh09vfwWXj5pBjseLHee5v27//ADx3wXf7ePutS/34/Ll/ivD8X9b+N4hOS7DDJXD0vP3YFIcmfIf/AJcCEvZ8B3Y9KZI4e3r6rKqsrr/x4b/mfH/ePIiQlyHcQ7/h2VoI4ST/APHzIQSCs45xDv8Ah23myAkr/wBD9gwYfLwXIGqwnkiaUeVF4oFjHSxPVaTIghj8D93AuyEJ9P8A3yLCN+Q4bFNxx5f480AQRJE0f/wlMB8mUML0S5IXToenX8f848iBK1CBBIAgfQHxZcpyoTwavt7aJy4vx7B9svu+ffNTgt1ET2/gz1UfCQMz6M+Jvksq0NgID2d/VRFEhMR6oKgKrABKvqz7eeNBhlaOEImfLf8A8LUiIwjCPhY5vHHh8/4aMT6JwJ8icNDk+Cgbxvo5eiy7l5Mf7r8PX/4f/v4o78Mwk88yB1P5KAaGpKfOeISPTQlZMLHwjpZkTd+p+z4vJ/hv/wCMh/hfLcU1tyh5VBuu2WAvmHHxz8Bk+LugfEPDr2Cn/wCBZgz8zmD6JfVWloAgdB5fCsvgKxdHzgUHPe30X/IeH/P8B5//ABkP8L5biG6HULQ+dPc+h8zcb8QxIiHCeBnpYQ5KcBejA/EPprZ4TQownJDtgHdPL+ARzxZ5IHtovo435wF/EHuoU8wmL0M9QfP/AD//ACHh/wA/wHn/APGQ/wAL5f8Au1BEQR5EkaWCetQeeXOpD4oNI6DUYHOS3mOqaR8puySHJefoF55/7/8A5Dw/5/gPP/4yH+F8v/4Nv+C8f/ic/wD8h4f8/wAB5/8AxkP8L5aq75ExtMmHVvr/AL/gvH/4HPPra0y3Dj1gnOTPd/yHh/z/AAHn/wDCJG0CV9AoRFdm4fo+q1xZOG+e1wJqsL5JimdiD/yp9Rk+KOETwIHbJD7SX/BeP+uaAoGR7Mn1J9VrJgwDSeZnmXoK4+UJEQOgOFNFBogP7vi7qHcMPZ39X/AeT/8AC3n0aVU6vHwqL4fn9vP3/wBmoEym/Mf2VpwMCfqL4nGq0dIwkcwHwQfbVVgYgjwAENnija4S/wAd9hno3EFqSnRxWvkFceg6P+pCDHIfl38NkO0JMIMAyc//ABRJI6eX04f5rq7Ob/fx9/8A4IuG90n25KwuDgg+SeLJ4Dhz4j/8Ea5dhw/w1sK3kaH9/wBH/wCQAgIkI6JYpuefL/Hi+DYLvwPD/wAeG/rfx/6SxnuZ+PP1cwLpwfTr+f8A8zmogElyHcy7/h5vL8QIS/rfxvnIEcfJ4LEpzQ4fNAgAEAEAf/nwpQ4M+BKhz0GHol990aI4CD/9M//Z";}), "./images/file.png": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; module.exports = __webpack_require__.p + "cee6b2eecb9ff70a.png";}), "./images/file.svg": (function (module) { -"use strict"; module.exports = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2MDAgNjAwIj48dGl0bGU+aWNvbi1zcXVhcmUtc21hbGw8L3RpdGxlPjxwYXRoIGZpbGw9IiNGRkYiIGQ9Ik0zMDAgLjFMNTY1IDE1MHYyOTkuOUwzMDAgNTk5LjggMzUgNDQ5LjlWMTUweiIvPjxwYXRoIGZpbGw9IiM4RUQ2RkIiIGQ9Ik01MTcuNyA0MzkuNUwzMDguOCA1NTcuOHYtOTJMNDM5IDM5NC4xbDc4LjcgNDUuNHptMTQuMy0xMi45VjE3OS40bC03Ni40IDQ0LjF2MTU5bDc2LjQgNDQuMXpNODEuNSA0MzkuNWwyMDguOSAxMTguMnYtOTJsLTEzMC4yLTcxLjYtNzguNyA0NS40em0tMTQuMy0xMi45VjE3OS40bDc2LjQgNDQuMXYxNTlsLTc2LjQgNDQuMXptOC45LTI2My4yTDI5MC40IDQyLjJ2ODlsLTEzNy4zIDc1LjUtMS4xLjYtNzUuOS00My45em00NDYuOSAwTDMwOC44IDQyLjJ2ODlMNDQ2IDIwNi44bDEuMS42IDc1LjktNDR6Ii8+PHBhdGggZmlsbD0iIzFDNzhDMCIgZD0iTTI5MC40IDQ0NC44TDE2MiAzNzQuMVYyMzQuMmwxMjguNCA3NC4xdjEzNi41em0xOC40IDBsMTI4LjQtNzAuNnYtMTQwbC0xMjguNCA3NC4xdjEzNi41ek0yOTkuNiAzMDN6bS0xMjktODVsMTI5LTcwLjlMNDI4LjUgMjE4bC0xMjguOSA3NC40LTEyOS03NC40eiIvPjwvc3ZnPgo=";}), },function(__webpack_require__) { diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt index a28eb954e908..1d5084bfe3c9 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _data_txt__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./data.txt"); console.log(_data_txt__WEBPACK_IMPORTED_MODULE_0__); }), "./data.txt": (function (module) { -"use strict"; module.exports = "- Isn't Rspack a gamechanging bundler?\n - Hella yeah!";}), },function(__webpack_require__) { diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt index 25f6074eeedf..63e76c9ba19c 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt @@ -24,36 +24,32 @@ ``` ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _style_module_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.module.css"); }), "./b.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "b-1": "___b_module____b-1--___eca6dd2253f6b569_eca", "b": "___b_module____b--___eca6dd2253f6b569_eca" + " " + "___b_module____b-1--___eca6dd2253f6b569_eca", }); }), "./d.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "d-1": "___d_module____d-1--___a41e34edaa1ca3c_a41", "d": "___d_module____d--___a41e34edaa1ca3c_a41" + " " + "___d_module____d-1--___a41e34edaa1ca3c_a41", }); }), "./f.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "f-1": "___f_module____f-1--___af10a85c64a6b515_af1", "f": "___f_module____f--___af10a85c64a6b515_af1" + " " + "___f_module____f-1--___af10a85c64a6b515_af1", }); }), "./style.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "chain2": "___style_module____chain2--___afc435275e612570_afc" + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], "chain1": "___style_module____chain1--___afc435275e612570_afc" + " " + "___style_module____chain2--___afc435275e612570_afc" + " " + "c" + " " + __webpack_require__("./d.module.css")["d"] + " " + "e" + " " + __webpack_require__("./f.module.css")["f"], diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt index b038d1133eaa..c3712ac63c31 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt @@ -6,16 +6,15 @@ ``` ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _style_module_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.module.css"); console.log(_style_module_css__WEBPACK_IMPORTED_MODULE_0__); }), "./style.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "foo": "___style_module____foo--___afc435275e612570_afc", }); diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt index 03a08613df70..e0f853a8a96f 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-html/variant/__snapshots__/output.snap.txt @@ -4,7 +4,7 @@ Rspack App - + diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt index a03b661efd89..273c6af0f810 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/builtins-define/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); // import assert from "assert"; @@ -253,7 +253,6 @@ console.log(console.log(console.log)); // TODO: recursive // assert.equal(suppe, wurst); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { DO_NOT_CONVERTED7: function() { return DO_NOT_CONVERTED7; }, diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt index ec612da42d42..7470f7fb98da 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-javascript/hashbang/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); //#!/usr/bin/env node @@ -9,7 +9,6 @@ __webpack_require__.r(__webpack_exports__); console.log("index", _lib__WEBPACK_IMPORTED_MODULE_0__.foo); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { foo: function() { return foo; } diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt index 39062b623d55..a7da44e999f3 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-json/simple/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _json_json__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./json.json"); /* harmony import */var _string_json__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./string.json"); @@ -10,10 +10,8 @@ __webpack_require__.r(__webpack_exports__); console.log(_json_json__WEBPACK_IMPORTED_MODULE_0__, _string_json__WEBPACK_IMPORTED_MODULE_1__); }), "./json.json": (function (module) { -"use strict"; module.exports = JSON.parse('{"hello":"world is better \'","b":"\\\\"}')}), "./string.json": (function (module) { -"use strict"; module.exports = "hello world"}), },function(__webpack_require__) { diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt index dd02754f2da6..0123381c7896 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/imports-multiple/__snapshots__/output.snap.txt @@ -17,9 +17,9 @@ var __webpack_exports__ = (__webpack_exec__("./index.js")); ``` ```js title=wasm_wasm.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["wasm_wasm"], { "./module.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.a(module, async function (__webpack_handle_async_dependencies__, __webpack_async_result__) { try { __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -37,7 +37,6 @@ function getNumber() { __webpack_async_result__(); } catch(e) { __webpack_async_result__(e); } });}), "./module2.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.a(module, async function (__webpack_handle_async_dependencies__, __webpack_async_result__) { try { __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -53,7 +52,6 @@ function getNumber() { __webpack_async_result__(); } catch(e) { __webpack_async_result__(e); } });}), "./wasm.wasm": (function (module, exports, __webpack_require__) { -"use strict"; var __webpack_instantiate__ = function ([WEBPACK_IMPORTED_MODULE_0, WEBPACK_IMPORTED_MODULE_1]) { return __webpack_require__.v(exports, module.id, "99f401a36b8fee81" , { "./module": { diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt index e73655adfb58..c5363e05cf5b 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-wasm/v128/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.a(module, async function (__webpack_handle_async_dependencies__, __webpack_async_result__) { try { __webpack_require__.r(__webpack_exports__); /* harmony import */var _v128_wasm__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./v128.wasm"); @@ -12,7 +12,6 @@ console.log(_v128_wasm__WEBPACK_IMPORTED_MODULE_0__["default"].x); __webpack_async_result__(); } catch(e) { __webpack_async_result__(e); } });}), "./v128.wasm": (function (module, exports, __webpack_require__) { -"use strict"; module.exports = __webpack_require__.v(exports, module.id, "83b6564dd2e8778e" );}), },function(__webpack_require__) { diff --git a/packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt index 0347bac9f8fc..77e1d49f694e 100644 --- a/packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/rspack/dynamic-import/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=child_a_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["child_a_js"], { "./child/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: function() { return a; } @@ -13,9 +13,9 @@ const a = "a"; ``` ```js title=child_b_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["child_b_js"], { "./child/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { b: function() { return b; } diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt index bacc541abddd..67453dbd4306 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/ancestor-has-all-modules/__snapshots__/output.snap.txt @@ -39,9 +39,9 @@ __webpack_require__.e(/* import() */ "shared_js").then(__webpack_require__.bind( ``` ```js title=shared_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["shared_js"], { "./shared.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foo__WEBPACK_IMPORTED_MODULE_0__); diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/__snapshots__/output.snap.txt index 5eea8a0d680b..887a60676ffd 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/concatenate-modules/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function () { -"use strict"; ;// CONCATENATED MODULE: ./answer.js const answer = 103330; diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt index cb347ea61ae9..a026038c5cb9 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-dynamic-entry/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=dynamic-1_js-_1d740.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["dynamic-1_js-_1d740"], { "./dynamic-1.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./shared.js"); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_shared__WEBPACK_IMPORTED_MODULE_0__); @@ -32,9 +32,9 @@ console.log("shared"); ``` ```js title=dynamic-2_js-_15a90.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["dynamic-2_js-_15a90"], { "./dynamic-2.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./shared.js"); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_shared__WEBPACK_IMPORTED_MODULE_0__); diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt index 463c1e15c441..a0bb829138f8 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/cycle-entry/__snapshots__/output.snap.txt @@ -44,9 +44,9 @@ var __webpack_exports__ = (__webpack_exec__("./index2.js")); ``` ```js title=index_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["index_js"], { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./shared.js"); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_shared__WEBPACK_IMPORTED_MODULE_0__); diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/__snapshots__/output.snap.txt index 889de5665e76..d5f9a737be50 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/mangle-exports/__snapshots__/output.snap.txt @@ -1,20 +1,18 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { K: function() { return answer; } }); const answer = 103330; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); _lib__WEBPACK_IMPORTED_MODULE_0__/* .answer */.K; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { K: function() { return /* reexport safe */ _answer__WEBPACK_IMPORTED_MODULE_0__.K; } }); diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt index 5b2613f517b9..ac79e0d75bd1 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/parent-have-partial-module/__snapshots__/output.snap.txt @@ -57,9 +57,9 @@ console.log("shared"); ``` ```js title=shared_js-_ac581.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["shared_js-_ac581"], { "./shared.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _exist__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./exist.js"); /* harmony import */var _exist__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_exist__WEBPACK_IMPORTED_MODULE_0__); diff --git a/packages/rspack-test-tools/tests/builtinCases/samples/simple/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/samples/simple/__snapshots__/output.snap.txt index 272776f2e8cc..e71a988deeb5 100644 --- a/packages/rspack-test-tools/tests/builtinCases/samples/simple/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/samples/simple/__snapshots__/output.snap.txt @@ -1,7 +1,7 @@ ```js title=a_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["a_js"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./shared.js"); /* harmony import */var _shared__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_shared__WEBPACK_IMPORTED_MODULE_0__); diff --git a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/source-map/index.js b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/source-map/index.js index 690ab0d80ef5..432967c32d41 100644 --- a/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/source-map/index.js +++ b/packages/rspack-test-tools/tests/configCases/builtin-swc-loader/source-map/index.js @@ -9,8 +9,9 @@ it("should generate correct sourceMap", async () => { __dirname + "/" + require("!!./a.ts?resource"), "utf-8" ); - expect(map.sources).toContain("webpack:///./a.ts"); - expect(map.sourcesContent[1]).toEqual(sourceContent); + const aSourceIndex = map.sources.indexOf("webpack:///./a.ts"); + expect(aSourceIndex).toBeGreaterThanOrEqual(0); + expect(map.sourcesContent[aSourceIndex]).toEqual(sourceContent); checkStub(["fo", "o"].join(""), sourceContent); checkStub(["ba", "r"].join(""), sourceContent); diff --git a/packages/rspack-test-tools/tests/configCases/css-loader/css-modules-classname/index.js b/packages/rspack-test-tools/tests/configCases/css-loader/css-modules-classname/index.js index 3a13aacbc7dd..47a201bbac09 100644 --- a/packages/rspack-test-tools/tests/configCases/css-loader/css-modules-classname/index.js +++ b/packages/rspack-test-tools/tests/configCases/css-loader/css-modules-classname/index.js @@ -8,6 +8,6 @@ try { it("css modules classname with default output hash options should works", () => { const code = fs.readFileSync(__filename, "utf-8"); - const name = /"__LOCAL_CLASS_NAME__": "(.*)"/.exec(code)[1]; + const name = /"__LOCAL_CLASS_NAME__": [`'"](.*)[`'"]/.exec(code)[1]; expect(name).toEqual("index-module____LOCAL_CLASS_NAME__--b4232134"); }); diff --git a/packages/rspack-test-tools/tests/configCases/library/amd-named/index.js b/packages/rspack-test-tools/tests/configCases/library/amd-named/index.js index e5f9b0cd3c64..23f572176fa0 100644 --- a/packages/rspack-test-tools/tests/configCases/library/amd-named/index.js +++ b/packages/rspack-test-tools/tests/configCases/library/amd-named/index.js @@ -6,7 +6,7 @@ it("should name define", function () { expect(source).toMatch('define("NamedLibrary",'); expect(source.includes("return __webpack_exports__")).toBe(true); - expect(source.includes("return (function() {\nvar __webpack_modules__")).toBe( + expect(source.includes("return (() => { // webpackBootstrap\nvar __webpack_modules__")).toBe( true ); }); diff --git a/packages/rspack-test-tools/tests/configCases/library/array-this/rspack.config.js b/packages/rspack-test-tools/tests/configCases/library/array-this/rspack.config.js index e76b87f14f73..700a9cfed3e2 100644 --- a/packages/rspack-test-tools/tests/configCases/library/array-this/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/library/array-this/rspack.config.js @@ -3,6 +3,9 @@ module.exports = { target: "web", output: { library: ["a", "b"], - libraryTarget: "this" + libraryTarget: "this", + environment: { + arrowFunction: false, + } } }; diff --git a/packages/rspack-test-tools/tests/configCases/source-map/source-map/index.js b/packages/rspack-test-tools/tests/configCases/source-map/source-map/index.js index 63bd1dd77f13..f4b8a7411afd 100644 --- a/packages/rspack-test-tools/tests/configCases/source-map/source-map/index.js +++ b/packages/rspack-test-tools/tests/configCases/source-map/source-map/index.js @@ -10,8 +10,9 @@ it("should map to the original content if `module` enabled", async () => { const app = fs.readFileSync(path.resolve(CONTEXT, "./App.jsx"), "utf-8"); const map = JSON.parse(source); const consumer = await new sourceMap.SourceMapConsumer(map); - expect(map.sources).toContain("webpack:///./App.jsx"); - expect(map.sourcesContent[1]).toEqual(app); + const appSourceIndex = map.sources.indexOf("webpack:///./App.jsx") + expect(appSourceIndex).toBeGreaterThanOrEqual(0); + expect(map.sourcesContent[appSourceIndex]).toEqual(app); const STUB = ["Hello", " ", "Rspack!"].join(""); const { line, column } = consumer.originalPositionFor( positionFor(generated, STUB) diff --git a/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js b/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js index dd5286072e3f..c548e678f98d 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js +++ b/packages/rspack-test-tools/tests/defaultsCases/config/browserslist.js @@ -20,6 +20,34 @@ module.exports = { - "devtoolNamespace": "@rspack/test-tools", + "devtoolNamespace": "browserslist-test", @@ ... @@ + - "arrowFunction": true, + - "asyncFunction": true, + - "bigIntLiteral": undefined, + - "const": true, + - "destructuring": true, + + "arrowFunction": false, + + "asyncFunction": false, + + "bigIntLiteral": false, + + "const": false, + + "destructuring": false, + @@ ... @@ + - "dynamicImport": undefined, + - "dynamicImportInWorker": undefined, + - "forOf": true, + - "globalThis": undefined, + - "module": undefined, + - "nodePrefixForCoreModules": true, + - "optionalChaining": true, + - "templateLiteral": true, + + "dynamicImport": false, + + "dynamicImportInWorker": false, + + "forOf": false, + + "globalThis": false, + + "module": false, + + "nodePrefixForCoreModules": false, + + "optionalChaining": false, + + "templateLiteral": false, + @@ ... @@ - "hotUpdateGlobal": "webpackHotUpdate_rspack_test_tools", + "hotUpdateGlobal": "webpackHotUpdatebrowserslist_test", @@ ... @@ @@ -28,5 +56,8 @@ module.exports = { @@ ... @@ - "", + "/tests/fixtures/browserslist", + @@ ... @@ + - "target": "web", + + "target": "browserslist", `) }; diff --git a/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js b/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js index 7abe74e79755..f4c78dfe2b60 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js +++ b/packages/rspack-test-tools/tests/defaultsCases/experiments/output-module.js @@ -16,6 +16,14 @@ module.exports = { - "chunkFilename": "[name].js", + "chunkFilename": "[name].mjs", @@ ... @@ + - "dynamicImport": undefined, + - "dynamicImportInWorker": undefined, + + "dynamicImport": true, + + "dynamicImportInWorker": true, + @@ ... @@ + - "module": undefined, + + "module": true, + @@ ... @@ - "filename": "[name].js", + "filename": "[name].mjs", @@ ... @@ diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js index d256483984dd..38c6bec667bd 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-main.js @@ -46,6 +46,9 @@ module.exports = { - "fetch", + "async-node", @@ ... @@ + - "document": true, + + "document": false, + @@ ... @@ - "globalObject": "self", + "globalObject": "global", @@ ... @@ diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js index 2938c13cb88c..04c1406c4079 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/electron-preload.js @@ -45,6 +45,9 @@ module.exports = { - "fetch", + "async-node", @@ ... @@ + - "document": true, + + "document": false, + @@ ... @@ - "globalObject": "self", + "globalObject": "global", @@ ... @@ diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/node.js b/packages/rspack-test-tools/tests/defaultsCases/target_/node.js index ec7655bbc442..bf5fa32db2eb 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/node.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/node.js @@ -41,6 +41,9 @@ module.exports = { - "fetch", + "async-node", @@ ... @@ + - "document": true, + + "document": false, + @@ ... @@ - "globalObject": "self", + "globalObject": "global", @@ ... @@ diff --git a/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js b/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js index a70fb15e1c3a..3d46802001bb 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js +++ b/packages/rspack-test-tools/tests/defaultsCases/target_/webworker.js @@ -22,6 +22,9 @@ module.exports = { @@ ... @@ - "jsonp", @@ ... @@ + - "document": true, + + "document": false, + @@ ... @@ + "worker", @@ ... @@ - "target": "web", diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt index 9824b7f0d220..e5459147e7cc 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/hooks.snap.txt @@ -5,13 +5,14 @@ ```javascript Array [ Object { - "main.js": (function() { -var __webpack_modules__ = { + "main.js": (() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -29,15 +30,19 @@ 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__("600"); })() -, +;, }, ] ``` diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt index e48d5b063301..57bb7499d4d6 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#afterProcessAssets/basic/output.snap.txt @@ -1,11 +1,12 @@ ```js title=main.js -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -23,13 +24,17 @@ 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__("600"); })() - +; ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt index ee39beb23ed6..08cb1cf56659 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/hooks.snap.txt @@ -5,13 +5,14 @@ ```javascript Array [ Object { - "main.de1e38a3841970a36482.js": (function() { -var __webpack_modules__ = { + "main.5aece4956ef367dbcfb6.js": (() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -29,15 +30,19 @@ 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__("600"); })() -, +;, }, ] ``` @@ -55,14 +60,15 @@ undefined ```javascript Array [ Object { - "main.de1e38a3841970a36482.js": // UPDATED -(function() { -var __webpack_modules__ = { + "main.5aece4956ef367dbcfb6.js": // UPDATED +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -80,15 +86,19 @@ 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__("600"); })() -, +;, }, ] ``` diff --git a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt index d78c52a08834..3cbd66446a2c 100644 --- a/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compilation#processAssets/update-asset/output.snap.txt @@ -1,12 +1,13 @@ -```js title=main.cb18450578c7263b2f4e.js +```js title=main.f42c84d646de3d5a4d82.js // UPDATED -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -24,13 +25,17 @@ 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__("600"); })() - +; ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt index a20a92f123aa..fc2e50acd545 100644 --- a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/hooks.snap.txt @@ -10,18 +10,33 @@ Array [ "content": Object { "data": Array [ 40, - 102, - 117, - 110, - 99, - 116, - 105, - 111, - 110, 40, 41, 32, + 61, + 62, + 32, 123, + 32, + 47, + 47, + 32, + 119, + 101, + 98, + 112, + 97, + 99, + 107, + 66, + 111, + 111, + 116, + 115, + 116, + 114, + 97, + 112, 10, 118, 97, @@ -49,6 +64,7 @@ Array [ 32, 61, 32, + 40, 123, 10, 34, @@ -118,6 +134,83 @@ Array [ 10, 10, 125, + 41, + 59, + 10, + 47, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 47, 10, 47, 47, @@ -619,6 +712,7 @@ Array [ 41, 59, 10, + 10, 47, 47, 32, @@ -681,6 +775,82 @@ Array [ 10, 125, 10, + 10, + 47, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 47, + 10, 47, 47, 32, @@ -732,6 +902,81 @@ Array [ 116, 115, 10, + 47, + 47, + 32, + 84, + 104, + 105, + 115, + 32, + 101, + 110, + 116, + 114, + 121, + 32, + 109, + 111, + 100, + 117, + 108, + 101, + 32, + 105, + 115, + 32, + 114, + 101, + 102, + 101, + 114, + 101, + 110, + 99, + 101, + 100, + 32, + 98, + 121, + 32, + 111, + 116, + 104, + 101, + 114, + 32, + 109, + 111, + 100, + 117, + 108, + 101, + 115, + 32, + 115, + 111, + 32, + 105, + 116, + 32, + 99, + 97, + 110, + 39, + 116, + 32, + 98, + 101, + 32, + 105, + 110, + 108, + 105, + 110, + 101, + 100, + 10, 118, 97, 114, @@ -791,17 +1036,19 @@ Array [ 40, 41, 10, + 59, ], "type": "Buffer", }, "outputPath": "/compiler#assetEmitted/basic", - "source": (function() { -var __webpack_modules__ = { + "source": (() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -819,15 +1066,19 @@ 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__("600"); })() -, +;, "targetPath": "/compiler#assetEmitted/basic/main.js", }, ] diff --git a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt index e48d5b063301..57bb7499d4d6 100644 --- a/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/compiler#assetEmitted/basic/output.snap.txt @@ -1,11 +1,12 @@ ```js title=main.js -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "600": (function (module) { module.exports = "This is hook"; }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -23,13 +24,17 @@ 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__("600"); })() - +; ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt index 55851dde92b9..3ba57a437686 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/output.snap.txt @@ -1,39 +1,17 @@ ```js title=main.js -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "./a.js": (function (module) { module.exports = "a"; }), "./c.js": (function (module) { module.exports = "c"; }), -"./duplicate.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); - - -// b.js will be transform to c.js - - -it("should remove duplicate request modules generate by after resolve hook", ()=>{ - expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); - expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); - expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); - const ext = ".js"; - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).not.toContain("./b" + ext); - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./c" + ext); - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8").split("./c" + ext).length - 1).toBe(2); -}); -}), "fs": (function (module) { module.exports = require('fs')}), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -51,12 +29,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/compat_get_default_export -!function() { +(() => { // getDefaultExport function for compatibility with non-harmony modules __webpack_require__.n = function (module) { var getter = module && module.__esModule ? @@ -69,9 +50,9 @@ __webpack_require__.n = function (module) { -}(); +})(); // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -79,17 +60,42 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./duplicate.js"); -})() +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be in strict mode. +(() => { +"use strict"; +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); +/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); + + +// b.js will be transform to c.js + +it("should remove duplicate request modules generate by after resolve hook", ()=>{ + expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); + expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); + expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); + const ext = ".js"; + expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).not.toContain("./b" + ext); + expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./c" + ext); + expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8").split("./c" + ext).length - 1).toBe(2); +}); + +})(); + +})() +; ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt index 21ae69b8b57d..5c5ec00a2c52 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt @@ -1,34 +1,17 @@ ```js title=main.js -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "./a.js": (function (module) { module.exports = "a"; }), "./c.js": (function (module) { module.exports = "b"; }), -"./request.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); - - - -it("should modify request by after resolve hook", ()=>{ - expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); - expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("b"); - const ext = ".js"; - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./c" + ext); -}); -}), "fs": (function (module) { module.exports = require('fs')}), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -46,12 +29,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/compat_get_default_export -!function() { +(() => { // getDefaultExport function for compatibility with non-harmony modules __webpack_require__.n = function (module) { var getter = module && module.__esModule ? @@ -64,9 +50,9 @@ __webpack_require__.n = function (module) { -}(); +})(); // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -74,17 +60,37 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./request.js"); -})() +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be in strict mode. +(() => { +"use strict"; +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); +/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); + + +it("should modify request by after resolve hook", ()=>{ + expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); + expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("b"); + const ext = ".js"; + expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./c" + ext); +}); + +})(); + +})() +; ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt index 5e1c8434afb2..db65ba43bb0d 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt @@ -1,34 +1,17 @@ ```js title=main.js -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "./a.js": (function (module) { module.exports = "a"; }), "./b.js": (function (module) { module.exports = "c"; }), -"./resource.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); - - - -it("should modify resource by after resolve hook", ()=>{ - expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); - expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); - const ext = ".js"; - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./b" + ext); -}); -}), "fs": (function (module) { module.exports = require('fs')}), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -46,12 +29,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/compat_get_default_export -!function() { +(() => { // getDefaultExport function for compatibility with non-harmony modules __webpack_require__.n = function (module) { var getter = module && module.__esModule ? @@ -64,9 +50,9 @@ __webpack_require__.n = function (module) { -}(); +})(); // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -74,17 +60,37 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./resource.js"); -})() +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be in strict mode. +(() => { +"use strict"; +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); +/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); + + +it("should modify resource by after resolve hook", ()=>{ + expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); + expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); + const ext = ".js"; + expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./b" + ext); +}); + +})(); + +})() +; ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt index 261ecf1c6577..466b8f93e43e 100644 --- a/packages/rspack-test-tools/tests/hotCases/asset/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/asset/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: 598 +- Update: main.LAST_HASH.hot-update.js, size: 594 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _logo_svg__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./logo.svg */ "./logo.svg"); @@ -41,12 +41,12 @@ __webpack_require__.r(__webpack_exports__); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt index c3f3dd12f1c7..c4eb541fab37 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import-webpackhot/__snapshots__/web/1.snap.txt @@ -10,7 +10,7 @@ - Manifest: main.LAST_HASH.hot-update.json, size: 51 - Update: chunk2_js.LAST_HASH.hot-update.js, size: 301 - Update: chunk_js.LAST_HASH.hot-update.js, size: 300 -- Update: main.LAST_HASH.hot-update.js, size: 201 +- Update: main.LAST_HASH.hot-update.js, size: 209 ## Manifest @@ -34,9 +34,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('chunk2_js', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -59,9 +59,9 @@ var value = 2; #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('chunk_js', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -84,16 +84,15 @@ var value = 2; #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt index a0d73aba07fc..f06abcf9e285 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/accept-system-import/__snapshots__/web/1.snap.txt @@ -10,7 +10,7 @@ - Manifest: main.LAST_HASH.hot-update.json, size: 51 - Update: chunk2_js.LAST_HASH.hot-update.js, size: 301 - Update: chunk_js.LAST_HASH.hot-update.js, size: 300 -- Update: main.LAST_HASH.hot-update.js, size: 201 +- Update: main.LAST_HASH.hot-update.js, size: 209 ## Manifest @@ -34,9 +34,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('chunk2_js', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -59,9 +59,9 @@ var value = 2; #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('chunk_js', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -84,16 +84,15 @@ var value = 2; #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/1.snap.txt index 9a3415e405cc..33e8b4119bdd 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 39 -- Update: main.LAST_HASH.hot-update.js, size: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/2.snap.txt index a9b35f40ec2c..dc698a373b4b 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/2.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: 524 +- Update: main.LAST_HASH.hot-update.js, size: 520 ## Manifest @@ -42,12 +42,12 @@ module.exports = __webpack_require__.p + "a09d8e0f399c215faa79.png";}), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/3.snap.txt index fff13e479847..101b04064f9c 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/asset/__snapshots__/web/3.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 39 -- Update: main.LAST_HASH.hot-update.js, size: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 4; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt index 8d71d557db95..1b33c2f5a7cc 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/ensure-chunk-change-to-promise-all/__snapshots__/web/1.snap.txt @@ -9,7 +9,7 @@ - Bundle: vendors-node_modules_vue_js.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 94 - Update: file_js.LAST_HASH.hot-update.js, size: 450 -- Update: main.LAST_HASH.hot-update.js, size: 726 +- Update: main.LAST_HASH.hot-update.js, size: 722 ## Manifest @@ -33,9 +33,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('file_js', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { Vue: function() { return /* reexport safe */ vue__WEBPACK_IMPORTED_MODULE_0__.Vue; } @@ -59,9 +59,9 @@ __webpack_require__.d(__webpack_exports__, { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./chunk.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { test: function() { return test; } @@ -73,12 +73,12 @@ function test(count) { },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt index 0e48bae1e3c0..0e273cea217f 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt @@ -13,7 +13,7 @@ - Update: a.LAST_HASH.hot-update.js, size: 94 - Update: b.LAST_HASH.hot-update.js, size: 94 - Update: main.LAST_HASH.hot-update.js, size: 97 -- Update: runtime.LAST_HASH.hot-update.js, size: 204 +- Update: runtime.LAST_HASH.hot-update.js, size: 212 ## Manifest @@ -97,16 +97,15 @@ module.exports = 2; #### Changed Content ```js -self["webpackHotUpdate"]('runtime', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('runtime', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt index 7dfe2e0cb3c7..f7d3437fd85e 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt @@ -13,7 +13,7 @@ - Update: a.LAST_HASH.hot-update.js, size: 94 - Update: b.LAST_HASH.hot-update.js, size: 94 - Update: main.LAST_HASH.hot-update.js, size: 97 -- Update: runtime.LAST_HASH.hot-update.js, size: 204 +- Update: runtime.LAST_HASH.hot-update.js, size: 212 ## Manifest @@ -97,16 +97,15 @@ module.exports = 3; #### Changed Content ```js -self["webpackHotUpdate"]('runtime', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('runtime', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt index 7f2b5e91864b..239d4c026481 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt @@ -13,7 +13,7 @@ - Update: a.LAST_HASH.hot-update.js, size: 94 - Update: b.LAST_HASH.hot-update.js, size: 94 - Update: main.LAST_HASH.hot-update.js, size: 97 -- Update: runtime.LAST_HASH.hot-update.js, size: 204 +- Update: runtime.LAST_HASH.hot-update.js, size: 212 ## Manifest @@ -97,16 +97,15 @@ module.exports = 4; #### Changed Content ```js -self["webpackHotUpdate"]('runtime', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('runtime', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/1.snap.txt index 6225856ea46f..78e1deeda6d7 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/1.snap.txt @@ -10,9 +10,9 @@ - Manifest: a.LAST_HASH.hot-update.json, size: 35 - Manifest: b.LAST_HASH.hot-update.json, size: 35 - Manifest: main.LAST_HASH.hot-update.json, size: 35 -- Update: a.LAST_HASH.hot-update.js, size: 256 -- Update: b.LAST_HASH.hot-update.js, size: 256 -- Update: main.LAST_HASH.hot-update.js, size: 259 +- Update: a.LAST_HASH.hot-update.js, size: 252 +- Update: b.LAST_HASH.hot-update.js, size: 252 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -59,12 +59,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -89,12 +89,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -119,12 +119,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/2.snap.txt index e8bcc6654762..142fef719573 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/2.snap.txt @@ -10,9 +10,9 @@ - Manifest: a.LAST_HASH.hot-update.json, size: 35 - Manifest: b.LAST_HASH.hot-update.json, size: 35 - Manifest: main.LAST_HASH.hot-update.json, size: 35 -- Update: a.LAST_HASH.hot-update.js, size: 256 -- Update: b.LAST_HASH.hot-update.js, size: 256 -- Update: main.LAST_HASH.hot-update.js, size: 259 +- Update: a.LAST_HASH.hot-update.js, size: 252 +- Update: b.LAST_HASH.hot-update.js, size: 252 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -59,12 +59,12 @@ module.exports = 3; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -89,12 +89,12 @@ module.exports = 3; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -119,12 +119,12 @@ module.exports = 3; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/3.snap.txt index 9bb1ece7c9a5..519dae594d07 100644 --- a/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/chunk/multi-chunk/__snapshots__/web/3.snap.txt @@ -10,9 +10,9 @@ - Manifest: a.LAST_HASH.hot-update.json, size: 35 - Manifest: b.LAST_HASH.hot-update.json, size: 35 - Manifest: main.LAST_HASH.hot-update.json, size: 35 -- Update: a.LAST_HASH.hot-update.js, size: 256 -- Update: b.LAST_HASH.hot-update.js, size: 256 -- Update: main.LAST_HASH.hot-update.js, size: 259 +- Update: a.LAST_HASH.hot-update.js, size: 252 +- Update: b.LAST_HASH.hot-update.js, size: 252 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -59,12 +59,12 @@ module.exports = 4; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -89,12 +89,12 @@ module.exports = 4; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -119,12 +119,12 @@ module.exports = 4; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt index f811ee5e413c..34e67dcafc9f 100644 --- a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept-webpackhot/__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: 429 +- Update: main.LAST_HASH.hot-update.js, size: 425 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = ("ok2"); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt index 0b1ef715ab2f..aeb2bd18ae1d 100644 --- a/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/code-generation/this-in-accept/__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: 429 +- Update: main.LAST_HASH.hot-update.js, size: 425 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = ("ok2"); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/1.snap.txt index 4599b7ce5c1f..d7ccff5c20c9 100644 --- a/packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/context/request-position/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: lib_a_js.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 630 +- Update: main.LAST_HASH.hot-update.js, size: 626 ## Manifest @@ -31,9 +31,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { fn: function() { return fn; } @@ -47,12 +47,12 @@ const fn = async function() { },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); 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 204ec2575235..a9d379abe7d9 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: 375 +- Update: main.LAST_HASH.hot-update.js, size: 371 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdatecss_test"]('main', { "./index.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; module.hot.accept(); __webpack_require__.r(module.exports = {}); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt index 5462760cf8c2..59513b95b16b 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/css-modules/__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: 386 +- Update: main.LAST_HASH.hot-update.js, size: 382 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./index.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "a": "-__index_module_css-a", }); @@ -40,12 +40,12 @@ __webpack_require__.r(module.exports = { },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); 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 a8a208e1cbfe..77082261c004 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: 367 +- Update: main.LAST_HASH.hot-update.js, size: 363 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./index.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; module.hot.accept(); __webpack_require__.r(module.exports = {}); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); 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 0bd69a4c7e7f..2a87dfb745b4 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: 491 +- Update: main.LAST_HASH.hot-update.js, size: 487 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./index.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { -"use strict"; __webpack_require__.r(module.exports = { "btn-info_is-disabled": "__index_module_css__btn-info_is-disabled", "btnInfoIsDisabled": "__index_module_css__btn-info_is-disabled", @@ -41,12 +41,12 @@ __webpack_require__.r(module.exports = { },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt index 886315adace0..b29006b278a2 100644 --- a/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/determinism/issue-10174/__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: 422 +- Update: main.LAST_HASH.hot-update.js, size: 418 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./hot.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt index 125f7a6b2e7e..bd1a91bb2cbe 100644 --- a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared-in-other-runtime/__snapshots__/web/1.snap.txt @@ -8,7 +8,7 @@ - Bundle: chunk1_js.chunk.CURRENT_HASH.js - Manifest: [runtime of chunk2_js].LAST_HASH.hot-update.json, size: 65 - Manifest: main.LAST_HASH.hot-update.json, size: 41 -- Update: main.LAST_HASH.hot-update.js, size: 18238 +- Update: main.LAST_HASH.hot-update.js, size: 18230 ## Manifest @@ -41,23 +41,23 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (42); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -670,7 +670,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt index 031ab20d2fe7..28c71d76df04 100644 --- a/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/disposing/remove-chunk-with-shared/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: bundle.js - Bundle: chunk1_js.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 52 -- Update: main.LAST_HASH.hot-update.js, size: 426 +- Update: main.LAST_HASH.hot-update.js, size: 422 ## Manifest @@ -31,21 +31,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (42); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt index 6ffaccd7c205..3c474c03ce3a 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/decline-webpackhot/__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: 420 +- Update: main.LAST_HASH.hot-update.js, size: 416 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/1.snap.txt index 70f00f80b06c..4b621e11afb8 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/decline/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/decline/__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: 420 +- Update: main.LAST_HASH.hot-update.js, size: 416 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/1.snap.txt index 0a63308166a2..6353f11bdf9c 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/events/__snapshots__/web/1.snap.txt @@ -12,7 +12,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 1881 +- Update: main.LAST_HASH.hot-update.js, size: 1793 ## Manifest @@ -42,41 +42,35 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), "./e.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), "./g.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), "./i.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); throw new Error("Error while loading module i"); }), "./j.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); throw new Error("Error while loading module j"); }), "./l.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); throw new Error("Error while loading module l"); @@ -84,12 +78,12 @@ throw new Error("Error while loading module l"); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt index 926ed23d91fe..ad998f584a4f 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/self-decline/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/self-decline/__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: 420 +- Update: main.LAST_HASH.hot-update.js, size: 416 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt index ea82c4072f76..fa437f119917 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 420 +- Update: main.LAST_HASH.hot-update.js, size: 416 ## Manifest @@ -31,21 +31,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt index 7dad77854771..6fcdddebb385 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/2.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 420 +- Update: main.LAST_HASH.hot-update.js, size: 416 ## Manifest @@ -31,21 +31,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt index 5dd7eb398bfe..8b3b52d0a8e4 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted-ignored/__snapshots__/web/3.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 639 +- Update: main.LAST_HASH.hot-update.js, size: 621 ## Manifest @@ -32,26 +32,25 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (4); }), "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt index c851c243f9fe..7f6cc70283f1 100644 --- a/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/errors/unaccepted/__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: 420 +- Update: main.LAST_HASH.hot-update.js, size: 416 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt index a6eb38271006..bc371a948b15 100644 --- a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/import-meta-webpack-hot/__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: 476 +- Update: main.LAST_HASH.hot-update.js, size: 472 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./node_modules/dep1/file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ var value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt index af5427aa273c..083abde5d750 100644 --- a/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/esm-dependency-import/module-hot/__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: 476 +- Update: main.LAST_HASH.hot-update.js, size: 472 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./node_modules/dep1/file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ var value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/1.snap.txt index f087c57db6ad..8dca44e7877e 100644 --- a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-default/__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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt index 5aa64388569c..bd43c4c986de 100644 --- a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import-multiple/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 521 +- Update: main.LAST_HASH.hot-update.js, size: 517 ## Manifest @@ -47,12 +47,12 @@ var value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt index e29caaeb2ac5..8f96e56a5886 100644 --- a/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/harmony/auto-import/__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: 458 +- Update: main.LAST_HASH.hot-update.js, size: 454 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ var value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt index 417c3637ca10..5886f0d4076a 100644 --- a/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/harmony/auto-reexport/__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: 460 +- Update: main.LAST_HASH.hot-update.js, size: 456 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ const value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt index 1115c6e8c5b1..f5efda7a001b 100644 --- a/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/harmony/cjs-analyze-changed/__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: 738 +- Update: main.LAST_HASH.hot-update.js, size: 734 ## Manifest @@ -48,12 +48,12 @@ __webpack_require__.r(__webpack_exports__); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt index d30dd6fe91b9..586b2e042226 100644 --- a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__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: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt index 2b48e7020ae6..c1b24908b728 100644 --- a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/2.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: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt index 3f2e18576b5a..d7cbb29dd04a 100644 --- a/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/hash/hot-index/__snapshots__/web/3.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: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/1.snap.txt index dd923ffab805..fae37797163c 100644 --- a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__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: 285 +- Update: main.LAST_HASH.hot-update.js, size: 281 ## Manifest @@ -30,19 +30,19 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./data.json": (function (module) { -"use strict"; module.exports = {"a":2,"b":1}}), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/2.snap.txt index f4fdfaa7b3ec..3a88c2a3f1c6 100644 --- a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/2.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: 285 +- Update: main.LAST_HASH.hot-update.js, size: 281 ## Manifest @@ -30,19 +30,19 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./data.json": (function (module) { -"use strict"; module.exports = {"a":2,"b":2}}), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/3.snap.txt index 93ed27cbe0cc..7ad47ad18277 100644 --- a/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/invalidate/conditional-accept/__snapshots__/web/3.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: 285 +- Update: main.LAST_HASH.hot-update.js, size: 281 ## Manifest @@ -30,19 +30,19 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./data.json": (function (module) { -"use strict"; module.exports = {"a":3,"b":3}}), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt index 417c3637ca10..5886f0d4076a 100644 --- a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/auto-reexport/__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: 460 +- Update: main.LAST_HASH.hot-update.js, size: 456 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ const value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt index 0e48bae1e3c0..0e273cea217f 100644 --- a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/1.snap.txt @@ -13,7 +13,7 @@ - Update: a.LAST_HASH.hot-update.js, size: 94 - Update: b.LAST_HASH.hot-update.js, size: 94 - Update: main.LAST_HASH.hot-update.js, size: 97 -- Update: runtime.LAST_HASH.hot-update.js, size: 204 +- Update: runtime.LAST_HASH.hot-update.js, size: 212 ## Manifest @@ -97,16 +97,15 @@ module.exports = 2; #### Changed Content ```js -self["webpackHotUpdate"]('runtime', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('runtime', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt index 7dfe2e0cb3c7..f7d3437fd85e 100644 --- a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/2.snap.txt @@ -13,7 +13,7 @@ - Update: a.LAST_HASH.hot-update.js, size: 94 - Update: b.LAST_HASH.hot-update.js, size: 94 - Update: main.LAST_HASH.hot-update.js, size: 97 -- Update: runtime.LAST_HASH.hot-update.js, size: 204 +- Update: runtime.LAST_HASH.hot-update.js, size: 212 ## Manifest @@ -97,16 +97,15 @@ module.exports = 3; #### Changed Content ```js -self["webpackHotUpdate"]('runtime', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('runtime', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt index 7f2b5e91864b..239d4c026481 100644 --- a/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/newTreeshaking/multi-chunk-single-runtime/__snapshots__/web/3.snap.txt @@ -13,7 +13,7 @@ - Update: a.LAST_HASH.hot-update.js, size: 94 - Update: b.LAST_HASH.hot-update.js, size: 94 - Update: main.LAST_HASH.hot-update.js, size: 97 -- Update: runtime.LAST_HASH.hot-update.js, size: 204 +- Update: runtime.LAST_HASH.hot-update.js, size: 212 ## Manifest @@ -97,16 +97,15 @@ module.exports = 4; #### Changed Content ```js -self["webpackHotUpdate"]('runtime', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('runtime', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/1.snap.txt index 6eddde8687f4..6640f386aa2b 100644 --- a/packages/rspack-test-tools/tests/hotCases/plugins/html/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/plugins/html/__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: 460 +- Update: main.LAST_HASH.hot-update.js, size: 456 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ const value = 1; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt index 96eb17b5b71a..50c92cf081ec 100644 --- a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__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: 766 +- Update: main.LAST_HASH.hot-update.js, size: 762 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getError: function() { return getError; }, @@ -52,12 +52,12 @@ throw new Error("Failed"); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt index 31ee05473b3c..32f35ee6d50b 100644 --- a/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/recover/recover-after-self-error/__snapshots__/web/3.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: 1092 +- Update: main.LAST_HASH.hot-update.js, size: 1084 ## Manifest @@ -31,9 +31,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getError: function() { return getError; }, @@ -52,7 +52,7 @@ const id = module.id; },function(__webpack_require__) { // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -60,14 +60,14 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/1.snap.txt index ccd662f8b6a8..94e4c1802990 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/accept/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/accept/__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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/1.snap.txt index f43cdc938356..1bc3a3e1b114 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-async/__snapshots__/web/1.snap.txt @@ -8,7 +8,7 @@ - Bundle: file_js.chunk.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 38 - Update: file_js.LAST_HASH.hot-update.js, size: 100 -- Update: main.LAST_HASH.hot-update.js, size: 201 +- Update: main.LAST_HASH.hot-update.js, size: 209 ## Manifest @@ -52,16 +52,15 @@ module.exports = 2; #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/1.snap.txt index 3160fc13aa89..713b2111ed41 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/bubble-update/__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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/1.snap.txt index 0f15055a1011..2cf30915ac0f 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/circular/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 843 +- Update: main.LAST_HASH.hot-update.js, size: 825 ## Manifest @@ -32,9 +32,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var ___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ */ "./index.js"); /* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./b */ "./b.js"); @@ -43,19 +43,18 @@ __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt index 2c58405e2c72..867ca3b14c45 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/1.snap.txt @@ -9,7 +9,7 @@ - Bundle: b_js.CURRENT_HASH.js - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 42 -- Update: main.LAST_HASH.hot-update.js, size: 542 +- Update: main.LAST_HASH.hot-update.js, size: 538 ## Manifest @@ -33,21 +33,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (__webpack_require__.e(/*! import() */ "b_js").then(__webpack_require__.bind(__webpack_require__, /*! ./b */ "./b.js"))); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt index 5855e9a0970f..f562d3e71773 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/2.snap.txt @@ -10,7 +10,7 @@ - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 35 - Update: b_js.LAST_HASH.hot-update.js, size: 269 -- Update: main.LAST_HASH.hot-update.js, size: 201 +- Update: main.LAST_HASH.hot-update.js, size: 209 ## Manifest @@ -34,9 +34,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('b_js', { "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = ("version b2"); }), @@ -56,16 +56,15 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt index e687e15dc580..71adfe5d515c 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-chunk/__snapshots__/web/3.snap.txt @@ -9,7 +9,7 @@ - Bundle: a_js.CURRENT_HASH.js - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 42 -- Update: main.LAST_HASH.hot-update.js, size: 542 +- Update: main.LAST_HASH.hot-update.js, size: 538 ## Manifest @@ -33,21 +33,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (__webpack_require__.e(/*! import() */ "a_js").then(__webpack_require__.bind(__webpack_require__, /*! ./a */ "./a.js"))); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt index 57861501df6f..07172aab233a 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 36 -- Update: main.LAST_HASH.hot-update.js, size: 678 +- Update: main.LAST_HASH.hot-update.js, size: 660 ## Manifest @@ -32,14 +32,13 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _b__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./b */ "./b.js"); @@ -47,12 +46,12 @@ __webpack_require__.r(__webpack_exports__); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt index d275a98c92ca..5577a754fbd2 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/dispose-removed-module/__snapshots__/web/2.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 36 -- Update: main.LAST_HASH.hot-update.js, size: 1170 +- Update: main.LAST_HASH.hot-update.js, size: 1148 ## Manifest @@ -33,14 +33,13 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./a.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (module.id); }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": function() { return /* reexport safe */ _a__WEBPACK_IMPORTED_MODULE_0__["default"]; } @@ -51,7 +50,7 @@ __webpack_require__.d(__webpack_exports__, { },function(__webpack_require__) { // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -59,14 +58,14 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt index 2087dc8f7eb2..749a2e8cfb75 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/hmr-circular/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 45 -- Update: main.LAST_HASH.hot-update.js, size: 437 +- Update: main.LAST_HASH.hot-update.js, size: 433 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./entry.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = ("new_entry.js"); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt index bf57bcd89eec..62d94f6d9ddd 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/import-after-download/__snapshots__/web/1.snap.txt @@ -10,7 +10,7 @@ - Bundle: unaffected-chunk_js.CURRENT_HASH.js - Manifest: main.LAST_HASH.hot-update.json, size: 39 - Update: chunk_js.LAST_HASH.hot-update.js, size: 267 -- Update: main.LAST_HASH.hot-update.js, size: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -34,9 +34,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('chunk_js', { "./inner.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (20); }), @@ -56,21 +56,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt index 71c8c8cb3885..73f9263a304c 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/replace-runtime-module/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ - Bundle: b.chunk.CURRENT_HASH.js - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 39 -- Update: main.LAST_HASH.hot-update.js, size: 543 +- Update: main.LAST_HASH.hot-update.js, size: 539 ## Manifest @@ -31,21 +31,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (__webpack_require__.e(/*! import() | b */ "b").then(__webpack_require__.bind(__webpack_require__, /*! ./b */ "./b.js"))); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt index a573c3a00b6e..6d4062834ba0 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/require-disposed-module-warning/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 36 -- Update: main.LAST_HASH.hot-update.js, size: 572 +- Update: main.LAST_HASH.hot-update.js, size: 568 ## Manifest @@ -43,12 +43,12 @@ module.exports = ()=>__webpack_require__(/*! ./b */ "./b.js"); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/1.snap.txt index 67ee0fa5bef7..cbe61631e160 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-and-dispose/__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: 267 +- Update: main.LAST_HASH.hot-update.js, size: 263 ## Manifest @@ -37,12 +37,12 @@ module.hot.data.callback(); },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/1.snap.txt index c889b3169dd3..4f7270f0e9d6 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/self-accept-factory/__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: 527 +- Update: main.LAST_HASH.hot-update.js, size: 523 ## Manifest @@ -44,12 +44,12 @@ module.exports = 1; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/1.snap.txt index 882ca9a76c5e..726bfca6c7ca 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-modules/__snapshots__/web/1.snap.txt @@ -7,7 +7,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 319 +- Update: main.LAST_HASH.hot-update.js, size: 315 ## Manifest @@ -42,12 +42,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/1.snap.txt index e2f55d6b8726..36b64404fc4f 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/2.snap.txt index e080057a58af..52ea844bba7f 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/2.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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 3; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/3.snap.txt index 59e1f0b86ef2..df6fa80825c4 100644 --- a/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/runtime/update-multiple-times/__snapshots__/web/3.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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 4; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/1.snap.txt index 3391ac472821..631479baa6f8 100644 --- a/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__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: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/2.snap.txt index fb4f8afbe487..d5b190be88e9 100644 --- a/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/2.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: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/3.snap.txt index d2b52898f0db..eeb674bd9478 100644 --- a/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/source-map/disable/__snapshots__/web/3.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: 423 +- Update: main.LAST_HASH.hot-update.js, size: 419 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/1.snap.txt index 8bc513f78220..b4d2df8be6ab 100644 --- a/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__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: 488 +- Update: main.LAST_HASH.hot-update.js, size: 484 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/2.snap.txt index 59f0f0f6f4d3..f8ba8e33eb26 100644 --- a/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/2.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: 488 +- Update: main.LAST_HASH.hot-update.js, size: 484 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/3.snap.txt index 224a550386e2..09e16872aff6 100644 --- a/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/source-map/enable/__snapshots__/web/3.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: 488 +- Update: main.LAST_HASH.hot-update.js, size: 484 ## Manifest @@ -30,21 +30,21 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/1.snap.txt index ccd662f8b6a8..94e4c1802990 100644 --- a/packages/rspack-test-tools/tests/hotCases/status/accept/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/status/accept/__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: 259 +- Update: main.LAST_HASH.hot-update.js, size: 255 ## Manifest @@ -37,12 +37,12 @@ module.exports = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/1.snap.txt index bb092b1f5573..6e5da6281903 100644 --- a/packages/rspack-test-tools/tests/hotCases/status/check/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/status/check/__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: 458 +- Update: main.LAST_HASH.hot-update.js, size: 454 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./file.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { value: function() { return value; } @@ -42,12 +42,12 @@ var value = 2; },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt index ca7e8564beca..ace41b43dd90 100644 --- a/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/unexpected-invalidation/used-exports/__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: 624 +- Update: main.LAST_HASH.hot-update.js, size: 620 ## Manifest @@ -30,9 +30,9 @@ #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('main', { "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": function() { return /* reexport safe */ _subject__WEBPACK_IMPORTED_MODULE_0__.def; } @@ -43,12 +43,12 @@ __webpack_require__.d(__webpack_exports__, { },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt index 9b14a4af1883..f93c1c8c785d 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/1.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (1); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt index 1f91233808c9..59066c670707 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/2.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (2); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt index 0ed8f3536826..83611643312e 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/3.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (3); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt index f506f40360c9..d409196f9ec5 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/4.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (4); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (4); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (4); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (4); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt index d0e7cd58fc97..789a26ad4e33 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/5.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (5); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (5); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (5); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (5); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt index 40614bed614a..9ad80b8b7a5c 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/6.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (6); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (6); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (6); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (6); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt index 254e3e8e9dcd..d4c4ac94d986 100644 --- a/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/worker/issue-5597/__snapshots__/web/7.snap.txt @@ -14,10 +14,10 @@ - Manifest: [runtime of workerA_js].LAST_HASH.hot-update.json, size: 62 - Manifest: [runtime of workerB_js].LAST_HASH.hot-update.json, size: 62 - Manifest: main.LAST_HASH.hot-update.json, size: 62 -- Update: main.LAST_HASH.hot-update.js, size: 201 -- Update: shared.LAST_HASH.hot-update.js, size: 493 -- Update: workerA_js.LAST_HASH.hot-update.js, size: 432 -- Update: workerB_js.LAST_HASH.hot-update.js, size: 432 +- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: shared.LAST_HASH.hot-update.js, size: 479 +- Update: workerA_js.LAST_HASH.hot-update.js, size: 428 +- Update: workerB_js.LAST_HASH.hot-update.js, size: 428 ## Manifest @@ -57,16 +57,15 @@ #### Changed Content ```js -self["webpackHotUpdate"]('main', { - -},function(__webpack_require__) { +"use strict"; +self["webpackHotUpdate"]('main', {},function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -85,14 +84,13 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('shared', { "./moduleAs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (7); }), "./moduleBs.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (7); }), @@ -112,21 +110,21 @@ __webpack_require__.r(__webpack_exports__); #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerA_js', { "./moduleA.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (7); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); @@ -144,21 +142,21 @@ __webpack_require__.h = function () { #### Changed Content ```js +"use strict"; self["webpackHotUpdate"]('workerB_js', { "./moduleB.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony default export */ __webpack_exports__["default"] = (7); }), },function(__webpack_require__) { // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "CURRENT_HASH"; }; -}(); +})(); } ); diff --git a/packages/rspack-test-tools/tests/statsAPICases/basic.js b/packages/rspack-test-tools/tests/statsAPICases/basic.js index e5ea9a211aa4..2aa1af7d7257 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/basic.js +++ b/packages/rspack-test-tools/tests/statsAPICases/basic.js @@ -20,21 +20,23 @@ module.exports = { expect(stats?.toJson(statsOptions)).toMatchSnapshot(); expect(stats?.toString(statsOptions)).toMatchInlineSnapshot(` "PublicPath: auto - asset main.js 211 bytes {909} [emitted] (name: main) - Entrypoint main 211 bytes = main.js + asset main.js 207 bytes {909} [emitted] (name: main) + Entrypoint main 207 bytes = main.js chunk {909} main.js (main) [entry] ./fixtures/a.js [585] {909} [no exports] - [no exports used] + [used exports unknown] Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 entry ./fixtures/a + cjs self exports reference self [585] ./fixtures/a.js [585] {909} [no exports] - [no exports used] + [used exports unknown] Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 entry ./fixtures/a + cjs self exports reference self [585] - Rspack compiled successfully (bca12e9a78756a7efe53)" + Rspack compiled successfully (d64955662040c788c943)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js b/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js index 388f580381ca..d07f83c18af7 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js +++ b/packages/rspack-test-tools/tests/statsAPICases/child-compiler.js @@ -1,4 +1,4 @@ -const { createFsFromVolume, Volume } = require("memfs") +const { createFsFromVolume, Volume } = require("memfs"); let statsJson; class TestPlugin { @@ -56,7 +56,7 @@ module.exports = { "hotModuleReplacement": false, }, "name": "TestChild.js", - "size": 726, + "size": 700, "type": "asset", }, Object { @@ -69,7 +69,7 @@ module.exports = { "hotModuleReplacement": false, }, "name": "main.js", - "size": 211, + "size": 207, "type": "asset", }, ], @@ -91,7 +91,7 @@ module.exports = { "hotModuleReplacement": false, }, "name": "TestChild.js", - "size": 726, + "size": 700, "type": "asset", }, ], diff --git a/packages/rspack-test-tools/tests/statsAPICases/exports.js b/packages/rspack-test-tools/tests/statsAPICases/exports.js index f06c8e391eb3..67fa66072e57 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/exports.js +++ b/packages/rspack-test-tools/tests/statsAPICases/exports.js @@ -30,8 +30,8 @@ module.exports = { expect(stats?.toJson(statsOptions)).toMatchSnapshot(); expect(stats?.toString(statsOptions)).toMatchInlineSnapshot(` "PublicPath: auto - asset main.js 784 bytes [emitted] (name: main) - Entrypoint main 784 bytes = main.js + asset main.js 720 bytes [emitted] (name: main) + Entrypoint main 720 bytes = main.js runtime modules 3 modules ./fixtures/esm/a.js [exports: a, default] @@ -44,7 +44,7 @@ module.exports = { ./fixtures/esm/abc.js [no exports] [no exports used] - Rspack compiled successfully (d58eb30bef2d7c671efc)" + Rspack compiled successfully (c0db196ceebe2a004f20)" `); } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/ids.js b/packages/rspack-test-tools/tests/statsAPICases/ids.js index 7a6bbecd0005..433300288ae5 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/ids.js +++ b/packages/rspack-test-tools/tests/statsAPICases/ids.js @@ -17,7 +17,7 @@ module.exports = { }; expect(stats?.toJson(options)).toMatchSnapshot(); expect(stats?.toString(options)).toMatchInlineSnapshot(` - "asset main.js 211 bytes {909} [emitted] (name: main) + "asset main.js 207 bytes {909} [emitted] (name: main) chunk {909} main.js (main) [entry] ./fixtures/a.js [585] {909}" `); diff --git a/packages/rspack-test-tools/tests/statsAPICases/to-string.js b/packages/rspack-test-tools/tests/statsAPICases/to-string.js index adebc8a04308..e78b0aba828b 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/to-string.js +++ b/packages/rspack-test-tools/tests/statsAPICases/to-string.js @@ -11,8 +11,8 @@ module.exports = { expect(stats?.toString({ timings: false, version: false })) .toMatchInlineSnapshot(` "PublicPath: auto - asset main.js 726 bytes [emitted] (name: main) - Entrypoint main 726 bytes = main.js + asset main.js 700 bytes [emitted] (name: main) + Entrypoint main 700 bytes = main.js ./fixtures/a.js ./fixtures/b.js ./fixtures/c.js @@ -31,7 +31,7 @@ module.exports = { help: You may need an appropriate loader to handle this file type. - Rspack compiled with 1 error (6343e7b6958312d248a1)" + Rspack compiled with 1 error (d28076e3fa339b42cdf4)" `); } }; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/__snapshots__/treeshaking.snap.txt index df80dd4dba3e..8abc7e7a9ef1 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/array-side-effects/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { app: function() { return app; } }); @@ -11,13 +11,11 @@ function app() {} app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0__.result; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/a.js"); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { result: function() { return result; } }); @@ -26,7 +24,6 @@ const result = 20000; const something = function() {}; }), "./src/a.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__.app; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/__snapshots__/treeshaking.snap.txt index bbfc0b588613..eae64fb60fb5 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/assign-with-side-effects/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { app: function() { return app; } }); @@ -11,13 +11,11 @@ function app() {} app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0__.result; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.app)(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { result: function() { return result; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/basic/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/basic/__snapshots__/treeshaking.snap.txt index 41ca4eaafa4a..ef6e884f59a6 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/basic/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/basic/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { answer: function() { return answer; } }); const answer = 103330; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); _lib__WEBPACK_IMPORTED_MODULE_0__.answer; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/bb/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/bb/__snapshots__/treeshaking.snap.txt index 19f24de5c88d..3f6c2bb8f8ce 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/bb/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/bb/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { ccc: function() { return ccc; } }); const ccc = 30; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./c.js"); _a_js__WEBPACK_IMPORTED_MODULE_0__.ccc; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt index 88cec5d2debc..ef7cd8671216 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/cjs-tree-shaking-basic/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { answer: function() { return answer; } @@ -10,14 +10,12 @@ __webpack_require__.d(__webpack_exports__, { const answer = 42; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); __webpack_require__("./answer.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { myanswer: function() { return myanswer; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/__snapshots__/treeshaking.snap.txt index 1b2c1dde404a..effbdf210c05 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/class-extend/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/class-extend/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { v: function() { return v; } }); @@ -17,13 +17,11 @@ function foo() { const v = _lib__WEBPACK_IMPORTED_MODULE_0__.value; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__.v; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { value: function() { return value; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/__snapshots__/treeshaking.snap.txt index 8d81452f14e6..697b5bd9894a 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/conflicted_name_by_re_export_all_should_be_hidden/__snapshots__/treeshaking.snap.txt @@ -1,16 +1,14 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function () { -"use strict"; const a = "bar"; }), "./foo.js": (function () { -"use strict"; const a = "foo"; const b = "foo"; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/__snapshots__/treeshaking.snap.txt index f94f2147e7ed..0f05ebb79c65 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/context-module-elimated/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function () { -"use strict"; function test() { a; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/__snapshots__/treeshaking.snap.txt index 9e7fb2f5f511..24d1ba4c4761 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/cyclic-reference-export-all/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./src/App.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/containers/containers.js"); const { PlatformProvider } = _containers__WEBPACK_IMPORTED_MODULE_0__; @@ -12,7 +12,6 @@ const Index = ()=>{ /* harmony default export */ __webpack_exports__["default"] = (Index); }), "./src/containers/containers.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { PlatformProvider: function() { return /* reexport safe */ _platform_container__WEBPACK_IMPORTED_MODULE_0__.PlatformProvider; }, @@ -23,7 +22,6 @@ __webpack_require__.d(__webpack_exports__, { }), "./src/containers/platform-container/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { PlatformProvider: function() { return PlatformProvider; }, usePlatform: function() { return usePlatform; } @@ -32,7 +30,6 @@ const usePlatform = 3; const PlatformProvider = 1000; }), "./src/index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _App__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/App.js"); (0, _App__WEBPACK_IMPORTED_MODULE_0__["default"])(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/default_export/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/default_export/__snapshots__/treeshaking.snap.txt index c25ed0974964..e9ddd930d6a1 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/default_export/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/default_export/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { answer: function() { return answer; } }); const answer = 103330; // export default answer; }), "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return result; }, render: function() { return render; } @@ -24,13 +23,11 @@ function render() { function result() {} }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.render)(_app__WEBPACK_IMPORTED_MODULE_0__["default"]); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { myanswer: function() { return myanswer; }, secret: function() { return secret; } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/__snapshots__/treeshaking.snap.txt index 141771a5edfa..fc60d6c154c5 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_1/__snapshots__/treeshaking.snap.txt @@ -1,11 +1,10 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function () { -"use strict"; const a = "bar"; }), "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -14,7 +13,6 @@ const a = "foo"; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); console.log(_foo__WEBPACK_IMPORTED_MODULE_0__.a); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/__snapshots__/treeshaking.snap.txt index 4b0c18cb9c99..a31550b51f14 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/explicit_named_export_higher_priority_2/__snapshots__/treeshaking.snap.txt @@ -1,18 +1,16 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function () { -"use strict"; const a = "bar"; }), "./baz.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); const a = "baz"; }), "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return /* reexport safe */ _baz__WEBPACK_IMPORTED_MODULE_0__.a; } }); @@ -22,7 +20,6 @@ __webpack_require__.d(__webpack_exports__, { }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); console.log(_foo__WEBPACK_IMPORTED_MODULE_0__.a); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt index f6bda3807460..6b674df86ed6 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-imported-import-all-as/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); _answer__WEBPACK_IMPORTED_MODULE_0__; }), "./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { result: function() { return result; } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt index df5cd29bb057..987348c8f92a 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-named-decl-as/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./src/answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { formatNumber: function() { return /* reexport safe */ _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0__["default"]; } @@ -11,13 +11,11 @@ __webpack_require__.d(__webpack_exports__, { }), "./src/index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/answer.js"); console.log(_answer__WEBPACK_IMPORTED_MODULE_0__); }), "./src/plugin/formatNumber.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return formatNumber_default; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt index d18556e8b9c8..ab7a72b94926 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/export-star-chain/__snapshots__/treeshaking.snap.txt @@ -1,21 +1,19 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./colors/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { red: function() { return red; } }); const red = "red"; }), "./colors/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { blue: function() { return blue; } }); const blue = "blue"; }), "./colors/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { result: function() { return /* reexport safe */ _result__WEBPACK_IMPORTED_MODULE_0__.result; } }); @@ -23,7 +21,6 @@ __webpack_require__.d(__webpack_exports__, { }), "./colors/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { blue: function() { return /* reexport safe */ _b__WEBPACK_IMPORTED_MODULE_1__.blue; }, @@ -38,14 +35,12 @@ __webpack_require__.d(__webpack_exports__, { }), "./colors/result.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { result: function() { return result; } }); const result = "ssss"; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./colors/index.js"); /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./something/Something.js"); @@ -53,7 +48,6 @@ _export__WEBPACK_IMPORTED_MODULE_0__; _export__WEBPACK_IMPORTED_MODULE_1__.Something; }), "./something/Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { Something: function() { return Something; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt index cc11f0dd2a99..0f64d457cfdd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/export_star/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { b: function() { return b; }, bar: function() { return /* reexport module object */ _foo__WEBPACK_IMPORTED_MODULE_0__; }, @@ -14,7 +14,6 @@ function b() {} }), "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: function() { return a; }, @@ -31,14 +30,12 @@ const foo = 3; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); _foo__WEBPACK_IMPORTED_MODULE_0__.bar.a; (0, _foo__WEBPACK_IMPORTED_MODULE_0__.c)(); }), "./result.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { c: function() { return c; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/__snapshots__/treeshaking.snap.txt index 4defa3df88e2..761ebfac2ff6 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star2/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/export_star2/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); function b() {} @@ -9,7 +9,6 @@ function b() {} }), "./foo.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); const a = 3; @@ -17,7 +16,6 @@ const a = 3; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./result.js"); @@ -26,7 +24,6 @@ const a = 3; }), "./result.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); const c = 103330; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/__snapshots__/treeshaking.snap.txt index 5b5e9e703287..3dbbb0d5a079 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/export_star_conflict_export_no_error/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { b: function() { return b; } }); @@ -12,7 +12,6 @@ function b() {} }), "./foo.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); /* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./result.js"); const a = 3; @@ -21,13 +20,11 @@ const b = 3; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./bar.js"); (0, _bar_js__WEBPACK_IMPORTED_MODULE_0__.b)(); }), "./result.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./bar.js"); const c = 103330; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/__snapshots__/treeshaking.snap.txt index f2dd0a7b18d8..b7a90cc247b0 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/handle-side-effects-commonjs-imported-unused/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function () { -"use strict"; console.log("something"); }), diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/__snapshots__/treeshaking.snap.txt index dfaae4647d4a..92564673cbad 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-as-default/__snapshots__/treeshaking.snap.txt @@ -1,12 +1,11 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; var a = 1; /* harmony default export */ __webpack_exports__["default"] = (a); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__["default"]; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/__snapshots__/treeshaking.snap.txt index 819e96be5740..8dfe12e52471 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-optional-chaining/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { app: function() { return app; } }); const app = "app"; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); function a() { diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt index 5a2fc9c3d3de..88638ec33553 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-star-as-and-export/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); _app__WEBPACK_IMPORTED_MODULE_0__; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: function() { return a; } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/__snapshots__/treeshaking.snap.txt index bfa3e75e77e9..84a47d34c0ea 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/import-var-assign-side-effects/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return Something; } }); @@ -9,7 +9,6 @@ class Something { } }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./Something.js"); (0, _export__WEBPACK_IMPORTED_MODULE_0__["default"])(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/__snapshots__/treeshaking.snap.txt index 6b6e92f3705e..e9c02ad0bce9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/inherit_export_map_should_lookup_in_dfs_order/__snapshots__/treeshaking.snap.txt @@ -1,19 +1,17 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { c: function() { return c; } }); const c = "a"; }), "./bar.js": (function () { -"use strict"; const a = "bar"; const c = "bar"; }), "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; }, b: function() { return /* reexport safe */ _foo__WEBPACK_IMPORTED_MODULE_0__.b; }, @@ -26,7 +24,6 @@ __webpack_require__.d(__webpack_exports__, { const a = 3; }), "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { b: function() { return b; }, c: function() { return /* reexport safe */ _a_js__WEBPACK_IMPORTED_MODULE_0__.c; } @@ -37,7 +34,6 @@ const a = "foo"; const b = "foo"; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./c.js"); // require("./c.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/__snapshots__/treeshaking.snap.txt index f51426ffc51c..77d9715bddd3 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/issue-4637/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "../../../../../node_modules/@swc/helpers/esm/_create_class.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { _: function() { return _create_class; } }); @@ -22,12 +22,10 @@ function _create_class(Constructor, protoProps, staticProps) { }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _util_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./util.js"); }), "./util.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _swc_helpers_create_class__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../../../../../node_modules/@swc/helpers/esm/_create_class.js"); var ConsoleExporterWeb; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/__snapshots__/treeshaking.snap.txt index c8f2f6239e58..ccae41097f4e 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/issues_3198/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); _test__WEBPACK_IMPORTED_MODULE_0__.obj.test = 1; }), "./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { obj: function() { return obj; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/__snapshots__/treeshaking.snap.txt index c712bab55d0f..d677713f18f8 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable1/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { defaults: function() { return defaults; } }); @@ -10,7 +10,6 @@ const defaults = { }; }), "./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { Something: function() { return Something; } }); @@ -23,7 +22,6 @@ var Sider = callit(); var Something = 20000; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); (0, _export__WEBPACK_IMPORTED_MODULE_0__.Something)(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/__snapshots__/treeshaking.snap.txt index a02656a38dce..874f8279d9d2 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/local-binding-reachable2/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { defaults: function() { return defaults; } }); @@ -10,7 +10,6 @@ const defaults = { }; }), "./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { Something: function() { return Something; } }); @@ -23,7 +22,6 @@ var Sider = new Test(); var Something = 333; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); (0, _export__WEBPACK_IMPORTED_MODULE_0__.Something)(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/__snapshots__/treeshaking.snap.txt index e408ca025e03..f18350655527 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects1/__snapshots__/treeshaking.snap.txt @@ -1,18 +1,16 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); const a = 3; }), "./c.js": (function () { -"use strict"; const c = 300; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/__snapshots__/treeshaking.snap.txt index 8b00f1157794..7e11a896f3ea 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/module-rule-side-effects2/__snapshots__/treeshaking.snap.txt @@ -1,18 +1,16 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); const a = 3; }), "./b.js": (function () { -"use strict"; const b = 30; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./a.js"); /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./b.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/__snapshots__/treeshaking.snap.txt index d4b91d05f875..103f5f2e036d 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/named-export-decl-with-src-eval/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { cccc: function() { return cccc; } }); function cccc() {} }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./c.js"); (0, _export__WEBPACK_IMPORTED_MODULE_0__.cccc)(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/__snapshots__/treeshaking.snap.txt index d90ff3a4074d..94c704e820c7 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/named_export_alias/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { something: function() { return something; } }); function something() {} }), "./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return a; } }); @@ -21,7 +20,6 @@ var a = function test() { }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./export.js"); _export__WEBPACK_IMPORTED_MODULE_0__["default"]; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/__snapshots__/treeshaking.snap.txt index be8784218818..eaf056fbc61c 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/namespace-access-var-decl-rhs/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -10,7 +10,6 @@ const a = { }; }), "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { b: function() { return b; } }); @@ -19,13 +18,11 @@ const b = { }; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); console.log(_lib__WEBPACK_IMPORTED_MODULE_0__.getDocPermissionTextSendMe); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { getDocPermissionTextSendMe: function() { return getDocPermissionTextSendMe; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/__snapshots__/treeshaking.snap.txt index 6f22d75c3d3f..87629510994f 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-3/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -9,7 +9,6 @@ const a = 103330; const b = 103330; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); _lib__WEBPACK_IMPORTED_MODULE_0__.a; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/__snapshots__/treeshaking.snap.txt index 6f22d75c3d3f..87629510994f 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/nested-import-4/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -9,7 +9,6 @@ const a = 103330; const b = 103330; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./answer.js"); _lib__WEBPACK_IMPORTED_MODULE_0__.a; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/__snapshots__/treeshaking.snap.txt index 27d1a8489576..310fdb2870e6 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/prune-bailout-module/__snapshots__/treeshaking.snap.txt @@ -1,11 +1,10 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; /* harmony default export */ __webpack_exports__["default"] = (300); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/__snapshots__/treeshaking.snap.txt index 61084ea64a6b..f8082d6d046a 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/pure_comments_magic_comments/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -13,7 +13,6 @@ const a = 3; /* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = ((/* unused pure expression or super */ null && (res()))); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__.a; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/__snapshots__/treeshaking.snap.txt index 8d985a9a6872..ecdeae1e3f34 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/react-redux-like/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./selector.js"); @@ -9,12 +9,10 @@ _foo__WEBPACK_IMPORTED_MODULE_0__["default"]; _foo__WEBPACK_IMPORTED_MODULE_1__["default"]; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; function Provider() {} /* harmony default export */ __webpack_exports__["default"] = (Provider); }), "./selector.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return useSelector; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/__snapshots__/treeshaking.snap.txt index 2b8a21627214..8570952c7526 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as-multi-level-nested/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./package/autogen/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -11,7 +11,6 @@ function dddd() {} }), "./package/autogen/aa.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { aa: function() { return aa; } }); @@ -19,7 +18,6 @@ const aa = 3; const cc = 3; }), "./src/index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/a.js"); /* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./package/autogen/aa.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/__snapshots__/treeshaking.snap.txt index 6868a72f68b9..288d1b7645f1 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport-all-as/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./package/autogen/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -9,7 +9,6 @@ function a() {} function dddd() {} }), "./src/index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package/autogen/a.js"); _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/__snapshots__/treeshaking.snap.txt index fa48ae90eeee..f9cf576ffd2f 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport_default_as/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return test; } }); function test() {} }), "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { Select: function() { return /* reexport safe */ _bar__WEBPACK_IMPORTED_MODULE_0__["default"]; } }); @@ -16,7 +15,6 @@ __webpack_require__.d(__webpack_exports__, { }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); (0, _foo__WEBPACK_IMPORTED_MODULE_0__.Select)(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/__snapshots__/treeshaking.snap.txt index 5cfc5a37f2ca..f348ba01d1c8 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/reexport_entry_elimination/__snapshots__/treeshaking.snap.txt @@ -1,17 +1,15 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./c.js"); /* harmony default export */ __webpack_exports__["default"] = (2000 + _c_js__WEBPACK_IMPORTED_MODULE_0__["default"]); }), "./c.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; /* harmony default export */ __webpack_exports__["default"] = (10); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./b.js"); _a_js__WEBPACK_IMPORTED_MODULE_0__["default"]; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/__snapshots__/treeshaking.snap.txt index 834ef2833417..b7f0acb765ac 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rename-export-from-import/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { q: function() { return /* reexport safe */ _lib__WEBPACK_IMPORTED_MODULE_0__.question; } }); @@ -10,13 +10,11 @@ __webpack_require__.d(__webpack_exports__, { }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__.q; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { question: function() { return question; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/__snapshots__/treeshaking.snap.txt index 347c094c58d9..171632da6c53 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports-function-argument/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { bar: function() { return bar; } }); @@ -14,7 +14,6 @@ function bar() { } }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); var answer = (0, _foo__WEBPACK_IMPORTED_MODULE_0__["default"])(); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/__snapshots__/treeshaking.snap.txt index c1ad4185a781..489582788277 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unmodified-default-exports/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./foo.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; var Foo = function() { console.log("side effect"); this.isFoo = true; @@ -14,7 +14,6 @@ Foo.prototype = { }; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); var foo = new _foo__WEBPACK_IMPORTED_MODULE_0__["default"](); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/__snapshots__/treeshaking.snap.txt index d0284dda60be..4843df464d7f 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-called-import/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./dead.js": (function () { -"use strict"; /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() { return "dead"; } }), "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } }); @@ -21,7 +20,6 @@ function foodead() { } }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); assert.equal((0, _foo__WEBPACK_IMPORTED_MODULE_0__["default"])(), "foo"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/__snapshots__/treeshaking.snap.txt index 04c272b4919b..2c9c3faa2c28 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-default-exports/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { foo: function() { return foo; } }); @@ -15,7 +15,6 @@ function mutate(obj) { /* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (mutate(foo)); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); assert.equal(_foo__WEBPACK_IMPORTED_MODULE_0__.foo.value, 2); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/__snapshots__/treeshaking.snap.txt index e0033e6b9662..32bacf299668 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-inner-functions-and-classes/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _stuff__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./stuff.js"); (0, _stuff__WEBPACK_IMPORTED_MODULE_0__.bar)(); @@ -19,7 +19,6 @@ class UnusedClass { console.log(getClass().name); }), "./stuff.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { bar: function() { return bar; }, baz: function() { return Baz; } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/__snapshots__/treeshaking.snap.txt index 09238e7bd733..2d15d221a9af 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/rollup-unused-var/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { foo: function() { return foo; } }); @@ -11,7 +11,6 @@ var baz = (/* unused pure expression or super */ null && (bar || foo)); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./foo.js"); console.log(_foo_js__WEBPACK_IMPORTED_MODULE_0__.foo); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/__snapshots__/treeshaking.snap.txt index d242f6acd1bb..70112a63b1f2 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-analyzed/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__["default"])(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/__snapshots__/treeshaking.snap.txt index 697bbbe96f6a..d4981f698e11 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-export-default-expr/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { b: function() { return b; } }); @@ -10,7 +10,6 @@ __webpack_require__.d(__webpack_exports__, { const b = 1; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__.b; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/__snapshots__/treeshaking.snap.txt index 191ae3136b4f..52e5af06d19c 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-flagged-only/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { something: function() { return /* reexport safe */ _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } }); @@ -11,13 +11,11 @@ __webpack_require__.d(__webpack_exports__, { }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } }); @@ -27,7 +25,6 @@ const something = function() {}; /* harmony default export */ function __WEBPACK_DEFAULT_EXPORT__() {} }), "./src/a.js": (function () { -"use strict"; /* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = ((()=>{ console.log(""); })); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/__snapshots__/treeshaking.snap.txt index 3d5c0418a950..fd60392b57bd 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-prune/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); // a; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { something: function() { return something; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/__snapshots__/treeshaking.snap.txt index d242f6acd1bb..70112a63b1f2 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/side-effects-two/__snapshots__/treeshaking.snap.txt @@ -1,13 +1,12 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./lib.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__["default"])(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return /* export default binding */ __WEBPACK_DEFAULT_EXPORT__; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/__snapshots__/treeshaking.snap.txt index e2d0cda61cea..6c2a2ec17d45 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/simple-namespace-access/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _maths_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./maths.js"); /* TREE-SHAKING */ console.log(_maths_js__WEBPACK_IMPORTED_MODULE_0__.xxx.test); console.log(_maths_js__WEBPACK_IMPORTED_MODULE_0__.square); }), "./maths.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { square: function() { return square; }, xxx: function() { return /* reexport module object */ _test_js__WEBPACK_IMPORTED_MODULE_0__; } @@ -29,7 +28,6 @@ function cube(x) { }), "./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { test: function() { return test; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/static-class/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/static-class/__snapshots__/treeshaking.snap.txt index cde74b921b4a..b0172c0cdd44 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/static-class/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/static-class/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -21,7 +21,6 @@ class Result { const a = 3; }), "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { bb: function() { return bb; } }); @@ -29,7 +28,6 @@ const bb = 2; const cc = 3; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); _a_js__WEBPACK_IMPORTED_MODULE_0__.a; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/__snapshots__/treeshaking.snap.txt index e417bc85afbe..d92cfcb53963 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-false-with-side-effect-true/__snapshots__/treeshaking.snap.txt @@ -1,21 +1,19 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./ b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { b: function() { return b; } }); const b = 3; }), "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); const a = 3; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./ b.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt index 02ab1e708e8f..84b434d86ec7 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-interop/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=bar_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["bar_js"], { "./bar.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": function() { return test; } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt index 5c810cb6c5a5..346cf5387537 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/tree-shaking-lazy-import/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=lib_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["lib_js"], { "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./test.js"); @@ -11,7 +11,6 @@ function myanswer() { /* harmony default export */ __webpack_exports__["default"] = (myanswer); }), "./test.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; function test() {} /* harmony default export */ __webpack_exports__["default"] = (test); }), @@ -20,16 +19,15 @@ function test() {} ``` ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { answer: function() { return answer; } }); const answer = 30; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); const a = test(()=>__webpack_require__.e(/* import() */ "lib_js").then(__webpack_require__.bind(__webpack_require__, "./lib.js"))); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/__snapshots__/treeshaking.snap.txt index b0f7f9c05699..c9e2b27e632d 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/ts-target-es5/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function () { -"use strict"; async function test() {} test(); }), diff --git a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/__snapshots__/treeshaking.snap.txt index db5aaad09f36..48571fc23812 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/unused-class-rename/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { test: function() { return test; } }); @@ -15,7 +15,6 @@ if (__AAA__) { } }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); _app__WEBPACK_IMPORTED_MODULE_0__.test; diff --git a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/__snapshots__/treeshaking.snap.txt index 806e5f8c8e93..8a9b89bf4b6b 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/var-function-expr/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { app: function() { return app; } }); @@ -17,13 +17,11 @@ var app4 = (0, _lib__WEBPACK_IMPORTED_MODULE_0__.something)("app4"), app5 = 1000 var app3 = (0, _lib__WEBPACK_IMPORTED_MODULE_0__.something)("app3"); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./app.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.app)(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { result: function() { return result; }, something: function() { return something; } diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/__snapshots__/treeshaking.snap.txt index 827a20d0b72a..5fa2864e27a8 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-export-default-named/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return abc; } }); @@ -12,7 +12,6 @@ function abc() { } }), "./b.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?b"); function abc() { @@ -20,7 +19,6 @@ function abc() { } }), "./c.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?c"); function abc() { @@ -29,7 +27,6 @@ function abc() { abc(); }), "./d.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { "default": function() { return def; } }); @@ -42,7 +39,6 @@ class def { } }), "./dep.js?a": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); @@ -50,12 +46,10 @@ const x = "x"; /* harmony default export */ __webpack_exports__["default"] = (true); }), "./dep.js?b": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; const x = "x"; /* harmony default export */ __webpack_exports__["default"] = (false); }), "./dep.js?c": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); @@ -63,7 +57,6 @@ const x = "x"; /* harmony default export */ __webpack_exports__["default"] = (true); }), "./dep.js?d": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); @@ -71,12 +64,10 @@ const x = "x"; /* harmony default export */ __webpack_exports__["default"] = (true); }), "./dep.js?e": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; const x = "x"; /* harmony default export */ __webpack_exports__["default"] = (false); }), "./dep.js?f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); @@ -84,7 +75,6 @@ const x = "x"; /* harmony default export */ __webpack_exports__["default"] = (true); }), "./e.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?e"); class def { @@ -94,7 +84,6 @@ class def { } }), "./f.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _dep_f__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./dep.js?f"); class def { @@ -105,7 +94,6 @@ class def { new def().method(); }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); /* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); /* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./c.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt index a52e852e672c..3a30cbb9b3b0 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-inner-graph-switch/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=chunk_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["chunk_js"], { "./chunk.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); }), diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt index bb30cb6890be..381f41203f98 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=chunk_js.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["chunk_js"], { "./chunk.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./inner.js"); @@ -11,9 +11,9 @@ __webpack_require__.r(__webpack_exports__); ``` ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./inner.js"); /* harmony import */var _module__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./module.js"); @@ -27,7 +27,6 @@ it("export should be unused when only unused functions use it", ()=>{ }); }), "./inner.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { A: function() { return A; }, B: function() { return B; }, @@ -49,7 +48,6 @@ const exportBUsed = true; const exportCUsed = false; }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { y: function() { return y; } }); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/__snapshots__/treeshaking.snap.txt index 5570068121a4..531467c3cdda 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-innergraph-circular2/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./module.js"); it("should be able to handle circular referenced", ()=>{ @@ -36,7 +36,6 @@ it("should be able to handle circular referenced", ()=>{ }); }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; }, f3: function() { return f3; }, diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt index 71261a9edc24..01ec53b22a49 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-reexport-namespace-and-default/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package1/script.js"); /* harmony import */var _package1_script2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./package1/script2.js"); /* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./package2/script.js"); @@ -22,7 +22,6 @@ it("default export should be used", ()=>{ }); }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { mod: function() { return mod; } @@ -34,7 +33,6 @@ __webpack_require__.d(__webpack_exports__, { const mod = _package2_script__WEBPACK_IMPORTED_MODULE_1__["default"]; }), "./package1/script.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { exportDefaultUsed: function() { return exportDefaultUsed; } }); @@ -45,13 +43,11 @@ __webpack_require__.d(__webpack_exports__, { const exportDefaultUsed = false; }), "./package1/script1.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _script2__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./package1/script2.js"); /* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = (1); }), "./package1/script2.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { exportDefaultUsed: function() { return exportDefaultUsed; } }); @@ -63,7 +59,6 @@ __webpack_require__.d(__webpack_exports__, { const exportDefaultUsed = false; }), "./package2/script.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { exportDefaultUsed: function() { return exportDefaultUsed; } }); @@ -74,7 +69,6 @@ __webpack_require__.d(__webpack_exports__, { const exportDefaultUsed = true; }), "./package2/script1.js": (function (__unused_webpack_module, __webpack_exports__) { -"use strict"; /* harmony default export */ __webpack_exports__["default"] = (1); }), diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt index 301d67136c30..94354c32e0fc 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-all-used/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "../node_modules/pmodule/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); @@ -14,7 +14,6 @@ var c = "c"; (0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("a.js"); }), "../node_modules/pmodule/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); @@ -27,7 +26,6 @@ var y = "y"; (0, _tracker__WEBPACK_IMPORTED_MODULE_1__.track)("b.js"); }), "../node_modules/pmodule/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { z: function() { return z; } }); @@ -38,7 +36,6 @@ var z = "z"; (0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("c.js"); }), "../node_modules/pmodule/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/tracker.js"); @@ -47,7 +44,6 @@ var z = "z"; /* harmony default export */ __webpack_exports__["default"] = ("def"); }), "../node_modules/pmodule/tracker.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { log: function() { return log; }, track: function() { return track; } @@ -62,7 +58,6 @@ function reset() { } }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../node_modules/pmodule/tracker.js"); /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/a.js"); /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/b.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt index 14de0517830f..f1f79cfd9bc2 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/webpack-side-effects-simple-unused/__snapshots__/treeshaking.snap.txt @@ -1,7 +1,7 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "../node_modules/pmodule/b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { x: function() { return x; } }); @@ -14,7 +14,6 @@ var y = "y"; (0, _tracker__WEBPACK_IMPORTED_MODULE_1__.track)("b.js"); }), "../node_modules/pmodule/c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { z: function() { return z; } }); @@ -25,7 +24,6 @@ var z = "z"; (0, _tracker__WEBPACK_IMPORTED_MODULE_0__.track)("c.js"); }), "../node_modules/pmodule/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/tracker.js"); @@ -34,7 +32,6 @@ var z = "z"; /* harmony default export */ __webpack_exports__["default"] = ("def"); }), "../node_modules/pmodule/tracker.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { log: function() { return log; }, track: function() { return track; } @@ -49,7 +46,6 @@ function reset() { } }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../node_modules/pmodule/tracker.js"); /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../node_modules/pmodule/b.js"); /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../node_modules/pmodule/c.js"); diff --git a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/__snapshots__/treeshaking.snap.txt index 488101a18122..7e4553a23d86 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/with-assets/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/with-assets/__snapshots__/treeshaking.snap.txt @@ -1,14 +1,13 @@ ```js title=main.js +"use strict"; (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { "./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); const a = 3; }), "./index.js": (function (__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { -"use strict"; /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); /* harmony import */var _a_svg__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./a.svg"); @@ -17,7 +16,6 @@ _a_js__WEBPACK_IMPORTED_MODULE_0__.a; _a_svg__WEBPACK_IMPORTED_MODULE_1__; }), "./a.svg": (function (module) { -"use strict"; module.exports = "data:image/svg+xml;base64,";}), },function(__webpack_require__) { diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index 8ab79f2de853..67447dd711df 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -2707,6 +2707,57 @@ export type EntryUnnamed = z.infer; // @public (undocumented) const entryUnnamed: z.ZodUnion<[z.ZodString, z.ZodArray]>; +// @public (undocumented) +export type Environment = z.infer; + +// @public (undocumented) +const environment: z.ZodObject<{ + arrowFunction: z.ZodOptional; + asyncFunction: z.ZodOptional; + bigIntLiteral: z.ZodOptional; + const: z.ZodOptional; + destructuring: z.ZodOptional; + document: z.ZodOptional; + dynamicImport: z.ZodOptional; + dynamicImportInWorker: z.ZodOptional; + forOf: z.ZodOptional; + globalThis: z.ZodOptional; + module: z.ZodOptional; + nodePrefixForCoreModules: z.ZodOptional; + optionalChaining: z.ZodOptional; + templateLiteral: z.ZodOptional; +}, "strict", z.ZodTypeAny, { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; +}, { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; +}>; + // @public export class EnvironmentPlugin { constructor(...keys: any[]); @@ -6531,6 +6582,52 @@ const output: z.ZodObject<{ devtoolNamespace: z.ZodOptional; devtoolModuleFilenameTemplate: z.ZodOptional, z.ZodAny>]>>; devtoolFallbackModuleFilenameTemplate: z.ZodOptional, z.ZodAny>]>>; + environment: z.ZodOptional; + asyncFunction: z.ZodOptional; + bigIntLiteral: z.ZodOptional; + const: z.ZodOptional; + destructuring: z.ZodOptional; + document: z.ZodOptional; + dynamicImport: z.ZodOptional; + dynamicImportInWorker: z.ZodOptional; + forOf: z.ZodOptional; + globalThis: z.ZodOptional; + module: z.ZodOptional; + nodePrefixForCoreModules: z.ZodOptional; + optionalChaining: z.ZodOptional; + templateLiteral: z.ZodOptional; + }, "strict", z.ZodTypeAny, { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + }, { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + }>>; }, "strict", z.ZodTypeAny, { path?: string | undefined; pathinfo?: boolean | "verbose" | undefined; @@ -6607,6 +6704,22 @@ const output: z.ZodObject<{ devtoolNamespace?: string | undefined; devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; + environment?: { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + } | undefined; }, { path?: string | undefined; pathinfo?: boolean | "verbose" | undefined; @@ -6683,6 +6796,22 @@ const output: z.ZodObject<{ devtoolNamespace?: string | undefined; devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; + environment?: { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + } | undefined; }>; // @public (undocumented) @@ -6752,6 +6881,8 @@ export interface OutputNormalized { // (undocumented) enabledWasmLoadingTypes?: EnabledWasmLoadingTypes; // (undocumented) + environment?: Environment; + // (undocumented) filename?: Filename; // (undocumented) globalObject?: GlobalObject; @@ -7791,6 +7922,7 @@ declare namespace rspackExports { DevtoolNamespace, DevtoolModuleFilenameTemplate, DevtoolFallbackModuleFilenameTemplate, + Environment, Output, ResolveAlias, ResolveTsconfig, @@ -8326,6 +8458,52 @@ export const rspackOptions: z.ZodObject<{ devtoolNamespace: z.ZodOptional; devtoolModuleFilenameTemplate: z.ZodOptional, z.ZodAny>]>>; devtoolFallbackModuleFilenameTemplate: z.ZodOptional, z.ZodAny>]>>; + environment: z.ZodOptional; + asyncFunction: z.ZodOptional; + bigIntLiteral: z.ZodOptional; + const: z.ZodOptional; + destructuring: z.ZodOptional; + document: z.ZodOptional; + dynamicImport: z.ZodOptional; + dynamicImportInWorker: z.ZodOptional; + forOf: z.ZodOptional; + globalThis: z.ZodOptional; + module: z.ZodOptional; + nodePrefixForCoreModules: z.ZodOptional; + optionalChaining: z.ZodOptional; + templateLiteral: z.ZodOptional; + }, "strict", z.ZodTypeAny, { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + }, { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + }>>; }, "strict", z.ZodTypeAny, { path?: string | undefined; pathinfo?: boolean | "verbose" | undefined; @@ -8402,6 +8580,22 @@ export const rspackOptions: z.ZodObject<{ devtoolNamespace?: string | undefined; devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; + environment?: { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + } | undefined; }, { path?: string | undefined; pathinfo?: boolean | "verbose" | undefined; @@ -8478,6 +8672,22 @@ export const rspackOptions: z.ZodObject<{ devtoolNamespace?: string | undefined; devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; + environment?: { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + } | undefined; }>>; target: z.ZodOptional, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodEnum<["web", "webworker", "es3", "es5", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020", "es2021", "es2022", "browserslist"]>, z.ZodLiteral<"node">]>, z.ZodLiteral<"async-node">]>, z.ZodType<`node${number}`, z.ZodTypeDef, `node${number}`>]>, z.ZodType<`async-node${number}`, z.ZodTypeDef, `async-node${number}`>]>, z.ZodType<`node${number}.${number}`, z.ZodTypeDef, `node${number}.${number}`>]>, z.ZodType<`async-node${number}.${number}`, z.ZodTypeDef, `async-node${number}.${number}`>]>, z.ZodLiteral<"electron-main">]>, z.ZodType<`electron${number}-main`, z.ZodTypeDef, `electron${number}-main`>]>, z.ZodType<`electron${number}.${number}-main`, z.ZodTypeDef, `electron${number}.${number}-main`>]>, z.ZodLiteral<"electron-renderer">]>, z.ZodType<`electron${number}-renderer`, z.ZodTypeDef, `electron${number}-renderer`>]>, z.ZodType<`electron${number}.${number}-renderer`, z.ZodTypeDef, `electron${number}.${number}-renderer`>]>, z.ZodLiteral<"electron-preload">]>, z.ZodType<`electron${number}-preload`, z.ZodTypeDef, `electron${number}-preload`>]>, z.ZodType<`electron${number}.${number}-preload`, z.ZodTypeDef, `electron${number}.${number}-preload`>]>]>, z.ZodArray, z.ZodLiteral<"node">]>, z.ZodLiteral<"async-node">]>, z.ZodType<`node${number}`, z.ZodTypeDef, `node${number}`>]>, z.ZodType<`async-node${number}`, z.ZodTypeDef, `async-node${number}`>]>, z.ZodType<`node${number}.${number}`, z.ZodTypeDef, `node${number}.${number}`>]>, z.ZodType<`async-node${number}.${number}`, z.ZodTypeDef, `async-node${number}.${number}`>]>, z.ZodLiteral<"electron-main">]>, z.ZodType<`electron${number}-main`, z.ZodTypeDef, `electron${number}-main`>]>, z.ZodType<`electron${number}.${number}-main`, z.ZodTypeDef, `electron${number}.${number}-main`>]>, z.ZodLiteral<"electron-renderer">]>, z.ZodType<`electron${number}-renderer`, z.ZodTypeDef, `electron${number}-renderer`>]>, z.ZodType<`electron${number}.${number}-renderer`, z.ZodTypeDef, `electron${number}.${number}-renderer`>]>, z.ZodLiteral<"electron-preload">]>, z.ZodType<`electron${number}-preload`, z.ZodTypeDef, `electron${number}-preload`>]>, z.ZodType<`electron${number}.${number}-preload`, z.ZodTypeDef, `electron${number}.${number}-preload`>]>, "many">]>>; mode: z.ZodOptional>; @@ -9949,6 +10159,22 @@ export const rspackOptions: z.ZodObject<{ devtoolNamespace?: string | undefined; devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; + environment?: { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + } | undefined; } | undefined; target?: false | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined; mode?: "none" | "development" | "production" | undefined; @@ -10372,6 +10598,22 @@ export const rspackOptions: z.ZodObject<{ devtoolNamespace?: string | undefined; devtoolModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; devtoolFallbackModuleFilenameTemplate?: string | ((args_0: any) => any) | undefined; + environment?: { + arrowFunction?: boolean | undefined; + asyncFunction?: boolean | undefined; + bigIntLiteral?: boolean | undefined; + const?: boolean | undefined; + destructuring?: boolean | undefined; + document?: boolean | undefined; + dynamicImport?: boolean | undefined; + dynamicImportInWorker?: boolean | undefined; + forOf?: boolean | undefined; + globalThis?: boolean | undefined; + module?: boolean | undefined; + nodePrefixForCoreModules?: boolean | undefined; + optionalChaining?: boolean | undefined; + templateLiteral?: boolean | undefined; + } | undefined; } | undefined; target?: false | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload` | ("es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "node" | "async-node" | "web" | "webworker" | "browserslist" | `node${number}` | `async-node${number}` | `node${number}.${number}` | `async-node${number}.${number}` | "electron-main" | `electron${number}-main` | `electron${number}.${number}-main` | "electron-renderer" | `electron${number}-renderer` | `electron${number}.${number}-renderer` | "electron-preload" | `electron${number}-preload` | `electron${number}.${number}-preload`)[] | undefined; mode?: "none" | "development" | "production" | undefined; diff --git a/packages/rspack/src/config/adapter.ts b/packages/rspack/src/config/adapter.ts index c08ef1a36703..4428d92e5481 100644 --- a/packages/rspack/src/config/adapter.ts +++ b/packages/rspack/src/config/adapter.ts @@ -59,6 +59,7 @@ import { CssModuleParserOptions, CssParserOptions, EntryRuntime, + Environment, GeneratorOptionsByModuleType, JavascriptParserOptions, LibraryName, @@ -248,7 +249,8 @@ function getRawOutput(output: OutputNormalized): RawOptions["output"] { workerWasmLoading: workerWasmLoading === false ? "false" : workerWasmLoading, workerPublicPath: output.workerPublicPath!, - scriptType: output.scriptType === false ? "false" : output.scriptType! + scriptType: output.scriptType === false ? "false" : output.scriptType!, + environment: output.environment! }; } diff --git a/packages/rspack/src/config/browserslistTargetHandler.js b/packages/rspack/src/config/browserslistTargetHandler.js index f605e18e460b..23a5e1a6ffb9 100644 --- a/packages/rspack/src/config/browserslistTargetHandler.js +++ b/packages/rspack/src/config/browserslistTargetHandler.js @@ -28,7 +28,7 @@ const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i; */ /** - * @param {string} input input string + * @param {string | null | undefined} input input string * @param {string} context the context directory * @returns {BrowserslistHandlerConfig} config */ @@ -52,9 +52,9 @@ const parse = (input, context) => { }; /** - * @param {string} input input string + * @param {string | null | undefined} input input string * @param {string} context the context directory - * @returns {string[] | undefined | null} selected browsers + * @returns {string[] | undefined} selected browsers */ const load = (input, context) => { const { configPath, env, query } = parse(input, context); @@ -71,7 +71,7 @@ const load = (input, context) => { }) : browserslist.loadConfig({ path: context, env }); - if (!config) return null; + if (!config) return; return browserslist(config); }; @@ -95,7 +95,9 @@ const resolve = browsers => { // safari TP supports all features for normal safari parsedVersion === "TP" ? [Infinity, Infinity] - : parsedVersion.split("."); + : parsedVersion.includes("-") + ? parsedVersion.split("-")[0].split(".") + : parsedVersion.split("."); if (typeof requiredVersion === "number") { return +parsedMajor >= requiredVersion; } @@ -123,9 +125,9 @@ const resolve = browsers => { samsung: [8, 2], android: 63, and_qq: [10, 4], - // baidu: Not supported - // and_uc: Not supported - // kaios: Not supported + baidu: [13, 18], + and_uc: [15, 5], + kaios: [3, 0], node: [12, 17] }); @@ -149,7 +151,7 @@ const resolve = browsers => { android: 37, and_qq: [10, 4], // Supported correctly in strict mode, otherwise supported without block scope - // baidu: Not supported + baidu: [13, 18], and_uc: [12, 12], kaios: [2, 5], node: [6, 0] @@ -192,7 +194,7 @@ const resolve = browsers => { // and_qq: Unknown support // baidu: Unknown support // and_uc: Unknown support - // kaios: Unknown support + kaios: [3, 0], node: [0, 12] }), destructuring: rawChecker({ @@ -211,7 +213,7 @@ const resolve = browsers => { // and_qq: Unknown support // baidu: Unknown support // and_uc: Unknown support - // kaios: Unknown support + kaios: [2, 5], node: [6, 0] }), bigIntLiteral: rawChecker({ @@ -227,10 +229,10 @@ const resolve = browsers => { ios_saf: 14, samsung: [9, 2], android: 67, - // and_qq: Not supported - // baidu: Not supported - // and_uc: Not supported - // kaios: Not supported + and_qq: [13, 1], + baidu: [13, 18], + and_uc: [15, 5], + kaios: [3, 0], node: [10, 4] }), // Support syntax `import` and `export` and no limitations and bugs on Node.js @@ -249,9 +251,9 @@ const resolve = browsers => { samsung: [8, 0], android: 61, and_qq: [10, 4], - // baidu: Not supported - // and_uc: Not supported - // kaios: Not supported + baidu: [13, 18], + and_uc: [15, 5], + kaios: [3, 0], node: [12, 17] }), dynamicImport: es6DynamicImport, @@ -274,7 +276,7 @@ const resolve = browsers => { // and_qq: Unknown support // baidu: Unknown support // and_uc: Unknown support - // kaios: Unknown support + kaios: [3, 0], node: 12 }), optionalChaining: rawChecker({ @@ -293,7 +295,7 @@ const resolve = browsers => { // and_qq: Not supported // baidu: Not supported // and_uc: Not supported - // kaios: Not supported + kaios: [3, 0], node: 14 }), templateLiteral: rawChecker({ @@ -315,6 +317,25 @@ const resolve = browsers => { kaios: [2, 5], node: 4 }), + asyncFunction: rawChecker({ + chrome: 55, + and_chr: 55, + edge: 15, + firefox: 52, + and_ff: 52, + // ie: Not supported, + opera: 42, + op_mob: 42, + safari: 11, + ios_saf: 11, + samsung: [6, 2], + android: 55, + and_qq: [13, 1], + baidu: [13, 18], + and_uc: [15, 5], + kaios: 3, + node: [7, 6] + }), browser: browserProperty, electron: false, node: nodeProperty, @@ -328,6 +349,12 @@ const resolve = browsers => { importScripts: false, importScriptsInWorker: true, nodeBuiltins: nodeProperty, + nodePrefixForCoreModules: + nodeProperty && + !browsers.some(b => b.startsWith("node 15")) && + rawChecker({ + node: [14, 18] + }), require: nodeProperty }; }; diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 0965b578a3ba..34fcdf8e1857 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -766,6 +766,40 @@ const applyOutputDefaults = ( // }); return Array.from(enabledWasmLoadingTypes); }); + + const environment = output.environment!; + const optimistic = (v?: boolean) => v || v === undefined; + const conditionallyOptimistic = (v?: boolean, c?: boolean) => + (v === undefined && c) || v; + + F(environment, "globalThis", () => tp && tp.globalThis); + F(environment, "bigIntLiteral", () => tp && tp.bigIntLiteral); + F(environment, "const", () => tp && optimistic(tp.const)); + F(environment, "arrowFunction", () => tp && optimistic(tp.arrowFunction)); + F(environment, "asyncFunction", () => tp && optimistic(tp.asyncFunction)); + F(environment, "forOf", () => tp && optimistic(tp.forOf)); + F(environment, "destructuring", () => tp && optimistic(tp.destructuring)); + F( + environment, + "optionalChaining", + () => tp && optimistic(tp.optionalChaining) + ); + F( + environment, + "nodePrefixForCoreModules", + () => tp && optimistic(tp.nodePrefixForCoreModules) + ); + F(environment, "templateLiteral", () => tp && optimistic(tp.templateLiteral)); + F(environment, "dynamicImport", () => + conditionallyOptimistic(tp && tp.dynamicImport, output.module) + ); + F(environment, "dynamicImportInWorker", () => + conditionallyOptimistic(tp && tp.dynamicImportInWorker, output.module) + ); + F(environment, "module", () => + conditionallyOptimistic(tp && tp.module, output.module) + ); + F(environment, "document", () => tp && optimistic(tp.document)); }; const applyExternalsPresetsDefaults = ( diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 1fbb86c8f905..95d6ee11eb8c 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -35,6 +35,7 @@ import type { EntryFilename, EntryRuntime, EntryStatic, + Environment, Externals, ExternalsPresets, ExternalsType, @@ -208,7 +209,8 @@ export const getNormalizedRspackOptions = ( devtoolNamespace: output.devtoolNamespace, devtoolModuleFilenameTemplate: output.devtoolModuleFilenameTemplate, devtoolFallbackModuleFilenameTemplate: - output.devtoolFallbackModuleFilenameTemplate + output.devtoolFallbackModuleFilenameTemplate, + environment: cloneObject(output.environment) }; }), resolve: nestedConfig(config.resolve, resolve => ({ @@ -488,6 +490,7 @@ export interface OutputNormalized { devtoolNamespace?: DevtoolNamespace; devtoolModuleFilenameTemplate?: DevtoolModuleFilenameTemplate; devtoolFallbackModuleFilenameTemplate?: DevtoolFallbackModuleFilenameTemplate; + environment?: Environment; } export interface ModuleOptionsNormalized { diff --git a/packages/rspack/src/config/target.js b/packages/rspack/src/config/target.js index 90ec3cd4fb68..6f094d54e9ae 100644 --- a/packages/rspack/src/config/target.js +++ b/packages/rspack/src/config/target.js @@ -8,6 +8,8 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ +"use strict"; + const { memoize } = require("../util/memoize"); const getBrowserslistTargetHandler = memoize(() => @@ -16,13 +18,11 @@ const getBrowserslistTargetHandler = memoize(() => /** * @param {string} context the context directory - * @returns {import("..").Target} target properties + * @returns {"browserslist" | "web"} default target */ const getDefaultTarget = context => { - // TODO: align with webpack - // const browsers = getBrowserslistTargetHandler().load(null, context); - // return browsers ? "browserslist" : "web"; - return "web"; + const browsers = getBrowserslistTargetHandler().load(null, context); + return browsers ? "browserslist" : "web"; }; /** @@ -46,6 +46,7 @@ const getDefaultTarget = context => { * @typedef {Object} ApiTargetProperties * @property {boolean | null} require has require function available * @property {boolean | null} nodeBuiltins has node.js built-in modules available + * @property {boolean | null} nodePrefixForCoreModules node.js allows to use `node:` prefix for core modules * @property {boolean | null} document has document available (allows script tags) * @property {boolean | null} importScripts has importScripts available * @property {boolean | null} importScriptsInWorker has importScripts available when creating a worker @@ -66,25 +67,43 @@ const getDefaultTarget = context => { * @property {boolean | null} module ESM syntax is available (when in module) * @property {boolean | null} optionalChaining optional chaining is available * @property {boolean | null} templateLiteral template literal is available + * @property {boolean | null} asyncFunction async functions and await are available */ ///** @typedef {PlatformTargetProperties | ApiTargetProperties | EcmaTargetProperties | PlatformTargetProperties & ApiTargetProperties | PlatformTargetProperties & EcmaTargetProperties | ApiTargetProperties & EcmaTargetProperties} TargetProperties */ -/** @template T @typedef {{ [P in keyof T]?: never }} Never */ -/** @template A @template B @typedef {(A & Never) | (Never & B) | (A & B)} Mix */ + +/** + * @template T + * @typedef {{ [P in keyof T]?: never }} Never + */ + +/** + * @template A + * @template B + * @typedef {(A & Never) | (Never & B) | (A & B)} Mix + */ + /** @typedef {Mix, Mix>} TargetProperties */ -// @ts-expect-error +/** + * @param {string} major major version + * @param {string | undefined} minor minor version + * @returns {(vMajor: number, vMinor?: number) => boolean | undefined} check if version is greater or equal + */ const versionDependent = (major, minor) => { - if (!major) return () => /** @type {undefined} */ (undefined); - major = +major; - minor = minor ? +minor : 0; - // @ts-expect-error + if (!major) { + return () => /** @type {undefined} */ (undefined); + } + /** @type {number} */ + const nMajor = +major; + /** @type {number} */ + const nMinor = minor ? +minor : 0; return (vMajor, vMinor = 0) => { - return major > vMajor || (major === vMajor && minor >= vMinor); + return nMajor > vMajor || (nMajor === vMajor && nMinor >= vMinor); }; }; -/** @type {[string, string, RegExp, (...args: string[]) => TargetProperties | false][]} */ +/** @type {[string, string, RegExp, (...args: string[]) => Partial][]} */ const TARGETS = [ [ "browserslist / browserslist:env / browserslist:query / browserslist:path-to-config / browserslist:path-to-config:env", @@ -93,7 +112,6 @@ const TARGETS = [ (rest, context) => { const browserslistTargetHandler = getBrowserslistTargetHandler(); const browsers = browserslistTargetHandler.load( - // @ts-expect-error rest ? rest.trim() : null, context ); @@ -103,6 +121,7 @@ See https://github.com/browserslist/browserslist#queries for possible ways to pr The recommended way is to add a 'browserslist' key to your package.json and list supported browsers (resp. node.js versions). You can also more options via the 'target' option: 'browserslist' / 'browserslist:env' / 'browserslist:query' / 'browserslist:path-to-config' / 'browserslist:path-to-config:env'`); } + return browserslistTargetHandler.resolve(browsers); } ], @@ -155,9 +174,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis [ "[async-]node[X[.Y]]", "Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.", - /^(async-)?node(\d+(?:\.(\d+))?)?$/, - // @ts-expect-error - (asyncFlag, major, minor) => { + /^(async-)?node((\d+)(?:\.(\d+))?)?$/, + (asyncFlag, _, major, minor) => { const v = versionDependent(major, minor); // see https://node.green/ return { @@ -170,6 +188,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis require: !asyncFlag, nodeBuiltins: true, + // v16.0.0, v14.18.0 + nodePrefixForCoreModules: +major < 15 ? v(14, 18) : v(16), global: true, document: false, fetchWasm: false, @@ -181,6 +201,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis templateLiteral: v(4), optionalChaining: v(14), arrowFunction: v(6), + asyncFunction: v(7, 6), forOf: v(5), destructuring: v(6), bigIntLiteral: v(10, 4), @@ -193,9 +214,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis [ "electron[X[.Y]]-main/preload/renderer", "Electron in version X.Y. Script is running in main, preload resp. renderer context.", - /^electron(\d+(?:\.(\d+))?)?-(main|preload|renderer)$/, - // @ts-expect-error - (major, minor, context) => { + /^electron((\d+)(?:\.(\d+))?)?-(main|preload|renderer)$/, + (_, major, minor, context) => { const v = versionDependent(major, minor); // see https://node.green/ + https://github.com/electron/releases return { @@ -212,6 +232,10 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis global: true, nodeBuiltins: true, + // 15.0.0 - Node.js v16.5 + // 14.0.0 - Mode.js v14.17, but prefixes only since v14.18 + nodePrefixForCoreModules: v(15), + require: true, document: context === "renderer", fetchWasm: context === "renderer", @@ -223,6 +247,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis templateLiteral: v(1, 1), optionalChaining: v(8), arrowFunction: v(1, 1), + asyncFunction: v(1, 7), forOf: v(0, 36), destructuring: v(1, 1), bigIntLiteral: v(4), @@ -235,9 +260,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis [ "nwjs[X[.Y]] / node-webkit[X[.Y]]", "NW.js in version X.Y.", - /^(?:nwjs|node-webkit)(\d+(?:\.(\d+))?)?$/, - // @ts-expect-error - (major, minor) => { + /^(?:nwjs|node-webkit)((\d+)(?:\.(\d+))?)?$/, + (_, major, minor) => { const v = versionDependent(major, minor); // see https://node.green/ + https://github.com/nwjs/nw.js/blob/nw48/CHANGELOG.md return { @@ -261,6 +285,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis templateLiteral: v(0, 13), optionalChaining: v(0, 44), arrowFunction: v(0, 15), + asyncFunction: v(0, 21), forOf: v(0, 13), destructuring: v(0, 15), bigIntLiteral: v(0, 32), @@ -285,6 +310,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis forOf: v >= 2015, destructuring: v >= 2015, module: v >= 2015, + asyncFunction: v >= 2017, globalThis: v >= 2020, bigIntLiteral: v >= 2020, dynamicImport: v >= 2020, @@ -305,7 +331,7 @@ const getTargetProperties = (target, context) => { if (match) { const [, ...args] = match; const result = handler(...args, context); - if (result) return result; + if (result) return /** @type {TargetProperties} */ (result); } } throw new Error( @@ -314,14 +340,20 @@ const getTargetProperties = (target, context) => { ).join("\n")}` ); }; -// @ts-expect-error + +/** + * @param {TargetProperties[]} targetProperties array of target properties + * @returns {TargetProperties} merged target properties + */ const mergeTargetProperties = targetProperties => { + /** @type {Set} */ const keys = new Set(); for (const tp of targetProperties) { for (const key of Object.keys(tp)) { - keys.add(key); + keys.add(/** @type {keyof TargetProperties} */ (key)); } } + /** @type {Object} */ const result = {}; for (const key of keys) { let hasTrue = false; @@ -338,8 +370,8 @@ const mergeTargetProperties = targetProperties => { } } if (hasTrue || hasFalse) - // @ts-expect-error - result[key] = hasFalse && hasTrue ? null : hasTrue ? true : false; + /** @type {TargetProperties} */ + (result)[key] = hasFalse && hasTrue ? null : hasTrue ? true : false; } return /** @type {TargetProperties} */ (result); }; @@ -356,5 +388,5 @@ const getTargetsProperties = (targets, context) => { }; exports.getDefaultTarget = getDefaultTarget; -exports.getTargetsProperties = getTargetsProperties; exports.getTargetProperties = getTargetProperties; +exports.getTargetsProperties = getTargetsProperties; diff --git a/packages/rspack/src/config/zod.ts b/packages/rspack/src/config/zod.ts index ff1735b52455..756665aaaef8 100644 --- a/packages/rspack/src/config/zod.ts +++ b/packages/rspack/src/config/zod.ts @@ -315,6 +315,24 @@ export type DevtoolFallbackModuleFilenameTemplate = z.infer< typeof devtoolFallbackModuleFilenameTemplate >; +const environment = z.strictObject({ + arrowFunction: z.boolean().optional(), + asyncFunction: z.boolean().optional(), + bigIntLiteral: z.boolean().optional(), + const: z.boolean().optional(), + destructuring: z.boolean().optional(), + document: z.boolean().optional(), + dynamicImport: z.boolean().optional(), + dynamicImportInWorker: z.boolean().optional(), + forOf: z.boolean().optional(), + globalThis: z.boolean().optional(), + module: z.boolean().optional(), + nodePrefixForCoreModules: z.boolean().optional(), + optionalChaining: z.boolean().optional(), + templateLiteral: z.boolean().optional() +}); +export type Environment = z.infer; + const output = z.strictObject({ path: path.optional(), pathinfo: pathinfo.optional(), @@ -364,7 +382,8 @@ const output = z.strictObject({ devtoolNamespace: devtoolNamespace.optional(), devtoolModuleFilenameTemplate: devtoolModuleFilenameTemplate.optional(), devtoolFallbackModuleFilenameTemplate: - devtoolFallbackModuleFilenameTemplate.optional() + devtoolFallbackModuleFilenameTemplate.optional(), + environment: environment.optional() }); export type Output = z.infer; //#endregion diff --git a/plugin-test/copy-plugin/build/main.js b/plugin-test/copy-plugin/build/main.js index a06d9d66c1d9..c4a85773ef7f 100644 --- a/plugin-test/copy-plugin/build/main.js +++ b/plugin-test/copy-plugin/build/main.js @@ -1 +1 @@ -!function(){var t={435:function(t,r,e){"use strict";e("287")},287:function(t,r,e){"use strict";t.exports=e.p+"asset-modules/deepnested.txt"}},r={};function e(i){var o=r[i];if(void 0!==o)return o.exports;var n=r[i]={exports:{}};return t[i](n,n.exports,e),n.exports}e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),!function(){e.g.importScripts&&(t=e.g.location+"");var t,r=e.g.document;if(!t&&r&&(r.currentScript&&(t=r.currentScript.src),!t)){var i=r.getElementsByTagName("script");if(i.length){for(var o=i.length-1;o>-1&&!t;)t=i[o--].src}}if(!t)throw Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t}(),e("435")}(); \ No newline at end of file +(()=>{"use strict";var t={287:function(t,r,e){t.exports=e.p+"asset-modules/deepnested.txt"}},r={};function e(o){var i=r[o];if(void 0!==i)return i.exports;var n=r[o]={exports:{}};return t[o](n,n.exports,e),n.exports}e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),(()=>{e.g.importScripts&&(t=e.g.location+"");var t,r=e.g.document;if(!t&&r&&(r.currentScript&&(t=r.currentScript.src),!t)){var o=r.getElementsByTagName("script");if(o.length){for(var i=o.length-1;i>-1&&!t;)t=o[i--].src}}if(!t)throw Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),e.p=t})();e("287")})(); \ No newline at end of file diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$dec0863f5e812ee7cadd$.css b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$98438b00a876a2cbe211$.css similarity index 100% rename from plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$dec0863f5e812ee7cadd$.css rename to plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.$98438b00a876a2cbe211$.css diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.js b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.js index b638abf8a060..138fddadbb88 100644 --- a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.js +++ b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/async.js @@ -1,6 +1,6 @@ +"use strict"; (self['webpackChunk'] = self['webpackChunk'] || []).push([["async"], { "./async.css?833a": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$dec0863f5e812ee7cadd$.css b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$98438b00a876a2cbe211$.css similarity index 100% rename from plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$dec0863f5e812ee7cadd$.css rename to plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.$98438b00a876a2cbe211$.css diff --git a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js index 2fe31e2f2742..cdfff0a180ff 100644 --- a/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js +++ b/plugin-test/css-extract/cases/chunkFilename-fullhash/expected/main.js @@ -1,20 +1,14 @@ -(function() { -var __webpack_modules__ = { -"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); - -/* eslint-disable-next-line no-unused-expressions */ __webpack_require__.e(/* import() | async */ "async").then(__webpack_require__.bind(__webpack_require__, "./async.css?833a")); }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -32,6 +26,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -39,8 +34,10 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/ensure_chunk -!function() { +(() => { __webpack_require__.f = {}; // This file contains only the entry chunk. // The chunk loading function for additional chunks @@ -53,9 +50,9 @@ __webpack_require__.e = function (chunkId) { ); }; -}(); +})(); // webpack/runtime/get javascript chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.u = function (chunkId) { // return url for filenames not based on template @@ -64,9 +61,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".js"; }; -}(); +})(); // webpack/runtime/get mini-css chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.miniCssF = function (chunkId) { // return url for filenames not based on template @@ -75,16 +72,16 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".$" + __webpack_require__.h() + "$.css"; }; -}(); +})(); // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { - return "dec0863f5e812ee7cadd"; + return "98438b00a876a2cbe211"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -94,16 +91,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -163,9 +160,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -174,9 +171,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -198,9 +195,9 @@ __webpack_require__.r = function(exports) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/css loading -!function() { +(() => { if (typeof document === "undefined") return; var createStylesheet = function ( chunkId, fullhref, oldTag, resolve, reject @@ -289,9 +286,9 @@ __webpack_require__.f.miniCss = function(chunkId, promises) { // no hmr -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -389,8 +386,17 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); + +/* eslint-disable-next-line no-unused-expressions */ __webpack_require__.e(/* import() | async */ "async").then(__webpack_require__.bind(__webpack_require__, "./async.css?833a")); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js b/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js index f1a87a9a8bdf..e87d387f004d 100644 --- a/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js +++ b/plugin-test/css-extract/cases/custom-loader-with-functional-exports/expected/main.js @@ -1,7 +1,7 @@ -(function() { -var __webpack_modules__ = { -"./style.css?3e20": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css?3e20": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { cnA: function() { return cnA; }, @@ -11,16 +11,9 @@ __webpack_require__.d(__webpack_exports__, { var cnA = ()=>"class-name-a"; var cnB = ()=>"class-name-b"; }), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?3e20"); - -// eslint-disable-next-line no-console -console.log((0, _style_css__WEBPACK_IMPORTED_MODULE_0__.cnA)(), (0, _style_css__WEBPACK_IMPORTED_MODULE_0__.cnB)()); -}), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -38,12 +31,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -51,16 +47,16 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -69,8 +65,18 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?3e20"); + +// eslint-disable-next-line no-console +console.log((0, _style_css__WEBPACK_IMPORTED_MODULE_0__.cnA)(), (0, _style_css__WEBPACK_IMPORTED_MODULE_0__.cnB)()); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs b/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs index 0ebd8c2813aa..29d619c02d0d 100644 --- a/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs +++ b/plugin-test/css-extract/cases/es-named-export-output-module/expected/main.mjs @@ -1,6 +1,5 @@ -var __webpack_modules__ = { +var __webpack_modules__ = ({ "./style.css?eccb": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { aClass: function() { return aClass; }, @@ -12,21 +11,9 @@ var aClass = "foo__style__a-class"; var bClass = "foo__style__b__class"; var cClass = "foo__style__cClass"; }), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?eccb"); -// eslint-disable-next-line no-console -console.log({ - css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], - aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, - bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, - cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); -}), - -} +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -44,12 +31,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -57,16 +47,16 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -75,7 +65,21 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); \ No newline at end of file +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?eccb"); + +// eslint-disable-next-line no-console +console.log({ + css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], + aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, + bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, + cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass +}); + +})(); + diff --git a/plugin-test/css-extract/cases/es-named-export/expected/main.js b/plugin-test/css-extract/cases/es-named-export/expected/main.js index 2c4ccc5a8bdd..71d67323c69a 100644 --- a/plugin-test/css-extract/cases/es-named-export/expected/main.js +++ b/plugin-test/css-extract/cases/es-named-export/expected/main.js @@ -1,7 +1,7 @@ -(function() { -var __webpack_modules__ = { -"./style.css?eccb": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css?eccb": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { aClass: function() { return aClass; }, @@ -13,21 +13,9 @@ var aClass = "foo__style__a-class"; var bClass = "foo__style__b__class"; var cClass = "foo__style__cClass"; }), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?eccb"); -// eslint-disable-next-line no-console -console.log({ - css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], - aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, - bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, - cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); -}), - -} +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -45,12 +33,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -58,16 +49,16 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -76,8 +67,23 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?eccb"); + +// eslint-disable-next-line no-console +console.log({ + css: _style_css__WEBPACK_IMPORTED_MODULE_0__["default"], + aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, + bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, + cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass +}); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js b/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js index 1c3281cda431..02b8678a306c 100644 --- a/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js +++ b/plugin-test/css-extract/cases/export-only-locals-and-es-named-export/expected/main.js @@ -1,7 +1,7 @@ -(function() { -var __webpack_modules__ = { -"./style.css": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { aClass: function() { return aClass; }, @@ -13,20 +13,9 @@ var aClass = "foo__style__a-class"; var bClass = "foo__style__b__class"; var cClass = "foo__style__cClass"; }), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css"); -// eslint-disable-next-line no-console -console.log({ - aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, - bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, - cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); -}), - -} +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -44,12 +33,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -57,16 +49,16 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -75,8 +67,22 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css"); + +// eslint-disable-next-line no-console +console.log({ + aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, + bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, + cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass +}); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js b/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js index 5d0d61ff4c6d..f41518fce5f1 100644 --- a/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js +++ b/plugin-test/css-extract/cases/export-only-locals-commonjs/expected/main.js @@ -1,25 +1,14 @@ -(function() { -var __webpack_modules__ = { -"./style.css": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin }), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css"); -// eslint-disable-next-line no-console -console.log({ - aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, - bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, - cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); -}), - -} +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -37,12 +26,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -51,8 +43,22 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css"); + +// eslint-disable-next-line no-console +console.log({ + aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, + bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, + cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass +}); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/export-only-locals/expected/main.js b/plugin-test/css-extract/cases/export-only-locals/expected/main.js index 5d0d61ff4c6d..f41518fce5f1 100644 --- a/plugin-test/css-extract/cases/export-only-locals/expected/main.js +++ b/plugin-test/css-extract/cases/export-only-locals/expected/main.js @@ -1,25 +1,14 @@ -(function() { -var __webpack_modules__ = { -"./style.css": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin }), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css"); -// eslint-disable-next-line no-console -console.log({ - aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, - bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, - cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass }); -}), - -} +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -37,12 +26,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -51,8 +43,22 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css"); + +// eslint-disable-next-line no-console +console.log({ + aClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.aClass, + bClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.bClass, + cClass: _style_css__WEBPACK_IMPORTED_MODULE_0__.cClass +}); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/hmr/expected/main.js b/plugin-test/css-extract/cases/hmr/expected/main.js index 4bfd959b9a8e..3aa34bab1eb2 100644 --- a/plugin-test/css-extract/cases/hmr/expected/main.js +++ b/plugin-test/css-extract/cases/hmr/expected/main.js @@ -1,5 +1,5 @@ -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "../../../../packages/rspack/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js": (function (module, __unused_webpack_exports, __webpack_require__) { "use strict"; /* eslint-env browser */ /* @@ -222,7 +222,8 @@ if (true) { } }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -232,7 +233,8 @@ function __webpack_require__(moduleId) { // Check if module is in cache var cachedModule = __webpack_module_cache__[moduleId]; if (cachedModule !== undefined) { -if (cachedModule.error !== undefined) throw cachedModule.error;return cachedModule.exports; +if (cachedModule.error !== undefined) throw cachedModule.error; +return cachedModule.exports; } // Create a new module (and put it into the cache) var module = (__webpack_module_cache__[moduleId] = { @@ -241,6 +243,7 @@ exports: {} }); // Execute the module function try { + var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: __webpack_require__ }; __webpack_require__.i.forEach(function(handler) { handler(execOptions); }); module = execOptions.module; @@ -248,8 +251,12 @@ if (!execOptions.factory) { console.error("undefined factory", moduleId) } execOptions.factory.call(module.exports, module, module.exports, execOptions.require); -} catch (e) {module.error = e; -throw e;}// Return the exports of the module + +} catch (e) { +module.error = e; +throw e; +} +// Return the exports of the module return module.exports; } @@ -262,8 +269,10 @@ __webpack_require__.c = __webpack_module_cache__; // expose the module execution interceptor __webpack_require__.i = []; + +/************************************************************************/ // webpack/runtime/get mini-css chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.miniCssF = function (chunkId) { // return url for filenames not based on template @@ -272,28 +281,28 @@ __webpack_require__.i = []; return "" + chunkId + ".css"; }; -}(); +})(); // webpack/runtime/get_chunk_update_filename -!function() { +(() => { __webpack_require__.hu = function (chunkId) { return '' + chunkId + '.' + __webpack_require__.h() + '.hot-update.js'; }; -}(); +})(); // webpack/runtime/get_full_hash -!function() { +(() => { __webpack_require__.h = function () { return "xxxxxxxxxxxxxxxxxxxxxx" } -}(); +})(); // webpack/runtime/get_main_filename/update manifest -!function() { +(() => { __webpack_require__.hmrF = function () { return "main." + __webpack_require__.h() + ".hot-update.json"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -303,16 +312,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/hot_module_replacement -!function() { +(() => { var currentModuleData = {}; var installedModules = __webpack_require__.c; @@ -677,9 +686,9 @@ function applyInvalidatedModules() { } } -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -739,9 +748,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -750,9 +759,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -774,9 +783,9 @@ __webpack_require__.r = function(exports) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/css loading -!function() { +(() => { if (typeof document === "undefined") return; var createStylesheet = function ( chunkId, fullhref, oldTag, resolve, reject @@ -881,9 +890,9 @@ __webpack_require__.hmrC.miniCss = function (chunkIds, removedChunks, removedMod } -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -1387,9 +1396,11 @@ __webpack_require__.hmrM = function () { ); }; -}(); +})(); +/************************************************************************/ // module cache are used so entry inlining is disabled // startup // Load entry module and return exports var __webpack_exports__ = __webpack_require__("./index.css?6fbf"); })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/insert-function/expected/main.js b/plugin-test/css-extract/cases/insert-function/expected/main.js index 50b56531d56e..967f9868c6e1 100644 --- a/plugin-test/css-extract/cases/insert-function/expected/main.js +++ b/plugin-test/css-extract/cases/insert-function/expected/main.js @@ -1,11 +1,6 @@ -(function() { -var __webpack_modules__ = { -"./src/index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -/* eslint-env browser */ // eslint-disable-next-line -__webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__.bind(__webpack_require__, "./src/inject.css?901b")); -}), - -} +(() => { // webpackBootstrap +var __webpack_modules__ = ({}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -23,6 +18,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -30,8 +26,10 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/ensure_chunk -!function() { +(() => { __webpack_require__.f = {}; // This file contains only the entry chunk. // The chunk loading function for additional chunks @@ -44,9 +42,9 @@ __webpack_require__.e = function (chunkId) { ); }; -}(); +})(); // webpack/runtime/get javascript chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.u = function (chunkId) { // return url for filenames not based on template @@ -55,9 +53,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".js"; }; -}(); +})(); // webpack/runtime/get mini-css chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.miniCssF = function (chunkId) { // return url for filenames not based on template @@ -66,9 +64,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".css"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -78,16 +76,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -147,9 +145,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -158,9 +156,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -182,9 +180,9 @@ __webpack_require__.r = function(exports) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/css loading -!function() { +(() => { if (typeof document === "undefined") return; var createStylesheet = function ( chunkId, fullhref, oldTag, resolve, reject @@ -274,9 +272,9 @@ __webpack_require__.f.miniCss = function(chunkId, promises) { // no hmr -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -374,8 +372,11 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./src/index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +/* eslint-env browser */ // eslint-disable-next-line +__webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__.bind(__webpack_require__, "./src/inject.css?901b")); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/insert-function/expected/src_inject_css.js b/plugin-test/css-extract/cases/insert-function/expected/src_inject_css.js index c9b64e45746a..b7ba5501c0e0 100644 --- a/plugin-test/css-extract/cases/insert-function/expected/src_inject_css.js +++ b/plugin-test/css-extract/cases/insert-function/expected/src_inject_css.js @@ -1,6 +1,6 @@ +"use strict"; (self['webpackChunk'] = self['webpackChunk'] || []).push([["src_inject_css"], { "./src/inject.css?901b": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin diff --git a/plugin-test/css-extract/cases/insert-string/expected/main.js b/plugin-test/css-extract/cases/insert-string/expected/main.js index 14d77728cfc2..423c67e292ab 100644 --- a/plugin-test/css-extract/cases/insert-string/expected/main.js +++ b/plugin-test/css-extract/cases/insert-string/expected/main.js @@ -1,11 +1,6 @@ -(function() { -var __webpack_modules__ = { -"./src/index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -/* eslint-env browser */ // eslint-disable-next-line -__webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__.bind(__webpack_require__, "./src/inject.css?901b")); -}), - -} +(() => { // webpackBootstrap +var __webpack_modules__ = ({}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -23,6 +18,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -30,8 +26,10 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/ensure_chunk -!function() { +(() => { __webpack_require__.f = {}; // This file contains only the entry chunk. // The chunk loading function for additional chunks @@ -44,9 +42,9 @@ __webpack_require__.e = function (chunkId) { ); }; -}(); +})(); // webpack/runtime/get javascript chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.u = function (chunkId) { // return url for filenames not based on template @@ -55,9 +53,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".js"; }; -}(); +})(); // webpack/runtime/get mini-css chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.miniCssF = function (chunkId) { // return url for filenames not based on template @@ -66,9 +64,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".css"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -78,16 +76,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -147,9 +145,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -158,9 +156,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -182,9 +180,9 @@ __webpack_require__.r = function(exports) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/css loading -!function() { +(() => { if (typeof document === "undefined") return; var createStylesheet = function ( chunkId, fullhref, oldTag, resolve, reject @@ -270,9 +268,9 @@ __webpack_require__.f.miniCss = function(chunkId, promises) { // no hmr -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -370,8 +368,11 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./src/index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +/* eslint-env browser */ // eslint-disable-next-line +__webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__.bind(__webpack_require__, "./src/inject.css?901b")); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/insert-string/expected/src_inject_css.js b/plugin-test/css-extract/cases/insert-string/expected/src_inject_css.js index c9b64e45746a..b7ba5501c0e0 100644 --- a/plugin-test/css-extract/cases/insert-string/expected/src_inject_css.js +++ b/plugin-test/css-extract/cases/insert-string/expected/src_inject_css.js @@ -1,6 +1,6 @@ +"use strict"; (self['webpackChunk'] = self['webpackChunk'] || []).push([["src_inject_css"], { "./src/inject.css?901b": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin diff --git a/plugin-test/css-extract/cases/insert-undefined/expected/main.js b/plugin-test/css-extract/cases/insert-undefined/expected/main.js index 748a0d12e3de..335e7bb34b0a 100644 --- a/plugin-test/css-extract/cases/insert-undefined/expected/main.js +++ b/plugin-test/css-extract/cases/insert-undefined/expected/main.js @@ -1,11 +1,6 @@ -(function() { -var __webpack_modules__ = { -"./src/index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -/* eslint-env browser */ // eslint-disable-next-line -__webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__.bind(__webpack_require__, "./src/inject.css?901b")); -}), - -} +(() => { // webpackBootstrap +var __webpack_modules__ = ({}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -23,6 +18,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -30,8 +26,10 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/ensure_chunk -!function() { +(() => { __webpack_require__.f = {}; // This file contains only the entry chunk. // The chunk loading function for additional chunks @@ -44,9 +42,9 @@ __webpack_require__.e = function (chunkId) { ); }; -}(); +})(); // webpack/runtime/get javascript chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.u = function (chunkId) { // return url for filenames not based on template @@ -55,9 +53,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".js"; }; -}(); +})(); // webpack/runtime/get mini-css chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.miniCssF = function (chunkId) { // return url for filenames not based on template @@ -66,9 +64,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".css"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -78,16 +76,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -147,9 +145,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -158,9 +156,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -182,9 +180,9 @@ __webpack_require__.r = function(exports) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/css loading -!function() { +(() => { if (typeof document === "undefined") return; var createStylesheet = function ( chunkId, fullhref, oldTag, resolve, reject @@ -273,9 +271,9 @@ __webpack_require__.f.miniCss = function(chunkId, promises) { // no hmr -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -373,8 +371,11 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./src/index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +/* eslint-env browser */ // eslint-disable-next-line +__webpack_require__.e(/* import() */ "src_inject_css").then(__webpack_require__.bind(__webpack_require__, "./src/inject.css?901b")); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/insert-undefined/expected/src_inject_css.js b/plugin-test/css-extract/cases/insert-undefined/expected/src_inject_css.js index c9b64e45746a..b7ba5501c0e0 100644 --- a/plugin-test/css-extract/cases/insert-undefined/expected/src_inject_css.js +++ b/plugin-test/css-extract/cases/insert-undefined/expected/src_inject_css.js @@ -1,6 +1,6 @@ +"use strict"; (self['webpackChunk'] = self['webpackChunk'] || []).push([["src_inject_css"], { "./src/inject.css?901b": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin diff --git a/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js b/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js index fd17bcaa4b8e..d19136f3f0bf 100644 --- a/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js +++ b/plugin-test/css-extract/cases/multiple-compiler/expected/one-main.js @@ -1,19 +1,14 @@ -(function() { -var __webpack_modules__ = { -"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); - }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -31,12 +26,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -45,8 +43,16 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); + + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js b/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js index fd17bcaa4b8e..d19136f3f0bf 100644 --- a/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js +++ b/plugin-test/css-extract/cases/multiple-compiler/expected/two-main.js @@ -1,19 +1,14 @@ -(function() { -var __webpack_modules__ = { -"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); - }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -31,12 +26,15 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; } + +/************************************************************************/ // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -45,8 +43,16 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); + + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/new-url/expected/main.js b/plugin-test/css-extract/cases/new-url/expected/main.js index 1c66df2ab3cb..5f7f1d56ba56 100644 --- a/plugin-test/css-extract/cases/new-url/expected/main.js +++ b/plugin-test/css-extract/cases/new-url/expected/main.js @@ -1,17 +1,14 @@ -(function() { -var __webpack_modules__ = { +(() => { // webpackBootstrap +var __webpack_modules__ = ({ "./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin -}), -"./index.js": (function (__unused_webpack_module, __unused_webpack_exports, __webpack_require__) { -const myURL = new URL(/* asset import */__webpack_require__("./style.css?b16f"), __webpack_require__.b); -console.log(myURL); }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -29,6 +26,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -36,15 +34,17 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -53,9 +53,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { __webpack_require__.b = document.baseURI || self.location.href; // object to store loaded and loading chunks @@ -63,8 +63,15 @@ __webpack_require__.b = document.baseURI || self.location.href; // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded var installedChunks = {"main": 0,}; -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +const myURL = new URL(/* asset import */__webpack_require__("./style.css?b16f"), __webpack_require__.b); +console.log(myURL); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/no-runtime/expected/async.js b/plugin-test/css-extract/cases/no-runtime/expected/async.js index b638abf8a060..138fddadbb88 100644 --- a/plugin-test/css-extract/cases/no-runtime/expected/async.js +++ b/plugin-test/css-extract/cases/no-runtime/expected/async.js @@ -1,6 +1,6 @@ +"use strict"; (self['webpackChunk'] = self['webpackChunk'] || []).push([["async"], { "./async.css?833a": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin diff --git a/plugin-test/css-extract/cases/no-runtime/expected/main.js b/plugin-test/css-extract/cases/no-runtime/expected/main.js index d3607377bed3..d3abb46aba62 100644 --- a/plugin-test/css-extract/cases/no-runtime/expected/main.js +++ b/plugin-test/css-extract/cases/no-runtime/expected/main.js @@ -1,20 +1,14 @@ -(function() { -var __webpack_modules__ = { -"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +(() => { // webpackBootstrap "use strict"; +var __webpack_modules__ = ({ +"./style.css?b16f": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); // extracted by css-extract-rspack-plugin -}), -"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); - -__webpack_require__.e(/* import() | async */ "async").then(__webpack_require__.bind(__webpack_require__, "./async.css?833a")); }), -} +}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -32,6 +26,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -39,8 +34,10 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/ensure_chunk -!function() { +(() => { __webpack_require__.f = {}; // This file contains only the entry chunk. // The chunk loading function for additional chunks @@ -53,9 +50,9 @@ __webpack_require__.e = function (chunkId) { ); }; -}(); +})(); // webpack/runtime/get javascript chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.u = function (chunkId) { // return url for filenames not based on template @@ -64,9 +61,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".js"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -76,16 +73,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -145,9 +142,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -156,9 +153,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -180,9 +177,9 @@ __webpack_require__.r = function(exports) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -280,8 +277,17 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); -// startup -// Load entry module and return exports -var __webpack_exports__ = __webpack_require__("./index.js"); +})(); +/************************************************************************/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./style.css?b16f"); + +__webpack_require__.e(/* import() | async */ "async").then(__webpack_require__.bind(__webpack_require__, "./async.css?833a")); + +})(); + })() +; \ No newline at end of file diff --git a/plugin-test/css-extract/cases/runtime/expected/runtime~main.js b/plugin-test/css-extract/cases/runtime/expected/runtime~main.js index 4e4a2382285d..15f9d765020d 100644 --- a/plugin-test/css-extract/cases/runtime/expected/runtime~main.js +++ b/plugin-test/css-extract/cases/runtime/expected/runtime~main.js @@ -1,7 +1,7 @@ -(function() { -var __webpack_modules__ = { - -} +(() => { // webpackBootstrap +"use strict"; +var __webpack_modules__ = ({}); +/************************************************************************/ // The module cache var __webpack_module_cache__ = {}; @@ -19,6 +19,7 @@ exports: {} }); // Execute the module function __webpack_modules__[moduleId](module, module.exports, __webpack_require__); + // Return the exports of the module return module.exports; @@ -26,8 +27,10 @@ return module.exports; // expose the modules object (__webpack_modules__) __webpack_require__.m = __webpack_modules__; + +/************************************************************************/ // webpack/runtime/create_fake_namespace_object -!function() { +(() => { var getProto = Object.getPrototypeOf ? function(obj) { return Object.getPrototypeOf(obj); } : function(obj) { return obj.__proto__ }; var leafPrototypes; // create a fake namespace object @@ -54,9 +57,9 @@ __webpack_require__.t = function(value, mode) { __webpack_require__.d(ns, def); return ns; }; -}(); +})(); // webpack/runtime/define_property_getters -!function() { +(() => { __webpack_require__.d = function(exports, definition) { for(var key in definition) { if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { @@ -64,9 +67,9 @@ __webpack_require__.d = function(exports, definition) { } } }; -}(); +})(); // webpack/runtime/ensure_chunk -!function() { +(() => { __webpack_require__.f = {}; // This file contains only the entry chunk. // The chunk loading function for additional chunks @@ -79,9 +82,9 @@ __webpack_require__.e = function (chunkId) { ); }; -}(); +})(); // webpack/runtime/get javascript chunk filename -!function() { +(() => { // This function allow to reference chunks __webpack_require__.u = function (chunkId) { // return url for filenames not based on template @@ -90,9 +93,9 @@ __webpack_require__.e = function (chunkId) { return "" + chunkId + ".js"; }; -}(); +})(); // webpack/runtime/global -!function() { +(() => { __webpack_require__.g = (function () { if (typeof globalThis === 'object') return globalThis; try { @@ -102,16 +105,16 @@ __webpack_require__.g = (function () { } })(); -}(); +})(); // webpack/runtime/has_own_property -!function() { +(() => { __webpack_require__.o = function (obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }; -}(); +})(); // webpack/runtime/load_script -!function() { +(() => { var inProgress = {}; @@ -171,9 +174,9 @@ __webpack_require__.l = function (url, done, key, chunkId) { needAttach && document.head.appendChild(script); }; -}(); +})(); // webpack/runtime/make_namespace_object -!function() { +(() => { // define __esModule on exports __webpack_require__.r = function(exports) { if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { @@ -182,9 +185,9 @@ __webpack_require__.r = function(exports) { Object.defineProperty(exports, '__esModule', { value: true }); }; -}(); +})(); // webpack/runtime/on_chunk_loaded -!function() { +(() => { var deferred = []; __webpack_require__.O = function (result, chunkIds, fn, priority) { if (chunkIds) { @@ -222,9 +225,9 @@ __webpack_require__.O = function (result, chunkIds, fn, priority) { return result; }; -}(); +})(); // webpack/runtime/auto_public_path -!function() { +(() => { var scriptUrl; if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; @@ -246,9 +249,9 @@ __webpack_require__.O = function (result, chunkIds, fn, priority) { scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); __webpack_require__.p = scriptUrl -}(); +})(); // webpack/runtime/jsonp_chunk_loading -!function() { +(() => { // object to store loaded and loading chunks // undefined = chunk not loaded, null = chunk preloaded/prefetched @@ -350,6 +353,7 @@ chunkLoadingGlobal.push = webpackJsonpCallback.bind( chunkLoadingGlobal.push.bind(chunkLoadingGlobal) ); -}(); - +})(); +/************************************************************************/ })() +; \ No newline at end of file diff --git a/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap b/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap index 04f3d7f31d33..0d9cc4488ea8 100644 --- a/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap +++ b/webpack-test/__snapshots__/StatsTestCases.basictest.js.snap @@ -7,16 +7,16 @@ Entrypoint main 294 KiB = warning.pro-web.js ./index.js WARNING in ⚠ asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ warning.pro-web.js (293.719 KiB) + │ warning.pro-web.js (293.959 KiB) WARNING in ⚠ entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (293.719 KiB) + │ main (293.959 KiB) │ warning.pro-web.js WARNING in ⚠ Rspack performance recommendations:You can limit the size of your bundles by using import() to lazy load some parts of your application. │ For more info visit https://www.rspack.dev/guide/optimization/code-splitting -Rspack x.x.x compiled with 3 warnings in X s (fdcda4a05775a95633ca) +Rspack x.x.x compiled with 3 warnings in X s (b953c5393c20babd176f) PublicPath: auto asset warning.pro-webworker.js 294 KiB [emitted] (name: main) @@ -24,40 +24,40 @@ Entrypoint main 294 KiB = warning.pro-webworker.js ./index.js WARNING in ⚠ asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ warning.pro-webworker.js (293.719 KiB) + │ warning.pro-webworker.js (293.959 KiB) WARNING in ⚠ entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (293.719 KiB) + │ main (293.959 KiB) │ warning.pro-webworker.js WARNING in ⚠ Rspack performance recommendations:You can limit the size of your bundles by using import() to lazy load some parts of your application. │ For more info visit https://www.rspack.dev/guide/optimization/code-splitting -Rspack x.x.x compiled with 3 warnings in X s (fdcda4a05775a95633ca) +Rspack x.x.x compiled with 3 warnings in X s (b953c5393c20babd176f) PublicPath: (none) asset no-warning.pro-node.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.pro-node.js ./index.js -Rspack x.x.x compiled successfully in X s (fdcda4a05775a95633ca) +Rspack x.x.x compiled successfully in X s (b953c5393c20babd176f) PublicPath: auto asset no-warning.dev-web.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.dev-web.js ./index.js -Rspack x.x.x compiled successfully in X s (451db70fa838cd6e895d) +Rspack x.x.x compiled successfully in X s (508f35f2580171cda521) PublicPath: (none) asset no-warning.dev-node.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.dev-node.js ./index.js -Rspack x.x.x compiled successfully in X s (451db70fa838cd6e895d) +Rspack x.x.x compiled successfully in X s (508f35f2580171cda521) PublicPath: auto asset no-warning.dev-web-with-limit-set.js 294 KiB [emitted] (name: main) Entrypoint main 294 KiB = no-warning.dev-web-with-limit-set.js ./index.js -Rspack x.x.x compiled successfully in X s (451db70fa838cd6e895d) +Rspack x.x.x compiled successfully in X s (508f35f2580171cda521) PublicPath: (none) asset warning.pro-node-with-hints-set.js 294 KiB [emitted] (name: main) @@ -65,24 +65,24 @@ Entrypoint main 294 KiB = warning.pro-node-with-hints-set.js ./index.js WARNING in ⚠ asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance.Assets: - │ warning.pro-node-with-hints-set.js (293.719 KiB) + │ warning.pro-node-with-hints-set.js (293.959 KiB) WARNING in ⚠ entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance.Entrypoints: - │ main (293.719 KiB) + │ main (293.959 KiB) │ warning.pro-node-with-hints-set.js WARNING in ⚠ Rspack performance recommendations:You can limit the size of your bundles by using import() to lazy load some parts of your application. │ For more info visit https://www.rspack.dev/guide/optimization/code-splitting -Rspack x.x.x compiled with 3 warnings in X s (fdcda4a05775a95633ca)" +Rspack x.x.x compiled with 3 warnings in X s (b953c5393c20babd176f)" `; exports[`StatsTestCases should print correct stats for performance-no-async-chunks-shown 1`] = ` "PublicPath: auto asset main.js 294 KiB [emitted] (name: main) -asset sec.js 1.03 KiB [emitted] (name: sec) +asset sec.js 1.16 KiB [emitted] (name: sec) Entrypoint main 294 KiB = main.js -Entrypoint sec 1.03 KiB = sec.js +Entrypoint sec 1.16 KiB = sec.js ./a.js ./b.js ./c.js @@ -92,12 +92,12 @@ Entrypoint sec 1.03 KiB = sec.js WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance. Assets: - main.js (293.920 KiB) + main.js (294.047 KiB) WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance. Entrypoints: - main (293.920 KiB) + main (294.047 KiB) main.js @@ -121,15 +121,15 @@ Entrypoint sec 294 KiB = sec.js ERROR in × asset size limit: The following asset(s) exceed the recommended size limit (244.141 KiB). This can impact web performance. Assets: - main.js (293.840 KiB) - sec.js (293.840 KiB) + main.js (293.967 KiB) + sec.js (293.967 KiB) ERROR in × entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244.141 KiB). This can impact web performance. Entrypoints: - main (293.840 KiB) + main (293.967 KiB) main.js - sec (293.840 KiB) + sec (293.967 KiB) sec.js diff --git a/webpack-test/configCases/library/0-create-library/test.filter.js b/webpack-test/configCases/library/0-create-library/test.filter.js deleted file mode 100644 index 3be456dcd23c..000000000000 --- a/webpack-test/configCases/library/0-create-library/test.filter.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => {return false} \ No newline at end of file diff --git a/webpack-test/configCases/library/1-use-library/node_modules/external.js b/webpack-test/configCases/library/1-use-library/node_modules/external.js new file mode 100644 index 000000000000..d95f84a9c8b2 --- /dev/null +++ b/webpack-test/configCases/library/1-use-library/node_modules/external.js @@ -0,0 +1 @@ +module.exports = ["external"]; diff --git a/webpack-test/configCases/library/1-use-library/test.filter.js b/webpack-test/configCases/library/1-use-library/test.filter.js index 3be456dcd23c..c3e6b9b2e57e 100644 --- a/webpack-test/configCases/library/1-use-library/test.filter.js +++ b/webpack-test/configCases/library/1-use-library/test.filter.js @@ -1 +1 @@ -module.exports = () => {return false} \ No newline at end of file +module.exports = () => {return "__nested_webpack_exports__"}