@oclif/core 3.0.0-beta.11 → 3.0.0-beta.13
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.js +29 -31
- package/lib/config/ts-node.js +10 -21
- package/package.json +1 -1
package/lib/config/config.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toCached = exports.Config = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
|
+
const node_util_1 = require("node:util");
|
|
6
|
+
const node_os_1 = require("node:os");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
5
8
|
const ejs = require("ejs");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const util_1 = require("util");
|
|
10
|
-
const util_2 = require("./util");
|
|
11
|
-
const util_3 = require("../util");
|
|
9
|
+
const errors_1 = require("../errors");
|
|
10
|
+
const util_1 = require("./util");
|
|
11
|
+
const util_2 = require("../util");
|
|
12
12
|
const module_loader_1 = require("../module-loader");
|
|
13
13
|
const help_1 = require("../help");
|
|
14
14
|
const stream_1 = require("../cli-ux/stream");
|
|
15
15
|
const performance_1 = require("../performance");
|
|
16
16
|
const settings_1 = require("../settings");
|
|
17
|
-
const node_os_1 = require("node:os");
|
|
18
|
-
const node_path_1 = require("node:path");
|
|
19
17
|
const plugin_loader_1 = require("./plugin-loader");
|
|
20
18
|
// eslint-disable-next-line new-cap
|
|
21
|
-
const debug = (0,
|
|
22
|
-
const _pjson = (0,
|
|
19
|
+
const debug = (0, util_1.Debug)();
|
|
20
|
+
const _pjson = (0, util_2.requireJson)(__dirname, '..', '..', 'package.json');
|
|
23
21
|
const BASE = `${_pjson.name}@${_pjson.version}`;
|
|
24
22
|
function channelFromVersion(version) {
|
|
25
23
|
const m = version.match(/[^-]+(?:-([^.]+))?/);
|
|
@@ -36,7 +34,7 @@ class Permutations extends Map {
|
|
|
36
34
|
}
|
|
37
35
|
add(permutation, commandId) {
|
|
38
36
|
this.validPermutations.set(permutation, commandId);
|
|
39
|
-
for (const id of (0,
|
|
37
|
+
for (const id of (0, util_1.collectUsableIds)([permutation])) {
|
|
40
38
|
if (this.has(id)) {
|
|
41
39
|
this.set(id, this.get(id).add(commandId));
|
|
42
40
|
}
|
|
@@ -74,7 +72,7 @@ class Config {
|
|
|
74
72
|
static async load(opts = module.filename || __dirname) {
|
|
75
73
|
// Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
|
|
76
74
|
if (typeof opts === 'string' && opts.startsWith('file://')) {
|
|
77
|
-
opts = (0,
|
|
75
|
+
opts = (0, node_url_1.fileURLToPath)(opts);
|
|
78
76
|
}
|
|
79
77
|
if (typeof opts === 'string')
|
|
80
78
|
opts = { root: opts };
|
|
@@ -118,8 +116,8 @@ class Config {
|
|
|
118
116
|
this.version = this.options.version || this.pjson.version || '0.0.0';
|
|
119
117
|
this.channel = this.options.channel || channelFromVersion(this.version);
|
|
120
118
|
this.valid = Config._rootPlugin.valid;
|
|
121
|
-
this.arch = (
|
|
122
|
-
this.platform = WSL ? 'wsl' :
|
|
119
|
+
this.arch = ((0, node_os_1.arch)() === 'ia32' ? 'x86' : (0, node_os_1.arch)());
|
|
120
|
+
this.platform = WSL ? 'wsl' : (0, node_os_1.platform)();
|
|
123
121
|
this.windows = this.platform === 'win32';
|
|
124
122
|
this.bin = this.pjson.oclif.bin || this.name;
|
|
125
123
|
this.binAliases = this.pjson.oclif.binAliases;
|
|
@@ -134,11 +132,11 @@ class Config {
|
|
|
134
132
|
this.userAgent = `${this.name}/${this.version} ${this.platform}-${this.arch} node-${process.version}`;
|
|
135
133
|
this.shell = this._shell();
|
|
136
134
|
this.debug = this._debug();
|
|
137
|
-
this.home = process.env.HOME || (this.windows && this.windowsHome()) ||
|
|
135
|
+
this.home = process.env.HOME || (this.windows && this.windowsHome()) || (0, node_os_1.homedir)() || (0, node_os_1.tmpdir)();
|
|
138
136
|
this.cacheDir = this.scopedEnvVar('CACHE_DIR') || this.macosCacheDir() || this.dir('cache');
|
|
139
137
|
this.configDir = this.scopedEnvVar('CONFIG_DIR') || this.dir('config');
|
|
140
138
|
this.dataDir = this.scopedEnvVar('DATA_DIR') || this.dir('data');
|
|
141
|
-
this.errlog =
|
|
139
|
+
this.errlog = (0, node_path_1.join)(this.cacheDir, 'error.log');
|
|
142
140
|
this.binPath = this.scopedEnvVar('BINPATH');
|
|
143
141
|
this.npmRegistry = this.scopedEnvVar('NPM_REGISTRY') || this.pjson.oclif.npmRegistry;
|
|
144
142
|
this.pjson.oclif.update = this.pjson.oclif.update || {};
|
|
@@ -230,7 +228,7 @@ class Config {
|
|
|
230
228
|
(0, errors_1.exit)(code);
|
|
231
229
|
},
|
|
232
230
|
log(message, ...args) {
|
|
233
|
-
stream_1.stdout.write((0,
|
|
231
|
+
stream_1.stdout.write((0, node_util_1.format)(message, ...args) + '\n');
|
|
234
232
|
},
|
|
235
233
|
error(message, options = {}) {
|
|
236
234
|
(0, errors_1.error)(message, options);
|
|
@@ -430,7 +428,7 @@ class Config {
|
|
|
430
428
|
architecture,
|
|
431
429
|
nodeVersion,
|
|
432
430
|
pluginVersions: Object.fromEntries([...this.plugins.values()].map(p => [p.name, { version: p.version, type: p.type, root: p.root }])),
|
|
433
|
-
osVersion: `${
|
|
431
|
+
osVersion: `${(0, node_os_1.type)()} ${(0, node_os_1.release)()}`,
|
|
434
432
|
shell: this.shell,
|
|
435
433
|
rootPath: this.root,
|
|
436
434
|
};
|
|
@@ -447,8 +445,8 @@ class Config {
|
|
|
447
445
|
const host = this.pjson.oclif.update.s3.host;
|
|
448
446
|
if (!host)
|
|
449
447
|
throw new Error('no s3 host is set');
|
|
450
|
-
const url = new
|
|
451
|
-
url.pathname =
|
|
448
|
+
const url = new node_url_1.URL(host);
|
|
449
|
+
url.pathname = (0, node_path_1.join)(url.pathname, key);
|
|
452
450
|
return url.toString();
|
|
453
451
|
}
|
|
454
452
|
getPluginsList() {
|
|
@@ -457,20 +455,20 @@ class Config {
|
|
|
457
455
|
dir(category) {
|
|
458
456
|
const base = process.env[`XDG_${category.toUpperCase()}_HOME`] ||
|
|
459
457
|
(this.windows && process.env.LOCALAPPDATA) ||
|
|
460
|
-
|
|
461
|
-
return
|
|
458
|
+
(0, node_path_1.join)(this.home, category === 'data' ? '.local/share' : '.' + category);
|
|
459
|
+
return (0, node_path_1.join)(base, this.dirname);
|
|
462
460
|
}
|
|
463
461
|
windowsHome() {
|
|
464
462
|
return this.windowsHomedriveHome() || this.windowsUserprofileHome();
|
|
465
463
|
}
|
|
466
464
|
windowsHomedriveHome() {
|
|
467
|
-
return (process.env.HOMEDRIVE && process.env.HOMEPATH &&
|
|
465
|
+
return (process.env.HOMEDRIVE && process.env.HOMEPATH && (0, node_path_1.join)(process.env.HOMEDRIVE, process.env.HOMEPATH));
|
|
468
466
|
}
|
|
469
467
|
windowsUserprofileHome() {
|
|
470
468
|
return process.env.USERPROFILE;
|
|
471
469
|
}
|
|
472
470
|
macosCacheDir() {
|
|
473
|
-
return (this.platform === 'darwin' &&
|
|
471
|
+
return (this.platform === 'darwin' && (0, node_path_1.join)(this.home, 'Library', 'Caches', this.dirname)) || undefined;
|
|
474
472
|
}
|
|
475
473
|
_shell() {
|
|
476
474
|
let shellPath;
|
|
@@ -508,7 +506,7 @@ class Config {
|
|
|
508
506
|
if (err instanceof Error) {
|
|
509
507
|
const modifiedErr = err;
|
|
510
508
|
modifiedErr.name = `${err.name} Plugin: ${this.name}`;
|
|
511
|
-
modifiedErr.detail = (0,
|
|
509
|
+
modifiedErr.detail = (0, util_1.compact)([
|
|
512
510
|
err.detail,
|
|
513
511
|
`module: ${this._base}`,
|
|
514
512
|
scope && `task: ${scope}`,
|
|
@@ -522,7 +520,7 @@ class Config {
|
|
|
522
520
|
// err is an object
|
|
523
521
|
process.emitWarning('Config.warn expected either a string or Error, but instead received an object');
|
|
524
522
|
err.name = `${err.name} Plugin: ${this.name}`;
|
|
525
|
-
err.detail = (0,
|
|
523
|
+
err.detail = (0, util_1.compact)([
|
|
526
524
|
err.detail,
|
|
527
525
|
`module: ${this._base}`,
|
|
528
526
|
scope && `task: ${scope}`,
|
|
@@ -533,7 +531,7 @@ class Config {
|
|
|
533
531
|
process.emitWarning(JSON.stringify(err));
|
|
534
532
|
}
|
|
535
533
|
get isProd() {
|
|
536
|
-
return (0,
|
|
534
|
+
return (0, util_2.isProd)();
|
|
537
535
|
}
|
|
538
536
|
isJitPluginCommand(c) {
|
|
539
537
|
// Return true if the command's plugin is listed under oclif.jitPlugins AND if the plugin hasn't been loaded to this.plugins
|
|
@@ -588,7 +586,7 @@ class Config {
|
|
|
588
586
|
}
|
|
589
587
|
loadTopics(plugin) {
|
|
590
588
|
const marker = performance_1.default.mark(`config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
591
|
-
for (const topic of (0,
|
|
589
|
+
for (const topic of (0, util_1.compact)(plugin.topics)) {
|
|
592
590
|
const existing = this._topics.get(topic.name);
|
|
593
591
|
if (existing) {
|
|
594
592
|
existing.description = topic.description || existing.description;
|
|
@@ -597,7 +595,7 @@ class Config {
|
|
|
597
595
|
else {
|
|
598
596
|
this._topics.set(topic.name, topic);
|
|
599
597
|
}
|
|
600
|
-
const permutations = this.flexibleTaxonomy ? (0,
|
|
598
|
+
const permutations = this.flexibleTaxonomy ? (0, util_1.getCommandIdPermutations)(topic.name) : [topic.name];
|
|
601
599
|
for (const permutation of permutations) {
|
|
602
600
|
this.topicPermutations.add(permutation, topic.name);
|
|
603
601
|
}
|
|
@@ -787,7 +785,7 @@ async function toCached(c, plugin, respectNoCacheDefault = false) {
|
|
|
787
785
|
}
|
|
788
786
|
}
|
|
789
787
|
const args = {};
|
|
790
|
-
for (const [name, arg] of Object.entries((0,
|
|
788
|
+
for (const [name, arg] of Object.entries((0, util_2.ensureArgObject)(c.args))) {
|
|
791
789
|
args[name] = {
|
|
792
790
|
name,
|
|
793
791
|
description: arg.description,
|
package/lib/config/ts-node.js
CHANGED
|
@@ -6,7 +6,6 @@ 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
9
|
const errors_1 = require("../errors");
|
|
11
10
|
// eslint-disable-next-line new-cap
|
|
12
11
|
const debug = (0, util_2.Debug)('ts-node');
|
|
@@ -92,7 +91,6 @@ function registerTSNode(root) {
|
|
|
92
91
|
REGISTERED.add(root);
|
|
93
92
|
return tsconfig;
|
|
94
93
|
}
|
|
95
|
-
// eslint-disable-next-line complexity
|
|
96
94
|
function tsPath(root, orig, plugin) {
|
|
97
95
|
if (!orig)
|
|
98
96
|
return orig;
|
|
@@ -102,28 +100,19 @@ function tsPath(root, orig, plugin) {
|
|
|
102
100
|
debug(`Skipping ts-node registration for ${root} because tsNodeEnabled is explicitly set to false`);
|
|
103
101
|
return orig;
|
|
104
102
|
}
|
|
105
|
-
// Skip ts-node registration
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
// Skip ts-node registration for ESM plugins.
|
|
104
|
+
// The node ecosystem is not mature enough to support auto-transpiling ESM modules at this time.
|
|
105
|
+
// See the following:
|
|
106
|
+
// - https://github.com/TypeStrong/ts-node/issues/1791#issuecomment-1149754228
|
|
107
|
+
// - https://github.com/nodejs/node/issues/49432
|
|
108
|
+
// - https://github.com/nodejs/node/pull/49407
|
|
109
|
+
// - https://github.com/nodejs/node/issues/34049
|
|
110
|
+
if (plugin?.moduleType === 'module') {
|
|
111
|
+
debug(`Skipping ts-node registration for ${root} because it's an ESM module`);
|
|
108
112
|
if (plugin.type === 'link')
|
|
109
|
-
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-
|
|
113
|
+
(0, errors_1.memoizedWarn)(`${plugin.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
110
114
|
return orig;
|
|
111
115
|
}
|
|
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
116
|
if (settings_1.settings.tsnodeEnabled === undefined && (0, util_1.isProd)() && plugin?.type !== 'link') {
|
|
128
117
|
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
|
|
129
118
|
return orig;
|