Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): script-based targets should be able to be modified in a project.json file #27309

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 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,16 @@ 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 (
// will use run-commands, different target
command ||
// Either uses a different executor or runs a different script
(executor &&
(executor !== 'nx:run-script' || options?.script !== target))
) {
delete packageJson.scripts?.[target];
}
}
}

Expand Down