diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep1.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep1.js new file mode 100644 index 00000000..d99d91de --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep1.js @@ -0,0 +1 @@ +export const value = 'hello' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep2.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep2.js new file mode 100644 index 00000000..51a1e4c5 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep2.js @@ -0,0 +1 @@ +export const value = 'world' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep3.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep3.ts new file mode 100644 index 00000000..e2befb13 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/dep3.ts @@ -0,0 +1 @@ +export const value = 3 diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/entrypoint.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/entrypoint.ts new file mode 100644 index 00000000..f80d396f --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/import-js-from-ts/entrypoint.ts @@ -0,0 +1,3 @@ +import { } from './dep1' +import { } from './dep2.js' +import { } from './dep3.js' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep1.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep1.ts new file mode 100644 index 00000000..d99d91de --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep1.ts @@ -0,0 +1 @@ +export const value = 'hello' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep2.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep2.js new file mode 100644 index 00000000..51a1e4c5 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/dep2.js @@ -0,0 +1 @@ +export const value = 'world' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/entrypoint.js b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/entrypoint.js new file mode 100644 index 00000000..7bee0690 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/no-import-ts-from-js/entrypoint.js @@ -0,0 +1,4 @@ +import { } from './dep1' +import { } from './dep1.ts' +import { } from './dep1.js' +import { } from './dep2' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep1.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep1.ts new file mode 100644 index 00000000..062a3151 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep1.ts @@ -0,0 +1 @@ +export const value1 = 'value1' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep2.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep2.ts new file mode 100644 index 00000000..2407fa53 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep2.ts @@ -0,0 +1 @@ +export const value2 = 'value2' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep3.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep3.ts new file mode 100644 index 00000000..28b05968 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/dep3.ts @@ -0,0 +1 @@ +export const value3 = 'value3' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/entrypoint.ts b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/entrypoint.ts new file mode 100644 index 00000000..5ab303a3 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/src/entrypoint.ts @@ -0,0 +1,3 @@ +export { value1 } from './dep1.ts' +export { value2 } from './dep2.js' +export { value3 } from './dep3' diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/tsconfig.json b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/tsconfig.json new file mode 100644 index 00000000..ba221115 --- /dev/null +++ b/packages/cli/src/services/check-parser/__tests__/check-parser-fixtures/tsconfig-allow-importing-ts-extensions/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "nodenext", + "esModuleInterop": true, + "baseUrl": ".", + "noEmit": true, + "allowImportingTsExtensions": true + } +} diff --git a/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts b/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts index 098894aa..65c0ec4c 100644 --- a/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts +++ b/packages/cli/src/services/check-parser/__tests__/check-parser.spec.ts @@ -156,6 +156,51 @@ describe('dependency-parser - parser()', () => { expect(dependencies.map(d => d.filePath).sort()).toEqual([]) }) + it('should support importing ts extensions if allowed', () => { + const toAbsolutePath = (...filepath: string[]) => path.join(__dirname, 'check-parser-fixtures', 'tsconfig-allow-importing-ts-extensions', ...filepath) + const parser = new Parser({ + supportedNpmModules: defaultNpmModules, + }) + const { dependencies } = parser.parse(toAbsolutePath('src', 'entrypoint.ts')) + expect(dependencies.map(d => d.filePath).sort()).toEqual([ + toAbsolutePath('src', 'dep1.ts'), + toAbsolutePath('src', 'dep2.ts'), + toAbsolutePath('src', 'dep3.ts'), + ]) + }) + + it('should not import TS files from a JS file', () => { + const toAbsolutePath = (...filepath: string[]) => path.join(__dirname, 'check-parser-fixtures', 'no-import-ts-from-js', ...filepath) + const parser = new Parser({ + supportedNpmModules: defaultNpmModules, + }) + try { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { dependencies } = parser.parse(toAbsolutePath('entrypoint.js')) + } catch (err) { + expect(err).toMatchObject({ + missingFiles: [ + toAbsolutePath('dep1'), + toAbsolutePath('dep1.ts'), + toAbsolutePath('dep1.js'), + ], + }) + } + }) + + it('should import JS files from a TS file', () => { + const toAbsolutePath = (...filepath: string[]) => path.join(__dirname, 'check-parser-fixtures', 'import-js-from-ts', ...filepath) + const parser = new Parser({ + supportedNpmModules: defaultNpmModules, + }) + const { dependencies } = parser.parse(toAbsolutePath('entrypoint.ts')) + expect(dependencies.map(d => d.filePath).sort()).toEqual([ + toAbsolutePath('dep1.js'), + toAbsolutePath('dep2.js'), + toAbsolutePath('dep3.ts'), + ]) + }) + it('should handle ES Modules', () => { const toAbsolutePath = (...filepath: string[]) => path.join(__dirname, 'check-parser-fixtures', 'esmodules-example', ...filepath) const parser = new Parser({ diff --git a/packages/cli/src/services/check-parser/package-files/extension.ts b/packages/cli/src/services/check-parser/package-files/extension.ts new file mode 100644 index 00000000..d1510f5e --- /dev/null +++ b/packages/cli/src/services/check-parser/package-files/extension.ts @@ -0,0 +1,76 @@ +import path from 'node:path' + +export type CoreExtension = '.js' | '.mjs' | '.cjs' | '.json' + +export const CoreExtensions: CoreExtension[] = ['.js', '.mjs', '.cjs', '.json'] + +type CoreExtensionMapping = { + [key in CoreExtension]: string[] +} + +/** + * @see https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution + */ +export const tsCoreExtensionLookupOrder: CoreExtensionMapping = { + '.js': ['.ts', '.tsx', '.js', '.jsx'], + '.mjs': ['.mts', '.mjs'], + '.cjs': ['.cts', '.cjs'], + '.json': ['.json'], +} + +export type TSExtension = '.ts' | '.mts' | '.tsx' + +export const TSExtensions: TSExtension[] = ['.ts', '.mts', '.tsx'] + +type TSExtensionMapping = { + [key in TSExtension]: string[] +} + +export const tsExtensionLookupOrder: TSExtensionMapping = { + '.ts': ['.ts'], + '.mts': ['.mts'], + '.tsx': ['.tsx'], +} + +function stripKnownSuffix (value: string, suffix: string): string { + return value.substring(0, value.length - suffix.length) +} + +export class FileExtPath { + filePath: string + ext: string + + private constructor (filePath: string, ext: string) { + this.filePath = filePath + this.ext = ext + } + + static fromFilePath (filePath: string) { + const ext = path.extname(filePath) + return new FileExtPath(filePath, ext) + } + + hasCoreExtension () { + return this.ext in tsCoreExtensionLookupOrder + } + + hasTypeScriptExtension () { + return this.ext in tsExtensionLookupOrder + } + + replaceExt (ext: string) { + return stripKnownSuffix(this.filePath, this.ext) + ext + } + + appendExt (ext: string) { + return this.filePath + ext + } + + resolve (...paths: string[]) { + return path.resolve(this.filePath, ...paths) + } + + self () { + return this.filePath + } +} diff --git a/packages/cli/src/services/check-parser/package-files/lookup.ts b/packages/cli/src/services/check-parser/package-files/lookup.ts new file mode 100644 index 00000000..64a4d8dd --- /dev/null +++ b/packages/cli/src/services/check-parser/package-files/lookup.ts @@ -0,0 +1,78 @@ +import { PackageJsonFile } from './package-json-file' +import { CoreExtension, FileExtPath, tsCoreExtensionLookupOrder, TSExtension, tsExtensionLookupOrder } from './extension' + +type Options = { + plainJs?: boolean + allowImportingTsExtensions?: boolean +} + +export class LookupContext { + #plainJs: boolean + #allowImportingTsExtensions: boolean + + constructor (options: Options) { + this.#plainJs = options.plainJs ?? false + this.#allowImportingTsExtensions = options.allowImportingTsExtensions ?? false + } + + static forFilePath (filePath: string, options?: Options) { + return new LookupContext({ + plainJs: FileExtPath.fromFilePath(filePath).hasCoreExtension(), + allowImportingTsExtensions: options?.allowImportingTsExtensions, + }) + } + + switch (options: Options) { + return new LookupContext({ + plainJs: options.plainJs ?? this.#plainJs, + allowImportingTsExtensions: options.allowImportingTsExtensions ?? this.#allowImportingTsExtensions, + }) + } + + collectLookupPaths (filePath: string): string[] { + const extPath = FileExtPath.fromFilePath(filePath) + + if (this.#plainJs) { + if (extPath.hasCoreExtension()) { + return [extPath.self()] + } + + return this.extlessCoreLookupPaths(extPath) + } + + if (extPath.hasCoreExtension()) { + const extensions = tsCoreExtensionLookupOrder[extPath.ext as CoreExtension] + return extensions.map(ext => extPath.replaceExt(ext)) + } + + if (this.#allowImportingTsExtensions) { + if (extPath.hasTypeScriptExtension()) { + const extensions = tsExtensionLookupOrder[extPath.ext as TSExtension] + return extensions.map(ext => extPath.replaceExt(ext)) + } + } + + return this.extlessTSLookupPaths(extPath) + } + + private extlessCoreLookupPaths (extPath: FileExtPath): string[] { + return [ + extPath.appendExt('.js'), + extPath.appendExt('.mjs'), + extPath.appendExt('.cjs'), + extPath.appendExt('.json'), + extPath.resolve(PackageJsonFile.FILENAME), + extPath.resolve('index.js'), + extPath.resolve('index.mjs'), + extPath.resolve('index.cjs'), + ] + } + + private extlessTSLookupPaths (extPath: FileExtPath): string[] { + return this.extlessCoreLookupPaths(extPath).flatMap(filePath => { + const extPath = FileExtPath.fromFilePath(filePath) + const extensions = tsCoreExtensionLookupOrder[extPath.ext as CoreExtension] + return extensions.map(ext => extPath.replaceExt(ext)) + }) + } +} diff --git a/packages/cli/src/services/check-parser/package-files/resolver.ts b/packages/cli/src/services/check-parser/package-files/resolver.ts index 418a7d39..891c0e70 100644 --- a/packages/cli/src/services/check-parser/package-files/resolver.ts +++ b/packages/cli/src/services/check-parser/package-files/resolver.ts @@ -9,6 +9,7 @@ import { JSConfigFile } from './jsconfig-json-file' import { isLocalPath, PathResult } from './paths' import { FileLoader, LoadFile } from './loader' import { JsonSourceFile } from './json-source-file' +import { LookupContext } from './lookup' class PackageFilesCache { #sourceFileCache = new FileLoader(SourceFile.loadFromFilePath) @@ -33,11 +34,9 @@ class PackageFilesCache { #tsconfigJsonCache = new FileLoader(this.#jsonFileLoader(TSConfigFile.loadFromJsonSourceFile)) #jsconfigJsonCache = new FileLoader(this.#jsonFileLoader(JSConfigFile.loadFromJsonSourceFile)) - sourceFile (filePath: string, suffixes?: string[]) { - for (const suffix of ['', ...suffixes ?? []]) { - const suffixFilePath = filePath + suffix - - const sourceFile = this.#sourceFileCache.load(suffixFilePath) + sourceFile (filePath: string, context: LookupContext) { + for (const lookupPath of context.collectLookupPaths(filePath)) { + const sourceFile = this.#sourceFileCache.load(lookupPath) if (sourceFile === undefined) { continue } @@ -185,7 +184,7 @@ export class PackageFilesResolver { return files } - private resolveSourceFile (sourceFile: SourceFile): SourceFile[] { + private resolveSourceFile (sourceFile: SourceFile, context: LookupContext): SourceFile[] { if (sourceFile.meta.basename === PackageJsonFile.FILENAME) { const packageJson = this.cache.packageJson(sourceFile.meta.filePath) if (packageJson === undefined) { @@ -208,9 +207,13 @@ export class PackageFilesResolver { continue } - const candidatePaths = configJson.collectLookupPaths(mainPath) + const candidatePaths = configJson.collectLookupPaths(mainPath).flatMap(filePath => { + return context.collectLookupPaths(filePath) + }) for (const candidatePath of candidatePaths) { - const mainSourceFile = this.cache.sourceFile(candidatePath) + const mainSourceFile = this.cache.sourceFile(candidatePath, context.switch({ + allowImportingTsExtensions: configJson.allowImportingTsExtensions, + })) if (mainSourceFile === undefined) { continue } @@ -221,7 +224,7 @@ export class PackageFilesResolver { } } - const mainSourceFile = this.cache.sourceFile(mainPath) + const mainSourceFile = this.cache.sourceFile(mainPath, context) if (mainSourceFile === undefined) { continue } @@ -239,7 +242,6 @@ export class PackageFilesResolver { resolveDependenciesForFilePath ( filePath: string, dependencies: string[], - suffixes: string[], ): Dependencies { const resolved: Dependencies = { external: [], @@ -250,14 +252,19 @@ export class PackageFilesResolver { const dirname = path.dirname(filePath) const { packageJson, tsconfigJson, jsconfigJson } = this.loadPackageFiles(filePath) + const mainConfigJson = tsconfigJson ?? jsconfigJson + + const context = LookupContext.forFilePath(filePath, { + allowImportingTsExtensions: mainConfigJson?.allowImportingTsExtensions, + }) resolve: for (const importPath of dependencies) { if (isLocalPath(importPath)) { const relativeDepPath = path.resolve(dirname, importPath) - const sourceFile = this.cache.sourceFile(relativeDepPath, suffixes) + const sourceFile = this.cache.sourceFile(relativeDepPath, context) if (sourceFile !== undefined) { - const resolvedFiles = this.resolveSourceFile(sourceFile) + const resolvedFiles = this.resolveSourceFile(sourceFile, context) let found = false for (const resolvedFile of resolvedFiles) { resolved.local.push({ @@ -278,20 +285,23 @@ export class PackageFilesResolver { continue resolve } - // TODO: Prefer jsconfig.json when dealing with a JavaScript file. for (const configJson of [tsconfigJson, jsconfigJson]) { if (configJson === undefined) { continue } + const configContext = context.switch({ + allowImportingTsExtensions: configJson.allowImportingTsExtensions, + }) + const resolvedPaths = configJson.resolvePath(importPath) if (resolvedPaths.length > 0) { let found = false for (const { source, target } of resolvedPaths) { const relativePath = path.resolve(configJson.basePath, target.path) - const sourceFile = this.cache.sourceFile(relativePath, suffixes) + const sourceFile = this.cache.sourceFile(relativePath, configContext) if (sourceFile !== undefined) { - const resolvedFiles = this.resolveSourceFile(sourceFile) + const resolvedFiles = this.resolveSourceFile(sourceFile, configContext) for (const resolvedFile of resolvedFiles) { configJson.registerRelatedSourceFile(resolvedFile) resolved.local.push({ @@ -326,9 +336,9 @@ export class PackageFilesResolver { if (configJson.baseUrl !== undefined) { const relativePath = path.resolve(configJson.basePath, configJson.baseUrl, importPath) - const sourceFile = this.cache.sourceFile(relativePath, suffixes) + const sourceFile = this.cache.sourceFile(relativePath, configContext) if (sourceFile !== undefined) { - const resolvedFiles = this.resolveSourceFile(sourceFile) + const resolvedFiles = this.resolveSourceFile(sourceFile, configContext) let found = false for (const resolvedFile of resolvedFiles) { configJson.registerRelatedSourceFile(resolvedFile) @@ -356,9 +366,9 @@ export class PackageFilesResolver { if (packageJson !== undefined) { if (packageJson.supportsPackageRelativePaths()) { const relativePath = path.resolve(packageJson.basePath, importPath) - const sourceFile = this.cache.sourceFile(relativePath, suffixes) + const sourceFile = this.cache.sourceFile(relativePath, context) if (sourceFile !== undefined) { - const resolvedFiles = this.resolveSourceFile(sourceFile) + const resolvedFiles = this.resolveSourceFile(sourceFile, context) let found = false for (const resolvedFile of resolvedFiles) { resolved.local.push({ diff --git a/packages/cli/src/services/check-parser/package-files/tsconfig-json-file.ts b/packages/cli/src/services/check-parser/package-files/tsconfig-json-file.ts index d8f9ec71..50ae15d4 100644 --- a/packages/cli/src/services/check-parser/package-files/tsconfig-json-file.ts +++ b/packages/cli/src/services/check-parser/package-files/tsconfig-json-file.ts @@ -54,29 +54,18 @@ interface CompilerOptions { * @see https://www.typescriptlang.org/tsconfig/#composite */ composite?: boolean + + /** + * If true, TypeScript-specific extensions can be imported. Requires + * either `noEmit: true` or `emitDeclarationOnly: true`. + */ + allowImportingTsExtensions?: boolean } export interface Schema { compilerOptions?: CompilerOptions } -type JSExtension = '.js' | '.mjs' | '.cjs' - -const JSExtensions: JSExtension[] = ['.js', '.mjs', '.cjs'] - -type JSExtensionMappings = { - [key in JSExtension]: string[] -} - -/** - * @see https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution - */ -const extensionMappings: JSExtensionMappings = { - '.js': ['.ts', '.tsx', '.js', '.jsx'], - '.mjs': ['.mts', '.mjs'], - '.cjs': ['.cts', '.cjs'], -} - export class TSConfigFile { static FILENAME = 'tsconfig.json' @@ -88,6 +77,7 @@ export class TSConfigFile { moduleResolution: string baseUrl?: string pathResolver: PathResolver + allowImportingTsExtensions: boolean relatedSourceFiles: SourceFile[] = [] @@ -104,6 +94,8 @@ export class TSConfigFile { } this.pathResolver = PathResolver.createFromPaths(this.baseUrl ?? '.', jsonFile.data.compilerOptions?.paths ?? {}) + + this.allowImportingTsExtensions = jsonFile.data.compilerOptions?.allowImportingTsExtensions ?? false } public get meta () { @@ -133,22 +125,6 @@ export class TSConfigFile { return this.pathResolver.resolve(importPath) } - private extifyLookupPaths (filePaths: string[]): string[] { - return filePaths.flatMap(filePath => { - let extensions = extensionMappings['.js'] - let extlessPath = filePath - - for (const ext of JSExtensions) { - if (filePath.endsWith(ext)) { - extensions = extensionMappings[ext] - extlessPath = filePath.substring(0, filePath.length - ext.length) - } - } - - return extensions.map(ext => path.resolve(this.basePath, extlessPath + ext)) - }) - } - collectLookupPaths (filePath: string): string[] { let { outDir, @@ -160,8 +136,8 @@ export class TSConfigFile { const candidates = [] if (outDir === undefined) { - candidates.push(filePath) - return this.extifyLookupPaths(candidates) // Nothing more we can do. + candidates.push(path.resolve(this.basePath, filePath)) + return candidates // Nothing more we can do. } if (composite === undefined) { @@ -187,8 +163,8 @@ export class TSConfigFile { // something that wasn't compiled using this tsconfig (or at all), and // stop looking. if (relativePath.startsWith('..')) { - candidates.push(filePath) - return this.extifyLookupPaths(candidates) + candidates.push(path.resolve(this.basePath, filePath)) + return candidates } candidates.push(path.resolve(this.basePath, rootDir, relativePath)) @@ -200,7 +176,7 @@ export class TSConfigFile { candidates.push(path.resolve(this.basePath, multiRootDir, relativePath)) } - return this.extifyLookupPaths(candidates) + return candidates } registerRelatedSourceFile (file: SourceFile) { diff --git a/packages/cli/src/services/check-parser/parser.ts b/packages/cli/src/services/check-parser/parser.ts index 1ecc2abc..10c807f1 100644 --- a/packages/cli/src/services/check-parser/parser.ts +++ b/packages/cli/src/services/check-parser/parser.ts @@ -20,26 +20,6 @@ type SupportedFileExtension = '.js' | '.mjs' | '.ts' const PACKAGE_EXTENSION = `${path.sep}package.json` -const JS_RESOLVE_ORDER = [ - '.js', - '.mjs', - PACKAGE_EXTENSION, - `${path.sep}index.js`, - // TODO: Check the module type in package.json to figure out the esm and common js file extensions - `${path.sep}index.mjs`, -] - -const TS_RESOLVE_ORDER = [ - '.ts', - '.js', - '.mjs', - PACKAGE_EXTENSION, - `${path.sep}index.ts`, - `${path.sep}index.js`, - // TODO: Check the module type in package.json to figure out the esm and common js file extensions - `${path.sep}index.mjs`, -] - const supportedBuiltinModules = [ 'assert', 'buffer', 'crypto', 'dns', 'fs', 'path', 'querystring', 'readline ', 'stream', 'string_decoder', 'timers', 'tls', 'url', 'util', 'zlib', @@ -131,9 +111,7 @@ export class Parser { continue } - const suffixes = extension === '.js' ? JS_RESOLVE_ORDER : TS_RESOLVE_ORDER - - const resolved = resolver.resolveDependenciesForFilePath(item.filePath, module.dependencies, suffixes) + const resolved = resolver.resolveDependenciesForFilePath(item.filePath, module.dependencies) if (this.checkUnsupportedModules) { const unsupportedDependencies = resolved.external.flatMap(dep => {