diff options
Diffstat (limited to 'node_modules/yargs/lib')
| -rw-r--r-- | node_modules/yargs/lib/platform-shims/browser.mjs | 92 | ||||
| -rw-r--r-- | node_modules/yargs/lib/platform-shims/esm.mjs | 67 | 
2 files changed, 159 insertions, 0 deletions
diff --git a/node_modules/yargs/lib/platform-shims/browser.mjs b/node_modules/yargs/lib/platform-shims/browser.mjs new file mode 100644 index 0000000..5740a0f --- /dev/null +++ b/node_modules/yargs/lib/platform-shims/browser.mjs @@ -0,0 +1,92 @@ +'use strict'; + +import cliui from 'https://unpkg.com/cliui@7.0.1/index.mjs'; // eslint-disable-line +import Parser from 'https://unpkg.com/yargs-parser@19.0.0/browser.js'; // eslint-disable-line +import {getProcessArgvBin} from '../../build/lib/utils/process-argv.js'; +import {YError} from '../../build/lib/yerror.js'; + +const REQUIRE_ERROR = 'require is not supported in browser'; +const REQUIRE_DIRECTORY_ERROR = +  'loading a directory of commands is not supported in browser'; + +export default { +  assert: { +    notStrictEqual: (a, b) => { +      // noop. +    }, +    strictEqual: (a, b) => { +      // noop. +    }, +  }, +  cliui, +  findUp: () => undefined, +  getEnv: key => { +    // There is no environment in browser: +    return undefined; +  }, +  inspect: console.log, +  getCallerFile: () => { +    throw new YError(REQUIRE_DIRECTORY_ERROR); +  }, +  getProcessArgvBin, +  mainFilename: 'yargs', +  Parser, +  path: { +    basename: str => str, +    dirname: str => str, +    extname: str => str, +    relative: str => str, +  }, +  process: { +    argv: () => [], +    cwd: () => '', +    execPath: () => '', +    // exit is noop browser: +    exit: () => {}, +    nextTick: cb => { +      window.setTimeout(cb, 1); +    }, +    stdColumns: 80, +  }, +  readFileSync: () => { +    return ''; +  }, +  require: () => { +    throw new YError(REQUIRE_ERROR); +  }, +  requireDirectory: () => { +    throw new YError(REQUIRE_DIRECTORY_ERROR); +  }, +  stringWidth: str => { +    return [...str].length; +  }, +  // TODO: replace this with y18n once it's ported to ESM: +  y18n: { +    __: (...str) => { +      if (str.length === 0) return ''; +      const args = str.slice(1); +      return sprintf(str[0], ...args); +    }, +    __n: (str1, str2, count, ...args) => { +      if (count === 1) { +        return sprintf(str1, ...args); +      } else { +        return sprintf(str2, ...args); +      } +    }, +    getLocale: () => { +      return 'en_US'; +    }, +    setLocale: () => {}, +    updateLocale: () => {}, +  }, +}; + +function sprintf(_str, ...args) { +  let str = ''; +  const split = _str.split('%s'); +  split.forEach((token, i) => { +    str += `${token}${split[i + 1] !== undefined && args[i] ? args[i] : ''}`; +  }); +  return str; +} diff --git a/node_modules/yargs/lib/platform-shims/esm.mjs b/node_modules/yargs/lib/platform-shims/esm.mjs new file mode 100644 index 0000000..bc04791 --- /dev/null +++ b/node_modules/yargs/lib/platform-shims/esm.mjs @@ -0,0 +1,67 @@ +'use strict' + +import { notStrictEqual, strictEqual } from 'assert' +import cliui from 'cliui' +import escalade from 'escalade/sync' +import { format, inspect } from 'util' +import { readFileSync } from 'fs' +import { fileURLToPath } from 'url'; +import Parser from 'yargs-parser' +import { basename, dirname, extname, relative, resolve } from 'path' +import { getProcessArgvBin } from '../../build/lib/utils/process-argv.js' +import { YError } from '../../build/lib/yerror.js' +import y18n from 'y18n' + +const REQUIRE_ERROR = 'require is not supported by ESM' +const REQUIRE_DIRECTORY_ERROR = 'loading a directory of commands is not supported yet for ESM' + +const mainFilename = fileURLToPath(import.meta.url).split('node_modules')[0] +const __dirname = fileURLToPath(import.meta.url) + +export default { +  assert: { +    notStrictEqual, +    strictEqual +  }, +  cliui, +  findUp: escalade, +  getEnv: (key) => { +    return process.env[key] +  }, +  inspect, +  getCallerFile: () => { +    throw new YError(REQUIRE_DIRECTORY_ERROR) +  }, +  getProcessArgvBin, +  mainFilename: mainFilename || process.cwd(), +  Parser, +  path: { +    basename, +    dirname, +    extname, +    relative, +    resolve +  }, +  process: { +    argv: () => process.argv, +    cwd: process.cwd, +    execPath: () => process.execPath, +    exit: process.exit, +    nextTick: process.nextTick, +    stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null +  }, +  readFileSync, +  require: () => { +    throw new YError(REQUIRE_ERROR) +  }, +  requireDirectory: () => { +    throw new YError(REQUIRE_DIRECTORY_ERROR) +  }, +  stringWidth: (str) => { +    return [...str].length +  }, +  y18n: y18n({ +    directory: resolve(__dirname, '../../../locales'), +    updateFiles: false +  }) +}  | 
