@platformatic/service 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/plugins/plugins.js +2 -3
- package/lib/plugins/sandbox-wrapper.js +21 -5
- package/lib/schema.js +25 -1
- package/package.json +7 -6
package/lib/plugins/plugins.js
CHANGED
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
const { join, resolve } = require('path')
|
|
4
4
|
const { readFile } = require('fs/promises')
|
|
5
5
|
const fp = require('fastify-plugin')
|
|
6
|
+
const wrapper = require('./sandbox-wrapper')
|
|
6
7
|
|
|
7
8
|
const { getJSPluginPath, isFileAccessible } = require('../utils')
|
|
8
9
|
|
|
9
|
-
const wrapperPath = join(__dirname, 'sandbox-wrapper.js')
|
|
10
|
-
|
|
11
10
|
async function loadPlugins (app) {
|
|
12
11
|
const configManager = app.platformatic.configManager
|
|
13
12
|
const config = configManager.current
|
|
@@ -45,7 +44,7 @@ async function loadPlugins (app) {
|
|
|
45
44
|
})
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
await app.register(
|
|
47
|
+
await app.register(wrapper, { packages: config.plugins.packages, paths: config.plugins.paths })
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
module.exports = fp(loadPlugins)
|
|
@@ -2,14 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
const fp = require('fastify-plugin')
|
|
4
4
|
const autoload = require('@fastify/autoload')
|
|
5
|
-
const { stat } = require('fs').promises
|
|
5
|
+
const { stat } = require('node:fs').promises
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
const { join } = require('node:path')
|
|
8
|
+
const { pathToFileURL } = require('node:url')
|
|
6
9
|
|
|
7
10
|
module.exports = fp(async function (app, opts) {
|
|
8
|
-
|
|
11
|
+
// fake require next to the configManager dirname
|
|
12
|
+
const _require = createRequire(join(app.platformatic.configManager.dirname, 'package.json'))
|
|
13
|
+
for (const plugin of opts.packages || []) {
|
|
14
|
+
const name = typeof plugin === 'string' ? plugin : plugin.name
|
|
15
|
+
const url = pathToFileURL(_require.resolve(name))
|
|
16
|
+
const loaded = await import(url)
|
|
17
|
+
await app.register(loaded, plugin.options)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (let plugin of opts.paths || []) {
|
|
9
21
|
if (typeof plugin === 'string') {
|
|
10
22
|
plugin = { path: plugin, encapsulate: true }
|
|
11
23
|
}
|
|
12
|
-
if ((await stat(plugin.path)).isDirectory()) {
|
|
24
|
+
if (plugin.path && (await stat(plugin.path)).isDirectory()) {
|
|
13
25
|
const patternOptions = patternOptionsFromPlugin(plugin)
|
|
14
26
|
|
|
15
27
|
app.register(autoload, {
|
|
@@ -27,7 +39,7 @@ module.exports = fp(async function (app, opts) {
|
|
|
27
39
|
...patternOptions
|
|
28
40
|
})
|
|
29
41
|
} else {
|
|
30
|
-
let loaded = await import(
|
|
42
|
+
let loaded = await import(pathToFileURL(plugin.path))
|
|
31
43
|
/* c8 ignore next 3 */
|
|
32
44
|
if (loaded.__esModule === true || typeof loaded.default === 'function') {
|
|
33
45
|
loaded = loaded.default
|
|
@@ -56,7 +68,11 @@ function patternOptionsFromPlugin (plugin) {
|
|
|
56
68
|
const config = {}
|
|
57
69
|
|
|
58
70
|
// Expected keys for autoload plugin options that expect regexp patterns
|
|
59
|
-
const patternOptionKeys = [
|
|
71
|
+
const patternOptionKeys = [
|
|
72
|
+
'ignorePattern',
|
|
73
|
+
'indexPattern',
|
|
74
|
+
'autoHooksPattern'
|
|
75
|
+
]
|
|
60
76
|
|
|
61
77
|
for (const key of patternOptionKeys) {
|
|
62
78
|
const pattern = plugin[key]
|
package/lib/schema.js
CHANGED
|
@@ -422,6 +422,26 @@ const plugins = {
|
|
|
422
422
|
$id: '#plugins',
|
|
423
423
|
type: 'object',
|
|
424
424
|
properties: {
|
|
425
|
+
packages: {
|
|
426
|
+
type: 'array',
|
|
427
|
+
items: {
|
|
428
|
+
anyOf: [{
|
|
429
|
+
type: 'string'
|
|
430
|
+
}, {
|
|
431
|
+
type: 'object',
|
|
432
|
+
properties: {
|
|
433
|
+
name: {
|
|
434
|
+
type: 'string'
|
|
435
|
+
},
|
|
436
|
+
options: {
|
|
437
|
+
type: 'object',
|
|
438
|
+
additionalProperties: true
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
required: ['name']
|
|
442
|
+
}]
|
|
443
|
+
}
|
|
444
|
+
},
|
|
425
445
|
paths: {
|
|
426
446
|
type: 'array',
|
|
427
447
|
items: {
|
|
@@ -517,7 +537,11 @@ const plugins = {
|
|
|
517
537
|
}
|
|
518
538
|
},
|
|
519
539
|
additionalProperties: false,
|
|
520
|
-
|
|
540
|
+
anyOf: [{
|
|
541
|
+
required: ['paths']
|
|
542
|
+
}, {
|
|
543
|
+
required: ['packages']
|
|
544
|
+
}]
|
|
521
545
|
}
|
|
522
546
|
|
|
523
547
|
const metrics = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@fastify/aws-lambda": "^3.3.0",
|
|
21
|
+
"@fastify/compress": "^6.5.0",
|
|
21
22
|
"bindings": "^1.5.0",
|
|
22
23
|
"c8": "^8.0.1",
|
|
23
24
|
"glob": "^10.3.10",
|
|
@@ -68,11 +69,11 @@
|
|
|
68
69
|
"pino-pretty": "^10.2.0",
|
|
69
70
|
"rfdc": "^1.3.0",
|
|
70
71
|
"ua-parser-js": "^1.0.36",
|
|
71
|
-
"@platformatic/client": "1.
|
|
72
|
-
"@platformatic/config": "1.
|
|
73
|
-
"@platformatic/
|
|
74
|
-
"@platformatic/
|
|
75
|
-
"@platformatic/
|
|
72
|
+
"@platformatic/client": "1.12.1",
|
|
73
|
+
"@platformatic/config": "1.12.1",
|
|
74
|
+
"@platformatic/telemetry": "1.12.1",
|
|
75
|
+
"@platformatic/utils": "1.12.1",
|
|
76
|
+
"@platformatic/swagger-ui-theme": "1.12.1"
|
|
76
77
|
},
|
|
77
78
|
"standard": {
|
|
78
79
|
"ignore": [
|