@oclif/core 3.0.0-beta.1 → 3.0.0-beta.2
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.d.ts +3 -0
- package/lib/config/config.js +7 -0
- package/lib/config/plugin.d.ts +1 -0
- package/lib/config/plugin.js +2 -1
- package/lib/config/ts-node.d.ts +3 -2
- package/lib/config/ts-node.js +83 -36
- package/lib/errors/errors/cli.d.ts +1 -0
- package/lib/errors/errors/cli.js +1 -0
- package/lib/errors/index.d.ts +1 -0
- package/lib/errors/index.js +8 -1
- package/lib/interfaces/config.d.ts +1 -0
- package/lib/interfaces/pjson.d.ts +1 -0
- package/lib/interfaces/plugin.d.ts +4 -0
- package/lib/interfaces/ts-config.d.ts +9 -0
- package/lib/main.d.ts +5 -10
- package/lib/main.js +9 -16
- package/lib/module-loader.js +5 -5
- package/package.json +8 -6
package/lib/config/config.d.ts
CHANGED
|
@@ -39,8 +39,10 @@ export declare class Config implements IConfig {
|
|
|
39
39
|
private _commands;
|
|
40
40
|
private _topics;
|
|
41
41
|
private _commandIDs;
|
|
42
|
+
private static _rootPlugin;
|
|
42
43
|
constructor(options: Options);
|
|
43
44
|
static load(opts?: LoadOptions): Promise<Config>;
|
|
45
|
+
static get rootPlugin(): Plugin.Plugin | undefined;
|
|
44
46
|
load(): Promise<void>;
|
|
45
47
|
loadPluginsAndCommands(): Promise<void>;
|
|
46
48
|
loadCorePlugins(): Promise<void>;
|
|
@@ -104,6 +106,7 @@ export declare class Config implements IConfig {
|
|
|
104
106
|
get versionDetails(): VersionDetails;
|
|
105
107
|
s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
|
|
106
108
|
s3Url(key: string): string;
|
|
109
|
+
getPluginsList(): IPlugin[];
|
|
107
110
|
protected dir(category: 'cache' | 'data' | 'config'): string;
|
|
108
111
|
protected windowsHome(): string | undefined;
|
|
109
112
|
protected windowsHomedriveHome(): string | undefined;
|
package/lib/config/config.js
CHANGED
|
@@ -83,11 +83,15 @@ class Config {
|
|
|
83
83
|
await config.load();
|
|
84
84
|
return config;
|
|
85
85
|
}
|
|
86
|
+
static get rootPlugin() {
|
|
87
|
+
return Config._rootPlugin;
|
|
88
|
+
}
|
|
86
89
|
// eslint-disable-next-line complexity
|
|
87
90
|
async load() {
|
|
88
91
|
settings_1.settings.performanceEnabled = (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
|
|
89
92
|
const plugin = new Plugin.Plugin({ root: this.options.root });
|
|
90
93
|
await plugin.load();
|
|
94
|
+
Config._rootPlugin = plugin;
|
|
91
95
|
this.plugins.push(plugin);
|
|
92
96
|
this.root = plugin.root;
|
|
93
97
|
this.pjson = plugin.pjson;
|
|
@@ -460,6 +464,9 @@ class Config {
|
|
|
460
464
|
url.pathname = path.join(url.pathname, key);
|
|
461
465
|
return url.toString();
|
|
462
466
|
}
|
|
467
|
+
getPluginsList() {
|
|
468
|
+
return this.plugins;
|
|
469
|
+
}
|
|
463
470
|
dir(category) {
|
|
464
471
|
const base = process.env[`XDG_${category.toUpperCase()}_HOME`] ||
|
|
465
472
|
(this.windows && process.env.LOCALAPPDATA) ||
|
package/lib/config/plugin.d.ts
CHANGED
package/lib/config/plugin.js
CHANGED
|
@@ -115,6 +115,7 @@ class Plugin {
|
|
|
115
115
|
this.root = root;
|
|
116
116
|
this._debug('reading %s plugin %s', this.type, root);
|
|
117
117
|
this.pjson = await (0, util_3.loadJSON)(path.join(root, 'package.json'));
|
|
118
|
+
this.moduleType = this.pjson.type === 'module' ? 'module' : 'commonjs';
|
|
118
119
|
this.name = this.pjson.name;
|
|
119
120
|
this.alias = this.options.name ?? this.pjson.name;
|
|
120
121
|
const pjsonPath = path.join(root, 'package.json');
|
|
@@ -149,7 +150,7 @@ class Plugin {
|
|
|
149
150
|
get commandsDir() {
|
|
150
151
|
if (this._commandsDir)
|
|
151
152
|
return this._commandsDir;
|
|
152
|
-
this._commandsDir = (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this
|
|
153
|
+
this._commandsDir = (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this);
|
|
153
154
|
return this._commandsDir;
|
|
154
155
|
}
|
|
155
156
|
get commandIDs() {
|
package/lib/config/ts-node.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Plugin } from '../interfaces';
|
|
1
2
|
/**
|
|
2
3
|
* Convert a path from the compiled ./lib files to the ./src typescript source
|
|
3
4
|
* this is for developing typescript plugins/CLIs
|
|
4
5
|
* if there is a tsconfig and the original sources exist, it attempts to require ts-node
|
|
5
6
|
*/
|
|
6
|
-
export declare function tsPath(root: string, orig: string,
|
|
7
|
-
export declare function tsPath(root: string, orig: string | undefined,
|
|
7
|
+
export declare function tsPath(root: string, orig: string, plugin: Plugin): string;
|
|
8
|
+
export declare function tsPath(root: string, orig: string | undefined, plugin?: Plugin): string | undefined;
|
package/lib/config/ts-node.js
CHANGED
|
@@ -6,11 +6,15 @@ const path = require("path");
|
|
|
6
6
|
const settings_1 = require("../settings");
|
|
7
7
|
const util_1 = require("../util");
|
|
8
8
|
const util_2 = require("./util");
|
|
9
|
+
const config_1 = require("./config");
|
|
10
|
+
const errors_1 = require("../errors");
|
|
9
11
|
// eslint-disable-next-line new-cap
|
|
10
12
|
const debug = (0, util_2.Debug)('ts-node');
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
+
const TS_CONFIGS = {};
|
|
14
|
+
const REGISTERED = new Set();
|
|
13
15
|
function loadTSConfig(root) {
|
|
16
|
+
if (TS_CONFIGS[root])
|
|
17
|
+
return TS_CONFIGS[root];
|
|
14
18
|
const tsconfigPath = path.join(root, 'tsconfig.json');
|
|
15
19
|
let typescript;
|
|
16
20
|
try {
|
|
@@ -18,7 +22,7 @@ function loadTSConfig(root) {
|
|
|
18
22
|
}
|
|
19
23
|
catch {
|
|
20
24
|
try {
|
|
21
|
-
typescript = require(root
|
|
25
|
+
typescript = require(path.join(root, 'node_modules', 'typescript'));
|
|
22
26
|
}
|
|
23
27
|
catch { }
|
|
24
28
|
}
|
|
@@ -28,6 +32,7 @@ function loadTSConfig(root) {
|
|
|
28
32
|
throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it ` +
|
|
29
33
|
'did not contain a "compilerOptions" section.');
|
|
30
34
|
}
|
|
35
|
+
TS_CONFIGS[root] = tsconfig;
|
|
31
36
|
return tsconfig;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -35,54 +40,96 @@ function registerTSNode(root) {
|
|
|
35
40
|
const tsconfig = loadTSConfig(root);
|
|
36
41
|
if (!tsconfig)
|
|
37
42
|
return;
|
|
43
|
+
if (REGISTERED.has(root))
|
|
44
|
+
return tsconfig;
|
|
38
45
|
debug('registering ts-node at', root);
|
|
39
46
|
const tsNodePath = require.resolve('ts-node', { paths: [root, __dirname] });
|
|
47
|
+
debug('ts-node path:', tsNodePath);
|
|
40
48
|
const tsNode = require(tsNodePath);
|
|
41
|
-
|
|
49
|
+
const typeRoots = [
|
|
50
|
+
path.join(root, 'node_modules', '@types'),
|
|
51
|
+
];
|
|
52
|
+
const rootDirs = [];
|
|
42
53
|
if (tsconfig.compilerOptions.rootDirs) {
|
|
43
|
-
|
|
54
|
+
for (const r of tsconfig.compilerOptions.rootDirs) {
|
|
55
|
+
rootDirs.push(path.join(root, r));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (tsconfig.compilerOptions.rootDir) {
|
|
59
|
+
rootDirs.push(path.join(root, tsconfig.compilerOptions.rootDir));
|
|
44
60
|
}
|
|
45
61
|
else {
|
|
46
|
-
|
|
62
|
+
rootDirs.push(path.join(root, 'src'));
|
|
47
63
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const conf = {
|
|
65
|
+
compilerOptions: {
|
|
66
|
+
esModuleInterop: tsconfig.compilerOptions.esModuleInterop,
|
|
67
|
+
target: tsconfig.compilerOptions.target ?? 'es2019',
|
|
68
|
+
experimentalDecorators: tsconfig.compilerOptions.experimentalDecorators ?? false,
|
|
69
|
+
emitDecoratorMetadata: tsconfig.compilerOptions.emitDecoratorMetadata ?? false,
|
|
70
|
+
module: tsconfig.compilerOptions.module ?? 'commonjs',
|
|
71
|
+
sourceMap: tsconfig.compilerOptions.sourceMap ?? true,
|
|
72
|
+
rootDirs,
|
|
73
|
+
typeRoots,
|
|
74
|
+
},
|
|
75
|
+
skipProject: true,
|
|
76
|
+
transpileOnly: true,
|
|
77
|
+
esm: tsconfig['ts-node']?.esm ?? true,
|
|
78
|
+
scope: true,
|
|
79
|
+
scopeDir: root,
|
|
80
|
+
cwd: root,
|
|
81
|
+
experimentalSpecifierResolution: tsconfig['ts-node']?.experimentalSpecifierResolution ?? 'explicit',
|
|
82
|
+
};
|
|
83
|
+
if (tsconfig.compilerOptions.moduleResolution) {
|
|
84
|
+
// @ts-expect-error TSNode.RegisterOptions.compilerOptions is typed as a plain object
|
|
85
|
+
conf.compilerOptions.moduleResolution = tsconfig.compilerOptions.moduleResolution;
|
|
67
86
|
}
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
if (tsconfig.compilerOptions.jsx) {
|
|
88
|
+
// @ts-expect-error TSNode.RegisterOptions.compilerOptions is typed as a plain object
|
|
89
|
+
conf.compilerOptions.jsx = tsconfig.compilerOptions.jsx;
|
|
70
90
|
}
|
|
91
|
+
tsNode.register(conf);
|
|
92
|
+
REGISTERED.add(root);
|
|
93
|
+
return tsconfig;
|
|
71
94
|
}
|
|
72
|
-
|
|
95
|
+
// eslint-disable-next-line complexity
|
|
96
|
+
function tsPath(root, orig, plugin) {
|
|
73
97
|
if (!orig)
|
|
74
98
|
return orig;
|
|
75
99
|
orig = orig.startsWith(root) ? orig : path.join(root, orig);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
//
|
|
82
|
-
if (
|
|
100
|
+
// NOTE: The order of these checks matter!
|
|
101
|
+
if (settings_1.settings.tsnodeEnabled === false) {
|
|
102
|
+
debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
|
|
103
|
+
return orig;
|
|
104
|
+
}
|
|
105
|
+
// Skip ts-node registration if plugin is an ESM plugin executing from a CJS plugin
|
|
106
|
+
if (plugin?.moduleType === 'module' && config_1.Config.rootPlugin?.moduleType === 'commonjs') {
|
|
107
|
+
debug(`Skipping ts-node registration for ${root} because it's an ESM module but the root plugin is CommonJS`);
|
|
108
|
+
if (plugin.type === 'link')
|
|
109
|
+
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-compiled from a CommonJS root plugin. Existing compiled source will be used instead.`);
|
|
83
110
|
return orig;
|
|
111
|
+
}
|
|
112
|
+
// If plugin is an ESM plugin being executed from an ESM root plugin, check to see if ts-node/esm loader has been set
|
|
113
|
+
// either in the NODE_OPTIONS env var or from the exec args. If the ts-node/esm loader has NOT been loaded then we want
|
|
114
|
+
// to skip ts-node registration so that it falls back on the compiled source.
|
|
115
|
+
if (plugin?.moduleType === 'module') {
|
|
116
|
+
const tsNodeEsmLoaderInExecArgv = process.execArgv.includes('--loader') && process.execArgv.includes('ts-node/esm');
|
|
117
|
+
const tsNodeEsmLoaderInNodeOptions = process.env.NODE_OPTIONS?.includes('--loader=ts-node/esm') ?? false;
|
|
118
|
+
if (!tsNodeEsmLoaderInExecArgv && !tsNodeEsmLoaderInNodeOptions) {
|
|
119
|
+
debug(`Skipping ts-node registration for ${root} because it's an ESM module but the ts-node/esm loader hasn't been run`);
|
|
120
|
+
debug('try setting NODE_OPTIONS="--loader ts-node/esm" in your environment.');
|
|
121
|
+
if (plugin.type === 'link') {
|
|
122
|
+
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-compiled without setting NODE_OPTIONS="--loader=ts-node/esm" in the environment. Existing compiled source will be used instead.`);
|
|
123
|
+
}
|
|
124
|
+
return orig;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (settings_1.settings.tsnodeEnabled === undefined && (0, util_1.isProd)() && plugin?.type !== 'link') {
|
|
128
|
+
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
|
|
129
|
+
return orig;
|
|
130
|
+
}
|
|
84
131
|
try {
|
|
85
|
-
const tsconfig =
|
|
132
|
+
const tsconfig = registerTSNode(root);
|
|
86
133
|
if (!tsconfig)
|
|
87
134
|
return orig;
|
|
88
135
|
const { rootDir, rootDirs, outDir } = tsconfig.compilerOptions;
|
|
@@ -8,6 +8,7 @@ export declare function addOclifExitCode(error: Record<string, any>, options?: {
|
|
|
8
8
|
export declare class CLIError extends Error implements OclifError {
|
|
9
9
|
oclif: OclifError['oclif'];
|
|
10
10
|
code?: string;
|
|
11
|
+
suggestions?: string[];
|
|
11
12
|
constructor(error: string | Error, options?: {
|
|
12
13
|
exit?: number | false;
|
|
13
14
|
} & PrettyPrintableError);
|
package/lib/errors/errors/cli.js
CHANGED
package/lib/errors/index.d.ts
CHANGED
package/lib/errors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.warn = exports.error = exports.exit = exports.config = exports.Logger = exports.CLIError = exports.ModuleLoadError = exports.ExitError = exports.handle = void 0;
|
|
3
|
+
exports.memoizedWarn = exports.warn = exports.error = exports.exit = exports.config = exports.Logger = exports.CLIError = exports.ModuleLoadError = exports.ExitError = exports.handle = void 0;
|
|
4
4
|
var handle_1 = require("./handle");
|
|
5
5
|
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
|
6
6
|
var exit_1 = require("./errors/exit");
|
|
@@ -60,3 +60,10 @@ function warn(input) {
|
|
|
60
60
|
config_2.config.errorLogger.log(err?.stack ?? '');
|
|
61
61
|
}
|
|
62
62
|
exports.warn = warn;
|
|
63
|
+
const WARNINGS = new Set();
|
|
64
|
+
function memoizedWarn(input) {
|
|
65
|
+
if (!WARNINGS.has(input))
|
|
66
|
+
warn(input);
|
|
67
|
+
WARNINGS.add(input);
|
|
68
|
+
}
|
|
69
|
+
exports.memoizedWarn = memoizedWarn;
|
|
@@ -135,6 +135,7 @@ export interface Config {
|
|
|
135
135
|
s3Url(key: string): string;
|
|
136
136
|
s3Key(type: 'versioned' | 'unversioned', ext: '.tar.gz' | '.tar.xz', options?: Config.s3Key.Options): string;
|
|
137
137
|
s3Key(type: keyof PJSON.S3.Templates, options?: Config.s3Key.Options): string;
|
|
138
|
+
getPluginsList(): Plugin[];
|
|
138
139
|
}
|
|
139
140
|
export declare namespace Config {
|
|
140
141
|
namespace s3Key {
|
|
@@ -7,5 +7,14 @@ export interface TSConfig {
|
|
|
7
7
|
esModuleInterop?: boolean;
|
|
8
8
|
experimentalDecorators?: boolean;
|
|
9
9
|
emitDecoratorMetadata?: boolean;
|
|
10
|
+
module?: string;
|
|
11
|
+
moduleResolution?: string;
|
|
12
|
+
sourceMap?: boolean;
|
|
13
|
+
jsx?: boolean;
|
|
14
|
+
};
|
|
15
|
+
'ts-node'?: {
|
|
16
|
+
esm?: boolean;
|
|
17
|
+
experimentalSpecifierResolution?: 'node' | 'explicit';
|
|
18
|
+
scope?: boolean;
|
|
10
19
|
};
|
|
11
20
|
}
|
package/lib/main.d.ts
CHANGED
|
@@ -11,46 +11,41 @@ export declare function run(argv?: string[], options?: Interfaces.LoadOptions):
|
|
|
11
11
|
*
|
|
12
12
|
* @example For ESM dev.js
|
|
13
13
|
* ```
|
|
14
|
-
* #!/usr/bin/env
|
|
15
|
-
* // eslint-disable-next-line node/shebang
|
|
14
|
+
* #!/usr/bin/env node
|
|
16
15
|
* (async () => {
|
|
17
16
|
* const oclif = await import('@oclif/core')
|
|
18
|
-
* await oclif.execute({
|
|
17
|
+
* await oclif.execute({development: true, dir: import.meta.url})
|
|
19
18
|
* })()
|
|
20
19
|
* ```
|
|
21
20
|
*
|
|
22
21
|
* @example For ESM run.js
|
|
23
22
|
* ```
|
|
24
23
|
* #!/usr/bin/env node
|
|
25
|
-
* // eslint-disable-next-line node/shebang
|
|
26
24
|
* (async () => {
|
|
27
25
|
* const oclif = await import('@oclif/core')
|
|
28
|
-
* await oclif.execute({
|
|
26
|
+
* await oclif.execute({dir: import.meta.url})
|
|
29
27
|
* })()
|
|
30
28
|
* ```
|
|
31
29
|
*
|
|
32
30
|
* @example For CJS dev.js
|
|
33
31
|
* ```
|
|
34
32
|
* #!/usr/bin/env node
|
|
35
|
-
* // eslint-disable-next-line node/shebang
|
|
36
33
|
* (async () => {
|
|
37
34
|
* const oclif = await import('@oclif/core')
|
|
38
|
-
* await oclif.execute({
|
|
35
|
+
* await oclif.execute({development: true, dir: __dirname})
|
|
39
36
|
* })()
|
|
40
37
|
* ```
|
|
41
38
|
*
|
|
42
39
|
* @example For CJS run.js
|
|
43
40
|
* ```
|
|
44
41
|
* #!/usr/bin/env node
|
|
45
|
-
* // eslint-disable-next-line node/shebang
|
|
46
42
|
* (async () => {
|
|
47
43
|
* const oclif = await import('@oclif/core')
|
|
48
|
-
* await oclif.execute({
|
|
44
|
+
* await oclif.execute({dir: __dirname})
|
|
49
45
|
* })()
|
|
50
46
|
* ```
|
|
51
47
|
*/
|
|
52
48
|
export declare function execute(options: {
|
|
53
|
-
type: 'cjs' | 'esm';
|
|
54
49
|
dir: string;
|
|
55
50
|
args?: string[];
|
|
56
51
|
loadOptions?: Interfaces.LoadOptions;
|
package/lib/main.js
CHANGED
|
@@ -8,9 +8,9 @@ const config_1 = require("./config");
|
|
|
8
8
|
const help_1 = require("./help");
|
|
9
9
|
const settings_1 = require("./settings");
|
|
10
10
|
const _1 = require(".");
|
|
11
|
-
const path_1 = require("path");
|
|
12
11
|
const stream_1 = require("./cli-ux/stream");
|
|
13
12
|
const performance_1 = require("./performance");
|
|
13
|
+
const debug = require('debug')('oclif:main');
|
|
14
14
|
const log = (message = '', ...args) => {
|
|
15
15
|
message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
|
|
16
16
|
stream_1.stdout.write((0, util_1.format)(message, ...args) + '\n');
|
|
@@ -45,6 +45,9 @@ async function run(argv, options) {
|
|
|
45
45
|
await performance_1.Performance.collect();
|
|
46
46
|
performance_1.Performance.debug();
|
|
47
47
|
};
|
|
48
|
+
debug(`process.execPath: ${process.execPath}`);
|
|
49
|
+
debug(`process.execArgv: ${process.execArgv}`);
|
|
50
|
+
debug('process.argv: %O', process.argv);
|
|
48
51
|
argv = argv ?? process.argv.slice(2);
|
|
49
52
|
// Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
|
|
50
53
|
if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
|
|
@@ -93,9 +96,6 @@ async function run(argv, options) {
|
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
exports.run = run;
|
|
96
|
-
function getTsConfigPath(dir, type) {
|
|
97
|
-
return type === 'cjs' ? (0, path_1.join)(dir, '..', 'tsconfig.json') : (0, path_1.join)((0, path_1.dirname)((0, url_1.fileURLToPath)(dir)), '..', 'tsconfig.json');
|
|
98
|
-
}
|
|
99
99
|
/**
|
|
100
100
|
* Load and run oclif CLI
|
|
101
101
|
*
|
|
@@ -104,41 +104,37 @@ function getTsConfigPath(dir, type) {
|
|
|
104
104
|
*
|
|
105
105
|
* @example For ESM dev.js
|
|
106
106
|
* ```
|
|
107
|
-
* #!/usr/bin/env
|
|
108
|
-
* // eslint-disable-next-line node/shebang
|
|
107
|
+
* #!/usr/bin/env node
|
|
109
108
|
* (async () => {
|
|
110
109
|
* const oclif = await import('@oclif/core')
|
|
111
|
-
* await oclif.execute({
|
|
110
|
+
* await oclif.execute({development: true, dir: import.meta.url})
|
|
112
111
|
* })()
|
|
113
112
|
* ```
|
|
114
113
|
*
|
|
115
114
|
* @example For ESM run.js
|
|
116
115
|
* ```
|
|
117
116
|
* #!/usr/bin/env node
|
|
118
|
-
* // eslint-disable-next-line node/shebang
|
|
119
117
|
* (async () => {
|
|
120
118
|
* const oclif = await import('@oclif/core')
|
|
121
|
-
* await oclif.execute({
|
|
119
|
+
* await oclif.execute({dir: import.meta.url})
|
|
122
120
|
* })()
|
|
123
121
|
* ```
|
|
124
122
|
*
|
|
125
123
|
* @example For CJS dev.js
|
|
126
124
|
* ```
|
|
127
125
|
* #!/usr/bin/env node
|
|
128
|
-
* // eslint-disable-next-line node/shebang
|
|
129
126
|
* (async () => {
|
|
130
127
|
* const oclif = await import('@oclif/core')
|
|
131
|
-
* await oclif.execute({
|
|
128
|
+
* await oclif.execute({development: true, dir: __dirname})
|
|
132
129
|
* })()
|
|
133
130
|
* ```
|
|
134
131
|
*
|
|
135
132
|
* @example For CJS run.js
|
|
136
133
|
* ```
|
|
137
134
|
* #!/usr/bin/env node
|
|
138
|
-
* // eslint-disable-next-line node/shebang
|
|
139
135
|
* (async () => {
|
|
140
136
|
* const oclif = await import('@oclif/core')
|
|
141
|
-
* await oclif.execute({
|
|
137
|
+
* await oclif.execute({dir: __dirname})
|
|
142
138
|
* })()
|
|
143
139
|
* ```
|
|
144
140
|
*/
|
|
@@ -146,9 +142,6 @@ async function execute(options) {
|
|
|
146
142
|
if (options.development) {
|
|
147
143
|
// In dev mode -> use ts-node and dev plugins
|
|
148
144
|
process.env.NODE_ENV = 'development';
|
|
149
|
-
require('ts-node').register({
|
|
150
|
-
project: getTsConfigPath(options.dir, options.type),
|
|
151
|
-
});
|
|
152
145
|
settings_1.settings.debug = true;
|
|
153
146
|
}
|
|
154
147
|
await run(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
|
package/lib/module-loader.js
CHANGED
|
@@ -4,13 +4,16 @@ const path = require("path");
|
|
|
4
4
|
const url = require("url");
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
|
-
const
|
|
7
|
+
const config_1 = require("./config");
|
|
8
8
|
const getPackageType = require('get-package-type');
|
|
9
9
|
/**
|
|
10
10
|
* Defines file extension resolution when source files do not have an extension.
|
|
11
11
|
*/
|
|
12
12
|
// eslint-disable-next-line camelcase
|
|
13
13
|
const s_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs'];
|
|
14
|
+
const isPlugin = (config) => {
|
|
15
|
+
return config.type !== undefined;
|
|
16
|
+
};
|
|
14
17
|
/**
|
|
15
18
|
* Provides a static class with several utility methods to work with Oclif config / plugin to load ESM or CJS Node
|
|
16
19
|
* modules and source files.
|
|
@@ -120,15 +123,12 @@ class ModuleLoader {
|
|
|
120
123
|
static resolvePath(config, modulePath) {
|
|
121
124
|
let isESM;
|
|
122
125
|
let filePath;
|
|
123
|
-
const isPlugin = (config) => {
|
|
124
|
-
return config.type !== undefined;
|
|
125
|
-
};
|
|
126
126
|
try {
|
|
127
127
|
filePath = require.resolve(modulePath);
|
|
128
128
|
isESM = ModuleLoader.isPathModule(filePath);
|
|
129
129
|
}
|
|
130
130
|
catch {
|
|
131
|
-
filePath = isPlugin(config) ?
|
|
131
|
+
filePath = (isPlugin(config) ? (0, config_1.tsPath)(config.root, modulePath, config) : (0, config_1.tsPath)(config.root, modulePath)) ?? modulePath;
|
|
132
132
|
let fileExists = false;
|
|
133
133
|
let isDirectory = false;
|
|
134
134
|
if (fs.existsSync(filePath)) {
|
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.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.2",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -66,13 +66,14 @@
|
|
|
66
66
|
"chai": "^4.3.7",
|
|
67
67
|
"chai-as-promised": "^7.1.1",
|
|
68
68
|
"commitlint": "^12.1.4",
|
|
69
|
+
"cross-env": "^7.0.3",
|
|
69
70
|
"eslint": "^7.32.0",
|
|
70
71
|
"eslint-config-oclif": "^4.0.0",
|
|
71
72
|
"eslint-config-oclif-typescript": "^1.0.3",
|
|
72
73
|
"fancy-test": "^2.0.16",
|
|
73
74
|
"globby": "^11.1.0",
|
|
74
75
|
"husky": "6",
|
|
75
|
-
"mocha": "^
|
|
76
|
+
"mocha": "^10.2.0",
|
|
76
77
|
"nock": "^13.3.0",
|
|
77
78
|
"proxyquire": "^2.1.3",
|
|
78
79
|
"shelljs": "^0.8.5",
|
|
@@ -110,14 +111,15 @@
|
|
|
110
111
|
"scripts": {
|
|
111
112
|
"build": "shx rm -rf lib && tsc",
|
|
112
113
|
"commitlint": "commitlint",
|
|
114
|
+
"compile": "tsc",
|
|
113
115
|
"lint": "eslint . --ext .ts --config .eslintrc",
|
|
114
116
|
"posttest": "yarn lint",
|
|
115
|
-
"compile": "tsc",
|
|
116
117
|
"prepack": "yarn run build",
|
|
117
|
-
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
|
|
118
|
-
"test:e2e": "mocha --forbid-only \"test/**/*.e2e.ts\" --timeout 1200000",
|
|
119
118
|
"pretest": "yarn build --noEmit && tsc -p test --noEmit --skipLibCheck",
|
|
120
|
-
"test:
|
|
119
|
+
"test:e2e": "mocha --forbid-only \"test/**/*.e2e.ts\" --parallel --timeout 1200000",
|
|
120
|
+
"test:esm-cjs": "cross-env DEBUG=e2e:* ts-node test/integration/esm-cjs.ts",
|
|
121
|
+
"test:perf": "ts-node test/perf/parser.perf.ts",
|
|
122
|
+
"test": "mocha --forbid-only \"test/**/*.test.ts\""
|
|
121
123
|
},
|
|
122
124
|
"types": "lib/index.d.ts"
|
|
123
125
|
}
|