Skip to content

Commit

Permalink
fix(core): respect extends when reading tsconfig options (#30062)
Browse files Browse the repository at this point in the history
Fix a bug introduced in #29774.

## Current Behavior

If a local plugin's `tsconfig.json` uses `extends`, the referenced base
config is not loaded.

## Expected Behavior

If a local plugin's `tsconfig.json` uses `extends`, the referenced base
config is loaded.

## Related Issue(s)

Fixes #30007

---------

Co-authored-by: Leosvel Pérez Espinosa <[email protected]>
  • Loading branch information
2 people authored and jaysoo committed Feb 18, 2025
1 parent ce23f14 commit eeae870
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
40 changes: 40 additions & 0 deletions packages/nx/src/plugins/js/utils/typescript.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { readTsConfigOptions } from './typescript';
import { join } from 'path';
import { TempFs } from '../../../internal-testing-utils/temp-fs';

describe('readTsConfigOptions', () => {
let fs: TempFs;
beforeEach(() => {
fs = new TempFs('Workspaces');
});
afterEach(() => {
fs.cleanup();
});

it('should handle extending local configs', async () => {
await fs.createFiles({
'a.json': JSON.stringify({ extends: './b.json' }),
'b.json': JSON.stringify({ compilerOptions: { strict: true } }),
});

expect(readTsConfigOptions(join(fs.tempDir, 'a.json'))).toEqual({
configFilePath: undefined,
strict: true,
});
});

it('should handle extending third-party configs', async () => {
await fs.createFiles({
'tsconfig.json': JSON.stringify({
extends: '@fake-third-party/some-package/tsconfig.json',
}),
'node_modules/@fake-third-party/some-package/tsconfig.json':
JSON.stringify({ compilerOptions: { strict: true } }),
});

expect(readTsConfigOptions(join(fs.tempDir, 'tsconfig.json'))).toEqual({
configFilePath: undefined,
strict: true,
});
});
});
10 changes: 5 additions & 5 deletions packages/nx/src/plugins/js/utils/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export function readTsConfigOptions(tsConfigPath: string) {
tsModule.sys.readFile
);

// we don't need to scan the files, we only care about options
const host: Partial<ts.ParseConfigHost> = {
// We only care about options, so we don't need to scan source files, and thus
// `readDirectory` is stubbed for performance.
const host = {
...tsModule.sys,
readDirectory: () => [],
readFile: () => '',
fileExists: tsModule.sys.fileExists,
};

return tsModule.parseJsonConfigFileContent(
readResult.config,
host as ts.ParseConfigHost,
host,
dirname(tsConfigPath)
).options;
}
Expand Down

0 comments on commit eeae870

Please sign in to comment.