Skip to content

Commit

Permalink
fix: replace build.js curl call with node https
Browse files Browse the repository at this point in the history
This was occasionally causing my machine to spin on CPU indefinitely
while trying to download the Closure Compiler output.

It would perhaps be better to investigate what is wrong with curl on my
machine, but since Node has a pretty nice built-in HTTPS client, I
figured it'd be easier to just cut out the external system dependency
entirely.
  • Loading branch information
isaacs committed Aug 31, 2021
1 parent d058745 commit c41333d
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,43 @@ run(browserify + ' .temp.js', function(error, stdout) {
].join('\n');

// Use the online Google Closure Compiler service for minification
fs.writeFileSync('.temp.js', querystring.stringify({
var body = Buffer.from(querystring.stringify({
compilation_level: 'SIMPLE_OPTIMIZATIONS',
output_info: 'compiled_code',
output_format: 'text',
js_code: code
}));
run('curl -d @.temp.js "https://closure-compiler.appspot.com/compile"', function(error, stdout) {
if (error) throw error;
var code = header + '\n' + stdout;
fs.unlinkSync('.temp.js');
fs.writeFileSync('browser-source-map-support.js', code);
fs.writeFileSync('amd-test/browser-source-map-support.js', code);
console.log('making request to google closure compiler');
var https = require('https');
var request = https.request({
method: 'POST',
host: 'closure-compiler.appspot.com',
path: '/compile',
headers: {
'content-length': body.length,
'content-type': 'application/x-www-form-urlencoded'
},
});
request.end(body);
request.on('response', function(response) {
if (response.statusCode !== 200) {
response.pipe(process.stderr);
response.on('end', function() {
throw new Error('failed to post to closure compiler');
});
return;
}

var data = [];
response.on('data', function(chunk) {
data.push(chunk);
});
response.on('end', function() {
var stdout = Buffer.concat(data);
var code = header + '\n' + stdout;
fs.writeFileSync('browser-source-map-support.js', code);
fs.writeFileSync('amd-test/browser-source-map-support.js', code);
});
});
});

Expand Down

0 comments on commit c41333d

Please sign in to comment.