Skip to content

Commit

Permalink
Merge pull request #4576 from novuhq/fix-nx-show-affected-script
Browse files Browse the repository at this point in the history
fix: updated the print-affected-array script after updating the nx
  • Loading branch information
LetItRock authored Oct 18, 2023
2 parents 64568b2 + 91e3e5c commit 9a47f4e
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions scripts/print-affected-array.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function commaSeparatedListToArray(str) {
function getAffectedCommandResult(str) {
const outputLines = str.trim().split(/\r?\n/);
if (outputLines.length > 2) {
return outputLines.slice(-1)[0];
return outputLines.slice(2).join('');
}

return '';
Expand All @@ -91,13 +91,22 @@ async function affectedProjectsContainingTask(taskName, baseBranch) {

return JSON.parse(cache);
}
// pnpm nx print-affected --target=[task] --base [base branch] --select=tasks.target.project
const result = commaSeparatedListToArray(
getAffectedCommandResult(
await pnpmRun('nx', 'print-affected', '--target', taskName, '--base', baseBranch, '--select=tasks.target.project')
)

const affectedCommandResult = await pnpmRun(
'nx',
'show',
'projects',
'--affected',
'--withTarget',
taskName,
'--base',
baseBranch,
'--json'
);

// pnpm nx show projects --affected --withTarget=[task] --base [base branch] --json
const result = JSON.parse(getAffectedCommandResult(affectedCommandResult));

fs.writeFileSync(cachePath, JSON.stringify(result));

return result;
Expand All @@ -113,21 +122,21 @@ async function allProjectsContainingTask(taskName) {
return JSON.parse(cache);
}

// pnpm nx print-affected --target=[task] --files package.json --select=tasks.target.project
const result = commaSeparatedListToArray(
getAffectedCommandResult(
await pnpmRun(
'nx',
'print-affected',
'--target',
taskName,
'--files',
'package.json',
'--select=tasks.target.project'
)
)
// pnpm nx show projects --affected --withTarget=[task] --files package.json --json
const affectedCommandResult = await pnpmRun(
'nx',
'show',
'projects',
'--affected',
'--withTarget',
taskName,
'--files',
'package.json',
'--json'
);

const result = JSON.parse(getAffectedCommandResult(affectedCommandResult));

fs.writeFileSync(cachePath, JSON.stringify(result));

return result;
Expand Down

0 comments on commit 9a47f4e

Please sign in to comment.