From a3a788b79587ebdf018a7911c49616cc882ddba8 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 20 Feb 2024 16:33:16 +0800 Subject: [PATCH] chore: reuse CHAIN_ID from Rsbuild (#5410) --- .pnpmfile.cjs | 12 +- package.json | 21 +- packages/cli/plugin-bff/package.json | 1 + packages/cli/plugin-bff/tests/cli.test.ts | 2 +- packages/runtime/plugin-garfish/package.json | 1 + .../runtime/plugin-garfish/tests/cli.test.tsx | 2 +- .../storybook/builder/src/docgen/index.ts | 3 +- .../cli/{constants/index.ts => constants.ts} | 2 - .../utils/src/cli/constants/chainId.ts | 201 ------------------ pnpm-lock.yaml | 13 +- scripts/prebundle/package.json | 1 - 11 files changed, 15 insertions(+), 244 deletions(-) rename packages/toolkit/utils/src/cli/{constants/index.ts => constants.ts} (99%) delete mode 100644 packages/toolkit/utils/src/cli/constants/chainId.ts diff --git a/.pnpmfile.cjs b/.pnpmfile.cjs index b19858357e17..b3b4619501a5 100644 --- a/.pnpmfile.cjs +++ b/.pnpmfile.cjs @@ -14,11 +14,7 @@ function readPackage(pkg, _context) { // Some packages still depend on esbuild < 0.17, so we upgrade it manually. // ref: https://github.com/lukeed/tsm/issues/48 - if ( - pkg.name === 'tsm' || - pkg.name === 'vite' || - pkg.name === 'esbuild-loader' - ) { + if (pkg.name === 'tsm' || pkg.name === 'vite') { pkg.dependencies.esbuild = '0.17.19'; } @@ -38,17 +34,13 @@ function readPackage(pkg, _context) { } } - const outsideModernPkgList = ['@modern-js/mdx-rs-binding']; - if ( (pkg.name?.startsWith('@rspress/') || pkg.name?.startsWith('rspress')) && pkg.dependencies ) { pkg.dependencies = Object.fromEntries( Object.entries(pkg.dependencies).map(([key, value]) => - key.startsWith('@modern-js/') && !outsideModernPkgList.includes(key) - ? [key, 'workspace:*'] - : [key, value], + key.startsWith('@modern-js/') ? [key, 'workspace:*'] : [key, value], ), ); } diff --git a/package.json b/package.json index 6a3a9660c483..0a56764548f8 100644 --- a/package.json +++ b/package.json @@ -100,38 +100,19 @@ } }, "allowedDeprecatedVersions": { - "@babel/plugin-proposal-class-properties": "7.18.6", - "@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6", "@babel/plugin-proposal-object-rest-spread": "7.12.1 || 7.20.7", - "@babel/plugin-proposal-optional-chaining": "7.21.0", - "@babel/plugin-proposal-private-methods": "7.18.6", "@babel/plugin-proposal-private-property-in-object": "7.21.0", "@financial-times/polyfill-useragent-normaliser": "1.10.2", - "core-js": "2.6.11", "formidable": "1.2.6", - "hast": "1.0.0", "sourcemap-codec": "1.4.8", - "uuid-browser": "3.1.0", - "stable": "0.1.8", "js-polyfills": "0.1.43", "picturefill": "3.0.3", - "string-similarity": "4.0.4", "querystring": "0.2.0", + "string-similarity": "4.0.4", "source-map-resolve": "0.6.0 || 0.5.3", "@formatjs/intl-utils": "3.8.4", "debug": "4.1.1", - "sane": "4.1.0", - "mkdirp": "0.3.5", - "@npmcli/move-file": "1.1.2", "uuid": "3.4.0", - "chokidar": "2.1.8", - "consolidate": "0.15.1", - "fsevents": "1.2.13", - "source-map-url": "0.4.1", - "urix": "0.1.0", - "resolve-url": "0.2.1", - "superagent": "6.1.0", - "@types/sass": "1.45.0", "trim": "0.0.1" } } diff --git a/packages/cli/plugin-bff/package.json b/packages/cli/plugin-bff/package.json index 94a75370a7ba..7956417efba0 100644 --- a/packages/cli/plugin-bff/package.json +++ b/packages/cli/plugin-bff/package.json @@ -70,6 +70,7 @@ "@swc/helpers": "0.5.3" }, "devDependencies": { + "@rsbuild/shared": "0.4.3", "@modern-js/runtime": "workspace:*", "@modern-js/core": "workspace:*", "@modern-js/bff-runtime": "workspace:*", diff --git a/packages/cli/plugin-bff/tests/cli.test.ts b/packages/cli/plugin-bff/tests/cli.test.ts index 93548965967c..2e848ab273d8 100644 --- a/packages/cli/plugin-bff/tests/cli.test.ts +++ b/packages/cli/plugin-bff/tests/cli.test.ts @@ -8,7 +8,7 @@ import { ResolvedConfigContext, } from '@modern-js/core'; import Chain from '@modern-js/utils/webpack-chain'; -import { CHAIN_ID } from '@modern-js/utils'; +import { CHAIN_ID } from '@rsbuild/shared'; import type { AppToolsHooks } from '@modern-js/app-tools'; import plugin from '../src/cli'; import './helper'; diff --git a/packages/runtime/plugin-garfish/package.json b/packages/runtime/plugin-garfish/package.json index 08375fb5aa2d..45d7f555fe04 100644 --- a/packages/runtime/plugin-garfish/package.json +++ b/packages/runtime/plugin-garfish/package.json @@ -86,6 +86,7 @@ "react-dom": ">=17" }, "devDependencies": { + "@rsbuild/shared": "0.4.3", "@modern-js/app-tools": "workspace:*", "@modern-js/core": "workspace:*", "@modern-js/plugin-router-v5": "workspace:*", diff --git a/packages/runtime/plugin-garfish/tests/cli.test.tsx b/packages/runtime/plugin-garfish/tests/cli.test.tsx index 13371a86910b..a1eefa2a59d6 100644 --- a/packages/runtime/plugin-garfish/tests/cli.test.tsx +++ b/packages/runtime/plugin-garfish/tests/cli.test.tsx @@ -1,7 +1,7 @@ import '@testing-library/jest-dom'; import { manager, CliPlugin } from '@modern-js/core'; import WebpackChain from '@modern-js/utils/webpack-chain'; -import { CHAIN_ID } from '@modern-js/utils'; +import { CHAIN_ID } from '@rsbuild/shared'; import type { AppUserConfig } from '@modern-js/app-tools'; import { garfishPlugin, externals } from '../src/cli'; import type { UseConfig } from '../src/cli'; diff --git a/packages/storybook/builder/src/docgen/index.ts b/packages/storybook/builder/src/docgen/index.ts index f6b07982e7ed..59d50d0e843d 100644 --- a/packages/storybook/builder/src/docgen/index.ts +++ b/packages/storybook/builder/src/docgen/index.ts @@ -1,5 +1,6 @@ import type { Options } from '@storybook/types'; -import { CHAIN_ID, logger } from '@modern-js/utils'; +import { logger } from '@modern-js/utils'; +import { CHAIN_ID } from '@rsbuild/shared'; import type { RspackConfig, WebpackChain } from '@rsbuild/shared'; export type DocgenOptions = { diff --git a/packages/toolkit/utils/src/cli/constants/index.ts b/packages/toolkit/utils/src/cli/constants.ts similarity index 99% rename from packages/toolkit/utils/src/cli/constants/index.ts rename to packages/toolkit/utils/src/cli/constants.ts index 5c8307178e28..61fea8f70708 100644 --- a/packages/toolkit/utils/src/cli/constants/index.ts +++ b/packages/toolkit/utils/src/cli/constants.ts @@ -174,5 +174,3 @@ export const INTERNAL_SERVER_PLUGINS: InternalPlugins = { [SERVER_PLUGIN_SERVER]: '@modern-js/plugin-server/server', [SERVER_PLUGIN_POLYFILL]: '@modern-js/plugin-polyfill/server', }; - -export * from './chainId'; diff --git a/packages/toolkit/utils/src/cli/constants/chainId.ts b/packages/toolkit/utils/src/cli/constants/chainId.ts deleted file mode 100644 index b411a558b7d8..000000000000 --- a/packages/toolkit/utils/src/cli/constants/chainId.ts +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Don't add anything. will be removed on next version - */ -export const CHAIN_ID = { - /** Predefined rules */ - RULE: { - /** Rule for .mjs */ - MJS: 'mjs', - /** Rule for predefined loaders */ - LOADERS: 'loaders', - /** Rule for fonts */ - FONT: 'font', - /** Rule for images */ - IMAGE: 'image', - /** Rule for media */ - MEDIA: 'media', - /** Rule for js */ - JS: 'js', - /** Rule for data uri encoded javascript */ - JS_DATA_URI: 'js-data-uri', - /** Rule for ts */ - TS: 'ts', - /** Rule for css */ - CSS: 'css', - /** Rule for less */ - LESS: 'less', - /** Rule for sass */ - SASS: 'sass', - /** Rule for stylus */ - STYLUS: 'stylus', - /** Rule for svg */ - SVG: 'svg', - /** Rule for pug */ - PUG: 'pug', - /** Rule for Vue */ - VUE: 'vue', - /** Rule for toml */ - TOML: 'toml', - /** Rule for yaml */ - YAML: 'yaml', - /** Rule for wasm */ - WASM: 'wasm', - /** Rule for node */ - NODE: 'node', - /** Rule for bff */ - JS_BFF_API: 'js-bff-api', - }, - /** Predefined rule groups */ - ONE_OF: { - SVG: 'svg', - SVG_URL: 'svg-url', - SVG_ASSET: 'svg-asset', - SVG_INLINE: 'svg-inline', - }, - /** Predefined loaders */ - USE: { - /** ts-loader */ - TS: 'ts', - /** css-loader */ - CSS: 'css', - /** sass-loader */ - SASS: 'sass', - /** less-loader */ - LESS: 'less', - /** stylus-loader */ - STYLUS: 'stylus', - /** url-loader */ - URL: 'url', - /** pug-loader */ - PUG: 'pug', - /** vue-loader */ - VUE: 'vue', - /** file-loader */ - FILE: 'file', - /** @svgr/webpack */ - SVGR: 'svgr', - /** yaml-loader */ - YAML: 'yaml', - /** toml-loader */ - TOML: 'toml', - /** html-loader */ - HTML: 'html', - /** node-loader */ - NODE: 'html', - /** babel-loader */ - BABEL: 'babel', - /** esbuild-loader */ - ESBUILD: 'esbuild', - /** swc-loader */ - SWC: 'swc', - /** style-loader */ - STYLE: 'style-loader', - /** postcss-loader */ - POSTCSS: 'postcss', - /** ignore-css-loader */ - IGNORE_CSS: 'ignore-css', - /** css-modules-typescript-loader */ - CSS_MODULES_TS: 'css-modules-typescript', - /** mini-css-extract-plugin.loader */ - MINI_CSS_EXTRACT: 'mini-css-extract', - /** resolve-url-loader */ - RESOLVE_URL_LOADER_FOR_SASS: 'resolve-url-loader', - /** builder-plugin-image-compress.loader */ - IMAGE_COMPRESS: 'image-compress', - /** builder-plugin-image-compress svgo-loader */ - SVGO: 'svgo', - /** builder-plugin-imagex */ - IMAGEX: 'imagex', - /** storybook-react-docgen */ - REACT_DOCGEN: 'react-docgen', - }, - /** Predefined plugins */ - PLUGIN: { - /** HotModuleReplacementPlugin */ - HMR: 'hmr', - /** CopyWebpackPlugin */ - COPY: 'copy', - /** HtmlWebpackPlugin */ - HTML: 'html', - /** DefinePlugin */ - DEFINE: 'define', - /** IgnorePlugin */ - IGNORE: 'ignore', - /** BannerPlugin */ - BANNER: 'banner', - /** Webpackbar */ - PROGRESS: 'progress', - /** Inspector */ - INSPECTOR: 'inspector', - /** AppIconPlugin */ - APP_ICON: 'app-icon', - /** FaviconUrlPlugin */ - FAVICON_URL: 'favicon-url', - /** LoadableWebpackPlugin */ - LOADABLE: 'loadable', - /** WebpackManifestPlugin */ - MANIFEST: 'webpack-manifest', - /** ForkTsCheckerWebpackPlugin */ - TS_CHECKER: 'ts-checker', - /** InlineChunkHtmlPlugin */ - INLINE_HTML: 'inline-html', - /** WebpackBundleAnalyzer */ - BUNDLE_ANALYZER: 'bundle-analyze', - /** BottomTemplatePlugin */ - BOTTOM_TEMPLATE: 'bottom-template', - /** HtmlTagsPlugin */ - HTML_TAGS: 'html-tags', - /** HtmlNoncePlugin */ - HTML_NONCE: 'html-nonce', - /** HtmlCrossOriginPlugin */ - HTML_CROSS_ORIGIN: 'html-cross-origin', - /** htmlPreconnectPlugin */ - HTML_PRECONNECT: 'html-preconnect-plugin', - /** htmlDnsPrefetchPlugin */ - HTML_DNS_PREFETCH: 'html-dns-prefetch-plugin', - /** htmlPrefetchPlugin */ - HTML_PREFETCH: 'html-prefetch-plugin', - /** htmlPreloadPlugin */ - HTML_PRELOAD: 'html-preload-plugin', - /** MiniCssExtractPlugin */ - MINI_CSS_EXTRACT: 'mini-css-extract', - /** VueLoaderPlugin */ - VUE_LOADER_PLUGIN: 'vue-loader-plugin', - /** ReactFastRefreshPlugin */ - REACT_FAST_REFRESH: 'react-fast-refresh', - /** ProvidePlugin for node polyfill */ - NODE_POLYFILL_PROVIDE: 'node-polyfill-provide', - /** WebpackSRIPlugin */ - SUBRESOURCE_INTEGRITY: 'subresource-integrity', - /** WebpackAssetsRetryPlugin */ - ASSETS_RETRY: 'ASSETS_RETRY', - /** AutoSetRootFontSizePlugin */ - AUTO_SET_ROOT_SIZE: 'auto-set-root-size', - /** HtmlAsyncChunkPlugin */ - HTML_ASYNC_CHUNK: 'html-async-chunk', - /** SWC_POLYFILL_CHECKER */ - SWC_POLYFILL_CHECKER: 'swc-polyfill-checker-plugin', - /** RouterPlugin */ - ROUTER_MANIFEST: 'route-plugin', - }, - /** Predefined minimizers */ - MINIMIZER: { - /** TerserWebpackPlugin */ - JS: 'js', - /** CssMinimizerWebpackPlugin */ - CSS: 'css', - /** ESBuildPlugin */ - ESBUILD: 'js-css', - /** SWCPlugin */ - SWC: 'swc', - }, - /** Predefined resolve plugins */ - RESOLVE_PLUGIN: { - /** ModuleScopePlugin */ - MODULE_SCOPE: 'module-scope', - /** TsConfigPathsPlugin */ - TS_CONFIG_PATHS: 'ts-config-paths', - }, -} as const; - -export type ChainIdentifier = typeof CHAIN_ID; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 695bc8d340dc..df89ae9d45e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -207,6 +207,9 @@ importers: '@modern-js/types': specifier: workspace:* version: link:../../toolkit/types + '@rsbuild/shared': + specifier: 0.4.3 + version: 0.4.3(@swc/helpers@0.5.3) '@scripts/build': specifier: workspace:* version: link:../../../scripts/build @@ -2821,6 +2824,9 @@ importers: '@modern-js/types': specifier: workspace:* version: link:../../toolkit/types + '@rsbuild/shared': + specifier: 0.4.3 + version: 0.4.3(@swc/helpers@0.5.3) '@scripts/build': specifier: workspace:* version: link:../../../scripts/build @@ -5081,9 +5087,6 @@ importers: url-join: specifier: 4.0.1 version: 4.0.1 - v8-compile-cache: - specifier: 2.3.0 - version: 2.3.0 webpack-chain: specifier: npm:webpack-5-chain@8.0.1 version: /webpack-5-chain@8.0.1 @@ -31607,10 +31610,6 @@ packages: /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - /v8-compile-cache@2.3.0: - resolution: {integrity: sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==} - dev: true - /v8-to-istanbul@9.1.0: resolution: {integrity: sha512-6z3GW9x8G1gd+JIIgQQQxXuiJtCXeAjp6RaPEPLv62mH3iPHPxV6W3robxtCzNErRo6ZwTmzWhsbNvjyEBKzKA==} engines: {node: '>=10.12.0'} diff --git a/scripts/prebundle/package.json b/scripts/prebundle/package.json index 083413827832..ca4fcc76debc 100644 --- a/scripts/prebundle/package.json +++ b/scripts/prebundle/package.json @@ -90,7 +90,6 @@ "tsconfig-paths": "4.1.1", "upath": "2.0.1", "url-join": "4.0.1", - "v8-compile-cache": "2.3.0", "webpack-chain": "npm:webpack-5-chain@8.0.1" } }