@oclif/core 1.7.0 → 1.8.2
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/CHANGELOG.md +21 -0
- package/lib/config/config.d.ts +8 -8
- package/lib/config/config.js +2 -2
- package/lib/config/plugin.d.ts +1 -1
- package/lib/help/index.d.ts +1 -1
- package/lib/help/util.js +6 -7
- package/lib/interfaces/command.d.ts +8 -1
- package/lib/interfaces/config.d.ts +6 -6
- package/lib/interfaces/hooks.d.ts +1 -1
- package/lib/interfaces/plugin.d.ts +1 -1
- package/lib/module-loader.d.ts +8 -0
- package/lib/module-loader.js +38 -8
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.8.2](https://github.com/oclif/core/compare/v1.8.1...v1.8.2) (2022-05-18)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* properly load index.js ES modules (cont) ([#417](https://github.com/oclif/core/issues/417)) ([77ba8b8](https://github.com/oclif/core/commit/77ba8b891f941e371bacd0dbedb32be25d6d2599))
|
|
11
|
+
|
|
12
|
+
### [1.8.1](https://github.com/oclif/core/compare/v1.8.0...v1.8.1) (2022-05-10)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* improve algo for collating command id ([#415](https://github.com/oclif/core/issues/415)) ([1a9bfdb](https://github.com/oclif/core/commit/1a9bfdb810e13506ed8fc4138cde1912981b97e3))
|
|
18
|
+
|
|
19
|
+
## [1.8.0](https://github.com/oclif/core/compare/v1.7.0...v1.8.0) (2022-05-06)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* improve Command interface ([#416](https://github.com/oclif/core/issues/416)) ([ed625e1](https://github.com/oclif/core/commit/ed625e1554a09e578e645ddd7aa2ddb1b368c03f))
|
|
25
|
+
|
|
5
26
|
## [1.7.0](https://github.com/oclif/core/compare/v1.6.4...v1.7.0) (2022-04-11)
|
|
6
27
|
|
|
7
28
|
|
package/lib/config/config.d.ts
CHANGED
|
@@ -43,16 +43,16 @@ export declare class Config implements IConfig {
|
|
|
43
43
|
loadDevPlugins(): Promise<void>;
|
|
44
44
|
loadUserPlugins(): Promise<void>;
|
|
45
45
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
46
|
-
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.
|
|
46
|
+
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable): Promise<T>;
|
|
47
47
|
scopedEnvVar(k: string): string | undefined;
|
|
48
48
|
scopedEnvVarTrue(k: string): boolean;
|
|
49
49
|
scopedEnvVarKey(k: string): string;
|
|
50
50
|
findCommand(id: string, opts: {
|
|
51
51
|
must: true;
|
|
52
|
-
}): Command.
|
|
52
|
+
}): Command.Loadable;
|
|
53
53
|
findCommand(id: string, opts?: {
|
|
54
54
|
must: boolean;
|
|
55
|
-
}): Command.
|
|
55
|
+
}): Command.Loadable | undefined;
|
|
56
56
|
findTopic(id: string, opts: {
|
|
57
57
|
must: true;
|
|
58
58
|
}): Topic;
|
|
@@ -72,18 +72,18 @@ export declare class Config implements IConfig {
|
|
|
72
72
|
* @param argv string[] process.argv containing the flags and arguments provided by the user
|
|
73
73
|
* @returns string[]
|
|
74
74
|
*/
|
|
75
|
-
findMatches(partialCmdId: string, argv: string[]): Command.
|
|
75
|
+
findMatches(partialCmdId: string, argv: string[]): Command.Loadable[];
|
|
76
76
|
/**
|
|
77
77
|
* Returns an array of all commands. If flexible taxonomy is enabled then all permutations will be appended to the array.
|
|
78
|
-
* @returns Command.
|
|
78
|
+
* @returns Command.Loadable[]
|
|
79
79
|
*/
|
|
80
|
-
getAllCommands(): Command.
|
|
80
|
+
getAllCommands(): Command.Loadable[];
|
|
81
81
|
/**
|
|
82
82
|
* Returns an array of all command ids. If flexible taxonomy is enabled then all permutations will be appended to the array.
|
|
83
83
|
* @returns string[]
|
|
84
84
|
*/
|
|
85
85
|
getAllCommandIDs(): string[];
|
|
86
|
-
get commands(): Command.
|
|
86
|
+
get commands(): Command.Loadable[];
|
|
87
87
|
get commandIDs(): string[];
|
|
88
88
|
get topics(): Topic[];
|
|
89
89
|
s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
|
|
@@ -126,7 +126,7 @@ export declare class Config implements IConfig {
|
|
|
126
126
|
* plugin as discovered (will not change the order)
|
|
127
127
|
*
|
|
128
128
|
* @param commands commands to determine the priority of
|
|
129
|
-
* @returns command instance {Command.
|
|
129
|
+
* @returns command instance {Command.Loadable} or undefined
|
|
130
130
|
*/
|
|
131
131
|
private determinePriority;
|
|
132
132
|
}
|
package/lib/config/config.js
CHANGED
|
@@ -324,7 +324,7 @@ class Config {
|
|
|
324
324
|
}
|
|
325
325
|
/**
|
|
326
326
|
* Returns an array of all commands. If flexible taxonomy is enabled then all permutations will be appended to the array.
|
|
327
|
-
* @returns Command.
|
|
327
|
+
* @returns Command.Loadable[]
|
|
328
328
|
*/
|
|
329
329
|
getAllCommands() {
|
|
330
330
|
const commands = [...this._commands.values()];
|
|
@@ -573,7 +573,7 @@ class Config {
|
|
|
573
573
|
* plugin as discovered (will not change the order)
|
|
574
574
|
*
|
|
575
575
|
* @param commands commands to determine the priority of
|
|
576
|
-
* @returns command instance {Command.
|
|
576
|
+
* @returns command instance {Command.Loadable} or undefined
|
|
577
577
|
*/
|
|
578
578
|
determinePriority(commands) {
|
|
579
579
|
var _a, _b;
|
package/lib/config/plugin.d.ts
CHANGED
package/lib/help/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare abstract class HelpBase extends HelpFormatter {
|
|
|
20
20
|
export declare class Help extends HelpBase {
|
|
21
21
|
protected CommandHelpClass: typeof CommandHelp;
|
|
22
22
|
private get _topics();
|
|
23
|
-
protected get sortedCommands(): Interfaces.Command.
|
|
23
|
+
protected get sortedCommands(): Interfaces.Command.Loadable[];
|
|
24
24
|
protected get sortedTopics(): Interfaces.Topic[];
|
|
25
25
|
constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>);
|
|
26
26
|
showHelp(argv: string[]): Promise<void>;
|
package/lib/help/util.js
CHANGED
|
@@ -33,28 +33,27 @@ exports.template = template;
|
|
|
33
33
|
function collateSpacedCmdIDFromArgs(argv, config) {
|
|
34
34
|
if (argv.length === 1)
|
|
35
35
|
return argv;
|
|
36
|
-
const ids = (0, util_1.collectUsableIds)(config.commandIDs);
|
|
37
36
|
const findId = (argv) => {
|
|
37
|
+
const ids = (0, util_1.collectUsableIds)(config.commandIDs);
|
|
38
38
|
const final = [];
|
|
39
39
|
const idPresent = (id) => ids.includes(id);
|
|
40
40
|
const isFlag = (s) => s.startsWith('-');
|
|
41
41
|
const isArgWithValue = (s) => s.includes('=');
|
|
42
42
|
const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
|
|
43
|
-
const
|
|
43
|
+
const hasArgs = () => {
|
|
44
|
+
var _a;
|
|
44
45
|
const id = finalizeId();
|
|
45
46
|
if (!id)
|
|
46
47
|
return false;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const subCommands = config.commands.filter(c => (c.id).startsWith(id));
|
|
50
|
-
return Boolean(subCommands.find(cmd => { var _a; return cmd.strict === false || ((_a = cmd.args) === null || _a === void 0 ? void 0 : _a.length) > 0; }));
|
|
48
|
+
const cmd = config.findCommand(id);
|
|
49
|
+
return Boolean(cmd && (cmd.strict === false || ((_a = cmd.args) === null || _a === void 0 ? void 0 : _a.length) > 0));
|
|
51
50
|
};
|
|
52
51
|
for (const arg of argv) {
|
|
53
52
|
if (idPresent(finalizeId(arg)))
|
|
54
53
|
final.push(arg);
|
|
55
54
|
// If the parent topic has a command that expects positional arguments, then we cannot
|
|
56
55
|
// assume that any subsequent string could be part of the command name
|
|
57
|
-
else if (isArgWithValue(arg) || isFlag(arg) ||
|
|
56
|
+
else if (isArgWithValue(arg) || isFlag(arg) || hasArgs())
|
|
58
57
|
break;
|
|
59
58
|
else
|
|
60
59
|
final.push(arg);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Config, LoadOptions } from './config';
|
|
2
2
|
import { ArgInput, BooleanFlagProps, FlagInput, OptionFlagProps } from './parser';
|
|
3
|
+
import { Plugin as IPlugin } from './plugin';
|
|
3
4
|
export declare type Example = string | {
|
|
4
5
|
description: string;
|
|
5
6
|
command: string;
|
|
@@ -78,7 +79,7 @@ export declare namespace Command {
|
|
|
78
79
|
_base: string;
|
|
79
80
|
}
|
|
80
81
|
interface Class extends Base {
|
|
81
|
-
plugin?:
|
|
82
|
+
plugin?: IPlugin;
|
|
82
83
|
flags?: FlagInput<any>;
|
|
83
84
|
args?: ArgInput;
|
|
84
85
|
strict: boolean;
|
|
@@ -89,6 +90,12 @@ export declare namespace Command {
|
|
|
89
90
|
interface Instance {
|
|
90
91
|
_run(argv: string[]): Promise<any>;
|
|
91
92
|
}
|
|
93
|
+
interface Loadable extends Command {
|
|
94
|
+
load(): Promise<Class>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated use Command.Loadable instead.
|
|
98
|
+
*/
|
|
92
99
|
interface Plugin extends Command {
|
|
93
100
|
load(): Promise<Class>;
|
|
94
101
|
}
|
|
@@ -88,27 +88,27 @@ export interface Config {
|
|
|
88
88
|
valid: boolean;
|
|
89
89
|
flexibleTaxonomy?: boolean;
|
|
90
90
|
topicSeparator: ':' | ' ';
|
|
91
|
-
readonly commands: Command.
|
|
91
|
+
readonly commands: Command.Loadable[];
|
|
92
92
|
readonly topics: Topic[];
|
|
93
93
|
readonly commandIDs: string[];
|
|
94
94
|
runCommand<T = unknown>(id: string, argv?: string[]): Promise<T>;
|
|
95
|
-
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.
|
|
95
|
+
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable): Promise<T>;
|
|
96
96
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
97
97
|
getAllCommandIDs(): string[];
|
|
98
|
-
getAllCommands(): Command.
|
|
98
|
+
getAllCommands(): Command.Loadable[];
|
|
99
99
|
findCommand(id: string, opts: {
|
|
100
100
|
must: true;
|
|
101
|
-
}): Command.
|
|
101
|
+
}): Command.Loadable;
|
|
102
102
|
findCommand(id: string, opts?: {
|
|
103
103
|
must: boolean;
|
|
104
|
-
}): Command.
|
|
104
|
+
}): Command.Loadable | undefined;
|
|
105
105
|
findTopic(id: string, opts: {
|
|
106
106
|
must: true;
|
|
107
107
|
}): Topic;
|
|
108
108
|
findTopic(id: string, opts?: {
|
|
109
109
|
must: boolean;
|
|
110
110
|
}): Topic | undefined;
|
|
111
|
-
findMatches(id: string, argv: string[]): Command.
|
|
111
|
+
findMatches(id: string, argv: string[]): Command.Loadable[];
|
|
112
112
|
scopedEnvVar(key: string): string | undefined;
|
|
113
113
|
scopedEnvVarKey(key: string): string;
|
|
114
114
|
scopedEnvVarTrue(key: string): boolean;
|
|
@@ -60,7 +60,7 @@ export interface Plugin {
|
|
|
60
60
|
* if it appears to be an npm package but does not look like it's really a CLI plugin, this is set to false
|
|
61
61
|
*/
|
|
62
62
|
valid: boolean;
|
|
63
|
-
commands: Command.
|
|
63
|
+
commands: Command.Loadable[];
|
|
64
64
|
hooks: {
|
|
65
65
|
[k: string]: string[];
|
|
66
66
|
};
|
package/lib/module-loader.d.ts
CHANGED
|
@@ -71,4 +71,12 @@ export default class ModuleLoader {
|
|
|
71
71
|
isESM: boolean;
|
|
72
72
|
filePath: string;
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Try adding the different extensions from `s_EXTENSIONS` to find the file.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} filePath - File path to load.
|
|
78
|
+
*
|
|
79
|
+
* @returns {string | null} Modified file path including extension or null if file is not found.
|
|
80
|
+
*/
|
|
81
|
+
static findFile(filePath: string): string | null;
|
|
74
82
|
}
|
package/lib/module-loader.js
CHANGED
|
@@ -119,6 +119,7 @@ class ModuleLoader {
|
|
|
119
119
|
* @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
|
|
120
120
|
*/
|
|
121
121
|
static resolvePath(config, modulePath) {
|
|
122
|
+
var _a, _b;
|
|
122
123
|
let isESM;
|
|
123
124
|
let filePath;
|
|
124
125
|
try {
|
|
@@ -127,20 +128,49 @@ class ModuleLoader {
|
|
|
127
128
|
}
|
|
128
129
|
catch {
|
|
129
130
|
filePath = Config.tsPath(config.root, modulePath);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (fs.
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
let fileExists = false;
|
|
132
|
+
let isDirectory = false;
|
|
133
|
+
if (fs.existsSync(filePath)) {
|
|
134
|
+
fileExists = true;
|
|
135
|
+
try {
|
|
136
|
+
if ((_b = (_a = fs.lstatSync(filePath)) === null || _a === void 0 ? void 0 : _a.isDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)) {
|
|
137
|
+
fileExists = false;
|
|
138
|
+
isDirectory = true;
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
catch { }
|
|
142
|
+
}
|
|
143
|
+
if (!fileExists) {
|
|
144
|
+
// Try all supported extensions.
|
|
145
|
+
let foundPath = ModuleLoader.findFile(filePath);
|
|
146
|
+
if (!foundPath && isDirectory) {
|
|
147
|
+
// Since filePath is a directory, try looking for index.js file.
|
|
148
|
+
foundPath = ModuleLoader.findFile(path.join(filePath, 'index'));
|
|
149
|
+
}
|
|
150
|
+
if (foundPath) {
|
|
151
|
+
filePath = foundPath;
|
|
152
|
+
}
|
|
140
153
|
}
|
|
141
154
|
isESM = ModuleLoader.isPathModule(filePath);
|
|
142
155
|
}
|
|
143
156
|
return { isESM, filePath };
|
|
144
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Try adding the different extensions from `s_EXTENSIONS` to find the file.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} filePath - File path to load.
|
|
162
|
+
*
|
|
163
|
+
* @returns {string | null} Modified file path including extension or null if file is not found.
|
|
164
|
+
*/
|
|
165
|
+
static findFile(filePath) {
|
|
166
|
+
// eslint-disable-next-line camelcase
|
|
167
|
+
for (const extension of s_EXTENSIONS) {
|
|
168
|
+
const testPath = `${filePath}${extension}`;
|
|
169
|
+
if (fs.existsSync(testPath)) {
|
|
170
|
+
return testPath;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
145
175
|
}
|
|
146
176
|
exports.default = ModuleLoader;
|
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": "1.
|
|
4
|
+
"version": "1.8.2",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"chalk": "^4.1.2",
|
|
14
14
|
"clean-stack": "^3.0.1",
|
|
15
15
|
"cli-progress": "^3.10.0",
|
|
16
|
-
"debug": "^4.3.
|
|
16
|
+
"debug": "^4.3.4",
|
|
17
17
|
"ejs": "^3.1.6",
|
|
18
18
|
"fs-extra": "^9.1.0",
|
|
19
19
|
"get-package-type": "^0.1.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"natural-orderby": "^2.0.3",
|
|
27
27
|
"object-treeify": "^1.1.33",
|
|
28
28
|
"password-prompt": "^1.1.2",
|
|
29
|
-
"semver": "^7.3.
|
|
29
|
+
"semver": "^7.3.7",
|
|
30
30
|
"string-width": "^4.2.3",
|
|
31
31
|
"strip-ansi": "^6.0.1",
|
|
32
32
|
"supports-color": "^8.1.1",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@types/fs-extra": "^9.0.13",
|
|
50
50
|
"@types/indent-string": "^4.0.1",
|
|
51
51
|
"@types/js-yaml": "^3.12.7",
|
|
52
|
-
"@types/lodash": "^4.14.
|
|
52
|
+
"@types/lodash": "^4.14.182",
|
|
53
53
|
"@types/mocha": "^8.2.3",
|
|
54
54
|
"@types/nock": "^11.1.0",
|
|
55
55
|
"@types/node": "^15.14.9",
|