fix(core): consider overrides for output path (#3172)
This commit is contained in:
parent
6636e53d64
commit
7301930d3d
@ -7,7 +7,7 @@ import { NxJson } from '../core/shared-interfaces';
|
|||||||
export interface Task {
|
export interface Task {
|
||||||
id: string;
|
id: string;
|
||||||
target: Target;
|
target: Target;
|
||||||
overrides: Object;
|
overrides: any;
|
||||||
hash?: string;
|
hash?: string;
|
||||||
projectRoot?: string;
|
projectRoot?: string;
|
||||||
hashDetails?: {
|
hashDetails?: {
|
||||||
|
|||||||
@ -4,7 +4,16 @@ describe('utils', () => {
|
|||||||
describe('getOutputsForTargetAndConfiguration', () => {
|
describe('getOutputsForTargetAndConfiguration', () => {
|
||||||
it('should return outputs when defined', () => {
|
it('should return outputs when defined', () => {
|
||||||
expect(
|
expect(
|
||||||
getOutputsForTargetAndConfiguration('build', 'production', {
|
getOutputsForTargetAndConfiguration(
|
||||||
|
{
|
||||||
|
overrides: {},
|
||||||
|
target: {
|
||||||
|
project: 'myapp',
|
||||||
|
target: 'build',
|
||||||
|
configuration: 'production',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
name: 'myapp',
|
name: 'myapp',
|
||||||
type: 'application',
|
type: 'application',
|
||||||
data: {
|
data: {
|
||||||
@ -15,13 +24,23 @@ describe('utils', () => {
|
|||||||
},
|
},
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
).toEqual(['one', 'two']);
|
).toEqual(['one', 'two']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return configuration-specific outputPath when defined', () => {
|
it('should return configuration-specific outputPath when defined', () => {
|
||||||
expect(
|
expect(
|
||||||
getOutputsForTargetAndConfiguration('build', 'production', {
|
getOutputsForTargetAndConfiguration(
|
||||||
|
{
|
||||||
|
overrides: {},
|
||||||
|
target: {
|
||||||
|
project: 'myapp',
|
||||||
|
target: 'build',
|
||||||
|
configuration: 'production',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
name: 'myapp',
|
name: 'myapp',
|
||||||
type: 'application',
|
type: 'application',
|
||||||
data: {
|
data: {
|
||||||
@ -39,13 +58,23 @@ describe('utils', () => {
|
|||||||
},
|
},
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
).toEqual(['two']);
|
).toEqual(['two']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return configuration-independent outputPath when defined', () => {
|
it('should return configuration-independent outputPath when defined', () => {
|
||||||
expect(
|
expect(
|
||||||
getOutputsForTargetAndConfiguration('build', 'production', {
|
getOutputsForTargetAndConfiguration(
|
||||||
|
{
|
||||||
|
overrides: {},
|
||||||
|
target: {
|
||||||
|
project: 'myapp',
|
||||||
|
target: 'build',
|
||||||
|
configuration: 'production',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
name: 'myapp',
|
name: 'myapp',
|
||||||
type: 'application',
|
type: 'application',
|
||||||
data: {
|
data: {
|
||||||
@ -61,13 +90,23 @@ describe('utils', () => {
|
|||||||
},
|
},
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
).toEqual(['one']);
|
).toEqual(['one']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle invalid configuration', () => {
|
it('should handle invalid configuration', () => {
|
||||||
expect(
|
expect(
|
||||||
getOutputsForTargetAndConfiguration('build', 'production', {
|
getOutputsForTargetAndConfiguration(
|
||||||
|
{
|
||||||
|
overrides: {},
|
||||||
|
target: {
|
||||||
|
project: 'myapp',
|
||||||
|
target: 'build',
|
||||||
|
configuration: 'production',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
name: 'myapp',
|
name: 'myapp',
|
||||||
type: 'application',
|
type: 'application',
|
||||||
data: {
|
data: {
|
||||||
@ -80,13 +119,54 @@ describe('utils', () => {
|
|||||||
},
|
},
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
).toEqual(['one']);
|
).toEqual(['one']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle overrides', () => {
|
||||||
|
expect(
|
||||||
|
getOutputsForTargetAndConfiguration(
|
||||||
|
{
|
||||||
|
overrides: {
|
||||||
|
outputPath: 'overrideOutputPath',
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
project: 'myapp',
|
||||||
|
target: 'build',
|
||||||
|
configuration: 'production',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'myapp',
|
||||||
|
type: 'application',
|
||||||
|
data: {
|
||||||
|
architect: {
|
||||||
|
build: {
|
||||||
|
options: {
|
||||||
|
outputPath: 'one',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
files: [],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).toEqual(['overrideOutputPath']);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return default output path when nothing else is defined', () => {
|
it('should return default output path when nothing else is defined', () => {
|
||||||
expect(
|
expect(
|
||||||
getOutputsForTargetAndConfiguration('build', 'production', {
|
getOutputsForTargetAndConfiguration(
|
||||||
|
{
|
||||||
|
overrides: {},
|
||||||
|
target: {
|
||||||
|
project: 'myapp',
|
||||||
|
target: 'build',
|
||||||
|
configuration: 'production',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
name: 'myapp',
|
name: 'myapp',
|
||||||
type: 'application',
|
type: 'application',
|
||||||
data: {
|
data: {
|
||||||
@ -96,7 +176,8 @@ describe('utils', () => {
|
|||||||
},
|
},
|
||||||
files: [],
|
files: [],
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
).toEqual(['dist/root-myapp']);
|
).toEqual(['dist/root-myapp']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -45,18 +45,17 @@ export function getCommand(cliCommand: string, isYarn: boolean, task: Task) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getOutputs(p: Record<string, ProjectGraphNode>, task: Task) {
|
export function getOutputs(p: Record<string, ProjectGraphNode>, task: Task) {
|
||||||
return getOutputsForTargetAndConfiguration(
|
return getOutputsForTargetAndConfiguration(task, p[task.target.project]);
|
||||||
task.target.target,
|
|
||||||
task.target.configuration,
|
|
||||||
p[task.target.project]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getOutputsForTargetAndConfiguration(
|
export function getOutputsForTargetAndConfiguration(
|
||||||
target: string,
|
task: Pick<Task, 'target' | 'overrides'>,
|
||||||
configuration: string,
|
|
||||||
node: ProjectGraphNode
|
node: ProjectGraphNode
|
||||||
) {
|
) {
|
||||||
|
if (task.overrides?.outputPath) {
|
||||||
|
return [task.overrides?.outputPath];
|
||||||
|
}
|
||||||
|
const { target, configuration } = task.target;
|
||||||
const architect = node.data.architect[target];
|
const architect = node.data.architect[target];
|
||||||
if (architect && architect.outputs) return architect.outputs;
|
if (architect && architect.outputs) return architect.outputs;
|
||||||
|
|
||||||
|
|||||||
@ -53,8 +53,10 @@ export function calculateProjectDependencies(
|
|||||||
return {
|
return {
|
||||||
name: libPackageJson.name, // i.e. @workspace/mylib
|
name: libPackageJson.name, // i.e. @workspace/mylib
|
||||||
outputs: getOutputsForTargetAndConfiguration(
|
outputs: getOutputsForTargetAndConfiguration(
|
||||||
context.target.target,
|
{
|
||||||
context.target.configuration,
|
overrides: {},
|
||||||
|
target: context.target,
|
||||||
|
},
|
||||||
depNode
|
depNode
|
||||||
),
|
),
|
||||||
node: depNode,
|
node: depNode,
|
||||||
@ -234,8 +236,10 @@ export function updateBuildableProjectPackageJsonDependencies(
|
|||||||
dependencies: DependentBuildableProjectNode[]
|
dependencies: DependentBuildableProjectNode[]
|
||||||
) {
|
) {
|
||||||
const outputs = getOutputsForTargetAndConfiguration(
|
const outputs = getOutputsForTargetAndConfiguration(
|
||||||
context.target.target,
|
{
|
||||||
context.target.configuration,
|
overrides: {},
|
||||||
|
target: context.target,
|
||||||
|
},
|
||||||
node
|
node
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -268,8 +272,10 @@ export function updateBuildableProjectPackageJsonDependencies(
|
|||||||
let depVersion;
|
let depVersion;
|
||||||
if (entry.node.type === ProjectType.lib) {
|
if (entry.node.type === ProjectType.lib) {
|
||||||
const outputs = getOutputsForTargetAndConfiguration(
|
const outputs = getOutputsForTargetAndConfiguration(
|
||||||
context.target.target,
|
{
|
||||||
context.target.configuration,
|
overrides: {},
|
||||||
|
target: context.target,
|
||||||
|
},
|
||||||
entry.node
|
entry.node
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user