Skip to content

Commit

Permalink
fix(core): fix module resolution in project locator (#2941)
Browse files Browse the repository at this point in the history
On windows, there is a bug in project module resolution, cause by path separator.  TypeScript resolveModuleName will always return a posix normalized path, so our appRootPath needs to be normalized for string replacement.

I came across the issue when trying to run dep-graph, but other areas (ex: affected:*) which rely on TargetProjectLocator are going to be impacted.
  • Loading branch information
rhutchison committed May 24, 2020
1 parent 2605836 commit b5025ef
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/workspace/src/utils/typescript.ts
Expand Up @@ -2,6 +2,8 @@ import { dirname } from 'path';
import * as ts from 'typescript';
import { appRootPath } from './app-root';

const normalizedAppRoot = appRootPath.replace(/\\/g, '/');

export function readTsConfig(tsConfigPath: string) {
const readResult = ts.readConfigFile(tsConfigPath, ts.sys.readFile);
return ts.parseJsonConfigFileContent(
Expand Down Expand Up @@ -38,7 +40,7 @@ export function resolveModuleByImport(importExpr: string, filePath: string) {
if (!resolvedModule) {
return;
} else {
return resolvedModule.resolvedFileName.replace(`${appRootPath}/`, '');
return resolvedModule.resolvedFileName.replace(`${normalizedAppRoot}/`, '');
}
}

Expand Down

0 comments on commit b5025ef

Please sign in to comment.