Skip to content

Commit 7301930

Browse files
authored
fix(core): consider overrides for output path (#3172)
1 parent 6636e53 commit 7301930

File tree

4 files changed

+159
-73
lines changed

4 files changed

+159
-73
lines changed

packages/workspace/src/tasks-runner/tasks-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NxJson } from '../core/shared-interfaces';
77
export interface Task {
88
id: string;
99
target: Target;
10-
overrides: Object;
10+
overrides: any;
1111
hash?: string;
1212
projectRoot?: string;
1313
hashDetails?: {

packages/workspace/src/tasks-runner/utils.spec.ts

Lines changed: 140 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,180 @@ describe('utils', () => {
44
describe('getOutputsForTargetAndConfiguration', () => {
55
it('should return outputs when defined', () => {
66
expect(
7-
getOutputsForTargetAndConfiguration('build', 'production', {
8-
name: 'myapp',
9-
type: 'application',
10-
data: {
11-
architect: {
12-
build: {
13-
outputs: ['one', 'two'],
14-
},
7+
getOutputsForTargetAndConfiguration(
8+
{
9+
overrides: {},
10+
target: {
11+
project: 'myapp',
12+
target: 'build',
13+
configuration: 'production',
1514
},
16-
files: [],
1715
},
18-
})
16+
{
17+
name: 'myapp',
18+
type: 'application',
19+
data: {
20+
architect: {
21+
build: {
22+
outputs: ['one', 'two'],
23+
},
24+
},
25+
files: [],
26+
},
27+
}
28+
)
1929
).toEqual(['one', 'two']);
2030
});
2131

2232
it('should return configuration-specific outputPath when defined', () => {
2333
expect(
24-
getOutputsForTargetAndConfiguration('build', 'production', {
25-
name: 'myapp',
26-
type: 'application',
27-
data: {
28-
architect: {
29-
build: {
30-
options: {
31-
outputPath: 'one',
32-
},
33-
configurations: {
34-
production: {
35-
outputPath: 'two',
34+
getOutputsForTargetAndConfiguration(
35+
{
36+
overrides: {},
37+
target: {
38+
project: 'myapp',
39+
target: 'build',
40+
configuration: 'production',
41+
},
42+
},
43+
{
44+
name: 'myapp',
45+
type: 'application',
46+
data: {
47+
architect: {
48+
build: {
49+
options: {
50+
outputPath: 'one',
51+
},
52+
configurations: {
53+
production: {
54+
outputPath: 'two',
55+
},
3656
},
3757
},
3858
},
59+
files: [],
3960
},
40-
files: [],
41-
},
42-
})
61+
}
62+
)
4363
).toEqual(['two']);
4464
});
4565

4666
it('should return configuration-independent outputPath when defined', () => {
4767
expect(
48-
getOutputsForTargetAndConfiguration('build', 'production', {
49-
name: 'myapp',
50-
type: 'application',
51-
data: {
52-
architect: {
53-
build: {
54-
options: {
55-
outputPath: 'one',
56-
},
57-
configurations: {
58-
production: {},
68+
getOutputsForTargetAndConfiguration(
69+
{
70+
overrides: {},
71+
target: {
72+
project: 'myapp',
73+
target: 'build',
74+
configuration: 'production',
75+
},
76+
},
77+
{
78+
name: 'myapp',
79+
type: 'application',
80+
data: {
81+
architect: {
82+
build: {
83+
options: {
84+
outputPath: 'one',
85+
},
86+
configurations: {
87+
production: {},
88+
},
5989
},
6090
},
91+
files: [],
6192
},
62-
files: [],
63-
},
64-
})
93+
}
94+
)
6595
).toEqual(['one']);
6696
});
6797

6898
it('should handle invalid configuration', () => {
6999
expect(
70-
getOutputsForTargetAndConfiguration('build', 'production', {
71-
name: 'myapp',
72-
type: 'application',
73-
data: {
74-
architect: {
75-
build: {
76-
options: {
77-
outputPath: 'one',
100+
getOutputsForTargetAndConfiguration(
101+
{
102+
overrides: {},
103+
target: {
104+
project: 'myapp',
105+
target: 'build',
106+
configuration: 'production',
107+
},
108+
},
109+
{
110+
name: 'myapp',
111+
type: 'application',
112+
data: {
113+
architect: {
114+
build: {
115+
options: {
116+
outputPath: 'one',
117+
},
78118
},
79119
},
120+
files: [],
80121
},
81-
files: [],
82-
},
83-
})
122+
}
123+
)
84124
).toEqual(['one']);
85125
});
86126

127+
it('should handle overrides', () => {
128+
expect(
129+
getOutputsForTargetAndConfiguration(
130+
{
131+
overrides: {
132+
outputPath: 'overrideOutputPath',
133+
},
134+
target: {
135+
project: 'myapp',
136+
target: 'build',
137+
configuration: 'production',
138+
},
139+
},
140+
{
141+
name: 'myapp',
142+
type: 'application',
143+
data: {
144+
architect: {
145+
build: {
146+
options: {
147+
outputPath: 'one',
148+
},
149+
},
150+
},
151+
files: [],
152+
},
153+
}
154+
)
155+
).toEqual(['overrideOutputPath']);
156+
});
157+
87158
it('should return default output path when nothing else is defined', () => {
88159
expect(
89-
getOutputsForTargetAndConfiguration('build', 'production', {
90-
name: 'myapp',
91-
type: 'application',
92-
data: {
93-
root: 'root-myapp',
94-
architect: {
95-
build: {},
160+
getOutputsForTargetAndConfiguration(
161+
{
162+
overrides: {},
163+
target: {
164+
project: 'myapp',
165+
target: 'build',
166+
configuration: 'production',
96167
},
97-
files: [],
98168
},
99-
})
169+
{
170+
name: 'myapp',
171+
type: 'application',
172+
data: {
173+
root: 'root-myapp',
174+
architect: {
175+
build: {},
176+
},
177+
files: [],
178+
},
179+
}
180+
)
100181
).toEqual(['dist/root-myapp']);
101182
});
102183
});

packages/workspace/src/tasks-runner/utils.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,17 @@ export function getCommand(cliCommand: string, isYarn: boolean, task: Task) {
4545
}
4646

4747
export function getOutputs(p: Record<string, ProjectGraphNode>, task: Task) {
48-
return getOutputsForTargetAndConfiguration(
49-
task.target.target,
50-
task.target.configuration,
51-
p[task.target.project]
52-
);
48+
return getOutputsForTargetAndConfiguration(task, p[task.target.project]);
5349
}
5450

5551
export function getOutputsForTargetAndConfiguration(
56-
target: string,
57-
configuration: string,
52+
task: Pick<Task, 'target' | 'overrides'>,
5853
node: ProjectGraphNode
5954
) {
55+
if (task.overrides?.outputPath) {
56+
return [task.overrides?.outputPath];
57+
}
58+
const { target, configuration } = task.target;
6059
const architect = node.data.architect[target];
6160
if (architect && architect.outputs) return architect.outputs;
6261

packages/workspace/src/utils/buildable-libs-utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ export function calculateProjectDependencies(
5353
return {
5454
name: libPackageJson.name, // i.e. @workspace/mylib
5555
outputs: getOutputsForTargetAndConfiguration(
56-
context.target.target,
57-
context.target.configuration,
56+
{
57+
overrides: {},
58+
target: context.target,
59+
},
5860
depNode
5961
),
6062
node: depNode,
@@ -234,8 +236,10 @@ export function updateBuildableProjectPackageJsonDependencies(
234236
dependencies: DependentBuildableProjectNode[]
235237
) {
236238
const outputs = getOutputsForTargetAndConfiguration(
237-
context.target.target,
238-
context.target.configuration,
239+
{
240+
overrides: {},
241+
target: context.target,
242+
},
239243
node
240244
);
241245

@@ -268,8 +272,10 @@ export function updateBuildableProjectPackageJsonDependencies(
268272
let depVersion;
269273
if (entry.node.type === ProjectType.lib) {
270274
const outputs = getOutputsForTargetAndConfiguration(
271-
context.target.target,
272-
context.target.configuration,
275+
{
276+
overrides: {},
277+
target: context.target,
278+
},
273279
entry.node
274280
);
275281

0 commit comments

Comments
 (0)