In my gulp-based workflow, I am trying to apply a transform to all typescript files before tsify compiles it:
gulp.task(
'deploy-typescript',
function() {
var modulePath = configuration.files.typescript.entry;
var bundleStream = browserify([modulePath])
.transform(includeTemplates)
.plugin(tsify)
.bundle();
return bundleStream
.pipe(sourcestream(configuration.files.typescript.bundle))
.pipe(gulp.dest(configuration.files.typescript.destination));
}
);
var includeTemplates = function(file, options) {
return through(function(buffer, encoding, next) {
this.push('!test!');
next();
}
}
However, it appears that the tsify plugin ignores any changes my plugin makes to the source files and uses the .ts files as they exist on disk. The generated bundle does not include any of the changes I expect my transform to make.
Unfortunately, what you have discovered is not a bug, but is the by-design behaviour.
tsify transforms TypeScript to JavaScript using TypeScript's Compiler API. Specifically, it implements the
CompilerHost
interface:The transformation is not performed file-by-file. Rather, the entire program is compiled and the resultant, transformed files are held in memory and are later passed to Browserify. This compilation involves the TypeScript compiler infrastructure reading the files from disk.
The author's comments are here: