Skip to content

Commit

Permalink
fix: resolve path to lucide-vue-next
Browse files Browse the repository at this point in the history
The dependency is resolved relative to the location of this module, so that package managers like pnpm without shamefully hoisting, or yarn with Plug'n'play enabled, also work.
  • Loading branch information
JaZo committed Jun 1, 2023
1 parent 2f301d0 commit aaa7940
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -32,7 +32,8 @@
},
"dependencies": {
"@nuxt/kit": "^3.5.1",
"lucide-vue-next": "^0.x"
"lucide-vue-next": "^0.x",
"pathe": "^1.1.0"
},
"devDependencies": {
"@nuxt/eslint-config": "^0.1.1",
Expand Down
14 changes: 11 additions & 3 deletions src/module.ts
@@ -1,4 +1,5 @@
import { defineNuxtModule, addComponent } from '@nuxt/kit';
import { addComponent, createResolver, defineNuxtModule } from '@nuxt/kit';
import { join } from 'pathe';
import * as icons from 'lucide-vue-next';

export interface LucideModuleOptions {
Expand All @@ -18,7 +19,14 @@ export default defineNuxtModule<LucideModuleOptions>({
namePrefix: 'Lucide',
},

setup(options: LucideModuleOptions) {
async setup(options: LucideModuleOptions) {
// Resolve path to lucide-vue-next.
// The dependency is resolved relative to the location of this file, so that package managers like pnpm
// without shamefully hoisting, or yarn with Plug'n'play enabled, also work.
const { resolvePath } = createResolver(import.meta.url)
const entrypoint = await resolvePath('lucide-vue-next') // node_modules/lucide-vue-next/dist/cjs/lucide-vue-next.js
const root = join(entrypoint, '../../..') // node_modules/lucide-vue-next

Object.keys(icons)
.filter((icon) => icon !== 'default')
.filter((icon) => !icon.startsWith('Lucide'))
Expand All @@ -27,7 +35,7 @@ export default defineNuxtModule<LucideModuleOptions>({
addComponent({
name: options.namePrefix + icon,
export: icon,
filePath: 'lucide-vue-next',
filePath: root,
})
);
},
Expand Down

0 comments on commit aaa7940

Please sign in to comment.