-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathresolver.ts
More file actions
33 lines (32 loc) · 1.01 KB
/
resolver.ts
File metadata and controls
33 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { CompilerOptions } from 'typescript';
import ts from 'typescript';
import type { Resolver, ResolverOptions } from './type.js';
import { isURLSpecifier } from './util.js';
export function createResolver(
compilerOptions: CompilerOptions,
moduleResolutionCache: ts.ModuleResolutionCache | undefined,
): Resolver {
return (specifier: string, options: ResolverOptions) => {
if (isURLSpecifier(specifier)) return undefined;
const host: ts.ModuleResolutionHost = {
...ts.sys,
fileExists: (fileName) => {
if (fileName.endsWith('.d.css.ts')) {
return ts.sys.fileExists(fileName.replace(/\.d\.css\.ts$/u, '.css'));
}
return ts.sys.fileExists(fileName);
},
};
const { resolvedModule } = ts.resolveModuleName(
specifier,
options.request,
compilerOptions,
host,
moduleResolutionCache,
);
if (resolvedModule) {
return resolvedModule.resolvedFileName.replace(/\.d\.css\.ts$/u, '.css');
}
return undefined;
};
}