Skip to content

Commit

Permalink
feat(rspack): add option to keep existing versions of packages for in…
Browse files Browse the repository at this point in the history
…it generator (#378)
  • Loading branch information
Coly010 committed Mar 6, 2024
1 parent ee0e8cb commit 1d20a14
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"license-webpack-plugin": "^4.0.2",
"sass-loader": "^12.2.0",
"stylus-loader": "^7.1.0",
"@nx/eslint": "^18.0.7"
},
"peerDependencies": {
"@rspack/core": ">= 0.4.0"
"@nx/eslint": "^18.0.7",
"@rspack/core": "^0.5.6",
"@rspack/plugin-react-refresh": "^0.5.6",
"@rspack/plugin-minify": "^0.5.6"
},
"nx-migrations": {
"migrations": "./migrations.json"
Expand Down
10 changes: 8 additions & 2 deletions packages/rspack/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
} from '@nx/devkit';
import { initGenerator } from '@nx/js';
import {
lessLoaderVersion,
rspackCoreVersion,
rspackDevServerVersion,
rspackPluginMinifyVersion,
lessLoaderVersion,
rspackPluginReactRefreshVersion,
} from '../../utils/versions';
import { InitGeneratorSchema } from './schema';
Expand Down Expand Up @@ -49,7 +49,13 @@ export async function rspackInitGenerator(
devDependencies['@rspack/dev-server'] = rspackDevServerVersion;
}

const installTask = addDependenciesToPackageJson(tree, {}, devDependencies);
const installTask = addDependenciesToPackageJson(
tree,
{},
devDependencies,
undefined,
schema.keepExistingVersions
);
tasks.push(installTask);

return runTasksInSerial(...tasks);
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface InitGeneratorSchema {
style?: 'none' | 'css' | 'scss' | 'less' | 'styl';
devServer?: boolean;
rootProject?: boolean;
keepExistingVersions?: boolean;
}
6 changes: 6 additions & 0 deletions packages/rspack/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"rootProject": {
"type": "boolean",
"x-priority": "internal"
},
"keepExistingVersions": {
"type": "boolean",
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
}
},
"required": []
Expand Down
4 changes: 3 additions & 1 deletion packages/rspack/src/utils/with-react.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Configuration } from '@rspack/core';
import { SharedConfigContext } from './model';
import { withWeb } from './with-web';
import ReactRefreshPlugin from "@rspack/plugin-react-refresh";

export function withReact(opts = {}) {
return function makeConfig(
Expand All @@ -16,6 +15,9 @@ export function withReact(opts = {}) {
context,
});

// eslint-disable-next-line @typescript-eslint/no-var-requires
const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');

const react = {
runtime: 'automatic',
development: isDev,
Expand Down

0 comments on commit 1d20a14

Please sign in to comment.