11import path from 'path'
22import fs from 'fs'
33import { spawn , type ChildProcess } from 'child_process'
4- import { createRequire } from 'module'
5- import { defineNuxtModule , createResolver , resolveFiles , addComponent , addImportsDir , extendPages } from '@nuxt/kit'
4+ import { fileURLToPath } from 'url'
5+ import {
6+ defineNuxtModule ,
7+ createResolver ,
8+ resolveFiles ,
9+ addComponent ,
10+ addImportsDir ,
11+ extendPages ,
12+ resolveModule ,
13+ } from '@nuxt/kit'
614import type { NuxtPage , NuxtModule } from '@nuxt/schema'
715import { joinURL , withoutLeadingSlash , withoutTrailingSlash } from 'ufo'
816import { minimatch } from 'minimatch'
@@ -55,22 +63,33 @@ const _module: NuxtModule<NuxtStoriesOptions> = defineNuxtModule<NuxtStoriesOpti
5563 mode : 'all' ,
5664 framePort : 3000 ,
5765 } ,
58- moduleDependencies : {
59- '@primevue/nuxt-module' : {
60- optional : true ,
61- defaults : {
62- autoImport : false ,
63- components : {
64- prefix : 'pv' ,
65- include : [ 'Tree' , 'Button' , 'InputText' , 'Splitter' , 'SplitterPanel' , 'Toolbar' , 'Menu' ] ,
66- } ,
67- options : {
68- theme : {
69- preset : Aura ,
66+ moduleDependencies ( nuxt ) {
67+ const mode =
68+ ( process . env . NUXT_STORIES_MODE as string | undefined ) ||
69+ ( nuxt . options as unknown as { stories ?: { mode ?: string } } ) . stories ?. mode ||
70+ 'all'
71+ if ( mode === 'frame' ) return { }
72+
73+ // pnpm isolation means @primevue /nuxt-module is not in the consumer's node_modules,
74+ // only in nuxt-stories' own. Passing an absolute path as the key bypasses that:
75+ // resolveModuleWithOptions() treats any truthy string as a valid module specifier,
76+ // and loadNuxtModuleInstance() loads absolute paths directly.
77+ try {
78+ return {
79+ [ fileURLToPath ( import . meta. resolve ( '@primevue/nuxt-module' ) ) ] : {
80+ defaults : {
81+ autoImport : false ,
82+ components : {
83+ prefix : 'pv' ,
84+ include : [ 'Tree' , 'Button' , 'InputText' , 'Splitter' , 'SplitterPanel' , 'Toolbar' , 'Menu' ] ,
85+ } ,
86+ options : { theme : { preset : Aura } } ,
7087 } ,
7188 } ,
72- } ,
73- } ,
89+ }
90+ } catch {
91+ return { }
92+ }
7493 } ,
7594 async setup ( options , nuxt ) {
7695 if ( ! options . enabled ) return
@@ -88,10 +107,9 @@ const _module: NuxtModule<NuxtStoriesOptions> = defineNuxtModule<NuxtStoriesOpti
88107 // • build.transpile → prevents Vite AND Nitro from externalising them; Nuxt propagates
89108 // transpile entries to nitro.externals.inline automatically
90109 if ( mode !== 'frame' ) {
91- const _require = createRequire ( import . meta. url )
92110 for ( const pkg of [ 'primevue' , '@primeuix/themes' , 'primeicons' ] ) {
93111 try {
94- nuxt . options . alias [ pkg ] = path . dirname ( _require . resolve ( `${ pkg } /package.json` ) )
112+ nuxt . options . alias [ pkg ] = path . dirname ( resolveModule ( `${ pkg } /package.json` ) )
95113 } catch {
96114 // package not resolvable from this context – skip
97115 }
0 commit comments