fix(core): consider overrides for output path (#3172)

This commit is contained in:
Jason Jean 2020-06-13 12:59:13 -04:00 committed by GitHub
parent 6636e53d64
commit 7301930d3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 159 additions and 73 deletions

View File

@ -7,7 +7,7 @@ import { NxJson } from '../core/shared-interfaces';
export interface Task {
id: string;
target: Target;
overrides: Object;
overrides: any;
hash?: string;
projectRoot?: string;
hashDetails?: {

View File

@ -4,99 +4,180 @@ describe('utils', () => {
describe('getOutputsForTargetAndConfiguration', () => {
it('should return outputs when defined', () => {
expect(
getOutputsForTargetAndConfiguration('build', 'production', {
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
outputs: ['one', 'two'],
},
getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: 'myapp',
target: 'build',
configuration: 'production',
},
files: [],
},
})
{
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
outputs: ['one', 'two'],
},
},
files: [],
},
}
)
).toEqual(['one', 'two']);
});
it('should return configuration-specific outputPath when defined', () => {
expect(
getOutputsForTargetAndConfiguration('build', 'production', {
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
options: {
outputPath: 'one',
},
configurations: {
production: {
outputPath: 'two',
getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: 'myapp',
target: 'build',
configuration: 'production',
},
},
{
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
options: {
outputPath: 'one',
},
configurations: {
production: {
outputPath: 'two',
},
},
},
},
files: [],
},
files: [],
},
})
}
)
).toEqual(['two']);
});
it('should return configuration-independent outputPath when defined', () => {
expect(
getOutputsForTargetAndConfiguration('build', 'production', {
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
options: {
outputPath: 'one',
},
configurations: {
production: {},
getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: 'myapp',
target: 'build',
configuration: 'production',
},
},
{
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
options: {
outputPath: 'one',
},
configurations: {
production: {},
},
},
},
files: [],
},
files: [],
},
})
}
)
).toEqual(['one']);
});
it('should handle invalid configuration', () => {
expect(
getOutputsForTargetAndConfiguration('build', 'production', {
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
options: {
outputPath: 'one',
getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: 'myapp',
target: 'build',
configuration: 'production',
},
},
{
name: 'myapp',
type: 'application',
data: {
architect: {
build: {
options: {
outputPath: 'one',
},
},
},
files: [],
},
files: [],
},
})
}
)
).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', () => {
expect(
getOutputsForTargetAndConfiguration('build', 'production', {
name: 'myapp',
type: 'application',
data: {
root: 'root-myapp',
architect: {
build: {},
getOutputsForTargetAndConfiguration(
{
overrides: {},
target: {
project: 'myapp',
target: 'build',
configuration: 'production',
},
files: [],
},
})
{
name: 'myapp',
type: 'application',
data: {
root: 'root-myapp',
architect: {
build: {},
},
files: [],
},
}
)
).toEqual(['dist/root-myapp']);
});
});

View File

@ -45,18 +45,17 @@ export function getCommand(cliCommand: string, isYarn: boolean, task: Task) {
}
export function getOutputs(p: Record<string, ProjectGraphNode>, task: Task) {
return getOutputsForTargetAndConfiguration(
task.target.target,
task.target.configuration,
p[task.target.project]
);
return getOutputsForTargetAndConfiguration(task, p[task.target.project]);
}
export function getOutputsForTargetAndConfiguration(
target: string,
configuration: string,
task: Pick<Task, 'target' | 'overrides'>,
node: ProjectGraphNode
) {
if (task.overrides?.outputPath) {
return [task.overrides?.outputPath];
}
const { target, configuration } = task.target;
const architect = node.data.architect[target];
if (architect && architect.outputs) return architect.outputs;

View File

@ -53,8 +53,10 @@ export function calculateProjectDependencies(
return {
name: libPackageJson.name, // i.e. @workspace/mylib
outputs: getOutputsForTargetAndConfiguration(
context.target.target,
context.target.configuration,
{
overrides: {},
target: context.target,
},
depNode
),
node: depNode,
@ -234,8 +236,10 @@ export function updateBuildableProjectPackageJsonDependencies(
dependencies: DependentBuildableProjectNode[]
) {
const outputs = getOutputsForTargetAndConfiguration(
context.target.target,
context.target.configuration,
{
overrides: {},
target: context.target,
},
node
);
@ -268,8 +272,10 @@ export function updateBuildableProjectPackageJsonDependencies(
let depVersion;
if (entry.node.type === ProjectType.lib) {
const outputs = getOutputsForTargetAndConfiguration(
context.target.target,
context.target.configuration,
{
overrides: {},
target: context.target,
},
entry.node
);