UNPKG

781 BJavaScriptView Raw
1var fs = require('fs');
2var path = require('path');
3
4
5var tsFolder = path.dirname(require.resolve('typescript'));
6var tscUnlockedPath = path.join(tsFolder, 'tsc-unlocked.js');
7
8try {
9 module.exports = require(tscUnlockedPath);
10} catch (err) {
11 unlockTsc();
12 module.exports = require(tscUnlockedPath);
13}
14
15function unlockTsc() {
16 var tscPath = path.join(tsFolder, 'tsc.js');
17 var source = String(fs.readFileSync(tscPath, 'utf8'));
18 var lines = source.split(/[\r\n]+/);
19
20 // Remove the following 2 lines from the source code:
21 // var batch = new TypeScript.BatchCompiler(TypeScript.IO);
22 // batch.batchCompile();
23 lines.splice(lines.length - 4, 2);
24
25 // Export the TypeScript module
26 lines.push('module.exports = TypeScript;');
27 fs.writeFileSync(tscUnlockedPath, lines.join('\n'));
28}