Skip to content

Commit

Permalink
fix(core): script-based targets should be able to be modified in a pr…
Browse files Browse the repository at this point in the history
…oject.json file
  • Loading branch information
AgentEnder committed Aug 6, 2024
1 parent a3869a8 commit df522d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/nx/src/plugins/package-json/create-nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,17 @@ describe('nx package.json workspaces plugin', () => {
name: 'root',
scripts: {
build: 'echo build',
test: 'echo test',
},
}),
'packages/a/project.json': JSON.stringify({
targets: {
'something-other-than-build': {
command: 'echo something-other-than-build',
},
test: {
dependsOn: ['build-native'],
},
},
}),
},
Expand All @@ -597,6 +601,7 @@ describe('nx package.json workspaces plugin', () => {
"targetGroups": {
"NPM Scripts": [
"build",
"test",
],
},
},
Expand Down Expand Up @@ -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",
},
},
},
},
},
Expand Down
8 changes: 7 additions & 1 deletion packages/nx/src/plugins/package-json/create-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}

Expand Down

0 comments on commit df522d1

Please sign in to comment.