Skip to content

Commit 07ccfb1

Browse files
committed
Added typescript@next work-around for node_modules
1 parent 3b18422 commit 07ccfb1

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

lib/Host.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var trace = require('util').debuglog(require('../package').name + '-trace');
88
var os = require('os');
99
var path = require('path');
1010
var util = require('util');
11+
var semver = require('semver');
1112

1213
module.exports = function (ts) {
1314
function Host(currentDirectory, opts) {
@@ -81,7 +82,8 @@ module.exports = function (ts) {
8182
contents: text,
8283
ts: file,
8384
root: root,
84-
version: version
85+
version: version,
86+
nodeModule: /\/node_modules\/(?!typescript\/)/.test(canonical)
8587
};
8688
this.emit('file', canonical, relative);
8789

@@ -158,6 +160,34 @@ module.exports = function (ts) {
158160
return rootFilenames;
159161
}
160162

163+
Host.prototype._nodeModuleFilenames = function () {
164+
165+
var nodeModuleFilenames = [];
166+
167+
for (var filename in this.files) {
168+
if (!Object.hasOwnProperty.call(this.files, filename)) continue;
169+
if (!this.files[filename].nodeModule) continue;
170+
nodeModuleFilenames.push(filename);
171+
}
172+
return nodeModuleFilenames;
173+
}
174+
175+
Host.prototype._compile = function (opts) {
176+
177+
var rootFilenames = this._rootFilenames();
178+
var nodeModuleFilenames = [];
179+
180+
log('Compiling files:');
181+
rootFilenames.forEach(function (file) { log(' %s', file); });
182+
183+
if (semver.gte(ts.version, '2.0.0')) {
184+
ts.createProgram(rootFilenames, opts, this);
185+
nodeModuleFilenames = this._nodeModuleFilenames();
186+
log(' + %d file(s) found in node_modules', nodeModuleFilenames.length);
187+
}
188+
return ts.createProgram(rootFilenames.concat(nodeModuleFilenames), opts, this);
189+
}
190+
161191
Host.prototype._output = function (filename) {
162192

163193
var outputCanonical = this._inferOutputCanonical(filename);

lib/Tsifier.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,9 @@ module.exports = function (ts) {
155155

156156
Tsifier.prototype.compile = function () {
157157
var self = this;
158-
var rootFilenames = self.host._rootFilenames();
159-
160-
log('Compiling files:');
161-
rootFilenames.forEach(function (file) { log(' %s', file); });
162158

163159
var createProgram_t0 = time.start();
164-
var program = ts.createProgram(rootFilenames, self.opts, self.host);
160+
var program = self.host._compile(self.opts);
165161
time.stop(createProgram_t0, 'createProgram');
166162

167163
var syntaxDiagnostics = self.checkSyntax(program);

0 commit comments

Comments
 (0)