feat(rspack): add option to keep existing versions of packages for init generator (#378)

This commit is contained in:
Colum Ferry 2024-03-06 12:28:30 +00:00 committed by GitHub
parent a2d91f0c8e
commit 55d1d56ff7
5 changed files with 22 additions and 7 deletions

View File

@ -28,10 +28,10 @@
"license-webpack-plugin": "^4.0.2", "license-webpack-plugin": "^4.0.2",
"sass-loader": "^12.2.0", "sass-loader": "^12.2.0",
"stylus-loader": "^7.1.0", "stylus-loader": "^7.1.0",
"@nx/eslint": "^18.0.7" "@nx/eslint": "^18.0.7",
}, "@rspack/core": "^0.5.6",
"peerDependencies": { "@rspack/plugin-react-refresh": "^0.5.6",
"@rspack/core": ">= 0.4.0" "@rspack/plugin-minify": "^0.5.6"
}, },
"nx-migrations": { "nx-migrations": {
"migrations": "./migrations.json" "migrations": "./migrations.json"

View File

@ -7,10 +7,10 @@ import {
} from '@nx/devkit'; } from '@nx/devkit';
import { initGenerator } from '@nx/js'; import { initGenerator } from '@nx/js';
import { import {
lessLoaderVersion,
rspackCoreVersion, rspackCoreVersion,
rspackDevServerVersion, rspackDevServerVersion,
rspackPluginMinifyVersion, rspackPluginMinifyVersion,
lessLoaderVersion,
rspackPluginReactRefreshVersion, rspackPluginReactRefreshVersion,
} from '../../utils/versions'; } from '../../utils/versions';
import { InitGeneratorSchema } from './schema'; import { InitGeneratorSchema } from './schema';
@ -49,7 +49,13 @@ export async function rspackInitGenerator(
devDependencies['@rspack/dev-server'] = rspackDevServerVersion; devDependencies['@rspack/dev-server'] = rspackDevServerVersion;
} }
const installTask = addDependenciesToPackageJson(tree, {}, devDependencies); const installTask = addDependenciesToPackageJson(
tree,
{},
devDependencies,
undefined,
schema.keepExistingVersions
);
tasks.push(installTask); tasks.push(installTask);
return runTasksInSerial(...tasks); return runTasksInSerial(...tasks);

View File

@ -5,4 +5,5 @@ export interface InitGeneratorSchema {
style?: 'none' | 'css' | 'scss' | 'less' | 'styl'; style?: 'none' | 'css' | 'scss' | 'less' | 'styl';
devServer?: boolean; devServer?: boolean;
rootProject?: boolean; rootProject?: boolean;
keepExistingVersions?: boolean;
} }

View File

@ -18,6 +18,12 @@
"rootProject": { "rootProject": {
"type": "boolean", "type": "boolean",
"x-priority": "internal" "x-priority": "internal"
},
"keepExistingVersions": {
"type": "boolean",
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
} }
}, },
"required": [] "required": []

View File

@ -1,7 +1,6 @@
import { Configuration } from '@rspack/core'; import { Configuration } from '@rspack/core';
import { SharedConfigContext } from './model'; import { SharedConfigContext } from './model';
import { withWeb } from './with-web'; import { withWeb } from './with-web';
import ReactRefreshPlugin from "@rspack/plugin-react-refresh";
export function withReact(opts = {}) { export function withReact(opts = {}) {
return function makeConfig( return function makeConfig(
@ -16,6 +15,9 @@ export function withReact(opts = {}) {
context, context,
}); });
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
const react = { const react = {
runtime: 'automatic', runtime: 'automatic',
development: isDev, development: isDev,