mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
The old version of prettier we were using didn't support the Flow syntax to access properties in a type using `SomeType['prop']`. This updates `prettier` and `rollup-plugin-prettier` to the latest versions. I added the prettier config `arrowParens: "avoid"` to reduce the diff size as the default has changed in Prettier 2.0. The largest amount of changes comes from function expressions now having a space. This doesn't have an option to preserve the old behavior, so we have to update this.
36 lines
993 B
JavaScript
36 lines
993 B
JavaScript
'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};
|
|
},
|
|
};
|
|
};
|