@oclif/core 1.8.0 → 1.9.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/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.0](https://github.com/oclif/core/compare/v1.8.2...v1.9.0) (2022-05-20)
6
+
7
+
8
+ ### Features
9
+
10
+ * support TS directory imports for ESM ([#422](https://github.com/oclif/core/issues/422)) ([4c58e78](https://github.com/oclif/core/commit/4c58e782e86dd7ecf91294bac0d2c759b4454596))
11
+
12
+ ### [1.8.2](https://github.com/oclif/core/compare/v1.8.1...v1.8.2) (2022-05-18)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * properly load index.js ES modules (cont) ([#417](https://github.com/oclif/core/issues/417)) ([77ba8b8](https://github.com/oclif/core/commit/77ba8b891f941e371bacd0dbedb32be25d6d2599))
18
+
19
+ ### [1.8.1](https://github.com/oclif/core/compare/v1.8.0...v1.8.1) (2022-05-10)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * improve algo for collating command id ([#415](https://github.com/oclif/core/issues/415)) ([1a9bfdb](https://github.com/oclif/core/commit/1a9bfdb810e13506ed8fc4138cde1912981b97e3))
25
+
5
26
  ## [1.8.0](https://github.com/oclif/core/compare/v1.7.0...v1.8.0) (2022-05-06)
6
27
 
7
28
 
@@ -2,7 +2,7 @@
2
2
  // tslint:disable
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.renderList = void 0;
5
- const maxBy_1 = require("lodash/maxBy");
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, maxBy_1.default)(items, '[0].length')[0].length;
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];
@@ -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 (_.isNumber(code) && code > 0) {
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 lodash_1 = require("lodash");
7
+ const util_1 = require("../../util");
8
8
  const js_yaml_1 = require("js-yaml");
9
- const util_1 = require("util");
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, lodash_1.capitalize)(key.replace(/_/g, ' '));
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, util_1.inspect)(val, { breakLength: Number.POSITIVE_INFINITY });
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, lodash_1.sumBy)(columns, c => c.width);
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, lodash_1.sumBy)(columns, c => c.minWidth);
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/help/util.js CHANGED
@@ -33,28 +33,27 @@ exports.template = template;
33
33
  function collateSpacedCmdIDFromArgs(argv, config) {
34
34
  if (argv.length === 1)
35
35
  return argv;
36
- const ids = (0, util_1.collectUsableIds)(config.commandIDs);
37
36
  const findId = (argv) => {
37
+ const ids = (0, util_1.collectUsableIds)(config.commandIDs);
38
38
  const final = [];
39
39
  const idPresent = (id) => ids.includes(id);
40
40
  const isFlag = (s) => s.startsWith('-');
41
41
  const isArgWithValue = (s) => s.includes('=');
42
42
  const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
43
- const hasSubCommandsWithArgs = () => {
43
+ const hasArgs = () => {
44
+ var _a;
44
45
  const id = finalizeId();
45
46
  if (!id)
46
47
  return false;
47
- // Get a list of sub commands for the current command id. A command is returned as a subcommand if the `id` starts with the current command id.
48
- // e.g. `foo:bar` is a subcommand of `foo`
49
- const subCommands = config.commands.filter(c => (c.id).startsWith(id));
50
- return Boolean(subCommands.find(cmd => { var _a; return cmd.strict === false || ((_a = cmd.args) === null || _a === void 0 ? void 0 : _a.length) > 0; }));
48
+ const cmd = config.findCommand(id);
49
+ return Boolean(cmd && (cmd.strict === false || ((_a = cmd.args) === null || _a === void 0 ? void 0 : _a.length) > 0));
51
50
  };
52
51
  for (const arg of argv) {
53
52
  if (idPresent(finalizeId(arg)))
54
53
  final.push(arg);
55
54
  // If the parent topic has a command that expects positional arguments, then we cannot
56
55
  // assume that any subsequent string could be part of the command name
57
- else if (isArgWithValue(arg) || isFlag(arg) || hasSubCommandsWithArgs())
56
+ else if (isArgWithValue(arg) || isFlag(arg) || hasArgs())
58
57
  break;
59
58
  else
60
59
  final.push(arg);
@@ -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
  }
@@ -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
- // Try all supported extensions.
131
- if (!fs.existsSync(filePath)) {
132
- // eslint-disable-next-line camelcase
133
- for (const extension of s_EXTENSIONS) {
134
- const testPath = `${filePath}${extension}`;
135
- if (fs.existsSync(testPath)) {
136
- filePath = testPath;
137
- break;
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.8.0",
4
+ "version": "1.9.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -22,11 +22,10 @@
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",
29
- "semver": "^7.3.5",
28
+ "semver": "^7.3.7",
30
29
  "string-width": "^4.2.3",
31
30
  "strip-ansi": "^6.0.1",
32
31
  "supports-color": "^8.1.1",
@@ -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",