Fix encoding in postcss-parser build (#8534)
Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com> Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
2 files changed
+29
-12
No files matched your search
+25
-12
@@ -4,6 +4,7 @@ const chalk = require("chalk");
|
||||
const execa = require("execa");
|
||||
const minimist = require("minimist");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const stringWidth = require("string-width");
|
||||
|
||||
const bundler = require("./bundler");
|
||||
@@ -36,21 +37,33 @@ function fitTerminal(input) {
|
||||
}
|
||||
|
||||
async function createBundle(bundleConfig, cache) {
|
||||
const { output } = bundleConfig;
|
||||
const { output, target } = bundleConfig;
|
||||
process.stdout.write(fitTerminal(output));
|
||||
|
||||
return bundler(bundleConfig, cache)
|
||||
.catch((error) => {
|
||||
console.log(FAIL + "\n");
|
||||
handleError(error);
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.cached) {
|
||||
console.log(CACHED);
|
||||
} else {
|
||||
console.log(OK);
|
||||
try {
|
||||
const { cached } = await bundler(bundleConfig, cache);
|
||||
|
||||
if (cached) {
|
||||
console.log(CACHED);
|
||||
return;
|
||||
}
|
||||
|
||||
// Files including U+FFEE can't load in Chrome Extension
|
||||
// `prettier-chrome-extension` https://github.com/prettier/prettier-chrome-extension
|
||||
// details https://github.com/prettier/prettier/pull/8534
|
||||
if (target === "universal") {
|
||||
const file = path.join("dist", output);
|
||||
const content = fs.readFileSync(file, "utf8");
|
||||
if (content.includes("\ufffe")) {
|
||||
throw new Error("Bundled umd file should not have U+FFFE character.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log(OK);
|
||||
} catch (error) {
|
||||
console.log(FAIL + "\n");
|
||||
handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
function handleError(error) {
|
||||
|
||||
@@ -47,6 +47,10 @@ const parsers = [
|
||||
// prevent terser generate extra .LICENSE file
|
||||
extractComments: false,
|
||||
terserOptions: {
|
||||
// prevent U+FFFE in the output
|
||||
output: {
|
||||
ascii_only: true,
|
||||
},
|
||||
mangle: {
|
||||
// postcss need keep_fnames when minify
|
||||
keep_fnames: true,
|
||||
|
||||
Reference in new issue
Block a user