Skip to content

Commit ba19700

Browse files
authored
fix: error when include does not contain *.tsx (#6)
* fix: error when `include` does not contain `*.tsx` * Create tough-planes-build.md
1 parent 6933107 commit ba19700

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

Diff for: .changeset/tough-planes-build.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"typescript-eslint-parser-for-extra-files": patch
3+
---
4+
5+
fix: error when `include` does not contain `*.tsx`

Diff for: src/ts.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export class TSService {
8484
tsconfigPath: string,
8585
extraFileExtensions: string[]
8686
): ts.WatchOfConfigFile<ts.BuilderProgram> {
87-
const normalizedTsconfigPath = normalizeFileName(tsconfigPath);
87+
const normalizedTsconfigPaths = new Set([
88+
normalizeFileName(toAbsolutePath(tsconfigPath)),
89+
]);
8890
const watchCompilerHost = ts.createWatchCompilerHost(
8991
tsconfigPath,
9092
{
@@ -149,18 +151,28 @@ export class TSService {
149151
if (!code) {
150152
return code;
151153
}
152-
if (normalizedTsconfigPath === normalized) {
154+
if (normalizedTsconfigPaths.has(normalized)) {
153155
const configJson = ts.parseConfigFileTextToJson(realFileName, code);
154156
if (!configJson.config) {
155157
return code;
156158
}
157-
let include = undefined;
159+
if (configJson.config.extends) {
160+
for (const extendConfigPath of [configJson.config.extends].flat()) {
161+
normalizedTsconfigPaths.add(
162+
normalizeFileName(
163+
toAbsolutePath(extendConfigPath, path.dirname(normalized))
164+
)
165+
);
166+
}
167+
}
158168

159-
if (configJson.config.include) {
160-
include = [configJson.config.include]
161-
.flat()
162-
.map((s) => toVirtualTSXlFileName(s, extraFileExtensions));
169+
if (!configJson.config.include) {
170+
return code;
163171
}
172+
const include = [configJson.config.include]
173+
.flat()
174+
.map((s) => toVirtualTSXlFileName(s, extraFileExtensions));
175+
164176
return JSON.stringify({
165177
...configJson.config,
166178
include,
@@ -274,8 +286,8 @@ function normalizeFileName(fileName: string) {
274286
return normalized.toLowerCase();
275287
}
276288

277-
function toAbsolutePath(filePath: string) {
289+
function toAbsolutePath(filePath: string, baseDir?: string) {
278290
return path.isAbsolute(filePath)
279291
? filePath
280-
: path.join(process.cwd(), filePath);
292+
: path.join(baseDir || process.cwd(), filePath);
281293
}

0 commit comments

Comments
 (0)