bajo 0.3.3 → 0.3.4
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import resolvePath from './resolve-path.js'
|
|
2
|
-
import { isFunction, isPlainObject } from 'lodash-es'
|
|
2
|
+
import { isFunction, isPlainObject, get } from 'lodash-es'
|
|
3
3
|
import error from './error.js'
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
|
|
6
|
-
async function load (file, asDefaultImport = true, noCache =
|
|
6
|
+
async function load (file, asDefaultImport = true, noCache = true) {
|
|
7
7
|
file = resolvePath(file, true)
|
|
8
8
|
if (noCache) file += `?_=${Date.now()}`
|
|
9
9
|
const imported = await import(file)
|
|
@@ -12,6 +12,13 @@ async function load (file, asDefaultImport = true, noCache = false) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
async function importModule (file, { asDefaultImport, asHandler, noCache } = {}) {
|
|
15
|
+
if (file.includes(':')) {
|
|
16
|
+
const [plugin, path] = file.split(':')
|
|
17
|
+
if (plugin.length > 1) {
|
|
18
|
+
const dir = get(this[plugin], 'config.dir.pkg')
|
|
19
|
+
file = `${dir}${path}`
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
if (!fs.existsSync(file)) return
|
|
16
23
|
let mod = await load(file, asDefaultImport, noCache)
|
|
17
24
|
if (!asHandler) return mod
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
async function startPlugin (name, ...args) {
|
|
2
|
-
const {
|
|
3
|
-
const
|
|
4
|
-
const start = await importModule(`${cfg.dir.pkg}/bajo/start.js`)
|
|
2
|
+
const { importModule } = this.bajo.helper
|
|
3
|
+
const start = await importModule(`${name}:/bajo/start.js`)
|
|
5
4
|
await start.call(this, ...args)
|
|
6
5
|
}
|
|
7
6
|
|
|
@@ -7,8 +7,7 @@ async function collectExitHandlers () {
|
|
|
7
7
|
this.bajo.exitHandler = this.bajo.exitHandler ?? {}
|
|
8
8
|
const names = []
|
|
9
9
|
await eachPlugins(async function ({ plugin, dir }) {
|
|
10
|
-
const
|
|
11
|
-
const mod = await importModule(file)
|
|
10
|
+
const mod = await importModule(`${dir}/bajo/exit.js`)
|
|
12
11
|
if (!mod) return undefined
|
|
13
12
|
this.bajo.exitHandler[plugin] = mod
|
|
14
13
|
names.push(plugin)
|
package/boot/plugins/run.js
CHANGED
|
@@ -8,8 +8,7 @@ async function run () {
|
|
|
8
8
|
for (const f of methods) {
|
|
9
9
|
await runHook(`bajo:${camelCase(`before ${f} all plugins`)}`)
|
|
10
10
|
await eachPlugins(async function ({ plugin, dir }) {
|
|
11
|
-
const
|
|
12
|
-
const mod = await importModule(file)
|
|
11
|
+
const mod = await importModule(`${dir}/bajo/${f}.js`)
|
|
13
12
|
if (mod) {
|
|
14
13
|
log.debug('%s: %s', print.__(upperFirst(f)), plugin)
|
|
15
14
|
await runHook(`bajo:${camelCase(`before ${f} ${plugin}`)}`)
|