Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngcc): avoid error due to circular dependency in `EsmDependencyHo…
…st` (#34512) Previously, there was circular dependency between `ngcc/src/utils.ts`, `ngcc/src/dependencies/dependency_host.ts` and `ngcc/src/dependencies/esm_dependency_host.ts`. More specifically, `utils.ts` would [import from `esm_dependency_host.ts`][1], which would [import from `dependency_host.ts`][2], which would in turn [import from `utils.ts`][3]. This might be fine in some environments/module formats, but it can cause unclear errors in the transpiled CommonJS/UMD format (given how Node.js handles [cycles in module resolution][4]). (An example error can be found [here][5].) This commit fixes the problem by moving the code that depends on `EsmDependencyHost` out of `utils.ts` and into a dedicated file under `dependencies/`. It also converts the `createDtsDependencyHost()` function to a class for consistency with the rest of the `DependencyHost`s. [1]: https://github.com/angular/angular/blob/18d89c9c8/packages/compiler-cli/ngcc/src/utils.ts#L10 [2]: https://github.com/angular/angular/blob/18d89c9c8/packages/compiler-cli/ngcc/src/dependencies/esm_dependency_host.ts#L10 [3]: https://github.com/angular/angular/blob/18d89c9c8/packages/compiler-cli/ngcc/src/dependencies/dependency_host.ts#L9 [4]: https://nodejs.org/api/modules.html#modules_cycles [5]: https://circleci.com/gh/angular/angular/577581 PR Close #34512
- Loading branch information
Showing
7 changed files
with
39 additions
and
23 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/compiler-cli/ngcc/src/dependencies/dts_dependency_host.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {FileSystem} from '../../../src/ngtsc/file_system'; | ||
import {PathMappings} from '../utils'; | ||
import {EsmDependencyHost} from './esm_dependency_host'; | ||
import {ModuleResolver} from './module_resolver'; | ||
|
||
/** | ||
* Helper functions for computing dependencies via typings files. | ||
*/ | ||
export class DtsDependencyHost extends EsmDependencyHost { | ||
constructor(fs: FileSystem, pathMappings?: PathMappings) { | ||
super(fs, new ModuleResolver(fs, pathMappings, ['', '.d.ts', '/index.d.ts'])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters