Skip to content

Commit ec801b4

Browse files
authored
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 #
1 parent 942f6fc commit ec801b4

File tree

66 files changed

+275
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+275
-21
lines changed

packages/angular/src/generators/application/application.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
Tree,
88
updateNxJson,
99
} from '@nx/devkit';
10+
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
1011
import { initGenerator as jsInitGenerator } from '@nx/js';
12+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1113
import { angularInitGenerator } from '../init/init';
1214
import { setupSsr } from '../setup-ssr/setup-ssr';
1315
import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind';
@@ -27,12 +29,13 @@ import {
2729
updateEditorTsConfig,
2830
} from './lib';
2931
import type { Schema } from './schema';
30-
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
3132

3233
export async function applicationGenerator(
3334
tree: Tree,
3435
schema: Partial<Schema>
3536
): Promise<GeneratorCallback> {
37+
assertNotUsingTsSolutionSetup(tree, 'angular', 'application');
38+
3639
const options = await normalizeOptions(tree, schema);
3740
const rootOffset = offsetFromRoot(options.appProjectRoot);
3841

packages/angular/src/generators/host/host.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ import {
99
determineProjectNameAndRootOptions,
1010
ensureProjectName,
1111
} from '@nx/devkit/src/generators/project-name-and-root-utils';
12+
import { isValidVariable } from '@nx/js';
13+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1214
import { E2eTestRunner } from '../../utils/test-runners';
1315
import applicationGenerator from '../application/application';
1416
import remoteGenerator from '../remote/remote';
1517
import { setupMf } from '../setup-mf/setup-mf';
18+
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
1619
import { updateSsrSetup } from './lib';
1720
import type { Schema } from './schema';
18-
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
19-
import { isValidVariable } from '@nx/js';
2021

2122
export async function host(tree: Tree, schema: Schema) {
23+
assertNotUsingTsSolutionSetup(tree, 'angular', 'host');
24+
2225
const { typescriptConfiguration = true, ...options }: Schema = schema;
2326
options.standalone = options.standalone ?? true;
2427

packages/angular/src/generators/init/init.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ import {
99
type Tree,
1010
} from '@nx/devkit';
1111
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
12-
import { getInstalledPackageVersion, versions } from '../utils/version-utils';
12+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1313
import { createNodesV2 } from '../../plugins/plugin';
14+
import { getInstalledPackageVersion, versions } from '../utils/version-utils';
1415
import { Schema } from './schema';
1516

1617
export async function angularInitGenerator(
1718
tree: Tree,
1819
options: Schema
1920
): Promise<GeneratorCallback> {
21+
assertNotUsingTsSolutionSetup(tree, 'angular', 'init');
22+
2023
ignoreAngularCacheDirectory(tree);
2124
const installTask = installAngularDevkitCoreIfMissing(tree, options);
2225

packages/angular/src/generators/library/library.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ import { addJest } from '../utils/add-jest';
3030
import { setGeneratorDefaults } from './lib/set-generator-defaults';
3131
import { ensureAngularDependencies } from '../utils/ensure-angular-dependencies';
3232
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
33+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
3334

3435
export async function libraryGenerator(
3536
tree: Tree,
3637
schema: Schema
3738
): Promise<GeneratorCallback> {
39+
assertNotUsingTsSolutionSetup(tree, 'angular', 'library');
40+
3841
// Do some validation checks
3942
if (!schema.routing && schema.lazy) {
4043
throw new Error(`To use "--lazy" option, "--routing" must also be set.`);

packages/angular/src/generators/remote/remote.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ import {
99
determineProjectNameAndRootOptions,
1010
ensureProjectName,
1111
} from '@nx/devkit/src/generators/project-name-and-root-utils';
12+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
13+
import { swcHelpersVersion } from '@nx/js/src/utils/versions';
1214
import { E2eTestRunner } from '../../utils/test-runners';
1315
import { applicationGenerator } from '../application/application';
1416
import { setupMf } from '../setup-mf/setup-mf';
17+
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
1518
import { findNextAvailablePort, updateSsrSetup } from './lib';
1619
import type { Schema } from './schema';
17-
import { swcHelpersVersion } from '@nx/js/src/utils/versions';
18-
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
1920

2021
export async function remote(tree: Tree, schema: Schema) {
22+
assertNotUsingTsSolutionSetup(tree, 'angular', 'remote');
23+
2124
const { typescriptConfiguration = true, ...options }: Schema = schema;
2225
options.standalone = options.standalone ?? true;
2326

packages/create-nx-workspace/bin/create-nx-workspace.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ async function determineStack(
397397
name: `none`,
398398
message:
399399
process.env.NX_ADD_PLUGINS !== 'false' &&
400-
process.env.NX_ADD_TS_PLUGIN === 'true'
400+
process.env.NX_ADD_TS_PLUGIN !== 'false'
401401
? `None: Configures a TypeScript/JavaScript monorepo.`
402402
: `None: Configures a TypeScript/JavaScript project with minimal structure.`,
403403
},
@@ -447,8 +447,9 @@ async function determineNoneOptions(
447447
parsedArgs: yargs.Arguments<NoneArguments>
448448
): Promise<Partial<NoneArguments>> {
449449
if (
450+
(!parsedArgs.preset || parsedArgs.preset === Preset.TS) &&
450451
process.env.NX_ADD_PLUGINS !== 'false' &&
451-
process.env.NX_ADD_TS_PLUGIN === 'true'
452+
process.env.NX_ADD_TS_PLUGIN !== 'false'
452453
) {
453454
const reply = await enquirer.prompt<{ prettier: 'Yes' | 'No' }>([
454455
{

packages/cypress/src/generators/component-configuration/component-configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
runTasksInSerial,
1515
GeneratorCallback,
1616
} from '@nx/devkit';
17+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1718
import { installedCypressVersion } from '../../utils/cypress-version';
1819

1920
import {
@@ -42,6 +43,8 @@ export async function componentConfigurationGeneratorInternal(
4243
tree: Tree,
4344
options: CypressComponentConfigurationSchema
4445
) {
46+
assertNotUsingTsSolutionSetup(tree, 'cypress', 'component-configuration');
47+
4548
const tasks: GeneratorCallback[] = [];
4649
const opts = normalizeOptions(tree, options);
4750

packages/cypress/src/generators/configuration/configuration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ import {
1717
updateJson,
1818
updateProjectConfiguration,
1919
} from '@nx/devkit';
20+
import { Linter, LinterType } from '@nx/eslint';
2021
import {
2122
getRelativePathToRootTsConfig,
2223
initGenerator as jsInitGenerator,
2324
} from '@nx/js';
24-
import { Linter, LinterType } from '@nx/eslint';
25+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
2526
import { join } from 'path';
2627
import { addLinterToCyProject } from '../../utils/add-linter';
2728
import { addDefaultE2EConfig } from '../../utils/config';
2829
import { installedCypressVersion } from '../../utils/cypress-version';
2930
import { typesNodeVersion, viteVersion } from '../../utils/versions';
30-
import cypressInitGenerator, { addPlugin } from '../init/init';
3131
import { addBaseCypressSetup } from '../base-setup/base-setup';
32+
import cypressInitGenerator, { addPlugin } from '../init/init';
3233

3334
export interface CypressE2EConfigSchema {
3435
project: string;
@@ -67,6 +68,8 @@ export async function configurationGeneratorInternal(
6768
tree: Tree,
6869
options: CypressE2EConfigSchema
6970
) {
71+
assertNotUsingTsSolutionSetup(tree, 'cypress', 'configuration');
72+
7073
const opts = normalizeOptions(tree, options);
7174
opts.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
7275
const tasks: GeneratorCallback[] = [];

packages/cypress/src/generators/init/init.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
updateNxJson,
1212
} from '@nx/devkit';
1313
import { addPlugin as _addPlugin } from '@nx/devkit/src/utils/add-plugin';
14+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1415
import { createNodesV2 } from '../../plugins/plugin';
1516
import { cypressVersion, nxVersion } from '../../utils/versions';
1617
import { Schema } from './schema';
@@ -105,6 +106,8 @@ export async function cypressInitGeneratorInternal(
105106
tree: Tree,
106107
options: Schema
107108
) {
109+
assertNotUsingTsSolutionSetup(tree, 'cypress', 'init');
110+
108111
updateProductionFileset(tree);
109112

110113
const nxJson = readNxJson(tree);

packages/detox/src/generators/application/application.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { formatFiles, runTasksInSerial, Tree } from '@nx/devkit';
2+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
23

34
import detoxInitGenerator from '../init/init';
45
import { addGitIgnoreEntry } from './lib/add-git-ignore-entry';
@@ -20,6 +21,8 @@ export async function detoxApplicationGeneratorInternal(
2021
host: Tree,
2122
schema: Schema
2223
) {
24+
assertNotUsingTsSolutionSetup(host, 'detox', 'application');
25+
2326
const options = await normalizeOptions(host, schema);
2427

2528
const initTask = await detoxInitGenerator(host, {

packages/detox/src/generators/init/init.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Tree,
1010
} from '@nx/devkit';
1111
import { addPluginV1 } from '@nx/devkit/src/utils/add-plugin';
12+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1213
import { createNodes } from '../../plugins/plugin';
1314
import { detoxVersion, nxVersion } from '../../utils/versions';
1415
import { Schema } from './schema';
@@ -18,6 +19,8 @@ export function detoxInitGenerator(host: Tree, schema: Schema) {
1819
}
1920

2021
export async function detoxInitGeneratorInternal(host: Tree, schema: Schema) {
22+
assertNotUsingTsSolutionSetup(host, 'detox', 'init');
23+
2124
const tasks: GeneratorCallback[] = [];
2225

2326
const nxJson = readNxJson(host);

packages/esbuild/src/generators/configuration/configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@nx/devkit';
99

1010
import { getImportPath } from '@nx/js/src/utils/get-import-path';
11+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1112

1213
import { esbuildInitGenerator } from '../init/init';
1314
import { EsBuildExecutorOptions } from '../../executors/esbuild/schema';
@@ -18,6 +19,8 @@ export async function configurationGenerator(
1819
tree: Tree,
1920
options: EsBuildProjectSchema
2021
) {
22+
assertNotUsingTsSolutionSetup(tree, 'esbuild', 'configuration');
23+
2124
const task = await esbuildInitGenerator(tree, {
2225
...options,
2326
skipFormat: true,

packages/esbuild/src/generators/init/init.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import {
44
GeneratorCallback,
55
Tree,
66
} from '@nx/devkit';
7-
import { Schema } from './schema';
7+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
88
import { esbuildVersion } from '@nx/js/src/utils/versions';
99
import { nxVersion } from '../../utils/versions';
10+
import { Schema } from './schema';
1011

1112
export async function esbuildInitGenerator(tree: Tree, schema: Schema) {
13+
assertNotUsingTsSolutionSetup(tree, 'esbuild', 'init');
14+
1215
let installTask: GeneratorCallback = () => {};
1316
if (!schema.skipPackageJson) {
1417
installTask = addDependenciesToPackageJson(

packages/expo/src/generators/application/application.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Tree,
77
} from '@nx/devkit';
88
import { initGenerator as jsInitGenerator } from '@nx/js';
9+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
910

1011
import { addLinting } from '../../utils/add-linting';
1112
import { addJest } from '../../utils/add-jest';
@@ -35,6 +36,8 @@ export async function expoApplicationGeneratorInternal(
3536
host: Tree,
3637
schema: Schema
3738
): Promise<GeneratorCallback> {
39+
assertNotUsingTsSolutionSetup(host, 'expo', 'application');
40+
3841
const options = await normalizeOptions(host, schema);
3942

4043
const tasks: GeneratorCallback[] = [];

packages/expo/src/generators/init/init.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Tree,
1010
} from '@nx/devkit';
1111
import { addPluginV1 } from '@nx/devkit/src/utils/add-plugin';
12+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1213
import { createNodes } from '../../../plugins/plugin';
1314
import {
1415
expoCliVersion,
@@ -27,6 +28,8 @@ export function expoInitGenerator(tree: Tree, schema: Schema) {
2728
}
2829

2930
export async function expoInitGeneratorInternal(host: Tree, schema: Schema) {
31+
assertNotUsingTsSolutionSetup(host, 'expo', 'init');
32+
3033
const nxJson = readNxJson(host);
3134
const addPluginDefault =
3235
process.env.NX_ADD_PLUGINS !== 'false' &&

packages/expo/src/generators/library/library.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
getRelativePathToRootTsConfig,
2121
initGenerator as jsInitGenerator,
2222
} from '@nx/js';
23+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
2324
import init from '../init/init';
2425
import { addLinting } from '../../utils/add-linting';
2526
import { addJest } from '../../utils/add-jest';
@@ -49,6 +50,8 @@ export async function expoLibraryGeneratorInternal(
4950
host: Tree,
5051
schema: Schema
5152
): Promise<GeneratorCallback> {
53+
assertNotUsingTsSolutionSetup(host, 'expo', 'library');
54+
5255
const options = await normalizeOptions(host, schema);
5356
if (options.publishable === true && !schema.importPath) {
5457
throw new Error(

packages/express/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@nx/devkit": "file:../devkit",
35+
"@nx/js": "file:../js",
3536
"@nx/node": "file:../node",
3637
"tslib": "^2.3.0"
3738
},

packages/express/src/generators/application/application.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
determineProjectNameAndRootOptions,
1212
ensureProjectName,
1313
} from '@nx/devkit/src/generators/project-name-and-root-utils';
14+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
1415
import { applicationGenerator as nodeApplicationGenerator } from '@nx/node';
1516
import { tslibVersion } from '@nx/node/src/utils/versions';
1617
import { join } from 'path';
@@ -74,6 +75,8 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
7475
}
7576

7677
export async function applicationGeneratorInternal(tree: Tree, schema: Schema) {
78+
assertNotUsingTsSolutionSetup(tree, 'express', 'application');
79+
7780
const options = await normalizeOptions(tree, schema);
7881

7982
const tasks: GeneratorCallback[] = [];

packages/express/src/generators/init/init.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
runTasksInSerial,
77
Tree,
88
} from '@nx/devkit';
9+
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
910
import { expressVersion, nxVersion } from '../../utils/versions';
1011
import type { Schema } from './schema';
1112

@@ -28,6 +29,8 @@ function updateDependencies(tree: Tree, schema: Schema) {
2829
}
2930

3031
export async function initGenerator(tree: Tree, schema: Schema) {
32+
assertNotUsingTsSolutionSetup(tree, 'express', 'init');
33+
3134
let installTask: GeneratorCallback = () => {};
3235
if (!schema.skipPackageJson) {
3336
installTask = updateDependencies(tree, schema);

packages/js/src/generators/init/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function initGeneratorInternal(
9090
process.env.NX_ADD_PLUGINS !== 'false' &&
9191
nxJson.useInferencePlugins !== false;
9292
schema.addTsPlugin ??=
93-
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN === 'true';
93+
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN !== 'false';
9494

9595
if (schema.addTsPlugin) {
9696
await addPlugin(

packages/js/src/utils/typescript/ts-solution-setup.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readJson, readNxJson, type Tree } from '@nx/devkit';
1+
import { output, readJson, readNxJson, type Tree } from '@nx/devkit';
22
import { isUsingPackageManagerWorkspaces } from '../package-manager-workspaces';
33

44
export function isUsingTypeScriptPlugin(tree: Tree): boolean {
@@ -61,3 +61,29 @@ function isWorkspaceSetupWithTsSolution(tree: Tree): boolean {
6161

6262
return true;
6363
}
64+
65+
export function assertNotUsingTsSolutionSetup(
66+
tree: Tree,
67+
pluginName: string,
68+
generatorName: string
69+
): void {
70+
if (
71+
process.env.NX_IGNORE_UNSUPPORTED_TS_SETUP === 'true' ||
72+
!isUsingTsSolutionSetup(tree)
73+
) {
74+
return;
75+
}
76+
77+
const artifactString =
78+
generatorName === 'init'
79+
? `"@nx/${pluginName}" plugin`
80+
: `"@nx/${pluginName}:${generatorName}" generator`;
81+
output.error({
82+
title: `The ${artifactString} doesn't yet support the existing TypeScript setup`,
83+
bodyLines: [
84+
`We're working hard to support the existing TypeScript setup with the ${artifactString}. We'll soon release a new version of Nx with support for it.`,
85+
],
86+
});
87+
88+
process.exit(1);
89+
}

0 commit comments

Comments
 (0)