Skip to content

Commit

Permalink
feat(core): remove support for
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 11, 2023
1 parent 1e31d47 commit 68780c3
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 117 deletions.
3 changes: 1 addition & 2 deletions docs/shared/concepts/task-pipeline-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 1 addition & 20 deletions e2e/nx-run/src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) => {
Expand Down
39 changes: 0 additions & 39 deletions packages/nx/schemas/nx-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions packages/nx/src/config/nx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
* @deprecated use {@link namedInputs} instead. For more information see https://nx.dev/deprecated/global-implicit-dependencies#global-implicit-dependencies
*/
implicitDependencies?: ImplicitDependencyEntry<T>;
/**
* @deprecated use targetDefaults instead
* Dependencies between different target names across all projects
*/
targetDependencies?: TargetDependencies;
/**
* Named inputs targets can refer to reduce duplication
*/
Expand Down
35 changes: 5 additions & 30 deletions packages/nx/src/config/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,49 +301,24 @@ export class Workspaces {
);
const baseNxJson =
readJsonFile<NxJsonConfiguration>(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 {};
}
}
}

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<T>(
implementation: string,
directory: string
Expand Down
2 changes: 0 additions & 2 deletions packages/nx/src/generators/utils/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function updateWorkspaceConfiguration(
npmScope,
namedInputs,
targetDefaults,
targetDependencies,
workspaceLayout,
tasksRunnerOptions,
affected,
Expand All @@ -49,7 +48,6 @@ export function updateWorkspaceConfiguration(
npmScope,
namedInputs,
targetDefaults,
targetDependencies,
workspaceLayout,
tasksRunnerOptions,
affected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('createTargetDefaults', () => {

it('should work', async () => {
const nxJson = readNxJson(tree);
nxJson.targetDependencies = {
(nxJson as any).targetDependencies = {
a: [],
b: [
'bb',
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,7 +10,9 @@ export default async function (tree: Tree) {
return;
}

const nxJson = readNxJson(tree);
const nxJson: NxJsonConfiguration & {
targetDependencies?: Record<string, TargetDependencyConfig[]>;
} = readNxJson(tree);

if (nxJson.targetDependencies) {
nxJson.targetDefaults = {};
Expand Down
21 changes: 10 additions & 11 deletions packages/nx/src/project-graph/nx-deps-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -15,7 +15,7 @@ describe('nx deps utils', () => {
shouldRecomputeWholeGraph(
createCache({ version: '5.1' }),
createPackageJsonDeps({}),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({}),
createTsConfigJson()
)
Expand All @@ -27,7 +27,7 @@ describe('nx deps utils', () => {
shouldRecomputeWholeGraph(
createCache({ version: '4.0' }),
createPackageJsonDeps({}),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({}),
createTsConfigJson()
)
Expand All @@ -44,7 +44,7 @@ describe('nx deps utils', () => {
},
}),
createPackageJsonDeps({}),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({}),
createTsConfigJson()
)
Expand All @@ -60,7 +60,7 @@ describe('nx deps utils', () => {
},
}),
createPackageJsonDeps({}),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({}),
createTsConfigJson()
)
Expand All @@ -72,7 +72,7 @@ describe('nx deps utils', () => {
shouldRecomputeWholeGraph(
createCache({}),
createPackageJsonDeps({}),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({}),
createTsConfigJson({ mylib: ['libs/mylib/changed.ts'] })
)
Expand All @@ -84,7 +84,7 @@ describe('nx deps utils', () => {
shouldRecomputeWholeGraph(
createCache({}),
createPackageJsonDeps({}),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({
plugins: ['plugin', 'plugin2'],
}),
Expand All @@ -98,7 +98,7 @@ describe('nx deps utils', () => {
shouldRecomputeWholeGraph(
createCache({}),
createPackageJsonDeps({ plugin: '2.0.0' }),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({}),
createTsConfigJson()
)
Expand All @@ -110,7 +110,7 @@ describe('nx deps utils', () => {
shouldRecomputeWholeGraph(
createCache({}),
createPackageJsonDeps({ plugin: '2.0.0' }),
createWorkspaceJson({}),
createProjectsConfiguration({}),
createNxJson({ pluginsConfig: { one: 1 } }),
createTsConfigJson()
)
Expand Down Expand Up @@ -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;
Expand All @@ -354,7 +354,6 @@ describe('nx deps utils', () => {
const defaults: NxJsonConfiguration = {
npmScope: '',
workspaceLayout: {} as any,
targetDependencies: {},
plugins: ['plugin'],
};
return { ...defaults, ...p };
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, TargetDependencyConfig[]>;
} = readNxJson(host);

const strictlyOrderedTargets = config.tasksRunnerOptions?.['default']?.options
?.strictlyOrderedTargets || ['build'];
delete config.tasksRunnerOptions?.['default']?.options
Expand Down

0 comments on commit 68780c3

Please sign in to comment.