From c05c01463b9f24d6e9c13d76efa03787f753d4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ng=C3=B4=20=C4=90=E1=BB=A9c=20Anh?= <75556609+DuCanhGH@users.noreply.github.com> Date: Fri, 30 Jun 2023 20:48:20 +0700 Subject: [PATCH] Publish packages (#48) --- .changeset/friendly-rice-attack.md | 7 ------- packages/next-pwa/CHANGELOG.md | 8 ++++++++ packages/next-pwa/package.json | 2 +- packages/utils/src/resolve-swc.ts | 2 +- packages/utils/src/swc-minify.ts | 15 ++++++++++++--- 5 files changed, 22 insertions(+), 12 deletions(-) delete mode 100644 .changeset/friendly-rice-attack.md diff --git a/.changeset/friendly-rice-attack.md b/.changeset/friendly-rice-attack.md deleted file mode 100644 index 22905540..00000000 --- a/.changeset/friendly-rice-attack.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"@ducanh2912/next-pwa": patch ---- - -fix(next-pwa): fixed swc-minify crashing build when all swc sources can't be resolved - -- The new behaviour should now be using `terser-webpack-plugin`'s `terserMinify` when they can't be found. diff --git a/packages/next-pwa/CHANGELOG.md b/packages/next-pwa/CHANGELOG.md index e5f5ae37..a8e5a599 100644 --- a/packages/next-pwa/CHANGELOG.md +++ b/packages/next-pwa/CHANGELOG.md @@ -1,5 +1,13 @@ # @ducanh2912/next-pwa +## 9.1.3 + +### Patch Changes + +- [`4d13948`](https://github.com/DuCanhGH/next-pwa/commit/4d13948375d144a89bed858d36aee561bc987ca4) Thanks [@DuCanhGH](https://github.com/DuCanhGH)! - fix(next-pwa): fixed swc-minify crashing build when all swc sources can't be resolved + + - The new behaviour should now be using `terser-webpack-plugin`'s `terserMinify` when they can't be found. + ## 9.1.2 ### Patch Changes diff --git a/packages/next-pwa/package.json b/packages/next-pwa/package.json index 1b5110e3..1ad709ec 100644 --- a/packages/next-pwa/package.json +++ b/packages/next-pwa/package.json @@ -1,6 +1,6 @@ { "name": "@ducanh2912/next-pwa", - "version": "9.1.2", + "version": "9.1.3", "type": "module", "description": "PWA for Next.js, powered by Workbox.", "repository": "https://github.com/DuCanhGH/next-pwa", diff --git a/packages/utils/src/resolve-swc.ts b/packages/utils/src/resolve-swc.ts index 39c0c131..daa67e88 100644 --- a/packages/utils/src/resolve-swc.ts +++ b/packages/utils/src/resolve-swc.ts @@ -3,7 +3,7 @@ import type { Compiler } from "@swc/core"; export const resolveSwc = () => { let swc: Compiler | undefined; - for (const swcSource of ["next/dist/build/swc", "@swc/core"]) { + for (const swcSource of ["@swc/core", "next/dist/build/swc"]) { try { swc = require(swcSource); break; diff --git a/packages/utils/src/swc-minify.ts b/packages/utils/src/swc-minify.ts index b25e1d1b..af61d726 100644 --- a/packages/utils/src/swc-minify.ts +++ b/packages/utils/src/swc-minify.ts @@ -50,14 +50,23 @@ export const swcMinify = async ( }; }; + const fallbackToTerser = () => { + return ( + require("terser-webpack-plugin") as typeof TerserWebpack + ).terserMinify(input, sourceMap, minimizerOptions, false); + }; + let swc: Compiler; try { swc = resolveSwc(); } catch { // swc might not be available, fallback to terser - return ( - require("terser-webpack-plugin") as typeof TerserWebpack - ).terserMinify(input, sourceMap, minimizerOptions, false); + return fallbackToTerser(); + } + + if (!swc.minify) { + // turns out that older versions of Next had `next/dist/build/swc` with no `swc.minify`... + return fallbackToTerser(); } // Copy `swc` options