diff --git a/packages/cypress/src/migrations/update-17-2-0/add-nx-cypress-plugin.ts b/packages/cypress/src/migrations/update-17-2-0/add-nx-cypress-plugin.ts index 43ede38c70..3f3a4a57b3 100644 --- a/packages/cypress/src/migrations/update-17-2-0/add-nx-cypress-plugin.ts +++ b/packages/cypress/src/migrations/update-17-2-0/add-nx-cypress-plugin.ts @@ -9,7 +9,7 @@ export default async function update(tree: Tree) { const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, rootMappings, '@nx/cypress/plugin', diff --git a/packages/devkit/src/utils/replace-project-configuration-with-plugin.spec.ts b/packages/devkit/src/utils/replace-project-configuration-with-plugin.spec.ts index 6da602909d..5875d42899 100644 --- a/packages/devkit/src/utils/replace-project-configuration-with-plugin.spec.ts +++ b/packages/devkit/src/utils/replace-project-configuration-with-plugin.spec.ts @@ -59,7 +59,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -88,7 +88,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -117,7 +117,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -134,7 +134,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); describe('inputs', () => { - it('should not be removed if there are additional inputs', () => { + it('should not be removed if there are additional inputs', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -149,7 +149,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -162,7 +162,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); }); - it('should not be removed if there are additional inputs which are objects', () => { + it('should not be removed if there are additional inputs which are objects', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -183,7 +183,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -202,7 +202,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); }); - it('should not be removed if there are less inputs', () => { + it('should not be removed if there are less inputs', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -217,7 +217,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -232,7 +232,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); describe('outputs', () => { - it('should not be removed if there are additional outputs', () => { + it('should not be removed if there are additional outputs', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -251,7 +251,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -268,7 +268,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); }); - it('should not be removed if there are less outputs', () => { + it('should not be removed if there are less outputs', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -282,7 +282,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -297,7 +297,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); describe('dependsOn', () => { - it('should be removed when it is the same', () => { + it('should be removed when it is the same', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -311,7 +311,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -324,7 +324,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { ).toBeUndefined(); }); - it('should not be removed when there are more dependent tasks', () => { + it('should not be removed when there are more dependent tasks', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -338,7 +338,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -351,7 +351,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); }); - it('should not be removed when there are less dependent tasks', () => { + it('should not be removed when there are less dependent tasks', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -365,7 +365,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -380,7 +380,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); describe('defaultConfiguration', () => { - it('should not be removed when the defaultConfiguration is different', () => { + it('should not be removed when the defaultConfiguration is different', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -394,7 +394,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', @@ -409,7 +409,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }); describe('configurations', () => { - it('should not be removed when an additional configuration is defined', () => { + it('should not be removed when an additional configuration is defined', async () => { addProjectConfiguration(tree, 'proj', { root: 'proj', targets: { @@ -427,7 +427,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => { }, }); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, new Map([['proj', 'proj']]), 'plugin-path', diff --git a/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts b/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts index 42027b9282..4a248f9106 100644 --- a/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts +++ b/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts @@ -3,7 +3,7 @@ import type { TargetConfiguration, } from 'nx/src/config/workspace-json-project-json'; import type { Tree } from 'nx/src/generators/tree'; -import type { CreateNodes } from 'nx/src/utils/nx-plugin'; +import type { CreateNodes, CreateNodesAsync } from 'nx/src/utils/nx-plugin'; import { requireNx } from '../../nx'; const { readNxJson, @@ -15,13 +15,13 @@ const { updateProjectConfiguration, } = requireNx(); -export function replaceProjectConfigurationsWithPlugin( +export async function replaceProjectConfigurationsWithPlugin( tree: Tree, rootMappings: Map, pluginPath: string, - createNodes: CreateNodes, + createNodes: CreateNodes | CreateNodesAsync, pluginOptions: T -): void { +): Promise { const nxJson = readNxJson(tree); const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string' ? p === pluginPath : p.plugin === pluginPath @@ -45,7 +45,7 @@ export function replaceProjectConfigurationsWithPlugin( try { const projectName = findProjectForPath(configFile, rootMappings); const projectConfig = readProjectConfiguration(tree, projectName); - const nodes = createNodesFunction(configFile, pluginOptions, { + const nodes = await createNodesFunction(configFile, pluginOptions, { workspaceRoot: tree.root, nxJsonConfiguration: readNxJson(tree), }); diff --git a/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap b/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap index 6e06280769..8edce47df0 100644 --- a/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap +++ b/tools/workspace-plugin/src/generators/create-nodes-plugin/__snapshots__/generator.spec.ts.snap @@ -261,7 +261,7 @@ export default async function update(tree: Tree) { const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, rootMappings, '@nx/eslint/plugin', diff --git a/tools/workspace-plugin/src/generators/create-nodes-plugin/files/src/migrations/update-17-2-0/add-__dirName__-plugin.ts b/tools/workspace-plugin/src/generators/create-nodes-plugin/files/src/migrations/update-17-2-0/add-__dirName__-plugin.ts index 4d7ad936ef..4eedfae7f2 100644 --- a/tools/workspace-plugin/src/generators/create-nodes-plugin/files/src/migrations/update-17-2-0/add-__dirName__-plugin.ts +++ b/tools/workspace-plugin/src/generators/create-nodes-plugin/files/src/migrations/update-17-2-0/add-__dirName__-plugin.ts @@ -9,7 +9,7 @@ export default async function update(tree: Tree) { const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj); - replaceProjectConfigurationsWithPlugin( + await replaceProjectConfigurationsWithPlugin( tree, rootMappings, '@nx/<%= dirName %>/plugin',