gulp-jspm icon indicating copy to clipboard operation
gulp-jspm copied to clipboard

In memory build instead using temp directory

Open davinkevin opened this issue 10 years ago • 8 comments

I've read the code, and the plugin seems to save file in a temp location (on disk) and read it again to provide it to the stream.

In SystemJS / JSPM, you can do everything in memory : https://github.com/systemjs/builder/issues/365

Like @gulpjs said on twitter : if you are using temp files or folders in gulp you are doing something horribly wrong -> https://twitter.com/contrahacks/status/656343475743428608

I think this issue is an improvement, and if I have enough time, I will try to do a PR.

Thanks

davinkevin avatar Oct 27 '15 13:10 davinkevin

The JSPM API is expecting a path. I don't see a way to keep all in memory without changing the code of https://github.com/jspm/jspm-cli. But it would be awesome if you find a way! Thanks!

brillout avatar Oct 27 '15 13:10 brillout

JSPM Builder seems to delegate to a SystemJS Builder, and the SystemJS builder can do all the work in memory : https://github.com/systemjs/builder#in-memory-builds

The output in the promise contains sources, sourceMap, module, assetList (not in the doc, only in https://github.com/systemjs/builder/issues/365 for now).

Say me if I missed something... (I've tried it in a project, seems to work).

davinkevin avatar Oct 27 '15 14:10 davinkevin

sounds good!

brillout avatar Oct 27 '15 15:10 brillout

see #16

brillout avatar Nov 26 '15 20:11 brillout

I think this would also fix the problem where you want to merge 2 streams that perform jspm() bundling, right now the following code fails because jspm cannot use the same temporary file twice concurrently:

es.merge(
  gulp.src('foo').pipe(jspm()).pipe(concat('foo')),
  gulp.src('bar').pipe(jspm()).pipe(concat('bar'))
).pipe(gulp.dest('dist/'))
[13:35:28] Error in plugin 'gulp-jspm'
Message:
    ENOENT: no such file or directory, open '/var/folders/5h/d5hh9f0s3zg6f1zn3zjtjtsr0000gn/T/gulp-jspm__build.js116522-22723-1dljtv3'
Details:
    cause: Error: ENOENT: no such file or directory, open '/var/folders/5h/d5hh9f0s3zg6f1zn3zjtjtsr0000gn/T/gulp-jspm__build.js116522-22723-1dljtv3'
    isOperational: true
    errno: -2
    code: ENOENT
    syscall: open
    path: /var/folders/5h/d5hh9f0s3zg6f1zn3zjtjtsr0000gn/T/gulp-jspm__build.js116522-22723-1dljtv3

weisk avatar Jun 22 '16 09:06 weisk

@weisk any luck with your issue? Note that gulp-jspm creates a new temporary file for every gulp-jspm() call and that gulp-jspm uses temp's automatic cleanup feature require("temp").track();.

brillout avatar Jun 24 '16 14:06 brillout

for now my workaround is just doing them in series:

export default function scripts() {
  const bundles = [
    (cb) =>  gulp.src('foo').pipe(jspm()).pipe(concat('foo')),
    (cb) =>  gulp.src('bar').pipe(jspm()).pipe(concat('bar'))
  ];
  return gulp.series(...bundles);

if I try to run them in parallel, it breaks with the previous error

weisk avatar Jun 24 '16 15:06 weisk

The issue pointed out by @weisk has a much simpler way to reproduce -- just try to run multiple independent JSPM builds in parallel.

Here is an example Gulp script that tries to build two versions, on minified and the other unminified:

function buildTask(src, options) {
    return gulp.src(src)
        .pipe(gulp_jspm(options))
        .pipe(gulp.dest('build/dist/'));
}

gulp.task('build:jspm', function() {
    return buildTask('main.js', {
        selfExecutingBundle: true,
        fileName: 'main',
    });
});

gulp.task('build:jspm:min', function() {
    return buildTask('main.js', {
        selfExecutingBundle: true,
        fileName: 'main.min',
        minify: true,
    });
});

gulp.task('build', ['build:jspm', 'build:jspm:min']);

If I run gulp build:jspm or gulp build:jspm:min, it works, but if I run gulp build, it throws the same error.

kohenkatz avatar Aug 08 '16 03:08 kohenkatz