From 93876858e6eee6894c0af5a5ee48554608679ffd Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Mon, 12 Dec 2022 10:55:02 -0500 Subject: [PATCH] fix(core): workspaceRoot is not correctly inrepolated when projectRoot is . --- packages/nx/src/tasks-runner/utils.spec.ts | 19 +++++++++++++++++++ packages/nx/src/tasks-runner/utils.ts | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/tasks-runner/utils.spec.ts b/packages/nx/src/tasks-runner/utils.spec.ts index 3e60d05d06879..7027317e25d94 100644 --- a/packages/nx/src/tasks-runner/utils.spec.ts +++ b/packages/nx/src/tasks-runner/utils.spec.ts @@ -97,6 +97,25 @@ describe('utils', () => { ]); }); + it('should interpolate {workspaceRoot} when {projectRoot} = . by removing the slash after it', () => { + const data = { + name: 'myapp', + type: 'app', + data: { + root: '.', + targets: { + build: { + outputs: ['{workspaceRoot}/dist'], + }, + }, + files: [], + }, + }; + expect(getOutputsForTargetAndConfiguration(task, data as any)).toEqual([ + 'dist', + ]); + }); + it('should throw when {projectRoot} is used not at the beginning and the value is .', () => { const data = { name: 'myapp', diff --git a/packages/nx/src/tasks-runner/utils.ts b/packages/nx/src/tasks-runner/utils.ts index a8a0d005652cb..17501210e827d 100644 --- a/packages/nx/src/tasks-runner/utils.ts +++ b/packages/nx/src/tasks-runner/utils.ts @@ -197,7 +197,7 @@ export function interpolate(template: string, data: any): string { let res = template.replace('{workspaceRoot}/', ''); if (data.projectRoot == '.') { - res = template.replace('{projectRoot}/', ''); + res = res.replace('{projectRoot}/', ''); } return res.replace(/{([\s\S]+?)}/g, (match: string) => {