Skip to content

Commit e298e77

Browse files
committed
fix: remove allowImportingTsExtensions support
Does not play well during a nested lookup when we're looking up a path that we've already resolved to a candidate with a .ts extension earlier in the process. Not a super useful feature anyway.
1 parent 1c92274 commit e298e77

File tree

4 files changed

+11
-41
lines changed

4 files changed

+11
-41
lines changed

packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ describe('dependency-parser - parser()', () => {
174174
const parser = new Parser({
175175
supportedNpmModules: defaultNpmModules,
176176
})
177+
expect.assertions(1)
177178
try {
178179
// eslint-disable-next-line @typescript-eslint/no-unused-vars
179180
const { dependencies } = parser.parse(toAbsolutePath('entrypoint.js'))

packages/cli/src/services/check-parser/package-files/lookup.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,18 @@ import { CoreExtension, FileExtPath, tsCoreExtensionLookupOrder, TSExtension, ts
33

44
type Options = {
55
plainJs?: boolean
6-
allowImportingTsExtensions?: boolean
76
}
87

98
export class LookupContext {
109
#plainJs: boolean
11-
#allowImportingTsExtensions: boolean
1210

1311
constructor (options: Options) {
1412
this.#plainJs = options.plainJs ?? false
15-
this.#allowImportingTsExtensions = options.allowImportingTsExtensions ?? false
1613
}
1714

18-
static forFilePath (filePath: string, options?: Options) {
15+
static forFilePath (filePath: string) {
1916
return new LookupContext({
2017
plainJs: FileExtPath.fromFilePath(filePath).hasCoreExtension(),
21-
allowImportingTsExtensions: options?.allowImportingTsExtensions,
22-
})
23-
}
24-
25-
switch (options: Options) {
26-
return new LookupContext({
27-
plainJs: options.plainJs ?? this.#plainJs,
28-
allowImportingTsExtensions: options.allowImportingTsExtensions ?? this.#allowImportingTsExtensions,
2918
})
3019
}
3120

@@ -45,11 +34,9 @@ export class LookupContext {
4534
return extensions.map(ext => extPath.replaceExt(ext))
4635
}
4736

48-
if (this.#allowImportingTsExtensions) {
49-
if (extPath.hasTypeScriptExtension()) {
50-
const extensions = tsExtensionLookupOrder[extPath.ext as TSExtension]
51-
return extensions.map(ext => extPath.replaceExt(ext))
52-
}
37+
if (extPath.hasTypeScriptExtension()) {
38+
const extensions = tsExtensionLookupOrder[extPath.ext as TSExtension]
39+
return extensions.map(ext => extPath.replaceExt(ext))
5340
}
5441

5542
return this.extlessTSLookupPaths(extPath)

packages/cli/src/services/check-parser/package-files/resolver.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ export class PackageFilesResolver {
204204
return context.collectLookupPaths(filePath)
205205
})
206206
for (const candidatePath of candidatePaths) {
207-
const mainSourceFile = this.cache.sourceFile(candidatePath, context.switch({
208-
allowImportingTsExtensions: configJson.allowImportingTsExtensions,
209-
}))
207+
const mainSourceFile = this.cache.sourceFile(candidatePath, context)
210208
if (mainSourceFile === undefined) {
211209
continue
212210
}
@@ -245,11 +243,8 @@ export class PackageFilesResolver {
245243
const dirname = path.dirname(filePath)
246244

247245
const { tsconfigJson, jsconfigJson } = this.loadPackageFiles(filePath)
248-
const mainConfigJson = tsconfigJson ?? jsconfigJson
249246

250-
const context = LookupContext.forFilePath(filePath, {
251-
allowImportingTsExtensions: mainConfigJson?.allowImportingTsExtensions,
252-
})
247+
const context = LookupContext.forFilePath(filePath)
253248

254249
resolve:
255250
for (const importPath of dependencies) {
@@ -283,18 +278,14 @@ export class PackageFilesResolver {
283278
continue
284279
}
285280

286-
const configContext = context.switch({
287-
allowImportingTsExtensions: configJson.allowImportingTsExtensions,
288-
})
289-
290281
const resolvedPaths = configJson.resolvePath(importPath)
291282
if (resolvedPaths.length > 0) {
292283
let found = false
293284
for (const { source, target } of resolvedPaths) {
294285
const relativePath = path.resolve(configJson.basePath, target.path)
295-
const sourceFile = this.cache.sourceFile(relativePath, configContext)
286+
const sourceFile = this.cache.sourceFile(relativePath, context)
296287
if (sourceFile !== undefined) {
297-
const resolvedFiles = this.resolveSourceFile(sourceFile, configContext)
288+
const resolvedFiles = this.resolveSourceFile(sourceFile, context)
298289
for (const resolvedFile of resolvedFiles) {
299290
configJson.registerRelatedSourceFile(resolvedFile)
300291
resolved.local.push({
@@ -329,9 +320,9 @@ export class PackageFilesResolver {
329320

330321
if (configJson.baseUrl !== undefined) {
331322
const relativePath = path.resolve(configJson.basePath, configJson.baseUrl, importPath)
332-
const sourceFile = this.cache.sourceFile(relativePath, configContext)
323+
const sourceFile = this.cache.sourceFile(relativePath, context)
333324
if (sourceFile !== undefined) {
334-
const resolvedFiles = this.resolveSourceFile(sourceFile, configContext)
325+
const resolvedFiles = this.resolveSourceFile(sourceFile, context)
335326
let found = false
336327
for (const resolvedFile of resolvedFiles) {
337328
configJson.registerRelatedSourceFile(resolvedFile)

packages/cli/src/services/check-parser/package-files/tsconfig-json-file.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ interface CompilerOptions {
5454
* @see https://www.typescriptlang.org/tsconfig/#composite
5555
*/
5656
composite?: boolean
57-
58-
/**
59-
* If true, TypeScript-specific extensions can be imported. Requires
60-
* either `noEmit: true` or `emitDeclarationOnly: true`.
61-
*/
62-
allowImportingTsExtensions?: boolean
6357
}
6458

6559
export interface Schema {
@@ -77,7 +71,6 @@ export class TSConfigFile {
7771
moduleResolution: string
7872
baseUrl?: string
7973
pathResolver: PathResolver
80-
allowImportingTsExtensions: boolean
8174

8275
relatedSourceFiles: SourceFile[] = []
8376

@@ -94,8 +87,6 @@ export class TSConfigFile {
9487
}
9588

9689
this.pathResolver = PathResolver.createFromPaths(this.baseUrl ?? '.', jsonFile.data.compilerOptions?.paths ?? {})
97-
98-
this.allowImportingTsExtensions = jsonFile.data.compilerOptions?.allowImportingTsExtensions ?? false
9990
}
10091

10192
public get meta () {

0 commit comments

Comments
 (0)