- Enable generating the new & minimal TS setup by default when generating the `ts` preset with CNW. The existing `NX_ADD_TS_PLUGIN` environment variable is kept with its default value inverted and set to `true`. It can be used to opt out of the new TS setup by running CNW with `NX_ADD_TS_PLUGIN=false`. - Throw an error when running generators that don't yet support the new TS setup. - We'll add support for those generators incrementally in follow-up PRs. <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> <!-- Fixes NXC-1066 --> <!-- Fixes NXC-1068 --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
117 lines
3.0 KiB
TypeScript
117 lines
3.0 KiB
TypeScript
import {
|
|
addDependenciesToPackageJson,
|
|
convertNxGenerator,
|
|
createProjectGraphAsync,
|
|
GeneratorCallback,
|
|
readNxJson,
|
|
runTasksInSerial,
|
|
Tree,
|
|
} from '@nx/devkit';
|
|
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
|
|
import { initGenerator } from '@nx/js';
|
|
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
|
|
import { createNodesV2 } from '../../../plugin';
|
|
import {
|
|
lessLoaderVersion,
|
|
reactRefreshVersion,
|
|
rspackCoreVersion,
|
|
rspackDevServerVersion,
|
|
rspackPluginMinifyVersion,
|
|
rspackPluginReactRefreshVersion,
|
|
} from '../../utils/versions';
|
|
import { InitGeneratorSchema } from './schema';
|
|
|
|
export async function rspackInitGenerator(
|
|
tree: Tree,
|
|
schema: InitGeneratorSchema
|
|
) {
|
|
assertNotUsingTsSolutionSetup(tree, 'rspack', 'init');
|
|
|
|
const tasks: GeneratorCallback[] = [];
|
|
|
|
const nxJson = readNxJson(tree);
|
|
const addPluginDefault =
|
|
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
nxJson.useInferencePlugins !== false;
|
|
schema.addPlugin ??= addPluginDefault;
|
|
|
|
if (schema.addPlugin) {
|
|
await addPlugin(
|
|
tree,
|
|
await createProjectGraphAsync(),
|
|
'@nx/rspack/plugin',
|
|
createNodesV2,
|
|
{
|
|
buildTargetName: [
|
|
'build',
|
|
'rspack:build',
|
|
'build:rspack',
|
|
'rspack-build',
|
|
'build-rspack',
|
|
],
|
|
serveTargetName: [
|
|
'serve',
|
|
'rspack:serve',
|
|
'serve:rspack',
|
|
'rspack-serve',
|
|
'serve-rspack',
|
|
],
|
|
previewTargetName: [
|
|
'preview',
|
|
'rspack:preview',
|
|
'preview:rspack',
|
|
'rspack-preview',
|
|
'preview-rspack',
|
|
],
|
|
},
|
|
schema.updatePackageScripts
|
|
);
|
|
}
|
|
|
|
const jsInitTask = await initGenerator(tree, {
|
|
...schema,
|
|
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
skipFormat: true,
|
|
});
|
|
|
|
tasks.push(jsInitTask);
|
|
|
|
const devDependencies = {
|
|
'@rspack/core': rspackCoreVersion,
|
|
'@rspack/cli': rspackCoreVersion,
|
|
'@rspack/plugin-minify': rspackPluginMinifyVersion,
|
|
'@rspack/plugin-react-refresh': rspackPluginReactRefreshVersion,
|
|
'react-refresh': reactRefreshVersion,
|
|
};
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
const version = require('../../../package.json').version;
|
|
if (version !== '0.0.1') {
|
|
// Ignored for local dev / e2e tests.
|
|
devDependencies['@nx/rspack'] = version;
|
|
}
|
|
|
|
if (schema.style === 'less') {
|
|
devDependencies['less-loader'] = lessLoaderVersion;
|
|
}
|
|
|
|
if (schema.framework !== 'none' || schema.devServer) {
|
|
devDependencies['@rspack/dev-server'] = rspackDevServerVersion;
|
|
}
|
|
|
|
const installTask = addDependenciesToPackageJson(
|
|
tree,
|
|
{},
|
|
devDependencies,
|
|
undefined,
|
|
schema.keepExistingVersions
|
|
);
|
|
tasks.push(installTask);
|
|
|
|
return runTasksInSerial(...tasks);
|
|
}
|
|
|
|
export default rspackInitGenerator;
|
|
|
|
export const rspackInitSchematic = convertNxGenerator(rspackInitGenerator);
|