diff --git a/packages/nx/migrations.json b/packages/nx/migrations.json index f287f739d45ba..cf5fd96773082 100644 --- a/packages/nx/migrations.json +++ b/packages/nx/migrations.json @@ -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" } } } diff --git a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts index 8f603e04f3ac1..c7f924ae710b9 100644 --- a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts +++ b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.spec.ts @@ -91,7 +91,7 @@ describe('15.0.0 migration (prefix-outputs)', () => { nx: { targets: { build: { - outputs: ['dist/proj'], + outputs: ['dist/proj', 'proj/build'], }, }, }, @@ -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'], }); }); diff --git a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts index 5f99a0bec689c..6991ff9fb60e1 100644 --- a/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts +++ b/packages/nx/src/migrations/update-15-0-0/prefix-outputs.ts @@ -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; } @@ -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; } diff --git a/packages/nx/src/tasks-runner/utils.ts b/packages/nx/src/tasks-runner/utils.ts index 48ea06df4135e..e8501178dacdd 100644 --- a/packages/nx/src/tasks-runner/utils.ts +++ b/packages/nx/src/tasks-runner/utils.ts @@ -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