Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add compilerOptions support #32

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 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,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']);
})
});
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
Loading