@azure-net/cli 5.1.1 → 6.0.0-next.3

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 (180) hide show
  1. package/README.md +201 -0
  2. package/bin/azure-net.js +236 -221
  3. package/dist/bin/azure-net.d.ts +2 -0
  4. package/dist/src/checks/architecture.d.ts +20 -0
  5. package/dist/src/checks/checkDomain.d.ts +1 -0
  6. package/dist/src/checks/checkFoldersStructure.d.ts +1 -0
  7. package/dist/src/checks/checkHooks.d.ts +1 -0
  8. package/dist/src/checks/checkImports.d.ts +1 -0
  9. package/dist/src/checks/checkInternal.d.ts +1 -0
  10. package/dist/src/checks/checkLayerBoundaries.d.ts +1 -0
  11. package/dist/src/checks/checkLayerImports.d.ts +1 -0
  12. package/dist/src/checks/checkPresenterNames.d.ts +1 -0
  13. package/dist/src/checks/checkProject.d.ts +1 -0
  14. package/dist/src/checks/checkProviderGraph.d.ts +1 -0
  15. package/dist/src/checks/checkProviderNames.d.ts +1 -0
  16. package/dist/src/generate/layers/generateRepository.d.ts +1 -0
  17. package/dist/src/generate/layers/generateRepositoryMethod.d.ts +1 -0
  18. package/dist/src/generate/layers/generateUseCases.d.ts +1 -0
  19. package/dist/src/generate/module/generateDomain.d.ts +8 -0
  20. package/dist/src/generate/module/generateModule.d.ts +1 -0
  21. package/dist/src/generate/module/generateModulePreset.d.ts +1 -0
  22. package/dist/src/generate/module/generatePresenter.d.ts +29 -0
  23. package/dist/src/generate/module/generateRepository.d.ts +15 -0
  24. package/dist/src/generate/module/generateRepositoryMethod.d.ts +2 -0
  25. package/dist/src/generate/module/generateSchemaFromType.d.ts +9 -0
  26. package/dist/src/generate/module/generateStore.d.ts +1 -0
  27. package/dist/src/generate/module/generateTypesJson.d.ts +2 -0
  28. package/dist/src/generate/module/generateUseCases.d.ts +1 -0
  29. package/dist/src/generate/module/repositoryModuleShared.d.ts +89 -0
  30. package/dist/src/generate/routes/generateRoutes.d.ts +14 -0
  31. package/dist/src/generate/ui/generateComponent.d.ts +1 -0
  32. package/dist/src/generate/ui/generateDesignComponent.d.ts +1 -0
  33. package/dist/src/generate/ui/generateWidget.d.ts +1 -0
  34. package/dist/src/git/commit.d.ts +23 -0
  35. package/dist/src/git/push.d.ts +11 -0
  36. package/dist/src/git/runGit.d.ts +2 -0
  37. package/dist/src/init/initAliases.d.ts +12 -0
  38. package/dist/src/init/initEdges.d.ts +2 -0
  39. package/dist/src/init/initStructure.d.ts +1 -0
  40. package/dist/src/install/configureCommitTools.d.ts +1 -0
  41. package/dist/src/install/installFresh.d.ts +1 -0
  42. package/dist/src/migrate/migrate.d.ts +22 -0
  43. package/dist/src/migrate/presenterFactories.d.ts +9 -0
  44. package/dist/src/migrate/presenters.d.ts +13 -0
  45. package/dist/src/migrate/translations.d.ts +8 -0
  46. package/dist/src/plugins/addLint.d.ts +5 -0
  47. package/dist/src/scaffolds/createCoreSchema.d.ts +1 -0
  48. package/dist/src/scaffolds/createDatasource.d.ts +1 -0
  49. package/dist/src/scaffolds/createProgram.d.ts +1 -0
  50. package/dist/src/scaffolds/createResponse.d.ts +1 -0
  51. package/dist/src/scaffolds/createSchemaRule.d.ts +1 -0
  52. package/dist/src/scaffolds/createTranslationManager.d.ts +1 -0
  53. package/{src/scaffolds/index.ts → dist/src/scaffolds/index.d.ts} +0 -2
  54. package/dist/src/scaffolds/registerDatasource.d.ts +2 -0
  55. package/dist/src/scaffolds/updateDefaultFactoryConfig.d.ts +1 -0
  56. package/dist/src/utils/architecture.d.ts +31 -0
  57. package/dist/src/utils/contextUtils.d.ts +6 -0
  58. package/dist/src/utils/fileUtils.d.ts +5 -0
  59. package/dist/src/utils/flattenConfig.d.ts +2 -0
  60. package/dist/src/utils/legacyAliases.d.ts +1 -0
  61. package/dist/src/utils/loadConfig.d.ts +16 -0
  62. package/dist/src/utils/packageImports.d.ts +4 -0
  63. package/dist/src/utils/sharedFoundation.d.ts +20 -0
  64. package/dist/src/utils/viteConfig.d.ts +9 -0
  65. package/package.json +17 -7
  66. package/src/checks/architecture.js +154 -0
  67. package/src/checks/checkDomain.js +124 -154
  68. package/src/checks/checkFoldersStructure.js +64 -52
  69. package/src/checks/checkHooks.js +12 -12
  70. package/src/checks/checkImports.js +26 -142
  71. package/src/checks/checkInternal.js +27 -24
  72. package/src/checks/checkLayerBoundaries.js +22 -197
  73. package/src/checks/checkLayerImports.js +14 -134
  74. package/src/checks/checkPresenterNames.js +156 -143
  75. package/src/checks/checkProject.js +27 -26
  76. package/src/checks/checkProviderGraph.js +182 -166
  77. package/src/checks/checkProviderNames.js +123 -112
  78. package/src/generate/layers/generateRepository.js +1 -109
  79. package/src/generate/layers/generateRepositoryMethod.js +1 -90
  80. package/src/generate/layers/generateUseCases.js +1 -44
  81. package/src/generate/module/generateDomain.js +81 -105
  82. package/src/generate/module/generateModule.js +34 -68
  83. package/src/generate/module/generateModulePreset.js +188 -248
  84. package/src/generate/module/generatePresenter.js +441 -369
  85. package/src/generate/module/generateRepository.js +102 -121
  86. package/src/generate/module/generateRepositoryMethod.js +117 -0
  87. package/src/generate/module/generateSchemaFromType.js +283 -280
  88. package/src/generate/module/generateStore.js +41 -0
  89. package/src/generate/module/generateTypesJson.js +196 -195
  90. package/src/generate/module/generateUseCases.js +47 -55
  91. package/src/generate/module/repositoryModuleShared.js +480 -459
  92. package/src/generate/routes/generateRoutes.js +4 -7
  93. package/src/generate/ui/generateComponent.js +44 -64
  94. package/src/generate/ui/generateDesignComponent.js +21 -41
  95. package/src/generate/ui/generateWidget.js +21 -41
  96. package/src/git/commit.js +67 -0
  97. package/src/git/push.js +19 -0
  98. package/src/git/runGit.js +11 -0
  99. package/src/init/initAliases.js +19 -135
  100. package/src/init/initEdges.js +79 -54
  101. package/src/init/initStructure.js +31 -145
  102. package/src/install/configureCommitTools.js +1 -0
  103. package/src/install/installFresh.js +39 -68
  104. package/src/migrate/migrate.js +1027 -0
  105. package/src/migrate/presenterFactories.js +189 -0
  106. package/src/migrate/presenters.js +373 -0
  107. package/src/migrate/translations.js +213 -0
  108. package/src/plugins/addLint.js +52 -219
  109. package/src/scaffolds/createCoreSchema.js +65 -91
  110. package/src/scaffolds/createDatasource.js +67 -101
  111. package/src/scaffolds/createProgram.js +8 -8
  112. package/src/scaffolds/createResponse.js +29 -29
  113. package/src/scaffolds/createSchemaRule.js +19 -19
  114. package/src/scaffolds/createTranslationManager.js +84 -37
  115. package/src/scaffolds/index.js +0 -2
  116. package/src/scaffolds/registerDatasource.js +59 -0
  117. package/src/scaffolds/updateDefaultFactoryConfig.js +31 -0
  118. package/src/utils/architecture.js +145 -0
  119. package/src/utils/contextUtils.js +32 -65
  120. package/src/utils/fileUtils.js +69 -50
  121. package/src/utils/flattenConfig.js +38 -0
  122. package/src/utils/legacyAliases.js +75 -0
  123. package/src/utils/loadConfig.js +76 -40
  124. package/src/utils/packageImports.js +63 -0
  125. package/src/utils/sharedFoundation.js +36 -42
  126. package/src/utils/viteConfig.js +295 -0
  127. package/.prettierrc +0 -7
  128. package/bin/azure-net.ts +0 -308
  129. package/eslint.config.js +0 -34
  130. package/src/checks/checkDomain.ts +0 -223
  131. package/src/checks/checkFoldersStructure.ts +0 -85
  132. package/src/checks/checkHooks.ts +0 -22
  133. package/src/checks/checkImports.ts +0 -193
  134. package/src/checks/checkInternal.ts +0 -48
  135. package/src/checks/checkLayerBoundaries.ts +0 -255
  136. package/src/checks/checkLayerImports.ts +0 -185
  137. package/src/checks/checkPresenterNames.ts +0 -203
  138. package/src/checks/checkProject.ts +0 -45
  139. package/src/checks/checkProviderGraph.ts +0 -234
  140. package/src/checks/checkProviderNames.ts +0 -165
  141. package/src/generate/layers/generateRepository.ts +0 -123
  142. package/src/generate/layers/generateRepositoryMethod.ts +0 -102
  143. package/src/generate/layers/generateUseCases.ts +0 -50
  144. package/src/generate/layers/repositoryShared.js +0 -506
  145. package/src/generate/layers/repositoryShared.ts +0 -662
  146. package/src/generate/module/generateDomain.ts +0 -147
  147. package/src/generate/module/generateModule.ts +0 -84
  148. package/src/generate/module/generateModulePreset.ts +0 -338
  149. package/src/generate/module/generatePresenter.ts +0 -498
  150. package/src/generate/module/generateRepository.ts +0 -158
  151. package/src/generate/module/generateSchemaFromType.ts +0 -368
  152. package/src/generate/module/generateTypesJson.ts +0 -259
  153. package/src/generate/module/generateUseCases.ts +0 -67
  154. package/src/generate/module/repositoryModuleShared.ts +0 -669
  155. package/src/generate/routes/generateRoutes.ts +0 -275
  156. package/src/generate/ui/generateComponent.ts +0 -100
  157. package/src/generate/ui/generateDesignComponent.ts +0 -71
  158. package/src/generate/ui/generateWidget.ts +0 -71
  159. package/src/init/initAliases.ts +0 -172
  160. package/src/init/initEdges.ts +0 -74
  161. package/src/init/initStructure.ts +0 -172
  162. package/src/install/installFresh.ts +0 -93
  163. package/src/plugins/addLint.ts +0 -274
  164. package/src/scaffolds/createCoreSchema.ts +0 -130
  165. package/src/scaffolds/createDatasource.ts +0 -161
  166. package/src/scaffolds/createDatasourceProvider.js +0 -127
  167. package/src/scaffolds/createDatasourceProvider.ts +0 -161
  168. package/src/scaffolds/createPresenterFactory.js +0 -83
  169. package/src/scaffolds/createPresenterFactory.ts +0 -102
  170. package/src/scaffolds/createProgram.ts +0 -19
  171. package/src/scaffolds/createResponse.ts +0 -66
  172. package/src/scaffolds/createSchemaRule.ts +0 -44
  173. package/src/scaffolds/createTranslationManager.ts +0 -80
  174. package/src/utils/contextUtils.ts +0 -88
  175. package/src/utils/fileUtils.ts +0 -74
  176. package/src/utils/loadConfig.ts +0 -68
  177. package/src/utils/sharedFoundation.ts +0 -70
  178. package/tsconfig.json +0 -19
  179. /package/{src/checks/index.ts → dist/src/checks/index.d.ts} +0 -0
  180. /package/{src/plugins/index.ts → dist/src/plugins/index.d.ts} +0 -0
@@ -1,203 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
-
4
- type PresenterOccurrence = {
5
- id: string;
6
- file: string;
7
- line: number;
8
- callee: string;
9
- };
10
-
11
- const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
12
- const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
13
-
14
- const CREATE_FACTORY_PATTERN = '(?:export\\s+)?(?:const|let|var)\\s+([A-Za-z_$][A-Za-z0-9_$]*)\\s*=\\s*createPresenterFactory\\s*\\(';
15
- const IMPORT_FROM_PRESENTER_PATTERN = 'import\\s*\\{([^}]+)\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]';
16
- const PRESENTER_CALL_PATTERN = '\\b([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(\\s*([\'"`])([^\'"`]*)\\2';
17
-
18
- const toPosixPath = (value: string): string => value.split(path.sep).join('/');
19
-
20
- const isPresenterImportPath = (importPath: string): boolean => {
21
- const normalized = importPath.replace(/\\/g, '/');
22
- return /(^|\/)presenter(\/|$)/.test(normalized);
23
- };
24
-
25
- const parseImportLocals = (rawImports: string): string[] => {
26
- const locals: string[] = [];
27
- for (const segment of rawImports.split(',')) {
28
- const item = segment.trim();
29
- if (!item.length) continue;
30
- const aliasMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
31
- if (aliasMatch?.[2]) {
32
- locals.push(aliasMatch[2]);
33
- continue;
34
- }
35
-
36
- const directMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)$/);
37
- if (directMatch?.[1]) {
38
- locals.push(directMatch[1]);
39
- }
40
- }
41
- return locals;
42
- };
43
-
44
- const listSourceFiles = async (rootDir: string): Promise<string[]> => {
45
- const result: string[] = [];
46
- const stack: string[] = [rootDir];
47
-
48
- while (stack.length) {
49
- const current = stack.pop();
50
- if (!current) continue;
51
-
52
- let entries: import('node:fs').Dirent[] = [];
53
- try {
54
- entries = await fs.readdir(current, { withFileTypes: true });
55
- } catch {
56
- continue;
57
- }
58
-
59
- for (const entry of entries) {
60
- if (entry.isDirectory()) {
61
- if (!IGNORED_DIRS.has(entry.name)) {
62
- stack.push(path.join(current, entry.name));
63
- }
64
- continue;
65
- }
66
-
67
- if (!entry.isFile()) continue;
68
- const fullPath = path.join(current, entry.name);
69
- const extension = path.extname(fullPath);
70
- if (!TARGET_EXTENSIONS.has(extension)) continue;
71
- result.push(fullPath);
72
- }
73
- }
74
-
75
- return result;
76
- };
77
-
78
- const getLineByIndex = (content: string, index: number): number => {
79
- let line = 1;
80
- for (let i = 0; i < index; i += 1) {
81
- if (content[i] === '\n') line += 1;
82
- }
83
- return line;
84
- };
85
-
86
- const extractFactoryNamesFromContent = (content: string): string[] => {
87
- const createFactoryRegex = new RegExp(CREATE_FACTORY_PATTERN, 'g');
88
- const names: string[] = [];
89
- let match: RegExpExecArray | null;
90
- while ((match = createFactoryRegex.exec(content)) !== null) {
91
- const name = match[1];
92
- if (name) names.push(name);
93
- }
94
- return names;
95
- };
96
-
97
- const extractImportedPresenterFactories = (content: string): string[] => {
98
- const importFromPresenterRegex = new RegExp(IMPORT_FROM_PRESENTER_PATTERN, 'g');
99
- const names: string[] = [];
100
- let match: RegExpExecArray | null;
101
- while ((match = importFromPresenterRegex.exec(content)) !== null) {
102
- const rawImports = match[1];
103
- const importPath = match[2];
104
- if (!rawImports || !importPath) continue;
105
- if (!isPresenterImportPath(importPath)) continue;
106
- names.push(...parseImportLocals(rawImports));
107
- }
108
- return names;
109
- };
110
-
111
- const collectPresenterOccurrences = (content: string, filePath: string, knownFactories: Set<string>): PresenterOccurrence[] => {
112
- const presenterCallRegex = new RegExp(PRESENTER_CALL_PATTERN, 'g');
113
- const occurrences: PresenterOccurrence[] = [];
114
- const availableCallees = new Set<string>(['createPresenter']);
115
-
116
- for (const name of extractFactoryNamesFromContent(content)) {
117
- availableCallees.add(name);
118
- }
119
- for (const name of extractImportedPresenterFactories(content)) {
120
- availableCallees.add(name);
121
- }
122
- for (const name of knownFactories) {
123
- availableCallees.add(name);
124
- }
125
-
126
- let match: RegExpExecArray | null;
127
- while ((match = presenterCallRegex.exec(content)) !== null) {
128
- const callee = match[1];
129
- const quote = match[2];
130
- const presenterId = match[3];
131
- if (!callee || !presenterId) continue;
132
- if (!availableCallees.has(callee)) continue;
133
- if (quote === '`' && presenterId.includes('${')) continue;
134
-
135
- occurrences.push({
136
- id: presenterId,
137
- file: filePath,
138
- line: getLineByIndex(content, match.index),
139
- callee
140
- });
141
- }
142
-
143
- return occurrences;
144
- };
145
-
146
- export default async function checkPresenterNames(): Promise<void> {
147
- const srcPath = path.join(process.cwd(), 'src');
148
- try {
149
- await fs.access(srcPath);
150
- } catch {
151
- console.error('❌ src folder not found in current workspace.');
152
- process.exitCode = 1;
153
- return;
154
- }
155
-
156
- const files = await listSourceFiles(srcPath);
157
- const fileContents = new Map<string, string>();
158
-
159
- for (const filePath of files) {
160
- const content = await fs.readFile(filePath, 'utf-8');
161
- fileContents.set(filePath, content);
162
- }
163
-
164
- const globalFactoryNames = new Set<string>();
165
- for (const content of fileContents.values()) {
166
- for (const name of extractFactoryNamesFromContent(content)) {
167
- globalFactoryNames.add(name);
168
- }
169
- }
170
-
171
- const occurrences: PresenterOccurrence[] = [];
172
- for (const [filePath, content] of fileContents.entries()) {
173
- occurrences.push(...collectPresenterOccurrences(content, filePath, globalFactoryNames));
174
- }
175
-
176
- if (!occurrences.length) {
177
- console.log('✅ No presenter declarations found.');
178
- return;
179
- }
180
-
181
- const grouped = new Map<string, PresenterOccurrence[]>();
182
- for (const occurrence of occurrences) {
183
- const list = grouped.get(occurrence.id) ?? [];
184
- list.push(occurrence);
185
- grouped.set(occurrence.id, list);
186
- }
187
-
188
- const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
189
- if (!duplicated.length) {
190
- console.log(`✅ Presenter names are unique (${occurrences.length} found).`);
191
- return;
192
- }
193
-
194
- console.error('❌ Duplicate presenter names found:');
195
- for (const [presenterId, list] of duplicated) {
196
- console.error(`\n- "${presenterId}"`);
197
- for (const item of list) {
198
- console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
199
- }
200
- }
201
-
202
- process.exitCode = 1;
203
- }
@@ -1,45 +0,0 @@
1
- import { execSync } from 'node:child_process';
2
- import { loadUserConfig } from '../utils/loadConfig.js';
3
- import checkInternal from './checkInternal.js';
4
-
5
- type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun';
6
-
7
- const isPackageManager = (value: unknown): value is PackageManager =>
8
- typeof value === 'string' && ['pnpm', 'npm', 'yarn', 'bun'].includes(value);
9
-
10
- const runScript = (manager: PackageManager, script: string): void => {
11
- const command = `${manager} run ${script}`;
12
- console.log(`\n▶ Running: ${command}`);
13
- execSync(command, { stdio: 'inherit' });
14
- };
15
-
16
- const runInternalChecks = async (): Promise<void> => {
17
- console.log('\n▶ Running: azure-net check internal');
18
- process.exitCode = 0;
19
- await checkInternal();
20
- if ((process.exitCode ?? 0) !== 0) {
21
- throw new Error('azure-net check internal failed');
22
- }
23
- };
24
-
25
- export default async function checkProject(): Promise<void> {
26
- const config = await loadUserConfig();
27
- const manager = config.packageManager;
28
-
29
- if (!isPackageManager(manager)) {
30
- console.error('❌ packageManager is missing or invalid in azure-net.config.ts/js. Use one of: bun, pnpm, npm, yarn');
31
- process.exitCode = 1;
32
- return;
33
- }
34
-
35
- try {
36
- runScript(manager, 'format');
37
- await runInternalChecks();
38
- runScript(manager, 'lint');
39
- runScript(manager, 'check');
40
- console.log('\n✅ Project checks passed.');
41
- } catch (error) {
42
- console.error(`\n❌ Project checks failed: ${error instanceof Error ? error.message : String(error)}`);
43
- process.exitCode = 1;
44
- }
45
- }
@@ -1,234 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
-
4
- type ProviderNode = {
5
- name: string;
6
- file: string;
7
- line: number;
8
- dependsOn: string[];
9
- };
10
-
11
- type GraphIssue = {
12
- file: string;
13
- line: number;
14
- message: string;
15
- };
16
-
17
- const TARGET_EXTENSIONS = new Set(['.ts', '.js']);
18
- const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
19
-
20
- const toPosixPath = (value: string): string => value.split(path.sep).join('/');
21
-
22
- const getLineByIndex = (content: string, index: number): number => {
23
- let line = 1;
24
- for (let i = 0; i < index; i += 1) {
25
- if (content[i] === '\n') line += 1;
26
- }
27
- return line;
28
- };
29
-
30
- const listSourceFiles = async (rootDir: string): Promise<string[]> => {
31
- const files: string[] = [];
32
- const stack: string[] = [rootDir];
33
-
34
- while (stack.length) {
35
- const current = stack.pop();
36
- if (!current) continue;
37
-
38
- let entries: import('node:fs').Dirent[] = [];
39
- try {
40
- entries = await fs.readdir(current, { withFileTypes: true });
41
- } catch {
42
- continue;
43
- }
44
-
45
- for (const entry of entries) {
46
- if (entry.isDirectory()) {
47
- if (!IGNORED_DIRS.has(entry.name)) stack.push(path.join(current, entry.name));
48
- continue;
49
- }
50
-
51
- if (!entry.isFile()) continue;
52
- const filePath = path.join(current, entry.name);
53
- if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
54
- files.push(filePath);
55
- }
56
- }
57
-
58
- return files;
59
- };
60
-
61
- const findMatchingBracket = (content: string, startIndex: number, openChar: string, closeChar: string): number => {
62
- let depth = 0;
63
- for (let i = startIndex; i < content.length; i += 1) {
64
- const ch = content[i];
65
- if (ch === openChar) depth += 1;
66
- if (ch === closeChar) {
67
- depth -= 1;
68
- if (depth === 0) return i;
69
- }
70
- }
71
- return -1;
72
- };
73
-
74
- const extractDependsOn = (configBlock: string): string[] => {
75
- const dependsOnMatch = configBlock.match(/dependsOn\s*:\s*\{([\s\S]*?)\}/m);
76
- if (!dependsOnMatch?.[1]) return [];
77
-
78
- const block = dependsOnMatch[1];
79
- const deps = new Set<string>();
80
- const keyRegex = /([A-Za-z_$][A-Za-z0-9_$]*)\s*:/g;
81
- let match: RegExpExecArray | null;
82
- while ((match = keyRegex.exec(block)) !== null) {
83
- const key = match[1];
84
- if (key) deps.add(key);
85
- }
86
- return [...deps];
87
- };
88
-
89
- const parseProviderGraphFromFile = (content: string, filePath: string): ProviderNode[] => {
90
- const nodes: ProviderNode[] = [];
91
- const token = 'createBoundaryProvider(';
92
- let fromIndex = 0;
93
-
94
- while (fromIndex < content.length) {
95
- const start = content.indexOf(token, fromIndex);
96
- if (start === -1) break;
97
-
98
- const openParenIndex = start + token.length - 1;
99
- const closeParenIndex = findMatchingBracket(content, openParenIndex, '(', ')');
100
- if (closeParenIndex === -1) break;
101
-
102
- const fullCall = content.slice(openParenIndex + 1, closeParenIndex);
103
- const idMatch = fullCall.match(/^\s*(['"`])([^'"`]+)\1\s*,/m);
104
- const providerName = idMatch?.[2];
105
- if (providerName) {
106
- const objectStartInCall = fullCall.indexOf('{');
107
- if (objectStartInCall !== -1) {
108
- const absoluteObjectStart = openParenIndex + 1 + objectStartInCall;
109
- const absoluteObjectEnd = findMatchingBracket(content, absoluteObjectStart, '{', '}');
110
- const configBlock =
111
- absoluteObjectEnd !== -1 ? content.slice(absoluteObjectStart, absoluteObjectEnd + 1) : fullCall.slice(objectStartInCall);
112
-
113
- nodes.push({
114
- name: providerName,
115
- file: filePath,
116
- line: getLineByIndex(content, start),
117
- dependsOn: extractDependsOn(configBlock)
118
- });
119
- } else {
120
- nodes.push({
121
- name: providerName,
122
- file: filePath,
123
- line: getLineByIndex(content, start),
124
- dependsOn: []
125
- });
126
- }
127
- }
128
-
129
- fromIndex = closeParenIndex + 1;
130
- }
131
-
132
- return nodes;
133
- };
134
-
135
- const findCycles = (graph: Map<string, string[]>): string[][] => {
136
- const cycles: string[][] = [];
137
- const visited = new Set<string>();
138
- const inStack = new Set<string>();
139
- const stack: string[] = [];
140
-
141
- const dfs = (node: string): void => {
142
- visited.add(node);
143
- inStack.add(node);
144
- stack.push(node);
145
-
146
- const neighbors = graph.get(node) ?? [];
147
- for (const next of neighbors) {
148
- if (!graph.has(next)) continue;
149
- if (!visited.has(next)) {
150
- dfs(next);
151
- continue;
152
- }
153
- if (inStack.has(next)) {
154
- const idx = stack.indexOf(next);
155
- if (idx !== -1) cycles.push([...stack.slice(idx), next]);
156
- }
157
- }
158
-
159
- stack.pop();
160
- inStack.delete(node);
161
- };
162
-
163
- for (const node of graph.keys()) {
164
- if (!visited.has(node)) dfs(node);
165
- }
166
-
167
- return cycles;
168
- };
169
-
170
- export default async function checkProviderGraph(): Promise<void> {
171
- const srcPath = path.join(process.cwd(), 'src');
172
- try {
173
- await fs.access(srcPath);
174
- } catch {
175
- console.error('❌ src folder not found in current workspace.');
176
- process.exitCode = 1;
177
- return;
178
- }
179
-
180
- const files = await listSourceFiles(srcPath);
181
- const providers: ProviderNode[] = [];
182
-
183
- for (const filePath of files) {
184
- const content = await fs.readFile(filePath, 'utf-8');
185
- providers.push(...parseProviderGraphFromFile(content, filePath));
186
- }
187
-
188
- if (!providers.length) {
189
- console.log('✅ No createBoundaryProvider declarations found.');
190
- return;
191
- }
192
-
193
- const graph = new Map<string, string[]>();
194
- const issues: GraphIssue[] = [];
195
- const byName = new Map<string, ProviderNode>();
196
-
197
- for (const provider of providers) {
198
- if (byName.has(provider.name)) {
199
- const existing = byName.get(provider.name)!;
200
- issues.push({
201
- file: provider.file,
202
- line: provider.line,
203
- message: `Provider graph ambiguity: duplicate provider id "${provider.name}" (first declared at ${toPosixPath(
204
- path.relative(process.cwd(), existing.file)
205
- )}:${existing.line})`
206
- });
207
- continue;
208
- }
209
- byName.set(provider.name, provider);
210
- graph.set(provider.name, provider.dependsOn);
211
- }
212
-
213
- const cycles = findCycles(graph);
214
- for (const cycle of cycles) {
215
- const firstNode = byName.get(cycle[0] ?? '');
216
- issues.push({
217
- file: firstNode?.file ?? srcPath,
218
- line: firstNode?.line ?? 1,
219
- message: `Circular provider dependency detected: ${cycle.join(' -> ')}`
220
- });
221
- }
222
-
223
- if (!issues.length) {
224
- console.log(`✅ Provider graph check passed (${providers.length} providers).`);
225
- return;
226
- }
227
-
228
- console.error('❌ Provider graph check failed:');
229
- for (const issue of issues) {
230
- console.error(`• ${toPosixPath(path.relative(process.cwd(), issue.file))}:${issue.line} — ${issue.message}`);
231
- }
232
-
233
- process.exitCode = 1;
234
- }
@@ -1,165 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
-
4
- type ProviderOccurrence = {
5
- id: string;
6
- file: string;
7
- line: number;
8
- callee: string;
9
- };
10
-
11
- const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
12
- const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
13
- const IMPORT_PATTERN = 'import\\s*\\{([^}]+)\\}\\s*from\\s*[\'"]([^\'"]+)[\'"]';
14
- const CALL_PATTERN = '\\b([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\(\\s*([\'"`])([^\'"`]*)\\2';
15
-
16
- const toPosixPath = (value: string): string => value.split(path.sep).join('/');
17
-
18
- const parseImportAliases = (rawImports: string, importName: string): string[] => {
19
- const aliases: string[] = [];
20
- for (const segment of rawImports.split(',')) {
21
- const item = segment.trim();
22
- if (!item.length) continue;
23
-
24
- const aliasMatch = item.match(/^([A-Za-z_$][A-Za-z0-9_$]*)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)$/);
25
- if (aliasMatch?.[1] === importName && aliasMatch[2]) {
26
- aliases.push(aliasMatch[2]);
27
- continue;
28
- }
29
-
30
- if (item === importName) {
31
- aliases.push(importName);
32
- }
33
- }
34
- return aliases;
35
- };
36
-
37
- const listSourceFiles = async (rootDir: string): Promise<string[]> => {
38
- const files: string[] = [];
39
- const stack: string[] = [rootDir];
40
-
41
- while (stack.length) {
42
- const current = stack.pop();
43
- if (!current) continue;
44
-
45
- let entries: import('node:fs').Dirent[] = [];
46
- try {
47
- entries = await fs.readdir(current, { withFileTypes: true });
48
- } catch {
49
- continue;
50
- }
51
-
52
- for (const entry of entries) {
53
- if (entry.isDirectory()) {
54
- if (!IGNORED_DIRS.has(entry.name)) {
55
- stack.push(path.join(current, entry.name));
56
- }
57
- continue;
58
- }
59
-
60
- if (!entry.isFile()) continue;
61
- const filepath = path.join(current, entry.name);
62
- if (!TARGET_EXTENSIONS.has(path.extname(filepath))) continue;
63
- files.push(filepath);
64
- }
65
- }
66
-
67
- return files;
68
- };
69
-
70
- const getLineByIndex = (content: string, index: number): number => {
71
- let line = 1;
72
- for (let i = 0; i < index; i += 1) {
73
- if (content[i] === '\n') line += 1;
74
- }
75
- return line;
76
- };
77
-
78
- const extractBoundaryFactoryAliases = (content: string): Set<string> => {
79
- const importRegex = new RegExp(IMPORT_PATTERN, 'g');
80
- const aliases = new Set<string>(['createBoundaryProvider']);
81
- let match: RegExpExecArray | null;
82
-
83
- while ((match = importRegex.exec(content)) !== null) {
84
- const rawImports = match[1];
85
- if (!rawImports) continue;
86
- for (const alias of parseImportAliases(rawImports, 'createBoundaryProvider')) {
87
- aliases.add(alias);
88
- }
89
- }
90
-
91
- return aliases;
92
- };
93
-
94
- const collectProviderOccurrences = (content: string, filepath: string): ProviderOccurrence[] => {
95
- const aliases = extractBoundaryFactoryAliases(content);
96
- const callRegex = new RegExp(CALL_PATTERN, 'g');
97
- const occurrences: ProviderOccurrence[] = [];
98
- let match: RegExpExecArray | null;
99
-
100
- while ((match = callRegex.exec(content)) !== null) {
101
- const callee = match[1];
102
- const quote = match[2];
103
- const providerId = match[3];
104
-
105
- if (!callee || !providerId) continue;
106
- if (!aliases.has(callee)) continue;
107
- if (quote === '`' && providerId.includes('${')) continue;
108
-
109
- occurrences.push({
110
- id: providerId,
111
- file: filepath,
112
- line: getLineByIndex(content, match.index),
113
- callee
114
- });
115
- }
116
-
117
- return occurrences;
118
- };
119
-
120
- export default async function checkProviderNames(): Promise<void> {
121
- const srcPath = path.join(process.cwd(), 'src');
122
- try {
123
- await fs.access(srcPath);
124
- } catch {
125
- console.error('❌ src folder not found in current workspace.');
126
- process.exitCode = 1;
127
- return;
128
- }
129
-
130
- const files = await listSourceFiles(srcPath);
131
- const occurrences: ProviderOccurrence[] = [];
132
-
133
- for (const filepath of files) {
134
- const content = await fs.readFile(filepath, 'utf-8');
135
- occurrences.push(...collectProviderOccurrences(content, filepath));
136
- }
137
-
138
- if (!occurrences.length) {
139
- console.log('✅ No providers declarations found.');
140
- return;
141
- }
142
-
143
- const grouped = new Map<string, ProviderOccurrence[]>();
144
- for (const occurrence of occurrences) {
145
- const list = grouped.get(occurrence.id) ?? [];
146
- list.push(occurrence);
147
- grouped.set(occurrence.id, list);
148
- }
149
-
150
- const duplicated = Array.from(grouped.entries()).filter(([, list]) => list.length > 1);
151
- if (!duplicated.length) {
152
- console.log(`✅ Provider names are unique (${occurrences.length} found).`);
153
- return;
154
- }
155
-
156
- console.error('❌ Duplicate provider names found:');
157
- for (const [providerId, list] of duplicated) {
158
- console.error(`\n- "${providerId}"`);
159
- for (const item of list) {
160
- console.error(` • ${toPosixPath(path.relative(process.cwd(), item.file))}:${item.line} (${item.callee})`);
161
- }
162
- }
163
-
164
- process.exitCode = 1;
165
- }