@oclif/core 4.0.0-beta.14 → 4.0.0-beta.16
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/ts-path.js +29 -6
- package/lib/help/command.js +6 -7
- package/lib/help/docopts.d.ts +1 -0
- package/lib/help/docopts.js +23 -2
- package/lib/interfaces/parser.d.ts +1 -1
- package/package.json +2 -2
package/lib/config/ts-path.js
CHANGED
|
@@ -78,6 +78,24 @@ async function loadTSConfig(root) {
|
|
|
78
78
|
(0, warn_1.memoizedWarn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
async function registerTsx(root, moduleType) {
|
|
82
|
+
if (REGISTERED.has(root))
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
const apiPath = moduleType === 'module' ? 'tsx/esm/api' : 'tsx/cjs/api';
|
|
86
|
+
const tsxPath = require.resolve(apiPath, { paths: [root] });
|
|
87
|
+
if (!tsxPath)
|
|
88
|
+
return;
|
|
89
|
+
debug('registering tsx at', root);
|
|
90
|
+
debug('tsx path:', tsxPath);
|
|
91
|
+
const { register } = await import(tsxPath);
|
|
92
|
+
register();
|
|
93
|
+
REGISTERED.add(root);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
debug(`Could not find tsx. Skipping tsx registration for ${root}.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
81
99
|
async function registerTSNode(root, tsconfig) {
|
|
82
100
|
if (REGISTERED.has(root))
|
|
83
101
|
return;
|
|
@@ -135,18 +153,20 @@ async function registerTSNode(root, tsconfig) {
|
|
|
135
153
|
}
|
|
136
154
|
/**
|
|
137
155
|
* Skip ts-node registration for ESM plugins in production.
|
|
138
|
-
* The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
|
|
156
|
+
* The node/ts-node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
|
|
139
157
|
* See the following:
|
|
140
158
|
* - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228
|
|
141
159
|
* - https://github.com/nodejs/node/issues/49432
|
|
142
160
|
* - https://github.com/nodejs/node/pull/49407
|
|
143
161
|
* - https://github.com/nodejs/node/issues/34049
|
|
144
162
|
*
|
|
145
|
-
* We still register ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM
|
|
163
|
+
* We still register tsx/ts-node for ESM plugins when NODE_ENV is "test" or "development" and root plugin is also ESM
|
|
146
164
|
* since that allows plugins to be auto-transpiled when developing locally using `bin/dev.js`.
|
|
147
165
|
*/
|
|
148
166
|
function cannotTranspileEsm(rootPlugin, plugin, isProduction) {
|
|
149
|
-
return (isProduction || rootPlugin?.moduleType === 'commonjs') &&
|
|
167
|
+
return ((isProduction || rootPlugin?.moduleType === 'commonjs') &&
|
|
168
|
+
plugin?.moduleType === 'module' &&
|
|
169
|
+
!plugin?.pjson.devDependencies?.tsx);
|
|
150
170
|
}
|
|
151
171
|
/**
|
|
152
172
|
* If the dev script is run with ts-node for an ESM plugin, skip ts-node registration
|
|
@@ -166,15 +186,18 @@ function cannotUseTsNode(root, plugin, isProduction) {
|
|
|
166
186
|
/**
|
|
167
187
|
* Determine the path to the source file from the compiled ./lib files
|
|
168
188
|
*/
|
|
169
|
-
async function determinePath(root, orig) {
|
|
189
|
+
async function determinePath(root, orig, plugin) {
|
|
170
190
|
const tsconfig = await loadTSConfig(root);
|
|
171
191
|
if (!tsconfig)
|
|
172
192
|
return orig;
|
|
173
193
|
debug(`Determining path for ${orig}`);
|
|
174
|
-
if (RUN_TIME === '
|
|
194
|
+
if (RUN_TIME === 'bun') {
|
|
175
195
|
debug(`Skipping ts-node registration for ${root} because the runtime is: ${RUN_TIME}`);
|
|
176
196
|
}
|
|
177
197
|
else {
|
|
198
|
+
// attempt to register tsx first. If it fails to register, we will fall back to ts-node
|
|
199
|
+
await registerTsx(root, plugin?.moduleType);
|
|
200
|
+
// if tsx registration succeeded, then this will exit early since the path will be in REGISTERED already
|
|
178
201
|
await registerTSNode(root, tsconfig);
|
|
179
202
|
}
|
|
180
203
|
const { baseUrl, outDir, rootDir, rootDirs } = tsconfig.compilerOptions;
|
|
@@ -251,7 +274,7 @@ async function tsPath(root, orig, plugin) {
|
|
|
251
274
|
return orig;
|
|
252
275
|
}
|
|
253
276
|
try {
|
|
254
|
-
return await determinePath(root, orig);
|
|
277
|
+
return await determinePath(root, orig, plugin);
|
|
255
278
|
}
|
|
256
279
|
catch (error) {
|
|
257
280
|
debug(error);
|
package/lib/help/command.js
CHANGED
|
@@ -153,12 +153,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
153
153
|
label = labels.join(flag.char ? (0, theme_1.colorize)(this.config?.theme?.flagSeparator, ', ') : ' ');
|
|
154
154
|
}
|
|
155
155
|
if (flag.type === 'option') {
|
|
156
|
-
let value = flag
|
|
157
|
-
if (!flag.helpValue && flag.options) {
|
|
158
|
-
value = showOptions || this.opts.showFlagOptionsInTitle ? `${flag.options.join('|')}` : '<option>';
|
|
159
|
-
}
|
|
160
|
-
if (flag.multiple)
|
|
161
|
-
value += '...';
|
|
156
|
+
let value = docopts_1.DocOpts.formatUsageType(flag, this.opts.showFlagNameInTitle ?? false, this.opts.showFlagOptionsInTitle ?? showOptions);
|
|
162
157
|
if (!value.includes('|'))
|
|
163
158
|
value = ansis_1.default.underline(value);
|
|
164
159
|
label += `=${value}`;
|
|
@@ -304,7 +299,11 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
304
299
|
const dollarSign = (0, theme_1.colorize)(this.config?.theme?.dollarSign, '$');
|
|
305
300
|
const bin = (0, theme_1.colorize)(this.config?.theme?.bin, this.config.bin);
|
|
306
301
|
const command = (0, theme_1.colorize)(this.config?.theme?.command, '<%= command.id %>');
|
|
307
|
-
const commandDescription = (0, theme_1.colorize)(this.config?.theme?.sectionDescription, u
|
|
302
|
+
const commandDescription = (0, theme_1.colorize)(this.config?.theme?.sectionDescription, u
|
|
303
|
+
.replace('<%= command.id %>', '')
|
|
304
|
+
.replace(new RegExp(`^${standardId}`), '')
|
|
305
|
+
.replace(new RegExp(`^${configuredId}`), '')
|
|
306
|
+
.trim());
|
|
308
307
|
const line = `${dollarSign} ${bin} ${command} ${commandDescription}`.trim();
|
|
309
308
|
if (line.length > allowedSpacing) {
|
|
310
309
|
const splitIndex = line.slice(0, Math.max(0, allowedSpacing)).lastIndexOf(' ');
|
package/lib/help/docopts.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export declare class DocOpts {
|
|
|
60
60
|
private flagList;
|
|
61
61
|
private flagMap;
|
|
62
62
|
constructor(cmd: Command.Loadable);
|
|
63
|
+
static formatUsageType(flag: Command.Flag.Any, showFlagName: boolean, showOptions: boolean): string;
|
|
63
64
|
static generate(cmd: Command.Loadable): string;
|
|
64
65
|
toString(): string;
|
|
65
66
|
private combineElementsToFlag;
|
package/lib/help/docopts.js
CHANGED
|
@@ -73,6 +73,27 @@ class DocOpts {
|
|
|
73
73
|
return flag;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
+
static formatUsageType(flag, showFlagName, showOptions) {
|
|
77
|
+
if (flag.type !== 'option')
|
|
78
|
+
return '';
|
|
79
|
+
let helpValues;
|
|
80
|
+
if (flag.helpValue) {
|
|
81
|
+
// if there is a given helpValue, use it
|
|
82
|
+
helpValues = typeof flag.helpValue === 'string' ? [flag.helpValue] : flag.helpValue;
|
|
83
|
+
}
|
|
84
|
+
else if (flag.options) {
|
|
85
|
+
// if there are options, show them if wanted
|
|
86
|
+
helpValues = [showOptions ? flag.options.join('|') : '<option>'];
|
|
87
|
+
}
|
|
88
|
+
else if (showFlagName) {
|
|
89
|
+
helpValues = [flag.name];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// default to <value>
|
|
93
|
+
helpValues = ['<value>'];
|
|
94
|
+
}
|
|
95
|
+
return helpValues.map((v) => `${v}${flag.multiple ? '...' : ''}`).join(' ');
|
|
96
|
+
}
|
|
76
97
|
static generate(cmd) {
|
|
77
98
|
return new DocOpts(cmd).toString();
|
|
78
99
|
}
|
|
@@ -93,7 +114,7 @@ class DocOpts {
|
|
|
93
114
|
const name = flag.char ? `-${flag.char}` : `--${flag.name}`;
|
|
94
115
|
if (flag.type === 'boolean')
|
|
95
116
|
return name;
|
|
96
|
-
return `${name}
|
|
117
|
+
return `${name}=${DocOpts.formatUsageType(flag, false, true)}`;
|
|
97
118
|
}));
|
|
98
119
|
}
|
|
99
120
|
return opts.join(' ');
|
|
@@ -123,7 +144,7 @@ class DocOpts {
|
|
|
123
144
|
// not all flags have short names
|
|
124
145
|
const flagName = flag.char ? `-${flag.char}` : `--${flag.name}`;
|
|
125
146
|
if (flag.type === 'option') {
|
|
126
|
-
type =
|
|
147
|
+
type = ` ${DocOpts.formatUsageType(flag, false, true)}`;
|
|
127
148
|
}
|
|
128
149
|
const element = `${flagName}${type}`;
|
|
129
150
|
elementMap[flag.name] = element;
|
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.16",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"clean-stack": "^3.0.1",
|
|
11
11
|
"cli-spinners": "^2.9.2",
|
|
12
12
|
"cosmiconfig": "^9.0.0",
|
|
13
|
-
"debug": "^4.3.
|
|
13
|
+
"debug": "^4.3.5",
|
|
14
14
|
"ejs": "^3.1.10",
|
|
15
15
|
"get-package-type": "^0.1.0",
|
|
16
16
|
"globby": "^11.1.0",
|