aboutsummaryrefslogtreecommitdiff
path: root/node_modules/yargs/build/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/yargs/build/lib/utils')
-rw-r--r--node_modules/yargs/build/lib/utils/apply-extends.js59
-rw-r--r--node_modules/yargs/build/lib/utils/is-promise.js5
-rw-r--r--node_modules/yargs/build/lib/utils/levenshtein.js26
-rw-r--r--node_modules/yargs/build/lib/utils/obj-filter.js10
-rw-r--r--node_modules/yargs/build/lib/utils/process-argv.js17
-rw-r--r--node_modules/yargs/build/lib/utils/set-blocking.js12
-rw-r--r--node_modules/yargs/build/lib/utils/which-module.js10
7 files changed, 139 insertions, 0 deletions
diff --git a/node_modules/yargs/build/lib/utils/apply-extends.js b/node_modules/yargs/build/lib/utils/apply-extends.js
new file mode 100644
index 0000000..0e593b4
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/apply-extends.js
@@ -0,0 +1,59 @@
+import { YError } from '../yerror.js';
+let previouslyVisitedConfigs = [];
+let shim;
+export function applyExtends(config, cwd, mergeExtends, _shim) {
+ shim = _shim;
+ let defaultConfig = {};
+ if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
+ if (typeof config.extends !== 'string')
+ return defaultConfig;
+ const isPath = /\.json|\..*rc$/.test(config.extends);
+ let pathToDefault = null;
+ if (!isPath) {
+ try {
+ pathToDefault = require.resolve(config.extends);
+ }
+ catch (_err) {
+ return config;
+ }
+ }
+ else {
+ pathToDefault = getPathToDefaultConfig(cwd, config.extends);
+ }
+ checkForCircularExtends(pathToDefault);
+ previouslyVisitedConfigs.push(pathToDefault);
+ defaultConfig = isPath
+ ? JSON.parse(shim.readFileSync(pathToDefault, 'utf8'))
+ : require(config.extends);
+ delete config.extends;
+ defaultConfig = applyExtends(defaultConfig, shim.path.dirname(pathToDefault), mergeExtends, shim);
+ }
+ previouslyVisitedConfigs = [];
+ return mergeExtends
+ ? mergeDeep(defaultConfig, config)
+ : Object.assign({}, defaultConfig, config);
+}
+function checkForCircularExtends(cfgPath) {
+ if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
+ throw new YError(`Circular extended configurations: '${cfgPath}'.`);
+ }
+}
+function getPathToDefaultConfig(cwd, pathToExtend) {
+ return shim.path.resolve(cwd, pathToExtend);
+}
+function mergeDeep(config1, config2) {
+ const target = {};
+ function isObject(obj) {
+ return obj && typeof obj === 'object' && !Array.isArray(obj);
+ }
+ Object.assign(target, config1);
+ for (const key of Object.keys(config2)) {
+ if (isObject(config2[key]) && isObject(target[key])) {
+ target[key] = mergeDeep(config1[key], config2[key]);
+ }
+ else {
+ target[key] = config2[key];
+ }
+ }
+ return target;
+}
diff --git a/node_modules/yargs/build/lib/utils/is-promise.js b/node_modules/yargs/build/lib/utils/is-promise.js
new file mode 100644
index 0000000..d250c08
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/is-promise.js
@@ -0,0 +1,5 @@
+export function isPromise(maybePromise) {
+ return (!!maybePromise &&
+ !!maybePromise.then &&
+ typeof maybePromise.then === 'function');
+}
diff --git a/node_modules/yargs/build/lib/utils/levenshtein.js b/node_modules/yargs/build/lib/utils/levenshtein.js
new file mode 100644
index 0000000..068168e
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/levenshtein.js
@@ -0,0 +1,26 @@
+export function levenshtein(a, b) {
+ if (a.length === 0)
+ return b.length;
+ if (b.length === 0)
+ return a.length;
+ const matrix = [];
+ let i;
+ for (i = 0; i <= b.length; i++) {
+ matrix[i] = [i];
+ }
+ let j;
+ for (j = 0; j <= a.length; j++) {
+ matrix[0][j] = j;
+ }
+ for (i = 1; i <= b.length; i++) {
+ for (j = 1; j <= a.length; j++) {
+ if (b.charAt(i - 1) === a.charAt(j - 1)) {
+ matrix[i][j] = matrix[i - 1][j - 1];
+ }
+ else {
+ matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1));
+ }
+ }
+ }
+ return matrix[b.length][a.length];
+}
diff --git a/node_modules/yargs/build/lib/utils/obj-filter.js b/node_modules/yargs/build/lib/utils/obj-filter.js
new file mode 100644
index 0000000..cd68ad2
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/obj-filter.js
@@ -0,0 +1,10 @@
+import { objectKeys } from '../typings/common-types.js';
+export function objFilter(original = {}, filter = () => true) {
+ const obj = {};
+ objectKeys(original).forEach(key => {
+ if (filter(key, original[key])) {
+ obj[key] = original[key];
+ }
+ });
+ return obj;
+}
diff --git a/node_modules/yargs/build/lib/utils/process-argv.js b/node_modules/yargs/build/lib/utils/process-argv.js
new file mode 100644
index 0000000..74dc9e4
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/process-argv.js
@@ -0,0 +1,17 @@
+function getProcessArgvBinIndex() {
+ if (isBundledElectronApp())
+ return 0;
+ return 1;
+}
+function isBundledElectronApp() {
+ return isElectronApp() && !process.defaultApp;
+}
+function isElectronApp() {
+ return !!process.versions.electron;
+}
+export function hideBin(argv) {
+ return argv.slice(getProcessArgvBinIndex() + 1);
+}
+export function getProcessArgvBin() {
+ return process.argv[getProcessArgvBinIndex()];
+}
diff --git a/node_modules/yargs/build/lib/utils/set-blocking.js b/node_modules/yargs/build/lib/utils/set-blocking.js
new file mode 100644
index 0000000..88fb806
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/set-blocking.js
@@ -0,0 +1,12 @@
+export default function setBlocking(blocking) {
+ if (typeof process === 'undefined')
+ return;
+ [process.stdout, process.stderr].forEach(_stream => {
+ const stream = _stream;
+ if (stream._handle &&
+ stream.isTTY &&
+ typeof stream._handle.setBlocking === 'function') {
+ stream._handle.setBlocking(blocking);
+ }
+ });
+}
diff --git a/node_modules/yargs/build/lib/utils/which-module.js b/node_modules/yargs/build/lib/utils/which-module.js
new file mode 100644
index 0000000..5974e22
--- /dev/null
+++ b/node_modules/yargs/build/lib/utils/which-module.js
@@ -0,0 +1,10 @@
+export default function whichModule(exported) {
+ if (typeof require === 'undefined')
+ return null;
+ for (let i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
+ mod = require.cache[files[i]];
+ if (mod.exports === exported)
+ return mod;
+ }
+ return null;
+}