Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'node:path'
import fs from 'node:fs'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { PluginContext, TransformPluginContext } from 'rollup'
import type { RawSourceMap } from 'source-map-js'
import type { EncodedSourceMap as TraceEncodedSourceMap } from '@jridgewell/trace-mapping'
import { TraceMap, eachMapping } from '@jridgewell/trace-mapping'
import type { EncodedSourceMap as GenEncodedSourceMap } from '@jridgewell/gen-mapping'
import { addMapping, fromMap, toEncodedMap } from '@jridgewell/gen-mapping'
import type { Rollup } from 'vite'
import { normalizePath, transformWithEsbuild } from 'vite'
import {
createDescriptor,
Expand All @@ -31,7 +31,7 @@ export async function transformMain(
code: string,
filename: string,
options: ResolvedOptions,
pluginContext: TransformPluginContext,
pluginContext: Rollup.TransformPluginContext,
ssr: boolean,
customElement: boolean,
) {
Expand Down Expand Up @@ -290,7 +290,7 @@ export async function transformMain(
async function genTemplateCode(
descriptor: SFCDescriptor,
options: ResolvedOptions,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
ssr: boolean,
customElement: boolean,
) {
Expand Down Expand Up @@ -339,7 +339,7 @@ async function genTemplateCode(
async function genScriptCode(
descriptor: SFCDescriptor,
options: ResolvedOptions,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
ssr: boolean,
customElement: boolean,
): Promise<{
Expand Down Expand Up @@ -397,7 +397,7 @@ async function genScriptCode(

async function genStyleCode(
descriptor: SFCDescriptor,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
customElement: boolean,
attachedProps: [string, string][],
) {
Expand Down Expand Up @@ -487,7 +487,7 @@ function genCSSModulesCode(

async function genCustomBlockCode(
descriptor: SFCDescriptor,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
) {
let code = ''
for (let index = 0; index < descriptor.customBlocks.length; index++) {
Expand All @@ -514,7 +514,7 @@ async function genCustomBlockCode(
async function linkSrcToDescriptor(
src: string,
descriptor: SFCDescriptor,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
scoped?: boolean,
) {
const srcFile =
Expand Down
9 changes: 6 additions & 3 deletions packages/plugin-vue/src/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ExistingRawSourceMap, TransformPluginContext } from 'rollup'
import type { RawSourceMap } from 'source-map-js'
import type { Rollup } from 'vite'
import { formatPostcssSourceMap } from 'vite'
import type { ExtendedSFCDescriptor } from './utils/descriptorCache'
import type { ResolvedOptions } from './index'
Expand All @@ -10,7 +10,7 @@ export async function transformStyle(
descriptor: ExtendedSFCDescriptor,
index: number,
options: ResolvedOptions,
pluginContext: TransformPluginContext,
pluginContext: Rollup.TransformPluginContext,
filename: string,
) {
const block = descriptor.styles[index]
Expand Down Expand Up @@ -54,7 +54,10 @@ export async function transformStyle(
? await formatPostcssSourceMap(
// version property of result.map is declared as string
// but actually it is a number
result.map as Omit<RawSourceMap, 'version'> as ExistingRawSourceMap,
result.map as Omit<
RawSourceMap,
'version'
> as Rollup.ExistingRawSourceMap,
filename,
)
: ({ mappings: '' } as any)
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
SFCTemplateCompileOptions,
SFCTemplateCompileResults,
} from 'vue/compiler-sfc'
import type { PluginContext, TransformPluginContext } from 'rollup'
import type { Rollup } from 'vite'
import { getResolvedScript, resolveScript } from './script'
import { createRollupError } from './utils/error'
import type { ResolvedOptions } from './index'
Expand All @@ -15,7 +15,7 @@ export async function transformTemplateAsModule(
code: string,
descriptor: SFCDescriptor,
options: ResolvedOptions,
pluginContext: TransformPluginContext,
pluginContext: Rollup.TransformPluginContext,
ssr: boolean,
customElement: boolean,
): Promise<{
Expand Down Expand Up @@ -56,7 +56,7 @@ export function transformTemplateInMain(
code: string,
descriptor: SFCDescriptor,
options: ResolvedOptions,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
ssr: boolean,
customElement: boolean,
): SFCTemplateCompileResults {
Expand All @@ -82,7 +82,7 @@ export function compile(
code: string,
descriptor: SFCDescriptor,
options: ResolvedOptions,
pluginContext: PluginContext,
pluginContext: Rollup.PluginContext,
ssr: boolean,
customElement: boolean,
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/utils/error.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { CompilerError } from 'vue/compiler-sfc'
import type { RollupError } from 'rollup'
import type { Rollup } from 'vite'

export function createRollupError(
id: string,
error: CompilerError | SyntaxError,
): RollupError {
): Rollup.RollupError {
const { message, name, stack } = error
const rollupError: RollupError = {
const rollupError: Rollup.RollupError = {
id,
plugin: 'vue',
message,
Expand Down
14 changes: 7 additions & 7 deletions playground/vitestSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
Logger,
PluginOption,
ResolvedConfig,
Rollup,
UserConfig,
ViteDevServer,
} from 'vite'
Expand All @@ -19,7 +20,6 @@ import {
preview,
} from 'vite'
import type { Browser, Page } from 'playwright-chromium'
import type { RollupError, RollupWatcher, RollupWatcherEvent } from 'rollup'
import type { File } from 'vitest'
import { beforeAll } from 'vitest'

Expand Down Expand Up @@ -72,7 +72,7 @@ export let resolvedConfig: ResolvedConfig = undefined!
export let page: Page = undefined!
export let browser: Browser = undefined!
export let viteTestUrl: string = ''
export let watcher: RollupWatcher | undefined = undefined
export let watcher: Rollup.RollupWatcher | undefined = undefined

declare module 'vite' {
interface InlineConfig {
Expand Down Expand Up @@ -269,7 +269,7 @@ export async function startDefaultServe(): Promise<void> {
const isWatch = !!resolvedConfig!.build.watch
// in build watch,call startStaticServer after the build is complete
if (isWatch) {
watcher = rollupOutput as RollupWatcher
watcher = rollupOutput as Rollup.RollupWatcher
await notifyRebuildComplete(watcher)
}
// @ts-ignore
Expand All @@ -290,10 +290,10 @@ export async function startDefaultServe(): Promise<void> {
* Send the rebuild complete message in build watch
*/
export async function notifyRebuildComplete(
watcher: RollupWatcher,
): Promise<RollupWatcher> {
watcher: Rollup.RollupWatcher,
): Promise<Rollup.RollupWatcher> {
let resolveFn: undefined | (() => void)
const callback = (event: RollupWatcherEvent): void => {
const callback = (event: Rollup.RollupWatcherEvent): void => {
if (event.code === 'END') {
resolveFn?.()
}
Expand All @@ -306,7 +306,7 @@ export async function notifyRebuildComplete(
}

function createInMemoryLogger(logs: string[]): Logger {
const loggedErrors = new WeakSet<Error | RollupError>()
const loggedErrors = new WeakSet<Error | Rollup.RollupError>()
const warnedMessages = new Set<string>()

const logger: Logger = {
Expand Down
6 changes: 3 additions & 3 deletions playground/vue-lib/__tests__/vue-lib.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import type { Rollup } from 'vite'
import { build } from 'vite'
import { describe, expect, test } from 'vitest'
import type { OutputChunk, RollupOutput } from 'rollup'

describe('vue component library', () => {
test('should output tree shakeable css module code', async () => {
Expand All @@ -14,10 +14,10 @@ describe('vue component library', () => {
const { output } = (await build({
logLevel: 'silent',
configFile: path.resolve(__dirname, '../vite.config.consumer.ts'),
})) as RollupOutput
})) as Rollup.RollupOutput
const { code } = output.find(
(e) => e.type === 'chunk' && e.isEntry,
) as OutputChunk
) as Rollup.OutputChunk
// Unused css module should be treeshaked
expect(code).toContain('styleA') // styleA is used by CompA
expect(code).not.toContain('styleB') // styleB is not used
Expand Down