@@ -7,6 +7,7 @@ import { parseModule } from 'magicast'
77import { addNuxtModule , getDefaultExportOptions } from 'magicast/helpers'
88import { checkForUpdateOf } from '../npm'
99import type { NpmCommandOptions , NpmCommandType , NuxtDevtoolsServerContext , PackageUpdateInfo , ServerFunctions } from '../types'
10+ import { magicastGuard } from '../utils/magicast'
1011
1112export function setupNpmRPC ( { nuxt, ensureDevAuthToken } : NuxtDevtoolsServerContext ) {
1213 let detectPromise : Promise < PackageManager | undefined > | undefined
@@ -97,11 +98,13 @@ export function setupNpmRPC({ nuxt, ensureDevAuthToken }: NuxtDevtoolsServerCont
9798 let source = latestGenerated
9899 if ( source == null )
99100 source = await fs . readFile ( filepath , 'utf-8' )
100- const mod = parseModule ( source , { sourceFileName : filepath } )
101101
102- addNuxtModule ( mod , name )
102+ const generated = await magicastGuard ( async ( ) => {
103+ const mod = parseModule ( source ! , { sourceFileName : filepath } )
104+ addNuxtModule ( mod , name )
103105
104- const generated = mod . generate ( ) . code
106+ return mod . generate ( ) . code
107+ } )
105108 const processId = `nuxt:add-module:${ name } `
106109
107110 if ( ! dry ) {
@@ -153,20 +156,22 @@ export function setupNpmRPC({ nuxt, ensureDevAuthToken }: NuxtDevtoolsServerCont
153156
154157 const filepath = nuxt . options . _nuxtConfigFile
155158 const source = await fs . readFile ( filepath , 'utf-8' )
156- const mod = parseModule ( source , { sourceFileName : filepath } )
157-
158- // TODO: remove module from config
159- // removeNuxtModule(mod, name)
160- const config = getDefaultExportOptions ( mod )
161- config . modules ||= [ ]
162- if ( config . modules . includes ( name ) ) {
163- Object . values ( config . modules ) . forEach ( ( value , index ) => {
164- if ( value === name )
165- config . modules . splice ( index - 1 , 1 )
166- } )
167- }
159+ const generated = await magicastGuard ( async ( ) => {
160+ const mod = parseModule ( source , { sourceFileName : filepath } )
161+
162+ // TODO: remove module from config
163+ // removeNuxtModule(mod, name)
164+ const config = getDefaultExportOptions ( mod )
165+ config . modules ||= [ ]
166+ if ( config . modules . includes ( name ) ) {
167+ Object . values ( config . modules ) . forEach ( ( value , index ) => {
168+ if ( value === name )
169+ config . modules . splice ( index - 1 , 1 )
170+ } )
171+ }
168172
169- const generated = mod . generate ( ) . code
173+ return mod . generate ( ) . code
174+ } )
170175
171176 const processId = `nuxt:remove-module:${ name } `
172177
0 commit comments