@oclif/core 4.0.28 → 4.0.30

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.
@@ -40,6 +40,7 @@ const performance_1 = require("../performance");
40
40
  const settings_1 = require("../settings");
41
41
  const determine_priority_1 = require("../util/determine-priority");
42
42
  const fs_1 = require("../util/fs");
43
+ const ids_1 = require("../util/ids");
43
44
  const os_1 = require("../util/os");
44
45
  const util_2 = require("../util/util");
45
46
  const ux_1 = require("../ux");
@@ -696,22 +697,26 @@ class Config {
696
697
  this.commandPermutations.add(permutation, command.id);
697
698
  }
698
699
  const handleAlias = (alias, hidden = false) => {
699
- if (this._commands.has(alias)) {
700
+ const aliasWithDefaultTopicSeparator = (0, ids_1.toStandardizedId)(alias, this);
701
+ if (this._commands.has(aliasWithDefaultTopicSeparator)) {
700
702
  const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
701
- this._commands.get(alias),
703
+ this._commands.get(aliasWithDefaultTopicSeparator),
702
704
  command,
703
705
  ]);
704
- this._commands.set(alias, { ...prioritizedCommand, id: alias });
706
+ this._commands.set(aliasWithDefaultTopicSeparator, {
707
+ ...prioritizedCommand,
708
+ id: aliasWithDefaultTopicSeparator,
709
+ });
705
710
  }
706
711
  else {
707
- this._commands.set(alias, { ...command, hidden, id: alias });
712
+ this._commands.set(aliasWithDefaultTopicSeparator, { ...command, hidden, id: aliasWithDefaultTopicSeparator });
708
713
  }
709
714
  // set every permutation of the aliases
710
715
  // v3 moved command alias permutations to the manifest, but some plugins may not have
711
716
  // the new manifest yet. For those, we need to calculate the permutations here.
712
717
  const aliasPermutations = this.flexibleTaxonomy && command.aliasPermutations === undefined
713
- ? (0, util_3.getCommandIdPermutations)(alias)
714
- : (command.permutations ?? [alias]);
718
+ ? (0, util_3.getCommandIdPermutations)(aliasWithDefaultTopicSeparator)
719
+ : (command.permutations ?? [aliasWithDefaultTopicSeparator]);
715
720
  // set every permutation
716
721
  for (const permutation of aliasPermutations) {
717
722
  this.commandPermutations.add(permutation, command.id);
@@ -2,7 +2,7 @@ type Options = {
2
2
  pretty?: boolean | undefined;
3
3
  theme?: Record<string, string> | undefined;
4
4
  };
5
- export declare function removeCycles(object: unknown): unknown;
5
+ export declare function stringifyInput(json?: unknown, options?: Options): string;
6
6
  export declare function tokenize(json?: unknown, options?: Options): {
7
7
  type: string;
8
8
  value: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeCycles = removeCycles;
3
+ exports.stringifyInput = stringifyInput;
4
4
  exports.tokenize = tokenize;
5
5
  exports.default = colorizeJson;
6
6
  const theme_1 = require("./theme");
@@ -16,46 +16,48 @@ const tokenTypes = [
16
16
  { regex: /^true|^false/, tokenType: 'boolean' },
17
17
  { regex: /^null/, tokenType: 'null' },
18
18
  ];
19
- function removeCycles(object) {
20
- // Keep track of seen objects.
21
- const seenObjects = new WeakMap();
22
- const _removeCycles = (obj) => {
23
- // Use object prototype to get around type and null checks
24
- if (Object.prototype.toString.call(obj) === '[object Object]') {
25
- // We know it is a "Record<string, unknown>" because of the conditional
26
- const dictionary = obj;
27
- // Seen, return undefined to remove.
28
- if (seenObjects.has(dictionary))
29
- return;
30
- seenObjects.set(dictionary, undefined);
31
- for (const key in dictionary) {
32
- // Delete the duplicate object if cycle found.
33
- if (_removeCycles(dictionary[key]) === undefined) {
34
- delete dictionary[key];
35
- }
36
- }
37
- }
38
- else if (Array.isArray(obj)) {
39
- for (const i in obj) {
40
- if (_removeCycles(obj[i]) === undefined) {
41
- // We don't want to delete the array, but we can replace the element with null.
42
- obj[i] = null;
43
- }
44
- }
19
+ function stringify(value, replacer, spaces) {
20
+ return JSON.stringify(value, serializer(replacer, replacer), spaces);
21
+ }
22
+ // Inspired by https://github.com/moll/json-stringify-safe
23
+ function serializer(replacer, cycleReplacer) {
24
+ const stack = [];
25
+ const keys = [];
26
+ if (!cycleReplacer)
27
+ cycleReplacer = function (key, value) {
28
+ if (stack[0] === value)
29
+ return '[Circular ~]';
30
+ return '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']';
31
+ };
32
+ return function (key, value) {
33
+ if (stack.length > 0) {
34
+ // @ts-expect-error because `this` is not typed
35
+ const thisPos = stack.indexOf(this);
36
+ // @ts-expect-error because `this` is not typed
37
+ // eslint-disable-next-line no-bitwise
38
+ ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
39
+ // eslint-disable-next-line no-bitwise
40
+ ~thisPos ? keys.splice(thisPos, Number.POSITIVE_INFINITY, key) : keys.push(key);
41
+ // @ts-expect-error because `this` is not typed
42
+ if (stack.includes(value))
43
+ value = cycleReplacer.call(this, key, value);
45
44
  }
46
- return obj;
45
+ else
46
+ stack.push(value);
47
+ // @ts-expect-error because `this` is not typed
48
+ return replacer ? replacer.call(this, key, value) : value;
47
49
  };
48
- return _removeCycles(object);
49
50
  }
50
- function formatInput(json, options) {
51
- return options?.pretty
52
- ? JSON.stringify(typeof json === 'string' ? JSON.parse(json) : json, null, 2)
51
+ function stringifyInput(json, options) {
52
+ const str = options?.pretty
53
+ ? stringify(typeof json === 'string' ? JSON.parse(json) : json, undefined, 2)
53
54
  : typeof json === 'string'
54
55
  ? json
55
- : JSON.stringify(json);
56
+ : stringify(json);
57
+ return str;
56
58
  }
57
59
  function tokenize(json, options) {
58
- let input = formatInput(removeCycles(json), options);
60
+ let input = stringifyInput(json, options);
59
61
  const tokens = [];
60
62
  let foundToken = false;
61
63
  do {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.0.28",
4
+ "version": "4.0.30",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -37,7 +37,7 @@
37
37
  "@types/debug": "^4.1.10",
38
38
  "@types/ejs": "^3.1.5",
39
39
  "@types/indent-string": "^4.0.1",
40
- "@types/mocha": "^10.0.8",
40
+ "@types/mocha": "^10.0.9",
41
41
  "@types/node": "^18",
42
42
  "@types/pnpapi": "^0.0.5",
43
43
  "@types/sinon": "^17.0.3",
@@ -51,7 +51,7 @@
51
51
  "cross-env": "^7.0.3",
52
52
  "eslint": "^8.57.1",
53
53
  "eslint-config-oclif": "^5.2.1",
54
- "eslint-config-oclif-typescript": "^3.1.11",
54
+ "eslint-config-oclif-typescript": "^3.1.12",
55
55
  "eslint-config-prettier": "^9.1.0",
56
56
  "husky": "^9.1.6",
57
57
  "lint-staged": "^15",