Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): addPlugin should not conflict on project.json targets #23264

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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