Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update esbuild to 0.18.2 #13525

Merged
merged 7 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
26 changes: 9 additions & 17 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,6 +65,7 @@ type TSConfigJSON = {
preserveValueImports?: boolean
target?: string
useDefineForClassFields?: boolean
verbatimModuleSyntax?: boolean
}
[key: string]: any
}
Expand Down Expand Up @@ -101,6 +103,7 @@ export async function transformWithEsbuild(
// https://esbuild.github.io/content-types/#tsconfig-json
const meaningfulFields: Array<keyof TSCompilerOptions> = [
'alwaysStrict',
'experimentalDecorators',
'importsNotUsedAsValues',
'jsx',
'jsxFactory',
Expand All @@ -109,6 +112,7 @@ export async function transformWithEsbuild(
'preserveValueImports',
'target',
'useDefineForClassFields',
'verbatimModuleSyntax',
]
const compilerOptionsForFile: TSCompilerOptions = {}
if (loader === 'ts' || loader === 'tsx') {
Expand All @@ -128,28 +132,13 @@ 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) {
options.jsx && (compilerOptions.jsx = undefined)
options.jsxFactory && (compilerOptions.jsxFactory = undefined)
options.jsxFragment && (compilerOptions.jsxFragmentFactory = undefined)
options.jsxImportSource && (compilerOptions.jsxImportSource = undefined)
options.target && (compilerOptions.target = undefined)
}

tsconfigRaw = {
Expand All @@ -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 include exists in ESBuildOptions
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
delete resolvedOptions.exclude
// @ts-expect-error include exists in ESBuildOptions
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
delete resolvedOptions.jsxInject

try {
Expand Down
Loading