MCPcopy Create free account
hub / github.com/cure53/DOMPurify / loadCompiler

Function loadCompiler

typescript/verify.js:49–66  ·  view source on GitHub ↗

* Loads the TypeScript compiler a project asks for. * * A project pins an older release by naming it in the `typescript` field of * its own `package.json`; the release itself is installed under an npm alias * in this directory's `package.json`. Everything else compiles with the * version the re

(directory)

Source from the content-addressed store, hash-verified

47 * @returns {Promise<typeof ts>} The compiler to use.
48 */
49async function loadCompiler(directory) {
50 let manifest = path.join(directory, 'package.json');
51 let contents;
52
53 try {
54 contents = await fs.readFile(manifest, { encoding: 'utf8' });
55 } catch (ex) {
56 if (ex.code === 'ENOENT') {
57 return ts;
58 }
59
60 throw ex;
61 }
62
63 let pinned = JSON.parse(contents).typescript;
64
65 return pinned ? require(pinned) : ts;
66}
67
68/**
69 * Verifies that a TypeScript project compiles.

Callers 1

verifyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected