Skip to content

Commit b3efb67

Browse files
feat: add unresolvedImports to export
1 parent 129f4ba commit b3efb67

7 files changed

Lines changed: 65 additions & 9 deletions

File tree

packages/core/src/lib/api/get-project-data.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import getFs from '../fs/getFs';
66

77
export type ProjectDataEntry = {
88
module: string;
9-
moduleType: 'barrel' | 'barrel-less',
9+
moduleType: 'barrel' | 'barrel-less';
1010
tags: string[];
1111
imports: string[];
1212
externalLibraries?: string[];
13+
unresolvedImports: string[];
1314
};
1415

1516
/**
@@ -143,12 +144,9 @@ export function getProjectData(
143144
const entry: ProjectDataEntry = {
144145
module: fileInfo.moduleInfo.path || '.',
145146
moduleType: fileInfo.moduleInfo.hasBarrel ? 'barrel' : 'barrel-less',
146-
tags: calcOrGetTags(
147-
fileInfo.moduleInfo.path,
148-
projectInfo,
149-
tagsCache,
150-
),
147+
tags: calcOrGetTags(fileInfo.moduleInfo.path, projectInfo, tagsCache),
151148
imports: fileInfo.imports.map((fileInfo) => fileInfo.path),
149+
unresolvedImports: fileInfo.unresolvableImports,
152150
};
153151

154152
if (options.includeExternalLibraries) {
@@ -184,6 +182,7 @@ function relativizeIfRequired(
184182
imports: moduleData.imports.map((importPath) =>
185183
relative(toFsPath(importPath)),
186184
),
185+
unresolvedImports: moduleData.unresolvedImports,
187186
};
188187

189188
if (options.includeExternalLibraries) {

packages/core/src/lib/checks/tests/encapsulation-barrel-less.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('barrel-less', () => {
178178
'customers.component.ts': ['../data/open.service.ts'],
179179
},
180180
data: {
181-
'index.ts': ['open.service.ts'],
181+
'index.ts': ['./open.service.ts'],
182182
'open.service.ts': [],
183183
internal: { 'hidden.service.ts': [] },
184184
},
@@ -192,7 +192,7 @@ describe('barrel-less', () => {
192192
assertProject()
193193
.withCustomerRoute({
194194
feature: {
195-
'customer.component.ts': [''],
195+
'customer.component.ts': [],
196196
'customers.component.ts': ['../data/sub1/internal/hidden.service.ts'],
197197
},
198198
data: {

packages/core/src/lib/cli/tests/__snapshots__/export-data.spec.ts.snap

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
1212
"src/holidays/index.ts",
1313
"src/customers/index.ts"
1414
],
15+
"unresolvedImports": [],
1516
"externalLibraries": []
1617
},
1718
"src/holidays/index.ts": {
@@ -21,6 +22,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
2122
"scope:holidays"
2223
],
2324
"imports": [],
25+
"unresolvedImports": [],
2426
"externalLibraries": []
2527
},
2628
"src/customers/index.ts": {
@@ -30,6 +32,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
3032
"scope:customers"
3133
],
3234
"imports": [],
35+
"unresolvedImports": [],
3336
"externalLibraries": []
3437
}
3538
}"
@@ -47,6 +50,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
4750
"src/app1.service.ts",
4851
"src/app2.service.ts"
4952
],
53+
"unresolvedImports": [],
5054
"externalLibraries": []
5155
},
5256
"src/app1.service.ts": {
@@ -58,6 +62,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
5862
"imports": [
5963
"src/app2.service.ts"
6064
],
65+
"unresolvedImports": [],
6166
"externalLibraries": []
6267
},
6368
"src/app2.service.ts": {
@@ -69,6 +74,24 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
6974
"imports": [
7075
"src/app1.service.ts"
7176
],
77+
"unresolvedImports": [],
78+
"externalLibraries": []
79+
}
80+
}"
81+
`;
82+
83+
exports[`export data > should show unresolved imports > unresolved-imports 1`] = `
84+
"{
85+
"src/main.ts": {
86+
"module": ".",
87+
"moduleType": "barrel-less",
88+
"tags": [
89+
"root"
90+
],
91+
"imports": [],
92+
"unresolvedImports": [
93+
"my-module"
94+
],
7295
"externalLibraries": []
7396
}
7497
}"
@@ -85,6 +108,7 @@ exports[`export data > should skip not reachable files > not-reachable-files 1`]
85108
"imports": [
86109
"src/app1.service.ts"
87110
],
111+
"unresolvedImports": [],
88112
"externalLibraries": []
89113
},
90114
"src/app1.service.ts": {
@@ -94,6 +118,7 @@ exports[`export data > should skip not reachable files > not-reachable-files 1`]
94118
"root"
95119
],
96120
"imports": [],
121+
"unresolvedImports": [],
97122
"externalLibraries": []
98123
}
99124
}"
@@ -110,6 +135,7 @@ exports[`export data > should test a simple application > simple-application 1`]
110135
"imports": [
111136
"src/holidays/feature/index.ts"
112137
],
138+
"unresolvedImports": [],
113139
"externalLibraries": []
114140
},
115141
"src/holidays/feature/index.ts": {
@@ -122,6 +148,7 @@ exports[`export data > should test a simple application > simple-application 1`]
122148
"imports": [
123149
"src/holidays/feature/holidays-container.component.ts"
124150
],
151+
"unresolvedImports": [],
125152
"externalLibraries": []
126153
},
127154
"src/holidays/feature/holidays-container.component.ts": {
@@ -136,6 +163,7 @@ exports[`export data > should test a simple application > simple-application 1`]
136163
"src/holidays/ui/index.ts",
137164
"src/holidays/model/index.ts"
138165
],
166+
"unresolvedImports": [],
139167
"externalLibraries": [
140168
"@angular/common",
141169
"@angular/core",
@@ -152,6 +180,7 @@ exports[`export data > should test a simple application > simple-application 1`]
152180
"imports": [
153181
"src/holidays/data/holidays-store.ts"
154182
],
183+
"unresolvedImports": [],
155184
"externalLibraries": []
156185
},
157186
"src/holidays/data/holidays-store.ts": {
@@ -164,6 +193,7 @@ exports[`export data > should test a simple application > simple-application 1`]
164193
"imports": [
165194
"src/holidays/model/index.ts"
166195
],
196+
"unresolvedImports": [],
167197
"externalLibraries": [
168198
"@ngrx/signals"
169199
]
@@ -178,6 +208,7 @@ exports[`export data > should test a simple application > simple-application 1`]
178208
"imports": [
179209
"src/holidays/model/holiday.ts"
180210
],
211+
"unresolvedImports": [],
181212
"externalLibraries": []
182213
},
183214
"src/holidays/model/holiday.ts": {
@@ -188,6 +219,7 @@ exports[`export data > should test a simple application > simple-application 1`]
188219
"type:model"
189220
],
190221
"imports": [],
222+
"unresolvedImports": [],
191223
"externalLibraries": []
192224
},
193225
"src/holidays/ui/index.ts": {
@@ -200,6 +232,7 @@ exports[`export data > should test a simple application > simple-application 1`]
200232
"imports": [
201233
"src/holidays/ui/holidays.component.ts"
202234
],
235+
"unresolvedImports": [],
203236
"externalLibraries": []
204237
},
205238
"src/holidays/ui/holidays.component.ts": {
@@ -212,6 +245,7 @@ exports[`export data > should test a simple application > simple-application 1`]
212245
"imports": [
213246
"src/holidays/model/index.ts"
214247
],
248+
"unresolvedImports": [],
215249
"externalLibraries": []
216250
}
217251
}"

packages/core/src/lib/cli/tests/export-data.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,19 @@ describe('export data', () => {
116116

117117
expect(allLogs()).toMatchSnapshot('sheriff-config');
118118
});
119+
120+
it('should show unresolved imports', () => {
121+
const { allLogs } = mockCli();
122+
123+
createProject({
124+
'tsconfig.json': tsConfig(),
125+
src: {
126+
'main.ts': ['my-module'],
127+
},
128+
});
129+
130+
exportData('src/main.ts');
131+
132+
expect(allLogs()).toMatchSnapshot('unresolved-imports');
133+
});
119134
});

packages/core/src/lib/file-info/traverse-filesystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function traverseFilesystem(
8484
// might be an undetected dependency in node_modules
8585
// or an incomplete import (= developer is still typing),
8686
// if we read from an unsaved file via ESLint.
87-
else if (fileName.startsWith('.')) {
87+
else {
8888
fileInfo.addUnresolvableImport(fileName);
8989
}
9090

packages/core/src/lib/file-info/unassigned-file-info.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export class UnassignedFileInfo {
2727
this.#unresolvableImports.push(importCommand);
2828
}
2929

30+
get unresolvableImports() {
31+
return [...this.#unresolvableImports];
32+
}
33+
3034
isUnresolvableImport(importCommand: string) {
3135
return this.#unresolvableImports.includes(importCommand);
3236
}

packages/core/src/lib/modules/file.info.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class FileInfo {
3939
return this.unassignedFileInfo.getRawImportForImportedFileInfo(path);
4040
}
4141

42+
get unresolvableImports() {
43+
return this.unassignedFileInfo.unresolvableImports;
44+
}
45+
4246
isUnresolvableImport(importCommand: string) {
4347
return this.unassignedFileInfo.isUnresolvableImport(importCommand);
4448
}

0 commit comments

Comments
 (0)