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
38 changes: 24 additions & 14 deletions packages/core/src/plugins/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import type { PluginOptions, Collection } from '../types'
import { scanComponents } from './utils'
import { watch } from 'chokidar'
import type { VitePlugin } from 'unplugin'
import { resolve } from 'pathe'
import { dirname, resolve } from 'pathe'
import { joinURL } from 'ufo'
import type { Component } from 'vue'
import { parseCompodiumMeta } from './meta/compodium-meta'
import { fileURLToPath } from 'node:url'

export function resolveCollections(options: PluginOptions, viteConfig: any): Collection[] {
const rootDir = options.rootDir ?? viteConfig.root
Expand All @@ -33,20 +34,29 @@ export function resolveCollections(options: PluginOptions, viteConfig: any): Col
}

const libraryCollections = options.includeLibraryCollections
? libraryCollectionsConfig.map(collection => ({
...collection,
exampleDir: {
path: collection.exampleDir,
pattern: '**/*.{vue,tsx}',
prefix: collection.prefix
},
dirs: [{
path: resolve(rootDir, collection.path),
pattern: '**/*.{vue,tsx}',
ignore: collection.ignore,
prefix: collection.prefix
? libraryCollectionsConfig.flatMap((collection) => {
let pkgPath
try {
pkgPath = dirname(fileURLToPath(import.meta.resolve(collection.package)))
} catch {
return []
}

return [{
...collection,
exampleDir: {
path: resolve(collection.exampleDir),
pattern: '**/*.{vue,tsx}',
prefix: collection.prefix
},
dirs: [{
path: resolve(pkgPath, collection.path),
pattern: '**/*.{vue,tsx}',
ignore: collection.ignore,
prefix: collection.prefix
}]
}]
}))
})
: []

return [
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export async function scanComponents(dirs: ComponentsDir[]): Promise<Component[]

const component: Partial<Component> = {
mode,
filePath,
realPath: await realpath(filePath),
filePath: await realpath(filePath),
pascalName,
kebabName
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export type Component = {
shortPath: string
mode?: 'client' | 'server' | 'all'
priority?: number
realPath: string
wrapperComponent?: string
docUrl?: string
examples?: ComponentExample[]
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/app/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function updateComponent() {
if (!component.value) return

await hooks.callHook('renderer:update-component', {
path: component.value.realPath,
path: component.value.filePath,
props: props.value,
wrapper: component.value?.wrapperComponent,
events: componentMeta.value?.events
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const libraryCollections = [
package: '@nuxt/ui',
icon: 'lineicons:nuxt',
exampleDir: resolve('./examples/ui'),
path: 'node_modules/@nuxt/ui/dist/runtime/components',
path: './runtime/components',
ignore: ['App.vue', 'Toast.vue', '*Provider.vue', '*Base.vue', '*Content.vue'],
prefix: 'U',
wrapperComponent: resolve('./examples/ui.vue'),
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/test/playground.nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('nuxt playground', async () => {
? button.componentPath
: undefined

const buttonSourcePath = [button.filePath, button.realPath, componentPath]
const buttonSourcePath = [button.filePath, componentPath]
.find(path => path?.includes('@nuxt/ui'))

if (!buttonSourcePath) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/test/playground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('vue playground', async () => {
? button.componentPath
: undefined

const buttonSourcePath = [button.filePath, button.realPath, componentPath]
const buttonSourcePath = [button.filePath, componentPath]
.find(path => path?.includes('@nuxt/ui'))

if (!buttonSourcePath) {
Expand Down
Loading