Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/core/src/lib/api/get-project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import getFs from '../fs/getFs';

export type ProjectDataEntry = {
module: string;
moduleType: 'barrel' | 'barrel-less',
moduleType: 'barrel' | 'barrel-less';
tags: string[];
imports: string[];
externalLibraries?: string[];
unresolvedImports: string[];
};

/**
Expand Down Expand Up @@ -143,12 +144,9 @@ export function getProjectData(
const entry: ProjectDataEntry = {
module: fileInfo.moduleInfo.path || '.',
moduleType: fileInfo.moduleInfo.hasBarrel ? 'barrel' : 'barrel-less',
tags: calcOrGetTags(
fileInfo.moduleInfo.path,
projectInfo,
tagsCache,
),
tags: calcOrGetTags(fileInfo.moduleInfo.path, projectInfo, tagsCache),
imports: fileInfo.imports.map((fileInfo) => fileInfo.path),
unresolvedImports: fileInfo.unresolvableImports,
};

if (options.includeExternalLibraries) {
Expand Down Expand Up @@ -184,6 +182,7 @@ function relativizeIfRequired(
imports: moduleData.imports.map((importPath) =>
relative(toFsPath(importPath)),
),
unresolvedImports: moduleData.unresolvedImports,
};

if (options.includeExternalLibraries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('barrel-less', () => {
'customers.component.ts': ['../data/open.service.ts'],
},
data: {
'index.ts': ['open.service.ts'],
'index.ts': ['./open.service.ts'],
'open.service.ts': [],
internal: { 'hidden.service.ts': [] },
},
Expand All @@ -192,7 +192,7 @@ describe('barrel-less', () => {
assertProject()
.withCustomerRoute({
feature: {
'customer.component.ts': [''],
'customer.component.ts': [],
'customers.component.ts': ['../data/sub1/internal/hidden.service.ts'],
},
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
"src/holidays/index.ts",
"src/customers/index.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/index.ts": {
Expand All @@ -21,6 +22,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
"scope:holidays"
],
"imports": [],
"unresolvedImports": [],
"externalLibraries": []
},
"src/customers/index.ts": {
Expand All @@ -30,6 +32,7 @@ exports[`export data > should also work with a sheriff.config.ts > sheriff-confi
"scope:customers"
],
"imports": [],
"unresolvedImports": [],
"externalLibraries": []
}
}"
Expand All @@ -47,6 +50,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
"src/app1.service.ts",
"src/app2.service.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/app1.service.ts": {
Expand All @@ -58,6 +62,7 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
"imports": [
"src/app2.service.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/app2.service.ts": {
Expand All @@ -69,6 +74,24 @@ exports[`export data > should avoid circular dependencies > circular-dependencie
"imports": [
"src/app1.service.ts"
],
"unresolvedImports": [],
"externalLibraries": []
}
}"
`;

exports[`export data > should show unresolved imports > unresolved-imports 1`] = `
"{
"src/main.ts": {
"module": ".",
"moduleType": "barrel-less",
"tags": [
"root"
],
"imports": [],
"unresolvedImports": [
"my-module"
],
"externalLibraries": []
}
}"
Expand All @@ -85,6 +108,7 @@ exports[`export data > should skip not reachable files > not-reachable-files 1`]
"imports": [
"src/app1.service.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/app1.service.ts": {
Expand All @@ -94,6 +118,7 @@ exports[`export data > should skip not reachable files > not-reachable-files 1`]
"root"
],
"imports": [],
"unresolvedImports": [],
"externalLibraries": []
}
}"
Expand All @@ -110,6 +135,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/feature/index.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/feature/index.ts": {
Expand All @@ -122,6 +148,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/feature/holidays-container.component.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/feature/holidays-container.component.ts": {
Expand All @@ -136,6 +163,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"src/holidays/ui/index.ts",
"src/holidays/model/index.ts"
],
"unresolvedImports": [],
"externalLibraries": [
"@angular/common",
"@angular/core",
Expand All @@ -152,6 +180,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/data/holidays-store.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/data/holidays-store.ts": {
Expand All @@ -164,6 +193,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/model/index.ts"
],
"unresolvedImports": [],
"externalLibraries": [
"@ngrx/signals"
]
Expand All @@ -178,6 +208,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/model/holiday.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/model/holiday.ts": {
Expand All @@ -188,6 +219,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"type:model"
],
"imports": [],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/ui/index.ts": {
Expand All @@ -200,6 +232,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/ui/holidays.component.ts"
],
"unresolvedImports": [],
"externalLibraries": []
},
"src/holidays/ui/holidays.component.ts": {
Expand All @@ -212,6 +245,7 @@ exports[`export data > should test a simple application > simple-application 1`]
"imports": [
"src/holidays/model/index.ts"
],
"unresolvedImports": [],
"externalLibraries": []
}
}"
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/lib/cli/tests/export-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,19 @@ describe('export data', () => {

expect(allLogs()).toMatchSnapshot('sheriff-config');
});

it('should show unresolved imports', () => {
const { allLogs } = mockCli();

createProject({
'tsconfig.json': tsConfig(),
src: {
'main.ts': ['my-module'],
},
});

exportData('src/main.ts');

expect(allLogs()).toMatchSnapshot('unresolved-imports');
});
});
2 changes: 1 addition & 1 deletion packages/core/src/lib/file-info/traverse-filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function traverseFilesystem(
// might be an undetected dependency in node_modules
// or an incomplete import (= developer is still typing),
// if we read from an unsaved file via ESLint.
else if (fileName.startsWith('.')) {
else {
fileInfo.addUnresolvableImport(fileName);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/lib/file-info/unassigned-file-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class UnassignedFileInfo {
this.#unresolvableImports.push(importCommand);
}

get unresolvableImports() {
return [...this.#unresolvableImports];
}

isUnresolvableImport(importCommand: string) {
return this.#unresolvableImports.includes(importCommand);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/lib/modules/file.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export class FileInfo {
return this.unassignedFileInfo.getRawImportForImportedFileInfo(path);
}

get unresolvableImports() {
return this.unassignedFileInfo.unresolvableImports;
}

isUnresolvableImport(importCommand: string) {
return this.unassignedFileInfo.isUnresolvableImport(importCommand);
}
Expand Down
1 change: 1 addition & 0 deletions test-projects/angular-i/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@ngrx/store-devtools": "^15.4.0",
"@ngx-formly/core": "^6.1.3",
"@ngx-formly/material": "^6.1.3",
"@testing-library/angular": "12",
"date-fns": "^2.29.3",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
Expand Down
Loading