bajo 0.2.0 → 0.2.2
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/boot/exit-handler.js +3 -1
- package/boot/helper/get-module-dir.js +26 -12
- package/package.json +1 -1
package/boot/exit-handler.js
CHANGED
|
@@ -4,7 +4,9 @@ async function exit (signal) {
|
|
|
4
4
|
await eachPlugins(async function ({ plugin }) {
|
|
5
5
|
const handler = this.bajo.exitHandler[plugin]
|
|
6
6
|
if (!handler) return undefined
|
|
7
|
-
|
|
7
|
+
try {
|
|
8
|
+
await handler.call(this)
|
|
9
|
+
} catch (err) {}
|
|
8
10
|
log.debug('Exited: %s', plugin)
|
|
9
11
|
})
|
|
10
12
|
log.debug('Program shutdown')
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
+
import fs from 'fs-extra'
|
|
3
|
+
import { get } from 'lodash-es'
|
|
4
|
+
import getGlobalModuleDir from './get-global-module-dir.js'
|
|
2
5
|
import resolvePath from './resolve-path.js'
|
|
3
6
|
import { createRequire } from 'module'
|
|
4
7
|
const require = createRequire(import.meta.url)
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
resolved = require.resolve(pkgPath, { paths })
|
|
15
|
-
} catch (err) {
|
|
16
|
-
return null
|
|
9
|
+
function findDeep (item, paths) {
|
|
10
|
+
let dir
|
|
11
|
+
for (const p of paths) {
|
|
12
|
+
const d = `${p}/${item}`
|
|
13
|
+
if (fs.existsSync(d)) {
|
|
14
|
+
dir = d
|
|
15
|
+
break
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
|
-
const dir = resolvePath(path.dirname(resolved))
|
|
19
18
|
return dir
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
function getModuleDir (pkgName, base) {
|
|
22
|
+
if (pkgName === 'app') return resolvePath(process.env.BAJOCWD)
|
|
23
|
+
if (base === 'app') base = process.env.BAJOCWD
|
|
24
|
+
else if (this && this[base]) base = get(this[base], 'config.pkg.name')
|
|
25
|
+
const pkgPath = pkgName + '/package.json'
|
|
26
|
+
const paths = require.resolve.paths(pkgPath)
|
|
27
|
+
const gdir = getGlobalModuleDir()
|
|
28
|
+
paths.unshift(gdir)
|
|
29
|
+
paths.unshift(resolvePath(path.join(process.env.BAJOCWD, 'node_modules')))
|
|
30
|
+
let dir = findDeep(pkgPath, paths)
|
|
31
|
+
if (base && !dir) dir = findDeep(`${base}/node_modules/${pkgPath}`, paths)
|
|
32
|
+
if (!dir) return null
|
|
33
|
+
return resolvePath(path.dirname(dir))
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
export default getModuleDir
|