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.
@@ -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
- await handler.call(this)
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
- const getModuleDir = (pkgName, base) => {
7
- if (base === 'app') base = process.env.BAJOCWD
8
- let pkgPath = pkgName + '/package.json'
9
- if (base) pkgPath = `${base}/node_modules/${pkgPath}`
10
- const paths = require.resolve.paths(pkgPath)
11
- paths.unshift(path.join(process.env.BAJOCWD, 'node_modules', pkgName))
12
- let resolved
13
- try {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {