Skip to content

Commit

Permalink
Update custom resolution logic to work with latest API changes (see m…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrantly committed Sep 12, 2015
1 parent 9b40d10 commit 7b81715
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
33 changes: 27 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ interface WebpackError {
loaderSource: string;
}

interface ResolvedModule {
resolvedFileName?: string;
resolvedModule?: ResolvedModule;
isExternalLibraryImport?: boolean;
}

var instances = <TSInstances>{};
var webpackInstances = [];

Expand Down Expand Up @@ -296,24 +302,39 @@ function ensureTypeScriptInstance(options: Options, loader: any): { instance?: T
getNewLine: () => newLine,
log: log,
resolveModuleNames: (moduleNames: string[], containingFile: string) => {
let resolvedFileNames: string[] = [];
let resolvedModules: any[] = [];

for (let moduleName of moduleNames) {
let resolvedFileName: string;
let resolutionResult: any;

try {
resolvedFileName = resolver.resolveSync(containingFile, moduleName)

if (!resolvedFileName.match(/\.ts(x?)$/)) resolvedFileName = null;
if (!resolvedFileName.match(/\.tsx?$/)) resolvedFileName = null;
else resolutionResult = { resolvedFileName };
}
catch (e) { resolvedFileName = null }

if (!resolvedFileName) {
resolvedFileName = compiler.resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost).resolvedFileName
let tsResolution: ResolvedModule = compiler.resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost);

if (tsResolution.resolvedModule) {
if (resolvedFileName) {
if (resolvedFileName == tsResolution.resolvedModule.resolvedFileName) {
resolutionResult.isExternalLibraryImport = tsResolution.resolvedModule.isExternalLibraryImport;
}
}
else resolutionResult = tsResolution.resolvedModule;
}
// this is for legacy compatibility purposes and can eventually be removed
else if (hasOwnProperty(tsResolution, 'resolvedFileName')) {
if (resolvedFileName) resolutionResult = resolvedFileName;
else resolutionResult = tsResolution.resolvedFileName;
}

resolvedFileNames.push(resolvedFileName);
resolvedModules.push(resolutionResult);
}
return resolvedFileNames;
return resolvedModules;
}
};

Expand Down
4 changes: 1 addition & 3 deletions test/nodeResolution/node_modules/a/a.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b81715

Please sign in to comment.