Skip to content

Commit a3d44c9

Browse files
committed
Read deps of .d.ts files inplace.
1 parent 8a048e2 commit a3d44c9

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

TypeScriptWebpackHost.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,40 @@ TypeScriptWebpackHost.prototype._readFile = function _readFile(filename) {
152152
});
153153
};
154154

155-
TypeScriptWebpackHost.prototype.addFile = function addFile(filename) {
155+
TypeScriptWebpackHost.prototype._readFileAndAdd = function _readFileAndAdd(filename) {
156156
return this._readFile(filename).then(this._addFile.bind(this, filename));
157157
};
158158

159+
TypeScriptWebpackHost.prototype._addDependencies = function(resolver, filename) {
160+
var dependencies = this.findImportDeclarations(filename).map(function(dep) {
161+
return resolver(path.dirname(filename), dep).then(function(filename) {
162+
var added = this._readFileAndAdd(filename);
163+
// This is d.ts which doesn't go through typescript-loader separately so
164+
// we should take care of it by analyzing its dependencies here.
165+
if (/\.d\.ts$/.exec(filename)) {
166+
added = added.then(function() {
167+
return this._addDependencies(resolver, filename);
168+
}.bind(this));
169+
}
170+
return added;
171+
}.bind(this));
172+
}.bind(this));
173+
return Promise.all(dependencies);
174+
}
175+
159176
/**
160177
* Emit compilation result for a specified filename.
161178
*/
162179
TypeScriptWebpackHost.prototype.emit = function emit(resolver, filename, text) {
163180
this._addFile(filename, text);
164181

182+
// Check if we need to compiler Webpack runtime definitions.
165183
if (!this._runtimeRead) {
166184
this._services.getEmitOutput(RUNTIME.filename);
167185
this._runtimeRead = true;
168186
}
169187

170-
var dependencies = Promise.all(
171-
this.findImportDeclarations(filename).map(function(dep) {
172-
return resolver(path.dirname(filename), dep).then(this.addFile.bind(this));
173-
}, this));
174-
175-
return dependencies.then(function() {
188+
return this._addDependencies(resolver, filename).then(function() {
176189
var output = this._services.getEmitOutput(filename);
177190
if (output.emitOutputStatus === ts.EmitReturnStatus.Succeeded) {
178191
return output;

0 commit comments

Comments
 (0)