@oclif/core 4.0.0-beta.1 → 4.0.0-beta.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/args.d.ts +4 -4
- package/lib/cache.d.ts +3 -3
- package/lib/cache.js +1 -1
- package/lib/command.d.ts +18 -18
- package/lib/command.js +11 -20
- package/lib/config/config.d.ts +12 -37
- package/lib/config/config.js +82 -118
- package/lib/config/plugin-loader.d.ts +6 -6
- package/lib/config/plugin-loader.js +4 -28
- package/lib/config/plugin.d.ts +3 -3
- package/lib/config/plugin.js +9 -11
- package/lib/config/ts-path.d.ts +1 -1
- package/lib/config/ts-path.js +6 -7
- package/lib/config/util.d.ts +1 -1
- package/lib/config/util.js +5 -21
- package/lib/errors/error.js +3 -3
- package/lib/errors/errors/cli.d.ts +5 -5
- package/lib/errors/errors/cli.js +2 -2
- package/lib/errors/errors/pretty-print.d.ts +2 -2
- package/lib/errors/errors/pretty-print.js +2 -2
- package/lib/errors/handle.js +4 -11
- package/lib/errors/index.d.ts +0 -2
- package/lib/errors/index.js +1 -5
- package/lib/errors/warn.d.ts +2 -8
- package/lib/errors/warn.js +12 -11
- package/lib/flags.d.ts +4 -4
- package/lib/flush.js +2 -2
- package/lib/help/formatter.d.ts +3 -3
- package/lib/help/index.d.ts +1 -0
- package/lib/help/index.js +19 -10
- package/lib/index.d.ts +5 -5
- package/lib/index.js +4 -2
- package/lib/interfaces/config.d.ts +9 -21
- package/lib/interfaces/errors.d.ts +5 -5
- package/lib/interfaces/flags.d.ts +2 -2
- package/lib/interfaces/index.d.ts +2 -1
- package/lib/interfaces/logger.d.ts +9 -0
- package/lib/interfaces/logger.js +2 -0
- package/lib/interfaces/parser.d.ts +6 -6
- package/lib/interfaces/pjson.d.ts +217 -150
- package/lib/interfaces/plugin.d.ts +26 -24
- package/lib/interfaces/topic.d.ts +2 -2
- package/lib/logger.d.ts +14 -0
- package/lib/logger.js +90 -0
- package/lib/main.js +5 -3
- package/lib/parser/errors.d.ts +1 -1
- package/lib/parser/parse.js +2 -1
- package/lib/performance.js +3 -2
- package/lib/settings.d.ts +5 -11
- package/lib/util/determine-priority.d.ts +21 -0
- package/lib/util/determine-priority.js +55 -0
- package/lib/util/find-root.d.ts +1 -0
- package/lib/util/find-root.js +19 -19
- package/lib/util/fs.js +12 -0
- package/lib/util/ids.d.ts +1 -1
- package/lib/util/read-pjson.d.ts +7 -0
- package/lib/util/read-pjson.js +60 -0
- package/lib/util/read-tsconfig.js +4 -9
- package/lib/ux/colorize-json.d.ts +2 -2
- package/lib/ux/index.d.ts +7 -2
- package/lib/ux/index.js +15 -3
- package/lib/ux/theme.d.ts +1 -1
- package/package.json +30 -14
- package/flush.d.ts +0 -3
- package/flush.js +0 -1
- package/handle.js +0 -1
- package/lib/errors/config.d.ts +0 -6
- package/lib/errors/config.js +0 -38
- package/lib/errors/logger.d.ts +0 -8
- package/lib/errors/logger.js +0 -48
package/lib/args.d.ts
CHANGED
|
@@ -21,14 +21,14 @@ import { Arg, ArgDefinition } from './interfaces/parser';
|
|
|
21
21
|
export declare function custom<T = string, P = Record<string, unknown>>(defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>;
|
|
22
22
|
export declare const boolean: ArgDefinition<boolean, Record<string, unknown>>;
|
|
23
23
|
export declare const integer: ArgDefinition<number, {
|
|
24
|
-
max?: number
|
|
25
|
-
min?: number
|
|
24
|
+
max?: number;
|
|
25
|
+
min?: number;
|
|
26
26
|
}>;
|
|
27
27
|
export declare const directory: ArgDefinition<string, {
|
|
28
|
-
exists?: boolean
|
|
28
|
+
exists?: boolean;
|
|
29
29
|
}>;
|
|
30
30
|
export declare const file: ArgDefinition<string, {
|
|
31
|
-
exists?: boolean
|
|
31
|
+
exists?: boolean;
|
|
32
32
|
}>;
|
|
33
33
|
/**
|
|
34
34
|
* Initializes a string as a URL. Throws an error
|
package/lib/cache.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Config } from './config/config';
|
|
2
|
-
import {
|
|
2
|
+
import { OclifConfiguration, Plugin } from './interfaces';
|
|
3
3
|
type OclifCoreInfo = {
|
|
4
4
|
name: string;
|
|
5
5
|
version: string;
|
|
@@ -7,7 +7,7 @@ type OclifCoreInfo = {
|
|
|
7
7
|
type CacheContents = {
|
|
8
8
|
rootPlugin: Plugin;
|
|
9
9
|
config: Config;
|
|
10
|
-
exitCodes:
|
|
10
|
+
exitCodes: OclifConfiguration['exitCodes'];
|
|
11
11
|
'@oclif/core': OclifCoreInfo;
|
|
12
12
|
};
|
|
13
13
|
type ValueOf<T> = T[keyof T];
|
|
@@ -21,7 +21,7 @@ export default class Cache extends Map<keyof CacheContents, ValueOf<CacheContent
|
|
|
21
21
|
get(key: 'config'): Config | undefined;
|
|
22
22
|
get(key: '@oclif/core'): OclifCoreInfo;
|
|
23
23
|
get(key: 'rootPlugin'): Plugin | undefined;
|
|
24
|
-
get(key: 'exitCodes'):
|
|
24
|
+
get(key: 'exitCodes'): OclifConfiguration['exitCodes'] | undefined;
|
|
25
25
|
private getOclifCoreMeta;
|
|
26
26
|
}
|
|
27
27
|
export {};
|
package/lib/cache.js
CHANGED
|
@@ -28,7 +28,7 @@ class Cache extends Map {
|
|
|
28
28
|
try {
|
|
29
29
|
return {
|
|
30
30
|
name: '@oclif/core',
|
|
31
|
-
version: JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8')),
|
|
31
|
+
version: JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8')).version,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
catch {
|
package/lib/command.d.ts
CHANGED
|
@@ -109,7 +109,7 @@ export declare abstract class Command {
|
|
|
109
109
|
log(message?: string, ...args: any[]): void;
|
|
110
110
|
protected logJson(json: unknown): void;
|
|
111
111
|
logToStderr(message?: string, ...args: any[]): void;
|
|
112
|
-
protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F,
|
|
112
|
+
protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, A>>;
|
|
113
113
|
protected toErrorJson(err: unknown): any;
|
|
114
114
|
protected toSuccessJson(result: unknown): any;
|
|
115
115
|
warn(input: Error | string): Error | string;
|
|
@@ -143,15 +143,15 @@ export declare namespace Command {
|
|
|
143
143
|
*/
|
|
144
144
|
type Cached = {
|
|
145
145
|
[key: string]: unknown;
|
|
146
|
-
aliasPermutations?: string[];
|
|
146
|
+
aliasPermutations?: string[] | undefined;
|
|
147
147
|
aliases: string[];
|
|
148
148
|
args: {
|
|
149
149
|
[name: string]: Arg.Cached;
|
|
150
150
|
};
|
|
151
|
-
deprecateAliases?: boolean;
|
|
152
|
-
deprecationOptions?: Deprecation;
|
|
153
|
-
description?: string;
|
|
154
|
-
examples?: Example[];
|
|
151
|
+
deprecateAliases?: boolean | undefined;
|
|
152
|
+
deprecationOptions?: Deprecation | undefined;
|
|
153
|
+
description?: string | undefined;
|
|
154
|
+
examples?: Example[] | undefined;
|
|
155
155
|
flags: {
|
|
156
156
|
[name: string]: Flag.Cached;
|
|
157
157
|
};
|
|
@@ -159,22 +159,22 @@ export declare namespace Command {
|
|
|
159
159
|
hidden: boolean;
|
|
160
160
|
hiddenAliases: string[];
|
|
161
161
|
id: string;
|
|
162
|
-
isESM?: boolean;
|
|
163
|
-
permutations?: string[];
|
|
164
|
-
pluginAlias?: string;
|
|
165
|
-
pluginName?: string;
|
|
166
|
-
pluginType?: string;
|
|
167
|
-
relativePath?: string[];
|
|
168
|
-
state?: 'beta' | 'deprecated' | string;
|
|
169
|
-
strict?: boolean;
|
|
170
|
-
summary?: string;
|
|
171
|
-
type?: string;
|
|
172
|
-
usage?: string | string[];
|
|
162
|
+
isESM?: boolean | undefined;
|
|
163
|
+
permutations?: string[] | undefined;
|
|
164
|
+
pluginAlias?: string | undefined;
|
|
165
|
+
pluginName?: string | undefined;
|
|
166
|
+
pluginType?: string | undefined;
|
|
167
|
+
relativePath?: string[] | undefined;
|
|
168
|
+
state?: 'beta' | 'deprecated' | string | undefined;
|
|
169
|
+
strict?: boolean | undefined;
|
|
170
|
+
summary?: string | undefined;
|
|
171
|
+
type?: string | undefined;
|
|
172
|
+
usage?: string | string[] | undefined;
|
|
173
173
|
};
|
|
174
174
|
type Flag = IFlag<any>;
|
|
175
175
|
namespace Flag {
|
|
176
176
|
type Cached = Omit<Flag, 'input' | 'parse'> & (BooleanFlagProps | OptionFlagProps) & {
|
|
177
|
-
hasDynamicHelp?: boolean;
|
|
177
|
+
hasDynamicHelp?: boolean | undefined;
|
|
178
178
|
};
|
|
179
179
|
type Any = Cached | Flag;
|
|
180
180
|
}
|
package/lib/command.js
CHANGED
|
@@ -34,11 +34,12 @@ const cache_1 = __importDefault(require("./cache"));
|
|
|
34
34
|
const config_1 = require("./config");
|
|
35
35
|
const Errors = __importStar(require("./errors"));
|
|
36
36
|
const util_1 = require("./help/util");
|
|
37
|
+
const logger_1 = require("./logger");
|
|
37
38
|
const Parser = __importStar(require("./parser"));
|
|
38
39
|
const aggregate_flags_1 = require("./util/aggregate-flags");
|
|
39
40
|
const ids_1 = require("./util/ids");
|
|
40
41
|
const util_2 = require("./util/util");
|
|
41
|
-
const ux_1 =
|
|
42
|
+
const ux_1 = require("./ux");
|
|
42
43
|
const pjson = cache_1.default.getInstance().get('@oclif/core');
|
|
43
44
|
/**
|
|
44
45
|
* swallows stdout epipe errors
|
|
@@ -123,7 +124,7 @@ class Command {
|
|
|
123
124
|
this.config = config;
|
|
124
125
|
this.id = this.ctor.id;
|
|
125
126
|
try {
|
|
126
|
-
this.debug =
|
|
127
|
+
this.debug = (0, logger_1.makeDebug)(this.id ? `${this.config.bin}:${this.id}` : this.config.bin);
|
|
127
128
|
}
|
|
128
129
|
catch {
|
|
129
130
|
this.debug = () => {
|
|
@@ -147,6 +148,9 @@ class Command {
|
|
|
147
148
|
opts = (0, node_url_1.fileURLToPath)(opts);
|
|
148
149
|
}
|
|
149
150
|
const config = await config_1.Config.load(opts || require.main?.filename || __dirname);
|
|
151
|
+
const cache = cache_1.default.getInstance();
|
|
152
|
+
if (!cache.has('config'))
|
|
153
|
+
cache.set('config', config);
|
|
150
154
|
const cmd = new this(argv, config);
|
|
151
155
|
if (!cmd.id) {
|
|
152
156
|
const id = cmd.constructor.name.toLowerCase();
|
|
@@ -167,7 +171,7 @@ class Command {
|
|
|
167
171
|
if (!err.message)
|
|
168
172
|
throw err;
|
|
169
173
|
try {
|
|
170
|
-
ux_1.
|
|
174
|
+
ux_1.ux.action.stop(ansis_1.default.bold.red('!'));
|
|
171
175
|
}
|
|
172
176
|
catch { }
|
|
173
177
|
throw err;
|
|
@@ -179,22 +183,9 @@ class Command {
|
|
|
179
183
|
exit(code = 0) {
|
|
180
184
|
Errors.exit(code);
|
|
181
185
|
}
|
|
182
|
-
async finally(_) {
|
|
183
|
-
try {
|
|
184
|
-
const { config } = Errors;
|
|
185
|
-
if (config.errorLogger)
|
|
186
|
-
await config.errorLogger.flush();
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
console.error(error);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
186
|
+
async finally(_) { }
|
|
192
187
|
async init() {
|
|
193
188
|
this.debug('init version: %s argv: %o', this.ctor._base, this.argv);
|
|
194
|
-
if (this.config.debug)
|
|
195
|
-
Errors.config.debug = true;
|
|
196
|
-
if (this.config.errlog)
|
|
197
|
-
Errors.config.errlog = this.config.errlog;
|
|
198
189
|
const g = global;
|
|
199
190
|
g['http-call'] = g['http-call'] || {};
|
|
200
191
|
g['http-call'].userAgent = this.config.userAgent;
|
|
@@ -223,16 +214,16 @@ class Command {
|
|
|
223
214
|
log(message = '', ...args) {
|
|
224
215
|
if (!this.jsonEnabled()) {
|
|
225
216
|
message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
|
|
226
|
-
ux_1.
|
|
217
|
+
ux_1.ux.stdout(message, ...args);
|
|
227
218
|
}
|
|
228
219
|
}
|
|
229
220
|
logJson(json) {
|
|
230
|
-
ux_1.
|
|
221
|
+
ux_1.ux.stdout(ux_1.ux.colorizeJson(json, { pretty: true, theme: this.config.theme?.json }));
|
|
231
222
|
}
|
|
232
223
|
logToStderr(message = '', ...args) {
|
|
233
224
|
if (!this.jsonEnabled()) {
|
|
234
225
|
message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
|
|
235
|
-
ux_1.
|
|
226
|
+
ux_1.ux.stderr(message, ...args);
|
|
236
227
|
}
|
|
237
228
|
}
|
|
238
229
|
async parse(options, argv = this.argv) {
|
package/lib/config/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command } from '../command';
|
|
2
|
-
import { Hook, Hooks, PJSON, Topic } from '../interfaces';
|
|
2
|
+
import { Hook, Hooks, OclifConfiguration, PJSON, S3Templates, Topic, UserPJSON } from '../interfaces';
|
|
3
3
|
import { ArchTypes, Config as IConfig, LoadOptions, PlatformTypes, VersionDetails } from '../interfaces/config';
|
|
4
4
|
import { Plugin as IPlugin, Options } from '../interfaces/plugin';
|
|
5
5
|
import { Theme } from '../interfaces/theme';
|
|
@@ -7,31 +7,29 @@ export declare class Config implements IConfig {
|
|
|
7
7
|
options: Options;
|
|
8
8
|
arch: ArchTypes;
|
|
9
9
|
bin: string;
|
|
10
|
-
binAliases?: string[];
|
|
11
|
-
binPath?: string;
|
|
10
|
+
binAliases?: string[] | undefined;
|
|
11
|
+
binPath?: string | undefined;
|
|
12
12
|
cacheDir: string;
|
|
13
13
|
channel: string;
|
|
14
14
|
configDir: string;
|
|
15
15
|
dataDir: string;
|
|
16
|
-
debug: number;
|
|
17
16
|
dirname: string;
|
|
18
|
-
errlog: string;
|
|
19
17
|
flexibleTaxonomy: boolean;
|
|
20
18
|
home: string;
|
|
21
19
|
isSingleCommandCLI: boolean;
|
|
22
20
|
name: string;
|
|
23
|
-
npmRegistry?: string;
|
|
24
|
-
nsisCustomization?: string;
|
|
25
|
-
pjson: PJSON
|
|
21
|
+
npmRegistry?: string | undefined;
|
|
22
|
+
nsisCustomization?: string | undefined;
|
|
23
|
+
pjson: PJSON;
|
|
26
24
|
platform: PlatformTypes;
|
|
27
25
|
plugins: Map<string, IPlugin>;
|
|
28
26
|
root: string;
|
|
29
27
|
shell: string;
|
|
30
|
-
theme?: Theme;
|
|
28
|
+
theme?: Theme | undefined;
|
|
31
29
|
topicSeparator: ' ' | ':';
|
|
32
|
-
updateConfig: NonNullable<
|
|
30
|
+
updateConfig: NonNullable<OclifConfiguration['update']>;
|
|
33
31
|
userAgent: string;
|
|
34
|
-
userPJSON?:
|
|
32
|
+
userPJSON?: UserPJSON | undefined;
|
|
35
33
|
valid: boolean;
|
|
36
34
|
version: string;
|
|
37
35
|
protected warned: boolean;
|
|
@@ -98,7 +96,7 @@ export declare class Config implements IConfig {
|
|
|
98
96
|
protected macosCacheDir(): string | undefined;
|
|
99
97
|
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable | null): Promise<T>;
|
|
100
98
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number, captureErrors?: boolean): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
101
|
-
s3Key(type: keyof
|
|
99
|
+
s3Key(type: keyof S3Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
|
|
102
100
|
s3Url(key: string): string;
|
|
103
101
|
scopedEnvVar(k: string): string | undefined;
|
|
104
102
|
/**
|
|
@@ -114,36 +112,11 @@ export declare class Config implements IConfig {
|
|
|
114
112
|
*/
|
|
115
113
|
scopedEnvVarKeys(k: string): string[];
|
|
116
114
|
scopedEnvVarTrue(k: string): boolean;
|
|
117
|
-
protected warn(err: {
|
|
118
|
-
detail: string;
|
|
119
|
-
name: string;
|
|
120
|
-
} | Error | string, scope?: string): void;
|
|
121
115
|
protected windowsHome(): string | undefined;
|
|
122
116
|
protected windowsHomedriveHome(): string | undefined;
|
|
123
117
|
protected windowsUserprofileHome(): string | undefined;
|
|
124
|
-
protected _debug(): number;
|
|
125
118
|
protected _shell(): string;
|
|
126
119
|
private buildS3Config;
|
|
127
|
-
/**
|
|
128
|
-
* This method is responsible for locating the correct plugin to use for a named command id
|
|
129
|
-
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
|
130
|
-
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
|
131
|
-
* create the same command or command alias.
|
|
132
|
-
*
|
|
133
|
-
* In the case of more than one found command, the function will select the command based on the order in which
|
|
134
|
-
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
|
135
|
-
* is selected as the command to run.
|
|
136
|
-
*
|
|
137
|
-
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
|
138
|
-
* is present, this function defers to the core plugin.
|
|
139
|
-
*
|
|
140
|
-
* If there is not a core plugin command present, this function will return the first
|
|
141
|
-
* plugin as discovered (will not change the order)
|
|
142
|
-
*
|
|
143
|
-
* @param commands commands to determine the priority of
|
|
144
|
-
* @returns command instance {Command.Loadable} or undefined
|
|
145
|
-
*/
|
|
146
|
-
private determinePriority;
|
|
147
120
|
private getCmdLookupId;
|
|
148
121
|
private getTopicLookupId;
|
|
149
122
|
/**
|
|
@@ -159,4 +132,6 @@ export declare class Config implements IConfig {
|
|
|
159
132
|
private isJitPluginCommand;
|
|
160
133
|
private loadCommands;
|
|
161
134
|
private loadTopics;
|
|
135
|
+
private maybeAdjustDebugSetting;
|
|
136
|
+
private warn;
|
|
162
137
|
}
|
package/lib/config/config.js
CHANGED
|
@@ -35,22 +35,32 @@ const node_url_1 = require("node:url");
|
|
|
35
35
|
const cache_1 = __importDefault(require("../cache"));
|
|
36
36
|
const errors_1 = require("../errors");
|
|
37
37
|
const util_1 = require("../help/util");
|
|
38
|
+
const logger_1 = require("../logger");
|
|
38
39
|
const module_loader_1 = require("../module-loader");
|
|
39
40
|
const performance_1 = require("../performance");
|
|
40
41
|
const settings_1 = require("../settings");
|
|
42
|
+
const determine_priority_1 = require("../util/determine-priority");
|
|
41
43
|
const fs_1 = require("../util/fs");
|
|
42
44
|
const os_1 = require("../util/os");
|
|
43
45
|
const util_2 = require("../util/util");
|
|
44
|
-
const ux_1 =
|
|
46
|
+
const ux_1 = require("../ux");
|
|
45
47
|
const theme_1 = require("../ux/theme");
|
|
46
48
|
const plugin_loader_1 = __importDefault(require("./plugin-loader"));
|
|
47
49
|
const ts_path_1 = require("./ts-path");
|
|
48
50
|
const util_3 = require("./util");
|
|
49
|
-
|
|
50
|
-
const debug = (0, util_3.Debug)();
|
|
51
|
+
const debug = (0, util_3.makeDebug)();
|
|
51
52
|
const _pjson = cache_1.default.getInstance().get('@oclif/core');
|
|
52
53
|
const BASE = `${_pjson.name}@${_pjson.version}`;
|
|
53
54
|
const ROOT_ONLY_HOOKS = new Set(['preparse']);
|
|
55
|
+
function displayWarnings() {
|
|
56
|
+
if (process.listenerCount('warning') > 1)
|
|
57
|
+
return;
|
|
58
|
+
process.on('warning', (warning) => {
|
|
59
|
+
console.error(warning.stack);
|
|
60
|
+
if (warning.detail)
|
|
61
|
+
console.error(warning.detail);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
54
64
|
function channelFromVersion(version) {
|
|
55
65
|
const m = version.match(/[^-]+(?:-([^.]+))?/);
|
|
56
66
|
return (m && m[1]) || 'stable';
|
|
@@ -94,9 +104,7 @@ class Config {
|
|
|
94
104
|
channel;
|
|
95
105
|
configDir;
|
|
96
106
|
dataDir;
|
|
97
|
-
debug = 0;
|
|
98
107
|
dirname;
|
|
99
|
-
errlog;
|
|
100
108
|
flexibleTaxonomy;
|
|
101
109
|
home;
|
|
102
110
|
isSingleCommandCLI = false;
|
|
@@ -129,6 +137,7 @@ class Config {
|
|
|
129
137
|
this.options = options;
|
|
130
138
|
}
|
|
131
139
|
static async load(opts = module.filename || __dirname) {
|
|
140
|
+
(0, logger_1.setLogger)(opts);
|
|
132
141
|
// Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
|
|
133
142
|
if (typeof opts === 'string' && opts.startsWith('file://')) {
|
|
134
143
|
opts = (0, node_url_1.fileURLToPath)(opts);
|
|
@@ -263,6 +272,9 @@ class Config {
|
|
|
263
272
|
async load() {
|
|
264
273
|
settings_1.settings.performanceEnabled =
|
|
265
274
|
(settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
|
|
275
|
+
if (settings_1.settings.debug)
|
|
276
|
+
displayWarnings();
|
|
277
|
+
(0, logger_1.setLogger)(this.options);
|
|
266
278
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.load');
|
|
267
279
|
this.pluginLoader = new plugin_loader_1.default({ plugins: this.options.plugins, root: this.options.root });
|
|
268
280
|
this.rootPlugin = await this.pluginLoader.loadRoot({ pjson: this.options.pjson });
|
|
@@ -295,12 +307,10 @@ class Config {
|
|
|
295
307
|
this.dirname = this.dirname.replace('/', '\\');
|
|
296
308
|
this.userAgent = `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;
|
|
297
309
|
this.shell = this._shell();
|
|
298
|
-
this.debug = this._debug();
|
|
299
310
|
this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0, os_1.getHomeDir)() || (0, node_os_1.tmpdir)();
|
|
300
311
|
this.cacheDir = this.scopedEnvVar('CACHE_DIR') || this.macosCacheDir() || this.dir('cache');
|
|
301
312
|
this.configDir = this.scopedEnvVar('CONFIG_DIR') || this.dir('config');
|
|
302
313
|
this.dataDir = this.scopedEnvVar('DATA_DIR') || this.dir('data');
|
|
303
|
-
this.errlog = (0, node_path_1.join)(this.cacheDir, 'error.log');
|
|
304
314
|
this.binPath = this.scopedEnvVar('BINPATH');
|
|
305
315
|
this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry;
|
|
306
316
|
this.theme = await this.loadTheme();
|
|
@@ -309,10 +319,10 @@ class Config {
|
|
|
309
319
|
node: this.pjson.oclif.update?.node ?? {},
|
|
310
320
|
s3: this.buildS3Config(),
|
|
311
321
|
};
|
|
312
|
-
this.isSingleCommandCLI = Boolean(this.pjson.oclif.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
322
|
+
this.isSingleCommandCLI = Boolean(typeof this.pjson.oclif.commands !== 'string' &&
|
|
323
|
+
this.pjson.oclif.commands?.strategy === 'single' &&
|
|
324
|
+
this.pjson.oclif.commands?.target);
|
|
325
|
+
this.maybeAdjustDebugSetting();
|
|
316
326
|
await this.loadPluginsAndCommands();
|
|
317
327
|
debug('config done');
|
|
318
328
|
marker?.addDetails({
|
|
@@ -348,12 +358,17 @@ class Config {
|
|
|
348
358
|
async loadTheme() {
|
|
349
359
|
if (this.scopedEnvVarTrue('DISABLE_THEME'))
|
|
350
360
|
return;
|
|
351
|
-
const defaultThemeFile = this.pjson.oclif.theme
|
|
352
|
-
? (0, node_path_1.resolve)(this.root, this.pjson.oclif.theme)
|
|
353
|
-
: this.pjson.oclif.theme;
|
|
354
361
|
const userThemeFile = (0, node_path_1.resolve)(this.configDir, 'theme.json');
|
|
362
|
+
const getDefaultTheme = async () => {
|
|
363
|
+
if (!this.pjson.oclif.theme)
|
|
364
|
+
return;
|
|
365
|
+
if (typeof this.pjson.oclif.theme === 'string') {
|
|
366
|
+
return (0, fs_1.safeReadJson)((0, node_path_1.resolve)(this.root, this.pjson.oclif.theme));
|
|
367
|
+
}
|
|
368
|
+
return this.pjson.oclif.theme;
|
|
369
|
+
};
|
|
355
370
|
const [defaultTheme, userTheme] = await Promise.all([
|
|
356
|
-
|
|
371
|
+
await getDefaultTheme(),
|
|
357
372
|
await (0, fs_1.safeReadJson)(userThemeFile),
|
|
358
373
|
]);
|
|
359
374
|
// Merge the default theme with the user theme, giving the user theme precedence.
|
|
@@ -447,7 +462,7 @@ class Config {
|
|
|
447
462
|
};
|
|
448
463
|
const plugins = ROOT_ONLY_HOOKS.has(event) ? [this.rootPlugin] : [...this.plugins.values()];
|
|
449
464
|
const promises = plugins.map(async (p) => {
|
|
450
|
-
const debug =
|
|
465
|
+
const debug = (0, logger_1.makeDebug)([p.name, 'hooks', event].join(':'));
|
|
451
466
|
const context = {
|
|
452
467
|
config: this,
|
|
453
468
|
debug,
|
|
@@ -458,7 +473,7 @@ class Config {
|
|
|
458
473
|
(0, errors_1.exit)(code);
|
|
459
474
|
},
|
|
460
475
|
log(message, ...args) {
|
|
461
|
-
ux_1.
|
|
476
|
+
ux_1.ux.stdout(message, ...args);
|
|
462
477
|
},
|
|
463
478
|
warn(message) {
|
|
464
479
|
(0, errors_1.warn)(message);
|
|
@@ -518,7 +533,7 @@ class Config {
|
|
|
518
533
|
options = ext;
|
|
519
534
|
else if (ext)
|
|
520
535
|
options.ext = ext;
|
|
521
|
-
const template = this.updateConfig.s3
|
|
536
|
+
const template = this.updateConfig.s3?.templates?.[options.platform ? 'target' : 'vanilla'][type] ?? '';
|
|
522
537
|
return ejs.render(template, { ...this, ...options });
|
|
523
538
|
}
|
|
524
539
|
s3Url(key) {
|
|
@@ -557,40 +572,6 @@ class Config {
|
|
|
557
572
|
const v = this.scopedEnvVar(k);
|
|
558
573
|
return v === '1' || v === 'true';
|
|
559
574
|
}
|
|
560
|
-
warn(err, scope) {
|
|
561
|
-
if (this.warned)
|
|
562
|
-
return;
|
|
563
|
-
if (typeof err === 'string') {
|
|
564
|
-
process.emitWarning(err);
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
if (err instanceof Error) {
|
|
568
|
-
const modifiedErr = err;
|
|
569
|
-
modifiedErr.name = `${err.name} Plugin: ${this.name}`;
|
|
570
|
-
modifiedErr.detail = (0, util_2.compact)([
|
|
571
|
-
err.detail,
|
|
572
|
-
`module: ${this._base}`,
|
|
573
|
-
scope && `task: ${scope}`,
|
|
574
|
-
`plugin: ${this.name}`,
|
|
575
|
-
`root: ${this.root}`,
|
|
576
|
-
'See more details with DEBUG=*',
|
|
577
|
-
]).join('\n');
|
|
578
|
-
process.emitWarning(err);
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
// err is an object
|
|
582
|
-
process.emitWarning('Config.warn expected either a string or Error, but instead received an object');
|
|
583
|
-
err.name = `${err.name} Plugin: ${this.name}`;
|
|
584
|
-
err.detail = (0, util_2.compact)([
|
|
585
|
-
err.detail,
|
|
586
|
-
`module: ${this._base}`,
|
|
587
|
-
scope && `task: ${scope}`,
|
|
588
|
-
`plugin: ${this.name}`,
|
|
589
|
-
`root: ${this.root}`,
|
|
590
|
-
'See more details with DEBUG=*',
|
|
591
|
-
]).join('\n');
|
|
592
|
-
process.emitWarning(JSON.stringify(err));
|
|
593
|
-
}
|
|
594
575
|
windowsHome() {
|
|
595
576
|
return this.windowsHomedriveHome() || this.windowsUserprofileHome();
|
|
596
577
|
}
|
|
@@ -600,17 +581,6 @@ class Config {
|
|
|
600
581
|
windowsUserprofileHome() {
|
|
601
582
|
return process.env.USERPROFILE;
|
|
602
583
|
}
|
|
603
|
-
_debug() {
|
|
604
|
-
if (this.scopedEnvVarTrue('DEBUG'))
|
|
605
|
-
return 1;
|
|
606
|
-
try {
|
|
607
|
-
const { enabled } = require('debug')(this.bin);
|
|
608
|
-
if (enabled)
|
|
609
|
-
return 1;
|
|
610
|
-
}
|
|
611
|
-
catch { }
|
|
612
|
-
return 0;
|
|
613
|
-
}
|
|
614
584
|
_shell() {
|
|
615
585
|
let shellPath;
|
|
616
586
|
const { COMSPEC } = process.env;
|
|
@@ -653,58 +623,6 @@ class Config {
|
|
|
653
623
|
templates,
|
|
654
624
|
};
|
|
655
625
|
}
|
|
656
|
-
/**
|
|
657
|
-
* This method is responsible for locating the correct plugin to use for a named command id
|
|
658
|
-
* It searches the {Config} registered commands to match either the raw command id or the command alias
|
|
659
|
-
* It is possible that more than one command will be found. This is due the ability of two distinct plugins to
|
|
660
|
-
* create the same command or command alias.
|
|
661
|
-
*
|
|
662
|
-
* In the case of more than one found command, the function will select the command based on the order in which
|
|
663
|
-
* the plugin is included in the package.json `oclif.plugins` list. The command that occurs first in the list
|
|
664
|
-
* is selected as the command to run.
|
|
665
|
-
*
|
|
666
|
-
* Commands can also be present from either an install or a link. When a command is one of these and a core plugin
|
|
667
|
-
* is present, this function defers to the core plugin.
|
|
668
|
-
*
|
|
669
|
-
* If there is not a core plugin command present, this function will return the first
|
|
670
|
-
* plugin as discovered (will not change the order)
|
|
671
|
-
*
|
|
672
|
-
* @param commands commands to determine the priority of
|
|
673
|
-
* @returns command instance {Command.Loadable} or undefined
|
|
674
|
-
*/
|
|
675
|
-
determinePriority(commands) {
|
|
676
|
-
const oclifPlugins = this.pjson.oclif?.plugins ?? [];
|
|
677
|
-
const commandPlugins = commands.sort((a, b) => {
|
|
678
|
-
const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
|
|
679
|
-
const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
|
|
680
|
-
const aIndex = oclifPlugins.indexOf(pluginAliasA);
|
|
681
|
-
const bIndex = oclifPlugins.indexOf(pluginAliasB);
|
|
682
|
-
// When both plugin types are 'core' plugins sort based on index
|
|
683
|
-
if (a.pluginType === 'core' && b.pluginType === 'core') {
|
|
684
|
-
// If b appears first in the pjson.plugins sort it first
|
|
685
|
-
return aIndex - bIndex;
|
|
686
|
-
}
|
|
687
|
-
// if b is a core plugin and a is not sort b first
|
|
688
|
-
if (b.pluginType === 'core' && a.pluginType !== 'core') {
|
|
689
|
-
return 1;
|
|
690
|
-
}
|
|
691
|
-
// if a is a core plugin and b is not sort a first
|
|
692
|
-
if (a.pluginType === 'core' && b.pluginType !== 'core') {
|
|
693
|
-
return -1;
|
|
694
|
-
}
|
|
695
|
-
// if a is a jit plugin and b is not sort b first
|
|
696
|
-
if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
|
|
697
|
-
return 1;
|
|
698
|
-
}
|
|
699
|
-
// if b is a jit plugin and a is not sort a first
|
|
700
|
-
if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
|
|
701
|
-
return -1;
|
|
702
|
-
}
|
|
703
|
-
// neither plugin is core, so do not change the order
|
|
704
|
-
return 0;
|
|
705
|
-
});
|
|
706
|
-
return commandPlugins[0];
|
|
707
|
-
}
|
|
708
626
|
getCmdLookupId(id) {
|
|
709
627
|
if (this._commands.has(id))
|
|
710
628
|
return id;
|
|
@@ -732,7 +650,7 @@ class Config {
|
|
|
732
650
|
for (const plugin of plugins) {
|
|
733
651
|
this.plugins.set(plugin.name, plugin);
|
|
734
652
|
// Delete all commands from the legacy plugin so that we can re-add them.
|
|
735
|
-
// This is necessary because
|
|
653
|
+
// This is necessary because determinePriority will pick the initial
|
|
736
654
|
// command that was added, which won't have been converted by PluginLegacy yet.
|
|
737
655
|
for (const cmd of plugin.commands ?? []) {
|
|
738
656
|
this._commands.delete(cmd.id);
|
|
@@ -753,7 +671,10 @@ class Config {
|
|
|
753
671
|
for (const command of plugin.commands) {
|
|
754
672
|
// set canonical command id
|
|
755
673
|
if (this._commands.has(command.id)) {
|
|
756
|
-
const prioritizedCommand =
|
|
674
|
+
const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
|
|
675
|
+
this._commands.get(command.id),
|
|
676
|
+
command,
|
|
677
|
+
]);
|
|
757
678
|
this._commands.set(prioritizedCommand.id, prioritizedCommand);
|
|
758
679
|
}
|
|
759
680
|
else {
|
|
@@ -770,7 +691,10 @@ class Config {
|
|
|
770
691
|
}
|
|
771
692
|
const handleAlias = (alias, hidden = false) => {
|
|
772
693
|
if (this._commands.has(alias)) {
|
|
773
|
-
const prioritizedCommand =
|
|
694
|
+
const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
|
|
695
|
+
this._commands.get(alias),
|
|
696
|
+
command,
|
|
697
|
+
]);
|
|
774
698
|
this._commands.set(alias, { ...prioritizedCommand, id: alias });
|
|
775
699
|
}
|
|
776
700
|
else {
|
|
@@ -828,5 +752,45 @@ class Config {
|
|
|
828
752
|
}
|
|
829
753
|
marker?.stop();
|
|
830
754
|
}
|
|
755
|
+
maybeAdjustDebugSetting() {
|
|
756
|
+
if (this.scopedEnvVarTrue('DEBUG')) {
|
|
757
|
+
settings_1.settings.debug = true;
|
|
758
|
+
displayWarnings();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
warn(err, scope) {
|
|
762
|
+
if (this.warned)
|
|
763
|
+
return;
|
|
764
|
+
if (typeof err === 'string') {
|
|
765
|
+
process.emitWarning(err);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
if (err instanceof Error) {
|
|
769
|
+
const modifiedErr = err;
|
|
770
|
+
modifiedErr.name = `${err.name} Plugin: ${this.name}`;
|
|
771
|
+
modifiedErr.detail = (0, util_2.compact)([
|
|
772
|
+
err.detail,
|
|
773
|
+
`module: ${this._base}`,
|
|
774
|
+
scope && `task: ${scope}`,
|
|
775
|
+
`plugin: ${this.name}`,
|
|
776
|
+
`root: ${this.root}`,
|
|
777
|
+
'See more details with DEBUG=*',
|
|
778
|
+
]).join('\n');
|
|
779
|
+
process.emitWarning(err);
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
// err is an object
|
|
783
|
+
process.emitWarning('Config.warn expected either a string or Error, but instead received an object');
|
|
784
|
+
err.name = `${err.name} Plugin: ${this.name}`;
|
|
785
|
+
err.detail = (0, util_2.compact)([
|
|
786
|
+
err.detail,
|
|
787
|
+
`module: ${this._base}`,
|
|
788
|
+
scope && `task: ${scope}`,
|
|
789
|
+
`plugin: ${this.name}`,
|
|
790
|
+
`root: ${this.root}`,
|
|
791
|
+
'See more details with DEBUG=*',
|
|
792
|
+
]).join('\n');
|
|
793
|
+
process.emitWarning(JSON.stringify(err));
|
|
794
|
+
}
|
|
831
795
|
}
|
|
832
796
|
exports.Config = Config;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { PJSON } from '../interfaces';
|
|
2
2
|
import { Plugin as IPlugin } from '../interfaces/plugin';
|
|
3
3
|
type PluginLoaderOptions = {
|
|
4
|
-
plugins?: IPlugin[] | PluginsMap;
|
|
4
|
+
plugins?: IPlugin[] | PluginsMap | undefined;
|
|
5
5
|
root: string;
|
|
6
6
|
};
|
|
7
7
|
type LoadOpts = {
|
|
8
8
|
dataDir: string;
|
|
9
|
-
devPlugins?: boolean;
|
|
10
|
-
force?: boolean;
|
|
9
|
+
devPlugins?: boolean | undefined;
|
|
10
|
+
force?: boolean | undefined;
|
|
11
11
|
rootPlugin: IPlugin;
|
|
12
|
-
userPlugins?: boolean;
|
|
12
|
+
userPlugins?: boolean | undefined;
|
|
13
13
|
pluginAdditions?: {
|
|
14
14
|
core?: string[];
|
|
15
15
|
dev?: string[];
|
|
16
16
|
path?: string;
|
|
17
|
-
};
|
|
17
|
+
} | undefined;
|
|
18
18
|
};
|
|
19
19
|
type PluginsMap = Map<string, IPlugin>;
|
|
20
20
|
export default class PluginLoader {
|
|
@@ -28,7 +28,7 @@ export default class PluginLoader {
|
|
|
28
28
|
plugins: PluginsMap;
|
|
29
29
|
}>;
|
|
30
30
|
loadRoot({ pjson }: {
|
|
31
|
-
pjson?: PJSON
|
|
31
|
+
pjson?: PJSON | undefined;
|
|
32
32
|
}): Promise<IPlugin>;
|
|
33
33
|
private loadCorePlugins;
|
|
34
34
|
private loadDevPlugins;
|