@oclif/core 3.10.0 → 3.10.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/ts-node.js +10 -19
- package/lib/util/fs.d.ts +1 -0
- package/lib/util/fs.js +9 -1
- package/lib/util/util.d.ts +1 -0
- package/lib/util/util.js +8 -1
- package/package.json +1 -1
package/lib/config/ts-node.js
CHANGED
|
@@ -15,28 +15,21 @@ const util_2 = require("./util");
|
|
|
15
15
|
const debug = (0, util_2.Debug)('ts-node');
|
|
16
16
|
exports.TS_CONFIGS = {};
|
|
17
17
|
const REGISTERED = new Set();
|
|
18
|
+
function isErrno(error) {
|
|
19
|
+
return 'code' in error && error.code === 'ENOENT';
|
|
20
|
+
}
|
|
18
21
|
async function loadTSConfig(root) {
|
|
19
22
|
try {
|
|
20
23
|
if (exports.TS_CONFIGS[root])
|
|
21
24
|
return exports.TS_CONFIGS[root];
|
|
22
|
-
|
|
23
|
-
const tsconfig = await (0, fs_1.readJson)(tsconfigPath);
|
|
24
|
-
if (!tsconfig || Object.keys(tsconfig.compilerOptions).length === 0)
|
|
25
|
-
return;
|
|
26
|
-
exports.TS_CONFIGS[root] = tsconfig;
|
|
27
|
-
if (tsconfig.extends) {
|
|
28
|
-
const { parse } = await import('tsconfck');
|
|
29
|
-
const result = await parse(tsconfigPath);
|
|
30
|
-
const tsNodeOpts = Object.fromEntries((result.extended ?? []).flatMap((e) => Object.entries(e.tsconfig['ts-node'] ?? {})).reverse());
|
|
31
|
-
exports.TS_CONFIGS[root] = { ...result.tsconfig, 'ts-node': tsNodeOpts };
|
|
32
|
-
}
|
|
25
|
+
exports.TS_CONFIGS[root] = await (0, fs_1.readTSConfig)((0, node_path_1.join)(root, 'tsconfig.json'));
|
|
33
26
|
return exports.TS_CONFIGS[root];
|
|
34
27
|
}
|
|
35
28
|
catch (error) {
|
|
36
|
-
if (error
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
29
|
+
if (isErrno(error))
|
|
30
|
+
return;
|
|
31
|
+
debug(`Could not parse tsconfig.json. Skipping ts-node registration for ${root}.`);
|
|
32
|
+
(0, errors_1.memoizedWarn)(`Could not parse tsconfig.json for ${root}. Falling back to compiled source.`);
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
35
|
async function registerTSNode(root) {
|
|
@@ -186,12 +179,10 @@ async function tsPath(root, orig, plugin) {
|
|
|
186
179
|
debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})))`);
|
|
187
180
|
if (plugin?.type === 'link')
|
|
188
181
|
(0, errors_1.memoizedWarn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
189
|
-
if (plugin?.options.url)
|
|
190
|
-
(0, errors_1.memoizedWarn)(`${plugin?.name} is an ESM module installed from github and cannot be auto-transpiled. Existing compiled source will be used instead.`);
|
|
191
182
|
return orig;
|
|
192
183
|
}
|
|
193
|
-
// Do not skip ts-node registration if the plugin is linked
|
|
194
|
-
if (settings_1.settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link'
|
|
184
|
+
// Do not skip ts-node registration if the plugin is linked
|
|
185
|
+
if (settings_1.settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') {
|
|
195
186
|
debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
|
|
196
187
|
return orig;
|
|
197
188
|
}
|
package/lib/util/fs.d.ts
CHANGED
|
@@ -18,3 +18,4 @@ export declare function readJsonSync(path: string, parse: false): string;
|
|
|
18
18
|
export declare function readJsonSync<T = unknown>(path: string, parse?: true): T;
|
|
19
19
|
export declare function safeReadJson<T>(path: string): Promise<T | undefined>;
|
|
20
20
|
export declare function existsSync(path: string): boolean;
|
|
21
|
+
export declare function readTSConfig(path: string): Promise<any>;
|
package/lib/util/fs.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.existsSync = exports.safeReadJson = exports.readJsonSync = exports.readJson = exports.fileExists = exports.dirExists = exports.requireJson = void 0;
|
|
3
|
+
exports.readTSConfig = exports.existsSync = exports.safeReadJson = exports.readJsonSync = exports.readJson = exports.fileExists = exports.dirExists = exports.requireJson = void 0;
|
|
4
4
|
const node_fs_1 = require("node:fs");
|
|
5
5
|
const promises_1 = require("node:fs/promises");
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
const util_1 = require("./util");
|
|
7
8
|
function requireJson(...pathParts) {
|
|
8
9
|
return JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(...pathParts), 'utf8'));
|
|
9
10
|
}
|
|
@@ -69,3 +70,10 @@ function existsSync(path) {
|
|
|
69
70
|
return (0, node_fs_1.existsSync)(path);
|
|
70
71
|
}
|
|
71
72
|
exports.existsSync = existsSync;
|
|
73
|
+
async function readTSConfig(path) {
|
|
74
|
+
const { parse } = await import('tsconfck');
|
|
75
|
+
const result = await parse(path);
|
|
76
|
+
const tsNodeOpts = (0, util_1.mergeNestedObjects)(result.extended ?? [result], 'tsconfig.ts-node');
|
|
77
|
+
return { ...result.tsconfig, 'ts-node': tsNodeOpts };
|
|
78
|
+
}
|
|
79
|
+
exports.readTSConfig = readTSConfig;
|
package/lib/util/util.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
|
|
|
19
19
|
}, fn: (i: T[keyof T], k: keyof T) => TResult): {
|
|
20
20
|
[P in keyof T]: TResult;
|
|
21
21
|
};
|
|
22
|
+
export declare function mergeNestedObjects(objs: Record<string, any>[], path: string): Record<string, any>;
|
|
22
23
|
export {};
|
package/lib/util/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapValues = exports.uniq = exports.isNotFalsy = exports.isTruthy = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.last = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
3
|
+
exports.mergeNestedObjects = exports.mapValues = exports.uniq = exports.isNotFalsy = exports.isTruthy = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.last = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
4
4
|
function pickBy(obj, fn) {
|
|
5
5
|
return Object.entries(obj).reduce((o, [k, v]) => {
|
|
6
6
|
if (fn(v))
|
|
@@ -96,3 +96,10 @@ function mapValues(obj, fn) {
|
|
|
96
96
|
}, {});
|
|
97
97
|
}
|
|
98
98
|
exports.mapValues = mapValues;
|
|
99
|
+
function get(obj, path) {
|
|
100
|
+
return path.split('.').reduce((o, p) => o?.[p], obj);
|
|
101
|
+
}
|
|
102
|
+
function mergeNestedObjects(objs, path) {
|
|
103
|
+
return Object.fromEntries(objs.flatMap((o) => Object.entries(get(o, path) ?? {})).reverse());
|
|
104
|
+
}
|
|
105
|
+
exports.mergeNestedObjects = mergeNestedObjects;
|