@supacloud/compiler 0.6.2 → 0.8.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
@@ -10,6 +10,54 @@ SupaCloud 应用静态编译器:读取 `@supacloud/app` 装饰器元数据的
10
10
  bun add @supacloud/compiler
11
11
  ```
12
12
 
13
+ ## 零配置项目
14
+
15
+ 在项目根目录执行:
16
+
17
+ ```bash
18
+ bunx supacloud-compiler compile
19
+ bunx supacloud-compiler dev
20
+ ```
21
+
22
+ 默认约定如下:
23
+
24
+ | 配置 | 默认值 |
25
+ | --- | --- |
26
+ | 源码目录 | `src` |
27
+ | 生成目录 | `generated` |
28
+ | 文件发现 | `**/*.module.ts`、`**/*.ts` |
29
+ | strict 类型安全门 | 开启 |
30
+ | typed client | 开启 |
31
+ | permissions manifest | 开启 |
32
+ | module boundary preset | `modular-monolith` |
33
+ | provider tree-shaking | 开启 |
34
+
35
+ 需要覆盖默认值时,在项目根目录添加 `supacloud.config.ts`:
36
+
37
+ ```ts
38
+ import { defineSupacloudConfig } from "@supacloud/compiler";
39
+
40
+ export default defineSupacloudConfig({
41
+ root: "src",
42
+ outDir: "generated",
43
+ strict: true,
44
+ generateClient: true,
45
+ generatePermissions: true,
46
+ moduleBoundaryPreset: "modular-monolith",
47
+ commandCapabilities: {
48
+ permission: true,
49
+ audit: true,
50
+ idempotency: true,
51
+ transaction: true,
52
+ },
53
+ });
54
+ ```
55
+
56
+ 命令行参数优先级高于配置文件。`--no-strict`、`--no-client` 和
57
+ `--no-permissions` 只建议用于本地迁移或调试;生产 CI 应保留默认 strict。
58
+ `commandCapabilities` 用于声明运行时实际支持的命令治理能力;命令声明了
59
+ `permission`、`audit` 或 `idempotency` 时,若对应能力关闭,编译器会失败。
60
+
13
61
  ## API
14
62
 
15
63
  ```ts
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli.ts
4
- import { resolve as resolve5 } from "node:path";
4
+ import { resolve as resolve6 } from "node:path";
5
5
 
6
6
  // src/analyze.ts
7
7
  import { createHash as createHash3 } from "node:crypto";
@@ -5084,6 +5084,69 @@ function watchProject(options) {
5084
5084
  };
5085
5085
  }
5086
5086
 
5087
+ // src/config.ts
5088
+ import { existsSync as existsSync5 } from "node:fs";
5089
+ import { join as join6, resolve as resolve5 } from "node:path";
5090
+ import { pathToFileURL } from "node:url";
5091
+ var DEFAULT_SUPACLOUD_CONFIG = {
5092
+ root: "src",
5093
+ outDir: "generated",
5094
+ include: ["**/*.module.ts", "**/*.ts"],
5095
+ strict: true,
5096
+ generateClient: true,
5097
+ generatePermissions: true,
5098
+ treeShakeUnusedProviders: true,
5099
+ moduleBoundaryPreset: "modular-monolith"
5100
+ };
5101
+ function defineSupacloudConfig(config = {}) {
5102
+ return {
5103
+ ...DEFAULT_SUPACLOUD_CONFIG,
5104
+ ...config,
5105
+ include: config.include ?? [...DEFAULT_SUPACLOUD_CONFIG.include]
5106
+ };
5107
+ }
5108
+ function resolveSupacloudConfig(config = {}, cwd = process.cwd()) {
5109
+ const resolved = defineSupacloudConfig(config);
5110
+ return {
5111
+ rootDir: resolve5(cwd, resolved.root ?? DEFAULT_SUPACLOUD_CONFIG.root),
5112
+ outDir: resolve5(cwd, resolved.outDir ?? DEFAULT_SUPACLOUD_CONFIG.outDir),
5113
+ include: resolved.include ?? [...DEFAULT_SUPACLOUD_CONFIG.include],
5114
+ strict: resolved.strict ?? DEFAULT_SUPACLOUD_CONFIG.strict,
5115
+ generateClient: resolved.generateClient ?? DEFAULT_SUPACLOUD_CONFIG.generateClient,
5116
+ generatePermissions: resolved.generatePermissions ?? DEFAULT_SUPACLOUD_CONFIG.generatePermissions,
5117
+ moduleBoundaryPreset: resolved.moduleBoundaryPreset ?? DEFAULT_SUPACLOUD_CONFIG.moduleBoundaryPreset,
5118
+ commandCapabilities: resolved.commandCapabilities,
5119
+ treeShakeUnusedProviders: resolved.treeShakeUnusedProviders ?? DEFAULT_SUPACLOUD_CONFIG.treeShakeUnusedProviders
5120
+ };
5121
+ }
5122
+ async function loadSupacloudConfig(cwd = process.cwd()) {
5123
+ const candidates = [
5124
+ join6(cwd, "supacloud.config.ts"),
5125
+ join6(cwd, "supacloud.config.mts"),
5126
+ join6(cwd, "supacloud.config.js"),
5127
+ join6(cwd, "supacloud.config.mjs")
5128
+ ];
5129
+ const configPath = candidates.find((candidate) => existsSync5(candidate));
5130
+ if (!configPath)
5131
+ return defineSupacloudConfig();
5132
+ const imported = await import(pathToFileURL(configPath).href);
5133
+ return defineSupacloudConfig(imported.default ?? {});
5134
+ }
5135
+ function compileOptionsFromConfig(config, cwd = process.cwd()) {
5136
+ const resolved = resolveSupacloudConfig(config, cwd);
5137
+ return {
5138
+ rootDir: resolved.rootDir,
5139
+ outDir: resolved.outDir,
5140
+ include: resolved.include,
5141
+ strict: resolved.strict,
5142
+ generateClient: resolved.generateClient,
5143
+ generatePermissions: resolved.generatePermissions,
5144
+ moduleBoundaryPreset: resolved.moduleBoundaryPreset,
5145
+ commandCapabilities: resolved.commandCapabilities,
5146
+ treeShakeUnusedProviders: resolved.treeShakeUnusedProviders
5147
+ };
5148
+ }
5149
+
5087
5150
  // src/cli.ts
5088
5151
  function isModuleBoundaryPresetName(value) {
5089
5152
  return value === "modular-monolith" || value === "feature-slices" || value === "vertical-slices" || value === "angular-enterprise" || value === "angular" || value === "clean-architecture" || value === "domain-driven";
@@ -5109,11 +5172,14 @@ Commands:
5109
5172
  doctor Run project and generated-artifact health checks
5110
5173
 
5111
5174
  Options:
5112
- --root, -r <dir> Application source root (default: current directory or first positional argument)
5113
- --out, -o <dir> Artifact output directory (default: <rootDir>/generated)
5114
- --strict Enable type-safety gates and treat all warnings as errors
5115
- --client Generate typed API client in client.ts
5116
- --permissions Generate typed permissions registry in permissions.ts
5175
+ --root, -r <dir> Application source root (default: ./src, or first positional argument)
5176
+ --out, -o <dir> Artifact output directory (default: ./generated)
5177
+ --strict Enable type-safety gates and treat all warnings as errors (default)
5178
+ --no-strict Disable strict diagnostics (local migration escape hatch)
5179
+ --client Generate typed API client in client.ts (default)
5180
+ --no-client Do not generate client.ts
5181
+ --permissions Generate typed permissions registry (default)
5182
+ --no-permissions Do not generate permissions.ts
5117
5183
  --debounce <ms> Debounce source changes in dev mode (default: 100)
5118
5184
  --json Print machine-readable output for graph/explain/doctor
5119
5185
  --preset, -p <name> Architecture preset ('modular-monolith' | 'angular-enterprise' | 'clean-architecture')
@@ -5132,11 +5198,11 @@ async function run() {
5132
5198
  printUsage();
5133
5199
  process.exit(1);
5134
5200
  }
5135
- let rootDir = ".";
5201
+ let rootDir;
5136
5202
  let outDir;
5137
- let strict = false;
5138
- let generateClient = false;
5139
- let generatePermissions = false;
5203
+ let strict;
5204
+ let generateClient;
5205
+ let generatePermissions;
5140
5206
  let preset;
5141
5207
  let debounceMs = 100;
5142
5208
  let query;
@@ -5149,10 +5215,16 @@ async function run() {
5149
5215
  outDir = args[++i];
5150
5216
  } else if (arg === "--strict") {
5151
5217
  strict = true;
5218
+ } else if (arg === "--no-strict") {
5219
+ strict = false;
5152
5220
  } else if (arg === "--client") {
5153
5221
  generateClient = true;
5222
+ } else if (arg === "--no-client") {
5223
+ generateClient = false;
5154
5224
  } else if (arg === "--permissions") {
5155
5225
  generatePermissions = true;
5226
+ } else if (arg === "--no-permissions") {
5227
+ generatePermissions = false;
5156
5228
  } else if (arg === "--debounce") {
5157
5229
  debounceMs = Number(args[++i]);
5158
5230
  if (!Number.isFinite(debounceMs) || debounceMs < 0) {
@@ -5168,7 +5240,7 @@ async function run() {
5168
5240
  process.exit(1);
5169
5241
  }
5170
5242
  preset = presetArg;
5171
- } else if (!arg.startsWith("-") && rootDir === ".") {
5243
+ } else if (!arg.startsWith("-") && !rootDir) {
5172
5244
  if (command === "explain" && !query)
5173
5245
  query = arg;
5174
5246
  else
@@ -5177,17 +5249,24 @@ async function run() {
5177
5249
  query = arg;
5178
5250
  }
5179
5251
  }
5180
- const resolvedRoot = resolve5(process.cwd(), rootDir);
5181
- const resolvedOut = outDir ? resolve5(process.cwd(), outDir) : resolve5(resolvedRoot, "generated");
5252
+ const loadedConfig = await loadSupacloudConfig(process.cwd());
5253
+ const defaults = resolveSupacloudConfig(loadedConfig, process.cwd());
5254
+ const resolvedRoot = rootDir ? resolve6(process.cwd(), rootDir) : defaults.rootDir;
5255
+ const resolvedOut = outDir ? resolve6(process.cwd(), outDir) : defaults.outDir;
5256
+ const configured = compileOptionsFromConfig({
5257
+ ...loadedConfig,
5258
+ root: resolvedRoot,
5259
+ outDir: resolvedOut,
5260
+ strict: strict ?? loadedConfig.strict,
5261
+ generateClient: generateClient ?? loadedConfig.generateClient,
5262
+ generatePermissions: generatePermissions ?? loadedConfig.generatePermissions
5263
+ }, process.cwd());
5264
+ const compileDefaults = {
5265
+ ...configured,
5266
+ moduleBoundaryPreset: preset ?? configured.moduleBoundaryPreset
5267
+ };
5182
5268
  if (command === "compile") {
5183
- const result = await compileProject({
5184
- rootDir: resolvedRoot,
5185
- outDir: resolvedOut,
5186
- strict,
5187
- moduleBoundaryPreset: preset,
5188
- generateClient,
5189
- generatePermissions
5190
- });
5269
+ const result = await compileProject(compileDefaults);
5191
5270
  printDiagnostics(result.diagnostics);
5192
5271
  const errors = result.diagnostics.filter((d) => d.severity === "error");
5193
5272
  if (errors.length > 0) {
@@ -5200,14 +5279,7 @@ Compilation succeeded. Generated artifacts:
5200
5279
  ${result.written.map((f) => ` - ${f}`).join(`
5201
5280
  `)}`);
5202
5281
  } else if (command === "check") {
5203
- const result = await checkProject({
5204
- rootDir: resolvedRoot,
5205
- outDir: resolvedOut,
5206
- strict,
5207
- moduleBoundaryPreset: preset,
5208
- generateClient,
5209
- generatePermissions
5210
- });
5282
+ const result = await checkProject(compileDefaults);
5211
5283
  printDiagnostics(result.diagnostics);
5212
5284
  const errors = result.diagnostics.filter((d) => d.severity === "error");
5213
5285
  if (errors.length > 0) {
@@ -5227,13 +5299,8 @@ Artifact drift detected:`);
5227
5299
  console.log("Artifact check passed: disk files match compiler output with no drift.");
5228
5300
  } else if (command === "dev") {
5229
5301
  const handle = watchProject({
5230
- rootDir: resolvedRoot,
5231
- outDir: resolvedOut,
5232
- strict,
5233
- moduleBoundaryPreset: preset,
5302
+ ...compileDefaults,
5234
5303
  debounceMs,
5235
- generateClient,
5236
- generatePermissions,
5237
5304
  onEvent: (event) => {
5238
5305
  if (event.type === "compile-start") {
5239
5306
  console.log(event.initial ? `
@@ -5284,12 +5351,7 @@ Source change detected; compiling...`);
5284
5351
  process.exit(1);
5285
5352
  }
5286
5353
  } else {
5287
- const result = await checkProject({
5288
- rootDir: resolvedRoot,
5289
- outDir: resolvedOut,
5290
- strict,
5291
- moduleBoundaryPreset: preset
5292
- });
5354
+ const result = await checkProject(compileDefaults);
5293
5355
  const doctor = doctorProject(resolvedRoot, resolvedOut, result.graph, result.upToDate, result.diagnostics);
5294
5356
  if (json) {
5295
5357
  console.log(JSON.stringify(doctor, null, 2));
@@ -0,0 +1,30 @@
1
+ import type { CommandExecutionCapabilities, CompileOptions, ModuleBoundaryPresetName } from "./types";
2
+ export interface SupaCloudConfig {
3
+ root?: string;
4
+ outDir?: string;
5
+ include?: string[];
6
+ strict?: boolean;
7
+ generateClient?: boolean;
8
+ generatePermissions?: boolean;
9
+ moduleBoundaryPreset?: ModuleBoundaryPresetName;
10
+ commandCapabilities?: CommandExecutionCapabilities;
11
+ treeShakeUnusedProviders?: boolean;
12
+ }
13
+ export declare const DEFAULT_SUPACLOUD_CONFIG: Required<Omit<SupaCloudConfig, "include" | "moduleBoundaryPreset" | "commandCapabilities">> & {
14
+ include: string[];
15
+ moduleBoundaryPreset: ModuleBoundaryPresetName;
16
+ };
17
+ export declare function defineSupacloudConfig(config?: SupaCloudConfig): SupaCloudConfig;
18
+ export declare function resolveSupacloudConfig(config?: SupaCloudConfig, cwd?: string): {
19
+ rootDir: string;
20
+ outDir: string;
21
+ include: string[];
22
+ strict: boolean;
23
+ generateClient: boolean;
24
+ generatePermissions: boolean;
25
+ moduleBoundaryPreset: ModuleBoundaryPresetName;
26
+ commandCapabilities?: CommandExecutionCapabilities;
27
+ treeShakeUnusedProviders: boolean;
28
+ };
29
+ export declare function loadSupacloudConfig(cwd?: string): Promise<SupaCloudConfig>;
30
+ export declare function compileOptionsFromConfig(config: SupaCloudConfig, cwd?: string): CompileOptions;
package/dist/index.d.ts CHANGED
@@ -16,6 +16,8 @@ export type { DoctorResult } from "./inspect";
16
16
  export { validateGraph, COMPILER_DIAGNOSTIC_CODES } from "./validate";
17
17
  export { scanGeneratedArtifacts, scanProductionSource } from "./type-safety";
18
18
  export type { TypeSafetyScanOptions } from "./type-safety";
19
+ export { DEFAULT_SUPACLOUD_CONFIG, compileOptionsFromConfig, defineSupacloudConfig, loadSupacloudConfig, resolveSupacloudConfig, } from "./config";
20
+ export type { SupaCloudConfig } from "./config";
19
21
  export { camelName } from "./util";
20
22
  export { ANGULAR_ENTERPRISE_RULES, CLEAN_ARCHITECTURE_RULES, MODULAR_MONOLITH_RULES, MODULE_BOUNDARY_PROFILES, getModuleBoundaryPreset, getModuleBoundaryProfile, resolveModuleBoundaries, } from "./profiles";
21
23
  export type { ApplicationGraph, AspectRefNode, CachedModuleEntry, CheckProjectResult, CommandExecutionCapabilities, CommandNode, CompileOptions, CompileResult, CompileStats, ControllerNode, DependencyGraphCache, DependencyGraphIndex, Diagnostic, ModuleBoundaryPresetName, ModuleBoundaryProfile, ModuleBoundaryRule, ModuleNode, JobNode, ProviderKind, ProviderNode, QueryNode, RouteNode, Scope, TokenKind, TypeSafetyOptions, ValidateOptions, WatchEvent, WatchHandle, WatchOptions, } from "./types";
package/dist/index.js CHANGED
@@ -5075,10 +5075,73 @@ function exportGraphDot(graph) {
5075
5075
  return lines.join(`
5076
5076
  `);
5077
5077
  }
5078
+ // src/config.ts
5079
+ import { existsSync as existsSync5 } from "node:fs";
5080
+ import { join as join6, resolve as resolve5 } from "node:path";
5081
+ import { pathToFileURL } from "node:url";
5082
+ var DEFAULT_SUPACLOUD_CONFIG = {
5083
+ root: "src",
5084
+ outDir: "generated",
5085
+ include: ["**/*.module.ts", "**/*.ts"],
5086
+ strict: true,
5087
+ generateClient: true,
5088
+ generatePermissions: true,
5089
+ treeShakeUnusedProviders: true,
5090
+ moduleBoundaryPreset: "modular-monolith"
5091
+ };
5092
+ function defineSupacloudConfig(config = {}) {
5093
+ return {
5094
+ ...DEFAULT_SUPACLOUD_CONFIG,
5095
+ ...config,
5096
+ include: config.include ?? [...DEFAULT_SUPACLOUD_CONFIG.include]
5097
+ };
5098
+ }
5099
+ function resolveSupacloudConfig(config = {}, cwd = process.cwd()) {
5100
+ const resolved = defineSupacloudConfig(config);
5101
+ return {
5102
+ rootDir: resolve5(cwd, resolved.root ?? DEFAULT_SUPACLOUD_CONFIG.root),
5103
+ outDir: resolve5(cwd, resolved.outDir ?? DEFAULT_SUPACLOUD_CONFIG.outDir),
5104
+ include: resolved.include ?? [...DEFAULT_SUPACLOUD_CONFIG.include],
5105
+ strict: resolved.strict ?? DEFAULT_SUPACLOUD_CONFIG.strict,
5106
+ generateClient: resolved.generateClient ?? DEFAULT_SUPACLOUD_CONFIG.generateClient,
5107
+ generatePermissions: resolved.generatePermissions ?? DEFAULT_SUPACLOUD_CONFIG.generatePermissions,
5108
+ moduleBoundaryPreset: resolved.moduleBoundaryPreset ?? DEFAULT_SUPACLOUD_CONFIG.moduleBoundaryPreset,
5109
+ commandCapabilities: resolved.commandCapabilities,
5110
+ treeShakeUnusedProviders: resolved.treeShakeUnusedProviders ?? DEFAULT_SUPACLOUD_CONFIG.treeShakeUnusedProviders
5111
+ };
5112
+ }
5113
+ async function loadSupacloudConfig(cwd = process.cwd()) {
5114
+ const candidates = [
5115
+ join6(cwd, "supacloud.config.ts"),
5116
+ join6(cwd, "supacloud.config.mts"),
5117
+ join6(cwd, "supacloud.config.js"),
5118
+ join6(cwd, "supacloud.config.mjs")
5119
+ ];
5120
+ const configPath = candidates.find((candidate) => existsSync5(candidate));
5121
+ if (!configPath)
5122
+ return defineSupacloudConfig();
5123
+ const imported = await import(pathToFileURL(configPath).href);
5124
+ return defineSupacloudConfig(imported.default ?? {});
5125
+ }
5126
+ function compileOptionsFromConfig(config, cwd = process.cwd()) {
5127
+ const resolved = resolveSupacloudConfig(config, cwd);
5128
+ return {
5129
+ rootDir: resolved.rootDir,
5130
+ outDir: resolved.outDir,
5131
+ include: resolved.include,
5132
+ strict: resolved.strict,
5133
+ generateClient: resolved.generateClient,
5134
+ generatePermissions: resolved.generatePermissions,
5135
+ moduleBoundaryPreset: resolved.moduleBoundaryPreset,
5136
+ commandCapabilities: resolved.commandCapabilities,
5137
+ treeShakeUnusedProviders: resolved.treeShakeUnusedProviders
5138
+ };
5139
+ }
5078
5140
  export {
5079
5141
  ANGULAR_ENTERPRISE_RULES,
5080
5142
  CLEAN_ARCHITECTURE_RULES,
5081
5143
  COMPILER_DIAGNOSTIC_CODES,
5144
+ DEFAULT_SUPACLOUD_CONFIG,
5082
5145
  MODULAR_MONOLITH_RULES,
5083
5146
  MODULE_BOUNDARY_PROFILES,
5084
5147
  ModuleDependencyGraph,
@@ -5086,11 +5149,13 @@ export {
5086
5149
  analyzeProject,
5087
5150
  camelName,
5088
5151
  checkProject,
5152
+ compileOptionsFromConfig,
5089
5153
  compileProject,
5090
5154
  compileTraits,
5091
5155
  createDependencyGraphCache,
5092
5156
  createIncrementalCompiler,
5093
5157
  createIncrementalProgramSession,
5158
+ defineSupacloudConfig,
5094
5159
  doctorProject,
5095
5160
  explainGraph,
5096
5161
  exportGraphDot,
@@ -5099,8 +5164,10 @@ export {
5099
5164
  generateApplication,
5100
5165
  getModuleBoundaryPreset,
5101
5166
  getModuleBoundaryProfile,
5167
+ loadSupacloudConfig,
5102
5168
  renderApplication,
5103
5169
  resolveModuleBoundaries,
5170
+ resolveSupacloudConfig,
5104
5171
  scanGeneratedArtifacts,
5105
5172
  scanProductionSource,
5106
5173
  validateGraph,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/compiler",
3
- "version": "0.6.2",
3
+ "version": "0.8.0",
4
4
  "description": "Static compiler for @supacloud/app metadata: builds the application graph from AST, validates it, and generates reflection-free factory code",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",