@azure-net/cli 4.1.0 → 4.1.1
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/bin/azure-net.js +9 -1
- package/bin/azure-net.ts +1 -1
- package/package.json +1 -1
- package/src/checks/checkImports.js +147 -0
- package/src/checks/checkImports.ts +28 -1
- package/src/checks/checkInternal.js +3 -4
- package/src/checks/checkLayerBoundaries.js +63 -38
- package/src/checks/checkLayerBoundaries.ts +48 -6
- package/src/checks/index.js +2 -0
package/bin/azure-net.js
CHANGED
|
@@ -5,7 +5,7 @@ import { addLint } from '../src/plugins/index.js';
|
|
|
5
5
|
|
|
6
6
|
const program = new Command();
|
|
7
7
|
|
|
8
|
-
program.name('azure-net').description('Azure-Net CLI generator').version('
|
|
8
|
+
program.name('azure-net').description('Azure-Net CLI generator').version('4.1.0');
|
|
9
9
|
|
|
10
10
|
const addCommand = program.command('add').description('Add project integrations and plugins');
|
|
11
11
|
const createCommand = program.command('create').description('Create project boilerplate artifacts');
|
|
@@ -257,6 +257,14 @@ checkCommand
|
|
|
257
257
|
await handler();
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
+
checkCommand
|
|
261
|
+
.command('imports')
|
|
262
|
+
.description('Check import extensions and import group order in src')
|
|
263
|
+
.action(async () => {
|
|
264
|
+
const handler = (await import('../src/checks/checkImports.js')).default;
|
|
265
|
+
await handler();
|
|
266
|
+
});
|
|
267
|
+
|
|
260
268
|
checkCommand
|
|
261
269
|
.command('layer-boundaries')
|
|
262
270
|
.description('Check layer boundaries between contexts by aliases')
|
package/bin/azure-net.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { addLint } from '../src/plugins/index.js';
|
|
|
5
5
|
|
|
6
6
|
const program = new Command();
|
|
7
7
|
|
|
8
|
-
program.name('azure-net').description('Azure-Net CLI generator').version('4.
|
|
8
|
+
program.name('azure-net').description('Azure-Net CLI generator').version('4.1.0');
|
|
9
9
|
|
|
10
10
|
const addCommand = program.command('add').description('Add project integrations and plugins');
|
|
11
11
|
const createCommand = program.command('create').description('Create project boilerplate artifacts');
|
package/package.json
CHANGED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
4
|
+
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
5
|
+
const IMPORT_DECLARATION_PATTERN = /(^|\n)\s*import\s+(?:[\s\S]*?\s+from\s*)?['"]([^'"]+)['"]\s*;?/g;
|
|
6
|
+
const EXPORT_DECLARATION_PATTERN = /(^|\n)\s*export\s+(?:type\s+)?(?:[\s\S]*?\s+from\s*)['"]([^'"]+)['"]\s*;?/g;
|
|
7
|
+
const FORBIDDEN_IMPORT_EXTENSION_PATTERN = /\.(?:ts|js)(?:$|[?#])/;
|
|
8
|
+
const toPosixPath = (value) => value.split(path.sep).join('/');
|
|
9
|
+
const getRelativePath = (filePath) => toPosixPath(path.relative(process.cwd(), filePath));
|
|
10
|
+
const findLineByIndex = (content, index) => {
|
|
11
|
+
let line = 1;
|
|
12
|
+
for (let i = 0; i < index; i += 1) {
|
|
13
|
+
if (content[i] === '\n') line += 1;
|
|
14
|
+
}
|
|
15
|
+
return line;
|
|
16
|
+
};
|
|
17
|
+
const listFiles = async (rootDir) => {
|
|
18
|
+
const files = [];
|
|
19
|
+
const stack = [rootDir];
|
|
20
|
+
while (stack.length) {
|
|
21
|
+
const current = stack.pop();
|
|
22
|
+
if (!current) continue;
|
|
23
|
+
let entries = [];
|
|
24
|
+
try {
|
|
25
|
+
entries = await fs.readdir(current, { withFileTypes: true });
|
|
26
|
+
} catch {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (entry.isDirectory()) {
|
|
31
|
+
if (!IGNORED_DIRS.has(entry.name)) {
|
|
32
|
+
stack.push(path.join(current, entry.name));
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!entry.isFile()) continue;
|
|
37
|
+
const filePath = path.join(current, entry.name);
|
|
38
|
+
if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
|
|
39
|
+
files.push(filePath);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return files;
|
|
43
|
+
};
|
|
44
|
+
const getImportKind = (raw) => {
|
|
45
|
+
const normalized = raw.trim();
|
|
46
|
+
if (/^import\s+type\b/.test(normalized)) return 'type';
|
|
47
|
+
if (/^import\s*['"]/.test(normalized)) return 'side-effect';
|
|
48
|
+
return 'value';
|
|
49
|
+
};
|
|
50
|
+
const getKindOrder = (kind) => {
|
|
51
|
+
if (kind === 'value') return 0;
|
|
52
|
+
if (kind === 'type') return 1;
|
|
53
|
+
return 2;
|
|
54
|
+
};
|
|
55
|
+
const extractImports = (content) => {
|
|
56
|
+
const imports = [];
|
|
57
|
+
const regex = new RegExp(IMPORT_DECLARATION_PATTERN.source, 'g');
|
|
58
|
+
let match;
|
|
59
|
+
while ((match = regex.exec(content)) !== null) {
|
|
60
|
+
const raw = match[0].trim();
|
|
61
|
+
const source = match[2];
|
|
62
|
+
if (!source) continue;
|
|
63
|
+
imports.push({
|
|
64
|
+
kind: getImportKind(raw),
|
|
65
|
+
line: findLineByIndex(content, match.index + (match[1] === '\n' ? 1 : 0)),
|
|
66
|
+
source,
|
|
67
|
+
raw
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return imports.sort((a, b) => a.line - b.line);
|
|
71
|
+
};
|
|
72
|
+
const extractExportSources = (content) => {
|
|
73
|
+
const exports = [];
|
|
74
|
+
const regex = new RegExp(EXPORT_DECLARATION_PATTERN.source, 'g');
|
|
75
|
+
let match;
|
|
76
|
+
while ((match = regex.exec(content)) !== null) {
|
|
77
|
+
const source = match[2];
|
|
78
|
+
if (!source) continue;
|
|
79
|
+
exports.push({
|
|
80
|
+
source,
|
|
81
|
+
line: findLineByIndex(content, match.index + (match[1] === '\n' ? 1 : 0))
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return exports;
|
|
85
|
+
};
|
|
86
|
+
const hasForbiddenExtension = (source) => {
|
|
87
|
+
const sourceWithoutQuery = source.split('?')[0] ?? source;
|
|
88
|
+
return FORBIDDEN_IMPORT_EXTENSION_PATTERN.test(sourceWithoutQuery);
|
|
89
|
+
};
|
|
90
|
+
const collectIssuesForFile = (filePath, content) => {
|
|
91
|
+
const issues = [];
|
|
92
|
+
const imports = extractImports(content);
|
|
93
|
+
let lastKindOrder = 0;
|
|
94
|
+
for (const importEntry of imports) {
|
|
95
|
+
if (hasForbiddenExtension(importEntry.source)) {
|
|
96
|
+
issues.push({
|
|
97
|
+
file: filePath,
|
|
98
|
+
line: importEntry.line,
|
|
99
|
+
message: `Import "${importEntry.source}" must not include .ts/.js extension`
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const currentOrder = getKindOrder(importEntry.kind);
|
|
103
|
+
if (currentOrder < lastKindOrder) {
|
|
104
|
+
issues.push({
|
|
105
|
+
file: filePath,
|
|
106
|
+
line: importEntry.line,
|
|
107
|
+
message: 'Import order violation: value imports first, then type imports, then side-effect imports'
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
lastKindOrder = Math.max(lastKindOrder, currentOrder);
|
|
111
|
+
}
|
|
112
|
+
for (const exportEntry of extractExportSources(content)) {
|
|
113
|
+
if (!hasForbiddenExtension(exportEntry.source)) continue;
|
|
114
|
+
issues.push({
|
|
115
|
+
file: filePath,
|
|
116
|
+
line: exportEntry.line,
|
|
117
|
+
message: `Export source "${exportEntry.source}" must not include .ts/.js extension`
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return issues;
|
|
121
|
+
};
|
|
122
|
+
export default async function checkImports() {
|
|
123
|
+
const srcRoot = path.join(process.cwd(), 'src');
|
|
124
|
+
try {
|
|
125
|
+
await fs.access(srcRoot);
|
|
126
|
+
} catch {
|
|
127
|
+
console.error('❌ src folder not found.');
|
|
128
|
+
process.exitCode = 1;
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const issues = [];
|
|
132
|
+
const files = await listFiles(srcRoot);
|
|
133
|
+
for (const filePath of files) {
|
|
134
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
135
|
+
issues.push(...collectIssuesForFile(filePath, content));
|
|
136
|
+
}
|
|
137
|
+
if (!issues.length) {
|
|
138
|
+
console.log('✅ Imports check passed: extensions and import groups are valid.');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
console.error('❌ Imports check failed:');
|
|
142
|
+
for (const issue of issues) {
|
|
143
|
+
console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
|
|
144
|
+
}
|
|
145
|
+
process.exitCode = 1;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=checkImports.js.map
|
|
@@ -19,7 +19,8 @@ type ImportEntry = {
|
|
|
19
19
|
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
20
20
|
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
21
21
|
const IMPORT_DECLARATION_PATTERN = /(^|\n)\s*import\s+(?:[\s\S]*?\s+from\s*)?['"]([^'"]+)['"]\s*;?/g;
|
|
22
|
-
const
|
|
22
|
+
const EXPORT_DECLARATION_PATTERN = /(^|\n)\s*export\s+(?:type\s+)?(?:[\s\S]*?\s+from\s*)['"]([^'"]+)['"]\s*;?/g;
|
|
23
|
+
const FORBIDDEN_IMPORT_EXTENSION_PATTERN = /\.(?:ts|js)(?:$|[?#])/;
|
|
23
24
|
|
|
24
25
|
const toPosixPath = (value: string): string => value.split(path.sep).join('/');
|
|
25
26
|
|
|
@@ -100,6 +101,23 @@ const extractImports = (content: string): ImportEntry[] => {
|
|
|
100
101
|
return imports.sort((a, b) => a.line - b.line);
|
|
101
102
|
};
|
|
102
103
|
|
|
104
|
+
const extractExportSources = (content: string): Array<{ source: string; line: number }> => {
|
|
105
|
+
const exports: Array<{ source: string; line: number }> = [];
|
|
106
|
+
const regex = new RegExp(EXPORT_DECLARATION_PATTERN.source, 'g');
|
|
107
|
+
let match: RegExpExecArray | null;
|
|
108
|
+
|
|
109
|
+
while ((match = regex.exec(content)) !== null) {
|
|
110
|
+
const source = match[2];
|
|
111
|
+
if (!source) continue;
|
|
112
|
+
exports.push({
|
|
113
|
+
source,
|
|
114
|
+
line: findLineByIndex(content, match.index + (match[1] === '\n' ? 1 : 0))
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return exports;
|
|
119
|
+
};
|
|
120
|
+
|
|
103
121
|
const hasForbiddenExtension = (source: string): boolean => {
|
|
104
122
|
const sourceWithoutQuery = source.split('?')[0] ?? source;
|
|
105
123
|
return FORBIDDEN_IMPORT_EXTENSION_PATTERN.test(sourceWithoutQuery);
|
|
@@ -130,6 +148,15 @@ const collectIssuesForFile = (filePath: string, content: string): ImportIssue[]
|
|
|
130
148
|
lastKindOrder = Math.max(lastKindOrder, currentOrder);
|
|
131
149
|
}
|
|
132
150
|
|
|
151
|
+
for (const exportEntry of extractExportSources(content)) {
|
|
152
|
+
if (!hasForbiddenExtension(exportEntry.source)) continue;
|
|
153
|
+
issues.push({
|
|
154
|
+
file: filePath,
|
|
155
|
+
line: exportEntry.line,
|
|
156
|
+
message: `Export source "${exportEntry.source}" must not include .ts/.js extension`
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
133
160
|
return issues;
|
|
134
161
|
};
|
|
135
162
|
|
|
@@ -4,26 +4,24 @@ import checkProviderGraph from './checkProviderGraph.js';
|
|
|
4
4
|
import checkDomain from './checkDomain.js';
|
|
5
5
|
import checkLayerBoundaries from './checkLayerBoundaries.js';
|
|
6
6
|
import checkFoldersStructure from './checkFoldersStructure.js';
|
|
7
|
-
|
|
7
|
+
import checkImports from './checkImports.js';
|
|
8
8
|
const tasks = [
|
|
9
9
|
{ name: 'presenter-names', run: checkPresenterNames },
|
|
10
10
|
{ name: 'provider-names', run: checkProviderNames },
|
|
11
11
|
{ name: 'provider-graph', run: checkProviderGraph },
|
|
12
12
|
{ name: 'domain', run: checkDomain },
|
|
13
|
+
{ name: 'imports', run: checkImports },
|
|
13
14
|
{ name: 'layer-boundaries', run: checkLayerBoundaries },
|
|
14
15
|
{ name: 'folders-structure', run: checkFoldersStructure }
|
|
15
16
|
];
|
|
16
|
-
|
|
17
17
|
const runTask = async (task) => {
|
|
18
18
|
console.log(`\n▶ Running check ${task.name}...`);
|
|
19
19
|
process.exitCode = 0;
|
|
20
20
|
await task.run();
|
|
21
|
-
|
|
22
21
|
if ((process.exitCode ?? 0) !== 0) {
|
|
23
22
|
throw new Error(`Check "${task.name}" failed`);
|
|
24
23
|
}
|
|
25
24
|
};
|
|
26
|
-
|
|
27
25
|
export default async function checkInternal() {
|
|
28
26
|
try {
|
|
29
27
|
for (const task of tasks) {
|
|
@@ -35,3 +33,4 @@ export default async function checkInternal() {
|
|
|
35
33
|
process.exitCode = 1;
|
|
36
34
|
}
|
|
37
35
|
}
|
|
36
|
+
//# sourceMappingURL=checkInternal.js.map
|
|
@@ -2,22 +2,17 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { loadUserConfig } from '../utils/loadConfig.js';
|
|
4
4
|
import { normalizeContexts } from '../init/initAliases.js';
|
|
5
|
-
|
|
6
5
|
const TARGET_EXTENSIONS = new Set(['.ts', '.js', '.svelte']);
|
|
7
6
|
const IGNORED_DIRS = new Set(['node_modules', 'dist', '.svelte-kit', '.git']);
|
|
8
|
-
|
|
9
7
|
const IMPORT_FROM_PATTERN = /\bimport\s+(?:type\s+)?[\s\S]*?\sfrom\s*['"]([^'"]+)['"]/g;
|
|
10
8
|
const EXPORT_FROM_PATTERN = /\bexport\s+(?:type\s+)?\{[\s\S]*?\}\sfrom\s*['"]([^'"]+)['"]/g;
|
|
11
9
|
const DYNAMIC_IMPORT_PATTERN = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
12
|
-
|
|
13
10
|
const toPosixPath = (value) => value.split(path.sep).join('/');
|
|
14
|
-
|
|
15
11
|
const normalizeAlias = (value, fallback = '') => {
|
|
16
12
|
const raw = String(value ?? '').trim();
|
|
17
13
|
if (!raw.length) return fallback;
|
|
18
14
|
return raw.startsWith('$') ? raw : `$${raw}`;
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
const findLineByIndex = (content, index) => {
|
|
22
17
|
let line = 1;
|
|
23
18
|
for (let i = 0; i < index; i += 1) {
|
|
@@ -25,24 +20,19 @@ const findLineByIndex = (content, index) => {
|
|
|
25
20
|
}
|
|
26
21
|
return line;
|
|
27
22
|
};
|
|
28
|
-
|
|
29
23
|
const getRelativePath = (filePath) => toPosixPath(path.relative(process.cwd(), filePath));
|
|
30
|
-
|
|
31
24
|
const listFiles = async (rootDir) => {
|
|
32
25
|
const files = [];
|
|
33
26
|
const stack = [rootDir];
|
|
34
|
-
|
|
35
27
|
while (stack.length) {
|
|
36
28
|
const current = stack.pop();
|
|
37
29
|
if (!current) continue;
|
|
38
|
-
|
|
39
30
|
let entries = [];
|
|
40
31
|
try {
|
|
41
32
|
entries = await fs.readdir(current, { withFileTypes: true });
|
|
42
33
|
} catch {
|
|
43
34
|
continue;
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
for (const entry of entries) {
|
|
47
37
|
if (entry.isDirectory()) {
|
|
48
38
|
if (!IGNORED_DIRS.has(entry.name)) {
|
|
@@ -50,21 +40,17 @@ const listFiles = async (rootDir) => {
|
|
|
50
40
|
}
|
|
51
41
|
continue;
|
|
52
42
|
}
|
|
53
|
-
|
|
54
43
|
if (!entry.isFile()) continue;
|
|
55
44
|
const filePath = path.join(current, entry.name);
|
|
56
45
|
if (!TARGET_EXTENSIONS.has(path.extname(filePath))) continue;
|
|
57
46
|
files.push(filePath);
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
return files;
|
|
62
50
|
};
|
|
63
|
-
|
|
64
51
|
const extractImports = (content) => {
|
|
65
52
|
const matches = [];
|
|
66
53
|
const patterns = [IMPORT_FROM_PATTERN, EXPORT_FROM_PATTERN, DYNAMIC_IMPORT_PATTERN];
|
|
67
|
-
|
|
68
54
|
for (const pattern of patterns) {
|
|
69
55
|
const regex = new RegExp(pattern.source, 'g');
|
|
70
56
|
let match;
|
|
@@ -74,10 +60,8 @@ const extractImports = (content) => {
|
|
|
74
60
|
matches.push({ value, line: findLineByIndex(content, match.index) });
|
|
75
61
|
}
|
|
76
62
|
}
|
|
77
|
-
|
|
78
63
|
return matches;
|
|
79
64
|
};
|
|
80
|
-
|
|
81
65
|
const resolveAliasFromImport = (importPath, aliases) => {
|
|
82
66
|
const sorted = [...aliases].sort((a, b) => b.length - a.length);
|
|
83
67
|
for (const alias of sorted) {
|
|
@@ -87,74 +71,117 @@ const resolveAliasFromImport = (importPath, aliases) => {
|
|
|
87
71
|
}
|
|
88
72
|
return null;
|
|
89
73
|
};
|
|
90
|
-
|
|
74
|
+
const resolveContextFromRelativeImport = (filePath, importPath, contexts) => {
|
|
75
|
+
if (!importPath.startsWith('.')) return null;
|
|
76
|
+
const absoluteImportPath = path.resolve(path.dirname(filePath), importPath);
|
|
77
|
+
const appRoot = path.join(process.cwd(), 'src', 'app');
|
|
78
|
+
for (const context of contexts) {
|
|
79
|
+
const contextRoot = path.join(appRoot, context.name);
|
|
80
|
+
if (absoluteImportPath === contextRoot || absoluteImportPath.startsWith(`${contextRoot}${path.sep}`)) {
|
|
81
|
+
return context;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
};
|
|
91
86
|
const isSharedLikeContext = (contextName, alias) => {
|
|
92
87
|
const normalizedName = contextName.toLowerCase();
|
|
93
88
|
const normalizedAlias = alias.toLowerCase();
|
|
94
89
|
return normalizedName.includes('shared') || normalizedAlias.includes('shared');
|
|
95
90
|
};
|
|
96
|
-
|
|
97
91
|
export default async function checkLayerBoundaries() {
|
|
98
92
|
const config = await loadUserConfig();
|
|
99
93
|
const contexts = normalizeContexts(config.contexts);
|
|
100
|
-
|
|
101
94
|
if (!contexts.length) {
|
|
102
95
|
console.error('❌ No contexts found in azure-net.config.ts/js. Fill `contexts` first.');
|
|
103
96
|
process.exitCode = 1;
|
|
104
97
|
return;
|
|
105
98
|
}
|
|
106
|
-
|
|
107
99
|
const coreAlias = normalizeAlias(config.coreAlias, '$core');
|
|
108
100
|
const sharedAliasRaw = normalizeAlias(config.sharedAlias, '');
|
|
109
101
|
const sharedAlias = sharedAliasRaw.length ? sharedAliasRaw : null;
|
|
110
|
-
|
|
111
102
|
const aliasToContext = new Map();
|
|
112
103
|
for (const context of contexts) {
|
|
113
104
|
aliasToContext.set(context.alias, context);
|
|
114
105
|
}
|
|
115
|
-
|
|
116
106
|
const knownAliases = [coreAlias, ...contexts.map((context) => context.alias)];
|
|
117
107
|
if (sharedAlias && !knownAliases.includes(sharedAlias)) {
|
|
118
108
|
knownAliases.push(sharedAlias);
|
|
119
109
|
}
|
|
120
|
-
|
|
121
110
|
const issues = [];
|
|
122
|
-
|
|
111
|
+
const coreRoot = path.join(process.cwd(), 'src', 'core');
|
|
112
|
+
try {
|
|
113
|
+
await fs.access(coreRoot);
|
|
114
|
+
const coreFiles = await listFiles(coreRoot);
|
|
115
|
+
for (const filePath of coreFiles) {
|
|
116
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
117
|
+
const imports = extractImports(content);
|
|
118
|
+
for (const entry of imports) {
|
|
119
|
+
const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
|
|
120
|
+
if (targetAlias && targetAlias !== coreAlias) {
|
|
121
|
+
const targetContext = aliasToContext.get(targetAlias);
|
|
122
|
+
issues.push({
|
|
123
|
+
file: filePath,
|
|
124
|
+
line: entry.line,
|
|
125
|
+
message: targetContext
|
|
126
|
+
? `Layer boundary violation: core cannot import from context "${targetContext.name}" (${targetAlias})`
|
|
127
|
+
: `Layer boundary violation: core cannot import from "${targetAlias}"`
|
|
128
|
+
});
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const relativeTargetContext = resolveContextFromRelativeImport(filePath, entry.value, contexts);
|
|
132
|
+
if (!relativeTargetContext) continue;
|
|
133
|
+
issues.push({
|
|
134
|
+
file: filePath,
|
|
135
|
+
line: entry.line,
|
|
136
|
+
message: `Layer boundary violation: core cannot import from context "${relativeTargetContext.name}" via relative path`
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
// Core folder is optional for the check.
|
|
142
|
+
}
|
|
123
143
|
for (const context of contexts) {
|
|
124
|
-
const
|
|
125
|
-
|
|
144
|
+
const contextRoot = path.join(process.cwd(), 'src', 'app', context.name);
|
|
126
145
|
try {
|
|
127
|
-
await fs.access(
|
|
146
|
+
await fs.access(contextRoot);
|
|
128
147
|
} catch {
|
|
129
148
|
continue;
|
|
130
149
|
}
|
|
131
|
-
|
|
132
|
-
const files = await listFiles(layersRoot);
|
|
150
|
+
const files = await listFiles(contextRoot);
|
|
133
151
|
const allowedAliases = new Set([context.alias, coreAlias]);
|
|
134
|
-
if (sharedAlias) {
|
|
152
|
+
if (sharedAlias && context.alias !== sharedAlias) {
|
|
135
153
|
allowedAliases.add(sharedAlias);
|
|
136
154
|
}
|
|
137
|
-
|
|
138
155
|
for (const filePath of files) {
|
|
139
156
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
140
157
|
const imports = extractImports(content);
|
|
141
|
-
|
|
142
158
|
for (const entry of imports) {
|
|
143
159
|
const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
|
|
144
160
|
if (!targetAlias) continue;
|
|
145
161
|
if (targetAlias === coreAlias) continue;
|
|
146
162
|
if (allowedAliases.has(targetAlias)) continue;
|
|
147
|
-
|
|
148
163
|
const targetContext = aliasToContext.get(targetAlias);
|
|
149
164
|
const baseMessage = targetContext
|
|
150
165
|
? `Layer boundary violation: context "${context.name}" cannot import from context "${targetContext.name}" (${targetAlias})`
|
|
151
166
|
: `Layer boundary violation: context "${context.name}" cannot import from "${targetAlias}"`;
|
|
152
|
-
|
|
153
167
|
const withSharedHint =
|
|
154
168
|
!sharedAlias && targetContext && isSharedLikeContext(targetContext.name, targetAlias)
|
|
155
169
|
? `${baseMessage}. sharedAlias is not configured in azure-net.config.ts/js; if this context is shared, set sharedAlias explicitly`
|
|
156
170
|
: baseMessage;
|
|
157
|
-
|
|
171
|
+
issues.push({
|
|
172
|
+
file: filePath,
|
|
173
|
+
line: entry.line,
|
|
174
|
+
message: withSharedHint
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
for (const entry of imports) {
|
|
178
|
+
const relativeTargetContext = resolveContextFromRelativeImport(filePath, entry.value, contexts);
|
|
179
|
+
if (!relativeTargetContext || relativeTargetContext.name === context.name) continue;
|
|
180
|
+
const baseMessage = `Layer boundary violation: context "${context.name}" cannot import from context "${relativeTargetContext.name}" via relative path`;
|
|
181
|
+
const withSharedHint =
|
|
182
|
+
!sharedAlias && isSharedLikeContext(relativeTargetContext.name, relativeTargetContext.alias)
|
|
183
|
+
? `${baseMessage}. sharedAlias is not configured in azure-net.config.ts/js; if this context is shared, set sharedAlias explicitly`
|
|
184
|
+
: baseMessage;
|
|
158
185
|
issues.push({
|
|
159
186
|
file: filePath,
|
|
160
187
|
line: entry.line,
|
|
@@ -163,16 +190,14 @@ export default async function checkLayerBoundaries() {
|
|
|
163
190
|
}
|
|
164
191
|
}
|
|
165
192
|
}
|
|
166
|
-
|
|
167
193
|
if (!issues.length) {
|
|
168
194
|
console.log('✅ Layer boundaries check passed.');
|
|
169
195
|
return;
|
|
170
196
|
}
|
|
171
|
-
|
|
172
197
|
console.error('❌ Layer boundaries check failed:');
|
|
173
198
|
for (const issue of issues) {
|
|
174
199
|
console.error(`• ${getRelativePath(issue.file)}:${issue.line} — ${issue.message}`);
|
|
175
200
|
}
|
|
176
|
-
|
|
177
201
|
process.exitCode = 1;
|
|
178
202
|
}
|
|
203
|
+
//# sourceMappingURL=checkLayerBoundaries.js.map
|
|
@@ -99,6 +99,22 @@ const resolveAliasFromImport = (importPath: string, aliases: string[]): string |
|
|
|
99
99
|
return null;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
const resolveContextFromRelativeImport = (filePath: string, importPath: string, contexts: ContextConfig[]): ContextConfig | null => {
|
|
103
|
+
if (!importPath.startsWith('.')) return null;
|
|
104
|
+
|
|
105
|
+
const absoluteImportPath = path.resolve(path.dirname(filePath), importPath);
|
|
106
|
+
const appRoot = path.join(process.cwd(), 'src', 'app');
|
|
107
|
+
|
|
108
|
+
for (const context of contexts) {
|
|
109
|
+
const contextRoot = path.join(appRoot, context.name);
|
|
110
|
+
if (absoluteImportPath === contextRoot || absoluteImportPath.startsWith(`${contextRoot}${path.sep}`)) {
|
|
111
|
+
return context;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return null;
|
|
116
|
+
};
|
|
117
|
+
|
|
102
118
|
const isSharedLikeContext = (contextName: string, alias: string): boolean => {
|
|
103
119
|
const normalizedName = contextName.toLowerCase();
|
|
104
120
|
const normalizedAlias = alias.toLowerCase();
|
|
@@ -141,16 +157,25 @@ export default async function checkLayerBoundaries(): Promise<void> {
|
|
|
141
157
|
|
|
142
158
|
for (const entry of imports) {
|
|
143
159
|
const targetAlias = resolveAliasFromImport(entry.value, knownAliases);
|
|
144
|
-
if (
|
|
145
|
-
|
|
160
|
+
if (targetAlias && targetAlias !== coreAlias) {
|
|
161
|
+
const targetContext = aliasToContext.get(targetAlias);
|
|
162
|
+
issues.push({
|
|
163
|
+
file: filePath,
|
|
164
|
+
line: entry.line,
|
|
165
|
+
message: targetContext
|
|
166
|
+
? `Layer boundary violation: core cannot import from context "${targetContext.name}" (${targetAlias})`
|
|
167
|
+
: `Layer boundary violation: core cannot import from "${targetAlias}"`
|
|
168
|
+
});
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const relativeTargetContext = resolveContextFromRelativeImport(filePath, entry.value, contexts);
|
|
173
|
+
if (!relativeTargetContext) continue;
|
|
146
174
|
|
|
147
|
-
const targetContext = aliasToContext.get(targetAlias);
|
|
148
175
|
issues.push({
|
|
149
176
|
file: filePath,
|
|
150
177
|
line: entry.line,
|
|
151
|
-
message:
|
|
152
|
-
? `Layer boundary violation: core cannot import from context "${targetContext.name}" (${targetAlias})`
|
|
153
|
-
: `Layer boundary violation: core cannot import from "${targetAlias}"`
|
|
178
|
+
message: `Layer boundary violation: core cannot import from context "${relativeTargetContext.name}" via relative path`
|
|
154
179
|
});
|
|
155
180
|
}
|
|
156
181
|
}
|
|
@@ -199,6 +224,23 @@ export default async function checkLayerBoundaries(): Promise<void> {
|
|
|
199
224
|
message: withSharedHint
|
|
200
225
|
});
|
|
201
226
|
}
|
|
227
|
+
|
|
228
|
+
for (const entry of imports) {
|
|
229
|
+
const relativeTargetContext = resolveContextFromRelativeImport(filePath, entry.value, contexts);
|
|
230
|
+
if (!relativeTargetContext || relativeTargetContext.name === context.name) continue;
|
|
231
|
+
|
|
232
|
+
const baseMessage = `Layer boundary violation: context "${context.name}" cannot import from context "${relativeTargetContext.name}" via relative path`;
|
|
233
|
+
const withSharedHint =
|
|
234
|
+
!sharedAlias && isSharedLikeContext(relativeTargetContext.name, relativeTargetContext.alias)
|
|
235
|
+
? `${baseMessage}. sharedAlias is not configured in azure-net.config.ts/js; if this context is shared, set sharedAlias explicitly`
|
|
236
|
+
: baseMessage;
|
|
237
|
+
|
|
238
|
+
issues.push({
|
|
239
|
+
file: filePath,
|
|
240
|
+
line: entry.line,
|
|
241
|
+
message: withSharedHint
|
|
242
|
+
});
|
|
243
|
+
}
|
|
202
244
|
}
|
|
203
245
|
}
|
|
204
246
|
|
package/src/checks/index.js
CHANGED
|
@@ -2,7 +2,9 @@ export { default as checkPresenterNames } from './checkPresenterNames.js';
|
|
|
2
2
|
export { default as checkProviderNames } from './checkProviderNames.js';
|
|
3
3
|
export { default as checkProviderGraph } from './checkProviderGraph.js';
|
|
4
4
|
export { default as checkDomain } from './checkDomain.js';
|
|
5
|
+
export { default as checkImports } from './checkImports.js';
|
|
5
6
|
export { default as checkLayerBoundaries } from './checkLayerBoundaries.js';
|
|
6
7
|
export { default as checkFoldersStructure } from './checkFoldersStructure.js';
|
|
7
8
|
export { default as checkInternal } from './checkInternal.js';
|
|
8
9
|
export { default as checkProject } from './checkProject.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|