From 9b2dc0e4e6228f6eafac405d199474274a647a2d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Mar 2022 21:22:52 +0800 Subject: [PATCH] Build: Fix build script for `next` branch (#12483) --- scripts/build/config.mjs | 5 +++-- scripts/build/esbuild-plugins/replace-module.mjs | 6 +++++- src/cli/format.js | 8 ++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/build/config.mjs b/scripts/build/config.mjs index 919267ac6..2884b8cc0 100644 --- a/scripts/build/config.mjs +++ b/scripts/build/config.mjs @@ -30,9 +30,10 @@ To reduce the bundle size, replace the entry with smaller files. We can switch to deep require once https://github.com/kpdecker/jsdiff/pull/351 get merged */ +const diffPackageDirectory = path.dirname(require.resolve("diff/package.json")); const replaceDiffPackageEntry = (file) => ({ - [require.resolve("diff")]: path.join( - path.dirname(require.resolve("diff/package.json")), + [path.join(diffPackageDirectory, "lib/index.mjs")]: path.join( + diffPackageDirectory, file ), }); diff --git a/scripts/build/esbuild-plugins/replace-module.mjs b/scripts/build/esbuild-plugins/replace-module.mjs index 3e5e22b22..1b06ec786 100644 --- a/scripts/build/esbuild-plugins/replace-module.mjs +++ b/scripts/build/esbuild-plugins/replace-module.mjs @@ -29,7 +29,11 @@ export default function esbuildPluginReplaceModule(replacements = {}) { build.onResolve({ filter: /./ }, async (args) => { if ( - !(args.kind === "require-call" || args.kind === "import-statement") || + !( + args.kind === "require-call" || + args.kind === "import-statement" || + args.kind === "dynamic-import" + ) || args.namespace !== "file" ) { return; diff --git a/src/cli/format.js b/src/cli/format.js index 8d02adac2..3182d259b 100644 --- a/src/cli/format.js +++ b/src/cli/format.js @@ -11,13 +11,13 @@ import isTTY from "./is-tty.js"; const { getStdin } = thirdParty; const { createIgnorer, errors } = prettierInternal; -let diffModule; +let createTwoFilesPatch; async function diff(a, b) { - if (!diffModule) { - ({ default: diffModule } = await import("diff")); + if (!createTwoFilesPatch) { + ({ createTwoFilesPatch } = await import("diff")); } - return diffModule.createTwoFilesPatch("", "", a, b, "", "", { context: 2 }); + return createTwoFilesPatch("", "", a, b, "", "", { context: 2 }); } function handleError(context, filename, error, printedFilename) {