From 954a6eb173013de48b05520929ae3565d0637fb0 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Wed, 25 Jun 2025 18:02:06 +0200 Subject: [PATCH 1/2] perf: include less files in typescript checker --- package.json | 3 ++- src/parser.ts | 17 ++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 25dabd6..a98f08c 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "dev:generate": "nuxi generate playground", "dev:prepare": "nuxt-module-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": { diff --git a/src/parser.ts b/src/parser.ts index 49fec09..26b5fd2 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -70,16 +70,11 @@ 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 @@ -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 From 55ad53abe6f8fe28caba7dd8354c658fafb66220 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Thu, 26 Jun 2025 13:22:37 +0200 Subject: [PATCH 2/2] dispose memory after vite build --- package.json | 2 +- src/parser.ts | 15 +++++++++++---- src/unplugin.ts | 15 +++++++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index a98f08c..deee089 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "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 run", "verify": "pnpm dev:prepare && pnpm lint && pnpm test", diff --git a/src/parser.ts b/src/parser.ts index 26b5fd2..88d8289 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -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) => { @@ -81,10 +85,6 @@ export function useComponentMetaParser ( ) } - /** - * 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) @@ -264,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, diff --git a/src/unplugin.ts b/src/unplugin.ts index ef97c4f..54238a0 100644 --- a/src/unplugin.ts +++ b/src/unplugin.ts @@ -5,7 +5,7 @@ type ComponentMetaUnpluginOptions = { parser?: ComponentMetaParser, parserOption // @ts-ignore -- arguments types are not correct export const metaPlugin = createUnplugin(({ parser, parserOptions }) => { - const instance = parser || useComponentMetaParser(parserOptions) + let instance = parser || useComponentMetaParser(parserOptions) let _configResolved: any return { @@ -17,15 +17,22 @@ export const metaPlugin = createUnplugin(({ 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() }