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.
@@ -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, getPlugin } = this.bajo.helper
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 = null
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('Connection \'default\' already exists')
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] = file.split(':')
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}`
@@ -6,7 +6,7 @@ function getPlugin (name) {
6
6
  // alias?
7
7
  const ref = find(this.bajo.pluginRefs ?? [], { alias: name })
8
8
  if (!ref) throw error('\'%s\' is not loaded', name)
9
- name = ref.name
9
+ name = ref.plugin
10
10
  }
11
11
  return this[name]
12
12
  }
@@ -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
- let [plugin, name] = pkg.split(':').map(item => item.trim())
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'))
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bajo",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "A framework to build a giant monstrous app rapidly",
5
5
  "main": "boot/index.js",
6
6
  "scripts": {