Skip to content

Commit 283251c

Browse files
committed
chore: add debugger
1 parent a02aaec commit 283251c

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"devDependencies": {
2525
"@antfu/eslint-config-ts": "^0.3.2",
26+
"@types/debug": "^4.1.5",
2627
"@typescript-eslint/eslint-plugin": "^3.9.1",
2728
"eslint": "^7.7.0",
2829
"rollup": "^2.26.4",
@@ -31,6 +32,7 @@
3132
"vite": "^1.0.0-rc.4"
3233
},
3334
"dependencies": {
35+
"debug": "^4.1.1",
3436
"fast-glob": "^3.2.4"
3537
}
3638
}

pnpm-lock.yaml

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generator/resolver.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import Debug from 'debug'
12
import { Context } from '../types'
23
import { RESOLVER_EXT } from '../constants'
34

5+
const debug = Debug('vite-plugin-components:resolver')
6+
47
export function isResolverPath(reqPath: string) {
58
return reqPath.endsWith(RESOLVER_EXT)
69
}
@@ -10,6 +13,9 @@ export function generateResolver(ctx: Context, reqPath: string) {
1013
const names = ctx.importMap[sfcPath] || []
1114
const components = ctx.components.filter(i => names.includes(i[0]) && i[1] !== sfcPath)
1215

16+
debug(`resolving ${sfcPath}`)
17+
debug(`components [${names.join(', ')}]`)
18+
1319
return `
1420
${components.map(([name, path]) => `import ${name} from "${path}"`).join('\n')}
1521

src/glob.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import path from 'path'
22
import fg from 'fast-glob'
3+
import Debug from 'debug'
34
import { Context, ComponentsInfo } from './types'
45

6+
const debug = Debug('vite-plugin-components:glob')
7+
58
function toArray<T>(arr: T | T[]): T[] {
69
if (Array.isArray(arr))
710
return arr
@@ -24,6 +27,8 @@ export async function searchComponents(ctx: Context, force = false) {
2427
: `${i}/*.${extsGlob}`,
2528
)
2629

30+
debug(`searching start with: [${globs.join(', ')}]`)
31+
2732
const files = await fg(globs, {
2833
ignore: [
2934
'node_modules',
@@ -36,6 +41,9 @@ export async function searchComponents(ctx: Context, force = false) {
3641

3742
const components: ComponentsInfo[] = files.map(f => [path.parse(f).name, `/${f}`])
3843

44+
debug(`${components.length} components found.`)
45+
debug(`[${components.map(i => i).join(', ')}]`)
46+
3947
ctx.components = components
4048
ctx._searchingPromise = undefined
4149
})()

src/plugins/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function createServerPlugin(context: Context): ServerPlugin {
1010
return next()
1111

1212
try {
13-
await searchComponents(context, true)
13+
await searchComponents(context)
1414
ctx.body = await generateResolver(context, ctx.path)
1515
ctx.type = 'js'
1616
ctx.status = 200

0 commit comments

Comments
 (0)