feat(core): use flag in nx.json for toggling crystal (#21980)

This commit is contained in:
Craigory Coppola 2024-02-29 15:18:46 -05:00 committed by GitHub
parent e9da3db560
commit a89c73483e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
62 changed files with 385 additions and 122 deletions

View File

@ -38,6 +38,7 @@ Nx.json configuration
- [targetDefaults](../../devkit/documents/NxJsonConfiguration#targetdefaults): TargetDefaults - [targetDefaults](../../devkit/documents/NxJsonConfiguration#targetdefaults): TargetDefaults
- [tasksRunnerOptions](../../devkit/documents/NxJsonConfiguration#tasksrunneroptions): Object - [tasksRunnerOptions](../../devkit/documents/NxJsonConfiguration#tasksrunneroptions): Object
- [useDaemonProcess](../../devkit/documents/NxJsonConfiguration#usedaemonprocess): boolean - [useDaemonProcess](../../devkit/documents/NxJsonConfiguration#usedaemonprocess): boolean
- [useInferencePlugins](../../devkit/documents/NxJsonConfiguration#useinferenceplugins): boolean
- [workspaceLayout](../../devkit/documents/NxJsonConfiguration#workspacelayout): Object - [workspaceLayout](../../devkit/documents/NxJsonConfiguration#workspacelayout): Object
## Properties ## Properties
@ -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 ### workspaceLayout
`Optional` **workspaceLayout**: `Object` `Optional` **workspaceLayout**: `Object`

View File

@ -37,6 +37,7 @@ use ProjectsConfigurations or NxJsonConfiguration
- [targetDefaults](../../devkit/documents/Workspace#targetdefaults): TargetDefaults - [targetDefaults](../../devkit/documents/Workspace#targetdefaults): TargetDefaults
- [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions): Object - [tasksRunnerOptions](../../devkit/documents/Workspace#tasksrunneroptions): Object
- [useDaemonProcess](../../devkit/documents/Workspace#usedaemonprocess): boolean - [useDaemonProcess](../../devkit/documents/Workspace#usedaemonprocess): boolean
- [useInferencePlugins](../../devkit/documents/Workspace#useinferenceplugins): boolean
- [version](../../devkit/documents/Workspace#version): number - [version](../../devkit/documents/Workspace#version): number
- [workspaceLayout](../../devkit/documents/Workspace#workspacelayout): Object - [workspaceLayout](../../devkit/documents/Workspace#workspacelayout): Object
@ -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
**version**: `number` **version**: `number`

View File

@ -8,6 +8,7 @@ import {
joinPathFragments, joinPathFragments,
readProjectConfiguration, readProjectConfiguration,
updateProjectConfiguration, updateProjectConfiguration,
readNxJson,
} from '@nx/devkit'; } from '@nx/devkit';
import { nxVersion } from '../../../utils/versions'; import { nxVersion } from '../../../utils/versions';
import { getInstalledAngularVersionInfo } from '../../utils/version-utils'; import { getInstalledAngularVersionInfo } from '../../utils/version-utils';
@ -15,7 +16,10 @@ import type { NormalizedSchema } from './normalized-schema';
export async function addE2e(tree: Tree, options: NormalizedSchema) { export async function addE2e(tree: Tree, options: NormalizedSchema) {
// since e2e are separate projects, default to adding plugins // 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') { if (options.e2eTestRunner === 'cypress') {
// TODO: This can call `@nx/web:static-config` generator when ready // TODO: This can call `@nx/web:static-config` generator when ready

View File

@ -11,6 +11,7 @@ import {
joinPathFragments, joinPathFragments,
offsetFromRoot, offsetFromRoot,
readJson, readJson,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
stripIndents, stripIndents,
updateJson, updateJson,
@ -342,6 +343,10 @@ export class E2eMigrator extends ProjectMigrator<SupportedTargets> {
tags: [], tags: [],
implicitDependencies: [this.appName], implicitDependencies: [this.appName],
}); });
const nxJson = readNxJson(this.tree) ?? {};
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
await configurationGenerator(this.tree, { await configurationGenerator(this.tree, {
project: this.project.name, project: this.project.name,
linter: this.isProjectUsingEsLint ? Linter.EsLint : Linter.None, linter: this.isProjectUsingEsLint ? Linter.EsLint : Linter.None,
@ -349,7 +354,7 @@ export class E2eMigrator extends ProjectMigrator<SupportedTargets> {
// any target would do, we replace it later with the target existing in the project being migrated // any target would do, we replace it later with the target existing in the project being migrated
devServerTarget: `${this.appName}:serve`, devServerTarget: `${this.appName}:serve`,
baseUrl: 'http://localhost:4200', baseUrl: 'http://localhost:4200',
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin,
}); });
const cypressConfigFilePath = this.updateOrCreateCypressConfigFile( const cypressConfigFilePath = this.updateOrCreateCypressConfigFile(

View File

@ -43,7 +43,7 @@ export async function componentConfigurationGeneratorInternal(
options: CypressComponentConfigurationSchema options: CypressComponentConfigurationSchema
) { ) {
const tasks: GeneratorCallback[] = []; const tasks: GeneratorCallback[] = [];
const opts = normalizeOptions(options); const opts = normalizeOptions(tree, options);
tasks.push( tasks.push(
await init(tree, { await init(tree, {
@ -78,7 +78,10 @@ export async function componentConfigurationGeneratorInternal(
return runTasksInSerial(...tasks); return runTasksInSerial(...tasks);
} }
function normalizeOptions(options: CypressComponentConfigurationSchema) { function normalizeOptions(
tree: Tree,
options: CypressComponentConfigurationSchema
) {
const cyVersion = installedCypressVersion(); const cyVersion = installedCypressVersion();
if (cyVersion && cyVersion < 10) { if (cyVersion && cyVersion < 10) {
throw new Error( throw new Error(
@ -86,8 +89,13 @@ function normalizeOptions(options: CypressComponentConfigurationSchema) {
); );
} }
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
return { return {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin,
...options, ...options,
directory: options.directory ?? 'cypress', directory: options.directory ?? 'cypress',
}; };

View File

@ -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'); 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 { return {
...options, ...options,
bundler: options.bundler ?? 'webpack', bundler: options.bundler ?? 'webpack',

View File

@ -105,7 +105,12 @@ export async function cypressInitGeneratorInternal(
options: Schema options: Schema
) { ) {
updateProductionFileset(tree); 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) { if (options.addPlugin) {
addPlugin(tree); addPlugin(tree);

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema'; import { Schema } from '../schema';
@ -23,8 +23,11 @@ export async function normalizeOptions(
projectNameAndRootFormat: options.projectNameAndRootFormat, projectNameAndRootFormat: options.projectNameAndRootFormat,
callingGenerator: '@nx/detox:application', callingGenerator: '@nx/detox:application',
}); });
const nxJson = readNxJson(host);
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
options.addPlugin ??= addPlugin;
const { fileName: appFileName, className: appClassName } = names( const { fileName: appFileName, className: appClassName } = names(
options.appName || options.appProject options.appName || options.appProject

View File

@ -20,7 +20,12 @@ export function detoxInitGenerator(host: Tree, schema: Schema) {
export async function detoxInitGeneratorInternal(host: Tree, schema: Schema) { export async function detoxInitGeneratorInternal(host: Tree, schema: Schema) {
const tasks: GeneratorCallback[] = []; 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) { if (!schema.skipPackageJson) {
tasks.push(moveDependency(host)); tasks.push(moveDependency(host));

View File

@ -74,7 +74,11 @@ export async function initEsLint(
tree: Tree, tree: Tree,
options: LinterInitOptions options: LinterInitOptions
): Promise<GeneratorCallback> { ): 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 hasPlugin = hasEslintPlugin(tree);
const rootEslintFile = findEslintFile(tree); const rootEslintFile = findEslintFile(tree);

View File

@ -5,6 +5,7 @@ import type {
Tree, Tree,
} from '@nx/devkit'; } from '@nx/devkit';
import { import {
readNxJson,
formatFiles, formatFiles,
offsetFromRoot, offsetFromRoot,
readJson, readJson,
@ -67,7 +68,11 @@ export async function lintProjectGeneratorInternal(
tree: Tree, tree: Tree,
options: LintProjectOptions 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 tasks: GeneratorCallback[] = [];
const initTask = await lintInitGenerator(tree, { const initTask = await lintInitGenerator(tree, {
skipPackageJson: options.skipPackageJson, skipPackageJson: options.skipPackageJson,

View File

@ -5,6 +5,7 @@ import {
generateFiles, generateFiles,
joinPathFragments, joinPathFragments,
logger, logger,
readNxJson,
Tree, Tree,
} from '@nx/devkit'; } from '@nx/devkit';
import { camelize } from '@nx/devkit/src/utils/string-utils'; import { camelize } from '@nx/devkit/src/utils/string-utils';
@ -22,10 +23,16 @@ export async function lintWorkspaceRuleGenerator(
tree: Tree, tree: Tree,
options: LintWorkspaceRuleGeneratorOptions options: LintWorkspaceRuleGeneratorOptions
) { ) {
const nxJson = readNxJson(tree);
// Ensure that the workspace rules project has been created // Ensure that the workspace rules project has been created
const projectGeneratorCallback = await lintWorkspaceRulesProjectGenerator( const projectGeneratorCallback = await lintWorkspaceRulesProjectGenerator(
tree, 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( const ruleDir = joinPathFragments(

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema'; import { Schema } from '../schema';
@ -30,7 +30,11 @@ export async function normalizeOptions(
callingGenerator: '@nx/expo:application', callingGenerator: '@nx/expo:application',
}); });
options.projectNameAndRootFormat = projectNameAndRootFormat; 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 { className } = names(options.name);
const parsedTags = options.tags const parsedTags = options.tags

View File

@ -28,7 +28,11 @@ export function expoInitGenerator(tree: Tree, schema: Schema) {
} }
export async function expoInitGeneratorInternal(host: 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); addGitIgnoreEntry(host);

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema'; import { Schema } from '../schema';
@ -28,7 +28,11 @@ export async function normalizeOptions(
projectNameAndRootFormat: options.projectNameAndRootFormat, projectNameAndRootFormat: options.projectNameAndRootFormat,
callingGenerator: '@nx/expo:library', 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 const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim()) ? options.tags.split(',').map((s) => s.trim())

View File

@ -2,6 +2,7 @@ import type { GeneratorCallback, Tree } from '@nx/devkit';
import { import {
addDependenciesToPackageJson, addDependenciesToPackageJson,
formatFiles, formatFiles,
readNxJson,
runTasksInSerial, runTasksInSerial,
toJS, toJS,
updateJson, updateJson,
@ -114,7 +115,11 @@ async function normalizeOptions(
callingGenerator: '@nx/express:application', callingGenerator: '@nx/express:application',
}); });
options.projectNameAndRootFormat = projectNameAndRootFormat; 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 { return {
...options, ...options,

View File

@ -36,7 +36,12 @@ function normalizeOptions(
options.testEnvironment = 'jsdom'; 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'; options.targetName ??= 'test';

View File

@ -110,7 +110,11 @@ export async function jestInitGeneratorInternal(
tree: Tree, tree: Tree,
options: JestInitSchema options: JestInitSchema
): Promise<GeneratorCallback> { ): 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'; const presetExt = isPresetCjs(tree) ? 'cjs' : 'js';

View File

@ -9,6 +9,7 @@ import {
names, names,
offsetFromRoot, offsetFromRoot,
ProjectConfiguration, ProjectConfiguration,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
runTasksInSerial, runTasksInSerial,
toJS, toJS,
@ -585,7 +586,11 @@ async function normalizeOptions(
tree: Tree, tree: Tree,
options: LibraryGeneratorSchema options: LibraryGeneratorSchema
): Promise<NormalizedSchema> { ): 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. * We are deprecating the compiler and the buildable options.

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Linter } from '@nx/eslint'; import { Linter } from '@nx/eslint';
import type { Schema as NodeApplicationGeneratorOptions } from '@nx/node/src/generators/application/schema'; import type { Schema as NodeApplicationGeneratorOptions } from '@nx/node/src/generators/application/schema';
@ -23,8 +23,13 @@ export async function normalizeOptions(
options.rootProject = appProjectRoot === '.'; options.rootProject = appProjectRoot === '.';
options.projectNameAndRootFormat = projectNameAndRootFormat; options.projectNameAndRootFormat = projectNameAndRootFormat;
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
return { return {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin,
...options, ...options,
strict: options.strict ?? false, strict: options.strict ?? false,
appProjectName, appProjectName,

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope'; import { getNpmScope } from '@nx/js/src/utils/package-json/get-npm-scope';
import type { LibraryGeneratorSchema as JsLibraryGeneratorSchema } from '@nx/js/src/utils/schema'; import type { LibraryGeneratorSchema as JsLibraryGeneratorSchema } from '@nx/js/src/utils/schema';
@ -22,7 +22,12 @@ export async function normalizeOptions(
projectNameAndRootFormat: options.projectNameAndRootFormat, projectNameAndRootFormat: options.projectNameAndRootFormat,
callingGenerator: '@nx/nest:library', callingGenerator: '@nx/nest:library',
}); });
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;
const fileName = options.simpleName const fileName = options.simpleName
? projectNames.projectSimpleName ? projectNames.projectSimpleName

View File

@ -1,4 +1,4 @@
import { joinPathFragments, names, Tree } from '@nx/devkit'; import { joinPathFragments, names, readNxJson, Tree } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Linter } from '@nx/eslint'; import { Linter } from '@nx/eslint';
import { assertValidStyle } from '@nx/react/src/utils/assertion'; import { assertValidStyle } from '@nx/react/src/utils/assertion';
@ -34,7 +34,13 @@ export async function normalizeOptions(
}); });
options.rootProject = appProjectRoot === '.'; options.rootProject = appProjectRoot === '.';
options.projectNameAndRootFormat = projectNameAndRootFormat; 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;
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`; const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;

View File

@ -4,6 +4,7 @@ import {
runTasksInSerial, runTasksInSerial,
type GeneratorCallback, type GeneratorCallback,
type Tree, type Tree,
readNxJson,
} from '@nx/devkit'; } from '@nx/devkit';
import { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts'; import { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts';
import { reactDomVersion, reactVersion } from '@nx/react/src/utils/versions'; import { reactDomVersion, reactVersion } from '@nx/react/src/utils/versions';
@ -44,7 +45,12 @@ export async function nextInitGeneratorInternal(
host: Tree, host: Tree,
schema: InitSchema schema: InitSchema
) { ) {
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.addPlugin) { if (schema.addPlugin) {
addPlugin(host); addPlugin(host);
} }

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema'; import { Schema } from '../schema';
@ -21,7 +21,12 @@ export async function normalizeOptions(
callingGenerator: '@nx/next:library', callingGenerator: '@nx/next:library',
}); });
options.projectNameAndRootFormat = projectNameAndRootFormat; 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 { return {
...options, ...options,

View File

@ -10,6 +10,7 @@ import {
names, names,
offsetFromRoot, offsetFromRoot,
ProjectConfiguration, ProjectConfiguration,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
runTasksInSerial, runTasksInSerial,
TargetConfiguration, TargetConfiguration,
@ -543,8 +544,13 @@ async function normalizeOptions(
? options.tags.split(',').map((s) => s.trim()) ? options.tags.split(',').map((s) => s.trim())
: []; : [];
const nxJson = readNxJson(host);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
return { return {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin,
...options, ...options,
name: appProjectName, name: appProjectName,
frontendProject: options.frontendProject frontendProject: options.frontendProject

View File

@ -7,6 +7,7 @@ import {
joinPathFragments, joinPathFragments,
names, names,
offsetFromRoot, offsetFromRoot,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
runTasksInSerial, runTasksInSerial,
Tree, Tree,
@ -163,8 +164,13 @@ async function normalizeOptions(
callingGenerator: null, callingGenerator: null,
}); });
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
return { return {
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin,
...options, ...options,
e2eProjectRoot, e2eProjectRoot,
e2eProjectName, e2eProjectName,

View File

@ -6,6 +6,7 @@ import {
joinPathFragments, joinPathFragments,
names, names,
offsetFromRoot, offsetFromRoot,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
runTasksInSerial, runTasksInSerial,
toJS, toJS,
@ -101,7 +102,13 @@ async function normalizeOptions(
callingGenerator: '@nx/node:library', callingGenerator: '@nx/node:library',
}); });
options.projectNameAndRootFormat = projectNameAndRootFormat; options.projectNameAndRootFormat = projectNameAndRootFormat;
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 fileName = getCaseAwareFileName({ const fileName = getCaseAwareFileName({
fileName: options.simpleModuleName fileName: options.simpleModuleName

View File

@ -86,7 +86,7 @@
"18.0.0-disable-adding-plugins-for-existing-workspaces": { "18.0.0-disable-adding-plugins-for-existing-workspaces": {
"cli": "nx", "cli": "nx",
"version": "18.0.0-beta.2", "version": "18.0.0-beta.2",
"description": "Updates .env to disabled adding plugins when generating projects in an existing Nx workspace", "description": "Updates nx.json to disabled adding plugins when generating projects in an existing Nx workspace",
"implementation": "./src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces", "implementation": "./src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces",
"x-repair-skip": true "x-repair-skip": true
}, },

View File

@ -101,6 +101,10 @@
"type": "boolean", "type": "boolean",
"description": "Specifies whether the daemon should be used for the default tasks runner." "description": "Specifies whether the daemon should be used for the default tasks runner."
}, },
"useInferencePlugins": {
"type": "boolean",
"description": "Specifies whether to add inference plugins when generating new projects."
},
"release": { "release": {
"type": "object", "type": "object",
"description": "Configuration for the nx release commands.", "description": "Configuration for the nx release commands.",

View File

@ -75,6 +75,7 @@ export const allowedWorkspaceExtensions = [
'parallel', 'parallel',
'cacheDirectory', 'cacheDirectory',
'useDaemonProcess', 'useDaemonProcess',
'useInferencePlugins',
] as const; ] as const;
if (!patched) { if (!patched) {

View File

@ -112,6 +112,7 @@ async function initializePlugin(
updatePackageScripts = options.updatePackageScripts; updatePackageScripts = options.updatePackageScripts;
} else { } else {
updatePackageScripts = updatePackageScripts =
readNxJson().useInferencePlugins !== false &&
process.env.NX_ADD_PLUGINS !== 'false' && process.env.NX_ADD_PLUGINS !== 'false' &&
coreNxPlugins.includes(pkgName); coreNxPlugins.includes(pkgName);
} }

View File

@ -1,7 +1,10 @@
import { Argv, CommandModule } from 'yargs'; import { Argv, CommandModule } from 'yargs';
import { parseCSV } from '../yargs-utils/shared-options'; import { parseCSV } from '../yargs-utils/shared-options';
import { readNxJson } from '../../config/nx-json';
const useV2 = process.env['NX_ADD_PLUGINS'] !== 'false'; const useV2 =
process.env['NX_ADD_PLUGINS'] !== 'false' &&
readNxJson().useInferencePlugins !== false;
export const yargsInitCommand: CommandModule = { export const yargsInitCommand: CommandModule = {
command: 'init', command: 'init',

View File

@ -392,6 +392,11 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
* Set this to false to disable the daemon. * Set this to false to disable the daemon.
*/ */
useDaemonProcess?: boolean; useDaemonProcess?: boolean;
/**
* Set this to false to disable adding inference plugins when generating new projects
*/
useInferencePlugins?: boolean;
} }
export type PluginConfiguration = export type PluginConfiguration =

View File

@ -1,29 +1,26 @@
import { createTree } from '../../generators/testing-utils/create-tree'; import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace';
import migrate from './disable-crystal-for-existing-workspaces'; import migrate from './disable-crystal-for-existing-workspaces';
describe('disable crystal for existing workspaces', () => { describe('disable crystal for existing workspaces', () => {
it("should create a .env if it doesn't exist", () => { it('should add flag to nx.json', () => {
const tree = createTree(); const tree = createTreeWithEmptyWorkspace();
migrate(tree); migrate(tree);
expect(tree.read('.env', 'utf-8')).toMatchInlineSnapshot(` expect(tree.read('nx.json', 'utf-8')).toMatchInlineSnapshot(`
"# Nx 18 enables using plugins to infer targets by default "{
# This is disabled for existing workspaces to maintain compatibility "affected": {
# For more info, see: https://nx.dev/concepts/inferred-tasks "defaultBase": "main"
NX_ADD_PLUGINS=false" },
`); "targetDefaults": {
}); "build": {
"cache": true
it('should update an existing .env', () => { },
const tree = createTree(); "lint": {
tree.write('.env', 'FOO=bar'); "cache": true
migrate(tree); }
expect(tree.read('.env', 'utf-8')).toMatchInlineSnapshot(` },
"FOO=bar "useInferencePlugins": false
}
# Nx 18 enables using plugins to infer targets by default "
# This is disabled for existing workspaces to maintain compatibility
# For more info, see: https://nx.dev/concepts/inferred-tasks
NX_ADD_PLUGINS=false"
`); `);
}); });
}); });

View File

@ -1,33 +1,8 @@
import { readNxJson, updateNxJson } from '../../generators/utils/nx-json';
import { Tree } from '../../generators/tree'; import { Tree } from '../../generators/tree';
import { logger } from '../../utils/logger';
import ignore from 'ignore';
export default function migrate(tree: Tree) { export default function migrate(tree: Tree) {
const ig = ignore(); const nxJson = readNxJson(tree);
try { nxJson.useInferencePlugins = false;
ig.add(tree.read('.gitignore', 'utf-8')); updateNxJson(tree, nxJson);
if (ig.ignores('.env')) {
logger.warn(
'NX The NX_ADD_PLUGINS=false environment variable was added to your .env file for backwards compatibility. However, your .env is ignored by git. Other contributors should add this key to their .env file or ensure that the environment variable is set to false when generating code with Nx.'
);
}
} catch {}
if (!tree.exists('.env')) {
tree.write('.env', '');
}
const dotenv = tree.read('.env', 'utf-8');
const newDotenvContents = [
'# Nx 18 enables using plugins to infer targets by default',
'# This is disabled for existing workspaces to maintain compatibility',
'# For more info, see: https://nx.dev/concepts/inferred-tasks',
'NX_ADD_PLUGINS=false',
];
if (dotenv.length) {
newDotenvContents.unshift(dotenv, '');
}
tree.write('.env', newDotenvContents.join('\n'));
} }

View File

@ -39,7 +39,10 @@ export async function configurationGeneratorInternal(
tree: Tree, tree: Tree,
options: ConfigurationGeneratorSchema options: ConfigurationGeneratorSchema
) { ) {
options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const nxJson = readNxJson(tree);
options.addPlugin ??=
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
const tasks: GeneratorCallback[] = []; const tasks: GeneratorCallback[] = [];
tasks.push( tasks.push(
await initGenerator(tree, { await initGenerator(tree, {

View File

@ -22,7 +22,12 @@ export async function initGeneratorInternal(
) { ) {
const tasks: GeneratorCallback[] = []; const tasks: 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;
if (!options.skipPackageJson) { if (!options.skipPackageJson) {
tasks.push( tasks.push(

View File

@ -11,6 +11,7 @@ import {
names, names,
offsetFromRoot, offsetFromRoot,
readJson, readJson,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
runTasksInSerial, runTasksInSerial,
updateProjectConfiguration, updateProjectConfiguration,
@ -37,7 +38,12 @@ async function normalizeOptions(
): Promise<NormalizedSchema> { ): Promise<NormalizedSchema> {
const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`; const projectName = options.rootProject ? 'e2e' : `${options.pluginName}-e2e`;
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;
let projectRoot: string; let projectRoot: string;
if (options.projectNameAndRootFormat === 'as-provided') { if (options.projectNameAndRootFormat === 'as-provided') {

View File

@ -1,4 +1,4 @@
import { joinPathFragments, names, Tree } from '@nx/devkit'; import { joinPathFragments, names, readNxJson, Tree } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema'; import { Schema } from '../schema';
@ -34,7 +34,11 @@ export async function normalizeOptions(
callingGenerator: '@nx/react-native:application', callingGenerator: '@nx/react-native:application',
}); });
options.projectNameAndRootFormat = projectNameAndRootFormat; 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, fileName } = names(options.name); const { className, fileName } = names(options.name);
const iosProjectRoot = joinPathFragments(appProjectRoot, 'ios'); const iosProjectRoot = joinPathFragments(appProjectRoot, 'ios');

View File

@ -32,7 +32,11 @@ export async function reactNativeInitGeneratorInternal(
) { ) {
addGitIgnoreEntry(host); addGitIgnoreEntry(host);
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.addPlugin) { if (schema.addPlugin) {
addPlugin(host); addPlugin(host);

View File

@ -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 { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { Schema } from '../schema'; import { Schema } from '../schema';
@ -30,7 +30,11 @@ export async function normalizeOptions(
callingGenerator: '@nx/react-native:library', callingGenerator: '@nx/react-native: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 const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim()) ? options.tags.split(',').map((s) => s.trim())

View File

@ -1,4 +1,4 @@
import { Tree, logger } from '@nx/devkit'; import { Tree, logger, readNxJson } from '@nx/devkit';
import { storybookConfigurationGenerator as reactStorybookConfigurationGenerator } from '@nx/react'; import { storybookConfigurationGenerator as reactStorybookConfigurationGenerator } from '@nx/react';
import { StorybookConfigureSchema } from './schema'; import { StorybookConfigureSchema } from './schema';
@ -23,7 +23,11 @@ export async function storybookConfigurationGeneratorInternal(
logger.warn( logger.warn(
`Please run 'nx run @nx/react:storybook-configuration ${schema.project}' instead.` `Please run 'nx run @nx/react:storybook-configuration ${schema.project}' instead.`
); );
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;
return reactStorybookConfigurationGenerator(host, schema); return reactStorybookConfigurationGenerator(host, schema);
} }

View File

@ -1,4 +1,4 @@
import { Tree, extractLayoutDirectory, names } from '@nx/devkit'; import { Tree, extractLayoutDirectory, names, readNxJson } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { assertValidStyle } from '../../../utils/assertion'; import { assertValidStyle } from '../../../utils/assertion';
import { NormalizedSchema, Schema } from '../schema'; import { NormalizedSchema, Schema } from '../schema';
@ -33,7 +33,13 @@ export async function normalizeOptions<T extends Schema = Schema>(
rootProject: options.rootProject, rootProject: options.rootProject,
callingGenerator, callingGenerator,
}); });
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;
options.rootProject = appProjectRoot === '.'; options.rootProject = appProjectRoot === '.';
options.projectNameAndRootFormat = projectNameAndRootFormat; options.projectNameAndRootFormat = projectNameAndRootFormat;

View File

@ -1,6 +1,7 @@
import { import {
ensurePackage, ensurePackage,
formatFiles, formatFiles,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
Tree, Tree,
} from '@nx/devkit'; } from '@nx/devkit';
@ -32,7 +33,12 @@ export async function cypressComponentConfigGeneratorInternal(
typeof import('@nx/cypress') typeof import('@nx/cypress')
>('@nx/cypress', nxVersion); >('@nx/cypress', nxVersion);
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;
const projectConfig = readProjectConfiguration(tree, options.project); const projectConfig = readProjectConfiguration(tree, options.project);
const installTask = await baseCyCtConfig(tree, { const installTask = await baseCyCtConfig(tree, {

View File

@ -3,6 +3,7 @@ import {
joinPathFragments, joinPathFragments,
logger, logger,
normalizePath, normalizePath,
readNxJson,
Tree, Tree,
} from '@nx/devkit'; } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
@ -26,7 +27,12 @@ export async function normalizeOptions(
projectNameAndRootFormat: options.projectNameAndRootFormat, projectNameAndRootFormat: options.projectNameAndRootFormat,
callingGenerator: '@nx/react:library', callingGenerator: '@nx/react:library',
}); });
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 = options.simpleName const fileName = options.simpleName
? projectNames.projectSimpleName ? projectNames.projectSimpleName

View File

@ -4,6 +4,7 @@ import {
ensurePackage, ensurePackage,
formatFiles, formatFiles,
joinPathFragments, joinPathFragments,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
Tree, Tree,
} from '@nx/devkit'; } from '@nx/devkit';
@ -47,7 +48,11 @@ export async function storybookConfigurationGeneratorInternal(
host: Tree, host: Tree,
schema: StorybookConfigureSchema schema: StorybookConfigureSchema
) { ) {
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;
const { configurationGenerator } = ensurePackage< const { configurationGenerator } = ensurePackage<
typeof import('@nx/storybook') typeof import('@nx/storybook')
>('@nx/storybook', nxVersion); >('@nx/storybook', nxVersion);

View File

@ -1,4 +1,4 @@
import { type Tree } from '@nx/devkit'; import { readNxJson, type Tree } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { type NxRemixGeneratorSchema } from '../schema'; import { type NxRemixGeneratorSchema } from '../schema';
import { Linter } from '@nx/eslint'; import { Linter } from '@nx/eslint';
@ -26,7 +26,11 @@ export async function normalizeOptions(
}); });
options.rootProject = projectRoot === '.'; options.rootProject = projectRoot === '.';
options.projectNameAndRootFormat = projectNameAndRootFormat; options.projectNameAndRootFormat = projectNameAndRootFormat;
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 e2eProjectName = options.rootProject ? 'e2e' : `${projectName}-e2e`; const e2eProjectName = options.rootProject ? 'e2e' : `${projectName}-e2e`;
const e2eProjectRoot = options.rootProject ? 'e2e' : `${projectRoot}-e2e`; const e2eProjectRoot = options.rootProject ? 'e2e' : `${projectRoot}-e2e`;

View File

@ -2,6 +2,7 @@ import {
formatFiles, formatFiles,
generateFiles, generateFiles,
readProjectConfiguration, readProjectConfiguration,
readNxJson,
type Tree, type Tree,
} from '@nx/devkit'; } from '@nx/devkit';
import { join } from 'path'; import { join } from 'path';
@ -22,7 +23,11 @@ export async function cypressComponentConfigurationGeneratorInternal(
tree: Tree, tree: Tree,
options: CypressComponentConfigurationSchema options: CypressComponentConfigurationSchema
) { ) {
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;
await cypressComponentConfigGenerator(tree, { await cypressComponentConfigGenerator(tree, {
project: options.project, project: options.project,
generateTests: options.generateTests, generateTests: options.generateTests,

View File

@ -62,7 +62,11 @@ export async function remixInitGeneratorInternal(tree: Tree, options: Schema) {
tasks.push(installTask); tasks.push(installTask);
} }
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;
if (options.addPlugin) { if (options.addPlugin) {
addPlugin(tree); addPlugin(tree);
} }

View File

@ -1,4 +1,4 @@
import type { Tree } from '@nx/devkit'; import { type Tree, readNxJson } from '@nx/devkit';
import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils';
import { getImportPath } from '@nx/js/src/utils/get-import-path'; import { getImportPath } from '@nx/js/src/utils/get-import-path';
import type { NxRemixGeneratorSchema } from '../schema'; import type { NxRemixGeneratorSchema } from '../schema';
@ -21,7 +21,11 @@ export async function normalizeOptions(
callingGenerator: '@nx/remix:library', callingGenerator: '@nx/remix:library',
}); });
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 importPath = options.importPath ?? getImportPath(tree, projectRoot); const importPath = options.importPath ?? getImportPath(tree, projectRoot);
@ -31,5 +35,6 @@ export async function normalizeOptions(
importPath, importPath,
projectName, projectName,
projectRoot, projectRoot,
projectNameAndRootFormat,
}; };
} }

View File

@ -1,4 +1,4 @@
import { formatFiles, GeneratorCallback, Tree } from '@nx/devkit'; import { formatFiles, GeneratorCallback, readNxJson, Tree } from '@nx/devkit';
import { runTasksInSerial } from '@nx/devkit'; import { runTasksInSerial } from '@nx/devkit';
import applicationGenerator from '../application/application.impl'; import applicationGenerator from '../application/application.impl';
@ -13,6 +13,11 @@ export default async function (tree: Tree, _options: RemixGeneratorSchema) {
const setupGenTask = await setupGenerator(tree); const setupGenTask = await setupGenerator(tree);
tasks.push(setupGenTask); tasks.push(setupGenTask);
const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
const appGenTask = await applicationGenerator(tree, { const appGenTask = await applicationGenerator(tree, {
name: options.appName, name: options.appName,
tags: options.tags, tags: options.tags,
@ -21,7 +26,7 @@ export default async function (tree: Tree, _options: RemixGeneratorSchema) {
unitTestRunner: options.unitTestRunner ?? 'vitest', unitTestRunner: options.unitTestRunner ?? 'vitest',
e2eTestRunner: options.e2eTestRunner ?? 'cypress', e2eTestRunner: options.e2eTestRunner ?? 'cypress',
js: options.js ?? false, js: options.js ?? false,
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin: addPluginDefault,
}); });
tasks.push(appGenTask); tasks.push(appGenTask);

View File

@ -2,6 +2,7 @@ import {
generateFiles, generateFiles,
joinPathFragments, joinPathFragments,
readProjectConfiguration, readProjectConfiguration,
readNxJson,
type Tree, type Tree,
} from '@nx/devkit'; } from '@nx/devkit';
import { join } from 'path'; import { join } from 'path';
@ -22,7 +23,11 @@ export default async function remixStorybookConfigurationInternal(
tree: Tree, tree: Tree,
schema: StorybookConfigurationSchema schema: StorybookConfigurationSchema
) { ) {
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addPlugin ??= addPluginDefault;
const { root } = readProjectConfiguration(tree, schema.project); const { root } = readProjectConfiguration(tree, schema.project);
if (!tree.exists(joinPathFragments(root, 'vite.config.ts'))) { if (!tree.exists(joinPathFragments(root, 'vite.config.ts'))) {

View File

@ -65,7 +65,7 @@ export async function configurationGeneratorInternal(
throw new Error(pleaseUpgrade()); throw new Error(pleaseUpgrade());
} }
const schema = normalizeSchema(rawSchema); const schema = normalizeSchema(tree, rawSchema);
const tasks: GeneratorCallback[] = []; const tasks: GeneratorCallback[] = [];
@ -259,14 +259,20 @@ export async function configurationGeneratorInternal(
} }
function normalizeSchema( function normalizeSchema(
tree: Tree,
schema: StorybookConfigureSchema schema: StorybookConfigureSchema
): StorybookConfigureSchema { ): StorybookConfigureSchema {
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
const defaults = { const defaults = {
interactionTests: true, interactionTests: true,
linter: Linter.EsLint, linter: Linter.EsLint,
js: false, js: false,
tsConfiguration: true, tsConfiguration: true,
addPlugin: process.env.NX_ADD_PLUGINS !== 'false', addPlugin,
}; };
return { return {
...defaults, ...defaults,

View File

@ -95,7 +95,11 @@ export function initGenerator(tree: Tree, schema: Schema) {
} }
export async function initGeneratorInternal(tree: Tree, schema: Schema) { export async function initGeneratorInternal(tree: Tree, schema: Schema) {
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addPlugin ??= addPluginDefault;
if (schema.addPlugin) { if (schema.addPlugin) {
addPlugin(tree); addPlugin(tree);

View File

@ -40,7 +40,11 @@ export async function viteConfigurationGeneratorInternal(
) { ) {
const tasks: GeneratorCallback[] = []; const tasks: GeneratorCallback[] = [];
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addPlugin ??= addPluginDefault;
const projectConfig = readProjectConfiguration(tree, schema.project); const projectConfig = readProjectConfiguration(tree, schema.project);
const { targets, root: projectRoot } = projectConfig; const { targets, root: projectRoot } = projectConfig;
@ -73,7 +77,6 @@ export async function viteConfigurationGeneratorInternal(
tasks.push(initTask); tasks.push(initTask);
tasks.push(ensureDependencies(tree, schema)); tasks.push(ensureDependencies(tree, schema));
const nxJson = readNxJson(tree);
const hasPlugin = nxJson.plugins?.some((p) => const hasPlugin = nxJson.plugins?.some((p) =>
typeof p === 'string' typeof p === 'string'
? p === '@nx/vite/plugin' ? p === '@nx/vite/plugin'

View File

@ -56,7 +56,11 @@ export async function initGeneratorInternal(
tree: Tree, tree: Tree,
schema: InitGeneratorSchema schema: InitGeneratorSchema
) { ) {
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addPlugin ??= addPluginDefault;
if (schema.addPlugin) { if (schema.addPlugin) {
addPlugin(tree); addPlugin(tree);
} }

View File

@ -467,7 +467,11 @@ async function normalizeOptions(
callingGenerator: '@nx/web:application', callingGenerator: '@nx/web:application',
}); });
options.projectNameAndRootFormat = projectNameAndRootFormat; 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 e2eProjectName = `${appProjectName}-e2e`; const e2eProjectName = `${appProjectName}-e2e`;
const e2eProjectRoot = `${appProjectRoot}-e2e`; const e2eProjectRoot = `${appProjectRoot}-e2e`;

View File

@ -3,6 +3,7 @@ import {
GeneratorCallback, GeneratorCallback,
joinPathFragments, joinPathFragments,
offsetFromRoot, offsetFromRoot,
readNxJson,
readProjectConfiguration, readProjectConfiguration,
runTasksInSerial, runTasksInSerial,
Tree, Tree,
@ -29,7 +30,11 @@ export async function configurationGeneratorInternal(
options: ConfigurationGeneratorSchema options: ConfigurationGeneratorSchema
) { ) {
const tasks: GeneratorCallback[] = []; const tasks: 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 initTask = await webpackInitGenerator(tree, { const initTask = await webpackInitGenerator(tree, {
...options, ...options,

View File

@ -16,7 +16,11 @@ export function webpackInitGenerator(tree: Tree, schema: Schema) {
} }
export async function webpackInitGeneratorInternal(tree: Tree, schema: Schema) { export async function webpackInitGeneratorInternal(tree: Tree, schema: Schema) {
schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false'; const nxJson = readNxJson(tree);
const addPluginDefault =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
schema.addPlugin ??= addPluginDefault;
if (schema.addPlugin) { if (schema.addPlugin) {
addPlugin(tree); addPlugin(tree);

View File

@ -91,6 +91,7 @@ function createNxJson(
}; };
if (process.env.NX_ADD_PLUGINS === 'false') { if (process.env.NX_ADD_PLUGINS === 'false') {
nxJson.targetDefaults.build.inputs = ['production', '^production']; nxJson.targetDefaults.build.inputs = ['production', '^production'];
nxJson.useInferencePlugins = false;
} }
} }

View File

@ -85,12 +85,16 @@ describe('preset', () => {
}); });
it('should create files (preset = react-native)', async () => { it('should create files (preset = react-native)', async () => {
console.log('Hello');
await presetGenerator(tree, { await presetGenerator(tree, {
name: 'proj', name: 'proj',
preset: Preset.ReactNative, preset: Preset.ReactNative,
linter: 'eslint', linter: 'eslint',
}); });
process.stderr.write('HELLO');
process.stderr.write(tree.listChanges().toString());
expect(tree.exists('/apps/proj/src/app/App.tsx')).toBe(true); expect(tree.exists('/apps/proj/src/app/App.tsx')).toBe(true);
}); });

View File

@ -1,4 +1,4 @@
import { installPackagesTask, names, Tree } from '@nx/devkit'; import { installPackagesTask, names, readNxJson, Tree } from '@nx/devkit';
import { Schema } from './schema'; import { Schema } from './schema';
import { Preset } from '../utils/presets'; import { Preset } from '../utils/presets';
import { join } from 'path'; import { join } from 'path';
@ -15,7 +15,15 @@ export async function presetGenerator(tree: Tree, options: Schema) {
export default presetGenerator; export default presetGenerator;
async function createPreset(tree: Tree, options: Schema) { async function createPreset(tree: Tree, options: Schema) {
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false'; console.log('Crate preset');
const nxJson = readNxJson(tree);
const addPlugin =
process.env.NX_ADD_PLUGINS !== 'false' &&
nxJson.useInferencePlugins !== false;
console.log('Add plugin', addPlugin);
console.log(options.preset, Preset.ReactNative);
if (options.preset === Preset.Apps) { if (options.preset === Preset.Apps) {
return; return;
} else if (options.preset === Preset.AngularMonorepo) { } else if (options.preset === Preset.AngularMonorepo) {
@ -210,8 +218,11 @@ async function createPreset(tree: Tree, options: Schema) {
addPlugin, addPlugin,
}); });
} else if (options.preset === Preset.ReactNative) { } else if (options.preset === Preset.ReactNative) {
console.log('Before require');
const { reactNativeApplicationGenerator } = require('@nx' + const { reactNativeApplicationGenerator } = require('@nx' +
'/react-native'); '/react-native');
console.log('Hello', reactNativeApplicationGenerator);
console.log('Active require');
return reactNativeApplicationGenerator(tree, { return reactNativeApplicationGenerator(tree, {
name: options.name, name: options.name,
directory: join('apps', options.name), directory: join('apps', options.name),