Skip to content

Commit 874cbac

Browse files
authored
fix: remove use of private API (#351)
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.
1 parent 4ecf28c commit 874cbac

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/jsii/lib/compiler.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class Compiler implements Emitter {
259259
if (files.length > 0) {
260260
ret.push(...files);
261261
} else {
262-
const parseConfigHost = (ts as any /* private API */).parseConfigHostFromCompilerHost(this.compilerHost);
262+
const parseConfigHost = parseConfigHostFromCompilerHost(this.compilerHost);
263263
const parsed = ts.parseJsonConfigFileContent(this.typescriptConfig, parseConfigHost, this.options.projectInfo.projectRoot);
264264
ret.push(...parsed.fileNames);
265265
}
@@ -323,3 +323,20 @@ function nodeJsCompatibleSearchPaths(dir: string): string[] {
323323

324324
return ret;
325325
}
326+
327+
function parseConfigHostFromCompilerHost(host: ts.CompilerHost): ts.ParseConfigHost {
328+
// Copied from upstream
329+
// https://github.com/Microsoft/TypeScript/blob/9e05abcfd3f8bb3d6775144ede807daceab2e321/src/compiler/program.ts#L3105
330+
return {
331+
fileExists: f => host.fileExists(f),
332+
readDirectory(root, extensions, excludes, includes, depth) {
333+
if (host.readDirectory === undefined) {
334+
throw new Error("'CompilerHost.readDirectory' must be implemented to correctly process 'projectReferences'");
335+
}
336+
return host.readDirectory!(root, extensions, excludes, includes, depth);
337+
},
338+
readFile: f => host.readFile(f),
339+
useCaseSensitiveFileNames: host.useCaseSensitiveFileNames(),
340+
trace: host.trace ? (s) => host.trace!(s) : undefined
341+
};
342+
}

0 commit comments

Comments
 (0)