fix(core): enable intelligent tsconfig changes in tsconfig.base.json (#3768)

This commit is contained in:
Jason Jean 2020-09-19 12:23:54 -04:00 committed by GitHub
parent 66038891ec
commit c2a1946fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 270 additions and 264 deletions

View File

@ -37,285 +37,290 @@ describe('getTouchedProjectsFromTsConfig', () => {
}, },
}; };
}); });
it('should not return changes when tsconfig.json is not touched', () => {
const result = getTouchedProjectsFromTsConfig(
[
{
file: 'source.ts',
ext: '.ts',
hash: 'some-hash',
getChanges: () => [new WholeFileChange()],
},
],
{},
{
npmScope: 'proj',
projects: {
proj1: {
tags: [],
},
},
}
);
expect(result).toEqual([]);
});
describe('Whole File Changes', () => { ['tsconfig.json', 'tsconfig.base.json'].forEach((tsConfig) => {
it('should return all projects for a whole file change', () => { describe(`(${tsConfig})`, () => {
const result = getTouchedProjectsFromTsConfig( it(`should not return changes when ${tsConfig} is not touched`, () => {
[ const result = getTouchedProjectsFromTsConfig(
[
{
file: 'source.ts',
ext: '.ts',
hash: 'some-hash',
getChanges: () => [new WholeFileChange()],
},
],
{},
{ {
file: 'tsconfig.json', npmScope: 'proj',
ext: '.json', projects: {
hash: 'some-hash', proj1: {
getChanges: () => [new WholeFileChange()], tags: [],
}, },
], },
null, }
null, );
null, expect(result).toEqual([]);
graph });
);
expect(result).toEqual(['proj1', 'proj2']);
});
});
describe('Changes to other compiler options', () => { describe('Whole File Changes', () => {
it('should return all projects', () => { it('should return all projects for a whole file change', () => {
const result = getTouchedProjectsFromTsConfig( const result = getTouchedProjectsFromTsConfig(
[ [
{ {
file: 'tsconfig.json', file: tsConfig,
ext: '.json', ext: '.json',
hash: 'some-hash', hash: 'some-hash',
getChanges: () => getChanges: () => [new WholeFileChange()],
jsonDiff( },
{ ],
compilerOptions: { null,
strict: false, null,
}, null,
}, graph
{ );
compilerOptions: { expect(result).toEqual(['proj1', 'proj2']);
strict: true, });
}, });
}
),
},
],
null,
null,
null,
graph
);
expect(result).toEqual(['proj1', 'proj2']);
});
});
describe('Adding new path mappings', () => { describe('Changes to other compiler options', () => {
it('should return projects pointed to by the path mappings', () => { it('should return all projects', () => {
const result = getTouchedProjectsFromTsConfig( const result = getTouchedProjectsFromTsConfig(
[ [
{ {
file: 'tsconfig.json', file: tsConfig,
ext: '.json', ext: '.json',
hash: 'some-hash', hash: 'some-hash',
getChanges: () => getChanges: () =>
jsonDiff( jsonDiff(
{ {
compilerOptions: { compilerOptions: {
paths: {}, strict: false,
}, },
},
{
compilerOptions: {
paths: {
'@proj/proj1': ['proj1/index.ts'],
}, },
}, {
} compilerOptions: {
), strict: true,
}, },
], }
null, ),
null, },
null, ],
graph null,
); null,
expect(result).toEqual(['proj1']); null,
}); graph
);
expect(result).toEqual(['proj1', 'proj2']);
});
});
it('should accept different types of paths', () => { describe('Adding new path mappings', () => {
const result = getTouchedProjectsFromTsConfig( it('should return projects pointed to by the path mappings', () => {
[ const result = getTouchedProjectsFromTsConfig(
{ [
file: 'tsconfig.json', {
ext: '.json', file: tsConfig,
hash: 'some-hash', ext: '.json',
getChanges: () => hash: 'some-hash',
jsonDiff( getChanges: () =>
{ jsonDiff(
compilerOptions: { {
paths: {}, compilerOptions: {
}, paths: {},
}, },
{
compilerOptions: {
paths: {
'@proj/proj1': ['./proj1/index.ts'],
}, },
}, {
} compilerOptions: {
), paths: {
}, '@proj/proj1': ['proj1/index.ts'],
], },
null, },
null, }
null, ),
graph },
); ],
expect(result).toEqual(['proj1']); null,
}); null,
}); null,
graph
);
expect(result).toEqual(['proj1']);
});
describe('Removing path mappings', () => { it('should accept different types of paths', () => {
it('should affect all projects if a project is removed', () => { const result = getTouchedProjectsFromTsConfig(
const result = getTouchedProjectsFromTsConfig( [
[ {
{ file: tsConfig,
file: 'tsconfig.json', ext: '.json',
ext: '.json', hash: 'some-hash',
hash: 'some-hash', getChanges: () =>
getChanges: () => jsonDiff(
jsonDiff( {
{ compilerOptions: {
compilerOptions: { paths: {},
paths: { },
'@proj/proj1': ['proj1/index.ts'],
}, },
}, {
}, compilerOptions: {
{ paths: {
compilerOptions: { '@proj/proj1': ['./proj1/index.ts'],
paths: {}, },
}, },
} }
), ),
}, },
], ],
null, null,
null, null,
null, null,
graph graph
); );
expect(result).toEqual(['proj1', 'proj2']); expect(result).toEqual(['proj1']);
}); });
});
it('should affect all projects if a path mapping is removed', () => { describe('Removing path mappings', () => {
const result = getTouchedProjectsFromTsConfig( it('should affect all projects if a project is removed', () => {
[ const result = getTouchedProjectsFromTsConfig(
{ [
file: 'tsconfig.json', {
ext: '.json', file: tsConfig,
hash: 'some-hash', ext: '.json',
getChanges: () => hash: 'some-hash',
jsonDiff( getChanges: () =>
{ jsonDiff(
compilerOptions: { {
paths: { compilerOptions: {
'@proj/proj1': ['proj1/index.ts', 'proj1/index2.ts'], paths: {
'@proj/proj1': ['proj1/index.ts'],
},
},
}, },
}, {
}, compilerOptions: {
{ paths: {},
compilerOptions: { },
paths: { }
'@proj/proj1': ['proj1/index.ts'], ),
}, },
}, ],
} null,
), null,
}, null,
], graph
null, );
null, expect(result).toEqual(['proj1', 'proj2']);
null, });
graph
);
expect(result).toContainEqual('proj1');
expect(result).toContainEqual('proj2');
});
});
describe('Modifying Path Mappings', () => { it('should affect all projects if a path mapping is removed', () => {
it('should return projects that have path mappings modified within them', () => { const result = getTouchedProjectsFromTsConfig(
const result = getTouchedProjectsFromTsConfig( [
[ {
{ file: tsConfig,
file: 'tsconfig.json', ext: '.json',
ext: '.json', hash: 'some-hash',
hash: 'some-hash', getChanges: () =>
getChanges: () => jsonDiff(
jsonDiff( {
{ compilerOptions: {
compilerOptions: { paths: {
paths: { '@proj/proj1': ['proj1/index.ts', 'proj1/index2.ts'],
'@proj/proj1': ['proj1/index.ts'], },
},
}, },
}, {
}, compilerOptions: {
{ paths: {
compilerOptions: { '@proj/proj1': ['proj1/index.ts'],
paths: { },
'@proj/proj1': ['proj1/index2.ts'], },
}, }
}, ),
} },
), ],
}, null,
], null,
null, null,
null, graph
null, );
graph expect(result).toContainEqual('proj1');
); expect(result).toContainEqual('proj2');
expect(result).toContainEqual('proj1'); });
expect(result).not.toContainEqual('proj2'); });
});
it('should return both projects that the mappings used to point to and point to now', () => { describe('Modifying Path Mappings', () => {
const result = getTouchedProjectsFromTsConfig( it('should return projects that have path mappings modified within them', () => {
[ const result = getTouchedProjectsFromTsConfig(
{ [
file: 'tsconfig.json', {
ext: '.json', file: tsConfig,
hash: 'some-hash', ext: '.json',
getChanges: () => hash: 'some-hash',
jsonDiff( getChanges: () =>
{ jsonDiff(
compilerOptions: { {
paths: { compilerOptions: {
'@proj/proj1': ['proj1/index.ts'], paths: {
'@proj/proj1': ['proj1/index.ts'],
},
},
}, },
}, {
}, compilerOptions: {
{ paths: {
compilerOptions: { '@proj/proj1': ['proj1/index2.ts'],
paths: { },
'@proj/proj1': ['proj2/index.ts'], },
}
),
},
],
null,
null,
null,
graph
);
expect(result).toContainEqual('proj1');
expect(result).not.toContainEqual('proj2');
});
it('should return both projects that the mappings used to point to and point to now', () => {
const result = getTouchedProjectsFromTsConfig(
[
{
file: tsConfig,
ext: '.json',
hash: 'some-hash',
getChanges: () =>
jsonDiff(
{
compilerOptions: {
paths: {
'@proj/proj1': ['proj1/index.ts'],
},
},
}, },
}, {
} compilerOptions: {
), paths: {
}, '@proj/proj1': ['proj2/index.ts'],
], },
null, },
null, }
null, ),
graph },
); ],
expect(result).toContainEqual('proj1'); null,
expect(result).toContainEqual('proj2'); null,
null,
graph
);
expect(result).toContainEqual('proj1');
expect(result).toContainEqual('proj2');
});
});
}); });
}); });
}); });

View File

@ -14,7 +14,8 @@ export const getTouchedProjectsFromTsConfig: TouchedProjectLocator<
WholeFileChange | JsonChange WholeFileChange | JsonChange
> = (touchedFiles, _a, _b, _c, graph): string[] => { > = (touchedFiles, _a, _b, _c, graph): string[] => {
const tsConfigJsonChanges = touchedFiles.find( const tsConfigJsonChanges = touchedFiles.find(
(change) => change.file === 'tsconfig.json' (change) =>
change.file === 'tsconfig.json' || change.file === 'tsconfig.base.json'
); );
if (!tsConfigJsonChanges) { if (!tsConfigJsonChanges) {
return []; return [];