Skip to content
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

Mac OSX is compiling typescript and bundle.js out of order #36

Closed
abogartz opened this issue Apr 3, 2015 · 3 comments
Closed

Mac OSX is compiling typescript and bundle.js out of order #36

abogartz opened this issue Apr 3, 2015 · 3 comments

Comments

@abogartz
Copy link

abogartz commented Apr 3, 2015

This behavior is also seen using the command line, but here is my Gulp file below:

When running on Windows the plugin works perfectly. The expected behavior is that upon save of any typescript file in the require tree of test-app.ts, the tsify plugin will compile the js files and then let browserify compile those files. On Mac OSX, this appears to not happen in the proper sequence, resulting in each change being one "save" behind.

For instance, if I add a console log of:

console.log("log 1");

The first time I save, it won't show up. If I change it to:

console.log("log 2");

I will then see "log 1" in the console. Upon next save, I'll then see "log 2".

'use strict';

var watchify = require('watchify');
var browserify = require('browserify');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var gutil = require('gulp-util');
var sourcemaps = require('gulp-sourcemaps');
var assign = require('lodash.assign');

// add custom browserify options here
var customOpts = {
    entries: ['./test-app.ts'],
    debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));

gulp.task('js', bundle); // so you can run `gulp js` to build the file
b.on('update', bundle); // on any dep update, runs the bundler
b.on('log', gutil.log); // output build logs to terminal
b.plugin('tsify')

function bundle() {
    return b.bundle()
        // log errors if they happen
        .on('error', gutil.log.bind(gutil, 'Browserify Error'))
        .pipe(source('bundle.js'))
        // optional, remove if you don't need to buffer file contents
        .pipe(buffer())
        // optional, remove if you dont want sourcemaps
        .pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file
        // Add transformation tasks to the pipeline here.
        .pipe(sourcemaps.write('./')) // writes .map file
        .pipe(gulp.dest('./'));
}
gulp.task("bundle", function () {
    bundle();
})
@smrq
Copy link
Member

smrq commented Apr 3, 2015

Just a thought, try moving b.plugin('tsify') above b.on('update', bundle). Maybe there's something platform-dependent with regards to how the event listeners get fired.

Also, what is this? A platform-specific issue where Windows isn't the problem?? 😱

@abogartz
Copy link
Author

abogartz commented Apr 3, 2015

😄

Ok, that still doesn't work. I'm on Windows while my co-worker with the problem is on Mac. We tried moving that line all around and it still does the same behavior. I thought maybe it was that he had a separate file watcher in Atom Editor that was maybe fooling Browserify, but we disabled that and confirmed that while it's compiling the typescript correctly, it's compiling Browserify before tsify.

@abogartz
Copy link
Author

abogartz commented Apr 6, 2015

This was fixed by completely uninstalling and reinstalling node using nvm. I have no idea what the issue was, but it's all working fine now.

@abogartz abogartz closed this as completed Apr 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants