Skip to content

Commit

Permalink
fix(misc): register plugins correctly in migration generators (#26670)
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` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

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

Fixes #
  • Loading branch information
leosvelperez authored Jun 25, 2024
1 parent 8872ca5 commit c936f86
Show file tree
Hide file tree
Showing 14 changed files with 763 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,33 +495,46 @@ describe('Cypress - Convert Executors To Plugin', () => {

// nx.json modifications
const nxJsonPlugins = readNxJson(tree).plugins;
const addedTestCypressPlugin = nxJsonPlugins.find((plugin) => {
if (
typeof plugin !== 'string' &&
plugin.plugin === '@nx/cypress/plugin' &&
plugin.include?.length === 2
) {
return true;
}
});
expect(addedTestCypressPlugin).toBeTruthy();
expect(
(addedTestCypressPlugin as ExpandedPluginConfiguration).include
).toEqual(['myapp-e2e/**/*', 'second/**/*']);

const addedIntegrationCypressPlugin = nxJsonPlugins.find((plugin) => {
if (
typeof plugin !== 'string' &&
plugin.plugin === '@nx/cypress/plugin' &&
plugin.include?.length === 1
) {
return true;
}
});
expect(addedIntegrationCypressPlugin).toBeTruthy();
expect(
(addedIntegrationCypressPlugin as ExpandedPluginConfiguration).include
).toEqual(['third/**/*']);
const addedCypressPlugins = nxJsonPlugins.filter(
(plugin) =>
typeof plugin !== 'string' && plugin.plugin === '@nx/cypress/plugin'
);
expect(addedCypressPlugins).toMatchInlineSnapshot(`
[
{
"options": {
"ciTargetName": "e2e-ci",
"targetName": "e2e",
},
"plugin": "@nx/cypress/plugin",
},
{
"include": [
"myapp-e2e/**/*",
"second/**/*",
],
"options": {
"ciTargetName": "e2e-ci",
"componentTestingTargetName": "component-test",
"openTargetName": "open-cypress",
"targetName": "test",
},
"plugin": "@nx/cypress/plugin",
},
{
"include": [
"third/**/*",
],
"options": {
"ciTargetName": "e2e-ci",
"componentTestingTargetName": "component-test",
"openTargetName": "open-cypress",
"targetName": "integration",
},
"plugin": "@nx/cypress/plugin",
},
]
`);
});

it('should keep Cypress options in project.json', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import {
type TargetConfiguration,
type Tree,
} from '@nx/devkit';
import { migrateExecutorToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import { createNodesV2 } from '../../plugins/plugin';
import { targetOptionsToCliMap } from './lib/target-options-map';
import { upsertBaseUrl } from './lib/upsert-baseUrl';
import { addDevServerTargetToConfig } from './lib/add-dev-server-target-to-config';
import { addExcludeSpecPattern } from './lib/add-exclude-spec-pattern';
import { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';
import {
processTargetOutputs,
toProjectRelativePath,
} from '@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils';
import { createNodesV2, type CypressPluginOptions } from '../../plugins/plugin';
import { addDevServerTargetToConfig } from './lib/add-dev-server-target-to-config';
import { addExcludeSpecPattern } from './lib/add-exclude-spec-pattern';
import { targetOptionsToCliMap } from './lib/target-options-map';
import { upsertBaseUrl } from './lib/upsert-baseUrl';

interface Schema {
project?: string;
Expand All @@ -23,38 +23,29 @@ interface Schema {

export async function convertToInferred(tree: Tree, options: Schema) {
const projectGraph = await createProjectGraphAsync();
const migratedProjectsModern = await migrateExecutorToPlugin(
tree,
projectGraph,
'@nx/cypress:cypress',
'@nx/cypress/plugin',
(targetName) => ({
targetName,
ciTargetName: 'e2e-ci',
}),
postTargetTransformer,
createNodesV2,
options.project
);

const migratedProjectsLegacy = await migrateExecutorToPlugin(
tree,
projectGraph,
'@nrwl/cypress:cypress',
'@nx/cypress/plugin',
(targetName) => ({
targetName,
ciTargetName: 'e2e-ci',
}),
postTargetTransformer,
createNodesV2,
options.project
);

const migratedProjects =
migratedProjectsModern.size + migratedProjectsLegacy.size;
await migrateProjectExecutorsToPlugin<CypressPluginOptions>(
tree,
projectGraph,
'@nx/cypress/plugin',
createNodesV2,
{
targetName: 'cypress',
ciTargetName: 'e2e-ci',
componentTestingTargetName: 'component-test',
openTargetName: 'open-cypress',
},
[
{
executors: ['@nx/cypress:cypress', '@nrwl/cypress:cypress'],
postTargetTransformer,
targetPluginOptionMapper: (targetName) => ({ targetName }),
},
],
options.project
);

if (migratedProjects === 0) {
if (migratedProjects.size === 0) {
throw new Error('Could not find any targets to migrate.');
}

Expand Down
Loading

0 comments on commit c936f86

Please sign in to comment.