@oclif/core 5.1.8 → 5.1.10
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/config/config.js +5 -1
- package/lib/config/plugin-loader.d.ts +1 -0
- package/lib/config/plugin-loader.js +7 -1
- package/lib/execute.d.ts +13 -4
- package/lib/execute.js +19 -42
- package/lib/help/command.js +3 -1
- package/lib/parser/parse.js +3 -1
- package/package.json +1 -1
package/lib/config/config.js
CHANGED
|
@@ -242,7 +242,11 @@ class Config {
|
|
|
242
242
|
displayWarnings();
|
|
243
243
|
(0, logger_1.setLogger)(this.options);
|
|
244
244
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.load');
|
|
245
|
-
this.pluginLoader = new plugin_loader_1.default({
|
|
245
|
+
this.pluginLoader = new plugin_loader_1.default({
|
|
246
|
+
ignoreManifest: this.options.ignoreManifest,
|
|
247
|
+
plugins: this.options.plugins,
|
|
248
|
+
root: this.options.root,
|
|
249
|
+
});
|
|
246
250
|
this.rootPlugin = await this.pluginLoader.loadRoot({ pjson: this.options.pjson });
|
|
247
251
|
// Cache the root plugin so that we can reference it later when determining if
|
|
248
252
|
// we should skip ts-node registration for an ESM plugin.
|
|
@@ -40,7 +40,12 @@ class PluginLoader {
|
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
|
|
43
|
-
rootPlugin = new plugin_1.Plugin({
|
|
43
|
+
rootPlugin = new plugin_1.Plugin({
|
|
44
|
+
ignoreManifest: this.options.ignoreManifest,
|
|
45
|
+
isRoot: true,
|
|
46
|
+
pjson,
|
|
47
|
+
root: this.options.root,
|
|
48
|
+
});
|
|
44
49
|
await rootPlugin.load();
|
|
45
50
|
marker?.addDetails({
|
|
46
51
|
commandCount: rootPlugin.commands.length,
|
|
@@ -118,6 +123,7 @@ class PluginLoader {
|
|
|
118
123
|
try {
|
|
119
124
|
const name = typeof plugin === 'string' ? plugin : plugin.name;
|
|
120
125
|
const opts = {
|
|
126
|
+
ignoreManifest: this.options.ignoreManifest,
|
|
121
127
|
name,
|
|
122
128
|
root,
|
|
123
129
|
type,
|
package/lib/execute.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LoadOptions, Options } from './interfaces';
|
|
2
|
+
type ExecuteOptions = Omit<Options, 'root'> & {
|
|
3
|
+
root?: string;
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* Load and run oclif CLI
|
|
4
7
|
*
|
|
@@ -36,9 +39,15 @@ import { type LoadOptions } from './interfaces';
|
|
|
36
39
|
* })()
|
|
37
40
|
* ```
|
|
38
41
|
*/
|
|
39
|
-
|
|
42
|
+
type ExecuteArguments = {
|
|
40
43
|
args?: string[];
|
|
41
44
|
development?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare function execute(options: (ExecuteArguments & {
|
|
47
|
+
dir: string;
|
|
48
|
+
loadOptions?: LoadOptions | ExecuteOptions;
|
|
49
|
+
}) | (ExecuteArguments & {
|
|
42
50
|
dir?: string;
|
|
43
|
-
loadOptions
|
|
44
|
-
}): Promise<unknown>;
|
|
51
|
+
loadOptions: Exclude<LoadOptions, undefined>;
|
|
52
|
+
})): Promise<unknown>;
|
|
53
|
+
export {};
|
package/lib/execute.js
CHANGED
|
@@ -1,48 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.execute = execute;
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
4
5
|
const errors_1 = require("./errors");
|
|
5
6
|
const handle_1 = require("./errors/handle");
|
|
6
7
|
const flush_1 = require("./flush");
|
|
7
8
|
const main_1 = require("./main");
|
|
8
9
|
const settings_1 = require("./settings");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @example For ESM run.js
|
|
21
|
-
* ```
|
|
22
|
-
* #!/usr/bin/env node
|
|
23
|
-
* import { execute } from '@oclif/core'
|
|
24
|
-
*
|
|
25
|
-
* await execute({dir: import.meta.url})
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @example For CJS dev.js
|
|
29
|
-
* ```
|
|
30
|
-
* #!/usr/bin/env ts-node
|
|
31
|
-
* void (async () => {
|
|
32
|
-
* const oclif = await import('@oclif/core')
|
|
33
|
-
* await oclif.execute({development: true, dir: __dirname})
|
|
34
|
-
* })()
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example For CJS run.js
|
|
38
|
-
* ```
|
|
39
|
-
* #!/usr/bin/env node
|
|
40
|
-
* void (async () => {
|
|
41
|
-
* const oclif = await import('@oclif/core')
|
|
42
|
-
* await oclif.execute({dir: __dirname})
|
|
43
|
-
* })()
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
10
|
+
function isOptions(loadOptions) {
|
|
11
|
+
return typeof loadOptions === 'object' && loadOptions !== null && !('runCommand' in loadOptions);
|
|
12
|
+
}
|
|
13
|
+
function normalizeLoadOptions(dir, loadOptions) {
|
|
14
|
+
if (!loadOptions || !isOptions(loadOptions))
|
|
15
|
+
return loadOptions ?? dir;
|
|
16
|
+
const root = loadOptions.root ?? (dir?.startsWith('file://') ? (0, node_url_1.fileURLToPath)(dir) : dir);
|
|
17
|
+
if (!root)
|
|
18
|
+
throw new errors_1.CLIError('dir or loadOptions.root is required.');
|
|
19
|
+
return { ...loadOptions, root };
|
|
20
|
+
}
|
|
46
21
|
async function execute(options) {
|
|
47
22
|
if (!options.dir && !options.loadOptions) {
|
|
48
23
|
throw new errors_1.CLIError('dir or loadOptions is required.');
|
|
@@ -52,10 +27,12 @@ async function execute(options) {
|
|
|
52
27
|
process.env.NODE_ENV = 'development';
|
|
53
28
|
settings_1.settings.debug = true;
|
|
54
29
|
}
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
(0, flush_1.flush)();
|
|
30
|
+
try {
|
|
31
|
+
const result = await (0, main_1.run)(options.args ?? process.argv.slice(2), normalizeLoadOptions(options.dir, options.loadOptions));
|
|
32
|
+
await (0, flush_1.flush)();
|
|
58
33
|
return result;
|
|
59
|
-
}
|
|
60
|
-
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return (0, handle_1.handle)(error instanceof Error ? error : new Error(String(error)));
|
|
37
|
+
}
|
|
61
38
|
}
|
package/lib/help/command.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CommandHelp = void 0;
|
|
7
7
|
const ansis_1 = __importDefault(require("ansis"));
|
|
8
|
+
const string_width_1 = __importDefault(require("string-width"));
|
|
8
9
|
const ensure_arg_object_1 = require("../util/ensure-arg-object");
|
|
9
10
|
const ids_1 = require("../util/ids");
|
|
10
11
|
const util_1 = require("../util/util");
|
|
@@ -208,7 +209,8 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
208
209
|
if (!flag.char)
|
|
209
210
|
flagHelp = flagHelp.replace(' '.repeat(4), '');
|
|
210
211
|
flagHelp +=
|
|
211
|
-
|
|
212
|
+
// maxWidth is a terminal width, so compare against display width instead of code unit count
|
|
213
|
+
(0, string_width_1.default)(flagHelp) + (0, string_width_1.default)(summary) + 2 < this.opts.maxWidth
|
|
212
214
|
? ' ' + summary
|
|
213
215
|
: '\n\n' + this.indent(this.wrap(summary, this.indentSpacing * 2));
|
|
214
216
|
return `${flagHelp}\n\n${this.indent(this.wrap(flag.description || '', this.indentSpacing * 2))}`;
|
package/lib/parser/parse.js
CHANGED
|
@@ -42,7 +42,9 @@ const readStdin = async () => {
|
|
|
42
42
|
const lines = [];
|
|
43
43
|
const ac = new AbortController();
|
|
44
44
|
const { signal } = ac;
|
|
45
|
-
const timeout = setTimeout(() => {
|
|
45
|
+
const timeout = setTimeout(() => {
|
|
46
|
+
ac.abort();
|
|
47
|
+
}, Number(process.env.OCLIF_STDIN_TIMEOUT_MS) || 10);
|
|
46
48
|
const rl = (0, node_readline_1.createInterface)({
|
|
47
49
|
input: stdin,
|
|
48
50
|
output: stdout,
|