Skip to content

Commit

Permalink
chore(misc): review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 10, 2023
1 parent 1ad4bc3 commit 5add77c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
14 changes: 7 additions & 7 deletions docs/shared/reference/project-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ You can also express the same configuration using:

```json
"build": {
"dependsOn": [{ "projects": "{dependencies}", "target": "build" }]
"dependsOn": [{ "projects": "dependencies", "target": "build" }]
},
"test": {
"dependsOn": [{ "projects": "{self}", "target": "build" }]
"dependsOn": [{ "projects": "self", "target": "build" }]
}
```

Expand All @@ -290,24 +290,24 @@ With the expanded syntax, you also have a third option available to configure ho
```json
"build": {
// forward params passed to this target to the dependency targets
"dependsOn": [{ "projects": "{dependencies}", "target": "build", "params": "forward" }]
"dependsOn": [{ "projects": "dependencies", "target": "build", "params": "forward" }]
},
"test": {
// ignore params passed to this target, won't be forwarded to the dependency targets
"dependsOn": [{ "projects": "{dependencies}", "target": "build", "params": "ignore" }]
"dependsOn": [{ "projects": "dependencies", "target": "build", "params": "ignore" }]
}
"lint": {
// ignore params passed to this target, won't be forwarded to the dependency targets
"dependsOn": [{ "projects": "{dependencies}", "target": "build" }]
"dependsOn": [{ "projects": "dependencies", "target": "build" }]
}
```

Obviously this also works when defining a relation for the target of the project itself using `"projects": "{self}"`:
Obviously this also works when defining a relation for the target of the project itself using `"projects": "self"`:

```json
"build": {
// forward params passed to this target to the project target
"dependsOn": [{ "projects": "{self}", "target": "pre-build", "params": "forward" }]
"dependsOn": [{ "projects": "self", "target": "pre-build", "params": "forward" }]
}
```

Expand Down
5 changes: 4 additions & 1 deletion packages/nx/src/config/workspace-json-project-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ export interface ProjectConfiguration {

export interface TargetDependencyConfig {
/**
* A list of projects that have `target`. Supports two tokens or a string[]:
* A list of projects that have `target`. Supports project names or two special values:
*
* - '{self}': This target depends on another target of the same project
* - '{dependencies}': This target depends on targets of the projects of it's deps.
*
* The special values {self}/{dependencies} should be preferred - they prevent cases where a project
* that needs to be built is missed.
*/
projects: string[] | string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
getProjects,
readNxJson,
updateNxJson,
updateProjectConfiguration,
} from '../../generators/utils/project-configuration';
import { Tree } from '../../generators/tree';

export default async function (tree: Tree) {
updateNxJson(tree);
updateDependsOnInsideNxJson(tree);

const projectsConfigurations = getProjects(tree);
for (const [projectName, projectConfiguration] of projectsConfigurations) {
Expand All @@ -16,11 +17,13 @@ export default async function (tree: Tree) {
)) {
for (const dependency of targetConfiguration.dependsOn ?? []) {
if (typeof dependency !== 'string') {
dependency.projects =
(dependency.projects as string) === 'self'
? '{self}'
: '{dependencies}';
projectChanged = true;
if (dependency.projects === 'self') {
dependency.projects = '{self}';
projectChanged = true;
} else if (dependency.projects === 'dependencies') {
dependency.projects = '{dependencies}';
projectChanged = true;
}
}
}
}
Expand All @@ -29,23 +32,25 @@ export default async function (tree: Tree) {
}
}
}
function updateNxJson(tree: Tree) {
function updateDependsOnInsideNxJson(tree: Tree) {
const nxJson = readNxJson(tree);
let nxJsonChanged = false;
for (const [target, defaults] of Object.entries(
nxJson?.targetDefaults ?? {}
)) {
for (const dependency of defaults.dependsOn ?? []) {
if (typeof dependency !== 'string') {
dependency.projects =
(dependency.projects as string) === 'self'
? '{self}'
: '{dependencies}';
nxJsonChanged = true;
if (dependency.projects === 'self') {
dependency.projects = '{self}';
nxJsonChanged = true;
} else if (dependency.projects === 'dependencies') {
dependency.projects = '{dependencies}';
nxJsonChanged = true;
}
}
}
}
if (nxJsonChanged) {
tree.write('nx.json', JSON.stringify(nxJson, null, 2));
updateNxJson(tree, nxJson);
}
}

0 comments on commit 5add77c

Please sign in to comment.