diff --git a/docs/shared/concepts/task-pipeline-configuration.md b/docs/shared/concepts/task-pipeline-configuration.md index 3d5fd840f450f..76b886f7f8a6e 100644 --- a/docs/shared/concepts/task-pipeline-configuration.md +++ b/docs/shared/concepts/task-pipeline-configuration.md @@ -60,8 +60,7 @@ This mechanism is very flexible. Let's look at this example: } ``` -> Note, older versions of Nx used targetDependencies instead of targetDefaults. Both still work, but targetDefaults is -> recommended. +> Note, older versions of Nx used targetDependencies instead of targetDefaults. `targetDependencies` was removed in version 16, with `targetDefaults` replacing its use case. When running `nx test myproj`, the above configuration would tell Nx to diff --git a/e2e/nx-run/src/run.test.ts b/e2e/nx-run/src/run.test.ts index 24441c619bbc8..94ba220807f3e 100644 --- a/e2e/nx-run/src/run.test.ts +++ b/e2e/nx-run/src/run.test.ts @@ -345,7 +345,7 @@ describe('Nx Running Tests', () => { ); }); - it('should be able to include deps using target dependencies', () => { + it('should be able to include deps using dependsOn', () => { const originalWorkspace = readProjectConfig(myapp); updateProjectConfig(myapp, (config) => { config.targets.prep = { @@ -370,25 +370,6 @@ describe('Nx Running Tests', () => { updateProjectConfig(myapp, () => originalWorkspace); }, 10000); - it('should be able to include deps using target dependencies defined at the root', () => { - const originalNxJson = readFile('nx.json'); - const nxJson = readJson('nx.json'); - nxJson.targetDependencies = { - build: ['^build', '^e2e-extra-entry-to-bust-cache'], - }; - updateFile('nx.json', JSON.stringify(nxJson)); - - const output = runCLI(`build ${myapp}`); - expect(output).toContain( - `NX Running target build for project ${myapp} and 2 tasks it depends on` - ); - expect(output).toContain(myapp); - expect(output).toContain(mylib1); - expect(output).toContain(mylib2); - - updateFile('nx.json', originalNxJson); - }, 10000); - it('should be able to include deps using target defaults defined at the root', () => { const nxJson = readJson('nx.json'); updateProjectConfig(myapp, (config) => { diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index f852c44be585f..19bc1ffb15885 100644 --- a/packages/nx/schemas/nx-schema.json +++ b/packages/nx/schemas/nx-schema.json @@ -43,13 +43,6 @@ "$ref": "#/definitions/targetDefaultsConfig" } }, - "targetDependencies": { - "type": "object", - "description": "Dependencies between different target names across all projects.", - "additionalProperties": { - "$ref": "#/definitions/targetDependencyConfig" - } - }, "workspaceLayout": { "type": "object", "description": "Where new apps + libs should be placed.", @@ -173,38 +166,6 @@ }, "additionalProperties": false }, - "targetDependencyConfig": { - "type": "array", - "items": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "object", - "properties": { - "projects": { - "type": "string", - "description": "The projects that the targets belong to.", - "enum": ["self", "dependencies"] - }, - "target": { - "type": "string", - "description": "The name of the target." - }, - "params": { - "type": "string", - "description": "Configuration for params handling.", - "enum": ["ignore", "forward"], - "default": "ignore" - } - }, - "additionalProperties": false, - "required": ["projects", "target"] - } - ] - } - }, "targetDefaultsConfig": { "type": "object", "description": "Target defaults", diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index b36f0e4a4409e..3a159b38cf2bd 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -59,11 +59,6 @@ export interface NxJsonConfiguration { * @deprecated use {@link namedInputs} instead. For more information see https://nx.dev/deprecated/global-implicit-dependencies#global-implicit-dependencies */ implicitDependencies?: ImplicitDependencyEntry; - /** - * @deprecated use targetDefaults instead - * Dependencies between different target names across all projects - */ - targetDependencies?: TargetDependencies; /** * Named inputs targets can refer to reduce duplication */ diff --git a/packages/nx/src/config/workspaces.ts b/packages/nx/src/config/workspaces.ts index 4030440f46bbe..050972cc3ac96 100644 --- a/packages/nx/src/config/workspaces.ts +++ b/packages/nx/src/config/workspaces.ts @@ -301,19 +301,17 @@ export class Workspaces { ); const baseNxJson = readJsonFile(extendedNxJsonPath); - return this.mergeTargetDefaultsAndTargetDependencies({ + return { ...baseNxJson, ...nxJsonConfiguration, - }); + }; } else { - return this.mergeTargetDefaultsAndTargetDependencies( - nxJsonConfiguration - ); + return nxJsonConfiguration; } } else { try { - return this.mergeTargetDefaultsAndTargetDependencies( - readJsonFile(join(__dirname, '..', '..', 'presets', 'core.json')) + return readJsonFile( + join(__dirname, '..', '..', 'presets', 'core.json') ); } catch (e) { return {}; @@ -321,29 +319,6 @@ export class Workspaces { } } - private mergeTargetDefaultsAndTargetDependencies( - nxJson: NxJsonConfiguration - ) { - if (!nxJson.targetDefaults) { - nxJson.targetDefaults = {}; - } - if (nxJson.targetDependencies) { - for (const targetName of Object.keys(nxJson.targetDependencies)) { - if (!nxJson.targetDefaults[targetName]) { - nxJson.targetDefaults[targetName] = {}; - } - if (!nxJson.targetDefaults[targetName].dependsOn) { - nxJson.targetDefaults[targetName].dependsOn = []; - } - nxJson.targetDefaults[targetName].dependsOn = [ - ...nxJson.targetDefaults[targetName].dependsOn, - ...nxJson.targetDependencies[targetName], - ]; - } - } - return nxJson; - } - private getImplementationFactory( implementation: string, directory: string diff --git a/packages/nx/src/generators/utils/deprecated.ts b/packages/nx/src/generators/utils/deprecated.ts index 023f3f618e8f1..c75a6a561ecd4 100644 --- a/packages/nx/src/generators/utils/deprecated.ts +++ b/packages/nx/src/generators/utils/deprecated.ts @@ -34,7 +34,6 @@ export function updateWorkspaceConfiguration( npmScope, namedInputs, targetDefaults, - targetDependencies, workspaceLayout, tasksRunnerOptions, affected, @@ -49,7 +48,6 @@ export function updateWorkspaceConfiguration( npmScope, namedInputs, targetDefaults, - targetDependencies, workspaceLayout, tasksRunnerOptions, affected, diff --git a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts index 033c1d6927751..271fb8ee8404c 100644 --- a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts +++ b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts @@ -15,7 +15,7 @@ describe('createTargetDefaults', () => { it('should work', async () => { const nxJson = readNxJson(tree); - nxJson.targetDependencies = { + (nxJson as any).targetDependencies = { a: [], b: [ 'bb', @@ -33,7 +33,7 @@ describe('createTargetDefaults', () => { dependsOn: ['bb', 'bbb', '^c'], }, }); - expect(updated.targetDependencies).toBeUndefined(); + expect((updated as any).targetDependencies).toBeUndefined(); }); it('should not error when nxJson does not exist', async () => { diff --git a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts index 08f37afbaf9bb..3e8cf737f1c86 100644 --- a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts +++ b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts @@ -1,3 +1,5 @@ +import { TargetDependencyConfig } from '../../config/workspace-json-project-json'; +import { NxJsonConfiguration } from '../../config/nx-json'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; import { Tree } from '../../generators/tree'; import { readNxJson, updateNxJson } from '../../generators/utils/nx-json'; @@ -8,7 +10,9 @@ export default async function (tree: Tree) { return; } - const nxJson = readNxJson(tree); + const nxJson: NxJsonConfiguration & { + targetDependencies?: Record; + } = readNxJson(tree); if (nxJson.targetDependencies) { nxJson.targetDefaults = {}; diff --git a/packages/nx/src/project-graph/nx-deps-cache.spec.ts b/packages/nx/src/project-graph/nx-deps-cache.spec.ts index fbf14c30b150d..94b48d69fe481 100644 --- a/packages/nx/src/project-graph/nx-deps-cache.spec.ts +++ b/packages/nx/src/project-graph/nx-deps-cache.spec.ts @@ -5,7 +5,7 @@ import { shouldRecomputeWholeGraph, } from './nx-deps-cache'; import { ProjectGraph } from '../config/project-graph'; -import { WorkspaceJsonConfiguration } from '../config/workspace-json-project-json'; +import { ProjectsConfigurations } from '../config/workspace-json-project-json'; import { NxJsonConfiguration } from '../config/nx-json'; describe('nx deps utils', () => { @@ -15,7 +15,7 @@ describe('nx deps utils', () => { shouldRecomputeWholeGraph( createCache({ version: '5.1' }), createPackageJsonDeps({}), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({}), createTsConfigJson() ) @@ -27,7 +27,7 @@ describe('nx deps utils', () => { shouldRecomputeWholeGraph( createCache({ version: '4.0' }), createPackageJsonDeps({}), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({}), createTsConfigJson() ) @@ -44,7 +44,7 @@ describe('nx deps utils', () => { }, }), createPackageJsonDeps({}), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({}), createTsConfigJson() ) @@ -60,7 +60,7 @@ describe('nx deps utils', () => { }, }), createPackageJsonDeps({}), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({}), createTsConfigJson() ) @@ -72,7 +72,7 @@ describe('nx deps utils', () => { shouldRecomputeWholeGraph( createCache({}), createPackageJsonDeps({}), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({}), createTsConfigJson({ mylib: ['libs/mylib/changed.ts'] }) ) @@ -84,7 +84,7 @@ describe('nx deps utils', () => { shouldRecomputeWholeGraph( createCache({}), createPackageJsonDeps({}), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({ plugins: ['plugin', 'plugin2'], }), @@ -98,7 +98,7 @@ describe('nx deps utils', () => { shouldRecomputeWholeGraph( createCache({}), createPackageJsonDeps({ plugin: '2.0.0' }), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({}), createTsConfigJson() ) @@ -110,7 +110,7 @@ describe('nx deps utils', () => { shouldRecomputeWholeGraph( createCache({}), createPackageJsonDeps({ plugin: '2.0.0' }), - createWorkspaceJson({}), + createProjectsConfiguration({}), createNxJson({ pluginsConfig: { one: 1 } }), createTsConfigJson() ) @@ -343,7 +343,7 @@ describe('nx deps utils', () => { return { ...defaults, ...p }; } - function createWorkspaceJson(p: any): WorkspaceJsonConfiguration { + function createProjectsConfiguration(p: any): ProjectsConfigurations { const defaults = { projects: { mylib: {} }, } as any; @@ -354,7 +354,6 @@ describe('nx deps utils', () => { const defaults: NxJsonConfiguration = { npmScope: '', workspaceLayout: {} as any, - targetDependencies: {}, plugins: ['plugin'], }; return { ...defaults, ...p }; diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index c3046f6c5f5c6..300644fdc6716 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -302,11 +302,11 @@ function constructLifeCycles(lifeCycle: LifeCycle) { } function mergeTargetDependencies( - defaults: TargetDefaults, + defaults: TargetDefaults | undefined | null, deps: TargetDependencies ): TargetDependencies { const res = {}; - Object.keys(defaults).forEach((k) => { + Object.keys(defaults ?? {}).forEach((k) => { res[k] = defaults[k].dependsOn; }); if (deps) { diff --git a/packages/workspace/src/generators/new/generate-workspace-files.ts b/packages/workspace/src/generators/new/generate-workspace-files.ts index 973f3fc262d77..4b651329bb9d4 100644 --- a/packages/workspace/src/generators/new/generate-workspace-files.ts +++ b/packages/workspace/src/generators/new/generate-workspace-files.ts @@ -49,7 +49,6 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) { addPropertyWithStableKeys(json, 'extends', 'nx/presets/npm.json'); delete json.implicitDependencies; delete json.targetDefaults; - delete json.targetDependencies; delete json.workspaceLayout; delete json.npmScope; } diff --git a/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts b/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts index fd66d6cb62d8e..68528b766761e 100644 --- a/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts +++ b/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts @@ -1,8 +1,18 @@ -import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit'; +import { + formatFiles, + NxJsonConfiguration, + readNxJson, + TargetDependencyConfig, + Tree, + updateNxJson, +} from '@nrwl/devkit'; import { output } from '../../utilities/output'; export async function setTargetDependencies(host: Tree) { - const config = readNxJson(host); + const config: NxJsonConfiguration & { + targetDependencies?: Record; + } = readNxJson(host); + const strictlyOrderedTargets = config.tasksRunnerOptions?.['default']?.options ?.strictlyOrderedTargets || ['build']; delete config.tasksRunnerOptions?.['default']?.options