diff --git a/libs/nx/src/nx.spec.ts b/libs/nx/src/nx.spec.ts index e4b5475..554694b 100644 --- a/libs/nx/src/nx.spec.ts +++ b/libs/nx/src/nx.spec.ts @@ -235,6 +235,40 @@ describe('nx', () => { ]) ); }); + + it('should work even if nx build config has no options', async () => { + jest.spyOn(fs.promises, 'readFile').mockImplementation((pathLike) => { + const path = pathLike.toString(); + + if (path.endsWith('proj1/project.json')) { + return Promise.resolve( + JSON.stringify({ + name: 'proj1', + sourceRoot: 'proj1/src', + targets: { + build: { + options: {}, + }, + }, + }) + ); + } + + return Promise.reject('File not found'); + }); + + const cwd = 'libs/nx/src/__fixtures__/nx-project'; + const projects = await getNxTrueAffectedProjects(cwd); + + expect(projects).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + name: 'proj1', + tsConfig: expect.stringContaining('proj1/tsconfig.json'), + }), + ]) + ); + }); }); describe('fallback tsconfig is found', () => { diff --git a/libs/nx/src/nx.ts b/libs/nx/src/nx.ts index d1f2cdf..ff2b6ae 100644 --- a/libs/nx/src/nx.ts +++ b/libs/nx/src/nx.ts @@ -103,9 +103,9 @@ export async function getNxTrueAffectedProjects( const projects = await getNxProjects(cwd); return projects.map(({ name, project }) => { - let tsConfig = project.targets?.build?.options.tsConfig; + let tsConfig = project.targets?.build?.options?.tsConfig; - if (tsConfig == null) { + if (!tsConfig) { const projectRoot = join(project.sourceRoot, '..'); if (project.projectType === 'library') {