@oclif/core 1.8.1 → 1.9.1
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/CHANGELOG.md +21 -0
- package/lib/cli-ux/list.js +3 -2
- package/lib/cli-ux/open.js +1 -2
- package/lib/cli-ux/styled/table.js +6 -6
- package/lib/config/plugin.js +2 -1
- package/lib/help/index.js +3 -1
- package/lib/main.js +5 -0
- package/lib/module-loader.d.ts +8 -0
- package/lib/module-loader.js +41 -9
- package/lib/util.d.ts +3 -0
- package/lib/util.js +20 -1
- package/package.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.9.1](https://github.com/oclif/core/compare/v1.9.0...v1.9.1) (2022-06-14)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* support CLIs with single top level command ([#426](https://github.com/oclif/core/issues/426)) ([44adb4d](https://github.com/oclif/core/commit/44adb4d387695548a017b38249b0bc3453aedbdf))
|
|
11
|
+
|
|
12
|
+
## [1.9.0](https://github.com/oclif/core/compare/v1.8.2...v1.9.0) (2022-05-20)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* support TS directory imports for ESM ([#422](https://github.com/oclif/core/issues/422)) ([4c58e78](https://github.com/oclif/core/commit/4c58e782e86dd7ecf91294bac0d2c759b4454596))
|
|
18
|
+
|
|
19
|
+
### [1.8.2](https://github.com/oclif/core/compare/v1.8.1...v1.8.2) (2022-05-18)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* properly load index.js ES modules (cont) ([#417](https://github.com/oclif/core/issues/417)) ([77ba8b8](https://github.com/oclif/core/commit/77ba8b891f941e371bacd0dbedb32be25d6d2599))
|
|
25
|
+
|
|
5
26
|
### [1.8.1](https://github.com/oclif/core/compare/v1.8.0...v1.8.1) (2022-05-10)
|
|
6
27
|
|
|
7
28
|
|
package/lib/cli-ux/list.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// tslint:disable
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.renderList = void 0;
|
|
5
|
-
const
|
|
5
|
+
const util_1 = require("../util");
|
|
6
6
|
const deps_1 = require("./deps");
|
|
7
7
|
function linewrap(length, s) {
|
|
8
8
|
const lw = require('@oclif/linewrap');
|
|
@@ -11,10 +11,11 @@ function linewrap(length, s) {
|
|
|
11
11
|
})(s).trim();
|
|
12
12
|
}
|
|
13
13
|
function renderList(items) {
|
|
14
|
+
var _a, _b;
|
|
14
15
|
if (items.length === 0) {
|
|
15
16
|
return '';
|
|
16
17
|
}
|
|
17
|
-
const maxLength = (0,
|
|
18
|
+
const maxLength = (_b = (_a = (0, util_1.maxBy)(items, item => item[0].length)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
18
19
|
const lines = items.map(i => {
|
|
19
20
|
let left = i[0];
|
|
20
21
|
let right = i[1];
|
package/lib/cli-ux/open.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
// this code is largely taken from opn
|
|
4
4
|
const childProcess = require("child_process");
|
|
5
|
-
const _ = require("lodash");
|
|
6
5
|
const isWsl = require('is-wsl');
|
|
7
6
|
function open(target, opts = {}) {
|
|
8
7
|
// opts = {wait: true, ...opts}
|
|
@@ -59,7 +58,7 @@ function open(target, opts = {}) {
|
|
|
59
58
|
return new Promise((resolve, reject) => {
|
|
60
59
|
cp.once('error', reject);
|
|
61
60
|
cp.once('close', code => {
|
|
62
|
-
if (
|
|
61
|
+
if (Number.isInteger(code) && code > 0) {
|
|
63
62
|
reject(new Error('Exited with code ' + code));
|
|
64
63
|
return;
|
|
65
64
|
}
|
|
@@ -4,9 +4,9 @@ exports.table = void 0;
|
|
|
4
4
|
const F = require("../../flags");
|
|
5
5
|
const screen_1 = require("@oclif/screen");
|
|
6
6
|
const chalk = require("chalk");
|
|
7
|
-
const
|
|
7
|
+
const util_1 = require("../../util");
|
|
8
8
|
const js_yaml_1 = require("js-yaml");
|
|
9
|
-
const
|
|
9
|
+
const util_2 = require("util");
|
|
10
10
|
const sw = require('string-width');
|
|
11
11
|
const { orderBy } = require('natural-orderby');
|
|
12
12
|
class Table {
|
|
@@ -17,7 +17,7 @@ class Table {
|
|
|
17
17
|
const col = columns[key];
|
|
18
18
|
const extended = col.extended || false;
|
|
19
19
|
const get = col.get || ((row) => row[key]);
|
|
20
|
-
const header = typeof col.header === 'string' ? col.header : (0,
|
|
20
|
+
const header = typeof col.header === 'string' ? col.header : (0, util_1.capitalize)(key.replace(/_/g, ' '));
|
|
21
21
|
const minWidth = Math.max(col.minWidth || 0, sw(header) + 1);
|
|
22
22
|
return {
|
|
23
23
|
extended,
|
|
@@ -49,7 +49,7 @@ class Table {
|
|
|
49
49
|
for (const col of this.columns) {
|
|
50
50
|
let val = col.get(d);
|
|
51
51
|
if (typeof val !== 'string')
|
|
52
|
-
val = (0,
|
|
52
|
+
val = (0, util_2.inspect)(val, { breakLength: Number.POSITIVE_INFINITY });
|
|
53
53
|
row[col.key] = val;
|
|
54
54
|
}
|
|
55
55
|
return row;
|
|
@@ -183,7 +183,7 @@ class Table {
|
|
|
183
183
|
if (options['no-truncate'] || (!process.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK))
|
|
184
184
|
return;
|
|
185
185
|
// don't shorten if there is enough screen width
|
|
186
|
-
const dataMaxWidth = (0,
|
|
186
|
+
const dataMaxWidth = (0, util_1.sumBy)(columns, c => c.width);
|
|
187
187
|
const overWidth = dataMaxWidth - maxWidth;
|
|
188
188
|
if (overWidth <= 0)
|
|
189
189
|
return;
|
|
@@ -194,7 +194,7 @@ class Table {
|
|
|
194
194
|
// if sum(minWidth's) is greater than term width
|
|
195
195
|
// nothing can be done so
|
|
196
196
|
// display all as minWidth
|
|
197
|
-
const dataMinWidth = (0,
|
|
197
|
+
const dataMinWidth = (0, util_1.sumBy)(columns, c => c.minWidth);
|
|
198
198
|
if (dataMinWidth >= maxWidth)
|
|
199
199
|
return;
|
|
200
200
|
// some wiggle room left, add it back to "needy" columns
|
package/lib/config/plugin.js
CHANGED
|
@@ -159,7 +159,8 @@ class Plugin {
|
|
|
159
159
|
const p = path.parse(file);
|
|
160
160
|
const topics = p.dir.split('/');
|
|
161
161
|
const command = p.name !== 'index' && p.name;
|
|
162
|
-
|
|
162
|
+
const id = [...topics, command].filter(f => f).join(':');
|
|
163
|
+
return id === '' ? '.' : id;
|
|
163
164
|
});
|
|
164
165
|
this._debug('found commands', ids);
|
|
165
166
|
return ids;
|
package/lib/help/index.js
CHANGED
|
@@ -77,8 +77,10 @@ class Help extends HelpBase {
|
|
|
77
77
|
if (!subject) {
|
|
78
78
|
if (this.config.pjson.oclif.default) {
|
|
79
79
|
const rootCmd = this.config.findCommand(this.config.pjson.oclif.default);
|
|
80
|
-
if (rootCmd)
|
|
80
|
+
if (rootCmd) {
|
|
81
81
|
await this.showCommandHelp(rootCmd);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
85
|
await this.showRootHelp();
|
|
84
86
|
return;
|
package/lib/main.js
CHANGED
|
@@ -70,6 +70,11 @@ async function run(argv = process.argv.slice(2), options) {
|
|
|
70
70
|
argvSlice = argv;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
// If the the default command is '.' (signifying that the CLI is a single command CLI) and '.' is provided
|
|
74
|
+
// as an argument, we need to add back the '.' to argv since it was stripped out earlier as part of the
|
|
75
|
+
// command id.
|
|
76
|
+
if (config.pjson.oclif.default === '.' && id === '.' && argv[0] === '.')
|
|
77
|
+
argvSlice = ['.', ...argvSlice];
|
|
73
78
|
await config.runCommand(id, argvSlice, cmd);
|
|
74
79
|
}
|
|
75
80
|
exports.run = run;
|
package/lib/module-loader.d.ts
CHANGED
|
@@ -71,4 +71,12 @@ export default class ModuleLoader {
|
|
|
71
71
|
isESM: boolean;
|
|
72
72
|
filePath: string;
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Try adding the different extensions from `s_EXTENSIONS` to find the file.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} filePath - File path to load.
|
|
78
|
+
*
|
|
79
|
+
* @returns {string | null} Modified file path including extension or null if file is not found.
|
|
80
|
+
*/
|
|
81
|
+
static findFile(filePath: string): string | null;
|
|
74
82
|
}
|
package/lib/module-loader.js
CHANGED
|
@@ -10,7 +10,7 @@ const getPackageType = require('get-package-type');
|
|
|
10
10
|
* Defines file extension resolution when source files do not have an extension.
|
|
11
11
|
*/
|
|
12
12
|
// eslint-disable-next-line camelcase
|
|
13
|
-
const s_EXTENSIONS = ['.js', '.mjs', '.cjs'];
|
|
13
|
+
const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'];
|
|
14
14
|
/**
|
|
15
15
|
* Provides a mechanism to use dynamic import / import() with tsconfig -> module: commonJS as otherwise import() gets
|
|
16
16
|
* transpiled to require().
|
|
@@ -101,6 +101,8 @@ class ModuleLoader {
|
|
|
101
101
|
switch (extension) {
|
|
102
102
|
case '.js':
|
|
103
103
|
return getPackageType.sync(filePath) === 'module';
|
|
104
|
+
case '.ts':
|
|
105
|
+
return getPackageType.sync(filePath) === 'module';
|
|
104
106
|
case '.mjs':
|
|
105
107
|
return true;
|
|
106
108
|
default:
|
|
@@ -119,6 +121,7 @@ class ModuleLoader {
|
|
|
119
121
|
* @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
|
|
120
122
|
*/
|
|
121
123
|
static resolvePath(config, modulePath) {
|
|
124
|
+
var _a, _b;
|
|
122
125
|
let isESM;
|
|
123
126
|
let filePath;
|
|
124
127
|
try {
|
|
@@ -127,20 +130,49 @@ class ModuleLoader {
|
|
|
127
130
|
}
|
|
128
131
|
catch {
|
|
129
132
|
filePath = Config.tsPath(config.root, modulePath);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (fs.
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
let fileExists = false;
|
|
134
|
+
let isDirectory = false;
|
|
135
|
+
if (fs.existsSync(filePath)) {
|
|
136
|
+
fileExists = true;
|
|
137
|
+
try {
|
|
138
|
+
if ((_b = (_a = fs.lstatSync(filePath)) === null || _a === void 0 ? void 0 : _a.isDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)) {
|
|
139
|
+
fileExists = false;
|
|
140
|
+
isDirectory = true;
|
|
138
141
|
}
|
|
139
142
|
}
|
|
143
|
+
catch { }
|
|
144
|
+
}
|
|
145
|
+
if (!fileExists) {
|
|
146
|
+
// Try all supported extensions.
|
|
147
|
+
let foundPath = ModuleLoader.findFile(filePath);
|
|
148
|
+
if (!foundPath && isDirectory) {
|
|
149
|
+
// Since filePath is a directory, try looking for index file.
|
|
150
|
+
foundPath = ModuleLoader.findFile(path.join(filePath, 'index'));
|
|
151
|
+
}
|
|
152
|
+
if (foundPath) {
|
|
153
|
+
filePath = foundPath;
|
|
154
|
+
}
|
|
140
155
|
}
|
|
141
156
|
isESM = ModuleLoader.isPathModule(filePath);
|
|
142
157
|
}
|
|
143
158
|
return { isESM, filePath };
|
|
144
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Try adding the different extensions from `s_EXTENSIONS` to find the file.
|
|
162
|
+
*
|
|
163
|
+
* @param {string} filePath - File path to load.
|
|
164
|
+
*
|
|
165
|
+
* @returns {string | null} Modified file path including extension or null if file is not found.
|
|
166
|
+
*/
|
|
167
|
+
static findFile(filePath) {
|
|
168
|
+
// eslint-disable-next-line camelcase
|
|
169
|
+
for (const extension of s_EXTENSIONS) {
|
|
170
|
+
const testPath = `${filePath}${extension}`;
|
|
171
|
+
if (fs.existsSync(testPath)) {
|
|
172
|
+
return testPath;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
145
177
|
}
|
|
146
178
|
exports.default = ModuleLoader;
|
package/lib/util.d.ts
CHANGED
|
@@ -4,4 +4,7 @@ declare type SortTypes = string | number | undefined | boolean;
|
|
|
4
4
|
export declare function sortBy<T>(arr: T[], fn: (i: T) => SortTypes | SortTypes[]): T[];
|
|
5
5
|
export declare function castArray<T>(input?: T | T[]): T[];
|
|
6
6
|
export declare function isProd(): boolean;
|
|
7
|
+
export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
|
|
8
|
+
export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
|
|
9
|
+
export declare function capitalize(s: string): string;
|
|
7
10
|
export {};
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
|
|
3
|
+
exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
|
|
4
4
|
function compact(a) {
|
|
5
5
|
return a.filter((a) => Boolean(a));
|
|
6
6
|
}
|
|
@@ -44,3 +44,22 @@ function isProd() {
|
|
|
44
44
|
return !['development', 'test'].includes((_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : '');
|
|
45
45
|
}
|
|
46
46
|
exports.isProd = isProd;
|
|
47
|
+
function maxBy(arr, fn) {
|
|
48
|
+
if (arr.length === 0) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return arr.reduce((maxItem, i) => {
|
|
52
|
+
const curr = fn(i);
|
|
53
|
+
const max = fn(maxItem);
|
|
54
|
+
return curr > max ? i : maxItem;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.maxBy = maxBy;
|
|
58
|
+
function sumBy(arr, fn) {
|
|
59
|
+
return arr.reduce((sum, i) => sum + fn(i), 0);
|
|
60
|
+
}
|
|
61
|
+
exports.sumBy = sumBy;
|
|
62
|
+
function capitalize(s) {
|
|
63
|
+
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
|
|
64
|
+
}
|
|
65
|
+
exports.capitalize = capitalize;
|
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": "1.
|
|
4
|
+
"version": "1.9.1",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"indent-string": "^4.0.0",
|
|
23
23
|
"is-wsl": "^2.2.0",
|
|
24
24
|
"js-yaml": "^3.14.1",
|
|
25
|
-
"lodash": "^4.17.21",
|
|
26
25
|
"natural-orderby": "^2.0.3",
|
|
27
26
|
"object-treeify": "^1.1.33",
|
|
28
27
|
"password-prompt": "^1.1.2",
|
|
@@ -49,7 +48,6 @@
|
|
|
49
48
|
"@types/fs-extra": "^9.0.13",
|
|
50
49
|
"@types/indent-string": "^4.0.1",
|
|
51
50
|
"@types/js-yaml": "^3.12.7",
|
|
52
|
-
"@types/lodash": "^4.14.182",
|
|
53
51
|
"@types/mocha": "^8.2.3",
|
|
54
52
|
"@types/nock": "^11.1.0",
|
|
55
53
|
"@types/node": "^15.14.9",
|