@supacloud/compiler 0.4.1 → 0.5.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ bun add @supacloud/compiler
13
13
  ## API
14
14
 
15
15
  ```ts
16
- import { analyzeProject, compileProject, validateGraph } from "@supacloud/compiler";
16
+ import { analyzeProject, compileProject, validateGraph, watchProject } from "@supacloud/compiler";
17
17
 
18
18
  // 完整流程:分析 → 校验 → 写出 application.ts 与 app.manifest.json
19
19
  const result = await compileProject({
@@ -26,6 +26,16 @@ result.diagnostics; // Diagnostic[]
26
26
  result.graph; // ApplicationGraph
27
27
  result.written; // 写出的绝对路径
28
28
 
29
+ // 开发模式:监听源码,防抖重编译;错误时保留最后一次成功产物
30
+ const handle = watchProject({
31
+ rootDir: "/path/to/app",
32
+ outDir: "/path/to/app/generated",
33
+ onEvent: (event) => console.log(event.type, event.durationMs),
34
+ });
35
+ await handle.ready;
36
+ // ...开发服务器运行...
37
+ await handle.close();
38
+
29
39
  // 只做分析 / 只做校验
30
40
  const graph = await analyzeProject("/path/to/app");
31
41
  const diagnostics = validateGraph(graph, /* strict */ false);
@@ -73,6 +83,24 @@ interface ApplicationGraph {
73
83
 
74
84
  依赖的 token 全图都无 provider 时不报错,记入 `externalTokens`(平台注入)。
75
85
 
86
+ ## 开发模式
87
+
88
+ ```bash
89
+ supacloud-compiler dev --root . --out ./generated
90
+ ```
91
+
92
+ 开发模式默认对源码变化做 100ms 防抖,并只监听 TypeScript 文件。编译器会复用进程内的源码快照:相同输入直接命中缓存;只改动普通实现文件时复用既有依赖图和生成物;只有 SupaCloud 元数据、模块声明或依赖相关文件变化时才重建图。编译失败时不会覆盖最后一次成功的 `application.ts` 和 `app.manifest.json`;修复错误后会自动生成新产物。`--debounce <ms>` 可调整防抖时间。
93
+
94
+ ## 图谱与诊断
95
+
96
+ ```bash
97
+ supacloud-compiler graph ./app
98
+ supacloud-compiler explain CaseService ./app
99
+ supacloud-compiler doctor ./app
100
+ ```
101
+
102
+ `graph` 输出模块拓扑和平台注入 token;`explain` 解释模块、provider 或 external token 的来源与依赖;`doctor` 检查项目结构、模块发现、生成物漂移和编译诊断。加 `--json` 可供 IDE、脚本和 CI 消费结构化结果。
103
+
76
104
  ## 开发
77
105
 
78
106
  ```bash
package/dist/analyze.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ApplicationGraph } from "./types";
1
+ import type { ApplicationGraph, DependencyGraphCache } from "./types";
2
2
  /**
3
3
  * Analyzes source code under rootDir (via ts-morph AST, without typecheck dependency) to build ApplicationGraph.
4
4
  * Decorators are matched by name only (Module/Injectable/Inject/Command/Query/Controller/Get/...),
5
5
  * without checking import origins, so this package does not need to depend on @supacloud/app.
6
6
  */
7
- export declare function analyzeProject(rootDir: string, include?: string[]): Promise<ApplicationGraph>;
7
+ export declare function analyzeProject(rootDir: string, include?: string[], cache?: DependencyGraphCache): Promise<ApplicationGraph>;