Skip to content

Commit

Permalink
fix: remove use of private API (#351)
Browse files Browse the repository at this point in the history
Don't use the upstream private API function to turn a `CompilerHost` into a
`ParseConfigHost` anymore; instead, I copied the implementation, which is
simple enough.

Fixes #350.
  • Loading branch information
rix0rrr authored Feb 1, 2019
1 parent 4ecf28c commit 874cbac
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/jsii/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class Compiler implements Emitter {
if (files.length > 0) {
ret.push(...files);
} else {
const parseConfigHost = (ts as any /* private API */).parseConfigHostFromCompilerHost(this.compilerHost);
const parseConfigHost = parseConfigHostFromCompilerHost(this.compilerHost);
const parsed = ts.parseJsonConfigFileContent(this.typescriptConfig, parseConfigHost, this.options.projectInfo.projectRoot);
ret.push(...parsed.fileNames);
}
Expand Down Expand Up @@ -323,3 +323,20 @@ function nodeJsCompatibleSearchPaths(dir: string): string[] {

return ret;
}

function parseConfigHostFromCompilerHost(host: ts.CompilerHost): ts.ParseConfigHost {
// Copied from upstream
// https://github.com/Microsoft/TypeScript/blob/9e05abcfd3f8bb3d6775144ede807daceab2e321/src/compiler/program.ts#L3105
return {
fileExists: f => host.fileExists(f),
readDirectory(root, extensions, excludes, includes, depth) {
if (host.readDirectory === undefined) {
throw new Error("'CompilerHost.readDirectory' must be implemented to correctly process 'projectReferences'");
}
return host.readDirectory!(root, extensions, excludes, includes, depth);
},
readFile: f => host.readFile(f),
useCaseSensitiveFileNames: host.useCaseSensitiveFileNames(),
trace: host.trace ? (s) => host.trace!(s) : undefined
};
}

0 comments on commit 874cbac

Please sign in to comment.