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

feat(core): add the outputs of a task onto the task #19561

Merged
merged 3 commits into from
Oct 12, 2023
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
9 changes: 9 additions & 0 deletions docs/generated/devkit/Task.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A representation of the invocation of an Executor
- [hash](../../devkit/documents/Task#hash): string
- [hashDetails](../../devkit/documents/Task#hashdetails): Object
- [id](../../devkit/documents/Task#id): string
- [outputs](../../devkit/documents/Task#outputs): string[]
- [overrides](../../devkit/documents/Task#overrides): any
- [projectRoot](../../devkit/documents/Task#projectroot): string
- [startTime](../../devkit/documents/Task#starttime): number
Expand Down Expand Up @@ -67,6 +68,14 @@ Unique ID

---

### outputs

• **outputs**: `string`[]

The outputs the task may produce

---

### overrides

• **overrides**: `any`
Expand Down
26 changes: 22 additions & 4 deletions docs/generated/devkit/getOutputsForTargetAndConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

▸ **getOutputsForTargetAndConfiguration**(`task`, `node`): `string`[]

#### Parameters

| Name | Type |
| :----- | :-------------------------------------------------------------------------- |
| `task` | [`Task`](../../devkit/documents/Task) |
| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/ProjectGraphProjectNode) |

#### Returns

`string`[]

**`Deprecated`**

Pass the target and overrides instead. This will be removed in v18.

▸ **getOutputsForTargetAndConfiguration**(`target`, `overrides`, `node`): `string`[]

Returns the list of outputs that will be cached.

#### Parameters

| Name | Type | Description |
| :----- | :-------------------------------------------------------------------------- | :-------------------------------------------------------- |
| `task` | `Pick`<[`Task`](../../devkit/documents/Task), `"overrides"` \| `"target"`\> | target + overrides |
| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/ProjectGraphProjectNode) | ProjectGraphProjectNode object that the task runs against |
| Name | Type |
| :---------- | :----------------------------------------------------------------------------------------------------------------- |
| `target` | [`Task`](../../devkit/documents/Task) \| { `configuration?`: `string` ; `project`: `string` ; `target`: `string` } |
| `overrides` | `any` |
| `node` | [`ProjectGraphProjectNode`](../../devkit/documents/ProjectGraphProjectNode) |

#### Returns

Expand Down
2 changes: 1 addition & 1 deletion e2e/angular-core/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const angularV1Json = (appName: string) => `{
},
"test": {
"builder": "@nx/jest:jest",
"outputs": ["coverage${appName}"],
"outputs": ["{workspaceRoot}/coverage${appName}"],
"options": {
"jestConfig": "${appName}/jest.config.ts",
"passWithNoTests": true
Expand Down
2 changes: 1 addition & 1 deletion e2e/next-core/src/next-webpack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('Next.js Webpack', () => {
updateJson(join('apps', appName, 'project.json'), (json) => {
json.targets.build = {
command: 'npx next build',
outputs: [`apps/${appName}/.next`],
outputs: [`{projectRoot}/.next`],
options: {
cwd: `apps/${appName}`,
},
Expand Down
4 changes: 2 additions & 2 deletions e2e/nx-run/src/invoke-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe('Invoke Runner', () => {
async function main(){
const r = await initTasksRunner({});

await r.invoke({tasks: [{id: '${mylib}:prebuild', target: {project: '${mylib}', target: 'prebuild'}, overrides: {__overrides_unparsed__: ''}}]});
await r.invoke({tasks: [{id: '${mylib}:build', target: {project: '${mylib}', target: 'build'}, overrides: {__overrides_unparsed__: ''}}]});
await r.invoke({tasks: [{id: '${mylib}:prebuild', target: {project: '${mylib}', target: 'prebuild'}, outputs: [], overrides: {__overrides_unparsed__: ''}}]});
await r.invoke({tasks: [{id: '${mylib}:build', target: {project: '${mylib}', target: 'build'}, outputs: [], overrides: {__overrides_unparsed__: ''}}]});
}

main().then(q => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ export function updateNgPackage(tree: Tree, schema: MoveImplOptions): void {
);
const outputs = getOutputsForTargetAndConfiguration(
{
target: {
project: schema.newProjectName,
target: 'build',
},
overrides: {},
project: schema.newProjectName,
target: 'build',
},
{},
{
name: schema.newProjectName,
type: 'lib',
Expand Down
13 changes: 13 additions & 0 deletions packages/js/src/utils/buildable-libs-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,26 +293,31 @@ describe('calculateDependenciesFromTaskGraph', () => {
id: 'lib1:build',
overrides: {},
target: { project: 'lib1', target: 'build' },
outputs: [],
},
'lib2:build': {
id: 'lib2:build',
overrides: {},
target: { project: 'lib2', target: 'build' },
outputs: [],
},
'lib2:build-base': {
id: 'lib2:build-base',
overrides: {},
target: { project: 'lib2', target: 'build-base' },
outputs: [],
},
'lib3:build': {
id: 'lib3:build',
overrides: {},
target: { project: 'lib3', target: 'build' },
outputs: [],
},
'lib4:build': {
id: 'lib4:build',
overrides: {},
target: { project: 'lib4', target: 'build' },
outputs: [],
},
},
};
Expand Down Expand Up @@ -458,41 +463,49 @@ describe('calculateDependenciesFromTaskGraph', () => {
id: 'lib1:build',
overrides: {},
target: { project: 'lib1', target: 'build' },
outputs: [],
},
'lib1:build-base': {
id: 'lib1:build-base',
overrides: {},
target: { project: 'lib1', target: 'build-base' },
outputs: [],
},
'lib2:build': {
id: 'lib2:build',
overrides: {},
target: { project: 'lib2', target: 'build' },
outputs: [],
},
'lib2:build-base': {
id: 'lib2:build-base',
overrides: {},
target: { project: 'lib2', target: 'build-base' },
outputs: [],
},
'lib3:build': {
id: 'lib3:build',
overrides: {},
target: { project: 'lib3', target: 'build' },
outputs: [],
},
'lib3:build-base': {
id: 'lib3:build-base',
overrides: {},
target: { project: 'lib3', target: 'build-base' },
outputs: [],
},
'lib4:build': {
id: 'lib4:build',
overrides: {},
target: { project: 'lib4', target: 'build' },
outputs: [],
},
'lib4:build-base': {
id: 'lib4:build-base',
overrides: {},
target: { project: 'lib4', target: 'build-base' },
outputs: [],
},
},
};
Expand Down
36 changes: 17 additions & 19 deletions packages/js/src/utils/buildable-libs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ export function calculateProjectDependencies(
: dep,
outputs: getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: projectName,
target: targetName,
configuration: configurationName,
},
project: projectName,
target: targetName,
configuration: configurationName,
},
{},
depNode
),
node: depNode,
Expand Down Expand Up @@ -260,7 +258,11 @@ export function calculateDependenciesFromTaskGraph(
return null;
}

let outputs = getOutputsForTargetAndConfiguration(depTask, depProjectNode);
let outputs = getOutputsForTargetAndConfiguration(
depTask.target,
depTask.overrides,
depProjectNode
);

if (outputs.length === 0) {
nonBuildableDependencies.push(depTask.target.project);
Expand Down Expand Up @@ -558,13 +560,11 @@ export function updateBuildableProjectPackageJsonDependencies(
) {
const outputs = getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: projectName,
target: targetName,
configuration: configurationName,
},
project: projectName,
target: targetName,
configuration: configurationName,
},
{},
node
);

Expand Down Expand Up @@ -598,13 +598,11 @@ export function updateBuildableProjectPackageJsonDependencies(
if (entry.node.type === 'lib') {
const outputs = getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: projectName,
target: targetName,
configuration: configurationName,
},
project: projectName,
target: targetName,
configuration: configurationName,
},
{},
entry.node
);

Expand Down
10 changes: 4 additions & 6 deletions packages/js/src/utils/package-json/update-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,11 @@ function addMissingDependencies(
) {
const outputs = getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: projectName,
target: targetName,
configuration: configurationName,
},
project: projectName,
target: targetName,
configuration: configurationName,
},
{},
entry.node
);

Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/command-line/affected/print-affected.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCommandAsString, getOutputs } from '../../tasks-runner/utils';
import { getCommandAsString } from '../../tasks-runner/utils';
import * as yargs from 'yargs';
import type { NxArgs } from '../../utils/command-line-utils';
import {
Expand Down Expand Up @@ -95,7 +95,7 @@ async function createTasks(
target: task.target,
hash: task.hash,
command: getCommandAsString(execCommand, task),
outputs: getOutputs(projectGraph.nodes, task),
outputs: task.outputs,
}));
}

Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/config/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export interface Task {
* Overrides for the configured options of the target
*/
overrides: any;

/**
* The outputs the task may produce
*/
outputs: string[];
/**
* Root of the project the task belongs to
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`TaskHasher dependentTasksOutputFiles should depend on dependent tasks o
"implicitDeps": {},
"nodes": {
"AllExternalDependencies": "3244421341483603138",
"ProjectConfiguration": "12802727827024321009",
"ProjectConfiguration": "16743571606168248002",
"TsConfig": "8767608672024750088",
"dist/libs/child/index.d.ts": "3244421341483603138",
"dist/libs/grandchild/index.d.ts": "3244421341483603138",
Expand All @@ -18,7 +18,7 @@ exports[`TaskHasher dependentTasksOutputFiles should depend on dependent tasks o
},
"runtime": {},
},
"value": "15526362704205124469",
"value": "14131423056691033336",
}
`;

Expand All @@ -29,7 +29,7 @@ exports[`TaskHasher dependentTasksOutputFiles should work with dependent tasks w
"implicitDeps": {},
"nodes": {
"AllExternalDependencies": "3244421341483603138",
"ProjectConfiguration": "12802727827024321009",
"ProjectConfiguration": "16743571606168248002",
"TsConfig": "8767608672024750088",
"dist/libs/child/index.d.ts": "3244421341483603138",
"dist/libs/grandchild/index.d.ts": "3244421341483603138",
Expand All @@ -40,7 +40,7 @@ exports[`TaskHasher dependentTasksOutputFiles should work with dependent tasks w
},
"runtime": {},
},
"value": "15526362704205124469",
"value": "14131423056691033336",
}
`;

Expand Down
Loading