diff --git a/libs/core/src/true-affected.spec.ts b/libs/core/src/true-affected.spec.ts index a3110bb..25b8102 100644 --- a/libs/core/src/true-affected.spec.ts +++ b/libs/core/src/true-affected.spec.ts @@ -480,4 +480,52 @@ 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', + }, + ], + compilerOptions + }); + + expect(affected).toEqual(['proj1']); + }) }); diff --git a/libs/core/src/true-affected.ts b/libs/core/src/true-affected.ts index c17c907..316dc2c 100644 --- a/libs/core/src/true-affected.ts +++ b/libs/core/src/true-affected.ts @@ -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'); @@ -48,6 +49,7 @@ export const trueAffected = async ({ const project = new Project({ compilerOptions: { allowJs: true, + ...compilerOptions }, ...(rootTsConfig == null ? {} diff --git a/libs/core/src/types.ts b/libs/core/src/types.ts index 06787f0..9bf8944 100644 --- a/libs/core/src/types.ts +++ b/libs/core/src/types.ts @@ -1,3 +1,5 @@ +import { CompilerOptions } from 'ts-morph'; + export interface TrueAffectedProject { name: string; sourceRoot: string; @@ -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;