@@ -70,14 +70,22 @@ router.post('/', permissions.isSuperAdmin, async (req, res) => {
7070 // create a pseudo npm package with a dependency to the plugin referenced from the registry
7171 await fs . writeFile ( path . join ( dir . path , 'package.json' ) , JSON . stringify ( {
7272 name : plugin . id . replace ( '@' , '' ) ,
73+ type : 'module' ,
7374 dependencies : {
7475 [ plugin . name ] : '^' + plugin . version
7576 }
7677 } , null , 2 ) )
7778 await exec ( 'npm install --omit=dev' , { cwd : dir . path } )
78- await fs . writeFile ( path . join ( dir . path , 'index.js' ) , `module.exports = require('${ plugin . name } ')` )
79- plugin . pluginConfigSchema = await fs . readJson ( path . join ( dir . path , 'node_modules' , plugin . name , 'plugin-config-schema.json' ) )
80- plugin . processingConfigSchema = await fs . readJson ( path . join ( dir . path , 'node_modules' , plugin . name , 'processing-config-schema.json' ) )
79+
80+ // move the plugin to the src directory (Stripping types is currently unsupported for files under node_modules)
81+ await fs . move ( path . join ( dir . path , 'node_modules' , plugin . name ) , path . join ( dir . path , 'src' ) , { overwrite : true } )
82+
83+ // generate an index.js file to export the main file
84+ const mainFile = ( await fs . readJson ( path . join ( dir . path , 'src' , 'package.json' ) ) ) . main || 'index.js'
85+ await fs . writeFile ( path . join ( dir . path , 'index.js' ) , `export * from './${ path . join ( 'src' , mainFile ) } '` )
86+
87+ plugin . pluginConfigSchema = await fs . readJson ( path . join ( dir . path , 'src' , 'plugin-config-schema.json' ) )
88+ plugin . processingConfigSchema = await fs . readJson ( path . join ( dir . path , 'src' , 'processing-config-schema.json' ) )
8189 await fs . writeFile ( path . join ( dir . path , 'plugin.json' ) , JSON . stringify ( plugin , null , 2 ) )
8290 await fs . move ( dir . path , pluginDir , { overwrite : true } )
8391 } finally {
0 commit comments