ClosureCompiler.js icon indicating copy to clipboard operation
ClosureCompiler.js copied to clipboard

Accept a Buffer in addition to files in `.compile()`

Open sindresorhus opened this issue 10 years ago • 7 comments

I've created a gulp plugin for Closure Compiler using this excellent module.

Gulp works on streams and buffers and not files while this module requires you to supply files. A lot of other Node things does this too.

It would be useful if you could also supply a buffer that is passed to the Closure Compiler stdin.

Like:

ClosureCompiler.compile(new Buffer('function foo() {}'), {}, function () {});

sindresorhus avatar Dec 30 '13 12:12 sindresorhus

I see. Do you know if closure compiler itself allows compilation of stdin? That'd be required to make something like this work. Everything else would still require a temporary file.

dcodeIO avatar Dec 30 '13 13:12 dcodeIO

Looks like it https://www.google.no/search?q=closure+compiler+stdin&oq=closure+compiler&aqs=chrome.0.69i59l3j69i57j69i60j69i65.2516j0j7&sourceid=chrome&espv=210&es_sm=91&ie=UTF-8

Would be something like:

closureProcess.stdin.write(new Buffer('test'));

sindresorhus avatar Dec 30 '13 13:12 sindresorhus

Any update on this?

sindresorhus avatar Feb 08 '14 13:02 sindresorhus

Bump, I would also really like to use this inside of a Connect pipeline. It's a shame to have to write content to a temporary file ;(

vjeux avatar Feb 22 '14 19:02 vjeux

+1 We demand that :-) Should I send PR?

steida avatar Feb 23 '14 11:02 steida

Any update?

callumlocke avatar Mar 20 '14 13:03 callumlocke

It's possible to use buffer for Closure Compiler. But unfortunatelly not like that:

files.map(function(file) {
  var src = file.contents.toString();
  jar.stdin.write(src);
});
jar.stdin.end()

From my experiments it seems that closure_entry_point option does not work with piped files. Especially, compiler seems to not be able to reorder files as needed. This https://code.google.com/p/closure-compiler/wiki/ManageClosureDependencies simply does not work. But when I use plain old -js parameter, it works. There is also another issue related to Windows, http://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string Fortunatelly, compiler supports special flag file.

So I am almost decided to use https://github.com/vesln/temporary, there is no other way.

New gulp-closure-compiler (or another name) will be finished soon.

steida avatar Apr 01 '14 20:04 steida