yargs 18.0.0-candidate.2 → 18.0.0-candidate.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/README.md CHANGED
@@ -78,7 +78,7 @@ $ ./plunder.js --ships 12 --distance 98.7
78
78
  Retreat from the xupptumblers!
79
79
  ```
80
80
 
81
- > Note: `hideBin` is a shorthand for [`process.argv.slice(2)`](https://nodejs.org/en/knowledge/command-line/how-to-parse-command-line-arguments/). It has the benefit that it takes into account variations in some environments, e.g., [Electron](https://github.com/electron/electron/issues/4690).
81
+ > Note: `hideBin` is a shorthand for `process.argv.slice(2)`. It has the benefit that it takes into account variations in some environments, e.g., [Electron](https://github.com/electron/electron/issues/4690).
82
82
 
83
83
  ### Complex Example
84
84
 
@@ -4,8 +4,6 @@ import { applyMiddleware, commandMiddlewareFactory, } from './middleware.js';
4
4
  import { parseCommand } from './parse-command.js';
5
5
  import { isYargsInstance, } from './yargs-factory.js';
6
6
  import { maybeAsyncResult } from './utils/maybe-async-result.js';
7
- import { readdirSync } from 'node:fs';
8
- import { join, dirname } from 'node:path';
9
7
  const DEFAULT_MARKER = /(^\*)|(^\$0)/;
10
8
  export class CommandInstance {
11
9
  constructor(usage, validation, globalMiddleware, shim) {
@@ -21,15 +19,15 @@ export class CommandInstance {
21
19
  addDirectory(dir, req, callerFile, opts) {
22
20
  opts = opts || {};
23
21
  this.requireCache.add(callerFile);
24
- const fullDirPath = join(dirname(callerFile), dir);
25
- const files = readdirSync(fullDirPath, {
22
+ const fullDirPath = this.shim.path.join(this.shim.path.dirname(callerFile), dir);
23
+ const files = this.shim.readdirSync(fullDirPath, {
26
24
  recursive: opts.recurse ? true : false,
27
25
  });
28
26
  if (!Array.isArray(opts.extensions))
29
27
  opts.extensions = ['js'];
30
28
  const visit = typeof opts.visit === 'function' ? opts.visit : (o) => o;
31
29
  for (const fileb of files) {
32
- const file = fileb.toString('utf8');
30
+ const file = fileb.toString();
33
31
  if (opts.exclude) {
34
32
  let exclude = false;
35
33
  if (typeof opts.exclude === 'function') {
@@ -58,7 +56,7 @@ export class CommandInstance {
58
56
  supportedExtension = true;
59
57
  }
60
58
  if (supportedExtension) {
61
- const joined = join(fullDirPath, file);
59
+ const joined = this.shim.path.join(fullDirPath, file);
62
60
  const module = req(joined);
63
61
  const visited = visit(module, joined, file);
64
62
  if (visited) {
@@ -42,7 +42,11 @@ _{{app_name}}_yargs_completions()
42
42
  local si=$IFS
43
43
  IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "\${words[@]}"))
44
44
  IFS=$si
45
- _describe 'values' reply
45
+ if [[ \${#reply} -gt 0 ]]; then
46
+ _describe 'values' reply
47
+ else
48
+ _default
49
+ fi
46
50
  }
47
51
  compdef _{{app_name}}_yargs_completions {{app_name}}
48
52
  ###-end-{{app_name}}-completions-###
@@ -1,6 +1,4 @@
1
1
  import { YError } from '../yerror.js';
2
- import { createRequire } from 'node:module';
3
- const require = createRequire(import.meta.url);
4
2
  let previouslyVisitedConfigs = [];
5
3
  let shim;
6
4
  export function applyExtends(config, cwd, mergeExtends, _shim) {
@@ -26,7 +24,7 @@ export function applyExtends(config, cwd, mergeExtends, _shim) {
26
24
  previouslyVisitedConfigs.push(pathToDefault);
27
25
  defaultConfig = isPath
28
26
  ? JSON.parse(shim.readFileSync(pathToDefault, 'utf8'))
29
- : require(config.extends);
27
+ : _shim.require(config.extends);
30
28
  delete config.extends;
31
29
  defaultConfig = applyExtends(defaultConfig, shim.path.dirname(pathToDefault), mergeExtends, shim);
32
30
  }
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable no-unused-vars */
2
2
  'use strict';
3
3
 
4
- import cliui from 'https://unpkg.com/cliui@7.0.1/index.mjs'; // eslint-disable-line
5
- import Parser from 'https://unpkg.com/yargs-parser@19.0.0/browser.js'; // eslint-disable-line
4
+ import cliui from 'https://unpkg.com/cliui@8.0.1/index.mjs'; // eslint-disable-line
5
+ import Parser from 'https://unpkg.com/yargs-parser@21.1.1/browser.js'; // eslint-disable-line
6
6
  import {getProcessArgvBin} from '../../build/lib/utils/process-argv.js';
7
7
  import {YError} from '../../build/lib/yerror.js';
8
8
 
@@ -37,6 +37,7 @@ export default {
37
37
  dirname: str => str,
38
38
  extname: str => str,
39
39
  relative: str => str,
40
+ join: (str, _str2) => str,
40
41
  },
41
42
  process: {
42
43
  argv: () => [],
@@ -54,6 +55,9 @@ export default {
54
55
  readFileSync: () => {
55
56
  return '';
56
57
  },
58
+ readdirSync: () => {
59
+ return [];
60
+ },
57
61
  require: () => {
58
62
  throw new YError(REQUIRE_ERROR);
59
63
  },
@@ -4,15 +4,15 @@ import { notStrictEqual, strictEqual } from 'assert'
4
4
  import cliui from 'cliui'
5
5
  import escalade from 'escalade/sync'
6
6
  import { inspect } from 'util'
7
- import { readFileSync } from 'fs'
8
7
  import { fileURLToPath } from 'url';
9
8
  import Parser from 'yargs-parser'
10
- import { basename, dirname, extname, relative, resolve } from 'path'
9
+ import { basename, dirname, extname, relative, resolve, join } from 'path'
11
10
  import { getProcessArgvBin } from '../../build/lib/utils/process-argv.js'
12
11
  import stringWidth from 'string-width';
13
12
  import y18n from 'y18n'
14
13
  import { createRequire } from 'node:module';
15
14
  import getCallerFile from 'get-caller-file';
15
+ import { readFileSync, readdirSync } from 'node:fs'
16
16
 
17
17
  const __dirname = fileURLToPath(import.meta.url);
18
18
  const mainFilename = __dirname.substring(0, __dirname.lastIndexOf('node_modules'));
@@ -37,7 +37,8 @@ export default {
37
37
  dirname,
38
38
  extname,
39
39
  relative,
40
- resolve
40
+ resolve,
41
+ join
41
42
  },
42
43
  process: {
43
44
  argv: () => process.argv,
@@ -52,6 +53,7 @@ export default {
52
53
  stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
53
54
  },
54
55
  readFileSync,
56
+ readdirSync,
55
57
  require,
56
58
  getCallerFile: () => {
57
59
  const callerFile = getCallerFile(3);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "18.0.0-candidate.2",
3
+ "version": "18.0.0-candidate.4",
4
4
  "description": "yargs the modern, pirate-themed, successor to optimist.",
5
5
  "main": "./index.mjs",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
8
8
  "./helpers": "./helpers/helpers.mjs",
9
9
  "./browser": {
10
- "import": "./browser.mjs",
11
- "types": "./browser.d.ts"
10
+ "types": "./browser.d.ts",
11
+ "import": "./browser.mjs"
12
12
  },
13
13
  ".": "./index.mjs",
14
14
  "./yargs": "./index.mjs"