From 837dccc334e0f8414f7c6348ba9e3a2aa7cb482c Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:53:58 +0900 Subject: [PATCH] chore: use types from rolldown --- .../src/node/__tests__/environment.spec.ts | 4 +- .../src/node/__tests__/plugins/terser.spec.ts | 4 +- .../vite/src/node/plugins/importAnalysis.ts | 2 +- packages/vite/src/node/plugins/index.ts | 1 + packages/vite/src/node/plugins/oxc.ts | 4 +- .../vite/src/node/plugins/splitVendorChunk.ts | 106 +++++++++--------- packages/vite/src/types/alias.d.ts | 6 +- 7 files changed, 64 insertions(+), 63 deletions(-) diff --git a/packages/vite/src/node/__tests__/environment.spec.ts b/packages/vite/src/node/__tests__/environment.spec.ts index 75b12136c5cd2d..aa4ae65dbb62fe 100644 --- a/packages/vite/src/node/__tests__/environment.spec.ts +++ b/packages/vite/src/node/__tests__/environment.spec.ts @@ -1,6 +1,6 @@ import path from 'node:path' import { describe, expect, onTestFinished, test } from 'vitest' -import type { RollupOutput } from 'rollup' +import type { RolldownOutput } from 'rolldown' import { createServer } from '../server' import type { InlineConfig } from '../config' import { createBuilder } from '../build' @@ -167,7 +167,7 @@ describe('custom environment conditions', () => { const results: Record = {} for (const key of ['ssr', 'worker', 'custom1', 'custom1_2']) { const output = await builder.build(builder.environments[key]) - const chunk = (output as RollupOutput).output[0] + const chunk = (output as RolldownOutput).output[0] const mod = await import( path.join( import.meta.dirname, diff --git a/packages/vite/src/node/__tests__/plugins/terser.spec.ts b/packages/vite/src/node/__tests__/plugins/terser.spec.ts index 9fed1ec2c5ee7e..9c1d5c68c09374 100644 --- a/packages/vite/src/node/__tests__/plugins/terser.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/terser.spec.ts @@ -2,7 +2,7 @@ import { resolve } from 'node:path' import { fileURLToPath } from 'node:url' import { describe, expect, test } from 'vitest' import { build } from 'vite' -import type { RollupOutput } from 'rollup' +import type { RolldownOutput } from 'rolldown' import type { TerserOptions } from '../../plugins/terser' const __dirname = resolve(fileURLToPath(import.meta.url), '..') @@ -32,7 +32,7 @@ describe('terser', () => { }, }, ], - })) as RollupOutput + })) as RolldownOutput return result.output[0].code } diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index c82926e7b627a7..d29c58f5e51313 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -13,7 +13,7 @@ import { parseAst } from 'rollup/parseAst' import type { StaticImport } from 'mlly' import { ESM_STATIC_IMPORT_RE, parseStaticImport } from 'mlly' import { makeLegalIdentifier } from '@rollup/pluginutils' -import type { PartialResolvedId, RollupError } from 'rollup' +import type { PartialResolvedId, RollupError } from 'rolldown' import type { Identifier, Literal } from 'estree' import { CLIENT_DIR, diff --git a/packages/vite/src/node/plugins/index.ts b/packages/vite/src/node/plugins/index.ts index ffcd9f8bf06ea7..34c79772ed301a 100644 --- a/packages/vite/src/node/plugins/index.ts +++ b/packages/vite/src/node/plugins/index.ts @@ -71,6 +71,7 @@ export async function resolvePlugins( }), }) : aliasPlugin({ + // @ts-expect-error aliasPlugin receives rollup types entries: config.resolve.alias, customResolver: viteAliasCustomResolver, }), diff --git a/packages/vite/src/node/plugins/oxc.ts b/packages/vite/src/node/plugins/oxc.ts index 87484f83dad23c..f51d20f2ed102d 100644 --- a/packages/vite/src/node/plugins/oxc.ts +++ b/packages/vite/src/node/plugins/oxc.ts @@ -6,10 +6,10 @@ import type { } from 'rolldown/experimental' import { transform } from 'rolldown/experimental' import type { RawSourceMap } from '@ampproject/remapping' -import { type InternalModuleFormat, type SourceMap, rolldown } from 'rolldown' +import type { InternalModuleFormat, RollupError, SourceMap } from 'rolldown' +import { rolldown } from 'rolldown' import type { FSWatcher } from 'dep-types/chokidar' import { TSConfckParseError } from 'tsconfck' -import type { RollupError } from 'rollup' import { combineSourcemaps, createFilter, diff --git a/packages/vite/src/node/plugins/splitVendorChunk.ts b/packages/vite/src/node/plugins/splitVendorChunk.ts index 642b8ae70034a7..065e5a7c804cc6 100644 --- a/packages/vite/src/node/plugins/splitVendorChunk.ts +++ b/packages/vite/src/node/plugins/splitVendorChunk.ts @@ -1,10 +1,9 @@ -import type { - GetManualChunk, - GetModuleInfo, - // ManualChunkMeta, - // OutputOptions, -} from 'rollup' -import { /* arraify, */ isInNodeModules } from '../utils' +import type {} from // GetManualChunk, +// GetModuleInfo, +// ManualChunkMeta, +// OutputOptions, +'rolldown' +// import { arraify, isInNodeModules } from '../utils' // import type { UserConfig } from '../../node' import type { Plugin } from '../plugin' @@ -43,55 +42,56 @@ export class SplitVendorChunkCache { * @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration */ export function splitVendorChunk( - options: { cache?: SplitVendorChunkCache } = {}, -): GetManualChunk { - const cache = options.cache ?? new SplitVendorChunkCache() - return (id, { getModuleInfo }) => { - if ( - isInNodeModules(id) && - !isCSSRequest(id) && - staticImportedByEntry(id, getModuleInfo, cache.cache) - ) { - return 'vendor' - } - } + _options: { cache?: SplitVendorChunkCache } = {}, +): () => null /* : GetManualChunk */ { + // const cache = options.cache ?? new SplitVendorChunkCache() + // return (id, { getModuleInfo }) => { + // if ( + // isInNodeModules(id) && + // !isCSSRequest(id) && + // staticImportedByEntry(id, getModuleInfo, cache.cache) + // ) { + // return 'vendor' + // } + // } + return () => null } -function staticImportedByEntry( - id: string, - getModuleInfo: GetModuleInfo, - cache: Map, - importStack: string[] = [], -): boolean { - if (cache.has(id)) { - return cache.get(id) as boolean - } - if (importStack.includes(id)) { - // circular deps! - cache.set(id, false) - return false - } - const mod = getModuleInfo(id) - if (!mod) { - cache.set(id, false) - return false - } +// function staticImportedByEntry( +// id: string, +// getModuleInfo: GetModuleInfo, +// cache: Map, +// importStack: string[] = [], +// ): boolean { +// if (cache.has(id)) { +// return cache.get(id) as boolean +// } +// if (importStack.includes(id)) { +// // circular deps! +// cache.set(id, false) +// return false +// } +// const mod = getModuleInfo(id) +// if (!mod) { +// cache.set(id, false) +// return false +// } - if (mod.isEntry) { - cache.set(id, true) - return true - } - const someImporterIs = mod.importers.some((importer) => - staticImportedByEntry( - importer, - getModuleInfo, - cache, - importStack.concat(id), - ), - ) - cache.set(id, someImporterIs) - return someImporterIs -} +// if (mod.isEntry) { +// cache.set(id, true) +// return true +// } +// const someImporterIs = mod.importers.some((importer) => +// staticImportedByEntry( +// importer, +// getModuleInfo, +// cache, +// importStack.concat(id), +// ), +// ) +// cache.set(id, someImporterIs) +// return someImporterIs +// } /** * @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration diff --git a/packages/vite/src/types/alias.d.ts b/packages/vite/src/types/alias.d.ts index 5752c25c04fc96..0e3b94b5c4a903 100644 --- a/packages/vite/src/types/alias.d.ts +++ b/packages/vite/src/types/alias.d.ts @@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { PluginHooks } from 'rollup' +import type { FunctionPluginHooks } from 'rolldown' export interface Alias { find: string | RegExp @@ -42,10 +42,10 @@ export interface Alias { export type MapToFunction = T extends Function ? T : never -export type ResolverFunction = MapToFunction +export type ResolverFunction = MapToFunction export interface ResolverObject { - buildStart?: PluginHooks['buildStart'] + buildStart?: FunctionPluginHooks['buildStart'] resolveId: ResolverFunction }