Skip to content

Commit a839caa

Browse files
committed
chore: use types from rolldown
1 parent 53d03ed commit a839caa

File tree

7 files changed

+64
-63
lines changed

7 files changed

+64
-63
lines changed

packages/vite/src/node/__tests__/environment.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22
import { describe, expect, onTestFinished, test } from 'vitest'
3-
import type { RollupOutput } from 'rollup'
3+
import type { RolldownOutput } from 'rolldown'
44
import { createServer } from '../server'
55
import type { InlineConfig } from '../config'
66
import { createBuilder } from '../build'
@@ -167,7 +167,7 @@ describe('custom environment conditions', () => {
167167
const results: Record<string, unknown> = {}
168168
for (const key of ['ssr', 'worker', 'custom1', 'custom1_2']) {
169169
const output = await builder.build(builder.environments[key])
170-
const chunk = (output as RollupOutput).output[0]
170+
const chunk = (output as RolldownOutput).output[0]
171171
const mod = await import(
172172
path.join(
173173
import.meta.dirname,

packages/vite/src/node/__tests__/plugins/terser.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { resolve } from 'node:path'
22
import { fileURLToPath } from 'node:url'
33
import { describe, expect, test } from 'vitest'
44
import { build } from 'vite'
5-
import type { RollupOutput } from 'rollup'
5+
import type { RolldownOutput } from 'rolldown'
66
import type { TerserOptions } from '../../plugins/terser'
77

88
const __dirname = resolve(fileURLToPath(import.meta.url), '..')
@@ -32,7 +32,7 @@ describe('terser', () => {
3232
},
3333
},
3434
],
35-
})) as RollupOutput
35+
})) as RolldownOutput
3636
return result.output[0].code
3737
}
3838

packages/vite/src/node/plugins/importAnalysis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { parseAst } from 'rollup/parseAst'
1313
import type { StaticImport } from 'mlly'
1414
import { ESM_STATIC_IMPORT_RE, parseStaticImport } from 'mlly'
1515
import { makeLegalIdentifier } from '@rollup/pluginutils'
16-
import type { PartialResolvedId, RollupError } from 'rollup'
16+
import type { PartialResolvedId, RollupError } from 'rolldown'
1717
import type { Identifier, Literal } from 'estree'
1818
import {
1919
CLIENT_DIR,

packages/vite/src/node/plugins/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export async function resolvePlugins(
7171
}),
7272
})
7373
: aliasPlugin({
74+
// @ts-expect-error aliasPlugin receives rollup types
7475
entries: config.resolve.alias,
7576
customResolver: viteAliasCustomResolver,
7677
}),

packages/vite/src/node/plugins/oxc.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import type {
66
} from 'rolldown/experimental'
77
import { transform } from 'rolldown/experimental'
88
import type { RawSourceMap } from '@ampproject/remapping'
9-
import { type InternalModuleFormat, type SourceMap, rolldown } from 'rolldown'
9+
import type { InternalModuleFormat, RollupError, SourceMap } from 'rolldown'
10+
import { rolldown } from 'rolldown'
1011
import type { FSWatcher } from 'dep-types/chokidar'
1112
import { TSConfckParseError } from 'tsconfck'
12-
import type { RollupError } from 'rollup'
1313
import {
1414
combineSourcemaps,
1515
createFilter,

packages/vite/src/node/plugins/splitVendorChunk.ts

+53-53
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type {
2-
GetManualChunk,
3-
GetModuleInfo,
4-
// ManualChunkMeta,
5-
// OutputOptions,
6-
} from 'rollup'
7-
import { /* arraify, */ isInNodeModules } from '../utils'
1+
import type {} from // GetManualChunk,
2+
// GetModuleInfo,
3+
// ManualChunkMeta,
4+
// OutputOptions,
5+
'rolldown'
6+
// import { arraify, isInNodeModules } from '../utils'
87
// import type { UserConfig } from '../../node'
98
import type { Plugin } from '../plugin'
109

@@ -43,55 +42,56 @@ export class SplitVendorChunkCache {
4342
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration
4443
*/
4544
export function splitVendorChunk(
46-
options: { cache?: SplitVendorChunkCache } = {},
47-
): GetManualChunk {
48-
const cache = options.cache ?? new SplitVendorChunkCache()
49-
return (id, { getModuleInfo }) => {
50-
if (
51-
isInNodeModules(id) &&
52-
!isCSSRequest(id) &&
53-
staticImportedByEntry(id, getModuleInfo, cache.cache)
54-
) {
55-
return 'vendor'
56-
}
57-
}
45+
_options: { cache?: SplitVendorChunkCache } = {},
46+
): () => null /* : GetManualChunk */ {
47+
// const cache = options.cache ?? new SplitVendorChunkCache()
48+
// return (id, { getModuleInfo }) => {
49+
// if (
50+
// isInNodeModules(id) &&
51+
// !isCSSRequest(id) &&
52+
// staticImportedByEntry(id, getModuleInfo, cache.cache)
53+
// ) {
54+
// return 'vendor'
55+
// }
56+
// }
57+
return () => null
5858
}
5959

60-
function staticImportedByEntry(
61-
id: string,
62-
getModuleInfo: GetModuleInfo,
63-
cache: Map<string, boolean>,
64-
importStack: string[] = [],
65-
): boolean {
66-
if (cache.has(id)) {
67-
return cache.get(id) as boolean
68-
}
69-
if (importStack.includes(id)) {
70-
// circular deps!
71-
cache.set(id, false)
72-
return false
73-
}
74-
const mod = getModuleInfo(id)
75-
if (!mod) {
76-
cache.set(id, false)
77-
return false
78-
}
60+
// function staticImportedByEntry(
61+
// id: string,
62+
// getModuleInfo: GetModuleInfo,
63+
// cache: Map<string, boolean>,
64+
// importStack: string[] = [],
65+
// ): boolean {
66+
// if (cache.has(id)) {
67+
// return cache.get(id) as boolean
68+
// }
69+
// if (importStack.includes(id)) {
70+
// // circular deps!
71+
// cache.set(id, false)
72+
// return false
73+
// }
74+
// const mod = getModuleInfo(id)
75+
// if (!mod) {
76+
// cache.set(id, false)
77+
// return false
78+
// }
7979

80-
if (mod.isEntry) {
81-
cache.set(id, true)
82-
return true
83-
}
84-
const someImporterIs = mod.importers.some((importer) =>
85-
staticImportedByEntry(
86-
importer,
87-
getModuleInfo,
88-
cache,
89-
importStack.concat(id),
90-
),
91-
)
92-
cache.set(id, someImporterIs)
93-
return someImporterIs
94-
}
80+
// if (mod.isEntry) {
81+
// cache.set(id, true)
82+
// return true
83+
// }
84+
// const someImporterIs = mod.importers.some((importer) =>
85+
// staticImportedByEntry(
86+
// importer,
87+
// getModuleInfo,
88+
// cache,
89+
// importStack.concat(id),
90+
// ),
91+
// )
92+
// cache.set(id, someImporterIs)
93+
// return someImporterIs
94+
// }
9595

9696
/**
9797
* @deprecated use build.rollupOptions.output.manualChunks or framework specific configuration

packages/vite/src/types/alias.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2727
THE SOFTWARE.
2828
*/
2929

30-
import type { PluginHooks } from 'rollup'
30+
import type { FunctionPluginHooks } from 'rolldown'
3131

3232
export interface Alias {
3333
find: string | RegExp
@@ -42,10 +42,10 @@ export interface Alias {
4242

4343
export type MapToFunction<T> = T extends Function ? T : never
4444

45-
export type ResolverFunction = MapToFunction<PluginHooks['resolveId']>
45+
export type ResolverFunction = MapToFunction<FunctionPluginHooks['resolveId']>
4646

4747
export interface ResolverObject {
48-
buildStart?: PluginHooks['buildStart']
48+
buildStart?: FunctionPluginHooks['buildStart']
4949
resolveId: ResolverFunction
5050
}
5151

0 commit comments

Comments
 (0)