gulp-jspm
gulp-jspm copied to clipboard
In memory build instead using temp directory
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
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!
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).
sounds good!
see #16
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
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();.
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
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.