@oclif/core 3.26.6 → 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 +12 -21
- package/lib/config/config.d.ts +14 -40
- package/lib/config/config.js +120 -153
- 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 +7 -11
- package/lib/config/ts-path.d.ts +1 -1
- package/lib/config/ts-path.js +1 -2
- package/lib/config/util.d.ts +1 -1
- package/lib/config/util.js +5 -21
- package/lib/errors/error.js +5 -8
- package/lib/errors/errors/cli.d.ts +5 -5
- package/lib/errors/errors/cli.js +5 -5
- package/lib/errors/errors/pretty-print.d.ts +2 -2
- package/lib/errors/errors/pretty-print.js +2 -2
- package/lib/errors/exit.d.ts +1 -0
- package/lib/errors/exit.js +8 -0
- package/lib/errors/handle.js +4 -11
- package/lib/errors/index.d.ts +1 -3
- package/lib/errors/index.js +5 -12
- package/lib/errors/warn.d.ts +5 -0
- package/lib/errors/warn.js +10 -5
- package/lib/execute.js +1 -1
- package/lib/flags.d.ts +4 -4
- package/lib/{cli-ux/flush.js → flush.js} +2 -2
- package/lib/help/command.js +6 -5
- package/lib/help/formatter.d.ts +3 -3
- package/lib/help/formatter.js +8 -9
- package/lib/help/index.d.ts +1 -0
- package/lib/help/index.js +23 -17
- package/lib/help/root.js +3 -3
- package/lib/index.d.ts +6 -7
- package/lib/index.js +8 -12
- package/lib/interfaces/config.d.ts +9 -20
- 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/parser.d.ts +6 -6
- package/lib/interfaces/pjson.d.ts +217 -151
- package/lib/interfaces/plugin.d.ts +26 -24
- package/lib/interfaces/theme.d.ts +30 -19
- package/lib/interfaces/theme.js +2 -19
- 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/errors.js +5 -5
- package/lib/parser/help.js +2 -2
- 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 +3 -8
- package/lib/{cli-ux → ux}/action/base.d.ts +5 -7
- package/lib/{cli-ux → ux}/action/base.js +0 -3
- package/lib/{cli-ux → ux}/action/spinner.d.ts +5 -4
- package/lib/{cli-ux → ux}/action/spinner.js +16 -39
- package/lib/ux/action/types.d.ts +5 -0
- package/lib/ux/action/types.js +2 -0
- package/lib/ux/colorize-json.d.ts +28 -0
- package/lib/ux/colorize-json.js +67 -0
- package/lib/ux/index.d.ts +69 -0
- package/lib/ux/index.js +88 -0
- package/lib/{cli-ux → ux}/list.d.ts +1 -1
- package/lib/{cli-ux → ux}/list.js +1 -2
- package/lib/ux/theme.d.ts +9 -0
- package/lib/ux/theme.js +43 -0
- package/lib/ux/write.d.ts +2 -0
- package/lib/ux/write.js +22 -0
- package/package.json +37 -42
- package/flush.d.ts +0 -3
- package/flush.js +0 -1
- package/handle.js +0 -1
- package/lib/cli-ux/action/spinners.d.ts +0 -251
- package/lib/cli-ux/action/spinners.js +0 -374
- package/lib/cli-ux/action/types.d.ts +0 -5
- package/lib/cli-ux/config.d.ts +0 -25
- package/lib/cli-ux/config.js +0 -52
- package/lib/cli-ux/exit.d.ts +0 -8
- package/lib/cli-ux/exit.js +0 -16
- package/lib/cli-ux/index.d.ts +0 -133
- package/lib/cli-ux/index.js +0 -183
- package/lib/cli-ux/prompt.d.ts +0 -32
- package/lib/cli-ux/prompt.js +0 -185
- package/lib/cli-ux/stream.d.ts +0 -23
- package/lib/cli-ux/stream.js +0 -43
- package/lib/cli-ux/styled/index.d.ts +0 -4
- package/lib/cli-ux/styled/index.js +0 -36
- package/lib/cli-ux/styled/object.d.ts +0 -1
- package/lib/cli-ux/styled/object.js +0 -39
- package/lib/cli-ux/styled/progress.d.ts +0 -2
- package/lib/cli-ux/styled/progress.js +0 -8
- package/lib/cli-ux/styled/table.d.ts +0 -45
- package/lib/cli-ux/styled/table.js +0 -345
- package/lib/cli-ux/styled/tree.d.ts +0 -9
- package/lib/cli-ux/styled/tree.js +0 -37
- package/lib/cli-ux/theme.d.ts +0 -11
- package/lib/cli-ux/theme.js +0 -61
- package/lib/cli-ux/wait.d.ts +0 -2
- package/lib/cli-ux/wait.js +0 -5
- package/lib/cli-ux/write.d.ts +0 -8
- package/lib/cli-ux/write.js +0 -15
- 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 -45
- /package/lib/{cli-ux/flush.d.ts → flush.d.ts} +0 -0
- /package/lib/{cli-ux/action/types.js → interfaces/logger.js} +0 -0
- /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
- /package/lib/{cli-ux → ux}/action/simple.js +0 -0
package/lib/config/config.js
CHANGED
|
@@ -33,24 +33,34 @@ const node_os_1 = require("node:os");
|
|
|
33
33
|
const node_path_1 = require("node:path");
|
|
34
34
|
const node_url_1 = require("node:url");
|
|
35
35
|
const cache_1 = __importDefault(require("../cache"));
|
|
36
|
-
const cli_ux_1 = require("../cli-ux");
|
|
37
|
-
const theme_1 = require("../cli-ux/theme");
|
|
38
36
|
const errors_1 = require("../errors");
|
|
39
37
|
const util_1 = require("../help/util");
|
|
38
|
+
const logger_1 = require("../logger");
|
|
40
39
|
const module_loader_1 = require("../module-loader");
|
|
41
40
|
const performance_1 = require("../performance");
|
|
42
41
|
const settings_1 = require("../settings");
|
|
42
|
+
const determine_priority_1 = require("../util/determine-priority");
|
|
43
43
|
const fs_1 = require("../util/fs");
|
|
44
44
|
const os_1 = require("../util/os");
|
|
45
45
|
const util_2 = require("../util/util");
|
|
46
|
+
const ux_1 = require("../ux");
|
|
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;
|
|
@@ -110,6 +118,7 @@ class Config {
|
|
|
110
118
|
shell;
|
|
111
119
|
theme;
|
|
112
120
|
topicSeparator = ':';
|
|
121
|
+
updateConfig;
|
|
113
122
|
userAgent;
|
|
114
123
|
userPJSON;
|
|
115
124
|
valid;
|
|
@@ -128,6 +137,7 @@ class Config {
|
|
|
128
137
|
this.options = options;
|
|
129
138
|
}
|
|
130
139
|
static async load(opts = module.filename || __dirname) {
|
|
140
|
+
(0, logger_1.setLogger)(opts);
|
|
131
141
|
// Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
|
|
132
142
|
if (typeof opts === 'string' && opts.startsWith('file://')) {
|
|
133
143
|
opts = (0, node_url_1.fileURLToPath)(opts);
|
|
@@ -262,6 +272,9 @@ class Config {
|
|
|
262
272
|
async load() {
|
|
263
273
|
settings_1.settings.performanceEnabled =
|
|
264
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);
|
|
265
278
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.load');
|
|
266
279
|
this.pluginLoader = new plugin_loader_1.default({ plugins: this.options.plugins, root: this.options.root });
|
|
267
280
|
this.rootPlugin = await this.pluginLoader.loadRoot({ pjson: this.options.pjson });
|
|
@@ -294,46 +307,22 @@ class Config {
|
|
|
294
307
|
this.dirname = this.dirname.replace('/', '\\');
|
|
295
308
|
this.userAgent = `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;
|
|
296
309
|
this.shell = this._shell();
|
|
297
|
-
this.debug = this._debug();
|
|
298
310
|
this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0, os_1.getHomeDir)() || (0, node_os_1.tmpdir)();
|
|
299
311
|
this.cacheDir = this.scopedEnvVar('CACHE_DIR') || this.macosCacheDir() || this.dir('cache');
|
|
300
312
|
this.configDir = this.scopedEnvVar('CONFIG_DIR') || this.dir('config');
|
|
301
313
|
this.dataDir = this.scopedEnvVar('DATA_DIR') || this.dir('data');
|
|
302
|
-
this.errlog = (0, node_path_1.join)(this.cacheDir, 'error.log');
|
|
303
314
|
this.binPath = this.scopedEnvVar('BINPATH');
|
|
304
315
|
this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
this.pjson.oclif.update.node = this.pjson.oclif.update.node || {};
|
|
311
|
-
const s3 = this.pjson.oclif.update.s3 || {};
|
|
312
|
-
this.pjson.oclif.update.s3 = s3;
|
|
313
|
-
s3.bucket = this.scopedEnvVar('S3_BUCKET') || s3.bucket;
|
|
314
|
-
if (s3.bucket && !s3.host)
|
|
315
|
-
s3.host = `https://${s3.bucket}.s3.amazonaws.com`;
|
|
316
|
-
s3.templates = {
|
|
317
|
-
...s3.templates,
|
|
318
|
-
target: {
|
|
319
|
-
baseDir: '<%- bin %>',
|
|
320
|
-
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>",
|
|
321
|
-
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
322
|
-
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
323
|
-
...(s3.templates && s3.templates.target),
|
|
324
|
-
},
|
|
325
|
-
vanilla: {
|
|
326
|
-
baseDir: '<%- bin %>',
|
|
327
|
-
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %>version",
|
|
328
|
-
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %><%- ext %>",
|
|
329
|
-
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %><%- ext %>",
|
|
330
|
-
...(s3.templates && s3.templates.vanilla),
|
|
331
|
-
},
|
|
316
|
+
this.theme = await this.loadTheme();
|
|
317
|
+
this.updateConfig = {
|
|
318
|
+
...this.pjson.oclif.update,
|
|
319
|
+
node: this.pjson.oclif.update?.node ?? {},
|
|
320
|
+
s3: this.buildS3Config(),
|
|
332
321
|
};
|
|
333
|
-
this.isSingleCommandCLI = Boolean(this.pjson.oclif.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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();
|
|
337
326
|
await this.loadPluginsAndCommands();
|
|
338
327
|
debug('config done');
|
|
339
328
|
marker?.addDetails({
|
|
@@ -366,23 +355,25 @@ class Config {
|
|
|
366
355
|
this.warn(error);
|
|
367
356
|
}
|
|
368
357
|
}
|
|
369
|
-
async
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
: this.pjson.oclif.theme;
|
|
358
|
+
async loadTheme() {
|
|
359
|
+
if (this.scopedEnvVarTrue('DISABLE_THEME'))
|
|
360
|
+
return;
|
|
373
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
|
+
};
|
|
374
370
|
const [defaultTheme, userTheme] = await Promise.all([
|
|
375
|
-
|
|
371
|
+
await getDefaultTheme(),
|
|
376
372
|
await (0, fs_1.safeReadJson)(userThemeFile),
|
|
377
373
|
]);
|
|
378
374
|
// Merge the default theme with the user theme, giving the user theme precedence.
|
|
379
375
|
const merged = { ...defaultTheme, ...userTheme };
|
|
380
|
-
return
|
|
381
|
-
// Point to the user file if it exists, otherwise use the default file.
|
|
382
|
-
// This doesn't really serve a purpose to anyone but removing it would be a breaking change.
|
|
383
|
-
file: userTheme ? userThemeFile : defaultThemeFile,
|
|
384
|
-
theme: Object.keys(merged).length > 0 ? (0, theme_1.parseTheme)(merged) : undefined,
|
|
385
|
-
};
|
|
376
|
+
return Object.keys(merged).length > 0 ? (0, theme_1.parseTheme)(merged) : undefined;
|
|
386
377
|
}
|
|
387
378
|
macosCacheDir() {
|
|
388
379
|
return (this.platform === 'darwin' && (0, node_path_1.join)(this.home, 'Library', 'Caches', this.dirname)) || undefined;
|
|
@@ -471,7 +462,7 @@ class Config {
|
|
|
471
462
|
};
|
|
472
463
|
const plugins = ROOT_ONLY_HOOKS.has(event) ? [this.rootPlugin] : [...this.plugins.values()];
|
|
473
464
|
const promises = plugins.map(async (p) => {
|
|
474
|
-
const debug =
|
|
465
|
+
const debug = (0, logger_1.makeDebug)([p.name, 'hooks', event].join(':'));
|
|
475
466
|
const context = {
|
|
476
467
|
config: this,
|
|
477
468
|
debug,
|
|
@@ -482,7 +473,7 @@ class Config {
|
|
|
482
473
|
(0, errors_1.exit)(code);
|
|
483
474
|
},
|
|
484
475
|
log(message, ...args) {
|
|
485
|
-
|
|
476
|
+
ux_1.ux.stdout(message, ...args);
|
|
486
477
|
},
|
|
487
478
|
warn(message) {
|
|
488
479
|
(0, errors_1.warn)(message);
|
|
@@ -542,11 +533,11 @@ class Config {
|
|
|
542
533
|
options = ext;
|
|
543
534
|
else if (ext)
|
|
544
535
|
options.ext = ext;
|
|
545
|
-
const template = this.
|
|
536
|
+
const template = this.updateConfig.s3?.templates?.[options.platform ? 'target' : 'vanilla'][type] ?? '';
|
|
546
537
|
return ejs.render(template, { ...this, ...options });
|
|
547
538
|
}
|
|
548
539
|
s3Url(key) {
|
|
549
|
-
const { host } = this.
|
|
540
|
+
const { host } = this.updateConfig.s3 ?? { host: undefined };
|
|
550
541
|
if (!host)
|
|
551
542
|
throw new Error('no s3 host is set');
|
|
552
543
|
const url = new node_url_1.URL(host);
|
|
@@ -581,40 +572,6 @@ class Config {
|
|
|
581
572
|
const v = this.scopedEnvVar(k);
|
|
582
573
|
return v === '1' || v === 'true';
|
|
583
574
|
}
|
|
584
|
-
warn(err, scope) {
|
|
585
|
-
if (this.warned)
|
|
586
|
-
return;
|
|
587
|
-
if (typeof err === 'string') {
|
|
588
|
-
process.emitWarning(err);
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
if (err instanceof Error) {
|
|
592
|
-
const modifiedErr = err;
|
|
593
|
-
modifiedErr.name = `${err.name} Plugin: ${this.name}`;
|
|
594
|
-
modifiedErr.detail = (0, util_2.compact)([
|
|
595
|
-
err.detail,
|
|
596
|
-
`module: ${this._base}`,
|
|
597
|
-
scope && `task: ${scope}`,
|
|
598
|
-
`plugin: ${this.name}`,
|
|
599
|
-
`root: ${this.root}`,
|
|
600
|
-
'See more details with DEBUG=*',
|
|
601
|
-
]).join('\n');
|
|
602
|
-
process.emitWarning(err);
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
// err is an object
|
|
606
|
-
process.emitWarning('Config.warn expected either a string or Error, but instead received an object');
|
|
607
|
-
err.name = `${err.name} Plugin: ${this.name}`;
|
|
608
|
-
err.detail = (0, util_2.compact)([
|
|
609
|
-
err.detail,
|
|
610
|
-
`module: ${this._base}`,
|
|
611
|
-
scope && `task: ${scope}`,
|
|
612
|
-
`plugin: ${this.name}`,
|
|
613
|
-
`root: ${this.root}`,
|
|
614
|
-
'See more details with DEBUG=*',
|
|
615
|
-
]).join('\n');
|
|
616
|
-
process.emitWarning(JSON.stringify(err));
|
|
617
|
-
}
|
|
618
575
|
windowsHome() {
|
|
619
576
|
return this.windowsHomedriveHome() || this.windowsUserprofileHome();
|
|
620
577
|
}
|
|
@@ -624,17 +581,6 @@ class Config {
|
|
|
624
581
|
windowsUserprofileHome() {
|
|
625
582
|
return process.env.USERPROFILE;
|
|
626
583
|
}
|
|
627
|
-
_debug() {
|
|
628
|
-
if (this.scopedEnvVarTrue('DEBUG'))
|
|
629
|
-
return 1;
|
|
630
|
-
try {
|
|
631
|
-
const { enabled } = require('debug')(this.bin);
|
|
632
|
-
if (enabled)
|
|
633
|
-
return 1;
|
|
634
|
-
}
|
|
635
|
-
catch { }
|
|
636
|
-
return 0;
|
|
637
|
-
}
|
|
638
584
|
_shell() {
|
|
639
585
|
let shellPath;
|
|
640
586
|
const { COMSPEC } = process.env;
|
|
@@ -650,57 +596,32 @@ class Config {
|
|
|
650
596
|
}
|
|
651
597
|
return shellPath.at(-1) ?? 'unknown';
|
|
652
598
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
// When both plugin types are 'core' plugins sort based on index
|
|
680
|
-
if (a.pluginType === 'core' && b.pluginType === 'core') {
|
|
681
|
-
// If b appears first in the pjson.plugins sort it first
|
|
682
|
-
return aIndex - bIndex;
|
|
683
|
-
}
|
|
684
|
-
// if b is a core plugin and a is not sort b first
|
|
685
|
-
if (b.pluginType === 'core' && a.pluginType !== 'core') {
|
|
686
|
-
return 1;
|
|
687
|
-
}
|
|
688
|
-
// if a is a core plugin and b is not sort a first
|
|
689
|
-
if (a.pluginType === 'core' && b.pluginType !== 'core') {
|
|
690
|
-
return -1;
|
|
691
|
-
}
|
|
692
|
-
// if a is a jit plugin and b is not sort b first
|
|
693
|
-
if (a.pluginType === 'jit' && b.pluginType !== 'jit') {
|
|
694
|
-
return 1;
|
|
695
|
-
}
|
|
696
|
-
// if b is a jit plugin and a is not sort a first
|
|
697
|
-
if (b.pluginType === 'jit' && a.pluginType !== 'jit') {
|
|
698
|
-
return -1;
|
|
699
|
-
}
|
|
700
|
-
// neither plugin is core, so do not change the order
|
|
701
|
-
return 0;
|
|
702
|
-
});
|
|
703
|
-
return commandPlugins[0];
|
|
599
|
+
buildS3Config() {
|
|
600
|
+
const s3 = this.pjson.oclif.update?.s3;
|
|
601
|
+
const bucket = this.scopedEnvVar('S3_BUCKET') ?? s3?.bucket;
|
|
602
|
+
const host = s3?.host ?? (bucket && `https://${bucket}.s3.amazonaws.com`);
|
|
603
|
+
const templates = {
|
|
604
|
+
...s3?.templates,
|
|
605
|
+
target: {
|
|
606
|
+
baseDir: '<%- bin %>',
|
|
607
|
+
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- platform %>-<%- arch %>",
|
|
608
|
+
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
609
|
+
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %>-<%- platform %>-<%- arch %><%- ext %>",
|
|
610
|
+
...(s3?.templates && s3?.templates.target),
|
|
611
|
+
},
|
|
612
|
+
vanilla: {
|
|
613
|
+
baseDir: '<%- bin %>',
|
|
614
|
+
manifest: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %>version",
|
|
615
|
+
unversioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %><%- ext %>",
|
|
616
|
+
versioned: "<%- channel === 'stable' ? '' : 'channels/' + channel + '/' %><%- bin %>-v<%- version %>/<%- bin %>-v<%- version %><%- ext %>",
|
|
617
|
+
...(s3?.templates && s3?.templates.vanilla),
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
return {
|
|
621
|
+
bucket,
|
|
622
|
+
host,
|
|
623
|
+
templates,
|
|
624
|
+
};
|
|
704
625
|
}
|
|
705
626
|
getCmdLookupId(id) {
|
|
706
627
|
if (this._commands.has(id))
|
|
@@ -729,7 +650,7 @@ class Config {
|
|
|
729
650
|
for (const plugin of plugins) {
|
|
730
651
|
this.plugins.set(plugin.name, plugin);
|
|
731
652
|
// Delete all commands from the legacy plugin so that we can re-add them.
|
|
732
|
-
// This is necessary because
|
|
653
|
+
// This is necessary because determinePriority will pick the initial
|
|
733
654
|
// command that was added, which won't have been converted by PluginLegacy yet.
|
|
734
655
|
for (const cmd of plugin.commands ?? []) {
|
|
735
656
|
this._commands.delete(cmd.id);
|
|
@@ -750,7 +671,10 @@ class Config {
|
|
|
750
671
|
for (const command of plugin.commands) {
|
|
751
672
|
// set canonical command id
|
|
752
673
|
if (this._commands.has(command.id)) {
|
|
753
|
-
const prioritizedCommand =
|
|
674
|
+
const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
|
|
675
|
+
this._commands.get(command.id),
|
|
676
|
+
command,
|
|
677
|
+
]);
|
|
754
678
|
this._commands.set(prioritizedCommand.id, prioritizedCommand);
|
|
755
679
|
}
|
|
756
680
|
else {
|
|
@@ -767,7 +691,10 @@ class Config {
|
|
|
767
691
|
}
|
|
768
692
|
const handleAlias = (alias, hidden = false) => {
|
|
769
693
|
if (this._commands.has(alias)) {
|
|
770
|
-
const prioritizedCommand =
|
|
694
|
+
const prioritizedCommand = (0, determine_priority_1.determinePriority)(this.pjson.oclif.plugins ?? [], [
|
|
695
|
+
this._commands.get(alias),
|
|
696
|
+
command,
|
|
697
|
+
]);
|
|
771
698
|
this._commands.set(alias, { ...prioritizedCommand, id: alias });
|
|
772
699
|
}
|
|
773
700
|
else {
|
|
@@ -825,5 +752,45 @@ class Config {
|
|
|
825
752
|
}
|
|
826
753
|
marker?.stop();
|
|
827
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
|
+
}
|
|
828
795
|
}
|
|
829
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;
|
|
@@ -1,37 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
const minimatch_1 = require("minimatch");
|
|
27
4
|
const node_path_1 = require("node:path");
|
|
28
5
|
const performance_1 = require("../performance");
|
|
29
6
|
const fs_1 = require("../util/fs");
|
|
30
7
|
const util_1 = require("../util/util");
|
|
31
|
-
const
|
|
8
|
+
const plugin_1 = require("./plugin");
|
|
32
9
|
const util_2 = require("./util");
|
|
33
|
-
|
|
34
|
-
const debug = (0, util_2.Debug)();
|
|
10
|
+
const debug = (0, util_2.makeDebug)();
|
|
35
11
|
function findMatchingDependencies(dependencies, patterns) {
|
|
36
12
|
return Object.keys(dependencies).filter((p) => patterns.some((w) => (0, minimatch_1.minimatch)(p, w)));
|
|
37
13
|
}
|
|
@@ -63,7 +39,7 @@ class PluginLoader {
|
|
|
63
39
|
}
|
|
64
40
|
else {
|
|
65
41
|
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
|
|
66
|
-
rootPlugin = new
|
|
42
|
+
rootPlugin = new plugin_1.Plugin({ isRoot: true, pjson, root: this.options.root });
|
|
67
43
|
await rootPlugin.load();
|
|
68
44
|
marker?.addDetails({
|
|
69
45
|
commandCount: rootPlugin.commands.length,
|
|
@@ -155,7 +131,7 @@ class PluginLoader {
|
|
|
155
131
|
if (this.plugins.has(name))
|
|
156
132
|
return;
|
|
157
133
|
const pluginMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.load#${name}`);
|
|
158
|
-
const instance = new
|
|
134
|
+
const instance = new plugin_1.Plugin(opts);
|
|
159
135
|
await instance.load();
|
|
160
136
|
pluginMarker?.addDetails({
|
|
161
137
|
commandCount: instance.commands.length,
|
package/lib/config/plugin.d.ts
CHANGED
|
@@ -19,10 +19,10 @@ export declare class Plugin implements IPlugin {
|
|
|
19
19
|
manifest: Manifest;
|
|
20
20
|
moduleType: 'commonjs' | 'module';
|
|
21
21
|
name: string;
|
|
22
|
-
parent
|
|
23
|
-
pjson: PJSON
|
|
22
|
+
parent?: Plugin | undefined;
|
|
23
|
+
pjson: PJSON;
|
|
24
24
|
root: string;
|
|
25
|
-
tag?: string;
|
|
25
|
+
tag?: string | undefined;
|
|
26
26
|
type: string;
|
|
27
27
|
valid: boolean;
|
|
28
28
|
version: string;
|
package/lib/config/plugin.js
CHANGED
|
@@ -15,6 +15,7 @@ const symbols_1 = require("../symbols");
|
|
|
15
15
|
const cache_command_1 = require("../util/cache-command");
|
|
16
16
|
const find_root_1 = require("../util/find-root");
|
|
17
17
|
const fs_1 = require("../util/fs");
|
|
18
|
+
const read_pjson_1 = require("../util/read-pjson");
|
|
18
19
|
const util_1 = require("../util/util");
|
|
19
20
|
const ts_path_1 = require("./ts-path");
|
|
20
21
|
const util_2 = require("./util");
|
|
@@ -56,12 +57,9 @@ function processCommandIds(files) {
|
|
|
56
57
|
return id === '' ? symbols_1.SINGLE_COMMAND_CLI_SYMBOL : id;
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
|
-
function determineCommandDiscoveryOptions(commandDiscovery
|
|
60
|
+
function determineCommandDiscoveryOptions(commandDiscovery) {
|
|
60
61
|
if (!commandDiscovery)
|
|
61
62
|
return;
|
|
62
|
-
if (typeof commandDiscovery === 'string' && defaultCmdId) {
|
|
63
|
-
return { strategy: 'single', target: commandDiscovery };
|
|
64
|
-
}
|
|
65
63
|
if (typeof commandDiscovery === 'string') {
|
|
66
64
|
return { globPatterns: GLOB_PATTERNS, strategy: 'pattern', target: commandDiscovery };
|
|
67
65
|
}
|
|
@@ -104,8 +102,7 @@ class Plugin {
|
|
|
104
102
|
valid = false;
|
|
105
103
|
version;
|
|
106
104
|
_base = `${_pjson.name}@${_pjson.version}`;
|
|
107
|
-
|
|
108
|
-
_debug = (0, util_2.Debug)();
|
|
105
|
+
_debug = (0, util_2.makeDebug)();
|
|
109
106
|
commandCache;
|
|
110
107
|
commandDiscoveryOpts;
|
|
111
108
|
flexibleTaxonomy;
|
|
@@ -183,15 +180,14 @@ class Plugin {
|
|
|
183
180
|
throw new errors_1.CLIError(`could not find package.json with ${(0, node_util_1.inspect)(this.options)}`);
|
|
184
181
|
this.root = root;
|
|
185
182
|
this._debug(`loading ${this.type} plugin from ${root}`);
|
|
186
|
-
this.pjson = this.options.pjson ?? (await (0,
|
|
183
|
+
this.pjson = this.options.pjson ?? (await (0, read_pjson_1.readPjson)(root));
|
|
187
184
|
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
188
185
|
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
189
186
|
this.name = this.pjson.name;
|
|
190
187
|
this.alias = this.options.name ?? this.pjson.name;
|
|
191
188
|
if (!this.name)
|
|
192
189
|
throw new errors_1.CLIError(`no name in package.json (${root})`);
|
|
193
|
-
|
|
194
|
-
this._debug = (0, util_2.Debug)(this.name);
|
|
190
|
+
this._debug = (0, util_2.makeDebug)(this.name);
|
|
195
191
|
this.version = this.pjson.version;
|
|
196
192
|
if (this.pjson.oclif) {
|
|
197
193
|
this.valid = true;
|
|
@@ -203,7 +199,7 @@ class Plugin {
|
|
|
203
199
|
k,
|
|
204
200
|
(0, util_1.castArray)(v).map((v) => determineHookOptions(v)),
|
|
205
201
|
]));
|
|
206
|
-
this.commandDiscoveryOpts = determineCommandDiscoveryOptions(this.pjson.oclif?.commands
|
|
202
|
+
this.commandDiscoveryOpts = determineCommandDiscoveryOptions(this.pjson.oclif?.commands);
|
|
207
203
|
this._debug('command discovery options', this.commandDiscoveryOpts);
|
|
208
204
|
this.manifest = await this._manifest();
|
|
209
205
|
this.commands = Object.entries(this.manifest.commands)
|
|
@@ -278,7 +274,7 @@ class Plugin {
|
|
|
278
274
|
throw this.addErrorScope(error, scope);
|
|
279
275
|
}
|
|
280
276
|
})))
|
|
281
|
-
// eslint-disable-next-line unicorn/
|
|
277
|
+
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
|
282
278
|
.filter((f) => Boolean(f))
|
|
283
279
|
.reduce((commands, [id, c]) => {
|
|
284
280
|
commands[id] = c;
|
package/lib/config/ts-path.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare const TS_CONFIGS: Record<string, TSConfig | undefined>;
|
|
|
6
6
|
* if there is a tsconfig and the original sources exist, it attempts to require ts-node
|
|
7
7
|
*/
|
|
8
8
|
export declare function tsPath(root: string, orig: string, plugin: Plugin): Promise<string>;
|
|
9
|
-
export declare function tsPath(root: string, orig: string | undefined, plugin?: Plugin): Promise<string | undefined>;
|
|
9
|
+
export declare function tsPath(root: string, orig: string | undefined, plugin?: Plugin | undefined): Promise<string | undefined>;
|
package/lib/config/ts-path.js
CHANGED
|
@@ -13,8 +13,7 @@ const fs_1 = require("../util/fs");
|
|
|
13
13
|
const read_tsconfig_1 = require("../util/read-tsconfig");
|
|
14
14
|
const util_1 = require("../util/util");
|
|
15
15
|
const util_2 = require("./util");
|
|
16
|
-
|
|
17
|
-
const debug = (0, util_2.Debug)('ts-path');
|
|
16
|
+
const debug = (0, util_2.makeDebug)('ts-path');
|
|
18
17
|
exports.TS_CONFIGS = {};
|
|
19
18
|
const REGISTERED = new Set();
|
|
20
19
|
function determineRuntime() {
|
package/lib/config/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function makeDebug(...scope: string[]): (..._: any) => void;
|
|
2
2
|
export declare function getPermutations(arr: string[]): Array<string[]>;
|
|
3
3
|
export declare function getCommandIdPermutations(commandId: string): string[];
|
|
4
4
|
/**
|
package/lib/config/util.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
return;
|
|
8
|
-
process.on('warning', (warning) => {
|
|
9
|
-
console.error(warning.stack);
|
|
10
|
-
if (warning.detail)
|
|
11
|
-
console.error(warning.detail);
|
|
12
|
-
});
|
|
3
|
+
exports.collectUsableIds = exports.getCommandIdPermutations = exports.getPermutations = exports.makeDebug = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
function makeDebug(...scope) {
|
|
6
|
+
return (formatter, ...args) => (0, logger_1.getLogger)(['config', ...scope].join(':')).debug(formatter, ...args);
|
|
13
7
|
}
|
|
14
|
-
|
|
15
|
-
if (!debug)
|
|
16
|
-
return (..._) => {
|
|
17
|
-
// noop
|
|
18
|
-
};
|
|
19
|
-
const d = debug(['config', ...scope].join(':'));
|
|
20
|
-
if (d.enabled)
|
|
21
|
-
displayWarnings();
|
|
22
|
-
return (...args) => d(...args);
|
|
23
|
-
}
|
|
24
|
-
exports.Debug = Debug;
|
|
8
|
+
exports.makeDebug = makeDebug;
|
|
25
9
|
// Adapted from https://github.com/angus-c/just/blob/master/packages/array-permutations/index.js
|
|
26
10
|
function getPermutations(arr) {
|
|
27
11
|
if (arr.length === 0)
|