bajo 0.2.0 → 0.2.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/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,34 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
+
import fs from 'fs-extra'
|
|
3
|
+
import getGlobalModuleDir from './get-global-module-dir.js'
|
|
2
4
|
import resolvePath from './resolve-path.js'
|
|
3
5
|
import { createRequire } from 'module'
|
|
4
6
|
const require = createRequire(import.meta.url)
|
|
5
7
|
|
|
8
|
+
const findDeep = (item, paths) => {
|
|
9
|
+
let dir
|
|
10
|
+
for (const p of paths) {
|
|
11
|
+
const d = `${p}/${item}`
|
|
12
|
+
if (fs.existsSync(d)) {
|
|
13
|
+
dir = d
|
|
14
|
+
break
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return dir
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
const getModuleDir = (pkgName, base) => {
|
|
21
|
+
if (pkgName === 'app') return resolvePath(process.env.BAJOCWD)
|
|
7
22
|
if (base === 'app') base = process.env.BAJOCWD
|
|
8
|
-
|
|
9
|
-
if (base) pkgPath = `${base}/node_modules/${pkgPath}`
|
|
23
|
+
const pkgPath = pkgName + '/package.json'
|
|
10
24
|
const paths = require.resolve.paths(pkgPath)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const dir = resolvePath(path.dirname(resolved))
|
|
19
|
-
return dir
|
|
25
|
+
const gdir = getGlobalModuleDir()
|
|
26
|
+
paths.unshift(gdir)
|
|
27
|
+
paths.unshift(resolvePath(path.join(process.env.BAJOCWD, 'node_modules')))
|
|
28
|
+
let dir = findDeep(pkgPath, paths)
|
|
29
|
+
if (base && !dir) dir = findDeep(`${base}/node_modules/${pkgPath}`, paths)
|
|
30
|
+
if (!dir) return null
|
|
31
|
+
return resolvePath(path.dirname(dir))
|
|
20
32
|
}
|
|
21
33
|
|
|
22
34
|
export default getModuleDir
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import getGlobalModuleDir from './get-global-module-dir.js'
|
|
2
|
+
import resolvePath from './resolve-path.js'
|
|
3
|
+
import { createRequire } from 'module'
|
|
4
|
+
const require = createRequire(import.meta.url)
|
|
5
|
+
|
|
6
|
+
function getDir (name, ns) {
|
|
7
|
+
const checker = '/package.json'
|
|
8
|
+
name = name + checker
|
|
9
|
+
let dir
|
|
10
|
+
let c = 0
|
|
11
|
+
try {
|
|
12
|
+
dir = require.resolve(resolvePath(name))
|
|
13
|
+
c = 1
|
|
14
|
+
} catch (err) {
|
|
15
|
+
try {
|
|
16
|
+
dir = require.resolve(name)
|
|
17
|
+
c = 2
|
|
18
|
+
} catch (err) {
|
|
19
|
+
try {
|
|
20
|
+
dir = require.resolve(process.cwd() + '/node_modules/' + name)
|
|
21
|
+
c = 3
|
|
22
|
+
} catch (err) {
|
|
23
|
+
try {
|
|
24
|
+
dir = getGlobalModuleDir(name, false)
|
|
25
|
+
c = 4
|
|
26
|
+
} catch (err) {
|
|
27
|
+
if (ns) {
|
|
28
|
+
const d = getGlobalModuleDir(null)
|
|
29
|
+
dir = require.resolve(`${d}/${ns}/node_modules/${name}`)
|
|
30
|
+
c = 5
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!dir) return
|
|
37
|
+
return dir.slice(0, dir.length - checker.length)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getModuleDir = (pkgName, ns) => {
|
|
41
|
+
let dir
|
|
42
|
+
if (pkgName === 'app') {
|
|
43
|
+
dir = process.env.BAJOCWD
|
|
44
|
+
} else {
|
|
45
|
+
dir = getDir(pkgName, ns)
|
|
46
|
+
}
|
|
47
|
+
return dir
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default getModuleDir
|