Skip to content

Commit

Permalink
feat(misc): enable new ts minimal setup by default and guard executio…
Browse files Browse the repository at this point in the history
…n of generators with no support for it
  • Loading branch information
leosvelperez committed Sep 30, 2024
1 parent 2a70629 commit caf24a2
Show file tree
Hide file tree
Showing 66 changed files with 274 additions and 21 deletions.
5 changes: 4 additions & 1 deletion packages/angular/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
Tree,
updateNxJson,
} from '@nx/devkit';
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
import { initGenerator as jsInitGenerator } from '@nx/js';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { angularInitGenerator } from '../init/init';
import { setupSsr } from '../setup-ssr/setup-ssr';
import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind';
Expand All @@ -27,12 +29,13 @@ import {
updateEditorTsConfig,
} from './lib';
import type { Schema } from './schema';
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';

export async function applicationGenerator(
tree: Tree,
schema: Partial<Schema>
): Promise<GeneratorCallback> {
assertNotUsingTsSolutionSetup(tree, 'angular', 'application');

const options = await normalizeOptions(tree, schema);
const rootOffset = offsetFromRoot(options.appProjectRoot);

Expand Down
7 changes: 5 additions & 2 deletions packages/angular/src/generators/host/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import {
Tree,
} from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { isValidVariable } from '@nx/js';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { E2eTestRunner } from '../../utils/test-runners';
import applicationGenerator from '../application/application';
import remoteGenerator from '../remote/remote';
import { setupMf } from '../setup-mf/setup-mf';
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
import { updateSsrSetup } from './lib';
import type { Schema } from './schema';
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
import { isValidVariable } from '@nx/js';

export async function host(tree: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(tree, 'angular', 'host');

const { typescriptConfiguration = true, ...options }: Schema = schema;
options.standalone = options.standalone ?? true;

Expand Down
5 changes: 4 additions & 1 deletion packages/angular/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import {
type Tree,
} from '@nx/devkit';
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
import { getInstalledPackageVersion, versions } from '../utils/version-utils';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { createNodesV2 } from '../../plugins/plugin';
import { getInstalledPackageVersion, versions } from '../utils/version-utils';
import { Schema } from './schema';

export async function angularInitGenerator(
tree: Tree,
options: Schema
): Promise<GeneratorCallback> {
assertNotUsingTsSolutionSetup(tree, 'angular', 'init');

ignoreAngularCacheDirectory(tree);
const installTask = installAngularDevkitCoreIfMissing(tree, options);

Expand Down
3 changes: 3 additions & 0 deletions packages/angular/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import { addJest } from '../utils/add-jest';
import { setGeneratorDefaults } from './lib/set-generator-defaults';
import { ensureAngularDependencies } from '../utils/ensure-angular-dependencies';
import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

export async function libraryGenerator(
tree: Tree,
schema: Schema
): Promise<GeneratorCallback> {
assertNotUsingTsSolutionSetup(tree, 'angular', 'library');

// Do some validation checks
if (!schema.routing && schema.lazy) {
throw new Error(`To use "--lazy" option, "--routing" must also be set.`);
Expand Down
7 changes: 5 additions & 2 deletions packages/angular/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import {
Tree,
} from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { swcHelpersVersion } from '@nx/js/src/utils/versions';
import { E2eTestRunner } from '../../utils/test-runners';
import { applicationGenerator } from '../application/application';
import { setupMf } from '../setup-mf/setup-mf';
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';
import { findNextAvailablePort, updateSsrSetup } from './lib';
import type { Schema } from './schema';
import { swcHelpersVersion } from '@nx/js/src/utils/versions';
import { addMfEnvToTargetDefaultInputs } from '../utils/add-mf-env-to-inputs';

export async function remote(tree: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(tree, 'angular', 'remote');

const { typescriptConfiguration = true, ...options }: Schema = schema;
options.standalone = options.standalone ?? true;

Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async function determineStack(
name: `none`,
message:
process.env.NX_ADD_PLUGINS !== 'false' &&
process.env.NX_ADD_TS_PLUGIN === 'true'
process.env.NX_ADD_TS_PLUGIN !== 'false'
? `None: Configures a TypeScript/JavaScript monorepo.`
: `None: Configures a TypeScript/JavaScript project with minimal structure.`,
},
Expand Down Expand Up @@ -448,7 +448,7 @@ async function determineNoneOptions(
): Promise<Partial<NoneArguments>> {
if (
process.env.NX_ADD_PLUGINS !== 'false' &&
process.env.NX_ADD_TS_PLUGIN === 'true'
process.env.NX_ADD_TS_PLUGIN !== 'false'
) {
const reply = await enquirer.prompt<{ prettier: 'Yes' | 'No' }>([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
runTasksInSerial,
GeneratorCallback,
} from '@nx/devkit';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { installedCypressVersion } from '../../utils/cypress-version';

import {
Expand Down Expand Up @@ -42,6 +43,8 @@ export async function componentConfigurationGeneratorInternal(
tree: Tree,
options: CypressComponentConfigurationSchema
) {
assertNotUsingTsSolutionSetup(tree, 'cypress', 'component-configuration');

const tasks: GeneratorCallback[] = [];
const opts = normalizeOptions(tree, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ import {
updateJson,
updateProjectConfiguration,
} from '@nx/devkit';
import { Linter, LinterType } from '@nx/eslint';
import {
getRelativePathToRootTsConfig,
initGenerator as jsInitGenerator,
} from '@nx/js';
import { Linter, LinterType } from '@nx/eslint';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { join } from 'path';
import { addLinterToCyProject } from '../../utils/add-linter';
import { addDefaultE2EConfig } from '../../utils/config';
import { installedCypressVersion } from '../../utils/cypress-version';
import { typesNodeVersion, viteVersion } from '../../utils/versions';
import cypressInitGenerator, { addPlugin } from '../init/init';
import { addBaseCypressSetup } from '../base-setup/base-setup';
import cypressInitGenerator, { addPlugin } from '../init/init';

export interface CypressE2EConfigSchema {
project: string;
Expand Down Expand Up @@ -67,6 +68,8 @@ export async function configurationGeneratorInternal(
tree: Tree,
options: CypressE2EConfigSchema
) {
assertNotUsingTsSolutionSetup(tree, 'cypress', 'configuration');

const opts = normalizeOptions(tree, options);
opts.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const tasks: GeneratorCallback[] = [];
Expand Down
3 changes: 3 additions & 0 deletions packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
updateNxJson,
} from '@nx/devkit';
import { addPlugin as _addPlugin } from '@nx/devkit/src/utils/add-plugin';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { createNodesV2 } from '../../plugins/plugin';
import { cypressVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';
Expand Down Expand Up @@ -105,6 +106,8 @@ export async function cypressInitGeneratorInternal(
tree: Tree,
options: Schema
) {
assertNotUsingTsSolutionSetup(tree, 'cypress', 'init');

updateProductionFileset(tree);

const nxJson = readNxJson(tree);
Expand Down
3 changes: 3 additions & 0 deletions packages/detox/src/generators/application/application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatFiles, runTasksInSerial, Tree } from '@nx/devkit';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

import detoxInitGenerator from '../init/init';
import { addGitIgnoreEntry } from './lib/add-git-ignore-entry';
Expand All @@ -20,6 +21,8 @@ export async function detoxApplicationGeneratorInternal(
host: Tree,
schema: Schema
) {
assertNotUsingTsSolutionSetup(host, 'detox', 'application');

const options = await normalizeOptions(host, schema);

const initTask = await detoxInitGenerator(host, {
Expand Down
3 changes: 3 additions & 0 deletions packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Tree,
} from '@nx/devkit';
import { addPluginV1 } from '@nx/devkit/src/utils/add-plugin';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { createNodes } from '../../plugins/plugin';
import { detoxVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';
Expand All @@ -18,6 +19,8 @@ export function detoxInitGenerator(host: Tree, schema: Schema) {
}

export async function detoxInitGeneratorInternal(host: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(host, 'detox', 'init');

const tasks: GeneratorCallback[] = [];

const nxJson = readNxJson(host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@nx/devkit';

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

import { esbuildInitGenerator } from '../init/init';
import { EsBuildExecutorOptions } from '../../executors/esbuild/schema';
Expand All @@ -18,6 +19,8 @@ export async function configurationGenerator(
tree: Tree,
options: EsBuildProjectSchema
) {
assertNotUsingTsSolutionSetup(tree, 'esbuild', 'configuration');

const task = await esbuildInitGenerator(tree, {
...options,
skipFormat: true,
Expand Down
5 changes: 4 additions & 1 deletion packages/esbuild/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import {
GeneratorCallback,
Tree,
} from '@nx/devkit';
import { Schema } from './schema';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { esbuildVersion } from '@nx/js/src/utils/versions';
import { nxVersion } from '../../utils/versions';
import { Schema } from './schema';

export async function esbuildInitGenerator(tree: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(tree, 'esbuild', 'init');

let installTask: GeneratorCallback = () => {};
if (!schema.skipPackageJson) {
installTask = addDependenciesToPackageJson(
Expand Down
3 changes: 3 additions & 0 deletions packages/expo/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Tree,
} from '@nx/devkit';
import { initGenerator as jsInitGenerator } from '@nx/js';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

import { addLinting } from '../../utils/add-linting';
import { addJest } from '../../utils/add-jest';
Expand Down Expand Up @@ -35,6 +36,8 @@ export async function expoApplicationGeneratorInternal(
host: Tree,
schema: Schema
): Promise<GeneratorCallback> {
assertNotUsingTsSolutionSetup(host, 'expo', 'application');

const options = await normalizeOptions(host, schema);

const tasks: GeneratorCallback[] = [];
Expand Down
3 changes: 3 additions & 0 deletions packages/expo/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Tree,
} from '@nx/devkit';
import { addPluginV1 } from '@nx/devkit/src/utils/add-plugin';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { createNodes } from '../../../plugins/plugin';
import {
expoCliVersion,
Expand All @@ -27,6 +28,8 @@ export function expoInitGenerator(tree: Tree, schema: Schema) {
}

export async function expoInitGeneratorInternal(host: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(host, 'expo', 'init');

const nxJson = readNxJson(host);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
Expand Down
3 changes: 3 additions & 0 deletions packages/expo/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getRelativePathToRootTsConfig,
initGenerator as jsInitGenerator,
} from '@nx/js';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import init from '../init/init';
import { addLinting } from '../../utils/add-linting';
import { addJest } from '../../utils/add-jest';
Expand Down Expand Up @@ -49,6 +50,8 @@ export async function expoLibraryGeneratorInternal(
host: Tree,
schema: Schema
): Promise<GeneratorCallback> {
assertNotUsingTsSolutionSetup(host, 'expo', 'library');

const options = await normalizeOptions(host, schema);
if (options.publishable === true && !schema.importPath) {
throw new Error(
Expand Down
1 change: 1 addition & 0 deletions packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"dependencies": {
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/node": "file:../node",
"tslib": "^2.3.0"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/express/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
updateJson,
} from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { applicationGenerator as nodeApplicationGenerator } from '@nx/node';
import { tslibVersion } from '@nx/node/src/utils/versions';
import { join } from 'path';
Expand Down Expand Up @@ -71,6 +72,8 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
}

export async function applicationGeneratorInternal(tree: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(tree, 'express', 'application');

const options = await normalizeOptions(tree, schema);

const tasks: GeneratorCallback[] = [];
Expand Down
3 changes: 3 additions & 0 deletions packages/express/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
runTasksInSerial,
Tree,
} from '@nx/devkit';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
import { expressVersion, nxVersion } from '../../utils/versions';
import type { Schema } from './schema';

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

export async function initGenerator(tree: Tree, schema: Schema) {
assertNotUsingTsSolutionSetup(tree, 'express', 'init');

let installTask: GeneratorCallback = () => {};
if (!schema.skipPackageJson) {
installTask = updateDependencies(tree, schema);
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function initGeneratorInternal(
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addTsPlugin ??=
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN === 'true';
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN !== 'false';

if (schema.addTsPlugin) {
await addPlugin(
Expand Down
28 changes: 27 additions & 1 deletion packages/js/src/utils/typescript/ts-solution-setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readJson, readNxJson, type Tree } from '@nx/devkit';
import { output, readJson, readNxJson, type Tree } from '@nx/devkit';
import { isUsingPackageManagerWorkspaces } from '../package-manager-workspaces';

export function isUsingTypeScriptPlugin(tree: Tree): boolean {
Expand Down Expand Up @@ -61,3 +61,29 @@ function isWorkspaceSetupWithTsSolution(tree: Tree): boolean {

return true;
}

export function assertNotUsingTsSolutionSetup(
tree: Tree,
pluginName: string,
generatorName: string
): void {
if (
process.env.NX_IGNORE_UNSUPPORTED_TS_SETUP === 'true' ||
!isUsingTsSolutionSetup(tree)
) {
return;
}

const artifactString =
generatorName === 'init'
? `"@nx/${pluginName}" plugin`
: `"@nx/${pluginName}:${generatorName}" generator`;
output.error({
title: `The ${artifactString} doesn't yet support the existing TypeScript setup`,
bodyLines: [
`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.`,
],
});

process.exit(1);
}
Loading

0 comments on commit caf24a2

Please sign in to comment.