nx
nx copied to clipboard
Reduce Configuration with targetDefaults docs imply targetDefaults can define targets for projects
Documentation issue
- [ ] Reporting a typo
- [x] Reporting a documentation bug
- [ ] Documentation improvement
- [x] Documentation feedback
Is there a specific documentation page you are reporting?
https://nx.dev/recipes/running-tasks/reduce-repetitive-configuration
Additional context or description
The documentation states that we can remove duplicate configuration code by moving common target configuration to the nx.json file. While this is true, and based on the example in this doc, it also seems to imply that the refactored nx.json is sufficient to provide targets such as lint and test to lib1, lib2, lib3.
For example with lib1 the initial configuration was:
{
"name": "lib1",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/lib1/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/lib1",
"main": "libs/lib1/src/index.ts",
"tsConfig": "libs/lib1/tsconfig.lib.json",
"assets": ["libs/lib1/*.md", "libs/lib1/src/images/*"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/lib1/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/lib1/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
Which was reduced to the following after moving common configuration to nx.json
{
"name": "lib1",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/lib1/src",
"projectType": "library",
"targets": {
"build": {
"options": {
"assets": ["libs/lib1/*.md", "libs/lib1/src/images/*"]
}
}
},
"tags": []
}
Before, lib1 had test and lint targets, but if you change to the new configuration it will no longer have access to those targets without adding the following:
{
"name": "lib1",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/lib1/src",
"projectType": "library",
"targets": {
"build": {
"options": {
"assets": ["libs/lib1/*.md", "libs/lib1/src/images/*"]
}
},
"lint": {},
"test": {},
},
"tags": []
}
So I'm not sure if the docs are wrong or if there's a bug that doesn't allow a repo to work in the way the documentation states.
The original docs were added back in August: https://github.com/nrwl/nx/pull/18714
Hmmm, yeah this is a bit incorrect but we are about to launch some stuff closer to the original intention here so we may not address this just yet
Well that's exciting, is that version 18 or a new minor version?