@travetto/cli 5.0.0-rc.6 → 5.0.0-rc.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "5.0.0-rc.6",
3
+ "version": "5.0.0-rc.7",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,8 +29,8 @@
29
29
  "directory": "module/cli"
30
30
  },
31
31
  "dependencies": {
32
- "@travetto/schema": "^5.0.0-rc.6",
33
- "@travetto/terminal": "^5.0.0-rc.6"
32
+ "@travetto/schema": "^5.0.0-rc.7",
33
+ "@travetto/terminal": "^5.0.0-rc.7"
34
34
  },
35
35
  "travetto": {
36
36
  "displayName": "Command Line Interface",
package/src/registry.ts CHANGED
@@ -76,7 +76,7 @@ class $CliCommandRegistry {
76
76
  async getInstance(name: string, failOnMissing = false): Promise<CliCommandShape | undefined> {
77
77
  const found = this.getCommandMapping().get(name);
78
78
  if (found) {
79
- const values = Object.values<Class>(await import(found));
79
+ const values = Object.values(await Runtime.importFrom<Record<string, Class>>(found));
80
80
  for (const v of values) {
81
81
  const cfg = this.getByClass(v);
82
82
  if (cfg) {
@@ -1,7 +1,4 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
-
4
- import { Runtime, RuntimeIndex } from '@travetto/runtime';
1
+ import { Runtime } from '@travetto/runtime';
5
2
  import { CliCommandShape, CliCommand, CliValidationError, ParsedState } from '@travetto/cli';
6
3
  import { Ignore } from '@travetto/schema';
7
4
 
@@ -14,19 +11,10 @@ export class MainCommand implements CliCommandShape {
14
11
  @Ignore()
15
12
  _parsed: ParsedState;
16
13
 
17
- async #getImport(fileOrImport: string): Promise<string | undefined> {
18
- // If referenced file exists
19
- let file = fileOrImport;
20
- if (await (fs.stat(path.resolve(fileOrImport)).then(() => true, () => false))) {
21
- file = path.join(Runtime.main.name, fileOrImport);
22
- }
23
-
24
- return RuntimeIndex.getFromImport(file)?.import;
25
- }
26
-
27
14
  async validate(fileOrImport: string): Promise<CliValidationError | undefined> {
28
- const imp = await this.#getImport(fileOrImport);
29
- if (!imp) {
15
+ try {
16
+ await Runtime.importFrom(fileOrImport);
17
+ } catch {
30
18
  return { message: `Unknown file: ${fileOrImport}` };
31
19
  }
32
20
  }
@@ -34,8 +22,7 @@ export class MainCommand implements CliCommandShape {
34
22
  async main(fileOrImport: string, args: string[] = []): Promise<void> {
35
23
  let res: unknown;
36
24
  try {
37
- const imp = await this.#getImport(fileOrImport);
38
- const mod = await import(imp!);
25
+ const mod = await Runtime.importFrom<{ main(..._: unknown[]): Promise<unknown> }>(fileOrImport);
39
26
  res = await mod.main(...args, ...this._parsed.unknown);
40
27
  } catch (err) {
41
28
  res = err;