From b3ea6799589d863972d858e24b4341530aa1df2e Mon Sep 17 00:00:00 2001 From: Sibiraj <20282546+sibiraj-s@users.noreply.github.com> Date: Fri, 12 Jun 2020 06:42:42 +0530 Subject: [PATCH] Fix encoding in postcss-parser build (#8534) Co-authored-by: Georgii Dolzhykov Co-authored-by: fisker --- scripts/build/build.js | 37 +++++++++++++++++++++++++------------ scripts/build/config.js | 4 ++++ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/scripts/build/build.js b/scripts/build/build.js index e5df72709..feb53d0a8 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -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) { diff --git a/scripts/build/config.js b/scripts/build/config.js index 109e723f6..0e43d8a62 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -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,