Skip to content

Commit

Permalink
feat(core): add compilerOptions support
Browse files Browse the repository at this point in the history
  • Loading branch information
itayper authored Aug 20, 2024
1 parent 4e75577 commit efe8bb5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
49 changes: 49 additions & 0 deletions libs/core/src/true-affected.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,53 @@ describe('trueAffected', () => {
'Added package proj2 to affected packages'
);
});

it('should support compilerOptions', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
filePath: 'proj1/index.ts',
changedLines: [4],
},
]);

const compilerOptions = {
paths: {
"@monorepo/proj1": [
"./proj1/index.ts"
],
"@monorepo/proj2": [
"./proj2/index.ts"
],
"@monorepo/proj3": [
"./proj3/index.ts"
],
}
}

const affected = await trueAffected({
cwd,
base: 'main',
projects: [
{
name: 'proj1',
sourceRoot: 'proj1/',
tsConfig: 'proj1/tsconfig.json',
},
{
name: 'proj2',
sourceRoot: 'proj2/',
tsConfig: 'proj2/tsconfig.json',
},
{
name: 'proj3',
sourceRoot: 'proj3/',
tsConfig: 'proj3/tsconfig.json',
},
],
include: filePatterns,
compilerOptions
});

expect(affected).toEqual(['proj1']);
})
});
2 changes: 2 additions & 0 deletions libs/core/src/true-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const trueAffected = async ({
projects,
include = [DEFAULT_INCLUDE_TEST_FILES],
logger = DEFAULT_LOGGER,
compilerOptions = {},
__experimentalLockfileCheck = false,
}: TrueAffected) => {
logger.debug('Getting affected projects');
Expand All @@ -48,6 +49,7 @@ export const trueAffected = async ({
const project = new Project({
compilerOptions: {
allowJs: true,
...compilerOptions
},
...(rootTsConfig == null
? {}
Expand Down
3 changes: 3 additions & 0 deletions libs/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CompilerOptions } from 'ts-morph';

export interface TrueAffectedProject {
name: string;
sourceRoot: string;
Expand All @@ -16,6 +18,7 @@ export interface TrueAffected extends TrueAffectedLogging {
base?: string;
projects: TrueAffectedProject[];
include?: (string | RegExp)[];
compilerOptions?: CompilerOptions;

// **experimental** - this is an experimental feature and may be removed or changed at any time
__experimentalLockfileCheck?: boolean;
Expand Down

0 comments on commit efe8bb5

Please sign in to comment.