bajo 0.3.4 → 0.3.5
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.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { get } from 'lodash-es'
|
|
2
|
+
|
|
3
|
+
function getPluginFile (file) {
|
|
4
|
+
if (file.includes(':')) {
|
|
5
|
+
const [plugin, path] = file.split(':')
|
|
6
|
+
if (plugin !== 'file' && this && this[plugin] && plugin.length > 1) {
|
|
7
|
+
const dir = get(this[plugin], 'config.dir.pkg')
|
|
8
|
+
file = `${dir}${path}`
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return file
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default getPluginFile
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import resolvePath from './resolve-path.js'
|
|
2
|
-
import
|
|
2
|
+
import getPluginFile from './get-plugin-file.js'
|
|
3
|
+
import { isFunction, isPlainObject } from 'lodash-es'
|
|
3
4
|
import error from './error.js'
|
|
4
5
|
import fs from 'fs-extra'
|
|
5
6
|
|
|
@@ -12,13 +13,7 @@ async function load (file, asDefaultImport = true, noCache = true) {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
async function importModule (file, { asDefaultImport, asHandler, noCache } = {}) {
|
|
15
|
-
|
|
16
|
-
const [plugin, path] = file.split(':')
|
|
17
|
-
if (plugin.length > 1) {
|
|
18
|
-
const dir = get(this[plugin], 'config.dir.pkg')
|
|
19
|
-
file = `${dir}${path}`
|
|
20
|
-
}
|
|
21
|
-
}
|
|
16
|
+
file = getPluginFile.call(this, file)
|
|
22
17
|
if (!fs.existsSync(file)) return
|
|
23
18
|
let mod = await load(file, asDefaultImport, noCache)
|
|
24
19
|
if (!asHandler) return mod
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPlainObject,
|
|
1
|
+
import { isPlainObject, last, isEmpty, has, keys, values, get } from 'lodash-es'
|
|
2
2
|
import os from 'os'
|
|
3
3
|
import getModuleDir from './get-module-dir.js'
|
|
4
4
|
import resolvePath from './resolve-path.js'
|
|
@@ -7,46 +7,21 @@ import defaultsDeep from './defaults-deep.js'
|
|
|
7
7
|
import path from 'path'
|
|
8
8
|
import fs from 'fs-extra'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
* Load/import a package dynamically. You can import package one-by-one or multiple
|
|
12
|
-
* packages at once.
|
|
13
|
-
*
|
|
14
|
-
* Package 'pkg' must be in the following format: ```<original name>:<new name>:<bajo package name>```
|
|
15
|
-
* ```<new name>``` can be omitted, so the format will be: ```<name>::<bajo package name>```
|
|
16
|
-
*
|
|
17
|
-
* If you only import one package, returned value is the imported package itself
|
|
18
|
-
* If multiple packages are imported, returned value is an object with ```<new name>``` as its
|
|
19
|
-
* keys and imported packages as its values
|
|
20
|
-
*
|
|
21
|
-
* Example:
|
|
22
|
-
* ```
|
|
23
|
-
* const imported = await importPkg('ora::bajo-cli')
|
|
24
|
-
* const multiple = await importPkg('ora::bajo-cli', 'lodash:_:bajo')
|
|
25
|
-
*
|
|
26
|
-
* @param {...string} pkg
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
async function importPkg (...pkg) {
|
|
10
|
+
async function importPkg (...pkgs) {
|
|
31
11
|
const result = {}
|
|
32
12
|
let opts = { returnDefault: true, thrownNotFound: false, noCache: false }
|
|
33
|
-
if (isPlainObject(last(
|
|
34
|
-
opts = defaultsDeep(
|
|
13
|
+
if (isPlainObject(last(pkgs))) {
|
|
14
|
+
opts = defaultsDeep(pkgs.pop(), opts)
|
|
35
15
|
}
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
ns = 'bajo'
|
|
42
|
-
name = orgName
|
|
43
|
-
} else if (parts.length === 2) {
|
|
44
|
-
name = orgName
|
|
16
|
+
for (const pkg of pkgs) {
|
|
17
|
+
let [plugin, name] = pkg.split(':').map(item => item.trim())
|
|
18
|
+
if (!name) {
|
|
19
|
+
name = plugin
|
|
20
|
+
plugin = 'bajo'
|
|
45
21
|
}
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const mainFileOrg = dir + '/' + (pkg.main ?? get(pkg, 'exports.default', 'index.js'))
|
|
22
|
+
const dir = getModuleDir.call(this, name, plugin)
|
|
23
|
+
const p = readJson(`${dir}/package.json`, opts.thrownNotFound)
|
|
24
|
+
const mainFileOrg = dir + '/' + (p.main ?? get(p, 'exports.default', 'index.js'))
|
|
50
25
|
let mainFile = resolvePath(mainFileOrg, os.platform() === 'win32')
|
|
51
26
|
if (isEmpty(path.extname(mainFile))) {
|
|
52
27
|
if (fs.existsSync(`${mainFileOrg}/index.js`)) mainFile += '/index.js'
|
|
@@ -60,7 +35,7 @@ async function importPkg (...pkg) {
|
|
|
60
35
|
}
|
|
61
36
|
result[name] = mod
|
|
62
37
|
}
|
|
63
|
-
if (
|
|
38
|
+
if (pkgs.length === 1) return result[keys(result)[0]]
|
|
64
39
|
if (opts.asObject) return result
|
|
65
40
|
return values(result)
|
|
66
41
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import resolvePath from './resolve-path.js'
|
|
3
|
+
import getPluginFile from './get-plugin-file.js'
|
|
3
4
|
import readJson from './read-json.js'
|
|
4
5
|
import parseObject from './parse-object.js'
|
|
5
6
|
import { find, map, isEmpty } from 'lodash-es'
|
|
@@ -7,7 +8,7 @@ import error from './error.js'
|
|
|
7
8
|
import fg from 'fast-glob'
|
|
8
9
|
|
|
9
10
|
async function readConfig (file, { pattern, globOptions = {}, ignoreError, defValue = {} } = {}) {
|
|
10
|
-
file = resolvePath(file)
|
|
11
|
+
file = resolvePath(getPluginFile.call(this, file))
|
|
11
12
|
let ext = path.extname(file)
|
|
12
13
|
const fname = path.dirname(file) + '/' + path.basename(file, ext)
|
|
13
14
|
ext = ext.toLowerCase()
|