diff --git a/packages/vite/package.json b/packages/vite/package.json index 7ce565f9e29505..4bcf629a1f358e 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -66,7 +66,7 @@ }, "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!", "dependencies": { - "esbuild": "^0.17.5", + "esbuild": "^0.18.2", "postcss": "^8.4.24", "rollup": "^3.21.0" }, diff --git a/packages/vite/src/node/plugins/esbuild.ts b/packages/vite/src/node/plugins/esbuild.ts index 08e6c7c7d955a3..adcc90f83582d8 100644 --- a/packages/vite/src/node/plugins/esbuild.ts +++ b/packages/vite/src/node/plugins/esbuild.ts @@ -56,6 +56,7 @@ type TSConfigJSON = { extends?: string compilerOptions?: { alwaysStrict?: boolean + experimentalDecorators?: boolean importsNotUsedAsValues?: 'remove' | 'preserve' | 'error' jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev' jsxFactory?: string @@ -64,6 +65,7 @@ type TSConfigJSON = { preserveValueImports?: boolean target?: string useDefineForClassFields?: boolean + verbatimModuleSyntax?: boolean } [key: string]: any } @@ -101,6 +103,7 @@ export async function transformWithEsbuild( // https://esbuild.github.io/content-types/#tsconfig-json const meaningfulFields: Array = [ 'alwaysStrict', + 'experimentalDecorators', 'importsNotUsedAsValues', 'jsx', 'jsxFactory', @@ -109,6 +112,7 @@ export async function transformWithEsbuild( 'preserveValueImports', 'target', 'useDefineForClassFields', + 'verbatimModuleSyntax', ] const compilerOptionsForFile: TSCompilerOptions = {} if (loader === 'ts' || loader === 'tsx') { @@ -128,20 +132,6 @@ export async function transformWithEsbuild( ...tsconfigRaw?.compilerOptions, } - // esbuild derives `useDefineForClassFields` from `target` instead of `tsconfig.compilerOptions.target` - // https://github.com/evanw/esbuild/issues/2584 - // but we want `useDefineForClassFields` to be derived from `tsconfig.compilerOptions.target` - if (compilerOptions.useDefineForClassFields === undefined) { - const lowercaseTarget = compilerOptions.target?.toLowerCase() ?? 'es3' - if (lowercaseTarget.startsWith('es')) { - const esVersion = lowercaseTarget.slice(2) - compilerOptions.useDefineForClassFields = - esVersion === 'next' || +esVersion >= 2022 - } else { - compilerOptions.useDefineForClassFields = false - } - } - // esbuild uses tsconfig fields when both the normal options and tsconfig was set // but we want to prioritize the normal options if (options) { @@ -149,7 +139,6 @@ export async function transformWithEsbuild( options.jsxFactory && (compilerOptions.jsxFactory = undefined) options.jsxFragment && (compilerOptions.jsxFragmentFactory = undefined) options.jsxImportSource && (compilerOptions.jsxImportSource = undefined) - options.target && (compilerOptions.target = undefined) } tsconfigRaw = { @@ -158,19 +147,22 @@ export async function transformWithEsbuild( } } - const resolvedOptions = { + const resolvedOptions: TransformOptions = { sourcemap: true, // ensure source file name contains full query sourcefile: filename, ...options, loader, tsconfigRaw, - } as ESBuildOptions + } // Some projects in the ecosystem are calling this function with an ESBuildOptions // object and esbuild throws an error for extra fields + // @ts-expect-error include exists in ESBuildOptions delete resolvedOptions.include + // @ts-expect-error exclude exists in ESBuildOptions delete resolvedOptions.exclude + // @ts-expect-error jsxInject exists in ESBuildOptions delete resolvedOptions.jsxInject try { @@ -199,6 +191,10 @@ export async function transformWithEsbuild( if (e.errors) { e.frame = '' e.errors.forEach((m: Message) => { + if (m.text === 'Experimental decorators are not currently enabled') { + m.text += + '. Vite 4.4+ now uses esbuild 0.18 and you need to enable them by adding "experimentalDecorators": true in your "tsconfig.json" file.' + } e.frame += `\n` + prettifyMessage(m, code) }) e.loc = e.errors[0].location diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9bfeceae5e6aa9..7fd5fb6f4c611a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -233,8 +233,8 @@ importers: packages/vite: dependencies: esbuild: - specifier: ^0.17.5 - version: 0.17.5 + specifier: ^0.18.2 + version: 0.18.2 postcss: specifier: ^8.4.24 version: 8.4.24 @@ -2826,8 +2826,8 @@ packages: dev: true optional: true - /@esbuild/android-arm64@0.17.5: - resolution: {integrity: sha512-KHWkDqYAMmKZjY4RAN1PR96q6UOtfkWlTS8uEwWxdLtkRt/0F/csUhXIrVfaSIFxnscIBMPynGfhsMwQDRIBQw==} + /@esbuild/android-arm64@0.18.2: + resolution: {integrity: sha512-1Y2pb0hLdmji8I0zBwNsYSDN7zJSQqufgLOuOsrrod00WEAgKywQR5MB/E046Is/YTP4bgcPS4BioaSDBaLaTg==} engines: {node: '>=12'} cpu: [arm64] os: [android] @@ -2853,8 +2853,8 @@ packages: dev: true optional: true - /@esbuild/android-arm@0.17.5: - resolution: {integrity: sha512-crmPUzgCmF+qZXfl1YkiFoUta2XAfixR1tEnr/gXIixE+WL8Z0BGqfydP5oox0EUOgQMMRgtATtakyAcClQVqQ==} + /@esbuild/android-arm@0.18.2: + resolution: {integrity: sha512-YAnQBHlY0IvYtvY0avnXjI8ywW23emEjk5XExqbFmypath+Snq9MgY1IS47rnqBKVSqnl0ElDt221ZgaeRrkXg==} engines: {node: '>=12'} cpu: [arm] os: [android] @@ -2871,8 +2871,8 @@ packages: dev: true optional: true - /@esbuild/android-x64@0.17.5: - resolution: {integrity: sha512-8fI/AnIdmWz/+1iza2WrCw8kwXK9wZp/yZY/iS8ioC+U37yJCeppi9EHY05ewJKN64ASoBIseufZROtcFnX5GA==} + /@esbuild/android-x64@0.18.2: + resolution: {integrity: sha512-P047Mh3pj8uYVE3A/B3QDX6nG8dKbHLJ+48R6Y0CRXCJ5PkXJxdHOTaS8SYs6eSR3FFU6/YQ5TishQXVHX7F5A==} engines: {node: '>=12'} cpu: [x64] os: [android] @@ -2889,8 +2889,8 @@ packages: dev: true optional: true - /@esbuild/darwin-arm64@0.17.5: - resolution: {integrity: sha512-EAvaoyIySV6Iif3NQCglUNpnMfHSUgC5ugt2efl3+QDntucJe5spn0udNZjTgNi6tKVqSceOw9tQ32liNZc1Xw==} + /@esbuild/darwin-arm64@0.18.2: + resolution: {integrity: sha512-a3Rkqd0tGVYMEKNy9SstWEdeBmM60l8FVD5o4rmwHr3xO1LbLqtCJSrWGbnf37hevo6m437mURVmpEHOmkXeTA==} engines: {node: '>=12'} cpu: [arm64] os: [darwin] @@ -2907,8 +2907,8 @@ packages: dev: true optional: true - /@esbuild/darwin-x64@0.17.5: - resolution: {integrity: sha512-ha7QCJh1fuSwwCgoegfdaljowwWozwTDjBgjD3++WAy/qwee5uUi1gvOg2WENJC6EUyHBOkcd3YmLDYSZ2TPPA==} + /@esbuild/darwin-x64@0.18.2: + resolution: {integrity: sha512-cvH58adz9L10JNsIcgtkWNS/1eutjRTi3rtWz1s3ZhR64BpdmkxJBAXE/UjqybyNAWLhaN8mPJdlYI2f+tQA7g==} engines: {node: '>=12'} cpu: [x64] os: [darwin] @@ -2925,8 +2925,8 @@ packages: dev: true optional: true - /@esbuild/freebsd-arm64@0.17.5: - resolution: {integrity: sha512-VbdXJkn2aI2pQ/wxNEjEcnEDwPpxt3CWWMFYmO7CcdFBoOsABRy2W8F3kjbF9F/pecEUDcI3b5i2w+By4VQFPg==} + /@esbuild/freebsd-arm64@0.18.2: + resolution: {integrity: sha512-68rGMGUdgmq+c5IvseCMqY4yaa2CAY/DIILMBA6bEU1caISF7fXnV69B1uU4s3ERuVDcasVVwiAFyNxCtkS6Zg==} engines: {node: '>=12'} cpu: [arm64] os: [freebsd] @@ -2943,8 +2943,8 @@ packages: dev: true optional: true - /@esbuild/freebsd-x64@0.17.5: - resolution: {integrity: sha512-olgGYND1/XnnWxwhjtY3/ryjOG/M4WfcA6XH8dBTH1cxMeBemMODXSFhkw71Kf4TeZFFTN25YOomaNh0vq2iXg==} + /@esbuild/freebsd-x64@0.18.2: + resolution: {integrity: sha512-ZSR9On/rXoYuAtrXo5hYKy7OuZwKZyFh2rr6L3TX4UeR1tWLf84aLyAFt7e0tlRbh4zNgqFx+ePWmsSHw7L9Bw==} engines: {node: '>=12'} cpu: [x64] os: [freebsd] @@ -2961,8 +2961,8 @@ packages: dev: true optional: true - /@esbuild/linux-arm64@0.17.5: - resolution: {integrity: sha512-8a0bqSwu3OlLCfu2FBbDNgQyBYdPJh1B9PvNX7jMaKGC9/KopgHs37t+pQqeMLzcyRqG6z55IGNQAMSlCpBuqg==} + /@esbuild/linux-arm64@0.18.2: + resolution: {integrity: sha512-DFKavAzbu/n9HXWuetxmYN10XnfzW7FgOgpcrGD8eXaiu77KdgB+OVWA83x9FtDYtsoFpfdlDuVFAQFfrhu77A==} engines: {node: '>=12'} cpu: [arm64] os: [linux] @@ -2979,8 +2979,8 @@ packages: dev: true optional: true - /@esbuild/linux-arm@0.17.5: - resolution: {integrity: sha512-YBdCyQwA3OQupi6W2/WO4FnI+NWFWe79cZEtlbqSESOHEg7a73htBIRiE6uHPQe7Yp5E4aALv+JxkRLGEUL7tw==} + /@esbuild/linux-arm@0.18.2: + resolution: {integrity: sha512-jAbA75qJ70T5AOdmw9X8675ppeRfj7j57sOypoZ4mQlfQ/LKF8eoeLzTYVo8+aqLKqeIIl0vQ4hKOB0FyG98Zg==} engines: {node: '>=12'} cpu: [arm] os: [linux] @@ -2997,8 +2997,8 @@ packages: dev: true optional: true - /@esbuild/linux-ia32@0.17.5: - resolution: {integrity: sha512-uCwm1r/+NdP7vndctgq3PoZrnmhmnecWAr114GWMRwg2QMFFX+kIWnp7IO220/JLgnXK/jP7VKAFBGmeOYBQYQ==} + /@esbuild/linux-ia32@0.18.2: + resolution: {integrity: sha512-VEaK3Z+vJyDwwPsP0sovaEw1foDzrMs7XQNYEIFkOwMjSe2BipKRKUUyrznil0p8qqsK7U8W+T7oNqZpgdnD2Q==} engines: {node: '>=12'} cpu: [ia32] os: [linux] @@ -3024,8 +3024,8 @@ packages: dev: true optional: true - /@esbuild/linux-loong64@0.17.5: - resolution: {integrity: sha512-3YxhSBl5Sb6TtBjJu+HP93poBruFzgXmf3PVfIe4xOXMj1XpxboYZyw3W8BhoX/uwxzZz4K1I99jTE/5cgDT1g==} + /@esbuild/linux-loong64@0.18.2: + resolution: {integrity: sha512-Af1uZdB0oeJo4PW67l9aw94oakSamFxhC6ltC2eDkndozd9QygVNMTF7s7uxTLjo+BJqyVqG9wjmLCYF1o4NmA==} engines: {node: '>=12'} cpu: [loong64] os: [linux] @@ -3042,8 +3042,8 @@ packages: dev: true optional: true - /@esbuild/linux-mips64el@0.17.5: - resolution: {integrity: sha512-Hy5Z0YVWyYHdtQ5mfmfp8LdhVwGbwVuq8mHzLqrG16BaMgEmit2xKO+iDakHs+OetEx0EN/2mUzDdfdktI+Nmg==} + /@esbuild/linux-mips64el@0.18.2: + resolution: {integrity: sha512-WcTbt61+9dREuOFKXac4Qg+3OuRhLxPL9lmkI2P7fGuq/fWS2qq+AvGGVLMyk+OtXGDjyQolcEDeYlRoOmjRYQ==} engines: {node: '>=12'} cpu: [mips64el] os: [linux] @@ -3060,8 +3060,8 @@ packages: dev: true optional: true - /@esbuild/linux-ppc64@0.17.5: - resolution: {integrity: sha512-5dbQvBLbU/Y3Q4ABc9gi23hww1mQcM7KZ9KBqabB7qhJswYMf8WrDDOSw3gdf3p+ffmijMd28mfVMvFucuECyg==} + /@esbuild/linux-ppc64@0.18.2: + resolution: {integrity: sha512-Ov+VHayvCPb52axma6+xm8QDawRjwHscPXedHg4U92DxlhKQ0H+6onRiC3J9kKI50p8pKKypprpCWrRrXjZN7Q==} engines: {node: '>=12'} cpu: [ppc64] os: [linux] @@ -3078,8 +3078,8 @@ packages: dev: true optional: true - /@esbuild/linux-riscv64@0.17.5: - resolution: {integrity: sha512-fp/KUB/ZPzEWGTEUgz9wIAKCqu7CjH1GqXUO2WJdik1UNBQ7Xzw7myIajpxztE4Csb9504ERiFMxZg5KZ6HlZQ==} + /@esbuild/linux-riscv64@0.18.2: + resolution: {integrity: sha512-qW37zzKKN9C5l5LnVDriOK0eZRzQeixhtrfd5C78PAsTE15GeHU9G0oyT/u/IkNjEBjXWpTZOOHKNbjhrvuL9g==} engines: {node: '>=12'} cpu: [riscv64] os: [linux] @@ -3096,8 +3096,8 @@ packages: dev: true optional: true - /@esbuild/linux-s390x@0.17.5: - resolution: {integrity: sha512-kRV3yw19YDqHTp8SfHXfObUFXlaiiw4o2lvT1XjsPZ++22GqZwSsYWJLjMi1Sl7j9qDlDUduWDze/nQx0d6Lzw==} + /@esbuild/linux-s390x@0.18.2: + resolution: {integrity: sha512-izzEFMRO8LaQIlX22+fTgP5I7Os3T51mtAWsRNpZ5pMfQIa9PqtgFAoRcb10DV+/YkH/TMMxQIlevUvDS6E4vw==} engines: {node: '>=12'} cpu: [s390x] os: [linux] @@ -3114,8 +3114,8 @@ packages: dev: true optional: true - /@esbuild/linux-x64@0.17.5: - resolution: {integrity: sha512-vnxuhh9e4pbtABNLbT2ANW4uwQ/zvcHRCm1JxaYkzSehugoFd5iXyC4ci1nhXU13mxEwCnrnTIiiSGwa/uAF1g==} + /@esbuild/linux-x64@0.18.2: + resolution: {integrity: sha512-y5yqQ1ww4FfI9bQ1ZP/0k1rcgA6Ql2/AgzvqpowN0Q5tXDZkCavPdJbFXKrqA43vd1UTXt+AutTHYJ7km6e2Eg==} engines: {node: '>=12'} cpu: [x64] os: [linux] @@ -3132,8 +3132,8 @@ packages: dev: true optional: true - /@esbuild/netbsd-x64@0.17.5: - resolution: {integrity: sha512-cigBpdiSx/vPy7doUyImsQQBnBjV5f1M99ZUlaJckDAJjgXWl6y9W17FIfJTy8TxosEF6MXq+fpLsitMGts2nA==} + /@esbuild/netbsd-x64@0.18.2: + resolution: {integrity: sha512-usNjpKFf83X4o60gdMD47NCblaSZ6DARf31/FyCzxOgnF80mJ+RhDs9RTqgyfH8KyduO5mjgInw9+ct286ayYA==} engines: {node: '>=12'} cpu: [x64] os: [netbsd] @@ -3150,8 +3150,8 @@ packages: dev: true optional: true - /@esbuild/openbsd-x64@0.17.5: - resolution: {integrity: sha512-VdqRqPVIjjZfkf40LrqOaVuhw9EQiAZ/GNCSM2UplDkaIzYVsSnycxcFfAnHdWI8Gyt6dO15KHikbpxwx+xHbw==} + /@esbuild/openbsd-x64@0.18.2: + resolution: {integrity: sha512-6urzy1+VwcPuhG+5jwHA8lD9E87E5+ey3qKw2EhRS+qUmMxLvfwP8szWC2JHVGZDPEDge6fgn0pBj+y9rxDLwQ==} engines: {node: '>=12'} cpu: [x64] os: [openbsd] @@ -3168,8 +3168,8 @@ packages: dev: true optional: true - /@esbuild/sunos-x64@0.17.5: - resolution: {integrity: sha512-ItxPaJ3MBLtI4nK+mALLEoUs6amxsx+J1ibnfcYMkqaCqHST1AkF4aENpBehty3czqw64r/XqL+W9WqU6kc2Qw==} + /@esbuild/sunos-x64@0.18.2: + resolution: {integrity: sha512-SMZPTACsvpKYAIl9o8nhnmMn6/lp62iMeV/2EBMtj+sW6dXwW9b0cLjihkBv4PG1CCRlwWKPZo43imqZxC95ZA==} engines: {node: '>=12'} cpu: [x64] os: [sunos] @@ -3186,8 +3186,8 @@ packages: dev: true optional: true - /@esbuild/win32-arm64@0.17.5: - resolution: {integrity: sha512-4u2Q6qsJTYNFdS9zHoAi80spzf78C16m2wla4eJPh4kSbRv+BpXIfl6TmBSWupD8e47B1NrTfrOlEuco7mYQtg==} + /@esbuild/win32-arm64@0.18.2: + resolution: {integrity: sha512-H2zzjPdzSDNwUnZdZf9/xfm0CYqHFXuenCMAx+tRzIRqWUT6MmZ9/q7722KnAZ6uPpq0RLs7EjCIIfmt6CaRGg==} engines: {node: '>=12'} cpu: [arm64] os: [win32] @@ -3204,8 +3204,8 @@ packages: dev: true optional: true - /@esbuild/win32-ia32@0.17.5: - resolution: {integrity: sha512-KYlm+Xu9TXsfTWAcocLuISRtqxKp/Y9ZBVg6CEEj0O5J9mn7YvBKzAszo2j1ndyzUPk+op+Tie2PJeN+BnXGqQ==} + /@esbuild/win32-ia32@0.18.2: + resolution: {integrity: sha512-lfyjTN+FrKgvNvrH7nOLtaz58J/8coZOo4LQwgBMP4D7ZOurhvluXS3GjePLzq9GbWnJDZdKCKbMKhZPPcdJJA==} engines: {node: '>=12'} cpu: [ia32] os: [win32] @@ -3222,8 +3222,8 @@ packages: dev: true optional: true - /@esbuild/win32-x64@0.17.5: - resolution: {integrity: sha512-XgA9qWRqby7xdYXuF6KALsn37QGBMHsdhmnpjfZtYxKxbTOwfnDM6MYi2WuUku5poNaX2n9XGVr20zgT/2QwCw==} + /@esbuild/win32-x64@0.18.2: + resolution: {integrity: sha512-Q4nIjqWXjxkELwd7kVepsJxbQ/6ERNsHpjz1j+IKjwSYw+g06U0RQOy5xh848AHvgr9itnGLa3cT2G5t0dBFsw==} engines: {node: '>=12'} cpu: [x64] os: [win32] @@ -5789,34 +5789,34 @@ packages: '@esbuild/win32-x64': 0.17.18 dev: true - /esbuild@0.17.5: - resolution: {integrity: sha512-Bu6WLCc9NMsNoMJUjGl3yBzTjVLXdysMltxQWiLAypP+/vQrf+3L1Xe8fCXzxaECus2cEJ9M7pk4yKatEwQMqQ==} + /esbuild@0.18.2: + resolution: {integrity: sha512-1P4sK9gXVcjvrrUjE94Hbo9goU+T6U1sdzLf+JJ+3uI6GEb4e4n3Wrqto9hZHUWabblpT2ifmC61LhZnLyTNFw==} engines: {node: '>=12'} hasBin: true requiresBuild: true optionalDependencies: - '@esbuild/android-arm': 0.17.5 - '@esbuild/android-arm64': 0.17.5 - '@esbuild/android-x64': 0.17.5 - '@esbuild/darwin-arm64': 0.17.5 - '@esbuild/darwin-x64': 0.17.5 - '@esbuild/freebsd-arm64': 0.17.5 - '@esbuild/freebsd-x64': 0.17.5 - '@esbuild/linux-arm': 0.17.5 - '@esbuild/linux-arm64': 0.17.5 - '@esbuild/linux-ia32': 0.17.5 - '@esbuild/linux-loong64': 0.17.5 - '@esbuild/linux-mips64el': 0.17.5 - '@esbuild/linux-ppc64': 0.17.5 - '@esbuild/linux-riscv64': 0.17.5 - '@esbuild/linux-s390x': 0.17.5 - '@esbuild/linux-x64': 0.17.5 - '@esbuild/netbsd-x64': 0.17.5 - '@esbuild/openbsd-x64': 0.17.5 - '@esbuild/sunos-x64': 0.17.5 - '@esbuild/win32-arm64': 0.17.5 - '@esbuild/win32-ia32': 0.17.5 - '@esbuild/win32-x64': 0.17.5 + '@esbuild/android-arm': 0.18.2 + '@esbuild/android-arm64': 0.18.2 + '@esbuild/android-x64': 0.18.2 + '@esbuild/darwin-arm64': 0.18.2 + '@esbuild/darwin-x64': 0.18.2 + '@esbuild/freebsd-arm64': 0.18.2 + '@esbuild/freebsd-x64': 0.18.2 + '@esbuild/linux-arm': 0.18.2 + '@esbuild/linux-arm64': 0.18.2 + '@esbuild/linux-ia32': 0.18.2 + '@esbuild/linux-loong64': 0.18.2 + '@esbuild/linux-mips64el': 0.18.2 + '@esbuild/linux-ppc64': 0.18.2 + '@esbuild/linux-riscv64': 0.18.2 + '@esbuild/linux-s390x': 0.18.2 + '@esbuild/linux-x64': 0.18.2 + '@esbuild/netbsd-x64': 0.18.2 + '@esbuild/openbsd-x64': 0.18.2 + '@esbuild/sunos-x64': 0.18.2 + '@esbuild/win32-arm64': 0.18.2 + '@esbuild/win32-ia32': 0.18.2 + '@esbuild/win32-x64': 0.18.2 dev: false /escalade@3.1.1: