@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.
- package/README.md +201 -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/presenterFactories.d.ts +9 -0
- package/dist/src/migrate/presenters.d.ts +13 -0
- package/dist/src/migrate/translations.d.ts +8 -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 +17 -7
- 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 +4 -7
- 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 +1027 -0
- package/src/migrate/presenterFactories.js +189 -0
- package/src/migrate/presenters.js +373 -0
- package/src/migrate/translations.js +213 -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 -275
- 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
|
@@ -8,32 +8,35 @@ import checkImports from './checkImports.js';
|
|
|
8
8
|
import checkHooks from './checkHooks.js';
|
|
9
9
|
import checkLayerImports from './checkLayerImports.js';
|
|
10
10
|
const tasks = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
{ name: 'presenter-names', run: checkPresenterNames },
|
|
12
|
+
{ name: 'provider-names', run: checkProviderNames },
|
|
13
|
+
{ name: 'provider-graph', run: checkProviderGraph },
|
|
14
|
+
{ name: 'domain', run: checkDomain },
|
|
15
|
+
{ name: 'imports', run: checkImports },
|
|
16
|
+
{ name: 'hooks', run: checkHooks },
|
|
17
|
+
{ name: 'layer-imports', run: checkLayerImports },
|
|
18
|
+
{ name: 'layer-boundaries', run: checkLayerBoundaries },
|
|
19
|
+
{ name: 'folders-structure', run: checkFoldersStructure }
|
|
20
20
|
];
|
|
21
21
|
const runTask = async (task) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
console.log(`\n▶ Running check ${task.name}...`);
|
|
23
|
+
process.exitCode = 0;
|
|
24
|
+
await task.run();
|
|
25
|
+
if ((process.exitCode ?? 0) !== 0) {
|
|
26
|
+
throw new Error(`Check "${task.name}" failed`);
|
|
27
|
+
}
|
|
28
28
|
};
|
|
29
29
|
export default async function checkInternal() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
let failed = false;
|
|
31
|
+
for (const task of tasks) {
|
|
32
|
+
try {
|
|
33
|
+
await runTask(task);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
failed = true;
|
|
37
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
process.exitCode = failed ? 1 : 0;
|
|
41
|
+
console[failed ? 'error' : 'log'](failed ? 'Internal checks failed.' : 'Internal checks passed.');
|
|
39
42
|
}
|
|
@@ -1,199 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
4
|
-
import { normalizeContexts } from '../init/initAliases.js';
|
|
5
|
-
import { SHARED_ESSENTIALS_DIR_NAME } from '../utils/sharedFoundation.js';
|
|
6
|
-
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
7
|
-
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
8
|
-
const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
|
|
9
|
-
const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
|
|
10
|
-
const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
11
|
-
const toPosixPath = (value) => value.split(path.sep).join('/');
|
|
12
|
-
const normalizeAlias = (value, fallback = '') => {
|
|
13
|
-
const raw = String(value ?? '').trim();
|
|
14
|
-
if (!raw.length) return fallback;
|
|
15
|
-
return raw.startsWith('$') ? raw : `$${raw}`;
|
|
16
|
-
};
|
|
17
|
-
const findLineByIndex = (content, index) => {
|
|
18
|
-
let line = 1;
|
|
19
|
-
for (let i = 0; i < index; i += 1) {
|
|
20
|
-
if (content[i] === '\n') line += 1;
|
|
21
|
-
}
|
|
22
|
-
return line;
|
|
23
|
-
};
|
|
24
|
-
const getRelativePath = (filePath) => toPosixPath(path.relative(process.cwd(), filePath));
|
|
25
|
-
const listFiles = async (rootDir) => {
|
|
26
|
-
const files = [];
|
|
27
|
-
const stack = [rootDir];
|
|
28
|
-
while (stack.length) {
|
|
29
|
-
const current = stack.pop();
|
|
30
|
-
if (!current) continue;
|
|
31
|
-
let entries = [];
|
|
32
|
-
try {
|
|
33
|
-
entries = await fs.readdir(current, { withFileTypes: true });
|
|
34
|
-
} catch {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
for (const entry of entries) {
|
|
38
|
-
if (entry.isDirectory()) {
|
|
39
|
-
if (!IGNORED_DIRS.has(entry.name)) {
|
|
40
|
-
stack.push(path.join(current, entry.name));
|
|
41
|
-
}
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (!entry.isFile()) continue;
|
|
45
|
-
const filePath = path.join(current, entry.name);
|
|
46
|
-
if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
|
|
47
|
-
files.push(filePath);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return files;
|
|
51
|
-
};
|
|
52
|
-
const extractImports = (content) => {
|
|
53
|
-
const matches = [];
|
|
54
|
-
const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
|
|
55
|
-
for (const pattern of patterns) {
|
|
56
|
-
const regex = new RegExp(pattern.source, 'g');
|
|
57
|
-
let match;
|
|
58
|
-
while ((match = regex.exec(content)) !== null) {
|
|
59
|
-
const value = match[1];
|
|
60
|
-
if (!value) continue;
|
|
61
|
-
matches.push({ value, line: findLineByIndex(content, match.index) });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return matches;
|
|
65
|
-
};
|
|
66
|
-
const resolveAliasFromImport = (importPath, aliases) => {
|
|
67
|
-
const sorted = [...aliases].sort((a, b) => b.length - a.length);
|
|
68
|
-
for (const alias of sorted) {
|
|
69
|
-
if (importPath === alias || importPath.startsWith(`${alias}/`)) {
|
|
70
|
-
return alias;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
};
|
|
75
|
-
const resolveContextFromRelativeImport = (filePath, importPath, contexts) => {
|
|
76
|
-
if (!importPath.startsWith('.')) return null;
|
|
77
|
-
const absoluteImportPath = path.resolve(path.dirname(filePath), importPath);
|
|
78
|
-
const appRoot = path.join(process.cwd(), 'src', 'app');
|
|
79
|
-
for (const context of contexts) {
|
|
80
|
-
const contextRoot = path.join(appRoot, context.name);
|
|
81
|
-
if (absoluteImportPath === contextRoot || absoluteImportPath.startsWith(`${contextRoot}${path.sep}`)) {
|
|
82
|
-
return context;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
};
|
|
87
|
-
const isInside = (targetPath, rootPath) => targetPath === rootPath || targetPath.startsWith(`${rootPath}${path.sep}`);
|
|
88
|
-
const resolveAbsoluteRelativeImport = (filePath, importPath) => {
|
|
89
|
-
if (!importPath.startsWith('.')) return null;
|
|
90
|
-
return path.resolve(path.dirname(filePath), importPath);
|
|
91
|
-
};
|
|
1
|
+
import { checkDependencies } from './architecture.js';
|
|
2
|
+
const common = new Set(['Ui', 'Scopes', 'Shell', 'routes', 'Routes']);
|
|
92
3
|
export default async function checkLayerBoundaries() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (!sharedContext) {
|
|
114
|
-
console.error(`❌ sharedAlias "${sharedAlias}" does not point to any configured context.`);
|
|
115
|
-
process.exitCode = 1;
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const issues = [];
|
|
119
|
-
for (const context of contexts) {
|
|
120
|
-
const contextRoot = path.join(process.cwd(), 'src', 'app', context.name);
|
|
121
|
-
const isSharedContext = context.alias === sharedAlias;
|
|
122
|
-
const sharedEssentialsRoot = isSharedContext ? path.join(contextRoot, SHARED_ESSENTIALS_DIR_NAME) : null;
|
|
123
|
-
try {
|
|
124
|
-
await fs.access(contextRoot);
|
|
125
|
-
} catch {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
const files = await listFiles(contextRoot);
|
|
129
|
-
const allowedAliases = new Set([context.alias]);
|
|
130
|
-
if (context.alias !== sharedAlias) {
|
|
131
|
-
allowedAliases.add(sharedAlias);
|
|
132
|
-
}
|
|
133
|
-
for (const filePath of files) {
|
|
134
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
135
|
-
const imports = extractImports(content);
|
|
136
|
-
const isSharedEssentialsFile = Boolean(sharedEssentialsRoot && isInside(filePath, sharedEssentialsRoot));
|
|
137
|
-
for (const entry of imports) {
|
|
138
|
-
const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
|
|
139
|
-
if (!targetAlias) continue;
|
|
140
|
-
if (isSharedEssentialsFile && targetAlias === sharedAlias) {
|
|
141
|
-
const importRest = entry.value.slice(sharedAlias.length).replace(/^\/+/, '');
|
|
142
|
-
if (importRest.length && !importRest.startsWith(`${SHARED_ESSENTIALS_DIR_NAME}/`)) {
|
|
143
|
-
issues.push({
|
|
144
|
-
file: filePath,
|
|
145
|
-
line: entry.line,
|
|
146
|
-
message: `Layer boundary violation: shared essentials cannot import from shared "${importRest}". Essentials may depend only on shared essentials code.`
|
|
147
|
-
});
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (allowedAliases.has(targetAlias)) continue;
|
|
152
|
-
const targetContext = aliasToContext.get(targetAlias);
|
|
153
|
-
const baseMessage = targetContext
|
|
154
|
-
? `Layer boundary violation: context "${context.name}" cannot import from context "${targetContext.name}" (${targetAlias})`
|
|
155
|
-
: `Layer boundary violation: context "${context.name}" cannot import from "${targetAlias}"`;
|
|
156
|
-
issues.push({
|
|
157
|
-
file: filePath,
|
|
158
|
-
line: entry.line,
|
|
159
|
-
message: baseMessage
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
for (const entry of imports) {
|
|
163
|
-
const absoluteRelativeImport = resolveAbsoluteRelativeImport(filePath, entry.value);
|
|
164
|
-
if (
|
|
165
|
-
isSharedEssentialsFile &&
|
|
166
|
-
absoluteRelativeImport &&
|
|
167
|
-
sharedEssentialsRoot &&
|
|
168
|
-
isInside(absoluteRelativeImport, contextRoot) &&
|
|
169
|
-
!isInside(absoluteRelativeImport, sharedEssentialsRoot)
|
|
170
|
-
) {
|
|
171
|
-
issues.push({
|
|
172
|
-
file: filePath,
|
|
173
|
-
line: entry.line,
|
|
174
|
-
message: 'Layer boundary violation: shared essentials cannot import from shared layers/ui via relative path.'
|
|
175
|
-
});
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const relativeTargetContext = resolveContextFromRelativeImport(filePath, entry.value, contexts);
|
|
179
|
-
if (!relativeTargetContext || relativeTargetContext.name === context.name) continue;
|
|
180
|
-
if (context.alias !== sharedAlias && relativeTargetContext.alias === sharedAlias) continue;
|
|
181
|
-
const baseMessage = `Layer boundary violation: context "${context.name}" cannot import from context "${relativeTargetContext.name}" via relative path`;
|
|
182
|
-
issues.push({
|
|
183
|
-
file: filePath,
|
|
184
|
-
line: entry.line,
|
|
185
|
-
message: baseMessage
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (!issues.length) {
|
|
191
|
-
console.log('✅ Layer boundaries check passed.');
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
console.error('❌ Layer boundaries check failed:');
|
|
195
|
-
for (const issue of issues) {
|
|
196
|
-
console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
|
|
197
|
-
}
|
|
198
|
-
process.exitCode = 1;
|
|
4
|
+
await checkDependencies('Layer boundaries', (source, target) => {
|
|
5
|
+
if (source[0] === 'Contexts') {
|
|
6
|
+
if (target[0] === 'Presentation')
|
|
7
|
+
return 'Contexts cannot import Presentation';
|
|
8
|
+
if (target[0] === 'Contexts' &&
|
|
9
|
+
source[1] !== target[1] &&
|
|
10
|
+
target[1] &&
|
|
11
|
+
(source[1] === 'SharedKernel' || target[1] !== 'SharedKernel')) {
|
|
12
|
+
return `Context "${source[1]}" cannot import context "${target[1]}"; only SharedKernel is shared`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (source[0] === 'Presentation' && target[0] === 'Presentation') {
|
|
16
|
+
const from = source[1];
|
|
17
|
+
const to = target[1];
|
|
18
|
+
if (from && to && source.length > 2 && !common.has(from) && !common.has(to) && from !== to && to !== 'Shared') {
|
|
19
|
+
return `Presentation workspace "${from}" cannot import workspace "${to}"`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
});
|
|
199
24
|
}
|
|
@@ -1,136 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { normalizeContexts } from '../init/initAliases.js';
|
|
4
|
-
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
5
|
-
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
6
|
-
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
7
|
-
const LAYERS = ['domain', 'application', 'infrastructure', 'presentation'];
|
|
8
|
-
const FORBIDDEN_LAYER_IMPORTS = {
|
|
9
|
-
infrastructure: ['application', 'presentation'],
|
|
10
|
-
application: ['presentation'],
|
|
11
|
-
domain: ['application', 'infrastructure', 'presentation'],
|
|
12
|
-
presentation: []
|
|
13
|
-
};
|
|
14
|
-
const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
|
|
15
|
-
const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
|
|
16
|
-
const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
17
|
-
const toPosixPath = (value) => value.split(path.sep).join('/');
|
|
18
|
-
const findLineByIndex = (content, index) => {
|
|
19
|
-
let line = 1;
|
|
20
|
-
for (let i = 0; i < index; i += 1) {
|
|
21
|
-
if (content[i] === '\n') line += 1;
|
|
22
|
-
}
|
|
23
|
-
return line;
|
|
24
|
-
};
|
|
25
|
-
const getRelativePath = (filePath) => toPosixPath(path.relative(process.cwd(), filePath));
|
|
26
|
-
const listFiles = async (rootDir) => {
|
|
27
|
-
const files = [];
|
|
28
|
-
const stack = [rootDir];
|
|
29
|
-
while (stack.length) {
|
|
30
|
-
const current = stack.pop();
|
|
31
|
-
if (!current) continue;
|
|
32
|
-
let entries = [];
|
|
33
|
-
try {
|
|
34
|
-
entries = await fs.readdir(current, { withFileTypes: true });
|
|
35
|
-
} catch {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
for (const entry of entries) {
|
|
39
|
-
if (entry.isDirectory()) {
|
|
40
|
-
if (!IGNORED_DIRS.has(entry.name)) {
|
|
41
|
-
stack.push(path.join(current, entry.name));
|
|
42
|
-
}
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (!entry.isFile()) continue;
|
|
46
|
-
const filePath = path.join(current, entry.name);
|
|
47
|
-
if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
|
|
48
|
-
files.push(filePath);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return files;
|
|
52
|
-
};
|
|
53
|
-
const extractImports = (content) => {
|
|
54
|
-
const matches = [];
|
|
55
|
-
const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
|
|
56
|
-
for (const pattern of patterns) {
|
|
57
|
-
const regex = new RegExp(pattern.source, 'g');
|
|
58
|
-
let match;
|
|
59
|
-
while ((match = regex.exec(content)) !== null) {
|
|
60
|
-
const value = match[1];
|
|
61
|
-
if (!value) continue;
|
|
62
|
-
matches.push({ value, line: findLineByIndex(content, match.index) });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return matches;
|
|
66
|
-
};
|
|
67
|
-
const getLayerFromPath = (filePath, contextRoot) => {
|
|
68
|
-
for (const layer of LAYERS) {
|
|
69
|
-
const layerRoot = path.join(contextRoot, 'layers', layer);
|
|
70
|
-
if (filePath === layerRoot || filePath.startsWith(`${layerRoot}${path.sep}`)) {
|
|
71
|
-
return layer;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
};
|
|
76
|
-
const getLayerFromAliasImport = (importPath, context) => {
|
|
77
|
-
if (importPath !== context.alias && !importPath.startsWith(`${context.alias}/`)) return null;
|
|
78
|
-
const withoutAlias = importPath.slice(context.alias.length).replace(/^\/+/, '');
|
|
79
|
-
for (const layer of LAYERS) {
|
|
80
|
-
if (withoutAlias === `layers/${layer}` || withoutAlias.startsWith(`layers/${layer}/`)) return layer;
|
|
81
|
-
if (withoutAlias === layer || withoutAlias.startsWith(`${layer}/`)) return layer;
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
};
|
|
85
|
-
const getLayerFromRelativeImport = (filePath, importPath, contextRoot) => {
|
|
86
|
-
if (!importPath.startsWith('.')) return null;
|
|
87
|
-
const absoluteImportPath = path.resolve(path.dirname(filePath), importPath);
|
|
88
|
-
return getLayerFromPath(absoluteImportPath, contextRoot);
|
|
89
|
-
};
|
|
90
|
-
const createMessage = (sourceLayer, targetLayer, context) =>
|
|
91
|
-
`Layer import violation: "${context.name}" ${sourceLayer} layer cannot import from ${targetLayer} layer`;
|
|
1
|
+
import { checkDependencies } from './architecture.js';
|
|
92
2
|
export default async function checkLayerImports() {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const files = await listFiles(path.join(contextRoot, 'layers'));
|
|
109
|
-
for (const filePath of files) {
|
|
110
|
-
const sourceLayer = getLayerFromPath(filePath, contextRoot);
|
|
111
|
-
if (!sourceLayer) continue;
|
|
112
|
-
const forbiddenLayers = FORBIDDEN_LAYER_IMPORTS[sourceLayer];
|
|
113
|
-
if (!forbiddenLayers.length) continue;
|
|
114
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
115
|
-
const imports = extractImports(content);
|
|
116
|
-
for (const entry of imports) {
|
|
117
|
-
const targetLayer = getLayerFromAliasImport(entry.value, context) ?? getLayerFromRelativeImport(filePath, entry.value, contextRoot);
|
|
118
|
-
if (!targetLayer || !forbiddenLayers.includes(targetLayer)) continue;
|
|
119
|
-
issues.push({
|
|
120
|
-
file: filePath,
|
|
121
|
-
line: entry.line,
|
|
122
|
-
message: createMessage(sourceLayer, targetLayer, context)
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (!issues.length) {
|
|
128
|
-
console.log('✅ Layer imports check passed.');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
console.error('❌ Layer imports check failed:');
|
|
132
|
-
for (const issue of issues) {
|
|
133
|
-
console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
|
|
134
|
-
}
|
|
135
|
-
process.exitCode = 1;
|
|
3
|
+
await checkDependencies('Layer imports', (source, target) => {
|
|
4
|
+
if (source[0] !== 'Contexts')
|
|
5
|
+
return null;
|
|
6
|
+
if (target[0] === 'Presentation')
|
|
7
|
+
return 'Contexts cannot import Presentation';
|
|
8
|
+
if (target[0] !== 'Contexts')
|
|
9
|
+
return null;
|
|
10
|
+
const from = source[2];
|
|
11
|
+
const to = target[2];
|
|
12
|
+
if ((from === 'Domain' && (to === 'Application' || to === 'Infrastructure')) || (from === 'Infrastructure' && to === 'Application'))
|
|
13
|
+
return `${from} cannot import ${to}`;
|
|
14
|
+
return null;
|
|
15
|
+
});
|
|
136
16
|
}
|