@oclif/core 4.0.0-beta.3 → 4.0.0-beta.5
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/plugin.js +2 -1
- package/lib/util/fs.js +12 -0
- package/lib/util/read-pjson.d.ts +7 -0
- package/lib/util/read-pjson.js +60 -0
- package/package.json +2 -1
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");
|
|
@@ -182,7 +183,7 @@ class Plugin {
|
|
|
182
183
|
throw new errors_1.CLIError(`could not find package.json with ${(0, node_util_1.inspect)(this.options)}`);
|
|
183
184
|
this.root = root;
|
|
184
185
|
this._debug(`loading ${this.type} plugin from ${root}`);
|
|
185
|
-
this.pjson = this.options.pjson ?? (await (0,
|
|
186
|
+
this.pjson = this.options.pjson ?? (await (0, read_pjson_1.readPjson)(root));
|
|
186
187
|
this.flexibleTaxonomy = this.options?.flexibleTaxonomy || this.pjson.oclif?.flexibleTaxonomy || false;
|
|
187
188
|
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
188
189
|
this.name = this.pjson.name;
|
package/lib/util/fs.js
CHANGED
|
@@ -43,17 +43,29 @@ const fileExists = async (input) => {
|
|
|
43
43
|
return input;
|
|
44
44
|
};
|
|
45
45
|
exports.fileExists = fileExists;
|
|
46
|
+
const cache = new Map();
|
|
46
47
|
async function readJson(path) {
|
|
48
|
+
if (cache.has(path)) {
|
|
49
|
+
return JSON.parse(cache.get(path));
|
|
50
|
+
}
|
|
47
51
|
const contents = await (0, promises_1.readFile)(path, 'utf8');
|
|
52
|
+
cache.set(path, contents);
|
|
48
53
|
return JSON.parse(contents);
|
|
49
54
|
}
|
|
50
55
|
exports.readJson = readJson;
|
|
51
56
|
function readJsonSync(path, parse = true) {
|
|
57
|
+
if (cache.has(path)) {
|
|
58
|
+
return JSON.parse(cache.get(path));
|
|
59
|
+
}
|
|
52
60
|
const contents = (0, node_fs_1.readFileSync)(path, 'utf8');
|
|
61
|
+
cache.set(path, contents);
|
|
53
62
|
return parse ? JSON.parse(contents) : contents;
|
|
54
63
|
}
|
|
55
64
|
exports.readJsonSync = readJsonSync;
|
|
56
65
|
async function safeReadJson(path) {
|
|
66
|
+
if (cache.has(path)) {
|
|
67
|
+
return JSON.parse(cache.get(path));
|
|
68
|
+
}
|
|
57
69
|
try {
|
|
58
70
|
return await readJson(path);
|
|
59
71
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PJSON } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Read the package.json file from a given path and add the oclif config (found by cosmiconfig) if it exists.
|
|
4
|
+
*
|
|
5
|
+
* We can assume that the package.json file exists because the plugin root has already been loaded at this point.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readPjson(path: string): Promise<PJSON.Plugin>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPjson = void 0;
|
|
4
|
+
const cosmiconfig_1 = require("cosmiconfig");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
const fs_1 = require("./fs");
|
|
8
|
+
const debug = (0, logger_1.makeDebug)('read-pjson');
|
|
9
|
+
/**
|
|
10
|
+
* Read the package.json file from a given path and add the oclif config (found by cosmiconfig) if it exists.
|
|
11
|
+
*
|
|
12
|
+
* We can assume that the package.json file exists because the plugin root has already been loaded at this point.
|
|
13
|
+
*/
|
|
14
|
+
async function readPjson(path) {
|
|
15
|
+
const pjsonPath = (0, node_path_1.join)(path, 'package.json');
|
|
16
|
+
if (process.env.OCLIF_DISABLE_RC) {
|
|
17
|
+
debug('OCLIF_DISABLE_RC is set, skipping rc search');
|
|
18
|
+
return (0, fs_1.readJson)(pjsonPath);
|
|
19
|
+
}
|
|
20
|
+
const pjson = await (0, fs_1.readJson)(pjsonPath);
|
|
21
|
+
// don't bother with cosmiconfig if the plugin's package.json already has an oclif config
|
|
22
|
+
if (pjson.oclif) {
|
|
23
|
+
debug(`found oclif config in ${pjsonPath}`);
|
|
24
|
+
return pjson;
|
|
25
|
+
}
|
|
26
|
+
debug(`searching for oclif config in ${path}`);
|
|
27
|
+
const explorer = (0, cosmiconfig_1.cosmiconfig)('oclif', {
|
|
28
|
+
/**
|
|
29
|
+
* Remove the following from the defaults:
|
|
30
|
+
* - package.json
|
|
31
|
+
* - any files under .config/
|
|
32
|
+
*/
|
|
33
|
+
searchPlaces: [
|
|
34
|
+
'.oclifrc',
|
|
35
|
+
'.oclifrc.json',
|
|
36
|
+
'.oclifrc.yaml',
|
|
37
|
+
'.oclifrc.yml',
|
|
38
|
+
'.oclifrc.js',
|
|
39
|
+
'.oclifrc.ts',
|
|
40
|
+
'.oclifrc.mjs',
|
|
41
|
+
'.oclifrc.cjs',
|
|
42
|
+
'oclif.config.js',
|
|
43
|
+
'oclif.config.ts',
|
|
44
|
+
'oclif.config.mjs',
|
|
45
|
+
'oclif.config.cjs',
|
|
46
|
+
],
|
|
47
|
+
searchStrategy: 'none',
|
|
48
|
+
});
|
|
49
|
+
const result = await explorer.search(path);
|
|
50
|
+
if (!result?.config) {
|
|
51
|
+
debug(`no oclif config found in ${path}`);
|
|
52
|
+
return pjson;
|
|
53
|
+
}
|
|
54
|
+
debug(`found oclif config for ${path}: %O`, result);
|
|
55
|
+
return {
|
|
56
|
+
...pjson,
|
|
57
|
+
oclif: result?.config ?? {},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.readPjson = readPjson;
|
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": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.5",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"ansis": "^3.0.1",
|
|
10
10
|
"clean-stack": "^3.0.1",
|
|
11
11
|
"cli-spinners": "^2.9.2",
|
|
12
|
+
"cosmiconfig": "^9.0.0",
|
|
12
13
|
"debug": "^4.3.4",
|
|
13
14
|
"ejs": "^3.1.10",
|
|
14
15
|
"get-package-type": "^0.1.0",
|