Skip to content

Commit

Permalink
fix(nx): project.targets.build.options could be undefined
Browse files Browse the repository at this point in the history
closes #26
  • Loading branch information
NexZhu authored and EladBezalel committed Dec 21, 2023
1 parent 8321276 commit acafda0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
34 changes: 34 additions & 0 deletions libs/nx/src/nx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions libs/nx/src/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit acafda0

Please sign in to comment.