Leosvel Pérez Espinosa ec801b4c16
feat(misc): enable new ts minimal setup by default and guard execution of generators with no support for it (#28199)
- 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 #
2024-10-02 08:29:06 -04:00

45 lines
1.1 KiB
TypeScript

import {
addDependenciesToPackageJson,
formatFiles,
GeneratorCallback,
removeDependenciesFromPackageJson,
runTasksInSerial,
Tree,
} from '@nx/devkit';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { nxVersion } from '../../utils/versions';
import { Schema } from './schema';
function updateDependencies(tree: Tree, options: Schema) {
const tasks: GeneratorCallback[] = [];
tasks.push(removeDependenciesFromPackageJson(tree, ['@nx/node'], []));
tasks.push(
addDependenciesToPackageJson(
tree,
{},
{ '@nx/node': nxVersion },
undefined,
options.keepExistingVersions
)
);
return runTasksInSerial(...tasks);
}
export async function initGenerator(tree: Tree, options: Schema) {
assertNotUsingTsSolutionSetup(tree, 'node', 'init');
let installTask: GeneratorCallback = () => {};
if (!options.skipPackageJson) {
installTask = updateDependencies(tree, options);
}
if (!options.skipFormat) {
await formatFiles(tree);
}
return installTask;
}
export default initGenerator;