@oclif/core 3.21.1 → 3.22.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/lib/config/config.js
CHANGED
|
@@ -10,6 +10,11 @@ type LoadOpts = {
|
|
|
10
10
|
force?: boolean;
|
|
11
11
|
rootPlugin: IPlugin;
|
|
12
12
|
userPlugins?: boolean;
|
|
13
|
+
pluginAdditions?: {
|
|
14
|
+
core?: string[];
|
|
15
|
+
dev?: string[];
|
|
16
|
+
path?: string;
|
|
17
|
+
};
|
|
13
18
|
};
|
|
14
19
|
type PluginsMap = Map<string, IPlugin>;
|
|
15
20
|
export default class PluginLoader {
|
|
@@ -23,6 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const minimatch_1 = require("minimatch");
|
|
26
27
|
const node_path_1 = require("node:path");
|
|
27
28
|
const performance_1 = require("../performance");
|
|
28
29
|
const fs_1 = require("../util/fs");
|
|
@@ -31,6 +32,9 @@ const Plugin = __importStar(require("./plugin"));
|
|
|
31
32
|
const util_2 = require("./util");
|
|
32
33
|
// eslint-disable-next-line new-cap
|
|
33
34
|
const debug = (0, util_2.Debug)();
|
|
35
|
+
function findMatchingDependencies(dependencies, patterns) {
|
|
36
|
+
return Object.keys(dependencies).filter((p) => patterns.some((w) => (0, minimatch_1.minimatch)(p, w)));
|
|
37
|
+
}
|
|
34
38
|
class PluginLoader {
|
|
35
39
|
options;
|
|
36
40
|
errors = [];
|
|
@@ -75,8 +79,23 @@ class PluginLoader {
|
|
|
75
79
|
return rootPlugin;
|
|
76
80
|
}
|
|
77
81
|
async loadCorePlugins(opts) {
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
const { plugins: corePlugins } = opts.rootPlugin.pjson.oclif;
|
|
83
|
+
if (corePlugins) {
|
|
84
|
+
const plugins = findMatchingDependencies(opts.rootPlugin.pjson.dependencies ?? {}, corePlugins);
|
|
85
|
+
await this.loadPlugins(opts.rootPlugin.root, 'core', plugins);
|
|
86
|
+
}
|
|
87
|
+
const { core: pluginAdditionsCore, path } = opts.pluginAdditions ?? { core: [] };
|
|
88
|
+
if (pluginAdditionsCore) {
|
|
89
|
+
if (path) {
|
|
90
|
+
// If path is provided, load plugins from the path
|
|
91
|
+
const pjson = await (0, fs_1.readJson)((0, node_path_1.join)(path, 'package.json'));
|
|
92
|
+
const plugins = findMatchingDependencies(pjson.dependencies ?? {}, pluginAdditionsCore);
|
|
93
|
+
await this.loadPlugins(path, 'core', plugins);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const plugins = findMatchingDependencies(opts.rootPlugin.pjson.dependencies ?? {}, pluginAdditionsCore);
|
|
97
|
+
await this.loadPlugins(opts.rootPlugin.root, 'core', plugins);
|
|
98
|
+
}
|
|
80
99
|
}
|
|
81
100
|
}
|
|
82
101
|
async loadDevPlugins(opts) {
|
|
@@ -86,8 +105,26 @@ class PluginLoader {
|
|
|
86
105
|
return;
|
|
87
106
|
try {
|
|
88
107
|
const { devPlugins } = opts.rootPlugin.pjson.oclif;
|
|
89
|
-
if (devPlugins)
|
|
90
|
-
|
|
108
|
+
if (devPlugins) {
|
|
109
|
+
const allDeps = { ...opts.rootPlugin.pjson.dependencies, ...opts.rootPlugin.pjson.devDependencies };
|
|
110
|
+
const plugins = findMatchingDependencies(allDeps ?? {}, devPlugins);
|
|
111
|
+
await this.loadPlugins(opts.rootPlugin.root, 'dev', plugins);
|
|
112
|
+
}
|
|
113
|
+
const { dev: pluginAdditionsDev, path } = opts.pluginAdditions ?? { core: [] };
|
|
114
|
+
if (pluginAdditionsDev) {
|
|
115
|
+
if (path) {
|
|
116
|
+
// If path is provided, load plugins from the path
|
|
117
|
+
const pjson = await (0, fs_1.readJson)((0, node_path_1.join)(path, 'package.json'));
|
|
118
|
+
const allDeps = { ...pjson.dependencies, ...pjson.devDependencies };
|
|
119
|
+
const plugins = findMatchingDependencies(allDeps ?? {}, pluginAdditionsDev);
|
|
120
|
+
await this.loadPlugins(path, 'dev', plugins);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const allDeps = { ...opts.rootPlugin.pjson.dependencies, ...opts.rootPlugin.pjson.devDependencies };
|
|
124
|
+
const plugins = findMatchingDependencies(allDeps ?? {}, pluginAdditionsDev);
|
|
125
|
+
await this.loadPlugins(opts.rootPlugin.root, 'dev', plugins);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
91
128
|
}
|
|
92
129
|
catch (error) {
|
|
93
130
|
process.emitWarning(error);
|
|
@@ -136,7 +173,13 @@ class PluginLoader {
|
|
|
136
173
|
parent.children = [];
|
|
137
174
|
parent.children.push(instance);
|
|
138
175
|
}
|
|
139
|
-
|
|
176
|
+
if (instance.pjson.oclif.plugins) {
|
|
177
|
+
const allDeps = type === 'dev'
|
|
178
|
+
? { ...instance.pjson.dependencies, ...instance.pjson.devDependencies }
|
|
179
|
+
: instance.pjson.dependencies;
|
|
180
|
+
const plugins = findMatchingDependencies(allDeps ?? {}, instance.pjson.oclif.plugins);
|
|
181
|
+
await this.loadPlugins(instance.root, type, plugins, instance);
|
|
182
|
+
}
|
|
140
183
|
}
|
|
141
184
|
catch (error) {
|
|
142
185
|
this.errors.push(error);
|
package/lib/config/plugin.d.ts
CHANGED
package/lib/config/plugin.js
CHANGED
|
@@ -103,7 +103,6 @@ class Plugin {
|
|
|
103
103
|
type;
|
|
104
104
|
valid = false;
|
|
105
105
|
version;
|
|
106
|
-
warned = false;
|
|
107
106
|
_base = `${_pjson.name}@${_pjson.version}`;
|
|
108
107
|
// eslint-disable-next-line new-cap
|
|
109
108
|
_debug = (0, util_2.Debug)();
|
|
@@ -272,7 +271,7 @@ class Plugin {
|
|
|
272
271
|
return [id, cached];
|
|
273
272
|
}
|
|
274
273
|
catch (error) {
|
|
275
|
-
const scope =
|
|
274
|
+
const scope = `findCommand (${id})`;
|
|
276
275
|
if (Boolean(errorOnManifestCreate) === false)
|
|
277
276
|
this.warn(error, scope);
|
|
278
277
|
else
|
|
@@ -367,8 +366,6 @@ class Plugin {
|
|
|
367
366
|
}
|
|
368
367
|
}
|
|
369
368
|
warn(err, scope) {
|
|
370
|
-
if (this.warned)
|
|
371
|
-
return;
|
|
372
369
|
if (typeof err === 'string')
|
|
373
370
|
err = new Error(err);
|
|
374
371
|
process.emitWarning(this.addErrorScope(err, scope));
|
|
@@ -22,6 +22,11 @@ export interface Options extends PluginOptions {
|
|
|
22
22
|
enablePerf?: boolean;
|
|
23
23
|
jitPlugins?: boolean;
|
|
24
24
|
pjson?: PJSON.Plugin;
|
|
25
|
+
pluginAdditions?: {
|
|
26
|
+
core?: string[];
|
|
27
|
+
dev?: string[];
|
|
28
|
+
path?: string;
|
|
29
|
+
};
|
|
25
30
|
plugins?: Map<string, Plugin>;
|
|
26
31
|
userPlugins?: boolean;
|
|
27
32
|
version?: string;
|
package/lib/module-loader.js
CHANGED
|
@@ -14,6 +14,12 @@ const getPackageType = require('get-package-type');
|
|
|
14
14
|
// eslint-disable-next-line camelcase
|
|
15
15
|
const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts'];
|
|
16
16
|
const isPlugin = (config) => config.type !== undefined;
|
|
17
|
+
function handleError(error, isESM, path) {
|
|
18
|
+
if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
19
|
+
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${path}: ${error.message}`);
|
|
20
|
+
}
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* Loads and returns a module.
|
|
19
25
|
*
|
|
@@ -39,10 +45,7 @@ async function load(config, modulePath) {
|
|
|
39
45
|
return (isESM ? await import((0, node_url_1.pathToFileURL)(filePath).href) : require(filePath));
|
|
40
46
|
}
|
|
41
47
|
catch (error) {
|
|
42
|
-
|
|
43
|
-
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}`);
|
|
44
|
-
}
|
|
45
|
-
throw error;
|
|
48
|
+
handleError(error, isESM, filePath ?? modulePath);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
exports.load = load;
|
|
@@ -73,10 +76,7 @@ async function loadWithData(config, modulePath) {
|
|
|
73
76
|
return { filePath, isESM, module };
|
|
74
77
|
}
|
|
75
78
|
catch (error) {
|
|
76
|
-
|
|
77
|
-
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}: ${error.message}`);
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
79
|
+
handleError(error, isESM, filePath ?? modulePath);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
exports.loadWithData = loadWithData;
|
|
@@ -109,10 +109,7 @@ async function loadWithDataFromManifest(cached, modulePath) {
|
|
|
109
109
|
return { filePath, isESM, module };
|
|
110
110
|
}
|
|
111
111
|
catch (error) {
|
|
112
|
-
|
|
113
|
-
throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}: ${error.message}`);
|
|
114
|
-
}
|
|
115
|
-
throw error;
|
|
112
|
+
handleError(error, isESM, filePath ?? modulePath);
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
exports.loadWithDataFromManifest = loadWithDataFromManifest;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/core",
|
|
3
3
|
"description": "base library for oclif CLIs",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.22.0",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"indent-string": "^4.0.0",
|
|
22
22
|
"is-wsl": "^2.2.0",
|
|
23
23
|
"js-yaml": "^3.14.1",
|
|
24
|
+
"minimatch": "^9.0.3",
|
|
24
25
|
"natural-orderby": "^2.0.3",
|
|
25
26
|
"object-treeify": "^1.1.33",
|
|
26
27
|
"password-prompt": "^1.1.3",
|