Skip to content

Commit c41333d

Browse files
committed
fix: replace build.js curl call with node https
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.
1 parent d058745 commit c41333d

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

build.js

+32-7
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,43 @@ run(browserify + ' .temp.js', function(error, stdout) {
3333
].join('\n');
3434

3535
// Use the online Google Closure Compiler service for minification
36-
fs.writeFileSync('.temp.js', querystring.stringify({
36+
var body = Buffer.from(querystring.stringify({
3737
compilation_level: 'SIMPLE_OPTIMIZATIONS',
3838
output_info: 'compiled_code',
3939
output_format: 'text',
4040
js_code: code
4141
}));
42-
run('curl -d @.temp.js "https://closure-compiler.appspot.com/compile"', function(error, stdout) {
43-
if (error) throw error;
44-
var code = header + '\n' + stdout;
45-
fs.unlinkSync('.temp.js');
46-
fs.writeFileSync('browser-source-map-support.js', code);
47-
fs.writeFileSync('amd-test/browser-source-map-support.js', code);
42+
console.log('making request to google closure compiler');
43+
var https = require('https');
44+
var request = https.request({
45+
method: 'POST',
46+
host: 'closure-compiler.appspot.com',
47+
path: '/compile',
48+
headers: {
49+
'content-length': body.length,
50+
'content-type': 'application/x-www-form-urlencoded'
51+
},
52+
});
53+
request.end(body);
54+
request.on('response', function(response) {
55+
if (response.statusCode !== 200) {
56+
response.pipe(process.stderr);
57+
response.on('end', function() {
58+
throw new Error('failed to post to closure compiler');
59+
});
60+
return;
61+
}
62+
63+
var data = [];
64+
response.on('data', function(chunk) {
65+
data.push(chunk);
66+
});
67+
response.on('end', function() {
68+
var stdout = Buffer.concat(data);
69+
var code = header + '\n' + stdout;
70+
fs.writeFileSync('browser-source-map-support.js', code);
71+
fs.writeFileSync('amd-test/browser-source-map-support.js', code);
72+
});
4873
});
4974
});
5075

0 commit comments

Comments
 (0)