Skip to content

Commit

Permalink
chore: move vite module types to core to avoid circle reference
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Mar 3, 2024
1 parent a7d5c6c commit 7c18de5
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 48 deletions.
1 change: 0 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.1.4",
"vite-plugin-vue-devtools": "workspace:^",
"vue": "^3.4.21"
}
}
3 changes: 1 addition & 2 deletions packages/client/src/components/assets/AssetDetails.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script setup lang="ts">
import { useTimeAgo } from '@vueuse/core'
import type { AssetInfo, CodeSnippet } from '@vue/devtools-core'
import type { AssetInfo, CodeSnippet, ImageMeta } from '@vue/devtools-core'
import { callViteServerAction, useDevToolsState } from '@vue/devtools-core'
import { VueButton, VueIcon, VTooltip as vTooltip } from '@vue/devtools-ui'
import type { ImageMeta } from 'vite-plugin-vue-devtools'
const props = defineProps<{
modelValue: AssetInfo
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/assets.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { VueCheckbox, VueDrawer, VueIcon, VueSelect } from '@vue/devtools-ui'
import { callViteServerAction, defineViteClientListener } from '@vue/devtools-core'
import type { AssetInfo } from 'vite-plugin-vue-devtools'
import type { AssetInfo } from '@vue/devtools-core'
import Fuse from 'fuse.js'
const DETAILS_MAX_ITEMS = 50
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/graph.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { callViteServerAction, defineViteClientListener } from '@vue/devtools-core'
import { Network } from 'vis-network'
import type { ModuleInfo } from 'vite-plugin-vue-devtools'
import type { ModuleInfo } from '@vue/devtools-core'
const getRoot = callViteServerAction<string>('get-vite-root')
const getGraph = callViteServerAction<ModuleInfo[]>('graph:get-modules')
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/vite-bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './client'
export * from './server'
export * from './module-types'
39 changes: 39 additions & 0 deletions packages/core/src/vite-bridge/module-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// assets
export type AssetType = 'image' | 'font' | 'video' | 'audio' | 'text' | 'json' | 'other'
export interface AssetInfo {
path: string
type: AssetType
publicPath: string
filePath: string
size: number
mtime: number
}
export interface ImageMeta {
width: number
height: number
orientation?: number
type?: string
mimeType?: string
}

export interface AssetEntry {
path: string
content: string
encoding?: BufferEncoding
override?: boolean
}

export interface CodeSnippet {
code: string
lang: string
name: string
docs?: string
}

// graph
export interface ModuleInfo {
id: string
plugins: { name: string, transform?: number, resolveId?: number }[]
deps: string[]
virtual: boolean
}
33 changes: 1 addition & 32 deletions packages/vite/src/modules/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,11 @@ import type { ViteInspectAPI } from 'vite-plugin-inspect'
import { debounce } from 'perfect-debounce'
import type { ResolvedConfig, ViteDevServer } from 'vite'
import { callViteClientListener, defineViteServerAction } from '@vue/devtools-core'
import type { AssetInfo, AssetType, ImageMeta } from '@vue/devtools-core'
import fg from 'fast-glob'
import { join, resolve } from 'pathe'
import { imageMeta } from 'image-meta'

// assets
export type AssetType = 'image' | 'font' | 'video' | 'audio' | 'text' | 'json' | 'other'
export interface AssetInfo {
path: string
type: AssetType
publicPath: string
filePath: string
size: number
mtime: number
}
export interface ImageMeta {
width: number
height: number
orientation?: number
type?: string
mimeType?: string
}

export interface AssetEntry {
path: string
content: string
encoding?: BufferEncoding
override?: boolean
}

export interface CodeSnippet {
code: string
lang: string
name: string
docs?: string
}

const defaultAllowedExtensions = [
'png',
'jpg',
Expand Down
8 changes: 0 additions & 8 deletions packages/vite/src/modules/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import { debounce } from 'perfect-debounce'
import type { ViteDevServer } from 'vite'
import { callViteClientListener, defineViteServerAction } from '@vue/devtools-core'

// graph
export interface ModuleInfo {
id: string
plugins: { name: string, transform?: number, resolveId?: number }[]
deps: string[]
virtual: boolean
}

export function setupGraphModule(options: { rpc: ViteInspectAPI['rpc'], server: ViteDevServer }) {
const { rpc, server } = options

Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c18de5

Please sign in to comment.