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);
replaceProjectConfigurationsWithPlugin(
await replaceProjectConfigurationsWithPlugin(
tree,
rootMappings,
'@nx/cypress/plugin',

View File

@ -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',

View File

@ -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<T = unknown>(
export async function replaceProjectConfigurationsWithPlugin<T = unknown>(
tree: Tree,
rootMappings: Map<string, string>,
pluginPath: string,
createNodes: CreateNodes<T>,
createNodes: CreateNodes<T> | CreateNodesAsync<T>,
pluginOptions: T
): void {
): Promise<void> {
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<T = unknown>(
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),
});

View File

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

View File

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