Skip to content

Commit

Permalink
refactor: Improve type loading
Browse files Browse the repository at this point in the history
- Don't include irrelevant types in the type loading process
- Ensure that modules from sap.ui.core are not looked up within the
linted project. This happened as there was no mapping for the
sap/ui/core namespace and TypeScript first tried to load the module
relative to the requesting module and only afterwards used the dts file
from "types".
  • Loading branch information
matz3 committed Feb 11, 2025
1 parent faa9b1d commit 55fad6f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/linter/ui5Types/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ function addSapui5TypesMappingToCompilerOptions(
// - When linting a framework library, the corresponding types should be loaded by default as they
// might not get loaded by the compiler otherwise, as the actual sources are available in the project.
options.types?.push(dtsPath);
} else {
// For other framework libraries we can add a paths mapping to load them on demand
const mappingNamespace = libraryNamespace + "/*";
const pathsEntry = paths[mappingNamespace] ?? (paths[mappingNamespace] = []);
pathsEntry.push(dtsPath);
}
// In every case, add a paths mapping to load them on demand and ensure loading them
// when the framework library itself is linted
const mappingNamespace = libraryNamespace + "/*";
const pathsEntry = paths[mappingNamespace] ?? (paths[mappingNamespace] = []);
pathsEntry.push(dtsPath);
});
}

Expand All @@ -84,6 +84,11 @@ export async function createVirtualLanguageServiceHost(

const typePackages = new Set(["@sapui5/types"]);
await collectTransitiveDependencies("@sapui5/types", typePackages);

// Remove dependencies that are not needed for UI5 linter type checking:
typePackages.delete("@types/three"); // Used in sap.ui.vk, but is not needed for linter checks.
typePackages.delete("@types/offscreencanvas"); // Used by @types/three

typePackages.forEach((pkgName) => {
addPathMappingForPackage(pkgName, typePathMappings);
});
Expand Down

0 comments on commit 55fad6f

Please sign in to comment.