From efe8bb5619c6fae62f2728aa7c4e19374be6142d Mon Sep 17 00:00:00 2001 From: Itay Perach Date: Tue, 20 Aug 2024 12:53:33 +0300 Subject: [PATCH 1/2] feat(core): add compilerOptions support --- libs/core/src/true-affected.spec.ts | 49 +++++++++++++++++++++++++++++ libs/core/src/true-affected.ts | 2 ++ libs/core/src/types.ts | 3 ++ 3 files changed, 54 insertions(+) diff --git a/libs/core/src/true-affected.spec.ts b/libs/core/src/true-affected.spec.ts index a3110bb..0a361d2 100644 --- a/libs/core/src/true-affected.spec.ts +++ b/libs/core/src/true-affected.spec.ts @@ -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']); + }) }); 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; From 0898e4221d520bf1ca48fbfd3910099edf9e15c0 Mon Sep 17 00:00:00 2001 From: Itay Perach Date: Tue, 20 Aug 2024 13:01:28 +0300 Subject: [PATCH 2/2] fix test remove redundant include filePatterns --- libs/core/src/true-affected.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/core/src/true-affected.spec.ts b/libs/core/src/true-affected.spec.ts index 0a361d2..25b8102 100644 --- a/libs/core/src/true-affected.spec.ts +++ b/libs/core/src/true-affected.spec.ts @@ -523,7 +523,6 @@ describe('trueAffected', () => { tsConfig: 'proj3/tsconfig.json', }, ], - include: filePatterns, compilerOptions });