@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.
- package/README.md +189 -0
- package/bin/azure-net.js +236 -221
- package/dist/bin/azure-net.d.ts +2 -0
- package/dist/src/checks/architecture.d.ts +20 -0
- package/dist/src/checks/checkDomain.d.ts +1 -0
- package/dist/src/checks/checkFoldersStructure.d.ts +1 -0
- package/dist/src/checks/checkHooks.d.ts +1 -0
- package/dist/src/checks/checkImports.d.ts +1 -0
- package/dist/src/checks/checkInternal.d.ts +1 -0
- package/dist/src/checks/checkLayerBoundaries.d.ts +1 -0
- package/dist/src/checks/checkLayerImports.d.ts +1 -0
- package/dist/src/checks/checkPresenterNames.d.ts +1 -0
- package/dist/src/checks/checkProject.d.ts +1 -0
- package/dist/src/checks/checkProviderGraph.d.ts +1 -0
- package/dist/src/checks/checkProviderNames.d.ts +1 -0
- package/dist/src/generate/layers/generateRepository.d.ts +1 -0
- package/dist/src/generate/layers/generateRepositoryMethod.d.ts +1 -0
- package/dist/src/generate/layers/generateUseCases.d.ts +1 -0
- package/dist/src/generate/module/generateDomain.d.ts +8 -0
- package/dist/src/generate/module/generateModule.d.ts +1 -0
- package/dist/src/generate/module/generateModulePreset.d.ts +1 -0
- package/dist/src/generate/module/generatePresenter.d.ts +29 -0
- package/dist/src/generate/module/generateRepository.d.ts +15 -0
- package/dist/src/generate/module/generateRepositoryMethod.d.ts +2 -0
- package/dist/src/generate/module/generateSchemaFromType.d.ts +9 -0
- package/dist/src/generate/module/generateStore.d.ts +1 -0
- package/dist/src/generate/module/generateTypesJson.d.ts +2 -0
- package/dist/src/generate/module/generateUseCases.d.ts +1 -0
- package/dist/src/generate/module/repositoryModuleShared.d.ts +89 -0
- package/dist/src/generate/routes/generateRoutes.d.ts +14 -0
- package/dist/src/generate/ui/generateComponent.d.ts +1 -0
- package/dist/src/generate/ui/generateDesignComponent.d.ts +1 -0
- package/dist/src/generate/ui/generateWidget.d.ts +1 -0
- package/dist/src/git/commit.d.ts +23 -0
- package/dist/src/git/push.d.ts +11 -0
- package/dist/src/git/runGit.d.ts +2 -0
- package/dist/src/init/initAliases.d.ts +12 -0
- package/dist/src/init/initEdges.d.ts +2 -0
- package/dist/src/init/initStructure.d.ts +1 -0
- package/dist/src/install/configureCommitTools.d.ts +1 -0
- package/dist/src/install/installFresh.d.ts +1 -0
- package/dist/src/migrate/migrate.d.ts +22 -0
- package/dist/src/migrate/presenters.d.ts +7 -0
- package/dist/src/plugins/addLint.d.ts +5 -0
- package/dist/src/scaffolds/createCoreSchema.d.ts +1 -0
- package/dist/src/scaffolds/createDatasource.d.ts +1 -0
- package/dist/src/scaffolds/createProgram.d.ts +1 -0
- package/dist/src/scaffolds/createResponse.d.ts +1 -0
- package/dist/src/scaffolds/createSchemaRule.d.ts +1 -0
- package/dist/src/scaffolds/createTranslationManager.d.ts +1 -0
- package/{src/scaffolds/index.ts → dist/src/scaffolds/index.d.ts} +0 -2
- package/dist/src/scaffolds/registerDatasource.d.ts +2 -0
- package/dist/src/scaffolds/updateDefaultFactoryConfig.d.ts +1 -0
- package/dist/src/utils/architecture.d.ts +31 -0
- package/dist/src/utils/contextUtils.d.ts +6 -0
- package/dist/src/utils/fileUtils.d.ts +5 -0
- package/dist/src/utils/flattenConfig.d.ts +2 -0
- package/dist/src/utils/legacyAliases.d.ts +1 -0
- package/dist/src/utils/loadConfig.d.ts +16 -0
- package/dist/src/utils/packageImports.d.ts +4 -0
- package/dist/src/utils/sharedFoundation.d.ts +20 -0
- package/dist/src/utils/viteConfig.d.ts +9 -0
- package/package.json +48 -36
- package/src/checks/architecture.js +154 -0
- package/src/checks/checkDomain.js +124 -154
- package/src/checks/checkFoldersStructure.js +64 -52
- package/src/checks/checkHooks.js +12 -12
- package/src/checks/checkImports.js +26 -142
- package/src/checks/checkInternal.js +27 -24
- package/src/checks/checkLayerBoundaries.js +22 -197
- package/src/checks/checkLayerImports.js +14 -134
- package/src/checks/checkPresenterNames.js +156 -143
- package/src/checks/checkProject.js +27 -26
- package/src/checks/checkProviderGraph.js +182 -166
- package/src/checks/checkProviderNames.js +123 -112
- package/src/generate/layers/generateRepository.js +1 -109
- package/src/generate/layers/generateRepositoryMethod.js +1 -90
- package/src/generate/layers/generateUseCases.js +1 -44
- package/src/generate/module/generateDomain.js +81 -105
- package/src/generate/module/generateModule.js +34 -68
- package/src/generate/module/generateModulePreset.js +188 -248
- package/src/generate/module/generatePresenter.js +441 -369
- package/src/generate/module/generateRepository.js +102 -121
- package/src/generate/module/generateRepositoryMethod.js +117 -0
- package/src/generate/module/generateSchemaFromType.js +283 -280
- package/src/generate/module/generateStore.js +41 -0
- package/src/generate/module/generateTypesJson.js +196 -195
- package/src/generate/module/generateUseCases.js +47 -55
- package/src/generate/module/repositoryModuleShared.js +480 -459
- package/src/generate/routes/generateRoutes.js +165 -174
- package/src/generate/ui/generateComponent.js +44 -64
- package/src/generate/ui/generateDesignComponent.js +21 -41
- package/src/generate/ui/generateWidget.js +21 -41
- package/src/git/commit.js +67 -0
- package/src/git/push.js +19 -0
- package/src/git/runGit.js +11 -0
- package/src/init/initAliases.js +19 -135
- package/src/init/initEdges.js +79 -54
- package/src/init/initStructure.js +31 -145
- package/src/install/configureCommitTools.js +1 -0
- package/src/install/installFresh.js +39 -68
- package/src/migrate/migrate.js +914 -0
- package/src/migrate/presenters.js +265 -0
- package/src/plugins/addLint.js +52 -219
- package/src/scaffolds/createCoreSchema.js +65 -91
- package/src/scaffolds/createDatasource.js +67 -101
- package/src/scaffolds/createProgram.js +8 -8
- package/src/scaffolds/createResponse.js +29 -29
- package/src/scaffolds/createSchemaRule.js +19 -19
- package/src/scaffolds/createTranslationManager.js +84 -37
- package/src/scaffolds/index.js +0 -2
- package/src/scaffolds/registerDatasource.js +59 -0
- package/src/scaffolds/updateDefaultFactoryConfig.js +31 -0
- package/src/utils/architecture.js +145 -0
- package/src/utils/contextUtils.js +32 -65
- package/src/utils/fileUtils.js +69 -50
- package/src/utils/flattenConfig.js +38 -0
- package/src/utils/legacyAliases.js +75 -0
- package/src/utils/loadConfig.js +76 -40
- package/src/utils/packageImports.js +63 -0
- package/src/utils/sharedFoundation.js +36 -42
- package/src/utils/viteConfig.js +295 -0
- package/.prettierrc +0 -7
- package/bin/azure-net.ts +0 -308
- package/eslint.config.js +0 -34
- package/src/checks/checkDomain.ts +0 -223
- package/src/checks/checkFoldersStructure.ts +0 -85
- package/src/checks/checkHooks.ts +0 -22
- package/src/checks/checkImports.ts +0 -193
- package/src/checks/checkInternal.ts +0 -48
- package/src/checks/checkLayerBoundaries.ts +0 -255
- package/src/checks/checkLayerImports.ts +0 -185
- package/src/checks/checkPresenterNames.ts +0 -203
- package/src/checks/checkProject.ts +0 -45
- package/src/checks/checkProviderGraph.ts +0 -234
- package/src/checks/checkProviderNames.ts +0 -165
- package/src/generate/layers/generateRepository.ts +0 -123
- package/src/generate/layers/generateRepositoryMethod.ts +0 -102
- package/src/generate/layers/generateUseCases.ts +0 -50
- package/src/generate/layers/repositoryShared.js +0 -506
- package/src/generate/layers/repositoryShared.ts +0 -662
- package/src/generate/module/generateDomain.ts +0 -147
- package/src/generate/module/generateModule.ts +0 -84
- package/src/generate/module/generateModulePreset.ts +0 -338
- package/src/generate/module/generatePresenter.ts +0 -498
- package/src/generate/module/generateRepository.ts +0 -158
- package/src/generate/module/generateSchemaFromType.ts +0 -368
- package/src/generate/module/generateTypesJson.ts +0 -259
- package/src/generate/module/generateUseCases.ts +0 -67
- package/src/generate/module/repositoryModuleShared.ts +0 -669
- package/src/generate/routes/generateRoutes.ts +0 -282
- package/src/generate/ui/generateComponent.ts +0 -100
- package/src/generate/ui/generateDesignComponent.ts +0 -71
- package/src/generate/ui/generateWidget.ts +0 -71
- package/src/init/initAliases.ts +0 -172
- package/src/init/initEdges.ts +0 -74
- package/src/init/initStructure.ts +0 -172
- package/src/install/installFresh.ts +0 -93
- package/src/plugins/addLint.ts +0 -274
- package/src/scaffolds/createCoreSchema.ts +0 -130
- package/src/scaffolds/createDatasource.ts +0 -161
- package/src/scaffolds/createDatasourceProvider.js +0 -127
- package/src/scaffolds/createDatasourceProvider.ts +0 -161
- package/src/scaffolds/createPresenterFactory.js +0 -83
- package/src/scaffolds/createPresenterFactory.ts +0 -102
- package/src/scaffolds/createProgram.ts +0 -19
- package/src/scaffolds/createResponse.ts +0 -66
- package/src/scaffolds/createSchemaRule.ts +0 -44
- package/src/scaffolds/createTranslationManager.ts +0 -80
- package/src/utils/contextUtils.ts +0 -88
- package/src/utils/fileUtils.ts +0 -74
- package/src/utils/loadConfig.ts +0 -68
- package/src/utils/sharedFoundation.ts +0 -70
- package/tsconfig.json +0 -19
- /package/{src/checks/index.ts → dist/src/checks/index.d.ts} +0 -0
- /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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
}
|