@arkstack/console 0.12.0 → 0.12.1

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,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { Arkstack } from "@arkstack/contract";
3
3
  import { readdirSync, writeFileSync } from "node:fs";
4
- import { Project } from "ts-morph";
4
+ import { Node, Project } from "ts-morph";
5
5
 
6
6
  //#region src/prepare/TSConfig.ts
7
7
  const TSConfig = {
@@ -68,12 +68,19 @@ var BuildInterfaces = class BuildInterfaces {
68
68
  });
69
69
  BuildInterfaces.checker = BuildInterfaces.project.getTypeChecker();
70
70
  const files = readdirSync(configDir).filter((f) => f.endsWith(".ts"));
71
+ const imports = /* @__PURE__ */ new Map();
71
72
  const properties = [];
72
73
  for (const file of files) {
73
74
  const configName = path.basename(file, ".ts");
74
- const exportAssignment = BuildInterfaces.project.addSourceFileAtPath(path.join(configDir, file)).getExportAssignment((e) => !e.isExportEquals());
75
+ const sourceFile = BuildInterfaces.project.addSourceFileAtPath(path.join(configDir, file));
76
+ const exportAssignment = sourceFile.getExportAssignment((e) => !e.isExportEquals());
75
77
  if (!exportAssignment) continue;
76
78
  const expr = exportAssignment.getExpression();
79
+ const annotatedType = BuildInterfaces.resolveReturnTypeAnnotation(sourceFile, expr, imports);
80
+ if (annotatedType) {
81
+ properties.push(` ${configName}: ${annotatedType}`);
82
+ continue;
83
+ }
77
84
  const type = BuildInterfaces.checker.getTypeAtLocation(expr);
78
85
  const callSignatures = type.getCallSignatures();
79
86
  const resolvedType = callSignatures.length ? callSignatures[0].getReturnType() : type;
@@ -81,6 +88,7 @@ var BuildInterfaces = class BuildInterfaces {
81
88
  properties.push(` ${configName}: ${typeStr}`);
82
89
  }
83
90
  return [
91
+ ...BuildInterfaces.renderImports(imports),
84
92
  "declare module '@arkstack/common' {",
85
93
  " interface ConfigRegistry {",
86
94
  ...properties,
@@ -90,6 +98,41 @@ var BuildInterfaces = class BuildInterfaces {
90
98
  "export {}"
91
99
  ].join("\n");
92
100
  }
101
+ static resolveReturnTypeAnnotation(sourceFile, expr, imports) {
102
+ if (!Node.isArrowFunction(expr) && !Node.isFunctionExpression(expr)) return;
103
+ const returnType = expr.getReturnTypeNode();
104
+ if (!returnType) return;
105
+ const referencedNames = /* @__PURE__ */ new Set();
106
+ if (Node.isTypeReference(returnType)) referencedNames.add(returnType.getTypeName().getText());
107
+ returnType.forEachDescendant((node) => {
108
+ if (Node.isTypeReference(node)) referencedNames.add(node.getTypeName().getText());
109
+ });
110
+ for (const name of referencedNames) {
111
+ const imported = BuildInterfaces.findNamedTypeImport(sourceFile, name);
112
+ if (imported) {
113
+ const specifiers = imports.get(imported.moduleSpecifier) ?? /* @__PURE__ */ new Set();
114
+ specifiers.add(imported.specifier);
115
+ imports.set(imported.moduleSpecifier, specifiers);
116
+ }
117
+ }
118
+ return returnType.getText(!!sourceFile);
119
+ }
120
+ static findNamedTypeImport(sourceFile, name) {
121
+ for (const declaration of sourceFile.getImportDeclarations()) for (const namedImport of declaration.getNamedImports()) {
122
+ const alias = namedImport.getAliasNode()?.getText();
123
+ const importedName = namedImport.getName();
124
+ if ((alias ?? importedName) !== name) continue;
125
+ return {
126
+ moduleSpecifier: declaration.getModuleSpecifierValue(),
127
+ specifier: alias ? `${importedName} as ${alias}` : importedName
128
+ };
129
+ }
130
+ }
131
+ static renderImports(imports) {
132
+ return [...imports.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([moduleSpecifier, specifiers]) => {
133
+ return `import type { ${[...specifiers].sort().join(", ")} } from '${moduleSpecifier}'`;
134
+ });
135
+ }
93
136
  /**
94
137
  * ts-morph resolves computed keys like path.join(...) as { [x: number]: any }
95
138
  * detect these by checking the type text for an index signature pattern
package/dist/index.d.ts CHANGED
@@ -5,6 +5,9 @@ declare class BuildInterfaces {
5
5
  static configs(configDir?: string): void;
6
6
  static tsconfig(): void;
7
7
  private static generateConfig;
8
+ private static resolveReturnTypeAnnotation;
9
+ private static findNamedTypeImport;
10
+ private static renderImports;
8
11
  private static isDynamicMap;
9
12
  private static resolveType;
10
13
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as ArkstackConsoleApp } from "./app-DGy8It6S.js";
3
- import { n as BaseTCConfig, r as TSConfig, t as BuildInterfaces } from "./BuildInterfaces-CjAQV0tH.js";
3
+ import { n as BaseTCConfig, r as TSConfig, t as BuildInterfaces } from "./BuildInterfaces-BoL-g5kU.js";
4
4
  import { abort, abortIf, assertFound, config, env, importFile, initializeGlobalContext, loadPrototypes, outputDir } from "@arkstack/common";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import path, { join } from "node:path";
package/dist/prepare.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as BuildInterfaces } from "./BuildInterfaces-CjAQV0tH.js";
2
+ import { t as BuildInterfaces } from "./BuildInterfaces-BoL-g5kU.js";
3
3
  import path from "node:path";
4
4
  import { Arkstack } from "@arkstack/contract";
5
5
  import { existsSync, mkdirSync } from "node:fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/console",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "type": "module",
5
5
  "description": "Console module for Arkstack, providing the command-line runtime and console integration layer.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/cli",
@@ -51,8 +51,8 @@
51
51
  "chalk": "^5.6.2",
52
52
  "resora": "^1.3.6",
53
53
  "ts-morph": "^28.0.0",
54
- "@arkstack/contract": "^0.12.0",
55
- "@arkstack/common": "^0.12.0"
54
+ "@arkstack/common": "^0.12.1",
55
+ "@arkstack/contract": "^0.12.1"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",