From 2e4e13851f1ceb3672125c09502750988fe30033 Mon Sep 17 00:00:00 2001 From: CyanSalt Date: Wed, 8 Feb 2023 20:48:18 +0800 Subject: [PATCH] fix: apply swc plugins after transforming --- README.md | 2 - package-lock.json | 372 ++++++++++++---------------------------------- package.json | 2 +- src/index.ts | 75 +++++----- 4 files changed, 133 insertions(+), 318 deletions(-) diff --git a/README.md b/README.md index 1ab1976..1959c34 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ Provides legacy browsers support for the production build with [SWC](https://git This package is intended to replace [`@vitejs/plugin-legacy`](https://www.npmjs.com/package/@vitejs/plugin-legacy) in performance-sensitive situations. It is basically an implementation of [vitejs/vite#4105](https://github.com/vitejs/vite/pull/4105). -Also, for [an uncontrollable reason](https://github.com/swc-project/swc/issues/6255) this plugin does not support `@swc/core>=1.3.7` at the moment, so its dependencies are fixed to `1.3.6`. - **WARNING: This package is not yet stable. Please take special care before using it in a production environment.** --- diff --git a/package-lock.json b/package-lock.json index 8fe7e8c..950cc43 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.1", "license": "ISC", "dependencies": { - "@swc/core": "1.3.6", + "@swc/core": "^1.3.34", "browserslist": "^4.21.5", "core-js": "^3.27.2", "magic-string": "^0.27.0", @@ -1040,13 +1040,10 @@ } }, "node_modules/@swc/core": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.6.tgz", - "integrity": "sha512-L3EemOWywrxXsRQFeU50PYFwrDKOxi2RGTT+TT3CcbIszwc7qnE6vsVzEll/eK32H1veicc0EegkZgtD4PFNRA==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.34.tgz", + "integrity": "sha512-kaOCGRpciMEs2FpCUFaPJSNHgggFteOGZToM88uL5k/CEy0nU/6wzl8kUO5J+rI/8/8vN7qyhM1Ajhyj3WCSsw==", "hasInstallScript": true, - "bin": { - "swcx": "run_swcx.js" - }, "engines": { "node": ">=10" }, @@ -1055,67 +1052,22 @@ "url": "https://opencollective.com/swc" }, "optionalDependencies": { - "@swc/core-android-arm-eabi": "1.3.6", - "@swc/core-android-arm64": "1.3.6", - "@swc/core-darwin-arm64": "1.3.6", - "@swc/core-darwin-x64": "1.3.6", - "@swc/core-freebsd-x64": "1.3.6", - "@swc/core-linux-arm-gnueabihf": "1.3.6", - "@swc/core-linux-arm64-gnu": "1.3.6", - "@swc/core-linux-arm64-musl": "1.3.6", - "@swc/core-linux-x64-gnu": "1.3.6", - "@swc/core-linux-x64-musl": "1.3.6", - "@swc/core-win32-arm64-msvc": "1.3.6", - "@swc/core-win32-ia32-msvc": "1.3.6", - "@swc/core-win32-x64-msvc": "1.3.6" - } - }, - "node_modules/@swc/core-android-arm-eabi": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.3.6.tgz", - "integrity": "sha512-FQk/4cRRDoMPLgSm/1WvEqRqlSgBb6Twd5W13NYUbXJpzPGoPHhzwaCEbpGjPKG/OvAqA2NVrWquuJjhDvQyVQ==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "android" - ], - "dependencies": { - "@swc/wasm": "1.2.122" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-android-arm64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm64/-/core-android-arm64-1.3.6.tgz", - "integrity": "sha512-6qjZYatlFAN0IKhhYFsN+BaywooHFpK9/A/jMkjgIfbUoDz3wPJWZc2MDvcttgqZ+cfsSCcGeNw++H894z1zfw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "android" - ], - "dependencies": { - "@swc/wasm": "1.2.130" - }, - "engines": { - "node": ">=10" + "@swc/core-darwin-arm64": "1.3.34", + "@swc/core-darwin-x64": "1.3.34", + "@swc/core-linux-arm-gnueabihf": "1.3.34", + "@swc/core-linux-arm64-gnu": "1.3.34", + "@swc/core-linux-arm64-musl": "1.3.34", + "@swc/core-linux-x64-gnu": "1.3.34", + "@swc/core-linux-x64-musl": "1.3.34", + "@swc/core-win32-arm64-msvc": "1.3.34", + "@swc/core-win32-ia32-msvc": "1.3.34", + "@swc/core-win32-x64-msvc": "1.3.34" } }, - "node_modules/@swc/core-android-arm64/node_modules/@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - }, "node_modules/@swc/core-darwin-arm64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.6.tgz", - "integrity": "sha512-2qjaABxA7cloVTkS+uDEcVQ5buSi8de7qEv6P6InDE/iCjnI5ALyDxn7eauJJsVKimh9DyqN9sSZJ/z9U4FDUQ==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.34.tgz", + "integrity": "sha512-m7+kybVLO9uo/TiGBlf/ISmpmm27I/NrFEBGOVBF2xNOs5BY1XHHM6ddbPPckQa38C19nWeAzdJPwGzJw+qO3A==", "cpu": [ "arm64" ], @@ -1128,9 +1080,9 @@ } }, "node_modules/@swc/core-darwin-x64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.6.tgz", - "integrity": "sha512-+OtW18d2o3RUuXodB41ZDj0iRCeXNL0OxVU0jTl7iyCWDypmCzhalbaQXD/ZJxgnpGRB7/s2ZwNR/gzjXgz9VA==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.34.tgz", + "integrity": "sha512-arH7LtcOhuC1wy88qgbCO/E5NnBThbxv9HhjScDfoUPRunyvT9whEvSK0eXCXxGvDAiAtXIrW3blIrteOsQaOQ==", "cpu": [ "x64" ], @@ -1142,34 +1094,10 @@ "node": ">=10" } }, - "node_modules/@swc/core-freebsd-x64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-freebsd-x64/-/core-freebsd-x64-1.3.6.tgz", - "integrity": "sha512-f+ePNodn7ET9qEa93VMfnsPNnubWKIkn0EfxmfzJCt/abNVZ7+DyCSABfWKkexOZ8OuNyxnBCdKLL6nlizxkhQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "dependencies": { - "@swc/wasm": "1.2.130" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-freebsd-x64/node_modules/@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - }, "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.6.tgz", - "integrity": "sha512-JwdJmqKzsdq7Itg5ssKDEY9mP3AkQ+XENF6WXXlaNu1U/InqQhD0DqsFzw4TQ4LzB7lB7Wj+dv3JjKIhnHNNag==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.34.tgz", + "integrity": "sha512-+pvjXsXTBzSxEL3U9869y3Am/3yo6kQfU6VGVAebgLv+pjM+mIHywbgo1Uxw+pgpTuD38BsrtYcaPNeBICN/wA==", "cpu": [ "arm" ], @@ -1177,23 +1105,14 @@ "os": [ "linux" ], - "dependencies": { - "@swc/wasm": "1.2.130" - }, "engines": { "node": ">=10" } }, - "node_modules/@swc/core-linux-arm-gnueabihf/node_modules/@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - }, "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.6.tgz", - "integrity": "sha512-sRoPnwYFX+t95S7khi4KL2lZMZwbuzvPUf8NYmtTzfqVIseo8HD6IMgyeaQHYDfwDGF5elQGi4ALjRx2huSi0Q==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.34.tgz", + "integrity": "sha512-hOV1n1j+mDAgp19J+aeAnW4itMTWbaPbSbhEvLsNbVB00LoL6q6pUkWvCi+UbrejV6BIyyE9t7F5fU26SdKR8A==", "cpu": [ "arm64" ], @@ -1206,9 +1125,9 @@ } }, "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.6.tgz", - "integrity": "sha512-XT8vRcxGaKujiplFfuMtGRgZ3Nx611TMVLUg91alzEIe2Adtrpaumzrwv2vqVdMr4X4GBK9z0rHsqkDLPhmuaw==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.34.tgz", + "integrity": "sha512-r2/Hegp1DRSzG+kg36Tujdn+WX+gO/2wQpVj/g6RPxIPdjy53OOf+UwvJ23Ecn5ZbyJcgKhhTN6H6/ZNHQPqjQ==", "cpu": [ "arm64" ], @@ -1221,9 +1140,9 @@ } }, "node_modules/@swc/core-linux-x64-gnu": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.6.tgz", - "integrity": "sha512-nip81Ngcx8cory+FtapKhXb/rgh/pTAlvTiwJjMhsE3xcKRsbnJEPMVIoArCBV0BmYJBLWvOtpHf8B62JS7L5w==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.34.tgz", + "integrity": "sha512-jPxxAo7XlAT7bdIi49PtYN/K1TAxvpVS7otteJLhThOPPTVblIDg63U94ivp3mVQJb3WFH4KNYatEXypyvXppQ==", "cpu": [ "x64" ], @@ -1236,9 +1155,9 @@ } }, "node_modules/@swc/core-linux-x64-musl": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.6.tgz", - "integrity": "sha512-IzrQB67BY/rSZPJXWU3XzpkJqh4vYkYuOUmz1yrV/vxgPjJp/kUllfBYsHCiIedb7sjvfTt409SIN0FlPJY2+Q==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.34.tgz", + "integrity": "sha512-eJaUuhvnNtcwpK9Mil4hZTSYZqG519gX5AQQ2VZOhrWBEBJi+jM0RXAvWdESsaXpS7W0CRtbmEXqeUff6UEgpQ==", "cpu": [ "x64" ], @@ -1251,9 +1170,9 @@ } }, "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.6.tgz", - "integrity": "sha512-gLsE/4qgqTxy0OOFJKi9QRs9mVYv4yOXSwPB2Rb+grOmNnG+Ds2LWqGEaABKDErnUtTQiOzLpdwesNZxeJgMhA==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.34.tgz", + "integrity": "sha512-KFdeC5bXDcxIQ/1J5Pjj8BOblRFjh89TTJxujxAhKdoD1k0NV9BKEZACja2cTBz0hWD4cYlBX0cESVdL2rkm3w==", "cpu": [ "arm64" ], @@ -1261,23 +1180,14 @@ "os": [ "win32" ], - "dependencies": { - "@swc/wasm": "1.2.130" - }, "engines": { "node": ">=10" } }, - "node_modules/@swc/core-win32-arm64-msvc/node_modules/@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - }, "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.6.tgz", - "integrity": "sha512-0Jr7KMGEPapYGni+97oNOeVP7edBwjMGQ9HsJUUN1uIE7fALQ+zVGuwbc+22myql2Uhh5V5hZx5xtVraqLVMHw==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.34.tgz", + "integrity": "sha512-MgWkAQDiWIHfJL5b5aoogenGIt3qcqBSvwLnDQqSWEhkodZjHyCWpQFuaa7Y6ER3pKUIZ5kR8O9aAkDmF39awQ==", "cpu": [ "ia32" ], @@ -1285,23 +1195,14 @@ "os": [ "win32" ], - "dependencies": { - "@swc/wasm": "1.2.130" - }, "engines": { "node": ">=10" } }, - "node_modules/@swc/core-win32-ia32-msvc/node_modules/@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - }, "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.6.tgz", - "integrity": "sha512-O3F/jxqaFwGq9XxYeCIVRCDIR4+GdSBu/5io6TkN8O5QLqB3/KOJVDn6TALtbL6ClwjUwZt66HKnYeSx19j2Ow==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.34.tgz", + "integrity": "sha512-UhaikgVRYBZZdMI7Zo4/eUyYLnjGrC6QAn9aggt1+PiFIM9tXpX8aONUL3LoLkhQhd+6iWygfQ298RRxjKAKuw==", "cpu": [ "x64" ], @@ -1313,12 +1214,6 @@ "node": ">=10" } }, - "node_modules/@swc/wasm": { - "version": "1.2.122", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.122.tgz", - "integrity": "sha512-sM1VCWQxmNhFtdxME+8UXNyPNhxNu7zdb6ikWpz0YKAQQFRGT5ThZgJrubEpah335SUToNg8pkdDF7ibVCjxbQ==", - "optional": true - }, "node_modules/@szmarczak/http-timer": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz", @@ -10276,165 +10171,80 @@ "dev": true }, "@swc/core": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.6.tgz", - "integrity": "sha512-L3EemOWywrxXsRQFeU50PYFwrDKOxi2RGTT+TT3CcbIszwc7qnE6vsVzEll/eK32H1veicc0EegkZgtD4PFNRA==", - "requires": { - "@swc/core-android-arm-eabi": "1.3.6", - "@swc/core-android-arm64": "1.3.6", - "@swc/core-darwin-arm64": "1.3.6", - "@swc/core-darwin-x64": "1.3.6", - "@swc/core-freebsd-x64": "1.3.6", - "@swc/core-linux-arm-gnueabihf": "1.3.6", - "@swc/core-linux-arm64-gnu": "1.3.6", - "@swc/core-linux-arm64-musl": "1.3.6", - "@swc/core-linux-x64-gnu": "1.3.6", - "@swc/core-linux-x64-musl": "1.3.6", - "@swc/core-win32-arm64-msvc": "1.3.6", - "@swc/core-win32-ia32-msvc": "1.3.6", - "@swc/core-win32-x64-msvc": "1.3.6" - } - }, - "@swc/core-android-arm-eabi": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.3.6.tgz", - "integrity": "sha512-FQk/4cRRDoMPLgSm/1WvEqRqlSgBb6Twd5W13NYUbXJpzPGoPHhzwaCEbpGjPKG/OvAqA2NVrWquuJjhDvQyVQ==", - "optional": true, - "requires": { - "@swc/wasm": "1.2.122" - } - }, - "@swc/core-android-arm64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm64/-/core-android-arm64-1.3.6.tgz", - "integrity": "sha512-6qjZYatlFAN0IKhhYFsN+BaywooHFpK9/A/jMkjgIfbUoDz3wPJWZc2MDvcttgqZ+cfsSCcGeNw++H894z1zfw==", - "optional": true, - "requires": { - "@swc/wasm": "1.2.130" - }, - "dependencies": { - "@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - } + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.34.tgz", + "integrity": "sha512-kaOCGRpciMEs2FpCUFaPJSNHgggFteOGZToM88uL5k/CEy0nU/6wzl8kUO5J+rI/8/8vN7qyhM1Ajhyj3WCSsw==", + "requires": { + "@swc/core-darwin-arm64": "1.3.34", + "@swc/core-darwin-x64": "1.3.34", + "@swc/core-linux-arm-gnueabihf": "1.3.34", + "@swc/core-linux-arm64-gnu": "1.3.34", + "@swc/core-linux-arm64-musl": "1.3.34", + "@swc/core-linux-x64-gnu": "1.3.34", + "@swc/core-linux-x64-musl": "1.3.34", + "@swc/core-win32-arm64-msvc": "1.3.34", + "@swc/core-win32-ia32-msvc": "1.3.34", + "@swc/core-win32-x64-msvc": "1.3.34" } }, "@swc/core-darwin-arm64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.6.tgz", - "integrity": "sha512-2qjaABxA7cloVTkS+uDEcVQ5buSi8de7qEv6P6InDE/iCjnI5ALyDxn7eauJJsVKimh9DyqN9sSZJ/z9U4FDUQ==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.34.tgz", + "integrity": "sha512-m7+kybVLO9uo/TiGBlf/ISmpmm27I/NrFEBGOVBF2xNOs5BY1XHHM6ddbPPckQa38C19nWeAzdJPwGzJw+qO3A==", "optional": true }, "@swc/core-darwin-x64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.6.tgz", - "integrity": "sha512-+OtW18d2o3RUuXodB41ZDj0iRCeXNL0OxVU0jTl7iyCWDypmCzhalbaQXD/ZJxgnpGRB7/s2ZwNR/gzjXgz9VA==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.34.tgz", + "integrity": "sha512-arH7LtcOhuC1wy88qgbCO/E5NnBThbxv9HhjScDfoUPRunyvT9whEvSK0eXCXxGvDAiAtXIrW3blIrteOsQaOQ==", "optional": true }, - "@swc/core-freebsd-x64": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-freebsd-x64/-/core-freebsd-x64-1.3.6.tgz", - "integrity": "sha512-f+ePNodn7ET9qEa93VMfnsPNnubWKIkn0EfxmfzJCt/abNVZ7+DyCSABfWKkexOZ8OuNyxnBCdKLL6nlizxkhQ==", - "optional": true, - "requires": { - "@swc/wasm": "1.2.130" - }, - "dependencies": { - "@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - } - } - }, "@swc/core-linux-arm-gnueabihf": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.6.tgz", - "integrity": "sha512-JwdJmqKzsdq7Itg5ssKDEY9mP3AkQ+XENF6WXXlaNu1U/InqQhD0DqsFzw4TQ4LzB7lB7Wj+dv3JjKIhnHNNag==", - "optional": true, - "requires": { - "@swc/wasm": "1.2.130" - }, - "dependencies": { - "@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - } - } + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.34.tgz", + "integrity": "sha512-+pvjXsXTBzSxEL3U9869y3Am/3yo6kQfU6VGVAebgLv+pjM+mIHywbgo1Uxw+pgpTuD38BsrtYcaPNeBICN/wA==", + "optional": true }, "@swc/core-linux-arm64-gnu": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.6.tgz", - "integrity": "sha512-sRoPnwYFX+t95S7khi4KL2lZMZwbuzvPUf8NYmtTzfqVIseo8HD6IMgyeaQHYDfwDGF5elQGi4ALjRx2huSi0Q==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.34.tgz", + "integrity": "sha512-hOV1n1j+mDAgp19J+aeAnW4itMTWbaPbSbhEvLsNbVB00LoL6q6pUkWvCi+UbrejV6BIyyE9t7F5fU26SdKR8A==", "optional": true }, "@swc/core-linux-arm64-musl": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.6.tgz", - "integrity": "sha512-XT8vRcxGaKujiplFfuMtGRgZ3Nx611TMVLUg91alzEIe2Adtrpaumzrwv2vqVdMr4X4GBK9z0rHsqkDLPhmuaw==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.34.tgz", + "integrity": "sha512-r2/Hegp1DRSzG+kg36Tujdn+WX+gO/2wQpVj/g6RPxIPdjy53OOf+UwvJ23Ecn5ZbyJcgKhhTN6H6/ZNHQPqjQ==", "optional": true }, "@swc/core-linux-x64-gnu": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.6.tgz", - "integrity": "sha512-nip81Ngcx8cory+FtapKhXb/rgh/pTAlvTiwJjMhsE3xcKRsbnJEPMVIoArCBV0BmYJBLWvOtpHf8B62JS7L5w==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.34.tgz", + "integrity": "sha512-jPxxAo7XlAT7bdIi49PtYN/K1TAxvpVS7otteJLhThOPPTVblIDg63U94ivp3mVQJb3WFH4KNYatEXypyvXppQ==", "optional": true }, "@swc/core-linux-x64-musl": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.6.tgz", - "integrity": "sha512-IzrQB67BY/rSZPJXWU3XzpkJqh4vYkYuOUmz1yrV/vxgPjJp/kUllfBYsHCiIedb7sjvfTt409SIN0FlPJY2+Q==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.34.tgz", + "integrity": "sha512-eJaUuhvnNtcwpK9Mil4hZTSYZqG519gX5AQQ2VZOhrWBEBJi+jM0RXAvWdESsaXpS7W0CRtbmEXqeUff6UEgpQ==", "optional": true }, "@swc/core-win32-arm64-msvc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.6.tgz", - "integrity": "sha512-gLsE/4qgqTxy0OOFJKi9QRs9mVYv4yOXSwPB2Rb+grOmNnG+Ds2LWqGEaABKDErnUtTQiOzLpdwesNZxeJgMhA==", - "optional": true, - "requires": { - "@swc/wasm": "1.2.130" - }, - "dependencies": { - "@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - } - } + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.34.tgz", + "integrity": "sha512-KFdeC5bXDcxIQ/1J5Pjj8BOblRFjh89TTJxujxAhKdoD1k0NV9BKEZACja2cTBz0hWD4cYlBX0cESVdL2rkm3w==", + "optional": true }, "@swc/core-win32-ia32-msvc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.6.tgz", - "integrity": "sha512-0Jr7KMGEPapYGni+97oNOeVP7edBwjMGQ9HsJUUN1uIE7fALQ+zVGuwbc+22myql2Uhh5V5hZx5xtVraqLVMHw==", - "optional": true, - "requires": { - "@swc/wasm": "1.2.130" - }, - "dependencies": { - "@swc/wasm": { - "version": "1.2.130", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.130.tgz", - "integrity": "sha512-rNcJsBxS70+pv8YUWwf5fRlWX6JoY/HJc25HD/F8m6Kv7XhJdqPPMhyX6TKkUBPAG7TWlZYoxa+rHAjPy4Cj3Q==", - "optional": true - } - } - }, - "@swc/core-win32-x64-msvc": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.6.tgz", - "integrity": "sha512-O3F/jxqaFwGq9XxYeCIVRCDIR4+GdSBu/5io6TkN8O5QLqB3/KOJVDn6TALtbL6ClwjUwZt66HKnYeSx19j2Ow==", + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.34.tgz", + "integrity": "sha512-MgWkAQDiWIHfJL5b5aoogenGIt3qcqBSvwLnDQqSWEhkodZjHyCWpQFuaa7Y6ER3pKUIZ5kR8O9aAkDmF39awQ==", "optional": true }, - "@swc/wasm": { - "version": "1.2.122", - "resolved": "https://registry.npmjs.org/@swc/wasm/-/wasm-1.2.122.tgz", - "integrity": "sha512-sM1VCWQxmNhFtdxME+8UXNyPNhxNu7zdb6ikWpz0YKAQQFRGT5ThZgJrubEpah335SUToNg8pkdDF7ibVCjxbQ==", + "@swc/core-win32-x64-msvc": { + "version": "1.3.34", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.34.tgz", + "integrity": "sha512-UhaikgVRYBZZdMI7Zo4/eUyYLnjGrC6QAn9aggt1+PiFIM9tXpX8aONUL3LoLkhQhd+6iWygfQ298RRxjKAKuw==", "optional": true }, "@szmarczak/http-timer": { diff --git a/package.json b/package.json index a4913d0..84d73af 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/CyanSalt/vite-plugin-legacy-swc#readme", "dependencies": { - "@swc/core": "1.3.6", + "@swc/core": "^1.3.34", "browserslist": "^4.21.5", "core-js": "^3.27.2", "magic-string": "^0.27.0", diff --git a/src/index.ts b/src/index.ts index 8bba6be..7759b34 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { createHash } from 'crypto' import path from 'path' import type { EnvConfig, + Options as SwcOptions, Plugin as SwcPlugin, Statement, } from '@swc/core' @@ -432,18 +433,13 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { // transform the legacy chunk with @swc/core const sourceMaps = Boolean(resolvedConfig.build.sourcemap) const swc = await loadSwc() - const result = await swc.transform(raw, { + const swcOptions: SwcOptions = { swcrc: false, configFile: false, sourceMaps, - inputSourceMap: undefined, // sourceMaps ? chunk.map : undefined, `.map` TODO: moved to OutputChunk? env: createSwcEnvOptions(targets, { needPolyfills, }), - plugin: swc.plugins([ - recordAndRemovePolyfillSwcPlugin(legacyPolyfills), - wrapIIFESwcPlugin(), - ]), jsc: { transform: { optimizer: { @@ -453,6 +449,19 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { }, }, }, + } + const transformResult = await swc.transform(raw, { + ...swcOptions, + inputSourceMap: undefined, // sourceMaps ? chunk.map : undefined, `.map` TODO: moved to OutputChunk? + }) + const plugin = swc.plugins([ + recordAndRemovePolyfillSwcPlugin(legacyPolyfills), + wrapIIFESwcPlugin(), + ]) + const ast = await swc.parse(transformResult.code) + const result = await swc.print(plugin(ast), { + ...swcOptions, + inputSourceMap: transformResult.map, }) return result @@ -609,25 +618,23 @@ export async function detectPolyfills( list: Set, ): Promise { const swc = await loadSwc() - await swc.transform(code, { + const result = await swc.transform(code, { swcrc: false, configFile: false, env: createSwcEnvOptions(targets), - plugin(program) { - for (const node of program.body) { - if (node.type === 'ImportDeclaration') { - const source = node.source.value - if ( - source.startsWith('core-js/') - || source.startsWith('regenerator-runtime/') - ) { - list.add(source) - } - } - } - return program - }, }) + const ast = await swc.parse(result.code) + for (const node of ast.body) { + if (node.type === 'ImportDeclaration') { + const source = node.source.value + if ( + source.startsWith('core-js/') + || source.startsWith('regenerator-runtime/') + ) { + list.add(source) + } + } + } } function createSwcEnvOptions( @@ -805,27 +812,27 @@ function wrapIIFESwcPlugin(): SwcPlugin { { type: 'ExpressionStatement', span: { start: 0, end: 0, ctxt: 0 }, - expression: { type: 'CallExpression', span: { start: 0, end: 0, ctxt: 0 }, - - arguments: [], callee: { - type: 'FunctionExpression', + type: 'ParenthesisExpression', span: { start: 0, end: 0, ctxt: 0 }, - - params: [], - - async: false, - generator: false, - - body: { - stmts: program.body as Statement[], - type: 'BlockStatement', + expression: { + type: 'FunctionExpression', + params: [], + decorators: [], span: { start: 0, end: 0, ctxt: 0 }, + body: { + type: 'BlockStatement', + span: { start: 0, end: 0, ctxt: 0 }, + stmts: program.body as Statement[], + }, + generator: false, + async: false, }, }, + arguments: [], }, }, ]