Skip to content

Commit fe26ae5

Browse files
committed
refactor(plugin-typescript): filter tsconfigs by content
1 parent 28d9038 commit fe26ae5

6 files changed

Lines changed: 21 additions & 21 deletions

File tree

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"include": ["src/**/*.ts"]
3+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"include": ["src/**/*.ts"]
3+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"include": ["src/**/*.ts"]
3+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"include": ["src/**/*.ts"]
3+
}

packages/plugin-typescript/src/lib/nx/tsconfig-paths.int.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ describe.skipIf(process.platform === 'win32')('Nx helpers', () => {
3737
});
3838

3939
describe('tsconfigFromAllNxProjects', () => {
40-
it('should find tsconfig files, filtering out empty configs and tsconfig.base.json', async () => {
41-
// cli project has tsconfig.json (empty arrays, filtered), tsconfig.base.json (excluded), tsconfig.lib.json (included)
42-
// other projects only have tsconfig.lib.json
40+
it('should find tsconfig files with explicit include or files values', async () => {
41+
// cli project has tsconfig.json (empty arrays), tsconfig.base.json (no include/files), tsconfig.lib.json (has include)
42+
// other projects only have tsconfig.lib.json (has include)
4343
await expect(tsconfigFromAllNxProjects()).resolves.toEqual([
4444
'packages/cli/tsconfig.lib.json',
4545
'packages/core/tsconfig.lib.json',

packages/plugin-typescript/src/lib/nx/tsconfig-paths.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,22 @@ import {
1010
import { formatMetaLog } from '../format.js';
1111

1212
const TSCONFIG_PATTERN = /^tsconfig(\..+)?\.json$/;
13-
const EXCLUDED_TSCONFIGS = new Set(['tsconfig.base.json', 'tsconfig.json']);
1413

1514
/**
16-
* Matches tsconfig.*.json files, excludes tsconfig.json and tsconfig.base.json.
17-
*/
18-
function isTsconfigFile(filename: string): boolean {
19-
return TSCONFIG_PATTERN.test(filename) && !EXCLUDED_TSCONFIGS.has(filename);
20-
}
21-
22-
/**
23-
* Returns false for empty configs (files and include both empty arrays).
15+
* Returns true only if config explicitly defines files or include with values.
2416
*/
2517
function hasFilesToCompile(tsconfigPath: string): boolean {
2618
const { config } = readConfigFile(tsconfigPath, sys.readFile);
2719

2820
if (!config) {
29-
return true;
21+
return false;
3022
}
3123

3224
const { files, include } = config;
33-
const filesEmpty = Array.isArray(files) && files.length === 0;
34-
const includeEmpty = Array.isArray(include) && include.length === 0;
25+
const hasFiles = Array.isArray(files) && files.length > 0;
26+
const hasInclude = Array.isArray(include) && include.length > 0;
3527

36-
return !(filesEmpty && includeEmpty);
28+
return hasFiles || hasInclude;
3729
}
3830

3931
function isProjectIncluded(
@@ -51,7 +43,7 @@ async function findTsconfigsInProject(projectRoot: string): Promise<string[]> {
5143
const files = await readdir(absoluteRoot);
5244

5345
return files
54-
.filter(isTsconfigFile)
46+
.filter(file => TSCONFIG_PATTERN.test(file))
5547
.filter(file => hasFilesToCompile(path.join(absoluteRoot, file)))
5648
.map(file => path.join(projectRoot, file));
5749
}

0 commit comments

Comments
 (0)