autosnippet 3.2.22 → 3.3.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.
Files changed (102) hide show
  1. package/dashboard/dist/assets/{icons-C1dUryS-.js → icons-BofcEZ3f.js} +1 -1
  2. package/dashboard/dist/assets/index-SiN1GChm.js +128 -0
  3. package/dashboard/dist/index.html +2 -2
  4. package/dist/bin/cli.d.ts +0 -1
  5. package/dist/bin/cli.js +0 -133
  6. package/dist/lib/cli/SetupService.d.ts +46 -2
  7. package/dist/lib/cli/SetupService.js +2 -27
  8. package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.d.ts +2 -5
  9. package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.js +159 -44
  10. package/dist/lib/core/discovery/index.d.ts +1 -1
  11. package/dist/lib/core/discovery/index.js +2 -2
  12. package/dist/lib/external/mcp/handlers/guard.js +6 -3
  13. package/dist/lib/http/HttpServer.js +0 -6
  14. package/dist/lib/http/routes/commands.d.ts +1 -1
  15. package/dist/lib/http/routes/commands.js +1 -66
  16. package/dist/lib/http/routes/remote.js +0 -5
  17. package/dist/lib/injection/ServiceMap.d.ts +0 -9
  18. package/dist/lib/injection/modules/AppModule.d.ts +2 -3
  19. package/dist/lib/injection/modules/AppModule.js +3 -30
  20. package/dist/lib/service/module/ModuleService.js +3 -13
  21. package/dist/lib/service/search/SearchEngine.js +1 -1
  22. package/dist/lib/shared/constants.d.ts +0 -15
  23. package/dist/lib/shared/constants.js +0 -10
  24. package/dist/scripts/release.js +2 -10
  25. package/package.json +4 -19
  26. package/dashboard/dist/assets/index-DdvZE4Yd.js +0 -128
  27. package/dist/lib/http/routes/snippets.d.ts +0 -6
  28. package/dist/lib/http/routes/snippets.js +0 -49
  29. package/dist/lib/platform/ClipboardManager.d.ts +0 -24
  30. package/dist/lib/platform/ClipboardManager.js +0 -142
  31. package/dist/lib/platform/NativeUi.d.ts +0 -53
  32. package/dist/lib/platform/NativeUi.js +0 -284
  33. package/dist/lib/platform/ios/index.d.ts +0 -38
  34. package/dist/lib/platform/ios/index.js +0 -42
  35. package/dist/lib/platform/ios/routes/spm.d.ts +0 -9
  36. package/dist/lib/platform/ios/routes/spm.js +0 -371
  37. package/dist/lib/platform/ios/snippet/PlaceholderConverter.d.ts +0 -21
  38. package/dist/lib/platform/ios/snippet/PlaceholderConverter.js +0 -48
  39. package/dist/lib/platform/ios/snippet/XcodeCodec.d.ts +0 -23
  40. package/dist/lib/platform/ios/snippet/XcodeCodec.js +0 -96
  41. package/dist/lib/platform/ios/spm/DependencyGraph.d.ts +0 -56
  42. package/dist/lib/platform/ios/spm/DependencyGraph.js +0 -195
  43. package/dist/lib/platform/ios/spm/PackageSwiftParser.d.ts +0 -69
  44. package/dist/lib/platform/ios/spm/PackageSwiftParser.js +0 -231
  45. package/dist/lib/platform/ios/spm/PathFinder.d.ts +0 -28
  46. package/dist/lib/platform/ios/spm/PathFinder.js +0 -117
  47. package/dist/lib/platform/ios/spm/PolicyEngine.d.ts +0 -44
  48. package/dist/lib/platform/ios/spm/PolicyEngine.js +0 -79
  49. package/dist/lib/platform/ios/spm/SpmHelper.d.ts +0 -102
  50. package/dist/lib/platform/ios/spm/SpmHelper.js +0 -464
  51. package/dist/lib/platform/ios/xcode/HeaderResolver.d.ts +0 -33
  52. package/dist/lib/platform/ios/xcode/HeaderResolver.js +0 -90
  53. package/dist/lib/platform/ios/xcode/SaveEventFilter.d.ts +0 -66
  54. package/dist/lib/platform/ios/xcode/SaveEventFilter.js +0 -142
  55. package/dist/lib/platform/ios/xcode/XcodeAutomation.d.ts +0 -71
  56. package/dist/lib/platform/ios/xcode/XcodeAutomation.js +0 -327
  57. package/dist/lib/platform/ios/xcode/XcodeImportResolver.d.ts +0 -130
  58. package/dist/lib/platform/ios/xcode/XcodeImportResolver.js +0 -404
  59. package/dist/lib/platform/ios/xcode/XcodeIntegration.d.ts +0 -89
  60. package/dist/lib/platform/ios/xcode/XcodeIntegration.js +0 -588
  61. package/dist/lib/platform/ios/xcode/XcodeWriteUtils.d.ts +0 -99
  62. package/dist/lib/platform/ios/xcode/XcodeWriteUtils.js +0 -190
  63. package/dist/lib/service/automation/ActionPipeline.d.ts +0 -34
  64. package/dist/lib/service/automation/ActionPipeline.js +0 -53
  65. package/dist/lib/service/automation/AutomationOrchestrator.d.ts +0 -86
  66. package/dist/lib/service/automation/AutomationOrchestrator.js +0 -57
  67. package/dist/lib/service/automation/ContextCollector.d.ts +0 -24
  68. package/dist/lib/service/automation/ContextCollector.js +0 -35
  69. package/dist/lib/service/automation/DirectiveDetector.d.ts +0 -51
  70. package/dist/lib/service/automation/DirectiveDetector.js +0 -112
  71. package/dist/lib/service/automation/FileWatcher.d.ts +0 -51
  72. package/dist/lib/service/automation/FileWatcher.js +0 -366
  73. package/dist/lib/service/automation/TriggerResolver.d.ts +0 -36
  74. package/dist/lib/service/automation/TriggerResolver.js +0 -62
  75. package/dist/lib/service/automation/handlers/AlinkHandler.d.ts +0 -7
  76. package/dist/lib/service/automation/handlers/AlinkHandler.js +0 -80
  77. package/dist/lib/service/automation/handlers/CreateHandler.d.ts +0 -11
  78. package/dist/lib/service/automation/handlers/CreateHandler.js +0 -170
  79. package/dist/lib/service/automation/handlers/GuardHandler.d.ts +0 -17
  80. package/dist/lib/service/automation/handlers/GuardHandler.js +0 -218
  81. package/dist/lib/service/automation/handlers/HeaderHandler.d.ts +0 -2
  82. package/dist/lib/service/automation/handlers/HeaderHandler.js +0 -32
  83. package/dist/lib/service/automation/handlers/SearchHandler.d.ts +0 -11
  84. package/dist/lib/service/automation/handlers/SearchHandler.js +0 -278
  85. package/dist/lib/service/snippet/SnippetFactory.d.ts +0 -101
  86. package/dist/lib/service/snippet/SnippetFactory.js +0 -145
  87. package/dist/lib/service/snippet/SnippetInstaller.d.ts +0 -91
  88. package/dist/lib/service/snippet/SnippetInstaller.js +0 -276
  89. package/dist/lib/service/snippet/codecs/SnippetCodec.d.ts +0 -44
  90. package/dist/lib/service/snippet/codecs/SnippetCodec.js +0 -35
  91. package/dist/lib/service/snippet/codecs/VSCodeCodec.d.ts +0 -27
  92. package/dist/lib/service/snippet/codecs/VSCodeCodec.js +0 -82
  93. package/dist/scripts/build-native-ui.d.ts +0 -3
  94. package/dist/scripts/build-native-ui.js +0 -62
  95. package/dist/scripts/init-snippets.d.ts +0 -30
  96. package/dist/scripts/init-snippets.js +0 -298
  97. package/dist/scripts/install-full.d.ts +0 -7
  98. package/dist/scripts/install-full.js +0 -38
  99. package/resources/native-ui/README.md +0 -29
  100. package/resources/native-ui/combined-window.swift +0 -494
  101. package/resources/native-ui/main.swift +0 -598
  102. package/scripts/postinstall-safe.mjs +0 -89
@@ -1,195 +0,0 @@
1
- /**
2
- * DependencyGraph — SPM 依赖图构建与分析
3
- * 合并 V1 DepGraphService + DepGraphAnalyzer
4
- * 构建 target 级依赖 DAG,支持层级计算、拓扑排序、可达性检查
5
- */
6
- import Logger from '#infra/logging/Logger.js';
7
- export class DependencyGraph {
8
- #adjacency; // Map<string, Set<string>>
9
- #reverseAdj; // Map<string, Set<string>>
10
- #nodes; // Set<string>
11
- #logger;
12
- constructor() {
13
- this.#adjacency = new Map();
14
- this.#reverseAdj = new Map();
15
- this.#nodes = new Set();
16
- this.#logger = Logger.getInstance();
17
- }
18
- /**
19
- * 从 PackageSwiftParser 的解析结果构建图
20
- * @param parsed
21
- */
22
- buildFromParsed(parsed) {
23
- this.clear();
24
- for (const target of parsed.targets || []) {
25
- this.addNode(target.name);
26
- for (const dep of target.dependencies || []) {
27
- this.addEdge(target.name, dep);
28
- }
29
- }
30
- this.#logger.debug(`[DependencyGraph] built: ${this.#nodes.size} nodes, ${this.edgeCount()} edges`);
31
- }
32
- /** 添加节点 */
33
- addNode(name) {
34
- this.#nodes.add(name);
35
- if (!this.#adjacency.has(name)) {
36
- this.#adjacency.set(name, new Set());
37
- }
38
- if (!this.#reverseAdj.has(name)) {
39
- this.#reverseAdj.set(name, new Set());
40
- }
41
- }
42
- /** 添加边: from 依赖 to */
43
- addEdge(from, to) {
44
- this.addNode(from);
45
- this.addNode(to);
46
- this.#adjacency.get(from).add(to);
47
- this.#reverseAdj.get(to).add(from);
48
- }
49
- /** BFS 可达性检查 */
50
- isReachable(from, to) {
51
- if (from === to) {
52
- return true;
53
- }
54
- const visited = new Set();
55
- const queue = [from];
56
- while (queue.length > 0) {
57
- const node = queue.shift();
58
- if (node === to) {
59
- return true;
60
- }
61
- if (visited.has(node)) {
62
- continue;
63
- }
64
- visited.add(node);
65
- for (const neighbor of this.#adjacency.get(node) || []) {
66
- queue.push(neighbor);
67
- }
68
- }
69
- return false;
70
- }
71
- /**
72
- * 检测循环依赖
73
- * @returns 循环路径列表
74
- */
75
- detectCycles() {
76
- const cycles = [];
77
- const white = new Set(this.#nodes);
78
- const gray = new Set();
79
- const black = new Set();
80
- const path = [];
81
- const dfs = (node) => {
82
- white.delete(node);
83
- gray.add(node);
84
- path.push(node);
85
- for (const neighbor of this.#adjacency.get(node) || []) {
86
- if (gray.has(neighbor)) {
87
- const cycleStart = path.indexOf(neighbor);
88
- cycles.push(path.slice(cycleStart).concat(neighbor));
89
- }
90
- else if (white.has(neighbor)) {
91
- dfs(neighbor);
92
- }
93
- }
94
- path.pop();
95
- gray.delete(node);
96
- black.add(node);
97
- };
98
- for (const node of this.#nodes) {
99
- if (white.has(node)) {
100
- dfs(node);
101
- }
102
- }
103
- return cycles;
104
- }
105
- /**
106
- * 拓扑排序 (Kahn's algorithm)
107
- * @returns 若有环则返回部分结果
108
- */
109
- topologicalSort() {
110
- const inDegree = new Map();
111
- for (const node of this.#nodes) {
112
- inDegree.set(node, 0);
113
- }
114
- for (const [, deps] of this.#adjacency) {
115
- for (const dep of deps) {
116
- inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
117
- }
118
- }
119
- const queue = [];
120
- for (const [node, degree] of inDegree) {
121
- if (degree === 0) {
122
- queue.push(node);
123
- }
124
- }
125
- const result = [];
126
- while (queue.length > 0) {
127
- const node = queue.shift();
128
- result.push(node);
129
- for (const dep of this.#adjacency.get(node) || []) {
130
- inDegree.set(dep, (inDegree.get(dep) ?? 0) - 1);
131
- if (inDegree.get(dep) === 0) {
132
- queue.push(dep);
133
- }
134
- }
135
- }
136
- return result;
137
- }
138
- /**
139
- * 层级计算: L0 = 无依赖的节点, L1 = 只依赖 L0, etc.
140
- * @returns node → level
141
- */
142
- computeLevels() {
143
- const levels = new Map();
144
- const topo = this.topologicalSort();
145
- // 反向处理: 叶子节点是 L0
146
- for (const node of topo.reverse()) {
147
- const deps = this.#adjacency.get(node) || new Set();
148
- if (deps.size === 0) {
149
- levels.set(node, 0);
150
- }
151
- else {
152
- let maxDepLevel = 0;
153
- for (const dep of deps) {
154
- maxDepLevel = Math.max(maxDepLevel, levels.get(dep) || 0);
155
- }
156
- levels.set(node, maxDepLevel + 1);
157
- }
158
- }
159
- return levels;
160
- }
161
- /** 获取节点的直接依赖 */
162
- getDependencies(node) {
163
- return [...(this.#adjacency.get(node) || [])];
164
- }
165
- /** 获取节点的直接依赖者 (谁依赖了这个节点) */
166
- getDependents(node) {
167
- return [...(this.#reverseAdj.get(node) || [])];
168
- }
169
- /** 获取所有节点 */
170
- getNodes() {
171
- return [...this.#nodes];
172
- }
173
- edgeCount() {
174
- let count = 0;
175
- for (const deps of this.#adjacency.values()) {
176
- count += deps.size;
177
- }
178
- return count;
179
- }
180
- clear() {
181
- this.#adjacency.clear();
182
- this.#reverseAdj.clear();
183
- this.#nodes.clear();
184
- }
185
- /** 导出为 JSON (可视化用) */
186
- toJSON() {
187
- const edges = [];
188
- for (const [from, deps] of this.#adjacency) {
189
- for (const to of deps) {
190
- edges.push({ from, to });
191
- }
192
- }
193
- return { nodes: [...this.#nodes], edges };
194
- }
195
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * PackageSwiftParser — Package.swift 解析器
3
- * 从 V1 PackageParserV2 迁移,提取包名/版本/targets/dependencies/products/platforms
4
- */
5
- export declare class PackageSwiftParser {
6
- #private;
7
- constructor(projectRoot: string);
8
- /**
9
- * 向上递归查找 Package.swift
10
- * @returns 路径
11
- */
12
- findPackageSwift(startPath?: string): any;
13
- /**
14
- * 向下递归扫描所有 Package.swift(支持多 Package 项目)
15
- * @param rootDir 扫描起点(默认 projectRoot)
16
- * @returns Package.swift 路径数组
17
- */
18
- findAllPackageSwifts(rootDir?: string): any;
19
- /**
20
- * 解析 Package.swift
21
- * @returns }
22
- */
23
- parse(packagePath: string): {
24
- path: string;
25
- name: string;
26
- version: string;
27
- targets: {
28
- name: string;
29
- type: string;
30
- path: string | null;
31
- dependencies: string[];
32
- }[];
33
- dependencies: ({
34
- url: string;
35
- version: string | null;
36
- type: string;
37
- } | {
38
- path: string;
39
- type: string;
40
- })[];
41
- products: {
42
- name: string;
43
- type: string;
44
- }[];
45
- platforms: {
46
- name: string;
47
- version: string;
48
- }[];
49
- };
50
- /** 获取包摘要 */
51
- getSummary(packagePath: string): {
52
- name: string;
53
- version: string;
54
- targetCount: number;
55
- dependencyCount: number;
56
- platforms: {
57
- name: string;
58
- version: string;
59
- }[];
60
- } | null;
61
- /** 提取 target blocks(公开方法,供外部使用) */
62
- extractTargets(content: string): {
63
- name: string;
64
- type: string;
65
- path: string | null;
66
- dependencies: string[];
67
- }[];
68
- clearCache(): void;
69
- }
@@ -1,231 +0,0 @@
1
- /**
2
- * PackageSwiftParser — Package.swift 解析器
3
- * 从 V1 PackageParserV2 迁移,提取包名/版本/targets/dependencies/products/platforms
4
- */
5
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
6
- import { dirname, join } from 'node:path';
7
- import Logger from '#infra/logging/Logger.js';
8
- export class PackageSwiftParser {
9
- #projectRoot;
10
- #cache;
11
- #logger;
12
- constructor(projectRoot) {
13
- this.#projectRoot = projectRoot;
14
- this.#cache = new Map();
15
- this.#logger = Logger.getInstance();
16
- }
17
- /**
18
- * 向上递归查找 Package.swift
19
- * @returns 路径
20
- */
21
- findPackageSwift(startPath = this.#projectRoot) {
22
- const cacheKey = `find:${startPath}`;
23
- if (this.#cache.has(cacheKey)) {
24
- return this.#cache.get(cacheKey);
25
- }
26
- let dir = startPath;
27
- for (let i = 0; i < 10; i++) {
28
- const candidate = join(dir, 'Package.swift');
29
- if (existsSync(candidate)) {
30
- this.#cache.set(cacheKey, candidate);
31
- return candidate;
32
- }
33
- const parent = dirname(dir);
34
- if (parent === dir) {
35
- break;
36
- }
37
- dir = parent;
38
- }
39
- return null;
40
- }
41
- /**
42
- * 向下递归扫描所有 Package.swift(支持多 Package 项目)
43
- * @param rootDir 扫描起点(默认 projectRoot)
44
- * @returns Package.swift 路径数组
45
- */
46
- findAllPackageSwifts(rootDir = this.#projectRoot) {
47
- const cacheKey = `findAll:${rootDir}`;
48
- if (this.#cache.has(cacheKey)) {
49
- return this.#cache.get(cacheKey);
50
- }
51
- const results = [];
52
- const skipDirs = new Set([
53
- 'node_modules',
54
- '.git',
55
- 'Build',
56
- '.build',
57
- '.swiftpm',
58
- 'Pods',
59
- 'DerivedData',
60
- ]);
61
- const scan = (dir, depth = 0) => {
62
- if (depth > 5) {
63
- return; // 限制深度
64
- }
65
- try {
66
- const entries = readdirSync(dir, { withFileTypes: true });
67
- for (const entry of entries) {
68
- if (entry.isDirectory()) {
69
- if (skipDirs.has(entry.name)) {
70
- continue;
71
- }
72
- scan(join(dir, entry.name), depth + 1);
73
- }
74
- else if (entry.name === 'Package.swift') {
75
- results.push(join(dir, entry.name));
76
- }
77
- }
78
- }
79
- catch {
80
- // 权限错误等,跳过
81
- }
82
- };
83
- scan(rootDir);
84
- this.#cache.set(cacheKey, results);
85
- return results;
86
- }
87
- /**
88
- * 解析 Package.swift
89
- * @returns }
90
- */
91
- parse(packagePath) {
92
- if (!packagePath || !existsSync(packagePath)) {
93
- throw new Error(`Package.swift not found: ${packagePath}`);
94
- }
95
- const content = readFileSync(packagePath, 'utf-8');
96
- const result = {
97
- path: packagePath,
98
- name: this.#extractName(content),
99
- version: this.#extractVersion(content),
100
- targets: this.#extractTargets(content),
101
- dependencies: this.#extractDependencies(content),
102
- products: this.#extractProducts(content),
103
- platforms: this.#extractPlatforms(content),
104
- };
105
- this.#logger.debug(`[PackageSwiftParser] 解析完成: ${result.name} (${result.targets.length} targets)`);
106
- return result;
107
- }
108
- /** 获取包摘要 */
109
- getSummary(packagePath) {
110
- try {
111
- const parsed = this.parse(packagePath);
112
- return {
113
- name: parsed.name,
114
- version: parsed.version,
115
- targetCount: parsed.targets.length,
116
- dependencyCount: parsed.dependencies.length,
117
- platforms: parsed.platforms,
118
- };
119
- }
120
- catch {
121
- return null;
122
- }
123
- }
124
- /** 提取 target blocks(公开方法,供外部使用) */
125
- extractTargets(content) {
126
- return this.#extractTargets(content);
127
- }
128
- clearCache() {
129
- this.#cache.clear();
130
- }
131
- // ─── 私有提取方法 ──────────────────────────────────────
132
- #extractName(content) {
133
- const m = content.match(/name\s*:\s*"([^"]+)"/);
134
- return m ? m[1] : 'unknown';
135
- }
136
- #extractVersion(content) {
137
- const m = content.match(/version\s*:\s*"([^"]+)"/);
138
- return m ? m[1] : '0.0.0';
139
- }
140
- #extractTargets(content) {
141
- const targets = [];
142
- const re = /\.(?:target|testTarget|executableTarget)\s*\(/g;
143
- let match;
144
- while ((match = re.exec(content)) !== null) {
145
- const type = match[0].includes('testTarget')
146
- ? 'testTarget'
147
- : match[0].includes('executableTarget')
148
- ? 'executableTarget'
149
- : 'target';
150
- const startPos = match.index + match[0].length;
151
- let depth = 1;
152
- let endPos = startPos;
153
- while (depth > 0 && endPos < content.length) {
154
- if (content[endPos] === '(') {
155
- depth++;
156
- }
157
- else if (content[endPos] === ')') {
158
- depth--;
159
- }
160
- endPos++;
161
- }
162
- if (depth === 0) {
163
- const block = content.substring(startPos, endPos - 1);
164
- const nameMatch = block.match(/name\s*:\s*"([^"]+)"/);
165
- if (!nameMatch) {
166
- continue;
167
- }
168
- const pathMatch = block.match(/path\s*:\s*"([^"]+)"/);
169
- const depsMatch = block.match(/dependencies\s*:\s*\[([^\]]*)\]/s);
170
- const deps = [];
171
- if (depsMatch) {
172
- const depRe = /\.(?:product|target)\s*\(\s*name\s*:\s*"([^"]+)"/g;
173
- let dm;
174
- while ((dm = depRe.exec(depsMatch[1])) !== null) {
175
- deps.push(dm[1]);
176
- }
177
- }
178
- targets.push({
179
- name: nameMatch[1],
180
- type,
181
- path: pathMatch ? pathMatch[1] : null,
182
- dependencies: deps,
183
- });
184
- }
185
- }
186
- return targets;
187
- }
188
- #extractDependencies(content) {
189
- const deps = [];
190
- // 1. URL 依赖: .package(url: "...", ...)
191
- const urlRe = /\.package\s*\(\s*url\s*:\s*"([^"]+)"[^)]*\)/g;
192
- let m;
193
- while ((m = urlRe.exec(content)) !== null) {
194
- const block = m[0];
195
- const fromMatch = block.match(/from\s*:\s*"([^"]+)"/);
196
- const exactMatch = block.match(/exact\s*:\s*"([^"]+)"/);
197
- deps.push({
198
- url: m[1],
199
- version: fromMatch ? fromMatch[1] : exactMatch ? exactMatch[1] : null,
200
- type: 'package',
201
- });
202
- }
203
- // 2. Local path 依赖: .package(path: "...")
204
- const pathRe = /\.package\s*\(\s*path\s*:\s*"([^"]+)"\s*\)/g;
205
- while ((m = pathRe.exec(content)) !== null) {
206
- deps.push({
207
- path: m[1],
208
- type: 'local',
209
- });
210
- }
211
- return deps;
212
- }
213
- #extractProducts(content) {
214
- const products = [];
215
- const re = /\.(library|executable)\s*\(\s*name\s*:\s*"([^"]+)"/g;
216
- let m;
217
- while ((m = re.exec(content)) !== null) {
218
- products.push({ name: m[2], type: m[1] });
219
- }
220
- return products;
221
- }
222
- #extractPlatforms(content) {
223
- const platforms = [];
224
- const re = /\.(iOS|macOS|tvOS|watchOS|visionOS)\s*\(\s*\.v(\d+(?:_\d+)?)\s*\)/g;
225
- let m;
226
- while ((m = re.exec(content)) !== null) {
227
- platforms.push({ name: m[1], version: m[2].replace(/_/g, '.') });
228
- }
229
- return platforms;
230
- }
231
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * PathFinder — 轻量级路径发现工具(V2 ESM)
3
- * 从文件路径向上查找 SPM 项目结构:Package.swift、Target 根目录、头文件路径
4
- */
5
- /** 向上遍历目录,查找含 Code/ 或 Sources/ 子目录的 target 根目录 */
6
- export declare function findTargetRootDir(filePath: string): Promise<string | null>;
7
- /** 向上查找 Package.swift */
8
- export declare function findPackageSwiftPath(filePath: string): Promise<string | null>;
9
- /** 简易解析 Package.swift,提取 targets 数组和包名 */
10
- export declare function parsePackageSwift(packagePath: string): Promise<{
11
- name: string;
12
- path: string;
13
- targets: string[];
14
- } | null>;
15
- /**
16
- * 在 targetRootDir 下递归查找指定头文件
17
- * @param rootDir target 根目录
18
- * @param headerName 不含扩展名的头文件名
19
- * @param moduleName 模块名(可选,用于优先匹配模块子目录)
20
- */
21
- export declare function findSubHeaderPath(rootDir: string, headerName: string, moduleName: string | null): Promise<string | null>;
22
- declare const _default: {
23
- findTargetRootDir: typeof findTargetRootDir;
24
- findPackageSwiftPath: typeof findPackageSwiftPath;
25
- parsePackageSwift: typeof parsePackageSwift;
26
- findSubHeaderPath: typeof findSubHeaderPath;
27
- };
28
- export default _default;
@@ -1,117 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- /**
4
- * PathFinder — 轻量级路径发现工具(V2 ESM)
5
- * 从文件路径向上查找 SPM 项目结构:Package.swift、Target 根目录、头文件路径
6
- */
7
- /** 向上遍历目录,查找含 Code/ 或 Sources/ 子目录的 target 根目录 */
8
- export async function findTargetRootDir(filePath) {
9
- let current = path.dirname(path.resolve(filePath));
10
- for (let i = 0; i < 10; i++) {
11
- try {
12
- const entries = fs.readdirSync(current, { withFileTypes: true });
13
- for (const e of entries) {
14
- if (e.isDirectory() && (e.name === 'Code' || e.name === 'Sources')) {
15
- return current;
16
- }
17
- }
18
- }
19
- catch {
20
- break;
21
- }
22
- const parent = path.dirname(current);
23
- if (parent === current) {
24
- break;
25
- }
26
- current = parent;
27
- }
28
- return null;
29
- }
30
- /** 向上查找 Package.swift */
31
- export async function findPackageSwiftPath(filePath) {
32
- let current = path.dirname(path.resolve(filePath));
33
- for (let i = 0; i < 15; i++) {
34
- const candidate = path.join(current, 'Package.swift');
35
- if (fs.existsSync(candidate)) {
36
- return candidate;
37
- }
38
- const parent = path.dirname(current);
39
- if (parent === current) {
40
- break;
41
- }
42
- current = parent;
43
- }
44
- return null;
45
- }
46
- /** 简易解析 Package.swift,提取 targets 数组和包名 */
47
- export async function parsePackageSwift(packagePath) {
48
- try {
49
- const content = fs.readFileSync(packagePath, 'utf8');
50
- const nameMatch = content.match(/name:\s*"([^"]+)"/);
51
- const name = nameMatch?.[1] || path.basename(path.dirname(packagePath));
52
- const targets = [];
53
- const targetRe = /\.(?:target|testTarget|executableTarget)\s*\(\s*name:\s*"([^"]+)"/g;
54
- let m;
55
- while ((m = targetRe.exec(content)) !== null) {
56
- targets.push(m[1]);
57
- }
58
- return { name, path: path.dirname(packagePath), targets };
59
- }
60
- catch {
61
- return null;
62
- }
63
- }
64
- /**
65
- * 在 targetRootDir 下递归查找指定头文件
66
- * @param rootDir target 根目录
67
- * @param headerName 不含扩展名的头文件名
68
- * @param moduleName 模块名(可选,用于优先匹配模块子目录)
69
- */
70
- export async function findSubHeaderPath(rootDir, headerName, moduleName) {
71
- if (!rootDir || !headerName) {
72
- return null;
73
- }
74
- const target = `${headerName}.h`;
75
- // 优先在模块名子目录下找
76
- if (moduleName) {
77
- const modDir = path.join(rootDir, 'Sources', moduleName);
78
- const found = _findFile(modDir, target);
79
- if (found) {
80
- return found;
81
- }
82
- }
83
- // 全局搜索
84
- return _findFile(rootDir, target);
85
- }
86
- function _findFile(dir, filename, maxDepth = 8, depth = 0) {
87
- if (depth > maxDepth || !fs.existsSync(dir)) {
88
- return null;
89
- }
90
- try {
91
- for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
92
- if (entry.name.startsWith('.')) {
93
- continue;
94
- }
95
- const full = path.join(dir, entry.name);
96
- if (entry.isFile() && entry.name === filename) {
97
- return full;
98
- }
99
- if (entry.isDirectory()) {
100
- const found = _findFile(full, filename, maxDepth, depth + 1);
101
- if (found) {
102
- return found;
103
- }
104
- }
105
- }
106
- }
107
- catch {
108
- /* ignore */
109
- }
110
- return null;
111
- }
112
- export default {
113
- findTargetRootDir,
114
- findPackageSwiftPath,
115
- parsePackageSwift,
116
- findSubHeaderPath,
117
- };
@@ -1,44 +0,0 @@
1
- /**
2
- * PolicyEngine — SPM 依赖策略引擎
3
- * 检查循环依赖、反向依赖 (违反分层架构原则)、方针约束
4
- */
5
- import type { DependencyGraph } from './DependencyGraph.js';
6
- /** 策略检查配置 */
7
- interface PolicyConfig {
8
- layerOrder?: string[];
9
- }
10
- /** 策略违规记录 */
11
- interface PolicyViolation {
12
- type: string;
13
- severity: string;
14
- message: string;
15
- nodes?: string[];
16
- from?: string;
17
- to?: string;
18
- fromLayer?: number;
19
- toLayer?: number;
20
- }
21
- export declare class PolicyEngine {
22
- #private;
23
- /**
24
- * 全面策略检查
25
- * @param config - layerOrder 定义分层顺序,低层不应依赖高层
26
- * @returns }
27
- */
28
- check(graph: DependencyGraph, config?: PolicyConfig): {
29
- passed: boolean;
30
- violations: PolicyViolation[];
31
- };
32
- /**
33
- * 单独检查能否添加新依赖
34
- * @returns }
35
- */
36
- canAddDependency(graph: DependencyGraph, from: string, to: string): {
37
- allowed: boolean;
38
- reason: string;
39
- } | {
40
- allowed: boolean;
41
- reason?: undefined;
42
- };
43
- }
44
- export {};