From df522d1b0b88956351243d89a759ee21d5a7368c Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Tue, 6 Aug 2024 09:28:56 -0400 Subject: [PATCH] fix(core): script-based targets should be able to be modified in a project.json file --- .../src/plugins/package-json/create-nodes.spec.ts | 15 +++++++++++++++ .../nx/src/plugins/package-json/create-nodes.ts | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/plugins/package-json/create-nodes.spec.ts b/packages/nx/src/plugins/package-json/create-nodes.spec.ts index 7560f89db2f13a..fa6bdda6d70db8 100644 --- a/packages/nx/src/plugins/package-json/create-nodes.spec.ts +++ b/packages/nx/src/plugins/package-json/create-nodes.spec.ts @@ -570,6 +570,7 @@ describe('nx package.json workspaces plugin', () => { name: 'root', scripts: { build: 'echo build', + test: 'echo test', }, }), 'packages/a/project.json': JSON.stringify({ @@ -577,6 +578,9 @@ describe('nx package.json workspaces plugin', () => { 'something-other-than-build': { command: 'echo something-other-than-build', }, + test: { + dependsOn: ['build-native'], + }, }, }), }, @@ -597,6 +601,7 @@ describe('nx package.json workspaces plugin', () => { "targetGroups": { "NPM Scripts": [ "build", + "test", ], }, }, @@ -624,6 +629,16 @@ describe('nx package.json workspaces plugin', () => { "executor": "@nx/js:release-publish", "options": {}, }, + "test": { + "executor": "nx:run-script", + "metadata": { + "runCommand": "npm run test", + "scriptContent": "echo test", + }, + "options": { + "script": "test", + }, + }, }, }, }, diff --git a/packages/nx/src/plugins/package-json/create-nodes.ts b/packages/nx/src/plugins/package-json/create-nodes.ts index d722ae90554c9c..186f052abbb427 100644 --- a/packages/nx/src/plugins/package-json/create-nodes.ts +++ b/packages/nx/src/plugins/package-json/create-nodes.ts @@ -151,7 +151,13 @@ export function buildProjectConfigurationFromPackageJson( if (siblingProjectJson) { for (const target of Object.keys(siblingProjectJson?.targets ?? {})) { - delete packageJson.scripts?.[target]; + const { executor, command, options } = siblingProjectJson.targets[target]; + if ( + command || + (executor && executor !== 'nx:run-script' && options.script !== target) + ) { + delete packageJson.scripts?.[target]; + } } }