bajo 1.0.2 → 1.0.4
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/class/app.js +3 -1
- package/boot/class/bajo-core/helper/attach-method.js +2 -1
- package/boot/class/bajo-core/helper/boot-order.js +3 -1
- package/boot/class/bajo-core/helper/build-config.js +2 -1
- package/boot/class/bajo-core/helper/build-plugins.js +3 -1
- package/boot/class/bajo-core/helper/collect-config-handlers.js +2 -1
- package/boot/class/bajo-core/method/arrange-array.js +2 -1
- package/boot/class/bajo-core/method/break-ns-path-from-file.js +2 -1
- package/boot/class/bajo-core/method/break-ns-path.js +3 -1
- package/boot/class/bajo-core/method/build-collections.js +3 -1
- package/boot/class/bajo-core/method/call-handler.js +3 -1
- package/boot/class/bajo-core/method/defaults-deep.js +4 -1
- package/boot/class/bajo-core/method/each-plugins.js +3 -1
- package/boot/class/bajo-core/method/get-global-module-dir.js +5 -3
- package/boot/class/bajo-core/method/get-method.js +3 -1
- package/boot/class/bajo-core/method/get-plugin-file.js +3 -1
- package/boot/class/bajo-core/method/import-module.js +3 -1
- package/boot/class/bajo-core/method/import-pkg.js +3 -1
- package/boot/class/bajo-core/method/includes.js +1 -3
- package/boot/class/bajo-core/method/is-log-in-range.js +3 -1
- package/boot/class/bajo-core/method/join.js +3 -1
- package/boot/class/bajo-core/method/num-unit.js +3 -1
- package/boot/class/bajo-core/method/paginate.js +3 -1
- package/boot/class/bajo-core/method/parse-object.js +2 -1
- package/boot/class/bajo-core/method/pascal-case.js +3 -1
- package/boot/class/bajo-core/method/read-config.js +3 -1
- package/boot/class/bajo-core/method/read-json.js +3 -1
- package/boot/class/bajo-core/method/run-hook.js +3 -1
- package/boot/class/bajo-core/method/save-as-download.js +3 -1
- package/boot/class/bajo-core/method/sec-to-hms.js +2 -1
- package/boot/class/bajo-core/method/titleize.js +2 -1
- package/boot/class/bajo-core.js +2 -1
- package/boot/class/bajo-plugin/helper/build-config.js +3 -1
- package/boot/class/bajo-plugin/helper/check-clash.js +3 -1
- package/boot/class/bajo-plugin/helper/check-dependency.js +3 -1
- package/boot/class/bajo-plugin/helper/collect-hooks.js +3 -1
- package/boot/class/bajo-plugin/helper/run.js +2 -1
- package/boot/class/bajo-plugin.js +7 -4
- package/boot/class/error.js +2 -1
- package/boot/class/log.js +3 -1
- package/boot/class/plugin.js +3 -1
- package/boot/class/print.js +3 -1
- package/boot/lib/create-method.js +3 -1
- package/boot/lib/parse-args-argv.js +3 -1
- package/boot/lib/parse-env.js +3 -1
- package/boot/lib/translate.js +2 -1
- package/package.json +3 -2
- package/boot/lib/get-global-module-path.js +0 -189
package/boot/class/app.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import util from 'util'
|
|
2
|
-
import
|
|
2
|
+
import lodash from 'lodash'
|
|
3
3
|
import BajoCore from './bajo-core.js'
|
|
4
4
|
import resolvePath from './bajo-core/method/resolve-path.js'
|
|
5
5
|
import parseArgsArgv from '../lib/parse-args-argv.js'
|
|
@@ -13,6 +13,8 @@ import bootPlugins from './bajo-core/helper/boot-plugins.js'
|
|
|
13
13
|
import exitHandler from './bajo-core/helper/exit-handler.js'
|
|
14
14
|
import runAsApplet from './bajo-core/helper/run-as-applet.js'
|
|
15
15
|
|
|
16
|
+
const { last } = lodash
|
|
17
|
+
|
|
16
18
|
class App {
|
|
17
19
|
constructor (cwd) {
|
|
18
20
|
if (!cwd) cwd = process.cwd()
|
|
@@ -5,6 +5,7 @@ import fs from 'fs-extra'
|
|
|
5
5
|
import fastGlob from 'fast-glob'
|
|
6
6
|
import { sprintf } from 'sprintf-js'
|
|
7
7
|
import outmatch from 'outmatch'
|
|
8
|
+
import lodash from 'lodash'
|
|
8
9
|
|
|
9
10
|
export default async function () {
|
|
10
11
|
await createMethod.call(this, `${currentLoc(import.meta).dir}/../method`)
|
|
@@ -18,7 +19,7 @@ export default async function () {
|
|
|
18
19
|
})
|
|
19
20
|
}
|
|
20
21
|
// commonly used libraries
|
|
21
|
-
this.lib._ =
|
|
22
|
+
this.lib._ = lodash
|
|
22
23
|
this.lib.fs = fs
|
|
23
24
|
this.lib.fastGlob = fastGlob
|
|
24
25
|
this.lib.sprintf = sprintf
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import getModuleDir from '../method/get-module-dir.js'
|
|
4
4
|
|
|
5
|
+
const { reduce, map, isNaN, trim, forOwn, orderBy } = lodash
|
|
6
|
+
|
|
5
7
|
async function bootOrder () {
|
|
6
8
|
this.log.debug('Setup boot order')
|
|
7
9
|
const order = reduce(this.pluginPkgs, (o, k, i) => {
|
|
@@ -9,7 +9,8 @@ import omitDeep from 'omit-deep'
|
|
|
9
9
|
import os from 'os'
|
|
10
10
|
import fs from 'fs-extra'
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import lodash from 'lodash'
|
|
13
|
+
const { map, pick, values, keys, set, get } = lodash
|
|
13
14
|
|
|
14
15
|
const omitted = ['spawn', 'cwd', 'name', 'alias', 'applet', 'a', 'plugins']
|
|
15
16
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import fs from 'fs-extra'
|
|
3
3
|
import getModuleDir from '../method/get-module-dir.js'
|
|
4
4
|
import BajoPlugin from '../../bajo-plugin.js'
|
|
5
5
|
|
|
6
|
+
const { isString, filter, map, trim, without, uniq, camelCase, isEmpty } = lodash
|
|
7
|
+
|
|
6
8
|
async function buildPlugins () {
|
|
7
9
|
let pluginPkgs = this.config.plugins ?? []
|
|
8
10
|
if (isString(pluginPkgs)) pluginPkgs = [pluginPkgs]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import getModuleDir from '../method/get-module-dir.js'
|
|
2
2
|
import importModule from '../method/import-module.js'
|
|
3
|
-
import
|
|
3
|
+
import lodash from 'lodash'
|
|
4
|
+
const { isFunction, isPlainObject, camelCase } = lodash
|
|
4
5
|
|
|
5
6
|
async function collectConfigHandlers () {
|
|
6
7
|
for (const pkg of this.pluginPkgs) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
|
+
|
|
3
|
+
const { filter, isArray, pullAt, camelCase, has, find, set, get, isFunction } = lodash
|
|
2
4
|
|
|
3
5
|
async function buildCollections (options = {}) {
|
|
4
6
|
const { runHook, join } = this.app.bajo
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import BajoPlugin from '../../bajo-plugin.js'
|
|
3
3
|
|
|
4
|
+
const { isString, isFunction, isPlainObject, find } = lodash
|
|
5
|
+
|
|
4
6
|
async function callHandler (item, ...args) {
|
|
5
7
|
let result
|
|
6
8
|
let scope = this
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import fastGlob from 'fast-glob'
|
|
3
3
|
import path from 'path'
|
|
4
4
|
|
|
5
|
+
const { camelCase, isString, omit, cloneDeep } = lodash
|
|
6
|
+
|
|
5
7
|
async function eachPlugins (handler, options = {}) {
|
|
6
8
|
if (typeof options === 'string') options = { glob: options }
|
|
7
9
|
const result = {}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import getGlobalPath from 'get-global-path'
|
|
2
2
|
import resolvePath from './resolve-path.js'
|
|
3
|
-
import
|
|
3
|
+
import lodash from 'lodash'
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
|
|
6
|
+
const { dropRight } = lodash
|
|
7
|
+
|
|
6
8
|
function getGlobalModuleDir (pkgName, silent = true) {
|
|
7
9
|
let nodeModulesDir = process.env.BAJO_GLOBAL_MODULE_DIR
|
|
8
10
|
if (!nodeModulesDir) {
|
|
9
|
-
const npmPath =
|
|
11
|
+
const npmPath = getGlobalPath('npm')
|
|
10
12
|
if (!npmPath) {
|
|
11
13
|
if (silent) return
|
|
12
14
|
throw this.error('Can\'t locate npm global module directory', { code: 'BAJO_CANT_LOCATE_NPM_GLOBAL_DIR' })
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import breakNsPath from './break-ns-path.js'
|
|
2
2
|
import currentLoc from '../../../lib/current-loc.js'
|
|
3
|
-
import
|
|
3
|
+
import lodash from 'lodash'
|
|
4
|
+
|
|
5
|
+
const { trim } = lodash
|
|
4
6
|
|
|
5
7
|
function getPluginFile (file) {
|
|
6
8
|
if (file[0] === '.') file = `${currentLoc(import.meta).dir}/${trim(file.slice(1), '/')}`
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import resolvePath from './resolve-path.js'
|
|
2
2
|
import getPluginFile from './get-plugin-file.js'
|
|
3
|
-
import
|
|
3
|
+
import lodash from 'lodash'
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
|
|
6
|
+
const { isFunction, isPlainObject } = lodash
|
|
7
|
+
|
|
6
8
|
async function load (file, asDefaultImport = true, noCache = false) {
|
|
7
9
|
file = resolvePath(file, true)
|
|
8
10
|
if (noCache) file += `?_=${Date.now()}`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import os from 'os'
|
|
3
3
|
import getModuleDir from './get-module-dir.js'
|
|
4
4
|
import resolvePath from './resolve-path.js'
|
|
@@ -8,6 +8,8 @@ import breakNsPath from './break-ns-path.js'
|
|
|
8
8
|
import path from 'path'
|
|
9
9
|
import fs from 'fs-extra'
|
|
10
10
|
|
|
11
|
+
const { isPlainObject, last, isEmpty, has, keys, values, get } = lodash
|
|
12
|
+
|
|
11
13
|
async function importPkg (...pkgs) {
|
|
12
14
|
const result = {}
|
|
13
15
|
const notFound = []
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import isSet from './is-set.js'
|
|
3
3
|
|
|
4
|
+
const { isPlainObject } = lodash
|
|
5
|
+
|
|
4
6
|
function join (array, sep) {
|
|
5
7
|
const isI18n = this && this.app && this.app.bajoI18N
|
|
6
8
|
if (array.length === 0) return isI18n ? this.app.bajoI18N.t('none') : 'none'
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
|
+
|
|
3
|
+
const { isEmpty, isPlainObject, orderBy, forOwn } = lodash
|
|
2
4
|
|
|
3
5
|
function paginate (collection, { page = 1, limit = 25, sort } = {}) {
|
|
4
6
|
const count = collection.length
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import dotenvParseVariables from 'dotenv-parse-variables'
|
|
3
3
|
import ms from 'ms'
|
|
4
4
|
import dayjs from '../../../lib/dayjs.js'
|
|
5
5
|
import isSet from './is-set.js'
|
|
6
6
|
import translate from '../../../lib/translate.js'
|
|
7
7
|
|
|
8
|
+
const { isPlainObject, isArray, isNumber, set, cloneDeep, isString, omit } = lodash
|
|
8
9
|
const statics = ['*']
|
|
9
10
|
|
|
10
11
|
function parseDur (val) {
|
|
@@ -3,9 +3,11 @@ import resolvePath from './resolve-path.js'
|
|
|
3
3
|
import getPluginFile from './get-plugin-file.js'
|
|
4
4
|
import readJson from './read-json.js'
|
|
5
5
|
import parseObject from './parse-object.js'
|
|
6
|
-
import
|
|
6
|
+
import lodash from 'lodash'
|
|
7
7
|
import fg from 'fast-glob'
|
|
8
8
|
|
|
9
|
+
const { find, map, isEmpty } = lodash
|
|
10
|
+
|
|
9
11
|
async function readConfig (file, { ns, pattern, globOptions = {}, ignoreError, defValue = {}, opts = {} } = {}) {
|
|
10
12
|
if (!ns) ns = this.name
|
|
11
13
|
file = resolvePath(getPluginFile.call(this, file))
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fs from 'fs-extra'
|
|
2
|
-
import
|
|
2
|
+
import lodash from 'lodash'
|
|
3
3
|
import parseObject from './parse-object.js'
|
|
4
4
|
|
|
5
|
+
const { isEmpty } = lodash
|
|
6
|
+
|
|
5
7
|
function readJson (file, thrownNotFound) {
|
|
6
8
|
if (!fs.existsSync(file) && thrownNotFound) throw this.error('File \'%s\' not found', file)
|
|
7
9
|
let resp = fs.readFileSync(file, 'utf8')
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import fs from 'fs-extra'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import
|
|
3
|
+
import lodash from 'lodash'
|
|
4
4
|
import increment from 'add-filename-increment'
|
|
5
5
|
|
|
6
|
+
const { trim } = lodash
|
|
7
|
+
|
|
6
8
|
async function saveAsDownload (file, obj, printSaved = true) {
|
|
7
9
|
const { print, getPluginDataDir } = this.app.bajo
|
|
8
10
|
const plugin = this.name
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import generateId from './generate-id.js'
|
|
3
3
|
|
|
4
|
+
const { words, upperFirst, map, concat, uniq, forOwn } = lodash
|
|
4
5
|
const defIgnores = ['or', 'and', 'of', 'with']
|
|
5
6
|
|
|
6
7
|
const titleize = (text, { ignores = [], replacement = {} } = {}) => {
|
package/boot/class/bajo-core.js
CHANGED
|
@@ -3,7 +3,8 @@ import dayjs from '../lib/dayjs.js'
|
|
|
3
3
|
import importModule from './bajo-core/method/import-module.js'
|
|
4
4
|
import readJson from './bajo-core/method/read-json.js'
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import lodash from 'lodash'
|
|
7
|
+
const { isFunction } = lodash
|
|
7
8
|
|
|
8
9
|
async function defConfigHandler (file, opts) {
|
|
9
10
|
let mod = await importModule(file)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import semver from 'semver'
|
|
3
3
|
|
|
4
|
+
const { reduce, map, trim, keys, intersection, each, camelCase, get } = lodash
|
|
5
|
+
|
|
4
6
|
async function runner ({ ns, pkgName }) {
|
|
5
7
|
const { join } = this.app.bajo
|
|
6
8
|
this.app.bajo.log.trace('- %s', ns)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Plugin from './plugin.js'
|
|
2
|
-
import
|
|
2
|
+
import lodash from 'lodash'
|
|
3
3
|
import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
|
|
4
4
|
import readAllConfigs from '../lib/read-all-configs.js'
|
|
5
5
|
import titleize from './bajo-core/method/titleize.js'
|
|
6
6
|
import fs from 'fs-extra'
|
|
7
7
|
|
|
8
|
+
const { pick, omit, camelCase, trim, without } = lodash
|
|
9
|
+
|
|
8
10
|
class BajoPlugin extends Plugin {
|
|
9
11
|
constructor (pkgName, app) {
|
|
10
12
|
super(pkgName, app)
|
|
@@ -41,15 +43,16 @@ class BajoPlugin extends Plugin {
|
|
|
41
43
|
const envArgv = defaultsDeep({}, omit(this.app.env[this.name] ?? {}, omittedPluginKeys) ?? {}, omit(this.app.argv[this.name] ?? {}, omittedPluginKeys) ?? {})
|
|
42
44
|
cfg = defaultsDeep({}, envArgv ?? {}, cfg ?? {})
|
|
43
45
|
this.title = this.title ?? cfg.title ?? titleize(this.alias)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
this.dependencies = []
|
|
48
|
+
const depFile = `${dir}/bajo/.dependencies`
|
|
49
|
+
if (fs.existsSync(depFile)) this.dependencies = without(fs.readFileSync(depFile, 'utf8').split('\n').map(item => trim(item)), '')
|
|
46
50
|
this.config = omit(cfg, ['title', 'dependencies'])
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
async _onoff (item, text, ...args) {
|
|
50
54
|
this.state[item] = false
|
|
51
55
|
const { runHook, importModule } = this.app.bajo
|
|
52
|
-
const { camelCase } = this.app.bajo.lib._
|
|
53
56
|
const mod = await importModule(`${this.dir.pkg}/bajo/${item}.js`)
|
|
54
57
|
if (mod) {
|
|
55
58
|
this.log.trace(text)
|
package/boot/class/error.js
CHANGED
package/boot/class/log.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import os from 'os'
|
|
2
|
-
import
|
|
2
|
+
import lodash from 'lodash'
|
|
3
3
|
import levels from './bajo-core/method/log-levels.js'
|
|
4
4
|
import isLogInRange from './bajo-core/method/is-log-in-range.js'
|
|
5
5
|
import translate from '../lib/translate.js'
|
|
6
6
|
import dayjs from 'dayjs'
|
|
7
7
|
|
|
8
|
+
const { isEmpty, without, merge, upperFirst } = lodash
|
|
9
|
+
|
|
8
10
|
class Log {
|
|
9
11
|
constructor (plugin) {
|
|
10
12
|
this.plugin = plugin
|
package/boot/class/plugin.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodash from 'lodash'
|
|
2
2
|
import omittedPluginKeys from '../lib/omitted-plugin-keys.js'
|
|
3
3
|
import Log from './log.js'
|
|
4
4
|
import Print from './print.js'
|
|
5
5
|
import BajoError from './error.js'
|
|
6
6
|
|
|
7
|
+
const { get, isEmpty, cloneDeep, omit, isPlainObject, camelCase } = lodash
|
|
8
|
+
|
|
7
9
|
class Plugin {
|
|
8
10
|
constructor (pkgName, app) {
|
|
9
11
|
this.pkgName = pkgName
|
package/boot/class/print.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import ora from 'ora'
|
|
2
|
-
import
|
|
2
|
+
import lodash from 'lodash'
|
|
3
3
|
import defaultsDeep from './bajo-core/method/defaults-deep.js'
|
|
4
4
|
import translate from '../lib/translate.js'
|
|
5
5
|
|
|
6
|
+
const { isPlainObject } = lodash
|
|
7
|
+
|
|
6
8
|
class Print {
|
|
7
9
|
constructor (plugin, opts = {}) {
|
|
8
10
|
this.opts = opts
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import fastGlob from 'fast-glob'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import
|
|
3
|
+
import lodash from 'lodash'
|
|
4
4
|
import resolvePath from '../class/bajo-core/method/resolve-path.js'
|
|
5
5
|
import importModule from '../class/bajo-core/method/import-module.js'
|
|
6
6
|
import readJson from '../class/bajo-core/method/read-json.js'
|
|
7
7
|
|
|
8
|
+
const { camelCase, isFunction, isPlainObject, forOwn } = lodash
|
|
9
|
+
|
|
8
10
|
export default async function (dir, pkg = 'bajo') {
|
|
9
11
|
dir = resolvePath(dir)
|
|
10
12
|
const files = await fastGlob([`!${dir}/**/_*.{js,json}`, `${dir}/**/*.{js,json}`])
|
|
@@ -4,11 +4,13 @@ import { unflatten } from 'flat'
|
|
|
4
4
|
import isSet from '../class/bajo-core/method/is-set.js'
|
|
5
5
|
import dotenvParseVariables from 'dotenv-parse-variables'
|
|
6
6
|
import importModule from '../class/bajo-core/method/import-module.js'
|
|
7
|
-
import
|
|
7
|
+
import lodash from 'lodash'
|
|
8
8
|
import fs from 'fs-extra'
|
|
9
9
|
import path from 'path'
|
|
10
10
|
import currentLoc from './current-loc.js'
|
|
11
11
|
|
|
12
|
+
const { find, each, set, camelCase, forOwn } = lodash
|
|
13
|
+
|
|
12
14
|
const parseItem = (data, delimiter) => {
|
|
13
15
|
return unflatten(data, {
|
|
14
16
|
delimiter,
|
package/boot/lib/parse-env.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import dotenvParseVariables from 'dotenv-parse-variables'
|
|
2
2
|
import { unflatten } from 'flat'
|
|
3
3
|
import dotEnv from 'dotenv'
|
|
4
|
-
import
|
|
4
|
+
import lodash from 'lodash'
|
|
5
|
+
|
|
6
|
+
const { each, set, camelCase, forOwn } = lodash
|
|
5
7
|
|
|
6
8
|
const parse = (data, delimiter) => {
|
|
7
9
|
return unflatten(data, {
|
package/boot/lib/translate.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bajo",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A framework to build a giant monstrous app rapidly",
|
|
5
5
|
"main": "boot/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"fast-glob": "^3.3.3",
|
|
36
36
|
"flat": "^6.0.1",
|
|
37
37
|
"fs-extra": "^11.2.0",
|
|
38
|
-
"
|
|
38
|
+
"get-global-path": "^0.0.1",
|
|
39
|
+
"lodash": "^4.17.21",
|
|
39
40
|
"ms": "^2.1.3",
|
|
40
41
|
"nanoid": "^5.0.9",
|
|
41
42
|
"omit-deep": "^0.3.0",
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
// based on global-modules-path, patching it to work on Node LTS
|
|
2
|
-
import { spawnSync } from 'child_process'
|
|
3
|
-
|
|
4
|
-
import path from 'path'
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
|
|
7
|
-
const supportedPlatforms = [
|
|
8
|
-
'win32',
|
|
9
|
-
'linux',
|
|
10
|
-
'darwin'
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
const nodeModulesDirName = 'node_modules'
|
|
14
|
-
|
|
15
|
-
const getNpmExecutable = (platform) => {
|
|
16
|
-
let npmExecutableName = 'npm'
|
|
17
|
-
if (platform === 'win32') npmExecutableName += '.cmd'
|
|
18
|
-
return npmExecutableName
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const spawnSyncWrapper = (command, commandArgs) => {
|
|
22
|
-
const result = spawnSync(command, commandArgs, { shell: true })
|
|
23
|
-
if (!result) return null
|
|
24
|
-
if (result.error) throw result.error
|
|
25
|
-
if (result.stdout) return result.stdout.toString().trim()
|
|
26
|
-
return null
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const getNpmPrefix = (pathToNpm) => {
|
|
30
|
-
try {
|
|
31
|
-
const npmPrefixStdout = spawnSyncWrapper(pathToNpm, ['config', 'get', 'prefix'])
|
|
32
|
-
return npmPrefixStdout && npmPrefixStdout.toString().trim()
|
|
33
|
-
} catch (err) {
|
|
34
|
-
console.error(err.message)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const getPathFromNpmConfig = (platform, packageName) => {
|
|
41
|
-
const pathToNpm = getNpmExecutable(platform)
|
|
42
|
-
const npmConfigPrefix = getNpmPrefix(pathToNpm)
|
|
43
|
-
|
|
44
|
-
if (npmConfigPrefix) {
|
|
45
|
-
let nodeModulesPath = path.join(npmConfigPrefix, nodeModulesDirName)
|
|
46
|
-
|
|
47
|
-
if (platform !== 'win32') {
|
|
48
|
-
nodeModulesPath = path.join(npmConfigPrefix, 'lib', nodeModulesDirName)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const packagePath = path.join(nodeModulesPath, packageName)
|
|
52
|
-
const verifiedPath = getVerifiedPath(packagePath, packageName)
|
|
53
|
-
|
|
54
|
-
if (verifiedPath) {
|
|
55
|
-
return verifiedPath
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return null
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const getPathFromCmdContent = (packageName, pathToExecutable) => {
|
|
63
|
-
if (fs.existsSync(pathToExecutable)) {
|
|
64
|
-
const executableContent = fs.readFileSync(pathToExecutable).toString()
|
|
65
|
-
|
|
66
|
-
let fullPath
|
|
67
|
-
|
|
68
|
-
let windowsPathRegExp = /(%~dp0[\w\\.-]+node_modules).*?'/g
|
|
69
|
-
let match = windowsPathRegExp.exec(executableContent)
|
|
70
|
-
|
|
71
|
-
if (match && match[1]) {
|
|
72
|
-
const realPath = path.normalize(match[1].replace('%~dp0', path.dirname(pathToExecutable)))
|
|
73
|
-
fullPath = path.join(realPath, packageName)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!fullPath) {
|
|
77
|
-
windowsPathRegExp = new RegExp(`(%~dp0[\\w\\\\.-]+?${packageName})(?:\\\\|')`, 'g')
|
|
78
|
-
match = windowsPathRegExp.exec(executableContent)
|
|
79
|
-
if (match && match[1]) fullPath = path.normalize(match[1].replace('%~dp0', path.dirname(pathToExecutable)))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (fullPath) {
|
|
83
|
-
const pathToPackage = getVerifiedPath(fullPath, packageName)
|
|
84
|
-
if (pathToPackage) return pathToPackage
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const getVerifiedPath = (suggestedPath, packageName) => {
|
|
90
|
-
const pathToPackageJson = path.join(suggestedPath, 'package.json')
|
|
91
|
-
if (fs.existsSync(suggestedPath) && fs.existsSync(pathToPackageJson)) {
|
|
92
|
-
try {
|
|
93
|
-
const packageJsonContent = JSON.parse(fs.readFileSync(pathToPackageJson))
|
|
94
|
-
if (packageJsonContent.name === packageName) return suggestedPath
|
|
95
|
-
} catch (err) {
|
|
96
|
-
// do nothing
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const getPathFromExecutableNameOnWindows = (packageName, executableName) => {
|
|
102
|
-
try {
|
|
103
|
-
const whereResult = (spawnSyncWrapper('where', [executableName]) || '').split('\n')
|
|
104
|
-
for (const line of whereResult) {
|
|
105
|
-
const pathToExecutable = line && line.trim()
|
|
106
|
-
|
|
107
|
-
if (pathToExecutable) {
|
|
108
|
-
const pathToLib = path.join(path.dirname(pathToExecutable), nodeModulesDirName, packageName)
|
|
109
|
-
const verifiedPath = getVerifiedPath(pathToLib, packageName)
|
|
110
|
-
if (verifiedPath) return verifiedPath
|
|
111
|
-
const pathToExecutableFromContent = getPathFromCmdContent(packageName, pathToExecutable)
|
|
112
|
-
if (pathToExecutableFromContent) return pathToExecutableFromContent
|
|
113
|
-
|
|
114
|
-
const resolvedPath = getPathWhenExecutableIsAddedDirectlyToPath(packageName, pathToExecutable)
|
|
115
|
-
if (resolvedPath) return resolvedPath
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} catch (err) {
|
|
119
|
-
console.error(err.message)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return null
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const getPathFromExecutableNameOnNonWindows = (packageName, executableName) => {
|
|
126
|
-
try {
|
|
127
|
-
const whichResult = spawnSyncWrapper('which', [executableName])
|
|
128
|
-
const lsLResult = spawnSyncWrapper('ls', ['-l', whichResult])
|
|
129
|
-
|
|
130
|
-
if (whichResult && lsLResult) {
|
|
131
|
-
const regex = new RegExp(`${whichResult}\\s+->\\s+(.*?)$`)
|
|
132
|
-
const match = lsLResult.match(regex)
|
|
133
|
-
|
|
134
|
-
if (match && match[1]) {
|
|
135
|
-
const pathToRealExecutable = fs.realpathSync(path.join(path.dirname(whichResult), match[1]))
|
|
136
|
-
const packagePathMatch = pathToRealExecutable.match(new RegExp(`(.*?${path.join(nodeModulesDirName, packageName)}).*$`))
|
|
137
|
-
if (packagePathMatch) {
|
|
138
|
-
const verifiedPath = getVerifiedPath(packagePathMatch[1], packageName)
|
|
139
|
-
if (verifiedPath) return verifiedPath
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return getPathWhenExecutableIsAddedDirectlyToPath(packageName, whichResult)
|
|
144
|
-
}
|
|
145
|
-
} catch (err) {
|
|
146
|
-
console.error(err.message)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return null
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const getPathWhenExecutableIsAddedDirectlyToPath = (packageName, executablePath) => {
|
|
153
|
-
const pathToPackageJson = path.join(path.dirname(executablePath), '..', 'package.json')
|
|
154
|
-
if (fs.existsSync(pathToPackageJson)) {
|
|
155
|
-
const packageNameFromPackageJson = JSON.parse(fs.readFileSync(pathToPackageJson)).name
|
|
156
|
-
if (packageNameFromPackageJson === packageName) return path.dirname(pathToPackageJson)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return null
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const getPath = (packageName, executableName) => {
|
|
163
|
-
const platform = process.platform
|
|
164
|
-
|
|
165
|
-
if (supportedPlatforms.indexOf(platform) === -1) {
|
|
166
|
-
throw new Error(`OS '${platform}' is not supported.'`)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let foundPath = null
|
|
170
|
-
|
|
171
|
-
if (executableName) {
|
|
172
|
-
foundPath = platform === 'win32' ?
|
|
173
|
-
getPathFromExecutableNameOnWindows(packageName, executableName) :
|
|
174
|
-
getPathFromExecutableNameOnNonWindows(packageName, executableName)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (!foundPath) foundPath = getPathFromNpmConfig(platform, packageName)
|
|
178
|
-
if (foundPath) {
|
|
179
|
-
try {
|
|
180
|
-
foundPath = fs.realpathSync(foundPath)
|
|
181
|
-
} catch (err) {
|
|
182
|
-
console.error(err.message)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return foundPath
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export default getPath
|