Skip to content

Commit a65b42a

Browse files
committed
fix separator in getDefaultLibFileName
Remove use of Path.join in the getDefaultLibFileName method that, on Windows, converts '/' in paths to '\'. TypeScript uses '/' internally so it has trouble locating the default lib location when this is reversed. Fixes TypeStrong#464 where lib directory cannot be found on Windows.
1 parent b53f9d3 commit a65b42a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/lib/converter/utils/compiler-host.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import * as ts from 'typescript';
22
import * as _ts from '../../ts-internal';
3-
import * as Path from 'path';
43

54
import {ConverterComponent} from '../components';
6-
import {normalizePath} from '../../utils/fs';
75

86
/**
97
* Return code of ts.sys.readFile when the file encoding is unsupported.
@@ -52,9 +50,8 @@ export class CompilerHost extends ConverterComponent implements ts.CompilerHost
5250
* @returns The full path of the default library.
5351
*/
5452
getDefaultLibFileName(options: ts.CompilerOptions): string {
55-
const lib = this.owner.getDefaultLib();
56-
const path = _ts.getDirectoryPath(normalizePath(require.resolve('typescript')));
57-
return Path.join(path, lib);
53+
const libLocation = _ts.getDirectoryPath(_ts.normalizePath(ts.sys.getExecutingFilePath()));
54+
return _ts.combinePaths(libLocation, ts.getDefaultLibFileName(options));
5855
}
5956

6057
getDirectories(path: string): string[] {

src/lib/ts-internal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ export function getDirectoryPath() {
5656
return tsany.getDirectoryPath.apply(this, arguments);
5757
}
5858

59+
// https://github.com/Microsoft/TypeScript/blob/v2.2.1/src/compiler/core.ts#L1418
60+
export function normalizePath(path: string): string {
61+
return tsany.normalizePath(path);
62+
}
63+
64+
// https://github.com/Microsoft/TypeScript/blob/v2.2.1/src/compiler/core.ts#L1628
65+
export function combinePaths(path1: string, path2: string): string {
66+
return tsany.combinePaths(path1, path2);
67+
}
68+
5969
/**
6070
* These functions are in "utilities" and are marked as @internal:
6171
* https://github.com/Microsoft/TypeScript/blob/v2.1.4/src/compiler/utilities.ts#L3-L4

0 commit comments

Comments
 (0)