@azure-net/cli 5.1.0 → 6.0.0-next.2

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