diff --git a/.changeset/fuzzy-ants-destroy.md b/.changeset/fuzzy-ants-destroy.md index 8ccbca0f2ce9..1506c9c66bfa 100644 --- a/.changeset/fuzzy-ants-destroy.md +++ b/.changeset/fuzzy-ants-destroy.md @@ -1,5 +1,4 @@ --- -'@modern-js/rspack-generator': patch '@modern-js/generator-common': patch --- diff --git a/.changeset/poor-panthers-raise.md b/.changeset/poor-panthers-raise.md new file mode 100644 index 000000000000..7f110db2c5cb --- /dev/null +++ b/.changeset/poor-panthers-raise.md @@ -0,0 +1,7 @@ +--- +'@modern-js/mwa-generator': patch +'@modern-js/generator-common': patch +--- + +feat(generator): remove rspack generator, you can enable it by one line configration +feat(generator): 移除 rspack 生成器, 现在只需要一行配置即可开启 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000000..b41e790475be --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +*.handlebars diff --git a/packages/generator/generator-common/src/common/solution.ts b/packages/generator/generator-common/src/common/solution.ts index 4b18ee7e8a37..3cc20457f4ce 100644 --- a/packages/generator/generator-common/src/common/solution.ts +++ b/packages/generator/generator-common/src/common/solution.ts @@ -112,7 +112,6 @@ export const getScenesSchema = (extra: Record = {}): Schema => { export const BaseGenerator = '@modern-js/base-generator'; export const PackagesGenerator = '@modern-js/packages-generator'; -export const RspackGenerator = '@modern-js/rspack-generator'; export const SolutionGenerator: Record = { [Solution.MWA]: '@modern-js/mwa-generator', diff --git a/packages/generator/generators/mwa-generator/package.json b/packages/generator/generators/mwa-generator/package.json index d8c3c9027abd..c44f96c528a4 100644 --- a/packages/generator/generators/mwa-generator/package.json +++ b/packages/generator/generators/mwa-generator/package.json @@ -40,7 +40,6 @@ "@modern-js/generator-common": "workspace:*", "@modern-js/generator-utils": "workspace:*", "@modern-js/packages-generator": "workspace:*", - "@modern-js/rspack-generator": "workspace:*", "@modern-js/plugin-i18n": "workspace:*", "@scripts/build": "workspace:*", "@scripts/jest-config": "workspace:*", diff --git a/packages/generator/generators/mwa-generator/src/index.ts b/packages/generator/generators/mwa-generator/src/index.ts index 26ae924c9cd8..c03bb22507ed 100644 --- a/packages/generator/generators/mwa-generator/src/index.ts +++ b/packages/generator/generators/mwa-generator/src/index.ts @@ -10,7 +10,6 @@ import { EntryGenerator, PackagesGenerator, BuildTools, - RspackGenerator, } from '@modern-js/generator-common'; import { getMWAProjectPath, @@ -117,6 +116,12 @@ export const handleTemplateFile = async ( generator.logger.debug(`inputData=${JSON.stringify(ans)}`, ans); const { packageName, packagePath, language, packageManager } = ans; + const { packagesInfo, buildTools } = context.config; + + const bundler = + buildTools === BuildTools.Rspack + ? `'experimental-rspack',` + : `'webpack', // Set to 'experimental-rspack' to enable rspack ⚡️🦀`; const projectPath = getMWAProjectPath( packagePath as string, @@ -155,6 +160,9 @@ export const handleTemplateFile = async ( resourceKey .replace('templates/ts-template/', projectPath) .replace('.handlebars', ''), + { + bundler, + }, ); } else { await appApi.forgeTemplate( @@ -164,6 +172,9 @@ export const handleTemplateFile = async ( resourceKey .replace('templates/js-template/', projectPath) .replace('.handlebars', ''), + { + bundler, + }, ); } @@ -183,21 +194,6 @@ export const handleTemplateFile = async ( }); } - const { packagesInfo, buildTools } = context.config; - - if (buildTools === BuildTools.Rspack) { - await appApi.runSubGenerator( - getGeneratorPath(RspackGenerator, context.config.distTag), - undefined, - { - ...context.config, - isNewProject: true, - isSubGenerator: true, - modernVersion, - }, - ); - } - if (packagesInfo && Object.keys(packagesInfo).length > 0) { await appApi.runSubGenerator( getGeneratorPath(PackagesGenerator, context.config.distTag), diff --git a/packages/generator/generators/mwa-generator/templates/js-template/modern.config.js.handlebars b/packages/generator/generators/mwa-generator/templates/js-template/modern.config.js.handlebars index 7323b81d1830..df8045c55d4f 100644 --- a/packages/generator/generators/mwa-generator/templates/js-template/modern.config.js.handlebars +++ b/packages/generator/generators/mwa-generator/templates/js-template/modern.config.js.handlebars @@ -5,5 +5,9 @@ module.exports = { runtime: { router: true, }, - plugins: [appTools()], + plugins: [ + appTools({ + bundler: {{{ bundler }}} + }), + ], }; diff --git a/packages/generator/generators/mwa-generator/templates/ts-template/modern.config.ts.handlebars b/packages/generator/generators/mwa-generator/templates/ts-template/modern.config.ts.handlebars index 85b0679f6276..f4625af73969 100644 --- a/packages/generator/generators/mwa-generator/templates/ts-template/modern.config.ts.handlebars +++ b/packages/generator/generators/mwa-generator/templates/ts-template/modern.config.ts.handlebars @@ -5,5 +5,9 @@ export default defineConfig({ runtime: { router: true, }, - plugins: [appTools()], + plugins: [ + appTools({ + bundler: {{{ bundler }}} + }), + ], }); diff --git a/packages/generator/generators/rspack-generator/.eslintrc.js b/packages/generator/generators/rspack-generator/.eslintrc.js deleted file mode 100644 index 414a253db518..000000000000 --- a/packages/generator/generators/rspack-generator/.eslintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - root: true, - extends: ['@modern-js'], - parserOptions: { - tsconfigRootDir: __dirname, - project: ['./tsconfig.json'], - }, -}; diff --git a/packages/generator/generators/rspack-generator/CHANGELOG.md b/packages/generator/generators/rspack-generator/CHANGELOG.md deleted file mode 100644 index 586b133fb454..000000000000 --- a/packages/generator/generators/rspack-generator/CHANGELOG.md +++ /dev/null @@ -1,265 +0,0 @@ -# @modern-js/rspack-generator - -## 3.3.8 - -### Patch Changes - -- @modern-js/utils@2.46.1 - -## 3.3.7 - -### Patch Changes - -- @modern-js/utils@2.46.0 - -## 3.3.6 - -### Patch Changes - -- @modern-js/utils@2.45.0 - -## 3.3.5 - -### Patch Changes - -- @modern-js/utils@2.44.0 - -## 3.3.4 - -### Patch Changes - -- @modern-js/utils@2.43.0 - -## 3.3.3 - -### Patch Changes - -- fa731a7: chore: bump codesmith to 2.3.2 - chore: 升级 codesmith 版本到 2.3.2 - - @modern-js/utils@2.42.2 - -## 3.3.2 - -### Patch Changes - -- @modern-js/utils@2.42.1 - -## 3.3.1 - -### Patch Changes - -- b182eb2: chore: bump codesmith v2.3.1 to show timing - chore: 升级 codesmith 到 v2.3.1, 用于展示执行时间 - - @modern-js/utils@2.42.0 - -## 3.3.0 - -### Patch Changes - -- Updated dependencies [c4d396a] - - @modern-js/utils@2.41.0 - -## 3.2.11 - -### Patch Changes - -- Updated dependencies [95f15d2] - - @modern-js/utils@2.40.0 - -## 3.2.10 - -### Patch Changes - -- @modern-js/utils@2.39.2 - -## 3.2.9 - -### Patch Changes - -- @modern-js/utils@2.39.1 - -## 3.2.8 - -### Patch Changes - -- @modern-js/utils@2.39.0 - -## 3.2.7 - -### Patch Changes - -- 8f43163: feat: optimize generator bundle - - feat: 优化生成器打包 - - - @modern-js/utils@2.38.0 - -## 3.2.6 - -## 3.2.5 - -## 3.2.4 - -## 3.2.3 - -## 3.2.2 - -## 3.2.1 - -## 3.2.0 - -## 3.1.39 - -## 3.1.38 - -## 3.1.37 - -## 3.1.36 - -### Patch Changes - -- f1de744: chore(generators): adjust build target to es2019 - - chore(generators): 调整构建的 target 为 es2019 - -## 3.1.35 - -## 3.1.34 - -## 3.1.33 - -## 3.1.32 - -## 3.1.31 - -## 3.1.30 - -## 3.1.29 - -## 3.1.28 - -## 3.1.27 - -## 3.1.26 - -## 3.1.25 - -### Patch Changes - -- 9aa2c25: feat: add named exports for all solutions - - feat: 为各个 solutions 添加 named 导出 - -## 3.1.24 - -## 3.1.23 - -## 3.1.22 - -### Patch Changes - -- 7e6fb5f: chore: publishConfig add provenance config - - chore: publishConfig 增加 provenance 配置 - -## 3.1.21 - -## 3.1.20 - -### Patch Changes - -- b647c68: chore(generator): update codesmith version - - chore(generator): 更新 codesmith 版本 - -## 3.1.19 - -## 3.1.18 - -### Patch Changes - -- 26dcf3a: chore: bump typescript to v5 in devDependencies - - chore: 升级 devDependencies 中的 typescript 版本到 v5 - -- de8f73f: feat: update codesmith version - - feat: 更新 codesmith 版本 - -## 3.1.17 - -### Patch Changes - -- 6b9d90a: chore: remove @babel/runtime. add @swc/helper and enable `externalHelper` config. - chore: 移除 @babel/runtime 依赖. 增加 @swc/helpers 依赖并且开启 `externalHelpers` 配置 - -## 3.1.16 - -## 3.1.15 - -## 3.1.14 - -### Patch Changes - -- 21c87bf: feat: bump codesmith packages version - - feat: 升级 codesmith 包版本 - -- bc61dab: feat: bump codesmith version - - feat: 升级 codesmith 版本 - -## 3.1.13 - -## 3.1.12 - -## 3.1.11 - -## 3.1.10 - -### Patch Changes - -- 4e876ab: chore: package.json include the monorepo-relative directory - - chore: 在 package.json 中声明 monorepo 的子路径 - -## 3.1.9 - -## 3.1.8 - -## 3.1.7 - -## 3.1.6 - -## 3.1.5 - -## 3.1.4 - -## 3.1.3 - -### Patch Changes - -- 034f36b: feat: set the default language of CLI to English - - feat: 将命令行的默认语言设置为英文 - -## 3.1.2 - -## 3.1.1 - -## 3.1.0 - -### Patch Changes - -- 0da32d0: chore: upgrade jest and puppeteer - chore: 升级 jest 和 puppeteer 到 latest - -## 3.0.11 - -## 3.0.10 - -### Patch Changes - -- cde9e8df93: fix(generators): update api document link - - fix(generators): 更新 api 文档链接 diff --git a/packages/generator/generators/rspack-generator/LICENSE b/packages/generator/generators/rspack-generator/LICENSE deleted file mode 100644 index 39e3c5971226..000000000000 --- a/packages/generator/generators/rspack-generator/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-present Modern.js - -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/generator/generators/rspack-generator/README.md b/packages/generator/generators/rspack-generator/README.md deleted file mode 100644 index f3d407c43230..000000000000 --- a/packages/generator/generators/rspack-generator/README.md +++ /dev/null @@ -1,26 +0,0 @@ -

- Modern.js Logo -

- -

Modern.js

- -

- A Progressive React Framework for modern web development. -

- -## Getting Started - -Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js. - -## Documentation - -- [English Documentation](https://modernjs.dev/en/) -- [中文文档](https://modernjs.dev) - -## Contributing - -Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md). - -## License - -Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE). diff --git a/packages/generator/generators/rspack-generator/jest.config.js b/packages/generator/generators/rspack-generator/jest.config.js deleted file mode 100644 index 5fcd3e5b28bd..000000000000 --- a/packages/generator/generators/rspack-generator/jest.config.js +++ /dev/null @@ -1,7 +0,0 @@ -const sharedConfig = require('@scripts/jest-config'); - -/** @type {import('@jest/types').Config.InitialOptions} */ -module.exports = { - ...sharedConfig, - rootDir: __dirname, -}; diff --git a/packages/generator/generators/rspack-generator/modern.config.js b/packages/generator/generators/rspack-generator/modern.config.js deleted file mode 100644 index 57303a8d8dfa..000000000000 --- a/packages/generator/generators/rspack-generator/modern.config.js +++ /dev/null @@ -1,5 +0,0 @@ -const { generatorBuildConfig } = require('@scripts/build'); - -module.exports = { - buildConfig: generatorBuildConfig, -}; diff --git a/packages/generator/generators/rspack-generator/package.json b/packages/generator/generators/rspack-generator/package.json deleted file mode 100644 index 73f37b187c0d..000000000000 --- a/packages/generator/generators/rspack-generator/package.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "name": "@modern-js/rspack-generator", - "description": "A Progressive React Framework for modern web development.", - "homepage": "https://modernjs.dev", - "bugs": "https://github.com/web-infra-dev/modern.js/issues", - "repository": { - "type": "git", - "url": "https://github.com/web-infra-dev/modern.js", - "directory": "packages/generator/generators/rspack-generator" - }, - "license": "MIT", - "keywords": [ - "react", - "framework", - "modern", - "modern.js" - ], - "version": "3.3.8", - "jsnext:source": "./src/index.ts", - "main": "./src/index.ts", - "files": [ - "/templates", - "/dist/index.js" - ], - "scripts": { - "prepublishOnly": "only-allow-pnpm", - "new": "modern-lib new", - "build": "modern-lib build", - "test": "jest --passWithNoTests" - }, - "dependencies": { - "@modern-js/utils": "workspace:*" - }, - "devDependencies": { - "@modern-js/codesmith": "2.3.4", - "@modern-js/codesmith-api-app": "2.3.4", - "@modern-js/dependence-generator": "workspace:*", - "@modern-js/generator-common": "workspace:*", - "@modern-js/generator-utils": "workspace:*", - "@modern-js/plugin-i18n": "workspace:*", - "@scripts/build": "workspace:*", - "@scripts/jest-config": "workspace:*", - "@types/jest": "^29", - "@types/node": "^14", - "jest": "^29", - "typescript": "^5" - }, - "sideEffects": false, - "publishConfig": { - "main": "./dist/index.js", - "registry": "https://registry.npmjs.org/", - "access": "public", - "provenance": true - }, - "types": "./src/index.ts" -} diff --git a/packages/generator/generators/rspack-generator/src/index.ts b/packages/generator/generators/rspack-generator/src/index.ts deleted file mode 100644 index c874fed7592e..000000000000 --- a/packages/generator/generators/rspack-generator/src/index.ts +++ /dev/null @@ -1,68 +0,0 @@ -import path from 'path'; -import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith'; -import { AppAPI } from '@modern-js/codesmith-api-app'; -import { isTsProject } from '@modern-js/generator-utils'; -import { - DependenceGenerator, - i18n as commonI18n, - Language, -} from '@modern-js/generator-common'; - -const getGeneratorPath = (generator: string, distTag: string) => { - if (process.env.CODESMITH_ENV === 'development') { - return path.dirname(require.resolve(generator)); - } else if (distTag) { - return `${generator}@${distTag}`; - } - return generator; -}; - -const handleTemplateFile = async ( - context: GeneratorContext, - _generator: GeneratorCore, - appApi: AppAPI, -) => { - const { isNewProject } = context.config; - if (isNewProject) { - const appDir = context.materials.default.basePath; - const language = isTsProject(appDir) ? Language.TS : Language.JS; - appApi.forgeTemplate( - language === Language.TS - ? 'templates/modern.config.ts.handlebars' - : 'templates/js/modern.config.js.handlebars', - undefined, - resourceKey => - resourceKey.replace('templates/', '').replace('.handlebars', ''), - ); - } - - await appApi.runSubGenerator( - getGeneratorPath(DependenceGenerator, context.config.distTag), - undefined, - { - ...context.config, - isSubGenerator: true, - }, - ); -}; - -export default async (context: GeneratorContext, generator: GeneratorCore) => { - const appApi = new AppAPI(context, generator); - - const { locale } = context.config; - commonI18n.changeLanguage({ locale }); - appApi.i18n.changeLanguage({ locale }); - - if (!(await appApi.checkEnvironment())) { - // eslint-disable-next-line no-process-exit - process.exit(1); - } - - generator.logger.debug(`start run @modern-js/rspack-generator`); - generator.logger.debug(`context=${JSON.stringify(context)}`); - generator.logger.debug(`context.data=${JSON.stringify(context.data)}`); - - await handleTemplateFile(context, generator, appApi); - - generator.logger.debug(`forge @modern-js/rspack-generator succeed `); -}; diff --git a/packages/generator/generators/rspack-generator/templates/modern.config.js.handlebars b/packages/generator/generators/rspack-generator/templates/modern.config.js.handlebars deleted file mode 100644 index e549646f75ce..000000000000 --- a/packages/generator/generators/rspack-generator/templates/modern.config.js.handlebars +++ /dev/null @@ -1,13 +0,0 @@ -import { appTools } from '@modern-js/app-tools'; - -// https://modernjs.dev/en/configure/app/usage -module.exports = { - runtime: { - router: true, - }, - plugins: [ - appTools({ - bundler: 'experimental-rspack', - }), - ], -}; diff --git a/packages/generator/generators/rspack-generator/templates/modern.config.ts.handlebars b/packages/generator/generators/rspack-generator/templates/modern.config.ts.handlebars deleted file mode 100644 index 5c96da18a0e9..000000000000 --- a/packages/generator/generators/rspack-generator/templates/modern.config.ts.handlebars +++ /dev/null @@ -1,13 +0,0 @@ -import { appTools, defineConfig } from '@modern-js/app-tools'; - -// https://modernjs.dev/en/configure/app/usage -export default defineConfig({ - runtime: { - router: true, - }, - plugins: [ - appTools({ - bundler: 'experimental-rspack', - }), - ], -}); diff --git a/packages/generator/generators/rspack-generator/tsconfig.json b/packages/generator/generators/rspack-generator/tsconfig.json deleted file mode 100644 index 32a7aee84b06..000000000000 --- a/packages/generator/generators/rspack-generator/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "@modern-js/tsconfig/base", - "compilerOptions": { - "declaration": false, - "jsx": "preserve", - "baseUrl": "./", - "paths": {} - }, - "include": ["src"] -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 21b3cf486339..52f9b182154c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2376,9 +2376,6 @@ importers: '@modern-js/plugin-i18n': specifier: workspace:* version: link:../../../cli/plugin-i18n - '@modern-js/rspack-generator': - specifier: workspace:* - version: link:../rspack-generator '@scripts/build': specifier: workspace:* version: link:../../../../scripts/build @@ -2533,49 +2530,6 @@ importers: specifier: ^5 version: 5.3.3 - packages/generator/generators/rspack-generator: - dependencies: - '@modern-js/utils': - specifier: workspace:* - version: link:../../../toolkit/utils - devDependencies: - '@modern-js/codesmith': - specifier: 2.3.4 - version: 2.3.4 - '@modern-js/codesmith-api-app': - specifier: 2.3.4 - version: 2.3.4(@modern-js/codesmith@2.3.4)(typescript@5.3.3) - '@modern-js/dependence-generator': - specifier: workspace:* - version: link:../dependence-generator - '@modern-js/generator-common': - specifier: workspace:* - version: link:../../generator-common - '@modern-js/generator-utils': - specifier: workspace:* - version: link:../../generator-utils - '@modern-js/plugin-i18n': - specifier: workspace:* - version: link:../../../cli/plugin-i18n - '@scripts/build': - specifier: workspace:* - version: link:../../../../scripts/build - '@scripts/jest-config': - specifier: workspace:* - version: link:../../../../scripts/jest-config - '@types/jest': - specifier: ^29 - version: 29.2.6 - '@types/node': - specifier: ^14 - version: 14.18.35 - jest: - specifier: ^29 - version: 29.5.0(@types/node@14.18.35)(ts-node@10.9.2) - typescript: - specifier: ^5 - version: 5.3.3 - packages/generator/generators/server-generator: dependencies: '@modern-js/utils': diff --git a/tests/generator/utils/prepare.ts b/tests/generator/utils/prepare.ts index a9de7ef730b2..ca36758b07bb 100644 --- a/tests/generator/utils/prepare.ts +++ b/tests/generator/utils/prepare.ts @@ -24,7 +24,6 @@ async function addNewActionDevDependence(repoCwd: string) { '@modern-js/storybook-next-generator': 'workspace:*', '@modern-js/ssg-generator': 'workspace:*', '@modern-js/module-test-generator': 'workspace:*', - '@modern-js/rspack-generator': 'workspace:*', '@modern-js/module-doc-generator': 'workspace:*', }; await fs.writeFile(