Skip to content

Commit a7ecd0f

Browse files
authored
refactor: remove direct imports from rollup (#7751)
1 parent 716b029 commit a7ecd0f

File tree

8 files changed

+12
-19
lines changed

8 files changed

+12
-19
lines changed

packages/browser/src/node/plugins/pluginContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PluginContext } from 'rollup'
1+
import type { Rollup } from 'vite'
22
import type { Plugin } from 'vitest/config'
33
import type { ParentBrowserProject } from '../projectParent'
44
import { fileURLToPath } from 'node:url'
@@ -28,7 +28,7 @@ export default function BrowserContext(globalServer: ParentBrowserProject): Plug
2828
}
2929

3030
async function generateContextFile(
31-
this: PluginContext,
31+
this: Rollup.PluginContext,
3232
globalServer: ParentBrowserProject,
3333
) {
3434
const commands = Object.keys(globalServer.commands)

packages/mocker/src/node/dynamicImportPlugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export function dynamicImportPlugin(options: DynamicImportPluginOptions = {}): P
3232
}
3333

3434
export interface DynamicImportInjectorResult {
35-
ast: Rollup.ProgramNode
3635
code: string
3736
map: SourceMap
3837
}
@@ -45,7 +44,7 @@ export function injectDynamicImport(
4544
): DynamicImportInjectorResult | undefined {
4645
const s = new MagicString(code)
4746

48-
let ast: any
47+
let ast: ReturnType<Rollup.PluginContext['parse']>
4948
try {
5049
ast = parse(code)
5150
}
@@ -75,7 +74,6 @@ export function injectDynamicImport(
7574
})
7675

7776
return {
78-
ast,
7977
code: s.toString(),
8078
map: s.generateMap({ hires: 'boundary', source: id }),
8179
}

packages/mocker/src/node/esmWalker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function isNodeInPattern(node: _Node): node is Property {
6161
* Except this is using acorn AST
6262
*/
6363
export function esmWalker(
64-
root: Rollup.ProgramNode,
64+
root: ReturnType<Rollup.PluginContext['parse']>,
6565
{ onIdentifier, onImportMeta, onDynamicImport, onCallExpression }: Visitors,
6666
): void {
6767
const parentStack: Node[] = []

packages/mocker/src/node/hoistMocksPlugin.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
VariableDeclaration,
1010
} from 'estree'
1111
import type { SourceMap } from 'magic-string'
12-
import type { RollupAstNode } from 'rollup'
1312
import type { Plugin, Rollup } from 'vite'
1413
import type { Node, Positioned } from './esmWalker'
1514
import { findNodeAround } from 'acorn-walk'
@@ -125,7 +124,6 @@ const regexpHoistable
125124
const hashbangRE = /^#!.*\n/
126125

127126
export interface HoistMocksResult {
128-
ast: Rollup.ProgramNode
129127
code: string
130128
map: SourceMap
131129
}
@@ -149,7 +147,7 @@ export function hoistMocks(
149147

150148
const s = new MagicString(code)
151149

152-
let ast: Rollup.ProgramNode
150+
let ast: ReturnType<Rollup.PluginContext['parse']>
153151
try {
154152
ast = parse(code)
155153
}
@@ -175,7 +173,7 @@ export function hoistMocks(
175173
const idToImportMap = new Map<string, string>()
176174

177175
const imports: {
178-
node: RollupAstNode<ImportDeclaration>
176+
node: Positioned<ImportDeclaration>
179177
id: string
180178
}[] = []
181179

@@ -549,7 +547,6 @@ export function hoistMocks(
549547
}
550548

551549
return {
552-
ast,
553550
code: s.toString(),
554551
map: s.generateMap({ hires: 'boundary', source: id }),
555552
}

packages/mocker/src/node/resolver.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { PartialResolvedId } from 'rollup'
2-
import type { ResolvedConfig as ViteConfig, ViteDevServer } from 'vite'
1+
import type { Rollup, ResolvedConfig as ViteConfig, ViteDevServer } from 'vite'
32
import { existsSync, readFileSync } from 'node:fs'
43
import { isAbsolute, join, resolve } from 'pathe'
54
import { cleanUrl } from '../utils'
@@ -117,7 +116,7 @@ export class ServerMockResolver {
117116
return this.resolveModule(rawId, resolved)
118117
}
119118

120-
private resolveModule(rawId: string, resolved: PartialResolvedId | null) {
119+
private resolveModule(rawId: string, resolved: Rollup.PartialResolvedId | null) {
121120
const id = resolved?.id || rawId
122121
const external
123122
= !isAbsolute(id) || isModuleDirectory(this.options, id) ? rawId : null

packages/vitest/src/node/viteLogger.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { RollupError } from 'rollup'
2-
import type { LogErrorOptions, Logger, LoggerOptions, LogLevel, LogType } from 'vite'
1+
import type { LogErrorOptions, Logger, LoggerOptions, LogLevel, LogType, Rollup } from 'vite'
32
import type { Logger as VitestLogger } from './logger'
43
import colors from 'tinyrainbow'
54

@@ -41,7 +40,7 @@ export function createViteLogger(
4140
level: LogLevel = 'info',
4241
options: LoggerOptions = {},
4342
): Logger {
44-
const loggedErrors = new WeakSet<Error | RollupError>()
43+
const loggedErrors = new WeakSet<Error | Rollup.RollupError>()
4544
const { prefix = '[vite]', allowClearScreen = true } = options
4645
const thresh = LogLevels[level]
4746
const canClearScreen

test/core/test/injector-esm.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseAst } from 'rollup/parseAst'
1+
import { parseAst } from 'vite'
22
import { expect, test } from 'vitest'
33
import { injectDynamicImport } from '../../../packages/mocker/src/node/dynamicImportPlugin'
44

test/core/test/injector-mock.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { HoistMocksPluginOptions } from '../../../packages/mocker/src/node/hoistMocksPlugin'
22
import { stripVTControlCharacters } from 'node:util'
3-
import { parseAst } from 'rollup/parseAst'
3+
import { parseAst } from 'vite'
44
import { describe, expect, it, test } from 'vitest'
55
import { generateCodeFrame } from 'vitest/src/node/error.js'
66
import { hoistMocks } from '../../../packages/mocker/src/node/hoistMocksPlugin'

0 commit comments

Comments
 (0)