@oclif/core 3.0.0-beta.9 → 3.0.1
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 +4 -2
- package/flush.d.ts +3 -0
- package/flush.js +1 -0
- package/handle.js +1 -0
- package/lib/args.d.ts +2 -2
- package/lib/args.js +17 -18
- package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
- package/lib/{ux → cli-ux}/action/base.js +126 -120
- package/lib/{ux → cli-ux}/action/simple.js +25 -30
- package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
- package/lib/{ux → cli-ux}/action/spinner.js +45 -37
- package/lib/{ux → cli-ux}/action/spinners.js +187 -187
- package/lib/cli-ux/action/types.d.ts +5 -0
- package/lib/cli-ux/action/types.js +2 -0
- package/lib/{ux → cli-ux}/config.d.ts +5 -5
- package/lib/{ux → cli-ux}/config.js +17 -17
- package/lib/{ux → cli-ux}/exit.js +3 -0
- package/lib/cli-ux/flush.d.ts +1 -0
- package/lib/cli-ux/flush.js +28 -0
- package/lib/cli-ux/index.d.ts +39 -0
- package/lib/{ux → cli-ux}/index.js +74 -88
- package/lib/{ux → cli-ux}/list.js +3 -3
- package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
- package/lib/{ux → cli-ux}/prompt.js +35 -25
- package/lib/{ux → cli-ux}/stream.d.ts +6 -6
- package/lib/{ux → cli-ux}/stream.js +11 -10
- package/lib/cli-ux/styled/index.d.ts +4 -0
- package/lib/cli-ux/styled/index.js +11 -0
- package/lib/{ux → cli-ux}/styled/object.js +7 -9
- package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
- package/lib/{ux → cli-ux}/styled/table.js +130 -133
- package/lib/{ux → cli-ux}/styled/tree.js +11 -13
- package/lib/cli-ux/wait.js +5 -0
- package/lib/command.d.ts +82 -88
- package/lib/command.js +196 -175
- package/lib/config/config.d.ts +89 -90
- package/lib/config/config.js +466 -566
- package/lib/config/index.d.ts +0 -1
- package/lib/config/index.js +1 -3
- package/lib/config/plugin-loader.d.ts +12 -12
- package/lib/config/plugin-loader.js +72 -56
- package/lib/config/plugin.d.ts +25 -24
- package/lib/config/plugin.js +188 -154
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +71 -58
- package/lib/config/util.d.ts +1 -11
- package/lib/config/util.js +6 -59
- package/lib/errors/config.d.ts +1 -1
- package/lib/errors/config.js +6 -6
- package/lib/errors/errors/cli.d.ts +7 -7
- package/lib/errors/errors/cli.js +20 -16
- package/lib/errors/errors/exit.d.ts +1 -4
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.d.ts +1 -4
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/errors/pretty-print.d.ts +1 -1
- package/lib/errors/errors/pretty-print.js +12 -10
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +26 -14
- package/lib/errors/index.d.ts +10 -10
- package/lib/errors/index.js +25 -24
- package/lib/errors/logger.d.ts +2 -2
- package/lib/errors/logger.js +14 -13
- package/lib/execute.d.ts +6 -6
- package/lib/execute.js +10 -9
- package/lib/flags.d.ts +103 -32
- package/lib/flags.js +79 -45
- package/lib/help/command.d.ts +16 -14
- package/lib/help/command.js +178 -163
- package/lib/help/docopts.d.ts +5 -5
- package/lib/help/docopts.js +50 -54
- package/lib/help/formatter.d.ts +37 -37
- package/lib/help/formatter.js +66 -55
- package/lib/help/index.d.ts +25 -21
- package/lib/help/index.js +169 -147
- package/lib/help/root.d.ts +1 -1
- package/lib/help/root.js +15 -17
- package/lib/help/util.d.ts +2 -8
- package/lib/help/util.js +8 -28
- package/lib/index.d.ts +19 -20
- package/lib/index.js +37 -43
- package/lib/interfaces/config.d.ts +67 -66
- package/lib/interfaces/errors.d.ts +5 -5
- package/lib/interfaces/help.d.ts +17 -17
- package/lib/interfaces/hooks.d.ts +49 -49
- package/lib/interfaces/index.d.ts +7 -7
- package/lib/interfaces/manifest.d.ts +1 -1
- package/lib/interfaces/parser.d.ts +175 -51
- package/lib/interfaces/pjson.d.ts +45 -41
- package/lib/interfaces/plugin.d.ts +47 -41
- package/lib/interfaces/s3-manifest.d.ts +7 -7
- package/lib/interfaces/topic.d.ts +1 -1
- package/lib/interfaces/ts-config.d.ts +7 -7
- package/lib/main.d.ts +2 -2
- package/lib/main.js +16 -16
- package/lib/module-loader.d.ts +67 -77
- package/lib/module-loader.js +183 -150
- package/lib/parser/errors.d.ts +7 -7
- package/lib/parser/errors.js +29 -22
- package/lib/parser/help.js +5 -5
- package/lib/parser/index.js +2 -2
- package/lib/parser/parse.d.ts +9 -6
- package/lib/parser/parse.js +253 -221
- package/lib/parser/validate.js +53 -33
- package/lib/performance.d.ts +43 -32
- package/lib/performance.js +133 -91
- package/lib/screen.js +2 -2
- package/lib/settings.d.ts +11 -12
- package/lib/settings.js +2 -2
- package/lib/util/aggregate-flags.d.ts +2 -0
- package/lib/util/aggregate-flags.js +13 -0
- package/lib/util/cache-command.d.ts +3 -0
- package/lib/util/cache-command.js +109 -0
- package/lib/util/cache-default-value.d.ts +2 -0
- package/lib/util/cache-default-value.js +28 -0
- package/lib/util/ensure-arg-object.d.ts +12 -0
- package/lib/util/ensure-arg-object.js +14 -0
- package/lib/util/fs.d.ts +7 -0
- package/lib/util/fs.js +54 -0
- package/lib/util/os.d.ts +19 -0
- package/lib/util/os.js +28 -0
- package/lib/{util.d.ts → util/util.d.ts} +7 -16
- package/lib/util/util.js +98 -0
- package/package.json +35 -37
- package/lib/util.js +0 -126
- package/lib/ux/flush.d.ts +0 -1
- package/lib/ux/flush.js +0 -27
- package/lib/ux/index.d.ts +0 -58
- package/lib/ux/styled/index.d.ts +0 -6
- package/lib/ux/styled/index.js +0 -13
- package/lib/ux/styled/json.d.ts +0 -1
- package/lib/ux/styled/json.js +0 -15
- package/lib/ux/wait.js +0 -7
- package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
- package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
- package/lib/{ux → cli-ux}/exit.d.ts +2 -2
- package/lib/{ux → cli-ux}/list.d.ts +0 -0
- package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
- package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
- package/lib/{ux → cli-ux}/styled/progress.js +0 -0
- package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
- /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
package/lib/config/ts-node.js
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsPath = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
exports.tsPath = exports.TS_CONFIGS = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
6
7
|
const settings_1 = require("../settings");
|
|
7
|
-
const
|
|
8
|
+
const fs_1 = require("../util/fs");
|
|
9
|
+
const util_1 = require("../util/util");
|
|
8
10
|
const util_2 = require("./util");
|
|
9
|
-
const config_1 = require("./config");
|
|
10
|
-
const errors_1 = require("../errors");
|
|
11
11
|
// eslint-disable-next-line new-cap
|
|
12
12
|
const debug = (0, util_2.Debug)('ts-node');
|
|
13
|
-
|
|
13
|
+
exports.TS_CONFIGS = {};
|
|
14
14
|
const REGISTERED = new Set();
|
|
15
|
+
/**
|
|
16
|
+
* Cache the root plugin so that we can reference it later when determining if
|
|
17
|
+
* we should skip ts-node registration for an ESM plugin.
|
|
18
|
+
*/
|
|
19
|
+
let ROOT_PLUGIN;
|
|
15
20
|
function loadTSConfig(root) {
|
|
16
|
-
if (TS_CONFIGS[root])
|
|
17
|
-
return TS_CONFIGS[root];
|
|
18
|
-
const tsconfigPath =
|
|
21
|
+
if (exports.TS_CONFIGS[root])
|
|
22
|
+
return exports.TS_CONFIGS[root];
|
|
23
|
+
const tsconfigPath = (0, node_path_1.join)(root, 'tsconfig.json');
|
|
19
24
|
let typescript;
|
|
20
25
|
try {
|
|
21
26
|
typescript = require('typescript');
|
|
22
27
|
}
|
|
23
28
|
catch {
|
|
24
29
|
try {
|
|
25
|
-
typescript = require(
|
|
30
|
+
typescript = require((0, node_path_1.join)(root, 'node_modules', 'typescript'));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
debug(`Could not find typescript dependency. Skipping ts-node registration for ${root}.`);
|
|
34
|
+
(0, errors_1.memoizedWarn)('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.');
|
|
35
|
+
return;
|
|
26
36
|
}
|
|
27
|
-
catch { }
|
|
28
37
|
}
|
|
29
|
-
if (
|
|
30
|
-
const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath,
|
|
38
|
+
if ((0, node_fs_1.existsSync)(tsconfigPath) && typescript) {
|
|
39
|
+
const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0, fs_1.readJsonSync)(tsconfigPath, false)).config;
|
|
31
40
|
if (!tsconfig || !tsconfig.compilerOptions) {
|
|
32
41
|
throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it ` +
|
|
33
42
|
'did not contain a "compilerOptions" section.');
|
|
34
43
|
}
|
|
35
|
-
TS_CONFIGS[root] = tsconfig;
|
|
44
|
+
exports.TS_CONFIGS[root] = tsconfig;
|
|
36
45
|
return tsconfig;
|
|
37
46
|
}
|
|
38
47
|
}
|
|
@@ -45,40 +54,46 @@ function registerTSNode(root) {
|
|
|
45
54
|
debug('registering ts-node at', root);
|
|
46
55
|
const tsNodePath = require.resolve('ts-node', { paths: [root, __dirname] });
|
|
47
56
|
debug('ts-node path:', tsNodePath);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
let tsNode;
|
|
58
|
+
try {
|
|
59
|
+
tsNode = require(tsNodePath);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
debug(`Could not find ts-node at ${tsNodePath}. Skipping ts-node registration for ${root}.`);
|
|
63
|
+
(0, errors_1.memoizedWarn)(`Could not find ts-node at ${tsNodePath}. Please ensure that ts-node is a devDependency. Falling back to compiled source.`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const typeRoots = [(0, node_path_1.join)(root, 'node_modules', '@types')];
|
|
52
67
|
const rootDirs = [];
|
|
53
68
|
if (tsconfig.compilerOptions.rootDirs) {
|
|
54
69
|
for (const r of tsconfig.compilerOptions.rootDirs) {
|
|
55
|
-
rootDirs.push(
|
|
70
|
+
rootDirs.push((0, node_path_1.join)(root, r));
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
else if (tsconfig.compilerOptions.rootDir) {
|
|
59
|
-
rootDirs.push(
|
|
74
|
+
rootDirs.push((0, node_path_1.join)(root, tsconfig.compilerOptions.rootDir));
|
|
60
75
|
}
|
|
61
76
|
else {
|
|
62
|
-
rootDirs.push(
|
|
77
|
+
rootDirs.push((0, node_path_1.join)(root, 'src'));
|
|
63
78
|
}
|
|
64
79
|
const conf = {
|
|
65
80
|
compilerOptions: {
|
|
81
|
+
emitDecoratorMetadata: tsconfig.compilerOptions.emitDecoratorMetadata ?? false,
|
|
66
82
|
esModuleInterop: tsconfig.compilerOptions.esModuleInterop,
|
|
67
|
-
target: tsconfig.compilerOptions.target ?? 'es2019',
|
|
68
83
|
experimentalDecorators: tsconfig.compilerOptions.experimentalDecorators ?? false,
|
|
69
|
-
emitDecoratorMetadata: tsconfig.compilerOptions.emitDecoratorMetadata ?? false,
|
|
70
84
|
module: tsconfig.compilerOptions.module ?? 'commonjs',
|
|
71
|
-
sourceMap: tsconfig.compilerOptions.sourceMap ?? true,
|
|
72
85
|
rootDirs,
|
|
86
|
+
sourceMap: tsconfig.compilerOptions.sourceMap ?? true,
|
|
87
|
+
target: tsconfig.compilerOptions.target ?? 'es2019',
|
|
73
88
|
typeRoots,
|
|
74
89
|
},
|
|
75
|
-
|
|
76
|
-
transpileOnly: true,
|
|
90
|
+
cwd: root,
|
|
77
91
|
esm: tsconfig['ts-node']?.esm ?? true,
|
|
92
|
+
experimentalSpecifierResolution: tsconfig['ts-node']?.experimentalSpecifierResolution ?? 'explicit',
|
|
78
93
|
scope: true,
|
|
79
94
|
scopeDir: root,
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
skipProject: true,
|
|
96
|
+
transpileOnly: true,
|
|
82
97
|
};
|
|
83
98
|
if (tsconfig.compilerOptions.moduleResolution) {
|
|
84
99
|
// @ts-expect-error TSNode.RegisterOptions.compilerOptions is typed as a plain object
|
|
@@ -92,39 +107,37 @@ function registerTSNode(root) {
|
|
|
92
107
|
REGISTERED.add(root);
|
|
93
108
|
return tsconfig;
|
|
94
109
|
}
|
|
95
|
-
// eslint-disable-next-line complexity
|
|
96
110
|
function tsPath(root, orig, plugin) {
|
|
111
|
+
if (plugin?.isRoot)
|
|
112
|
+
ROOT_PLUGIN = plugin;
|
|
97
113
|
if (!orig)
|
|
98
114
|
return orig;
|
|
99
|
-
orig = orig.startsWith(root) ? orig :
|
|
115
|
+
orig = orig.startsWith(root) ? orig : (0, node_path_1.join)(root, orig);
|
|
100
116
|
// NOTE: The order of these checks matter!
|
|
101
|
-
if (settings_1.
|
|
117
|
+
if (settings_1.settings.tsnodeEnabled === false) {
|
|
102
118
|
debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
|
|
103
119
|
return orig;
|
|
104
120
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
121
|
+
const isProduction = (0, util_1.isProd)();
|
|
122
|
+
/**
|
|
123
|
+
* Skip ts-node registration for ESM plugins.
|
|
124
|
+
* The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
|
|
125
|
+
* See the following:
|
|
126
|
+
* - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228
|
|
127
|
+
* - https://github.com/nodejs/node/issues/49432
|
|
128
|
+
* - https://github.com/nodejs/node/pull/49407
|
|
129
|
+
* - https://github.com/nodejs/node/issues/34049
|
|
130
|
+
*
|
|
131
|
+
* We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM.
|
|
132
|
+
* In other words, this allows plugins to be auto-transpiled when developing locally using `bin/dev.js`.
|
|
133
|
+
*/
|
|
134
|
+
if ((isProduction || ROOT_PLUGIN?.moduleType === 'commonjs') && plugin?.moduleType === 'module') {
|
|
135
|
+
debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${ROOT_PLUGIN?.moduleType})))`);
|
|
108
136
|
if (plugin.type === 'link')
|
|
109
|
-
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-
|
|
137
|
+
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
110
138
|
return orig;
|
|
111
139
|
}
|
|
112
|
-
|
|
113
|
-
// either in the NODE_OPTIONS env var or from the exec args. If the ts-node/esm loader has NOT been loaded then we want
|
|
114
|
-
// to skip ts-node registration so that it falls back on the compiled source.
|
|
115
|
-
if (plugin?.moduleType === 'module') {
|
|
116
|
-
const tsNodeEsmLoaderInExecArgv = process.execArgv.includes('--loader') && process.execArgv.includes('ts-node/esm');
|
|
117
|
-
const tsNodeEsmLoaderInNodeOptions = process.env.NODE_OPTIONS?.includes('--loader=ts-node/esm') ?? false;
|
|
118
|
-
if (!tsNodeEsmLoaderInExecArgv && !tsNodeEsmLoaderInNodeOptions) {
|
|
119
|
-
debug(`Skipping ts-node registration for ${root} because it's an ESM module but the ts-node/esm loader hasn't been run`);
|
|
120
|
-
debug('try setting NODE_OPTIONS="--loader ts-node/esm" in your environment.');
|
|
121
|
-
if (plugin.type === 'link') {
|
|
122
|
-
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-compiled without setting NODE_OPTIONS="--loader=ts-node/esm" in the environment. Existing compiled source will be used instead.`);
|
|
123
|
-
}
|
|
124
|
-
return orig;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (settings_1.default.tsnodeEnabled === undefined && (0, util_1.isProd)() && plugin?.type !== 'link') {
|
|
140
|
+
if (settings_1.settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') {
|
|
128
141
|
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
|
|
129
142
|
return orig;
|
|
130
143
|
}
|
|
@@ -132,22 +145,22 @@ function tsPath(root, orig, plugin) {
|
|
|
132
145
|
const tsconfig = registerTSNode(root);
|
|
133
146
|
if (!tsconfig)
|
|
134
147
|
return orig;
|
|
135
|
-
const { rootDir, rootDirs
|
|
148
|
+
const { outDir, rootDir, rootDirs } = tsconfig.compilerOptions;
|
|
136
149
|
const rootDirPath = rootDir || (rootDirs || [])[0];
|
|
137
150
|
if (!rootDirPath || !outDir)
|
|
138
151
|
return orig;
|
|
139
152
|
// rewrite path from ./lib/foo to ./src/foo
|
|
140
|
-
const lib =
|
|
141
|
-
const src =
|
|
142
|
-
const relative =
|
|
153
|
+
const lib = (0, node_path_1.join)(root, outDir); // ./lib
|
|
154
|
+
const src = (0, node_path_1.join)(root, rootDirPath); // ./src
|
|
155
|
+
const relative = (0, node_path_1.relative)(lib, orig); // ./commands
|
|
143
156
|
// For hooks, it might point to a js file, not a module. Something like "./hooks/myhook.js" which doesn't need the js.
|
|
144
|
-
const out =
|
|
157
|
+
const out = (0, node_path_1.join)(src, relative).replace(/\.js$/, ''); // ./src/commands
|
|
145
158
|
// this can be a directory of commands or point to a hook file
|
|
146
159
|
// if it's a directory, we check if the path exists. If so, return the path to the directory.
|
|
147
160
|
// For hooks, it might point to a module, not a file. Something like "./hooks/myhook"
|
|
148
161
|
// That file doesn't exist, and the real file is "./hooks/myhook.ts"
|
|
149
162
|
// In that case we attempt to resolve to the filename. If it fails it will revert back to the lib path
|
|
150
|
-
if (
|
|
163
|
+
if ((0, node_fs_1.existsSync)(out) || (0, node_fs_1.existsSync)(out + '.ts'))
|
|
151
164
|
return out;
|
|
152
165
|
return orig;
|
|
153
166
|
}
|
package/lib/config/util.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
export declare function flatMap<T, U>(arr: T[], fn: (i: T) => U[]): U[];
|
|
2
|
-
export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
|
|
3
|
-
[P in keyof T]: T[P];
|
|
4
|
-
}, fn: (i: T[keyof T], k: keyof T) => TResult): {
|
|
5
|
-
[P in keyof T]: TResult;
|
|
6
|
-
};
|
|
7
|
-
export declare function exists(path: string): Promise<boolean>;
|
|
8
1
|
export declare function resolvePackage(id: string, paths: {
|
|
9
2
|
paths: string[];
|
|
10
3
|
}): string;
|
|
11
|
-
export declare function loadJSON(path: string): Promise<any>;
|
|
12
|
-
export declare function compact<T>(a: (T | undefined)[]): T[];
|
|
13
|
-
export declare function uniq<T>(arr: T[]): T[];
|
|
14
4
|
export declare function Debug(...scope: string[]): (..._: any) => void;
|
|
15
5
|
export declare function getPermutations(arr: string[]): Array<string[]>;
|
|
16
6
|
export declare function getCommandIdPermutations(commandId: string): string[];
|
|
@@ -33,4 +23,4 @@ export declare function getCommandIdPermutations(commandId: string): string[];
|
|
|
33
23
|
* @param commandIds string[]
|
|
34
24
|
* @returns string[]
|
|
35
25
|
*/
|
|
36
|
-
export declare
|
|
26
|
+
export declare const collectUsableIds: (commandIds: string[]) => Set<string>;
|
package/lib/config/util.js
CHANGED
|
@@ -1,54 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.
|
|
4
|
-
const fs = require("fs");
|
|
3
|
+
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.Debug = exports.resolvePackage = void 0;
|
|
5
4
|
const debug = require('debug');
|
|
6
|
-
function flatMap(arr, fn) {
|
|
7
|
-
return arr.reduce((arr, i) => [...arr, ...fn(i)], []);
|
|
8
|
-
}
|
|
9
|
-
exports.flatMap = flatMap;
|
|
10
|
-
function mapValues(obj, fn) {
|
|
11
|
-
return Object.entries(obj)
|
|
12
|
-
.reduce((o, [k, v]) => {
|
|
13
|
-
o[k] = fn(v, k);
|
|
14
|
-
return o;
|
|
15
|
-
}, {});
|
|
16
|
-
}
|
|
17
|
-
exports.mapValues = mapValues;
|
|
18
|
-
function exists(path) {
|
|
19
|
-
// eslint-disable-next-line no-promise-executor-return
|
|
20
|
-
return new Promise(resolve => resolve(fs.existsSync(path)));
|
|
21
|
-
}
|
|
22
|
-
exports.exists = exists;
|
|
23
5
|
function resolvePackage(id, paths) {
|
|
24
6
|
return require.resolve(id, paths);
|
|
25
7
|
}
|
|
26
8
|
exports.resolvePackage = resolvePackage;
|
|
27
|
-
function loadJSON(path) {
|
|
28
|
-
debug('config')('loadJSON %s', path);
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
fs.readFile(path, 'utf8', (err, d) => {
|
|
31
|
-
try {
|
|
32
|
-
if (err)
|
|
33
|
-
reject(err);
|
|
34
|
-
else
|
|
35
|
-
resolve(JSON.parse(d));
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
reject(error);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
exports.loadJSON = loadJSON;
|
|
44
|
-
function compact(a) {
|
|
45
|
-
return a.filter((a) => Boolean(a));
|
|
46
|
-
}
|
|
47
|
-
exports.compact = compact;
|
|
48
|
-
function uniq(arr) {
|
|
49
|
-
return [...new Set(arr)].sort();
|
|
50
|
-
}
|
|
51
|
-
exports.uniq = uniq;
|
|
52
9
|
function displayWarnings() {
|
|
53
10
|
if (process.listenerCount('warning') > 1)
|
|
54
11
|
return;
|
|
@@ -60,7 +17,9 @@ function displayWarnings() {
|
|
|
60
17
|
}
|
|
61
18
|
function Debug(...scope) {
|
|
62
19
|
if (!debug)
|
|
63
|
-
return (..._) => {
|
|
20
|
+
return (..._) => {
|
|
21
|
+
// noop
|
|
22
|
+
};
|
|
64
23
|
const d = debug(['config', ...scope].join(':'));
|
|
65
24
|
if (d.enabled)
|
|
66
25
|
displayWarnings();
|
|
@@ -89,7 +48,7 @@ function getPermutations(arr) {
|
|
|
89
48
|
}
|
|
90
49
|
exports.getPermutations = getPermutations;
|
|
91
50
|
function getCommandIdPermutations(commandId) {
|
|
92
|
-
return getPermutations(commandId.split(':')).flatMap(c => c.join(':'));
|
|
51
|
+
return getPermutations(commandId.split(':')).flatMap((c) => c.join(':'));
|
|
93
52
|
}
|
|
94
53
|
exports.getCommandIdPermutations = getCommandIdPermutations;
|
|
95
54
|
/**
|
|
@@ -111,17 +70,5 @@ exports.getCommandIdPermutations = getCommandIdPermutations;
|
|
|
111
70
|
* @param commandIds string[]
|
|
112
71
|
* @returns string[]
|
|
113
72
|
*/
|
|
114
|
-
|
|
115
|
-
const usuableIds = [];
|
|
116
|
-
for (const id of commandIds) {
|
|
117
|
-
const parts = id.split(':');
|
|
118
|
-
while (parts.length > 0) {
|
|
119
|
-
const name = parts.join(':');
|
|
120
|
-
if (name)
|
|
121
|
-
usuableIds.push(name);
|
|
122
|
-
parts.pop();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return new Set(usuableIds);
|
|
126
|
-
}
|
|
73
|
+
const collectUsableIds = (commandIds) => new Set(commandIds.flatMap((id) => id.split(':').map((_, i, a) => a.slice(0, i + 1).join(':'))));
|
|
127
74
|
exports.collectUsableIds = collectUsableIds;
|
package/lib/errors/config.d.ts
CHANGED
package/lib/errors/config.js
CHANGED
|
@@ -13,26 +13,26 @@ function displayWarnings() {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
exports.config = {
|
|
16
|
-
errorLogger: undefined,
|
|
17
16
|
get debug() {
|
|
18
|
-
return Boolean(settings_1.
|
|
17
|
+
return Boolean(settings_1.settings.debug);
|
|
19
18
|
},
|
|
20
19
|
set debug(enabled) {
|
|
21
|
-
settings_1.
|
|
20
|
+
settings_1.settings.debug = enabled;
|
|
22
21
|
if (enabled)
|
|
23
22
|
displayWarnings();
|
|
24
23
|
},
|
|
25
24
|
get errlog() {
|
|
26
|
-
return settings_1.
|
|
25
|
+
return settings_1.settings.errlog;
|
|
27
26
|
},
|
|
28
27
|
set errlog(errlog) {
|
|
29
28
|
if (errlog) {
|
|
30
29
|
this.errorLogger = new logger_1.Logger(errlog);
|
|
31
|
-
settings_1.
|
|
30
|
+
settings_1.settings.errlog = errlog;
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
33
|
delete this.errorLogger;
|
|
35
|
-
delete settings_1.
|
|
34
|
+
delete settings_1.settings.errlog;
|
|
36
35
|
}
|
|
37
36
|
},
|
|
37
|
+
errorLogger: undefined,
|
|
38
38
|
};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OclifError, PrettyPrintableError } from '../../interfaces/errors';
|
|
2
2
|
/**
|
|
3
3
|
* properties specific to internal oclif error handling
|
|
4
4
|
*/
|
|
5
5
|
export declare function addOclifExitCode(error: Record<string, any>, options?: {
|
|
6
|
-
exit?:
|
|
6
|
+
exit?: false | number;
|
|
7
7
|
}): OclifError;
|
|
8
8
|
export declare class CLIError extends Error implements OclifError {
|
|
9
|
-
oclif: OclifError['oclif'];
|
|
10
9
|
code?: string;
|
|
10
|
+
oclif: OclifError['oclif'];
|
|
11
11
|
suggestions?: string[];
|
|
12
|
-
constructor(error:
|
|
13
|
-
exit?:
|
|
12
|
+
constructor(error: Error | string, options?: {
|
|
13
|
+
exit?: false | number;
|
|
14
14
|
} & PrettyPrintableError);
|
|
15
|
-
get stack(): string;
|
|
16
15
|
/**
|
|
17
16
|
* @deprecated `render` Errors display should be handled by display function, like pretty-print
|
|
18
17
|
* @return {string} returns a string representing the dispay of the error
|
|
19
18
|
*/
|
|
20
19
|
render(): string;
|
|
21
20
|
get bang(): string | undefined;
|
|
21
|
+
get stack(): string;
|
|
22
22
|
}
|
|
23
23
|
export declare namespace CLIError {
|
|
24
24
|
class Warn extends CLIError {
|
|
25
|
-
constructor(err:
|
|
25
|
+
constructor(err: Error | string);
|
|
26
26
|
get bang(): string | undefined;
|
|
27
27
|
}
|
|
28
28
|
}
|
package/lib/errors/errors/cli.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CLIError = exports.addOclifExitCode = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const clean_stack_1 = tslib_1.__importDefault(require("clean-stack"));
|
|
7
|
+
const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
|
|
8
|
+
const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
|
|
9
|
+
const screen_1 = require("../../screen");
|
|
9
10
|
const config_1 = require("../config");
|
|
10
11
|
/**
|
|
11
12
|
* properties specific to internal oclif error handling
|
|
12
13
|
*/
|
|
13
14
|
function addOclifExitCode(error, options) {
|
|
14
15
|
if (!('oclif' in error)) {
|
|
16
|
+
;
|
|
15
17
|
error.oclif = {};
|
|
16
18
|
}
|
|
17
19
|
error.oclif.exit = options?.exit === undefined ? 2 : options.exit;
|
|
@@ -19,16 +21,15 @@ function addOclifExitCode(error, options) {
|
|
|
19
21
|
}
|
|
20
22
|
exports.addOclifExitCode = addOclifExitCode;
|
|
21
23
|
class CLIError extends Error {
|
|
24
|
+
code;
|
|
25
|
+
oclif = {};
|
|
26
|
+
suggestions;
|
|
22
27
|
constructor(error, options = {}) {
|
|
23
28
|
super(error instanceof Error ? error.message : error);
|
|
24
|
-
this.oclif = {};
|
|
25
29
|
addOclifExitCode(this, options);
|
|
26
30
|
this.code = options.code;
|
|
27
31
|
this.suggestions = options.suggestions;
|
|
28
32
|
}
|
|
29
|
-
get stack() {
|
|
30
|
-
return cs(super.stack, { pretty: true });
|
|
31
|
-
}
|
|
32
33
|
/**
|
|
33
34
|
* @deprecated `render` Errors display should be handled by display function, like pretty-print
|
|
34
35
|
* @return {string} returns a string representing the dispay of the error
|
|
@@ -38,18 +39,21 @@ class CLIError extends Error {
|
|
|
38
39
|
return this.stack;
|
|
39
40
|
}
|
|
40
41
|
let output = `${this.name}: ${this.message}`;
|
|
41
|
-
output =
|
|
42
|
-
output =
|
|
43
|
-
output =
|
|
44
|
-
output =
|
|
42
|
+
output = (0, wrap_ansi_1.default)(output, screen_1.errtermwidth - 6, { hard: true, trim: false });
|
|
43
|
+
output = (0, indent_string_1.default)(output, 3);
|
|
44
|
+
output = (0, indent_string_1.default)(output, 1, { includeEmptyLines: true, indent: this.bang });
|
|
45
|
+
output = (0, indent_string_1.default)(output, 1);
|
|
45
46
|
return output;
|
|
46
47
|
}
|
|
47
48
|
get bang() {
|
|
48
49
|
try {
|
|
49
|
-
return
|
|
50
|
+
return chalk_1.default.red(process.platform === 'win32' ? '»' : '›');
|
|
50
51
|
}
|
|
51
52
|
catch { }
|
|
52
53
|
}
|
|
54
|
+
get stack() {
|
|
55
|
+
return (0, clean_stack_1.default)(super.stack, { pretty: true });
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
exports.CLIError = CLIError;
|
|
55
59
|
(function (CLIError) {
|
|
@@ -60,10 +64,10 @@ exports.CLIError = CLIError;
|
|
|
60
64
|
}
|
|
61
65
|
get bang() {
|
|
62
66
|
try {
|
|
63
|
-
return
|
|
67
|
+
return chalk_1.default.yellow(process.platform === 'win32' ? '»' : '›');
|
|
64
68
|
}
|
|
65
69
|
catch { }
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
CLIError.Warn = Warn;
|
|
69
|
-
})(CLIError
|
|
73
|
+
})(CLIError || (exports.CLIError = CLIError = {}));
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { CLIError } from './cli';
|
|
2
1
|
import { OclifError } from '../../interfaces';
|
|
2
|
+
import { CLIError } from './cli';
|
|
3
3
|
export declare class ExitError extends CLIError implements OclifError {
|
|
4
|
-
oclif: {
|
|
5
|
-
exit: number;
|
|
6
|
-
};
|
|
7
4
|
code: string;
|
|
8
5
|
constructor(exitCode?: number);
|
|
9
6
|
render(): string;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExitError = void 0;
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
class ExitError extends cli_1.CLIError {
|
|
6
|
+
code = 'EEXIT';
|
|
6
7
|
constructor(exitCode = 1) {
|
|
7
8
|
super(`EEXIT: ${exitCode}`, { exit: exitCode });
|
|
8
|
-
this.code = 'EEXIT';
|
|
9
9
|
}
|
|
10
10
|
render() {
|
|
11
11
|
return '';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { CLIError } from './cli';
|
|
2
1
|
import { OclifError } from '../../interfaces';
|
|
2
|
+
import { CLIError } from './cli';
|
|
3
3
|
export declare class ModuleLoadError extends CLIError implements OclifError {
|
|
4
|
-
oclif: {
|
|
5
|
-
exit: number;
|
|
6
|
-
};
|
|
7
4
|
code: string;
|
|
8
5
|
constructor(message: string);
|
|
9
6
|
}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ModuleLoadError = void 0;
|
|
4
4
|
const cli_1 = require("./cli");
|
|
5
5
|
class ModuleLoadError extends cli_1.CLIError {
|
|
6
|
+
code = 'MODULE_NOT_FOUND';
|
|
6
7
|
constructor(message) {
|
|
7
8
|
super(`[MODULE_NOT_FOUND] ${message}`, { exit: 1 });
|
|
8
|
-
this.code = 'MODULE_NOT_FOUND';
|
|
9
9
|
this.name = 'ModuleLoadError';
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PrettyPrintableError } from '../../interfaces/errors';
|
|
2
2
|
type CLIErrorDisplayOptions = {
|
|
3
|
-
name?: string;
|
|
4
3
|
bang?: string;
|
|
4
|
+
name?: string;
|
|
5
5
|
};
|
|
6
6
|
export declare function applyPrettyPrintOptions(error: Error, options: PrettyPrintableError): PrettyPrintableError;
|
|
7
7
|
export default function prettyPrint(error: Error & PrettyPrintableError & CLIErrorDisplayOptions): string | undefined;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyPrettyPrintOptions = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
|
|
6
|
+
const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
|
|
7
|
+
const screen_1 = require("../../screen");
|
|
7
8
|
const config_1 = require("../config");
|
|
8
9
|
function applyPrettyPrintOptions(error, options) {
|
|
9
10
|
const prettyErrorKeys = ['message', 'code', 'ref', 'suggestions'];
|
|
10
11
|
for (const key of prettyErrorKeys) {
|
|
11
12
|
const applyOptionsKey = !(key in error) && options[key];
|
|
12
13
|
if (applyOptionsKey) {
|
|
14
|
+
;
|
|
13
15
|
error[key] = options[key];
|
|
14
16
|
}
|
|
15
17
|
}
|
|
@@ -22,14 +24,14 @@ const formatSuggestions = (suggestions) => {
|
|
|
22
24
|
return undefined;
|
|
23
25
|
if (suggestions.length === 1)
|
|
24
26
|
return `${label} ${suggestions[0]}`;
|
|
25
|
-
const multiple = suggestions.map(suggestion => `* ${suggestion}`).join('\n');
|
|
26
|
-
return `${label}\n${
|
|
27
|
+
const multiple = suggestions.map((suggestion) => `* ${suggestion}`).join('\n');
|
|
28
|
+
return `${label}\n${(0, indent_string_1.default)(multiple, 2)}`;
|
|
27
29
|
};
|
|
28
30
|
function prettyPrint(error) {
|
|
29
31
|
if (config_1.config.debug) {
|
|
30
32
|
return error.stack;
|
|
31
33
|
}
|
|
32
|
-
const {
|
|
34
|
+
const { bang, code, message, name: errorSuffix, ref, suggestions } = error;
|
|
33
35
|
// errorSuffix is pulled from the 'name' property on CLIError
|
|
34
36
|
// and is like either Error or Warning
|
|
35
37
|
const formattedHeader = message ? `${errorSuffix || 'Error'}: ${message}` : undefined;
|
|
@@ -39,10 +41,10 @@ function prettyPrint(error) {
|
|
|
39
41
|
const formatted = [formattedHeader, formattedCode, formattedSuggestions, formattedReference]
|
|
40
42
|
.filter(Boolean)
|
|
41
43
|
.join('\n');
|
|
42
|
-
let output =
|
|
43
|
-
output =
|
|
44
|
-
output =
|
|
45
|
-
output =
|
|
44
|
+
let output = (0, wrap_ansi_1.default)(formatted, screen_1.errtermwidth - 6, { hard: true, trim: false });
|
|
45
|
+
output = (0, indent_string_1.default)(output, 3);
|
|
46
|
+
output = (0, indent_string_1.default)(output, 1, { includeEmptyLines: true, indent: bang || '' });
|
|
47
|
+
output = (0, indent_string_1.default)(output, 1);
|
|
46
48
|
return output;
|
|
47
49
|
}
|
|
48
50
|
exports.default = prettyPrint;
|
package/lib/errors/handle.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { OclifError, PrettyPrintableError } from '../interfaces';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* This is an odd abstraction for process.exit, but it allows us to stub it in tests.
|
|
4
|
+
*
|
|
5
|
+
* https://github.com/sinonjs/sinon/issues/562
|
|
6
|
+
*/
|
|
7
|
+
export declare const Exit: {
|
|
8
|
+
exit(code?: number): never;
|
|
9
|
+
};
|
|
10
|
+
type ErrorToHandle = Error & Partial<PrettyPrintableError> & Partial<OclifError> & {
|
|
3
11
|
skipOclifErrorHandling?: boolean;
|
|
4
|
-
}
|
|
12
|
+
};
|
|
13
|
+
export declare function handle(err: ErrorToHandle): Promise<void>;
|
|
14
|
+
export {};
|