Skip to content

Commit

Permalink
fix(core): review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Jul 19, 2023
1 parent 675b946 commit 870a9bd
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/nx/src/migrations/update-16-5-4/update-output-globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,28 @@ import { TargetConfiguration } from '../../config/workspace-json-project-json';
import { updateJson } from '../../generators/utils/json';
import { NxJsonConfiguration } from '../../config/nx-json';

function replaceOutputs(targetConfiguration: TargetConfiguration<any>) {
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) {
for (const [projectName, projectConfiguration] of getProjects(
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);
}
Expand All @@ -48,7 +43,8 @@ export default async function updateOutputsGlobs(tree: Tree) {
continue;
}

targetConfiguration.outputs = replaceOutputs(targetConfiguration);
targetConfiguration.outputs =
targetConfiguration.outputs.map(replaceOutput);
}
return json;
});
Expand Down

0 comments on commit 870a9bd

Please sign in to comment.