From 870a9bd52e348586325caa05c959f64c94a01f4d Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Wed, 19 Jul 2023 17:26:42 -0400 Subject: [PATCH] fix(core): review comments --- .../update-16-5-4/update-output-globs.ts | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/nx/src/migrations/update-16-5-4/update-output-globs.ts b/packages/nx/src/migrations/update-16-5-4/update-output-globs.ts index 487ca898a9a02..47803469a4c3f 100644 --- a/packages/nx/src/migrations/update-16-5-4/update-output-globs.ts +++ b/packages/nx/src/migrations/update-16-5-4/update-output-globs.ts @@ -8,19 +8,13 @@ import { TargetConfiguration } from '../../config/workspace-json-project-json'; import { updateJson } from '../../generators/utils/json'; import { NxJsonConfiguration } from '../../config/nx-json'; -function replaceOutputs(targetConfiguration: TargetConfiguration) { - let outputs = []; - for (const output of targetConfiguration.outputs ?? []) { - // replace {projectRoot}/folder/*.(js|map|ts) to {projectRoot}/folder/*.{js,map,ts} - const regex = /\(([^)]+)\)/g; - const newOutput = output.replace(regex, (match, group1) => { - let replacements = group1.split('|').join(','); - return `{${replacements}}`; - }); - - outputs.push(newOutput); - } - return outputs; +function replaceOutput(output: string) { + // replace {projectRoot}/folder/*.(js|map|ts) to {projectRoot}/folder/*.{js,map,ts} + const regex = /\(([^)]+)\)/g; + return output.replace(regex, (match, group1) => { + let replacements = group1.split('|').join(','); + return `{${replacements}}`; + }); } export default async function updateOutputsGlobs(tree: Tree) { @@ -28,13 +22,14 @@ export default async function updateOutputsGlobs(tree: Tree) { tree ).entries()) { for (const [targetName, targetConfiguration] of Object.entries( - projectConfiguration.targets + projectConfiguration.targets ?? {} )) { if (!Array.isArray(targetConfiguration.outputs)) { continue; } - targetConfiguration.outputs = replaceOutputs(targetConfiguration); + targetConfiguration.outputs = + targetConfiguration.outputs.map(replaceOutput); } updateProjectConfiguration(tree, projectName, projectConfiguration); } @@ -48,7 +43,8 @@ export default async function updateOutputsGlobs(tree: Tree) { continue; } - targetConfiguration.outputs = replaceOutputs(targetConfiguration); + targetConfiguration.outputs = + targetConfiguration.outputs.map(replaceOutput); } return json; });