From 5fc78ca4052759a2f0421055b4193eb5cc3f4560 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Thu, 17 Apr 2025 16:06:33 +0200 Subject: [PATCH 1/5] feat: use previous meta and prevent duplicate parse --- .github/workflows/ci.yml | 2 + package.json | 1 + pnpm-lock.yaml | 70 ++++++++++++++----------- src/module.ts | 15 +++--- src/parser.ts | 108 +++++++++++++++++++++++---------------- src/unplugin.ts | 26 ++++++---- 6 files changed, 132 insertions(+), 90 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78a4140..70fc50a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,8 @@ on: push: branches: - main + - feat/* + - fix/* pull_request: branches: - main diff --git a/package.json b/package.json index 0d7df12..52816ec 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@nuxt/kit": "^3.15.1", "citty": "^0.1.6", "mlly": "^1.7.4", + "ohash": "^2.0.11", "scule": "^1.3.0", "typescript": "^5.7.3", "ufo": "^1.5.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4735d7f..77da445 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: mlly: specifier: ^1.7.4 version: 1.7.4 + ohash: + specifier: ^2.0.11 + version: 2.0.11 scule: specifier: ^1.3.0 version: 1.3.0 @@ -5114,6 +5117,7 @@ packages: lodash.pick@4.4.0: resolution: {integrity: sha512-hXt6Ul/5yWjfklSGvLQl8vM//l3FtyHZeuelpzK6mm99pNvN9yTDruNZPEJZD1oWrqo+izBmB7oUfWgcCX7s4Q==} + deprecated: This package is deprecated. Use destructuring assignment syntax instead. lodash.uniq@4.5.0: resolution: {integrity: sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==} @@ -5784,12 +5788,12 @@ packages: ofetch@1.4.1: resolution: {integrity: sha512-QZj2DfGplQAr2oj9KzceK9Hwz6Whxazmn85yYeVuS3u9XTMOGMRx0kO95MQ+vLsj/S/NwBDMMLU5hpxvI6Tklw==} - ohash@1.1.3: - resolution: {integrity: sha512-zuHHiGTYTA1sYJ/wZN+t5HKZaH23i4yI1HMwbuXm24Nid7Dv0KcuRlKoNKS9UNfAVSBlnGLcuQrnOKWOZoEGaw==} - ohash@1.1.4: resolution: {integrity: sha512-FlDryZAahJmEF3VR3w1KogSEdWX3WhA5GPakFx4J81kEAiHyLMpdLLElS8n8dfNadMgAne/MywcvmogzscVt4g==} + ohash@2.0.11: + resolution: {integrity: sha512-RdR9FQrFwNBNXAr4GixM8YaRZRJ5PUWbKYbE5eOsrwAjJW0q2REGcf79oYPsLyskQCZG1PLN+S/K1V00joZAoQ==} + on-finished@2.4.1: resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} engines: {node: '>= 0.8'} @@ -6543,6 +6547,7 @@ packages: read-package-json@7.0.0: resolution: {integrity: sha512-uL4Z10OKV4p6vbdvIXB+OzhInYtIozl/VxUBPgNkBuUi2DeRonnuspmaVAMcrkmfjKGNmRndyQAbE7/AmzGwFg==} engines: {node: ^16.14.0 || >=18.0.0} + deprecated: This package is no longer supported. Please use @npmcli/package-json instead. read-pkg-up@7.0.1: resolution: {integrity: sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==} @@ -6906,12 +6911,15 @@ packages: shikiji-core@0.9.12: resolution: {integrity: sha512-AYsAtsbZuq0FPT3mdskNMa+yxD5VwXrFC2sH7R2ELmncVGNYvSzR6Zlfq8iEzINq7/kKL5prtt81UFzFWTTbxQ==} + deprecated: Deprecated, use @shikijs/core instead shikiji-transformers@0.9.12: resolution: {integrity: sha512-ge+47j4MLTbKAnTnhTTolD9DKGW2Fhp80MV7Tb2E+p4HsJixu4slq2SDV/eFR34iH/egtyi/cjGMD8vJbNLBUA==} + deprecated: Deprecated, use @shikijs/transformers instead shikiji@0.9.12: resolution: {integrity: sha512-jYbulSGcPKYKu2uFZOSg4lgrF7s9s8/ITFzRvczE6633wypMjnnTcRnG/mCFe6v1Dbov7bRCMsXVINBUD2FV9w==} + deprecated: Deprecated, use shiki instead side-channel@1.0.4: resolution: {integrity: sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==} @@ -9638,7 +9646,7 @@ snapshots: micromark-util-sanitize-uri: 2.0.0 micromark-util-types: 2.0.0 minisearch: 6.3.0 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.1 scule: 1.1.1 shiki-es: 0.14.0 @@ -9814,7 +9822,7 @@ snapshots: nuxt: 3.9.0(@parcel/watcher@2.4.1)(@types/node@20.10.5)(encoding@0.1.13)(eslint@9.18.0(jiti@2.4.2))(magicast@0.3.5)(optionator@0.9.3)(rollup@4.30.1)(terser@5.26.0)(typescript@5.3.3)(vite@5.4.10(@types/node@20.10.5)(terser@5.26.0))(webpack-sources@3.2.3) nypm: 0.3.3 ofetch: 1.3.3 - ohash: 1.1.3 + ohash: 1.1.4 pacote: 17.0.5 pathe: 1.1.1 perfect-debounce: 1.0.0 @@ -9877,7 +9885,7 @@ snapshots: nuxt: 3.9.0(@parcel/watcher@2.4.1)(@types/node@20.10.5)(encoding@0.1.13)(eslint@9.18.0(jiti@2.4.2))(magicast@0.3.5)(optionator@0.9.3)(rollup@4.9.1)(terser@5.26.0)(typescript@5.7.3)(vite@5.0.10(@types/node@20.10.5)(terser@5.26.0))(webpack-sources@3.2.3) nypm: 0.3.3 ofetch: 1.3.3 - ohash: 1.1.3 + ohash: 1.1.4 pacote: 17.0.5 pathe: 1.1.1 perfect-debounce: 1.0.0 @@ -10493,7 +10501,7 @@ snapshots: knitwork: 1.0.0 magic-string: 0.30.5 mlly: 1.7.4 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.1 perfect-debounce: 1.0.0 pkg-types: 1.0.3 @@ -10549,7 +10557,7 @@ snapshots: knitwork: 1.0.0 magic-string: 0.30.5 mlly: 1.7.4 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.1 perfect-debounce: 1.0.0 pkg-types: 1.0.3 @@ -10586,12 +10594,12 @@ snapshots: '@nuxtjs/eslint-config-typescript@12.1.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3)': dependencies: - '@nuxtjs/eslint-config': 12.0.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + '@nuxtjs/eslint-config': 12.0.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) '@typescript-eslint/eslint-plugin': 6.16.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3) '@typescript-eslint/parser': 6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3) eslint: 9.18.0(jiti@2.4.2) - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1)(eslint@9.18.0(jiti@2.4.2)) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) eslint-plugin-vue: 9.19.2(eslint@9.18.0(jiti@2.4.2)) transitivePeerDependencies: - eslint-import-resolver-node @@ -10599,11 +10607,11 @@ snapshots: - supports-color - typescript - '@nuxtjs/eslint-config@12.0.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2))': + '@nuxtjs/eslint-config@12.0.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2))': dependencies: eslint: 9.18.0(jiti@2.4.2) - eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint-plugin-n@15.7.0(eslint@9.18.0(jiti@2.4.2)))(eslint-plugin-promise@6.1.1(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-config-standard: 17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@15.7.0(eslint@9.18.0(jiti@2.4.2)))(eslint-plugin-promise@6.1.1(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) eslint-plugin-n: 15.7.0(eslint@9.18.0(jiti@2.4.2)) eslint-plugin-node: 11.1.0(eslint@9.18.0(jiti@2.4.2)) eslint-plugin-promise: 6.1.1(eslint@9.18.0(jiti@2.4.2)) @@ -10630,7 +10638,7 @@ snapshots: hast-util-to-string: 3.0.0 mdast-util-to-hast: 13.0.2 micromark-util-sanitize-uri: 2.0.0 - ohash: 1.1.3 + ohash: 1.1.4 property-information: 6.4.0 rehype-external-links: 3.0.0 rehype-raw: 7.0.0 @@ -12688,7 +12696,7 @@ snapshots: giget: 1.2.3 jiti: 1.21.6 mlly: 1.7.4 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.2 perfect-debounce: 1.0.0 pkg-types: 1.2.0 @@ -12704,7 +12712,7 @@ snapshots: giget: 1.2.1 jiti: 1.21.6 mlly: 1.7.4 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.1 perfect-debounce: 1.0.0 pkg-types: 1.0.3 @@ -13691,10 +13699,10 @@ snapshots: transitivePeerDependencies: - eslint - eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint-plugin-n@15.7.0(eslint@9.18.0(jiti@2.4.2)))(eslint-plugin-promise@6.1.1(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)): + eslint-config-standard@17.1.0(eslint-plugin-import@2.29.1)(eslint-plugin-n@15.7.0(eslint@9.18.0(jiti@2.4.2)))(eslint-plugin-promise@6.1.1(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)): dependencies: eslint: 9.18.0(jiti@2.4.2) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) eslint-plugin-n: 15.7.0(eslint@9.18.0(jiti@2.4.2)) eslint-plugin-promise: 6.1.1(eslint@9.18.0(jiti@2.4.2)) @@ -13710,13 +13718,13 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)): + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1)(eslint@9.18.0(jiti@2.4.2)): dependencies: debug: 4.3.4 enhanced-resolve: 5.15.0 eslint: 9.18.0(jiti@2.4.2) - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) fast-glob: 3.3.2 get-tsconfig: 4.7.2 is-core-module: 2.13.1 @@ -13731,14 +13739,14 @@ snapshots: dependencies: eslint: 9.18.0(jiti@2.4.2) - eslint-module-utils@2.8.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)): + eslint-module-utils@2.8.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3) eslint: 9.18.0(jiti@2.4.2) eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1)(eslint@9.18.0(jiti@2.4.2)) transitivePeerDependencies: - supports-color @@ -13774,7 +13782,7 @@ snapshots: - supports-color - typescript - eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)): + eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)): dependencies: array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 @@ -13784,7 +13792,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.18.0(jiti@2.4.2) eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-plugin-import@2.29.1(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)))(eslint@9.18.0(jiti@2.4.2)) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.16.0(eslint@9.18.0(jiti@2.4.2))(typescript@5.7.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@9.18.0(jiti@2.4.2)) hasown: 2.0.0 is-core-module: 2.13.1 is-glob: 4.0.3 @@ -15921,7 +15929,7 @@ snapshots: mri: 1.2.0 node-fetch-native: 1.6.1 ofetch: 1.3.3 - ohash: 1.1.3 + ohash: 1.1.4 openapi-typescript: 6.7.3 pathe: 1.1.1 perfect-debounce: 1.0.0 @@ -16272,7 +16280,7 @@ snapshots: nuxi: 3.10.0 nypm: 0.3.3 ofetch: 1.3.3 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.1 perfect-debounce: 1.0.0 pkg-types: 1.0.3 @@ -16371,7 +16379,7 @@ snapshots: nuxi: 3.10.0 nypm: 0.3.3 ofetch: 1.3.3 - ohash: 1.1.3 + ohash: 1.1.4 pathe: 1.1.1 perfect-debounce: 1.0.0 pkg-types: 1.0.3 @@ -16509,10 +16517,10 @@ snapshots: node-fetch-native: 1.6.4 ufo: 1.5.4 - ohash@1.1.3: {} - ohash@1.1.4: {} + ohash@2.0.11: {} + on-finished@2.4.1: dependencies: ee-first: 1.1.1 diff --git a/src/module.ts b/src/module.ts index bf29ccd..b278abf 100644 --- a/src/module.ts +++ b/src/module.ts @@ -182,17 +182,20 @@ export default defineNuxtModule({ parser = useComponentMetaParser(parserOptions) // Stub output in case it does not exist yet - await parser.stubOutput() + await Promise.all([ + parser.init(), + parser.stubOutput(), + ]) }) // Add useComponentMeta addImportsDir(resolver.resolve('./runtime/composables')) - addTemplate({ - filename: 'component-meta.mjs', - getContents: () => 'export default {}', - write: true - }) + // addTemplate({ + // filename: 'component-meta.mjs', + // getContents: () => 'export default {}', + // write: true + // }) addTemplate({ filename: 'component-meta.d.ts', diff --git a/src/parser.ts b/src/parser.ts index addf317..6ed229f 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1,11 +1,11 @@ -import { writeFile, readFile, unlink, mkdir } from 'fs/promises' import { performance } from 'perf_hooks' -import { existsSync } from 'fs' +import fs, { existsSync } from 'fs' import { dirname, join, relative } from 'pathe' import { logger } from '@nuxt/kit' import { createCheckerByJson } from 'vue-component-meta' import type { Component } from '@nuxt/schema' import { resolvePathSync } from 'mlly' +import { hash } from 'ohash' import type { ModuleOptions } from './options' import type { NuxtComponentMeta } from './types' import { defu } from 'defu' @@ -48,31 +48,6 @@ export function useComponentMetaParser ( }) } - /** - * Initialize component data object from components - */ - const components: NuxtComponentMeta = { ...metaSources } - for (const component of _components || []) { - // Locally support exclude as it seem broken from createCheckerByJson - if (isExcluded(component)) { continue } - if (!component.filePath || !component.pascalName) { continue } - - const filePath = resolvePathSync(component.filePath) - - components[component.pascalName] = { - ...component, - fullPath: filePath, - filePath: relative(rootDir, filePath), - meta: { - type: 0, - props: [], - slots: [], - events: [], - exposed: [] - } - } - } - const getStringifiedComponents = () => { const _components = Object.keys(components).map((key) => ([ key, @@ -111,14 +86,51 @@ 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) + + for (const component of _components || []) { + // Locally support exclude as it seem broken from createCheckerByJson + if (isExcluded(component)) { continue } + if (!component.filePath || !component.pascalName) { continue } + + const filePath = resolvePathSync(component.filePath) + + components[component.pascalName] = { + ...component, + fullPath: filePath, + filePath: relative(rootDir, filePath), + meta: { + type: 0, + props: [], + slots: [], + events: [], + exposed: [] + } + } + } + + Object.keys(meta).forEach((key) => { + if (components[key]) { + components[key].meta = meta[key].meta + } else { + components[key] = meta[key] + } + }) + } + /** * Write the output file. */ - const updateOutput = async (content?: string) => { + const updateOutput = (content?: string) => { const path = outputPath + '.mjs' - if (!existsSync(dirname(path))) { await mkdir(dirname(path), { recursive: true }) } - if (existsSync(path)) { await unlink(path) } - await writeFile( + if (!existsSync(dirname(path))) { fs.mkdirSync(dirname(path), { recursive: true }) } + if (existsSync(path)) { fs.unlinkSync(path) } + fs.writeFileSync( path, content || getVirtualModuleContent(), 'utf-8' @@ -136,12 +148,12 @@ export function useComponentMetaParser ( /** * Fetch a component metas by its file name. */ - const fetchComponent = async (component: string | any) => { + const fetchComponent = (component: string | any) => { // Create the checker at the very last moment and silently fail if unavailable. if (!checker) { try { refreshChecker() - } catch (e) { + } catch { return } } @@ -164,23 +176,30 @@ export function useComponentMetaParser ( // Component is missing required values if (!component?.fullPath || !component?.pascalName) { return } + // Read component code + let code = fs.readFileSync(component.fullPath, 'utf-8') + const codeHash = hash(code) + if (codeHash === component.meta.hash) { + return + } + // Support transformers if (transformers && transformers.length > 0) { - // Read component code - let code = await readFile(component.fullPath, 'utf-8') - for (const transform of transformers) { const transformResult = transform(component, code) component = transformResult?.component || component code = transformResult?.code || code } + // Ensure file is updated checker.updateFile(component.fullPath, code) } + const { type, props, slots, events, exposed } = checker.getComponentMeta(component.fullPath) + component.meta.hash = codeHash component.meta.type = metaFields.type ? type : 0 component.meta.slots = metaFields.slots ? slots : [] component.meta.events = metaFields.events ? events : [] @@ -211,9 +230,7 @@ export function useComponentMetaParser ( component.meta.exposed = component.meta.exposed.map((sch: any) => stripeTypeScriptInternalTypesSchema(sch, true)) component.meta.events = component.meta.events.map((sch: any) => stripeTypeScriptInternalTypesSchema(sch, true)) - - const content = await readFile(component.fullPath, 'utf-8') - const extendComponentMetaMatch = content.match(/extendComponentMeta\((\{[\s\S]*?\})\)/); + const extendComponentMetaMatch = code.match(/extendComponentMeta\((\{[\s\S]*?\})\)/); const extendedComponentMeta = extendComponentMetaMatch?.length ? eval(`(${extendComponentMetaMatch[1]})`) : null component.meta = defu(component.meta, extendedComponentMeta) @@ -221,8 +238,10 @@ export function useComponentMetaParser ( removeFields(component.meta, ['declarations']) components[component.pascalName] = component - } catch (e) { - debug && logger.info(`Could not parse ${component?.pascalName || component?.filePath || 'a component'}!`) + } catch { + if (debug) { + logger.info(`Could not parse ${component?.pascalName || component?.filePath || 'a component'}!`) + } } const endTime = performance.now() if (debug === 2) { logger.success(`${component?.pascalName || component?.filePath || 'a component'} metas parsed in ${(endTime - startTime).toFixed(2)}ms`) } @@ -231,9 +250,11 @@ export function useComponentMetaParser ( /** * Fetch all components metas */ - const fetchComponents = async () => { + const fetchComponents = () => { const startTime = performance.now() - await Promise.all(Object.values(components).map(fetchComponent)) + for (const component of Object.values(components)) { + fetchComponent(component) + } const endTime = performance.now() if (!debug || debug === 2) { logger.success(`Components metas parsed in ${(endTime - startTime).toFixed(2)}ms`) } } @@ -241,6 +262,7 @@ export function useComponentMetaParser ( return { get checker () { return checker }, get components () { return components }, + init, refreshChecker, stubOutput, outputPath, diff --git a/src/unplugin.ts b/src/unplugin.ts index 430b4f3..a243d81 100644 --- a/src/unplugin.ts +++ b/src/unplugin.ts @@ -3,32 +3,38 @@ import { type ComponentMetaParser, useComponentMetaParser, type ComponentMetaPar type ComponentMetaUnpluginOptions = { parser?: ComponentMetaParser, parserOptions: ComponentMetaParserOptions } -export const metaPlugin = createUnplugin( - ({ parser, parserOptions }) => { +// @ts-ignore -- arguments types are not correct +export const metaPlugin = createUnplugin(({ parser, parserOptions }) => { const instance = parser || useComponentMetaParser(parserOptions) let _configResolved: any - return { + return [ + { + name: 'vite-plugin-nuxt-component-meta', + enforce: 'before', + }, + { name: 'vite-plugin-nuxt-component-meta', enforce: 'post', - async buildStart () { + buildStart () { // avoid parsing meta twice in SSR if (_configResolved?.build.ssr) { return } - await instance.fetchComponents() - await instance.updateOutput() + + instance.fetchComponents() + instance.updateOutput() }, vite: { configResolved (config) { _configResolved = config }, - async handleHotUpdate ({ file }) { + handleHotUpdate ({ file }) { if (Object.entries(instance.components).some(([, comp]: any) => comp.fullPath === file)) { - await instance.fetchComponent(file) - await instance.updateOutput() + instance.fetchComponent(file) + instance.updateOutput() } } } - } + }] }) From e8d96f81e06bdab6207a041b762908eda3105539 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Thu, 17 Apr 2025 17:24:53 +0200 Subject: [PATCH 2/5] reduce io operation by ignoring cached components from node packages --- src/parser.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parser.ts b/src/parser.ts index 6ed229f..04dc20d 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -176,6 +176,11 @@ export function useComponentMetaParser ( // Component is missing required values if (!component?.fullPath || !component?.pascalName) { return } + if (component.meta.hash && component.fullPath.includes('/node_modules/')) { + // We assume that components from node_modules don't change + return + } + // Read component code let code = fs.readFileSync(component.fullPath, 'utf-8') const codeHash = hash(code) From 83f5d3808967c7c886494952ed2797915396283f Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Thu, 17 Apr 2025 17:29:25 +0200 Subject: [PATCH 3/5] fix: initate checker is needed --- src/parser.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 04dc20d..6f916d4 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -149,15 +149,6 @@ export function useComponentMetaParser ( * Fetch a component metas by its file name. */ const fetchComponent = (component: string | any) => { - // Create the checker at the very last moment and silently fail if unavailable. - if (!checker) { - try { - refreshChecker() - } catch { - return - } - } - const startTime = performance.now() try { if (typeof component === 'string') { @@ -188,6 +179,15 @@ export function useComponentMetaParser ( return } + // Create the checker at the very last moment and silently fail if unavailable. + if (!checker) { + try { + refreshChecker() + } catch { + return + } + } + // Support transformers if (transformers && transformers.length > 0) { for (const transform of transformers) { From fd07bb1b02ae9e77922c285eaf68c373f48ee4b0 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Thu, 17 Apr 2025 17:33:35 +0200 Subject: [PATCH 4/5] cleanup --- src/unplugin.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/unplugin.ts b/src/unplugin.ts index a243d81..ef97c4f 100644 --- a/src/unplugin.ts +++ b/src/unplugin.ts @@ -8,12 +8,7 @@ export const metaPlugin = createUnplugin(({ parser const instance = parser || useComponentMetaParser(parserOptions) let _configResolved: any - return [ - { - name: 'vite-plugin-nuxt-component-meta', - enforce: 'before', - }, - { + return { name: 'vite-plugin-nuxt-component-meta', enforce: 'post', buildStart () { @@ -36,5 +31,5 @@ export const metaPlugin = createUnplugin(({ parser } } } - }] + } }) From 9d23978ac3176df016a8b6ddb8869413c873334d Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Tue, 22 Apr 2025 10:20:02 +0200 Subject: [PATCH 5/5] fix: undefined error --- src/parser.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 6f916d4..49fec09 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -114,13 +114,15 @@ export function useComponentMetaParser ( } } - Object.keys(meta).forEach((key) => { - if (components[key]) { - components[key].meta = meta[key].meta - } else { - components[key] = meta[key] - } - }) + if (meta) { + Object.keys(meta).forEach((key) => { + if (components[key]) { + components[key].meta = meta[key].meta + } else { + components[key] = meta[key] + } + }) + } } /**