fix(core): await for createNodesAsync (#20232)

This commit is contained in:
Katerina Skroumpelou 2023-11-14 15:13:38 +02:00 committed by GitHub
parent bdc30ca23e
commit 5d389dd62d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 31 deletions

View File

@ -9,7 +9,7 @@ export default async function update(tree: Tree) {
const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj); const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj);
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
rootMappings, rootMappings,
'@nx/cypress/plugin', '@nx/cypress/plugin',

View File

@ -59,7 +59,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -88,7 +88,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -117,7 +117,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -134,7 +134,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}); });
describe('inputs', () => { 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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -149,7 +149,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', '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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -183,7 +183,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', '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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -217,7 +217,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -232,7 +232,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}); });
describe('outputs', () => { 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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -251,7 +251,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', '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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -282,7 +282,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -297,7 +297,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}); });
describe('dependsOn', () => { describe('dependsOn', () => {
it('should be removed when it is the same', () => { it('should be removed when it is the same', async () => {
addProjectConfiguration(tree, 'proj', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -311,7 +311,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -324,7 +324,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
).toBeUndefined(); ).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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -338,7 +338,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', '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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -365,7 +365,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -380,7 +380,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}); });
describe('defaultConfiguration', () => { 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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -394,7 +394,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',
@ -409,7 +409,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}); });
describe('configurations', () => { 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', { addProjectConfiguration(tree, 'proj', {
root: 'proj', root: 'proj',
targets: { targets: {
@ -427,7 +427,7 @@ describe('replaceProjectConfigurationsWithPlugin', () => {
}, },
}); });
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
new Map([['proj', 'proj']]), new Map([['proj', 'proj']]),
'plugin-path', 'plugin-path',

View File

@ -3,7 +3,7 @@ import type {
TargetConfiguration, TargetConfiguration,
} from 'nx/src/config/workspace-json-project-json'; } from 'nx/src/config/workspace-json-project-json';
import type { Tree } from 'nx/src/generators/tree'; 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'; import { requireNx } from '../../nx';
const { const {
readNxJson, readNxJson,
@ -15,13 +15,13 @@ const {
updateProjectConfiguration, updateProjectConfiguration,
} = requireNx(); } = requireNx();
export function replaceProjectConfigurationsWithPlugin<T = unknown>( export async function replaceProjectConfigurationsWithPlugin<T = unknown>(
tree: Tree, tree: Tree,
rootMappings: Map<string, string>, rootMappings: Map<string, string>,
pluginPath: string, pluginPath: string,
createNodes: CreateNodes<T>, createNodes: CreateNodes<T> | CreateNodesAsync<T>,
pluginOptions: T pluginOptions: T
): void { ): Promise<void> {
const nxJson = readNxJson(tree); const nxJson = readNxJson(tree);
const hasPlugin = nxJson.plugins?.some((p) => const hasPlugin = nxJson.plugins?.some((p) =>
typeof p === 'string' ? p === pluginPath : p.plugin === pluginPath typeof p === 'string' ? p === pluginPath : p.plugin === pluginPath
@ -45,7 +45,7 @@ export function replaceProjectConfigurationsWithPlugin<T = unknown>(
try { try {
const projectName = findProjectForPath(configFile, rootMappings); const projectName = findProjectForPath(configFile, rootMappings);
const projectConfig = readProjectConfiguration(tree, projectName); const projectConfig = readProjectConfiguration(tree, projectName);
const nodes = createNodesFunction(configFile, pluginOptions, { const nodes = await createNodesFunction(configFile, pluginOptions, {
workspaceRoot: tree.root, workspaceRoot: tree.root,
nxJsonConfiguration: readNxJson(tree), nxJsonConfiguration: readNxJson(tree),
}); });

View File

@ -261,7 +261,7 @@ export default async function update(tree: Tree) {
const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj); const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj);
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
rootMappings, rootMappings,
'@nx/eslint/plugin', '@nx/eslint/plugin',

View File

@ -9,7 +9,7 @@ export default async function update(tree: Tree) {
const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj); const rootMappings = createProjectRootMappingsFromProjectConfigurations(proj);
replaceProjectConfigurationsWithPlugin( await replaceProjectConfigurationsWithPlugin(
tree, tree,
rootMappings, rootMappings,
'@nx/<%= dirName %>/plugin', '@nx/<%= dirName %>/plugin',