* 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)
| 47 | * @returns {Promise<typeof ts>} The compiler to use. |
| 48 | */ |
| 49 | async 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. |