bajo 0.3.6 → 0.3.8
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/helper/break-ns-path.js +9 -6
- package/boot/helper/build-collections.js +1 -1
- package/boot/helper/get-plugin-file.js +3 -1
- package/boot/helper/get-plugin.js +1 -1
- package/boot/helper/import-pkg.js +2 -5
- package/boot/helper/run-hook.js +5 -2
- package/boot/lib/shim.js +2 -3
- package/package.json +1 -1
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { isEmpty } from 'lodash-es'
|
|
1
|
+
import { isEmpty, find } from 'lodash-es'
|
|
2
2
|
|
|
3
|
-
function breakNsPath (item = '') {
|
|
4
|
-
const { error
|
|
3
|
+
function breakNsPath (item = '', defaultNs = 'bajo') {
|
|
4
|
+
const { error } = this.bajo.helper
|
|
5
5
|
let [ns, ...path] = item.split(':')
|
|
6
6
|
path = path.join(':')
|
|
7
7
|
if (isEmpty(path)) {
|
|
8
8
|
path = ns
|
|
9
|
-
ns =
|
|
9
|
+
ns = defaultNs
|
|
10
|
+
}
|
|
11
|
+
if (ns.length === 1) return [ns, path].join(':') // windows fs
|
|
12
|
+
if (!this[ns]) {
|
|
13
|
+
const ref = find(this.bajo.pluginRefs ?? [], { alias: ns })
|
|
14
|
+
if (ref) ns = ref.plugin
|
|
10
15
|
}
|
|
11
|
-
// if (path.startsWith('.')) throw error('Path \'%s\' must be an absolute path', path)
|
|
12
|
-
if (!this[ns]) ns = (getPlugin(ns) || {}).name
|
|
13
16
|
if (!this[ns]) throw error('Unknown plugin \'%s\' or plugin isn\'t loaded yet', ns)
|
|
14
17
|
return [ns, path]
|
|
15
18
|
}
|
|
@@ -16,7 +16,7 @@ async function buildCollections (options = {}) {
|
|
|
16
16
|
const item = data[index]
|
|
17
17
|
if (useDefaultName) {
|
|
18
18
|
if (!has(item, 'name')) {
|
|
19
|
-
if (find(data, { name: 'default' })) throw error('
|
|
19
|
+
if (find(data, { name: 'default' })) throw error('Collection \'default\' already exists')
|
|
20
20
|
else item.name = 'default'
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { get } from 'lodash-es'
|
|
2
|
+
import breakNsPath from './break-ns-path.js'
|
|
2
3
|
|
|
3
4
|
function getPluginFile (file) {
|
|
5
|
+
if (!get(this, 'bajo.helper')) return file
|
|
4
6
|
if (file.includes(':')) {
|
|
5
|
-
const [plugin, path] =
|
|
7
|
+
const [plugin, path] = breakNsPath.call(this, file)
|
|
6
8
|
if (plugin !== 'file' && this && this[plugin] && plugin.length > 1) {
|
|
7
9
|
const dir = get(this[plugin], 'config.dir.pkg')
|
|
8
10
|
file = `${dir}${path}`
|
|
@@ -4,6 +4,7 @@ import getModuleDir from './get-module-dir.js'
|
|
|
4
4
|
import resolvePath from './resolve-path.js'
|
|
5
5
|
import readJson from './read-json.js'
|
|
6
6
|
import defaultsDeep from './defaults-deep.js'
|
|
7
|
+
import breakNsPath from './break-ns-path.js'
|
|
7
8
|
import path from 'path'
|
|
8
9
|
import fs from 'fs-extra'
|
|
9
10
|
|
|
@@ -14,11 +15,7 @@ async function importPkg (...pkgs) {
|
|
|
14
15
|
opts = defaultsDeep(pkgs.pop(), opts)
|
|
15
16
|
}
|
|
16
17
|
for (const pkg of pkgs) {
|
|
17
|
-
|
|
18
|
-
if (!name) {
|
|
19
|
-
name = plugin
|
|
20
|
-
plugin = 'bajo'
|
|
21
|
-
}
|
|
18
|
+
const [plugin, name] = breakNsPath.call(this, pkg)
|
|
22
19
|
const dir = getModuleDir.call(this, name, plugin)
|
|
23
20
|
const p = readJson(`${dir}/package.json`, opts.thrownNotFound)
|
|
24
21
|
const mainFileOrg = dir + '/' + (p.main ?? get(p, 'exports.default', 'index.js'))
|
package/boot/helper/run-hook.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { filter, isEmpty, orderBy } from 'lodash-es'
|
|
1
|
+
import { filter, isEmpty, orderBy, pullAt } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @module helper/runHook
|
|
@@ -26,6 +26,7 @@ async function runHook (hookName, ...args) {
|
|
|
26
26
|
if (isEmpty(fns)) return
|
|
27
27
|
fns = orderBy(fns, ['level'])
|
|
28
28
|
const results = []
|
|
29
|
+
const removed = []
|
|
29
30
|
for (const i in fns) {
|
|
30
31
|
const fn = fns[i]
|
|
31
32
|
/*
|
|
@@ -36,10 +37,12 @@ async function runHook (hookName, ...args) {
|
|
|
36
37
|
const res = await fn.handler.call(this, ...args)
|
|
37
38
|
results.push({
|
|
38
39
|
hook: hookName,
|
|
39
|
-
tag: fn.tag,
|
|
40
40
|
resp: res
|
|
41
41
|
})
|
|
42
|
+
if (path.startsWith('once')) removed.push(i)
|
|
42
43
|
}
|
|
44
|
+
if (removed.length > 0) pullAt(this.bajo.hooks, removed)
|
|
45
|
+
|
|
43
46
|
return results
|
|
44
47
|
}
|
|
45
48
|
|
package/boot/lib/shim.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// taken from: https://vanillajstoolkit.com/polyfills/stringreplaceall/
|
|
2
|
-
|
|
3
1
|
function shim () {
|
|
2
|
+
// taken from: https://vanillajstoolkit.com/polyfills/stringreplaceall/
|
|
4
3
|
if (!String.prototype.replaceAll) {
|
|
5
|
-
String.prototype.replaceAll = function(str, newStr){
|
|
4
|
+
String.prototype.replaceAll = function(str, newStr) { // eslint-disable-line
|
|
6
5
|
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
|
|
7
6
|
return this.replace(str, newStr)
|
|
8
7
|
}
|