diff --git a/.github/workflows/test-ubuntu.yml b/.github/workflows/test-ubuntu.yml index 45d7c994bf..10020fc248 100644 --- a/.github/workflows/test-ubuntu.yml +++ b/.github/workflows/test-ubuntu.yml @@ -42,6 +42,8 @@ jobs: changed: - "!**/*.md" - "!**/*.mdx" + - "!**/_meta.json" + - "!**/dictionary.txt" - name: Setup Node.js ${{ matrix.node-version }} if: steps.changes.outputs.changed == 'true' @@ -83,6 +85,8 @@ jobs: changed: - "!**/*.md" - "!**/*.mdx" + - "!**/_meta.json" + - "!**/dictionary.txt" - name: Setup Node.js ${{ matrix.node-version }} if: steps.changes.outputs.changed == 'true' diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 68f461ba03..f700387eaa 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -46,6 +46,8 @@ jobs: changed: - "!**/*.md" - "!**/*.mdx" + - "!**/_meta.json" + - "!**/dictionary.txt" - name: Setup Node.js ${{ matrix.node-version }} if: steps.changes.outputs.changed == 'true' @@ -92,6 +94,8 @@ jobs: changed: - "!**/*.md" - "!**/*.mdx" + - "!**/_meta.json" + - "!**/dictionary.txt" - name: Setup Node.js ${{ matrix.node-version }} if: steps.changes.outputs.changed == 'true' diff --git a/.vscode/settings.json b/.vscode/settings.json index 202d372f3f..6353cbfc27 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "search.exclude": { "**/.git": true, "**/dist": true, + "**/dist-types": true, "**/coverage": true, "**/compiled": true, "**/doc_build": true, diff --git a/README.md b/README.md index 0dc36cd223..eb8260a1fd 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ To get started with Rsbuild, see the [Quick Start](https://rsbuild.dev/guide/sta - [Modern.js](https://github.com/web-infra-dev/modern.js): A progressive React framework based on Rsbuild. - [awesome-rspack](https://github.com/web-infra-dev/awesome-rspack): A curated list of awesome things related to Rspack and Rsbuild. - [rspack-examples](https://github.com/rspack-contrib/rspack-examples): Examples for Rspack, Rsbuild, Rspress and Rsdoctor. +- [storybook-rsbuild](https://github.com/rspack-contrib/storybook-rsbuild): Storybook builder powered by Rsbuild. - [rsbuild-plugin-template](https://github.com/rspack-contrib/rsbuild-plugin-template):Use this template to create your own Rsbuild plugin. - [rsfamily-design-resources](https://github.com/rspack-contrib/rsfamily-design-resources):Design resources for Rspack, Rsbuild, Rspress and Rsdoctor. diff --git a/README.zh-CN.md b/README.zh-CN.md index 776b2309c5..5af695d6dc 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -94,6 +94,7 @@ Rsbuild 具备以下特性: - [Modern.js](https://github.com/web-infra-dev/modern.js):基于 Rsbuild 的渐进式 React 框架。 - [awesome-rspack](https://github.com/web-infra-dev/awesome-rspack):与 Rspack 和 Rsbuild 相关的精彩内容列表。 - [rspack-examples](https://github.com/rspack-contrib/rspack-examples):Rspack、Rsbuild、Rspress 和 Rsdoctor 的示例项目。 +- [storybook-rsbuild](https://github.com/rspack-contrib/storybook-rsbuild): 基于 Rsbuild 构建的 Storybook。 - [rsbuild-plugin-template](https://github.com/rspack-contrib/rsbuild-plugin-template):使用此模板创建你的 Rsbuild 插件。 - [rsfamily-design-resources](https://github.com/rspack-contrib/rsfamily-design-resources):Rspack、Rsbuild、Rspress 和 Rsdoctor 的设计资源。 diff --git a/e2e/cases/babel/preset-node/index.test.ts b/e2e/cases/babel/preset-node/index.test.ts new file mode 100644 index 0000000000..e5d2110536 --- /dev/null +++ b/e2e/cases/babel/preset-node/index.test.ts @@ -0,0 +1,15 @@ +import { build, rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; + +rspackOnlyTest( + 'should run babel with @rsbuild/babel-preset/node correctly', + async () => { + await build({ + cwd: __dirname, + runServer: true, + }); + + const { foo } = await import('./dist/server/index.js'); + expect(foo).toEqual(1); + }, +); diff --git a/e2e/cases/babel/preset/rsbuild.config.ts b/e2e/cases/babel/preset-node/rsbuild.config.ts similarity index 86% rename from e2e/cases/babel/preset/rsbuild.config.ts rename to e2e/cases/babel/preset-node/rsbuild.config.ts index 3c5542f020..7d63825ba8 100644 --- a/e2e/cases/babel/preset/rsbuild.config.ts +++ b/e2e/cases/babel/preset-node/rsbuild.config.ts @@ -1,6 +1,9 @@ import { pluginBabel } from '@rsbuild/plugin-babel'; export default { + output: { + targets: ['node'], + }, plugins: [ pluginBabel({ babelLoaderOptions: (_, { addPresets }) => { diff --git a/e2e/cases/babel/preset-node/src/index.js b/e2e/cases/babel/preset-node/src/index.js new file mode 100644 index 0000000000..afecb427b8 --- /dev/null +++ b/e2e/cases/babel/preset-node/src/index.js @@ -0,0 +1,3 @@ +console.log('hello'); + +export const foo = 1; diff --git a/e2e/cases/babel/preset/index.test.ts b/e2e/cases/babel/preset-web/index.test.ts similarity index 85% rename from e2e/cases/babel/preset/index.test.ts rename to e2e/cases/babel/preset-web/index.test.ts index 8d1edb7ad1..296e6f2c72 100644 --- a/e2e/cases/babel/preset/index.test.ts +++ b/e2e/cases/babel/preset-web/index.test.ts @@ -2,7 +2,7 @@ import { build, gotoPage, rspackOnlyTest } from '@e2e/helper'; import { expect } from '@playwright/test'; rspackOnlyTest( - 'should run babel with @rsbuild/babel-preset correctly', + 'should run babel with @rsbuild/babel-preset/web correctly', async ({ page }) => { const rsbuild = await build({ cwd: __dirname, diff --git a/e2e/cases/babel/preset-web/rsbuild.config.ts b/e2e/cases/babel/preset-web/rsbuild.config.ts new file mode 100644 index 0000000000..1222431410 --- /dev/null +++ b/e2e/cases/babel/preset-web/rsbuild.config.ts @@ -0,0 +1,11 @@ +import { pluginBabel } from '@rsbuild/plugin-babel'; + +export default { + plugins: [ + pluginBabel({ + babelLoaderOptions: (_, { addPresets }) => { + addPresets([require.resolve('@rsbuild/babel-preset/node')]); + }, + }), + ], +}; diff --git a/e2e/cases/babel/preset/src/index.js b/e2e/cases/babel/preset-web/src/index.js similarity index 100% rename from e2e/cases/babel/preset/src/index.js rename to e2e/cases/babel/preset-web/src/index.js diff --git a/e2e/cases/css/css-assets/index.test.ts b/e2e/cases/css/css-assets/index.test.ts new file mode 100644 index 0000000000..5b798c4982 --- /dev/null +++ b/e2e/cases/css/css-assets/index.test.ts @@ -0,0 +1,22 @@ +import path from 'node:path'; +import { build } from '@e2e/helper'; +import { globContentJSON } from '@e2e/helper'; +import { expect, test } from '@playwright/test'; + +test('should build CSS assets correctly', async () => { + await expect( + build({ + cwd: __dirname, + rsbuildConfig: {}, + }), + ).resolves.toBeDefined(); + + const outputs = await globContentJSON(path.join(__dirname, 'dist')); + const outputFiles = Object.keys(outputs); + + expect( + outputFiles.find( + (item) => item.includes('static/image/image') && item.endsWith('.jpeg'), + ), + ).toBeTruthy(); +}); diff --git a/e2e/cases/css/css-assets/rsbuild.config.ts b/e2e/cases/css/css-assets/rsbuild.config.ts new file mode 100644 index 0000000000..1d63b545ed --- /dev/null +++ b/e2e/cases/css/css-assets/rsbuild.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from '@rsbuild/core'; +import { pluginReact } from '@rsbuild/plugin-react'; + +export default defineConfig({ + plugins: [pluginReact()], + output: {} +}); diff --git a/e2e/cases/css/css-assets/src/index.tsx b/e2e/cases/css/css-assets/src/index.tsx new file mode 100644 index 0000000000..2fe6322232 --- /dev/null +++ b/e2e/cases/css/css-assets/src/index.tsx @@ -0,0 +1,7 @@ +function load(key: string) { + import(`./test/${key}`).then(res => { + console.log('res', res); + }) +} + +load('a'); diff --git a/e2e/cases/css/css-assets/src/test/a.ts b/e2e/cases/css/css-assets/src/test/a.ts new file mode 100644 index 0000000000..3a90f13425 --- /dev/null +++ b/e2e/cases/css/css-assets/src/test/a.ts @@ -0,0 +1,5 @@ +import styles from './index.module.less'; + +console.log('s', styles); + +export const a = 1; diff --git a/e2e/cases/css/css-assets/src/test/index.module.less b/e2e/cases/css/css-assets/src/test/index.module.less new file mode 100644 index 0000000000..b309110b39 --- /dev/null +++ b/e2e/cases/css/css-assets/src/test/index.module.less @@ -0,0 +1,3 @@ +.header { + background: url('@assets/image.jpeg') no-repeat; +} diff --git a/e2e/cases/css/css-modules-dom/index.test.ts b/e2e/cases/css/css-modules-dom/index.test.ts index efac8feb42..f6c939918a 100644 --- a/e2e/cases/css/css-modules-dom/index.test.ts +++ b/e2e/cases/css/css-modules-dom/index.test.ts @@ -2,22 +2,18 @@ import { join, resolve } from 'node:path'; import { build, gotoPage } from '@e2e/helper'; import { expect, test } from '@playwright/test'; import { pluginReact } from '@rsbuild/plugin-react'; +import { pluginTypedCSSModules } from '@rsbuild/plugin-typed-css-modules'; import { fse } from '@rsbuild/shared'; const fixtures = resolve(__dirname); -test('enableCssModuleTSDeclaration', async () => { +test('plugin-typed-css-modules', async () => { fse.removeSync(join(fixtures, 'src/App.module.less.d.ts')); fse.removeSync(join(fixtures, 'src/App.module.scss.d.ts')); await build({ cwd: fixtures, - plugins: [pluginReact()], - rsbuildConfig: { - output: { - enableCssModuleTSDeclaration: true, - }, - }, + plugins: [pluginReact(), pluginTypedCSSModules()], }); expect( diff --git a/e2e/cases/css/css-modules-named-export/index.test.ts b/e2e/cases/css/css-modules-named-export/index.test.ts index e68cdf2549..9e9927e75a 100644 --- a/e2e/cases/css/css-modules-named-export/index.test.ts +++ b/e2e/cases/css/css-modules-named-export/index.test.ts @@ -7,6 +7,16 @@ rspackOnlyTest( const rsbuild = await build({ cwd: __dirname, runServer: true, + rsbuildConfig: { + tools: { + cssLoader: { + modules: { + // TODO: css-loader need support named export when namedExports: false. + namedExport: true + } + } + } + } }); const files = await rsbuild.unwrapOutputJSON(); diff --git a/e2e/cases/css/css-modules-ts-declaration/index.test.ts b/e2e/cases/css/css-modules-ts-declaration/index.test.ts index ed4dbfb249..0831af3c06 100644 --- a/e2e/cases/css/css-modules-ts-declaration/index.test.ts +++ b/e2e/cases/css/css-modules-ts-declaration/index.test.ts @@ -1,6 +1,7 @@ import { join, resolve } from 'node:path'; import { build } from '@e2e/helper'; import { expect, test } from '@playwright/test'; +import { pluginTypedCSSModules } from '@rsbuild/plugin-typed-css-modules'; import { fse } from '@rsbuild/shared'; const fixtures = __dirname; @@ -18,13 +19,11 @@ test('should generator ts declaration correctly for css modules auto true', asyn await build({ cwd: __dirname, + plugins: [pluginTypedCSSModules()], rsbuildConfig: { source: { entry: { index: resolve(testDir, 'index.js') }, }, - output: { - enableCssModuleTSDeclaration: true, - }, }, }); @@ -51,12 +50,12 @@ test('should generator ts declaration correctly for css modules auto function', await build({ cwd: __dirname, + plugins: [pluginTypedCSSModules()], rsbuildConfig: { source: { entry: { index: resolve(testDir, 'index.js') }, }, output: { - enableCssModuleTSDeclaration: true, cssModules: { auto: (path) => { return path.endsWith('.less'); @@ -80,12 +79,12 @@ test('should generator ts declaration correctly for css modules auto Regexp', as await build({ cwd: __dirname, + plugins: [pluginTypedCSSModules()], rsbuildConfig: { source: { entry: { index: resolve(testDir, 'index.js') }, }, output: { - enableCssModuleTSDeclaration: true, cssModules: { auto: /\.module\./i, }, @@ -107,12 +106,12 @@ test('should generator ts declaration correctly for custom exportLocalsConventio await build({ cwd: __dirname, + plugins: [pluginTypedCSSModules()], rsbuildConfig: { source: { entry: { index: resolve(testDir, 'index.js') }, }, output: { - enableCssModuleTSDeclaration: true, cssModules: { auto: /\.module\./i, exportLocalsConvention: 'asIs', diff --git a/e2e/cases/css/css-modules/index.test.ts b/e2e/cases/css/css-modules/index.test.ts index 364cc6f123..4c09ce7fdd 100644 --- a/e2e/cases/css/css-modules/index.test.ts +++ b/e2e/cases/css/css-modules/index.test.ts @@ -37,3 +37,45 @@ test('should compile CSS Modules follow by output.cssModules', async () => { /.the-a-class{color:red}.the-b-class-\w{6}{color:blue}.the-c-class{color:yellow}.the-d-class{color:green}/, ); }); + +test('should compile CSS Modules follow by output.cssModules custom localIdentName', async () => { + const rsbuild = await build({ + cwd: __dirname, + rsbuildConfig: { + output: { + cssModules: { + localIdentName: '[hash:base64:8]', + }, + }, + }, + }); + const files = await rsbuild.unwrapOutputJSON(); + + const content = + files[Object.keys(files).find((file) => file.endsWith('.css'))!]; + + expect(content).toMatch( + /\.the-a-class{color:red}\.\w{8}{color:blue}\.\w{8}{color:yellow}\.the-d-class{color:green}/, + ); +}); + +test('should compile CSS Modules follow by output.cssModules custom localIdentName - hashDigest', async () => { + const rsbuild = await build({ + cwd: __dirname, + rsbuildConfig: { + output: { + cssModules: { + localIdentName: '[hash:hex:4]', + }, + }, + }, + }); + const files = await rsbuild.unwrapOutputJSON(); + + const content = + files[Object.keys(files).find((file) => file.endsWith('.css'))!]; + + expect(content).toMatch( + /\.the-a-class{color:red}\.\w{4}{color:blue}\.\w{4}{color:yellow}\.the-d-class{color:green}/, + ); +}); diff --git a/e2e/cases/css/import-loaders/index.test.ts b/e2e/cases/css/import-loaders/index.test.ts index 77f90330aa..c4ff6870b2 100644 --- a/e2e/cases/css/import-loaders/index.test.ts +++ b/e2e/cases/css/import-loaders/index.test.ts @@ -1,20 +1,16 @@ import { build } from '@e2e/helper'; -import { webpackOnlyTest } from '@e2e/helper'; -import { expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; -webpackOnlyTest( - 'should compile CSS Modules which depends on importLoaders correctly', - async () => { - const rsbuild = await build({ - cwd: __dirname, - }); - const files = await rsbuild.unwrapOutputJSON(); +test('should compile CSS Modules which depends on importLoaders correctly', async () => { + const rsbuild = await build({ + cwd: __dirname, + }); + const files = await rsbuild.unwrapOutputJSON(); - const content = - files[Object.keys(files).find((file) => file.endsWith('.css'))!]; + const content = + files[Object.keys(files).find((file) => file.endsWith('.css'))!]; - expect(content).toEqual( - '.class-foo-yQ8Tl7+.hello-class-foo{background-color:red}.class-bar-TVH2T6 .hello-class-bar{background-color:blue}', - ); - }, -); + expect(content).toEqual( + '.class-foo-yQ8Tl7+.hello-class-foo{background-color:red}.class-bar-TVH2T6 .hello-class-bar{background-color:blue}', + ); +}); diff --git a/e2e/cases/css/postcss-config-ts/index.test.ts b/e2e/cases/css/postcss-config-ts/index.test.ts new file mode 100644 index 0000000000..b245f4de4a --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/index.test.ts @@ -0,0 +1,17 @@ +import { build } from '@e2e/helper'; +import { expect, test } from '@playwright/test'; + +test('should load postcss.config.ts correctly', async () => { + const rsbuild = await build({ + cwd: __dirname, + }); + + const files = await rsbuild.unwrapOutputJSON(); + const indexCssFile = Object.keys(files).find( + (file) => file.includes('index.') && file.endsWith('.css'), + )!; + + expect(files[indexCssFile]).toEqual( + '.text-3xl{font-size:1.875rem;line-height:2.25rem}.font-bold{font-weight:700}.underline{text-decoration-line:underline}', + ); +}); diff --git a/e2e/cases/css/postcss-config-ts/postcss.config.ts b/e2e/cases/css/postcss-config-ts/postcss.config.ts new file mode 100644 index 0000000000..ee31a19cee --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/postcss.config.ts @@ -0,0 +1,9 @@ +const path = require('node:path'); + +export default { + plugins: { + tailwindcss: { + config: path.join(__dirname, './tailwind.config.cjs'), + }, + }, +}; diff --git a/e2e/cases/css/postcss-config-ts/rsbuild.config.ts b/e2e/cases/css/postcss-config-ts/rsbuild.config.ts new file mode 100644 index 0000000000..7ab8cb40dc --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/rsbuild.config.ts @@ -0,0 +1,5 @@ +export default { + html: { + template: './src/index.html', + }, +}; diff --git a/e2e/cases/css/postcss-config-ts/src/index.css b/e2e/cases/css/postcss-config-ts/src/index.css new file mode 100644 index 0000000000..65dd5f63a7 --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/src/index.css @@ -0,0 +1 @@ +@tailwind utilities; diff --git a/e2e/cases/css/postcss-config-ts/src/index.html b/e2e/cases/css/postcss-config-ts/src/index.html new file mode 100644 index 0000000000..3dbf610b4a --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/src/index.html @@ -0,0 +1,7 @@ + + + + +

Hello world!

+ + diff --git a/e2e/cases/css/postcss-config-ts/src/index.ts b/e2e/cases/css/postcss-config-ts/src/index.ts new file mode 100644 index 0000000000..6a9a4b1328 --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/src/index.ts @@ -0,0 +1 @@ +import './index.css'; diff --git a/e2e/cases/css/postcss-config-ts/tailwind.config.cjs b/e2e/cases/css/postcss-config-ts/tailwind.config.cjs new file mode 100644 index 0000000000..e03a0c3e05 --- /dev/null +++ b/e2e/cases/css/postcss-config-ts/tailwind.config.cjs @@ -0,0 +1,10 @@ +const path = require('node:path'); + +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: [path.join(__dirname, './src/**/*.{html,js,ts,jsx,tsx}')], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/e2e/cases/mjs-artifact/test.mjs b/e2e/cases/mjs-artifact/test.mjs index 526b1162d8..e53b7d015b 100644 --- a/e2e/cases/mjs-artifact/test.mjs +++ b/e2e/cases/mjs-artifact/test.mjs @@ -1,3 +1,5 @@ +import { getBabelConfigForNode } from '@rsbuild/babel-preset/node'; +import { getBabelConfigForWeb } from '@rsbuild/babel-preset/web'; import { pluginAssetsRetry } from '@rsbuild/plugin-assets-retry'; import { pluginBabel } from '@rsbuild/plugin-babel'; import { pluginCheckSyntax } from '@rsbuild/plugin-check-syntax'; @@ -17,6 +19,7 @@ import { pluginStyledComponents } from '@rsbuild/plugin-styled-components'; import { pluginStylus } from '@rsbuild/plugin-stylus'; import { pluginSvelte } from '@rsbuild/plugin-svelte'; import { pluginSvgr } from '@rsbuild/plugin-svgr'; +import { pluginSwc } from '@rsbuild/plugin-swc'; import { pluginToml } from '@rsbuild/plugin-toml'; import { pluginTypeCheck } from '@rsbuild/plugin-type-check'; import { pluginUmd } from '@rsbuild/plugin-umd'; @@ -25,8 +28,11 @@ import { pluginVueJsx } from '@rsbuild/plugin-vue-jsx'; import { pluginVue2 } from '@rsbuild/plugin-vue2'; import { pluginVue2Jsx } from '@rsbuild/plugin-vue2-jsx'; import { pluginYaml } from '@rsbuild/plugin-yaml'; +import * as shared from '@rsbuild/shared'; +import { webpackProvider } from '@rsbuild/webpack'; export default { + shared, pluginAssetsRetry, pluginBabel, pluginCheckSyntax, @@ -54,4 +60,8 @@ export default { pluginToml, pluginYaml, pluginMdx, + pluginSwc, + getBabelConfigForWeb, + getBabelConfigForNode, + webpackProvider, }; diff --git a/e2e/cases/output/manifest-async-chunks/index.test.ts b/e2e/cases/output/manifest-async-chunks/index.test.ts new file mode 100644 index 0000000000..edbc7098ef --- /dev/null +++ b/e2e/cases/output/manifest-async-chunks/index.test.ts @@ -0,0 +1,44 @@ +import { build } from '@e2e/helper'; +import { expect, test } from '@playwright/test'; + +const fixtures = __dirname; + +test('should generate manifest for async chunks correctly', async () => { + const rsbuild = await build({ + cwd: fixtures, + rsbuildConfig: { + output: { + manifest: true, + legalComments: 'none', + filenameHash: false, + }, + performance: { + chunkSplit: { + strategy: 'all-in-one', + }, + }, + }, + }); + + const files = await rsbuild.unwrapOutputJSON(); + + const manifestContent = + files[Object.keys(files).find((file) => file.endsWith('manifest.json'))!]; + + expect(manifestContent).toBeDefined(); + + const manifest = JSON.parse(manifestContent); + + expect(Object.keys(manifest.allFiles).length).toBe(4); + + expect(manifest.entries.index).toMatchObject({ + html: ['/index.html'], + initial: { + js: ['/static/js/index.js'], + }, + async: { + js: ['/static/js/async/async-chunk.js'], + css: ['/static/css/async/async-chunk.css'], + }, + }); +}); diff --git a/e2e/cases/output/manifest-async-chunks/src/async.ts b/e2e/cases/output/manifest-async-chunks/src/async.ts new file mode 100644 index 0000000000..c354cf83bf --- /dev/null +++ b/e2e/cases/output/manifest-async-chunks/src/async.ts @@ -0,0 +1,3 @@ +import './style.css'; + +console.log('hello!'); diff --git a/e2e/cases/output/manifest-async-chunks/src/index.ts b/e2e/cases/output/manifest-async-chunks/src/index.ts new file mode 100644 index 0000000000..b1d2a94bc4 --- /dev/null +++ b/e2e/cases/output/manifest-async-chunks/src/index.ts @@ -0,0 +1 @@ +import(/* webpackChunkName: "async-chunk" */ './async'); diff --git a/e2e/cases/output/manifest-async-chunks/src/style.css b/e2e/cases/output/manifest-async-chunks/src/style.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/e2e/cases/performance/print-file-size/rsbuild.config.ts b/e2e/cases/performance/print-file-size/rsbuild.config.ts new file mode 100644 index 0000000000..d8df500358 --- /dev/null +++ b/e2e/cases/performance/print-file-size/rsbuild.config.ts @@ -0,0 +1,5 @@ +import { pluginReact } from '@rsbuild/plugin-react'; + +export default { + plugins: [pluginReact()], +}; diff --git a/e2e/cases/plugin-api/plugin-after-build-hook/index.test.ts b/e2e/cases/plugin-api/plugin-after-build-hook/index.test.ts index ce0281c09a..b739dde4b9 100644 --- a/e2e/cases/plugin-api/plugin-after-build-hook/index.test.ts +++ b/e2e/cases/plugin-api/plugin-after-build-hook/index.test.ts @@ -1,5 +1,6 @@ import path from 'node:path'; -import { expect, test } from '@playwright/test'; +import { rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; import { type RsbuildPlugin, createRsbuild } from '@rsbuild/core'; import { fse } from '@rsbuild/shared'; @@ -29,21 +30,24 @@ const plugin: RsbuildPlugin = { }, }; -test('should run onAfterBuild hooks correctly when have multiple targets', async () => { - fse.removeSync(distFile); +rspackOnlyTest( + 'should run onAfterBuild hooks correctly when have multiple targets', + async () => { + fse.removeSync(distFile); - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [plugin], - output: { - targets: ['web', 'node'], + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [plugin], + output: { + targets: ['web', 'node'], + }, }, - }, - }); + }); - await rsbuild.build(); - write('2'); + await rsbuild.build(); + write('2'); - expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual(['1', '2']); -}); + expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual(['1', '2']); + }, +); diff --git a/e2e/cases/plugin-api/plugin-expose/index.test.ts b/e2e/cases/plugin-api/plugin-expose/index.test.ts index 324bcb81fc..84883aaa47 100644 --- a/e2e/cases/plugin-api/plugin-expose/index.test.ts +++ b/e2e/cases/plugin-api/plugin-expose/index.test.ts @@ -1,4 +1,5 @@ -import { expect, test } from '@playwright/test'; +import { rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; import { type RsbuildPlugin, createRsbuild } from '@rsbuild/core'; type ParentAPI = { @@ -6,7 +7,7 @@ type ParentAPI = { double: (val: number) => number; }; -test('should allow plugin to expose and consume API', async () => { +rspackOnlyTest('should allow plugin to expose and consume API', async () => { const parentSymbol = Symbol('parent-api'); const pluginParent: RsbuildPlugin = { diff --git a/e2e/cases/plugin-api/plugin-hooks/index.test.ts b/e2e/cases/plugin-api/plugin-hooks/index.test.ts index f0dc3c6a7a..118cf70824 100644 --- a/e2e/cases/plugin-api/plugin-hooks/index.test.ts +++ b/e2e/cases/plugin-api/plugin-hooks/index.test.ts @@ -1,6 +1,6 @@ import path from 'node:path'; -import { gotoPage } from '@e2e/helper'; -import { expect, test } from '@playwright/test'; +import { gotoPage, rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; import { type RsbuildPlugin, createRsbuild } from '@rsbuild/core'; import { fse, setNodeEnv } from '@rsbuild/shared'; @@ -40,81 +40,88 @@ const plugin: RsbuildPlugin = { }, }; -test('should run plugin hooks correctly when running build', async () => { - fse.removeSync(distFile); - - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [plugin], - }, - }); - - await rsbuild.build(); - - expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([ - 'ModifyRsbuildConfig', - 'ModifyBundlerChain', - 'ModifyBundlerConfig', - 'BeforeCreateCompiler', - 'AfterCreateCompiler', - 'BeforeBuild', - 'ModifyHTMLTags', - 'AfterBuild', - ]); -}); - -test('should run plugin hooks correctly when running startDevServer', async ({ - page, -}) => { - setNodeEnv('development'); - fse.removeSync(distFile); - - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [plugin], - }, - }); - - const result = await rsbuild.startDevServer(); - - await gotoPage(page, result); - - await result.server.close(); - - expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([ - 'ModifyRsbuildConfig', - 'BeforeStartDevServer', - 'ModifyBundlerChain', - 'ModifyBundlerConfig', - 'BeforeCreateCompiler', - 'AfterCreateCompiler', - 'AfterStartDevServer', - 'ModifyHTMLTags', - 'OnDevCompileDone', - 'OnCloseDevServer', - ]); - - setNodeEnv('test'); -}); - -test('should run plugin hooks correctly when running preview', async () => { - const rsbuild = await createRsbuild({ - cwd: __dirname, - rsbuildConfig: { - plugins: [plugin], - }, - }); - - fse.removeSync(distFile); - const result = await rsbuild.preview(); - - expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([ - 'ModifyRsbuildConfig', - 'BeforeStartProdServer', - 'AfterStartProdServer', - ]); - - await result.server.close(); -}); +rspackOnlyTest( + 'should run plugin hooks correctly when running build', + async () => { + fse.removeSync(distFile); + + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [plugin], + }, + }); + + await rsbuild.build(); + + expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([ + 'ModifyRsbuildConfig', + 'ModifyBundlerChain', + 'ModifyBundlerConfig', + 'BeforeCreateCompiler', + 'AfterCreateCompiler', + 'BeforeBuild', + 'ModifyHTMLTags', + 'AfterBuild', + ]); + }, +); + +rspackOnlyTest( + 'should run plugin hooks correctly when running startDevServer', + async ({ page }) => { + setNodeEnv('development'); + fse.removeSync(distFile); + + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [plugin], + }, + }); + + const result = await rsbuild.startDevServer(); + + await gotoPage(page, result); + + await result.server.close(); + + expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([ + 'ModifyRsbuildConfig', + 'BeforeStartDevServer', + 'ModifyBundlerChain', + 'ModifyBundlerConfig', + 'BeforeCreateCompiler', + 'AfterCreateCompiler', + 'AfterStartDevServer', + 'ModifyHTMLTags', + 'OnDevCompileDone', + 'OnCloseDevServer', + ]); + + setNodeEnv('test'); + }, +); + +rspackOnlyTest( + 'should run plugin hooks correctly when running preview', + async () => { + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [plugin], + }, + }); + + fse.removeSync(distFile); + const result = await rsbuild.preview(); + + expect(fse.readFileSync(distFile, 'utf-8').split(',')).toEqual([ + 'ModifyRsbuildConfig', + 'BeforeStartProdServer', + 'AfterStartProdServer', + ]); + + await result.server.close(); + }, +); diff --git a/e2e/cases/rem/basic/index.test.ts b/e2e/cases/rem/basic/index.test.ts index 2cfdac837c..fd1403abe6 100644 --- a/e2e/cases/rem/basic/index.test.ts +++ b/e2e/cases/rem/basic/index.test.ts @@ -89,7 +89,7 @@ test('should apply crossorigin to rem runtime script', async ({ page }) => { expect(htmlFile).toBeTruthy(); expect(files[htmlFile!]).toMatch( - / + + diff --git a/e2e/cases/vue/sfc-css-modules/src/index.js b/e2e/cases/vue/sfc-css-modules/src/index.js new file mode 100644 index 0000000000..84c0113d33 --- /dev/null +++ b/e2e/cases/vue/sfc-css-modules/src/index.js @@ -0,0 +1,4 @@ +import { createApp } from 'vue'; +import App from './App.vue'; + +createApp(App).mount('#root'); diff --git a/e2e/cases/vue/sfc-css-modules/src/style.module.css b/e2e/cases/vue/sfc-css-modules/src/style.module.css new file mode 100644 index 0000000000..fa95e11ba9 --- /dev/null +++ b/e2e/cases/vue/sfc-css-modules/src/style.module.css @@ -0,0 +1,3 @@ +.green { + color: green; +} diff --git a/e2e/cases/vue2/sfc-css-modules/index.test.ts b/e2e/cases/vue2/sfc-css-modules/index.test.ts new file mode 100644 index 0000000000..9969cd15da --- /dev/null +++ b/e2e/cases/vue2/sfc-css-modules/index.test.ts @@ -0,0 +1,45 @@ +import { build, dev, gotoPage, rspackOnlyTest } from '@e2e/helper'; +import { expect } from '@playwright/test'; + +rspackOnlyTest( + 'should build Vue sfc with CSS Modules correctly in dev build', + async ({ page }) => { + const rsbuild = await dev({ + cwd: __dirname, + }); + + await gotoPage(page, rsbuild); + + const test1 = page.locator('#test1'); + const test2 = page.locator('#test2'); + const test3 = page.locator('#test3'); + + await expect(test1).toHaveCSS('color', 'rgb(255, 0, 0)'); + await expect(test2).toHaveCSS('color', 'rgb(0, 0, 255)'); + await expect(test3).toHaveCSS('color', 'rgb(0, 128, 0)'); + + await rsbuild.close(); + }, +); + +rspackOnlyTest( + 'should build Vue sfc with CSS Modules correctly in prod build', + async ({ page }) => { + const rsbuild = await build({ + cwd: __dirname, + runServer: true, + }); + + await gotoPage(page, rsbuild); + + const test1 = page.locator('#test1'); + const test2 = page.locator('#test2'); + const test3 = page.locator('#test3'); + + await expect(test1).toHaveCSS('color', 'rgb(255, 0, 0)'); + await expect(test2).toHaveCSS('color', 'rgb(0, 0, 255)'); + await expect(test3).toHaveCSS('color', 'rgb(0, 128, 0)'); + + await rsbuild.close(); + }, +); diff --git a/e2e/cases/vue2/sfc-css-modules/rsbuild.config.ts b/e2e/cases/vue2/sfc-css-modules/rsbuild.config.ts new file mode 100644 index 0000000000..c1daf5100d --- /dev/null +++ b/e2e/cases/vue2/sfc-css-modules/rsbuild.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from '@rsbuild/core'; +import { pluginVue2 } from '@rsbuild/plugin-vue2'; + +export default defineConfig({ + plugins: [pluginVue2()], + dev: { + writeToDisk: true, + }, +}); diff --git a/e2e/cases/vue2/sfc-css-modules/src/App.vue b/e2e/cases/vue2/sfc-css-modules/src/App.vue new file mode 100644 index 0000000000..603b375605 --- /dev/null +++ b/e2e/cases/vue2/sfc-css-modules/src/App.vue @@ -0,0 +1,29 @@ + + + + + diff --git a/e2e/cases/vue2/sfc-css-modules/src/index.js b/e2e/cases/vue2/sfc-css-modules/src/index.js new file mode 100644 index 0000000000..0850ce8809 --- /dev/null +++ b/e2e/cases/vue2/sfc-css-modules/src/index.js @@ -0,0 +1,7 @@ +import Vue from 'vue'; +import App from './App.vue'; + +new Vue({ + el: '#root', + render: (h) => h(App), +}); diff --git a/e2e/cases/vue2/sfc-css-modules/src/style.module.css b/e2e/cases/vue2/sfc-css-modules/src/style.module.css new file mode 100644 index 0000000000..fa95e11ba9 --- /dev/null +++ b/e2e/cases/vue2/sfc-css-modules/src/style.module.css @@ -0,0 +1,3 @@ +.green { + color: green; +} diff --git a/e2e/package.json b/e2e/package.json index 90763e352c..fed1cce38f 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -10,10 +10,10 @@ "dependencies": { "lodash": "^4.17.21", "moment": "^2.30.1", - "preact": "^10.21.0", + "preact": "^10.22.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "react-router-dom": "^6.23.0", + "react-router-dom": "^6.23.1", "solid-js": "^1.8.17", "vue": "^3.4.19", "vue-router": "^4.3.2" @@ -21,7 +21,7 @@ "devDependencies": { "strip-ansi": "6.0.1", "@e2e/helper": "workspace:*", - "@playwright/test": "1.43.1", + "@playwright/test": "1.44.0", "@rsbuild/babel-preset": "workspace:*", "@rsbuild/core": "workspace:*", "@rsbuild/plugin-assets-retry": "workspace:*", @@ -50,6 +50,7 @@ "@rsbuild/plugin-vue": "workspace:*", "@rsbuild/plugin-vue-jsx": "workspace:*", "@rsbuild/plugin-vue2": "workspace:*", + "@rsbuild/plugin-typed-css-modules": "workspace:*", "@rsbuild/plugin-vue2-jsx": "workspace:*", "@rsbuild/plugin-yaml": "workspace:*", "@rsbuild/shared": "workspace:*", @@ -57,10 +58,10 @@ "@scripts/test-helper": "workspace:*", "@types/lodash": "^4.17.1", "@types/node": "18.x", - "@types/react": "^18.3.1", + "@types/react": "^18.3.2", "@types/react-dom": "^18.3.0", "fast-glob": "^3.3.2", - "playwright": "1.43.1", + "playwright": "1.44.0", "tailwindcss": "^3.4.3", "typescript": "^5.4.2" } diff --git a/e2e/scripts/shared.ts b/e2e/scripts/shared.ts index 2fd8e3d0d2..9a9534232d 100644 --- a/e2e/scripts/shared.ts +++ b/e2e/scripts/shared.ts @@ -146,6 +146,27 @@ export async function dev({ const rsbuild = await createRsbuild(options, plugins); + rsbuild.addPlugins([ + { + // fix hmr problem temporary (only appears in rsbuild repo, because css-loader is not in node_modules/ ) + // https://github.com/web-infra-dev/rspack/issues/5723 + name: 'fix-react-refresh-in-rsbuild', + setup(api) { + api.modifyBundlerChain({ + order: 'post', + handler: (chain, { CHAIN_ID }) => { + if (chain.plugins.has(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH)) { + chain.plugin(CHAIN_ID.PLUGIN.REACT_FAST_REFRESH).tap((config) => { + config[0].exclude = [/node_modules/, /css-loader/]; + return config; + }); + } + }, + }); + }, + }, + ]); + const result = await rsbuild.startDevServer(); return { diff --git a/examples/preact/package.json b/examples/preact/package.json index 556b3e0cd6..d0765108a1 100644 --- a/examples/preact/package.json +++ b/examples/preact/package.json @@ -7,7 +7,7 @@ "preview": "rsbuild preview" }, "dependencies": { - "preact": "^10.21.0" + "preact": "^10.22.0" }, "devDependencies": { "@rsbuild/core": "workspace:*", diff --git a/examples/svelte/package.json b/examples/svelte/package.json index c6ac6414b9..cb17ab1d39 100644 --- a/examples/svelte/package.json +++ b/examples/svelte/package.json @@ -7,7 +7,7 @@ "preview": "rsbuild preview" }, "dependencies": { - "svelte": "^4.2.15" + "svelte": "^4.2.16" }, "devDependencies": { "@rsbuild/core": "workspace:*", diff --git a/nx.json b/nx.json index 7b57524e8f..a0af9956b4 100644 --- a/nx.json +++ b/nx.json @@ -20,7 +20,7 @@ "cache": true, "dependsOn": ["^build", "prebundle"], "inputs": ["build", "^build"], - "outputs": ["{projectRoot}/dist"] + "outputs": ["{projectRoot}/dist", "{projectRoot}/dist-types"] }, "prebundle": { "cache": true, diff --git a/package.json b/package.json index 8e518ae8c8..9f9d109233 100644 --- a/package.json +++ b/package.json @@ -40,16 +40,16 @@ "package.json": "pnpm run check-dependency-version" }, "devDependencies": { - "@biomejs/biome": "1.7.2", + "@biomejs/biome": "1.7.3", "@changesets/cli": "^2.27.1", - "@modern-js/module-tools": "^2.49.2", + "@modern-js/module-tools": "^2.49.3", "@rsbuild/tsconfig": "workspace:*", "@scripts/test-helper": "workspace:*", "check-dependency-version-consistency": "^4.1.0", "cross-env": "^7.0.3", "cspell-ban-words": "^0.0.3", "nano-staged": "^0.8.0", - "nx": "^19.0.1", + "nx": "^19.0.2", "prettier": "^3.2.5", "simple-git-hooks": "^2.11.1", "vitest": "^1.6.0" diff --git a/packages/compat/babel-preset/modern.config.ts b/packages/compat/babel-preset/modern.config.ts index 01b2b34e71..fdb3509d40 100644 --- a/packages/compat/babel-preset/modern.config.ts +++ b/packages/compat/babel-preset/modern.config.ts @@ -1,3 +1,15 @@ -import baseConfig from '../../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../../scripts/modern.base.config'; -export default baseConfig; +export default { + plugins: [moduleTools()], + buildConfig: dualBuildConfigs.map((config) => { + config.input = [ + 'src/index.ts', + 'src/web.ts', + 'src/node.ts', + 'src/pluginLockCorejsVersion.ts', + ]; + return config; + }), +}; diff --git a/packages/compat/babel-preset/package.json b/packages/compat/babel-preset/package.json index c08a6a9776..b3013ef655 100644 --- a/packages/compat/babel-preset/package.json +++ b/packages/compat/babel-preset/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/babel-preset", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "The babel config of Rsbuild.", "homepage": "https://rsbuild.dev", "repository": { @@ -9,22 +9,25 @@ "directory": "packages/babel-preset" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "require": "./dist/index.cjs", + "import": "./dist/index.js" }, "./web": { "types": "./dist/web.d.ts", - "default": "./dist/web.js" + "require": "./dist/web.cjs", + "import": "./dist/web.js" }, "./node": { "types": "./dist/node.d.ts", - "default": "./dist/node.js" + "require": "./dist/node.cjs", + "import": "./dist/node.js" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "typesVersions": { "*": { @@ -57,12 +60,12 @@ "@babel/preset-typescript": "^7.24.1", "@babel/runtime": "^7.24.5", "@babel/types": "^7.24.5", + "@rsbuild/plugin-babel": "workspace:*", "@types/babel__core": "^7.20.5", "babel-plugin-dynamic-import-node": "2.3.3", "core-js": "~3.36.0" }, "devDependencies": { - "@rsbuild/plugin-babel": "workspace:*", "@types/node": "18.x", "typescript": "^5.4.2" }, diff --git a/packages/compat/babel-preset/src/web.ts b/packages/compat/babel-preset/src/web.ts index 8d0e4e657e..9a58f064ba 100644 --- a/packages/compat/babel-preset/src/web.ts +++ b/packages/compat/babel-preset/src/web.ts @@ -48,7 +48,7 @@ export const getBabelConfigForWeb = (options: WebPresetOptions) => { ]); } - config.plugins?.push(join(__dirname, './pluginLockCorejsVersion')); + config.plugins?.push(join(__dirname, './pluginLockCorejsVersion.cjs')); return config; }; diff --git a/packages/compat/babel-preset/tests/__snapshots__/web.test.ts.snap b/packages/compat/babel-preset/tests/__snapshots__/web.test.ts.snap index 0d250dacac..19f6a4ba48 100644 --- a/packages/compat/babel-preset/tests/__snapshots__/web.test.ts.snap +++ b/packages/compat/babel-preset/tests/__snapshots__/web.test.ts.snap @@ -24,7 +24,7 @@ exports[`should allow to enable legacy decorator 1`] = ` "version": "7.24.5", }, ], - "/packages/compat/babel-preset/src/pluginLockCorejsVersion", + "/packages/compat/babel-preset/src/pluginLockCorejsVersion.cjs", ], "presets": [ [ @@ -84,7 +84,7 @@ exports[`should allow to enable specific version decorator 1`] = ` "version": "7.24.5", }, ], - "/packages/compat/babel-preset/src/pluginLockCorejsVersion", + "/packages/compat/babel-preset/src/pluginLockCorejsVersion.cjs", ], "presets": [ [ @@ -134,7 +134,7 @@ exports[`should provide web preset as expected 1`] = ` "version": "7.24.5", }, ], - "/packages/compat/babel-preset/src/pluginLockCorejsVersion", + "/packages/compat/babel-preset/src/pluginLockCorejsVersion.cjs", ], "presets": [ [ @@ -225,7 +225,7 @@ exports[`should support inject core-js polyfills by entry 1`] = ` "version": "7.24.5", }, ], - "/packages/compat/babel-preset/src/pluginLockCorejsVersion", + "/packages/compat/babel-preset/src/pluginLockCorejsVersion.cjs", ], "presets": [ [ @@ -278,7 +278,7 @@ exports[`should support inject core-js polyfills by usage 1`] = ` "version": "7.24.5", }, ], - "/packages/compat/babel-preset/src/pluginLockCorejsVersion", + "/packages/compat/babel-preset/src/pluginLockCorejsVersion.cjs", ], "presets": [ [ diff --git a/packages/compat/plugin-swc/modern.config.ts b/packages/compat/plugin-swc/modern.config.ts index 01b2b34e71..eb421927cf 100644 --- a/packages/compat/plugin-swc/modern.config.ts +++ b/packages/compat/plugin-swc/modern.config.ts @@ -1,3 +1,13 @@ -import baseConfig from '../../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../../scripts/modern.base.config'; -export default baseConfig; +export default { + plugins: [moduleTools()], + buildConfig: dualBuildConfigs.map((config) => { + if (config.format === 'cjs') { + // add loader to entry + config.input = ['src/index.ts', 'src/loader.ts']; + } + return config; + }), +}; diff --git a/packages/compat/plugin-swc/package.json b/packages/compat/plugin-swc/package.json index 2b5cd0bc2b..9a12a574e3 100644 --- a/packages/compat/plugin-swc/package.json +++ b/packages/compat/plugin-swc/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-swc", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "SWC plugin for Rsbuild", "repository": { "type": "git", @@ -8,26 +8,15 @@ "directory": "packages/compat/plugin-swc" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, - "./loader": { - "types": "./dist/loader.d.ts", - "default": "./dist/loader.js" - }, - "./plugin": { - "types": "./dist/plugin.d.ts", - "default": "./dist/plugin.js" - }, - "./binding": { - "types": "./dist/binding.d.ts", - "default": "./dist/binding.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -52,7 +41,7 @@ "webpack": "^5.91.0" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/compat/plugin-swc/src/minimizer.ts b/packages/compat/plugin-swc/src/minimizer.ts index d0ce44840a..38272f4227 100644 --- a/packages/compat/plugin-swc/src/minimizer.ts +++ b/packages/compat/plugin-swc/src/minimizer.ts @@ -1,13 +1,6 @@ -import { logger } from '@rsbuild/core'; -import { - CSS_REGEX, - type NormalizedConfig, - color, - getSwcMinimizerOptions, - parseMinifyOptions, -} from '@rsbuild/shared'; +import { type NormalizedConfig, __internalHelper, logger } from '@rsbuild/core'; +import { color, deepmerge } from '@rsbuild/shared'; import type { webpack } from '@rsbuild/webpack'; -import { merge } from 'lodash'; import { minify, minifyCss } from './binding'; import { JS_REGEX } from './constants'; import type { CssMinifyOptions, JsMinifyOptions, Output } from './types'; @@ -30,6 +23,8 @@ const normalize = ( return v; }; +const CSS_REGEX = /\.css$/; + export class SwcMinimizerPlugin { private readonly minifyOptions: NormalizedSwcMinifyOption; @@ -40,10 +35,15 @@ export class SwcMinimizerPlugin { cssMinify?: boolean | CssMinifyOptions; rsbuildConfig: NormalizedConfig; }) { - const { minifyJs, minifyCss } = parseMinifyOptions(options.rsbuildConfig); + const { minify } = options.rsbuildConfig.output; + const minifyJs = + minify === true || (typeof minify === 'object' && minify.js); + const minifyCss = + minify === true || (typeof minify === 'object' && minify.css); + this.minifyOptions = { jsMinify: minifyJs - ? merge( + ? deepmerge( this.getDefaultJsMinifyOptions(options.rsbuildConfig), normalize(options.jsMinify, {}), ) @@ -54,7 +54,7 @@ export class SwcMinimizerPlugin { getDefaultJsMinifyOptions(rsbuildConfig: NormalizedConfig): JsMinifyOptions { const options = { - ...getSwcMinimizerOptions(rsbuildConfig), + ...__internalHelper.getSwcMinimizerOptions(rsbuildConfig), mangle: true, }; diff --git a/packages/compat/plugin-swc/src/plugin.ts b/packages/compat/plugin-swc/src/plugin.ts index 71da7fe473..09c7a82628 100644 --- a/packages/compat/plugin-swc/src/plugin.ts +++ b/packages/compat/plugin-swc/src/plugin.ts @@ -1,10 +1,9 @@ import path from 'node:path'; +import type { RsbuildPlugin } from '@rsbuild/core'; import { DEFAULT_BROWSERSLIST, - type RsbuildPlugin, SCRIPT_REGEX, applyScriptCondition, - parseMinifyOptions, } from '@rsbuild/shared'; import { SwcMinimizerPlugin } from './minimizer'; import type { @@ -77,7 +76,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ rule .test(test || SCRIPT_REGEX) .use(CHAIN_ID.USE.SWC) - .loader(path.resolve(__dirname, './loader')) + .loader(path.resolve(__dirname, './loader.cjs')) .options(removeUselessOptions(swcConfig) satisfies TransformConfig); if (include) { @@ -113,7 +112,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ .resolve.set('fullySpecified', false) .end() .use(CHAIN_ID.USE.SWC) - .loader(path.resolve(__dirname, './loader')) + .loader(path.resolve(__dirname, './loader.cjs')) .options(removeUselessOptions(mainConfig) satisfies TransformConfig); }, }); @@ -134,7 +133,11 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ minimizersChain.delete(CHAIN_ID.MINIMIZER.CSS).end(); } - const { minifyJs, minifyCss } = parseMinifyOptions(rsbuildConfig); + const { minify } = rsbuildConfig.output; + const minifyJs = + minify === true || (typeof minify === 'object' && minify.js); + const minifyCss = + minify === true || (typeof minify === 'object' && minify.css); minimizersChain .end() diff --git a/packages/compat/plugin-swc/src/utils.ts b/packages/compat/plugin-swc/src/utils.ts index 6303964906..929a9fa4b4 100644 --- a/packages/compat/plugin-swc/src/utils.ts +++ b/packages/compat/plugin-swc/src/utils.ts @@ -1,12 +1,10 @@ import fs from 'node:fs'; -import { applySwcDecoratorConfig } from '@rsbuild/core/internal'; +import path from 'node:path'; +import { __internalHelper } from '@rsbuild/core'; +import type { ModifyChainUtils, NormalizedConfig } from '@rsbuild/core'; import { - type ModifyChainUtils, - type NormalizedConfig, - findUp, getBrowserslistWithDefault, getCoreJsVersion, - getDefaultStyledComponentsConfig, isUsingHMR, } from '@rsbuild/shared'; import semver from '@rsbuild/shared/semver'; @@ -19,6 +17,32 @@ import type { TransformConfig, } from './types'; +const { applySwcDecoratorConfig } = __internalHelper; + +async function findUp({ + filename, + cwd = process.cwd(), +}: { + filename: string; + cwd?: string; +}) { + const { root } = path.parse(cwd); + + let dir = cwd; + while (dir && dir !== root) { + const filePath = path.join(dir, filename); + + try { + const stats = await fs.promises.stat(filePath); + if (stats?.isFile()) { + return filePath; + } + } catch {} + + dir = path.dirname(dir); + } +} + const isBeyondReact17 = async (cwd: string) => { const pkgPath = await findUp({ cwd, filename: 'package.json' }); @@ -140,6 +164,17 @@ export async function finalizeConfig( return finalized; } +const getDefaultStyledComponentsConfig = (isProd: boolean, ssr: boolean) => { + return { + ssr, + // "pure" is used to improve dead code elimination in production. + // we don't need to enable it in development because it will slow down the build process. + pure: isProd, + displayName: true, + transpileTemplateLiterals: true, + }; +}; + export async function applyPluginConfig( rawOptions: PluginSwcOptions, utils: ModifyChainUtils, diff --git a/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap b/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap index 774a2b44b2..0fcf51f113 100644 --- a/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap +++ b/packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap @@ -23,7 +23,7 @@ exports[`plugin-swc > should apply source.include and source.exclude correctly 1 "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -83,7 +83,7 @@ exports[`plugin-swc > should apply source.include and source.exclude correctly 1 }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -154,7 +154,7 @@ exports[`plugin-swc > should disable react refresh when dev.hmr is false 1`] = ` "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -214,7 +214,7 @@ exports[`plugin-swc > should disable react refresh when dev.hmr is false 1`] = ` }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -284,7 +284,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 1`] = "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -341,7 +341,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 1`] = }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -408,7 +408,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 2`] = "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -468,7 +468,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 2`] = }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -538,7 +538,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 3`] = "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -598,7 +598,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 3`] = }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -668,7 +668,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 4`] = "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -728,7 +728,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 4`] = }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -837,7 +837,7 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = ` "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -889,7 +889,7 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = ` "test": /override\\.ts/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -949,7 +949,7 @@ exports[`plugin-swc > should set multiple swc-loader 1`] = ` }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -1038,7 +1038,7 @@ exports[`plugin-swc > should set swc-loader 1`] = ` "test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { @@ -1098,7 +1098,7 @@ exports[`plugin-swc > should set swc-loader 1`] = ` }, "use": [ { - "loader": "/packages/compat/plugin-swc/src/loader", + "loader": "/packages/compat/plugin-swc/src/loader.cjs", "options": { "cwd": "/packages/compat/plugin-swc/tests", "env": { diff --git a/packages/compat/plugin-swc/tests/plugin.test.ts b/packages/compat/plugin-swc/tests/plugin.test.ts index eb96b09d22..f9a5dcf6eb 100644 --- a/packages/compat/plugin-swc/tests/plugin.test.ts +++ b/packages/compat/plugin-swc/tests/plugin.test.ts @@ -1,7 +1,4 @@ -import type { - ModifyWebpackChainUtils, - NormalizedConfig, -} from '@rsbuild/shared'; +import type { ModifyChainUtils, NormalizedConfig } from '@rsbuild/core'; import { webpackProvider } from '@rsbuild/webpack'; import { createStubRsbuild } from '@scripts/test-helper'; import { pluginSwc } from '../src'; @@ -17,7 +14,7 @@ const TEST_BUILDER_CONFIG = { }, } as unknown as NormalizedConfig; -const UTILS = { target: 'web', isProd: true } as ModifyWebpackChainUtils; +const UTILS = { target: 'web', isProd: true } as ModifyChainUtils; describe('plugin-swc', () => { it('should set swc-loader', async () => { diff --git a/packages/compat/webpack/compiled/ansi-escapes/index.d.ts b/packages/compat/webpack/compiled/ansi-escapes/index.d.ts deleted file mode 100644 index 4b08cf10dc..0000000000 --- a/packages/compat/webpack/compiled/ansi-escapes/index.d.ts +++ /dev/null @@ -1,248 +0,0 @@ -/// -import {LiteralUnion} from './type-fest'; - -declare namespace ansiEscapes { - interface ImageOptions { - /** - The width is given as a number followed by a unit, or the word `'auto'`. - - - `N`: N character cells. - - `Npx`: N pixels. - - `N%`: N percent of the session's width or height. - - `auto`: The image's inherent size will be used to determine an appropriate dimension. - */ - readonly width?: LiteralUnion<'auto', number | string>; - - /** - The height is given as a number followed by a unit, or the word `'auto'`. - - - `N`: N character cells. - - `Npx`: N pixels. - - `N%`: N percent of the session's width or height. - - `auto`: The image's inherent size will be used to determine an appropriate dimension. - */ - readonly height?: LiteralUnion<'auto', number | string>; - - readonly preserveAspectRatio?: boolean; - } - - interface AnnotationOptions { - /** - Nonzero number of columns to annotate. - - Default: The remainder of the line. - */ - readonly length?: number; - - /** - Starting X coordinate. - - Must be used with `y` and `length`. - - Default: The cursor position - */ - readonly x?: number; - - /** - Starting Y coordinate. - - Must be used with `x` and `length`. - - Default: Cursor position. - */ - readonly y?: number; - - /** - Create a "hidden" annotation. - - Annotations created this way can be shown using the "Show Annotations" iTerm command. - */ - readonly isHidden?: boolean; - } -} - -declare const ansiEscapes: { - /** - Set the absolute position of the cursor. `x0` `y0` is the top left of the screen. - */ - cursorTo(x: number, y?: number): string; - - /** - Set the position of the cursor relative to its current position. - */ - cursorMove(x: number, y?: number): string; - - /** - Move cursor up a specific amount of rows. - - @param count - Count of rows to move up. Default is `1`. - */ - cursorUp(count?: number): string; - - /** - Move cursor down a specific amount of rows. - - @param count - Count of rows to move down. Default is `1`. - */ - cursorDown(count?: number): string; - - /** - Move cursor forward a specific amount of rows. - - @param count - Count of rows to move forward. Default is `1`. - */ - cursorForward(count?: number): string; - - /** - Move cursor backward a specific amount of rows. - - @param count - Count of rows to move backward. Default is `1`. - */ - cursorBackward(count?: number): string; - - /** - Move cursor to the left side. - */ - cursorLeft: string; - - /** - Save cursor position. - */ - cursorSavePosition: string; - - /** - Restore saved cursor position. - */ - cursorRestorePosition: string; - - /** - Get cursor position. - */ - cursorGetPosition: string; - - /** - Move cursor to the next line. - */ - cursorNextLine: string; - - /** - Move cursor to the previous line. - */ - cursorPrevLine: string; - - /** - Hide cursor. - */ - cursorHide: string; - - /** - Show cursor. - */ - cursorShow: string; - - /** - Erase from the current cursor position up the specified amount of rows. - - @param count - Count of rows to erase. - */ - eraseLines(count: number): string; - - /** - Erase from the current cursor position to the end of the current line. - */ - eraseEndLine: string; - - /** - Erase from the current cursor position to the start of the current line. - */ - eraseStartLine: string; - - /** - Erase the entire current line. - */ - eraseLine: string; - - /** - Erase the screen from the current line down to the bottom of the screen. - */ - eraseDown: string; - - /** - Erase the screen from the current line up to the top of the screen. - */ - eraseUp: string; - - /** - Erase the screen and move the cursor the top left position. - */ - eraseScreen: string; - - /** - Scroll display up one line. - */ - scrollUp: string; - - /** - Scroll display down one line. - */ - scrollDown: string; - - /** - Clear the terminal screen. (Viewport) - */ - clearScreen: string; - - /** - Clear the whole terminal, including scrollback buffer. (Not just the visible part of it) - */ - clearTerminal: string; - - /** - Output a beeping sound. - */ - beep: string; - - /** - Create a clickable link. - - [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support. - */ - link(text: string, url: string): string; - - /** - Display an image. - - _Currently only supported on iTerm2 >=3_ - - See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module. - - @param buffer - Buffer of an image. Usually read in with `fs.readFile()`. - */ - image(buffer: Buffer, options?: ansiEscapes.ImageOptions): string; - - iTerm: { - /** - [Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click). - - @param cwd - Current directory. Default: `process.cwd()`. - */ - setCwd(cwd?: string): string; - - /** - An annotation looks like this when shown: - - ![screenshot of iTerm annotation](https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png) - - See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information. - - @param message - The message to display within the annotation. The `|` character is disallowed and will be stripped. - @returns An escape code which will create an annotation when printed in iTerm2. - */ - annotation(message: string, options?: ansiEscapes.AnnotationOptions): string; - }; - - // TODO: remove this in the next major version - default: typeof ansiEscapes; -}; - -export = ansiEscapes; diff --git a/packages/compat/webpack/compiled/ansi-escapes/index.js b/packages/compat/webpack/compiled/ansi-escapes/index.js deleted file mode 100644 index 470d26d951..0000000000 --- a/packages/compat/webpack/compiled/ansi-escapes/index.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var e={933:e=>{const r=e.exports;e.exports["default"]=r;const n="[";const t="]";const o="";const i=";";const s=process.env.TERM_PROGRAM==="Apple_Terminal";r.cursorTo=(e,r)=>{if(typeof e!=="number"){throw new TypeError("The `x` argument is required")}if(typeof r!=="number"){return n+(e+1)+"G"}return n+(r+1)+";"+(e+1)+"H"};r.cursorMove=(e,r)=>{if(typeof e!=="number"){throw new TypeError("The `x` argument is required")}let t="";if(e<0){t+=n+-e+"D"}else if(e>0){t+=n+e+"C"}if(r<0){t+=n+-r+"A"}else if(r>0){t+=n+r+"B"}return t};r.cursorUp=(e=1)=>n+e+"A";r.cursorDown=(e=1)=>n+e+"B";r.cursorForward=(e=1)=>n+e+"C";r.cursorBackward=(e=1)=>n+e+"D";r.cursorLeft=n+"G";r.cursorSavePosition=s?"7":n+"s";r.cursorRestorePosition=s?"8":n+"u";r.cursorGetPosition=n+"6n";r.cursorNextLine=n+"E";r.cursorPrevLine=n+"F";r.cursorHide=n+"?25l";r.cursorShow=n+"?25h";r.eraseLines=e=>{let n="";for(let t=0;t[t,"8",i,i,r,o,e,t,"8",i,i,o].join("");r.image=(e,r={})=>{let n=`${t}1337;File=inline=1`;if(r.width){n+=`;width=${r.width}`}if(r.height){n+=`;height=${r.height}`}if(r.preserveAspectRatio===false){n+=";preserveAspectRatio=0"}return n+":"+e.toString("base64")+o};r.iTerm={setCwd:(e=process.cwd())=>`${t}50;CurrentDir=${e}${o}`,annotation:(e,r={})=>{let n=`${t}1337;`;const i=typeof r.x!=="undefined";const s=typeof r.y!=="undefined";if((i||s)&&!(i&&s&&typeof r.length!=="undefined")){throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined")}e=e.replace(/\|/g,"");n+=r.isHidden?"AddHiddenAnnotation=":"AddAnnotation=";if(r.length>0){n+=(i?[e,r.length,r.x,r.y]:[r.length,e]).join("|")}else{n+=e}return n+o}}}};var r={};function __nccwpck_require__(n){var t=r[n];if(t!==undefined){return t.exports}var o=r[n]={exports:{}};var i=true;try{e[n](o,o.exports,__nccwpck_require__);i=false}finally{if(i)delete r[n]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n=__nccwpck_require__(933);module.exports=n})(); \ No newline at end of file diff --git a/packages/compat/webpack/compiled/ansi-escapes/license b/packages/compat/webpack/compiled/ansi-escapes/license deleted file mode 100644 index fa7ceba3eb..0000000000 --- a/packages/compat/webpack/compiled/ansi-escapes/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (https://sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/compat/webpack/compiled/ansi-escapes/package.json b/packages/compat/webpack/compiled/ansi-escapes/package.json deleted file mode 100644 index 909e28d7af..0000000000 --- a/packages/compat/webpack/compiled/ansi-escapes/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"ansi-escapes","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"version":"4.3.2","funding":"https://github.com/sponsors/sindresorhus","license":"MIT"} diff --git a/packages/compat/webpack/compiled/ansi-escapes/type-fest/index.d.ts b/packages/compat/webpack/compiled/ansi-escapes/type-fest/index.d.ts deleted file mode 100644 index 206261c21d..0000000000 --- a/packages/compat/webpack/compiled/ansi-escapes/type-fest/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// These are all the basic types that's compatible with all supported TypeScript versions. -export * from './base'; diff --git a/packages/compat/webpack/compiled/cli-truncate/index.d.ts b/packages/compat/webpack/compiled/cli-truncate/index.d.ts deleted file mode 100644 index 41caf8d932..0000000000 --- a/packages/compat/webpack/compiled/cli-truncate/index.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -declare namespace cliTruncate { - interface Options { - /** - Position to truncate the string. - - @default 'end' - */ - readonly position?: 'start' | 'middle' | 'end'; - - /** - Add a space between the text and the ellipsis. - - @default false - - @example - ``` - cliTruncate('unicorns', 5, {position: 'end', space: true}); - //=> 'uni …' - - cliTruncate('unicorns', 5, {position: 'end', space: false}); - //=> 'unic…' - - cliTruncate('unicorns', 6, {position: 'start', space: true}); - //=> '… orns' - - cliTruncate('unicorns', 7, {position: 'middle', space: true}); - //=> 'uni … s' - ``` - */ - readonly space?: boolean; - - /** - Truncate the string from a whitespace if it is within 3 characters from the actual breaking point. - - @default false - - @example - ``` - cliTruncate('unicorns rainbow dragons', 20, {position: 'start', preferTruncationOnSpace: true}); - //=> '…rainbow dragons' - - cliTruncate('unicorns rainbow dragons', 20, {position: 'middle', preferTruncationOnSpace: true}); - //=> 'unicorns…dragons' - - cliTruncate('unicorns rainbow dragons', 6, {position: 'end', preferTruncationOnSpace: true}); - //=> 'unico…' - ```` - */ - readonly preferTruncationOnSpace?: boolean; - } -} - -/** -Truncate a string to a specific width in the terminal. - -@param text - Text to truncate. -@param columns - Columns to occupy in the terminal. - -@example -``` -import cliTruncate = require('./cli-truncate'); - -cliTruncate('unicorn', 4); -//=> 'uni…' - -// Truncate at different positions -cliTruncate('unicorn', 4, {position: 'start'}); -//=> '…orn' - -cliTruncate('unicorn', 4, {position: 'middle'}); -//=> 'un…n' - -cliTruncate('\u001B[31municorn\u001B[39m', 4); -//=> '\u001B[31muni\u001B[39m…' - -// Truncate Unicode surrogate pairs -cliTruncate('uni\uD83C\uDE00corn', 5); -//=> 'uni\uD83C\uDE00…' - -// Truncate fullwidth characters -cliTruncate('안녕하세요', 3); -//=> '안…' - -// Truncate the paragraph to the terminal width -const paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.'; -cliTruncate(paragraph, process.stdout.columns)); -//=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…' -``` -*/ -declare function cliTruncate( - text: string, - columns: number, - options?: cliTruncate.Options -): string; - -export = cliTruncate; diff --git a/packages/compat/webpack/compiled/cli-truncate/index.js b/packages/compat/webpack/compiled/cli-truncate/index.js deleted file mode 100644 index 2ecc75a396..0000000000 --- a/packages/compat/webpack/compiled/cli-truncate/index.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{var D={275:D=>{"use strict";D.exports=({onlyFirst:D=false}={})=>{const u=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(u,D?undefined:"g")}},44:(D,u,e)=>{"use strict";D=e.nmd(D);const wrapAnsi16=(D,u)=>(...e)=>{const t=D(...e);return`[${t+u}m`};const wrapAnsi256=(D,u)=>(...e)=>{const t=D(...e);return`[${38+u};5;${t}m`};const wrapAnsi16m=(D,u)=>(...e)=>{const t=D(...e);return`[${38+u};2;${t[0]};${t[1]};${t[2]}m`};const ansi2ansi=D=>D;const rgb2rgb=(D,u,e)=>[D,u,e];const setLazyProperty=(D,u,e)=>{Object.defineProperty(D,u,{get:()=>{const t=e();Object.defineProperty(D,u,{value:t,enumerable:true,configurable:true});return t},enumerable:true,configurable:true})};let t;const makeDynamicStyles=(D,u,n,r)=>{if(t===undefined){t=e(767)}const o=r?10:0;const F={};for(const[e,r]of Object.entries(t)){const t=e==="ansi16"?"ansi":e;if(e===u){F[t]=D(n,o)}else if(typeof r==="object"){F[t]=D(r[u],o)}}return F};function assembleStyles(){const D=new Map;const u={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};u.color.gray=u.color.blackBright;u.bgColor.bgGray=u.bgColor.bgBlackBright;u.color.grey=u.color.blackBright;u.bgColor.bgGrey=u.bgColor.bgBlackBright;for(const[e,t]of Object.entries(u)){for(const[e,n]of Object.entries(t)){u[e]={open:`[${n[0]}m`,close:`[${n[1]}m`};t[e]=u[e];D.set(n[0],n[1])}Object.defineProperty(u,e,{value:t,enumerable:false})}Object.defineProperty(u,"codes",{value:D,enumerable:false});u.color.close="";u.bgColor.close="";setLazyProperty(u.color,"ansi",(()=>makeDynamicStyles(wrapAnsi16,"ansi16",ansi2ansi,false)));setLazyProperty(u.color,"ansi256",(()=>makeDynamicStyles(wrapAnsi256,"ansi256",ansi2ansi,false)));setLazyProperty(u.color,"ansi16m",(()=>makeDynamicStyles(wrapAnsi16m,"rgb",rgb2rgb,false)));setLazyProperty(u.bgColor,"ansi",(()=>makeDynamicStyles(wrapAnsi16,"ansi16",ansi2ansi,true)));setLazyProperty(u.bgColor,"ansi256",(()=>makeDynamicStyles(wrapAnsi256,"ansi256",ansi2ansi,true)));setLazyProperty(u.bgColor,"ansi16m",(()=>makeDynamicStyles(wrapAnsi16m,"rgb",rgb2rgb,true)));return u}Object.defineProperty(D,"exports",{enumerable:true,get:assembleStyles})},788:D=>{"use strict";const u="[\ud800-\udbff][\udc00-\udfff]";const astralRegex=D=>D&&D.exact?new RegExp(`^${u}$`):new RegExp(u,"g");D.exports=astralRegex},922:(D,u,e)=>{"use strict";const t=e(770);const n=e(629);function getIndexOfNearestSpace(D,u,e){if(D.charAt(u)===" "){return u}for(let t=1;t<=3;t++){if(e){if(D.charAt(u+t)===" "){return u+t}}else if(D.charAt(u-t)===" "){return u-t}}return u}D.exports=(D,u,e)=>{e={position:"end",preferTruncationOnSpace:false,...e};const{position:r,space:o,preferTruncationOnSpace:F}=e;let s="…";let c=1;if(typeof D!=="string"){throw new TypeError(`Expected \`input\` to be a string, got ${typeof D}`)}if(typeof u!=="number"){throw new TypeError(`Expected \`columns\` to be a number, got ${typeof u}`)}if(u<1){return""}if(u===1){return s}const C=n(D);if(C<=u){return D}if(r==="start"){if(F){const e=getIndexOfNearestSpace(D,C-u+1,true);return s+t(D,e,C).trim()}if(o===true){s+=" ";c=2}return s+t(D,C-u+c,C)}if(r==="middle"){if(o===true){s=" "+s+" ";c=3}const e=Math.floor(u/2);if(F){const n=getIndexOfNearestSpace(D,e);const r=getIndexOfNearestSpace(D,C-(u-e)+1,true);return t(D,0,n)+s+t(D,r,C).trim()}return t(D,0,e)+s+t(D,C-(u-e)+c,C)}if(r==="end"){if(F){const e=getIndexOfNearestSpace(D,u-1);return t(D,0,e)+s}if(o===true){s=" "+s;c=2}return t(D,0,u-c)+s}throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${r}`)}},226:(D,u,e)=>{const t=e(866);const n={};for(const D of Object.keys(t)){n[t[D]]=D}const r={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};D.exports=r;for(const D of Object.keys(r)){if(!("channels"in r[D])){throw new Error("missing channels property: "+D)}if(!("labels"in r[D])){throw new Error("missing channel labels property: "+D)}if(r[D].labels.length!==r[D].channels){throw new Error("channel and label counts mismatch: "+D)}const{channels:u,labels:e}=r[D];delete r[D].channels;delete r[D].labels;Object.defineProperty(r[D],"channels",{value:u});Object.defineProperty(r[D],"labels",{value:e})}r.rgb.hsl=function(D){const u=D[0]/255;const e=D[1]/255;const t=D[2]/255;const n=Math.min(u,e,t);const r=Math.max(u,e,t);const o=r-n;let F;let s;if(r===n){F=0}else if(u===r){F=(e-t)/o}else if(e===r){F=2+(t-u)/o}else if(t===r){F=4+(u-e)/o}F=Math.min(F*60,360);if(F<0){F+=360}const c=(n+r)/2;if(r===n){s=0}else if(c<=.5){s=o/(r+n)}else{s=o/(2-r-n)}return[F,s*100,c*100]};r.rgb.hsv=function(D){let u;let e;let t;let n;let r;const o=D[0]/255;const F=D[1]/255;const s=D[2]/255;const c=Math.max(o,F,s);const C=c-Math.min(o,F,s);const diffc=function(D){return(c-D)/6/C+1/2};if(C===0){n=0;r=0}else{r=C/c;u=diffc(o);e=diffc(F);t=diffc(s);if(o===c){n=t-e}else if(F===c){n=1/3+u-t}else if(s===c){n=2/3+e-u}if(n<0){n+=1}else if(n>1){n-=1}}return[n*360,r*100,c*100]};r.rgb.hwb=function(D){const u=D[0];const e=D[1];let t=D[2];const n=r.rgb.hsl(D)[0];const o=1/255*Math.min(u,Math.min(e,t));t=1-1/255*Math.max(u,Math.max(e,t));return[n,o*100,t*100]};r.rgb.cmyk=function(D){const u=D[0]/255;const e=D[1]/255;const t=D[2]/255;const n=Math.min(1-u,1-e,1-t);const r=(1-u-n)/(1-n)||0;const o=(1-e-n)/(1-n)||0;const F=(1-t-n)/(1-n)||0;return[r*100,o*100,F*100,n*100]};function comparativeDistance(D,u){return(D[0]-u[0])**2+(D[1]-u[1])**2+(D[2]-u[2])**2}r.rgb.keyword=function(D){const u=n[D];if(u){return u}let e=Infinity;let r;for(const u of Object.keys(t)){const n=t[u];const o=comparativeDistance(D,n);if(o.04045?((u+.055)/1.055)**2.4:u/12.92;e=e>.04045?((e+.055)/1.055)**2.4:e/12.92;t=t>.04045?((t+.055)/1.055)**2.4:t/12.92;const n=u*.4124+e*.3576+t*.1805;const r=u*.2126+e*.7152+t*.0722;const o=u*.0193+e*.1192+t*.9505;return[n*100,r*100,o*100]};r.rgb.lab=function(D){const u=r.rgb.xyz(D);let e=u[0];let t=u[1];let n=u[2];e/=95.047;t/=100;n/=108.883;e=e>.008856?e**(1/3):7.787*e+16/116;t=t>.008856?t**(1/3):7.787*t+16/116;n=n>.008856?n**(1/3):7.787*n+16/116;const o=116*t-16;const F=500*(e-t);const s=200*(t-n);return[o,F,s]};r.hsl.rgb=function(D){const u=D[0]/360;const e=D[1]/100;const t=D[2]/100;let n;let r;let o;if(e===0){o=t*255;return[o,o,o]}if(t<.5){n=t*(1+e)}else{n=t+e-t*e}const F=2*t-n;const s=[0,0,0];for(let D=0;D<3;D++){r=u+1/3*-(D-1);if(r<0){r++}if(r>1){r--}if(6*r<1){o=F+(n-F)*6*r}else if(2*r<1){o=n}else if(3*r<2){o=F+(n-F)*(2/3-r)*6}else{o=F}s[D]=o*255}return s};r.hsl.hsv=function(D){const u=D[0];let e=D[1]/100;let t=D[2]/100;let n=e;const r=Math.max(t,.01);t*=2;e*=t<=1?t:2-t;n*=r<=1?r:2-r;const o=(t+e)/2;const F=t===0?2*n/(r+n):2*e/(t+e);return[u,F*100,o*100]};r.hsv.rgb=function(D){const u=D[0]/60;const e=D[1]/100;let t=D[2]/100;const n=Math.floor(u)%6;const r=u-Math.floor(u);const o=255*t*(1-e);const F=255*t*(1-e*r);const s=255*t*(1-e*(1-r));t*=255;switch(n){case 0:return[t,s,o];case 1:return[F,t,o];case 2:return[o,t,s];case 3:return[o,F,t];case 4:return[s,o,t];case 5:return[t,o,F]}};r.hsv.hsl=function(D){const u=D[0];const e=D[1]/100;const t=D[2]/100;const n=Math.max(t,.01);let r;let o;o=(2-e)*t;const F=(2-e)*n;r=e*n;r/=F<=1?F:2-F;r=r||0;o/=2;return[u,r*100,o*100]};r.hwb.rgb=function(D){const u=D[0]/360;let e=D[1]/100;let t=D[2]/100;const n=e+t;let r;if(n>1){e/=n;t/=n}const o=Math.floor(6*u);const F=1-t;r=6*u-o;if((o&1)!==0){r=1-r}const s=e+r*(F-e);let c;let C;let i;switch(o){default:case 6:case 0:c=F;C=s;i=e;break;case 1:c=s;C=F;i=e;break;case 2:c=e;C=F;i=s;break;case 3:c=e;C=s;i=F;break;case 4:c=s;C=e;i=F;break;case 5:c=F;C=e;i=s;break}return[c*255,C*255,i*255]};r.cmyk.rgb=function(D){const u=D[0]/100;const e=D[1]/100;const t=D[2]/100;const n=D[3]/100;const r=1-Math.min(1,u*(1-n)+n);const o=1-Math.min(1,e*(1-n)+n);const F=1-Math.min(1,t*(1-n)+n);return[r*255,o*255,F*255]};r.xyz.rgb=function(D){const u=D[0]/100;const e=D[1]/100;const t=D[2]/100;let n;let r;let o;n=u*3.2406+e*-1.5372+t*-.4986;r=u*-.9689+e*1.8758+t*.0415;o=u*.0557+e*-.204+t*1.057;n=n>.0031308?1.055*n**(1/2.4)-.055:n*12.92;r=r>.0031308?1.055*r**(1/2.4)-.055:r*12.92;o=o>.0031308?1.055*o**(1/2.4)-.055:o*12.92;n=Math.min(Math.max(0,n),1);r=Math.min(Math.max(0,r),1);o=Math.min(Math.max(0,o),1);return[n*255,r*255,o*255]};r.xyz.lab=function(D){let u=D[0];let e=D[1];let t=D[2];u/=95.047;e/=100;t/=108.883;u=u>.008856?u**(1/3):7.787*u+16/116;e=e>.008856?e**(1/3):7.787*e+16/116;t=t>.008856?t**(1/3):7.787*t+16/116;const n=116*e-16;const r=500*(u-e);const o=200*(e-t);return[n,r,o]};r.lab.xyz=function(D){const u=D[0];const e=D[1];const t=D[2];let n;let r;let o;r=(u+16)/116;n=e/500+r;o=r-t/200;const F=r**3;const s=n**3;const c=o**3;r=F>.008856?F:(r-16/116)/7.787;n=s>.008856?s:(n-16/116)/7.787;o=c>.008856?c:(o-16/116)/7.787;n*=95.047;r*=100;o*=108.883;return[n,r,o]};r.lab.lch=function(D){const u=D[0];const e=D[1];const t=D[2];let n;const r=Math.atan2(t,e);n=r*360/2/Math.PI;if(n<0){n+=360}const o=Math.sqrt(e*e+t*t);return[u,o,n]};r.lch.lab=function(D){const u=D[0];const e=D[1];const t=D[2];const n=t/360*2*Math.PI;const r=e*Math.cos(n);const o=e*Math.sin(n);return[u,r,o]};r.rgb.ansi16=function(D,u=null){const[e,t,n]=D;let o=u===null?r.rgb.hsv(D)[2]:u;o=Math.round(o/50);if(o===0){return 30}let F=30+(Math.round(n/255)<<2|Math.round(t/255)<<1|Math.round(e/255));if(o===2){F+=60}return F};r.hsv.ansi16=function(D){return r.rgb.ansi16(r.hsv.rgb(D),D[2])};r.rgb.ansi256=function(D){const u=D[0];const e=D[1];const t=D[2];if(u===e&&e===t){if(u<8){return 16}if(u>248){return 231}return Math.round((u-8)/247*24)+232}const n=16+36*Math.round(u/255*5)+6*Math.round(e/255*5)+Math.round(t/255*5);return n};r.ansi16.rgb=function(D){let u=D%10;if(u===0||u===7){if(D>50){u+=3.5}u=u/10.5*255;return[u,u,u]}const e=(~~(D>50)+1)*.5;const t=(u&1)*e*255;const n=(u>>1&1)*e*255;const r=(u>>2&1)*e*255;return[t,n,r]};r.ansi256.rgb=function(D){if(D>=232){const u=(D-232)*10+8;return[u,u,u]}D-=16;let u;const e=Math.floor(D/36)/5*255;const t=Math.floor((u=D%36)/6)/5*255;const n=u%6/5*255;return[e,t,n]};r.rgb.hex=function(D){const u=((Math.round(D[0])&255)<<16)+((Math.round(D[1])&255)<<8)+(Math.round(D[2])&255);const e=u.toString(16).toUpperCase();return"000000".substring(e.length)+e};r.hex.rgb=function(D){const u=D.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!u){return[0,0,0]}let e=u[0];if(u[0].length===3){e=e.split("").map((D=>D+D)).join("")}const t=parseInt(e,16);const n=t>>16&255;const r=t>>8&255;const o=t&255;return[n,r,o]};r.rgb.hcg=function(D){const u=D[0]/255;const e=D[1]/255;const t=D[2]/255;const n=Math.max(Math.max(u,e),t);const r=Math.min(Math.min(u,e),t);const o=n-r;let F;let s;if(o<1){F=r/(1-o)}else{F=0}if(o<=0){s=0}else if(n===u){s=(e-t)/o%6}else if(n===e){s=2+(t-u)/o}else{s=4+(u-e)/o}s/=6;s%=1;return[s*360,o*100,F*100]};r.hsl.hcg=function(D){const u=D[1]/100;const e=D[2]/100;const t=e<.5?2*u*e:2*u*(1-e);let n=0;if(t<1){n=(e-.5*t)/(1-t)}return[D[0],t*100,n*100]};r.hsv.hcg=function(D){const u=D[1]/100;const e=D[2]/100;const t=u*e;let n=0;if(t<1){n=(e-t)/(1-t)}return[D[0],t*100,n*100]};r.hcg.rgb=function(D){const u=D[0]/360;const e=D[1]/100;const t=D[2]/100;if(e===0){return[t*255,t*255,t*255]}const n=[0,0,0];const r=u%1*6;const o=r%1;const F=1-o;let s=0;switch(Math.floor(r)){case 0:n[0]=1;n[1]=o;n[2]=0;break;case 1:n[0]=F;n[1]=1;n[2]=0;break;case 2:n[0]=0;n[1]=1;n[2]=o;break;case 3:n[0]=0;n[1]=F;n[2]=1;break;case 4:n[0]=o;n[1]=0;n[2]=1;break;default:n[0]=1;n[1]=0;n[2]=F}s=(1-e)*t;return[(e*n[0]+s)*255,(e*n[1]+s)*255,(e*n[2]+s)*255]};r.hcg.hsv=function(D){const u=D[1]/100;const e=D[2]/100;const t=u+e*(1-u);let n=0;if(t>0){n=u/t}return[D[0],n*100,t*100]};r.hcg.hsl=function(D){const u=D[1]/100;const e=D[2]/100;const t=e*(1-u)+.5*u;let n=0;if(t>0&&t<.5){n=u/(2*t)}else if(t>=.5&&t<1){n=u/(2*(1-t))}return[D[0],n*100,t*100]};r.hcg.hwb=function(D){const u=D[1]/100;const e=D[2]/100;const t=u+e*(1-u);return[D[0],(t-u)*100,(1-t)*100]};r.hwb.hcg=function(D){const u=D[1]/100;const e=D[2]/100;const t=1-e;const n=t-u;let r=0;if(n<1){r=(t-n)/(1-n)}return[D[0],n*100,r*100]};r.apple.rgb=function(D){return[D[0]/65535*255,D[1]/65535*255,D[2]/65535*255]};r.rgb.apple=function(D){return[D[0]/255*65535,D[1]/255*65535,D[2]/255*65535]};r.gray.rgb=function(D){return[D[0]/100*255,D[0]/100*255,D[0]/100*255]};r.gray.hsl=function(D){return[0,0,D[0]]};r.gray.hsv=r.gray.hsl;r.gray.hwb=function(D){return[0,100,D[0]]};r.gray.cmyk=function(D){return[0,0,0,D[0]]};r.gray.lab=function(D){return[D[0],0,0]};r.gray.hex=function(D){const u=Math.round(D[0]/100*255)&255;const e=(u<<16)+(u<<8)+u;const t=e.toString(16).toUpperCase();return"000000".substring(t.length)+t};r.rgb.gray=function(D){const u=(D[0]+D[1]+D[2])/3;return[u/255*100]}},767:(D,u,e)=>{const t=e(226);const n=e(392);const r={};const o=Object.keys(t);function wrapRaw(D){const wrappedFn=function(...u){const e=u[0];if(e===undefined||e===null){return e}if(e.length>1){u=e}return D(u)};if("conversion"in D){wrappedFn.conversion=D.conversion}return wrappedFn}function wrapRounded(D){const wrappedFn=function(...u){const e=u[0];if(e===undefined||e===null){return e}if(e.length>1){u=e}const t=D(u);if(typeof t==="object"){for(let D=t.length,u=0;u{r[D]={};Object.defineProperty(r[D],"channels",{value:t[D].channels});Object.defineProperty(r[D],"labels",{value:t[D].labels});const u=n(D);const e=Object.keys(u);e.forEach((e=>{const t=u[e];r[D][e]=wrapRounded(t);r[D][e].raw=wrapRaw(t)}))}));D.exports=r},392:(D,u,e)=>{const t=e(226);function buildGraph(){const D={};const u=Object.keys(t);for(let e=u.length,t=0;t{"use strict";D.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}},331:D=>{"use strict";D.exports=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g}},82:D=>{"use strict";const isFullwidthCodePoint=D=>{if(Number.isNaN(D)){return false}if(D>=4352&&(D<=4447||D===9001||D===9002||11904<=D&&D<=12871&&D!==12351||12880<=D&&D<=19903||19968<=D&&D<=42182||43360<=D&&D<=43388||44032<=D&&D<=55203||63744<=D&&D<=64255||65040<=D&&D<=65049||65072<=D&&D<=65131||65281<=D&&D<=65376||65504<=D&&D<=65510||110592<=D&&D<=110593||127488<=D&&D<=127569||131072<=D&&D<=262141)){return true}return false};D.exports=isFullwidthCodePoint;D.exports["default"]=isFullwidthCodePoint},770:(D,u,e)=>{"use strict";const t=e(82);const n=e(788);const r=e(44);const o=["","›"];const wrapAnsi=D=>`${o[0]}[${D}m`;const checkAnsi=(D,u,e)=>{let t=[];D=[...D];for(let e of D){const n=e;if(e.match(";")){e=e.split(";")[0][0]+"0"}const o=r.codes.get(parseInt(e,10));if(o){const e=D.indexOf(o.toString());if(e>=0){D.splice(e,1)}else{t.push(wrapAnsi(u?o:n))}}else if(u){t.push(wrapAnsi(0));break}else{t.push(wrapAnsi(n))}}if(u){t=t.filter(((D,u)=>t.indexOf(D)===u));if(e!==undefined){const D=wrapAnsi(r.codes.get(parseInt(e,10)));t=t.reduce(((u,e)=>e===D?[e,...u]:[...u,e]),[])}}return t.join("")};D.exports=(D,u,e)=>{const r=[...D.normalize()];const F=[];e=typeof e==="number"?e:r.length;let s=false;let c;let C=0;let i="";for(const[l,a]of r.entries()){let r=false;if(o.includes(a)){const u=/\d[^m]*/.exec(D.slice(l,l+18));c=u&&u.length>0?u[0]:undefined;if(Cu&&C<=e){i+=a}else if(C===u&&!s&&c!==undefined){i=checkAnsi(F)}else if(C>=e){i+=checkAnsi(F,true,c);break}}return i}},629:(D,u,e)=>{"use strict";const t=e(647);const n=e(82);const r=e(331);const stringWidth=D=>{if(typeof D!=="string"||D.length===0){return 0}D=t(D);if(D.length===0){return 0}D=D.replace(r()," ");let u=0;for(let e=0;e=127&&t<=159){continue}if(t>=768&&t<=879){continue}if(t>65535){e++}u+=n(t)?2:1}return u};D.exports=stringWidth;D.exports["default"]=stringWidth},647:(D,u,e)=>{"use strict";const t=e(275);D.exports=D=>typeof D==="string"?D.replace(t(),""):D}};var u={};function __nccwpck_require__(e){var t=u[e];if(t!==undefined){return t.exports}var n=u[e]={id:e,loaded:false,exports:{}};var r=true;try{D[e](n,n.exports,__nccwpck_require__);r=false}finally{if(r)delete u[e]}n.loaded=true;return n.exports}(()=>{__nccwpck_require__.nmd=D=>{D.paths=[];if(!D.children)D.children=[];return D}})();if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var e=__nccwpck_require__(922);module.exports=e})(); \ No newline at end of file diff --git a/packages/compat/webpack/compiled/cli-truncate/license b/packages/compat/webpack/compiled/cli-truncate/license deleted file mode 100644 index e7af2f7710..0000000000 --- a/packages/compat/webpack/compiled/cli-truncate/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/compat/webpack/compiled/cli-truncate/package.json b/packages/compat/webpack/compiled/cli-truncate/package.json deleted file mode 100644 index 435b24814d..0000000000 --- a/packages/compat/webpack/compiled/cli-truncate/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"cli-truncate","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"version":"2.1.0","funding":"https://github.com/sponsors/sindresorhus","license":"MIT"} diff --git a/packages/compat/webpack/compiled/copy-webpack-plugin/index.d.ts b/packages/compat/webpack/compiled/copy-webpack-plugin/index.d.ts deleted file mode 100644 index a2ac5f9bc2..0000000000 --- a/packages/compat/webpack/compiled/copy-webpack-plugin/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export = any; diff --git a/packages/compat/webpack/compiled/copy-webpack-plugin/index.js b/packages/compat/webpack/compiled/copy-webpack-plugin/index.js deleted file mode 100644 index 3f4c4903b6..0000000000 --- a/packages/compat/webpack/compiled/copy-webpack-plugin/index.js +++ /dev/null @@ -1,22 +0,0 @@ -(()=>{var e={793:(e,t,r)=>{"use strict";const n=r(897);e.exports=n.default},897:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});t["default"]=void 0;var n=_interopRequireDefault(r(17));var o=r(739);var i=_interopRequireDefault(r(937));var a=_interopRequireDefault(r(327));var s=_interopRequireDefault(r(498));var c=_interopRequireDefault(r(677));var u=_interopRequireDefault(r(7));var f=r(684);var l=_interopRequireDefault(r(452));var p=r(552);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const d=/\[\\*([\w:]+)\\*\]/i;class CopyPlugin{constructor(e={}){(0,o.validate)(l.default,e,{name:"Copy Plugin",baseDataPath:"options"});this.patterns=e.patterns;this.options=e.options||{}}static async createSnapshot(e,t,r){return new Promise(((n,o)=>{e.fileSystemInfo.createSnapshot(t,[r],undefined,undefined,null,((e,t)=>{if(e){o(e);return}n(t)}))}))}static async checkSnapshotValid(e,t){return new Promise(((r,n)=>{e.fileSystemInfo.checkSnapshotValid(t,((e,t)=>{if(e){n(e);return}r(t)}))}))}static getContentHash(e,t,r){const{outputOptions:n}=t;const{hashDigest:o,hashDigestLength:i,hashFunction:a,hashSalt:s}=n;const c=e.webpack.util.createHash(a);if(s){c.update(s)}c.update(r);const u=c.digest(o);return u.slice(0,i)}static async runPattern(e,t,o,l,g,h){const{RawSource:m}=e.webpack.sources;const b=typeof g==="string"?{from:g}:{...g};b.fromOrigin=b.from;b.from=n.default.normalize(b.from);b.context=typeof b.context==="undefined"?e.context:n.default.isAbsolute(b.context)?b.context:n.default.join(e.context,b.context);o.log(`starting to process a pattern from '${b.from}' using '${b.context}' context`);if(n.default.isAbsolute(b.from)){b.absoluteFrom=b.from}else{b.absoluteFrom=n.default.resolve(b.context,b.from)}o.debug(`getting stats for '${b.absoluteFrom}'...`);const{inputFileSystem:y}=e;let w;try{w=await(0,p.stat)(y,b.absoluteFrom)}catch(e){}if(w){if(w.isDirectory()){b.fromType="dir";o.debug(`determined '${b.absoluteFrom}' is a directory`)}else if(w.isFile()){b.fromType="file";o.debug(`determined '${b.absoluteFrom}' is a file`)}else{o.debug(`determined '${b.absoluteFrom}' is a glob`)}}b.globOptions={...{followSymbolicLinks:true},...b.globOptions||{},...{cwd:b.context,objectMode:true}};b.globOptions.fs=y;switch(b.fromType){case"dir":t.contextDependencies.add(b.absoluteFrom);o.debug(`added '${b.absoluteFrom}' as a context dependency`);b.context=b.absoluteFrom;b.glob=n.default.posix.join(u.default.escapePath((0,s.default)(n.default.resolve(b.absoluteFrom))),"**/*");b.absoluteFrom=n.default.join(b.absoluteFrom,"**/*");if(typeof b.globOptions.dot==="undefined"){b.globOptions.dot=true}break;case"file":t.fileDependencies.add(b.absoluteFrom);o.debug(`added '${b.absoluteFrom}' as a file dependency`);b.context=n.default.dirname(b.absoluteFrom);b.glob=u.default.escapePath((0,s.default)(n.default.resolve(b.absoluteFrom)));if(typeof b.globOptions.dot==="undefined"){b.globOptions.dot=true}break;default:{const e=n.default.normalize((0,c.default)(b.absoluteFrom));t.contextDependencies.add(e);o.debug(`added '${e}' as a context dependency`);b.fromType="glob";b.glob=n.default.isAbsolute(b.fromOrigin)?b.fromOrigin:n.default.posix.join(u.default.escapePath((0,s.default)(n.default.resolve(b.context))),b.fromOrigin)}}o.log(`begin globbing '${b.glob}'...`);let v;try{v=await(0,i.default)(b.glob,b.globOptions)}catch(e){t.errors.push(e);return}if(v.length===0){if(b.noErrorOnMissing){o.log(`finished to process a pattern from '${b.from}' using '${b.context}' context to '${b.to}'`);return}const e=new Error(`unable to locate '${b.glob}' glob`);t.errors.push(e);return}const x=(await Promise.all(v.map((async e=>{if(!e.dirent.isFile()){return false}if(b.filter){let r;try{r=await b.filter(e.path)}catch(e){t.errors.push(e);return false}if(!r){o.log(`skip '${e.path}', because it was filtered`)}return r?e:false}return e})))).filter((e=>e));if(x.length===0){if(b.noErrorOnMissing){o.log(`finished to process a pattern from '${b.from}' using '${b.context}' context to '${b.to}'`);return}const e=new Error(`unable to locate '${b.glob}' glob after filtering paths`);t.errors.push(e);return}const k=await Promise.all(x.map((async t=>{const r=t.path;o.debug(`found '${r}'`);const i=n.default.resolve(b.context,r);b.to=typeof b.to==="function"?await b.to({context:b.context,absoluteFilename:i}):n.default.normalize(typeof b.to!=="undefined"?b.to:"");const a=n.default.extname(b.to)===""||b.to.slice(-1)===n.default.sep;const c=b.toType?b.toType:d.test(b.to)?"template":a?"dir":"file";o.log(`'to' option '${b.to}' determinated as '${c}'`);const u=n.default.relative(b.context,i);let f=c==="dir"?n.default.join(b.to,u):b.to;if(n.default.isAbsolute(f)){f=n.default.relative(e.options.output.path,f)}o.log(`determined that '${r}' should write to '${f}'`);const l=(0,s.default)(n.default.relative(e.context,i));return{absoluteFilename:i,sourceFilename:l,filename:f,toType:c}})));let _;try{_=await Promise.all(k.map((async i=>{const{absoluteFilename:c,sourceFilename:u,filename:d,toType:g}=i;const w=typeof b.info==="function"?b.info(i)||{}:b.info||{};const v={absoluteFilename:c,sourceFilename:u,filename:d,force:b.force,info:w};if(b.fromType==="dir"||b.fromType==="glob"){t.fileDependencies.add(c);o.debug(`added '${c}' as a file dependency`)}let x;o.debug(`getting cache for '${c}'...`);try{x=await l.getPromise(`${u}|${h}`,null)}catch(e){t.errors.push(e);return}if(x){o.debug(`found cache for '${c}'...`);let e;o.debug(`checking snapshot on valid for '${c}'...`);try{e=await CopyPlugin.checkSnapshotValid(t,x.snapshot)}catch(e){t.errors.push(e);return}if(e){o.debug(`snapshot for '${c}' is valid`);v.source=x.source}else{o.debug(`snapshot for '${c}' is invalid`)}}else{o.debug(`missed cache for '${c}'`)}if(!v.source){const e=Date.now();o.debug(`reading '${c}'...`);let r;try{r=await(0,p.readFile)(y,c)}catch(e){t.errors.push(e);return}o.debug(`read '${c}'`);v.source=new m(r);let n;o.debug(`creating snapshot for '${c}'...`);try{n=await CopyPlugin.createSnapshot(t,e,c)}catch(e){t.errors.push(e);return}if(n){o.debug(`created snapshot for '${c}'`);o.debug(`storing cache for '${c}'...`);try{await l.storePromise(`${u}|${h}`,null,{source:v.source,snapshot:n})}catch(e){t.errors.push(e);return}o.debug(`stored cache for '${c}'`)}}if(b.transform){const t=typeof b.transform==="function"?{transformer:b.transform}:b.transform;if(t.transformer){o.log(`transforming content for '${c}'...`);const n=v.source.buffer();if(t.cache){const i=e.webpack&&e.webpack.util&&e.webpack.util.createHash?e.webpack.util.createHash("xxhash64"):r(113).createHash("md4");const s={version:f.version,sourceFilename:u,transform:t.transformer,contentHash:i.update(n).digest("hex"),index:h};const p=`transform|${(0,a.default)(typeof t.cache.keys==="function"?await t.cache.keys(s,c):{...s,...b.transform.cache.keys})}`;o.debug(`getting transformation cache for '${c}'...`);const d=l.getItemCache(p,l.getLazyHashedEtag(v.source));v.source=await d.getPromise();o.debug(v.source?`found transformation cache for '${c}'`:`no transformation cache for '${c}'`);if(!v.source){const e=await t.transformer(n,c);v.source=new m(e);o.debug(`caching transformation for '${c}'...`);await d.storePromise(v.source);o.debug(`cached transformation for '${c}'`)}}else{v.source=new m(await t.transformer(n,c))}}}if(g==="template"){o.log(`interpolating template '${d}' for '${u}'...`);const r=CopyPlugin.getContentHash(e,t,v.source.buffer());const i=n.default.extname(v.sourceFilename);const a=n.default.basename(v.sourceFilename);const f=a.slice(0,a.length-i.length);const l={filename:(0,s.default)(n.default.relative(b.context,c)),contentHash:r,chunk:{name:f,id:v.sourceFilename,hash:r,contentHash:r}};const{path:p,info:g}=t.getPathWithInfo((0,s.default)(v.filename),l);v.info={...v.info,...g};v.filename=p;o.log(`interpolated template '${d}' for '${u}'`)}else{v.filename=(0,s.default)(v.filename)}return v})))}catch(e){t.errors.push(e);return}o.log(`finished to process a pattern from '${b.from}' using '${b.context}' context to '${b.to}'`);return _}apply(e){const t=this.constructor.name;e.hooks.thisCompilation.tap(t,(r=>{const n=r.getLogger("copy-webpack-plugin");const o=r.getCache("CopyWebpackPlugin");r.hooks.processAssets.tapAsync({name:"copy-webpack-plugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL},(async(t,i)=>{n.log("starting to add additional assets...");const c=new Map;const u=[];this.patterns.map(((t,i)=>u.push((async()=>{let u;try{u=await CopyPlugin.runPattern(e,r,n,o,t,i)}catch(e){r.errors.push(e);return}if(u&&u.length>0){if(t.transformAll){if(typeof t.to==="undefined"){r.errors.push(new Error(`Invalid "pattern.to" for the "pattern.from": "${t.from}" and "pattern.transformAll" function. The "to" option must be specified.`));return}u.sort(((e,t)=>e.absoluteFilename>t.absoluteFilename?1:e.absoluteFilename{e=o.mergeEtags(r===1?o.getLazyHashedEtag(e.source.buffer()):e,o.getLazyHashedEtag(t.source.buffer()));return e}));const i=`transformAll|${(0,a.default)({version:f.version,from:t.from,to:t.to,transformAll:t.transformAll})}`;const c=o.getLazyHashedEtag(n);const l=o.getItemCache(i,c);let p=await l.getPromise();if(!p){p={filename:t.to};try{p.data=await t.transformAll(u.map((e=>({data:e.source.buffer(),sourceFilename:e.sourceFilename,absoluteFilename:e.absoluteFilename}))))}catch(e){r.errors.push(e);return}if(d.test(t.to)){const n=CopyPlugin.getContentHash(e,r,p.data);const{path:o,info:i}=r.getPathWithInfo((0,s.default)(t.to),{contentHash:n,chunk:{hash:n,contentHash:n}});p.filename=o;p.info=i}const{RawSource:n}=e.webpack.sources;p.source=new n(p.data);p.force=t.force;await l.storePromise(p)}u=[p]}const n=t.priority||0;if(!c.has(n)){c.set(n,[])}c.get(n).push(...u)}}))));await(0,p.throttleAll)(this.options.concurrency||100,u);const l=[...c.entries()].sort(((e,t)=>e[0]-t[0]));l.reduce(((e,t)=>e.concat(t[1])),[]).filter(Boolean).forEach((e=>{const{absoluteFilename:t,sourceFilename:o,filename:i,source:a,force:s}=e;const c=r.getAsset(i);if(c){if(s){const s={copied:true,sourceFilename:o};n.log(`force updating '${i}' from '${t}' to compilation assets, because it already exists...`);r.updateAsset(i,a,{...s,...e.info});n.log(`force updated '${i}' from '${t}' to compilation assets, because it already exists`);return}n.log(`skip adding '${i}' from '${t}' to compilation assets, because it already exists`);return}const u={copied:true,sourceFilename:o};n.log(`writing '${i}' from '${t}' to compilation assets...`);r.emitAsset(i,a,{...u,...e.info});n.log(`written '${i}' from '${t}' to compilation assets`)}));n.log("finished to adding additional assets");i()}));if(r.hooks.statsPrinter){r.hooks.statsPrinter.tap(t,(e=>{e.hooks.print.for("asset.info.copied").tap("copy-webpack-plugin",((e,{green:t,formatFlag:r})=>e?t(r("copied")):undefined))}))}}))}}var g=CopyPlugin;t["default"]=g},552:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:true});t.readFile=readFile;t.stat=stat;t.throttleAll=throttleAll;function stat(e,t){return new Promise(((r,n)=>{e.stat(t,((e,t)=>{if(e){n(e)}r(t)}))}))}function readFile(e,t){return new Promise(((r,n)=>{e.readFile(t,((e,t)=>{if(e){n(e)}r(t)}))}))}const r=Symbol(`not-settled`);function throttleAll(e,t){if(!Number.isInteger(e)||e<1){throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${e}\` (${typeof e})`)}if(!Array.isArray(t)||!t.every((e=>typeof e===`function`))){throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`)}return new Promise(((n,o)=>{const i=Array(t.length).fill(r);const a=t.entries();const next=()=>{const{done:e,value:t}=a.next();if(e){const e=!i.includes(r);if(e){n(i)}return}const[s,c]=t;const onFulfilled=e=>{i[s]=e;next()};c().then(onFulfilled,o)};Array(e).fill(0).forEach(next)}))}},677:(e,t,r)=>{"use strict";var n=r(654);var o=r(17).posix.dirname;var i=r(37).platform()==="win32";var a="/";var s=/\\/g;var c=/\\([!*?|[\](){}])/g;e.exports=function globParent(e,t){var r=Object.assign({flipBackslashes:true},t);if(r.flipBackslashes&&i&&e.indexOf(a)<0){e=e.replace(s,a)}if(isEnclosure(e)){e+=a}e+="a";do{e=o(e)}while(isGlobby(e));return e.replace(c,"$1")};function isEnclosure(e){var t=e.slice(-1);var r;switch(t){case"}":r="{";break;case"]":r="[";break;default:return false}var n=e.indexOf(r);if(n<0){return false}return e.slice(n+1,-1).includes(a)}function isGlobby(e){if(/\([^()]+$/.test(e)){return true}if(e[0]==="{"||e[0]==="["){return true}if(/[^\\][{[]/.test(e)){return true}return n(e)}},71:e=>{ -/*! - * is-extglob - * - * Copyright (c) 2014-2016, Jon Schlinkert. - * Licensed under the MIT License. - */ -e.exports=function isExtglob(e){if(typeof e!=="string"||e===""){return false}var t;while(t=/(\\).|([@?!+*]\(.*\))/g.exec(e)){if(t[2])return true;e=e.slice(t.index+t[0].length)}return false}},654:(e,t,r)=>{ -/*! - * is-glob - * - * Copyright (c) 2014-2017, Jon Schlinkert. - * Released under the MIT License. - */ -var n=r(71);var o={"{":"}","(":")","[":"]"};var strictCheck=function(e){if(e[0]==="!"){return true}var t=0;var r=-2;var n=-2;var i=-2;var a=-2;var s=-2;while(tt){if(s===-1||s>n){return true}s=e.indexOf("\\",t);if(s===-1||s>n){return true}}}if(i!==-1&&e[t]==="{"&&e[t+1]!=="}"){i=e.indexOf("}",t);if(i>t){s=e.indexOf("\\",t);if(s===-1||s>i){return true}}}if(a!==-1&&e[t]==="("&&e[t+1]==="?"&&/[:!=]/.test(e[t+2])&&e[t+3]!==")"){a=e.indexOf(")",t);if(a>t){s=e.indexOf("\\",t);if(s===-1||s>a){return true}}}if(r!==-1&&e[t]==="("&&e[t+1]!=="|"){if(rr){s=e.indexOf("\\",r);if(s===-1||s>a){return true}}}}if(e[t]==="\\"){var c=e[t+1];t+=2;var u=o[c];if(u){var f=e.indexOf(u,t);if(f!==-1){t=f+1}}if(e[t]==="!"){return true}}else{t++}}return false};var relaxedCheck=function(e){if(e[0]==="!"){return true}var t=0;while(t{ -/*! - * normalize-path - * - * Copyright (c) 2014-2018, Jon Schlinkert. - * Released under the MIT License. - */ -e.exports=function(e,t){if(typeof e!=="string"){throw new TypeError("expected path to be a string")}if(e==="\\"||e==="/")return"/";var r=e.length;if(r<=1)return e;var n="";if(r>4&&e[3]==="\\"){var o=e[2];if((o==="?"||o===".")&&e.slice(0,2)==="\\\\"){e=e.slice(2);n="//"}}var i=e.split(/[/\\]+/);if(t!==false&&i[i.length-1]===""){i.pop()}return n+i.join("/")}},856:(e,t,r)=>{e.exports=r(113).randomBytes},327:(e,t,r)=>{"use strict";var n=r(856);var o=16;var i=generateUID();var a=new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-'+i+'-(\\d+)__@"',"g");var s=/\{\s*\[native code\]\s*\}/g;var c=/function.*?\(/;var u=/.*?=>.*?/;var f=/[<>\/\u2028\u2029]/g;var l=["*","async"];var p={"<":"\\u003C",">":"\\u003E","/":"\\u002F","\u2028":"\\u2028","\u2029":"\\u2029"};function escapeUnsafeChars(e){return p[e]}function generateUID(){var e=n(o);var t="";for(var r=0;r0}));var o=n.filter((function(e){return l.indexOf(e)===-1}));if(o.length>0){return(n.indexOf("async")>-1?"async ":"")+"function"+(n.join("").indexOf("*")>-1?"*":"")+t.substr(r)}return t}if(t.ignoreFunction&&typeof e==="function"){e=undefined}if(e===undefined){return String(e)}var w;if(t.isJSON&&!t.space){w=JSON.stringify(e)}else{w=JSON.stringify(e,t.isJSON?null:replacer,t.space)}if(typeof w!=="string"){return String(w)}if(t.unsafe!==true){w=w.replace(f,escapeUnsafeChars)}if(r.length===0&&n.length===0&&o.length===0&&p.length===0&&d.length===0&&g.length===0&&h.length===0&&m.length===0&&b.length===0&&y.length===0){return w}return w.replace(a,(function(e,i,a,s){if(i){return e}if(a==="D"){return'new Date("'+o[s].toISOString()+'")'}if(a==="R"){return"new RegExp("+serialize(n[s].source)+', "'+n[s].flags+'")'}if(a==="M"){return"new Map("+serialize(Array.from(p[s].entries()),t)+")"}if(a==="S"){return"new Set("+serialize(Array.from(d[s].values()),t)+")"}if(a==="A"){return"Array.prototype.slice.call("+serialize(Object.assign({length:g[s].length},g[s]),t)+")"}if(a==="U"){return"undefined"}if(a==="I"){return m[s]}if(a==="B"){return'BigInt("'+b[s]+'")'}if(a==="L"){return'new URL("'+y[s].toString()+'")'}var c=r[s];return serializeFunc(c)}))}},739:e=>{"use strict";e.exports=require("../schema-utils3")},684:e=>{"use strict";e.exports=require("./package.json")},7:e=>{"use strict";e.exports=require("fast-glob")},937:e=>{"use strict";e.exports=require("globby")},113:e=>{"use strict";e.exports=require("crypto")},37:e=>{"use strict";e.exports=require("os")},17:e=>{"use strict";e.exports=require("path")},452:e=>{"use strict";e.exports=JSON.parse('{"definitions":{"ObjectPattern":{"type":"object","additionalProperties":false,"properties":{"from":{"type":"string","description":"Glob or path from where we copy files.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#from","minLength":1},"to":{"anyOf":[{"type":"string"},{"instanceof":"Function"}],"description":"Output path.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#to"},"context":{"type":"string","description":"A path that determines how to interpret the \'from\' path.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#context"},"globOptions":{"type":"object","description":"Allows to configute the glob pattern matching library used by the plugin.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#globoptions"},"filter":{"instanceof":"Function","description":"Allows to filter copied assets.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#filter"},"transformAll":{"instanceof":"Function","description":"Allows you to modify the contents of multiple files and save the result to one file.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#transformall"},"toType":{"enum":["dir","file","template"],"description":"Determinate what is to option - directory, file or template.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#totype"},"force":{"type":"boolean","description":"Overwrites files already in \'compilation.assets\' (usually added by other plugins/loaders).","link":"https://github.com/webpack-contrib/copy-webpack-plugin#force"},"priority":{"type":"number","description":"Allows to specify the priority of copying files with the same destination name.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#priority"},"info":{"anyOf":[{"type":"object"},{"instanceof":"Function"}],"description":"Allows to add assets info.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#info"},"transform":{"description":"Allows to modify the file contents.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#transform","anyOf":[{"instanceof":"Function"},{"type":"object","additionalProperties":false,"properties":{"transformer":{"instanceof":"Function","description":"Allows to modify the file contents.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#transformer"},"cache":{"description":"Enables/disables and configure caching.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#cache","anyOf":[{"type":"boolean"},{"type":"object","additionalProperties":false,"properties":{"keys":{"anyOf":[{"type":"object","additionalProperties":true},{"instanceof":"Function"}]}}}]}}}]},"transformPath":{"instanceof":"Function"},"noErrorOnMissing":{"type":"boolean","description":"Doesn\'t generate an error on missing file(s).","link":"https://github.com/webpack-contrib/copy-webpack-plugin#noerroronmissing"}},"required":["from"]},"StringPattern":{"type":"string","minLength":1}},"type":"object","additionalProperties":false,"properties":{"patterns":{"type":"array","minItems":1,"items":{"anyOf":[{"$ref":"#/definitions/StringPattern"},{"$ref":"#/definitions/ObjectPattern"}]}},"options":{"type":"object","additionalProperties":false,"properties":{"concurrency":{"type":"number","description":"Limits the number of simultaneous requests to fs.","link":"https://github.com/webpack-contrib/copy-webpack-plugin#concurrency"}}}},"required":["patterns"]}')}};var t={};function __nccwpck_require__(r){var n=t[r];if(n!==undefined){return n.exports}var o=t[r]={exports:{}};var i=true;try{e[r](o,o.exports,__nccwpck_require__);i=false}finally{if(i)delete t[r]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r=__nccwpck_require__(793);module.exports=r})(); \ No newline at end of file diff --git a/packages/compat/webpack/compiled/copy-webpack-plugin/license b/packages/compat/webpack/compiled/copy-webpack-plugin/license deleted file mode 100644 index 8c11fc7289..0000000000 --- a/packages/compat/webpack/compiled/copy-webpack-plugin/license +++ /dev/null @@ -1,20 +0,0 @@ -Copyright JS Foundation and other contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/compat/webpack/compiled/copy-webpack-plugin/package.json b/packages/compat/webpack/compiled/copy-webpack-plugin/package.json deleted file mode 100644 index 1fedf3037b..0000000000 --- a/packages/compat/webpack/compiled/copy-webpack-plugin/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"copy-webpack-plugin","author":"Len Boyette","version":"9.1.0","funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"license":"MIT","types":"index.d.ts"} diff --git a/packages/compat/webpack/compiled/patch-console/build/index.d.ts b/packages/compat/webpack/compiled/patch-console/build/index.d.ts deleted file mode 100644 index 314bb1b1b3..0000000000 --- a/packages/compat/webpack/compiled/patch-console/build/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare type Callback = (stream: 'stdout' | 'stderr', data: string) => void; -declare type Restore = () => void; -declare const patchConsole: (callback: Callback) => Restore; -export = patchConsole; diff --git a/packages/compat/webpack/compiled/patch-console/index.js b/packages/compat/webpack/compiled/patch-console/index.js deleted file mode 100644 index 458fd0ab5e..0000000000 --- a/packages/compat/webpack/compiled/patch-console/index.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var e={130:(e,r,o)=>{const t=o(781);const s=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"];let n={};const patchConsole=e=>{const r=new t.PassThrough;const o=new t.PassThrough;r.write=r=>e("stdout",r);o.write=r=>e("stderr",r);const _=new console.Console(r,o);for(const e of s){n[e]=console[e];console[e]=_[e]}return()=>{for(const e of s){console[e]=n[e]}n={}}};e.exports=patchConsole},781:e=>{e.exports=require("stream")}};var r={};function __nccwpck_require__(o){var t=r[o];if(t!==undefined){return t.exports}var s=r[o]={exports:{}};var n=true;try{e[o](s,s.exports,__nccwpck_require__);n=false}finally{if(n)delete r[o]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var o=__nccwpck_require__(130);module.exports=o})(); \ No newline at end of file diff --git a/packages/compat/webpack/compiled/patch-console/package.json b/packages/compat/webpack/compiled/patch-console/package.json deleted file mode 100644 index 0229f3899c..0000000000 --- a/packages/compat/webpack/compiled/patch-console/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"patch-console","author":{"name":"vdemedes","email":"vdemedes@gmail.com","url":"https://github.com/vadimdemedes"},"version":"1.0.0","license":"MIT","types":"build/index.d.ts"} diff --git a/packages/compat/webpack/compiled/schema-utils3/index.d.ts b/packages/compat/webpack/compiled/schema-utils3/index.d.ts deleted file mode 100644 index a2ac5f9bc2..0000000000 --- a/packages/compat/webpack/compiled/schema-utils3/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export = any; diff --git a/packages/compat/webpack/compiled/schema-utils3/index.js b/packages/compat/webpack/compiled/schema-utils3/index.js deleted file mode 100644 index d5aa92acd6..0000000000 --- a/packages/compat/webpack/compiled/schema-utils3/index.js +++ /dev/null @@ -1,3 +0,0 @@ -(()=>{var e={4133:(e,r,t)=>{"use strict";var a=t(5507);e.exports=defineKeywords;function defineKeywords(e,r){if(Array.isArray(r)){for(var t=0;t{"use strict";var a=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i;var s=/t|\s/i;var i={date:compareDate,time:compareTime,"date-time":compareDateTime};var o={type:"object",required:["$data"],properties:{$data:{type:"string",anyOf:[{format:"relative-json-pointer"},{format:"json-pointer"}]}},additionalProperties:false};e.exports=function(e){var r="format"+e;return function defFunc(a){defFunc.definition={type:"string",inline:t(6516),statements:true,errors:"full",dependencies:["format"],metaSchema:{anyOf:[{type:"string"},o]}};a.addKeyword(r,defFunc.definition);a.addKeyword("formatExclusive"+e,{dependencies:["format"+e],metaSchema:{anyOf:[{type:"boolean"},o]}});extendFormats(a);return a}};function extendFormats(e){var r=e._formats;for(var t in i){var a=r[t];if(typeof a!="object"||a instanceof RegExp||!a.validate)a=r[t]={validate:a};if(!a.compare)a.compare=i[t]}}function compareDate(e,r){if(!(e&&r))return;if(e>r)return 1;if(er)return 1;if(e{"use strict";e.exports={metaSchemaRef:metaSchemaRef};var r="http://json-schema.org/draft-07/schema";function metaSchemaRef(e){var t=e._opts.defaultMeta;if(typeof t=="string")return{$ref:t};if(e.getSchema(r))return{$ref:r};console.warn("meta schema not defined");return{}}},3672:e=>{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"object",macro:function(e,r){if(!e)return true;var t=Object.keys(r.properties);if(t.length==0)return true;return{required:t}},metaSchema:{type:"boolean"},dependencies:["properties"]};e.addKeyword("allRequired",defFunc.definition);return e}},2390:e=>{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"object",macro:function(e){if(e.length==0)return true;if(e.length==1)return{required:e};var r=e.map((function(e){return{required:[e]}}));return{anyOf:r}},metaSchema:{type:"array",items:{type:"string"}}};e.addKeyword("anyRequired",defFunc.definition);return e}},9357:(e,r,t)=>{"use strict";var a=t(2298);e.exports=function defFunc(e){defFunc.definition={type:"object",macro:function(e){var r=[];for(var t in e)r.push(getSchema(t,e[t]));return{allOf:r}},metaSchema:{type:"object",propertyNames:{type:"string",format:"json-pointer"},additionalProperties:a.metaSchemaRef(e)}};e.addKeyword("deepProperties",defFunc.definition);return e};function getSchema(e,r){var t=e.split("/");var a={};var s=a;for(var i=1;i{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"object",inline:function(e,r,t){var a="";for(var s=0;s{"use strict";e.exports=function generate__formatLimit(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f;var c="data"+(i||"");var h="valid"+s;a+="var "+h+" = undefined;";if(e.opts.format===false){a+=" "+h+" = true; ";return a}var d=e.schema.format,p=e.opts.$data&&d.$data,m="";if(p){var g=e.util.getData(d.$data,i,e.dataPathArr),y="format"+s,P="compare"+s;a+=" var "+y+" = formats["+g+"] , "+P+" = "+y+" && "+y+".compare;"}else{var y=e.formats[d];if(!(y&&y.compare)){a+=" "+h+" = true; ";return a}var P="formats"+e.util.getProperty(d)+".compare"}var b=r=="formatMaximum",E="formatExclusive"+(b?"Maximum":"Minimum"),S=e.schema[E],w=e.opts.$data&&S&&S.$data,x=b?"<":">",$="result"+s;var _=e.opts.$data&&o&&o.$data,R;if(_){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";R="schema"+s}else{R=o}if(w){var F=e.util.getData(S.$data,i,e.dataPathArr),O="exclusive"+s,D="op"+s,j="' + "+D+" + '";a+=" var schemaExcl"+s+" = "+F+"; ";F="schemaExcl"+s;a+=" if (typeof "+F+" != 'boolean' && "+F+" !== undefined) { "+h+" = false; ";var f=E;var I=I||[];I.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_formatExclusiveLimit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: {} ";if(e.opts.messages!==false){a+=" , message: '"+E+" should be boolean' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var k=a;a=I.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+k+"]); "}else{a+=" validate.errors = ["+k+"]; return false; "}}else{a+=" var err = "+k+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } ";if(u){m+="}";a+=" else { "}if(_){a+=" if ("+R+" === undefined) "+h+" = true; else if (typeof "+R+" != 'string') "+h+" = false; else { ";m+="}"}if(p){a+=" if (!"+P+") "+h+" = true; else { ";m+="}"}a+=" var "+$+" = "+P+"("+c+", ";if(_){a+=""+R}else{a+=""+e.util.toQuotedString(o)}a+=" ); if ("+$+" === undefined) "+h+" = false; var "+O+" = "+F+" === true; if ("+h+" === undefined) { "+h+" = "+O+" ? "+$+" "+x+" 0 : "+$+" "+x+"= 0; } if (!"+h+") var op"+s+" = "+O+" ? '"+x+"' : '"+x+"=';"}else{var O=S===true,j=x;if(!O)j+="=";var D="'"+j+"'";if(_){a+=" if ("+R+" === undefined) "+h+" = true; else if (typeof "+R+" != 'string') "+h+" = false; else { ";m+="}"}if(p){a+=" if (!"+P+") "+h+" = true; else { ";m+="}"}a+=" var "+$+" = "+P+"("+c+", ";if(_){a+=""+R}else{a+=""+e.util.toQuotedString(o)}a+=" ); if ("+$+" === undefined) "+h+" = false; if ("+h+" === undefined) "+h+" = "+$+" "+x;if(!O){a+="="}a+=" 0;"}a+=""+m+"if (!"+h+") { ";var f=r;var I=I||[];I.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_formatLimit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { comparison: "+D+", limit: ";if(_){a+=""+R}else{a+=""+e.util.toQuotedString(o)}a+=" , exclusive: "+O+" } ";if(e.opts.messages!==false){a+=" , message: 'should be "+j+' "';if(_){a+="' + "+R+" + '"}else{a+=""+e.util.escapeQuotes(o)}a+="\"' "}if(e.opts.verbose){a+=" , schema: ";if(_){a+="validate.schema"+n}else{a+=""+e.util.toQuotedString(o)}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var k=a;a=I.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+k+"]); "}else{a+=" validate.errors = ["+k+"]; return false; "}}else{a+=" var err = "+k+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+="}";return a}},2558:e=>{"use strict";e.exports=function generate_patternRequired(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="key"+s,d="idx"+s,p="patternMatched"+s,m="dataProperties"+s,g="",y=e.opts.ownProperties;a+="var "+c+" = true;";if(y){a+=" var "+m+" = undefined;"}var P=o;if(P){var b,E=-1,S=P.length-1;while(E{"use strict";e.exports=function generate_switch(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="errs__"+s;var d=e.util.copy(e);var p="";d.level++;var m="valid"+d.level;var g="ifPassed"+e.level,y=d.baseId,P;a+="var "+g+";";var b=o;if(b){var E,S=-1,w=b.length-1;while(S0:e.util.schemaHasRules(E.if,e.RULES.all))){a+=" var "+h+" = errors; ";var x=e.compositeRule;e.compositeRule=d.compositeRule=true;d.createErrors=false;d.schema=E.if;d.schemaPath=n+"["+S+"].if";d.errSchemaPath=l+"/"+S+"/if";a+=" "+e.validate(d)+" ";d.baseId=y;d.createErrors=true;e.compositeRule=d.compositeRule=x;a+=" "+g+" = "+m+"; if ("+g+") { ";if(typeof E.then=="boolean"){if(E.then===false){var $=$||[];$.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"switch"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { caseIndex: "+S+" } ";if(e.opts.messages!==false){a+=" , message: 'should pass \"switch\" keyword validation' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var _=a;a=$.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+_+"]); "}else{a+=" validate.errors = ["+_+"]; return false; "}}else{a+=" var err = "+_+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}}a+=" var "+m+" = "+E.then+"; "}else{d.schema=E.then;d.schemaPath=n+"["+S+"].then";d.errSchemaPath=l+"/"+S+"/then";a+=" "+e.validate(d)+" ";d.baseId=y}a+=" } else { errors = "+h+"; if (vErrors !== null) { if ("+h+") vErrors.length = "+h+"; else vErrors = null; } } "}else{a+=" "+g+" = true; ";if(typeof E.then=="boolean"){if(E.then===false){var $=$||[];$.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"switch"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { caseIndex: "+S+" } ";if(e.opts.messages!==false){a+=" , message: 'should pass \"switch\" keyword validation' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var _=a;a=$.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+_+"]); "}else{a+=" validate.errors = ["+_+"]; return false; "}}else{a+=" var err = "+_+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}}a+=" var "+m+" = "+E.then+"; "}else{d.schema=E.then;d.schemaPath=n+"["+S+"].then";d.errSchemaPath=l+"/"+S+"/then";a+=" "+e.validate(d)+" ";d.baseId=y}}P=E.continue}}a+=""+p+"var "+c+" = "+m+";";return a}},8882:e=>{"use strict";var r={};var t={timestamp:function(){return Date.now()},datetime:function(){return(new Date).toISOString()},date:function(){return(new Date).toISOString().slice(0,10)},time:function(){return(new Date).toISOString().slice(11)},random:function(){return Math.random()},randomint:function(e){var r=e&&e.max||2;return function(){return Math.floor(Math.random()*r)}},seq:function(e){var t=e&&e.name||"";r[t]=r[t]||0;return function(){return r[t]++}}};e.exports=function defFunc(e){defFunc.definition={compile:function(e,r,t){var a={};for(var s in e){var i=e[s];var o=getDefault(typeof i=="string"?i:i.func);a[s]=o.length?o(i.args):o}return t.opts.useDefaults&&!t.compositeRule?assignDefaults:noop;function assignDefaults(r){for(var s in e){if(r[s]===undefined||t.opts.useDefaults=="empty"&&(r[s]===null||r[s]===""))r[s]=a[s]()}return true}function noop(){return true}},DEFAULTS:t,metaSchema:{type:"object",additionalProperties:{type:["string","object"],additionalProperties:false,required:["func","args"],properties:{func:{type:"string"},args:{type:"object"}}}}};e.addKeyword("dynamicDefaults",defFunc.definition);return e;function getDefault(e){var r=t[e];if(r)return r;throw new Error('invalid "dynamicDefaults" keyword property value: '+e)}}},442:(e,r,t)=>{"use strict";e.exports=t(7921)("Maximum")},4422:(e,r,t)=>{"use strict";e.exports=t(7921)("Minimum")},5507:(e,r,t)=>{"use strict";e.exports={instanceof:t(3300),range:t(6962),regexp:t(4840),typeof:t(1147),dynamicDefaults:t(8882),allRequired:t(3672),anyRequired:t(2390),oneRequired:t(9425),prohibited:t(8460),uniqueItemProperties:t(7705),deepProperties:t(9357),deepRequired:t(5568),formatMinimum:t(4422),formatMaximum:t(442),patternRequired:t(1780),switch:t(593),select:t(9128),transform:t(2615)}},3300:e=>{"use strict";var r={Object:Object,Array:Array,Function:Function,Number:Number,String:String,Date:Date,RegExp:RegExp};e.exports=function defFunc(e){if(typeof Buffer!="undefined")r.Buffer=Buffer;if(typeof Promise!="undefined")r.Promise=Promise;defFunc.definition={compile:function(e){if(typeof e=="string"){var r=getConstructor(e);return function(e){return e instanceof r}}var t=e.map(getConstructor);return function(e){for(var r=0;r{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"object",macro:function(e){if(e.length==0)return true;if(e.length==1)return{required:e};var r=e.map((function(e){return{required:[e]}}));return{oneOf:r}},metaSchema:{type:"array",items:{type:"string"}}};e.addKeyword("oneRequired",defFunc.definition);return e}},1780:(e,r,t)=>{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"object",inline:t(2558),statements:true,errors:"full",metaSchema:{type:"array",items:{type:"string",format:"regex"},uniqueItems:true}};e.addKeyword("patternRequired",defFunc.definition);return e}},8460:e=>{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"object",macro:function(e){if(e.length==0)return true;if(e.length==1)return{not:{required:e}};var r=e.map((function(e){return{required:[e]}}));return{not:{anyOf:r}}},metaSchema:{type:"array",items:{type:"string"}}};e.addKeyword("prohibited",defFunc.definition);return e}},6962:e=>{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"number",macro:function(e,r){var t=e[0],a=e[1],s=r.exclusiveRange;validateRangeSchema(t,a,s);return s===true?{exclusiveMinimum:t,exclusiveMaximum:a}:{minimum:t,maximum:a}},metaSchema:{type:"array",minItems:2,maxItems:2,items:{type:"number"}}};e.addKeyword("range",defFunc.definition);e.addKeyword("exclusiveRange");return e;function validateRangeSchema(e,r,t){if(t!==undefined&&typeof t!="boolean")throw new Error("Invalid schema for exclusiveRange keyword, should be boolean");if(e>r||t&&e==r)throw new Error("There are no numbers in range")}}},4840:e=>{"use strict";e.exports=function defFunc(e){defFunc.definition={type:"string",inline:function(e,r,t){return getRegExp()+".test(data"+(e.dataLevel||"")+")";function getRegExp(){try{if(typeof t=="object")return new RegExp(t.pattern,t.flags);var e=t.match(/^\/(.*)\/([gimuy]*)$/);if(e)return new RegExp(e[1],e[2]);throw new Error("cannot parse string into RegExp")}catch(e){console.error("regular expression",t,"is invalid");throw e}}},metaSchema:{type:["string","object"],properties:{pattern:{type:"string"},flags:{type:"string"}},required:["pattern"],additionalProperties:false}};e.addKeyword("regexp",defFunc.definition);return e}},9128:(e,r,t)=>{"use strict";var a=t(2298);e.exports=function defFunc(e){if(!e._opts.$data){console.warn("keyword select requires $data option");return e}var r=a.metaSchemaRef(e);var t=[];defFunc.definition={validate:function v(e,r,t){if(t.selectCases===undefined)throw new Error('keyword "selectCases" is absent');var a=getCompiledSchemas(t,false);var s=a.cases[e];if(s===undefined)s=a.default;if(typeof s=="boolean")return s;var i=s(r);if(!i)v.errors=s.errors;return i},$data:true,metaSchema:{type:["string","number","boolean","null"]}};e.addKeyword("select",defFunc.definition);e.addKeyword("selectCases",{compile:function(e,r){var t=getCompiledSchemas(r);for(var a in e)t.cases[a]=compileOrBoolean(e[a]);return function(){return true}},valid:true,metaSchema:{type:"object",additionalProperties:r}});e.addKeyword("selectDefault",{compile:function(e,r){var t=getCompiledSchemas(r);t.default=compileOrBoolean(e);return function(){return true}},valid:true,metaSchema:r});return e;function getCompiledSchemas(e,r){var a;t.some((function(r){if(r.parentSchema===e){a=r;return true}}));if(!a&&r!==false){a={parentSchema:e,cases:{},default:true};t.push(a)}return a}function compileOrBoolean(r){return typeof r=="boolean"?r:e.compile(r)}}},593:(e,r,t)=>{"use strict";var a=t(2298);e.exports=function defFunc(e){if(e.RULES.keywords.switch&&e.RULES.keywords.if)return;var r=a.metaSchemaRef(e);defFunc.definition={inline:t(5244),statements:true,errors:"full",metaSchema:{type:"array",items:{required:["then"],properties:{if:r,then:{anyOf:[{type:"boolean"},r]},continue:{type:"boolean"}},additionalProperties:false,dependencies:{continue:["if"]}}}};e.addKeyword("switch",defFunc.definition);return e}},2615:e=>{"use strict";e.exports=function defFunc(e){var r={trimLeft:function(e){return e.replace(/^[\s]+/,"")},trimRight:function(e){return e.replace(/[\s]+$/,"")},trim:function(e){return e.trim()},toLowerCase:function(e){return e.toLowerCase()},toUpperCase:function(e){return e.toUpperCase()},toEnumCase:function(e,r){return r.hash[makeHashTableKey(e)]||e}};defFunc.definition={type:"string",errors:false,modifying:true,valid:true,compile:function(e,t){var a;if(e.indexOf("toEnumCase")!==-1){a={hash:{}};if(!t.enum)throw new Error('Missing enum. To use `transform:["toEnumCase"]`, `enum:[...]` is required.');for(var s=t.enum.length;s--;s){var i=t.enum[s];if(typeof i!=="string")continue;var o=makeHashTableKey(i);if(a.hash[o])throw new Error('Invalid enum uniqueness. To use `transform:["toEnumCase"]`, all values must be unique when case insensitive.');a.hash[o]=i}}return function(t,s,i,o){if(!i)return;for(var n=0,l=e.length;n{"use strict";var r=["undefined","string","number","object","function","boolean","symbol"];e.exports=function defFunc(e){defFunc.definition={inline:function(e,r,t){var a="data"+(e.dataLevel||"");if(typeof t=="string")return"typeof "+a+' == "'+t+'"';t="validate.schema"+e.schemaPath+"."+r;return t+".indexOf(typeof "+a+") >= 0"},metaSchema:{anyOf:[{type:"string",enum:r},{type:"array",items:{type:"string",enum:r}}]}};e.addKeyword("typeof",defFunc.definition);return e}},7705:e=>{"use strict";var r=["number","integer","string","boolean","null"];e.exports=function defFunc(e){defFunc.definition={type:"array",compile:function(e,r,t){var a=t.util.equal;var s=getScalarKeys(e,r);return function(r){if(r.length>1){for(var t=0;t=0}))}},8601:(e,r,t)=>{"use strict";var a=t(6905),s=t(8708),i=t(4578),o=t(4841),n=t(7351),l=t(3978),u=t(8404),f=t(9341),c=t(7224);e.exports=Ajv;Ajv.prototype.validate=validate;Ajv.prototype.compile=compile;Ajv.prototype.addSchema=addSchema;Ajv.prototype.addMetaSchema=addMetaSchema;Ajv.prototype.validateSchema=validateSchema;Ajv.prototype.getSchema=getSchema;Ajv.prototype.removeSchema=removeSchema;Ajv.prototype.addFormat=addFormat;Ajv.prototype.errorsText=errorsText;Ajv.prototype._addSchema=_addSchema;Ajv.prototype._compile=_compile;Ajv.prototype.compileAsync=t(6211);var h=t(398);Ajv.prototype.addKeyword=h.add;Ajv.prototype.getKeyword=h.get;Ajv.prototype.removeKeyword=h.remove;Ajv.prototype.validateKeyword=h.validate;var d=t(8373);Ajv.ValidationError=d.Validation;Ajv.MissingRefError=d.MissingRef;Ajv.$dataMetaSchema=f;var p="http://json-schema.org/draft-07/schema";var m=["removeAdditional","useDefaults","coerceTypes","strictDefaults"];var g=["/properties"];function Ajv(e){if(!(this instanceof Ajv))return new Ajv(e);e=this._opts=c.copy(e)||{};setLogger(this);this._schemas={};this._refs={};this._fragments={};this._formats=l(e.format);this._cache=e.cache||new i;this._loadingSchemas={};this._compilations=[];this.RULES=u();this._getId=chooseGetId(e);e.loopRequired=e.loopRequired||Infinity;if(e.errorDataPath=="property")e._errorDataPathProperty=true;if(e.serialize===undefined)e.serialize=n;this._metaOpts=getMetaSchemaOptions(this);if(e.formats)addInitialFormats(this);if(e.keywords)addInitialKeywords(this);addDefaultMetaSchema(this);if(typeof e.meta=="object")this.addMetaSchema(e.meta);if(e.nullable)this.addKeyword("nullable",{metaSchema:{type:"boolean"}});addInitialSchemas(this)}function validate(e,r){var t;if(typeof e=="string"){t=this.getSchema(e);if(!t)throw new Error('no schema with key or ref "'+e+'"')}else{var a=this._addSchema(e);t=a.validate||this._compile(a)}var s=t(r);if(t.$async!==true)this.errors=t.errors;return s}function compile(e,r){var t=this._addSchema(e,undefined,r);return t.validate||this._compile(t)}function addSchema(e,r,t,a){if(Array.isArray(e)){for(var i=0;i{"use strict";var r=e.exports=function Cache(){this._cache={}};r.prototype.put=function Cache_put(e,r){this._cache[e]=r};r.prototype.get=function Cache_get(e){return this._cache[e]};r.prototype.del=function Cache_del(e){delete this._cache[e]};r.prototype.clear=function Cache_clear(){this._cache={}}},6211:(e,r,t)=>{"use strict";var a=t(8373).MissingRef;e.exports=compileAsync;function compileAsync(e,r,t){var s=this;if(typeof this._opts.loadSchema!="function")throw new Error("options.loadSchema should be a function");if(typeof r=="function"){t=r;r=undefined}var i=loadMetaSchemaOf(e).then((function(){var t=s._addSchema(e,undefined,r);return t.validate||_compileAsync(t)}));if(t){i.then((function(e){t(null,e)}),t)}return i;function loadMetaSchemaOf(e){var r=e.$schema;return r&&!s.getSchema(r)?compileAsync.call(s,{$ref:r},true):Promise.resolve()}function _compileAsync(e){try{return s._compile(e)}catch(e){if(e instanceof a)return loadMissingSchema(e);throw e}function loadMissingSchema(t){var a=t.missingSchema;if(added(a))throw new Error("Schema "+a+" is loaded but "+t.missingRef+" cannot be resolved");var i=s._loadingSchemas[a];if(!i){i=s._loadingSchemas[a]=s._opts.loadSchema(a);i.then(removePromise,removePromise)}return i.then((function(e){if(!added(a)){return loadMetaSchemaOf(e).then((function(){if(!added(a))s.addSchema(e,a,undefined,r)}))}})).then((function(){return _compileAsync(e)}));function removePromise(){delete s._loadingSchemas[a]}function added(e){return s._refs[e]||s._schemas[e]}}}}},8373:(e,r,t)=>{"use strict";var a=t(8708);e.exports={Validation:errorSubclass(ValidationError),MissingRef:errorSubclass(MissingRefError)};function ValidationError(e){this.message="validation failed";this.errors=e;this.ajv=this.validation=true}MissingRefError.message=function(e,r){return"can't resolve reference "+r+" from id "+e};function MissingRefError(e,r,t){this.message=t||MissingRefError.message(e,r);this.missingRef=a.url(e,r);this.missingSchema=a.normalizeId(a.fullPath(this.missingRef))}function errorSubclass(e){e.prototype=Object.create(Error.prototype);e.prototype.constructor=e;return e}},3978:(e,r,t)=>{"use strict";var a=t(7224);var s=/^(\d\d\d\d)-(\d\d)-(\d\d)$/;var i=[0,31,28,31,30,31,30,31,31,30,31,30,31];var o=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;var n=/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i;var l=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;var u=/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;var f=/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;var c=/^(?:(?:http[s\u017F]?|ftp):\/\/)(?:(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+(?::(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?@)?(?:(?!10(?:\.[0-9]{1,3}){3})(?!127(?:\.[0-9]{1,3}){3})(?!169\.254(?:\.[0-9]{1,3}){2})(?!192\.168(?:\.[0-9]{1,3}){2})(?!172\.(?:1[6-9]|2[0-9]|3[01])(?:\.[0-9]{1,3}){2})(?:[1-9][0-9]?|1[0-9][0-9]|2[01][0-9]|22[0-3])(?:\.(?:1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])){2}(?:\.(?:[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))|(?:(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)(?:\.(?:(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+-)*(?:[0-9a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+)*(?:\.(?:(?:[a-z\xA1-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]){2,})))(?::[0-9]{2,5})?(?:\/(?:[\0-\x08\x0E-\x1F!-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uD7FF\uE000-\uFEFE\uFF00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*)?$/i;var h=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;var d=/^(?:\/(?:[^~/]|~0|~1)*)*$/;var p=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;var m=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;e.exports=formats;function formats(e){e=e=="full"?"full":"fast";return a.copy(formats[e])}formats.fast={date:/^\d\d\d\d-[0-1]\d-[0-3]\d$/,time:/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i,"date-time":/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i,uri:/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,"uri-reference":/^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,"uri-template":f,url:c,email:/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,hostname:n,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:regex,uuid:h,"json-pointer":d,"json-pointer-uri-fragment":p,"relative-json-pointer":m};formats.full={date:date,time:time,"date-time":date_time,uri:uri,"uri-reference":u,"uri-template":f,url:c,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,hostname:n,ipv4:/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipv6:/^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,regex:regex,uuid:h,"json-pointer":d,"json-pointer-uri-fragment":p,"relative-json-pointer":m};function isLeapYear(e){return e%4===0&&(e%100!==0||e%400===0)}function date(e){var r=e.match(s);if(!r)return false;var t=+r[1];var a=+r[2];var o=+r[3];return a>=1&&a<=12&&o>=1&&o<=(a==2&&isLeapYear(t)?29:i[a])}function time(e,r){var t=e.match(o);if(!t)return false;var a=t[1];var s=t[2];var i=t[3];var n=t[5];return(a<=23&&s<=59&&i<=59||a==23&&s==59&&i==60)&&(!r||n)}var g=/t|\s/i;function date_time(e){var r=e.split(g);return r.length==2&&date(r[0])&&time(r[1],true)}var y=/\/|:/;function uri(e){return y.test(e)&&l.test(e)}var P=/[^\\]\\Z/;function regex(e){if(P.test(e))return false;try{new RegExp(e);return true}catch(e){return false}}},6905:(e,r,t)=>{"use strict";var a=t(8708),s=t(7224),i=t(8373),o=t(7351);var n=t(2801);var l=s.ucs2length;var u=t(7447);var f=i.Validation;e.exports=compile;function compile(e,r,t,c){var h=this,d=this._opts,p=[undefined],m={},g=[],y={},P=[],b={},E=[];r=r||{schema:e,refVal:p,refs:m};var S=checkCompiling.call(this,e,r,c);var w=this._compilations[S.index];if(S.compiling)return w.callValidate=callValidate;var x=this._formats;var $=this.RULES;try{var _=localCompile(e,r,t,c);w.validate=_;var R=w.callValidate;if(R){R.schema=_.schema;R.errors=null;R.refs=_.refs;R.refVal=_.refVal;R.root=_.root;R.$async=_.$async;if(d.sourceCode)R.source=_.source}return _}finally{endCompiling.call(this,e,r,c)}function callValidate(){var e=w.validate;var r=e.apply(this,arguments);callValidate.errors=e.errors;return r}function localCompile(e,t,o,c){var y=!t||t&&t.schema==e;if(t.schema!=r.schema)return compile.call(h,e,t,o,c);var b=e.$async===true;var S=n({isTop:true,schema:e,isRoot:y,baseId:c,root:t,schemaPath:"",errSchemaPath:"#",errorPath:'""',MissingRefError:i.MissingRef,RULES:$,validate:n,util:s,resolve:a,resolveRef:resolveRef,usePattern:usePattern,useDefault:useDefault,useCustomRule:useCustomRule,opts:d,formats:x,logger:h.logger,self:h});S=vars(p,refValCode)+vars(g,patternCode)+vars(P,defaultCode)+vars(E,customRuleCode)+S;if(d.processCode)S=d.processCode(S,e);var w;try{var _=new Function("self","RULES","formats","root","refVal","defaults","customRules","equal","ucs2length","ValidationError",S);w=_(h,$,x,r,p,P,E,u,l,f);p[0]=w}catch(e){h.logger.error("Error compiling schema, function code:",S);throw e}w.schema=e;w.errors=null;w.refs=m;w.refVal=p;w.root=y?w:t;if(b)w.$async=true;if(d.sourceCode===true){w.source={code:S,patterns:g,defaults:P}}return w}function resolveRef(e,s,i){s=a.url(e,s);var o=m[s];var n,l;if(o!==undefined){n=p[o];l="refVal["+o+"]";return resolvedRef(n,l)}if(!i&&r.refs){var u=r.refs[s];if(u!==undefined){n=r.refVal[u];l=addLocalRef(s,n);return resolvedRef(n,l)}}l=addLocalRef(s);var f=a.call(h,localCompile,r,s);if(f===undefined){var c=t&&t[s];if(c){f=a.inlineRef(c,d.inlineRefs)?c:compile.call(h,c,r,t,e)}}if(f===undefined){removeLocalRef(s)}else{replaceLocalRef(s,f);return resolvedRef(f,l)}}function addLocalRef(e,r){var t=p.length;p[t]=r;m[e]=t;return"refVal"+t}function removeLocalRef(e){delete m[e]}function replaceLocalRef(e,r){var t=m[e];p[t]=r}function resolvedRef(e,r){return typeof e=="object"||typeof e=="boolean"?{code:r,schema:e,inline:true}:{code:r,$async:e&&!!e.$async}}function usePattern(e){var r=y[e];if(r===undefined){r=y[e]=g.length;g[r]=e}return"pattern"+r}function useDefault(e){switch(typeof e){case"boolean":case"number":return""+e;case"string":return s.toQuotedString(e);case"object":if(e===null)return"null";var r=o(e);var t=b[r];if(t===undefined){t=b[r]=P.length;P[t]=e}return"default"+t}}function useCustomRule(e,r,t,a){if(h._opts.validateSchema!==false){var s=e.definition.dependencies;if(s&&!s.every((function(e){return Object.prototype.hasOwnProperty.call(t,e)})))throw new Error("parent schema must have all required keywords: "+s.join(","));var i=e.definition.validateSchema;if(i){var o=i(r);if(!o){var n="keyword schema is invalid: "+h.errorsText(i.errors);if(h._opts.validateSchema=="log")h.logger.error(n);else throw new Error(n)}}}var l=e.definition.compile,u=e.definition.inline,f=e.definition.macro;var c;if(l){c=l.call(h,r,t,a)}else if(f){c=f.call(h,r,t,a);if(d.validateSchema!==false)h.validateSchema(c,true)}else if(u){c=u.call(h,a,e.keyword,r,t)}else{c=e.definition.validate;if(!c)return}if(c===undefined)throw new Error('custom keyword "'+e.keyword+'"failed to compile');var p=E.length;E[p]=c;return{code:"customRule"+p,validate:c}}}function checkCompiling(e,r,t){var a=compIndex.call(this,e,r,t);if(a>=0)return{index:a,compiling:true};a=this._compilations.length;this._compilations[a]={schema:e,root:r,baseId:t};return{index:a,compiling:false}}function endCompiling(e,r,t){var a=compIndex.call(this,e,r,t);if(a>=0)this._compilations.splice(a,1)}function compIndex(e,r,t){for(var a=0;a{"use strict";var a=t(199),s=t(7447),i=t(7224),o=t(4841),n=t(4432);e.exports=resolve;resolve.normalizeId=normalizeId;resolve.fullPath=getFullPath;resolve.url=resolveUrl;resolve.ids=resolveIds;resolve.inlineRef=inlineRef;resolve.schema=resolveSchema;function resolve(e,r,t){var a=this._refs[t];if(typeof a=="string"){if(this._refs[a])a=this._refs[a];else return resolve.call(this,e,r,a)}a=a||this._schemas[t];if(a instanceof o){return inlineRef(a.schema,this._opts.inlineRefs)?a.schema:a.validate||this._compile(a)}var s=resolveSchema.call(this,r,t);var i,n,l;if(s){i=s.schema;r=s.root;l=s.baseId}if(i instanceof o){n=i.validate||e.call(this,i.schema,r,undefined,l)}else if(i!==undefined){n=inlineRef(i,this._opts.inlineRefs)?i:e.call(this,i,r,undefined,l)}return n}function resolveSchema(e,r){var t=a.parse(r),s=_getFullPath(t),i=getFullPath(this._getId(e.schema));if(Object.keys(e.schema).length===0||s!==i){var n=normalizeId(s);var l=this._refs[n];if(typeof l=="string"){return resolveRecursive.call(this,e,l,t)}else if(l instanceof o){if(!l.validate)this._compile(l);e=l}else{l=this._schemas[n];if(l instanceof o){if(!l.validate)this._compile(l);if(n==normalizeId(r))return{schema:l,root:e,baseId:i};e=l}else{return}}if(!e.schema)return;i=getFullPath(this._getId(e.schema))}return getJsonPointer.call(this,t,i,e.schema,e)}function resolveRecursive(e,r,t){var a=resolveSchema.call(this,e,r);if(a){var s=a.schema;var i=a.baseId;e=a.root;var o=this._getId(s);if(o)i=resolveUrl(i,o);return getJsonPointer.call(this,t,i,s,e)}}var l=i.toHash(["properties","patternProperties","enum","dependencies","definitions"]);function getJsonPointer(e,r,t,a){e.fragment=e.fragment||"";if(e.fragment.slice(0,1)!="/")return;var s=e.fragment.split("/");for(var o=1;o{"use strict";var a=t(734),s=t(7224).toHash;e.exports=function rules(){var e=[{type:"number",rules:[{maximum:["exclusiveMaximum"]},{minimum:["exclusiveMinimum"]},"multipleOf","format"]},{type:"string",rules:["maxLength","minLength","pattern","format"]},{type:"array",rules:["maxItems","minItems","items","contains","uniqueItems"]},{type:"object",rules:["maxProperties","minProperties","required","dependencies","propertyNames",{properties:["additionalProperties","patternProperties"]}]},{rules:["$ref","const","enum","not","anyOf","oneOf","allOf","if"]}];var r=["type","$comment"];var t=["$schema","$id","id","$data","$async","title","description","default","definitions","examples","readOnly","writeOnly","contentMediaType","contentEncoding","additionalItems","then","else"];var i=["number","integer","string","array","object","boolean","null"];e.all=s(r);e.types=s(i);e.forEach((function(t){t.rules=t.rules.map((function(t){var s;if(typeof t=="object"){var i=Object.keys(t)[0];s=t[i];t=i;s.forEach((function(t){r.push(t);e.all[t]=true}))}r.push(t);var o=e.all[t]={keyword:t,code:a[t],implements:s};return o}));e.all.$comment={keyword:"$comment",code:a.$comment};if(t.type)e.types[t.type]=t}));e.keywords=s(r.concat(t));e.custom={};return e}},4841:(e,r,t)=>{"use strict";var a=t(7224);e.exports=SchemaObject;function SchemaObject(e){a.copy(e,this)}},7980:e=>{"use strict";e.exports=function ucs2length(e){var r=0,t=e.length,a=0,s;while(a=55296&&s<=56319&&a{"use strict";e.exports={copy:copy,checkDataType:checkDataType,checkDataTypes:checkDataTypes,coerceToTypes:coerceToTypes,toHash:toHash,getProperty:getProperty,escapeQuotes:escapeQuotes,equal:t(7447),ucs2length:t(7980),varOccurences:varOccurences,varReplace:varReplace,schemaHasRules:schemaHasRules,schemaHasRulesExcept:schemaHasRulesExcept,schemaUnknownRules:schemaUnknownRules,toQuotedString:toQuotedString,getPathExpr:getPathExpr,getPath:getPath,getData:getData,unescapeFragment:unescapeFragment,unescapeJsonPointer:unescapeJsonPointer,escapeFragment:escapeFragment,escapeJsonPointer:escapeJsonPointer};function copy(e,r){r=r||{};for(var t in e)r[t]=e[t];return r}function checkDataType(e,r,t,a){var s=a?" !== ":" === ",i=a?" || ":" && ",o=a?"!":"",n=a?"":"!";switch(e){case"null":return r+s+"null";case"array":return o+"Array.isArray("+r+")";case"object":return"("+o+r+i+"typeof "+r+s+'"object"'+i+n+"Array.isArray("+r+"))";case"integer":return"(typeof "+r+s+'"number"'+i+n+"("+r+" % 1)"+i+r+s+r+(t?i+o+"isFinite("+r+")":"")+")";case"number":return"(typeof "+r+s+'"'+e+'"'+(t?i+o+"isFinite("+r+")":"")+")";default:return"typeof "+r+s+'"'+e+'"'}}function checkDataTypes(e,r,t){switch(e.length){case 1:return checkDataType(e[0],r,t,true);default:var a="";var s=toHash(e);if(s.array&&s.object){a=s.null?"(":"(!"+r+" || ";a+="typeof "+r+' !== "object")';delete s.null;delete s.array;delete s.object}if(s.number)delete s.integer;for(var i in s)a+=(a?" && ":"")+checkDataType(i,r,t,true);return a}}var a=toHash(["string","number","integer","boolean","null"]);function coerceToTypes(e,r){if(Array.isArray(r)){var t=[];for(var s=0;s=r)throw new Error("Cannot access property/index "+a+" levels up, current level is "+r);return t[r-a]}if(a>r)throw new Error("Cannot access data "+a+" levels up, current level is "+r);i="data"+(r-a||"");if(!s)return i}var u=i;var f=s.split("/");for(var c=0;c{"use strict";var r=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"];e.exports=function(e,t){for(var a=0;a{"use strict";var a=t(7136);e.exports={$id:"https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js",definitions:{simpleTypes:a.definitions.simpleTypes},type:"object",dependencies:{schema:["validate"],$data:["validate"],statements:["inline"],valid:{not:{required:["macro"]}}},properties:{type:a.properties.type,schema:{type:"boolean"},statements:{type:"boolean"},dependencies:{type:"array",items:{type:"string"}},metaSchema:{type:"object"},modifying:{type:"boolean"},valid:{type:"boolean"},$data:{type:"boolean"},async:{type:"boolean"},errors:{anyOf:[{type:"boolean"},{const:"full"}]}}}},9510:e=>{"use strict";e.exports=function generate__limit(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f;var c="data"+(i||"");var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}var p=r=="maximum",m=p?"exclusiveMaximum":"exclusiveMinimum",g=e.schema[m],y=e.opts.$data&&g&&g.$data,P=p?"<":">",b=p?">":"<",f=undefined;if(!(h||typeof o=="number"||o===undefined)){throw new Error(r+" must be number")}if(!(y||g===undefined||typeof g=="number"||typeof g=="boolean")){throw new Error(m+" must be number or boolean")}if(y){var E=e.util.getData(g.$data,i,e.dataPathArr),S="exclusive"+s,w="exclType"+s,x="exclIsNumber"+s,$="op"+s,_="' + "+$+" + '";a+=" var schemaExcl"+s+" = "+E+"; ";E="schemaExcl"+s;a+=" var "+S+"; var "+w+" = typeof "+E+"; if ("+w+" != 'boolean' && "+w+" != 'undefined' && "+w+" != 'number') { ";var f=m;var R=R||[];R.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_exclusiveLimit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: {} ";if(e.opts.messages!==false){a+=" , message: '"+m+" should be boolean' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var F=a;a=R.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+F+"]); "}else{a+=" validate.errors = ["+F+"]; return false; "}}else{a+=" var err = "+F+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } else if ( ";if(h){a+=" ("+d+" !== undefined && typeof "+d+" != 'number') || "}a+=" "+w+" == 'number' ? ( ("+S+" = "+d+" === undefined || "+E+" "+P+"= "+d+") ? "+c+" "+b+"= "+E+" : "+c+" "+b+" "+d+" ) : ( ("+S+" = "+E+" === true) ? "+c+" "+b+"= "+d+" : "+c+" "+b+" "+d+" ) || "+c+" !== "+c+") { var op"+s+" = "+S+" ? '"+P+"' : '"+P+"='; ";if(o===undefined){f=m;l=e.errSchemaPath+"/"+m;d=E;h=y}}else{var x=typeof g=="number",_=P;if(x&&h){var $="'"+_+"'";a+=" if ( ";if(h){a+=" ("+d+" !== undefined && typeof "+d+" != 'number') || "}a+=" ( "+d+" === undefined || "+g+" "+P+"= "+d+" ? "+c+" "+b+"= "+g+" : "+c+" "+b+" "+d+" ) || "+c+" !== "+c+") { "}else{if(x&&o===undefined){S=true;f=m;l=e.errSchemaPath+"/"+m;d=g;b+="="}else{if(x)d=Math[p?"min":"max"](g,o);if(g===(x?d:true)){S=true;f=m;l=e.errSchemaPath+"/"+m;b+="="}else{S=false;_+="="}}var $="'"+_+"'";a+=" if ( ";if(h){a+=" ("+d+" !== undefined && typeof "+d+" != 'number') || "}a+=" "+c+" "+b+" "+d+" || "+c+" !== "+c+") { "}}f=f||r;var R=R||[];R.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_limit")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { comparison: "+$+", limit: "+d+", exclusive: "+S+" } ";if(e.opts.messages!==false){a+=" , message: 'should be "+_+" ";if(h){a+="' + "+d}else{a+=""+d+"'"}}if(e.opts.verbose){a+=" , schema: ";if(h){a+="validate.schema"+n}else{a+=""+o}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var F=a;a=R.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+F+"]); "}else{a+=" validate.errors = ["+F+"]; return false; "}}else{a+=" var err = "+F+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } ";if(u){a+=" else { "}return a}},2982:e=>{"use strict";e.exports=function generate__limitItems(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f;var c="data"+(i||"");var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}if(!(h||typeof o=="number")){throw new Error(r+" must be number")}var p=r=="maxItems"?">":"<";a+="if ( ";if(h){a+=" ("+d+" !== undefined && typeof "+d+" != 'number') || "}a+=" "+c+".length "+p+" "+d+") { ";var f=r;var m=m||[];m.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_limitItems")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { limit: "+d+" } ";if(e.opts.messages!==false){a+=" , message: 'should NOT have ";if(r=="maxItems"){a+="more"}else{a+="fewer"}a+=" than ";if(h){a+="' + "+d+" + '"}else{a+=""+o}a+=" items' "}if(e.opts.verbose){a+=" , schema: ";if(h){a+="validate.schema"+n}else{a+=""+o}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var g=a;a=m.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+g+"]); "}else{a+=" validate.errors = ["+g+"]; return false; "}}else{a+=" var err = "+g+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+="} ";if(u){a+=" else { "}return a}},8598:e=>{"use strict";e.exports=function generate__limitLength(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f;var c="data"+(i||"");var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}if(!(h||typeof o=="number")){throw new Error(r+" must be number")}var p=r=="maxLength"?">":"<";a+="if ( ";if(h){a+=" ("+d+" !== undefined && typeof "+d+" != 'number') || "}if(e.opts.unicode===false){a+=" "+c+".length "}else{a+=" ucs2length("+c+") "}a+=" "+p+" "+d+") { ";var f=r;var m=m||[];m.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_limitLength")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { limit: "+d+" } ";if(e.opts.messages!==false){a+=" , message: 'should NOT be ";if(r=="maxLength"){a+="longer"}else{a+="shorter"}a+=" than ";if(h){a+="' + "+d+" + '"}else{a+=""+o}a+=" characters' "}if(e.opts.verbose){a+=" , schema: ";if(h){a+="validate.schema"+n}else{a+=""+o}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var g=a;a=m.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+g+"]); "}else{a+=" validate.errors = ["+g+"]; return false; "}}else{a+=" var err = "+g+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+="} ";if(u){a+=" else { "}return a}},1667:e=>{"use strict";e.exports=function generate__limitProperties(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f;var c="data"+(i||"");var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}if(!(h||typeof o=="number")){throw new Error(r+" must be number")}var p=r=="maxProperties"?">":"<";a+="if ( ";if(h){a+=" ("+d+" !== undefined && typeof "+d+" != 'number') || "}a+=" Object.keys("+c+").length "+p+" "+d+") { ";var f=r;var m=m||[];m.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"_limitProperties")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { limit: "+d+" } ";if(e.opts.messages!==false){a+=" , message: 'should NOT have ";if(r=="maxProperties"){a+="more"}else{a+="fewer"}a+=" than ";if(h){a+="' + "+d+" + '"}else{a+=""+o}a+=" properties' "}if(e.opts.verbose){a+=" , schema: ";if(h){a+="validate.schema"+n}else{a+=""+o}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var g=a;a=m.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+g+"]); "}else{a+=" validate.errors = ["+g+"]; return false; "}}else{a+=" var err = "+g+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+="} ";if(u){a+=" else { "}return a}},1308:e=>{"use strict";e.exports=function generate_allOf(e,r,t){var a=" ";var s=e.schema[r];var i=e.schemaPath+e.util.getProperty(r);var o=e.errSchemaPath+"/"+r;var n=!e.opts.allErrors;var l=e.util.copy(e);var u="";l.level++;var f="valid"+l.level;var c=l.baseId,h=true;var d=s;if(d){var p,m=-1,g=d.length-1;while(m0||p===false:e.util.schemaHasRules(p,e.RULES.all)){h=false;l.schema=p;l.schemaPath=i+"["+m+"]";l.errSchemaPath=o+"/"+m;a+=" "+e.validate(l)+" ";l.baseId=c;if(n){a+=" if ("+f+") { ";u+="}"}}}}if(n){if(h){a+=" if (true) { "}else{a+=" "+u.slice(0,-1)+" "}}return a}},7128:e=>{"use strict";e.exports=function generate_anyOf(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="errs__"+s;var d=e.util.copy(e);var p="";d.level++;var m="valid"+d.level;var g=o.every((function(r){return e.opts.strictKeywords?typeof r=="object"&&Object.keys(r).length>0||r===false:e.util.schemaHasRules(r,e.RULES.all)}));if(g){var y=d.baseId;a+=" var "+h+" = errors; var "+c+" = false; ";var P=e.compositeRule;e.compositeRule=d.compositeRule=true;var b=o;if(b){var E,S=-1,w=b.length-1;while(S{"use strict";e.exports=function generate_comment(e,r,t){var a=" ";var s=e.schema[r];var i=e.errSchemaPath+"/"+r;var o=!e.opts.allErrors;var n=e.util.toQuotedString(s);if(e.opts.$comment===true){a+=" console.log("+n+");"}else if(typeof e.opts.$comment=="function"){a+=" self._opts.$comment("+n+", "+e.util.toQuotedString(i)+", validate.root.schema);"}return a}},3507:e=>{"use strict";e.exports=function generate_const(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}if(!h){a+=" var schema"+s+" = validate.schema"+n+";"}a+="var "+c+" = equal("+f+", schema"+s+"); if (!"+c+") { ";var p=p||[];p.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"const"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { allowedValue: schema"+s+" } ";if(e.opts.messages!==false){a+=" , message: 'should be equal to constant' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var m=a;a=p.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+m+"]); "}else{a+=" validate.errors = ["+m+"]; return false; "}}else{a+=" var err = "+m+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" }";if(u){a+=" else { "}return a}},3348:e=>{"use strict";e.exports=function generate_contains(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="errs__"+s;var d=e.util.copy(e);var p="";d.level++;var m="valid"+d.level;var g="i"+s,y=d.dataLevel=e.dataLevel+1,P="data"+y,b=e.baseId,E=e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===false:e.util.schemaHasRules(o,e.RULES.all);a+="var "+h+" = errors;var "+c+";";if(E){var S=e.compositeRule;e.compositeRule=d.compositeRule=true;d.schema=o;d.schemaPath=n;d.errSchemaPath=l;a+=" var "+m+" = false; for (var "+g+" = 0; "+g+" < "+f+".length; "+g+"++) { ";d.errorPath=e.util.getPathExpr(e.errorPath,g,e.opts.jsonPointers,true);var w=f+"["+g+"]";d.dataPathArr[y]=g;var x=e.validate(d);d.baseId=b;if(e.util.varOccurences(x,P)<2){a+=" "+e.util.varReplace(x,P,w)+" "}else{a+=" var "+P+" = "+w+"; "+x+" "}a+=" if ("+m+") break; } ";e.compositeRule=d.compositeRule=S;a+=" "+p+" if (!"+m+") {"}else{a+=" if ("+f+".length == 0) {"}var $=$||[];$.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"contains"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: {} ";if(e.opts.messages!==false){a+=" , message: 'should contain a valid item' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var _=a;a=$.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+_+"]); "}else{a+=" validate.errors = ["+_+"]; return false; "}}else{a+=" var err = "+_+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } else { ";if(E){a+=" errors = "+h+"; if (vErrors !== null) { if ("+h+") vErrors.length = "+h+"; else vErrors = null; } "}if(e.opts.allErrors){a+=" } "}return a}},9481:e=>{"use strict";e.exports=function generate_custom(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f;var c="data"+(i||"");var h="valid"+s;var d="errs__"+s;var p=e.opts.$data&&o&&o.$data,m;if(p){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";m="schema"+s}else{m=o}var g=this,y="definition"+s,P=g.definition,b="";var E,S,w,x,$;if(p&&P.$data){$="keywordValidate"+s;var _=P.validateSchema;a+=" var "+y+" = RULES.custom['"+r+"'].definition; var "+$+" = "+y+".validate;"}else{x=e.useCustomRule(g,o,e.schema,e);if(!x)return;m="validate.schema"+n;$=x.code;E=P.compile;S=P.inline;w=P.macro}var R=$+".errors",F="i"+s,O="ruleErr"+s,D=P.async;if(D&&!e.async)throw new Error("async keyword in sync schema");if(!(S||w)){a+=""+R+" = null;"}a+="var "+d+" = errors;var "+h+";";if(p&&P.$data){b+="}";a+=" if ("+m+" === undefined) { "+h+" = true; } else { ";if(_){b+="}";a+=" "+h+" = "+y+".validateSchema("+m+"); if ("+h+") { "}}if(S){if(P.statements){a+=" "+x.validate+" "}else{a+=" "+h+" = "+x.validate+"; "}}else if(w){var j=e.util.copy(e);var b="";j.level++;var I="valid"+j.level;j.schema=x.validate;j.schemaPath="";var k=e.compositeRule;e.compositeRule=j.compositeRule=true;var C=e.validate(j).replace(/validate\.schema/g,$);e.compositeRule=j.compositeRule=k;a+=" "+C}else{var A=A||[];A.push(a);a="";a+=" "+$+".call( ";if(e.opts.passContext){a+="this"}else{a+="self"}if(E||P.schema===false){a+=" , "+c+" "}else{a+=" , "+m+" , "+c+" , validate.schema"+e.schemaPath+" "}a+=" , (dataPath || '')";if(e.errorPath!='""'){a+=" + "+e.errorPath}var N=i?"data"+(i-1||""):"parentData",T=i?e.dataPathArr[i]:"parentDataProperty";a+=" , "+N+" , "+T+" , rootData ) ";var L=a;a=A.pop();if(P.errors===false){a+=" "+h+" = ";if(D){a+="await "}a+=""+L+"; "}else{if(D){R="customErrors"+s;a+=" var "+R+" = null; try { "+h+" = await "+L+"; } catch (e) { "+h+" = false; if (e instanceof ValidationError) "+R+" = e.errors; else throw e; } "}else{a+=" "+R+" = null; "+h+" = "+L+"; "}}}if(P.modifying){a+=" if ("+N+") "+c+" = "+N+"["+T+"];"}a+=""+b;if(P.valid){if(u){a+=" if (true) { "}}else{a+=" if ( ";if(P.valid===undefined){a+=" !";if(w){a+=""+I}else{a+=""+h}}else{a+=" "+!P.valid+" "}a+=") { ";f=g.keyword;var A=A||[];A.push(a);a="";var A=A||[];A.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(f||"custom")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { keyword: '"+g.keyword+"' } ";if(e.opts.messages!==false){a+=" , message: 'should pass \""+g.keyword+"\" keyword validation' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+c+" "}a+=" } "}else{a+=" {} "}var q=a;a=A.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+q+"]); "}else{a+=" validate.errors = ["+q+"]; return false; "}}else{a+=" var err = "+q+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}var z=a;a=A.pop();if(S){if(P.errors){if(P.errors!="full"){a+=" for (var "+F+"="+d+"; "+F+"{"use strict";e.exports=function generate_dependencies(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="errs__"+s;var h=e.util.copy(e);var d="";h.level++;var p="valid"+h.level;var m={},g={},y=e.opts.ownProperties;for(S in o){if(S=="__proto__")continue;var P=o[S];var b=Array.isArray(P)?g:m;b[S]=P}a+="var "+c+" = errors;";var E=e.errorPath;a+="var missing"+s+";";for(var S in g){b=g[S];if(b.length){a+=" if ( "+f+e.util.getProperty(S)+" !== undefined ";if(y){a+=" && Object.prototype.hasOwnProperty.call("+f+", '"+e.util.escapeQuotes(S)+"') "}if(u){a+=" && ( ";var w=b;if(w){var x,$=-1,_=w.length-1;while($<_){x=w[$+=1];if($){a+=" || "}var R=e.util.getProperty(x),F=f+R;a+=" ( ( "+F+" === undefined ";if(y){a+=" || ! Object.prototype.hasOwnProperty.call("+f+", '"+e.util.escapeQuotes(x)+"') "}a+=") && (missing"+s+" = "+e.util.toQuotedString(e.opts.jsonPointers?x:R)+") ) "}}a+=")) { ";var O="missing"+s,D="' + "+O+" + '";if(e.opts._errorDataPathProperty){e.errorPath=e.opts.jsonPointers?e.util.getPathExpr(E,O,true):E+" + "+O}var j=j||[];j.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"dependencies"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { property: '"+e.util.escapeQuotes(S)+"', missingProperty: '"+D+"', depsCount: "+b.length+", deps: '"+e.util.escapeQuotes(b.length==1?b[0]:b.join(", "))+"' } ";if(e.opts.messages!==false){a+=" , message: 'should have ";if(b.length==1){a+="property "+e.util.escapeQuotes(b[0])}else{a+="properties "+e.util.escapeQuotes(b.join(", "))}a+=" when property "+e.util.escapeQuotes(S)+" is present' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var I=a;a=j.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+I+"]); "}else{a+=" validate.errors = ["+I+"]; return false; "}}else{a+=" var err = "+I+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}}else{a+=" ) { ";var k=b;if(k){var x,C=-1,A=k.length-1;while(C0||P===false:e.util.schemaHasRules(P,e.RULES.all)){a+=" "+p+" = true; if ( "+f+e.util.getProperty(S)+" !== undefined ";if(y){a+=" && Object.prototype.hasOwnProperty.call("+f+", '"+e.util.escapeQuotes(S)+"') "}a+=") { ";h.schema=P;h.schemaPath=n+e.util.getProperty(S);h.errSchemaPath=l+"/"+e.util.escapeFragment(S);a+=" "+e.validate(h)+" ";h.baseId=N;a+=" } ";if(u){a+=" if ("+p+") { ";d+="}"}}}if(u){a+=" "+d+" if ("+c+" == errors) {"}return a}},3691:e=>{"use strict";e.exports=function generate_enum(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}var p="i"+s,m="schema"+s;if(!h){a+=" var "+m+" = validate.schema"+n+";"}a+="var "+c+";";if(h){a+=" if (schema"+s+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+s+")) "+c+" = false; else {"}a+=""+c+" = false;for (var "+p+"=0; "+p+"<"+m+".length; "+p+"++) if (equal("+f+", "+m+"["+p+"])) { "+c+" = true; break; }";if(h){a+=" } "}a+=" if (!"+c+") { ";var g=g||[];g.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"enum"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { allowedValues: schema"+s+" } ";if(e.opts.messages!==false){a+=" , message: 'should be equal to one of the allowed values' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var y=a;a=g.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+y+"]); "}else{a+=" validate.errors = ["+y+"]; return false; "}}else{a+=" var err = "+y+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" }";if(u){a+=" else { "}return a}},1811:e=>{"use strict";e.exports=function generate_format(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");if(e.opts.format===false){if(u){a+=" if (true) { "}return a}var c=e.opts.$data&&o&&o.$data,h;if(c){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";h="schema"+s}else{h=o}var d=e.opts.unknownFormats,p=Array.isArray(d);if(c){var m="format"+s,g="isObject"+s,y="formatType"+s;a+=" var "+m+" = formats["+h+"]; var "+g+" = typeof "+m+" == 'object' && !("+m+" instanceof RegExp) && "+m+".validate; var "+y+" = "+g+" && "+m+".type || 'string'; if ("+g+") { ";if(e.async){a+=" var async"+s+" = "+m+".async; "}a+=" "+m+" = "+m+".validate; } if ( ";if(c){a+=" ("+h+" !== undefined && typeof "+h+" != 'string') || "}a+=" (";if(d!="ignore"){a+=" ("+h+" && !"+m+" ";if(p){a+=" && self._opts.unknownFormats.indexOf("+h+") == -1 "}a+=") || "}a+=" ("+m+" && "+y+" == '"+t+"' && !(typeof "+m+" == 'function' ? ";if(e.async){a+=" (async"+s+" ? await "+m+"("+f+") : "+m+"("+f+")) "}else{a+=" "+m+"("+f+") "}a+=" : "+m+".test("+f+"))))) {"}else{var m=e.formats[o];if(!m){if(d=="ignore"){e.logger.warn('unknown format "'+o+'" ignored in schema at path "'+e.errSchemaPath+'"');if(u){a+=" if (true) { "}return a}else if(p&&d.indexOf(o)>=0){if(u){a+=" if (true) { "}return a}else{throw new Error('unknown format "'+o+'" is used in schema at path "'+e.errSchemaPath+'"')}}var g=typeof m=="object"&&!(m instanceof RegExp)&&m.validate;var y=g&&m.type||"string";if(g){var P=m.async===true;m=m.validate}if(y!=t){if(u){a+=" if (true) { "}return a}if(P){if(!e.async)throw new Error("async format in sync schema");var b="formats"+e.util.getProperty(o)+".validate";a+=" if (!(await "+b+"("+f+"))) { "}else{a+=" if (! ";var b="formats"+e.util.getProperty(o);if(g)b+=".validate";if(typeof m=="function"){a+=" "+b+"("+f+") "}else{a+=" "+b+".test("+f+") "}a+=") { "}}var E=E||[];E.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"format"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { format: ";if(c){a+=""+h}else{a+=""+e.util.toQuotedString(o)}a+=" } ";if(e.opts.messages!==false){a+=" , message: 'should match format \"";if(c){a+="' + "+h+" + '"}else{a+=""+e.util.escapeQuotes(o)}a+="\"' "}if(e.opts.verbose){a+=" , schema: ";if(c){a+="validate.schema"+n}else{a+=""+e.util.toQuotedString(o)}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var S=a;a=E.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+S+"]); "}else{a+=" validate.errors = ["+S+"]; return false; "}}else{a+=" var err = "+S+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } ";if(u){a+=" else { "}return a}},2678:e=>{"use strict";e.exports=function generate_if(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="errs__"+s;var d=e.util.copy(e);d.level++;var p="valid"+d.level;var m=e.schema["then"],g=e.schema["else"],y=m!==undefined&&(e.opts.strictKeywords?typeof m=="object"&&Object.keys(m).length>0||m===false:e.util.schemaHasRules(m,e.RULES.all)),P=g!==undefined&&(e.opts.strictKeywords?typeof g=="object"&&Object.keys(g).length>0||g===false:e.util.schemaHasRules(g,e.RULES.all)),b=d.baseId;if(y||P){var E;d.createErrors=false;d.schema=o;d.schemaPath=n;d.errSchemaPath=l;a+=" var "+h+" = errors; var "+c+" = true; ";var S=e.compositeRule;e.compositeRule=d.compositeRule=true;a+=" "+e.validate(d)+" ";d.baseId=b;d.createErrors=true;a+=" errors = "+h+"; if (vErrors !== null) { if ("+h+") vErrors.length = "+h+"; else vErrors = null; } ";e.compositeRule=d.compositeRule=S;if(y){a+=" if ("+p+") { ";d.schema=e.schema["then"];d.schemaPath=e.schemaPath+".then";d.errSchemaPath=e.errSchemaPath+"/then";a+=" "+e.validate(d)+" ";d.baseId=b;a+=" "+c+" = "+p+"; ";if(y&&P){E="ifClause"+s;a+=" var "+E+" = 'then'; "}else{E="'then'"}a+=" } ";if(P){a+=" else { "}}else{a+=" if (!"+p+") { "}if(P){d.schema=e.schema["else"];d.schemaPath=e.schemaPath+".else";d.errSchemaPath=e.errSchemaPath+"/else";a+=" "+e.validate(d)+" ";d.baseId=b;a+=" "+c+" = "+p+"; ";if(y&&P){E="ifClause"+s;a+=" var "+E+" = 'else'; "}else{E="'else'"}a+=" } "}a+=" if (!"+c+") { var err = ";if(e.createErrors!==false){a+=" { keyword: '"+"if"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { failingKeyword: "+E+" } ";if(e.opts.messages!==false){a+=" , message: 'should match \"' + "+E+" + '\" schema' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}a+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ";if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(vErrors); "}else{a+=" validate.errors = vErrors; return false; "}}a+=" } ";if(u){a+=" else { "}}else{if(u){a+=" if (true) { "}}return a}},734:(e,r,t)=>{"use strict";e.exports={$ref:t(6915),allOf:t(1308),anyOf:t(7128),$comment:t(3365),const:t(3507),contains:t(3348),dependencies:t(7862),enum:t(3691),format:t(1811),if:t(2678),items:t(7540),maximum:t(9510),minimum:t(9510),maxItems:t(2982),minItems:t(2982),maxLength:t(8598),minLength:t(8598),maxProperties:t(1667),minProperties:t(1667),multipleOf:t(2958),not:t(4453),oneOf:t(8899),pattern:t(5476),properties:t(6435),propertyNames:t(3862),required:t(3478),uniqueItems:t(6266),validate:t(2801)}},7540:e=>{"use strict";e.exports=function generate_items(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="errs__"+s;var d=e.util.copy(e);var p="";d.level++;var m="valid"+d.level;var g="i"+s,y=d.dataLevel=e.dataLevel+1,P="data"+y,b=e.baseId;a+="var "+h+" = errors;var "+c+";";if(Array.isArray(o)){var E=e.schema.additionalItems;if(E===false){a+=" "+c+" = "+f+".length <= "+o.length+"; ";var S=l;l=e.errSchemaPath+"/additionalItems";a+=" if (!"+c+") { ";var w=w||[];w.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"additionalItems"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { limit: "+o.length+" } ";if(e.opts.messages!==false){a+=" , message: 'should NOT have more than "+o.length+" items' "}if(e.opts.verbose){a+=" , schema: false , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var x=a;a=w.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+x+"]); "}else{a+=" validate.errors = ["+x+"]; return false; "}}else{a+=" var err = "+x+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } ";l=S;if(u){p+="}";a+=" else { "}}var $=o;if($){var _,R=-1,F=$.length-1;while(R0||_===false:e.util.schemaHasRules(_,e.RULES.all)){a+=" "+m+" = true; if ("+f+".length > "+R+") { ";var O=f+"["+R+"]";d.schema=_;d.schemaPath=n+"["+R+"]";d.errSchemaPath=l+"/"+R;d.errorPath=e.util.getPathExpr(e.errorPath,R,e.opts.jsonPointers,true);d.dataPathArr[y]=R;var D=e.validate(d);d.baseId=b;if(e.util.varOccurences(D,P)<2){a+=" "+e.util.varReplace(D,P,O)+" "}else{a+=" var "+P+" = "+O+"; "+D+" "}a+=" } ";if(u){a+=" if ("+m+") { ";p+="}"}}}}if(typeof E=="object"&&(e.opts.strictKeywords?typeof E=="object"&&Object.keys(E).length>0||E===false:e.util.schemaHasRules(E,e.RULES.all))){d.schema=E;d.schemaPath=e.schemaPath+".additionalItems";d.errSchemaPath=e.errSchemaPath+"/additionalItems";a+=" "+m+" = true; if ("+f+".length > "+o.length+") { for (var "+g+" = "+o.length+"; "+g+" < "+f+".length; "+g+"++) { ";d.errorPath=e.util.getPathExpr(e.errorPath,g,e.opts.jsonPointers,true);var O=f+"["+g+"]";d.dataPathArr[y]=g;var D=e.validate(d);d.baseId=b;if(e.util.varOccurences(D,P)<2){a+=" "+e.util.varReplace(D,P,O)+" "}else{a+=" var "+P+" = "+O+"; "+D+" "}if(u){a+=" if (!"+m+") break; "}a+=" } } ";if(u){a+=" if ("+m+") { ";p+="}"}}}else if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===false:e.util.schemaHasRules(o,e.RULES.all)){d.schema=o;d.schemaPath=n;d.errSchemaPath=l;a+=" for (var "+g+" = "+0+"; "+g+" < "+f+".length; "+g+"++) { ";d.errorPath=e.util.getPathExpr(e.errorPath,g,e.opts.jsonPointers,true);var O=f+"["+g+"]";d.dataPathArr[y]=g;var D=e.validate(d);d.baseId=b;if(e.util.varOccurences(D,P)<2){a+=" "+e.util.varReplace(D,P,O)+" "}else{a+=" var "+P+" = "+O+"; "+D+" "}if(u){a+=" if (!"+m+") break; "}a+=" }"}if(u){a+=" "+p+" if ("+h+" == errors) {"}return a}},2958:e=>{"use strict";e.exports=function generate_multipleOf(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c=e.opts.$data&&o&&o.$data,h;if(c){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";h="schema"+s}else{h=o}if(!(c||typeof o=="number")){throw new Error(r+" must be number")}a+="var division"+s+";if (";if(c){a+=" "+h+" !== undefined && ( typeof "+h+" != 'number' || "}a+=" (division"+s+" = "+f+" / "+h+", ";if(e.opts.multipleOfPrecision){a+=" Math.abs(Math.round(division"+s+") - division"+s+") > 1e-"+e.opts.multipleOfPrecision+" "}else{a+=" division"+s+" !== parseInt(division"+s+") "}a+=" ) ";if(c){a+=" ) "}a+=" ) { ";var d=d||[];d.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"multipleOf"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { multipleOf: "+h+" } ";if(e.opts.messages!==false){a+=" , message: 'should be multiple of ";if(c){a+="' + "+h}else{a+=""+h+"'"}}if(e.opts.verbose){a+=" , schema: ";if(c){a+="validate.schema"+n}else{a+=""+o}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var p=a;a=d.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+p+"]); "}else{a+=" validate.errors = ["+p+"]; return false; "}}else{a+=" var err = "+p+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+="} ";if(u){a+=" else { "}return a}},4453:e=>{"use strict";e.exports=function generate_not(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="errs__"+s;var h=e.util.copy(e);h.level++;var d="valid"+h.level;if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===false:e.util.schemaHasRules(o,e.RULES.all)){h.schema=o;h.schemaPath=n;h.errSchemaPath=l;a+=" var "+c+" = errors; ";var p=e.compositeRule;e.compositeRule=h.compositeRule=true;h.createErrors=false;var m;if(h.opts.allErrors){m=h.opts.allErrors;h.opts.allErrors=false}a+=" "+e.validate(h)+" ";h.createErrors=true;if(m)h.opts.allErrors=m;e.compositeRule=h.compositeRule=p;a+=" if ("+d+") { ";var g=g||[];g.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"not"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: {} ";if(e.opts.messages!==false){a+=" , message: 'should NOT be valid' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var y=a;a=g.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+y+"]); "}else{a+=" validate.errors = ["+y+"]; return false; "}}else{a+=" var err = "+y+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } else { errors = "+c+"; if (vErrors !== null) { if ("+c+") vErrors.length = "+c+"; else vErrors = null; } ";if(e.opts.allErrors){a+=" } "}}else{a+=" var err = ";if(e.createErrors!==false){a+=" { keyword: '"+"not"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: {} ";if(e.opts.messages!==false){a+=" , message: 'should NOT be valid' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}a+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ";if(u){a+=" if (false) { "}}return a}},8899:e=>{"use strict";e.exports=function generate_oneOf(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h="errs__"+s;var d=e.util.copy(e);var p="";d.level++;var m="valid"+d.level;var g=d.baseId,y="prevValid"+s,P="passingSchemas"+s;a+="var "+h+" = errors , "+y+" = false , "+c+" = false , "+P+" = null; ";var b=e.compositeRule;e.compositeRule=d.compositeRule=true;var E=o;if(E){var S,w=-1,x=E.length-1;while(w0||S===false:e.util.schemaHasRules(S,e.RULES.all)){d.schema=S;d.schemaPath=n+"["+w+"]";d.errSchemaPath=l+"/"+w;a+=" "+e.validate(d)+" ";d.baseId=g}else{a+=" var "+m+" = true; "}if(w){a+=" if ("+m+" && "+y+") { "+c+" = false; "+P+" = ["+P+", "+w+"]; } else { ";p+="}"}a+=" if ("+m+") { "+c+" = "+y+" = true; "+P+" = "+w+"; }"}}e.compositeRule=d.compositeRule=b;a+=""+p+"if (!"+c+") { var err = ";if(e.createErrors!==false){a+=" { keyword: '"+"oneOf"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { passingSchemas: "+P+" } ";if(e.opts.messages!==false){a+=" , message: 'should match exactly one schema in oneOf' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}a+="; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ";if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(vErrors); "}else{a+=" validate.errors = vErrors; return false; "}}a+="} else { errors = "+h+"; if (vErrors !== null) { if ("+h+") vErrors.length = "+h+"; else vErrors = null; }";if(e.opts.allErrors){a+=" } "}return a}},5476:e=>{"use strict";e.exports=function generate_pattern(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c=e.opts.$data&&o&&o.$data,h;if(c){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";h="schema"+s}else{h=o}var d=c?"(new RegExp("+h+"))":e.usePattern(o);a+="if ( ";if(c){a+=" ("+h+" !== undefined && typeof "+h+" != 'string') || "}a+=" !"+d+".test("+f+") ) { ";var p=p||[];p.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"pattern"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { pattern: ";if(c){a+=""+h}else{a+=""+e.util.toQuotedString(o)}a+=" } ";if(e.opts.messages!==false){a+=" , message: 'should match pattern \"";if(c){a+="' + "+h+" + '"}else{a+=""+e.util.escapeQuotes(o)}a+="\"' "}if(e.opts.verbose){a+=" , schema: ";if(c){a+="validate.schema"+n}else{a+=""+e.util.toQuotedString(o)}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var m=a;a=p.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+m+"]); "}else{a+=" validate.errors = ["+m+"]; return false; "}}else{a+=" var err = "+m+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+="} ";if(u){a+=" else { "}return a}},6435:e=>{"use strict";e.exports=function generate_properties(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="errs__"+s;var h=e.util.copy(e);var d="";h.level++;var p="valid"+h.level;var m="key"+s,g="idx"+s,y=h.dataLevel=e.dataLevel+1,P="data"+y,b="dataProperties"+s;var E=Object.keys(o||{}).filter(notProto),S=e.schema.patternProperties||{},w=Object.keys(S).filter(notProto),x=e.schema.additionalProperties,$=E.length||w.length,_=x===false,R=typeof x=="object"&&Object.keys(x).length,F=e.opts.removeAdditional,O=_||R||F,D=e.opts.ownProperties,j=e.baseId;var I=e.schema.required;if(I&&!(e.opts.$data&&I.$data)&&I.length8){a+=" || validate.schema"+n+".hasOwnProperty("+m+") "}else{var C=E;if(C){var A,N=-1,T=C.length-1;while(N0||ee===false:e.util.schemaHasRules(ee,e.RULES.all)){var re=e.util.getProperty(A),B=f+re,te=G&&ee.default!==undefined;h.schema=ee;h.schemaPath=n+re;h.errSchemaPath=l+"/"+e.util.escapeFragment(A);h.errorPath=e.util.getPath(e.errorPath,A,e.opts.jsonPointers);h.dataPathArr[y]=e.util.toQuotedString(A);var Z=e.validate(h);h.baseId=j;if(e.util.varOccurences(Z,P)<2){Z=e.util.varReplace(Z,P,B);var ae=B}else{var ae=P;a+=" var "+P+" = "+B+"; "}if(te){a+=" "+Z+" "}else{if(k&&k[A]){a+=" if ( "+ae+" === undefined ";if(D){a+=" || ! Object.prototype.hasOwnProperty.call("+f+", '"+e.util.escapeQuotes(A)+"') "}a+=") { "+p+" = false; ";var U=e.errorPath,Q=l,se=e.util.escapeQuotes(A);if(e.opts._errorDataPathProperty){e.errorPath=e.util.getPath(U,A,e.opts.jsonPointers)}l=e.errSchemaPath+"/required";var K=K||[];K.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"required"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { missingProperty: '"+se+"' } ";if(e.opts.messages!==false){a+=" , message: '";if(e.opts._errorDataPathProperty){a+="is a required property"}else{a+="should have required property \\'"+se+"\\'"}a+="' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var H=a;a=K.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+H+"]); "}else{a+=" validate.errors = ["+H+"]; return false; "}}else{a+=" var err = "+H+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}l=Q;e.errorPath=U;a+=" } else { "}else{if(u){a+=" if ( "+ae+" === undefined ";if(D){a+=" || ! Object.prototype.hasOwnProperty.call("+f+", '"+e.util.escapeQuotes(A)+"') "}a+=") { "+p+" = true; } else { "}else{a+=" if ("+ae+" !== undefined ";if(D){a+=" && Object.prototype.hasOwnProperty.call("+f+", '"+e.util.escapeQuotes(A)+"') "}a+=" ) { "}}a+=" "+Z+" } "}}if(u){a+=" if ("+p+") { ";d+="}"}}}}if(w.length){var ie=w;if(ie){var q,oe=-1,ne=ie.length-1;while(oe0||ee===false:e.util.schemaHasRules(ee,e.RULES.all)){h.schema=ee;h.schemaPath=e.schemaPath+".patternProperties"+e.util.getProperty(q);h.errSchemaPath=e.errSchemaPath+"/patternProperties/"+e.util.escapeFragment(q);if(D){a+=" "+b+" = "+b+" || Object.keys("+f+"); for (var "+g+"=0; "+g+"<"+b+".length; "+g+"++) { var "+m+" = "+b+"["+g+"]; "}else{a+=" for (var "+m+" in "+f+") { "}a+=" if ("+e.usePattern(q)+".test("+m+")) { ";h.errorPath=e.util.getPathExpr(e.errorPath,m,e.opts.jsonPointers);var B=f+"["+m+"]";h.dataPathArr[y]=m;var Z=e.validate(h);h.baseId=j;if(e.util.varOccurences(Z,P)<2){a+=" "+e.util.varReplace(Z,P,B)+" "}else{a+=" var "+P+" = "+B+"; "+Z+" "}if(u){a+=" if (!"+p+") break; "}a+=" } ";if(u){a+=" else "+p+" = true; "}a+=" } ";if(u){a+=" if ("+p+") { ";d+="}"}}}}}if(u){a+=" "+d+" if ("+c+" == errors) {"}return a}},3862:e=>{"use strict";e.exports=function generate_propertyNames(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="errs__"+s;var h=e.util.copy(e);var d="";h.level++;var p="valid"+h.level;a+="var "+c+" = errors;";if(e.opts.strictKeywords?typeof o=="object"&&Object.keys(o).length>0||o===false:e.util.schemaHasRules(o,e.RULES.all)){h.schema=o;h.schemaPath=n;h.errSchemaPath=l;var m="key"+s,g="idx"+s,y="i"+s,P="' + "+m+" + '",b=h.dataLevel=e.dataLevel+1,E="data"+b,S="dataProperties"+s,w=e.opts.ownProperties,x=e.baseId;if(w){a+=" var "+S+" = undefined; "}if(w){a+=" "+S+" = "+S+" || Object.keys("+f+"); for (var "+g+"=0; "+g+"<"+S+".length; "+g+"++) { var "+m+" = "+S+"["+g+"]; "}else{a+=" for (var "+m+" in "+f+") { "}a+=" var startErrs"+s+" = errors; ";var $=m;var _=e.compositeRule;e.compositeRule=h.compositeRule=true;var R=e.validate(h);h.baseId=x;if(e.util.varOccurences(R,E)<2){a+=" "+e.util.varReplace(R,E,$)+" "}else{a+=" var "+E+" = "+$+"; "+R+" "}e.compositeRule=h.compositeRule=_;a+=" if (!"+p+") { for (var "+y+"=startErrs"+s+"; "+y+"{"use strict";e.exports=function generate_ref(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.errSchemaPath+"/"+r;var l=!e.opts.allErrors;var u="data"+(i||"");var f="valid"+s;var c,h;if(o=="#"||o=="#/"){if(e.isRoot){c=e.async;h="validate"}else{c=e.root.schema.$async===true;h="root.refVal[0]"}}else{var d=e.resolveRef(e.baseId,o,e.isRoot);if(d===undefined){var p=e.MissingRefError.message(e.baseId,o);if(e.opts.missingRefs=="fail"){e.logger.error(p);var m=m||[];m.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"$ref"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(n)+" , params: { ref: '"+e.util.escapeQuotes(o)+"' } ";if(e.opts.messages!==false){a+=" , message: 'can\\'t resolve reference "+e.util.escapeQuotes(o)+"' "}if(e.opts.verbose){a+=" , schema: "+e.util.toQuotedString(o)+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+u+" "}a+=" } "}else{a+=" {} "}var g=a;a=m.pop();if(!e.compositeRule&&l){if(e.async){a+=" throw new ValidationError(["+g+"]); "}else{a+=" validate.errors = ["+g+"]; return false; "}}else{a+=" var err = "+g+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}if(l){a+=" if (false) { "}}else if(e.opts.missingRefs=="ignore"){e.logger.warn(p);if(l){a+=" if (true) { "}}else{throw new e.MissingRefError(e.baseId,o,p)}}else if(d.inline){var y=e.util.copy(e);y.level++;var P="valid"+y.level;y.schema=d.schema;y.schemaPath="";y.errSchemaPath=o;var b=e.validate(y).replace(/validate\.schema/g,d.code);a+=" "+b+" ";if(l){a+=" if ("+P+") { "}}else{c=d.$async===true||e.async&&d.$async!==false;h=d.code}}if(h){var m=m||[];m.push(a);a="";if(e.opts.passContext){a+=" "+h+".call(this, "}else{a+=" "+h+"( "}a+=" "+u+", (dataPath || '')";if(e.errorPath!='""'){a+=" + "+e.errorPath}var E=i?"data"+(i-1||""):"parentData",S=i?e.dataPathArr[i]:"parentDataProperty";a+=" , "+E+" , "+S+", rootData) ";var w=a;a=m.pop();if(c){if(!e.async)throw new Error("async schema referenced by sync schema");if(l){a+=" var "+f+"; "}a+=" try { await "+w+"; ";if(l){a+=" "+f+" = true; "}a+=" } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; ";if(l){a+=" "+f+" = false; "}a+=" } ";if(l){a+=" if ("+f+") { "}}else{a+=" if (!"+w+") { if (vErrors === null) vErrors = "+h+".errors; else vErrors = vErrors.concat("+h+".errors); errors = vErrors.length; } ";if(l){a+=" else { "}}}return a}},3478:e=>{"use strict";e.exports=function generate_required(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}var p="schema"+s;if(!h){if(o.length0||E===false:e.util.schemaHasRules(E,e.RULES.all)))){m[m.length]=y}}}}else{var m=o}}if(h||m.length){var S=e.errorPath,w=h||m.length>=e.opts.loopRequired,x=e.opts.ownProperties;if(u){a+=" var missing"+s+"; ";if(w){if(!h){a+=" var "+p+" = validate.schema"+n+"; "}var $="i"+s,_="schema"+s+"["+$+"]",R="' + "+_+" + '";if(e.opts._errorDataPathProperty){e.errorPath=e.util.getPathExpr(S,_,e.opts.jsonPointers)}a+=" var "+c+" = true; ";if(h){a+=" if (schema"+s+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+s+")) "+c+" = false; else {"}a+=" for (var "+$+" = 0; "+$+" < "+p+".length; "+$+"++) { "+c+" = "+f+"["+p+"["+$+"]] !== undefined ";if(x){a+=" && Object.prototype.hasOwnProperty.call("+f+", "+p+"["+$+"]) "}a+="; if (!"+c+") break; } ";if(h){a+=" } "}a+=" if (!"+c+") { ";var F=F||[];F.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"required"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { missingProperty: '"+R+"' } ";if(e.opts.messages!==false){a+=" , message: '";if(e.opts._errorDataPathProperty){a+="is a required property"}else{a+="should have required property \\'"+R+"\\'"}a+="' "}if(e.opts.verbose){a+=" , schema: validate.schema"+n+" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var O=a;a=F.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+O+"]); "}else{a+=" validate.errors = ["+O+"]; return false; "}}else{a+=" var err = "+O+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } else { "}else{a+=" if ( ";var D=m;if(D){var j,$=-1,I=D.length-1;while(${"use strict";e.exports=function generate_uniqueItems(e,r,t){var a=" ";var s=e.level;var i=e.dataLevel;var o=e.schema[r];var n=e.schemaPath+e.util.getProperty(r);var l=e.errSchemaPath+"/"+r;var u=!e.opts.allErrors;var f="data"+(i||"");var c="valid"+s;var h=e.opts.$data&&o&&o.$data,d;if(h){a+=" var schema"+s+" = "+e.util.getData(o.$data,i,e.dataPathArr)+"; ";d="schema"+s}else{d=o}if((o||h)&&e.opts.uniqueItems!==false){if(h){a+=" var "+c+"; if ("+d+" === false || "+d+" === undefined) "+c+" = true; else if (typeof "+d+" != 'boolean') "+c+" = false; else { "}a+=" var i = "+f+".length , "+c+" = true , j; if (i > 1) { ";var p=e.schema.items&&e.schema.items.type,m=Array.isArray(p);if(!p||p=="object"||p=="array"||m&&(p.indexOf("object")>=0||p.indexOf("array")>=0)){a+=" outer: for (;i--;) { for (j = i; j--;) { if (equal("+f+"[i], "+f+"[j])) { "+c+" = false; break outer; } } } "}else{a+=" var itemIndices = {}, item; for (;i--;) { var item = "+f+"[i]; ";var g="checkDataType"+(m?"s":"");a+=" if ("+e.util[g](p,"item",e.opts.strictNumbers,true)+") continue; ";if(m){a+=" if (typeof item == 'string') item = '\"' + item; "}a+=" if (typeof itemIndices[item] == 'number') { "+c+" = false; j = itemIndices[item]; break; } itemIndices[item] = i; } "}a+=" } ";if(h){a+=" } "}a+=" if (!"+c+") { ";var y=y||[];y.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+"uniqueItems"+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(l)+" , params: { i: i, j: j } ";if(e.opts.messages!==false){a+=" , message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)' "}if(e.opts.verbose){a+=" , schema: ";if(h){a+="validate.schema"+n}else{a+=""+o}a+=" , parentSchema: validate.schema"+e.schemaPath+" , data: "+f+" "}a+=" } "}else{a+=" {} "}var P=a;a=y.pop();if(!e.compositeRule&&u){if(e.async){a+=" throw new ValidationError(["+P+"]); "}else{a+=" validate.errors = ["+P+"]; return false; "}}else{a+=" var err = "+P+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}a+=" } ";if(u){a+=" else { "}}else{if(u){a+=" if (true) { "}}return a}},2801:e=>{"use strict";e.exports=function generate_validate(e,r,t){var a="";var s=e.schema.$async===true,i=e.util.schemaHasRulesExcept(e.schema,e.RULES.all,"$ref"),o=e.self._getId(e.schema);if(e.opts.strictKeywords){var n=e.util.schemaUnknownRules(e.schema,e.RULES.keywords);if(n){var l="unknown keyword: "+n;if(e.opts.strictKeywords==="log")e.logger.warn(l);else throw new Error(l)}}if(e.isTop){a+=" var validate = ";if(s){e.async=true;a+="async "}a+="function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; ";if(o&&(e.opts.sourceCode||e.opts.processCode)){a+=" "+("/*# sourceURL="+o+" */")+" "}}if(typeof e.schema=="boolean"||!(i||e.schema.$ref)){var r="false schema";var u=e.level;var f=e.dataLevel;var c=e.schema[r];var h=e.schemaPath+e.util.getProperty(r);var d=e.errSchemaPath+"/"+r;var p=!e.opts.allErrors;var m;var g="data"+(f||"");var y="valid"+u;if(e.schema===false){if(e.isTop){p=true}else{a+=" var "+y+" = false; "}var P=P||[];P.push(a);a="";if(e.createErrors!==false){a+=" { keyword: '"+(m||"false schema")+"' , dataPath: (dataPath || '') + "+e.errorPath+" , schemaPath: "+e.util.toQuotedString(d)+" , params: {} ";if(e.opts.messages!==false){a+=" , message: 'boolean schema is false' "}if(e.opts.verbose){a+=" , schema: false , parentSchema: validate.schema"+e.schemaPath+" , data: "+g+" "}a+=" } "}else{a+=" {} "}var b=a;a=P.pop();if(!e.compositeRule&&p){if(e.async){a+=" throw new ValidationError(["+b+"]); "}else{a+=" validate.errors = ["+b+"]; return false; "}}else{a+=" var err = "+b+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; "}}else{if(e.isTop){if(s){a+=" return data; "}else{a+=" validate.errors = null; return true; "}}else{a+=" var "+y+" = true; "}}if(e.isTop){a+=" }; return validate; "}return a}if(e.isTop){var E=e.isTop,u=e.level=0,f=e.dataLevel=0,g="data";e.rootId=e.resolve.fullPath(e.self._getId(e.root.schema));e.baseId=e.baseId||e.rootId;delete e.isTop;e.dataPathArr=[""];if(e.schema.default!==undefined&&e.opts.useDefaults&&e.opts.strictDefaults){var S="default is ignored in the schema root";if(e.opts.strictDefaults==="log")e.logger.warn(S);else throw new Error(S)}a+=" var vErrors = null; ";a+=" var errors = 0; ";a+=" if (rootData === undefined) rootData = data; "}else{var u=e.level,f=e.dataLevel,g="data"+(f||"");if(o)e.baseId=e.resolve.url(e.baseId,o);if(s&&!e.async)throw new Error("async schema in sync schema");a+=" var errs_"+u+" = errors;"}var y="valid"+u,p=!e.opts.allErrors,w="",x="";var m;var $=e.schema.type,_=Array.isArray($);if($&&e.opts.nullable&&e.schema.nullable===true){if(_){if($.indexOf("null")==-1)$=$.concat("null")}else if($!="null"){$=[$,"null"];_=true}}if(_&&$.length==1){$=$[0];_=false}if(e.schema.$ref&&i){if(e.opts.extendRefs=="fail"){throw new Error('$ref: validation keywords used in schema at path "'+e.errSchemaPath+'" (see option extendRefs)')}else if(e.opts.extendRefs!==true){i=false;e.logger.warn('$ref: keywords ignored in schema at path "'+e.errSchemaPath+'"')}}if(e.schema.$comment&&e.opts.$comment){a+=" "+e.RULES.all.$comment.code(e,"$comment")}if($){if(e.opts.coerceTypes){var R=e.util.coerceToTypes(e.opts.coerceTypes,$)}var F=e.RULES.types[$];if(R||_||F===true||F&&!$shouldUseGroup(F)){var h=e.schemaPath+".type",d=e.errSchemaPath+"/type";var h=e.schemaPath+".type",d=e.errSchemaPath+"/type",O=_?"checkDataTypes":"checkDataType";a+=" if ("+e.util[O]($,g,e.opts.strictNumbers,true)+") { ";if(R){var D="dataType"+u,j="coerced"+u;a+=" var "+D+" = typeof "+g+"; var "+j+" = undefined; ";if(e.opts.coerceTypes=="array"){a+=" if ("+D+" == 'object' && Array.isArray("+g+") && "+g+".length == 1) { "+g+" = "+g+"[0]; "+D+" = typeof "+g+"; if ("+e.util.checkDataType(e.schema.type,g,e.opts.strictNumbers)+") "+j+" = "+g+"; } "}a+=" if ("+j+" !== undefined) ; ";var I=R;if(I){var k,C=-1,A=I.length-1;while(C{"use strict";var a=/^[a-z_$][a-z0-9_$-]*$/i;var s=t(9481);var i=t(7125);e.exports={add:addKeyword,get:getKeyword,remove:removeKeyword,validate:validateKeyword};function addKeyword(e,r){var t=this.RULES;if(t.keywords[e])throw new Error("Keyword "+e+" is already defined");if(!a.test(e))throw new Error("Keyword "+e+" is not a valid identifier");if(r){this.validateKeyword(r,true);var i=r.type;if(Array.isArray(i)){for(var o=0;o{"use strict";e.exports=function equal(e,r){if(e===r)return true;if(e&&r&&typeof e=="object"&&typeof r=="object"){if(e.constructor!==r.constructor)return false;var t,a,s;if(Array.isArray(e)){t=e.length;if(t!=r.length)return false;for(a=t;a--!==0;)if(!equal(e[a],r[a]))return false;return true}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();s=Object.keys(e);t=s.length;if(t!==Object.keys(r).length)return false;for(a=t;a--!==0;)if(!Object.prototype.hasOwnProperty.call(r,s[a]))return false;for(a=t;a--!==0;){var i=s[a];if(!equal(e[i],r[i]))return false}return true}return e!==e&&r!==r}},7351:e=>{"use strict";e.exports=function(e,r){if(!r)r={};if(typeof r==="function")r={cmp:r};var t=typeof r.cycles==="boolean"?r.cycles:false;var a=r.cmp&&function(e){return function(r){return function(t,a){var s={key:t,value:r[t]};var i={key:a,value:r[a]};return e(s,i)}}}(r.cmp);var s=[];return function stringify(e){if(e&&e.toJSON&&typeof e.toJSON==="function"){e=e.toJSON()}if(e===undefined)return;if(typeof e=="number")return isFinite(e)?""+e:"null";if(typeof e!=="object")return JSON.stringify(e);var r,i;if(Array.isArray(e)){i="[";for(r=0;r{"use strict";var r=e.exports=function(e,r,t){if(typeof r=="function"){t=r;r={}}t=r.cb||t;var a=typeof t=="function"?t:t.pre||function(){};var s=t.post||function(){};_traverse(r,a,s,e,"",e)};r.keywords={additionalItems:true,items:true,contains:true,additionalProperties:true,propertyNames:true,not:true};r.arrayKeywords={items:true,allOf:true,anyOf:true,oneOf:true};r.propsKeywords={definitions:true,properties:true,patternProperties:true,dependencies:true};r.skipKeywords={default:true,enum:true,const:true,required:true,maximum:true,minimum:true,exclusiveMaximum:true,exclusiveMinimum:true,multipleOf:true,maxLength:true,minLength:true,pattern:true,format:true,maxItems:true,minItems:true,uniqueItems:true,maxProperties:true,minProperties:true};function _traverse(e,t,a,s,i,o,n,l,u,f){if(s&&typeof s=="object"&&!Array.isArray(s)){t(s,i,o,n,l,u,f);for(var c in s){var h=s[c];if(Array.isArray(h)){if(c in r.arrayKeywords){for(var d=0;d{"use strict";Object.defineProperty(r,"__esModule",{value:true});r["default"]=void 0;const{stringHints:a,numberHints:s}=t(544);const i={type:1,not:1,oneOf:1,anyOf:1,if:1,enum:1,const:1,instanceof:1,required:2,pattern:2,patternRequired:2,format:2,formatMinimum:2,formatMaximum:2,minimum:2,exclusiveMinimum:2,maximum:2,exclusiveMaximum:2,multipleOf:2,uniqueItems:2,contains:2,minLength:2,maxLength:2,minItems:2,maxItems:2,minProperties:2,maxProperties:2,dependencies:2,propertyNames:2,additionalItems:2,additionalProperties:2,absolutePath:2};function filterMax(e,r){const t=e.reduce(((e,t)=>Math.max(e,r(t))),0);return e.filter((e=>r(e)===t))}function filterChildren(e){let r=e;r=filterMax(r,(e=>e.dataPath?e.dataPath.length:0));r=filterMax(r,(e=>i[e.keyword]||2));return r}function findAllChildren(e,r){let t=e.length-1;const predicate=r=>e[t].schemaPath.indexOf(r)!==0;while(t>-1&&!r.every(predicate)){if(e[t].keyword==="anyOf"||e[t].keyword==="oneOf"){const r=extractRefs(e[t]);const a=findAllChildren(e.slice(0,t),r.concat(e[t].schemaPath));t=a-1}else{t-=1}}return t+1}function extractRefs(e){const{schema:r}=e;if(!Array.isArray(r)){return[]}return r.map((({$ref:e})=>e)).filter((e=>e))}function groupChildrenByFirstChild(e){const r=[];let t=e.length-1;while(t>0){const a=e[t];if(a.keyword==="anyOf"||a.keyword==="oneOf"){const s=extractRefs(a);const i=findAllChildren(e.slice(0,t),s.concat(a.schemaPath));if(i!==t){r.push(Object.assign({},a,{children:e.slice(i,t)}));t=i}else{r.push(a)}}else{r.push(a)}t-=1}if(t===0){r.push(e[t])}return r.reverse()}function indent(e,r){return e.replace(/\n(?!$)/g,`\n${r}`)}function hasNotInSchema(e){return!!e.not}function findFirstTypedSchema(e){if(hasNotInSchema(e)){return findFirstTypedSchema(e.not)}return e}function canApplyNot(e){const r=findFirstTypedSchema(e);return likeNumber(r)||likeInteger(r)||likeString(r)||likeNull(r)||likeBoolean(r)}function isObject(e){return typeof e==="object"&&e!==null}function likeNumber(e){return e.type==="number"||typeof e.minimum!=="undefined"||typeof e.exclusiveMinimum!=="undefined"||typeof e.maximum!=="undefined"||typeof e.exclusiveMaximum!=="undefined"||typeof e.multipleOf!=="undefined"}function likeInteger(e){return e.type==="integer"||typeof e.minimum!=="undefined"||typeof e.exclusiveMinimum!=="undefined"||typeof e.maximum!=="undefined"||typeof e.exclusiveMaximum!=="undefined"||typeof e.multipleOf!=="undefined"}function likeString(e){return e.type==="string"||typeof e.minLength!=="undefined"||typeof e.maxLength!=="undefined"||typeof e.pattern!=="undefined"||typeof e.format!=="undefined"||typeof e.formatMinimum!=="undefined"||typeof e.formatMaximum!=="undefined"}function likeBoolean(e){return e.type==="boolean"}function likeArray(e){return e.type==="array"||typeof e.minItems==="number"||typeof e.maxItems==="number"||typeof e.uniqueItems!=="undefined"||typeof e.items!=="undefined"||typeof e.additionalItems!=="undefined"||typeof e.contains!=="undefined"}function likeObject(e){return e.type==="object"||typeof e.minProperties!=="undefined"||typeof e.maxProperties!=="undefined"||typeof e.required!=="undefined"||typeof e.properties!=="undefined"||typeof e.patternProperties!=="undefined"||typeof e.additionalProperties!=="undefined"||typeof e.dependencies!=="undefined"||typeof e.propertyNames!=="undefined"||typeof e.patternRequired!=="undefined"}function likeNull(e){return e.type==="null"}function getArticle(e){if(/^[aeiou]/i.test(e)){return"an"}return"a"}function getSchemaNonTypes(e){if(!e){return""}if(!e.type){if(likeNumber(e)||likeInteger(e)){return" | should be any non-number"}if(likeString(e)){return" | should be any non-string"}if(likeArray(e)){return" | should be any non-array"}if(likeObject(e)){return" | should be any non-object"}}return""}function formatHints(e){return e.length>0?`(${e.join(", ")})`:""}function getHints(e,r){if(likeNumber(e)||likeInteger(e)){return s(e,r)}else if(likeString(e)){return a(e,r)}return[]}class ValidationError extends Error{constructor(e,r,t={}){super();this.name="ValidationError";this.errors=e;this.schema=r;let a;let s;if(r.title&&(!t.name||!t.baseDataPath)){const e=r.title.match(/^(.+) (.+)$/);if(e){if(!t.name){[,a]=e}if(!t.baseDataPath){[,,s]=e}}}this.headerName=t.name||a||"Object";this.baseDataPath=t.baseDataPath||s||"configuration";this.postFormatter=t.postFormatter||null;const i=`Invalid ${this.baseDataPath} object. ${this.headerName} has been initialized using ${getArticle(this.baseDataPath)} ${this.baseDataPath} object that does not match the API schema.\n`;this.message=`${i}${this.formatValidationErrors(e)}`;Error.captureStackTrace(this,this.constructor)}getSchemaPart(e){const r=e.split("/");let t=this.schema;for(let e=1;e{if(!s){return this.formatSchema(r,a,t)}if(t.includes(r)){return"(recursive)"}return this.formatSchema(r,a,t.concat(e))};if(hasNotInSchema(e)&&!likeObject(e)){if(canApplyNot(e.not)){a=!r;return formatInnerSchema(e.not)}const t=!e.not.not;const s=r?"":"non ";a=!r;return t?s+formatInnerSchema(e.not):formatInnerSchema(e.not)}if(e.instanceof){const{instanceof:r}=e;const t=!Array.isArray(r)?[r]:r;return t.map((e=>e==="Function"?"function":e)).join(" | ")}if(e.enum){return e.enum.map((e=>JSON.stringify(e))).join(" | ")}if(typeof e.const!=="undefined"){return JSON.stringify(e.const)}if(e.oneOf){return e.oneOf.map((e=>formatInnerSchema(e,true))).join(" | ")}if(e.anyOf){return e.anyOf.map((e=>formatInnerSchema(e,true))).join(" | ")}if(e.allOf){return e.allOf.map((e=>formatInnerSchema(e,true))).join(" & ")}if(e.if){const{if:r,then:t,else:a}=e;return`${r?`if ${formatInnerSchema(r)}`:""}${t?` then ${formatInnerSchema(t)}`:""}${a?` else ${formatInnerSchema(a)}`:""}`}if(e.$ref){return formatInnerSchema(this.getSchemaPart(e.$ref),true)}if(likeNumber(e)||likeInteger(e)){const[t,...a]=getHints(e,r);const s=`${t}${a.length>0?` ${formatHints(a)}`:""}`;return r?s:a.length>0?`non-${t} | ${s}`:`non-${t}`}if(likeString(e)){const[t,...a]=getHints(e,r);const s=`${t}${a.length>0?` ${formatHints(a)}`:""}`;return r?s:s==="string"?"non-string":`non-string | ${s}`}if(likeBoolean(e)){return`${r?"":"non-"}boolean`}if(likeArray(e)){a=true;const r=[];if(typeof e.minItems==="number"){r.push(`should not have fewer than ${e.minItems} item${e.minItems>1?"s":""}`)}if(typeof e.maxItems==="number"){r.push(`should not have more than ${e.maxItems} item${e.maxItems>1?"s":""}`)}if(e.uniqueItems){r.push("should not have duplicate items")}const t=typeof e.additionalItems==="undefined"||Boolean(e.additionalItems);let s="";if(e.items){if(Array.isArray(e.items)&&e.items.length>0){s=`${e.items.map((e=>formatInnerSchema(e))).join(", ")}`;if(t){if(e.additionalItems&&isObject(e.additionalItems)&&Object.keys(e.additionalItems).length>0){r.push(`additional items should be ${formatInnerSchema(e.additionalItems)}`)}}}else if(e.items&&Object.keys(e.items).length>0){s=`${formatInnerSchema(e.items)}`}else{s="any"}}else{s="any"}if(e.contains&&Object.keys(e.contains).length>0){r.push(`should contains at least one ${this.formatSchema(e.contains)} item`)}return`[${s}${t?", ...":""}]${r.length>0?` (${r.join(", ")})`:""}`}if(likeObject(e)){a=true;const r=[];if(typeof e.minProperties==="number"){r.push(`should not have fewer than ${e.minProperties} ${e.minProperties>1?"properties":"property"}`)}if(typeof e.maxProperties==="number"){r.push(`should not have more than ${e.maxProperties} ${e.minProperties&&e.minProperties>1?"properties":"property"}`)}if(e.patternProperties&&Object.keys(e.patternProperties).length>0){const t=Object.keys(e.patternProperties);r.push(`additional property names should match pattern${t.length>1?"s":""} ${t.map((e=>JSON.stringify(e))).join(" | ")}`)}const t=e.properties?Object.keys(e.properties):[];const s=e.required?e.required:[];const i=[...new Set([].concat(s).concat(t))];const o=i.map((e=>{const r=s.includes(e);return`${e}${r?"":"?"}`})).concat(typeof e.additionalProperties==="undefined"||Boolean(e.additionalProperties)?e.additionalProperties&&isObject(e.additionalProperties)?[`: ${formatInnerSchema(e.additionalProperties)}`]:["…"]:[]).join(", ");const{dependencies:n,propertyNames:l,patternRequired:u}=e;if(n){Object.keys(n).forEach((e=>{const t=n[e];if(Array.isArray(t)){r.push(`should have ${t.length>1?"properties":"property"} ${t.map((e=>`'${e}'`)).join(", ")} when property '${e}' is present`)}else{r.push(`should be valid according to the schema ${formatInnerSchema(t)} when property '${e}' is present`)}}))}if(l&&Object.keys(l).length>0){r.push(`each property name should match format ${JSON.stringify(e.propertyNames.format)}`)}if(u&&u.length>0){r.push(`should have property matching pattern ${u.map((e=>JSON.stringify(e)))}`)}return`object {${o?` ${o} `:""}}${r.length>0?` (${r.join(", ")})`:""}`}if(likeNull(e)){return`${r?"":"non-"}null`}if(Array.isArray(e.type)){return`${e.type.join(" | ")}`}return JSON.stringify(e,null,2)}getSchemaPartText(e,r,t=false,a=true){if(!e){return""}if(Array.isArray(r)){for(let t=0;t ${e.description}`}if(e.link){s+=`\n-> Read more at ${e.link}`}return s}getSchemaPartDescription(e){if(!e){return""}while(e.$ref){e=this.getSchemaPart(e.$ref)}let r="";if(e.description){r+=`\n-> ${e.description}`}if(e.link){r+=`\n-> Read more at ${e.link}`}return r}formatValidationError(e){const{keyword:r,dataPath:t}=e;const a=`${this.baseDataPath}${t}`;switch(r){case"type":{const{parentSchema:r,params:t}=e;switch(t.type){case"number":return`${a} should be a ${this.getSchemaPartText(r,false,true)}`;case"integer":return`${a} should be an ${this.getSchemaPartText(r,false,true)}`;case"string":return`${a} should be a ${this.getSchemaPartText(r,false,true)}`;case"boolean":return`${a} should be a ${this.getSchemaPartText(r,false,true)}`;case"array":return`${a} should be an array:\n${this.getSchemaPartText(r)}`;case"object":return`${a} should be an object:\n${this.getSchemaPartText(r)}`;case"null":return`${a} should be a ${this.getSchemaPartText(r,false,true)}`;default:return`${a} should be:\n${this.getSchemaPartText(r)}`}}case"instanceof":{const{parentSchema:r}=e;return`${a} should be an instance of ${this.getSchemaPartText(r,false,true)}`}case"pattern":{const{params:r,parentSchema:t}=e;const{pattern:s}=r;return`${a} should match pattern ${JSON.stringify(s)}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"format":{const{params:r,parentSchema:t}=e;const{format:s}=r;return`${a} should match format ${JSON.stringify(s)}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"formatMinimum":case"formatMaximum":{const{params:r,parentSchema:t}=e;const{comparison:s,limit:i}=r;return`${a} should be ${s} ${JSON.stringify(i)}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"minimum":case"maximum":case"exclusiveMinimum":case"exclusiveMaximum":{const{parentSchema:r,params:t}=e;const{comparison:s,limit:i}=t;const[,...o]=getHints(r,true);if(o.length===0){o.push(`should be ${s} ${i}`)}return`${a} ${o.join(" ")}${getSchemaNonTypes(r)}.${this.getSchemaPartDescription(r)}`}case"multipleOf":{const{params:r,parentSchema:t}=e;const{multipleOf:s}=r;return`${a} should be multiple of ${s}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"patternRequired":{const{params:r,parentSchema:t}=e;const{missingPattern:s}=r;return`${a} should have property matching pattern ${JSON.stringify(s)}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"minLength":{const{params:r,parentSchema:t}=e;const{limit:s}=r;if(s===1){return`${a} should be a non-empty string${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}const i=s-1;return`${a} should be longer than ${i} character${i>1?"s":""}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"minItems":{const{params:r,parentSchema:t}=e;const{limit:s}=r;if(s===1){return`${a} should be a non-empty array${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}return`${a} should not have fewer than ${s} items${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"minProperties":{const{params:r,parentSchema:t}=e;const{limit:s}=r;if(s===1){return`${a} should be a non-empty object${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}return`${a} should not have fewer than ${s} properties${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"maxLength":{const{params:r,parentSchema:t}=e;const{limit:s}=r;const i=s+1;return`${a} should be shorter than ${i} character${i>1?"s":""}${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"maxItems":{const{params:r,parentSchema:t}=e;const{limit:s}=r;return`${a} should not have more than ${s} items${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"maxProperties":{const{params:r,parentSchema:t}=e;const{limit:s}=r;return`${a} should not have more than ${s} properties${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"uniqueItems":{const{params:r,parentSchema:t}=e;const{i:s}=r;return`${a} should not contain the item '${e.data[s]}' twice${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"additionalItems":{const{params:r,parentSchema:t}=e;const{limit:s}=r;return`${a} should not have more than ${s} items${getSchemaNonTypes(t)}. These items are valid:\n${this.getSchemaPartText(t)}`}case"contains":{const{parentSchema:r}=e;return`${a} should contains at least one ${this.getSchemaPartText(r,["contains"])} item${getSchemaNonTypes(r)}.`}case"required":{const{parentSchema:r,params:t}=e;const s=t.missingProperty.replace(/^\./,"");const i=r&&Boolean(r.properties&&r.properties[s]);return`${a} misses the property '${s}'${getSchemaNonTypes(r)}.${i?` Should be:\n${this.getSchemaPartText(r,["properties",s])}`:this.getSchemaPartDescription(r)}`}case"additionalProperties":{const{params:r,parentSchema:t}=e;const{additionalProperty:s}=r;return`${a} has an unknown property '${s}'${getSchemaNonTypes(t)}. These properties are valid:\n${this.getSchemaPartText(t)}`}case"dependencies":{const{params:r,parentSchema:t}=e;const{property:s,deps:i}=r;const o=i.split(",").map((e=>`'${e.trim()}'`)).join(", ");return`${a} should have properties ${o} when property '${s}' is present${getSchemaNonTypes(t)}.${this.getSchemaPartDescription(t)}`}case"propertyNames":{const{params:r,parentSchema:t,schema:s}=e;const{propertyName:i}=r;return`${a} property name '${i}' is invalid${getSchemaNonTypes(t)}. Property names should be match format ${JSON.stringify(s.format)}.${this.getSchemaPartDescription(t)}`}case"enum":{const{parentSchema:r}=e;if(r&&r.enum&&r.enum.length===1){return`${a} should be ${this.getSchemaPartText(r,false,true)}`}return`${a} should be one of these:\n${this.getSchemaPartText(r)}`}case"const":{const{parentSchema:r}=e;return`${a} should be equal to constant ${this.getSchemaPartText(r,false,true)}`}case"not":{const r=likeObject(e.parentSchema)?`\n${this.getSchemaPartText(e.parentSchema)}`:"";const t=this.getSchemaPartText(e.schema,false,false,false);if(canApplyNot(e.schema)){return`${a} should be any ${t}${r}.`}const{schema:s,parentSchema:i}=e;return`${a} should not be ${this.getSchemaPartText(s,false,true)}${i&&likeObject(i)?`\n${this.getSchemaPartText(i)}`:""}`}case"oneOf":case"anyOf":{const{parentSchema:r,children:t}=e;if(t&&t.length>0){if(e.schema.length===1){const e=t[t.length-1];const a=t.slice(0,t.length-1);return this.formatValidationError(Object.assign({},e,{children:a,parentSchema:Object.assign({},r,e.parentSchema)}))}let s=filterChildren(t);if(s.length===1){return this.formatValidationError(s[0])}s=groupChildrenByFirstChild(s);return`${a} should be one of these:\n${this.getSchemaPartText(r)}\nDetails:\n${s.map((e=>` * ${indent(this.formatValidationError(e)," ")}`)).join("\n")}`}return`${a} should be one of these:\n${this.getSchemaPartText(r)}`}case"if":{const{params:r,parentSchema:t}=e;const{failingKeyword:s}=r;return`${a} should match "${s}" schema:\n${this.getSchemaPartText(t,[s])}`}case"absolutePath":{const{message:r,parentSchema:t}=e;return`${a}: ${r}${this.getSchemaPartDescription(t)}`}default:{const{message:r,parentSchema:t}=e;const s=JSON.stringify(e,null,2);return`${a} ${r} (${s}).\n${this.getSchemaPartText(t,false)}`}}}formatValidationErrors(e){return e.map((e=>{let r=this.formatValidationError(e);if(this.postFormatter){r=this.postFormatter(r,e)}return` - ${indent(r," ")}`})).join("\n")}}var o=ValidationError;r["default"]=o},1489:(e,r,t)=>{"use strict";const{validate:a,ValidationError:s}=t(2121);e.exports={validate:a,ValidationError:s}},9294:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r["default"]=void 0;function errorMessage(e,r,t){return{dataPath:undefined,schemaPath:undefined,keyword:"absolutePath",params:{absolutePath:t},message:e,parentSchema:r}}function getErrorFor(e,r,t){const a=e?`The provided value ${JSON.stringify(t)} is not an absolute path!`:`A relative path is expected. However, the provided value ${JSON.stringify(t)} is an absolute path!`;return errorMessage(a,r,t)}function addAbsolutePathKeyword(e){e.addKeyword("absolutePath",{errors:true,type:"string",compile(e,r){const callback=t=>{let a=true;const s=t.includes("!");if(s){callback.errors=[errorMessage(`The provided value ${JSON.stringify(t)} contains exclamation mark (!) which is not allowed because it's reserved for loader syntax.`,r,t)];a=false}const i=e===/^(?:[A-Za-z]:(\\|\/)|\\\\|\/)/.test(t);if(!i){callback.errors=[getErrorFor(e,r,t)];a=false}return a};callback.errors=[];return callback}});return e}var t=addAbsolutePathKeyword;r["default"]=t},6378:e=>{"use strict";class Range{static getOperator(e,r){if(e==="left"){return r?">":">="}return r?"<":"<="}static formatRight(e,r,t){if(r===false){return Range.formatLeft(e,!r,!t)}return`should be ${Range.getOperator("right",t)} ${e}`}static formatLeft(e,r,t){if(r===false){return Range.formatRight(e,!r,!t)}return`should be ${Range.getOperator("left",t)} ${e}`}static formatRange(e,r,t,a,s){let i="should be";i+=` ${Range.getOperator(s?"left":"right",s?t:!t)} ${e} `;i+=s?"and":"or";i+=` ${Range.getOperator(s?"right":"left",s?a:!a)} ${r}`;return i}static getRangeValue(e,r){let t=r?Infinity:-Infinity;let a=-1;const s=r?([e])=>e<=t:([e])=>e>=t;for(let r=0;r-1){return e[a]}return[Infinity,true]}constructor(){this._left=[];this._right=[]}left(e,r=false){this._left.push([e,r])}right(e,r=false){this._right.push([e,r])}format(e=true){const[r,t]=Range.getRangeValue(this._left,e);const[a,s]=Range.getRangeValue(this._right,!e);if(!Number.isFinite(r)&&!Number.isFinite(a)){return""}const i=t?r+1:r;const o=s?a-1:a;if(i===o){return`should be ${e?"":"!"}= ${i}`}if(Number.isFinite(r)&&!Number.isFinite(a)){return Range.formatLeft(r,e,t)}if(!Number.isFinite(r)&&Number.isFinite(a)){return Range.formatRight(a,e,s)}return Range.formatRange(r,a,t,s,e)}}e.exports=Range},544:(e,r,t)=>{"use strict";const a=t(6378);e.exports.stringHints=function stringHints(e,r){const t=[];let a="string";const s={...e};if(!r){const e=s.minLength;const r=s.formatMinimum;const t=s.formatExclusiveMaximum;s.minLength=s.maxLength;s.maxLength=e;s.formatMinimum=s.formatMaximum;s.formatMaximum=r;s.formatExclusiveMaximum=!s.formatExclusiveMinimum;s.formatExclusiveMinimum=!t}if(typeof s.minLength==="number"){if(s.minLength===1){a="non-empty string"}else{const e=Math.max(s.minLength-1,0);t.push(`should be longer than ${e} character${e>1?"s":""}`)}}if(typeof s.maxLength==="number"){if(s.maxLength===0){a="empty string"}else{const e=s.maxLength+1;t.push(`should be shorter than ${e} character${e>1?"s":""}`)}}if(s.pattern){t.push(`should${r?"":" not"} match pattern ${JSON.stringify(s.pattern)}`)}if(s.format){t.push(`should${r?"":" not"} match format ${JSON.stringify(s.format)}`)}if(s.formatMinimum){t.push(`should be ${s.formatExclusiveMinimum?">":">="} ${JSON.stringify(s.formatMinimum)}`)}if(s.formatMaximum){t.push(`should be ${s.formatExclusiveMaximum?"<":"<="} ${JSON.stringify(s.formatMaximum)}`)}return[a].concat(t)};e.exports.numberHints=function numberHints(e,r){const t=[e.type==="integer"?"integer":"number"];const s=new a;if(typeof e.minimum==="number"){s.left(e.minimum)}if(typeof e.exclusiveMinimum==="number"){s.left(e.exclusiveMinimum,true)}if(typeof e.maximum==="number"){s.right(e.maximum)}if(typeof e.exclusiveMaximum==="number"){s.right(e.exclusiveMaximum,true)}const i=s.format(r);if(i){t.push(i)}if(typeof e.multipleOf==="number"){t.push(`should${r?"":" not"} be multiple of ${e.multipleOf}`)}return t}},2121:(e,r,t)=>{"use strict";Object.defineProperty(r,"__esModule",{value:true});r.validate=validate;Object.defineProperty(r,"ValidationError",{enumerable:true,get:function(){return s.default}});var a=_interopRequireDefault(t(9294));var s=_interopRequireDefault(t(5826));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const i=t(8601);const o=t(4133);const n=new i({allErrors:true,verbose:true,$data:true});o(n,["instanceof","formatMinimum","formatMaximum","patternRequired"]);(0,a.default)(n);function validate(e,r,t){let a=[];if(Array.isArray(r)){a=Array.from(r,(r=>validateObject(e,r)));a.forEach(((e,r)=>{const applyPrefix=e=>{e.dataPath=`[${r}]${e.dataPath}`;if(e.children){e.children.forEach(applyPrefix)}};e.forEach(applyPrefix)}));a=a.reduce(((e,r)=>{e.push(...r);return e}),[])}else{a=validateObject(e,r)}if(a.length>0){throw new s.default(a,e,t)}}function validateObject(e,r){const t=n.compile(e);const a=t(r);if(a)return[];return t.errors?filterErrors(t.errors):[]}function filterErrors(e){let r=[];for(const t of e){const{dataPath:e}=t;let a=[];r=r.filter((r=>{if(r.dataPath.includes(e)){if(r.children){a=a.concat(r.children.slice(0))}r.children=undefined;a.push(r);return false}return true}));if(a.length){t.children=a}r.push(t)}return r}},199:function(e,r){ -/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */ -(function(e,t){true?t(r):0})(this,(function(e){"use strict";function merge(){for(var e=arguments.length,r=Array(e),t=0;t1){r[0]=r[0].slice(0,-1);var a=r.length-1;for(var s=1;s= 0x80 (not a basic code point)","invalid-input":"Invalid input"};var y=i-o;var P=Math.floor;var b=String.fromCharCode;function error$1(e){throw new RangeError(g[e])}function map(e,r){var t=[];var a=e.length;while(a--){t[a]=r(e[a])}return t}function mapDomain(e,r){var t=e.split("@");var a="";if(t.length>1){a=t[0]+"@";e=t[1]}e=e.replace(m,".");var s=e.split(".");var i=map(s,r).join(".");return a+i}function ucs2decode(e){var r=[];var t=0;var a=e.length;while(t=55296&&s<=56319&&t>1;e+=P(e/r);for(;e>y*n>>1;a+=i){e=P(e/y)}return P(a+(y+1)*e/(e+l))};var $=function decode(e){var r=[];var t=e.length;var a=0;var l=c;var u=f;var d=e.lastIndexOf(h);if(d<0){d=0}for(var p=0;p=128){error$1("not-basic")}r.push(e.charCodeAt(p))}for(var m=d>0?d+1:0;m=t){error$1("invalid-input")}var E=S(e.charCodeAt(m++));if(E>=i||E>P((s-a)/y)){error$1("overflow")}a+=E*y;var w=b<=u?o:b>=u+n?n:b-u;if(EP(s/$)){error$1("overflow")}y*=$}var _=r.length+1;u=x(a-g,_,g==0);if(P(a/_)>s-l){error$1("overflow")}l+=P(a/_);a%=_;r.splice(a++,0,l)}return String.fromCodePoint.apply(String,r)};var _=function encode(e){var r=[];e=ucs2decode(e);var t=e.length;var a=c;var l=0;var u=f;var d=true;var p=false;var m=undefined;try{for(var g=e[Symbol.iterator](),y;!(d=(y=g.next()).done);d=true){var E=y.value;if(E<128){r.push(b(E))}}}catch(e){p=true;m=e}finally{try{if(!d&&g.return){g.return()}}finally{if(p){throw m}}}var S=r.length;var $=S;if(S){r.push(h)}while($=a&&I<_){_=I}}}catch(e){F=true;O=e}finally{try{if(!R&&D.return){D.return()}}finally{if(F){throw O}}}var k=$+1;if(_-a>P((s-l)/k)){error$1("overflow")}l+=(_-a)*k;a=_;var C=true;var A=false;var N=undefined;try{for(var T=e[Symbol.iterator](),L;!(C=(L=T.next()).done);C=true){var q=L.value;if(qs){error$1("overflow")}if(q==a){var z=l;for(var M=i;;M+=i){var U=M<=u?o:M>=u+n?n:M-u;if(z>6|192).toString(16).toUpperCase()+"%"+(r&63|128).toString(16).toUpperCase();else t="%"+(r>>12|224).toString(16).toUpperCase()+"%"+(r>>6&63|128).toString(16).toUpperCase()+"%"+(r&63|128).toString(16).toUpperCase();return t}function pctDecChars(e){var r="";var t=0;var a=e.length;while(t=194&&s<224){if(a-t>=6){var i=parseInt(e.substr(t+4,2),16);r+=String.fromCharCode((s&31)<<6|i&63)}else{r+=e.substr(t,6)}t+=6}else if(s>=224){if(a-t>=9){var o=parseInt(e.substr(t+4,2),16);var n=parseInt(e.substr(t+7,2),16);r+=String.fromCharCode((s&15)<<12|(o&63)<<6|n&63)}else{r+=e.substr(t,9)}t+=9}else{r+=e.substr(t,3);t+=3}}return r}function _normalizeComponentEncoding(e,r){function decodeUnreserved(e){var t=pctDecChars(e);return!t.match(r.UNRESERVED)?e:t}if(e.scheme)e.scheme=String(e.scheme).replace(r.PCT_ENCODED,decodeUnreserved).toLowerCase().replace(r.NOT_SCHEME,"");if(e.userinfo!==undefined)e.userinfo=String(e.userinfo).replace(r.PCT_ENCODED,decodeUnreserved).replace(r.NOT_USERINFO,pctEncChar).replace(r.PCT_ENCODED,toUpperCase);if(e.host!==undefined)e.host=String(e.host).replace(r.PCT_ENCODED,decodeUnreserved).toLowerCase().replace(r.NOT_HOST,pctEncChar).replace(r.PCT_ENCODED,toUpperCase);if(e.path!==undefined)e.path=String(e.path).replace(r.PCT_ENCODED,decodeUnreserved).replace(e.scheme?r.NOT_PATH:r.NOT_PATH_NOSCHEME,pctEncChar).replace(r.PCT_ENCODED,toUpperCase);if(e.query!==undefined)e.query=String(e.query).replace(r.PCT_ENCODED,decodeUnreserved).replace(r.NOT_QUERY,pctEncChar).replace(r.PCT_ENCODED,toUpperCase);if(e.fragment!==undefined)e.fragment=String(e.fragment).replace(r.PCT_ENCODED,decodeUnreserved).replace(r.NOT_FRAGMENT,pctEncChar).replace(r.PCT_ENCODED,toUpperCase);return e}function _stripLeadingZeros(e){return e.replace(/^0*(.*)/,"$1")||"0"}function _normalizeIPv4(e,r){var t=e.match(r.IPV4ADDRESS)||[];var s=a(t,2),i=s[1];if(i){return i.split(".").map(_stripLeadingZeros).join(".")}else{return e}}function _normalizeIPv6(e,r){var t=e.match(r.IPV6ADDRESS)||[];var s=a(t,3),i=s[1],o=s[2];if(i){var n=i.toLowerCase().split("::").reverse(),l=a(n,2),u=l[0],f=l[1];var c=f?f.split(":").map(_stripLeadingZeros):[];var h=u.split(":").map(_stripLeadingZeros);var d=r.IPV4ADDRESS.test(h[h.length-1]);var p=d?7:8;var m=h.length-p;var g=Array(p);for(var y=0;y1){var S=g.slice(0,b.index);var w=g.slice(b.index+b.length);E=S.join(":")+"::"+w.join(":")}else{E=g.join(":")}if(o){E+="%"+o}return E}else{return e}}var j=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;var I="".match(/(){0}/)[1]===undefined;function parse(e){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var s={};var i=a.iri!==false?t:r;if(a.reference==="suffix")e=(a.scheme?a.scheme+":":"")+"//"+e;var o=e.match(j);if(o){if(I){s.scheme=o[1];s.userinfo=o[3];s.host=o[4];s.port=parseInt(o[5],10);s.path=o[6]||"";s.query=o[7];s.fragment=o[8];if(isNaN(s.port)){s.port=o[5]}}else{s.scheme=o[1]||undefined;s.userinfo=e.indexOf("@")!==-1?o[3]:undefined;s.host=e.indexOf("//")!==-1?o[4]:undefined;s.port=parseInt(o[5],10);s.path=o[6]||"";s.query=e.indexOf("?")!==-1?o[7]:undefined;s.fragment=e.indexOf("#")!==-1?o[8]:undefined;if(isNaN(s.port)){s.port=e.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?o[4]:undefined}}if(s.host){s.host=_normalizeIPv6(_normalizeIPv4(s.host,i),i)}if(s.scheme===undefined&&s.userinfo===undefined&&s.host===undefined&&s.port===undefined&&!s.path&&s.query===undefined){s.reference="same-document"}else if(s.scheme===undefined){s.reference="relative"}else if(s.fragment===undefined){s.reference="absolute"}else{s.reference="uri"}if(a.reference&&a.reference!=="suffix"&&a.reference!==s.reference){s.error=s.error||"URI is not a "+a.reference+" reference."}var n=D[(a.scheme||s.scheme||"").toLowerCase()];if(!a.unicodeSupport&&(!n||!n.unicodeSupport)){if(s.host&&(a.domainHost||n&&n.domainHost)){try{s.host=O.toASCII(s.host.replace(i.PCT_ENCODED,pctDecChars).toLowerCase())}catch(e){s.error=s.error||"Host's domain name can not be converted to ASCII via punycode: "+e}}_normalizeComponentEncoding(s,r)}else{_normalizeComponentEncoding(s,i)}if(n&&n.parse){n.parse(s,a)}}else{s.error=s.error||"URI can not be parsed."}return s}function _recomposeAuthority(e,a){var s=a.iri!==false?t:r;var i=[];if(e.userinfo!==undefined){i.push(e.userinfo);i.push("@")}if(e.host!==undefined){i.push(_normalizeIPv6(_normalizeIPv4(String(e.host),s),s).replace(s.IPV6ADDRESS,(function(e,r,t){return"["+r+(t?"%25"+t:"")+"]"})))}if(typeof e.port==="number"||typeof e.port==="string"){i.push(":");i.push(String(e.port))}return i.length?i.join(""):undefined}var k=/^\.\.?\//;var C=/^\/\.(\/|$)/;var A=/^\/\.\.(\/|$)/;var N=/^\/?(?:.|\n)*?(?=\/|$)/;function removeDotSegments(e){var r=[];while(e.length){if(e.match(k)){e=e.replace(k,"")}else if(e.match(C)){e=e.replace(C,"/")}else if(e.match(A)){e=e.replace(A,"/");r.pop()}else if(e==="."||e===".."){e=""}else{var t=e.match(N);if(t){var a=t[0];e=e.slice(a.length);r.push(a)}else{throw new Error("Unexpected dot segment condition")}}}return r.join("")}function serialize(e){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var s=a.iri?t:r;var i=[];var o=D[(a.scheme||e.scheme||"").toLowerCase()];if(o&&o.serialize)o.serialize(e,a);if(e.host){if(s.IPV6ADDRESS.test(e.host)){}else if(a.domainHost||o&&o.domainHost){try{e.host=!a.iri?O.toASCII(e.host.replace(s.PCT_ENCODED,pctDecChars).toLowerCase()):O.toUnicode(e.host)}catch(r){e.error=e.error||"Host's domain name can not be converted to "+(!a.iri?"ASCII":"Unicode")+" via punycode: "+r}}}_normalizeComponentEncoding(e,s);if(a.reference!=="suffix"&&e.scheme){i.push(e.scheme);i.push(":")}var n=_recomposeAuthority(e,a);if(n!==undefined){if(a.reference!=="suffix"){i.push("//")}i.push(n);if(e.path&&e.path.charAt(0)!=="/"){i.push("/")}}if(e.path!==undefined){var l=e.path;if(!a.absolutePath&&(!o||!o.absolutePath)){l=removeDotSegments(l)}if(n===undefined){l=l.replace(/^\/\//,"/%2F")}i.push(l)}if(e.query!==undefined){i.push("?");i.push(e.query)}if(e.fragment!==undefined){i.push("#");i.push(e.fragment)}return i.join("")}function resolveComponents(e,r){var t=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var a=arguments[3];var s={};if(!a){e=parse(serialize(e,t),t);r=parse(serialize(r,t),t)}t=t||{};if(!t.tolerant&&r.scheme){s.scheme=r.scheme;s.userinfo=r.userinfo;s.host=r.host;s.port=r.port;s.path=removeDotSegments(r.path||"");s.query=r.query}else{if(r.userinfo!==undefined||r.host!==undefined||r.port!==undefined){s.userinfo=r.userinfo;s.host=r.host;s.port=r.port;s.path=removeDotSegments(r.path||"");s.query=r.query}else{if(!r.path){s.path=e.path;if(r.query!==undefined){s.query=r.query}else{s.query=e.query}}else{if(r.path.charAt(0)==="/"){s.path=removeDotSegments(r.path)}else{if((e.userinfo!==undefined||e.host!==undefined||e.port!==undefined)&&!e.path){s.path="/"+r.path}else if(!e.path){s.path=r.path}else{s.path=e.path.slice(0,e.path.lastIndexOf("/")+1)+r.path}s.path=removeDotSegments(s.path)}s.query=r.query}s.userinfo=e.userinfo;s.host=e.host;s.port=e.port}s.scheme=e.scheme}s.fragment=r.fragment;return s}function resolve(e,r,t){var a=assign({scheme:"null"},t);return serialize(resolveComponents(parse(e,a),parse(r,a),a,true),a)}function normalize(e,r){if(typeof e==="string"){e=serialize(parse(e,r),r)}else if(typeOf(e)==="object"){e=parse(serialize(e,r),r)}return e}function equal(e,r,t){if(typeof e==="string"){e=serialize(parse(e,t),t)}else if(typeOf(e)==="object"){e=serialize(e,t)}if(typeof r==="string"){r=serialize(parse(r,t),t)}else if(typeOf(r)==="object"){r=serialize(r,t)}return e===r}function escapeComponent(e,a){return e&&e.toString().replace(!a||!a.iri?r.ESCAPE:t.ESCAPE,pctEncChar)}function unescapeComponent(e,a){return e&&e.toString().replace(!a||!a.iri?r.PCT_ENCODED:t.PCT_ENCODED,pctDecChars)}var T={scheme:"http",domainHost:true,parse:function parse(e,r){if(!e.host){e.error=e.error||"HTTP URIs must have a host."}return e},serialize:function serialize(e,r){var t=String(e.scheme).toLowerCase()==="https";if(e.port===(t?443:80)||e.port===""){e.port=undefined}if(!e.path){e.path="/"}return e}};var L={scheme:"https",domainHost:T.domainHost,parse:T.parse,serialize:T.serialize};function isSecure(e){return typeof e.secure==="boolean"?e.secure:String(e.scheme).toLowerCase()==="wss"}var q={scheme:"ws",domainHost:true,parse:function parse(e,r){var t=e;t.secure=isSecure(t);t.resourceName=(t.path||"/")+(t.query?"?"+t.query:"");t.path=undefined;t.query=undefined;return t},serialize:function serialize(e,r){if(e.port===(isSecure(e)?443:80)||e.port===""){e.port=undefined}if(typeof e.secure==="boolean"){e.scheme=e.secure?"wss":"ws";e.secure=undefined}if(e.resourceName){var t=e.resourceName.split("?"),s=a(t,2),i=s[0],o=s[1];e.path=i&&i!=="/"?i:undefined;e.query=o;e.resourceName=undefined}e.fragment=undefined;return e}};var z={scheme:"wss",domainHost:q.domainHost,parse:q.parse,serialize:q.serialize};var M={};var U=true;var V="[A-Za-z0-9\\-\\.\\_\\~"+(U?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]";var Q="[0-9A-Fa-f]";var K=subexp(subexp("%[EFef]"+Q+"%"+Q+Q+"%"+Q+Q)+"|"+subexp("%[89A-Fa-f]"+Q+"%"+Q+Q)+"|"+subexp("%"+Q+Q));var H="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]";var J="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]";var B=merge(J,'[\\"\\\\]');var Z="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]";var G=new RegExp(V,"g");var Y=new RegExp(K,"g");var W=new RegExp(merge("[^]",H,"[\\.]",'[\\"]',B),"g");var X=new RegExp(merge("[^]",V,Z),"g");var ee=X;function decodeUnreserved(e){var r=pctDecChars(e);return!r.match(G)?e:r}var re={scheme:"mailto",parse:function parse$$1(e,r){var t=e;var a=t.to=t.path?t.path.split(","):[];t.path=undefined;if(t.query){var s=false;var i={};var o=t.query.split("&");for(var n=0,l=o.length;n{"use strict";e.exports=JSON.parse('{"$schema":"http://json-schema.org/draft-07/schema#","$id":"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#","description":"Meta-schema for $data reference (JSON Schema extension proposal)","type":"object","required":["$data"],"properties":{"$data":{"type":"string","anyOf":[{"format":"relative-json-pointer"},{"format":"json-pointer"}]}},"additionalProperties":false}')},7136:e=>{"use strict";e.exports=JSON.parse('{"$schema":"http://json-schema.org/draft-07/schema#","$id":"http://json-schema.org/draft-07/schema#","title":"Core schema meta-schema","definitions":{"schemaArray":{"type":"array","minItems":1,"items":{"$ref":"#"}},"nonNegativeInteger":{"type":"integer","minimum":0},"nonNegativeIntegerDefault0":{"allOf":[{"$ref":"#/definitions/nonNegativeInteger"},{"default":0}]},"simpleTypes":{"enum":["array","boolean","integer","null","number","object","string"]},"stringArray":{"type":"array","items":{"type":"string"},"uniqueItems":true,"default":[]}},"type":["object","boolean"],"properties":{"$id":{"type":"string","format":"uri-reference"},"$schema":{"type":"string","format":"uri"},"$ref":{"type":"string","format":"uri-reference"},"$comment":{"type":"string"},"title":{"type":"string"},"description":{"type":"string"},"default":true,"readOnly":{"type":"boolean","default":false},"examples":{"type":"array","items":true},"multipleOf":{"type":"number","exclusiveMinimum":0},"maximum":{"type":"number"},"exclusiveMaximum":{"type":"number"},"minimum":{"type":"number"},"exclusiveMinimum":{"type":"number"},"maxLength":{"$ref":"#/definitions/nonNegativeInteger"},"minLength":{"$ref":"#/definitions/nonNegativeIntegerDefault0"},"pattern":{"type":"string","format":"regex"},"additionalItems":{"$ref":"#"},"items":{"anyOf":[{"$ref":"#"},{"$ref":"#/definitions/schemaArray"}],"default":true},"maxItems":{"$ref":"#/definitions/nonNegativeInteger"},"minItems":{"$ref":"#/definitions/nonNegativeIntegerDefault0"},"uniqueItems":{"type":"boolean","default":false},"contains":{"$ref":"#"},"maxProperties":{"$ref":"#/definitions/nonNegativeInteger"},"minProperties":{"$ref":"#/definitions/nonNegativeIntegerDefault0"},"required":{"$ref":"#/definitions/stringArray"},"additionalProperties":{"$ref":"#"},"definitions":{"type":"object","additionalProperties":{"$ref":"#"},"default":{}},"properties":{"type":"object","additionalProperties":{"$ref":"#"},"default":{}},"patternProperties":{"type":"object","additionalProperties":{"$ref":"#"},"propertyNames":{"format":"regex"},"default":{}},"dependencies":{"type":"object","additionalProperties":{"anyOf":[{"$ref":"#"},{"$ref":"#/definitions/stringArray"}]}},"propertyNames":{"$ref":"#"},"const":true,"enum":{"type":"array","items":true,"minItems":1,"uniqueItems":true},"type":{"anyOf":[{"$ref":"#/definitions/simpleTypes"},{"type":"array","items":{"$ref":"#/definitions/simpleTypes"},"minItems":1,"uniqueItems":true}]},"format":{"type":"string"},"contentMediaType":{"type":"string"},"contentEncoding":{"type":"string"},"if":{"$ref":"#"},"then":{"$ref":"#"},"else":{"$ref":"#"},"allOf":{"$ref":"#/definitions/schemaArray"},"anyOf":{"$ref":"#/definitions/schemaArray"},"oneOf":{"$ref":"#/definitions/schemaArray"},"not":{"$ref":"#"}},"default":true}')}};var r={};function __nccwpck_require__(t){var a=r[t];if(a!==undefined){return a.exports}var s=r[t]={exports:{}};var i=true;try{e[t].call(s.exports,s,s.exports,__nccwpck_require__);i=false}finally{if(i)delete r[t]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(1489);module.exports=t})(); \ No newline at end of file diff --git a/packages/compat/webpack/compiled/schema-utils3/license b/packages/compat/webpack/compiled/schema-utils3/license deleted file mode 100644 index 8c11fc7289..0000000000 --- a/packages/compat/webpack/compiled/schema-utils3/license +++ /dev/null @@ -1,20 +0,0 @@ -Copyright JS Foundation and other contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/compat/webpack/compiled/schema-utils3/package.json b/packages/compat/webpack/compiled/schema-utils3/package.json deleted file mode 100644 index 30a7f365ab..0000000000 --- a/packages/compat/webpack/compiled/schema-utils3/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"schema-utils3","author":"webpack Contrib (https://github.com/webpack-contrib)","version":"3.1.1","funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"license":"MIT","types":"index.d.ts"} diff --git a/packages/compat/webpack/compiled/tapable/index.js b/packages/compat/webpack/compiled/tapable/index.js deleted file mode 100644 index e213eb631b..0000000000 --- a/packages/compat/webpack/compiled/tapable/index.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var e={410:(e,t,n)=>{const o=n(506);const r=n(507);class AsyncParallelBailHookCodeFactory extends r{content({onError:e,onResult:t,onDone:n}){let o="";o+=`var _results = new Array(${this.options.taps.length});\n`;o+="var _checkDone = function() {\n";o+="for(var i = 0; i < _results.length; i++) {\n";o+="var item = _results[i];\n";o+="if(item === undefined) return false;\n";o+="if(item.result !== undefined) {\n";o+=t("item.result");o+="return true;\n";o+="}\n";o+="if(item.error) {\n";o+=e("item.error");o+="return true;\n";o+="}\n";o+="}\n";o+="return false;\n";o+="}\n";o+=this.callTapsParallel({onError:(e,t,n,o)=>{let r="";r+=`if(${e} < _results.length && ((_results.length = ${e+1}), (_results[${e}] = { error: ${t} }), _checkDone())) {\n`;r+=o(true);r+="} else {\n";r+=n();r+="}\n";return r},onResult:(e,t,n,o)=>{let r="";r+=`if(${e} < _results.length && (${t} !== undefined && (_results.length = ${e+1}), (_results[${e}] = { result: ${t} }), _checkDone())) {\n`;r+=o(true);r+="} else {\n";r+=n();r+="}\n";return r},onTap:(e,t,n,o)=>{let r="";if(e>0){r+=`if(${e} >= _results.length) {\n`;r+=n();r+="} else {\n"}r+=t();if(e>0)r+="}\n";return r},onDone:n});return o}}const s=new AsyncParallelBailHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncParallelBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncParallelBailHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncParallelBailHook.prototype=null;e.exports=AsyncParallelBailHook},598:(e,t,n)=>{const o=n(506);const r=n(507);class AsyncParallelHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsParallel({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncParallelHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncParallelHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncParallelHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncParallelHook.prototype=null;e.exports=AsyncParallelHook},178:(e,t,n)=>{const o=n(506);const r=n(507);class AsyncSeriesBailHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,onDone:o}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onResult:(e,n,o)=>`if(${n} !== undefined) {\n${t(n)}\n} else {\n${o()}}\n`,resultReturns:n,onDone:o})}}const s=new AsyncSeriesBailHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesBailHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesBailHook.prototype=null;e.exports=AsyncSeriesBailHook},97:(e,t,n)=>{const o=n(506);const r=n(507);class AsyncSeriesHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncSeriesHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesHook.prototype=null;e.exports=AsyncSeriesHook},243:(e,t,n)=>{const o=n(506);const r=n(507);class AsyncSeriesLoopHookCodeFactory extends r{content({onError:e,onDone:t}){return this.callTapsLooping({onError:(t,n,o,r)=>e(n)+r(true),onDone:t})}}const s=new AsyncSeriesLoopHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesLoopHook(e=[],t=undefined){const n=new o(e,t);n.constructor=AsyncSeriesLoopHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesLoopHook.prototype=null;e.exports=AsyncSeriesLoopHook},969:(e,t,n)=>{const o=n(506);const r=n(507);class AsyncSeriesWaterfallHookCodeFactory extends r{content({onError:e,onResult:t,onDone:n}){return this.callTapsSeries({onError:(t,n,o,r)=>e(n)+r(true),onResult:(e,t,n)=>{let o="";o+=`if(${t} !== undefined) {\n`;o+=`${this._args[0]} = ${t};\n`;o+=`}\n`;o+=n();return o},onDone:()=>t(this._args[0])})}}const s=new AsyncSeriesWaterfallHookCodeFactory;const COMPILE=function(e){s.setup(this,e);return s.create(e)};function AsyncSeriesWaterfallHook(e=[],t=undefined){if(e.length<1)throw new Error("Waterfall hooks must have at least one argument");const n=new o(e,t);n.constructor=AsyncSeriesWaterfallHook;n.compile=COMPILE;n._call=undefined;n.call=undefined;return n}AsyncSeriesWaterfallHook.prototype=null;e.exports=AsyncSeriesWaterfallHook},506:(e,t,n)=>{const o=n(837);const r=o.deprecate((()=>{}),"Hook.context is deprecated and will be removed");const CALL_DELEGATE=function(...e){this.call=this._createCall("sync");return this.call(...e)};const CALL_ASYNC_DELEGATE=function(...e){this.callAsync=this._createCall("async");return this.callAsync(...e)};const PROMISE_DELEGATE=function(...e){this.promise=this._createCall("promise");return this.promise(...e)};class Hook{constructor(e=[],t=undefined){this._args=e;this.name=t;this.taps=[];this.interceptors=[];this._call=CALL_DELEGATE;this.call=CALL_DELEGATE;this._callAsync=CALL_ASYNC_DELEGATE;this.callAsync=CALL_ASYNC_DELEGATE;this._promise=PROMISE_DELEGATE;this.promise=PROMISE_DELEGATE;this._x=undefined;this.compile=this.compile;this.tap=this.tap;this.tapAsync=this.tapAsync;this.tapPromise=this.tapPromise}compile(e){throw new Error("Abstract: should be overridden")}_createCall(e){return this.compile({taps:this.taps,interceptors:this.interceptors,args:this._args,type:e})}_tap(e,t,n){if(typeof t==="string"){t={name:t.trim()}}else if(typeof t!=="object"||t===null){throw new Error("Invalid tap options")}if(typeof t.name!=="string"||t.name===""){throw new Error("Missing name for tap")}if(typeof t.context!=="undefined"){r()}t=Object.assign({type:e,fn:n},t);t=this._runRegisterInterceptors(t);this._insert(t)}tap(e,t){this._tap("sync",e,t)}tapAsync(e,t){this._tap("async",e,t)}tapPromise(e,t){this._tap("promise",e,t)}_runRegisterInterceptors(e){for(const t of this.interceptors){if(t.register){const n=t.register(e);if(n!==undefined){e=n}}}return e}withOptions(e){const mergeOptions=t=>Object.assign({},e,typeof t==="string"?{name:t}:t);return{name:this.name,tap:(e,t)=>this.tap(mergeOptions(e),t),tapAsync:(e,t)=>this.tapAsync(mergeOptions(e),t),tapPromise:(e,t)=>this.tapPromise(mergeOptions(e),t),intercept:e=>this.intercept(e),isUsed:()=>this.isUsed(),withOptions:e=>this.withOptions(mergeOptions(e))}}isUsed(){return this.taps.length>0||this.interceptors.length>0}intercept(e){this._resetCompilation();this.interceptors.push(Object.assign({},e));if(e.register){for(let t=0;t0){o--;const e=this.taps[o];this.taps[o+1]=e;const r=e.stage||0;if(t){if(t.has(e.name)){t.delete(e.name);continue}if(t.size>0){continue}}if(r>n){continue}o++;break}this.taps[o]=e}}Object.setPrototypeOf(Hook.prototype,null);e.exports=Hook},507:e=>{class HookCodeFactory{constructor(e){this.config=e;this.options=undefined;this._args=undefined}create(e){this.init(e);let t;switch(this.options.type){case"sync":t=new Function(this.args(),'"use strict";\n'+this.header()+this.contentWithInterceptors({onError:e=>`throw ${e};\n`,onResult:e=>`return ${e};\n`,resultReturns:true,onDone:()=>"",rethrowIfPossible:true}));break;case"async":t=new Function(this.args({after:"_callback"}),'"use strict";\n'+this.header()+this.contentWithInterceptors({onError:e=>`_callback(${e});\n`,onResult:e=>`_callback(null, ${e});\n`,onDone:()=>"_callback();\n"}));break;case"promise":let e=false;const n=this.contentWithInterceptors({onError:t=>{e=true;return`_error(${t});\n`},onResult:e=>`_resolve(${e});\n`,onDone:()=>"_resolve();\n"});let o="";o+='"use strict";\n';o+=this.header();o+="return new Promise((function(_resolve, _reject) {\n";if(e){o+="var _sync = true;\n";o+="function _error(_err) {\n";o+="if(_sync)\n";o+="_resolve(Promise.resolve().then((function() { throw _err; })));\n";o+="else\n";o+="_reject(_err);\n";o+="};\n"}o+=n;if(e){o+="_sync = false;\n"}o+="}));\n";t=new Function(this.args(),o);break}this.deinit();return t}setup(e,t){e._x=t.taps.map((e=>e.fn))}init(e){this.options=e;this._args=e.args.slice()}deinit(){this.options=undefined;this._args=undefined}contentWithInterceptors(e){if(this.options.interceptors.length>0){const t=e.onError;const n=e.onResult;const o=e.onDone;let r="";for(let e=0;e{let n="";for(let t=0;t{let t="";for(let n=0;n{let e="";for(let t=0;t0){e+="var _taps = this.taps;\n";e+="var _interceptors = this.interceptors;\n"}return e}needContext(){for(const e of this.options.taps)if(e.context)return true;return false}callTap(e,{onError:t,onResult:n,onDone:o,rethrowIfPossible:r}){let s="";let i=false;for(let t=0;te.type!=="sync"));const c=n||r;let a="";let l=o;let p=0;for(let n=this.options.taps.length-1;n>=0;n--){const r=n;const u=l!==o&&(this.options.taps[r].type!=="sync"||p++>20);if(u){p=0;a+=`function _next${r}() {\n`;a+=l();a+=`}\n`;l=()=>`${c?"return ":""}_next${r}();\n`}const f=l;const doneBreak=e=>{if(e)return"";return o()};const h=this.callTap(r,{onError:t=>e(r,t,f,doneBreak),onResult:t&&(e=>t(r,e,f,doneBreak)),onDone:!t&&f,rethrowIfPossible:s&&(i<0||rh}a+=l();return a}callTapsLooping({onError:e,onDone:t,rethrowIfPossible:n}){if(this.options.taps.length===0)return t();const o=this.options.taps.every((e=>e.type==="sync"));let r="";if(!o){r+="var _looper = (function() {\n";r+="var _loopAsync = false;\n"}r+="var _loop;\n";r+="do {\n";r+="_loop = false;\n";for(let e=0;e{let s="";s+=`if(${t} !== undefined) {\n`;s+="_loop = true;\n";if(!o)s+="if(_loopAsync) _looper();\n";s+=r(true);s+=`} else {\n`;s+=n();s+=`}\n`;return s},onDone:t&&(()=>{let e="";e+="if(!_loop) {\n";e+=t();e+="}\n";return e}),rethrowIfPossible:n&&o});r+="} while(_loop);\n";if(!o){r+="_loopAsync = true;\n";r+="});\n";r+="_looper();\n"}return r}callTapsParallel({onError:e,onResult:t,onDone:n,rethrowIfPossible:o,onTap:r=((e,t)=>t())}){if(this.options.taps.length<=1){return this.callTapsSeries({onError:e,onResult:t,onDone:n,rethrowIfPossible:o})}let s="";s+="do {\n";s+=`var _counter = ${this.options.taps.length};\n`;if(n){s+="var _done = (function() {\n";s+=n();s+="});\n"}for(let i=0;i{if(n)return"if(--_counter === 0) _done();\n";else return"--_counter;"};const doneBreak=e=>{if(e||!n)return"_counter = 0;\n";else return"_counter = 0;\n_done();\n"};s+="if(_counter <= 0) break;\n";s+=r(i,(()=>this.callTap(i,{onError:t=>{let n="";n+="if(_counter > 0) {\n";n+=e(i,t,done,doneBreak);n+="}\n";return n},onResult:t&&(e=>{let n="";n+="if(_counter > 0) {\n";n+=t(i,e,done,doneBreak);n+="}\n";return n}),onDone:!t&&(()=>done()),rethrowIfPossible:o})),done,doneBreak)}s+="} while(false);\n";return s}args({before:e,after:t}={}){let n=this._args;if(e)n=[e].concat(n);if(t)n=n.concat(t);if(n.length===0){return""}else{return n.join(", ")}}getTapFn(e){return`_x[${e}]`}getTap(e){return`_taps[${e}]`}getInterceptor(e){return`_interceptors[${e}]`}}e.exports=HookCodeFactory},876:(e,t,n)=>{const o=n(837);const defaultFactory=(e,t)=>t;class HookMap{constructor(e,t=undefined){this._map=new Map;this.name=t;this._factory=e;this._interceptors=[]}get(e){return this._map.get(e)}for(e){const t=this.get(e);if(t!==undefined){return t}let n=this._factory(e);const o=this._interceptors;for(let t=0;t{const o=n(506);class MultiHook{constructor(e,t=undefined){this.hooks=e;this.name=t}tap(e,t){for(const n of this.hooks){n.tap(e,t)}}tapAsync(e,t){for(const n of this.hooks){n.tapAsync(e,t)}}tapPromise(e,t){for(const n of this.hooks){n.tapPromise(e,t)}}isUsed(){for(const e of this.hooks){if(e.isUsed())return true}return false}intercept(e){for(const t of this.hooks){t.intercept(e)}}withOptions(e){return new MultiHook(this.hooks.map((t=>t.withOptions(e))),this.name)}}e.exports=MultiHook},130:(e,t,n)=>{const o=n(506);const r=n(507);class SyncBailHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,onDone:o,rethrowIfPossible:r}){return this.callTapsSeries({onError:(t,n)=>e(n),onResult:(e,n,o)=>`if(${n} !== undefined) {\n${t(n)};\n} else {\n${o()}}\n`,resultReturns:n,onDone:o,rethrowIfPossible:r})}}const s=new SyncBailHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncBailHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncBailHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncBailHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncBailHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncBailHook.prototype=null;e.exports=SyncBailHook},856:(e,t,n)=>{const o=n(506);const r=n(507);class SyncHookCodeFactory extends r{content({onError:e,onDone:t,rethrowIfPossible:n}){return this.callTapsSeries({onError:(t,n)=>e(n),onDone:t,rethrowIfPossible:n})}}const s=new SyncHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncHook.prototype=null;e.exports=SyncHook},925:(e,t,n)=>{const o=n(506);const r=n(507);class SyncLoopHookCodeFactory extends r{content({onError:e,onDone:t,rethrowIfPossible:n}){return this.callTapsLooping({onError:(t,n)=>e(n),onDone:t,rethrowIfPossible:n})}}const s=new SyncLoopHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncLoopHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncLoopHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncLoopHook(e=[],t=undefined){const n=new o(e,t);n.constructor=SyncLoopHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncLoopHook.prototype=null;e.exports=SyncLoopHook},844:(e,t,n)=>{const o=n(506);const r=n(507);class SyncWaterfallHookCodeFactory extends r{content({onError:e,onResult:t,resultReturns:n,rethrowIfPossible:o}){return this.callTapsSeries({onError:(t,n)=>e(n),onResult:(e,t,n)=>{let o="";o+=`if(${t} !== undefined) {\n`;o+=`${this._args[0]} = ${t};\n`;o+=`}\n`;o+=n();return o},onDone:()=>t(this._args[0]),doneReturns:n,rethrowIfPossible:o})}}const s=new SyncWaterfallHookCodeFactory;const TAP_ASYNC=()=>{throw new Error("tapAsync is not supported on a SyncWaterfallHook")};const TAP_PROMISE=()=>{throw new Error("tapPromise is not supported on a SyncWaterfallHook")};const COMPILE=function(e){s.setup(this,e);return s.create(e)};function SyncWaterfallHook(e=[],t=undefined){if(e.length<1)throw new Error("Waterfall hooks must have at least one argument");const n=new o(e,t);n.constructor=SyncWaterfallHook;n.tapAsync=TAP_ASYNC;n.tapPromise=TAP_PROMISE;n.compile=COMPILE;return n}SyncWaterfallHook.prototype=null;e.exports=SyncWaterfallHook},837:e=>{e.exports=require("util")}};var t={};function __nccwpck_require__(n){var o=t[n];if(o!==undefined){return o.exports}var r=t[n]={exports:{}};var s=true;try{e[n](r,r.exports,__nccwpck_require__);s=false}finally{if(s)delete t[n]}return r.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var n={};(()=>{var e=n;e.__esModule=true;e.SyncHook=__nccwpck_require__(856);e.SyncBailHook=__nccwpck_require__(130);e.SyncWaterfallHook=__nccwpck_require__(844);e.SyncLoopHook=__nccwpck_require__(925);e.AsyncParallelHook=__nccwpck_require__(598);e.AsyncParallelBailHook=__nccwpck_require__(410);e.AsyncSeriesHook=__nccwpck_require__(97);e.AsyncSeriesBailHook=__nccwpck_require__(178);e.AsyncSeriesLoopHook=__nccwpck_require__(243);e.AsyncSeriesWaterfallHook=__nccwpck_require__(969);e.HookMap=__nccwpck_require__(876);e.MultiHook=__nccwpck_require__(274)})();module.exports=n})(); \ No newline at end of file diff --git a/packages/compat/webpack/compiled/tapable/license b/packages/compat/webpack/compiled/tapable/license deleted file mode 100644 index 03c083cefe..0000000000 --- a/packages/compat/webpack/compiled/tapable/license +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License - -Copyright JS Foundation and other contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/packages/compat/webpack/compiled/tapable/package.json b/packages/compat/webpack/compiled/tapable/package.json deleted file mode 100644 index 3bf8a40b03..0000000000 --- a/packages/compat/webpack/compiled/tapable/package.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"tapable","author":"Tobias Koppers @sokra","version":"2.2.1","license":"MIT","types":"./tapable.d.ts"} diff --git a/packages/compat/webpack/compiled/tapable/tapable.d.ts b/packages/compat/webpack/compiled/tapable/tapable.d.ts deleted file mode 100644 index 0201c9a820..0000000000 --- a/packages/compat/webpack/compiled/tapable/tapable.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -type FixedSizeArray = T extends 0 - ? void[] - : ReadonlyArray & { - 0: U; - length: T; - }; -type Measure = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 - ? T - : never; -type Append = { - 0: [U]; - 1: [T[0], U]; - 2: [T[0], T[1], U]; - 3: [T[0], T[1], T[2], U]; - 4: [T[0], T[1], T[2], T[3], U]; - 5: [T[0], T[1], T[2], T[3], T[4], U]; - 6: [T[0], T[1], T[2], T[3], T[4], T[5], U]; - 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U]; - 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U]; -}[Measure]; -type AsArray = T extends any[] ? T : [T]; - -declare class UnsetAdditionalOptions { - _UnsetAdditionalOptions: true -} -type IfSet = X extends UnsetAdditionalOptions ? {} : X; - -type Callback = (error: E | null, result?: T) => void; -type InnerCallback = (error?: E | null | false, result?: T) => void; - -type FullTap = Tap & { - type: "sync" | "async" | "promise", - fn: Function -} - -type Tap = TapOptions & { - name: string; -}; - -type TapOptions = { - before?: string; - stage?: number; -}; - -interface HookInterceptor { - name?: string; - tap?: (tap: FullTap & IfSet) => void; - call?: (...args: any[]) => void; - loop?: (...args: any[]) => void; - error?: (err: Error) => void; - result?: (result: R) => void; - done?: () => void; - register?: (tap: FullTap & IfSet) => FullTap & IfSet; -} - -type ArgumentNames = FixedSizeArray; - -declare class Hook { - constructor(args?: ArgumentNames>, name?: string); - name: string | undefined; - taps: FullTap[]; - intercept(interceptor: HookInterceptor): void; - isUsed(): boolean; - callAsync(...args: Append, Callback>): void; - promise(...args: AsArray): Promise; - tap(options: string | Tap & IfSet, fn: (...args: AsArray) => R): void; - withOptions(options: TapOptions & IfSet): Omit; -} - -export class SyncHook extends Hook { - call(...args: AsArray): R; -} - -export class SyncBailHook extends SyncHook {} -export class SyncLoopHook extends SyncHook {} -export class SyncWaterfallHook extends SyncHook[0], AdditionalOptions> {} - -declare class AsyncHook extends Hook { - tapAsync( - options: string | Tap & IfSet, - fn: (...args: Append, InnerCallback>) => void - ): void; - tapPromise( - options: string | Tap & IfSet, - fn: (...args: AsArray) => Promise - ): void; -} - -export class AsyncParallelHook extends AsyncHook {} -export class AsyncParallelBailHook extends AsyncHook {} -export class AsyncSeriesHook extends AsyncHook {} -export class AsyncSeriesBailHook extends AsyncHook {} -export class AsyncSeriesLoopHook extends AsyncHook {} -export class AsyncSeriesWaterfallHook extends AsyncHook[0], AdditionalOptions> {} - -type HookFactory = (key: any, hook?: H) => H; - -interface HookMapInterceptor { - factory?: HookFactory; -} - -export class HookMap { - constructor(factory: HookFactory, name?: string); - name: string | undefined; - get(key: any): H | undefined; - for(key: any): H; - intercept(interceptor: HookMapInterceptor): void; -} - -export class MultiHook { - constructor(hooks: H[], name?: string); - name: string | undefined; - tap(options: string | Tap, fn?: Function): void; - tapAsync(options: string | Tap, fn?: Function): void; - tapPromise(options: string | Tap, fn?: Function): void; -} diff --git a/packages/compat/webpack/modern.config.ts b/packages/compat/webpack/modern.config.ts index 01b2b34e71..c3efdfdeee 100644 --- a/packages/compat/webpack/modern.config.ts +++ b/packages/compat/webpack/modern.config.ts @@ -1,3 +1,3 @@ -import baseConfig from '../../../scripts/modern.base.config'; +import { configForDualPackage } from '../../../scripts/modern.base.config'; -export default baseConfig; +export default configForDualPackage; diff --git a/packages/compat/webpack/package.json b/packages/compat/webpack/package.json index 4719d09436..7d7d037cab 100644 --- a/packages/compat/webpack/package.json +++ b/packages/compat/webpack/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/webpack", - "version": "0.6.13", + "version": "0.7.0-beta.5", "homepage": "https://rsbuild.dev", "repository": { "type": "git", @@ -8,22 +8,18 @@ "directory": "packages/compat/webpack" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "default": "./dist/index.js" - }, - "./plugin-css": { - "types": "./dist/plugins/css.d.ts", - "default": "./dist/plugins/css.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "static", - "compiled", "dist" ], "scripts": { @@ -33,9 +29,8 @@ "dependencies": { "@rsbuild/core": "workspace:*", "@rsbuild/shared": "workspace:*", - "fast-glob": "^3.3.2", - "globby": "^11.1.0", "mini-css-extract-plugin": "2.8.1", + "copy-webpack-plugin": "9.1.0", "postcss": "^8.4.38", "tsconfig-paths-webpack-plugin": "4.1.0", "webpack": "^5.91.0" @@ -43,6 +38,9 @@ "devDependencies": { "@scripts/test-helper": "workspace:*", "@types/node": "18.x", + "ansi-escapes": "4.3.2", + "cli-truncate": "2.1.0", + "patch-console": "1.0.0", "typescript": "^5.4.2" }, "publishConfig": { diff --git a/packages/compat/webpack/src/build.ts b/packages/compat/webpack/src/build.ts index 32bdf2a3ff..ecf6f5ad31 100644 --- a/packages/compat/webpack/src/build.ts +++ b/packages/compat/webpack/src/build.ts @@ -1,17 +1,16 @@ +import { type Rspack, logger } from '@rsbuild/core'; import { type BuildOptions, type MultiStats, - type Rspack, type RspackConfig, type Stats, getNodeEnv, - logger, onCompileDone, setNodeEnv, } from '@rsbuild/shared'; import type { Configuration as WebpackConfig } from 'webpack'; // @ts-expect-error -import WebpackMultiStats from 'webpack/lib/MultiStats'; +import WebpackMultiStats from 'webpack/lib/MultiStats.js'; import { createCompiler } from './createCompiler'; import { type InitConfigsOptions, initConfigs } from './initConfigs'; diff --git a/packages/compat/webpack/src/createCompiler.ts b/packages/compat/webpack/src/createCompiler.ts index 1ed53a80da..a7cb62a966 100644 --- a/packages/compat/webpack/src/createCompiler.ts +++ b/packages/compat/webpack/src/createCompiler.ts @@ -1,21 +1,20 @@ +import { type Rspack, logger } from '@rsbuild/core'; import { - type InternalContext, - formatStats, - getDevMiddleware, - getStatsOptions, -} from '@rsbuild/core/internal'; -import { - type Rspack, type RspackConfig, type Stats, debug, isDev, - logger, onCompileDone, } from '@rsbuild/shared'; // @ts-expect-error -import WebpackMultiStats from 'webpack/lib/MultiStats'; +import WebpackMultiStats from 'webpack/lib/MultiStats.js'; import { type InitConfigsOptions, initConfigs } from './initConfigs'; +import { + type InternalContext, + formatStats, + getDevMiddleware, + getStatsOptions, +} from './shared'; import type { WebpackConfig } from './types'; export async function createCompiler({ @@ -89,7 +88,7 @@ export async function createDevMiddleware( } return { - devMiddleware: getDevMiddleware(compiler), + devMiddleware: await getDevMiddleware(compiler), compiler, }; } diff --git a/packages/compat/webpack/src/initConfigs.ts b/packages/compat/webpack/src/initConfigs.ts index f4c650f73e..1ba17d4e1b 100644 --- a/packages/compat/webpack/src/initConfigs.ts +++ b/packages/compat/webpack/src/initConfigs.ts @@ -1,7 +1,3 @@ -import { - type InternalContext, - initRsbuildConfig, -} from '@rsbuild/core/internal'; import { type CreateRsbuildOptions, type InspectConfigOptions, @@ -9,6 +5,7 @@ import { isDebug, } from '@rsbuild/shared'; import { inspectConfig } from './inspectConfig'; +import { type InternalContext, initRsbuildConfig } from './shared'; import type { WebpackConfig } from './types'; import { generateWebpackConfig } from './webpackConfig'; diff --git a/packages/compat/webpack/src/inspectConfig.ts b/packages/compat/webpack/src/inspectConfig.ts index c1b479e5b9..fa9070e8fc 100644 --- a/packages/compat/webpack/src/inspectConfig.ts +++ b/packages/compat/webpack/src/inspectConfig.ts @@ -41,7 +41,7 @@ export async function inspectConfig({ pluginNames: string[]; } = { ...context.normalizedConfig!, - pluginNames: pluginManager.plugins.map((p) => p.name), + pluginNames: pluginManager.getPlugins().map((p) => p.name), }; const rawRsbuildConfig = await stringifyConfig( diff --git a/packages/compat/webpack/src/plugin.ts b/packages/compat/webpack/src/plugin.ts new file mode 100644 index 0000000000..db4186cf52 --- /dev/null +++ b/packages/compat/webpack/src/plugin.ts @@ -0,0 +1,125 @@ +import fs from 'node:fs'; +import { + type BundlerChain, + type ChainIdentifier, + type CopyPluginOptions, + type RsbuildPlugin, + type RsbuildTarget, + TARGET_ID_MAP, + isWebTarget, +} from '@rsbuild/shared'; + +async function applyTsConfigPathsPlugin({ + chain, + CHAIN_ID, + mainFields, + extensions, + configFile, +}: { + chain: BundlerChain; + CHAIN_ID: ChainIdentifier; + mainFields: (string | string[])[]; + extensions: string[]; + configFile: string; +}) { + const { TsconfigPathsPlugin } = await import('tsconfig-paths-webpack-plugin'); + + chain.resolve + .plugin(CHAIN_ID.RESOLVE_PLUGIN.TS_CONFIG_PATHS) + .use(TsconfigPathsPlugin, [ + { + configFile, + extensions, + // https://github.com/dividab/tsconfig-paths-webpack-plugin/pull/106 + mainFields: mainFields as string[], + }, + ]); +} + +const getMainFields = (chain: BundlerChain, target: RsbuildTarget) => { + const mainFields = chain.resolve.mainFields.values(); + + if (mainFields.length) { + return mainFields; + } + + if (isWebTarget(target)) { + return ['browser', 'module', 'main']; + } + + return ['module', 'main']; +}; + +/** + * Handling differences between Webpack and Rspack + */ +export const pluginAdaptor = (): RsbuildPlugin => ({ + name: 'rsbuild-webpack:adaptor', + + setup(api) { + api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => { + const config = api.getNormalizedConfig(); + + if ( + api.context.tsconfigPath && + config.source.aliasStrategy === 'prefer-tsconfig' + ) { + await applyTsConfigPathsPlugin({ + chain, + CHAIN_ID, + configFile: api.context.tsconfigPath, + mainFields: getMainFields(chain, target), + extensions: chain.resolve.extensions.values(), + }); + } + + // enable progress bar for webpack by default + const progress = config.dev.progressBar ?? true; + if (progress) { + const { ProgressPlugin } = await import('./progress/ProgressPlugin'); + chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [ + { + id: TARGET_ID_MAP[target], + ...(progress === true ? {} : progress), + }, + ]); + } + + const { copy } = config.output; + if (copy) { + const { default: CopyPlugin } = await import( + // @ts-expect-error copy-webpack-plugin does not provide types + 'copy-webpack-plugin' + ); + + const options: CopyPluginOptions = Array.isArray(copy) + ? { patterns: copy } + : copy; + + chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [options]); + } + }); + + api.modifyWebpackConfig(async (config) => { + const copyPlugin = config.plugins?.find( + (item) => item?.constructor.name === 'CopyPlugin', + ) as unknown as CopyPluginOptions; + + if (copyPlugin) { + // If the pattern.context directory not exists, we should remove CopyPlugin. + // Otherwise the CopyPlugin will cause the webpack to re-compile. + const isContextNotExists = copyPlugin.patterns.every( + (pattern) => + typeof pattern !== 'string' && + pattern.context && + !fs.existsSync(pattern.context), + ); + if (isContextNotExists) { + config.plugins = config.plugins?.filter( + (item) => item?.constructor.name !== 'CopyPlugin', + ); + } + } + }); + }, +}); diff --git a/packages/compat/webpack/src/plugins/copy.ts b/packages/compat/webpack/src/plugins/copy.ts deleted file mode 100644 index 0ff63f70ab..0000000000 --- a/packages/compat/webpack/src/plugins/copy.ts +++ /dev/null @@ -1,49 +0,0 @@ -import fs from 'node:fs'; -import type { CopyPluginOptions, RsbuildPlugin } from '@rsbuild/shared'; - -export const pluginCopy = (): RsbuildPlugin => ({ - name: 'rsbuild-webpack:copy', - - setup(api) { - api.modifyBundlerChain(async (chain, { CHAIN_ID }) => { - const config = api.getNormalizedConfig(); - const { copy } = config.output; - - if (!copy) { - return; - } - - const { default: CopyPlugin } = await import( - '../../compiled/copy-webpack-plugin' - ); - - const options: CopyPluginOptions = Array.isArray(copy) - ? { patterns: copy } - : copy; - - chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [options]); - }); - - api.modifyWebpackConfig(async (config) => { - const copyPlugin = config.plugins?.find( - (item) => item?.constructor.name === 'CopyPlugin', - ) as unknown as CopyPluginOptions; - - if (copyPlugin) { - // If the pattern.context directory not exists, we should remove CopyPlugin. - // Otherwise the CopyPlugin will cause the webpack to re-compile. - const isContextNotExists = copyPlugin.patterns.every( - (pattern) => - typeof pattern !== 'string' && - pattern.context && - !fs.existsSync(pattern.context), - ); - if (isContextNotExists) { - config.plugins = config.plugins?.filter( - (item) => item?.constructor.name !== 'CopyPlugin', - ); - } - } - }); - }, -}); diff --git a/packages/compat/webpack/src/plugins/css.ts b/packages/compat/webpack/src/plugins/css.ts deleted file mode 100644 index b78ef8e90b..0000000000 --- a/packages/compat/webpack/src/plugins/css.ts +++ /dev/null @@ -1,153 +0,0 @@ -import { - type BundlerChainRule, - type CSSExtractOptions, - CSS_REGEX, - type ModifyChainUtils, - type NormalizedConfig, - type RsbuildContext, - type RsbuildPlugin, - getBrowserslistWithDefault, - getCssLoaderOptions, - getCssModuleLocalIdentName, - getPostcssLoaderOptions, - getSharedPkgCompiledPath, - isUseCssExtract, - mergeChainedOptions, - resolvePackage, -} from '@rsbuild/shared'; - -export async function applyBaseCSSRule({ - rule, - config, - context, - utils: { target, isProd, isServer, CHAIN_ID, isWebWorker }, - importLoaders = 1, -}: { - rule: BundlerChainRule; - config: NormalizedConfig; - context: RsbuildContext; - utils: ModifyChainUtils; - importLoaders?: number; -}) { - const browserslist = await getBrowserslistWithDefault( - context.rootPath, - config, - target, - ); - - // 1. Check user config - const enableExtractCSS = isUseCssExtract(config, target); - const enableCSSModuleTS = Boolean(config.output.enableCssModuleTSDeclaration); - - // 2. Prepare loader options - const localIdentName = getCssModuleLocalIdentName(config, isProd); - - const cssLoaderOptions = getCssLoaderOptions({ - config, - importLoaders, - isServer, - isWebWorker, - localIdentName, - }); - - // 3. Create webpack rule - // Order: style-loader/mini-css-extract -> css-loader -> postcss-loader - if (!isServer && !isWebWorker) { - // use mini-css-extract-plugin loader - if (enableExtractCSS) { - const extraCSSOptions: Required = - typeof config.tools.cssExtract === 'object' - ? config.tools.cssExtract - : { - loaderOptions: {}, - pluginOptions: {}, - }; - - rule - .use(CHAIN_ID.USE.MINI_CSS_EXTRACT) - .loader(require('mini-css-extract-plugin').loader) - .options(extraCSSOptions.loaderOptions) - .end(); - } - // use style-loader - else { - const styleLoaderOptions = mergeChainedOptions({ - defaults: {}, - options: config.tools.styleLoader, - }); - - rule - .use(CHAIN_ID.USE.STYLE) - .loader(getSharedPkgCompiledPath('style-loader')) - .options(styleLoaderOptions) - .end(); - } - - // use css-modules-typescript-loader - if (enableCSSModuleTS && cssLoaderOptions.modules) { - rule - .use(CHAIN_ID.USE.CSS_MODULES_TS) - .loader( - resolvePackage( - '@rsbuild/shared/css-modules-typescript-loader', - __dirname, - ), - ) - .options({ - modules: cssLoaderOptions.modules, - }) - .end(); - } - } else { - rule - .use(CHAIN_ID.USE.IGNORE_CSS) - .loader(resolvePackage('@rsbuild/shared/ignore-css-loader', __dirname)) - .end(); - } - - rule - .use(CHAIN_ID.USE.CSS) - .loader(getSharedPkgCompiledPath('css-loader')) - .options(cssLoaderOptions) - .end(); - - if (!isServer && !isWebWorker) { - const postcssLoaderOptions = await getPostcssLoaderOptions({ - browserslist, - config, - root: context.rootPath, - }); - - rule - .use(CHAIN_ID.USE.POSTCSS) - .loader(getSharedPkgCompiledPath('postcss-loader')) - .options(postcssLoaderOptions) - .end(); - } - - // CSS imports should always be treated as sideEffects - rule.merge({ sideEffects: true }); - - // Enable preferRelative by default, which is consistent with the default behavior of css-loader - // see: https://github.com/webpack-contrib/css-loader/blob/579fc13/src/plugins/postcss-import-parser.js#L234 - rule.resolve.preferRelative(true); -} - -export const pluginCss = (): RsbuildPlugin => { - return { - name: 'rsbuild-webpack:css', - setup(api) { - api.modifyBundlerChain(async (chain, utils) => { - const rule = chain.module.rule(utils.CHAIN_ID.RULE.CSS); - const config = api.getNormalizedConfig(); - rule.test(CSS_REGEX); - await applyBaseCSSRule({ - rule, - utils, - config, - context: api.context, - }); - }); - }, - }; -}; diff --git a/packages/compat/webpack/src/plugins/less.ts b/packages/compat/webpack/src/plugins/less.ts deleted file mode 100644 index 3d7c2548a1..0000000000 --- a/packages/compat/webpack/src/plugins/less.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { - type FileFilterUtil, - LESS_REGEX, - type RsbuildPlugin, - getLessLoaderOptions, - getSharedPkgCompiledPath, -} from '@rsbuild/shared'; - -export type LessLoaderUtils = { - addExcludes: FileFilterUtil; -}; - -export function pluginLess(): RsbuildPlugin { - return { - name: 'rsbuild-webpack:less', - setup(api) { - api.modifyBundlerChain(async (chain, utils) => { - const config = api.getNormalizedConfig(); - const { applyBaseCSSRule } = await import('./css'); - - const { options, excludes } = getLessLoaderOptions( - config.tools.less, - config.output.sourceMap.css, - api.context.rootPath, - ); - const rule = chain.module - .rule(utils.CHAIN_ID.RULE.LESS) - .test(LESS_REGEX); - - for (const item of excludes) { - rule.exclude.add(item); - } - - await applyBaseCSSRule({ - rule, - utils, - config, - context: api.context, - importLoaders: 2, - }); - - rule - .use(utils.CHAIN_ID.USE.LESS) - .loader(getSharedPkgCompiledPath('less-loader')) - .options(options); - }); - }, - }; -} diff --git a/packages/compat/webpack/src/plugins/output.ts b/packages/compat/webpack/src/plugins/output.ts deleted file mode 100644 index 7700b7d1c2..0000000000 --- a/packages/compat/webpack/src/plugins/output.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { posix } from 'node:path'; -import { - type RsbuildPlugin, - applyOutputPlugin, - getDistPath, - getFilename, - isUseCssExtract, - mergeChainedOptions, -} from '@rsbuild/shared'; - -export const pluginOutput = (): RsbuildPlugin => ({ - name: 'rsbuild-webpack:output', - - setup(api) { - applyOutputPlugin(api); - - api.modifyBundlerChain(async (chain, { isProd, target, CHAIN_ID }) => { - const config = api.getNormalizedConfig(); - - // css output - if (isUseCssExtract(config, target)) { - const { default: MiniCssExtractPlugin } = await import( - 'mini-css-extract-plugin' - ); - const extractPluginOptions = mergeChainedOptions({ - defaults: {}, - options: config.tools.cssExtract?.pluginOptions, - }); - - const cssPath = getDistPath(config, 'css'); - const cssAsyncPath = getDistPath(config, 'cssAsync'); - const cssFilename = getFilename(config, 'css', isProd); - - chain - .plugin(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT) - .use(MiniCssExtractPlugin, [ - { - filename: posix.join(cssPath, cssFilename), - chunkFilename: posix.join(cssAsyncPath, cssFilename), - ignoreOrder: true, - ...extractPluginOptions, - }, - ]); - } - }); - }, -}); diff --git a/packages/compat/webpack/src/plugins/progress.ts b/packages/compat/webpack/src/plugins/progress.ts deleted file mode 100644 index 523f60834c..0000000000 --- a/packages/compat/webpack/src/plugins/progress.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { type RsbuildPlugin, TARGET_ID_MAP } from '@rsbuild/shared'; - -export const pluginProgress = (): RsbuildPlugin => ({ - name: 'rsbuild-webpack:progress', - setup(api) { - api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => { - const config = api.getNormalizedConfig(); - // enable progress bar for webpack by default - const options = config.dev.progressBar ?? true; - - if (!options) { - return; - } - - const { ProgressPlugin } = await import('../progress/ProgressPlugin'); - chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [ - { - id: TARGET_ID_MAP[target], - ...(options === true ? {} : options), - }, - ]); - }); - }, -}); diff --git a/packages/compat/webpack/src/plugins/resolve.ts b/packages/compat/webpack/src/plugins/resolve.ts deleted file mode 100644 index 43d51c867d..0000000000 --- a/packages/compat/webpack/src/plugins/resolve.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - type BundlerChain, - type ChainIdentifier, - type RsbuildPlugin, - type RsbuildTarget, - applyResolvePlugin, - isWebTarget, -} from '@rsbuild/shared'; - -async function applyTsConfigPathsPlugin({ - chain, - CHAIN_ID, - mainFields, - extensions, - configFile, -}: { - chain: BundlerChain; - CHAIN_ID: ChainIdentifier; - mainFields: (string | string[])[]; - extensions: string[]; - configFile: string; -}) { - const { TsconfigPathsPlugin } = await import('tsconfig-paths-webpack-plugin'); - - chain.resolve - .plugin(CHAIN_ID.RESOLVE_PLUGIN.TS_CONFIG_PATHS) - .use(TsconfigPathsPlugin, [ - { - configFile, - extensions, - // https://github.com/dividab/tsconfig-paths-webpack-plugin/pull/106 - mainFields: mainFields as string[], - }, - ]); -} - -const getMainFields = (chain: BundlerChain, target: RsbuildTarget) => { - const mainFields = chain.resolve.mainFields.values(); - - if (mainFields.length) { - return mainFields; - } - - if (isWebTarget(target)) { - return ['browser', 'module', 'main']; - } - - return ['module', 'main']; -}; - -export const pluginResolve = (): RsbuildPlugin => ({ - name: 'rsbuild-webpack:resolve', - - setup(api) { - applyResolvePlugin(api); - - api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => { - const config = api.getNormalizedConfig(); - - if ( - api.context.tsconfigPath && - config.source.aliasStrategy === 'prefer-tsconfig' - ) { - await applyTsConfigPathsPlugin({ - chain, - CHAIN_ID, - configFile: api.context.tsconfigPath, - mainFields: getMainFields(chain, target), - extensions: chain.resolve.extensions.values(), - }); - } - }); - }, -}); diff --git a/packages/compat/webpack/src/plugins/sass.ts b/packages/compat/webpack/src/plugins/sass.ts deleted file mode 100644 index bb15430993..0000000000 --- a/packages/compat/webpack/src/plugins/sass.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { - type RsbuildPlugin, - SASS_REGEX, - getResolveUrlJoinFn, - getSassLoaderOptions, - getSharedPkgCompiledPath, - patchCompilerGlobalLocation, -} from '@rsbuild/shared'; - -export function pluginSass(): RsbuildPlugin { - return { - name: 'rsbuild-webpack:sass', - setup(api) { - api.onAfterCreateCompiler(({ compiler }) => { - patchCompilerGlobalLocation(compiler); - }); - - api.modifyBundlerChain(async (chain, utils) => { - const config = api.getNormalizedConfig(); - const { applyBaseCSSRule } = await import('./css'); - - const { options, excludes } = getSassLoaderOptions( - config.tools.sass, - // source-maps required for loaders preceding resolve-url-loader - true, - ); - const rule = chain.module - .rule(utils.CHAIN_ID.RULE.SASS) - .test(SASS_REGEX); - - for (const item of excludes) { - rule.exclude.add(item); - } - - await applyBaseCSSRule({ - rule, - utils, - config, - context: api.context, - // postcss-loader, resolve-url-loader, sass-loader - importLoaders: 3, - }); - - rule - .use(utils.CHAIN_ID.USE.RESOLVE_URL) - .loader(getSharedPkgCompiledPath('resolve-url-loader')) - .options({ - join: await getResolveUrlJoinFn(), - // 'resolve-url-loader' relies on 'adjust-sourcemap-loader', - // it has performance regression issues in some scenarios, - // so we need to disable the sourceMap option. - sourceMap: false, - }) - .end() - .use(utils.CHAIN_ID.USE.SASS) - .loader(getSharedPkgCompiledPath('sass-loader')) - .options(options); - }); - }, - }; -} diff --git a/packages/compat/webpack/src/progress/helpers/bar.ts b/packages/compat/webpack/src/progress/helpers/bar.ts index 340d8672b0..325140469e 100644 --- a/packages/compat/webpack/src/progress/helpers/bar.ts +++ b/packages/compat/webpack/src/progress/helpers/bar.ts @@ -1,5 +1,5 @@ import { color as colors } from '@rsbuild/shared'; -import cliTruncate from '../../../compiled/cli-truncate'; +import cliTruncate from 'cli-truncate'; import type { Props } from './type'; import { clamp } from './utils'; diff --git a/packages/compat/webpack/src/progress/helpers/bus.ts b/packages/compat/webpack/src/progress/helpers/bus.ts index cb1e07f9c0..e043405fe4 100644 --- a/packages/compat/webpack/src/progress/helpers/bus.ts +++ b/packages/compat/webpack/src/progress/helpers/bus.ts @@ -1,7 +1,7 @@ import { Console } from 'node:console'; import { getProgressColor } from '@rsbuild/shared'; -import cliTruncate from '../../../compiled/cli-truncate'; -import patchConsole from '../../../compiled/patch-console'; +import cliTruncate from 'cli-truncate'; +import patchConsole from 'patch-console'; import { FULL_WIDTH, renderBar } from './bar'; import { create } from './log'; import type { LogUpdate } from './log'; diff --git a/packages/compat/webpack/src/progress/helpers/log.ts b/packages/compat/webpack/src/progress/helpers/log.ts index d9765d236f..3b29ad32a1 100644 --- a/packages/compat/webpack/src/progress/helpers/log.ts +++ b/packages/compat/webpack/src/progress/helpers/log.ts @@ -1,5 +1,5 @@ import type { Writable } from 'node:stream'; -import ansiEscapes from '../../../compiled/ansi-escapes'; +import ansiEscapes from 'ansi-escapes'; export interface LogUpdate { clear: () => void; diff --git a/packages/compat/webpack/src/provider.ts b/packages/compat/webpack/src/provider.ts index 60f1a4d286..f570c91b49 100644 --- a/packages/compat/webpack/src/provider.ts +++ b/packages/compat/webpack/src/provider.ts @@ -1,10 +1,3 @@ -import { - createContext, - createPublicContext, - getPluginAPI, - initRsbuildConfig, - plugins, -} from '@rsbuild/core/internal'; import { type CreateCompiler, type PreviewServerOptions, @@ -12,6 +5,16 @@ import { pickRsbuildConfig, } from '@rsbuild/shared'; import { initConfigs } from './initConfigs'; +import { + createContext, + createDevServer, + createPublicContext, + getPluginAPI, + initRsbuildConfig, + plugins, + setCssExtractPlugin, + startProdServer, +} from './shared'; export const webpackProvider: RsbuildProvider<'webpack'> = async ({ pluginManager, @@ -23,6 +26,9 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ context.pluginAPI = pluginAPI; + const { default: cssExtractPlugin } = await import('mini-css-extract-plugin'); + setCssExtractPlugin(cssExtractPlugin); + const createCompiler = (async () => { const { createCompiler } = await import('./createCompiler'); const { webpackConfigs } = await initConfigs({ @@ -44,16 +50,15 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ async applyDefaultPlugins() { const allPlugins = await Promise.all([ - plugins.basic?.(), - plugins.entry?.(), - plugins.cache?.(), - plugins.target?.(), - import('./plugins/output').then((m) => m.pluginOutput()), - import('./plugins/resolve').then((m) => m.pluginResolve()), - plugins.fileSize?.(), - plugins.cleanOutput?.(), + plugins.basic(), + plugins.entry(), + plugins.cache(), + plugins.target(), + plugins.output(), + plugins.resolve(), + plugins.fileSize(), + plugins.cleanOutput(), plugins.asset(), - import('./plugins/copy').then((m) => m.pluginCopy()), plugins.html(async (tags) => { const result = await context.hooks.modifyHTMLTags.call(tags); return result[0]; @@ -62,14 +67,13 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ plugins.moment(), plugins.nodeAddons(), plugins.define(), - import('./plugins/progress').then((m) => m.pluginProgress()), - import('./plugins/css').then((m) => m.pluginCss()), - import('./plugins/sass').then((m) => m.pluginSass()), - import('./plugins/less').then((m) => m.pluginLess()), + plugins.css(), + plugins.less(), + plugins.sass(), plugins.bundleAnalyzer(), plugins.rsdoctor(), plugins.splitChunks(), - plugins.startUrl?.(), + plugins.startUrl(), plugins.inlineChunk(), plugins.externals(), plugins.performance(), @@ -77,6 +81,7 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ plugins.server(), plugins.moduleFederation(), plugins.manifest(), + import('./plugin').then((m) => m.pluginAdaptor()), ]); pluginManager.addPlugins(allPlugins); @@ -92,7 +97,6 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ }, async createDevServer(options) { - const { createDevServer } = await import('@rsbuild/core/internal'); const { createDevMiddleware } = await import('./createCompiler'); await initRsbuildConfig({ context, pluginManager }); return createDevServer( @@ -103,7 +107,6 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ }, async startDevServer(options) { - const { createDevServer } = await import('@rsbuild/core/internal'); const { createDevMiddleware } = await import('./createCompiler'); await initRsbuildConfig({ context, @@ -123,7 +126,6 @@ export const webpackProvider: RsbuildProvider<'webpack'> = async ({ }, async preview(options?: PreviewServerOptions) { - const { startProdServer } = await import('@rsbuild/core/internal'); await initRsbuildConfig({ context, pluginManager, diff --git a/packages/compat/webpack/src/shared.ts b/packages/compat/webpack/src/shared.ts index 68ddf15d51..c73137c7c4 100644 --- a/packages/compat/webpack/src/shared.ts +++ b/packages/compat/webpack/src/shared.ts @@ -1,14 +1,33 @@ -import fs from 'node:fs'; -import { join } from 'node:path'; -import { - type SharedCompiledPkgNames, - getSharedPkgCompiledPath, -} from '@rsbuild/shared'; +import { __internalHelper } from '@rsbuild/core'; -export const getCompiledPath = (packageName: string) => { - const providerCompilerPath = join(__dirname, '../../compiled', packageName); - if (fs.existsSync(providerCompilerPath)) { - return providerCompilerPath; - } - return getSharedPkgCompiledPath(packageName as SharedCompiledPkgNames); +const { + plugins, + createContext, + createPublicContext, + getPluginAPI, + getChainUtils, + initRsbuildConfig, + setCssExtractPlugin, + createDevServer, + startProdServer, + formatStats, + getDevMiddleware, + getStatsOptions, +} = __internalHelper; + +export { + plugins, + createContext, + createPublicContext, + getPluginAPI, + getChainUtils, + initRsbuildConfig, + setCssExtractPlugin, + createDevServer, + startProdServer, + formatStats, + getDevMiddleware, + getStatsOptions, }; + +export type InternalContext = __internalHelper.InternalContext; diff --git a/packages/compat/webpack/src/webpackConfig.ts b/packages/compat/webpack/src/webpackConfig.ts index 25625cac7c..5d66326bff 100644 --- a/packages/compat/webpack/src/webpackConfig.ts +++ b/packages/compat/webpack/src/webpackConfig.ts @@ -1,7 +1,4 @@ -import { - type InternalContext, - getChainUtils as getBaseChainUtils, -} from '@rsbuild/core/internal'; +import { __internalHelper } from '@rsbuild/core'; import { type BundlerChain, type ModifyWebpackChainUtils, @@ -15,7 +12,10 @@ import { modifyBundlerChain, } from '@rsbuild/shared'; import type { RuleSetRule, WebpackPluginInstance } from 'webpack'; -import { getCompiledPath } from './shared'; +import { + type InternalContext, + getChainUtils as getBaseChainUtils, +} from './shared'; import type { WebpackConfig } from './types'; async function modifyWebpackChain( @@ -69,7 +69,6 @@ async function getChainUtils( target: RsbuildTarget, ): Promise { const { default: webpack } = await import('webpack'); - const { getHTMLPlugin } = await import('@rsbuild/core/internal'); const nameMap = { web: 'client', node: 'server', @@ -81,8 +80,7 @@ async function getChainUtils( ...getBaseChainUtils(target), name: nameMap[target] || '', webpack, - getCompiledPath, - HtmlWebpackPlugin: getHTMLPlugin(), + HtmlWebpackPlugin: __internalHelper.getHTMLPlugin(), }; } @@ -142,13 +140,14 @@ export async function generateWebpackConfig({ context: InternalContext; }) { const chainUtils = await getChainUtils(target); + const { default: webpack } = await import('webpack'); const { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, HotModuleReplacementPlugin, - } = await import('webpack'); + } = webpack; const bundlerChain = await modifyBundlerChain(context, { ...chainUtils, diff --git a/packages/compat/webpack/tests/__snapshots__/css.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/css.test.ts.snap deleted file mode 100644 index cf97f00383..0000000000 --- a/packages/compat/webpack/tests/__snapshots__/css.test.ts.snap +++ /dev/null @@ -1,154 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`plugin-css > should not apply postcss-loader when target is node 1`] = ` -{ - "module": { - "rules": [ - { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.css\\$/, - "use": [ - { - "loader": "@rsbuild/shared/ignore-css-loader", - }, - { - "loader": "/packages/shared/compiled/css-loader", - "options": { - "importLoaders": 1, - "modules": { - "auto": true, - "exportLocalsConvention": "camelCase", - "exportOnlyLocals": true, - "localIdentName": "[path][name]__[local]-[hash:base64:6]", - "namedExport": false, - }, - "sourceMap": false, - }, - }, - ], - }, - ], - }, -} -`; - -exports[`plugin-css > should override browserslist of autoprefixer when using output.overrideBrowserslist config 1`] = ` -{ - "module": { - "rules": [ - { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.css\\$/, - "use": [ - { - "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", - }, - { - "loader": "/packages/shared/compiled/css-loader", - "options": { - "importLoaders": 1, - "modules": { - "auto": true, - "exportLocalsConvention": "camelCase", - "localIdentName": "[path][name]__[local]-[hash:base64:6]", - "namedExport": false, - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "Chrome 80", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "Chrome 80", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], - }, - ], - }, -} -`; - -exports[`plugin-css > should remove some postcss plugins based on browserslist 1`] = ` -{ - "module": { - "rules": [ - { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.css\\$/, - "use": [ - { - "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", - }, - { - "loader": "/packages/shared/compiled/css-loader", - "options": { - "importLoaders": 1, - "modules": { - "auto": true, - "exportLocalsConvention": "camelCase", - "localIdentName": "[path][name]__[local]-[hash:base64:6]", - "namedExport": false, - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "Chrome 100", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "Chrome 100", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], - }, - ], - }, -} -`; diff --git a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap index eb591fc2bf..5c87166f0c 100644 --- a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap @@ -64,7 +64,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -91,7 +91,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -118,7 +118,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -145,7 +145,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -172,7 +172,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 1, "modules": { @@ -185,7 +185,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -222,15 +222,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "test": /\\\\\\.less\\$/, "use": [ { "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 3, + "importLoaders": 2, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -241,7 +241,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -272,19 +272,18 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, }, { - "loader": "/packages/shared/compiled/resolve-url-loader", + "loader": "/packages/core/compiled/less-loader", "options": { - "join": [Function], + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/compat/webpack/tests/node_modules", + ], + }, "sourceMap": false, }, }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, ], }, { @@ -292,15 +291,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.less\\$/, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, "use": [ { "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 2, + "importLoaders": 3, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -311,7 +310,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -342,18 +341,19 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, }, { - "loader": "/packages/shared/compiled/less-loader", + "loader": "/packages/core/compiled/resolve-url-loader", "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/compat/webpack/tests/node_modules", - ], - }, + "join": [Function], "sourceMap": false, }, }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, + }, + }, ], }, ], @@ -601,7 +601,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -628,7 +628,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -655,7 +655,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -682,7 +682,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -709,7 +709,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 1, "modules": { @@ -722,7 +722,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -759,15 +759,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "test": /\\\\\\.less\\$/, "use": [ { "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 3, + "importLoaders": 2, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -778,7 +778,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -809,19 +809,18 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, }, { - "loader": "/packages/shared/compiled/resolve-url-loader", + "loader": "/packages/core/compiled/less-loader", "options": { - "join": [Function], + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/compat/webpack/tests/node_modules", + ], + }, "sourceMap": false, }, }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, ], }, { @@ -829,15 +828,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.less\\$/, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, "use": [ { "loader": "/node_modules//mini-css-extract-plugin/dist/loader.js", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 2, + "importLoaders": 3, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -848,7 +847,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -879,18 +878,19 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ }, }, { - "loader": "/packages/shared/compiled/less-loader", + "loader": "/packages/core/compiled/resolve-url-loader", "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/compat/webpack/tests/node_modules", - ], - }, + "join": [Function], "sourceMap": false, }, }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, + }, + }, ], }, ], @@ -1172,7 +1172,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1199,7 +1199,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1226,7 +1226,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1253,7 +1253,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1273,7 +1273,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "test": /\\\\\\.node\\$/, "use": [ { - "loader": "/packages/core/dist/rspack/transformRawLoader", + "loader": "/packages/core/dist/transformRawLoader.cjs", "options": { "id": "rsbuild-transform-0", }, @@ -1288,10 +1288,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "test": /\\\\\\.css\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 1, "modules": { @@ -1311,15 +1311,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "test": /\\\\\\.less\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 3, + "importLoaders": 2, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -1331,19 +1331,18 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, }, { - "loader": "/packages/shared/compiled/resolve-url-loader", + "loader": "/packages/core/compiled/less-loader", "options": { - "join": [Function], + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/compat/webpack/tests/node_modules", + ], + }, "sourceMap": false, }, }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, ], }, { @@ -1351,15 +1350,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.less\\$/, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 2, + "importLoaders": 3, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -1371,18 +1370,19 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, }, { - "loader": "/packages/shared/compiled/less-loader", + "loader": "/packages/core/compiled/resolve-url-loader", "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/compat/webpack/tests/node_modules", - ], - }, + "join": [Function], "sourceMap": false, }, }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, + }, + }, ], }, ], @@ -1529,7 +1529,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1556,7 +1556,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1583,7 +1583,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1610,7 +1610,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1634,10 +1634,10 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "test": /\\\\\\.css\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 1, "modules": { @@ -1657,15 +1657,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "test": /\\\\\\.less\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 3, + "importLoaders": 2, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -1677,19 +1677,18 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, }, { - "loader": "/packages/shared/compiled/resolve-url-loader", + "loader": "/packages/core/compiled/less-loader", "options": { - "join": [Function], + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/compat/webpack/tests/node_modules", + ], + }, "sourceMap": false, }, }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, ], }, { @@ -1697,15 +1696,15 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "preferRelative": true, }, "sideEffects": true, - "test": /\\\\\\.less\\$/, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { - "importLoaders": 2, + "importLoaders": 3, "modules": { "auto": true, "exportLocalsConvention": "camelCase", @@ -1717,18 +1716,19 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, }, { - "loader": "/packages/shared/compiled/less-loader", + "loader": "/packages/core/compiled/resolve-url-loader", "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/compat/webpack/tests/node_modules", - ], - }, + "join": [Function], "sourceMap": false, }, }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, + }, + }, ], }, ], diff --git a/packages/compat/webpack/tests/__snapshots__/output.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/output.test.ts.snap deleted file mode 100644 index 3ce6e21c2d..0000000000 --- a/packages/compat/webpack/tests/__snapshots__/output.test.ts.snap +++ /dev/null @@ -1,105 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`plugin-output > should allow to custom server directory with distPath.server 1`] = ` -{ - "output": { - "chunkFilename": "[name].js", - "filename": "[name].js", - "hashFunction": "xxhash64", - "libraryTarget": "commonjs2", - "path": "/packages/compat/webpack/tests/dist/server", - "pathinfo": false, - "publicPath": "/", - }, -} -`; - -exports[`plugin-output > should allow to set distPath.js and distPath.css to empty string 1`] = ` -{ - "output": { - "chunkFilename": "async/[name].js", - "filename": "[name].js", - "hashFunction": "xxhash64", - "path": "/packages/compat/webpack/tests/dist", - "pathinfo": false, - "publicPath": "/", - }, - "plugins": [ - MiniCssExtractPlugin { - "_sortedModulesCache": WeakMap {}, - "options": { - "chunkFilename": "async/[name].css", - "experimentalUseImportModule": undefined, - "filename": "[name].css", - "ignoreOrder": true, - "runtime": true, - }, - "runtimeOptions": { - "attributes": undefined, - "insert": undefined, - "linkType": "text/css", - }, - }, - ], -} -`; - -exports[`plugin-output > should allow to use filename.js to modify filename 1`] = ` -{ - "output": { - "chunkFilename": "static/js/async/foo.js", - "filename": "static/js/foo.js", - "hashFunction": "xxhash64", - "path": "/packages/compat/webpack/tests/dist", - "pathinfo": false, - "publicPath": "/", - }, - "plugins": [ - MiniCssExtractPlugin { - "_sortedModulesCache": WeakMap {}, - "options": { - "chunkFilename": "static/css/async/[name].css", - "experimentalUseImportModule": undefined, - "filename": "static/css/[name].css", - "ignoreOrder": true, - "runtime": true, - }, - "runtimeOptions": { - "attributes": undefined, - "insert": undefined, - "linkType": "text/css", - }, - }, - ], -} -`; - -exports[`plugin-output > should set output correctly 1`] = ` -{ - "output": { - "chunkFilename": "static/js/async/[name].js", - "filename": "static/js/[name].js", - "hashFunction": "xxhash64", - "path": "/packages/compat/webpack/tests/dist", - "pathinfo": false, - "publicPath": "/", - }, - "plugins": [ - MiniCssExtractPlugin { - "_sortedModulesCache": WeakMap {}, - "options": { - "chunkFilename": "static/css/async/[name].css", - "experimentalUseImportModule": undefined, - "filename": "static/css/[name].css", - "ignoreOrder": true, - "runtime": true, - }, - "runtimeOptions": { - "attributes": undefined, - "insert": undefined, - "linkType": "text/css", - }, - }, - ], -} -`; diff --git a/packages/compat/webpack/tests/__snapshots__/resolve.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/resolve.test.ts.snap deleted file mode 100644 index 624b669363..0000000000 --- a/packages/compat/webpack/tests/__snapshots__/resolve.test.ts.snap +++ /dev/null @@ -1,50 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`plugin-resolve > should disable resolve.fullySpecified by default 1`] = ` -{ - "module": { - "rules": [ - { - "resolve": { - "fullySpecified": false, - }, - "test": /\\\\\\.m\\?js/, - }, - ], - }, - "resolve": { - "extensions": [ - ".ts", - ".tsx", - ".js", - ".jsx", - ".mjs", - ".json", - ], - "plugins": [ - TsconfigPathsPlugin { - "absoluteBaseUrl": "/packages/compat/webpack/tests", - "baseUrl": "./", - "extensions": [ - ".ts", - ".tsx", - ".js", - ".jsx", - ".mjs", - ".json", - ], - "log": { - "log": [Function], - "logError": [Function], - "logInfo": [Function], - "logWarning": [Function], - }, - "matchPath": [Function], - "referenceMatchMap": {}, - "source": "described-resolve", - "target": "resolve", - }, - ], - }, -} -`; diff --git a/packages/compat/webpack/tests/css.test.ts b/packages/compat/webpack/tests/css.test.ts deleted file mode 100644 index 9c0ee89c3d..0000000000 --- a/packages/compat/webpack/tests/css.test.ts +++ /dev/null @@ -1,284 +0,0 @@ -import { pluginCss } from '../src/plugins/css'; -import { pluginLess } from '../src/plugins/less'; -import { pluginSass } from '../src/plugins/sass'; -import { createStubRsbuild } from './helper'; - -describe('plugin-css', () => { - // need check(skipped before because this case time out in CI env) - it('should set css config with style-loader', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - injectStyles: true, - }, - }, - }); - const includeStyleLoader = await rsbuild.matchLoader( - 'style-loader', - 'index.css', - ); - - expect(includeStyleLoader).toBe(true); - }); - - // need check(skipped before because this case time out in CI env) - it('should set css config with mini-css-extract-plugin', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: {}, - }); - - const includeMiniCssExtractLoader = await rsbuild.matchLoader( - 'mini-css-extract-plugin', - 'index.css', - ); - - expect(includeMiniCssExtractLoader).toBe(true); - }); - - it('should add sass-loader', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginSass()], - rsbuildConfig: { - tools: { - sass: {}, - }, - }, - }); - - const includeSassLoader = await rsbuild.matchLoader( - 'sass-loader', - 'index.scss', - ); - - expect(includeSassLoader).toBe(true); - }); - - it('should add less-loader', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginLess()], - rsbuildConfig: { - tools: { - less: {}, - }, - }, - }); - - const includeLessLoader = await rsbuild.matchLoader( - 'less-loader', - 'index.less', - ); - - expect(includeLessLoader).toBe(true); - }); - - it('should override browserslist of autoprefixer when using output.overrideBrowserslist config', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - overrideBrowserslist: ['Chrome 80'], - }, - }, - }); - const config = await rsbuild.unwrapConfig(); - - expect(config).toMatchSnapshot(); - }); - - it('should not apply mini-css-extract-plugin when target is node', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - targets: ['node'], - }, - }, - }); - - const includeMiniCssExtractLoader = await rsbuild.matchLoader( - 'mini-css-extract-plugin', - 'index.css', - ); - - expect(includeMiniCssExtractLoader).toBe(false); - }); - - it('should not apply mini-css-extract-plugin when target is web-worker', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - targets: ['web-worker'], - }, - }, - }); - - const includeMiniCssExtractLoader = await rsbuild.matchLoader( - 'mini-css-extract-plugin', - 'index.css', - ); - - expect(includeMiniCssExtractLoader).toBe(false); - }); - - it('should not apply style-loader when target is node', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - targets: ['node'], - injectStyles: true, - }, - tools: { - styleLoader: {}, - }, - }, - }); - - const includeStyleLoader = await rsbuild.matchLoader( - 'style-loader', - 'index.css', - ); - - expect(includeStyleLoader).toBe(false); - }); - - it('should not apply style-loader when target is web-worker', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - targets: ['web-worker'], - injectStyles: true, - }, - tools: { - styleLoader: {}, - }, - }, - }); - - const includeStyleLoader = await rsbuild.matchLoader( - 'style-loader', - 'index.css', - ); - - expect(includeStyleLoader).toBe(false); - }); - - it('should allow to disable extract css plugin', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - injectStyles: true, - }, - }, - }); - - const includeMiniCssExtractLoader = await rsbuild.matchLoader( - 'mini-css-extract-plugin', - 'index.css', - ); - - expect(includeMiniCssExtractLoader).toBe(false); - }); - - it('should not apply postcss-loader when target is node', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - targets: ['node'], - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - - expect(config).toMatchSnapshot(); - }); - - it('should enable source map when output.sourceMap.css is true', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - sourceMap: { - css: true, - }, - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - - expect(JSON.stringify(config)).toContain('"sourceMap":true'); - }); - - it('should disable source map when output.sourceMap.css is false', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - sourceMap: { - css: false, - }, - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - - expect(JSON.stringify(config)).toContain('"sourceMap":false'); - }); - - it('should disable source map in production by default', async () => { - const { NODE_ENV } = process.env; - process.env.NODE_ENV = 'production'; - - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - }); - - const config = await rsbuild.unwrapConfig(); - - expect(JSON.stringify(config)).toContain('"sourceMap":false'); - - process.env.NODE_ENV = NODE_ENV; - }); - - it('should allow to custom cssModules.localIdentName', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - cssModules: { - localIdentName: '[hash:base64]', - }, - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - - expect(JSON.stringify(config)).toContain( - '"localIdentName":"[hash:base64]"', - ); - }); - - it('should remove some postcss plugins based on browserslist', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - overrideBrowserslist: ['Chrome 100'], - }, - }, - }); - const config = await rsbuild.unwrapConfig(); - - expect(config).toMatchSnapshot(); - }); -}); diff --git a/packages/compat/webpack/tests/output.test.ts b/packages/compat/webpack/tests/output.test.ts deleted file mode 100644 index c311c489ce..0000000000 --- a/packages/compat/webpack/tests/output.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { pluginOutput } from '../src/plugins/output'; -import { createStubRsbuild } from './helper'; - -describe('plugin-output', () => { - it('should set output correctly', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginOutput()], - }); - - const config = await rsbuild.unwrapConfig(); - expect(config).toMatchSnapshot(); - }); - - it('should allow to custom server directory with distPath.server', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginOutput()], - rsbuildConfig: { - output: { - targets: ['node'], - distPath: { - server: 'server', - }, - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - expect(config).toMatchSnapshot(); - }); - - it('should allow to set distPath.js and distPath.css to empty string', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginOutput()], - rsbuildConfig: { - output: { - distPath: { - js: '', - css: '', - }, - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - expect(config).toMatchSnapshot(); - }); - - it('should allow to use filename.js to modify filename', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginOutput()], - rsbuildConfig: { - output: { - filename: { - js: 'foo.js', - }, - }, - }, - }); - - const config = await rsbuild.unwrapConfig(); - expect(config).toMatchSnapshot(); - }); -}); diff --git a/packages/compat/webpack/tests/progress.test.ts b/packages/compat/webpack/tests/plugin.test.ts similarity index 91% rename from packages/compat/webpack/tests/progress.test.ts rename to packages/compat/webpack/tests/plugin.test.ts index 17a7b415db..e70f82befc 100644 --- a/packages/compat/webpack/tests/progress.test.ts +++ b/packages/compat/webpack/tests/plugin.test.ts @@ -1,11 +1,11 @@ -import { pluginProgress } from '../src/plugins/progress'; +import { pluginAdaptor } from '../src/plugin'; import { createFriendlyPercentage } from '../src/progress/helpers'; import { createStubRsbuild } from './helper'; describe('plugin-progress', () => { it('should register ProgressPlugin by default', async () => { const rsbuild = await createStubRsbuild({ - plugins: [pluginProgress()], + plugins: [pluginAdaptor()], }); const matched = await rsbuild.matchBundlerPlugin('ProgressPlugin'); @@ -14,7 +14,7 @@ describe('plugin-progress', () => { it('should not register ProgressPlugin if dev.progressBar is false', async () => { const rsbuild = await createStubRsbuild({ - plugins: [pluginProgress()], + plugins: [pluginAdaptor()], rsbuildConfig: { dev: { progressBar: false, diff --git a/packages/compat/webpack/tests/resolve.test.ts b/packages/compat/webpack/tests/resolve.test.ts deleted file mode 100644 index 8fc74b5e11..0000000000 --- a/packages/compat/webpack/tests/resolve.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { pluginResolve } from '../src/plugins/resolve'; -import { createStubRsbuild } from './helper'; - -describe('plugin-resolve', () => { - it('should apply default extensions correctly', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginResolve()], - }); - const config = await rsbuild.unwrapConfig(); - expect(config.resolve?.extensions).toEqual([ - '.ts', - '.tsx', - '.js', - '.jsx', - '.mjs', - '.json', - ]); - }); - - it('should allow to use source.alias to config webpack alias', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginResolve()], - rsbuildConfig: { - source: { - alias: { - foo: 'bar', - }, - }, - }, - }); - const config = await rsbuild.unwrapConfig(); - - expect(config.resolve?.alias).toEqual({ - foo: 'bar', - }); - }); - - it('should support source.alias to be a function', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginResolve()], - rsbuildConfig: { - source: { - alias() { - return { - foo: 'bar', - }; - }, - }, - }, - }); - const config = await rsbuild.unwrapConfig(); - - expect(config.resolve?.alias).toEqual({ - foo: 'bar', - }); - }); - - it('should disable resolve.fullySpecified by default', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginResolve()], - }); - const config = await rsbuild.unwrapConfig(); - - expect(config).toMatchSnapshot(); - }); -}); diff --git a/packages/core/bin/rsbuild.js b/packages/core/bin/rsbuild.js index 76e6ff6058..f449de1545 100755 --- a/packages/core/bin/rsbuild.js +++ b/packages/core/bin/rsbuild.js @@ -1,14 +1,15 @@ #!/usr/bin/env node -const { prepareCli } = require('../dist/cli/prepare'); +import { logger } from '@rsbuild/shared'; +import { __internalHelper } from '../dist/index.js'; + +const { runCli, prepareCli } = __internalHelper; async function main() { prepareCli(); try { - const { runCli } = require('../dist/cli/commands'); runCli(); } catch (err) { - const { logger } = require('@rsbuild/shared/rslog'); logger.error(err); } } diff --git a/packages/core/modern.config.ts b/packages/core/modern.config.ts index bcee294a73..be36b4bc4c 100644 --- a/packages/core/modern.config.ts +++ b/packages/core/modern.config.ts @@ -1,22 +1,77 @@ -import { defineConfig } from '@modern-js/module-tools'; -import { baseBuildConfig } from '../../scripts/modern.base.config'; +import fs from 'node:fs'; +import path from 'node:path'; +import { + type CliPlugin, + type ModuleTools, + defineConfig, + moduleTools, +} from '@modern-js/module-tools'; +import { + BUILD_TARGET, + cjsBuildConfig, + commonExternals, + emitTypePkgJsonPlugin, + esmBuildConfig, +} from '../../scripts/modern.base.config'; + +const externals = [ + ...commonExternals, + '@rsbuild/core/client/hmr', + '@rsbuild/core/client/overlay', +]; + +// Since the relative paths of bundle and compiled have changed, +// we need to rewrite the import paths. +export const redirectCompiledPlugin: CliPlugin = { + name: 'redirect-compiled-plugin', + setup() { + return { + afterBuild() { + const distFiles = [ + path.join(__dirname, 'dist/index.js'), + path.join(__dirname, 'dist/index.cjs'), + ]; + + for (const file of distFiles) { + let content = fs.readFileSync(file, 'utf-8'); + content = content.replace(/(\.\.\/){2,3}compiled/g, '../compiled'); + fs.writeFileSync(file, content); + } + }, + }; + }, +}; export default defineConfig({ - ...baseBuildConfig, + plugins: [moduleTools(), emitTypePkgJsonPlugin, redirectCompiledPlugin], buildConfig: [ + // Node / ESM + { + ...esmBuildConfig, + input: ['src/index.ts'], + externals, + dts: false, + }, + // Node / CJS { - ...baseBuildConfig.buildConfig, - input: ['src', '!src/client/hmr.ts', '!src/client/overlay.ts'], + ...cjsBuildConfig, + input: [ + 'src/index.ts', + 'src/loader/ignoreCssLoader.ts', + 'src/loader/transformLoader.ts', + 'src/loader/transformRawLoader.ts', + ], + externals, }, + // Client / ESM { - buildType: 'bundle', format: 'esm', - target: 'es2017', - dts: false, input: { hmr: 'src/client/hmr.ts', overlay: 'src/client/overlay.ts', }, + target: BUILD_TARGET.client, + dts: false, externals: ['./hmr'], outDir: './dist/client', autoExtension: true, @@ -28,5 +83,14 @@ export default defineConfig({ return options; }, }, + // Types + { + externals, + buildType: 'bundleless', + dts: { + distPath: '../dist-types', + only: true, + }, + }, ], }); diff --git a/packages/core/package.json b/packages/core/package.json index 32c873376e..e2888a911a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/core", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "The Rspack-based build tool.", "homepage": "https://rsbuild.dev", "bugs": { @@ -12,37 +12,35 @@ "directory": "packages/core" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "types": "./dist-types/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" }, "./client/hmr": { - "types": "./dist/client/hmr/index.d.ts", - "default": "./dist/client/hmr.mjs" + "types": "./dist-types/client/hmr/index.d.ts", + "default": "./dist/client/hmr.js" }, "./client/overlay": { - "types": "./dist/client/overlay.d.ts", - "default": "./dist/client/overlay.mjs" - }, - "./internal": { - "types": "./dist/internal.d.ts", - "default": "./dist/internal.js" + "types": "./dist-types/client/overlay.d.ts", + "default": "./dist/client/overlay.js" }, "./types": { "types": "./types.d.ts" }, "./package.json": "./package.json" }, - "main": "./dist/index.js", - "types": "./dist/index.d.ts", + "main": "./dist/index.cjs", + "types": "./dist-types/index.d.ts", "bin": { "rsbuild": "./bin/rsbuild.js" }, "files": [ "bin", "dist", + "dist-types", "static", "compiled", "types.d.ts" @@ -54,7 +52,7 @@ }, "dependencies": { "@rsbuild/shared": "workspace:*", - "@rspack/core": "0.6.5", + "@rspack/core": "0.7.0-beta.0", "@swc/helpers": "0.5.3", "core-js": "~3.36.0", "html-webpack-plugin": "npm:html-rspack-plugin@5.7.2", @@ -62,20 +60,29 @@ "source-map": "0.5.7" }, "devDependencies": { + "@types/fs-extra": "^11.0.4", "@types/node": "18.x", "@types/on-finished": "2.3.4", "@types/ws": "^8.5.10", - "commander": "^12.0.0", + "commander": "^12.1.0", "connect-history-api-fallback": "^2.0.0", - "rspack-manifest-plugin": "5.0.0", + "css-loader": "7.1.1", "dotenv": "16.4.5", "dotenv-expand": "11.0.6", - "http-compression": "1.0.19", + "http-compression": "1.0.20", "launch-editor-middleware": "^2.6.1", + "fs-extra": "^11.2.0", + "less-loader": "12.2.0", "on-finished": "2.4.1", "open": "^8.4.0", + "postcss-load-config": "5.1.0", + "postcss-loader": "8.1.1", + "postcss-value-parser": "4.2.0", "prebundle": "1.1.0", + "resolve-url-loader": "5.0.0", + "rspack-manifest-plugin": "5.0.0", "sirv": "^2.0.4", + "style-loader": "3.3.4", "typescript": "^5.4.2", "webpack": "^5.91.0", "webpack-dev-middleware": "7.2.1", diff --git a/packages/core/prebundle.config.mjs b/packages/core/prebundle.config.mjs index 87970a0792..8b6ba9b681 100644 --- a/packages/core/prebundle.config.mjs +++ b/packages/core/prebundle.config.mjs @@ -1,16 +1,32 @@ -import fs from 'node:fs'; // @ts-check import { join } from 'node:path'; +import fse from 'fs-extra'; // The package size of `schema-utils` is large, and validate has a performance overhead of tens of ms. // So we skip the validation and let TypeScript to ensure type safety. const writeEmptySchemaUtils = (task) => { const schemaUtilsPath = join(task.distPath, 'schema-utils.js'); - fs.writeFileSync(schemaUtilsPath, 'module.exports.validate = () => {};'); + fse.writeFileSync(schemaUtilsPath, 'module.exports.validate = () => {};'); }; +function replaceFileContent(filePath, replaceFn) { + const content = fse.readFileSync(filePath, 'utf-8'); + const newContent = replaceFn(content); + if (newContent !== content) { + fse.writeFileSync(filePath, newContent); + } +} + /** @type {import('prebundle').Config} */ export default { + externals: { + // External caniuse-lite data, so users can update it manually. + 'caniuse-lite': 'caniuse-lite', + '/^caniuse-lite(/.*)/': 'caniuse-lite$1', + webpack: 'webpack', + postcss: 'postcss', + typescript: 'typescript', + }, dependencies: [ 'open', 'commander', @@ -26,6 +42,10 @@ export default { picocolors: '@rsbuild/shared/picocolors', }, }, + { + name: 'postcss-value-parser', + ignoreDts: true, + }, { name: 'sirv', ignoreDts: true, @@ -49,5 +69,69 @@ export default { ignoreDts: true, afterBundle: writeEmptySchemaUtils, }, + { + name: 'style-loader', + ignoreDts: true, + afterBundle: (task) => { + fse.copySync( + join(task.depPath, 'dist/runtime'), + join(task.distPath, 'runtime'), + ); + }, + }, + { + name: 'less-loader', + ignoreDts: true, + externals: { + less: '@rsbuild/shared/less', + }, + }, + { + name: 'css-loader', + ignoreDts: true, + externals: { + 'postcss-value-parser': '../postcss-value-parser', + semver: '@rsbuild/shared/semver', + }, + }, + { + name: 'postcss-loader', + externals: { + jiti: '@rsbuild/shared/jiti', + semver: '@rsbuild/shared/semver', + }, + ignoreDts: true, + }, + { + name: 'postcss-load-config', + externals: { + yaml: '@rsbuild/shared/yaml', + '@rsbuild/shared/jiti': '@rsbuild/shared/jiti', + }, + ignoreDts: true, + // this is a trick to avoid ncc compiling the dynamic import syntax + // https://github.com/vercel/ncc/issues/935 + beforeBundle(task) { + replaceFileContent(join(task.depPath, 'src/req.js'), (content) => + content + .replaceAll('await import', 'await __import') + .replaceAll(`import('jiti')`, `import('@rsbuild/shared/jiti')`), + ); + }, + afterBundle(task) { + replaceFileContent( + join(task.distPath, 'index.js'), + (content) => + `${content.replaceAll('await __import', 'await import')}`, + ); + }, + }, + { + name: 'resolve-url-loader', + ignoreDts: true, + externals: { + 'loader-utils': '@rsbuild/shared/loader-utils2', + }, + }, ], }; diff --git a/packages/core/src/cli/commands.ts b/packages/core/src/cli/commands.ts index cb693bd59c..ff33b3f4ba 100644 --- a/packages/core/src/cli/commands.ts +++ b/packages/core/src/cli/commands.ts @@ -1,7 +1,7 @@ import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { type RsbuildMode, color, logger } from '@rsbuild/shared'; -import { type Command, program } from '../../compiled/commander'; +import { type Command, program } from '../../compiled/commander/index.js'; import { init } from './init'; export type CommonOptions = { diff --git a/packages/core/src/cli/prepare.ts b/packages/core/src/cli/prepare.ts index 927d0246a9..7bacf868b8 100644 --- a/packages/core/src/cli/prepare.ts +++ b/packages/core/src/cli/prepare.ts @@ -1,4 +1,4 @@ -import { logger } from '@rsbuild/shared/rslog'; +import { logger } from '@rsbuild/shared'; function initNodeEnv() { if (!process.env.NODE_ENV) { diff --git a/packages/core/src/client/format.ts b/packages/core/src/client/format.ts index 3443d3003d..f4601c3eba 100644 --- a/packages/core/src/client/format.ts +++ b/packages/core/src/client/format.ts @@ -5,13 +5,20 @@ import { findSourceCode } from './findSourceMap'; function resolveFileName(stats: StatsError) { // Get the real source file path with stats.moduleIdentifier. // e.g. moduleIdentifier is "builtin:react-refresh-loader!/Users/x/src/App.jsx" - const regex = /(?:\!|^)([^!]+)$/; - const fileName = stats.moduleIdentifier?.match(regex)?.at(-1) ?? ''; - return fileName - ? // add default column add lines for linking - `File: ${fileName}:1:1\n` - : // fallback to moduleName if moduleIdentifier parse failed - `File: ${stats.moduleName}\n`; + if (stats.moduleIdentifier) { + const regex = /(?:\!|^)([^!]+)$/; + const matched = stats.moduleIdentifier.match(regex); + if (matched) { + const fileName = matched.pop(); + if (fileName) { + // add default column add lines for linking + return `File: ${fileName}:1:1\n`; + } + } + } + + // fallback to moduleName if moduleIdentifier parse failed + return `File: ${stats.moduleName}\n`; } // Cleans up Rspack error messages. @@ -22,8 +29,7 @@ function formatMessage(stats: StatsError | string) { // Stats error object if (typeof stats === 'object') { const fileName = resolveFileName(stats); - const mainMessage = - typeof stats.formatted === 'string' ? stats.formatted : stats.message; + const mainMessage = stats.message; const details = stats.details ? `\nDetails: ${stats.details}\n` : ''; const stack = stats.stack ? `\n${stats.stack}` : ''; diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index fb164af8b5..36b9ec81de 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -16,13 +16,10 @@ import { SERVER_DIST_DIR, SERVICE_WORKER_DIST_DIR, SVG_DIST_DIR, - TS_CONFIG_FILE, WASM_DIST_DIR, color, debounce, - findExists, getNodeEnv, - isFileExists, isObject, logger, } from '@rsbuild/shared'; @@ -39,6 +36,8 @@ import type { RsbuildConfig, RsbuildEntry, } from '@rsbuild/shared'; +import { TS_CONFIG_FILE } from './constants'; +import { findExists, isFileExists } from './helpers'; import { mergeRsbuildConfig } from './mergeConfig'; import { restartDevServer } from './server/restart'; @@ -145,7 +144,6 @@ const getDefaultOutputConfig = (): NormalizedOutputConfig => ({ css: false, }, filenameHash: true, - enableCssModuleTSDeclaration: false, inlineScripts: false, inlineStyles: false, cssModules: { diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index d7a9bcf422..95b7d6bb93 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -1,5 +1,17 @@ +import { join } from 'node:path'; + export const PLUGIN_SWC_NAME = 'rsbuild:swc'; export const PLUGIN_CSS_NAME = 'rsbuild:css'; export const PLUGIN_LESS_NAME = 'rsbuild:less'; export const PLUGIN_SASS_NAME = 'rsbuild:sass'; export const PLUGIN_STYLUS_NAME = 'rsbuild:stylus'; + +// loaders will be emitted to the same folder of the main bundle +export const LOADER_PATH = join(__dirname); +export const STATIC_PATH = join(__dirname, '../static'); +export const COMPILED_PATH = join(__dirname, '../compiled'); + +export const TS_CONFIG_FILE = 'tsconfig.json'; + +export const HTML_REGEX = /\.html$/; +export const CSS_REGEX = /\.css$/; diff --git a/packages/core/src/createRsbuild.ts b/packages/core/src/createRsbuild.ts index 09b4fba789..e5a9c14564 100644 --- a/packages/core/src/createRsbuild.ts +++ b/packages/core/src/createRsbuild.ts @@ -48,7 +48,12 @@ export async function createRsbuild( debug('add default plugins done'); const rsbuild = { - ...pick(pluginManager, ['addPlugins', 'removePlugins', 'isPluginExists']), + ...pick(pluginManager, [ + 'addPlugins', + 'getPlugins', + 'removePlugins', + 'isPluginExists', + ]), ...pick(pluginAPI, [ 'onBeforeBuild', 'onBeforeCreateCompiler', diff --git a/packages/core/src/provider/shared.ts b/packages/core/src/helpers.ts similarity index 72% rename from packages/core/src/provider/shared.ts rename to packages/core/src/helpers.ts index 8b3127bf7c..d39bfc4f2e 100644 --- a/packages/core/src/provider/shared.ts +++ b/packages/core/src/helpers.ts @@ -1,16 +1,19 @@ -import { join } from 'node:path'; +import path from 'node:path'; import { + type BundlerChain, + DEFAULT_ASSET_PREFIX, type MultiStats, - type SharedCompiledPkgNames, type Stats, type StatsError, + addTrailingSlash, color, - getSharedPkgCompiledPath, isMultiCompiler, + removeTailingSlash, } from '@rsbuild/shared'; import { fse } from '@rsbuild/shared'; import type { StatsCompilation, StatsValue } from '@rspack/core'; -import { formatStatsMessages } from '../client/format'; +import { formatStatsMessages } from './client/format'; +import { COMPILED_PATH } from './constants'; // depend on native IgnorePlugin export const rspackMinVersion = '0.6.2'; @@ -50,15 +53,8 @@ export const isSatisfyRspackVersion = async (originalVersion: string) => { return true; }; -export const getCompiledPath = (packageName: string) => { - const providerCompilerPath = join(__dirname, '../../compiled', packageName); - if (fse.existsSync(providerCompilerPath)) { - return providerCompilerPath; - } - return getSharedPkgCompiledPath(packageName as SharedCompiledPkgNames); -}; - -export const BUILTIN_LOADER = 'builtin:'; +export const getCompiledPath = (packageName: string) => + path.join(COMPILED_PATH, packageName); /** * Add node polyfill tip when failed to resolve node built-in modules. @@ -223,3 +219,65 @@ export function formatStats( return {}; } + +export const formatPublicPath = (publicPath: string, withSlash = true) => { + // 'auto' is a magic value in Rspack and we should not add trailing slash + if (publicPath === 'auto') { + return publicPath; + } + + return withSlash + ? addTrailingSlash(publicPath) + : removeTailingSlash(publicPath); +}; + +export const getPublicPathFromChain = ( + chain: BundlerChain, + withSlash = true, +) => { + const publicPath = chain.output.get('publicPath'); + + if (typeof publicPath === 'string') { + return formatPublicPath(publicPath, withSlash); + } + + return formatPublicPath(DEFAULT_ASSET_PREFIX, withSlash); +}; + +/** + * ensure absolute file path. + * @param base - Base path to resolve relative from. + * @param filePath - Absolute or relative file path. + * @returns Resolved absolute file path. + */ +export const ensureAbsolutePath = (base: string, filePath: string): string => + path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath); + +export const isFileSync = (filePath: string) => { + try { + return fse.statSync(filePath, { throwIfNoEntry: false })?.isFile(); + } catch (_) { + return false; + } +}; + +/** + * Find first already exists file. + * @param files - Absolute file paths with extension. + * @returns The file path if exists, or false if no file exists. + */ +export const findExists = (files: string[]): string | false => { + for (const file of files) { + if (isFileSync(file)) { + return file; + } + } + return false; +}; + +export async function isFileExists(file: string) { + return fse.promises + .access(file, fse.constants.F_OK) + .then(() => true) + .catch(() => false); +} diff --git a/packages/core/src/htmlUtils.ts b/packages/core/src/htmlUtils.ts deleted file mode 100644 index c071185ee4..0000000000 --- a/packages/core/src/htmlUtils.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * This file is used to provide/set a global html-plugin singleton - */ -import type HtmlWebpackPlugin from 'html-webpack-plugin'; - -let htmlPlugin: typeof HtmlWebpackPlugin; - -/** - * This method is used to override the Rsbuild default html-plugin (html-rspack-plugin). - */ -export const setHTMLPlugin = (plugin: typeof HtmlWebpackPlugin) => { - if (plugin) { - htmlPlugin = plugin; - } -}; - -export const getHTMLPlugin = () => { - if (!htmlPlugin) { - htmlPlugin = require('html-webpack-plugin'); - } - return htmlPlugin; -}; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 6e8abc44ec..ff5234e17a 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,6 +4,7 @@ */ import { rspack } from '@rspack/core'; import type * as Rspack from '@rspack/core'; +import * as __internalHelper from './internal'; // Core methods export { loadEnv } from './loadEnv'; @@ -68,6 +69,38 @@ export type { RsbuildInstance, CreateRsbuildOptions, InspectConfigOptions, + // Subtypes of Config + Minify, + Polyfill, + PrintUrls, + PublicDir, + Decorators, + RspackRule, + WatchFiles, + CSSModules, + CrossOrigin, + ConsoleType, + SplitChunks, + BundlerChain, + ClientConfig, + ScriptInject, + ChainedConfig, + PostCSSPlugin, + ScriptLoading, + LegalComments, + AliasStrategy, + FilenameConfig, + DistPathConfig, + OutputStructure, + ChainIdentifier, + PreconnectOption, + CSSLoaderOptions, + ModifyChainUtils, + StyleLoaderOptions, + PostCSSLoaderOptions, + ChainedConfigWithUtils, + ModifyRspackConfigUtils, + CSSModulesLocalsConvention, // Hook Callback Types OnExitFn, OnAfterBuildFn, @@ -86,3 +119,10 @@ export type { TransformFn, TransformHandler, } from '@rsbuild/shared'; + +export { + /** + * @private + */ + __internalHelper, +}; diff --git a/packages/core/src/initPlugins.ts b/packages/core/src/initPlugins.ts index 2ad0edcc00..c01dce7f45 100644 --- a/packages/core/src/initPlugins.ts +++ b/packages/core/src/initPlugins.ts @@ -10,6 +10,7 @@ import { removeLeadingSlash, } from '@rsbuild/shared'; import type { Compiler } from '@rspack/core'; +import { LOADER_PATH } from './constants'; import { createPublicContext } from './createContext'; import type { InternalContext, NormalizedConfig } from './types'; @@ -127,9 +128,9 @@ export function getPluginAPI({ } const loaderName = descriptor.raw - ? 'transformRawLoader' - : 'transformLoader'; - const loaderPath = join(__dirname, `./rspack/${loaderName}`); + ? 'transformRawLoader.cjs' + : 'transformLoader.cjs'; + const loaderPath = join(LOADER_PATH, loaderName); rule.use(id).loader(loaderPath).options({ id }); diff --git a/packages/core/src/internal.ts b/packages/core/src/internal.ts index 4ed54c0bc8..e5ea282786 100644 --- a/packages/core/src/internal.ts +++ b/packages/core/src/internal.ts @@ -4,18 +4,24 @@ * Please do not use them in your Rsbuild project or plugins. */ -export { rspackProvider } from './provider/provider'; +export { runCli } from './cli/commands'; +export { prepareCli } from './cli/prepare'; export { createContext, createPublicContext } from './createContext'; export { initPlugins, createPluginManager } from './pluginManager'; export { initHooks, type Hooks } from './initHooks'; export { initRsbuildConfig } from './provider/initConfigs'; +export { applyCSSRule } from './plugins/css'; export { getPluginAPI } from './initPlugins'; -export { applyBaseCSSRule, applyCSSModuleRule } from './provider/plugins/css'; export type { InternalContext } from './types'; -export { setHTMLPlugin, getHTMLPlugin } from './htmlUtils'; -export { formatStats, getStatsOptions } from './provider/shared'; +export { + setHTMLPlugin, + getHTMLPlugin, + setCssExtractPlugin, +} from './pluginHelper'; +export { formatStats, getStatsOptions } from './helpers'; export { getChainUtils } from './provider/rspackConfig'; -export { applySwcDecoratorConfig } from './provider/plugins/swc'; +export { applySwcDecoratorConfig } from './plugins/swc'; +export { getSwcMinimizerOptions } from './plugins/minimize'; export { getDevMiddleware } from './server/devMiddleware'; export { createDevServer, startProdServer } from './server'; export { plugins } from './plugins'; diff --git a/packages/core/src/loadEnv.ts b/packages/core/src/loadEnv.ts index 08d54fd213..7b952a603b 100644 --- a/packages/core/src/loadEnv.ts +++ b/packages/core/src/loadEnv.ts @@ -1,8 +1,9 @@ import fs from 'node:fs'; import { join } from 'node:path'; -import { getNodeEnv, isFileSync } from '@rsbuild/shared'; -import { parse } from '../compiled/dotenv'; -import { expand } from '../compiled/dotenv-expand'; +import { getNodeEnv } from '@rsbuild/shared'; +import { expand } from '../compiled/dotenv-expand/index.js'; +import { parse } from '../compiled/dotenv/index.js'; +import { isFileSync } from './helpers'; export type LoadEnvOptions = { /** diff --git a/packages/shared/src/loaders/ignoreCssLoader.ts b/packages/core/src/loader/ignoreCssLoader.ts similarity index 100% rename from packages/shared/src/loaders/ignoreCssLoader.ts rename to packages/core/src/loader/ignoreCssLoader.ts diff --git a/packages/core/src/rspack/transformLoader.ts b/packages/core/src/loader/transformLoader.ts similarity index 100% rename from packages/core/src/rspack/transformLoader.ts rename to packages/core/src/loader/transformLoader.ts diff --git a/packages/core/src/rspack/transformRawLoader.ts b/packages/core/src/loader/transformRawLoader.ts similarity index 100% rename from packages/core/src/rspack/transformRawLoader.ts rename to packages/core/src/loader/transformRawLoader.ts diff --git a/packages/core/src/pluginHelper.ts b/packages/core/src/pluginHelper.ts new file mode 100644 index 0000000000..66cd47ca59 --- /dev/null +++ b/packages/core/src/pluginHelper.ts @@ -0,0 +1,36 @@ +/** + * This file is used to get/set the global instance for html-plugin and css-extract plugin. + */ +import rspack from '@rspack/core'; +import type HtmlWebpackPlugin from 'html-webpack-plugin'; + +let htmlPlugin: typeof HtmlWebpackPlugin; + +/** + * This method is used to override the Rsbuild default html-plugin (html-rspack-plugin). + */ +export const setHTMLPlugin = (plugin: typeof HtmlWebpackPlugin) => { + if (plugin) { + htmlPlugin = plugin; + } +}; + +export const getHTMLPlugin = (): typeof HtmlWebpackPlugin => { + if (!htmlPlugin) { + htmlPlugin = require('html-webpack-plugin'); + } + return htmlPlugin; +}; + +let cssExtractPlugin: unknown; + +export const setCssExtractPlugin = (plugin: unknown) => { + cssExtractPlugin = plugin; +}; + +export const getCssExtractPlugin = () => { + if (cssExtractPlugin) { + return cssExtractPlugin as typeof rspack.CssExtractRspackPlugin; + } + return rspack.CssExtractRspackPlugin; +}; diff --git a/packages/core/src/pluginManager.ts b/packages/core/src/pluginManager.ts index 510f5c7d68..c44069e502 100644 --- a/packages/core/src/pluginManager.ts +++ b/packages/core/src/pluginManager.ts @@ -92,9 +92,7 @@ export function createPluginManager(): PluginManager { Boolean(plugins.find((plugin) => plugin.name === pluginName)); return { - get plugins() { - return plugins; - }, + getPlugins: () => plugins, addPlugins, removePlugins, isPluginExists, @@ -177,7 +175,7 @@ export async function initPlugins({ }) { debug('init plugins'); - const plugins = pluginDagSort(pluginManager.plugins); + const plugins = pluginDagSort(pluginManager.getPlugins()); const removedPlugins = plugins.reduce((ret, plugin) => { if (plugin.remove) { diff --git a/packages/core/src/plugins/basic.ts b/packages/core/src/plugins/basic.ts index 04fa7b49ed..9b876d56a7 100644 --- a/packages/core/src/plugins/basic.ts +++ b/packages/core/src/plugins/basic.ts @@ -63,6 +63,12 @@ export const pluginBasic = (): RsbuildPlugin => ({ path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), ); } + + process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent'; + + // improve kill process performance + // https://github.com/web-infra-dev/rspack/pull/5486 + process.env.WATCHPACK_WATCHER_LIMIT ||= '20'; }, ); }, diff --git a/packages/core/src/plugins/cache.ts b/packages/core/src/plugins/cache.ts index 35fc4038e3..bab5947358 100644 --- a/packages/core/src/plugins/cache.ts +++ b/packages/core/src/plugins/cache.ts @@ -1,12 +1,8 @@ import crypto from 'node:crypto'; import { isAbsolute, join } from 'node:path'; import { fse } from '@rsbuild/shared'; -import { - type BuildCacheOptions, - type RsbuildContext, - findExists, - isFileExists, -} from '@rsbuild/shared'; +import type { BuildCacheOptions, RsbuildContext } from '@rsbuild/shared'; +import { findExists, isFileExists } from '../helpers'; import type { NormalizedConfig, RsbuildPlugin } from '../types'; async function validateCache( diff --git a/packages/shared/src/css.ts b/packages/core/src/plugins/css.ts similarity index 54% rename from packages/shared/src/css.ts rename to packages/core/src/plugins/css.ts index 183926ce26..000b58bf01 100644 --- a/packages/shared/src/css.ts +++ b/packages/core/src/plugins/css.ts @@ -1,17 +1,35 @@ +import path from 'node:path'; +import { + type BundlerChainRule, + type CSSExtractOptions, + type CSSLoaderOptions, + type ModifyChainUtils, + type PostCSSLoaderOptions, + type PostCSSOptions, + type RsbuildContext, + type RsbuildTarget, + deepmerge, + getBrowserslistWithDefault, + isFunction, + isPlainObject, + mergeChainedOptions, +} from '@rsbuild/shared'; import type { AcceptedPlugin } from 'postcss'; -import deepmerge from '../compiled/deepmerge'; -import { CSS_MODULES_REGEX, NODE_MODULES_REGEX } from './constants'; -import { mergeChainedOptions } from './mergeChainedOptions'; -import type { - CSSLoaderOptions, - NormalizedConfig, - PostCSSLoaderOptions, - PostCSSOptions, - RsbuildTarget, -} from './types'; -import { isFunction, isPlainObject } from './utils'; - -export const getCssModuleLocalIdentName = ( +import { CSS_REGEX, LOADER_PATH } from '../constants'; +import { getCompiledPath } from '../helpers'; +import { getCssExtractPlugin } from '../pluginHelper'; +import type { NormalizedConfig, RsbuildPlugin } from '../types'; + +export const enableNativeCss = (config: NormalizedConfig) => + !config.output.injectStyles; + +export const isUseCssExtract = ( + config: NormalizedConfig, + target: RsbuildTarget, +) => + !config.output.injectStyles && target !== 'node' && target !== 'web-worker'; + +const getCSSModulesLocalIdentName = ( config: NormalizedConfig, isProd: boolean, ) => @@ -21,39 +39,35 @@ export const getCssModuleLocalIdentName = ( ? '[local]-[hash:base64:6]' : '[path][name]__[local]-[hash:base64:6]'); -export const isInNodeModules = (path: string) => NODE_MODULES_REGEX.test(path); +// If the target is not `web` and the modules option of css-loader is enabled, +// we must enable exportOnlyLocals to only exports the modules identifier mappings. +// Otherwise, the compiled CSS code may contain invalid code, such as `new URL`. +// https://github.com/webpack-contrib/css-loader#exportonlylocals +export const normalizeCssLoaderOptions = ( + options: CSSLoaderOptions, + exportOnlyLocals: boolean, +) => { + if (options.modules && exportOnlyLocals) { + let { modules } = options; + if (modules === true) { + modules = { exportOnlyLocals: true }; + } else if (typeof modules === 'string') { + modules = { mode: modules, exportOnlyLocals: true }; + } else { + // create a new object to avoid modifying the original options + modules = { + ...modules, + exportOnlyLocals: true, + }; + } -export type CssLoaderModules = - | boolean - | string - | { - auto: boolean | RegExp | ((filename: string) => boolean); + return { + ...options, + modules, }; - -export const isCssModules = (filename: string, modules: CssLoaderModules) => { - if (typeof modules === 'boolean') { - return modules; } - // Same as the `mode` option - // https://github.com/webpack-contrib/css-loader?tab=readme-ov-file#mode - if (typeof modules === 'string') { - // CSS Modules will be disabled if mode is 'global' - return modules !== 'global'; - } - - const { auto } = modules; - - if (typeof auto === 'boolean') { - return auto && CSS_MODULES_REGEX.test(filename); - } - if (auto instanceof RegExp) { - return auto.test(filename); - } - if (typeof auto === 'function') { - return auto(filename); - } - return true; + return options; }; const userPostcssrcCache = new Map< @@ -69,7 +83,7 @@ async function loadUserPostcssrc(root: string): Promise { } const { default: postcssrc } = await import( - '../compiled/postcss-load-config' + '../../compiled/postcss-load-config/index.js' ); const promise = postcssrc({}, root).catch((err: Error) => { @@ -110,7 +124,9 @@ export const applyAutoprefixer = async ( }); if (!hasAutoprefixer) { - const { default: autoprefixer } = await import('../compiled/autoprefixer'); + const { default: autoprefixer } = await import( + '@rsbuild/shared/autoprefixer' + ); const autoprefixerOptions = mergeChainedOptions({ defaults: { @@ -128,7 +144,7 @@ export const applyAutoprefixer = async ( return pluginObjects; }; -export const getPostcssLoaderOptions = async ({ +const getPostcssLoaderOptions = async ({ browserslist, config, root, @@ -184,48 +200,15 @@ export const getPostcssLoaderOptions = async ({ return mergedConfig; }; -// If the target is 'node' or 'web-worker' and the modules option of css-loader is enabled, -// we must enable exportOnlyLocals to only exports the modules identifier mappings. -// Otherwise, the compiled CSS code may contain invalid code, such as `new URL`. -// https://github.com/webpack-contrib/css-loader#exportonlylocals -export const normalizeCssLoaderOptions = ( - options: CSSLoaderOptions, - exportOnlyLocals: boolean, -) => { - if (options.modules && exportOnlyLocals) { - let { modules } = options; - if (modules === true) { - modules = { exportOnlyLocals: true }; - } else if (typeof modules === 'string') { - modules = { mode: modules, exportOnlyLocals: true }; - } else { - // create a new object to avoid modifying the original options - modules = { - ...modules, - exportOnlyLocals: true, - }; - } - - return { - ...options, - modules, - }; - } - - return options; -}; - -export const getCssLoaderOptions = ({ +const getCSSLoaderOptions = ({ config, importLoaders, - isServer, - isWebWorker, + target, localIdentName, }: { config: NormalizedConfig; importLoaders: number; - isServer: boolean; - isWebWorker: boolean; + target: RsbuildTarget; localIdentName: string; }) => { const { cssModules } = config.output; @@ -249,40 +232,131 @@ export const getCssLoaderOptions = ({ const cssLoaderOptions = normalizeCssLoaderOptions( mergedCssLoaderOptions, - isServer || isWebWorker, + target !== 'web', ); return cssLoaderOptions; }; -export const isUseCssExtract = ( - config: NormalizedConfig, - target: RsbuildTarget, -) => - !config.output.injectStyles && target !== 'node' && target !== 'web-worker'; +export async function applyCSSRule({ + rule, + config, + context, + utils: { target, isProd, CHAIN_ID }, + importLoaders = 1, +}: { + rule: BundlerChainRule; + config: NormalizedConfig; + context: RsbuildContext; + utils: ModifyChainUtils; + importLoaders?: number; +}) { + const browserslist = await getBrowserslistWithDefault( + context.rootPath, + config, + target, + ); -/** - * fix resolve-url-loader can't deal with resolve.alias config - * - * reference: https://github.com/bholloway/resolve-url-loader/blob/e2695cde68f325f617825e168173df92236efb93/packages/resolve-url-loader/docs/advanced-features.md - */ -export const getResolveUrlJoinFn = async () => { - const { - createJoinFunction, - asGenerator, - createJoinImplementation, - defaultJoinGenerator, - } = await import('../compiled/resolve-url-loader'); - - const rsbuildGenerator = asGenerator((item: any, ...rest: any[]) => { - // only handle relative path (not absolutely accurate, but can meet common scenarios) - if (!item.uri.startsWith('.')) { - return [null]; - } - return defaultJoinGenerator(item, ...rest); + // 1. Check user config + const enableExtractCSS = isUseCssExtract(config, target); + + // 2. Prepare loader options + const localIdentName = getCSSModulesLocalIdentName(config, isProd); + + const cssLoaderOptions = getCSSLoaderOptions({ + config, + importLoaders, + target, + localIdentName, }); - return createJoinFunction( - 'rsbuild-resolve-join-fn', - createJoinImplementation(rsbuildGenerator), - ); + + // 3. Create Rspack rule + // Order: style-loader/mini-css-extract -> css-loader -> postcss-loader + if (target === 'web') { + // use mini-css-extract-plugin loader + if (enableExtractCSS) { + const extraCSSOptions: Required = + typeof config.tools.cssExtract === 'object' + ? config.tools.cssExtract + : { + loaderOptions: {}, + pluginOptions: {}, + }; + + rule + .use(CHAIN_ID.USE.MINI_CSS_EXTRACT) + .loader(getCssExtractPlugin().loader) + .options(extraCSSOptions.loaderOptions) + .end(); + } + // use style-loader + else { + const styleLoaderOptions = mergeChainedOptions({ + defaults: {}, + options: config.tools.styleLoader, + }); + + rule + .use(CHAIN_ID.USE.STYLE) + .loader(getCompiledPath('style-loader')) + .options(styleLoaderOptions) + .end(); + } + } else { + rule + .use(CHAIN_ID.USE.IGNORE_CSS) + .loader(path.join(LOADER_PATH, 'ignoreCssLoader.cjs')) + .end(); + } + + rule + .use(CHAIN_ID.USE.CSS) + .loader(getCompiledPath('css-loader')) + .options(cssLoaderOptions) + .end(); + + if (target === 'web') { + const postcssLoaderOptions = await getPostcssLoaderOptions({ + browserslist, + config, + root: context.rootPath, + }); + + rule + .use(CHAIN_ID.USE.POSTCSS) + .loader(getCompiledPath('postcss-loader')) + .options(postcssLoaderOptions) + .end(); + } + + // CSS imports should always be treated as sideEffects + rule.merge({ sideEffects: true }); + + // Enable preferRelative by default, which is consistent with the default behavior of css-loader + // see: https://github.com/webpack-contrib/css-loader/blob/579fc13/src/plugins/postcss-import-parser.js#L234 + rule.resolve.preferRelative(true); +} + +export const pluginCss = (): RsbuildPlugin => { + return { + name: 'rsbuild:css', + setup(api) { + api.modifyBundlerChain(async (chain, utils) => { + const rule = chain.module.rule(utils.CHAIN_ID.RULE.CSS); + const config = api.getNormalizedConfig(); + rule.test(CSS_REGEX); + await applyCSSRule({ + rule, + utils, + config, + context: api.context, + }); + }); + + api.modifyRspackConfig(async (rspackConfig) => { + rspackConfig.experiments ||= {}; + rspackConfig.experiments.css = false; + }); + }, + }; }; diff --git a/packages/core/src/plugins/define.ts b/packages/core/src/plugins/define.ts index 86f58607f4..95315433b4 100644 --- a/packages/core/src/plugins/define.ts +++ b/packages/core/src/plugins/define.ts @@ -1,8 +1,5 @@ -import { - type Define, - getNodeEnv, - getPublicPathFromChain, -} from '@rsbuild/shared'; +import { type Define, getNodeEnv } from '@rsbuild/shared'; +import { getPublicPathFromChain } from '../helpers'; import type { RsbuildPlugin } from '../types'; export const pluginDefine = (): RsbuildPlugin => ({ diff --git a/packages/core/src/plugins/fileSize.ts b/packages/core/src/plugins/fileSize.ts index c5e3a4745f..562001d13c 100644 --- a/packages/core/src/plugins/fileSize.ts +++ b/packages/core/src/plugins/fileSize.ts @@ -3,7 +3,7 @@ * license at https://github.com/facebook/create-react-app/blob/master/LICENSE */ import path from 'node:path'; -import { CSS_REGEX, HTML_REGEX, JS_REGEX, fse } from '@rsbuild/shared'; +import { JS_REGEX, fse } from '@rsbuild/shared'; import { color, logger } from '@rsbuild/shared'; import type { MultiStats, @@ -11,6 +11,7 @@ import type { Stats, StatsAsset, } from '@rsbuild/shared'; +import { CSS_REGEX, HTML_REGEX } from '../constants'; import type { RsbuildPlugin } from '../types'; /** Filter source map and license files */ diff --git a/packages/core/src/plugins/html.ts b/packages/core/src/plugins/html.ts index 28f2dfbc5d..f8774cae41 100644 --- a/packages/core/src/plugins/html.ts +++ b/packages/core/src/plugins/html.ts @@ -1,14 +1,13 @@ import path, { isAbsolute } from 'node:path'; import { + type MinifyJSOptions, applyToCompiler, castArray, color, createVirtualModule, + deepmerge, fse, getDistPath, - getHtmlMinifyOptions, - getPublicPathFromChain, - isFileExists, isHtmlDisabled, isNil, isPlainObject, @@ -23,8 +22,87 @@ import type { RsbuildPluginAPI, } from '@rsbuild/shared'; import type { EntryDescription } from '@rspack/core'; +import { STATIC_PATH } from '../constants'; +import { getPublicPathFromChain, isFileExists } from '../helpers'; import type { HtmlInfo, TagConfig } from '../rspack/HtmlBasicPlugin'; import type { RsbuildPlugin } from '../types'; +import { parseMinifyOptions } from './minimize'; + +function applyRemoveConsole( + options: MinifyJSOptions, + config: NormalizedConfig, +) { + const { removeConsole } = config.performance; + const compressOptions = + typeof options.compress === 'boolean' ? {} : options.compress || {}; + + if (removeConsole === true) { + options.compress = { + ...compressOptions, + drop_console: true, + }; + } else if (Array.isArray(removeConsole)) { + const pureFuncs = removeConsole.map((method) => `console.${method}`); + options.compress = { + ...compressOptions, + pure_funcs: pureFuncs, + }; + } + + return options; +} + +function getTerserMinifyOptions(config: NormalizedConfig) { + const options: MinifyJSOptions = { + mangle: { + safari10: true, + }, + format: { + ascii_only: config.output.charset === 'ascii', + }, + }; + + if (config.output.legalComments === 'none') { + options.format!.comments = false; + } + + const finalOptions = applyRemoveConsole(options, config); + return finalOptions; +} + +export async function getHtmlMinifyOptions( + isProd: boolean, + config: NormalizedConfig, +) { + if ( + !isProd || + !config.output.minify || + !parseMinifyOptions(config).minifyHtml + ) { + return false; + } + + const minifyJS: MinifyJSOptions = getTerserMinifyOptions(config); + + const htmlMinifyDefaultOptions = { + removeComments: false, + useShortDoctype: true, + keepClosingSlash: true, + collapseWhitespace: true, + removeRedundantAttributes: true, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true, + removeEmptyAttributes: true, + minifyJS, + minifyCSS: true, + minifyURLs: true, + }; + + const htmlMinifyOptions = parseMinifyOptions(config).htmlOptions; + return typeof htmlMinifyOptions === 'object' + ? deepmerge(htmlMinifyDefaultOptions, htmlMinifyOptions) + : htmlMinifyDefaultOptions; +} export function getTitle(entryName: string, config: NormalizedConfig) { return mergeChainedOptions({ @@ -52,10 +130,7 @@ export async function getTemplate( config: NormalizedConfig, rootPath: string, ): Promise<{ templatePath: string; templateContent?: string }> { - const DEFAULT_TEMPLATE = path.resolve( - __dirname, - '../../static/template.html', - ); + const DEFAULT_TEMPLATE = path.resolve(STATIC_PATH, 'template.html'); const templatePath = mergeChainedOptions({ defaults: DEFAULT_TEMPLATE, @@ -202,7 +277,7 @@ const getTagConfig = (api: RsbuildPluginAPI): TagConfig | undefined => { }; }; -export const pluginHtml = (modifyTagsFn: ModifyHTMLTagsFn): RsbuildPlugin => ({ +export const pluginHtml = (modifyTagsFn?: ModifyHTMLTagsFn): RsbuildPlugin => ({ name: 'rsbuild:html', setup(api) { diff --git a/packages/core/src/plugins/index.ts b/packages/core/src/plugins/index.ts index 88c408c7b8..e307f31dce 100644 --- a/packages/core/src/plugins/index.ts +++ b/packages/core/src/plugins/index.ts @@ -4,6 +4,8 @@ export const plugins = { basic: () => import('./basic').then((m) => m.pluginBasic()), html: (modifyTagsFn: ModifyHTMLTagsFn) => import('./html').then((m) => m.pluginHtml(modifyTagsFn)), + output: () => import('./output').then((m) => m.pluginOutput()), + resolve: () => import('./resolve').then((m) => m.pluginResolve()), cleanOutput: () => import('./cleanOutput').then((m) => m.pluginCleanOutput()), startUrl: () => import('./startUrl').then((m) => m.pluginStartUrl()), fileSize: () => import('./fileSize').then((m) => m.pluginFileSize()), @@ -24,6 +26,9 @@ export const plugins = { import('./resourceHints').then((m) => m.pluginResourceHints()), performance: () => import('./performance').then((m) => m.pluginPerformance()), define: () => import('./define').then((m) => m.pluginDefine()), + css: () => import('./css').then((m) => m.pluginCss()), + less: () => import('./less').then((m) => m.pluginLess()), + sass: () => import('./sass').then((m) => m.pluginSass()), server: () => import('./server').then((m) => m.pluginServer()), moduleFederation: () => import('./moduleFederation').then((m) => m.pluginModuleFederation()), diff --git a/packages/core/src/plugins/inlineChunk.ts b/packages/core/src/plugins/inlineChunk.ts index 7ee88330ea..4773eb795d 100644 --- a/packages/core/src/plugins/inlineChunk.ts +++ b/packages/core/src/plugins/inlineChunk.ts @@ -1,10 +1,10 @@ import { - CSS_REGEX, type InlineChunkTest, JS_REGEX, isHtmlDisabled, pick, } from '@rsbuild/shared'; +import { CSS_REGEX } from '../constants'; import type { RsbuildPlugin } from '../types'; export const pluginInlineChunk = (): RsbuildPlugin => ({ diff --git a/packages/core/src/plugins/less.ts b/packages/core/src/plugins/less.ts new file mode 100644 index 0000000000..8dfca4d159 --- /dev/null +++ b/packages/core/src/plugins/less.ts @@ -0,0 +1,104 @@ +import path from 'node:path'; +import { + type FileFilterUtil, + type LessLoaderOptions, + type ToolsLessConfig, + castArray, + deepmerge, + getSharedPkgCompiledPath, + mergeChainedOptions, +} from '@rsbuild/shared'; +import { getCompiledPath } from '../helpers'; +import type { RsbuildPlugin } from '../types'; + +const getLessLoaderOptions = ( + rsbuildLessConfig: ToolsLessConfig | undefined, + isUseCssSourceMap: boolean, + rootPath: string, +) => { + const excludes: (RegExp | string)[] = []; + + const addExcludes: FileFilterUtil = (items) => { + excludes.push(...castArray(items)); + }; + + const defaultLessLoaderOptions: LessLoaderOptions = { + lessOptions: { + javascriptEnabled: true, + // let less resolve from node_modules in the current root directory, + // Avoid resolving from wrong node_modules. + paths: [path.join(rootPath, 'node_modules')], + }, + sourceMap: isUseCssSourceMap, + implementation: getSharedPkgCompiledPath('less'), + }; + + const mergeFn = ( + defaults: LessLoaderOptions, + userOptions: LessLoaderOptions, + ): LessLoaderOptions => { + const getLessOptions = () => { + if (defaults.lessOptions && userOptions.lessOptions) { + return deepmerge(defaults.lessOptions, userOptions.lessOptions); + } + return userOptions.lessOptions || defaults.lessOptions; + }; + + return { + ...defaults, + ...userOptions, + lessOptions: getLessOptions(), + }; + }; + + const mergedOptions = mergeChainedOptions({ + defaults: defaultLessLoaderOptions, + options: rsbuildLessConfig, + utils: { addExcludes }, + mergeFn, + }); + + return { + options: mergedOptions, + excludes, + }; +}; + +export function pluginLess(): RsbuildPlugin { + return { + name: 'rsbuild:less', + setup(api) { + api.modifyBundlerChain(async (chain, utils) => { + const config = api.getNormalizedConfig(); + const { applyCSSRule } = await import('./css'); + + const rule = chain.module + .rule(utils.CHAIN_ID.RULE.LESS) + .test(/\.less$/); + + const { excludes, options } = getLessLoaderOptions( + config.tools.less, + config.output.sourceMap.css, + api.context.rootPath, + ); + + for (const item of excludes) { + rule.exclude.add(item); + } + + await applyCSSRule({ + rule, + utils, + config, + context: api.context, + importLoaders: 2, + }); + + rule + .use(utils.CHAIN_ID.USE.LESS) + .loader(getCompiledPath('less-loader')) + .options(options); + }); + }, + }; +} diff --git a/packages/core/src/plugins/manifest.ts b/packages/core/src/plugins/manifest.ts index de219ac0f6..165266913e 100644 --- a/packages/core/src/plugins/manifest.ts +++ b/packages/core/src/plugins/manifest.ts @@ -125,7 +125,7 @@ const generateManifest = if (asyncCSS.length) { entryManifest.async = { - ...(entries[name].async || {}), + ...(entryManifest.async || {}), css: asyncCSS, }; } @@ -158,7 +158,7 @@ export const pluginManifest = (): RsbuildPlugin => ({ typeof manifest === 'string' ? manifest : 'manifest.json'; const { RspackManifestPlugin } = await import( - '../../compiled/rspack-manifest-plugin' + '../../compiled/rspack-manifest-plugin/index.js' ); chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [ diff --git a/packages/shared/src/minimize.ts b/packages/core/src/plugins/minimize.ts similarity index 50% rename from packages/shared/src/minimize.ts rename to packages/core/src/plugins/minimize.ts index 047b62686a..ea16243dbb 100644 --- a/packages/shared/src/minimize.ts +++ b/packages/core/src/plugins/minimize.ts @@ -1,89 +1,17 @@ +import { + CHAIN_ID, + type HTMLPluginOptions, + type NormalizedConfig, + deepmerge, + isObject, +} from '@rsbuild/shared'; +import { rspack } from '@rspack/core'; import type { SwcJsMinimizerRspackPluginOptions } from '@rspack/core'; -import deepmerge from '../compiled/deepmerge'; -import type { - HTMLPluginOptions, - MinifyJSOptions, - NormalizedConfig, -} from './types'; -import { isObject } from './utils'; - -function applyRemoveConsole( - options: MinifyJSOptions, - config: NormalizedConfig, -) { - const { removeConsole } = config.performance; - const compressOptions = - typeof options.compress === 'boolean' ? {} : options.compress || {}; - - if (removeConsole === true) { - options.compress = { - ...compressOptions, - drop_console: true, - }; - } else if (Array.isArray(removeConsole)) { - const pureFuncs = removeConsole.map((method) => `console.${method}`); - options.compress = { - ...compressOptions, - pure_funcs: pureFuncs, - }; - } +import type { RsbuildPlugin } from '../types'; - return options; -} - -function getTerserMinifyOptions(config: NormalizedConfig) { - const options: MinifyJSOptions = { - mangle: { - safari10: true, - }, - format: { - ascii_only: config.output.charset === 'ascii', - }, - }; - - if (config.output.legalComments === 'none') { - options.format!.comments = false; - } - - const finalOptions = applyRemoveConsole(options, config); - return finalOptions; -} - -export async function getHtmlMinifyOptions( - isProd: boolean, +export const getSwcMinimizerOptions = ( config: NormalizedConfig, -) { - if ( - !isProd || - !config.output.minify || - !parseMinifyOptions(config).minifyHtml - ) { - return false; - } - - const minifyJS: MinifyJSOptions = getTerserMinifyOptions(config); - - const htmlMinifyDefaultOptions = { - removeComments: false, - useShortDoctype: true, - keepClosingSlash: true, - collapseWhitespace: true, - removeRedundantAttributes: true, - removeScriptTypeAttributes: true, - removeStyleLinkTypeAttributes: true, - removeEmptyAttributes: true, - minifyJS, - minifyCSS: true, - minifyURLs: true, - }; - - const htmlMinifyOptions = parseMinifyOptions(config).htmlOptions; - return typeof htmlMinifyOptions === 'object' - ? deepmerge(htmlMinifyDefaultOptions, htmlMinifyOptions) - : htmlMinifyDefaultOptions; -} - -export const getSwcMinimizerOptions = (config: NormalizedConfig) => { +): SwcJsMinimizerRspackPluginOptions => { const options: SwcJsMinimizerRspackPluginOptions = {}; const { removeConsole } = config.performance; @@ -169,3 +97,37 @@ export const parseMinifyOptions = ( htmlOptions: minify.htmlOptions, }; }; + +export const pluginMinimize = (): RsbuildPlugin => ({ + name: 'rsbuild:minimize', + + setup(api) { + api.modifyBundlerChain(async (chain, { isProd }) => { + const config = api.getNormalizedConfig(); + const isMinimize = isProd && config.output.minify !== false; + + if (!isMinimize) { + return; + } + + const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } = + rspack; + + const { minifyJs, minifyCss } = parseMinifyOptions(config); + + if (minifyJs) { + chain.optimization + .minimizer(CHAIN_ID.MINIMIZER.JS) + .use(SwcJsMinimizerRspackPlugin, [getSwcMinimizerOptions(config)]) + .end(); + } + + if (minifyCss) { + chain.optimization + .minimizer(CHAIN_ID.MINIMIZER.CSS) + .use(SwcCssMinimizerRspackPlugin, []) + .end(); + } + }); + }, +}); diff --git a/packages/core/src/plugins/moduleFederation.ts b/packages/core/src/plugins/moduleFederation.ts index 730332f5df..41a99498d2 100644 --- a/packages/core/src/plugins/moduleFederation.ts +++ b/packages/core/src/plugins/moduleFederation.ts @@ -1,7 +1,7 @@ import { type CacheGroup, DEFAULT_ASSET_PREFIX, - type RspackCompiler, + type Rspack, } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; import type { RspackPluginInstance } from '@rspack/core'; @@ -19,7 +19,7 @@ class PatchSplitChunksPlugin implements RspackPluginInstance { this.name = name; } - apply(compiler: RspackCompiler) { + apply(compiler: Rspack.Compiler) { const { splitChunks } = compiler.options.optimization; if (!splitChunks) { diff --git a/packages/core/src/plugins/output.ts b/packages/core/src/plugins/output.ts new file mode 100644 index 0000000000..79943e7f4a --- /dev/null +++ b/packages/core/src/plugins/output.ts @@ -0,0 +1,142 @@ +import { posix } from 'node:path'; +import { + DEFAULT_ASSET_PREFIX, + DEFAULT_DEV_HOST, + DEFAULT_PORT, + type NormalizedConfig, + type RsbuildContext, + getDistPath, + getFilename, + mergeChainedOptions, +} from '@rsbuild/shared'; +import { rspack } from '@rspack/core'; +import { formatPublicPath } from '../helpers'; +import { getCssExtractPlugin } from '../pluginHelper'; +import type { RsbuildPlugin } from '../types'; +import { isUseCssExtract } from './css'; + +function getPublicPath({ + isProd, + config, + context, +}: { + isProd: boolean; + config: NormalizedConfig; + context: RsbuildContext; +}) { + const { dev, output } = config; + + let publicPath = DEFAULT_ASSET_PREFIX; + + if (isProd) { + if (typeof output.assetPrefix === 'string') { + publicPath = output.assetPrefix; + } + } else if (typeof dev.assetPrefix === 'string') { + publicPath = dev.assetPrefix; + } else if (dev.assetPrefix === true) { + const protocol = context.devServer?.https ? 'https' : 'http'; + const hostname = context.devServer?.hostname || DEFAULT_DEV_HOST; + const port = context.devServer?.port || DEFAULT_PORT; + if (hostname === DEFAULT_DEV_HOST) { + const localHostname = 'localhost'; + // If user not specify the hostname, it would use 0.0.0.0 + // The http://0.0.0.0:port can't visit in windows, so we shouldn't set publicPath as `//0.0.0.0:${port}/`; + // Relative to docs: + // - https://github.com/quarkusio/quarkus/issues/12246 + publicPath = `${protocol}://${localHostname}:${port}/`; + } else { + publicPath = `${protocol}://${hostname}:${port}/`; + } + } + + return formatPublicPath(publicPath); +} + +export const pluginOutput = (): RsbuildPlugin => ({ + name: 'rsbuild:output', + + setup(api) { + api.modifyBundlerChain( + async ( + chain, + { CHAIN_ID, target, isProd, isServer, isServiceWorker }, + ) => { + const config = api.getNormalizedConfig(); + + const publicPath = getPublicPath({ + config, + isProd, + context: api.context, + }); + + // js output + const jsPath = getDistPath(config, 'js'); + const jsAsyncPath = getDistPath(config, 'jsAsync'); + const jsFilename = getFilename(config, 'js', isProd); + + chain.output + .path(api.context.distPath) + .filename(posix.join(jsPath, jsFilename)) + .chunkFilename(posix.join(jsAsyncPath, jsFilename)) + .publicPath(publicPath) + // disable pathinfo to improve compile performance + // the path info is useless in most cases + // see: https://webpack.js.org/guides/build-performance/#output-without-path-info + .pathinfo(false) + // since webpack v5.54.0+, hashFunction supports xxhash64 as a faster algorithm + // which will be used as default when experiments.futureDefaults is enabled. + .hashFunction('xxhash64'); + + if (isServer) { + const serverPath = getDistPath(config, 'server'); + + chain.output + .path(posix.join(api.context.distPath, serverPath)) + .filename('[name].js') + .chunkFilename('[name].js') + .libraryTarget('commonjs2'); + } + + if (isServiceWorker) { + const workerPath = getDistPath(config, 'worker'); + const filename = posix.join(workerPath, '[name].js'); + + chain.output.filename(filename).chunkFilename(filename); + } + + if (config.output.copy && api.context.bundlerType === 'rspack') { + const { copy } = config.output; + const options = Array.isArray(copy) ? { patterns: copy } : copy; + + chain + .plugin(CHAIN_ID.PLUGIN.COPY) + .use(rspack.CopyRspackPlugin, [options]); + } + + // css output + if (isUseCssExtract(config, target)) { + const extractPluginOptions = mergeChainedOptions({ + defaults: {}, + options: config.tools.cssExtract?.pluginOptions, + }); + + const cssPath = getDistPath(config, 'css'); + const cssFilename = getFilename(config, 'css', isProd); + const cssAsyncPath = getDistPath(config, 'cssAsync'); + + chain + .plugin(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT) + .use(getCssExtractPlugin(), [ + { + filename: posix.join(cssPath, cssFilename), + chunkFilename: posix.join(cssAsyncPath, cssFilename), + ignoreOrder: true, + ...extractPluginOptions, + }, + ]); + } + }, + ); + }, +}); diff --git a/packages/core/src/plugins/performance.ts b/packages/core/src/plugins/performance.ts index fddecf7c33..d7d8434923 100644 --- a/packages/core/src/plugins/performance.ts +++ b/packages/core/src/plugins/performance.ts @@ -1,21 +1,5 @@ -import type { BundlerChain, NormalizedConfig } from '@rsbuild/shared'; import type { RsbuildPlugin } from '../types'; -function applyProfile({ - chain, - config, -}: { - chain: BundlerChain; - config: NormalizedConfig; -}) { - const { profile } = config.performance; - if (!profile) { - return; - } - - chain.profile(profile); -} - /** * Apply some configs of Rsbuild performance */ @@ -40,10 +24,15 @@ export const pluginPerformance = (): RsbuildPlugin => ({ } } }); + api.modifyBundlerChain((chain) => { const config = api.getNormalizedConfig(); + const { profile } = config.performance; + if (!profile) { + return; + } - applyProfile({ chain, config }); + chain.profile(profile); }); }, }); diff --git a/packages/core/src/provider/plugins/progress.ts b/packages/core/src/plugins/progress.ts similarity index 94% rename from packages/core/src/provider/plugins/progress.ts rename to packages/core/src/plugins/progress.ts index 76c1fe1372..9bda79d63e 100644 --- a/packages/core/src/provider/plugins/progress.ts +++ b/packages/core/src/plugins/progress.ts @@ -1,6 +1,6 @@ import { TARGET_ID_MAP, isProd } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; -import type { RsbuildPlugin } from '../../types'; +import type { RsbuildPlugin } from '../types'; export const pluginProgress = (): RsbuildPlugin => ({ name: 'rsbuild:progress', diff --git a/packages/core/src/plugins/resolve.ts b/packages/core/src/plugins/resolve.ts new file mode 100644 index 0000000000..e44ae94be0 --- /dev/null +++ b/packages/core/src/plugins/resolve.ts @@ -0,0 +1,122 @@ +import { + type BundlerChain, + type ChainIdentifier, + type NormalizedConfig, + type RsbuildTarget, + castArray, + mergeChainedOptions, +} from '@rsbuild/shared'; +import { ensureAbsolutePath } from '../helpers'; +import type { RsbuildPlugin } from '../types'; + +// compatible with legacy packages with type="module" +// https://github.com/webpack/webpack/issues/11467 +function applyFullySpecified({ + chain, + CHAIN_ID, +}: { + chain: BundlerChain; + config: NormalizedConfig; + CHAIN_ID: ChainIdentifier; +}) { + chain.module + .rule(CHAIN_ID.RULE.MJS) + .test(/\.m?js/) + .resolve.set('fullySpecified', false); +} + +function applyExtensions({ chain }: { chain: BundlerChain }) { + const extensions = [ + // most projects are using TypeScript, resolve .ts(x) files first to reduce resolve time. + '.ts', + '.tsx', + '.js', + '.jsx', + '.mjs', + '.json', + ]; + + chain.resolve.extensions.merge(extensions); +} + +function applyAlias({ + chain, + target, + config, + rootPath, +}: { + chain: BundlerChain; + target: RsbuildTarget; + config: NormalizedConfig; + rootPath: string; +}) { + const { alias } = config.source; + + if (!alias) { + return; + } + + const mergedAlias = mergeChainedOptions({ + defaults: {}, + options: alias, + utils: { target }, + }); + + /** + * Format alias value: + * - Relative paths need to be turned into absolute paths. + * - Absolute paths or a package name are not processed. + */ + for (const name of Object.keys(mergedAlias)) { + const values = castArray(mergedAlias[name]); + const formattedValues = values.map((value) => { + if (typeof value === 'string' && value.startsWith('.')) { + return ensureAbsolutePath(rootPath, value); + } + return value; + }); + + chain.resolve.alias.set( + name, + (formattedValues.length === 1 ? formattedValues[0] : formattedValues) as + | string + | string[], + ); + } +} + +export const pluginResolve = (): RsbuildPlugin => ({ + name: 'rsbuild:resolve', + + setup(api) { + api.modifyBundlerChain({ + order: 'pre', + handler: (chain, { target, CHAIN_ID }) => { + const config = api.getNormalizedConfig(); + + applyExtensions({ chain }); + + applyAlias({ + chain, + target, + config, + rootPath: api.context.rootPath, + }); + + // in some cases (modern.js), get error when fullySpecified rule after js rule + applyFullySpecified({ chain, config, CHAIN_ID }); + }, + }); + + api.modifyRspackConfig(async (rspackConfig) => { + const isTsProject = Boolean(api.context.tsconfigPath); + const config = api.getNormalizedConfig(); + + rspackConfig.resolve ||= {}; + + if (isTsProject && config.source.aliasStrategy === 'prefer-tsconfig') { + rspackConfig.resolve.tsConfigPath = api.context.tsconfigPath; + } + }); + }, +}); diff --git a/packages/core/src/plugins/resourceHints.ts b/packages/core/src/plugins/resourceHints.ts index 0c99a234ac..b959fab2f9 100644 --- a/packages/core/src/plugins/resourceHints.ts +++ b/packages/core/src/plugins/resourceHints.ts @@ -1,7 +1,8 @@ -import type { - DnsPrefetchOption, - HtmlBasicTag, - PreconnectOption, +import { + type DnsPrefetchOption, + type HtmlBasicTag, + type PreconnectOption, + isHtmlDisabled, } from '@rsbuild/shared'; import type { RsbuildPlugin } from '../types'; @@ -44,39 +45,33 @@ export const pluginResourceHints = (): RsbuildPlugin => ({ return { headTags, bodyTags }; }); - api.modifyBundlerChain( - async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker }) => { - const config = api.getNormalizedConfig(); - const { - performance: { preload, prefetch }, - } = config; + api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => { + const config = api.getNormalizedConfig(); + const { + performance: { preload, prefetch }, + } = config; - if (isServer || isWebWorker || isServiceWorker) { - return; - } + if (isHtmlDisabled(config, target)) { + return; + } - const HTMLCount = chain.entryPoints.values().length; + const HTMLCount = chain.entryPoints.values().length; - const { HtmlPreloadOrPrefetchPlugin } = await import( - '../rspack/preload/HtmlPreloadOrPrefetchPlugin' - ); + const { HtmlPreloadOrPrefetchPlugin } = await import( + '../rspack/preload/HtmlPreloadOrPrefetchPlugin' + ); - if (prefetch) { - chain - .plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH) - .use(HtmlPreloadOrPrefetchPlugin, [ - prefetch, - 'prefetch', - HTMLCount, - ]); - } + if (prefetch) { + chain + .plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH) + .use(HtmlPreloadOrPrefetchPlugin, [prefetch, 'prefetch', HTMLCount]); + } - if (preload) { - chain - .plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD) - .use(HtmlPreloadOrPrefetchPlugin, [preload, 'preload', HTMLCount]); - } - }, - ); + if (preload) { + chain + .plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD) + .use(HtmlPreloadOrPrefetchPlugin, [preload, 'preload', HTMLCount]); + } + }); }, }); diff --git a/packages/core/src/provider/plugins/rspackProfile.ts b/packages/core/src/plugins/rspackProfile.ts similarity index 98% rename from packages/core/src/provider/plugins/rspackProfile.ts rename to packages/core/src/plugins/rspackProfile.ts index 81ed008009..236e72ada5 100644 --- a/packages/core/src/provider/plugins/rspackProfile.ts +++ b/packages/core/src/plugins/rspackProfile.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fse } from '@rsbuild/shared'; import { logger } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; -import type { RsbuildPlugin } from '../../types'; +import type { RsbuildPlugin } from '../types'; export const stopProfiler = ( output: string, diff --git a/packages/core/src/plugins/sass.ts b/packages/core/src/plugins/sass.ts new file mode 100644 index 0000000000..fbaeed8e00 --- /dev/null +++ b/packages/core/src/plugins/sass.ts @@ -0,0 +1,184 @@ +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; +import { + type CompilerTapFn, + type FileFilterUtil, + type SassLoaderOptions, + type ToolsSassConfig, + castArray, + deepmerge, + getSharedPkgCompiledPath, + mergeChainedOptions, +} from '@rsbuild/shared'; +import { getCompiledPath } from '../helpers'; +import type { RsbuildPlugin } from '../types'; + +const GLOBAL_PATCHED_SYMBOL: unique symbol = Symbol('GLOBAL_PATCHED_SYMBOL'); + +declare global { + interface Location { + [GLOBAL_PATCHED_SYMBOL]?: true; + } +} + +/** fix issue about dart2js: https://github.com/dart-lang/sdk/issues/27979 */ +function patchGlobalLocation() { + if (!global.location) { + const href = pathToFileURL(process.cwd()).href + path.sep; + const location = Object.freeze({ [GLOBAL_PATCHED_SYMBOL]: true, href }); + global.location = location as unknown as Location; + } +} + +function unpatchGlobalLocation() { + if (global.location?.[GLOBAL_PATCHED_SYMBOL]) { + // @ts-expect-error + delete global.location; + } +} + +export function patchCompilerGlobalLocation(compiler: { + hooks: { + run: CompilerTapFn; + watchRun: CompilerTapFn; + watchClose: CompilerTapFn; + done: CompilerTapFn; + }; +}) { + // https://github.com/webpack/webpack/blob/136b723023f8f26d71eabdd16badf04c1c8554e4/lib/MultiCompiler.js#L64 + compiler.hooks.run.tap('PatchGlobalLocation', patchGlobalLocation); + compiler.hooks.watchRun.tap('PatchGlobalLocation', patchGlobalLocation); + compiler.hooks.watchClose.tap('PatchGlobalLocation', unpatchGlobalLocation); + compiler.hooks.done.tap('PatchGlobalLocation', unpatchGlobalLocation); +} + +const getSassLoaderOptions = ( + rsbuildSassConfig: ToolsSassConfig | undefined, + isUseCssSourceMap: boolean, +): { + options: SassLoaderOptions; + excludes: (RegExp | string)[]; +} => { + const excludes: (RegExp | string)[] = []; + + const addExcludes: FileFilterUtil = (items) => { + excludes.push(...castArray(items)); + }; + + const mergeFn = ( + defaults: SassLoaderOptions, + userOptions: SassLoaderOptions, + ) => { + const getSassOptions = () => { + if (defaults.sassOptions && userOptions.sassOptions) { + return deepmerge( + defaults.sassOptions, + userOptions.sassOptions, + ); + } + return userOptions.sassOptions || defaults.sassOptions; + }; + + return { + ...defaults, + ...userOptions, + sassOptions: getSassOptions(), + }; + }; + + const mergedOptions = mergeChainedOptions({ + defaults: { + sourceMap: isUseCssSourceMap, + implementation: getSharedPkgCompiledPath('sass'), + }, + options: rsbuildSassConfig, + utils: { addExcludes }, + mergeFn, + }); + + return { + options: mergedOptions, + excludes, + }; +}; + +/** + * fix resolve-url-loader can't deal with resolve.alias config + * + * reference: https://github.com/bholloway/resolve-url-loader/blob/e2695cde68f325f617825e168173df92236efb93/packages/resolve-url-loader/docs/advanced-features.md + */ +const getResolveUrlJoinFn = async () => { + const { + createJoinFunction, + asGenerator, + createJoinImplementation, + defaultJoinGenerator, + } = await import('../../compiled/resolve-url-loader/index.js'); + + const rsbuildGenerator = asGenerator((item: any, ...rest: any[]) => { + // only handle relative path (not absolutely accurate, but can meet common scenarios) + if (!item.uri.startsWith('.')) { + return [null]; + } + return defaultJoinGenerator(item, ...rest); + }); + return createJoinFunction( + 'rsbuild-resolve-join-fn', + createJoinImplementation(rsbuildGenerator), + ); +}; + +export function pluginSass(): RsbuildPlugin { + return { + name: 'rsbuild:sass', + setup(api) { + api.onAfterCreateCompiler(({ compiler }) => { + patchCompilerGlobalLocation(compiler); + }); + + api.modifyBundlerChain(async (chain, utils) => { + const config = api.getNormalizedConfig(); + const { applyCSSRule } = await import('./css'); + + const { excludes, options } = getSassLoaderOptions( + config.tools.sass, + // source-maps required for loaders preceding resolve-url-loader + // otherwise the resolve-url-loader will throw an error + true, + ); + + const rule = chain.module + .rule(utils.CHAIN_ID.RULE.SASS) + .test(/\.s(?:a|c)ss$/); + + for (const item of excludes) { + rule.exclude.add(item); + } + + await applyCSSRule({ + rule, + utils, + config, + context: api.context, + // postcss-loader, resolve-url-loader, sass-loader + importLoaders: 3, + }); + + rule + .use(utils.CHAIN_ID.USE.RESOLVE_URL) + .loader(getCompiledPath('resolve-url-loader')) + .options({ + join: await getResolveUrlJoinFn(), + // 'resolve-url-loader' relies on 'adjust-sourcemap-loader', + // it has performance regression issues in some scenarios, + // so we need to disable the sourceMap option. + sourceMap: false, + }) + .end() + .use(utils.CHAIN_ID.USE.SASS) + .loader(getSharedPkgCompiledPath('sass-loader')) + .options(options); + }); + }, + }; +} diff --git a/packages/core/src/plugins/splitChunks.ts b/packages/core/src/plugins/splitChunks.ts index 95487fedce..9c33d47e79 100644 --- a/packages/core/src/plugins/splitChunks.ts +++ b/packages/core/src/plugins/splitChunks.ts @@ -137,7 +137,7 @@ function splitByModule(ctx: SplitChunksContext): SplitChunks { ...userDefinedCacheGroups, // Core group vendors: { - priority: -10, + priority: -9, test: NODE_MODULES_REGEX, name(module) { return module diff --git a/packages/core/src/plugins/startUrl.ts b/packages/core/src/plugins/startUrl.ts index 340dc2784a..fdd4f6b48c 100644 --- a/packages/core/src/plugins/startUrl.ts +++ b/packages/core/src/plugins/startUrl.ts @@ -1,7 +1,7 @@ import { exec } from 'node:child_process'; -import { join } from 'node:path'; import { promisify } from 'node:util'; import { type Routes, castArray, debug, logger } from '@rsbuild/shared'; +import { STATIC_PATH } from '../constants'; import type { RsbuildPlugin } from '../types'; const execAsync = promisify(exec); @@ -53,7 +53,7 @@ export async function openBrowser(url: string): Promise { url, )}" "${targetBrowser}"`, { - cwd: join(__dirname, '../../static'), + cwd: STATIC_PATH, }, ); @@ -69,7 +69,7 @@ export async function openBrowser(url: string): Promise { // Fallback to open // (It will always open new tab) try { - const { default: open } = await import('../../compiled/open'); + const { default: open } = await import('../../compiled/open/index.js'); await open(url); return true; } catch (err) { diff --git a/packages/core/src/provider/plugins/swc.ts b/packages/core/src/plugins/swc.ts similarity index 97% rename from packages/core/src/provider/plugins/swc.ts rename to packages/core/src/plugins/swc.ts index 139c0f80f9..bfbfcc4e92 100644 --- a/packages/core/src/provider/plugins/swc.ts +++ b/packages/core/src/plugins/swc.ts @@ -13,16 +13,16 @@ import { mergeChainedOptions, } from '@rsbuild/shared'; import type { SwcLoaderOptions } from '@rspack/core'; -import { PLUGIN_SWC_NAME } from '../../constants'; +import { PLUGIN_SWC_NAME } from '../constants'; import type { NormalizedConfig, NormalizedSourceConfig, RsbuildPlugin, -} from '../../types'; +} from '../types'; const builtinSwcLoaderName = 'builtin:swc-loader'; -export async function getDefaultSwcConfig( +async function getDefaultSwcConfig( config: NormalizedConfig, rootPath: string, target: RsbuildTarget, @@ -31,7 +31,7 @@ export async function getDefaultSwcConfig( jsc: { externalHelpers: true, parser: { - tsx: true, + tsx: false, syntax: 'typescript', decorators: true, }, diff --git a/packages/core/src/provider/build.ts b/packages/core/src/provider/build.ts index 98044868ce..3d18a5b80a 100644 --- a/packages/core/src/provider/build.ts +++ b/packages/core/src/provider/build.ts @@ -2,9 +2,8 @@ import { getNodeEnv, logger, onCompileDone, setNodeEnv } from '@rsbuild/shared'; import type { BuildOptions, MultiStats, - RspackCompiler, + Rspack, RspackConfig, - RspackMultiCompiler, Stats, } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; @@ -21,7 +20,7 @@ export const build = async ( const { context } = initOptions; - let compiler: RspackCompiler | RspackMultiCompiler; + let compiler: Rspack.Compiler | Rspack.MultiCompiler; let bundlerConfigs: RspackConfig[] | undefined; if (customCompiler) { diff --git a/packages/core/src/provider/createCompiler.ts b/packages/core/src/provider/createCompiler.ts index f13b1f05fa..0cbcd1bcc3 100644 --- a/packages/core/src/provider/createCompiler.ts +++ b/packages/core/src/provider/createCompiler.ts @@ -1,9 +1,7 @@ import { - type CreateDevMiddlewareReturns, type MultiStats, - type RspackCompiler, + type Rspack, type RspackConfig, - type RspackMultiCompiler, type Stats, TARGET_ID_MAP, color, @@ -16,14 +14,15 @@ import { } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; import type { StatsCompilation } from '@rspack/core'; -import type { InternalContext } from '../types'; -import { type InitConfigsOptions, initConfigs } from './initConfigs'; import { formatStats, getStatsOptions, isSatisfyRspackVersion, rspackMinVersion, -} from './shared'; +} from '../helpers'; +import type { DevMiddlewareAPI } from '../server/devMiddleware'; +import type { DevConfig, InternalContext } from '../types'; +import { type InitConfigsOptions, initConfigs } from './initConfigs'; export async function createCompiler({ context, @@ -31,7 +30,7 @@ export async function createCompiler({ }: { context: InternalContext; rspackConfigs: RspackConfig[]; -}): Promise { +}): Promise { debug('create compiler'); await context.hooks.onBeforeCreateCompiler.call({ bundlerConfigs: rspackConfigs, @@ -131,11 +130,44 @@ export async function createCompiler({ return compiler; } +export type MiddlewareCallbacks = { + onInvalid: () => void; + onDone: (stats: any) => void; +}; + +export type DevMiddlewareOptions = { + /** To ensure HMR works, the devMiddleware need inject the hmr client path into page when HMR enable. */ + clientPaths?: string[]; + clientConfig: DevConfig['client']; + publicPath?: string; + + /** When liveReload is disabled, the page does not reload. */ + liveReload?: boolean; + + etag?: 'weak' | 'strong'; + + /** The options need by compiler middleware (like webpackMiddleware) */ + headers?: Record; + writeToDisk?: boolean | ((filename: string) => boolean); + stats?: boolean; + + /** should trigger when compiler hook called */ + callbacks: MiddlewareCallbacks; + + /** whether use Server Side Render */ + serverSideRender?: boolean; +}; + +export type CreateDevMiddlewareReturns = { + devMiddleware: (options: DevMiddlewareOptions) => DevMiddlewareAPI; + compiler: Rspack.Compiler | Rspack.MultiCompiler; +}; + export async function createDevMiddleware( options: InitConfigsOptions, - customCompiler?: RspackCompiler | RspackMultiCompiler, + customCompiler?: Rspack.Compiler | Rspack.MultiCompiler, ): Promise { - let compiler: RspackCompiler | RspackMultiCompiler; + let compiler: Rspack.Compiler | Rspack.MultiCompiler; if (customCompiler) { compiler = customCompiler; } else { @@ -148,7 +180,7 @@ export async function createDevMiddleware( const { getDevMiddleware } = await import('../server/devMiddleware'); return { - devMiddleware: getDevMiddleware(compiler), + devMiddleware: await getDevMiddleware(compiler), compiler, }; } diff --git a/packages/core/src/provider/css-modules-typescript-pre-loader/index.ts b/packages/core/src/provider/css-modules-typescript-pre-loader/index.ts deleted file mode 100644 index f7ca019cf5..0000000000 --- a/packages/core/src/provider/css-modules-typescript-pre-loader/index.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { - type CssModules, - isCssModules, - isInNodeModules, -} from '@rsbuild/shared'; -import type { CssModuleLocalsConvention } from '@rsbuild/shared'; -import cssModulesTypescriptLoader from '@rsbuild/shared/css-modules-typescript-loader'; -import type { LoaderContext } from '@rspack/core'; -import type { PostcssParsePluginOptions } from './postcssIcssExtractPlugin'; - -async function processCss( - inputSource: string, - { - exportLocalsConvention, - }: { - exportLocalsConvention: CssModuleLocalsConvention; - }, -) { - const { default: postcss } = await import('postcss'); - - const { default: localByDefault } = await import( - '@rsbuild/shared/postcss-modules-local-by-default' - ); - - const { default: modulesScope } = await import( - '@rsbuild/shared/postcss-modules-scope' - ); - - const { default: postcssICSSExtractPlugin } = await import( - './postcssIcssExtractPlugin' - ); - - const { default: extractImports } = await import( - '@rsbuild/shared/postcss-modules-extract-imports' - ); - - const { default: modulesValues } = await import( - '@rsbuild/shared/postcss-modules-values' - ); - - const parserOptions = { - exportLocalsConvention, - } as PostcssParsePluginOptions; - - // https://github.com/webpack-contrib/css-loader/blob/4673caa4aa68d5fb1127c172b4afd081bd56eb73/src/utils.js#L776 - const pipeline = postcss([ - localByDefault({ - mode: 'local', - }), - extractImports(), - modulesValues, - modulesScope({ - // scopedName is not important in this scenario - generateScopedName: (exportName: string) => exportName, - exportGlobals: false, - }), - postcssICSSExtractPlugin(parserOptions), - ]); - - await pipeline.process(inputSource, { - from: '/fake-css-modules-loader', - to: undefined, - }); - - return { - cssModuleKeys: parserOptions.cssModuleKeys, - }; -} - -export default async function ( - this: LoaderContext<{ - modules: Required; - mode: string; - }>, - content: string, - ...input: any[] -) { - if (this.cacheable) { - this.cacheable(); - } - - const filename = this.resourcePath; - const { modules } = this.getOptions() || {}; - const callback = this.async(); - - // filter files - if (!isCssModules(filename, modules) || isInNodeModules(filename)) { - return callback(null, content, ...input); - } - - // handle css modules like css-loader, but only get cssModuleKeys not modify the source. - const { cssModuleKeys } = await processCss(content, { - exportLocalsConvention: modules.exportLocalsConvention, - }); - - // @ts-expect-error - this.cssModuleKeys = cssModuleKeys; - - return cssModulesTypescriptLoader.call(this, content, ...input); -} diff --git a/packages/core/src/provider/css-modules-typescript-pre-loader/postcssIcssExtractPlugin.ts b/packages/core/src/provider/css-modules-typescript-pre-loader/postcssIcssExtractPlugin.ts deleted file mode 100644 index c917fdd647..0000000000 --- a/packages/core/src/provider/css-modules-typescript-pre-loader/postcssIcssExtractPlugin.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { type CssModuleLocalsConvention, camelCase } from '@rsbuild/shared'; -// @ts-expect-error -import { extractICSS } from '@rsbuild/shared/icss-utils'; - -import type { AcceptedPlugin as PostCSSPlugin } from 'postcss'; - -const dashesCamelCase = (str: string) => - str.replace(/-+(\w)/g, (_match, firstLetter) => firstLetter.toUpperCase()); - -export type PostcssParsePluginOptions = { - exportLocalsConvention: CssModuleLocalsConvention; - cssModuleKeys: string[]; -}; - -const getExportLocalsConvention = ( - name: string, - exportLocalsConventionType: CssModuleLocalsConvention, -) => { - switch (exportLocalsConventionType) { - case 'camelCase': { - const camelName = camelCase(name); - return camelName === name ? [name] : [name, camelCase(name)]; - } - case 'camelCaseOnly': { - return [camelCase(name)]; - } - case 'dashes': { - const dashesCamelName = dashesCamelCase(name); - return dashesCamelName === name ? [name] : [name, dashesCamelCase(name)]; - } - case 'dashesOnly': { - return [dashesCamelCase(name)]; - } - default: - return [name]; - } -}; - -const plugin = (options: PostcssParsePluginOptions): PostCSSPlugin => { - return { - postcssPlugin: 'postcss-icss-extract', - OnceExit(root) { - const { icssExports } = extractICSS(root); - - const cssModuleKeys = Object.keys(icssExports).reduce( - (total, key) => { - total.push( - ...getExportLocalsConvention(key, options.exportLocalsConvention), - ); - return total; - }, - [], - ); - - options.cssModuleKeys = cssModuleKeys; - }, - }; -}; - -plugin.postcss = true; - -export default plugin; diff --git a/packages/core/src/provider/inspectConfig.ts b/packages/core/src/provider/inspectConfig.ts index 248642a29a..44c1d620b7 100644 --- a/packages/core/src/provider/inspectConfig.ts +++ b/packages/core/src/provider/inspectConfig.ts @@ -41,7 +41,7 @@ export async function inspectConfig({ pluginNames: string[]; } = { ...context.normalizedConfig!, - pluginNames: pluginManager.plugins.map((p) => p.name), + pluginNames: pluginManager.getPlugins().map((p) => p.name), }; const rawRsbuildConfig = await stringifyConfig( diff --git a/packages/core/src/provider/plugins/css.ts b/packages/core/src/provider/plugins/css.ts deleted file mode 100644 index 261c2cfff7..0000000000 --- a/packages/core/src/provider/plugins/css.ts +++ /dev/null @@ -1,265 +0,0 @@ -import path from 'node:path'; -import { - type BundlerChain, - CSS_MODULES_REGEX, - CSS_REGEX, - type ModifyBundlerChainUtils, - type RsbuildContext, - type RspackRule, - type RuleSetRule, - getBrowserslistWithDefault, - getCssLoaderOptions, - getCssModuleLocalIdentName, - getPostcssLoaderOptions, - getSharedPkgCompiledPath, - isUseCssExtract, - kebabCase, - logger, - mergeChainedOptions, - resolvePackage, -} from '@rsbuild/shared'; -import type { NormalizedConfig, RsbuildPlugin } from '../../types'; - -export const enableNativeCss = (config: NormalizedConfig) => - !config.output.injectStyles; - -export async function applyBaseCSSRule({ - rule, - config, - context, - utils: { target, isProd, isServer, isWebWorker, CHAIN_ID }, - importLoaders = 1, -}: { - rule: ReturnType; - config: NormalizedConfig; - context: RsbuildContext; - utils: ModifyBundlerChainUtils; - importLoaders?: number; -}) { - // 1. Check user config - const enableCSSModuleTS = Boolean(config.output.enableCssModuleTSDeclaration); - - const browserslist = await getBrowserslistWithDefault( - context.rootPath, - config, - target, - ); - - // when disableExtractCSS, use css-loader + style-loader - if (!enableNativeCss(config)) { - const localIdentName = getCssModuleLocalIdentName(config, isProd); - - const cssLoaderOptions = getCssLoaderOptions({ - config, - importLoaders, - isServer, - isWebWorker, - localIdentName, - }); - - if (!isServer && !isWebWorker) { - const styleLoaderOptions = mergeChainedOptions({ - defaults: {}, - options: config.tools.styleLoader, - }); - - rule - .use(CHAIN_ID.USE.STYLE) - .loader(getSharedPkgCompiledPath('style-loader')) - .options(styleLoaderOptions) - .end(); - - // use css-modules-typescript-loader - if (enableCSSModuleTS && cssLoaderOptions.modules) { - rule - .use(CHAIN_ID.USE.CSS_MODULES_TS) - .loader( - resolvePackage( - '@rsbuild/shared/css-modules-typescript-loader', - __dirname, - ), - ) - .options({ - modules: cssLoaderOptions.modules, - }) - .end(); - } - } else { - rule - .use(CHAIN_ID.USE.IGNORE_CSS) - .loader(resolvePackage('@rsbuild/shared/ignore-css-loader', __dirname)) - .end(); - } - - rule - .use(CHAIN_ID.USE.CSS) - .loader(getSharedPkgCompiledPath('css-loader')) - .options(cssLoaderOptions) - .end(); - } else { - // can not get experiment.css result, so we fake a css-modules-typescript-pre-loader - if (!isServer && !isWebWorker && enableCSSModuleTS) { - const { cssModules } = config.output; - rule - .use(CHAIN_ID.USE.CSS_MODULES_TS) - .loader(path.resolve(__dirname, '../css-modules-typescript-pre-loader')) - .options({ - modules: { - exportLocalsConvention: cssModules.exportLocalsConvention, - auto: cssModules.auto, - }, - }) - .end(); - } - - rule.type('css'); - } - - if (!isServer && !isWebWorker) { - const postcssLoaderOptions = await getPostcssLoaderOptions({ - browserslist, - config, - root: context.rootPath, - }); - - rule - .use(CHAIN_ID.USE.POSTCSS) - .loader(getSharedPkgCompiledPath('postcss-loader')) - .options(postcssLoaderOptions) - .end(); - } - - // CSS imports should always be treated as sideEffects - rule.merge({ sideEffects: true }); - - // Enable preferRelative by default, which is consistent with the default behavior of css-loader - // see: https://github.com/webpack-contrib/css-loader/blob/579fc13/src/plugins/postcss-import-parser.js#L234 - rule.resolve.preferRelative(true); -} - -/** - * Use type: "css/module" rule instead of css-loader modules.auto config - * - * applyCSSModuleRule in modifyRspackConfig, so that other plugins can easily adjust css rule in Chain. - */ -export const applyCSSModuleRule = ( - rules: RspackRule[] | undefined, - ruleTest: RegExp, - config: NormalizedConfig, -) => { - if (!rules || !enableNativeCss(config)) { - return; - } - - const ruleIndex = rules.findIndex( - (r) => r && r !== '...' && r.test === ruleTest, - ); - - if (ruleIndex === -1) { - return; - } - - const cssModulesAuto = config.output.cssModules.auto; - - if (!cssModulesAuto) { - return; - } - - const rule = rules[ruleIndex] as RuleSetRule; - - const { test, type, ...rest } = rule; - - rules[ruleIndex] = { - test: ruleTest, - oneOf: [ - { - ...rest, - test: - typeof cssModulesAuto !== 'boolean' - ? cssModulesAuto - : // auto: true - CSS_MODULES_REGEX, - type: 'css/module', - }, - { - ...rest, - type: 'css', - }, - ], - }; -}; - -export const pluginCss = (): RsbuildPlugin => { - return { - name: 'rsbuild:css', - setup(api) { - api.modifyBundlerChain(async (chain, utils) => { - const config = api.getNormalizedConfig(); - - const rule = chain.module.rule(utils.CHAIN_ID.RULE.CSS); - rule.test(CSS_REGEX); - - await applyBaseCSSRule({ - rule, - utils, - config, - context: api.context, - }); - - const enableExtractCSS = isUseCssExtract(config, utils.target); - - // TODO: there is no switch to turn off experiments.css sourcemap in rspack, so we manually remove css sourcemap in Rsbuild - if (!config.output.sourceMap.css && enableExtractCSS) { - const { RemoveCssSourcemapPlugin } = await import( - '../../rspack/RemoveCssSourcemapPlugin' - ); - chain - .plugin('remove-css-sourcemap') - .use(RemoveCssSourcemapPlugin, []); - } - }); - api.modifyRspackConfig( - async (rspackConfig, { isProd, isServer, isWebWorker }) => { - const config = api.getNormalizedConfig(); - - if (!enableNativeCss(config)) { - rspackConfig.experiments ||= {}; - rspackConfig.experiments.css = false; - return; - } - - let localIdentName = - config.output.cssModules.localIdentName || - // Using shorter classname in production to reduce bundle size - (isProd ? '[local]-[hash:6]' : '[path][name]__[local]-[hash:6]'); - - if (localIdentName.includes(':base64')) { - logger.warn( - `Custom hashDigest in output.cssModules.localIdentName is currently not supported when using Rspack, the 'base64' will be ignored.`, - ); - localIdentName = localIdentName.replace(':base64', ''); - } - - // need use "css/module" generator instead of modules.auto config - rspackConfig.module ||= {}; - rspackConfig.module.generator ||= {}; - rspackConfig.module.generator['css/module'] = { - exportsConvention: kebabCase( - config.output.cssModules.exportLocalsConvention, - ), - localIdentName, - exportsOnly: isServer || isWebWorker, - }; - rspackConfig.module.parser ||= {}; - rspackConfig.module.parser['css/module'] = { - namedExports: false, - }; - - const rules = rspackConfig.module?.rules; - - applyCSSModuleRule(rules, CSS_REGEX, config); - }, - ); - }, - }; -}; diff --git a/packages/core/src/provider/plugins/less.ts b/packages/core/src/provider/plugins/less.ts deleted file mode 100644 index 0c6fcd32a3..0000000000 --- a/packages/core/src/provider/plugins/less.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - LESS_REGEX, - getLessLoaderOptions, - getSharedPkgCompiledPath, -} from '@rsbuild/shared'; -import type { RsbuildPlugin } from '../../types'; - -export function pluginLess(): RsbuildPlugin { - return { - name: 'rsbuild:less', - setup(api) { - api.modifyBundlerChain(async (chain, utils) => { - const config = api.getNormalizedConfig(); - const { applyBaseCSSRule } = await import('./css'); - - const rule = chain.module - .rule(utils.CHAIN_ID.RULE.LESS) - .test(LESS_REGEX); - - const { excludes, options } = getLessLoaderOptions( - config.tools.less, - config.output.sourceMap.css, - api.context.rootPath, - ); - - for (const item of excludes) { - rule.exclude.add(item); - } - - await applyBaseCSSRule({ - rule, - utils, - config, - context: api.context, - importLoaders: 2, - }); - - rule - .use(utils.CHAIN_ID.USE.LESS) - .loader(getSharedPkgCompiledPath('less-loader')) - .options(options); - }); - - api.modifyRspackConfig(async (rspackConfig) => { - const { applyCSSModuleRule } = await import('./css'); - const config = api.getNormalizedConfig(); - - const rules = rspackConfig.module?.rules; - - applyCSSModuleRule(rules, LESS_REGEX, config); - }); - }, - }; -} diff --git a/packages/core/src/provider/plugins/minimize.ts b/packages/core/src/provider/plugins/minimize.ts deleted file mode 100644 index 2b876e2888..0000000000 --- a/packages/core/src/provider/plugins/minimize.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - CHAIN_ID, - getSwcMinimizerOptions, - parseMinifyOptions, -} from '@rsbuild/shared'; -import { rspack } from '@rspack/core'; -import type { RsbuildPlugin } from '../../types'; - -export const pluginMinimize = (): RsbuildPlugin => ({ - name: 'rsbuild:minimize', - - setup(api) { - api.modifyBundlerChain(async (chain, { isProd }) => { - const config = api.getNormalizedConfig(); - const isMinimize = isProd && config.output.minify !== false; - - if (!isMinimize) { - return; - } - - const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } = - rspack; - - const { minifyJs, minifyCss } = parseMinifyOptions(config); - - if (minifyJs) { - chain.optimization - .minimizer(CHAIN_ID.MINIMIZER.JS) - .use(SwcJsMinimizerRspackPlugin, [getSwcMinimizerOptions(config)]) - .end(); - } - - if (minifyCss) { - chain.optimization - .minimizer(CHAIN_ID.MINIMIZER.CSS) - .use(SwcCssMinimizerRspackPlugin, []) - .end(); - } - }); - }, -}); diff --git a/packages/core/src/provider/plugins/output.ts b/packages/core/src/provider/plugins/output.ts deleted file mode 100644 index 1523c75453..0000000000 --- a/packages/core/src/provider/plugins/output.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { posix } from 'node:path'; -import { applyOutputPlugin, getDistPath, getFilename } from '@rsbuild/shared'; -import { rspack } from '@rspack/core'; -import type { RsbuildPlugin } from '../../types'; - -export const pluginOutput = (): RsbuildPlugin => ({ - name: 'rsbuild:output', - - setup(api) { - applyOutputPlugin(api); - - api.modifyBundlerChain(async (chain, { CHAIN_ID }) => { - const config = api.getNormalizedConfig(); - - if (config.output.copy) { - const { copy } = config.output; - const options = Array.isArray(copy) ? { patterns: copy } : copy; - - chain - .plugin(CHAIN_ID.PLUGIN.COPY) - .use(rspack.CopyRspackPlugin, [options]); - } - }); - - api.modifyRspackConfig(async (rspackConfig, { isProd }) => { - const config = api.getNormalizedConfig(); - const cssPath = getDistPath(config, 'css'); - const cssAsyncPath = getDistPath(config, 'cssAsync'); - const cssFilename = getFilename(config, 'css', isProd); - - rspackConfig.output ||= {}; - rspackConfig.output.cssFilename = posix.join(cssPath, cssFilename); - rspackConfig.output.cssChunkFilename = posix.join( - cssAsyncPath, - cssFilename, - ); - }); - }, -}); diff --git a/packages/core/src/provider/plugins/resolve.ts b/packages/core/src/provider/plugins/resolve.ts deleted file mode 100644 index a50960ce24..0000000000 --- a/packages/core/src/provider/plugins/resolve.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { applyResolvePlugin } from '@rsbuild/shared'; -import type { RsbuildPlugin } from '../../types'; - -export const pluginResolve = (): RsbuildPlugin => ({ - name: 'rsbuild:resolve', - - setup(api) { - applyResolvePlugin(api); - - api.modifyRspackConfig(async (rspackConfig) => { - const isTsProject = Boolean(api.context.tsconfigPath); - const config = api.getNormalizedConfig(); - - rspackConfig.resolve ||= {}; - - if (isTsProject && config.source.aliasStrategy === 'prefer-tsconfig') { - rspackConfig.resolve.tsConfigPath = api.context.tsconfigPath; - } - }); - }, -}); diff --git a/packages/core/src/provider/plugins/sass.ts b/packages/core/src/provider/plugins/sass.ts deleted file mode 100644 index 3b12627631..0000000000 --- a/packages/core/src/provider/plugins/sass.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { - SASS_REGEX, - getResolveUrlJoinFn, - getSassLoaderOptions, - getSharedPkgCompiledPath, - patchCompilerGlobalLocation, -} from '@rsbuild/shared'; -import type { RsbuildPlugin } from '../../types'; - -export function pluginSass(): RsbuildPlugin { - return { - name: 'rsbuild:sass', - setup(api) { - api.onAfterCreateCompiler(({ compiler }) => { - patchCompilerGlobalLocation(compiler); - }); - - api.modifyBundlerChain(async (chain, utils) => { - const config = api.getNormalizedConfig(); - const { applyBaseCSSRule } = await import('./css'); - - const { excludes, options } = getSassLoaderOptions( - config.tools.sass, - // source-maps required for loaders preceding resolve-url-loader - // otherwise the resolve-url-loader will throw an error - true, - ); - - const rule = chain.module - .rule(utils.CHAIN_ID.RULE.SASS) - .test(SASS_REGEX); - - for (const item of excludes) { - rule.exclude.add(item); - } - - await applyBaseCSSRule({ - rule, - utils, - config, - context: api.context, - // postcss-loader, resolve-url-loader, sass-loader - importLoaders: 3, - }); - - rule - .use(utils.CHAIN_ID.USE.RESOLVE_URL) - .loader(getSharedPkgCompiledPath('resolve-url-loader')) - .options({ - join: await getResolveUrlJoinFn(), - // 'resolve-url-loader' relies on 'adjust-sourcemap-loader', - // it has performance regression issues in some scenarios, - // so we need to disable the sourceMap option. - sourceMap: false, - }) - .end() - .use(utils.CHAIN_ID.USE.SASS) - .loader(getSharedPkgCompiledPath('sass-loader')) - .options(options); - }); - - api.modifyRspackConfig(async (rspackConfig) => { - const { applyCSSModuleRule } = await import('./css'); - const config = api.getNormalizedConfig(); - - const rules = rspackConfig.module?.rules; - - applyCSSModuleRule(rules, SASS_REGEX, config); - }); - }, - }; -} diff --git a/packages/core/src/provider/plugins/transition.ts b/packages/core/src/provider/plugins/transition.ts deleted file mode 100644 index bfa3e124a9..0000000000 --- a/packages/core/src/provider/plugins/transition.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { RsbuildPlugin } from '../../types'; - -/** - * Provide some temporary configurations for Rspack early transition - */ -export const pluginTransition = (): RsbuildPlugin => ({ - name: 'rsbuild:transition', - - setup() { - process.env.RSPACK_CONFIG_VALIDATE = 'loose-silent'; - - // improve kill process performance - // https://github.com/web-infra-dev/rspack/pull/5486 - process.env.WATCHPACK_WATCHER_LIMIT ||= '20'; - }, -}); diff --git a/packages/core/src/provider/provider.ts b/packages/core/src/provider/provider.ts index e16faac6d4..7272a0809f 100644 --- a/packages/core/src/provider/provider.ts +++ b/packages/core/src/provider/provider.ts @@ -45,13 +45,12 @@ export const rspackProvider: RsbuildProvider = async ({ async applyDefaultPlugins() { const allPlugins = await Promise.all([ - import('./plugins/transition').then((m) => m.pluginTransition()), plugins.basic(), plugins.entry(), // plugins.cache(), plugins.target(), - import('./plugins/output').then((m) => m.pluginOutput()), - import('./plugins/resolve').then((m) => m.pluginResolve()), + plugins.output(), + plugins.resolve(), plugins.fileSize(), // cleanOutput plugin should before the html plugin plugins.cleanOutput(), @@ -64,12 +63,12 @@ export const rspackProvider: RsbuildProvider = async ({ plugins.moment(), plugins.nodeAddons(), plugins.define(), - import('./plugins/css').then((m) => m.pluginCss()), - import('./plugins/less').then((m) => m.pluginLess()), - import('./plugins/sass').then((m) => m.pluginSass()), - import('./plugins/minimize').then((m) => m.pluginMinimize()), - import('./plugins/progress').then((m) => m.pluginProgress()), - import('./plugins/swc').then((m) => m.pluginSwc()), + plugins.css(), + plugins.less(), + plugins.sass(), + import('../plugins/minimize').then((m) => m.pluginMinimize()), + import('../plugins/progress').then((m) => m.pluginProgress()), + import('../plugins/swc').then((m) => m.pluginSwc()), plugins.externals(), plugins.splitChunks(), plugins.startUrl(), @@ -81,7 +80,7 @@ export const rspackProvider: RsbuildProvider = async ({ plugins.server(), plugins.moduleFederation(), plugins.manifest(), - import('./plugins/rspackProfile').then((m) => m.pluginRspackProfile()), + import('../plugins/rspackProfile').then((m) => m.pluginRspackProfile()), ]); pluginManager.addPlugins(allPlugins); diff --git a/packages/core/src/provider/rspackConfig.ts b/packages/core/src/provider/rspackConfig.ts index 71f4709d6b..70d4d89f00 100644 --- a/packages/core/src/provider/rspackConfig.ts +++ b/packages/core/src/provider/rspackConfig.ts @@ -12,9 +12,8 @@ import { modifyBundlerChain, } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; -import { getHTMLPlugin } from '../htmlUtils'; +import { getHTMLPlugin } from '../pluginHelper'; import type { InternalContext } from '../types'; -import { getCompiledPath } from './shared'; async function modifyRspackConfig( context: InternalContext, @@ -101,7 +100,6 @@ export function getChainUtils(target: RsbuildTarget): ModifyChainUtils { isServer: target === 'node', isWebWorker: target === 'web-worker', isServiceWorker: target === 'service-worker', - getCompiledPath, CHAIN_ID, HtmlPlugin: getHTMLPlugin(), }; diff --git a/packages/core/src/rspack/HtmlAppIconPlugin.ts b/packages/core/src/rspack/HtmlAppIconPlugin.ts index 1c77aff229..67cc781f6c 100644 --- a/packages/core/src/rspack/HtmlAppIconPlugin.ts +++ b/packages/core/src/rspack/HtmlAppIconPlugin.ts @@ -2,7 +2,7 @@ import fs from 'node:fs'; import { basename, posix } from 'node:path'; import { getPublicPathFromCompiler, withPublicPath } from '@rsbuild/shared'; import type { Compilation, Compiler } from '@rspack/core'; -import { getHTMLPlugin } from '../htmlUtils'; +import { getHTMLPlugin } from '../pluginHelper'; type AppIconOptions = { distDir: string; diff --git a/packages/core/src/rspack/HtmlBasicPlugin.ts b/packages/core/src/rspack/HtmlBasicPlugin.ts index bed5e61e1f..cd6acd5689 100644 --- a/packages/core/src/rspack/HtmlBasicPlugin.ts +++ b/packages/core/src/rspack/HtmlBasicPlugin.ts @@ -11,7 +11,7 @@ import { import type { Compilation, Compiler } from '@rspack/core'; import type HtmlWebpackPlugin from 'html-webpack-plugin'; import type { HtmlTagObject } from 'html-webpack-plugin'; -import { getHTMLPlugin } from '../htmlUtils'; +import { getHTMLPlugin } from '../pluginHelper'; export type TagConfig = { tags?: HtmlTagDescriptor[]; diff --git a/packages/core/src/rspack/InlineChunkHtmlPlugin.ts b/packages/core/src/rspack/InlineChunkHtmlPlugin.ts index 3ad9dbd9a5..4c05a66222 100644 --- a/packages/core/src/rspack/InlineChunkHtmlPlugin.ts +++ b/packages/core/src/rspack/InlineChunkHtmlPlugin.ts @@ -14,7 +14,7 @@ import { } from '@rsbuild/shared'; import type { Compilation, Compiler } from '@rspack/core'; import type { HtmlTagObject } from 'html-webpack-plugin'; -import { getHTMLPlugin } from '../htmlUtils'; +import { getHTMLPlugin } from '../pluginHelper'; export type InlineChunkHtmlPluginOptions = { styleTests: InlineChunkTest[]; diff --git a/packages/core/src/rspack/RemoveCssSourcemapPlugin.ts b/packages/core/src/rspack/RemoveCssSourcemapPlugin.ts deleted file mode 100644 index 27c4536b6d..0000000000 --- a/packages/core/src/rspack/RemoveCssSourcemapPlugin.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { Compilation, Compiler } from '@rspack/core'; - -export class RemoveCssSourcemapPlugin { - name: string; - - constructor() { - this.name = 'RemoveCssSourcemapPlugin'; - } - - apply(compiler: Compiler) { - compiler.hooks.compilation.tap(this.name, (compilation: Compilation) => { - compilation.hooks.processAssets.tap( - { - name: this.name, - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE, - }, - () => { - for (const name of Object.keys(compilation.assets)) { - if (name.endsWith('.css.map')) { - compilation.deleteAsset(name); - } - } - }, - ); - }); - } -} diff --git a/packages/core/src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts b/packages/core/src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts index 7c0e9028e7..6d610fcd4a 100644 --- a/packages/core/src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts +++ b/packages/core/src/rspack/preload/HtmlPreloadOrPrefetchPlugin.ts @@ -23,7 +23,7 @@ import { } from '@rsbuild/shared'; import type { Compilation, Compiler, RspackPluginInstance } from '@rspack/core'; import type HtmlWebpackPlugin from 'html-webpack-plugin'; -import { getHTMLPlugin } from '../../htmlUtils'; +import { getHTMLPlugin } from '../../pluginHelper'; import { type As, type BeforeAssetTagGenerationHtmlPluginData, diff --git a/packages/core/src/server/compilerDevMiddleware.ts b/packages/core/src/server/compilerDevMiddleware.ts index 800c21eef4..c1c5333113 100644 --- a/packages/core/src/server/compilerDevMiddleware.ts +++ b/packages/core/src/server/compilerDevMiddleware.ts @@ -1,12 +1,10 @@ import type { IncomingMessage, ServerResponse } from 'node:http'; import type { Socket } from 'node:net'; +import type { DevConfig, NextFunction, ServerConfig } from '@rsbuild/shared'; import type { DevMiddleware as CustomDevMiddleware, - DevConfig, DevMiddlewareAPI, - NextFunction, - ServerConfig, -} from '@rsbuild/shared'; +} from './devMiddleware'; import { SocketServer } from './socketServer'; type Options = { diff --git a/packages/core/src/server/devMiddleware.ts b/packages/core/src/server/devMiddleware.ts index 3319663dac..4cdd935198 100644 --- a/packages/core/src/server/devMiddleware.ts +++ b/packages/core/src/server/devMiddleware.ts @@ -1,12 +1,44 @@ +import type { IncomingMessage, ServerResponse } from 'node:http'; import { + type CompilerTapFn, type DevConfig, - type DevMiddleware, + type NextFunction, applyToCompiler, isClientCompiler, - setupServerHooks, + isNodeCompiler, } from '@rsbuild/shared'; import type { Compiler, MultiCompiler } from '@rspack/core'; -import webpackDevMiddleware from '../../compiled/webpack-dev-middleware'; +import type { DevMiddlewareOptions } from '../provider/createCompiler'; + +type ServerCallbacks = { + onInvalid: () => void; + onDone: (stats: any) => void; +}; + +export const setupServerHooks = ( + compiler: { + options: { + target?: Compiler['options']['target']; + }; + hooks: { + compile: CompilerTapFn; + invalid: CompilerTapFn; + done: CompilerTapFn; + }; + }, + hookCallbacks: ServerCallbacks, +) => { + // TODO: node SSR HMR is not supported yet + if (isNodeCompiler(compiler)) { + return; + } + + const { compile, invalid, done } = compiler.hooks; + + compile.tap('rsbuild-dev-server', hookCallbacks.onInvalid); + invalid.tap('rsbuild-dev-server', hookCallbacks.onInvalid); + done.tap('rsbuild-dev-server', hookCallbacks.onDone); +}; function applyHMREntry({ compiler, @@ -35,9 +67,31 @@ function applyHMREntry({ } } -export const getDevMiddleware = - (multiCompiler: Compiler | MultiCompiler): NonNullable => - (options) => { +export type Middleware = ( + req: IncomingMessage, + res: ServerResponse, + next: NextFunction, +) => Promise; + +export type DevMiddlewareAPI = Middleware & { + close: (callback: (err: Error | null | undefined) => void) => any; +}; + +/** + * The rsbuild/server do nothing about compiler, the devMiddleware need do such things to ensure dev works well: + * - Call compiler.watch (normally did by webpack-dev-middleware). + * - Inject the hmr client path into page (the hmr client rsbuild/server already provide). + * - Notify server when compiler hooks are triggered. + */ +export type DevMiddleware = (options: DevMiddlewareOptions) => DevMiddlewareAPI; + +export const getDevMiddleware = async ( + multiCompiler: Compiler | MultiCompiler, +): Promise> => { + const { default: webpackDevMiddleware } = await import( + '../../compiled/webpack-dev-middleware/index.js' + ); + return (options) => { const { clientPaths, clientConfig, callbacks, liveReload, ...restOptions } = options; @@ -58,3 +112,4 @@ export const getDevMiddleware = return webpackDevMiddleware(multiCompiler, restOptions); }; +}; diff --git a/packages/core/src/server/devServer.ts b/packages/core/src/server/devServer.ts index d1826b1c36..82a47a40f2 100644 --- a/packages/core/src/server/devServer.ts +++ b/packages/core/src/server/devServer.ts @@ -1,25 +1,30 @@ import fs from 'node:fs'; import { - type CreateDevMiddlewareReturns, type CreateDevServerOptions, ROOT_DIST_DIR, type RsbuildDevServer, + type Rspack, type StartDevServerOptions, type StartServerResult, debug, - getAddressUrls, getNodeEnv, getPublicPathFromCompiler, isMultiCompiler, setNodeEnv, } from '@rsbuild/shared'; import connect from '@rsbuild/shared/connect'; +import type { CreateDevMiddlewareReturns } from '../provider/createCompiler'; import type { InternalContext } from '../types'; import { type RsbuildDevMiddlewareOptions, getMiddlewares, } from './getDevMiddlewares'; -import { formatRoutes, getDevOptions, printServerURLs } from './helper'; +import { + formatRoutes, + getAddressUrls, + getDevOptions, + printServerURLs, +} from './helper'; import { createHttpServer } from './httpServer'; import { notFoundMiddleware } from './middlewares'; import { onBeforeRestartServer } from './restart'; @@ -66,7 +71,7 @@ export async function createDevServer< https, }; - let outputFileSystem = fs; + let outputFileSystem: Rspack.OutputFileSystem = fs; const startCompile: () => Promise< RsbuildDevMiddlewareOptions['compileMiddlewareAPI'] @@ -91,9 +96,10 @@ export async function createDevServer< compilerDevMiddleware.init(); - outputFileSystem = isMultiCompiler(compiler) - ? compiler.compilers[0].outputFileSystem - : compiler.outputFileSystem; + outputFileSystem = + (isMultiCompiler(compiler) + ? compiler.compilers[0].outputFileSystem + : compiler.outputFileSystem) || fs; return { middleware: compilerDevMiddleware.middleware, diff --git a/packages/core/src/server/getDevMiddlewares.ts b/packages/core/src/server/getDevMiddlewares.ts index 9932833dc8..2d5a1b05a8 100644 --- a/packages/core/src/server/getDevMiddlewares.ts +++ b/packages/core/src/server/getDevMiddlewares.ts @@ -1,11 +1,9 @@ -import type fs from 'node:fs'; import { isAbsolute, join } from 'node:path'; import url from 'node:url'; import type { - CompileMiddlewareAPI, DevConfig, - Middlewares, RequestHandler, + Rspack, ServerAPIs, ServerConfig, UpgradeEvent, @@ -17,12 +15,19 @@ import { getRequestLoggerMiddleware, } from './middlewares'; +export type CompileMiddlewareAPI = { + middleware: RequestHandler; + sockWrite: ServerAPIs['sockWrite']; + onUpgrade: UpgradeEvent; + close: () => void; +}; + export type RsbuildDevMiddlewareOptions = { pwd: string; dev: DevConfig; server: ServerConfig; compileMiddlewareAPI?: CompileMiddlewareAPI; - outputFileSystem: typeof fs; + outputFileSystem: Rspack.OutputFileSystem; output: { distPath: string; }; @@ -54,6 +59,8 @@ const applySetupMiddlewares = ( return { before, after }; }; +export type Middlewares = Array; + const applyDefaultMiddlewares = async ({ middlewares, server, @@ -70,7 +77,7 @@ const applyDefaultMiddlewares = async ({ // compression should be the first middleware if (server.compress) { const { default: compression } = await import( - '../../compiled/http-compression' + '../../compiled/http-compression/index.js' ); middlewares.push((req, res, next) => { compression({ @@ -112,7 +119,7 @@ const applyDefaultMiddlewares = async ({ } const { default: launchEditorMiddleware } = await import( - '../../compiled/launch-editor-middleware' + '../../compiled/launch-editor-middleware/index.js' ); middlewares.push(['/__open-in-editor', launchEditorMiddleware()]); @@ -136,7 +143,7 @@ const applyDefaultMiddlewares = async ({ } if (server.publicDir !== false && server.publicDir?.name) { - const { default: sirv } = await import('../../compiled/sirv'); + const { default: sirv } = await import('../../compiled/sirv/index.js'); const { name } = server.publicDir; const publicDir = isAbsolute(name) ? name : join(pwd, name); @@ -162,7 +169,7 @@ const applyDefaultMiddlewares = async ({ if (server.historyApiFallback) { const { default: connectHistoryApiFallback } = await import( - '../../compiled/connect-history-api-fallback' + '../../compiled/connect-history-api-fallback/index.js' ); const historyApiFallbackMiddleware = connectHistoryApiFallback( server.historyApiFallback === true ? {} : server.historyApiFallback, diff --git a/packages/core/src/server/helper.ts b/packages/core/src/server/helper.ts index d393555051..fa0359c364 100644 --- a/packages/core/src/server/helper.ts +++ b/packages/core/src/server/helper.ts @@ -1,10 +1,11 @@ import net from 'node:net'; +import { isIPv6 } from 'node:net'; +import os from 'node:os'; import { DEFAULT_DEV_HOST, DEFAULT_PORT, color, deepmerge, - getUrlLabel, isFunction, logger, normalizeUrl, @@ -288,3 +289,115 @@ export const getDevOptions = async ({ liveReload, }; }; + +const getIpv4Interfaces = () => { + const interfaces = os.networkInterfaces(); + const ipv4Interfaces: Map = new Map(); + + for (const key of Object.keys(interfaces)) { + for (const detail of interfaces[key]!) { + // 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6 + const familyV4Value = typeof detail.family === 'string' ? 'IPv4' : 4; + + if ( + detail.family === familyV4Value && + !ipv4Interfaces.has(detail.address) + ) { + ipv4Interfaces.set(detail.address, detail); + } + } + } + + return Array.from(ipv4Interfaces.values()); +}; + +const isLoopbackHost = (host: string) => { + const loopbackHosts = [ + 'localhost', + '127.0.0.1', + '::1', + '0000:0000:0000:0000:0000:0000:0000:0001', + ]; + return loopbackHosts.includes(host); +}; + +const getHostInUrl = (host: string) => { + if (isIPv6(host)) { + return host === '::' ? '[::1]' : `[${host}]`; + } + return host; +}; + +const concatUrl = ({ + host, + port, + protocol, +}: { + host: string; + port: number; + protocol: string; +}) => `${protocol}://${host}:${port}`; + +const LOCAL_LABEL = 'Local: '; +const NETWORK_LABEL = 'Network: '; + +export const getUrlLabel = (url: string) => { + try { + const { host } = new URL(url); + return isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL; + } catch (err) { + return NETWORK_LABEL; + } +}; + +type AddressUrl = { label: string; url: string }; + +export const getAddressUrls = ({ + protocol = 'http', + port, + host, +}: { + protocol?: string; + port: number; + host?: string; +}): AddressUrl[] => { + if (host && host !== DEFAULT_DEV_HOST) { + return [ + { + label: isLoopbackHost(host) ? LOCAL_LABEL : NETWORK_LABEL, + url: concatUrl({ + port, + host: getHostInUrl(host), + protocol, + }), + }, + ]; + } + + const ipv4Interfaces = getIpv4Interfaces(); + const addressUrls: AddressUrl[] = []; + let hasLocalUrl = false; + + for (const detail of ipv4Interfaces) { + if (isLoopbackHost(detail.address) || detail.internal) { + // avoid multiple prints of localhost + // https://github.com/web-infra-dev/rsbuild/discussions/1543 + if (hasLocalUrl) { + continue; + } + + addressUrls.push({ + label: LOCAL_LABEL, + url: concatUrl({ host: 'localhost', port, protocol }), + }); + hasLocalUrl = true; + } else { + addressUrls.push({ + label: NETWORK_LABEL, + url: concatUrl({ host: detail.address, port, protocol }), + }); + } + } + + return addressUrls; +}; diff --git a/packages/core/src/server/middlewares.ts b/packages/core/src/server/middlewares.ts index 9e5bf00a1e..6fba4dffb2 100644 --- a/packages/core/src/server/middlewares.ts +++ b/packages/core/src/server/middlewares.ts @@ -1,9 +1,9 @@ -import type fs from 'node:fs'; import path from 'node:path'; import { parse } from 'node:url'; import { type HtmlFallback, type RequestHandler as Middleware, + type Rspack, color, debug, isDebug, @@ -38,7 +38,9 @@ const getStatusCodeColor = (status: number) => { export const getRequestLoggerMiddleware: () => Promise = async () => { - const { default: onFinished } = await import('../../compiled/on-finished'); + const { default: onFinished } = await import( + '../../compiled/on-finished/index.js' + ); return (req, res, next) => { const _startAt = process.hrtime(); @@ -79,12 +81,12 @@ export const getHtmlFallbackMiddleware: (params: { distPath: string; callback?: Middleware; htmlFallback?: HtmlFallback; - outputFileSystem: typeof fs; + outputFileSystem: Rspack.OutputFileSystem; }) => Middleware = ({ htmlFallback, distPath, callback, outputFileSystem }) => { /** * support access page without suffix and support fallback in some edge cases */ - return (req, res, next) => { + return async (req, res, next) => { if ( // Only accept GET or HEAD (req.method !== 'GET' && req.method !== 'HEAD') || @@ -117,6 +119,14 @@ export const getHtmlFallbackMiddleware: (params: { return next(); } + const isFileExists = async (filePath: string) => { + return new Promise((resolve) => { + outputFileSystem.stat(filePath, (_error, stats) => { + resolve(stats?.isFile()); + }); + }); + }; + const rewrite = (newUrl: string, isFallback = false) => { if (isFallback && isDebug()) { debug( @@ -141,7 +151,7 @@ export const getHtmlFallbackMiddleware: (params: { const newUrl = `${pathname}index.html`; const filePath = path.join(distPath, pathname, 'index.html'); - if (outputFileSystem.existsSync(filePath)) { + if (await isFileExists(filePath)) { return rewrite(newUrl); } } else if ( @@ -151,13 +161,13 @@ export const getHtmlFallbackMiddleware: (params: { const newUrl = `${pathname}.html`; const filePath = path.join(distPath, `${pathname}.html`); - if (outputFileSystem.existsSync(filePath)) { + if (await isFileExists(filePath)) { return rewrite(newUrl); } } if (htmlFallback === 'index') { - if (outputFileSystem.existsSync(path.join(distPath, 'index.html'))) { + if (await isFileExists(path.join(distPath, 'index.html'))) { return rewrite('/index.html', true); } } diff --git a/packages/core/src/server/prodServer.ts b/packages/core/src/server/prodServer.ts index 3a2e42fe5d..4a9a52f621 100644 --- a/packages/core/src/server/prodServer.ts +++ b/packages/core/src/server/prodServer.ts @@ -7,15 +7,19 @@ import { type RsbuildConfig, type ServerConfig, type StartServerResult, - getAddressUrls, getNodeEnv, isDebug, setNodeEnv, } from '@rsbuild/shared'; import connect from '@rsbuild/shared/connect'; -import sirv from '../../compiled/sirv'; +import sirv from '../../compiled/sirv/index.js'; import type { InternalContext } from '../types'; -import { formatRoutes, getServerOptions, printServerURLs } from './helper'; +import { + formatRoutes, + getAddressUrls, + getServerOptions, + printServerURLs, +} from './helper'; import { createHttpServer } from './httpServer'; import { faviconFallbackMiddleware, @@ -58,7 +62,7 @@ export class RsbuildProdServer { // compression should be the first middleware if (compress) { const { default: compression } = await import( - '../../compiled/http-compression' + '../../compiled/http-compression/index.js' ); this.middlewares.use((req, res, next) => { compression({ @@ -92,7 +96,7 @@ export class RsbuildProdServer { if (historyApiFallback) { const { default: connectHistoryApiFallback } = await import( - '../../compiled/connect-history-api-fallback' + '../../compiled/connect-history-api-fallback/index.js' ); const historyApiFallbackMiddleware = connectHistoryApiFallback( historyApiFallback === true ? {} : historyApiFallback, diff --git a/packages/core/src/server/socketServer.ts b/packages/core/src/server/socketServer.ts index eef3bcca89..74411b9080 100644 --- a/packages/core/src/server/socketServer.ts +++ b/packages/core/src/server/socketServer.ts @@ -1,8 +1,8 @@ import type { IncomingMessage } from 'node:http'; import type { Socket } from 'node:net'; import { type DevConfig, type Stats, logger } from '@rsbuild/shared'; -import ws from '../../compiled/ws'; -import { getAllStatsErrors, getAllStatsWarnings } from '../provider/shared'; +import ws from '../../compiled/ws/index.js'; +import { getAllStatsErrors, getAllStatsWarnings } from '../helpers'; interface ExtWebSocket extends ws { isAlive: boolean; diff --git a/packages/core/src/server/watchFiles.ts b/packages/core/src/server/watchFiles.ts index 697a7b975c..4c8de56082 100644 --- a/packages/core/src/server/watchFiles.ts +++ b/packages/core/src/server/watchFiles.ts @@ -1,10 +1,10 @@ import type { ChokidarWatchOptions, - CompileMiddlewareAPI, DevConfig, ServerConfig, WatchFiles, } from '@rsbuild/shared'; +import type { CompileMiddlewareAPI } from './getDevMiddlewares'; type WatchFilesOptions = { dev: DevConfig; diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 7f61111c01..b48a7e53fd 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -15,6 +15,16 @@ declare module '@rspack/core' { } } +export type RspackSourceMap = { + version: number; + sources: string[]; + mappings: string; + file?: string; + sourceRoot?: string; + sourcesContent?: string[]; + names?: string[]; +}; + export type { RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI }; /** The inner context. */ diff --git a/packages/core/tests/__snapshots__/asset.test.ts.snap b/packages/core/tests/__snapshots__/asset.test.ts.snap index 568087aac0..b7d80f7a01 100644 --- a/packages/core/tests/__snapshots__/asset.test.ts.snap +++ b/packages/core/tests/__snapshots__/asset.test.ts.snap @@ -23,7 +23,7 @@ exports[`plugin-asset > should add image rules correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -50,7 +50,7 @@ exports[`plugin-asset > should add image rules correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -77,7 +77,7 @@ exports[`plugin-asset > should add image rules correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -104,7 +104,7 @@ exports[`plugin-asset > should add image rules correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -140,7 +140,7 @@ exports[`plugin-asset > should add image rules correctly 2`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -167,7 +167,7 @@ exports[`plugin-asset > should add image rules correctly 2`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -194,7 +194,7 @@ exports[`plugin-asset > should add image rules correctly 2`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -221,7 +221,7 @@ exports[`plugin-asset > should add image rules correctly 2`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -257,7 +257,7 @@ exports[`plugin-asset > should allow to use distPath.image to modify dist path 1 }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -284,7 +284,7 @@ exports[`plugin-asset > should allow to use distPath.image to modify dist path 1 }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -311,7 +311,7 @@ exports[`plugin-asset > should allow to use distPath.image to modify dist path 1 }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -338,7 +338,7 @@ exports[`plugin-asset > should allow to use distPath.image to modify dist path 1 }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -374,7 +374,7 @@ exports[`plugin-asset > should allow to use filename.image to modify filename 1` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -401,7 +401,7 @@ exports[`plugin-asset > should allow to use filename.image to modify filename 1` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -428,7 +428,7 @@ exports[`plugin-asset > should allow to use filename.image to modify filename 1` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -455,7 +455,7 @@ exports[`plugin-asset > should allow to use filename.image to modify filename 1` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", diff --git a/packages/core/tests/__snapshots__/builder.test.ts.snap b/packages/core/tests/__snapshots__/builder.test.ts.snap index 554e568cd8..b30470f3f5 100644 --- a/packages/core/tests/__snapshots__/builder.test.ts.snap +++ b/packages/core/tests/__snapshots__/builder.test.ts.snap @@ -11,6 +11,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "experiments": { "asyncWebAssembly": true, + "css": false, }, "ignoreWarnings": [ /Conflicting order/, @@ -20,17 +21,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "mode": "development", "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, "parser": { - "css/module": { - "namedExports": false, - }, "javascript": { "exportsPresence": "error", }, @@ -77,7 +68,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -121,7 +112,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -153,7 +144,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -180,7 +171,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -207,7 +198,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -234,7 +225,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -251,316 +242,199 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` "type": "asset/resource", }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -594,8 +468,6 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` }, "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "devtoolModuleFilenameTemplate": [Function], "filename": "static/js/[name].js", "hashFunction": "xxhash64", @@ -611,6 +483,13 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` HotModuleReplacementPlugin { "name": "HotModuleReplacementPlugin", }, + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, HtmlWebpackPlugin { "options": { "base": false, @@ -678,9 +557,6 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` "affectedHooks": "compilation", "name": "DefinePlugin", }, - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, ], "resolve": { "alias": { diff --git a/packages/core/tests/__snapshots__/css.test.ts.snap b/packages/core/tests/__snapshots__/css.test.ts.snap index 6552f26818..6e94e72d35 100644 --- a/packages/core/tests/__snapshots__/css.test.ts.snap +++ b/packages/core/tests/__snapshots__/css.test.ts.snap @@ -1,344 +1,132 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`plugin-css > should apply custom css-modules-typescript-loader when enableCssModuleTSDeclaration 1`] = ` +exports[`plugin-css > should override browserslist of autoprefixer when using output.overrideBrowserslist config 1`] = ` { + "experiments": { + "css": false, + }, "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, - "parser": { - "css/module": { - "namedExports": false, - }, - }, "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/core/src/provider/css-modules-typescript-pre-loader", - "options": { - "modules": { - "auto": true, - "exportLocalsConvention": "camelCase", - }, - }, - }, - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/core/src/provider/css-modules-typescript-pre-loader", - "options": { - "modules": { - "auto": true, - "exportLocalsConvention": "camelCase", - }, - }, - }, - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, }, - ], - }, - ], - "test": /\\\\\\.css\\$/, - }, - ], - }, - "plugins": [ - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, - ], -} -`; - -exports[`plugin-css > should override browserslist of autoprefixer when using output.overrideBrowserslist config 1`] = ` -{ - "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, - "parser": { - "css/module": { - "namedExports": false, - }, - }, - "rules": [ - { - "oneOf": [ - { - "resolve": { - "preferRelative": true, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "Chrome 80", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "Chrome 80", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], }, { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "Chrome 80", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "Chrome 80", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "Chrome 80", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "Chrome 80", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, ], }, - "plugins": [ - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, - ], } `; exports[`plugin-css > should use custom cssModules rule when using output.cssModules config 1`] = ` { + "experiments": { + "css": false, + }, "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, - "parser": { - "css/module": { - "namedExports": false, - }, - }, "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": [Function], - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": [Function], + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, ], }, - "plugins": [ - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, - ], } `; @@ -357,10 +145,10 @@ exports[`plugin-css injectStyles > should apply ignoreCssLoader when injectStyle "test": /\\\\\\.css\\$/, "use": [ { - "loader": "@rsbuild/shared/ignore-css-loader", + "loader": "/packages/core/src/ignoreCssLoader.cjs", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 1, "modules": { @@ -395,10 +183,10 @@ exports[`plugin-css injectStyles > should use css-loader + style-loader when inj "test": /\\\\\\.css\\$/, "use": [ { - "loader": "/packages/shared/compiled/style-loader", + "loader": "/packages/core/compiled/style-loader", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 1, "modules": { @@ -411,7 +199,7 @@ exports[`plugin-css injectStyles > should use css-loader + style-loader when inj }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -453,116 +241,73 @@ exports[`plugin-less > should add less-loader 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, ], }, @@ -581,10 +326,10 @@ exports[`plugin-less > should add less-loader and css-loader when injectStyles 1 "test": /\\\\\\.less\\$/, "use": [ { - "loader": "/packages/shared/compiled/style-loader", + "loader": "/packages/core/compiled/style-loader", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 2, "modules": { @@ -597,7 +342,7 @@ exports[`plugin-less > should add less-loader and css-loader when injectStyles 1 }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -628,7 +373,7 @@ exports[`plugin-less > should add less-loader and css-loader when injectStyles 1 }, }, { - "loader": "/packages/shared/compiled/less-loader", + "loader": "/packages/core/compiled/less-loader", "options": { "implementation": "/packages/shared/compiled/less", "lessOptions": { @@ -652,122 +397,76 @@ exports[`plugin-less > should add less-loader with excludes 1`] = ` "module": { "rules": [ { - "oneOf": [ + "exclude": [ + /node_modules/, + ], + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "exclude": [ - /node_modules/, - ], - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "exclude": [ - /node_modules/, - ], - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, ], }, @@ -779,116 +478,73 @@ exports[`plugin-less > should add less-loader with tools.less 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": false, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": false, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": false, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, ], }, @@ -900,118 +556,74 @@ exports[`plugin-sass > should add sass-loader 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -1030,10 +642,10 @@ exports[`plugin-sass > should add sass-loader and css-loader when injectStyles 1 "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, "use": [ { - "loader": "/packages/shared/compiled/style-loader", + "loader": "/packages/core/compiled/style-loader", }, { - "loader": "/packages/shared/compiled/css-loader", + "loader": "/packages/core/compiled/css-loader", "options": { "importLoaders": 3, "modules": { @@ -1046,7 +658,7 @@ exports[`plugin-sass > should add sass-loader and css-loader when injectStyles 1 }, }, { - "loader": "/packages/shared/compiled/postcss-loader", + "loader": "/packages/core/compiled/postcss-loader", "options": { "postcssOptions": { "config": false, @@ -1077,7 +689,7 @@ exports[`plugin-sass > should add sass-loader and css-loader when injectStyles 1 }, }, { - "loader": "/packages/shared/compiled/resolve-url-loader", + "loader": "/packages/core/compiled/resolve-url-loader", "options": { "join": [Function], "sourceMap": false, @@ -1102,124 +714,77 @@ exports[`plugin-sass > should add sass-loader with excludes 1`] = ` "module": { "rules": [ { - "oneOf": [ + "exclude": [ + /node_modules/, + ], + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "exclude": [ - /node_modules/, - ], - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "exclude": [ - /node_modules/, - ], - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, diff --git a/packages/core/tests/__snapshots__/default.test.ts.snap b/packages/core/tests/__snapshots__/default.test.ts.snap index 1eb82cab5b..702a8e8e79 100644 --- a/packages/core/tests/__snapshots__/default.test.ts.snap +++ b/packages/core/tests/__snapshots__/default.test.ts.snap @@ -11,6 +11,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "experiments": { "asyncWebAssembly": true, + "css": false, }, "ignoreWarnings": [ /Conflicting order/, @@ -20,17 +21,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "mode": "development", "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, "parser": { - "css/module": { - "namedExports": false, - }, "javascript": { "exportsPresence": "error", }, @@ -77,7 +68,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -121,7 +112,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -153,7 +144,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -180,7 +171,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -207,7 +198,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -234,7 +225,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -251,316 +242,199 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "type": "asset/resource", }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -594,8 +468,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` }, "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "devtoolModuleFilenameTemplate": [Function], "filename": "static/js/[name].js", "hashFunction": "xxhash64", @@ -611,6 +483,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` HotModuleReplacementPlugin { "name": "HotModuleReplacementPlugin", }, + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, HtmlWebpackPlugin { "options": { "base": false, @@ -678,9 +557,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "affectedHooks": "compilation", "name": "DefinePlugin", }, - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, ], "resolve": { "alias": { @@ -715,6 +591,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "experiments": { "asyncWebAssembly": true, + "css": false, }, "ignoreWarnings": [ /Conflicting order/, @@ -724,17 +601,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "mode": "production", "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[local]-[hash:6]", - }, - }, "parser": { - "css/module": { - "namedExports": false, - }, "javascript": { "exportsPresence": "error", }, @@ -781,7 +648,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -825,7 +692,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -857,7 +724,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -884,7 +751,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -911,7 +778,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -938,7 +805,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -955,316 +822,199 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "type": "asset/resource", }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -1321,8 +1071,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod }, "output": { "chunkFilename": "static/js/async/[name].[contenthash:8].js", - "cssChunkFilename": "static/css/async/[name].[contenthash:8].css", - "cssFilename": "static/css/[name].[contenthash:8].css", "filename": "static/js/[name].[contenthash:8].js", "hashFunction": "xxhash64", "path": "/packages/core/tests/dist", @@ -1334,6 +1082,13 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "hints": false, }, "plugins": [ + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].[contenthash:8].css", + "filename": "static/css/[name].[contenthash:8].css", + "ignoreOrder": true, + }, + }, HtmlWebpackPlugin { "options": { "base": false, @@ -1439,9 +1194,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "affectedHooks": "compilation", "name": "DefinePlugin", }, - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, ProgressPlugin { "_options": { "prefix": "Client", @@ -1484,6 +1236,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "experiments": { "asyncWebAssembly": true, + "css": false, }, "ignoreWarnings": [ /Conflicting order/, @@ -1493,17 +1246,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "mode": "development", "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": true, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, "parser": { - "css/module": { - "namedExports": false, - }, "javascript": { "exportsPresence": "error", }, @@ -1544,7 +1287,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1582,7 +1325,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1614,7 +1357,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1641,7 +1384,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1668,7 +1411,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1695,7 +1438,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -1715,7 +1458,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe "test": /\\\\\\.node\\$/, "use": [ { - "loader": "/packages/core/dist/rspack/transformRawLoader", + "loader": "/packages/core/dist/transformRawLoader.cjs", "options": { "id": "rsbuild-transform-0", }, @@ -1723,126 +1466,109 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe ], }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "exportOnlyLocals": true, + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/packages/core/dist/ignoreCssLoader.cjs", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "exportOnlyLocals": true, + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + "loader": "/packages/core/dist/ignoreCssLoader.cjs", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "exportOnlyLocals": true, + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -1853,8 +1579,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe }, "output": { "chunkFilename": "[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "[name].js", "hashFunction": "xxhash64", "libraryTarget": "commonjs2", @@ -1906,6 +1630,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "experiments": { "asyncWebAssembly": true, + "css": false, }, "ignoreWarnings": [ /Conflicting order/, @@ -1915,17 +1640,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "mode": "development", "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, "parser": { - "css/module": { - "namedExports": false, - }, "javascript": { "exportsPresence": "error", }, @@ -1980,7 +1695,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -2024,7 +1739,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -2056,7 +1771,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -2083,7 +1798,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -2110,7 +1825,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -2137,7 +1852,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -2154,316 +1869,199 @@ exports[`tools.rspack > should match snapshot 1`] = ` "type": "asset/resource", }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/core/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/core/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -2497,8 +2095,6 @@ exports[`tools.rspack > should match snapshot 1`] = ` }, "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "devtoolModuleFilenameTemplate": [Function], "filename": "static/js/[name].js", "hashFunction": "xxhash64", @@ -2517,6 +2113,13 @@ exports[`tools.rspack > should match snapshot 1`] = ` HotModuleReplacementPlugin { "name": "HotModuleReplacementPlugin", }, + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, HtmlWebpackPlugin { "options": { "base": false, @@ -2584,9 +2187,6 @@ exports[`tools.rspack > should match snapshot 1`] = ` "affectedHooks": "compilation", "name": "DefinePlugin", }, - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, ], "resolve": { "alias": { diff --git a/packages/core/tests/__snapshots__/inspect.test.ts.snap b/packages/core/tests/__snapshots__/inspect.test.ts.snap index 4b6c630f11..df8acdb3ad 100644 --- a/packages/core/tests/__snapshots__/inspect.test.ts.snap +++ b/packages/core/tests/__snapshots__/inspect.test.ts.snap @@ -2,7 +2,6 @@ exports[`inspectConfig > should print plugin names when inspect config 1`] = ` [ - "rsbuild:transition", "rsbuild:basic", "rsbuild:entry", "rsbuild:target", diff --git a/packages/core/tests/__snapshots__/nodeAddons.test.ts.snap b/packages/core/tests/__snapshots__/nodeAddons.test.ts.snap index 6fe69383a4..9ae4dfdbcc 100644 --- a/packages/core/tests/__snapshots__/nodeAddons.test.ts.snap +++ b/packages/core/tests/__snapshots__/nodeAddons.test.ts.snap @@ -8,7 +8,7 @@ exports[`plugin-node-addons > should add node addons rule properly 1`] = ` "test": /\\\\\\.node\\$/, "use": [ { - "loader": "/packages/core/dist/rspack/transformRawLoader", + "loader": "/packages/core/dist/transformRawLoader.cjs", "options": { "id": "rsbuild-transform-0", }, diff --git a/packages/core/tests/__snapshots__/output.test.ts.snap b/packages/core/tests/__snapshots__/output.test.ts.snap index 0c2264cf2c..1524e77105 100644 --- a/packages/core/tests/__snapshots__/output.test.ts.snap +++ b/packages/core/tests/__snapshots__/output.test.ts.snap @@ -4,8 +4,6 @@ exports[`plugin-output > should allow to custom server directory with distPath.s { "output": { "chunkFilename": "[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "[name].js", "hashFunction": "xxhash64", "libraryTarget": "commonjs2", @@ -20,14 +18,21 @@ exports[`plugin-output > should allow to set distPath.js and distPath.css to emp { "output": { "chunkFilename": "async/[name].js", - "cssChunkFilename": "async/[name].css", - "cssFilename": "[name].css", "filename": "[name].js", "hashFunction": "xxhash64", "path": "/packages/core/tests/dist", "pathinfo": false, "publicPath": "/", }, + "plugins": [ + CssExtractRspackPlugin { + "options": { + "chunkFilename": "async/[name].css", + "filename": "[name].css", + "ignoreOrder": true, + }, + }, + ], } `; @@ -35,8 +40,6 @@ exports[`plugin-output > should allow to use copy plugin 1`] = ` { "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "static/js/[name].js", "hashFunction": "xxhash64", "path": "/packages/core/tests/dist", @@ -59,6 +62,13 @@ exports[`plugin-output > should allow to use copy plugin 1`] = ` "affectedHooks": undefined, "name": "CopyRspackPlugin", }, + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, ], } `; @@ -67,8 +77,6 @@ exports[`plugin-output > should allow to use copy plugin with multiply config 1` { "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "static/js/[name].js", "hashFunction": "xxhash64", "path": "/packages/core/tests/dist", @@ -105,6 +113,13 @@ exports[`plugin-output > should allow to use copy plugin with multiply config 1` "affectedHooks": undefined, "name": "CopyRspackPlugin", }, + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, ], } `; @@ -113,14 +128,21 @@ exports[`plugin-output > should allow to use filename.js to modify filename 1`] { "output": { "chunkFilename": "static/js/async/foo.js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "static/js/foo.js", "hashFunction": "xxhash64", "path": "/packages/core/tests/dist", "pathinfo": false, "publicPath": "/", }, + "plugins": [ + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, + ], } `; @@ -128,13 +150,20 @@ exports[`plugin-output > should set output correctly 1`] = ` { "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "static/js/[name].js", "hashFunction": "xxhash64", "path": "/packages/core/tests/dist", "pathinfo": false, "publicPath": "/", }, + "plugins": [ + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, + ], } `; diff --git a/packages/core/tests/__snapshots__/splitChunks.test.ts.snap b/packages/core/tests/__snapshots__/splitChunks.test.ts.snap index 72365d14fd..f885e33fe4 100644 --- a/packages/core/tests/__snapshots__/splitChunks.test.ts.snap +++ b/packages/core/tests/__snapshots__/splitChunks.test.ts.snap @@ -152,7 +152,7 @@ exports[`plugin-split-chunks > should set split-by-module config 1`] = ` "cacheGroups": { "vendors": { "name": [Function], - "priority": -10, + "priority": -9, "test": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/, }, }, diff --git a/packages/core/tests/__snapshots__/swc.test.ts.snap b/packages/core/tests/__snapshots__/swc.test.ts.snap index 26630e442d..4ea9ae0c6e 100644 --- a/packages/core/tests/__snapshots__/swc.test.ts.snap +++ b/packages/core/tests/__snapshots__/swc.test.ts.snap @@ -44,7 +44,7 @@ exports[`plugin-swc > should add antd pluginImport 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -88,7 +88,7 @@ exports[`plugin-swc > should add antd pluginImport 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -154,7 +154,7 @@ exports[`plugin-swc > should add browserslist 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -195,7 +195,7 @@ exports[`plugin-swc > should add browserslist 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -262,7 +262,7 @@ exports[`plugin-swc > should add browserslist 2`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -303,7 +303,7 @@ exports[`plugin-swc > should add browserslist 2`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -373,7 +373,7 @@ exports[`plugin-swc > should add pluginImport 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -424,7 +424,7 @@ exports[`plugin-swc > should add pluginImport 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -544,7 +544,7 @@ exports[`plugin-swc > should allow to use \`tools.swc\` to configure swc-loader "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -588,7 +588,7 @@ exports[`plugin-swc > should allow to use \`tools.swc\` to configure swc-loader "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -648,7 +648,7 @@ exports[`plugin-swc > should disable all pluginImport 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -692,7 +692,7 @@ exports[`plugin-swc > should disable all pluginImport 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -755,7 +755,7 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -793,7 +793,7 @@ exports[`plugin-swc > should disable preset_env in target other than web 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -860,7 +860,7 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -902,7 +902,7 @@ exports[`plugin-swc > should disable preset_env mode 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -971,7 +971,7 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1014,7 +1014,7 @@ exports[`plugin-swc > should enable entry mode preset_env 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1084,7 +1084,7 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1128,7 +1128,7 @@ exports[`plugin-swc > should enable usage mode preset_env 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1198,7 +1198,7 @@ exports[`plugin-swc > should has correct core-js 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1241,7 +1241,7 @@ exports[`plugin-swc > should has correct core-js 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1305,7 +1305,7 @@ exports[`plugin-swc > should has correct core-js 2`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1343,7 +1343,7 @@ exports[`plugin-swc > should has correct core-js 2`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1412,7 +1412,7 @@ exports[`plugin-swc > should'n override browserslist when target platform is not "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -1456,7 +1456,7 @@ exports[`plugin-swc > should'n override browserslist when target platform is not "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { diff --git a/packages/core/tests/cache.test.ts b/packages/core/tests/cache.test.ts index c1997186ee..684e32ba4d 100644 --- a/packages/core/tests/cache.test.ts +++ b/packages/core/tests/cache.test.ts @@ -1,7 +1,7 @@ import { createStubRsbuild } from '@scripts/test-helper'; import { pluginCache } from '../src/plugins/cache'; -vi.mock('@rsbuild/shared', async (importOriginal) => { +vi.mock('../src/helpers.js', async (importOriginal) => { const mod = await importOriginal(); return { ...mod, diff --git a/packages/core/tests/createPluginManager.test.ts b/packages/core/tests/createPluginManager.test.ts index 0820b40626..cc9c50a9fa 100644 --- a/packages/core/tests/createPluginManager.test.ts +++ b/packages/core/tests/createPluginManager.test.ts @@ -3,7 +3,7 @@ import { createPluginManager } from '../src/pluginManager'; describe('createPluginManager', () => { it('addPlugins and removePlugins works', () => { const pluginManager = createPluginManager(); - expect(pluginManager.plugins).toEqual([]); + expect(pluginManager.getPlugins()).toEqual([]); pluginManager.addPlugins([ { name: 'foo', @@ -18,9 +18,9 @@ describe('createPluginManager', () => { }, }, ]); - expect(pluginManager.plugins).toHaveLength(2); + expect(pluginManager.getPlugins()).toHaveLength(2); pluginManager.removePlugins(['foo']); - expect(pluginManager.plugins).toHaveLength(1); + expect(pluginManager.getPlugins()).toHaveLength(1); expect(pluginManager.isPluginExists('foo')).toBe(false); }); }); diff --git a/packages/core/tests/css.test.ts b/packages/core/tests/css.test.ts index 91d346f108..e00aa75688 100644 --- a/packages/core/tests/css.test.ts +++ b/packages/core/tests/css.test.ts @@ -1,7 +1,47 @@ +import type { NormalizedConfig } from '@rsbuild/shared'; +import autoprefixer from '@rsbuild/shared/autoprefixer'; import { createStubRsbuild } from '@scripts/test-helper'; -import { pluginCss } from '../src/provider/plugins/css'; -import { pluginLess } from '../src/provider/plugins/less'; -import { pluginSass } from '../src/provider/plugins/sass'; +import { + applyAutoprefixer, + normalizeCssLoaderOptions, + pluginCss, +} from '../src/plugins/css'; +import { pluginLess } from '../src/plugins/less'; +import { pluginSass } from '../src/plugins/sass'; + +describe('normalizeCssLoaderOptions', () => { + it('should enable exportOnlyLocals correctly', () => { + expect(normalizeCssLoaderOptions({ modules: false }, true)).toEqual({ + modules: false, + }); + + expect(normalizeCssLoaderOptions({ modules: true }, true)).toEqual({ + modules: { + exportOnlyLocals: true, + }, + }); + + expect(normalizeCssLoaderOptions({ modules: true }, false)).toEqual({ + modules: true, + }); + + expect(normalizeCssLoaderOptions({ modules: 'local' }, true)).toEqual({ + modules: { + mode: 'local', + exportOnlyLocals: true, + }, + }); + + expect( + normalizeCssLoaderOptions({ modules: { auto: true } }, true), + ).toEqual({ + modules: { + auto: true, + exportOnlyLocals: true, + }, + }); + }); +}); describe('plugin-css', () => { it('should override browserslist of autoprefixer when using output.overrideBrowserslist config', async () => { @@ -85,25 +125,6 @@ describe('plugin-css', () => { ); }); - it('should ignore hashDigest when custom cssModules.localIdentName', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - cssModules: { - localIdentName: '[hash:base64:5]', - }, - }, - }, - }); - - const bundlerConfigs = await rsbuild.initConfigs(); - - expect(JSON.stringify(bundlerConfigs[0])).toContain( - '"localIdentName":"[hash:5]"', - ); - }); - it('should use custom cssModules rule when using output.cssModules config', async () => { const rsbuild = await createStubRsbuild({ plugins: [pluginCss()], @@ -118,19 +139,6 @@ describe('plugin-css', () => { const bundlerConfigs = await rsbuild.initConfigs(); expect(bundlerConfigs[0]).toMatchSnapshot(); }); - - it('should apply custom css-modules-typescript-loader when enableCssModuleTSDeclaration', async () => { - const rsbuild = await createStubRsbuild({ - plugins: [pluginCss()], - rsbuildConfig: { - output: { - enableCssModuleTSDeclaration: true, - }, - }, - }); - const bundlerConfigs = await rsbuild.initConfigs(); - expect(bundlerConfigs[0]).toMatchSnapshot(); - }); }); describe('plugin-css injectStyles', () => { @@ -218,7 +226,7 @@ describe('plugin-less', () => { plugins: [pluginLess()], rsbuildConfig: { tools: { - less(config, { addExcludes }) { + less(_config, { addExcludes }) { addExcludes(/node_modules/); }, }, @@ -262,7 +270,7 @@ describe('plugin-sass', () => { plugins: [pluginSass()], rsbuildConfig: { tools: { - sass(config, { addExcludes }) { + sass(_config, { addExcludes }) { addExcludes(/node_modules/); }, }, @@ -273,3 +281,22 @@ describe('plugin-sass', () => { expect(bundlerConfigs[0]).toMatchSnapshot(); }); }); + +it('should not apply autoprefixer if user config contains autoprefixer', async () => { + const config = { + tools: {}, + } as NormalizedConfig; + + expect( + (await applyAutoprefixer([autoprefixer()], ['Chrome >= 100'], config)) + .length, + ).toEqual(1); + + expect( + (await applyAutoprefixer([autoprefixer], ['Chrome >= 100'], config)).length, + ).toEqual(1); + + expect( + (await applyAutoprefixer([], ['Chrome >= 100'], config)).length, + ).toEqual(1); +}); diff --git a/packages/core/tests/default.test.ts b/packages/core/tests/default.test.ts index 484d60cf74..c5bc2a412e 100644 --- a/packages/core/tests/default.test.ts +++ b/packages/core/tests/default.test.ts @@ -1,6 +1,5 @@ import type { RsbuildPlugin } from '@rsbuild/shared'; import { createStubRsbuild } from '@scripts/test-helper'; -import { BUILTIN_LOADER } from '../src/provider/shared'; describe('applyDefaultPlugins', () => { it('should apply default plugins correctly', async () => { @@ -158,7 +157,7 @@ describe('bundlerApi', () => { .type('javascript/auto') .test(/\.ya?ml$/) .use('yaml') - .loader(`${BUILTIN_LOADER}yaml-loader`); + .loader('builtin:yaml-loader'); }); }, }; diff --git a/packages/core/tests/html.test.ts b/packages/core/tests/html.test.ts index 9fb81495d0..6a9fb976be 100644 --- a/packages/core/tests/html.test.ts +++ b/packages/core/tests/html.test.ts @@ -3,7 +3,7 @@ import { createStubRsbuild } from '@scripts/test-helper'; import { pluginEntry } from '../src/plugins/entry'; import { pluginHtml } from '../src/plugins/html'; -vi.mock('@rsbuild/shared', async (importOriginal) => { +vi.mock('../src/helpers.js', async (importOriginal) => { const mod = await importOriginal(); return { ...mod, diff --git a/packages/core/tests/minimize.test.ts b/packages/core/tests/minimize.test.ts index d60d5017ff..7b3b9861b5 100644 --- a/packages/core/tests/minimize.test.ts +++ b/packages/core/tests/minimize.test.ts @@ -1,7 +1,7 @@ import { createStubRsbuild } from '@scripts/test-helper'; import { pluginEntry } from '../src/plugins/entry'; import { pluginHtml } from '../src/plugins/html'; -import { pluginMinimize } from '../src/provider/plugins/minimize'; +import { pluginMinimize } from '../src/plugins/minimize'; describe('plugin-minimize', () => { it('should not apply minimizer in development', async () => { diff --git a/packages/core/tests/output.test.ts b/packages/core/tests/output.test.ts index 2037ad4937..3ebcda3785 100644 --- a/packages/core/tests/output.test.ts +++ b/packages/core/tests/output.test.ts @@ -1,5 +1,5 @@ import { createStubRsbuild } from '@scripts/test-helper'; -import { pluginOutput } from '../src/provider/plugins/output'; +import { pluginOutput } from '../src/plugins/output'; describe('plugin-output', () => { it('should set output correctly', async () => { diff --git a/packages/core/tests/resolve.test.ts b/packages/core/tests/resolve.test.ts index 166de85a9a..e78acb3737 100644 --- a/packages/core/tests/resolve.test.ts +++ b/packages/core/tests/resolve.test.ts @@ -1,5 +1,5 @@ import { createStubRsbuild } from '@scripts/test-helper'; -import { pluginResolve } from '../src/provider/plugins/resolve'; +import { pluginResolve } from '../src/plugins/resolve'; describe('plugin-resolve', () => { it('should apply default extensions correctly', async () => { diff --git a/packages/core/tests/rspackVersion.test.ts b/packages/core/tests/rspackVersion.test.ts index 8c66166c7b..fe7e687af2 100644 --- a/packages/core/tests/rspackVersion.test.ts +++ b/packages/core/tests/rspackVersion.test.ts @@ -1,7 +1,4 @@ -import { - isSatisfyRspackVersion, - rspackMinVersion, -} from '../src/provider/shared'; +import { isSatisfyRspackVersion, rspackMinVersion } from '../src/helpers'; describe('rspack version', () => { it('isSatisfyRspackVersion', async () => { diff --git a/packages/core/tests/server.test.ts b/packages/core/tests/server.test.ts index cb41f6a257..71c45099b0 100644 --- a/packages/core/tests/server.test.ts +++ b/packages/core/tests/server.test.ts @@ -1,5 +1,6 @@ -import { isClientCompiler, setupServerHooks } from '@rsbuild/shared'; +import { isClientCompiler } from '@rsbuild/shared'; import { rspack } from '@rspack/core'; +import { setupServerHooks } from '../src/server/devMiddleware'; import { formatRoutes, mergeDevOptions, diff --git a/packages/core/tests/swc.test.ts b/packages/core/tests/swc.test.ts index 1215f584d5..d7dbebb5a4 100644 --- a/packages/core/tests/swc.test.ts +++ b/packages/core/tests/swc.test.ts @@ -1,7 +1,7 @@ import type { RsbuildConfig } from '@rsbuild/shared'; import { createStubRsbuild } from '@scripts/test-helper'; import { pluginEntry } from '../src/plugins/entry'; -import { pluginSwc } from '../src/provider/plugins/swc'; +import { pluginSwc } from '../src/plugins/swc'; describe('plugin-swc', () => { it('should disable preset_env in target other than web', async () => { diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index b7eb92df53..d9f909b987 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -4,6 +4,7 @@ "outDir": "./dist", "baseUrl": "./", "rootDir": "src", + "declarationDir": "./dist-types", "composite": true, "types": ["webpack/module"] }, diff --git a/packages/create-rsbuild/modern.config.ts b/packages/create-rsbuild/modern.config.ts index 0e2c1ed3a3..24e2cad9df 100644 --- a/packages/create-rsbuild/modern.config.ts +++ b/packages/create-rsbuild/modern.config.ts @@ -1,3 +1,7 @@ -import { bundleMjsOnlyConfig } from '../../scripts/modern.base.config'; +import { defineConfig, moduleTools } from '@modern-js/module-tools'; +import { esmBuildConfig } from '../../scripts/modern.base.config'; -export default bundleMjsOnlyConfig; +export default defineConfig({ + plugins: [moduleTools()], + buildConfig: [esmBuildConfig], +}); diff --git a/packages/create-rsbuild/package.json b/packages/create-rsbuild/package.json index c84245e93d..5349a2ebfb 100644 --- a/packages/create-rsbuild/package.json +++ b/packages/create-rsbuild/package.json @@ -1,6 +1,6 @@ { "name": "create-rsbuild", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Create a new Rsbuild project", "homepage": "https://rsbuild.dev", "repository": { diff --git a/packages/create-rsbuild/template-preact-js/package.json b/packages/create-rsbuild/template-preact-js/package.json index 0ae9e49289..7d6496299d 100644 --- a/packages/create-rsbuild/template-preact-js/package.json +++ b/packages/create-rsbuild/template-preact-js/package.json @@ -8,7 +8,7 @@ "preview": "rsbuild preview" }, "dependencies": { - "preact": "^10.21.0" + "preact": "^10.22.0" }, "devDependencies": { "@rsbuild/core": "workspace:*", diff --git a/packages/create-rsbuild/template-preact-ts/package.json b/packages/create-rsbuild/template-preact-ts/package.json index 5f9d14a517..0fc8cf1b1e 100644 --- a/packages/create-rsbuild/template-preact-ts/package.json +++ b/packages/create-rsbuild/template-preact-ts/package.json @@ -8,7 +8,7 @@ "preview": "rsbuild preview" }, "dependencies": { - "preact": "^10.21.0" + "preact": "^10.22.0" }, "devDependencies": { "@rsbuild/core": "workspace:*", diff --git a/packages/create-rsbuild/template-react-ts/package.json b/packages/create-rsbuild/template-react-ts/package.json index 08f3706670..8c8c3ab436 100644 --- a/packages/create-rsbuild/template-react-ts/package.json +++ b/packages/create-rsbuild/template-react-ts/package.json @@ -14,7 +14,7 @@ "devDependencies": { "@rsbuild/core": "workspace:*", "@rsbuild/plugin-react": "workspace:*", - "@types/react": "^18.3.1", + "@types/react": "^18.3.2", "@types/react-dom": "^18.3.0", "typescript": "^5.4.2" } diff --git a/packages/create-rsbuild/template-svelte-js/package.json b/packages/create-rsbuild/template-svelte-js/package.json index ee98430b7f..c25d57b506 100644 --- a/packages/create-rsbuild/template-svelte-js/package.json +++ b/packages/create-rsbuild/template-svelte-js/package.json @@ -8,7 +8,7 @@ "preview": "rsbuild preview" }, "dependencies": { - "svelte": "^4.2.15" + "svelte": "^4.2.16" }, "devDependencies": { "@rsbuild/core": "workspace:*", diff --git a/packages/create-rsbuild/template-svelte-ts/package.json b/packages/create-rsbuild/template-svelte-ts/package.json index 3286fdb8dd..8ba60a4347 100644 --- a/packages/create-rsbuild/template-svelte-ts/package.json +++ b/packages/create-rsbuild/template-svelte-ts/package.json @@ -8,7 +8,7 @@ "preview": "rsbuild preview" }, "dependencies": { - "svelte": "^4.2.15" + "svelte": "^4.2.16" }, "devDependencies": { "@rsbuild/core": "workspace:*", diff --git a/packages/monorepo-utils/modern.config.ts b/packages/monorepo-utils/modern.config.ts deleted file mode 100644 index 52cae05a53..0000000000 --- a/packages/monorepo-utils/modern.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -import baseConfig from '../../scripts/modern.base.config'; - -export default baseConfig; diff --git a/packages/monorepo-utils/package.json b/packages/monorepo-utils/package.json deleted file mode 100644 index 876ba1c384..0000000000 --- a/packages/monorepo-utils/package.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "@rsbuild/monorepo-utils", - "version": "0.6.13", - "description": "The monorepo utils of Rsbuild.", - "homepage": "https://rsbuild.dev", - "repository": { - "type": "git", - "url": "https://github.com/web-infra-dev/rsbuild", - "directory": "packages/monorepo-utils" - }, - "license": "MIT", - "type": "commonjs", - "exports": { - ".": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - } - }, - "main": "./dist/index.js", - "types": "./dist/index.d.ts", - "files": [ - "dist" - ], - "scripts": { - "build": "modern build", - "dev": "modern build --watch" - }, - "dependencies": { - "@rsbuild/shared": "workspace:*", - "fast-glob": "^3.3.2" - }, - "devDependencies": { - "@types/node": "18.x", - "typescript": "^5.4.2" - }, - "publishConfig": { - "access": "public", - "provenance": true, - "registry": "https://registry.npmjs.org/" - } -} diff --git a/packages/monorepo-utils/src/index.ts b/packages/monorepo-utils/src/index.ts deleted file mode 100644 index 22b1d0481d..0000000000 --- a/packages/monorepo-utils/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './common'; -export * from './project'; -export * from './project-utils'; -export * from './constants'; -export * from './types'; diff --git a/packages/plugin-assets-retry/modern.config.ts b/packages/plugin-assets-retry/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-assets-retry/modern.config.ts +++ b/packages/plugin-assets-retry/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-assets-retry/package.json b/packages/plugin-assets-retry/package.json index c98d395f47..49d62bee10 100644 --- a/packages/plugin-assets-retry/package.json +++ b/packages/plugin-assets-retry/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-assets-retry", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Assets retry plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,21 +9,21 @@ "directory": "packages/plugin-assets-retry" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" ], "scripts": { - "build": "modern build && node scripts/postCompile.js", + "build": "modern build && node scripts/postCompile.mjs", "dev": "modern build --watch" }, "dependencies": { @@ -42,7 +42,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-assets-retry/scripts/postCompile.js b/packages/plugin-assets-retry/scripts/postCompile.mjs similarity index 74% rename from packages/plugin-assets-retry/scripts/postCompile.js rename to packages/plugin-assets-retry/scripts/postCompile.mjs index fab58ca40f..0742ef0728 100644 --- a/packages/plugin-assets-retry/scripts/postCompile.js +++ b/packages/plugin-assets-retry/scripts/postCompile.mjs @@ -1,7 +1,12 @@ -const path = require('node:path'); -const { readFile, writeFile, mkdir } = require('node:fs/promises'); -const { transformAsync } = require('@babel/core'); -const { performance } = require('node:perf_hooks'); +import { existsSync } from 'node:fs'; +import { mkdir, readFile, writeFile } from 'node:fs/promises'; +import path from 'node:path'; +import { performance } from 'node:perf_hooks'; +import { fileURLToPath } from 'node:url'; +import { transformAsync } from '@babel/core'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); /** * transform ../src/runtime/${filename}.ts @@ -48,11 +53,17 @@ async function compileRuntimeFile(filename) { async function compile() { const startTime = performance.now(); - await mkdir(path.join(__dirname, '../dist/runtime')); + + const runtimeDir = path.join(__dirname, '../dist/runtime'); + if (!existsSync(runtimeDir)) { + await mkdir(runtimeDir); + } + await Promise.all([ compileRuntimeFile('initialChunkRetry'), compileRuntimeFile('asyncChunkRetry'), ]); + console.log( `Compiled assets retry runtime code. Time cost: ${( performance.now() - startTime diff --git a/packages/plugin-assets-retry/src/AssetsRetryPlugin.ts b/packages/plugin-assets-retry/src/AssetsRetryPlugin.ts index 02ccb41c7c..e4893f1504 100644 --- a/packages/plugin-assets-retry/src/AssetsRetryPlugin.ts +++ b/packages/plugin-assets-retry/src/AssetsRetryPlugin.ts @@ -1,6 +1,6 @@ import path from 'node:path'; +import type { Rspack } from '@rsbuild/core'; import { - type Rspack, fse, generateScriptTag, getPublicPathFromCompiler, diff --git a/packages/plugin-assets-retry/src/runtime/initialChunkRetry.ts b/packages/plugin-assets-retry/src/runtime/initialChunkRetry.ts index ebf05cf2ba..8e7afb41c2 100644 --- a/packages/plugin-assets-retry/src/runtime/initialChunkRetry.ts +++ b/packages/plugin-assets-retry/src/runtime/initialChunkRetry.ts @@ -1,5 +1,5 @@ // rsbuild/runtime/initial-chunk-retry -import type { CrossOrigin } from '@rsbuild/shared'; +import type { CrossOrigin } from '@rsbuild/core'; import type { AssetsRetryHookContext, RuntimeRetryOptions } from '../types'; interface ScriptElementAttributes { diff --git a/packages/plugin-assets-retry/src/types.ts b/packages/plugin-assets-retry/src/types.ts index 5c640e46cd..587aa40a9e 100644 --- a/packages/plugin-assets-retry/src/types.ts +++ b/packages/plugin-assets-retry/src/types.ts @@ -1,4 +1,4 @@ -import type { CrossOrigin } from '@rsbuild/shared'; +import type { CrossOrigin } from '@rsbuild/core'; export type PluginAssetsRetryOptions = { /** diff --git a/packages/plugin-babel/modern.config.ts b/packages/plugin-babel/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-babel/modern.config.ts +++ b/packages/plugin-babel/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-babel/package.json b/packages/plugin-babel/package.json index d2d2091c2e..0bb54ad858 100644 --- a/packages/plugin-babel/package.json +++ b/packages/plugin-babel/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-babel", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Babel plugin for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-babel" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist", @@ -45,7 +45,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-babel/src/helper.ts b/packages/plugin-babel/src/helper.ts index bc935087a3..a720a5c88b 100644 --- a/packages/plugin-babel/src/helper.ts +++ b/packages/plugin-babel/src/helper.ts @@ -1,12 +1,11 @@ import { isAbsolute, normalize, sep } from 'node:path'; import type { PluginOptions as BabelPluginOptions } from '@babel/core'; -import { - type BundlerChain, - type ChainIdentifier, - type NormalizedConfig, - castArray, - mergeChainedOptions, -} from '@rsbuild/shared'; +import type { + BundlerChain, + ChainIdentifier, + NormalizedConfig, +} from '@rsbuild/core'; +import { castArray, mergeChainedOptions } from '@rsbuild/shared'; import upath from 'upath'; import type { BabelConfigUtils, diff --git a/packages/plugin-babel/src/types.ts b/packages/plugin-babel/src/types.ts index 48afeefbe1..8d9b6d79c4 100644 --- a/packages/plugin-babel/src/types.ts +++ b/packages/plugin-babel/src/types.ts @@ -2,7 +2,7 @@ import type { PluginItem as BabelPlugin, TransformOptions as BabelTransformOptions, } from '@babel/core'; -import type { ChainedConfigWithUtils } from '@rsbuild/shared'; +import type { ChainedConfigWithUtils } from '@rsbuild/core'; export type { BabelPlugin, BabelTransformOptions }; diff --git a/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap b/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap index f52f06acd0..e0b8fd8458 100644 --- a/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-babel/tests/__snapshots__/index.test.ts.snap @@ -40,7 +40,7 @@ exports[`plugins/babel > babel-loader should works with builtin:swc-loader 1`] = "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { diff --git a/packages/plugin-basic-ssl/modern.config.ts b/packages/plugin-basic-ssl/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-basic-ssl/modern.config.ts +++ b/packages/plugin-basic-ssl/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-basic-ssl/package.json b/packages/plugin-basic-ssl/package.json index dfce310acf..c1d66e0b45 100644 --- a/packages/plugin-basic-ssl/package.json +++ b/packages/plugin-basic-ssl/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-basic-ssl", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "SSL plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-basic-ssl" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,7 +27,6 @@ "dev": "modern build --watch" }, "dependencies": { - "@rsbuild/shared": "workspace:*", "selfsigned": "^2.4.1" }, "devDependencies": { @@ -35,7 +34,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-basic-ssl/src/util.ts b/packages/plugin-basic-ssl/src/util.ts index eda23c938e..fff51e5de0 100644 --- a/packages/plugin-basic-ssl/src/util.ts +++ b/packages/plugin-basic-ssl/src/util.ts @@ -1,6 +1,6 @@ import fs from 'node:fs'; import path from 'node:path'; -import type { ServerConfig } from '@rsbuild/shared'; +import type { ServerConfig } from '@rsbuild/core'; import selfsigned from 'selfsigned'; export const resolveHttpsConfig = (config: ServerConfig['https']) => { diff --git a/packages/plugin-basic-ssl/tsconfig.json b/packages/plugin-basic-ssl/tsconfig.json index 0caaa55ade..c07e6fe949 100644 --- a/packages/plugin-basic-ssl/tsconfig.json +++ b/packages/plugin-basic-ssl/tsconfig.json @@ -9,9 +9,6 @@ "references": [ { "path": "../core" - }, - { - "path": "../shared" } ], "include": ["src"] diff --git a/packages/plugin-check-syntax/modern.config.ts b/packages/plugin-check-syntax/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-check-syntax/modern.config.ts +++ b/packages/plugin-check-syntax/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-check-syntax/package.json b/packages/plugin-check-syntax/package.json index f82f49bad7..b6ceb4786b 100644 --- a/packages/plugin-check-syntax/package.json +++ b/packages/plugin-check-syntax/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-check-syntax", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Check syntax plugin of Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-check-syntax" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -38,7 +38,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-check-syntax/src/CheckSyntaxPlugin.ts b/packages/plugin-check-syntax/src/CheckSyntaxPlugin.ts index 976527a9b0..c5131f72b6 100644 --- a/packages/plugin-check-syntax/src/CheckSyntaxPlugin.ts +++ b/packages/plugin-check-syntax/src/CheckSyntaxPlugin.ts @@ -1,11 +1,6 @@ import { resolve } from 'node:path'; import type { Rspack } from '@rsbuild/core'; -import { - HTML_REGEX, - JS_REGEX, - browserslistToESVersion, - fse, -} from '@rsbuild/shared'; +import { JS_REGEX, browserslistToESVersion, fse } from '@rsbuild/shared'; import { parse } from 'acorn'; import { checkIsExcludeSource, @@ -24,6 +19,8 @@ import type { type Compiler = Rspack.Compiler; type Compilation = Rspack.Compilation; +const HTML_REGEX = /\.html$/; + export class CheckSyntaxPlugin { errors: ECMASyntaxError[] = []; diff --git a/packages/plugin-check-syntax/src/index.ts b/packages/plugin-check-syntax/src/index.ts index 89d4521720..e6a2ef4df6 100644 --- a/packages/plugin-check-syntax/src/index.ts +++ b/packages/plugin-check-syntax/src/index.ts @@ -1,9 +1,9 @@ -import type { RsbuildPlugin } from '@rsbuild/core'; -import { - type NormalizedConfig, - type RsbuildTarget, - getBrowserslistWithDefault, -} from '@rsbuild/shared'; +import type { + NormalizedConfig, + RsbuildPlugin, + RsbuildTarget, +} from '@rsbuild/core'; +import { getBrowserslistWithDefault } from '@rsbuild/shared'; import type { CheckSyntaxOptions } from './types'; export type PluginCheckSyntaxOptions = CheckSyntaxOptions; diff --git a/packages/plugin-css-minimizer/modern.config.ts b/packages/plugin-css-minimizer/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-css-minimizer/modern.config.ts +++ b/packages/plugin-css-minimizer/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-css-minimizer/package.json b/packages/plugin-css-minimizer/package.json index d7f03a1599..ca5c05a86c 100644 --- a/packages/plugin-css-minimizer/package.json +++ b/packages/plugin-css-minimizer/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-css-minimizer", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "CSS minimizer for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-css-minimizer" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -37,7 +37,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-css-minimizer/src/index.ts b/packages/plugin-css-minimizer/src/index.ts index edab5fbf48..f050032dd2 100644 --- a/packages/plugin-css-minimizer/src/index.ts +++ b/packages/plugin-css-minimizer/src/index.ts @@ -1,11 +1,10 @@ -import type { RsbuildPlugin } from '@rsbuild/core'; -import { - type BundlerChain, - type ChainIdentifier, - type ChainedConfig, - mergeChainedOptions, - parseMinifyOptions, -} from '@rsbuild/shared'; +import type { + BundlerChain, + ChainIdentifier, + ChainedConfig, + RsbuildPlugin, +} from '@rsbuild/core'; +import { mergeChainedOptions } from '@rsbuild/shared'; import CssMinimizerWebpackPlugin from 'css-minimizer-webpack-plugin'; import type CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; @@ -67,12 +66,12 @@ export const pluginCssMinimizer = ( setup(api) { api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => { const config = api.getNormalizedConfig(); - const isMinimize = - isProd && - config.output.minify !== false && - parseMinifyOptions(config).minifyCss; + const { minify } = config.output; - if (isMinimize) { + if ( + isProd && + (minify === true || (typeof minify === 'object' && minify.css)) + ) { applyCSSMinimizer(chain, CHAIN_ID, options); } }); diff --git a/packages/plugin-eslint/modern.config.ts b/packages/plugin-eslint/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-eslint/modern.config.ts +++ b/packages/plugin-eslint/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-eslint/package.json b/packages/plugin-eslint/package.json index 90fd3d493b..8e178976ac 100644 --- a/packages/plugin-eslint/package.json +++ b/packages/plugin-eslint/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-eslint", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "ESLint plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-eslint" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,7 +27,6 @@ "dev": "modern build --watch" }, "dependencies": { - "@rsbuild/shared": "workspace:*", "eslint": "^8.57.0", "eslint-webpack-plugin": "^4.1.0", "webpack": "^5.91.0" @@ -38,7 +37,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-eslint/tsconfig.json b/packages/plugin-eslint/tsconfig.json index 0caaa55ade..c07e6fe949 100644 --- a/packages/plugin-eslint/tsconfig.json +++ b/packages/plugin-eslint/tsconfig.json @@ -9,9 +9,6 @@ "references": [ { "path": "../core" - }, - { - "path": "../shared" } ], "include": ["src"] diff --git a/packages/plugin-image-compress/modern.config.ts b/packages/plugin-image-compress/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-image-compress/modern.config.ts +++ b/packages/plugin-image-compress/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-image-compress/package.json b/packages/plugin-image-compress/package.json index 3661e096b9..4d818f2bb3 100644 --- a/packages/plugin-image-compress/package.json +++ b/packages/plugin-image-compress/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-image-compress", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Image compress plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-image-compress" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -28,8 +28,7 @@ }, "dependencies": { "@napi-rs/image": "^1.9.2", - "@rsbuild/shared": "workspace:*", - "svgo": "^3.2.0" + "svgo": "^3.3.2" }, "devDependencies": { "@rsbuild/core": "workspace:*", @@ -40,7 +39,7 @@ "webpack": "^5.91.0" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-image-compress/src/types/index.ts b/packages/plugin-image-compress/src/types/index.ts index 69abb8510a..c405d0c350 100644 --- a/packages/plugin-image-compress/src/types/index.ts +++ b/packages/plugin-image-compress/src/types/index.ts @@ -16,7 +16,7 @@ export interface CodecBaseOptions { jpeg: JpegCompressOptions; png: PngQuantOptions; pngLossless: PNGLosslessOptions; - ico: Record; + ico: Record; svg: SvgoConfig; } diff --git a/packages/plugin-image-compress/tests/__snapshots__/index.test.ts.snap b/packages/plugin-image-compress/tests/__snapshots__/index.test.ts.snap index f72168e76b..9b37e3391f 100644 --- a/packages/plugin-image-compress/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-image-compress/tests/__snapshots__/index.test.ts.snap @@ -23,7 +23,7 @@ exports[`plugin-image-compress > should generate correct options 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -50,7 +50,7 @@ exports[`plugin-image-compress > should generate correct options 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -77,7 +77,7 @@ exports[`plugin-image-compress > should generate correct options 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -104,7 +104,7 @@ exports[`plugin-image-compress > should generate correct options 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", diff --git a/packages/plugin-image-compress/tsconfig.json b/packages/plugin-image-compress/tsconfig.json index 0caaa55ade..c07e6fe949 100644 --- a/packages/plugin-image-compress/tsconfig.json +++ b/packages/plugin-image-compress/tsconfig.json @@ -9,9 +9,6 @@ "references": [ { "path": "../core" - }, - { - "path": "../shared" } ], "include": ["src"] diff --git a/packages/plugin-lightningcss/modern.config.ts b/packages/plugin-lightningcss/modern.config.ts index 2f45b1e25f..50a5604bfe 100644 --- a/packages/plugin-lightningcss/modern.config.ts +++ b/packages/plugin-lightningcss/modern.config.ts @@ -1,9 +1,9 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs.map((config) => { + buildConfig: dualBuildConfigs.map((config) => { if (config.format === 'cjs') { // add loader to entry config.input = ['src/index.ts', 'src/loader.ts']; diff --git a/packages/plugin-lightningcss/package.json b/packages/plugin-lightningcss/package.json index c2db41bd83..6c78336ff9 100644 --- a/packages/plugin-lightningcss/package.json +++ b/packages/plugin-lightningcss/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-lightningcss", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "lightningcss for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-lightningcss" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,7 +27,7 @@ }, "dependencies": { "@rsbuild/shared": "workspace:*", - "lightningcss": "^1.24.1" + "lightningcss": "^1.25.0" }, "devDependencies": { "@rsbuild/core": "workspace:*", @@ -36,7 +36,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-lightningcss/src/loader.ts b/packages/plugin-lightningcss/src/loader.ts index 226b71008a..6d03ffafd1 100644 --- a/packages/plugin-lightningcss/src/loader.ts +++ b/packages/plugin-lightningcss/src/loader.ts @@ -4,7 +4,7 @@ import { Buffer } from 'node:buffer'; * MIT License https://github.com/fz6m/lightningcss-loader/blob/main/LICENSE * Author @fz6m */ -import type { Rspack } from '@rsbuild/shared'; +import type { Rspack } from '@rsbuild/core'; import { transform as _transform } from 'lightningcss'; import type { LightningCSSLoaderOptions } from './types'; diff --git a/packages/plugin-lightningcss/src/minimizer.ts b/packages/plugin-lightningcss/src/minimizer.ts index c5ba21a0ad..1a7b64fc2e 100644 --- a/packages/plugin-lightningcss/src/minimizer.ts +++ b/packages/plugin-lightningcss/src/minimizer.ts @@ -1,6 +1,5 @@ import { Buffer } from 'node:buffer'; -import { CSS_REGEX } from '@rsbuild/shared'; -import type { Rspack } from '@rsbuild/shared'; +import type { Rspack } from '@rsbuild/core'; /** * modified from https://github.com/fz6m/lightningcss-loader * MIT License https://github.com/fz6m/lightningcss-loader/blob/main/LICENSE @@ -11,6 +10,8 @@ import type { LightningCSSMinifyPluginOptions } from './types'; const PLUGIN_NAME = 'lightningcss-minify-plugin'; +const CSS_REGEX = /\.css$/; + export class LightningCSSMinifyPlugin { private readonly options: LightningCSSMinifyPluginOptions; diff --git a/packages/plugin-lightningcss/src/plugin.ts b/packages/plugin-lightningcss/src/plugin.ts index df8b6cad7d..4cc7760fb7 100644 --- a/packages/plugin-lightningcss/src/plugin.ts +++ b/packages/plugin-lightningcss/src/plugin.ts @@ -1,17 +1,15 @@ import path from 'node:path'; -import { - getBrowserslistWithDefault, - mergeChainedOptions, - parseMinifyOptions, -} from '@rsbuild/shared'; import type { - BundlerChain, - ModifyBundlerChainUtils, NormalizedConfig, RsbuildContext, RsbuildPlugin, RsbuildTarget, +} from '@rsbuild/core'; +import { + getBrowserslistWithDefault, + mergeChainedOptions, } from '@rsbuild/shared'; +import type { BundlerChain, ModifyBundlerChainUtils } from '@rsbuild/shared'; import browserslist from '@rsbuild/shared/browserslist'; import { browserslistToTargets as _browserslistToTargets } from 'lightningcss'; import type * as LightningCSS from 'lightningcss'; @@ -101,7 +99,7 @@ const applyLightningCSSLoader = ({ const rule = chain.module.rule(ruleId); const use = rule.use(CHAIN_ID.USE.LIGHTNINGCSS); - use.loader(path.resolve(__dirname, './loader')).options(mergedOptions); + use.loader(path.resolve(__dirname, './loader.cjs')).options(mergedOptions); switch (ruleId) { case CHAIN_ID.RULE.SASS: @@ -164,7 +162,7 @@ export const pluginLightningcss = ( setup(api) { api.modifyBundlerChain(async (chain, utils) => { - const { isServer, isWebWorker, isProd, target } = utils; + const { isProd, target } = utils; const { context } = api; const config = api.getNormalizedConfig(); const targets = await getLightningCSSTargets({ @@ -174,7 +172,7 @@ export const pluginLightningcss = ( options, }); - if (!isServer && !isWebWorker && options?.transform !== false) { + if (target === 'web' && options?.transform !== false) { applyLightningCSSLoader({ chain, utils, @@ -183,10 +181,10 @@ export const pluginLightningcss = ( }); } + const { minify } = config.output; const isMinimize = isProd && - config.output.minify !== false && - parseMinifyOptions(config).minifyCss; + (minify === true || (typeof minify === 'object' && minify.css)); if (isMinimize && options?.minify !== false) { await applyLightningCSSMinifyPlugin({ diff --git a/packages/plugin-lightningcss/tests/__snapshots__/index.test.ts.snap b/packages/plugin-lightningcss/tests/__snapshots__/index.test.ts.snap index 355787a454..56332db4da 100644 --- a/packages/plugin-lightningcss/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-lightningcss/tests/__snapshots__/index.test.ts.snap @@ -5,268 +5,175 @@ exports[`plugins/lightningcss > plugin-lightningcss should be cancelable by user exports[`plugins/lightningcss > plugin-lightningcss should be configurable by users 1`] = ` [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "cssModules": { - "dashedIdents": true, - "pattern": "[hash]-[local]", - }, - "errorRecovery": true, - "implementation": { - "browserslistToTargets": [Function], - "transform": [Function], - }, - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - "visitor": { - "Length": [Function], - }, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "cssModules": { - "dashedIdents": true, - "pattern": "[hash]-[local]", - }, - "errorRecovery": true, - "implementation": { - "browserslistToTargets": [Function], - "transform": [Function], - }, - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - "visitor": { - "Length": [Function], - }, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "cssModules": { + "dashedIdents": true, + "pattern": "[hash]-[local]", + }, + "errorRecovery": true, + "implementation": { + "browserslistToTargets": [Function], + "transform": [Function], + }, + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, + }, + "visitor": { + "Length": [Function], }, - ], + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "cssModules": { - "dashedIdents": true, - "pattern": "[hash]-[local]", - }, - "errorRecovery": true, - "implementation": { - "browserslistToTargets": [Function], - "transform": [Function], - }, - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - "visitor": { - "Length": [Function], - }, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "cssModules": { + "dashedIdents": true, + "pattern": "[hash]-[local]", + }, + "errorRecovery": true, + "implementation": { + "browserslistToTargets": [Function], + "transform": [Function], + }, + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, + }, + "visitor": { + "Length": [Function], }, - ], + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/node_modules", + ], + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "cssModules": { - "dashedIdents": true, - "pattern": "[hash]-[local]", - }, - "errorRecovery": true, - "implementation": { - "browserslistToTargets": [Function], - "transform": [Function], - }, - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - "visitor": { - "Length": [Function], - }, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "cssModules": { - "dashedIdents": true, - "pattern": "[hash]-[local]", - }, - "errorRecovery": true, - "implementation": { - "browserslistToTargets": [Function], - "transform": [Function], - }, - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - "visitor": { - "Length": [Function], - }, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "cssModules": { + "dashedIdents": true, + "pattern": "[hash]-[local]", + }, + "errorRecovery": true, + "implementation": { + "browserslistToTargets": [Function], + "transform": [Function], + }, + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, + }, + "visitor": { + "Length": [Function], }, - ], + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "cssModules": { - "dashedIdents": true, - "pattern": "[hash]-[local]", - }, - "errorRecovery": true, - "implementation": { - "browserslistToTargets": [Function], - "transform": [Function], - }, - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - "visitor": { - "Length": [Function], - }, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ] `; @@ -316,196 +223,139 @@ exports[`plugins/lightningcss > plugin-lightningcss should be configurable by us exports[`plugins/lightningcss > plugin-lightningcss should be configurable by users with true options 1`] = ` [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, }, - ], + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, }, - ], + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/node_modules", + ], + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, }, - ], + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ] `; @@ -549,196 +399,139 @@ exports[`plugins/lightningcss > plugin-lightningcss should not set lightningCssM exports[`plugins/lightningcss > plugin-lightningcss should replace postcss-loader with lightningcss-loader with default options 1`] = ` [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, }, - ], + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, }, - ], + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/node_modules", + ], + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + }, + { + "loader": "/packages/plugin-lightningcss/src/loader.cjs", + "options": { + "targets": { + "chrome": 5701632, + "edge": 5767168, + "firefox": 5111808, + "safari": 917504, }, - ], + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/plugin-lightningcss/src/loader", - "options": { - "targets": { - "chrome": 5701632, - "edge": 5767168, - "firefox": 5111808, - "safari": 917504, - }, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ] `; diff --git a/packages/plugin-lightningcss/tests/index.test.ts b/packages/plugin-lightningcss/tests/index.test.ts index f11a0cff39..b14d1b42b1 100644 --- a/packages/plugin-lightningcss/tests/index.test.ts +++ b/packages/plugin-lightningcss/tests/index.test.ts @@ -1,14 +1,10 @@ -import { createRsbuild } from '@rsbuild/core'; -import { - type RspackConfig, - type RuleSetRule, - isPlainObject, -} from '@rsbuild/shared'; +import { type Rspack, createRsbuild } from '@rsbuild/core'; +import { isPlainObject } from '@rsbuild/shared'; import { createStubRsbuild } from '@scripts/test-helper'; import { describe, expect, it } from 'vitest'; import { lightningcss, pluginLightningcss } from '../src'; -const getCssRules = (rspackConfig: RspackConfig) => { +const getCSSRules = (rspackConfig: Rspack.Configuration) => { const CSS_RULES = ['css', 'scss', 'sass', 'less', 'stylus']; return ( @@ -19,7 +15,7 @@ const getCssRules = (rspackConfig: RspackConfig) => { item.test?.toString().replace(/[\W]/g, '').includes(txt), ); return isRule; - }) as RuleSetRule[]) ?? [] + }) as Rspack.RuleSetRule[]) ?? [] ); }; @@ -32,7 +28,7 @@ describe('plugins/lightningcss', () => { }); const bundlerConfigs = await rsbuild.initConfigs(); - const cssRules = getCssRules(bundlerConfigs[0]); + const cssRules = getCSSRules(bundlerConfigs[0]); expect(cssRules).toMatchSnapshot(); expect(cssRules).not.contain('postcss-loader'); }); @@ -138,7 +134,7 @@ describe('plugins/lightningcss', () => { }); const bundlerConfigs = await rsbuild.initConfigs(); - const cssRules = getCssRules(bundlerConfigs[0]); + const cssRules = getCSSRules(bundlerConfigs[0]); expect(cssRules).toMatchSnapshot(); expect(cssRules).not.contain('postcss-loader'); @@ -161,7 +157,7 @@ describe('plugins/lightningcss', () => { }); const bundlerConfigs = await rsbuild.initConfigs(); - const cssRules = getCssRules(bundlerConfigs[0]); + const cssRules = getCSSRules(bundlerConfigs[0]); expect(cssRules).toMatchSnapshot(); expect(cssRules).not.contain('postcss-loader'); diff --git a/packages/plugin-mdx/modern.config.ts b/packages/plugin-mdx/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-mdx/modern.config.ts +++ b/packages/plugin-mdx/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-mdx/package.json b/packages/plugin-mdx/package.json index ee5eb8dac5..67f6e91377 100644 --- a/packages/plugin-mdx/package.json +++ b/packages/plugin-mdx/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-mdx", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Mdx plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-mdx" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -36,7 +36,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap b/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap index a936d5652d..7f0e0eaa99 100644 --- a/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-mdx/tests/__snapshots__/index.test.ts.snap @@ -24,7 +24,7 @@ exports[`plugin-mdx > should allow to configure mdx loader 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -69,7 +69,7 @@ exports[`plugin-mdx > should register mdx loader correctly 1`] = ` "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { diff --git a/packages/plugin-node-polyfill/modern.config.ts b/packages/plugin-node-polyfill/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-node-polyfill/modern.config.ts +++ b/packages/plugin-node-polyfill/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-node-polyfill/package.json b/packages/plugin-node-polyfill/package.json index f86d905a40..74c1d8d34c 100644 --- a/packages/plugin-node-polyfill/package.json +++ b/packages/plugin-node-polyfill/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-node-polyfill", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Node polyfill plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-node-polyfill" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,7 +27,6 @@ "dev": "modern build --watch" }, "dependencies": { - "@rsbuild/shared": "workspace:*", "assert": "^2.1.0", "browserify-zlib": "^0.2.0", "buffer": "^5.7.1", @@ -57,7 +56,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-preact/modern.config.ts b/packages/plugin-preact/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-preact/modern.config.ts +++ b/packages/plugin-preact/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-preact/package.json b/packages/plugin-preact/package.json index 44b8592552..a553c0a8f0 100644 --- a/packages/plugin-preact/package.json +++ b/packages/plugin-preact/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-preact", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Preact plugin for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-preact" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -34,7 +34,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-preact/src/index.ts b/packages/plugin-preact/src/index.ts index b0be11a314..b4e997f1f0 100644 --- a/packages/plugin-preact/src/index.ts +++ b/packages/plugin-preact/src/index.ts @@ -28,6 +28,11 @@ export const pluginPreact = ( tools: { swc: { jsc: { + parser: { + syntax: 'typescript', + // enable supports for JSX/TSX compilation + tsx: true, + }, transform: { react: reactOptions, }, diff --git a/packages/plugin-pug/modern.config.ts b/packages/plugin-pug/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-pug/modern.config.ts +++ b/packages/plugin-pug/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-pug/package.json b/packages/plugin-pug/package.json index 9f6316b25a..18136dbe29 100644 --- a/packages/plugin-pug/package.json +++ b/packages/plugin-pug/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-pug", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Pug plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-pug" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -36,7 +36,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-react/modern.config.ts b/packages/plugin-react/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-react/modern.config.ts +++ b/packages/plugin-react/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json index b7b24387c3..83574ebaa9 100644 --- a/packages/plugin-react/package.json +++ b/packages/plugin-react/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-react", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "React plugin for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-react" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,7 +27,7 @@ }, "dependencies": { "@rsbuild/shared": "workspace:*", - "@rspack/plugin-react-refresh": "0.6.5", + "@rspack/plugin-react-refresh": "0.7.0-beta.0", "react-refresh": "^0.14.2" }, "devDependencies": { @@ -37,7 +37,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-react/src/react.ts b/packages/plugin-react/src/react.ts index d841d2f777..09a67135ec 100644 --- a/packages/plugin-react/src/react.ts +++ b/packages/plugin-react/src/react.ts @@ -1,12 +1,35 @@ import path from 'node:path'; -import type { RsbuildConfig, RsbuildPluginAPI, Rspack } from '@rsbuild/core'; -import { - SCRIPT_REGEX, - isUsingHMR, - modifySwcLoaderOptions, -} from '@rsbuild/shared'; +import type { + BundlerChain, + ChainIdentifier, + RsbuildConfig, + RsbuildPluginAPI, + Rspack, +} from '@rsbuild/core'; +import { SCRIPT_REGEX, deepmerge, isUsingHMR } from '@rsbuild/shared'; import type { PluginReactOptions } from '.'; +const modifySwcLoaderOptions = ({ + chain, + CHAIN_ID, + modifier, +}: { + chain: BundlerChain; + CHAIN_ID: ChainIdentifier; + modifier: (config: Rspack.SwcLoaderOptions) => Rspack.SwcLoaderOptions; +}) => { + const ruleIds = [CHAIN_ID.RULE.JS, CHAIN_ID.RULE.JS_DATA_URI]; + + for (const ruleId of ruleIds) { + if (chain.module.rules.has(ruleId)) { + const rule = chain.module.rule(ruleId); + if (rule.uses.has(CHAIN_ID.USE.SWC)) { + rule.use(CHAIN_ID.USE.SWC).tap(modifier); + } + } + } +}; + export const applyBasicReactSupport = ( api: RsbuildPluginAPI, options: PluginReactOptions, @@ -25,14 +48,22 @@ export const applyBasicReactSupport = ( modifySwcLoaderOptions({ chain, + CHAIN_ID, modifier: (opts) => { - opts.jsc ??= {}; - opts.jsc.transform ??= {}; - opts.jsc.transform.react = { - ...opts.jsc.transform.react, - ...reactOptions, + const extraOptions: Rspack.SwcLoaderOptions = { + jsc: { + parser: { + syntax: 'typescript', + // enable supports for React JSX/TSX compilation + tsx: true, + }, + transform: { + react: reactOptions, + }, + }, }; - return opts; + + return deepmerge(opts, extraOptions); }, }); diff --git a/packages/plugin-react/src/splitChunks.ts b/packages/plugin-react/src/splitChunks.ts index 466a91ba0c..0a0c37311c 100644 --- a/packages/plugin-react/src/splitChunks.ts +++ b/packages/plugin-react/src/splitChunks.ts @@ -1,10 +1,5 @@ -import type { RsbuildPluginAPI } from '@rsbuild/core'; -import { - type SplitChunks, - createCacheGroups, - isPlainObject, - isProd, -} from '@rsbuild/shared'; +import type { RsbuildPluginAPI, SplitChunks } from '@rsbuild/core'; +import { createCacheGroups, isPlainObject, isProd } from '@rsbuild/shared'; import type { SplitReactChunkOptions } from '.'; export const applySplitChunksRule = ( diff --git a/packages/plugin-react/tests/__snapshots__/index.test.ts.snap b/packages/plugin-react/tests/__snapshots__/index.test.ts.snap index 395c97efdb..48a1f7449c 100644 --- a/packages/plugin-react/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-react/tests/__snapshots__/index.test.ts.snap @@ -28,6 +28,7 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "experiments": { "asyncWebAssembly": true, + "css": false, }, "ignoreWarnings": [ /Conflicting order/, @@ -37,17 +38,7 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "mode": "development", "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, "parser": { - "css/module": { - "namedExports": false, - }, "javascript": { "exportsPresence": "error", }, @@ -180,7 +171,7 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -207,7 +198,7 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -234,7 +225,7 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -261,7 +252,7 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -278,316 +269,199 @@ exports[`plugins/react > should work with swc-loader 1`] = ` "type": "asset/resource", }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/plugin-react/tests/node_modules", - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/plugin-react/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/plugin-react/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, @@ -633,8 +507,6 @@ exports[`plugins/react > should work with swc-loader 1`] = ` }, "output": { "chunkFilename": "static/js/async/[name].js", - "cssChunkFilename": "static/css/async/[name].css", - "cssFilename": "static/css/[name].css", "filename": "static/js/[name].js", "hashFunction": "xxhash64", "path": "/packages/plugin-react/tests/dist", @@ -649,6 +521,13 @@ exports[`plugins/react > should work with swc-loader 1`] = ` HotModuleReplacementPlugin { "name": "HotModuleReplacementPlugin", }, + CssExtractRspackPlugin { + "options": { + "chunkFilename": "static/css/async/[name].css", + "filename": "static/css/[name].css", + "ignoreOrder": true, + }, + }, HtmlWebpackPlugin { "options": { "base": false, @@ -716,9 +595,6 @@ exports[`plugins/react > should work with swc-loader 1`] = ` "affectedHooks": "compilation", "name": "DefinePlugin", }, - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, ReactRefreshRspackPlugin { "options": { "exclude": /node_modules/i, diff --git a/packages/plugin-react/tests/features.test.ts b/packages/plugin-react/tests/features.test.ts index 3445365b98..7a5e00fc97 100644 --- a/packages/plugin-react/tests/features.test.ts +++ b/packages/plugin-react/tests/features.test.ts @@ -1,4 +1,3 @@ -import { SCRIPT_REGEX } from '@rsbuild/shared'; import { createStubRsbuild } from '@scripts/test-helper'; import { describe, expect, it, vi } from 'vitest'; import { pluginReact } from '../src'; diff --git a/packages/plugin-rem/modern.config.ts b/packages/plugin-rem/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-rem/modern.config.ts +++ b/packages/plugin-rem/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-rem/package.json b/packages/plugin-rem/package.json index 2cb3ed54c1..a00fe9d4ff 100644 --- a/packages/plugin-rem/package.json +++ b/packages/plugin-rem/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-rem", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Rem plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-rem" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist", @@ -41,7 +41,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-rem/src/AutoSetRootFontSizePlugin.ts b/packages/plugin-rem/src/AutoSetRootFontSizePlugin.ts index 4b65b6d4ed..48ccc81487 100644 --- a/packages/plugin-rem/src/AutoSetRootFontSizePlugin.ts +++ b/packages/plugin-rem/src/AutoSetRootFontSizePlugin.ts @@ -1,8 +1,6 @@ import path from 'node:path'; -import { logger } from '@rsbuild/core'; +import { type Rspack, type ScriptLoading, logger } from '@rsbuild/core'; import { - type Rspack, - type ScriptLoading, generateScriptTag, getPublicPathFromCompiler, isProd, diff --git a/packages/plugin-rem/src/index.ts b/packages/plugin-rem/src/index.ts index 0f47975bb0..ebe4263097 100644 --- a/packages/plugin-rem/src/index.ts +++ b/packages/plugin-rem/src/index.ts @@ -1,5 +1,5 @@ -import type { RsbuildPlugin } from '@rsbuild/core'; -import { type PostCSSPlugin, getDistPath } from '@rsbuild/shared'; +import type { PostCSSPlugin, RsbuildPlugin } from '@rsbuild/core'; +import { getDistPath } from '@rsbuild/shared'; import { cloneDeep } from '@rsbuild/shared'; import type { PluginRemOptions, PxToRemOptions } from './types'; diff --git a/packages/plugin-rem/tests/__snapshots__/index.test.ts.snap b/packages/plugin-rem/tests/__snapshots__/index.test.ts.snap index 79e538c8ca..54601c42d2 100644 --- a/packages/plugin-rem/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-rem/tests/__snapshots__/index.test.ts.snap @@ -2,248 +2,150 @@ exports[`plugin-rem > should not run htmlPlugin with enableRuntime is false 1`] = ` { + "experiments": { + "css": false, + }, "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, - "parser": { - "css/module": { - "namedExports": false, - }, - }, "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], + }, + { + "AtRule": [Function], + "Declaration": [Function], + "Once": [Function], + "postcssPlugin": "postcss-pxtorem", }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, ], }, - "plugins": [ - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, - ], } `; exports[`plugin-rem > should run rem plugin with custom config 1`] = ` { + "experiments": { + "css": false, + }, "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, - "parser": { - "css/module": { - "namedExports": false, - }, - }, "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], + }, + { + "AtRule": [Function], + "Declaration": [Function], + "Once": [Function], + "postcssPlugin": "postcss-pxtorem", }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, ], }, "plugins": [ - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, AutoSetRootFontSizePlugin { "HtmlPlugin": [Function], "distDir": "static/js", @@ -275,374 +177,227 @@ exports[`plugin-rem > should run rem plugin with custom config 1`] = ` exports[`plugin-rem > should run rem plugin with default config 1`] = ` { + "experiments": { + "css": false, + }, "module": { - "generator": { - "css/module": { - "exportsConvention": "camel-case", - "exportsOnly": false, - "localIdentName": "[path][name]__[local]-[hash:6]", - }, - }, - "parser": { - "css/module": { - "namedExports": false, - }, - }, "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, - ], - }, - "sourceMap": false, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], + }, + { + "AtRule": [Function], + "Declaration": [Function], + "Once": [Function], + "postcssPlugin": "postcss-pxtorem", }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.css\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.less\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/plugin-rem/tests/node_modules", - ], + { + "AtRule": [Function], + "Declaration": [Function], + "Once": [Function], + "postcssPlugin": "postcss-pxtorem", }, - "sourceMap": false, - }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/less-loader", - "options": { - "implementation": "/packages/shared/compiled/less", - "lessOptions": { - "javascriptEnabled": true, - "paths": [ - "/packages/plugin-rem/tests/node_modules", - ], - }, - "sourceMap": false, - }, + "loader": "/packages/core/compiled/less-loader", + "options": { + "implementation": "/packages/shared/compiled/less", + "lessOptions": { + "javascriptEnabled": true, + "paths": [ + "/packages/plugin-rem/tests/node_modules", + ], }, - ], + "sourceMap": false, + }, }, ], - "test": /\\\\\\.less\\$/, }, { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 3, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, + { + "AtRule": [Function], + "Declaration": [Function], + "Once": [Function], + "postcssPlugin": "postcss-pxtorem", + }, + ], }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/resolve-url-loader", + "options": { + "join": [Function], + "sourceMap": false, + }, + }, + { + "loader": "/packages/shared/compiled/sass-loader", + "options": { + "implementation": "/packages/shared/compiled/sass", + "sourceMap": true, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - { - "AtRule": [Function], - "Declaration": [Function], - "Once": [Function], - "postcssPlugin": "postcss-pxtorem", - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/resolve-url-loader", - "options": { - "join": [Function], - "sourceMap": false, - }, - }, - { - "loader": "/packages/shared/compiled/sass-loader", - "options": { - "implementation": "/packages/shared/compiled/sass", - "sourceMap": true, - }, - }, - ], }, ], - "test": /\\\\\\.s\\(\\?:a\\|c\\)ss\\$/, }, ], }, "plugins": [ - RemoveCssSourcemapPlugin { - "name": "RemoveCssSourcemapPlugin", - }, AutoSetRootFontSizePlugin { "HtmlPlugin": [Function], "distDir": "static/js", diff --git a/packages/plugin-rem/tests/index.test.ts b/packages/plugin-rem/tests/index.test.ts index cf6effd859..469c130fe4 100644 --- a/packages/plugin-rem/tests/index.test.ts +++ b/packages/plugin-rem/tests/index.test.ts @@ -1,7 +1,7 @@ import { createStubRsbuild } from '@scripts/test-helper'; -import { pluginCss } from '../../core/src/provider/plugins/css'; -import { pluginLess } from '../../core/src/provider/plugins/less'; -import { pluginSass } from '../../core/src/provider/plugins/sass'; +import { pluginCss } from '../../core/src/plugins/css'; +import { pluginLess } from '../../core/src/plugins/less'; +import { pluginSass } from '../../core/src/plugins/sass'; import { pluginRem } from '../src'; describe('plugin-rem', () => { diff --git a/packages/plugin-solid/modern.config.ts b/packages/plugin-solid/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-solid/modern.config.ts +++ b/packages/plugin-solid/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-solid/package.json b/packages/plugin-solid/package.json index 4e044f5c16..62ba2fe9f0 100644 --- a/packages/plugin-solid/package.json +++ b/packages/plugin-solid/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-solid", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Solid plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-solid" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -39,7 +39,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-source-build/modern.config.ts b/packages/plugin-source-build/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-source-build/modern.config.ts +++ b/packages/plugin-source-build/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-source-build/package.json b/packages/plugin-source-build/package.json index 54d5632ce7..3255e289d6 100644 --- a/packages/plugin-source-build/package.json +++ b/packages/plugin-source-build/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-source-build", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Source build plugin of Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-source-build" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,8 +27,8 @@ "dev": "modern build --watch" }, "dependencies": { - "@rsbuild/monorepo-utils": "workspace:*", - "@rsbuild/shared": "workspace:*" + "@rsbuild/shared": "workspace:*", + "fast-glob": "^3.3.2" }, "devDependencies": { "@babel/core": "^7.24.5", @@ -38,7 +38,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/monorepo-utils/src/common/getBaseData.ts b/packages/plugin-source-build/src/common/getBaseData.ts similarity index 100% rename from packages/monorepo-utils/src/common/getBaseData.ts rename to packages/plugin-source-build/src/common/getBaseData.ts diff --git a/packages/monorepo-utils/src/common/getProjects.ts b/packages/plugin-source-build/src/common/getProjects.ts similarity index 100% rename from packages/monorepo-utils/src/common/getProjects.ts rename to packages/plugin-source-build/src/common/getProjects.ts diff --git a/packages/monorepo-utils/src/common/index.ts b/packages/plugin-source-build/src/common/index.ts similarity index 100% rename from packages/monorepo-utils/src/common/index.ts rename to packages/plugin-source-build/src/common/index.ts diff --git a/packages/monorepo-utils/src/common/isMonorepo.ts b/packages/plugin-source-build/src/common/isMonorepo.ts similarity index 100% rename from packages/monorepo-utils/src/common/isMonorepo.ts rename to packages/plugin-source-build/src/common/isMonorepo.ts diff --git a/packages/monorepo-utils/src/common/pnpm.ts b/packages/plugin-source-build/src/common/pnpm.ts similarity index 100% rename from packages/monorepo-utils/src/common/pnpm.ts rename to packages/plugin-source-build/src/common/pnpm.ts diff --git a/packages/monorepo-utils/src/common/rush.ts b/packages/plugin-source-build/src/common/rush.ts similarity index 100% rename from packages/monorepo-utils/src/common/rush.ts rename to packages/plugin-source-build/src/common/rush.ts diff --git a/packages/monorepo-utils/src/constants.ts b/packages/plugin-source-build/src/constants.ts similarity index 100% rename from packages/monorepo-utils/src/constants.ts rename to packages/plugin-source-build/src/constants.ts diff --git a/packages/plugin-source-build/src/index.ts b/packages/plugin-source-build/src/index.ts index a0c83a03e3..229216e470 100644 --- a/packages/plugin-source-build/src/index.ts +++ b/packages/plugin-source-build/src/index.ts @@ -1,161 +1,8 @@ -import fs from 'node:fs'; -import path from 'node:path'; -import type { RsbuildPlugin } from '@rsbuild/core'; -import { - type ExtraMonorepoStrategies, - type Project, - filterByField, - getDependentProjects, -} from '@rsbuild/monorepo-utils'; -import { TS_CONFIG_FILE, fse } from '@rsbuild/shared'; - -export const PLUGIN_SOURCE_BUILD_NAME = 'rsbuild:source-build'; - -export const getSourceInclude = async (options: { - projects: Project[]; - sourceField: string; -}) => { - const { projects, sourceField } = options; - - const includes = []; - for (const project of projects) { - includes.push( - ...project.getSourceEntryPaths({ field: sourceField, exports: true }), - ); - } - - return includes; -}; - -export interface PluginSourceBuildOptions { - /** - * Used to configure the resolve field of the source code files. - * @default 'source'' - */ - sourceField?: string; - /** - * Whether to read source code or output code first. - * @default 'source' - */ - resolvePriority?: 'source' | 'output'; - projectName?: string; - extraMonorepoStrategies?: ExtraMonorepoStrategies; -} - -export function pluginSourceBuild( - options?: PluginSourceBuildOptions, -): RsbuildPlugin { - const { - projectName, - sourceField = 'source', - resolvePriority = 'source', - extraMonorepoStrategies, - } = options ?? {}; - - return { - name: PLUGIN_SOURCE_BUILD_NAME, - - setup(api) { - const projectRootPath = api.context.rootPath; - - let projects: Project[] = []; - - api.modifyRsbuildConfig(async (config) => { - projects = await getDependentProjects(projectName || projectRootPath, { - cwd: projectRootPath, - recursive: true, - filter: filterByField(sourceField, true), - extraMonorepoStrategies, - }); - - const includes = await getSourceInclude({ - projects, - sourceField, - }); - - config.source = config.source ?? {}; - config.source.include = [...(config.source.include ?? []), ...includes]; - }); - - api.modifyBundlerChain((chain, { CHAIN_ID }) => { - for (const ruleId of [CHAIN_ID.RULE.TS, CHAIN_ID.RULE.JS]) { - if (chain.module.rules.get(ruleId)) { - const rule = chain.module.rule(ruleId); - - // https://rspack.dev/config/resolve - // when source is not exist, other mainFields will effect. // source > Rspack default mainFields. - rule.resolve.mainFields.merge( - resolvePriority === 'source' - ? [sourceField, '...'] - : ['...', sourceField], - ); - - // bundler-chain do not support resolve.conditionNames yet - rule.resolve.merge({ - // `conditionNames` is not affected by `resolvePriority`. - // The priority is controlled by the order of fields declared in `exports`. - conditionNames: ['...', sourceField], - }); - } - } - }); - - const getReferences = async (): Promise => { - const refers = projects - .map((project) => path.join(project.dir, TS_CONFIG_FILE)) - .filter((filePath) => fs.existsSync(filePath)); - - // merge with user references - if (api.context.tsconfigPath) { - const { default: json5 } = await import('@rsbuild/shared/json5'); - const { references } = json5.parse( - fse.readFileSync(api.context.tsconfigPath, 'utf-8'), - ); - - return Array.isArray(references) - ? references - .map((r) => r.path) - .filter(Boolean) - .concat(refers) - : refers; - } - - return refers; - }; - - if (api.context.bundlerType === 'rspack') { - api.modifyRspackConfig(async (config) => { - if (!api.context.tsconfigPath) { - return; - } - - config.resolve ||= {}; - config.resolve.tsConfig = { - ...config.resolve.tsConfig, - configFile: api.context.tsconfigPath, - references: await getReferences(), - }; - }); - } else { - api.modifyBundlerChain(async (chain, { CHAIN_ID }) => { - const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN; - - if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) { - return; - } - - const references = await getReferences(); - - // set references config - // https://github.com/dividab/tsconfig-paths-webpack-plugin#options - chain.resolve.plugin(TS_CONFIG_PATHS).tap((options) => - options.map((option) => ({ - ...option, - references, - })), - ); - }); - } - }, - }; -} +export { + PLUGIN_SOURCE_BUILD_NAME, + pluginSourceBuild, + type PluginSourceBuildOptions, +} from './plugin'; +export { Project } from './project'; +export { getMonorepoBaseData, getMonorepoSubProjects } from './common'; +export type { MonorepoAnalyzer } from './types'; diff --git a/packages/plugin-source-build/src/plugin.ts b/packages/plugin-source-build/src/plugin.ts new file mode 100644 index 0000000000..7fe4b3aaa0 --- /dev/null +++ b/packages/plugin-source-build/src/plugin.ts @@ -0,0 +1,160 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import type { RsbuildPlugin } from '@rsbuild/core'; +import type { Project } from './project'; +import { + type ExtraMonorepoStrategies, + filterByField, + getDependentProjects, +} from './project-utils'; + +export const PLUGIN_SOURCE_BUILD_NAME = 'rsbuild:source-build'; + +export const getSourceInclude = async (options: { + projects: Project[]; + sourceField: string; +}) => { + const { projects, sourceField } = options; + + const includes = []; + for (const project of projects) { + includes.push( + ...project.getSourceEntryPaths({ field: sourceField, exports: true }), + ); + } + + return includes; +}; + +export interface PluginSourceBuildOptions { + /** + * Used to configure the resolve field of the source code files. + * @default 'source'' + */ + sourceField?: string; + /** + * Whether to read source code or output code first. + * @default 'source' + */ + resolvePriority?: 'source' | 'output'; + projectName?: string; + extraMonorepoStrategies?: ExtraMonorepoStrategies; +} + +export function pluginSourceBuild( + options?: PluginSourceBuildOptions, +): RsbuildPlugin { + const { + projectName, + sourceField = 'source', + resolvePriority = 'source', + extraMonorepoStrategies, + } = options ?? {}; + + return { + name: PLUGIN_SOURCE_BUILD_NAME, + + setup(api) { + const projectRootPath = api.context.rootPath; + + let projects: Project[] = []; + + api.modifyRsbuildConfig(async (config) => { + projects = await getDependentProjects(projectName || projectRootPath, { + cwd: projectRootPath, + recursive: true, + filter: filterByField(sourceField, true), + extraMonorepoStrategies, + }); + + const includes = await getSourceInclude({ + projects, + sourceField, + }); + + config.source = config.source ?? {}; + config.source.include = [...(config.source.include ?? []), ...includes]; + }); + + api.modifyBundlerChain((chain, { CHAIN_ID }) => { + for (const ruleId of [CHAIN_ID.RULE.TS, CHAIN_ID.RULE.JS]) { + if (chain.module.rules.get(ruleId)) { + const rule = chain.module.rule(ruleId); + + // https://rspack.dev/config/resolve + // when source is not exist, other mainFields will effect. // source > Rspack default mainFields. + rule.resolve.mainFields.merge( + resolvePriority === 'source' + ? [sourceField, '...'] + : ['...', sourceField], + ); + + // bundler-chain do not support resolve.conditionNames yet + rule.resolve.merge({ + // `conditionNames` is not affected by `resolvePriority`. + // The priority is controlled by the order of fields declared in `exports`. + conditionNames: ['...', sourceField], + }); + } + } + }); + + const getReferences = async (): Promise => { + const refers = projects + .map((project) => path.join(project.dir, 'tsconfig.json')) + .filter((filePath) => fs.existsSync(filePath)); + + // merge with user references + if (api.context.tsconfigPath) { + const { default: json5 } = await import('@rsbuild/shared/json5'); + const { references } = json5.parse( + fs.readFileSync(api.context.tsconfigPath, 'utf-8'), + ); + + return Array.isArray(references) + ? references + .map((r) => r.path) + .filter(Boolean) + .concat(refers) + : refers; + } + + return refers; + }; + + if (api.context.bundlerType === 'rspack') { + api.modifyRspackConfig(async (config) => { + if (!api.context.tsconfigPath) { + return; + } + + config.resolve ||= {}; + config.resolve.tsConfig = { + ...config.resolve.tsConfig, + configFile: api.context.tsconfigPath, + references: await getReferences(), + }; + }); + } else { + api.modifyBundlerChain(async (chain, { CHAIN_ID }) => { + const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN; + + if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) { + return; + } + + const references = await getReferences(); + + // set references config + // https://github.com/dividab/tsconfig-paths-webpack-plugin#options + chain.resolve.plugin(TS_CONFIG_PATHS).tap((options) => + options.map((option) => ({ + ...option, + references, + })), + ); + }); + } + }, + }; +} diff --git a/packages/monorepo-utils/src/project-utils/filter.ts b/packages/plugin-source-build/src/project-utils/filter.ts similarity index 100% rename from packages/monorepo-utils/src/project-utils/filter.ts rename to packages/plugin-source-build/src/project-utils/filter.ts diff --git a/packages/monorepo-utils/src/project-utils/getDependentProjects.ts b/packages/plugin-source-build/src/project-utils/getDependentProjects.ts similarity index 100% rename from packages/monorepo-utils/src/project-utils/getDependentProjects.ts rename to packages/plugin-source-build/src/project-utils/getDependentProjects.ts diff --git a/packages/monorepo-utils/src/project-utils/index.ts b/packages/plugin-source-build/src/project-utils/index.ts similarity index 100% rename from packages/monorepo-utils/src/project-utils/index.ts rename to packages/plugin-source-build/src/project-utils/index.ts diff --git a/packages/monorepo-utils/src/project/index.ts b/packages/plugin-source-build/src/project/index.ts similarity index 100% rename from packages/monorepo-utils/src/project/index.ts rename to packages/plugin-source-build/src/project/index.ts diff --git a/packages/monorepo-utils/src/project/project.ts b/packages/plugin-source-build/src/project/project.ts similarity index 100% rename from packages/monorepo-utils/src/project/project.ts rename to packages/plugin-source-build/src/project/project.ts diff --git a/packages/monorepo-utils/src/types/index.ts b/packages/plugin-source-build/src/types/index.ts similarity index 100% rename from packages/monorepo-utils/src/types/index.ts rename to packages/plugin-source-build/src/types/index.ts diff --git a/packages/monorepo-utils/src/types/packageJson.ts b/packages/plugin-source-build/src/types/packageJson.ts similarity index 100% rename from packages/monorepo-utils/src/types/packageJson.ts rename to packages/plugin-source-build/src/types/packageJson.ts diff --git a/packages/monorepo-utils/src/types/rushJson.ts b/packages/plugin-source-build/src/types/rushJson.ts similarity index 100% rename from packages/monorepo-utils/src/types/rushJson.ts rename to packages/plugin-source-build/src/types/rushJson.ts diff --git a/packages/monorepo-utils/src/utils.ts b/packages/plugin-source-build/src/utils.ts similarity index 100% rename from packages/monorepo-utils/src/utils.ts rename to packages/plugin-source-build/src/utils.ts diff --git a/packages/plugin-styled-components/modern.config.ts b/packages/plugin-styled-components/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-styled-components/modern.config.ts +++ b/packages/plugin-styled-components/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-styled-components/package.json b/packages/plugin-styled-components/package.json index b4fda36941..08dd56e8e7 100644 --- a/packages/plugin-styled-components/package.json +++ b/packages/plugin-styled-components/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-styled-components", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "styled-components plugin for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-styled-components" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -34,7 +34,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-styled-components/src/index.ts b/packages/plugin-styled-components/src/index.ts index c7fbfe1ed4..42e1a7ff12 100644 --- a/packages/plugin-styled-components/src/index.ts +++ b/packages/plugin-styled-components/src/index.ts @@ -1,7 +1,9 @@ -import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core'; +import type { + ChainedConfig, + RsbuildConfig, + RsbuildPlugin, +} from '@rsbuild/core'; import { - type ChainedConfig, - getDefaultStyledComponentsConfig, getNodeEnv, isServerTarget, mergeChainedOptions, @@ -23,6 +25,17 @@ export type PluginStyledComponentsOptions = { cssProps?: boolean; }; +const getDefaultStyledComponentsConfig = (isProd: boolean, ssr: boolean) => { + return { + ssr, + // "pure" is used to improve dead code elimination in production. + // we don't need to enable it in development because it will slow down the build process. + pure: isProd, + displayName: true, + transpileTemplateLiterals: true, + }; +}; + export const pluginStyledComponents = ( pluginOptions: ChainedConfig = {}, ): RsbuildPlugin => ({ diff --git a/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap b/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap index 601284863a..07021d4f6d 100644 --- a/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-styled-components/tests/__snapshots__/index.test.ts.snap @@ -36,7 +36,7 @@ exports[`plugins/styled-components > should apply styledComponents option to swc "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -89,7 +89,7 @@ exports[`plugins/styled-components > should enable ssr option when target contai "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { @@ -148,7 +148,7 @@ exports[`plugins/styled-components > should enable ssr option when target contai "parser": { "decorators": true, "syntax": "typescript", - "tsx": true, + "tsx": false, }, "preserveAllComments": true, "transform": { diff --git a/packages/plugin-stylus/modern.config.ts b/packages/plugin-stylus/modern.config.ts index 429305ec29..b9f477c31b 100644 --- a/packages/plugin-stylus/modern.config.ts +++ b/packages/plugin-stylus/modern.config.ts @@ -1,9 +1,9 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs.map((config) => { + buildConfig: dualBuildConfigs.map((config) => { return { ...config, externals: ['@rsbuild/webpack/plugin-css'], diff --git a/packages/plugin-stylus/package.json b/packages/plugin-stylus/package.json index 42efe816f7..8e1a502b0d 100644 --- a/packages/plugin-stylus/package.json +++ b/packages/plugin-stylus/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-stylus", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Stylus plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-stylus" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -39,7 +39,7 @@ "webpack": "^5.91.0" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-stylus/src/index.ts b/packages/plugin-stylus/src/index.ts index d753145159..16b2b33e62 100644 --- a/packages/plugin-stylus/src/index.ts +++ b/packages/plugin-stylus/src/index.ts @@ -45,14 +45,8 @@ export function pluginStylus(options?: PluginStylusOptions): RsbuildPlugin { .rule(utils.CHAIN_ID.RULE.STYLUS) .test(STYLUS_REGEX); - const { bundlerType } = api.context; - const { applyBaseCSSRule } = await import( - bundlerType === 'webpack' - ? '@rsbuild/webpack/plugin-css' - : '@rsbuild/core/internal' - ); - - await applyBaseCSSRule({ + const { __internalHelper } = await import('@rsbuild/core'); + await __internalHelper.applyCSSRule({ rule, config, context: api.context, @@ -65,15 +59,6 @@ export function pluginStylus(options?: PluginStylusOptions): RsbuildPlugin { .loader(require.resolve('stylus-loader')) .options(mergedOptions); }); - - api.modifyRspackConfig(async (rspackConfig) => { - const { applyCSSModuleRule } = await import('@rsbuild/core/internal'); - - const config = api.getNormalizedConfig(); - const rules = rspackConfig.module?.rules; - - applyCSSModuleRule(rules, STYLUS_REGEX, config); - }); }, }; } diff --git a/packages/plugin-stylus/tests/__snapshots__/index.test.ts.snap b/packages/plugin-stylus/tests/__snapshots__/index.test.ts.snap index f2cbfe36ed..f052d65854 100644 --- a/packages/plugin-stylus/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-stylus/tests/__snapshots__/index.test.ts.snap @@ -5,102 +5,66 @@ exports[`plugin-stylus > should add stylus loader config correctly 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.styl\\(us\\)\\?\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - }, - }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//stylus-loader/dist/cjs.js", + "options": { + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - }, - }, - ], }, ], - "test": /\\\\\\.styl\\(us\\)\\?\\$/, }, ], }, @@ -112,108 +76,69 @@ exports[`plugin-stylus > should allow to configure stylus options 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.styl\\(us\\)\\?\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - "stylusOptions": { - "lineNumbers": false, - }, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - "stylusOptions": { - "lineNumbers": false, - }, - }, + "sourceMap": false, + }, + }, + { + "loader": "/node_modules//stylus-loader/dist/cjs.js", + "options": { + "sourceMap": false, + "stylusOptions": { + "lineNumbers": false, }, - ], + }, }, ], - "test": /\\\\\\.styl\\(us\\)\\?\\$/, }, ], }, diff --git a/packages/plugin-stylus/tests/__snapshots__/rspack.test.ts.snap b/packages/plugin-stylus/tests/__snapshots__/rspack.test.ts.snap index f2cbfe36ed..f052d65854 100644 --- a/packages/plugin-stylus/tests/__snapshots__/rspack.test.ts.snap +++ b/packages/plugin-stylus/tests/__snapshots__/rspack.test.ts.snap @@ -5,102 +5,66 @@ exports[`plugin-stylus > should add stylus loader config correctly 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.styl\\(us\\)\\?\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - }, - }, - ], + "sourceMap": false, + }, }, { - "resolve": { - "preferRelative": true, + "loader": "/node_modules//stylus-loader/dist/cjs.js", + "options": { + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - }, - }, - ], }, ], - "test": /\\\\\\.styl\\(us\\)\\?\\$/, }, ], }, @@ -112,108 +76,69 @@ exports[`plugin-stylus > should allow to configure stylus options 1`] = ` "module": { "rules": [ { - "oneOf": [ + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.styl\\(us\\)\\?\\$/, + "use": [ { - "resolve": { - "preferRelative": true, - }, - "sideEffects": true, - "test": /\\\\\\.module\\\\\\.\\\\w\\+\\$/i, - "type": "css/module", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, - ], - }, - "sourceMap": false, - }, - }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - "stylusOptions": { - "lineNumbers": false, - }, - }, - }, - ], + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", }, { - "resolve": { - "preferRelative": true, + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 2, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, }, - "sideEffects": true, - "type": "css", - "use": [ - { - "loader": "/packages/shared/compiled/postcss-loader", - "options": { - "postcssOptions": { - "config": false, - "plugins": [ - { - "browsers": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "info": [Function], - "options": { - "flexbox": "no-2009", - "overrideBrowserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - }, - "postcssPlugin": "autoprefixer", - "prepare": [Function], - }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], }, - "sourceMap": false, - }, + ], }, - { - "loader": "/node_modules//stylus-loader/dist/cjs.js", - "options": { - "sourceMap": false, - "stylusOptions": { - "lineNumbers": false, - }, - }, + "sourceMap": false, + }, + }, + { + "loader": "/node_modules//stylus-loader/dist/cjs.js", + "options": { + "sourceMap": false, + "stylusOptions": { + "lineNumbers": false, }, - ], + }, }, ], - "test": /\\\\\\.styl\\(us\\)\\?\\$/, }, ], }, diff --git a/packages/plugin-svelte/modern.config.ts b/packages/plugin-svelte/modern.config.ts index c8d42a9956..3ff9b2203b 100644 --- a/packages/plugin-svelte/modern.config.ts +++ b/packages/plugin-svelte/modern.config.ts @@ -1,3 +1,14 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default { + plugins: [moduleTools()], + buildConfig: dualBuildConfigs.map((config) => { + config.externals = [ + ...(config.externals || []), + 'svelte/compiler', + 'svelte-preprocess/dist/types', + ]; + return config; + }), +}; diff --git a/packages/plugin-svelte/package.json b/packages/plugin-svelte/package.json index d27228b900..097c7792c0 100644 --- a/packages/plugin-svelte/package.json +++ b/packages/plugin-svelte/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-svelte", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Svelte plugin for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-svelte" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -34,11 +34,11 @@ "@rsbuild/core": "workspace:*", "@scripts/test-helper": "workspace:*", "@types/node": "18.x", - "svelte": "^4.2.15", + "svelte": "^4.2.16", "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-svgr/modern.config.ts b/packages/plugin-svgr/modern.config.ts index 2f45b1e25f..50a5604bfe 100644 --- a/packages/plugin-svgr/modern.config.ts +++ b/packages/plugin-svgr/modern.config.ts @@ -1,9 +1,9 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs.map((config) => { + buildConfig: dualBuildConfigs.map((config) => { if (config.format === 'cjs') { // add loader to entry config.input = ['src/index.ts', 'src/loader.ts']; diff --git a/packages/plugin-svgr/package.json b/packages/plugin-svgr/package.json index c433c226bf..6f0057bcdc 100644 --- a/packages/plugin-svgr/package.json +++ b/packages/plugin-svgr/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-svgr", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "svgr plugin for Rsbuild", "repository": { "type": "git", @@ -8,15 +8,15 @@ "directory": "packages/plugin-svgr" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist", @@ -44,7 +44,7 @@ "url-loader": "4.1.1" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-svgr/src/index.ts b/packages/plugin-svgr/src/index.ts index 02b70c753e..628e68d150 100644 --- a/packages/plugin-svgr/src/index.ts +++ b/packages/plugin-svgr/src/index.ts @@ -3,7 +3,6 @@ import type { RsbuildPlugin, Rspack } from '@rsbuild/core'; import { PLUGIN_REACT_NAME } from '@rsbuild/plugin-react'; import { SCRIPT_REGEX, - SVG_REGEX, deepmerge, getDistPath, getFilename, @@ -12,6 +11,8 @@ import type { Config } from '@svgr/core'; export type SvgDefaultExport = 'component' | 'url'; +export const SVG_REGEX = /\.svg$/; + export type PluginSvgrOptions = { /** * Configure SVGR options. @@ -117,7 +118,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({ .type('javascript/auto') .resourceQuery(options.query || /react/) .use(CHAIN_ID.USE.SVGR) - .loader(path.resolve(__dirname, './loader')) + .loader(path.resolve(__dirname, './loader.cjs')) .options({ ...svgrOptions, exportType: 'default', @@ -145,7 +146,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({ // The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file. .set('issuer', issuer) .use(CHAIN_ID.USE.SVGR) - .loader(path.resolve(__dirname, './loader')) + .loader(path.resolve(__dirname, './loader.cjs')) .options({ ...svgrOptions, exportType, @@ -159,7 +160,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({ if (mixedImport && exportType === 'named') { svgRule .use(CHAIN_ID.USE.URL) - .loader(path.join(__dirname, '../compiled', 'url-loader')) + .loader(path.join(__dirname, '../compiled', 'url-loader/index.js')) .options({ limit: maxSize, name: outputName, diff --git a/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap b/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap index 597f688ce1..dd7142ce8a 100644 --- a/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap +++ b/packages/plugin-svgr/tests/__snapshots__/index.test.ts.snap @@ -55,7 +55,7 @@ exports[`svgr > 'configure SVGR options' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -83,7 +83,7 @@ exports[`svgr > 'configure SVGR options' 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -148,7 +148,7 @@ exports[`svgr > 'exportType default / mixedImport false' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -213,7 +213,7 @@ exports[`svgr > 'exportType default / mixedImport false' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -240,7 +240,7 @@ exports[`svgr > 'exportType default / mixedImport false' 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -305,7 +305,7 @@ exports[`svgr > 'exportType default / mixedImport true' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -370,7 +370,7 @@ exports[`svgr > 'exportType default / mixedImport true' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -397,7 +397,7 @@ exports[`svgr > 'exportType default / mixedImport true' 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -462,7 +462,7 @@ exports[`svgr > 'exportType named / mixedImport false' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -527,7 +527,7 @@ exports[`svgr > 'exportType named / mixedImport false' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "named", "svgo": true, @@ -554,7 +554,7 @@ exports[`svgr > 'exportType named / mixedImport false' 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", @@ -619,7 +619,7 @@ exports[`svgr > 'exportType named / mixedImport true' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "default", "svgo": true, @@ -684,7 +684,7 @@ exports[`svgr > 'exportType named / mixedImport true' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/src/loader", + "loader": "/packages/plugin-svgr/src/loader.cjs", "options": { "exportType": "named", "svgo": true, @@ -704,9 +704,9 @@ exports[`svgr > 'exportType named / mixedImport true' 1`] = ` }, }, { - "loader": "/packages/plugin-svgr/compiled/url-loader", + "loader": "/packages/plugin-svgr/compiled/url-loader/index.js", "options": { - "limit": 10000, + "limit": 4096, "name": "static/svg/[name].[contenthash:8].svg", }, }, @@ -718,7 +718,7 @@ exports[`svgr > 'exportType named / mixedImport true' 1`] = ` }, "parser": { "dataUrlCondition": { - "maxSize": 10000, + "maxSize": 4096, }, }, "type": "asset", diff --git a/packages/plugin-svgr/tests/index.test.ts b/packages/plugin-svgr/tests/index.test.ts index c72b191637..b6a5861592 100644 --- a/packages/plugin-svgr/tests/index.test.ts +++ b/packages/plugin-svgr/tests/index.test.ts @@ -1,8 +1,7 @@ import { pluginReact } from '@rsbuild/plugin-react'; -import { SVG_REGEX } from '@rsbuild/shared'; import { createStubRsbuild } from '@scripts/test-helper'; import { describe, expect, it } from 'vitest'; -import { type PluginSvgrOptions, pluginSvgr } from '../src'; +import { type PluginSvgrOptions, SVG_REGEX, pluginSvgr } from '../src'; describe('svgr', () => { const cases: Array<{ name: string; pluginConfig: PluginSvgrOptions }> = [ diff --git a/packages/plugin-toml/modern.config.ts b/packages/plugin-toml/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-toml/modern.config.ts +++ b/packages/plugin-toml/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-toml/package.json b/packages/plugin-toml/package.json index 3c933a9f76..049858608b 100644 --- a/packages/plugin-toml/package.json +++ b/packages/plugin-toml/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-toml", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "TOML plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-toml" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -27,7 +27,6 @@ "dev": "modern build --watch" }, "dependencies": { - "@rsbuild/shared": "workspace:*", "toml": "^3.0.0" }, "devDependencies": { @@ -35,7 +34,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-toml/tsconfig.json b/packages/plugin-toml/tsconfig.json index 0caaa55ade..c07e6fe949 100644 --- a/packages/plugin-toml/tsconfig.json +++ b/packages/plugin-toml/tsconfig.json @@ -9,9 +9,6 @@ "references": [ { "path": "../core" - }, - { - "path": "../shared" } ], "include": ["src"] diff --git a/packages/plugin-type-check/modern.config.ts b/packages/plugin-type-check/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-type-check/modern.config.ts +++ b/packages/plugin-type-check/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-type-check/package.json b/packages/plugin-type-check/package.json index 77d5b304e0..5986fdb0f9 100644 --- a/packages/plugin-type-check/package.json +++ b/packages/plugin-type-check/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-type-check", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "TS checker plugin of Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-type-check" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -37,7 +37,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-type-check/src/index.ts b/packages/plugin-type-check/src/index.ts index e5bb2d57bc..a8ace7c62c 100644 --- a/packages/plugin-type-check/src/index.ts +++ b/packages/plugin-type-check/src/index.ts @@ -1,7 +1,6 @@ -import { type RsbuildPlugin, logger } from '@rsbuild/core'; +import { type ChainedConfig, type RsbuildPlugin, logger } from '@rsbuild/core'; import { CHAIN_ID, - type ChainedConfig, NODE_MODULES_REGEX, deepmerge, fse, diff --git a/packages/monorepo-utils/LICENSE b/packages/plugin-typed-css-modules/LICENSE similarity index 100% rename from packages/monorepo-utils/LICENSE rename to packages/plugin-typed-css-modules/LICENSE diff --git a/packages/monorepo-utils/README.md b/packages/plugin-typed-css-modules/README.md similarity index 100% rename from packages/monorepo-utils/README.md rename to packages/plugin-typed-css-modules/README.md diff --git a/packages/plugin-typed-css-modules/modern.config.ts b/packages/plugin-typed-css-modules/modern.config.ts new file mode 100644 index 0000000000..50a5604bfe --- /dev/null +++ b/packages/plugin-typed-css-modules/modern.config.ts @@ -0,0 +1,13 @@ +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; + +export default { + plugins: [moduleTools()], + buildConfig: dualBuildConfigs.map((config) => { + if (config.format === 'cjs') { + // add loader to entry + config.input = ['src/index.ts', 'src/loader.ts']; + } + return config; + }), +}; diff --git a/packages/plugin-typed-css-modules/package.json b/packages/plugin-typed-css-modules/package.json new file mode 100644 index 0000000000..cc8e7a95d4 --- /dev/null +++ b/packages/plugin-typed-css-modules/package.json @@ -0,0 +1,49 @@ +{ + "name": "@rsbuild/plugin-typed-css-modules", + "version": "0.7.0-beta.5", + "description": "Generate TypeScript declaration file for CSS Modules", + "homepage": "https://rsbuild.dev", + "repository": { + "type": "git", + "url": "https://github.com/web-infra-dev/rsbuild", + "directory": "packages/plugin-typed-css-modules" + }, + "license": "MIT", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "main": "./dist/index.cjs", + "types": "./dist/index.d.ts", + "files": [ + "dist", + "compiled" + ], + "scripts": { + "build": "modern build", + "dev": "modern build --watch", + "prebundle": "prebundle" + }, + "dependencies": { + "@rsbuild/shared": "workspace:*" + }, + "devDependencies": { + "@rsbuild/core": "workspace:*", + "@scripts/test-helper": "workspace:*", + "typescript": "^5.4.2", + "line-diff": "2.1.1", + "prebundle": "1.1.0" + }, + "peerDependencies": { + "@rsbuild/core": "workspace:^0.7.0-beta.5" + }, + "publishConfig": { + "access": "public", + "provenance": true, + "registry": "https://registry.npmjs.org/" + } +} diff --git a/packages/plugin-typed-css-modules/prebundle.config.mjs b/packages/plugin-typed-css-modules/prebundle.config.mjs new file mode 100644 index 0000000000..b18ce4184e --- /dev/null +++ b/packages/plugin-typed-css-modules/prebundle.config.mjs @@ -0,0 +1,10 @@ +// @ts-check +/** @type {import('prebundle').Config} */ +export default { + dependencies: [ + { + name: 'line-diff', + ignoreDts: true, + }, + ], +}; diff --git a/packages/plugin-typed-css-modules/src/index.ts b/packages/plugin-typed-css-modules/src/index.ts new file mode 100644 index 0000000000..64a4a5905f --- /dev/null +++ b/packages/plugin-typed-css-modules/src/index.ts @@ -0,0 +1,56 @@ +import path from 'node:path'; +import type { CSSLoaderOptions, RsbuildPlugin } from '@rsbuild/core'; + +const PLUGIN_NAME = 'rsbuild:typed-css-modules'; + +export const pluginTypedCSSModules = (): RsbuildPlugin => ({ + name: PLUGIN_NAME, + + setup(api) { + api.modifyBundlerChain({ + order: 'post', + handler: async (chain, { target, CHAIN_ID }) => { + if (target === 'web') { + const ruleIds = [ + CHAIN_ID.RULE.CSS, + CHAIN_ID.RULE.SASS, + CHAIN_ID.RULE.LESS, + CHAIN_ID.RULE.STYLUS, + ]; + + for (const ruleId of ruleIds) { + if (!chain.module.rules.has(ruleId)) { + continue; + } + + const rule = chain.module.rule(ruleId); + + if (!rule.uses.has(CHAIN_ID.USE.CSS)) { + continue; + } + + const cssLoaderOptions: CSSLoaderOptions = rule + .use(CHAIN_ID.USE.CSS) + .get('options'); + + if ( + !cssLoaderOptions.modules || + (typeof cssLoaderOptions.modules === 'object' && + cssLoaderOptions.modules.auto === false) + ) { + continue; + } + + rule + .use(CHAIN_ID.USE.CSS_MODULES_TS) + .loader(path.resolve(__dirname, './loader.cjs')) + .options({ + modules: cssLoaderOptions.modules, + }) + .before(CHAIN_ID.USE.CSS); + } + } + }, + }); + }, +}); diff --git a/packages/shared/src/loaders/cssModulesTypescriptLoader.ts b/packages/plugin-typed-css-modules/src/loader.ts similarity index 74% rename from packages/shared/src/loaders/cssModulesTypescriptLoader.ts rename to packages/plugin-typed-css-modules/src/loader.ts index 1807eee055..fee54c54aa 100644 --- a/packages/shared/src/loaders/cssModulesTypescriptLoader.ts +++ b/packages/plugin-typed-css-modules/src/loader.ts @@ -12,9 +12,20 @@ import fs from 'node:fs'; import path from 'node:path'; -import type { LoaderContext } from '@rspack/core'; -import LineDiff from '../../compiled/line-diff'; -import { type CssLoaderModules, isCssModules, isInNodeModules } from '../css'; +import type { Rspack } from '@rsbuild/core'; +import { NODE_MODULES_REGEX } from '@rsbuild/shared'; +import LineDiff from '../compiled/line-diff/index.js'; + +export type CssLoaderModules = + | boolean + | string + | { + auto: boolean | RegExp | ((filename: string) => boolean); + }; + +export const isInNodeModules = (path: string) => NODE_MODULES_REGEX.test(path); + +export const CSS_MODULES_REGEX = /\.module\.\w+$/i; const bannerMessage = '// This file is automatically generated.\n// Please do not change this file!'; @@ -27,6 +38,32 @@ const getNoDeclarationFileError = ({ filename }: { filename: string }) => `Generated type declaration does not exist. Run webpack and commit the type declaration for '${filename}'`, ); +export const isCSSModules = (filename: string, modules: CssLoaderModules) => { + if (typeof modules === 'boolean') { + return modules; + } + + // Same as the `mode` option + // https://github.com/webpack-contrib/css-loader?tab=readme-ov-file#mode + if (typeof modules === 'string') { + // CSS Modules will be disabled if mode is 'global' + return modules !== 'global'; + } + + const { auto } = modules; + + if (typeof auto === 'boolean') { + return auto && CSS_MODULES_REGEX.test(filename); + } + if (auto instanceof RegExp) { + return auto.test(filename); + } + if (typeof auto === 'function') { + return auto(filename); + } + return true; +}; + const getTypeMismatchError = ({ filename, expected, @@ -56,8 +93,8 @@ export function wrapQuotes(key: string) { return `'${key}'`; } -const cssModuleToInterface = (cssModuleKeys: string[]) => { - const interfaceFields = cssModuleKeys +const cssModuleToInterface = (cssModulesKeys: string[]) => { + const interfaceFields = cssModulesKeys .sort() .map((key) => ` ${wrapQuotes(key)}: string;`) .join('\n'); @@ -109,30 +146,30 @@ const extractLocalExports = (content: string) => { return localExports; }; -const getCssModuleKeys = (content: string) => { +const getCSSModulesKeys = (content: string) => { const keyRegex = /"([^\\"]+)":/g; - const cssModuleKeys = []; + const cssModulesKeys = []; const localExports = extractLocalExports(content); let match = keyRegex.exec(localExports); while (match !== null) { - if (cssModuleKeys.indexOf(match[1]) < 0) { - cssModuleKeys.push(match[1]); + if (cssModulesKeys.indexOf(match[1]) < 0) { + cssModulesKeys.push(match[1]); } match = keyRegex.exec(localExports); } - return cssModuleKeys; + return cssModulesKeys; }; export default function ( - this: LoaderContext<{ + this: Rspack.LoaderContext<{ mode: string; modules: CssLoaderModules; }> & { - cssModuleKeys?: string[]; + cssModulesKeys?: string[]; }, content: string, ...rest: any[] @@ -146,16 +183,16 @@ export default function ( return failed(new Error(`Invalid mode option: ${mode}`)); } - if (!isCssModules(filename, modules) || isInNodeModules(filename)) { + if (!isCSSModules(filename, modules) || isInNodeModules(filename)) { return success(); } const cssModuleInterfaceFilename = filenameToTypingsFilename(filename); const { read, write } = makeFileHandlers(cssModuleInterfaceFilename); - const cssModuleKeys = this.cssModuleKeys || getCssModuleKeys(content); + const cssModulesKeys = this.cssModulesKeys || getCSSModulesKeys(content); const cssModuleDefinition = `${bannerMessage}\n${cssModuleToInterface( - cssModuleKeys, + cssModulesKeys, )}\n${cssModuleExport}`; if (mode === 'verify') { diff --git a/packages/plugin-typed-css-modules/tests/__snapshots__/index.test.ts.snap b/packages/plugin-typed-css-modules/tests/__snapshots__/index.test.ts.snap new file mode 100644 index 0000000000..5ca01d4e8a --- /dev/null +++ b/packages/plugin-typed-css-modules/tests/__snapshots__/index.test.ts.snap @@ -0,0 +1,134 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`plugin-typed-css-modules > should apply css-modules-typescript-loader 1`] = ` +[ + { + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/plugin-typed-css-modules/src/loader.cjs", + "options": { + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + }, + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": true, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], + }, + ], + }, + "sourceMap": false, + }, + }, + ], + }, +] +`; + +exports[`plugin-typed-css-modules > should not apply css-modules-typescript-loader 1`] = ` +[ + { + "resolve": { + "preferRelative": true, + }, + "sideEffects": true, + "test": /\\\\\\.css\\$/, + "use": [ + { + "loader": "/node_modules//@rspack/core/dist/builtin-plugin/css-extract/loader.js", + }, + { + "loader": "/packages/core/compiled/css-loader", + "options": { + "importLoaders": 1, + "modules": { + "auto": false, + "exportLocalsConvention": "camelCase", + "localIdentName": "[path][name]__[local]-[hash:base64:6]", + "namedExport": false, + }, + "sourceMap": false, + }, + }, + { + "loader": "/packages/core/compiled/postcss-loader", + "options": { + "postcssOptions": { + "config": false, + "plugins": [ + { + "browsers": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + "info": [Function], + "options": { + "flexbox": "no-2009", + "overrideBrowserslist": [ + "chrome >= 87", + "edge >= 88", + "firefox >= 78", + "safari >= 14", + ], + }, + "postcssPlugin": "autoprefixer", + "prepare": [Function], + }, + ], + }, + "sourceMap": false, + }, + }, + ], + }, +] +`; diff --git a/packages/plugin-typed-css-modules/tests/helper.test.ts b/packages/plugin-typed-css-modules/tests/helper.test.ts new file mode 100644 index 0000000000..500ee77380 --- /dev/null +++ b/packages/plugin-typed-css-modules/tests/helper.test.ts @@ -0,0 +1,40 @@ +import { isCSSModules } from '../src/loader'; + +it('check isCSSModules', () => { + expect(isCSSModules('src/index.css', false)).toBeFalsy(); + expect(isCSSModules('src/index.css', { auto: false })).toBeFalsy(); + expect(isCSSModules('src/index.module.css', { auto: false })).toBeFalsy(); + + expect(isCSSModules('src/index.css', true)).toBeTruthy(); + + expect(isCSSModules('src/index.css', { auto: true })).toBeFalsy(); + expect(isCSSModules('src/index.module.css', { auto: true })).toBeTruthy(); + + expect( + isCSSModules('src/index.module.css', { + auto: (path) => { + return path.includes('.module.'); + }, + }), + ).toBeTruthy(); + + expect( + isCSSModules('src/index.css', { + auto: (path) => { + return path.includes('.module.'); + }, + }), + ).toBeFalsy(); + + expect( + isCSSModules('src/index.module.css', { + auto: /\.module\./i, + }), + ).toBeTruthy(); + + expect( + isCSSModules('src/index.css', { + auto: /\.module\./i, + }), + ).toBeFalsy(); +}); diff --git a/packages/plugin-typed-css-modules/tests/index.test.ts b/packages/plugin-typed-css-modules/tests/index.test.ts new file mode 100644 index 0000000000..280ed32828 --- /dev/null +++ b/packages/plugin-typed-css-modules/tests/index.test.ts @@ -0,0 +1,51 @@ +import type { Rspack, RspackRule } from '@rsbuild/core'; +import { createStubRsbuild } from '@scripts/test-helper'; +import { describe, expect, it } from 'vitest'; +import { pluginCss } from '../../core/src/plugins/css'; +import { pluginTypedCSSModules } from '../src'; + +function matchRules( + config: Rspack.Configuration, + testFile: string, +): RspackRule[] { + if (!config.module?.rules) { + return []; + } + return config.module.rules.filter((rule) => { + if ( + rule && + typeof rule === 'object' && + rule.test && + rule.test instanceof RegExp && + rule.test.test(testFile) + ) { + return true; + } + return false; + }); +} + +describe('plugin-typed-css-modules', () => { + it('should apply css-modules-typescript-loader', async () => { + const rsbuild = await createStubRsbuild({ + plugins: [pluginCss(), pluginTypedCSSModules()], + }); + const bundlerConfigs = await rsbuild.initConfigs(); + expect(matchRules(bundlerConfigs[0], 'a.css')).toMatchSnapshot(); + }); + + it('should not apply css-modules-typescript-loader', async () => { + const rsbuild = await createStubRsbuild({ + plugins: [pluginCss(), pluginTypedCSSModules()], + rsbuildConfig: { + output: { + cssModules: { + auto: false, + }, + }, + }, + }); + const bundlerConfigs = await rsbuild.initConfigs(); + expect(matchRules(bundlerConfigs[0], 'a.css')).toMatchSnapshot(); + }); +}); diff --git a/packages/shared/tests/loaders/wrapQuotes.test.ts b/packages/plugin-typed-css-modules/tests/loader.test.ts similarity index 88% rename from packages/shared/tests/loaders/wrapQuotes.test.ts rename to packages/plugin-typed-css-modules/tests/loader.test.ts index bde8bf4112..d4506837b7 100644 --- a/packages/shared/tests/loaders/wrapQuotes.test.ts +++ b/packages/plugin-typed-css-modules/tests/loader.test.ts @@ -1,4 +1,5 @@ -import { wrapQuotes } from '../../src/loaders/cssModulesTypescriptLoader'; +import { expect, it } from 'vitest'; +import { wrapQuotes } from '../src/loader'; it('should wrap key correctly', () => { // do not need wrap diff --git a/packages/plugin-typed-css-modules/tests/tsconfig.json b/packages/plugin-typed-css-modules/tests/tsconfig.json new file mode 100644 index 0000000000..9b63f390ce --- /dev/null +++ b/packages/plugin-typed-css-modules/tests/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "@rsbuild/tsconfig/base", + "compilerOptions": { + "baseUrl": "./", + "types": ["vitest/globals"] + }, + "include": ["./**/*.ts"] +} diff --git a/packages/monorepo-utils/tsconfig.json b/packages/plugin-typed-css-modules/tsconfig.json similarity index 100% rename from packages/monorepo-utils/tsconfig.json rename to packages/plugin-typed-css-modules/tsconfig.json diff --git a/packages/plugin-umd/modern.config.ts b/packages/plugin-umd/modern.config.ts index 68cfd3e5a2..1ffdd229e2 100644 --- a/packages/plugin-umd/modern.config.ts +++ b/packages/plugin-umd/modern.config.ts @@ -1,7 +1,7 @@ -import moduleTools from '@modern-js/module-tools'; -import { buildConfigWithMjs } from '../../scripts/modern.base.config'; +import { moduleTools } from '@modern-js/module-tools'; +import { dualBuildConfigs } from '../../scripts/modern.base.config'; export default { plugins: [moduleTools()], - buildConfig: buildConfigWithMjs, + buildConfig: dualBuildConfigs, }; diff --git a/packages/plugin-umd/package.json b/packages/plugin-umd/package.json index a60281a21b..5378b99663 100644 --- a/packages/plugin-umd/package.json +++ b/packages/plugin-umd/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-umd", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "UMD plugin for Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-umd" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -35,7 +35,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-vue-jsx/modern.config.ts b/packages/plugin-vue-jsx/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-vue-jsx/modern.config.ts +++ b/packages/plugin-vue-jsx/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 51f218884e..1388645fe0 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-vue-jsx", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Vue 3 JSX plugin of Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-vue-jsx" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -39,7 +39,7 @@ "typescript": "^5.4.2" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-vue/modern.config.ts b/packages/plugin-vue/modern.config.ts index c8d42a9956..8f40b68926 100644 --- a/packages/plugin-vue/modern.config.ts +++ b/packages/plugin-vue/modern.config.ts @@ -1,3 +1,3 @@ -import { configWithMjs } from '../../scripts/modern.base.config'; +import { configForDualPackage } from '../../scripts/modern.base.config'; -export default configWithMjs; +export default configForDualPackage; diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index 2d7250e17a..e0e24607c0 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@rsbuild/plugin-vue", - "version": "0.6.13", + "version": "0.7.0-beta.5", "description": "Vue 3 plugin of Rsbuild", "homepage": "https://rsbuild.dev", "repository": { @@ -9,15 +9,15 @@ "directory": "packages/plugin-vue" }, "license": "MIT", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "default": "./dist/index.js" + "import": "./dist/index.js", + "require": "./dist/index.cjs" } }, - "main": "./dist/index.js", + "main": "./dist/index.cjs", "types": "./dist/index.d.ts", "files": [ "dist" @@ -39,7 +39,7 @@ "webpack": "^5.91.0" }, "peerDependencies": { - "@rsbuild/core": "workspace:^0.6.13" + "@rsbuild/core": "workspace:^0.7.0-beta.5" }, "publishConfig": { "access": "public", diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index dde11c9af0..55e8d21f15 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -1,7 +1,5 @@ -import type { RsbuildPlugin } from '@rsbuild/core'; -import { deepmerge } from '@rsbuild/shared'; -import { VueLoaderPlugin } from 'vue-loader'; -import type { VueLoaderOptions } from 'vue-loader'; +import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core'; +import { type VueLoaderOptions, VueLoaderPlugin } from 'vue-loader'; import { applySplitChunksRule } from './splitChunks'; export type SplitVueChunkOptions = { @@ -34,8 +32,11 @@ export function pluginVue(options: PluginVueOptions = {}): RsbuildPlugin { name: 'rsbuild:vue', setup(api) { + const VUE_REGEXP = /\.vue$/; + const CSS_MODULES_REGEX = /\.modules?\.\w+$/i; + api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => { - return mergeRsbuildConfig(config, { + const extraConfig: RsbuildConfig = { source: { define: { // https://link.vuejs.org/feature-flags @@ -44,25 +45,45 @@ export function pluginVue(options: PluginVueOptions = {}): RsbuildPlugin { __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false, }, }, - }); + }; + + const merged = mergeRsbuildConfig(extraConfig, config); + + merged.output ||= {}; + merged.output.cssModules ||= {}; + + // Support `