@oclif/core 2.5.1 → 2.6.0

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.
@@ -1,5 +1,5 @@
1
1
  import { Options, Plugin as IPlugin } from '../interfaces/plugin';
2
- import { Config as IConfig, ArchTypes, PlatformTypes, LoadOptions } from '../interfaces/config';
2
+ import { Config as IConfig, ArchTypes, PlatformTypes, LoadOptions, VersionDetails } from '../interfaces/config';
3
3
  import { Hook, Hooks, PJSON, Topic } from '../interfaces';
4
4
  import * as Plugin from './plugin';
5
5
  import { Command } from '../command';
@@ -89,6 +89,7 @@ export declare class Config implements IConfig {
89
89
  get commands(): Command.Loadable[];
90
90
  get commandIDs(): string[];
91
91
  get topics(): Topic[];
92
+ get versionDetails(): VersionDetails;
92
93
  s3Key(type: keyof PJSON.S3.Templates, ext?: '.tar.gz' | '.tar.xz' | IConfig.s3Key.Options, options?: IConfig.s3Key.Options): string;
93
94
  s3Url(key: string): string;
94
95
  protected dir(category: 'cache' | 'data' | 'config'): string;
@@ -416,6 +416,18 @@ class Config {
416
416
  get topics() {
417
417
  return [...this._topics.values()];
418
418
  }
419
+ get versionDetails() {
420
+ const [cliVersion, architecture, nodeVersion] = this.userAgent.split(' ');
421
+ return {
422
+ cliVersion,
423
+ architecture,
424
+ nodeVersion,
425
+ pluginVersions: Object.fromEntries(this.plugins.map(p => [p.name, { version: p.version, type: p.type, root: p.root }])),
426
+ osVersion: `${os.type()} ${os.release()}`,
427
+ shell: this.shell,
428
+ rootPath: this.root,
429
+ };
430
+ }
419
431
  s3Key(type, ext, options = {}) {
420
432
  if (typeof ext === 'object')
421
433
  options = ext;
@@ -24,6 +24,7 @@ export declare class Plugin implements IPlugin {
24
24
  parent: Plugin | undefined;
25
25
  children: Plugin[];
26
26
  hasManifest: boolean;
27
+ private _commandsDir;
27
28
  protected _debug: (..._: any) => void;
28
29
  protected warned: boolean;
29
30
  constructor(options: PluginOptions);
@@ -141,7 +141,10 @@ class Plugin {
141
141
  return topicsToArray(this.pjson.oclif.topics || {});
142
142
  }
143
143
  get commandsDir() {
144
- return (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands);
144
+ if (this._commandsDir)
145
+ return this._commandsDir;
146
+ this._commandsDir = (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this.type);
147
+ return this._commandsDir;
145
148
  }
146
149
  get commandIDs() {
147
150
  if (!this.commandsDir)
@@ -179,7 +182,7 @@ class Plugin {
179
182
  };
180
183
  let m;
181
184
  try {
182
- const p = path.join(this.pjson.oclif.commands, ...id.split(':'));
185
+ const p = path.join(this.commandsDir ?? this.pjson.oclif.commands, ...id.split(':'));
183
186
  const { isESM, module, filePath } = await module_loader_1.default.loadWithData(this, p);
184
187
  this._debug(isESM ? '(import)' : '(require)', filePath);
185
188
  m = module;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * convert a path from the compiled ./lib files to the ./src typescript source
2
+ * Convert a path from the compiled ./lib files to the ./src typescript source
3
3
  * this is for developing typescript plugins/CLIs
4
- * if there is a tsconfig and the original sources exist, it attempts to require ts-
4
+ * if there is a tsconfig and the original sources exist, it attempts to require ts-node
5
5
  */
6
- export declare function tsPath(root: string, orig: string): string;
7
- export declare function tsPath(root: string, orig: string | undefined): string | undefined;
6
+ export declare function tsPath(root: string, orig: string, type?: string): string;
7
+ export declare function tsPath(root: string, orig: string | undefined, type?: string): string | undefined;
@@ -8,6 +8,8 @@ const util_1 = require("../util");
8
8
  const util_2 = require("./util");
9
9
  // eslint-disable-next-line new-cap
10
10
  const debug = (0, util_2.Debug)('ts-node');
11
+ const TYPE_ROOTS = [`${__dirname}/../node_modules/@types`];
12
+ const ROOT_DIRS = [];
11
13
  function loadTSConfig(root) {
12
14
  const tsconfigPath = path.join(root, 'tsconfig.json');
13
15
  let typescript;
@@ -29,19 +31,58 @@ function loadTSConfig(root) {
29
31
  return tsconfig;
30
32
  }
31
33
  }
32
- function tsPath(root, orig) {
34
+ function registerTSNode(root) {
35
+ const tsconfig = loadTSConfig(root);
36
+ if (!tsconfig)
37
+ return;
38
+ debug('registering ts-node at', root);
39
+ const tsNodePath = require.resolve('ts-node', { paths: [root, __dirname] });
40
+ const tsNode = require(tsNodePath);
41
+ TYPE_ROOTS.push(`${root}/node_modules/@types`);
42
+ if (tsconfig.compilerOptions.rootDirs) {
43
+ ROOT_DIRS.push(...tsconfig.compilerOptions.rootDirs.map(r => path.join(root, r)));
44
+ }
45
+ else {
46
+ ROOT_DIRS.push(`${root}/src`);
47
+ }
48
+ const cwd = process.cwd();
49
+ try {
50
+ process.chdir(root);
51
+ tsNode.register({
52
+ skipProject: true,
53
+ transpileOnly: true,
54
+ compilerOptions: {
55
+ esModuleInterop: tsconfig.compilerOptions.esModuleInterop,
56
+ target: tsconfig.compilerOptions.target || 'es2017',
57
+ experimentalDecorators: tsconfig.compilerOptions.experimentalDecorators || false,
58
+ emitDecoratorMetadata: tsconfig.compilerOptions.emitDecoratorMetadata || false,
59
+ module: 'commonjs',
60
+ sourceMap: true,
61
+ rootDirs: ROOT_DIRS,
62
+ typeRoots: TYPE_ROOTS,
63
+ jsx: 'react',
64
+ },
65
+ });
66
+ return tsconfig;
67
+ }
68
+ finally {
69
+ process.chdir(cwd);
70
+ }
71
+ }
72
+ function tsPath(root, orig, type) {
33
73
  if (!orig)
34
74
  return orig;
35
- orig = path.join(root, orig);
75
+ orig = orig.startsWith(root) ? orig : path.join(root, orig);
36
76
  const skipTSNode =
37
77
  // the CLI specifically turned it off
38
78
  (settings_1.settings.tsnodeEnabled === false) ||
39
79
  // the CLI didn't specify ts-node and it is production
40
80
  (settings_1.settings.tsnodeEnabled === undefined && (0, util_1.isProd)());
41
- if (skipTSNode)
81
+ // We always want to load the tsconfig for linked plugins.
82
+ if (skipTSNode && type !== 'link')
42
83
  return orig;
43
84
  try {
44
- const tsconfig = loadTSConfig(root);
85
+ const tsconfig = type === 'link' ? registerTSNode(root) : loadTSConfig(root);
45
86
  if (!tsconfig)
46
87
  return orig;
47
88
  const { rootDir, rootDirs, outDir } = tsconfig.compilerOptions;
@@ -6,6 +6,19 @@ import { Command } from '../command';
6
6
  export type LoadOptions = Options | string | Config | undefined;
7
7
  export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' | 'wsl';
8
8
  export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86';
9
+ export type VersionDetails = {
10
+ cliVersion: string;
11
+ architecture: string;
12
+ nodeVersion: string;
13
+ pluginVersions?: Record<string, {
14
+ version: string;
15
+ type: string;
16
+ root: string;
17
+ }>;
18
+ osVersion?: string;
19
+ shell?: string;
20
+ rootPath?: string;
21
+ };
9
22
  export interface Config {
10
23
  name: string;
11
24
  version: string;
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": "2.5.1",
4
+ "version": "2.6.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -29,6 +29,7 @@
29
29
  "strip-ansi": "^6.0.1",
30
30
  "supports-color": "^8.1.1",
31
31
  "supports-hyperlinks": "^2.2.0",
32
+ "ts-node": "^10.9.1",
32
33
  "tslib": "^2.5.0",
33
34
  "widest-line": "^3.1.0",
34
35
  "wordwrap": "^1.0.0",
@@ -73,7 +74,6 @@
73
74
  "shelljs": "^0.8.5",
74
75
  "shx": "^0.3.4",
75
76
  "sinon": "^11.1.2",
76
- "ts-node": "^10.9.1",
77
77
  "tsd": "^0.25.0",
78
78
  "typescript": "^4.9.5"
79
79
  },