Skip to content

Commit

Permalink
fix(core): fix migration and warn for invalid outputs (#18310)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Jul 26, 2023
1 parent eef0bd5 commit 2b67959
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions packages/nx/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
"version": "16.2.0-beta.0",
"description": "Remove outputPath from run commands",
"implementation": "./src/migrations/update-16-2-0/remove-run-commands-output-path"
},
"16.6.0-prefix-outputs": {
"cli": "nx",
"version": "16.6.0-beta.6",
"description": "Prefix outputs with {workspaceRoot}/{projectRoot} if needed",
"implementation": "./src/migrations/update-15-0-0/prefix-outputs"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('15.0.0 migration (prefix-outputs)', () => {
nx: {
targets: {
build: {
outputs: ['dist/proj'],
outputs: ['dist/proj', 'proj/build'],
},
},
},
Expand All @@ -101,7 +101,7 @@ describe('15.0.0 migration (prefix-outputs)', () => {
await prefixOutputs(tree);

expect(readJson(tree, 'proj/package.json').nx.targets.build).toEqual({
outputs: ['dist/proj'],
outputs: ['{workspaceRoot}/dist/proj', '{projectRoot}/build'],
});
});

Expand Down
17 changes: 10 additions & 7 deletions packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ export default async function (tree: Tree) {
const nxJson = readNxJson(tree);

for (const [projectName, project] of getProjects(tree)) {
if (!project.targets) {
continue;
}

for (const [_, target] of Object.entries(project.targets)) {
for (const [_, target] of Object.entries(project.targets ?? {})) {
if (!target.outputs) {
continue;
}
Expand All @@ -46,8 +42,15 @@ export default async function (tree: Tree) {
tree,
join(project.root, 'package.json'),
(json) => {
json.nx ??= {};
json.nx.targets ??= project.targets;
for (const target of Object.values(json.nx?.targets ?? {})) {
if (target.outputs) {
try {
validateOutputs(target.outputs);
} catch (e) {
target.outputs = transformLegacyOutputs(project.root, e);
}
}
}

return json;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/tasks-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export function getOutputsForTargetAndConfiguration(
validateOutputs(targetConfiguration.outputs);
} catch (error) {
if (error instanceof InvalidOutputsError) {
// TODO(v16): start warning for invalid outputs
// TODO(@FrozenPandaz): In v17, throw this error and do not transform.
console.warn(error.message);
targetConfiguration.outputs = transformLegacyOutputs(
node.data.root,
error
Expand Down

1 comment on commit 2b67959

@vercel
Copy link

@vercel vercel bot commented on 2b67959 Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.