Skip to content

Added typescript@next work-around for node_modules #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lib/Host.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var trace = require('util').debuglog(require('../package').name + '-trace');
var os = require('os');
var path = require('path');
var util = require('util');
var semver = require('semver');

module.exports = function (ts) {
function Host(currentDirectory, opts) {
Expand Down Expand Up @@ -81,7 +82,8 @@ module.exports = function (ts) {
contents: text,
ts: file,
root: root,
version: version
version: version,
nodeModule: /\/node_modules\/(?!typescript\/)/.test(canonical)
};
this.emit('file', canonical, relative);

Expand Down Expand Up @@ -158,6 +160,34 @@ module.exports = function (ts) {
return rootFilenames;
}

Host.prototype._nodeModuleFilenames = function () {

var nodeModuleFilenames = [];

for (var filename in this.files) {
if (!Object.hasOwnProperty.call(this.files, filename)) continue;
if (!this.files[filename].nodeModule) continue;
nodeModuleFilenames.push(filename);
}
return nodeModuleFilenames;
}

Host.prototype._compile = function (opts) {

var rootFilenames = this._rootFilenames();
var nodeModuleFilenames = [];

log('Compiling files:');
rootFilenames.forEach(function (file) { log(' %s', file); });

if (semver.gte(ts.version, '2.0.0')) {
ts.createProgram(rootFilenames, opts, this);
nodeModuleFilenames = this._nodeModuleFilenames();
log(' + %d file(s) found in node_modules', nodeModuleFilenames.length);
}
return ts.createProgram(rootFilenames.concat(nodeModuleFilenames), opts, this);
}

Host.prototype._output = function (filename) {

var outputCanonical = this._inferOutputCanonical(filename);
Expand Down
6 changes: 1 addition & 5 deletions lib/Tsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,9 @@ module.exports = function (ts) {

Tsifier.prototype.compile = function () {
var self = this;
var rootFilenames = self.host._rootFilenames();

log('Compiling files:');
rootFilenames.forEach(function (file) { log(' %s', file); });

var createProgram_t0 = time.start();
var program = ts.createProgram(rootFilenames, self.opts, self.host);
var program = self.host._compile(self.opts);
time.stop(createProgram_t0, 'createProgram');

var syntaxDiagnostics = self.checkSyntax(program);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
},
"dependencies": {
"convert-source-map": "^1.1.0",
"fs.realpath": "^1.0.0",
"semver": "^5.1.0",
"through2": "^2.0.0",
"tsconfig": "^2.2.0",
"fs.realpath": "^1.0.0"
"tsconfig": "^2.2.0"
},
"devDependencies": {
"babel-preset-react": "^6.5.0",
Expand All @@ -40,7 +41,6 @@
"event-stream": "^3.3.1",
"fs-extra": "^0.30.0",
"node-foo": "^0.2.3",
"semver": "^5.1.0",
"source-map": "^0.5.3",
"tape": "^4.0.0",
"test-peer-range": "^1.0.1",
Expand Down