@oclif/core 3.0.0-beta.9 → 3.0.0
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 +41 -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/plugin.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Plugin = void 0;
|
|
4
|
+
const globby_1 = require("globby");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
4
7
|
const errors_1 = require("../errors");
|
|
5
|
-
const globby = require("globby");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const util_1 = require("util");
|
|
8
|
-
const config_1 = require("./config");
|
|
9
|
-
const util_2 = require("./util");
|
|
10
|
-
const ts_node_1 = require("./ts-node");
|
|
11
|
-
const util_3 = require("./util");
|
|
12
|
-
const util_4 = require("../util");
|
|
13
8
|
const module_loader_1 = require("../module-loader");
|
|
14
9
|
const performance_1 = require("../performance");
|
|
15
|
-
const
|
|
10
|
+
const cache_command_1 = require("../util/cache-command");
|
|
11
|
+
const fs_1 = require("../util/fs");
|
|
12
|
+
const util_1 = require("../util/util");
|
|
13
|
+
const ts_node_1 = require("./ts-node");
|
|
14
|
+
const util_2 = require("./util");
|
|
15
|
+
const _pjson = (0, fs_1.requireJson)(__dirname, '..', '..', 'package.json');
|
|
16
16
|
function topicsToArray(input, base) {
|
|
17
17
|
if (!input)
|
|
18
18
|
return [];
|
|
19
19
|
base = base ? `${base}:` : '';
|
|
20
20
|
if (Array.isArray(input)) {
|
|
21
|
-
return [...input,
|
|
21
|
+
return [...input, input.flatMap((t) => topicsToArray(t.subtopics, `${base}${t.name}`))];
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return Object.keys(input).flatMap((k) => {
|
|
24
24
|
input[k].name = k;
|
|
25
25
|
return [{ ...input[k], name: `${base}${k}` }, ...topicsToArray(input[k].subtopics, `${base}${input[k].name}`)];
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
// essentially just "cd .."
|
|
29
29
|
function* up(from) {
|
|
30
|
-
while (
|
|
30
|
+
while ((0, node_path_1.dirname)(from) !== from) {
|
|
31
31
|
yield from;
|
|
32
|
-
from =
|
|
32
|
+
from = (0, node_path_1.dirname)(from);
|
|
33
33
|
}
|
|
34
34
|
yield from;
|
|
35
35
|
}
|
|
36
36
|
async function findSourcesRoot(root) {
|
|
37
37
|
for (const next of up(root)) {
|
|
38
|
-
const cur =
|
|
38
|
+
const cur = (0, node_path_1.join)(next, 'package.json');
|
|
39
39
|
// eslint-disable-next-line no-await-in-loop
|
|
40
|
-
if (await (0,
|
|
41
|
-
return
|
|
40
|
+
if (await (0, fs_1.exists)(cur))
|
|
41
|
+
return (0, node_path_1.dirname)(cur);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -56,23 +56,23 @@ async function findRootLegacy(name, root) {
|
|
|
56
56
|
for (const next of up(root)) {
|
|
57
57
|
let cur;
|
|
58
58
|
if (name) {
|
|
59
|
-
cur =
|
|
59
|
+
cur = (0, node_path_1.join)(next, 'node_modules', name, 'package.json');
|
|
60
60
|
// eslint-disable-next-line no-await-in-loop
|
|
61
|
-
if (await (0,
|
|
62
|
-
return
|
|
61
|
+
if (await (0, fs_1.exists)(cur))
|
|
62
|
+
return (0, node_path_1.dirname)(cur);
|
|
63
63
|
try {
|
|
64
64
|
// eslint-disable-next-line no-await-in-loop
|
|
65
|
-
const pkg = await (0,
|
|
65
|
+
const pkg = await (0, fs_1.readJson)((0, node_path_1.join)(next, 'package.json'));
|
|
66
66
|
if (pkg.name === name)
|
|
67
67
|
return next;
|
|
68
68
|
}
|
|
69
69
|
catch { }
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
cur =
|
|
72
|
+
cur = (0, node_path_1.join)(next, 'package.json');
|
|
73
73
|
// eslint-disable-next-line no-await-in-loop
|
|
74
|
-
if (await (0,
|
|
75
|
-
return
|
|
74
|
+
if (await (0, fs_1.exists)(cur))
|
|
75
|
+
return (0, node_path_1.dirname)(cur);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -80,131 +80,48 @@ async function findRoot(name, root) {
|
|
|
80
80
|
if (name) {
|
|
81
81
|
let pkgPath;
|
|
82
82
|
try {
|
|
83
|
-
pkgPath = (0,
|
|
83
|
+
pkgPath = (0, util_2.resolvePackage)(name, { paths: [root] });
|
|
84
84
|
}
|
|
85
85
|
catch { }
|
|
86
|
-
return pkgPath ? findSourcesRoot(
|
|
86
|
+
return pkgPath ? findSourcesRoot((0, node_path_1.dirname)(pkgPath)) : findRootLegacy(name, root);
|
|
87
87
|
}
|
|
88
88
|
return findSourcesRoot(root);
|
|
89
89
|
}
|
|
90
|
+
const cachedCommandCanBeUsed = (manifest, id) => Boolean(manifest?.commands[id] && 'isESM' in manifest.commands[id] && 'relativePath' in manifest.commands[id]);
|
|
91
|
+
const search = (cmd) => {
|
|
92
|
+
if (typeof cmd.run === 'function')
|
|
93
|
+
return cmd;
|
|
94
|
+
if (cmd.default && cmd.default.run)
|
|
95
|
+
return cmd.default;
|
|
96
|
+
return Object.values(cmd).find((cmd) => typeof cmd.run === 'function');
|
|
97
|
+
};
|
|
90
98
|
class Plugin {
|
|
99
|
+
options;
|
|
100
|
+
_base = `${_pjson.name}@${_pjson.version}`;
|
|
101
|
+
_commandsDir;
|
|
102
|
+
// eslint-disable-next-line new-cap
|
|
103
|
+
_debug = (0, util_2.Debug)();
|
|
104
|
+
flexibleTaxonomy;
|
|
105
|
+
alias;
|
|
106
|
+
alreadyLoaded = false;
|
|
107
|
+
children = [];
|
|
108
|
+
commands;
|
|
109
|
+
hasManifest = false;
|
|
110
|
+
hooks;
|
|
111
|
+
isRoot = false;
|
|
112
|
+
manifest;
|
|
113
|
+
moduleType;
|
|
114
|
+
name;
|
|
115
|
+
parent;
|
|
116
|
+
pjson;
|
|
117
|
+
root;
|
|
118
|
+
tag;
|
|
119
|
+
type;
|
|
120
|
+
valid = false;
|
|
121
|
+
version;
|
|
122
|
+
warned = false;
|
|
91
123
|
constructor(options) {
|
|
92
124
|
this.options = options;
|
|
93
|
-
this._base = `${_pjson.name}@${_pjson.version}`;
|
|
94
|
-
this.valid = false;
|
|
95
|
-
this.alreadyLoaded = false;
|
|
96
|
-
this.children = [];
|
|
97
|
-
this.hasManifest = false;
|
|
98
|
-
// eslint-disable-next-line new-cap
|
|
99
|
-
this._debug = (0, util_2.Debug)();
|
|
100
|
-
this.warned = false;
|
|
101
|
-
}
|
|
102
|
-
async load() {
|
|
103
|
-
this.type = this.options.type || 'core';
|
|
104
|
-
this.tag = this.options.tag;
|
|
105
|
-
const root = await findRoot(this.options.name, this.options.root);
|
|
106
|
-
if (!root)
|
|
107
|
-
throw new errors_1.CLIError(`could not find package.json with ${(0, util_1.inspect)(this.options)}`);
|
|
108
|
-
this.root = root;
|
|
109
|
-
this._debug('reading %s plugin %s', this.type, root);
|
|
110
|
-
this.pjson = await (0, util_3.loadJSON)(path.join(root, 'package.json'));
|
|
111
|
-
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
112
|
-
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
113
|
-
this.name = this.pjson.name;
|
|
114
|
-
this.alias = this.options.name ?? this.pjson.name;
|
|
115
|
-
const pjsonPath = path.join(root, 'package.json');
|
|
116
|
-
if (!this.name)
|
|
117
|
-
throw new errors_1.CLIError(`no name in ${pjsonPath}`);
|
|
118
|
-
if (!(0, util_4.isProd)() && !this.pjson.files)
|
|
119
|
-
this.warn(`files attribute must be specified in ${pjsonPath}`);
|
|
120
|
-
// eslint-disable-next-line new-cap
|
|
121
|
-
this._debug = (0, util_2.Debug)(this.name);
|
|
122
|
-
this.version = this.pjson.version;
|
|
123
|
-
if (this.pjson.oclif) {
|
|
124
|
-
this.valid = true;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
this.pjson.oclif = this.pjson['cli-engine'] || {};
|
|
128
|
-
}
|
|
129
|
-
this.hooks = (0, util_3.mapValues)(this.pjson.oclif.hooks || {}, i => Array.isArray(i) ? i : [i]);
|
|
130
|
-
this.manifest = await this._manifest();
|
|
131
|
-
this.commands = Object
|
|
132
|
-
.entries(this.manifest.commands)
|
|
133
|
-
.map(([id, c]) => ({
|
|
134
|
-
...c,
|
|
135
|
-
pluginAlias: this.alias,
|
|
136
|
-
pluginType: c.pluginType === 'jit' ? 'jit' : this.type,
|
|
137
|
-
load: async () => this.findCommand(id, { must: true }),
|
|
138
|
-
}))
|
|
139
|
-
.sort((a, b) => a.id.localeCompare(b.id));
|
|
140
|
-
}
|
|
141
|
-
get topics() {
|
|
142
|
-
return topicsToArray(this.pjson.oclif.topics || {});
|
|
143
|
-
}
|
|
144
|
-
get commandsDir() {
|
|
145
|
-
if (this._commandsDir)
|
|
146
|
-
return this._commandsDir;
|
|
147
|
-
this._commandsDir = (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this);
|
|
148
|
-
return this._commandsDir;
|
|
149
|
-
}
|
|
150
|
-
get commandIDs() {
|
|
151
|
-
if (!this.commandsDir)
|
|
152
|
-
return [];
|
|
153
|
-
const marker = performance_1.default.mark(`plugin.commandIDs#${this.name}`, { plugin: this.name });
|
|
154
|
-
this._debug(`loading IDs from ${this.commandsDir}`);
|
|
155
|
-
const patterns = [
|
|
156
|
-
'**/*.+(js|cjs|mjs|ts|tsx)',
|
|
157
|
-
'!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js)?(x)',
|
|
158
|
-
];
|
|
159
|
-
const ids = globby.sync(patterns, { cwd: this.commandsDir })
|
|
160
|
-
.map(file => {
|
|
161
|
-
const p = path.parse(file);
|
|
162
|
-
const topics = p.dir.split('/');
|
|
163
|
-
const command = p.name !== 'index' && p.name;
|
|
164
|
-
const id = [...topics, command].filter(f => f).join(':');
|
|
165
|
-
return id === '' ? '.' : id;
|
|
166
|
-
});
|
|
167
|
-
this._debug('found commands', ids);
|
|
168
|
-
marker?.addDetails({ count: ids.length });
|
|
169
|
-
marker?.stop();
|
|
170
|
-
return ids;
|
|
171
|
-
}
|
|
172
|
-
async findCommand(id, opts = {}) {
|
|
173
|
-
const marker = performance_1.default.mark(`plugin.findCommand#${this.name}.${id}`, { id, plugin: this.name });
|
|
174
|
-
const fetch = async () => {
|
|
175
|
-
if (!this.commandsDir)
|
|
176
|
-
return;
|
|
177
|
-
const search = (cmd) => {
|
|
178
|
-
if (typeof cmd.run === 'function')
|
|
179
|
-
return cmd;
|
|
180
|
-
if (cmd.default && cmd.default.run)
|
|
181
|
-
return cmd.default;
|
|
182
|
-
return Object.values(cmd).find((cmd) => typeof cmd.run === 'function');
|
|
183
|
-
};
|
|
184
|
-
let m;
|
|
185
|
-
try {
|
|
186
|
-
const p = path.join(this.commandsDir ?? this.pjson.oclif.commands, ...id.split(':'));
|
|
187
|
-
const { isESM, module, filePath } = await module_loader_1.default.loadWithData(this, p);
|
|
188
|
-
this._debug(isESM ? '(import)' : '(require)', filePath);
|
|
189
|
-
m = module;
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
if (!opts.must && error.code === 'MODULE_NOT_FOUND')
|
|
193
|
-
return;
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
const cmd = search(m);
|
|
197
|
-
if (!cmd)
|
|
198
|
-
return;
|
|
199
|
-
cmd.id = id;
|
|
200
|
-
cmd.plugin = this;
|
|
201
|
-
return cmd;
|
|
202
|
-
};
|
|
203
|
-
const cmd = await fetch();
|
|
204
|
-
if (!cmd && opts.must)
|
|
205
|
-
(0, errors_1.error)(`command ${id} not found`);
|
|
206
|
-
marker?.stop();
|
|
207
|
-
return cmd;
|
|
208
125
|
}
|
|
209
126
|
async _manifest() {
|
|
210
127
|
const ignoreManifest = Boolean(this.options.ignoreManifest);
|
|
@@ -212,8 +129,8 @@ class Plugin {
|
|
|
212
129
|
const respectNoCacheDefault = Boolean(this.options.respectNoCacheDefault);
|
|
213
130
|
const readManifest = async (dotfile = false) => {
|
|
214
131
|
try {
|
|
215
|
-
const p =
|
|
216
|
-
const manifest = await (0,
|
|
132
|
+
const p = (0, node_path_1.join)(this.root, `${dotfile ? '.' : ''}oclif.manifest.json`);
|
|
133
|
+
const manifest = await (0, fs_1.readJson)(p);
|
|
217
134
|
if (!process.env.OCLIF_NEXT_VERSION && manifest.version.split('-')[0] !== this.version.split('-')[0]) {
|
|
218
135
|
process.emitWarning(`Mismatched version in ${this.name} plugin manifest. Expected: ${this.version} Received: ${manifest.version}\nThis usually means you have an oclif.manifest.json file that should be deleted in development. This file should be automatically generated when publishing.`);
|
|
219
136
|
}
|
|
@@ -233,45 +150,58 @@ class Plugin {
|
|
|
233
150
|
}
|
|
234
151
|
}
|
|
235
152
|
};
|
|
236
|
-
const marker = performance_1.
|
|
153
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.manifest#${this.name}`, { plugin: this.name });
|
|
237
154
|
if (!ignoreManifest) {
|
|
238
155
|
const manifest = await readManifest();
|
|
239
156
|
if (manifest) {
|
|
240
|
-
marker?.addDetails({
|
|
157
|
+
marker?.addDetails({ commandCount: Object.keys(manifest.commands).length, fromCache: true });
|
|
241
158
|
marker?.stop();
|
|
242
159
|
return manifest;
|
|
243
160
|
}
|
|
244
161
|
}
|
|
245
162
|
const manifest = {
|
|
246
|
-
version: this.version,
|
|
247
163
|
commands: (await Promise.all(this.commandIDs.map(async (id) => {
|
|
248
164
|
try {
|
|
249
|
-
const cached = await (0,
|
|
165
|
+
const cached = await (0, cache_command_1.cacheCommand)(await this.findCommand(id, { must: true }), this, respectNoCacheDefault);
|
|
250
166
|
if (this.flexibleTaxonomy) {
|
|
251
167
|
const permutations = (0, util_2.getCommandIdPermutations)(id);
|
|
252
|
-
const aliasPermutations = cached.aliases.flatMap(a => (0, util_2.getCommandIdPermutations)(a));
|
|
253
|
-
return [id, { ...cached,
|
|
168
|
+
const aliasPermutations = cached.aliases.flatMap((a) => (0, util_2.getCommandIdPermutations)(a));
|
|
169
|
+
return [id, { ...cached, aliasPermutations, permutations }];
|
|
254
170
|
}
|
|
255
171
|
return [id, cached];
|
|
256
172
|
}
|
|
257
173
|
catch (error) {
|
|
258
|
-
const scope = '
|
|
174
|
+
const scope = 'cacheCommand';
|
|
259
175
|
if (Boolean(errorOnManifestCreate) === false)
|
|
260
176
|
this.warn(error, scope);
|
|
261
177
|
else
|
|
262
178
|
throw this.addErrorScope(error, scope);
|
|
263
179
|
}
|
|
264
180
|
})))
|
|
181
|
+
// eslint-disable-next-line unicorn/no-await-expression-member, unicorn/prefer-native-coercion-functions
|
|
265
182
|
.filter((f) => Boolean(f))
|
|
266
183
|
.reduce((commands, [id, c]) => {
|
|
267
184
|
commands[id] = c;
|
|
268
185
|
return commands;
|
|
269
186
|
}, {}),
|
|
187
|
+
version: this.version,
|
|
270
188
|
};
|
|
271
|
-
marker?.addDetails({
|
|
189
|
+
marker?.addDetails({ commandCount: Object.keys(manifest.commands).length, fromCache: false });
|
|
272
190
|
marker?.stop();
|
|
273
191
|
return manifest;
|
|
274
192
|
}
|
|
193
|
+
addErrorScope(err, scope) {
|
|
194
|
+
err.name = `${err.name} Plugin: ${this.name}`;
|
|
195
|
+
err.detail = (0, util_1.compact)([
|
|
196
|
+
err.detail,
|
|
197
|
+
`module: ${this._base}`,
|
|
198
|
+
scope && `task: ${scope}`,
|
|
199
|
+
`plugin: ${this.name}`,
|
|
200
|
+
`root: ${this.root}`,
|
|
201
|
+
'See more details with DEBUG=*',
|
|
202
|
+
]).join('\n');
|
|
203
|
+
return err;
|
|
204
|
+
}
|
|
275
205
|
warn(err, scope) {
|
|
276
206
|
if (this.warned)
|
|
277
207
|
return;
|
|
@@ -279,10 +209,114 @@ class Plugin {
|
|
|
279
209
|
err = new Error(err);
|
|
280
210
|
process.emitWarning(this.addErrorScope(err, scope));
|
|
281
211
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
212
|
+
async findCommand(id, opts = {}) {
|
|
213
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.findCommand#${this.name}.${id}`, {
|
|
214
|
+
id,
|
|
215
|
+
plugin: this.name,
|
|
216
|
+
});
|
|
217
|
+
const fetch = async () => {
|
|
218
|
+
if (!this.commandsDir)
|
|
219
|
+
return;
|
|
220
|
+
let module;
|
|
221
|
+
let isESM;
|
|
222
|
+
let filePath;
|
|
223
|
+
try {
|
|
224
|
+
;
|
|
225
|
+
({ filePath, isESM, module } = cachedCommandCanBeUsed(this.manifest, id)
|
|
226
|
+
? await (0, module_loader_1.loadWithDataFromManifest)(this.manifest.commands[id], this.root)
|
|
227
|
+
: await (0, module_loader_1.loadWithData)(this, (0, node_path_1.join)(this.commandsDir ?? this.pjson.oclif.commands, ...id.split(':'))));
|
|
228
|
+
this._debug(isESM ? '(import)' : '(require)', filePath);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (!opts.must && error.code === 'MODULE_NOT_FOUND')
|
|
232
|
+
return;
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
const cmd = search(module);
|
|
236
|
+
if (!cmd)
|
|
237
|
+
return;
|
|
238
|
+
cmd.id = id;
|
|
239
|
+
cmd.plugin = this;
|
|
240
|
+
cmd.isESM = isESM;
|
|
241
|
+
cmd.relativePath = (0, node_path_1.relative)(this.root, filePath || '').split(node_path_1.sep);
|
|
242
|
+
return cmd;
|
|
243
|
+
};
|
|
244
|
+
const cmd = await fetch();
|
|
245
|
+
if (!cmd && opts.must)
|
|
246
|
+
(0, errors_1.error)(`command ${id} not found`);
|
|
247
|
+
marker?.stop();
|
|
248
|
+
return cmd;
|
|
249
|
+
}
|
|
250
|
+
async load() {
|
|
251
|
+
this.type = this.options.type || 'core';
|
|
252
|
+
this.tag = this.options.tag;
|
|
253
|
+
this.isRoot = this.options.isRoot ?? false;
|
|
254
|
+
if (this.options.parent)
|
|
255
|
+
this.parent = this.options.parent;
|
|
256
|
+
// Linked plugins already have a root so there's no need to search for it.
|
|
257
|
+
// However there could be child plugins nested inside the linked plugin, in which
|
|
258
|
+
// case we still need to search for the child plugin's root.
|
|
259
|
+
const root = this.type === 'link' && !this.parent ? this.options.root : await findRoot(this.options.name, this.options.root);
|
|
260
|
+
if (!root)
|
|
261
|
+
throw new errors_1.CLIError(`could not find package.json with ${(0, node_util_1.inspect)(this.options)}`);
|
|
262
|
+
this.root = root;
|
|
263
|
+
this._debug('reading %s plugin %s', this.type, root);
|
|
264
|
+
this.pjson = await (0, fs_1.readJson)((0, node_path_1.join)(root, 'package.json'));
|
|
265
|
+
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
266
|
+
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
267
|
+
this.name = this.pjson.name;
|
|
268
|
+
this.alias = this.options.name ?? this.pjson.name;
|
|
269
|
+
const pjsonPath = (0, node_path_1.join)(root, 'package.json');
|
|
270
|
+
if (!this.name)
|
|
271
|
+
throw new errors_1.CLIError(`no name in ${pjsonPath}`);
|
|
272
|
+
if (!(0, util_1.isProd)() && !this.pjson.files)
|
|
273
|
+
this.warn(`files attribute must be specified in ${pjsonPath}`);
|
|
274
|
+
// eslint-disable-next-line new-cap
|
|
275
|
+
this._debug = (0, util_2.Debug)(this.name);
|
|
276
|
+
this.version = this.pjson.version;
|
|
277
|
+
if (this.pjson.oclif) {
|
|
278
|
+
this.valid = true;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
this.pjson.oclif = this.pjson['cli-engine'] || {};
|
|
282
|
+
}
|
|
283
|
+
this.hooks = (0, util_1.mapValues)(this.pjson.oclif.hooks || {}, (i) => (Array.isArray(i) ? i : [i]));
|
|
284
|
+
this.manifest = await this._manifest();
|
|
285
|
+
this.commands = Object.entries(this.manifest.commands)
|
|
286
|
+
.map(([id, c]) => ({
|
|
287
|
+
...c,
|
|
288
|
+
load: async () => this.findCommand(id, { must: true }),
|
|
289
|
+
pluginAlias: this.alias,
|
|
290
|
+
pluginType: c.pluginType === 'jit' ? 'jit' : this.type,
|
|
291
|
+
}))
|
|
292
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
293
|
+
}
|
|
294
|
+
get commandIDs() {
|
|
295
|
+
if (!this.commandsDir)
|
|
296
|
+
return [];
|
|
297
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.commandIDs#${this.name}`, { plugin: this.name });
|
|
298
|
+
this._debug(`loading IDs from ${this.commandsDir}`);
|
|
299
|
+
const patterns = ['**/*.+(js|cjs|mjs|ts|tsx)', '!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js)?(x)'];
|
|
300
|
+
const ids = (0, globby_1.sync)(patterns, { cwd: this.commandsDir }).map((file) => {
|
|
301
|
+
const p = (0, node_path_1.parse)(file);
|
|
302
|
+
const topics = p.dir.split('/');
|
|
303
|
+
const command = p.name !== 'index' && p.name;
|
|
304
|
+
const id = [...topics, command].filter(Boolean).join(':');
|
|
305
|
+
return id === '' ? '.' : id;
|
|
306
|
+
});
|
|
307
|
+
this._debug('found commands', ids);
|
|
308
|
+
marker?.addDetails({ count: ids.length });
|
|
309
|
+
marker?.stop();
|
|
310
|
+
return ids;
|
|
311
|
+
}
|
|
312
|
+
get commandsDir() {
|
|
313
|
+
if (this._commandsDir)
|
|
314
|
+
return this._commandsDir;
|
|
315
|
+
this._commandsDir = (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this);
|
|
316
|
+
return this._commandsDir;
|
|
317
|
+
}
|
|
318
|
+
get topics() {
|
|
319
|
+
return topicsToArray(this.pjson.oclif.topics || {});
|
|
286
320
|
}
|
|
287
321
|
}
|
|
288
322
|
exports.Plugin = Plugin;
|
package/lib/config/ts-node.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Plugin } from '../interfaces';
|
|
1
|
+
import { Plugin, TSConfig } from '../interfaces';
|
|
2
|
+
export declare const TS_CONFIGS: Record<string, TSConfig>;
|
|
2
3
|
/**
|
|
3
4
|
* Convert a path from the compiled ./lib files to the ./src typescript source
|
|
4
5
|
* this is for developing typescript plugins/CLIs
|