Skip to content

Commit 304ec64

Browse files
committed
refactor(@angular-devkit/build-angular): ensure TS resolution cache with file replacements
When overriding module resolution on a TypeScript Host object, TypeScript will not automatically create a resolution cache for the Host. Within the application build system the TypeScript resolution is only overrided if file replacements are used. A resolution cache is now manually created and added to the TypeScript Host when file replacements are present.
1 parent e6b3774 commit 304ec64

File tree

1 file changed

+9
-1
lines changed
  • packages/angular_devkit/build_angular/src/tools/esbuild/angular

1 file changed

+9
-1
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/angular/angular-host.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ export function createAngularCompilerHost(
7777

7878
// Augment TypeScript Host for file replacements option
7979
if (hostOptions.fileReplacements) {
80-
augmentHostWithReplacements(host, hostOptions.fileReplacements);
80+
// Provide a resolution cache since overriding resolution prevents automatic creation
81+
const resolutionCache = ts.createModuleResolutionCache(
82+
host.getCurrentDirectory(),
83+
host.getCanonicalFileName.bind(host),
84+
compilerOptions,
85+
);
86+
host.getModuleResolutionCache = () => resolutionCache;
87+
88+
augmentHostWithReplacements(host, hostOptions.fileReplacements, resolutionCache);
8189
}
8290

8391
// Augment TypeScript Host with source file caching if provided

0 commit comments

Comments
 (0)