From 48164bd3acf424db059ed7ffb63cf10d7900cd5f Mon Sep 17 00:00:00 2001 From: AgentEnder Date: Wed, 24 Jan 2024 17:57:38 -0500 Subject: [PATCH] chore(core): fix failing tests --- .../generators/utils/project-configuration.ts | 13 +++++++++-- .../utils/normalize-project-nodes.spec.ts | 22 ------------------- .../utils/project-configuration-utils.spec.ts | 5 ++++- .../utils/project-configuration-utils.ts | 11 +++++++--- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/packages/nx/src/generators/utils/project-configuration.ts b/packages/nx/src/generators/utils/project-configuration.ts index f9e173d7596c8..0efb1d3bc0f10 100644 --- a/packages/nx/src/generators/utils/project-configuration.ts +++ b/packages/nx/src/generators/utils/project-configuration.ts @@ -211,7 +211,13 @@ function readAndCombineAllProjectConfigurations(tree: Tree): { if (basename(projectFile) === 'project.json') { const json = readJson(tree, projectFile); const config = buildProjectFromProjectJson(json, projectFile); - mergeProjectConfigurationIntoRootMap(rootMap, config); + mergeProjectConfigurationIntoRootMap( + rootMap, + config, + undefined, + undefined, + true + ); } else if (basename(projectFile) === 'package.json') { const packageJson = readJson(tree, projectFile); const config = buildProjectConfigurationFromPackageJson( @@ -227,7 +233,10 @@ function readAndCombineAllProjectConfigurations(tree: Tree): { { name: config.name, root: config.root, - } + }, + undefined, + undefined, + true ); } } diff --git a/packages/nx/src/project-graph/utils/normalize-project-nodes.spec.ts b/packages/nx/src/project-graph/utils/normalize-project-nodes.spec.ts index a34162a266b6b..86d4c3f8d0157 100644 --- a/packages/nx/src/project-graph/utils/normalize-project-nodes.spec.ts +++ b/packages/nx/src/project-graph/utils/normalize-project-nodes.spec.ts @@ -80,28 +80,6 @@ describe('workspace-projects', () => { }); describe('normalizeTargets', () => { - it('should convert command property to run-commands executor', () => { - expect( - normalizeProjectTargets( - { - root: 'my/project', - targets: { - build: { - command: 'echo', - }, - }, - }, - 'build' - ).build - ).toEqual({ - executor: 'nx:run-commands', - configurations: {}, - options: { - command: 'echo', - }, - }); - }); - it('should support {projectRoot}, {workspaceRoot}, and {projectName} tokens', () => { expect( normalizeProjectTargets( diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts index 43fe3ddcf2f76..53749382762e0 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.spec.ts @@ -433,7 +433,10 @@ describe('project-configuration-utils', () => { "root": "libs/lib-a", "targets": { "build": { - "command": "tsc", + "executor": "nx:run-commands", + "options": { + "command": "tsc", + }, }, "echo": { "command": "echo lib-a", diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.ts index 79e13d2320dc7..63bea10bae7e7 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -28,7 +28,10 @@ export function mergeProjectConfigurationIntoRootMap( >; }, configurationSourceMaps?: ConfigurationSourceMaps, - sourceInformation?: SourceInformation + sourceInformation?: SourceInformation, + // This function is used when reading project configuration + // in generators, where we don't want to do this. + skipCommandNormalization?: boolean ): void { if (configurationSourceMaps && !configurationSourceMaps[project.root]) { configurationSourceMaps[project.root] = {}; @@ -158,11 +161,13 @@ export function mergeProjectConfigurationIntoRootMap( updatedProjectConfiguration.targets[targetName] = mergeTargetConfigurations( - resolveCommandSyntacticSugar(target, project.root), + skipCommandNormalization + ? target + : resolveCommandSyntacticSugar(target, project.root), matchingProject.targets?.[targetName], sourceMap, sourceInformation, - `targets.${target}` + `targets.${targetName}` ); } }