Skip to content

Commit 11f609c

Browse files
authored
feat: add support for typescript plugins (#35)
1 parent 5c5b2b0 commit 11f609c

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

api/src/routers/plugins.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@data-fair/processings-shared",
33
"type": "module",
44
"devDependencies": {
5-
"@data-fair/lib-express": "^1.8.0"
5+
"@data-fair/lib-express": "^1.13.1"
66
},
77
"dependencies": {
88
"@data-fair/lib-node": "^2.1.0",

ui/dts/typed-router.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ declare module 'vue-router/auto-routes' {
2020
export interface RouteNamedMap {
2121
'/admin/': RouteRecordInfo<'/admin/', '/admin', Record<never, never>, Record<never, never>>,
2222
'/admin/plugins': RouteRecordInfo<'/admin/plugins', '/admin/plugins', Record<never, never>, Record<never, never>>,
23-
'/dev': RouteRecordInfo<'/dev', '/dev', Record<never, never>, Record<never, never>>,
2423
'/processings/': RouteRecordInfo<'/processings/', '/processings', Record<never, never>, Record<never, never>>,
2524
'/processings/[id]': RouteRecordInfo<'/processings/[id]', '/processings/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,
2625
'/runs/[id]': RouteRecordInfo<'/runs/[id]', '/runs/:id', { id: ParamValue<true> }, { id: ParamValue<false> }>,

worker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@data-fair/lib-common-types": "^1.5.4",
16-
"@data-fair/lib-express": "^1.12.6",
16+
"@data-fair/lib-express": "^1.13.1",
1717
"@types/child-process-promise": "^2.2.6",
1818
"@types/nodemailer": "^6.4.16",
1919
"@types/resolve-path": "^1.4.3"

0 commit comments

Comments
 (0)