Skip to content

Use typescript.sys as the module resolution host #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ export interface ResolveSync {
(context: string, path: string, moduleName: string): string;
}

export interface ModuleResolutionHost {
fileExists(fileName: string): boolean;
readFile(fileName: string): string
}

export interface TSInstance {
compiler: typeof typescript;
compilerOptions: typescript.CompilerOptions;
Expand Down
15 changes: 6 additions & 9 deletions src/servicesHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ function makeServicesHost(
// make a (sync) resolver that follows webpack's rules
const resolveSync = makeResolver(loader.options);

const moduleResolutionHost = {
fileExists: (fileName: string) => utils.readFile(fileName) !== undefined,
readFile: (fileName: string) => utils.readFile(fileName),
};
const moduleResolutionHost = typescript.sys;

return {
getProjectVersion: () => `${instance.version}`,
Expand Down Expand Up @@ -69,7 +66,7 @@ function makeServicesHost(
getDefaultLibFileName: (options: typescript.CompilerOptions) => compiler.getDefaultLibFilePath(options),
getNewLine: () => newLine,
log: log.log,
resolveModuleNames: (moduleNames: string[], containingFile: string) =>
resolveModuleNames: (moduleNames: string[], containingFile: string) =>
resolveModuleNames(
resolveSync, moduleResolutionHost, appendTsSuffixTo, scriptRegex, instance,
moduleNames, containingFile)
Expand All @@ -78,14 +75,14 @@ function makeServicesHost(

function resolveModuleNames(
resolveSync: interfaces.ResolveSync,
moduleResolutionHost: interfaces.ModuleResolutionHost,
moduleResolutionHost: typescript.ModuleResolutionHost,
appendTsSuffixTo: RegExp[],
scriptRegex: RegExp,
instance: interfaces.TSInstance,
moduleNames: string[],
containingFile: string
) {
const resolvedModules = moduleNames.map(moduleName =>
const resolvedModules = moduleNames.map(moduleName =>
resolveModuleName(resolveSync, moduleResolutionHost, appendTsSuffixTo, scriptRegex, instance,
moduleName, containingFile)
);
Expand All @@ -97,7 +94,7 @@ function resolveModuleNames(

function resolveModuleName(
resolveSync: interfaces.ResolveSync,
moduleResolutionHost: interfaces.ModuleResolutionHost,
moduleResolutionHost: typescript.ModuleResolutionHost,
appendTsSuffixTo: RegExp[],
scriptRegex: RegExp,
instance: interfaces.TSInstance,
Expand All @@ -106,7 +103,7 @@ function resolveModuleName(
containingFile: string
) {
const { compiler, compilerOptions } = instance;

let resolutionResult: interfaces.ResolvedModule;

try {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function collectAllDependencies(
const result = {};
result[filePath] = true;
collected[filePath] = true;
let directDependencies = dependencyGraph[filePath];
let directDependencies = dependencyGraph[filePath];
if (directDependencies) {
directDependencies.forEach(dependencyFilePath => {
if (!collected[dependencyFilePath]) {
Expand Down