@@ -105,10 +105,10 @@ export default defineNuxtModule<ModuleOptions>({
105
105
debug : false ,
106
106
} ,
107
107
async setup ( config , nuxt ) {
108
- const { resolve } = createResolver ( import . meta. url )
109
- const { version, name } = await readPackageJSON ( resolve ( '../package.json' ) )
110
- nuxt . options . alias [ '#nuxt-scripts-validator' ] = resolve ( `./runtime/validation/${ ( nuxt . options . dev || nuxt . options . _prepare ) ? 'valibot' : 'mock' } ` )
111
- nuxt . options . alias [ '#nuxt-scripts' ] = resolve ( './runtime' )
108
+ const { resolvePath } = createResolver ( import . meta. url )
109
+ const { version, name } = await readPackageJSON ( await resolvePath ( '../package.json' ) )
110
+ nuxt . options . alias [ '#nuxt-scripts-validator' ] = await resolvePath ( `./runtime/validation/${ ( nuxt . options . dev || nuxt . options . _prepare ) ? 'valibot' : 'mock' } ` )
111
+ nuxt . options . alias [ '#nuxt-scripts' ] = await resolvePath ( './runtime' )
112
112
logger . level = ( config . debug || nuxt . options . debug ) ? 4 : 3
113
113
if ( ! config . enabled ) {
114
114
// TODO fallback to useHead?
@@ -129,23 +129,36 @@ export default defineNuxtModule<ModuleOptions>({
129
129
defaultScriptOptions : config . defaultScriptOptions ,
130
130
}
131
131
addImportsDir ( [
132
- resolve ( './runtime/composables' ) ,
132
+ await resolvePath ( './runtime/composables' ) ,
133
133
] )
134
134
135
135
addComponentsDir ( {
136
- path : resolve ( './runtime/components' ) ,
136
+ path : await resolvePath ( './runtime/components' ) ,
137
137
} )
138
138
139
- const scripts = registry ( resolve )
139
+ const scripts = await registry ( resolvePath ) as ( RegistryScript & { _importRegistered ?: boolean } ) [ ]
140
+
141
+ for ( const script of scripts ) {
142
+ if ( script . import ?. name ) {
143
+ addImports ( { priority : 2 , ...script . import } )
144
+ script . _importRegistered = true
145
+ }
146
+ }
147
+
140
148
nuxt . hooks . hook ( 'modules:done' , async ( ) => {
141
149
const registryScripts = [ ...scripts ]
142
150
143
151
// @ts -expect-error nuxi prepare is broken to generate these types, possibly because of the runtime path
144
152
await nuxt . hooks . callHook ( 'scripts:registry' , registryScripts )
145
- const registryScriptsWithImport = registryScripts . filter ( i => ! ! i . import ?. name ) as Required < RegistryScript > [ ]
146
- addImports ( registryScriptsWithImport . map ( i => i . import ) )
153
+
154
+ for ( const script of registryScripts ) {
155
+ if ( script . import ?. name && ! script . _importRegistered ) {
156
+ addImports ( { priority : 3 , ...script . import } )
157
+ }
158
+ }
147
159
148
160
// compare the registryScripts to the original registry to find new scripts
161
+ const registryScriptsWithImport = registryScripts . filter ( i => ! ! i . import ?. name ) as Required < RegistryScript > [ ]
149
162
const newScripts = registryScriptsWithImport . filter ( i => ! scripts . some ( r => r . import ?. name === i . import . name ) )
150
163
151
164
// augment types to support the integrations registry
@@ -215,6 +228,6 @@ ${newScripts.map((i) => {
215
228
} )
216
229
217
230
if ( nuxt . options . dev )
218
- setupDevToolsUI ( config , resolve )
231
+ setupDevToolsUI ( config , resolvePath )
219
232
} ,
220
233
} )
0 commit comments