Skip to content

Commit

Permalink
feat(core): use flag in nx.json for toggling crystal (#21980)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Feb 29, 2024
1 parent e9da3db commit a89c734
Show file tree
Hide file tree
Showing 62 changed files with 385 additions and 122 deletions.
9 changes: 9 additions & 0 deletions docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Nx.json configuration
- [targetDefaults](../../devkit/documents/NxJsonConfiguration#targetdefaults): TargetDefaults
- [tasksRunnerOptions](../../devkit/documents/NxJsonConfiguration#tasksrunneroptions): Object
- [useDaemonProcess](../../devkit/documents/NxJsonConfiguration#usedaemonprocess): boolean
- [useInferencePlugins](../../devkit/documents/NxJsonConfiguration#useinferenceplugins): boolean
- [workspaceLayout](../../devkit/documents/NxJsonConfiguration#workspacelayout): Object

## Properties
Expand Down Expand Up @@ -248,6 +249,14 @@ Set this to false to disable the daemon.

---

### useInferencePlugins

`Optional` **useInferencePlugins**: `boolean`

Set this to false to disable adding inference plugins when generating new projects

---

### workspaceLayout

`Optional` **workspaceLayout**: `Object`
Expand Down
13 changes: 13 additions & 0 deletions docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use ProjectsConfigurations or NxJsonConfiguration
- [targetDefaults](../../devkit/documents/Workspace#targetdefaults): TargetDefaults
- [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions): Object
- [useDaemonProcess](../../devkit/documents/Workspace#usedaemonprocess): boolean
- [useInferencePlugins](../../devkit/documents/Workspace#useinferenceplugins): boolean
- [version](../../devkit/documents/Workspace#version): number
- [workspaceLayout](../../devkit/documents/Workspace#workspacelayout): Object

Expand Down Expand Up @@ -340,6 +341,18 @@ Set this to false to disable the daemon.

---

### useInferencePlugins

`Optional` **useInferencePlugins**: `boolean`

Set this to false to disable adding inference plugins when generating new projects

#### Inherited from

[NxJsonConfiguration](../../devkit/documents/NxJsonConfiguration).[useInferencePlugins](../../devkit/documents/NxJsonConfiguration#useinferenceplugins)

---

### version

**version**: `number`
Expand Down
6 changes: 5 additions & 1 deletion packages/angular/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import {
joinPathFragments,
readProjectConfiguration,
updateProjectConfiguration,
readNxJson,
} from '@nx/devkit';
import { nxVersion } from '../../../utils/versions';
import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
import type { NormalizedSchema } from './normalized-schema';

export async function addE2e(tree: Tree, options: NormalizedSchema) {
// since e2e are separate projects, default to adding plugins
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

if (options.e2eTestRunner === 'cypress') {
// TODO: This can call `@nx/web:static-config` generator when ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
joinPathFragments,
offsetFromRoot,
readJson,
readNxJson,
readProjectConfiguration,
stripIndents,
updateJson,
Expand Down Expand Up @@ -342,14 +343,18 @@ export class E2eMigrator extends ProjectMigrator<SupportedTargets> {
tags: [],
implicitDependencies: [this.appName],
});
const nxJson = readNxJson(this.tree) ?? {};
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
await configurationGenerator(this.tree, {
project: this.project.name,
linter: this.isProjectUsingEsLint ? Linter.EsLint : Linter.None,
skipFormat: true,
// any target would do, we replace it later with the target existing in the project being migrated
devServerTarget: `${this.appName}:serve`,
baseUrl: 'http://localhost:4200',
addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
addPlugin,
});

const cypressConfigFilePath = this.updateOrCreateCypressConfigFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function componentConfigurationGeneratorInternal(
options: CypressComponentConfigurationSchema
) {
const tasks: GeneratorCallback[] = [];
const opts = normalizeOptions(options);
const opts = normalizeOptions(tree, options);

tasks.push(
await init(tree, {
Expand Down Expand Up @@ -78,16 +78,24 @@ export async function componentConfigurationGeneratorInternal(
return runTasksInSerial(...tasks);
}

function normalizeOptions(options: CypressComponentConfigurationSchema) {
function normalizeOptions(
tree: Tree,
options: CypressComponentConfigurationSchema
) {
const cyVersion = installedCypressVersion();
if (cyVersion && cyVersion < 10) {
throw new Error(
'Cypress version of 10 or higher is required to use component testing. See the migration guide to upgrade. https://nx.dev/cypress/v11-migration-guide'
);
}

const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

return {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
addPlugin,
...options,
directory: options.directory ?? 'cypress',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:
throw new Error('Either baseUrl or devServerTarget must be provided');
}

const nxJson = readNxJson(tree);
options.addPlugin ??=
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

return {
...options,
bundler: options.bundler ?? 'webpack',
Expand Down
7 changes: 6 additions & 1 deletion packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ export async function cypressInitGeneratorInternal(
options: Schema
) {
updateProductionFileset(tree);
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';

const nxJson = readNxJson(tree);

options.addPlugin ??=
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

if (options.addPlugin) {
addPlugin(tree);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { names, readProjectConfiguration, Tree } from '@nx/devkit';
import { names, readNxJson, readProjectConfiguration, Tree } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema';

Expand All @@ -23,8 +23,11 @@ export async function normalizeOptions(
projectNameAndRootFormat: options.projectNameAndRootFormat,
callingGenerator: '@nx/detox:application',
});

options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(host);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPlugin;

const { fileName: appFileName, className: appClassName } = names(
options.appName || options.appProject
Expand Down
7 changes: 6 additions & 1 deletion packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export function detoxInitGenerator(host: Tree, schema: Schema) {
export async function detoxInitGeneratorInternal(host: Tree, schema: Schema) {
const tasks: GeneratorCallback[] = [];

schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(host);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

schema.addPlugin ??= addPluginDefault;

if (!schema.skipPackageJson) {
tasks.push(moveDependency(host));
Expand Down
6 changes: 5 additions & 1 deletion packages/eslint/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export async function initEsLint(
tree: Tree,
options: LinterInitOptions
): Promise<GeneratorCallback> {
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPluginDefault;
const hasPlugin = hasEslintPlugin(tree);
const rootEslintFile = findEslintFile(tree);

Expand Down
7 changes: 6 additions & 1 deletion packages/eslint/src/generators/lint-project/lint-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
Tree,
} from '@nx/devkit';
import {
readNxJson,
formatFiles,
offsetFromRoot,
readJson,
Expand Down Expand Up @@ -67,7 +68,11 @@ export async function lintProjectGeneratorInternal(
tree: Tree,
options: LintProjectOptions
) {
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPluginDefault;
const tasks: GeneratorCallback[] = [];
const initTask = await lintInitGenerator(tree, {
skipPackageJson: options.skipPackageJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
generateFiles,
joinPathFragments,
logger,
readNxJson,
Tree,
} from '@nx/devkit';
import { camelize } from '@nx/devkit/src/utils/string-utils';
Expand All @@ -22,10 +23,16 @@ export async function lintWorkspaceRuleGenerator(
tree: Tree,
options: LintWorkspaceRuleGeneratorOptions
) {
const nxJson = readNxJson(tree);
// Ensure that the workspace rules project has been created
const projectGeneratorCallback = await lintWorkspaceRulesProjectGenerator(
tree,
{ skipFormat: true, addPlugin: process.env.NX_ADD_PLUGINS !== 'false' }
{
skipFormat: true,
addPlugin:
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false,
}
);

const ruleDir = joinPathFragments(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { names, Tree } from '@nx/devkit';
import { names, readNxJson, Tree } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema';

Expand Down Expand Up @@ -30,7 +30,11 @@ export async function normalizeOptions(
callingGenerator: '@nx/expo:application',
});
options.projectNameAndRootFormat = projectNameAndRootFormat;
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(host);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPluginDefault;

const { className } = names(options.name);
const parsedTags = options.tags
Expand Down
6 changes: 5 additions & 1 deletion packages/expo/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export function expoInitGenerator(tree: Tree, schema: Schema) {
}

export async function expoInitGeneratorInternal(host: Tree, schema: Schema) {
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(host);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addPlugin ??= addPluginDefault;

addGitIgnoreEntry(host);

Expand Down
8 changes: 6 additions & 2 deletions packages/expo/src/generators/library/lib/normalize-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree } from '@nx/devkit';
import { Tree, readNxJson } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema';

Expand Down Expand Up @@ -28,7 +28,11 @@ export async function normalizeOptions(
projectNameAndRootFormat: options.projectNameAndRootFormat,
callingGenerator: '@nx/expo:library',
});
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(host);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPluginDefault;

const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
Expand Down
7 changes: 6 additions & 1 deletion packages/express/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { GeneratorCallback, Tree } from '@nx/devkit';
import {
addDependenciesToPackageJson,
formatFiles,
readNxJson,
runTasksInSerial,
toJS,
updateJson,
Expand Down Expand Up @@ -114,7 +115,11 @@ async function normalizeOptions(
callingGenerator: '@nx/express:application',
});
options.projectNameAndRootFormat = projectNameAndRootFormat;
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(host);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPlugin;

return {
...options,
Expand Down
7 changes: 6 additions & 1 deletion packages/jest/src/generators/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ function normalizeOptions(
options.testEnvironment = 'jsdom';
}

options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

options.addPlugin ??= addPlugin;

options.targetName ??= 'test';

Expand Down
6 changes: 5 additions & 1 deletion packages/jest/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export async function jestInitGeneratorInternal(
tree: Tree,
options: JestInitSchema
): Promise<GeneratorCallback> {
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPluginDefault;

const presetExt = isPresetCjs(tree) ? 'cjs' : 'js';

Expand Down
7 changes: 6 additions & 1 deletion packages/js/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
names,
offsetFromRoot,
ProjectConfiguration,
readNxJson,
readProjectConfiguration,
runTasksInSerial,
toJS,
Expand Down Expand Up @@ -585,7 +586,11 @@ async function normalizeOptions(
tree: Tree,
options: LibraryGeneratorSchema
): Promise<NormalizedSchema> {
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPlugin;

/**
* We are deprecating the compiler and the buildable options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tree } from '@nx/devkit';
import { Tree, readNxJson } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Linter } from '@nx/eslint';
import type { Schema as NodeApplicationGeneratorOptions } from '@nx/node/src/generators/application/schema';
Expand All @@ -23,8 +23,13 @@ export async function normalizeOptions(
options.rootProject = appProjectRoot === '.';
options.projectNameAndRootFormat = projectNameAndRootFormat;

const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;

return {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false',
addPlugin,
...options,
strict: options.strict ?? false,
appProjectName,
Expand Down
Loading

0 comments on commit a89c734

Please sign in to comment.