@oclif/core 3.0.0-beta.12 → 3.0.0-beta.14

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.
Files changed (76) hide show
  1. package/README.md +3 -1
  2. package/lib/args.d.ts +1 -1
  3. package/lib/args.js +13 -15
  4. package/lib/cli-ux/action/base.d.ts +1 -1
  5. package/lib/cli-ux/action/base.js +20 -15
  6. package/lib/cli-ux/action/simple.js +10 -8
  7. package/lib/cli-ux/action/spinner.js +11 -10
  8. package/lib/cli-ux/config.js +8 -7
  9. package/lib/cli-ux/flush.js +2 -3
  10. package/lib/cli-ux/index.d.ts +10 -28
  11. package/lib/cli-ux/index.js +26 -45
  12. package/lib/cli-ux/list.js +1 -1
  13. package/lib/cli-ux/prompt.js +24 -19
  14. package/lib/cli-ux/styled/index.d.ts +5 -6
  15. package/lib/cli-ux/styled/index.js +11 -11
  16. package/lib/cli-ux/styled/json.js +3 -2
  17. package/lib/cli-ux/styled/object.js +6 -8
  18. package/lib/cli-ux/styled/table.js +36 -45
  19. package/lib/cli-ux/wait.js +3 -5
  20. package/lib/command.d.ts +7 -5
  21. package/lib/command.js +35 -28
  22. package/lib/config/config.d.ts +2 -2
  23. package/lib/config/config.js +57 -43
  24. package/lib/config/plugin-loader.js +25 -11
  25. package/lib/config/plugin.d.ts +1 -1
  26. package/lib/config/plugin.js +66 -56
  27. package/lib/config/ts-node.d.ts +2 -1
  28. package/lib/config/ts-node.js +42 -46
  29. package/lib/config/util.d.ts +1 -5
  30. package/lib/config/util.js +5 -46
  31. package/lib/errors/config.js +1 -1
  32. package/lib/errors/errors/cli.d.ts +1 -1
  33. package/lib/errors/errors/cli.js +14 -13
  34. package/lib/errors/errors/exit.d.ts +0 -3
  35. package/lib/errors/errors/module-load.d.ts +0 -3
  36. package/lib/errors/errors/pretty-print.js +9 -8
  37. package/lib/errors/handle.d.ts +12 -2
  38. package/lib/errors/handle.js +23 -14
  39. package/lib/errors/index.d.ts +2 -2
  40. package/lib/errors/index.js +20 -19
  41. package/lib/errors/logger.js +4 -4
  42. package/lib/execute.d.ts +5 -5
  43. package/lib/execute.js +6 -5
  44. package/lib/flags.d.ts +102 -31
  45. package/lib/flags.js +75 -42
  46. package/lib/help/command.d.ts +2 -0
  47. package/lib/help/command.js +32 -32
  48. package/lib/help/docopts.js +2 -9
  49. package/lib/help/formatter.d.ts +1 -1
  50. package/lib/help/formatter.js +17 -17
  51. package/lib/help/index.d.ts +2 -2
  52. package/lib/help/index.js +22 -21
  53. package/lib/help/root.js +2 -2
  54. package/lib/help/util.d.ts +1 -1
  55. package/lib/help/util.js +9 -9
  56. package/lib/index.d.ts +19 -20
  57. package/lib/index.js +38 -42
  58. package/lib/interfaces/config.d.ts +5 -4
  59. package/lib/interfaces/errors.d.ts +1 -1
  60. package/lib/interfaces/parser.d.ts +168 -45
  61. package/lib/interfaces/plugin.d.ts +1 -0
  62. package/lib/main.d.ts +1 -1
  63. package/lib/main.js +16 -16
  64. package/lib/module-loader.d.ts +67 -77
  65. package/lib/module-loader.js +179 -149
  66. package/lib/parser/errors.d.ts +2 -2
  67. package/lib/parser/errors.js +4 -3
  68. package/lib/parser/help.js +3 -2
  69. package/lib/parser/parse.d.ts +3 -0
  70. package/lib/parser/parse.js +56 -52
  71. package/lib/parser/validate.js +9 -5
  72. package/lib/performance.d.ts +6 -2
  73. package/lib/performance.js +23 -12
  74. package/lib/util.d.ts +25 -1
  75. package/lib/util.js +93 -29
  76. package/package.json +10 -15
package/lib/main.js CHANGED
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.versionAddition = exports.helpAddition = void 0;
4
- const url_1 = require("url");
5
- const util_1 = require("util");
6
- const url_2 = require("url");
7
- const config_1 = require("./config");
3
+ exports.run = exports.versionAddition = exports.helpAddition = void 0;
4
+ const node_url_1 = require("node:url");
5
+ const node_util_1 = require("node:util");
8
6
  const help_1 = require("./help");
9
- const stream_1 = require("./cli-ux/stream");
7
+ const config_1 = require("./config");
10
8
  const performance_1 = require("./performance");
9
+ const stream_1 = require("./cli-ux/stream");
11
10
  const debug = require('debug')('oclif:main');
12
11
  const log = (message = '', ...args) => {
13
- message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
14
- stream_1.stdout.write((0, util_1.format)(message, ...args) + '\n');
12
+ message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
13
+ stream_1.stdout.write((0, node_util_1.format)(message, ...args) + '\n');
15
14
  };
16
15
  const helpAddition = (argv, config) => {
17
16
  if (argv.length === 0 && !config.pjson.oclif.default)
@@ -35,21 +34,22 @@ const versionAddition = (argv, config) => {
35
34
  };
36
35
  exports.versionAddition = versionAddition;
37
36
  async function run(argv, options) {
38
- const marker = performance_1.default.mark('main.run');
39
- const initMarker = performance_1.default.mark('main.run#init');
37
+ const marker = performance_1.Performance.mark('main.run');
38
+ const initMarker = performance_1.Performance.mark('main.run#init');
40
39
  const collectPerf = async () => {
41
40
  marker?.stop();
42
- initMarker?.stop();
43
- await performance_1.default.collect();
44
- performance_1.default.debug();
41
+ if (!initMarker?.stopped)
42
+ initMarker?.stop();
43
+ await performance_1.Performance.collect();
44
+ performance_1.Performance.debug();
45
45
  };
46
46
  debug(`process.execPath: ${process.execPath}`);
47
47
  debug(`process.execArgv: ${process.execArgv}`);
48
48
  debug('process.argv: %O', process.argv);
49
49
  argv = argv ?? process.argv.slice(2);
50
50
  // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
51
- if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
52
- options = (0, url_1.fileURLToPath)(options);
51
+ if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof node_url_1.URL)) {
52
+ options = (0, node_url_1.fileURLToPath)(options);
53
53
  }
54
54
  const config = await config_1.Config.load(options ?? require.main?.filename ?? __dirname);
55
55
  let [id, ...argvSlice] = (0, help_1.normalizeArgv)(config, argv);
@@ -93,4 +93,4 @@ async function run(argv, options) {
93
93
  await collectPerf();
94
94
  }
95
95
  }
96
- exports.default = run;
96
+ exports.run = run;
@@ -1,81 +1,71 @@
1
1
  import { Config as IConfig, Plugin as IPlugin } from './interfaces';
2
+ import { Command } from './command';
2
3
  /**
3
- * Provides a static class with several utility methods to work with Oclif config / plugin to load ESM or CJS Node
4
- * modules and source files.
4
+ * Loads and returns a module.
5
5
  *
6
- * @author Michael Leahy <support@typhonjs.io> (https://github.com/typhonrt)
6
+ * Uses `getPackageType` to determine if `type` is set to 'module. If so loads '.js' files as ESM otherwise uses
7
+ * a bare require to load as CJS. Also loads '.mjs' files as ESM.
8
+ *
9
+ * Uses dynamic import to load ESM source or require for CommonJS.
10
+ *
11
+ * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
12
+ * provides a consistent stack trace and info.
13
+ *
14
+ * @param {IConfig|IPlugin} config - Oclif config or plugin config.
15
+ * @param {string} modulePath - NPM module name or file path to load.
16
+ *
17
+ * @returns {Promise<*>} The entire ESM module from dynamic import or CJS module by require.
18
+ */
19
+ export declare function load(config: IConfig | IPlugin, modulePath: string): Promise<any>;
20
+ /**
21
+ * Loads a module and returns an object with the module and data about the module.
22
+ *
23
+ * Uses `getPackageType` to determine if `type` is set to `module`. If so loads '.js' files as ESM otherwise uses
24
+ * a bare require to load as CJS. Also loads '.mjs' files as ESM.
25
+ *
26
+ * Uses dynamic import to load ESM source or require for CommonJS.
27
+ *
28
+ * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
29
+ * provides a consistent stack trace and info.
30
+ *
31
+ * @param {IConfig|IPlugin} config - Oclif config or plugin config.
32
+ * @param {string} modulePath - NPM module name or file path to load.
33
+ *
34
+ * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
35
+ * file path and whether the module is ESM.
7
36
  */
8
- export default class ModuleLoader {
9
- /**
10
- * Loads and returns a module.
11
- *
12
- * Uses `getPackageType` to determine if `type` is set to 'module. If so loads '.js' files as ESM otherwise uses
13
- * a bare require to load as CJS. Also loads '.mjs' files as ESM.
14
- *
15
- * Uses dynamic import to load ESM source or require for CommonJS.
16
- *
17
- * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
18
- * provides a consistent stack trace and info.
19
- *
20
- * @param {IConfig|IPlugin} config - Oclif config or plugin config.
21
- * @param {string} modulePath - NPM module name or file path to load.
22
- *
23
- * @returns {Promise<*>} The entire ESM module from dynamic import or CJS module by require.
24
- */
25
- static load(config: IConfig | IPlugin, modulePath: string): Promise<any>;
26
- /**
27
- * Loads a module and returns an object with the module and data about the module.
28
- *
29
- * Uses `getPackageType` to determine if `type` is set to `module`. If so loads '.js' files as ESM otherwise uses
30
- * a bare require to load as CJS. Also loads '.mjs' files as ESM.
31
- *
32
- * Uses dynamic import to load ESM source or require for CommonJS.
33
- *
34
- * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
35
- * provides a consistent stack trace and info.
36
- *
37
- * @param {IConfig|IPlugin} config - Oclif config or plugin config.
38
- * @param {string} modulePath - NPM module name or file path to load.
39
- *
40
- * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
41
- * file path and whether the module is ESM.
42
- */
43
- static loadWithData(config: IConfig | IPlugin, modulePath: string): Promise<{
44
- isESM: boolean;
45
- module: any;
46
- filePath: string;
47
- }>;
48
- /**
49
- * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
50
- * the `modulePath` provided ends in `.mjs` it is assumed to be ESM.
51
- *
52
- * @param {string} filePath - File path to test.
53
- *
54
- * @returns {boolean} The modulePath is an ES Module.
55
- * @see https://www.npmjs.com/package/get-package-type
56
- */
57
- static isPathModule(filePath: string): boolean;
58
- /**
59
- * Resolves a modulePath first by `require.resolve` to allow Node to resolve an actual module. If this fails then
60
- * the `modulePath` is resolved from the root of the provided config. `Config.tsPath` is used for initial resolution.
61
- * If this file path does not exist then several extensions are tried from `s_EXTENSIONS` in order: '.js', '.mjs',
62
- * '.cjs'. After a file path has been selected `isPathModule` is used to determine if the file is an ES Module.
63
- *
64
- * @param {IConfig|IPlugin} config - Oclif config or plugin config.
65
- * @param {string} modulePath - File path to load.
66
- *
67
- * @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
68
- */
69
- static resolvePath(config: IConfig | IPlugin, modulePath: string): {
70
- isESM: boolean;
71
- filePath: string;
72
- };
73
- /**
74
- * Try adding the different extensions from `s_EXTENSIONS` to find the file.
75
- *
76
- * @param {string} filePath - File path to load.
77
- *
78
- * @returns {string | null} Modified file path including extension or null if file is not found.
79
- */
80
- static findFile(filePath: string): string | null;
81
- }
37
+ export declare function loadWithData(config: IConfig | IPlugin, modulePath: string): Promise<{
38
+ isESM: boolean;
39
+ module: any;
40
+ filePath: string;
41
+ }>;
42
+ /**
43
+ * Loads a module and returns an object with the module and data about the module.
44
+ *
45
+ * Uses cached `isESM` and `relativePath` in plugin manifest to determine if dynamic import (isESM = true)
46
+ * or require (isESM = false | undefined) should be used.
47
+ *
48
+ * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
49
+ * provides a consistent stack trace and info.
50
+ *
51
+ * @param {Command.Cached} cached - Cached command data from plugin manifest.
52
+ * @param {string} modulePath - NPM module name or file path to load.
53
+ *
54
+ * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
55
+ * file path and whether the module is ESM.
56
+ */
57
+ export declare function loadWithDataFromManifest(cached: Command.Cached, modulePath: string): Promise<{
58
+ isESM: boolean;
59
+ module: any;
60
+ filePath: string;
61
+ }>;
62
+ /**
63
+ * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
64
+ * the `modulePath` provided ends in `.mjs` it is assumed to be ESM.
65
+ *
66
+ * @param {string} filePath - File path to test.
67
+ *
68
+ * @returns {boolean} The modulePath is an ES Module.
69
+ * @see https://www.npmjs.com/package/get-package-type
70
+ */
71
+ export declare function isPathModule(filePath: string): boolean;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const path = require("path");
4
- const url = require("url");
5
- const fs_1 = require("fs");
3
+ exports.isPathModule = exports.loadWithDataFromManifest = exports.loadWithData = exports.load = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
6
  const errors_1 = require("./errors");
7
+ const node_url_1 = require("node:url");
7
8
  const config_1 = require("./config");
8
9
  const getPackageType = require('get-package-type');
9
10
  /**
@@ -11,167 +12,196 @@ const getPackageType = require('get-package-type');
11
12
  */
12
13
  // eslint-disable-next-line camelcase
13
14
  const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'];
14
- const isPlugin = (config) => {
15
- return config.type !== undefined;
16
- };
15
+ const isPlugin = (config) => config.type !== undefined;
17
16
  /**
18
- * Provides a static class with several utility methods to work with Oclif config / plugin to load ESM or CJS Node
19
- * modules and source files.
17
+ * Loads and returns a module.
20
18
  *
21
- * @author Michael Leahy <support@typhonjs.io> (https://github.com/typhonrt)
19
+ * Uses `getPackageType` to determine if `type` is set to 'module. If so loads '.js' files as ESM otherwise uses
20
+ * a bare require to load as CJS. Also loads '.mjs' files as ESM.
21
+ *
22
+ * Uses dynamic import to load ESM source or require for CommonJS.
23
+ *
24
+ * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
25
+ * provides a consistent stack trace and info.
26
+ *
27
+ * @param {IConfig|IPlugin} config - Oclif config or plugin config.
28
+ * @param {string} modulePath - NPM module name or file path to load.
29
+ *
30
+ * @returns {Promise<*>} The entire ESM module from dynamic import or CJS module by require.
22
31
  */
23
- // eslint-disable-next-line unicorn/no-static-only-class
24
- class ModuleLoader {
25
- /**
26
- * Loads and returns a module.
27
- *
28
- * Uses `getPackageType` to determine if `type` is set to 'module. If so loads '.js' files as ESM otherwise uses
29
- * a bare require to load as CJS. Also loads '.mjs' files as ESM.
30
- *
31
- * Uses dynamic import to load ESM source or require for CommonJS.
32
- *
33
- * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
34
- * provides a consistent stack trace and info.
35
- *
36
- * @param {IConfig|IPlugin} config - Oclif config or plugin config.
37
- * @param {string} modulePath - NPM module name or file path to load.
38
- *
39
- * @returns {Promise<*>} The entire ESM module from dynamic import or CJS module by require.
40
- */
41
- static async load(config, modulePath) {
42
- let filePath;
43
- let isESM;
44
- try {
45
- ({ isESM, filePath } = ModuleLoader.resolvePath(config, modulePath));
46
- // It is important to await on import to catch the error code.
47
- return isESM ? await import(url.pathToFileURL(filePath).href) : require(filePath);
48
- }
49
- catch (error) {
50
- if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
51
- throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}`);
52
- }
53
- throw error;
54
- }
32
+ async function load(config, modulePath) {
33
+ let filePath;
34
+ let isESM;
35
+ try {
36
+ ({ isESM, filePath } = resolvePath(config, modulePath));
37
+ return isESM ? await import((0, node_url_1.pathToFileURL)(filePath).href) : require(filePath);
55
38
  }
56
- /**
57
- * Loads a module and returns an object with the module and data about the module.
58
- *
59
- * Uses `getPackageType` to determine if `type` is set to `module`. If so loads '.js' files as ESM otherwise uses
60
- * a bare require to load as CJS. Also loads '.mjs' files as ESM.
61
- *
62
- * Uses dynamic import to load ESM source or require for CommonJS.
63
- *
64
- * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
65
- * provides a consistent stack trace and info.
66
- *
67
- * @param {IConfig|IPlugin} config - Oclif config or plugin config.
68
- * @param {string} modulePath - NPM module name or file path to load.
69
- *
70
- * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
71
- * file path and whether the module is ESM.
72
- */
73
- static async loadWithData(config, modulePath) {
74
- let filePath;
75
- let isESM;
76
- try {
77
- ({ isESM, filePath } = ModuleLoader.resolvePath(config, modulePath));
78
- const module = isESM ? await import(url.pathToFileURL(filePath).href) : require(filePath);
79
- return { isESM, module, filePath };
39
+ catch (error) {
40
+ if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
41
+ throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}`);
80
42
  }
81
- catch (error) {
82
- if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
83
- throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}: ${error.message}`);
84
- }
85
- throw error;
43
+ throw error;
44
+ }
45
+ }
46
+ exports.load = load;
47
+ /**
48
+ * Loads a module and returns an object with the module and data about the module.
49
+ *
50
+ * Uses `getPackageType` to determine if `type` is set to `module`. If so loads '.js' files as ESM otherwise uses
51
+ * a bare require to load as CJS. Also loads '.mjs' files as ESM.
52
+ *
53
+ * Uses dynamic import to load ESM source or require for CommonJS.
54
+ *
55
+ * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
56
+ * provides a consistent stack trace and info.
57
+ *
58
+ * @param {IConfig|IPlugin} config - Oclif config or plugin config.
59
+ * @param {string} modulePath - NPM module name or file path to load.
60
+ *
61
+ * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
62
+ * file path and whether the module is ESM.
63
+ */
64
+ async function loadWithData(config, modulePath) {
65
+ let filePath;
66
+ let isESM;
67
+ try {
68
+ ({ isESM, filePath } = resolvePath(config, modulePath));
69
+ const module = isESM ? await import((0, node_url_1.pathToFileURL)(filePath).href) : require(filePath);
70
+ return { isESM, module, filePath };
71
+ }
72
+ catch (error) {
73
+ if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
74
+ throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}: ${error.message}`);
86
75
  }
76
+ throw error;
87
77
  }
88
- /**
89
- * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
90
- * the `modulePath` provided ends in `.mjs` it is assumed to be ESM.
91
- *
92
- * @param {string} filePath - File path to test.
93
- *
94
- * @returns {boolean} The modulePath is an ES Module.
95
- * @see https://www.npmjs.com/package/get-package-type
96
- */
97
- static isPathModule(filePath) {
98
- const extension = path.extname(filePath).toLowerCase();
99
- switch (extension) {
100
- case '.js':
101
- case '.jsx':
102
- case '.ts':
103
- case '.tsx':
104
- return getPackageType.sync(filePath) === 'module';
105
- case '.mjs':
106
- case '.mts':
107
- return true;
108
- default:
109
- return false;
78
+ }
79
+ exports.loadWithData = loadWithData;
80
+ /**
81
+ * Loads a module and returns an object with the module and data about the module.
82
+ *
83
+ * Uses cached `isESM` and `relativePath` in plugin manifest to determine if dynamic import (isESM = true)
84
+ * or require (isESM = false | undefined) should be used.
85
+ *
86
+ * A unique error, ModuleLoadError, combines both CJS and ESM loader module not found errors into a single error that
87
+ * provides a consistent stack trace and info.
88
+ *
89
+ * @param {Command.Cached} cached - Cached command data from plugin manifest.
90
+ * @param {string} modulePath - NPM module name or file path to load.
91
+ *
92
+ * @returns {Promise<{isESM: boolean, module: *, filePath: string}>} An object with the loaded module & data including
93
+ * file path and whether the module is ESM.
94
+ */
95
+ async function loadWithDataFromManifest(cached, modulePath) {
96
+ const { isESM, relativePath, id } = cached;
97
+ if (!relativePath) {
98
+ throw new errors_1.ModuleLoadError(`Cached command ${id} does not have a relative path`);
99
+ }
100
+ if (isESM === undefined) {
101
+ throw new errors_1.ModuleLoadError(`Cached command ${id} does not have the isESM property set`);
102
+ }
103
+ const filePath = (0, node_path_1.join)(modulePath, relativePath.join(node_path_1.sep));
104
+ try {
105
+ const module = isESM ? await import((0, node_url_1.pathToFileURL)(filePath).href) : require(filePath);
106
+ return { isESM, module, filePath };
107
+ }
108
+ catch (error) {
109
+ if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ERR_MODULE_NOT_FOUND') {
110
+ throw new errors_1.ModuleLoadError(`${isESM ? 'import()' : 'require'} failed to load ${filePath || modulePath}: ${error.message}`);
110
111
  }
112
+ throw error;
111
113
  }
112
- /**
113
- * Resolves a modulePath first by `require.resolve` to allow Node to resolve an actual module. If this fails then
114
- * the `modulePath` is resolved from the root of the provided config. `Config.tsPath` is used for initial resolution.
115
- * If this file path does not exist then several extensions are tried from `s_EXTENSIONS` in order: '.js', '.mjs',
116
- * '.cjs'. After a file path has been selected `isPathModule` is used to determine if the file is an ES Module.
117
- *
118
- * @param {IConfig|IPlugin} config - Oclif config or plugin config.
119
- * @param {string} modulePath - File path to load.
120
- *
121
- * @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
122
- */
123
- static resolvePath(config, modulePath) {
124
- let isESM;
125
- let filePath;
126
- try {
127
- filePath = require.resolve(modulePath);
128
- isESM = ModuleLoader.isPathModule(filePath);
114
+ }
115
+ exports.loadWithDataFromManifest = loadWithDataFromManifest;
116
+ /**
117
+ * For `.js` files uses `getPackageType` to determine if `type` is set to `module` in associated `package.json`. If
118
+ * the `modulePath` provided ends in `.mjs` it is assumed to be ESM.
119
+ *
120
+ * @param {string} filePath - File path to test.
121
+ *
122
+ * @returns {boolean} The modulePath is an ES Module.
123
+ * @see https://www.npmjs.com/package/get-package-type
124
+ */
125
+ function isPathModule(filePath) {
126
+ const extension = (0, node_path_1.extname)(filePath).toLowerCase();
127
+ switch (extension) {
128
+ case '.js':
129
+ case '.jsx':
130
+ case '.ts':
131
+ case '.tsx': {
132
+ return getPackageType.sync(filePath) === 'module';
133
+ }
134
+ case '.mjs':
135
+ case '.mts': {
136
+ return true;
129
137
  }
130
- catch {
131
- filePath = (isPlugin(config) ? (0, config_1.tsPath)(config.root, modulePath, config) : (0, config_1.tsPath)(config.root, modulePath)) ?? modulePath;
132
- let fileExists = false;
133
- let isDirectory = false;
134
- if ((0, fs_1.existsSync)(filePath)) {
135
- fileExists = true;
136
- try {
137
- if ((0, fs_1.lstatSync)(filePath)?.isDirectory?.()) {
138
- fileExists = false;
139
- isDirectory = true;
140
- }
138
+ default: {
139
+ return false;
140
+ }
141
+ }
142
+ }
143
+ exports.isPathModule = isPathModule;
144
+ /**
145
+ * Resolves a modulePath first by `require.resolve` to allow Node to resolve an actual module. If this fails then
146
+ * the `modulePath` is resolved from the root of the provided config. `Config.tsPath` is used for initial resolution.
147
+ * If this file path does not exist then several extensions are tried from `s_EXTENSIONS` in order: '.js', '.mjs',
148
+ * '.cjs'. After a file path has been selected `isPathModule` is used to determine if the file is an ES Module.
149
+ *
150
+ * @param {IConfig|IPlugin} config - Oclif config or plugin config.
151
+ * @param {string} modulePath - File path to load.
152
+ *
153
+ * @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
154
+ */
155
+ function resolvePath(config, modulePath) {
156
+ let isESM;
157
+ let filePath;
158
+ try {
159
+ filePath = require.resolve(modulePath);
160
+ isESM = isPathModule(filePath);
161
+ }
162
+ catch {
163
+ filePath = (isPlugin(config) ? (0, config_1.tsPath)(config.root, modulePath, config) : (0, config_1.tsPath)(config.root, modulePath)) ?? modulePath;
164
+ let fileExists = false;
165
+ let isDirectory = false;
166
+ if ((0, node_fs_1.existsSync)(filePath)) {
167
+ fileExists = true;
168
+ try {
169
+ if ((0, node_fs_1.lstatSync)(filePath)?.isDirectory?.()) {
170
+ fileExists = false;
171
+ isDirectory = true;
141
172
  }
142
- catch { }
143
173
  }
144
- if (!fileExists) {
145
- // Try all supported extensions.
146
- let foundPath = ModuleLoader.findFile(filePath);
147
- if (!foundPath && isDirectory) {
148
- // Since filePath is a directory, try looking for index file.
149
- foundPath = ModuleLoader.findFile(path.join(filePath, 'index'));
150
- }
151
- if (foundPath) {
152
- filePath = foundPath;
153
- }
174
+ catch { }
175
+ }
176
+ if (!fileExists) {
177
+ // Try all supported extensions.
178
+ let foundPath = findFile(filePath);
179
+ if (!foundPath && isDirectory) {
180
+ // Since filePath is a directory, try looking for index file.
181
+ foundPath = findFile((0, node_path_1.join)(filePath, 'index'));
182
+ }
183
+ if (foundPath) {
184
+ filePath = foundPath;
154
185
  }
155
- isESM = ModuleLoader.isPathModule(filePath);
156
186
  }
157
- return { isESM, filePath };
187
+ isESM = isPathModule(filePath);
158
188
  }
159
- /**
160
- * Try adding the different extensions from `s_EXTENSIONS` to find the file.
161
- *
162
- * @param {string} filePath - File path to load.
163
- *
164
- * @returns {string | null} Modified file path including extension or null if file is not found.
165
- */
166
- static findFile(filePath) {
167
- // eslint-disable-next-line camelcase
168
- for (const extension of s_EXTENSIONS) {
169
- const testPath = `${filePath}${extension}`;
170
- if ((0, fs_1.existsSync)(testPath)) {
171
- return testPath;
172
- }
189
+ return { isESM, filePath };
190
+ }
191
+ /**
192
+ * Try adding the different extensions from `s_EXTENSIONS` to find the file.
193
+ *
194
+ * @param {string} filePath - File path to load.
195
+ *
196
+ * @returns {string | null} Modified file path including extension or null if file is not found.
197
+ */
198
+ function findFile(filePath) {
199
+ // eslint-disable-next-line camelcase
200
+ for (const extension of s_EXTENSIONS) {
201
+ const testPath = `${filePath}${extension}`;
202
+ if ((0, node_fs_1.existsSync)(testPath)) {
203
+ return testPath;
173
204
  }
174
- return null;
175
205
  }
206
+ return null;
176
207
  }
177
- exports.default = ModuleLoader;
@@ -1,6 +1,6 @@
1
- import { CLIError } from '../errors';
2
- import { OptionFlag, Flag } from '../interfaces';
3
1
  import { Arg, ArgInput, CLIParseErrorOptions } from '../interfaces/parser';
2
+ import { Flag, OptionFlag } from '../interfaces';
3
+ import { CLIError } from '../errors';
4
4
  export { CLIError } from '../errors';
5
5
  export type Validation = {
6
6
  name: string;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const errors_1 = require("../errors");
6
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
5
7
  const help_1 = require("./help");
6
8
  const list_1 = require("../cli-ux/list");
7
- const chalk = require("chalk");
8
- const util_1 = require("../config/util");
9
+ const util_1 = require("../util");
9
10
  var errors_2 = require("../errors");
10
11
  Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
11
12
  class CLIParseError extends errors_1.CLIError {
@@ -91,7 +92,7 @@ class FailedFlagValidationError extends CLIParseError {
91
92
  const reasons = failed.map(r => r.reason);
92
93
  const deduped = (0, util_1.uniq)(reasons);
93
94
  const errString = deduped.length === 1 ? 'error' : 'errors';
94
- const message = `The following ${errString} occurred:\n ${chalk.dim(deduped.join('\n '))}`;
95
+ const message = `The following ${errString} occurred:\n ${chalk_1.default.dim(deduped.join('\n '))}`;
95
96
  super({ parse, message });
96
97
  }
97
98
  }
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flagUsages = exports.flagUsage = void 0;
4
- const chalk = require("chalk");
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
5
6
  const util_1 = require("../util");
6
7
  function flagUsage(flag, options = {}) {
7
8
  const label = [];
@@ -18,7 +19,7 @@ function flagUsage(flag, options = {}) {
18
19
  let description = flag.summary || flag.description || '';
19
20
  if (options.displayRequired && flag.required)
20
21
  description = `(required) ${description}`;
21
- description = description ? chalk.dim(description) : undefined;
22
+ description = description ? chalk_1.default.dim(description) : undefined;
22
23
  return [` ${label.join(',').trim()}${usage}`, description];
23
24
  }
24
25
  exports.flagUsage = flagUsage;
@@ -16,4 +16,7 @@ export declare class Parser<T extends ParserInput, TFlags extends OutputFlags<T[
16
16
  private get _argTokens();
17
17
  private _setNames;
18
18
  private mapAndValidateFlags;
19
+ private findLongFlag;
20
+ private findShortFlag;
21
+ private findFlag;
19
22
  }