Skip to content

Commit

Permalink
fix(core): addPlugin should not conflict on project.json targets (#23264
Browse files Browse the repository at this point in the history
)

<!-- 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` -->

## Current Behavior
<!-- This is the behavior we have today -->
Calculating conflicts in target names does not consider if the
project.json defined targets will actually be impacted by the plugin
that wants to be added creating false negatives

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Calculating conflicts should be more accurate

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #22476
  • Loading branch information
Coly010 authored May 13, 2024
1 parent 08654e1 commit 85c8916
Show file tree
Hide file tree
Showing 59 changed files with 291 additions and 242 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import {
DependencyType,
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { readJson, updateJson } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import {
getProjects,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import type { Tree } from '@nx/devkit';
import { readJson } from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import type { Tree } from '@nx/devkit';
import { readJson } from '@nx/devkit';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/ngrx/ngrx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { E2eTestRunner } from '../../utils/test-runners';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import scamGenerator from '../scam/scam';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/setup-mf/setup-mf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import {
readJson,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import {
NxJsonConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
import { readJson, writeJson } from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import { readJson, updateJson } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import {
readJson,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-load-nx-plugin';

import {
ProjectGraph,
readJson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function configurationGeneratorInternal(
})
);
} else if (opts.addPlugin) {
await addPlugin(tree, projectGraph, false);
await addPlugin(tree, false);
}

const nxJson = readNxJson(tree);
Expand Down
21 changes: 3 additions & 18 deletions packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import {
addDependenciesToPackageJson,
createProjectGraphAsync,
formatFiles,
GeneratorCallback,
ProjectGraph,
readNxJson,
removeDependenciesFromPackageJson,
runTasksInSerial,
Tree,
updateNxJson,
} from '@nx/devkit';
import {
addPlugin as _addPlugin,
generateCombinations,
} from '@nx/devkit/src/utils/add-plugin';
import { addPlugin as _addPlugin } from '@nx/devkit/src/utils/add-plugin';
import { createNodes } from '../../plugins/plugin';
import { cypressVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';
import { CypressPluginOptions } from '../../plugins/plugin';

function setupE2ETargetDefaults(tree: Tree) {
const nxJson = readNxJson(tree);
Expand Down Expand Up @@ -60,14 +54,9 @@ function updateDependencies(tree: Tree, options: Schema) {
return runTasksInSerial(...tasks);
}

export function addPlugin(
tree: Tree,
graph: ProjectGraph,
updatePackageScripts: boolean
) {
export function addPlugin(tree: Tree, updatePackageScripts: boolean) {
return _addPlugin(
tree,
graph,
'@nx/cypress/plugin',
createNodes,
{
Expand Down Expand Up @@ -118,11 +107,7 @@ export async function cypressInitGeneratorInternal(
nxJson.useInferencePlugins !== false;

if (options.addPlugin) {
await addPlugin(
tree,
await createProjectGraphAsync(),
options.updatePackageScripts
);
await addPlugin(tree, options.updatePackageScripts);
} else {
setupE2ETargetDefaults(tree);
}
Expand Down
9 changes: 2 additions & 7 deletions packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import {
addDependenciesToPackageJson,
createProjectGraphAsync,
formatFiles,
GeneratorCallback,
readNxJson,
removeDependenciesFromPackageJson,
runTasksInSerial,
Tree,
} from '@nx/devkit';
import {
addPlugin,
generateCombinations,
} from '@nx/devkit/src/utils/add-plugin';
import { createNodes, DetoxPluginOptions } from '../../plugins/plugin';
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
import { createNodes } from '../../plugins/plugin';
import { detoxVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';

Expand All @@ -38,7 +34,6 @@ export async function detoxInitGeneratorInternal(host: Tree, schema: Schema) {
if (schema.addPlugin) {
await addPlugin(
host,
await createProjectGraphAsync(),
'@nx/detox/plugin',
createNodes,
{
Expand Down
Loading

0 comments on commit 85c8916

Please sign in to comment.