-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(typescript): support for ESM variant of the Angular compiler plu…
…gin (#2982) As of v13, the `@angular/compiler-cli` package will come as strict ESM package. This means that the import currently in `tsc_wrapped` does not work for v13+ of Angular. This commit adds an interop allowing for both the ESM variant, and CJS variant of the Angular compiler to work.
- Loading branch information
1 parent
5b6ac1e
commit 6f97a7c
Showing
4 changed files
with
74 additions
and
31 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
third_party/github.com/bazelbuild/rules_typescript/internal/tsc_wrapped/angular_plugin.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,23 @@ | ||
// The `@angular/compiler-cli` module is optional so we only | ||
// access as type-only at the file top-level. | ||
import type {NgTscPlugin} from '@angular/compiler-cli'; | ||
|
||
type CompilerCliModule = typeof import('@angular/compiler-cli'); | ||
|
||
/** | ||
* Gets the constructor for instantiating the Angular `ngtsc` | ||
* emit plugin supported by `tsc_wrapped`. | ||
*/ | ||
export async function getAngularEmitPlugin(): Promise<typeof NgTscPlugin|null> { | ||
try { | ||
// Note: This is an interop allowing for the `@angular/compiler-cli` package | ||
// to be shipped as strict ESM, or as CommonJS. If the CLI is a CommonJS | ||
// package (pre v13 of Angular), then the exports are in the `default` property. | ||
// See: https://nodejs.org/api/esm.html#esm_import_statements. | ||
const exports = await import('@angular/compiler-cli') as | ||
Partial<CompilerCliModule> & {default?: CompilerCliModule} | ||
return exports.NgTscPlugin ?? exports.default?.NgTscPlugin ?? null; | ||
} catch { | ||
return null; | ||
} | ||
} |
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