vite.config.ts
This file
Path
vite.config.ts
365 lines · 11.1 KiB · TypeScript
Last changed by
chore: unified oxfmt and oxlint config (#5518)Rahul Mishrabefore adoptionf78a245
History of this fileTake it
chore: convert build scripts into plugins (#5448)Rahul Mishrabefore adoptionee0622e
lines 1–2why, one step back1import { RolldownMagicString } from 'rolldown'2import { parse, Visitor } from 'rolldown/utils'chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
line 3why, one step back3import { defineConfig } from 'vite-plus'chore: convert build scripts into plugins (#5448)Rahul Mishrabefore adoptionee0622e
line 4why, one step back4import type { TsdownPluginOption } from 'vite-plus/pack'fix(build): keep internal types private in bundled d.ts and avoid a self-referencing JSX.IntrinsicElements (#5485)Yusuke Wadabefore adoptionbe1f749
line 5why, one step back5import { appendExportEmptyToDts } from './build/dts-plugins'chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
lines 6–14why, one step back67const entry = ['src/**/*.ts', '!src/**/*.test.ts', '!src/**/*.test.tsx']8const common = {9 entry,10 tsconfig: 'tsconfig.build.json',11 unbundle: true,12 clean: false,13}14chore: convert build scripts into plugins (#5448)Rahul Mishrabefore adoptionee0622e
lines 15–88why, one step back15const removeDtsPrivateFieldsPlugin: TsdownPluginOption = {16 name: 'hono:remove-dts-private-fields',17 async renderChunk(code, id) {18 if (!id.fileName.endsWith('.d.ts')) {19 return20 }2122 const ast = await parse(id.fileName, code)23 const ms = new RolldownMagicString(code, { filename: id.fileName })2425 new Visitor({26 ClassDeclaration: (node) => {27 node.body.body.forEach((elem) => {28 if (elem.type === 'PropertyDefinition' && elem.key.type === 'PrivateIdentifier') {29 this.info(`Removing private field from ${id.fileName}`)30 ms.remove(elem.start, elem.end)31 }32 })33 },34 }).visit(ast.program)3536 return ms.toString()37 },38}3940const validatePackageExportsPlugin: TsdownPluginOption = {41 name: 'hono:validate-package-exports',42 async buildStart() {43 const validateExports = (44 source: Record<string, unknown>,45 target: Record<string, unknown>,46 fileName: string47 ) => {48 const isEntryInTarget = (entry: string): boolean => {49 if (entry in target) {50 return true51 }5253 // e.g., "./utils/*" -> "./utils"54 const wildcardPrefix = entry.replace(/\/\*$/, '')55 if (entry.endsWith('/*')) {56 return Object.keys(target).some(57 (targetEntry) =>58 targetEntry.startsWith(wildcardPrefix + '/') && targetEntry !== wildcardPrefix59 )60 }6162 const separatedEntry = entry.split('/')63 while (separatedEntry.length > 0) {64 const pattern = `${separatedEntry.join('/')}/*`65 if (pattern in target) {66 return true67 }68 separatedEntry.pop()69 }7071 return false72 }7374 Object.keys(source).forEach((sourceEntry) => {75 if (!isEntryInTarget(sourceEntry)) {76 throw new Error(`Missing "${sourceEntry}" in '${fileName}'`)77 }78 })79 }8081 const pkgJson = await import('./package.json', { with: { type: 'json' } })82 const jsrJson = await import('./jsr.json', { with: { type: 'json' } })8384 validateExports(pkgJson.exports, jsrJson.exports, 'jsr.json')85 validateExports(jsrJson.exports, pkgJson.exports, 'package.json')86 },87}88chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
line 89why, one step back89export default defineConfig({chore: unified oxfmt and oxlint config (#5518)Rahul Mishrabefore adoptionf78a245
lines 90–338why, one step back90 fmt: {91 printWidth: 100,92 trailingComma: 'es5',93 tabWidth: 2,94 semi: false,95 singleQuote: true,96 jsxSingleQuote: true,97 endOfLine: 'lf',98 sortImports: {99 newlinesBetween: false,100 },101 sortPackageJson: false,102 ignorePatterns: ['dist/', 'coverage/', '.wrangler/', 'pnpm-lock.yaml', '**/*.json', '**/*.mts'],103 },104 lint: {105 plugins: ['node', 'typescript', 'import', 'unicorn'],106 categories: {107 correctness: 'off',108 },109 env: {110 builtin: true,111 es2024: true,112 },113 globals: {114 __dirname: 'off',115 __filename: 'off',116 AbortController: 'readonly',117 AbortSignal: 'readonly',118 atob: 'readonly',119 Blob: 'readonly',120 BroadcastChannel: 'readonly',121 btoa: 'readonly',122 Buffer: 'readonly',123 ByteLengthQueuingStrategy: 'readonly',124 clearImmediate: 'readonly',125 clearInterval: 'readonly',126 clearTimeout: 'readonly',127 CloseEvent: 'readonly',128 CompressionStream: 'readonly',129 console: 'readonly',130 CountQueuingStrategy: 'readonly',131 crypto: 'readonly',132 Crypto: 'readonly',133 CryptoKey: 'readonly',134 CustomEvent: 'readonly',135 DecompressionStream: 'readonly',136 DOMException: 'readonly',137 Event: 'readonly',138 EventTarget: 'readonly',139 exports: 'off',140 fetch: 'readonly',141 File: 'readonly',142 FormData: 'readonly',143 global: 'readonly',144 Headers: 'readonly',145 MessageChannel: 'readonly',146 MessageEvent: 'readonly',147 MessagePort: 'readonly',148 module: 'off',149 navigator: 'readonly',150 Navigator: 'readonly',151 performance: 'readonly',152 Performance: 'readonly',153 PerformanceEntry: 'readonly',154 PerformanceMark: 'readonly',155 PerformanceMeasure: 'readonly',156 PerformanceObserver: 'readonly',157 PerformanceObserverEntryList: 'readonly',158 PerformanceResourceTiming: 'readonly',159 process: 'readonly',160 queueMicrotask: 'readonly',161 ReadableByteStreamController: 'readonly',162 ReadableStream: 'readonly',163 ReadableStreamBYOBReader: 'readonly',164 ReadableStreamBYOBRequest: 'readonly',165 ReadableStreamDefaultController: 'readonly',166 ReadableStreamDefaultReader: 'readonly',167 Request: 'readonly',168 require: 'off',169 Response: 'readonly',170 setImmediate: 'readonly',171 setInterval: 'readonly',172 setTimeout: 'readonly',173 structuredClone: 'readonly',174 SubtleCrypto: 'readonly',175 TextDecoder: 'readonly',176 TextDecoderStream: 'readonly',177 TextEncoder: 'readonly',178 TextEncoderStream: 'readonly',179 TransformStream: 'readonly',180 TransformStreamDefaultController: 'readonly',181 URL: 'readonly',182 URLSearchParams: 'readonly',183 WebAssembly: 'readonly',184 WebSocket: 'readonly',185 WritableStream: 'readonly',186 WritableStreamDefaultController: 'readonly',187 WritableStreamDefaultWriter: 'readonly',188 addEventListener: 'readonly',189 },190 ignorePatterns: ['.wrangler', '**/coverage', '**/dist'],191 rules: {192 'constructor-super': 'error',193 'for-direction': 'error',194 'getter-return': 'error',195 'no-async-promise-executor': 'error',196 'no-case-declarations': 'error',197 'no-class-assign': 'error',198 'no-compare-neg-zero': 'error',199 'no-cond-assign': 'error',200 'no-const-assign': 'error',201 'no-constant-binary-expression': 'error',202 'no-constant-condition': 'error',203 'no-control-regex': 'error',204 'no-debugger': ['error'],205 'no-delete-var': 'error',206 'no-dupe-class-members': 'error',207 'no-dupe-else-if': 'error',208 'no-dupe-keys': 'error',209 'no-duplicate-case': 'error',210 'no-empty': [211 'warn',212 {213 allowEmptyCatch: true,214 },215 ],216 'no-empty-character-class': 'error',217 'no-empty-pattern': 'error',218 'no-empty-static-block': 'error',219 'no-ex-assign': 'error',220 'no-extra-boolean-cast': 'error',221 'no-fallthrough': 'error',222 'no-func-assign': 'error',223 'no-global-assign': 'error',224 'no-import-assign': 'error',225 'no-invalid-regexp': 'error',226 'no-irregular-whitespace': 'error',227 'no-loss-of-precision': 'error',228 'no-misleading-character-class': 'error',229 'no-new-native-nonconstructor': 'error',230 'no-nonoctal-decimal-escape': 'error',231 'no-obj-calls': 'error',232 'no-prototype-builtins': 'error',233 'no-redeclare': 'error',234 'no-regex-spaces': 'error',235 'no-self-assign': 'error',236 'no-setter-return': 'error',237 'no-shadow-restricted-names': 'error',238 'no-sparse-arrays': 'error',239 'no-this-before-super': 'error',240 'no-unreachable': 'error',241 'no-unsafe-finally': 'error',242 'no-unsafe-negation': 'error',243 'no-unsafe-optional-chaining': 'error',244 'no-unused-labels': 'error',245 'no-unused-private-class-members': 'error',246 'no-unused-vars': [247 'warn',248 {249 args: 'all',250 argsIgnorePattern: '^_',251 caughtErrors: 'all',252 caughtErrorsIgnorePattern: '^_',253 destructuredArrayIgnorePattern: '^_',254 varsIgnorePattern: '^_',255 ignoreRestSiblings: true,256 },257 ],258 'no-useless-backreference': 'error',259 'no-useless-catch': 'error',260 'no-with': 'error',261 'require-yield': 'error',262 'use-isnan': 'error',263 'valid-typeof': 'error',264 'no-array-constructor': 'error',265 'no-empty-function': [266 'error',267 {268 allow: ['arrowFunctions'],269 },270 ],271 'prefer-const': [272 'warn',273 {274 destructuring: 'all',275 },276 ],277 curly: ['error', 'all'],278 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],279 'import/no-duplicates': 'error',280 'node/no-exports-assign': 'error',281 'typescript/ban-ts-comment': [282 'error',283 {284 minimumDescriptionLength: 10,285 },286 ],287 'typescript/no-duplicate-enum-values': 'error',288 'typescript/no-explicit-any': 'warn',289 'typescript/no-extra-non-null-assertion': 'error',290 'typescript/no-misused-new': 'error',291 'typescript/no-namespace': 'error',292 'typescript/no-non-null-asserted-nullish-coalescing': 'error',293 'typescript/no-non-null-asserted-optional-chain': 'error',294 'typescript/no-this-alias': 'error',295 'typescript/no-unnecessary-type-constraint': 'error',296 'typescript/no-unsafe-declaration-merging': 'error',297 'typescript/no-wrapper-object-types': 'error',298 'typescript/prefer-as-const': 'error',299 'typescript/prefer-namespace-keyword': 'error',300 'typescript/triple-slash-reference': 'error',301 'typescript/adjacent-overload-signatures': 'error',302 'typescript/ban-tslint-comment': 'error',303 'typescript/class-literal-property-style': 'error',304 'typescript/consistent-type-assertions': 'error',305 'typescript/consistent-type-imports': [306 'error',307 {308 prefer: 'type-imports',309 },310 ],311 },312 overrides: [313 {314 files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],315 rules: {316 'constructor-super': 'off',317 'getter-return': 'off',318 'no-class-assign': 'off',319 'no-const-assign': 'off',320 'no-dupe-class-members': 'off',321 'no-dupe-keys': 'off',322 'no-func-assign': 'off',323 'no-import-assign': 'off',324 'no-new-native-nonconstructor': 'off',325 'no-obj-calls': 'off',326 'no-redeclare': 'off',327 'no-setter-return': 'off',328 'no-this-before-super': 'off',329 'no-unreachable': 'off',330 'no-unsafe-negation': 'off',331 'no-var': 'error',332 'no-with': 'off',333 'prefer-rest-params': 'error',334 'prefer-spread': 'error',335 },336 },337 ],338 },chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
lines 339–345why, one step back339 pack: [340 {341 ...common,342 format: ['esm'],343 outDir: 'dist',344 dts: false,345 outExtensions: () => ({ js: '.js' }),chore: convert build scripts into plugins (#5448)Rahul Mishrabefore adoptionee0622e
line 346why, one step back346 plugins: [validatePackageExportsPlugin],chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
lines 347–353why, one step back347 },348 {349 ...common,350 format: ['cjs'],351 outDir: 'dist/cjs',352 dts: false,353 outExtensions: () => ({ js: '.js' }),chore: convert build scripts into plugins (#5448)Rahul Mishrabefore adoptionee0622e
line 354why, one step back354 // No need to validate package exports for CJS build, as it is already validated in ESM build.chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
lines 355–360why, one step back355 },356 {357 ...common,358 format: ['esm'],359 outDir: 'dist/types',360 dts: { emitDtsOnly: true },fix(build): keep internal types private in bundled d.ts and avoid a self-referencing JSX.IntrinsicElements (#5485)Yusuke Wadabefore adoptionbe1f749
line 361why, one step back361 plugins: [removeDtsPrivateFieldsPlugin, appendExportEmptyToDts],chore: introduce Vite+ (#5444)Yusuke Wadabefore adoption5f31392
lines 362–365why, one step back362 outExtensions: () => ({ dts: '.d.ts' }),363 },364 ],365})