/
githubmr
/
facebook-react
Обзор
Документация
Войти
/
githubmr
/
facebook-react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
v17.0.2
scripts/rollup/plugins/closure-plugin.js
35 строк
992 B
Sebastian Markbåge
Upgrade Closure Compiler (#19041)
29 май 2020, 19:17
Не верифицирован
29 май 2020, 19:17
c03b866
Код
Авторство
О чём код?
'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 renderChunk(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}; }, }; };