diff --git a/helper/_option.ts b/helper/_option.ts index dfaa8df..481b4c4 100644 --- a/helper/_option.ts +++ b/helper/_option.ts @@ -28,7 +28,6 @@ function makeHostOption( libMap: Map, compilerOptions: CompilerOptions, ): CompilerHost { - console.log(libMap, compilerOptions); return { readFile, useCaseSensitiveFileNames, diff --git a/helper/_runtime.ts b/helper/_runtime.ts index f78edfe..77e702b 100644 --- a/helper/_runtime.ts +++ b/helper/_runtime.ts @@ -2,7 +2,6 @@ import type { CompilerHost, CompilerOptions, ModuleResolutionHost, - ResolvedModule, } from "../deps.ts"; import { ts } from "../deps.ts"; @@ -93,17 +92,32 @@ type ResolveModuleNames = Exclude< undefined >; +const reRemoteModule = /^https?:\/\//; + +function remoteModuleExists(value: string[]): boolean { + return value.some((v) => reRemoteModule.test(v)); +} + function makeResolveModuleNames( compilerOptions: CompilerOptions, ): typeof resolveModuleNames { function resolveModuleNames( ...[moduleNames, containingFile]: Parameters ): ReturnType { - const resolvedModules: ResolvedModule[] = []; - - for (const moduleName of moduleNames.map(removeTsExtension)) { - const result = ts.resolveModuleName( - moduleName, + const tmpPath = remoteModuleExists(moduleNames) + ? (() => + Deno.makeTempFileSync({ + suffix: ".ts", + }))() + : undefined; + + return moduleNames.map((moduleName) => { + const fixedModulePath = reRemoteModule.test(moduleName) + ? removeTsExtension(tmpPath!) + : removeTsExtension(moduleName); + + const { resolvedModule } = ts.resolveModuleName( + fixedModulePath, containingFile, compilerOptions, { @@ -115,18 +129,9 @@ function makeResolveModuleNames( realpath, }, ); - console.log({ - moduleName, - containingFile, - compilerOptions, - result, - }); - if (result.resolvedModule) { - resolvedModules.push(result.resolvedModule); - } - } - return resolvedModules; + return resolvedModule; + }); } return resolveModuleNames; } diff --git a/matcher/mod.ts b/matcher/mod.ts index f642d5e..c068631 100644 --- a/matcher/mod.ts +++ b/matcher/mod.ts @@ -11,6 +11,9 @@ import { isNotAssignable } from "./is_not_assignable.ts"; import type { Matcher } from "./types.ts"; import type { RequiredByKeys } from "../_types.ts"; +const IS_NOT_MODULE = 2306; +const ignoreDiagnosticsCodes = new Set([IS_NOT_MODULE]); + const assertionMap = { expectType: isIdentical, expectNotType: isNotIdentical, @@ -48,7 +51,10 @@ function inspect(program: Program): Result[] { ].filter(({ file }) => !!file).filter(({ messageText }) => { // for lib.es2021.d.ts return messageText !== "File '/lib.es2021.intl.d.ts' not found."; - }) as RequiredByKeys[]; + }).filter(({ code }) => !ignoreDiagnosticsCodes.has(code)) as RequiredByKeys< + TSDiagnostic, + "file" + >[]; const typeChecker = program.getTypeChecker(); const assertions = extractAssertions(program);