From 3f79f92df409259087cd5e9e6d89422de73c7517 Mon Sep 17 00:00:00 2001 From: tada5hi Date: Sun, 5 Nov 2023 20:12:07 +0100 Subject: [PATCH] feat: allow passing ProgramFiles(x86)=C:\Program Files (x86) CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files NUMBER_OF_PROCESSORS=24 PROCESSOR_LEVEL=25 TERMINAL_EMULATOR=JetBrains-JediTerm USERDOMAIN_ROAMINGPROFILE=WG HOMESHARE=\\192.168.27.4\Users\Data\Peter PROGRAMFILES=C:\Program Files MSYSTEM=MINGW64 ChocolateyInstall=C:\ProgramData\chocolatey PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW OS=Windows_NT NVM_SYMLINK=C:\Program Files\nodejs TERM_SESSION_ID=2dedab26-6543-4194-9405-65cace15f335 HOMEDRIVE=M: GNUPGHOME=/c//Data/.gnupg USERDOMAIN=WG USERDNSDOMAIN=WG.LOCAL PWD=/c/Data/Projects/tada5hi/forks/rollup-plugins USERPROFILE=C:\Users\Peter OneDriveConsumer=C:\Users\Peter\OneDrive AMDRMPATH=C:\Program Files\AMD\RyzenMaster\ ALLUSERSPROFILE=C:\ProgramData CommonProgramW6432=C:\Program Files\Common Files HOME=/c/Users/Peter USERNAME=Peter PLINK_PROTOCOL=ssh OneDrive=C:\Users\Peter\OneDrive COMSPEC=C:\WINDOWS\system32\cmd.exe APPDATA=C:\Users\Peter\AppData\Roaming SYSTEMROOT=C:\WINDOWS LOCALAPPDATA=C:\Users\Peter\AppData\Local __COMPAT_LAYER=Installer COMPUTERNAME=PETER-PC PYSPARK_PYTHON=C:\Data\services\spark TERM=xterm-256color NVM_HOME=C:\Users\Peter\AppData\Roaming\nvm HADOOP_HOME=C:\Data\services\spark LOGONSERVER=\\IVY PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules TEMP=/tmp SHLVL=0 PROCESSOR_REVISION=2100 DriverData=C:\Windows\System32\Drivers\DriverData COMMONPROGRAMFILES=C:\Program Files\Common Files IDEA_INITIAL_DIRECTORY=C:\Users\Peter\AppData\Local\JetBrains\Toolbox\apps\WebStorm\ch-1\232.10203.14\bin EXEPATH=C:\Program Files\Git\bin PROCESSOR_IDENTIFIER=AMD64 Family 25 Model 33 Stepping 0, AuthenticAMD PS1=\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ FIG_JETBRAINS_SHELL_INTEGRATION=1 HOMEPATH=\ TMP=/tmp PATH=/mingw64/bin:/usr/bin:/c/Users/Peter/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/c/Python310/Scripts:/c/Python310:/c/Python39/Scripts:/c/Python39:/c/Python38/Scripts:/c/Python38:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/ProgramData/chocolatey/bin:/c/Program Files/PHP/7.4:/c/Program Files/dotnet:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/ProgramData/ComposerSetup/bin:/c/Program Files/Nginx/1.19.2:/c/Program Files (x86)/Yarn/bin:/c/Data/services/openjdk-15/jdk-15/bin:/c/Users/Peter/AppData/Roaming/nvm:/c/Program Files/nodejs:/c/cygwin64/bin:/c/Program Files/nodejs:/c/Program Files/GitHub CLI:/cmd:/c/Program Files/Docker/Docker/resources/bin:/c/Users/Peter/.cargo/bin:/c/Users/Peter/AppData/Local/Microsoft/WindowsApps://192.168.27.4/Users/Data/Peter/AppData/Roaming/npm:/c/Users/Peter/AppData/Roaming/Composer/vendor/bin:/c/Users/Peter/AppData/Local/Yarn/bin:/c/Users/Peter/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/Peter/AppData/Local/gitkraken/bin:/c/Data/services/spark/bin:/c/Users/Peter/AppData/Local/JetBrains/Toolbox/scripts:/c/Users/Peter/AppData/Roaming/npm:/c/Users/Peter/AppData/Local/GitHubDesktop/bin:/c/Users/Peter/AppData/Local/Programs/MiKTeX/miktex/bin/x64:/c/Users/Peter/AppData/Local/Pandoc:/c/Users/Peter/.deno/bin:/c/Data/Projects/tada5hi/forks/rollup-plugins/node_modules/.bin ProgramW6432=C:\Program Files WINDIR=C:\WINDOWS PROCESSOR_ARCHITECTURE=AMD64 PUBLIC=C:\Users\Public SYSTEMDRIVE=C: ProgramData=C:\ProgramData ChocolateyLastPathUpdate=132558807520336500 _=/usr/bin/env property as option --- packages/swc/src/module.ts | 10 +++++++-- packages/swc/test/test.js | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/packages/swc/src/module.ts b/packages/swc/src/module.ts index d39d73462..84933c172 100644 --- a/packages/swc/src/module.ts +++ b/packages/swc/src/module.ts @@ -9,7 +9,7 @@ import type { Options } from './type'; export function swc(input: Options = {}): Plugin { const filter = createFilter(input.include, input.exclude); - const swcOptions: SWCOptions = merge({}, input.swc || {}, { + const defaults: SWCOptions = { jsc: { target: 'es2020', parser: { @@ -22,7 +22,13 @@ export function swc(input: Options = {}): Plugin { }, loose: true } - }); + }; + + if (input.swc && input.swc.env) { + delete defaults.jsc?.target; + } + + const swcOptions: SWCOptions = merge({}, input.swc || {}, defaults); return { name: 'swc', diff --git a/packages/swc/test/test.js b/packages/swc/test/test.js index a98c54134..b7eca0495 100644 --- a/packages/swc/test/test.js +++ b/packages/swc/test/test.js @@ -83,3 +83,47 @@ test.serial('work with source map', async (t) => { t.is(sourceMap.fileName, 'unminified.js.map'); t.is(sourceMap.type, 'asset'); }); + +test.serial('allow passing swc.env', async (t) => { + const bundle = await rollup({ + input: 'test/fixtures/export-default.js', + plugins: [ + swc({ + env: { + targets: ['es2020'], + shippedProposals: true + } + }) + ] + }); + const result = await bundle.generate({ format: 'cjs' }); + t.is(result.output.length, 1); + const [output] = result.output; + t.is(output.code, "'use strict';\n\nvar exportDefault = 5;\n\nmodule.exports = exportDefault;\n"); +}); + +test.serial('catch error on jsc and env option', async (t) => { + try { + const bundle = await rollup({ + input: 'test/fixtures/export-default.js', + plugins: [ + swc({ + swc: { + jsc: { + target: 'es2020' + }, + env: { + targets: ['es2022'], + shippedProposals: true + } + } + }) + ] + }); + + await bundle.generate({ format: 'cjs' }); + t.is(0, 1); + } catch (e) { + t.is(e.message, '`env` and `jsc.target` cannot be used together'); + } +});