-
Notifications
You must be signed in to change notification settings - Fork 46.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Java version of Google Closure Compiler (#12800)
* makes closure compiler threaded * Dans PR with a closure compiler java version * Remove unused dep * Pin GCC * Prettier * Nit rename * Fix error handling * Name plugins consistently * Fix lint * Maybe this works? * or this * AppVeyor * Fix lint
- Loading branch information
Showing
8 changed files
with
71 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const ClosureCompiler = require('google-closure-compiler').compiler; | ||
const {promisify} = require('util'); | ||
const fs = require('fs'); | ||
const tmp = require('tmp'); | ||
const writeFileAsync = promisify(fs.writeFile); | ||
|
||
function compile(flags) { | ||
return new Promise((resolve, reject) => { | ||
const closureCompiler = new ClosureCompiler(flags); | ||
closureCompiler.run(function(exitCode, stdOut, stdErr) { | ||
if (!stdErr) { | ||
resolve(stdOut); | ||
} else { | ||
reject(new Error(stdErr)); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = function closure(flags = {}) { | ||
return { | ||
name: 'scripts/rollup/plugins/closure-plugin', | ||
async transformBundle(code) { | ||
const inputFile = tmp.fileSync(); | ||
const tempPath = inputFile.name; | ||
flags = Object.assign({}, flags, {js: tempPath}); | ||
await writeFileAsync(tempPath, code, 'utf8'); | ||
const compiledCode = await compile(flags); | ||
inputFile.removeCallback(); | ||
return {code: compiledCode}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters