@oclif/core 4.0.27 → 4.0.29
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/lib/ux/colorize-json.d.ts +1 -0
- package/lib/ux/colorize-json.js +39 -5
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ type Options = {
|
|
|
2
2
|
pretty?: boolean | undefined;
|
|
3
3
|
theme?: Record<string, string> | undefined;
|
|
4
4
|
};
|
|
5
|
+
export declare function stringifyInput(json?: unknown, options?: Options): string;
|
|
5
6
|
export declare function tokenize(json?: unknown, options?: Options): {
|
|
6
7
|
type: string;
|
|
7
8
|
value: string;
|
package/lib/ux/colorize-json.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyInput = stringifyInput;
|
|
3
4
|
exports.tokenize = tokenize;
|
|
4
5
|
exports.default = colorizeJson;
|
|
5
6
|
const theme_1 = require("./theme");
|
|
@@ -15,15 +16,48 @@ const tokenTypes = [
|
|
|
15
16
|
{ regex: /^true|^false/, tokenType: 'boolean' },
|
|
16
17
|
{ regex: /^null/, tokenType: 'null' },
|
|
17
18
|
];
|
|
18
|
-
function
|
|
19
|
-
return
|
|
20
|
-
|
|
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);
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
stack.push(value);
|
|
47
|
+
// @ts-expect-error because `this` is not typed
|
|
48
|
+
return replacer ? replacer.call(this, key, value) : value;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function stringifyInput(json, options) {
|
|
52
|
+
const str = options?.pretty
|
|
53
|
+
? stringify(typeof json === 'string' ? JSON.parse(json) : json, undefined, 2)
|
|
21
54
|
: typeof json === 'string'
|
|
22
55
|
? json
|
|
23
|
-
:
|
|
56
|
+
: stringify(json);
|
|
57
|
+
return str;
|
|
24
58
|
}
|
|
25
59
|
function tokenize(json, options) {
|
|
26
|
-
let input =
|
|
60
|
+
let input = stringifyInput(json, options);
|
|
27
61
|
const tokens = [];
|
|
28
62
|
let foundToken = false;
|
|
29
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.
|
|
4
|
+
"version": "4.0.29",
|
|
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.
|
|
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",
|