Skip to content

perf: include less files in typescript checker #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:generate": "nuxi generate playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
"lint": "eslint ",
"test": "vitest",
"test": "vitest run",
"verify": "pnpm dev:prepare && pnpm lint && pnpm test",
"release": "pnpm test && release-it"
},
"dependencies": {
Expand Down
32 changes: 17 additions & 15 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export function useComponentMetaParser (
) {
// const logger = consola.withScope('nuxt-component-meta')

/**
* Initialize component data object from components
*/
let components: NuxtComponentMeta = { ...metaSources }
const outputPath = join(outputDir, 'component-meta')

const isExcluded = (component: any) => {
Expand Down Expand Up @@ -70,26 +74,17 @@ export function useComponentMetaParser (
{
extends: `${rootDir}/tsconfig.json`,
skipLibCheck: true,
include: [
'**/*',
...componentDirs.map((dir) => {
const path = typeof dir === 'string' ? dir : (dir?.path || '')
if (path.endsWith('.vue')) {
return path
}
return `${path}/**/*`
})
],
include: componentDirs.map((dir) => {
const path = typeof dir === 'string' ? dir : (dir?.path || '')
const ext = path.split('.').pop()!
return ['vue', 'ts', 'tsx', 'js', 'jsx'].includes(ext) ? path : `${path}/**/*`
}),
exclude: []
},
checkerOptions
)
}

/**
* Initialize component data object from components
*/
const components: NuxtComponentMeta = { ...metaSources }
const init = async () => {
const meta = await import(outputPath + '.mjs').then((m) => m.default || m).catch(() => null)

Expand Down Expand Up @@ -171,7 +166,7 @@ export function useComponentMetaParser (

if (component.meta.hash && component.fullPath.includes('/node_modules/')) {
// We assume that components from node_modules don't change
return
return
}

// Read component code
Expand Down Expand Up @@ -269,6 +264,13 @@ export function useComponentMetaParser (
return {
get checker () { return checker },
get components () { return components },
dispose() {
checker.clearCache()
// @ts-expect-error - Remove checker
checker = null
// Clear components cache
components = {}
},
init,
refreshChecker,
stubOutput,
Expand Down
15 changes: 11 additions & 4 deletions src/unplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type ComponentMetaUnpluginOptions = { parser?: ComponentMetaParser, parserOption

// @ts-ignore -- arguments types are not correct
export const metaPlugin = createUnplugin<ComponentMetaUnpluginOptions>(({ parser, parserOptions }) => {
const instance = parser || useComponentMetaParser(parserOptions)
let instance = parser || useComponentMetaParser(parserOptions)
let _configResolved: any

return {
Expand All @@ -17,15 +17,22 @@ export const metaPlugin = createUnplugin<ComponentMetaUnpluginOptions>(({ parser
return
}

instance.fetchComponents()
instance.updateOutput()
instance?.fetchComponents()
instance?.updateOutput()
},
buildEnd () {
if (!_configResolved?.env.DEV && _configResolved?.env.PROD) {
instance?.dispose()
// @ts-expect-error -- Remove instance from memory
instance = null
}
},
vite: {
configResolved (config) {
_configResolved = config
},
handleHotUpdate ({ file }) {
if (Object.entries(instance.components).some(([, comp]: any) => comp.fullPath === file)) {
if (instance && Object.entries(instance.components).some(([, comp]: any) => comp.fullPath === file)) {
instance.fetchComponent(file)
instance.updateOutput()
}
Expand Down