feat(ivy): produce and consume ES2015 re-exports for NgModule re-exports (#28852)
In certain configurations (such as the g3 repository) which have lots of small compilation units as well as strict dependency checking on generated code, ngtsc's default strategy of directly importing directives/pipes into components will not work. To handle these cases, an additional mode is introduced, and is enabled when using the FileToModuleHost provided by such compilation environments. In this mode, when ngtsc encounters an NgModule which re-exports another from a different file, it will re-export all the directives it contains at the ES2015 level. The exports will have a predictable name based on the FileToModuleHost. For example, if the host says that a directive Foo is from the 'root/external/foo' module, ngtsc will add: ``` export {Foo as ɵng$root$external$foo$$Foo} from 'root/external/foo'; ``` Consumers of the re-exported directive will then import it via this path instead of directly from root/external/foo, preserving strict dependency semantics. PR Close #28852
This commit is contained in:

committed by
Ben Lesh

parent
15c065f9a0
commit
c1392ce618
@ -21,9 +21,20 @@ const NODE_MODULES_PACKAGE_NAME = /node_modules\/((\w|-|\.)+|(@(\w|-|\.)+\/(\w|-
|
||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||
const CSS_PREPROCESSOR_EXT = /(\.scss|\.less|\.styl)$/;
|
||||
|
||||
let augmentHostForTest: {[name: string]: Function}|null = null;
|
||||
|
||||
export function setAugmentHostForTest(augmentation: {[name: string]: Function} | null): void {
|
||||
augmentHostForTest = augmentation;
|
||||
}
|
||||
|
||||
export function createCompilerHost(
|
||||
{options, tsHost = ts.createCompilerHost(options, true)}:
|
||||
{options: CompilerOptions, tsHost?: ts.CompilerHost}): CompilerHost {
|
||||
if (augmentHostForTest !== null) {
|
||||
for (const name of Object.keys(augmentHostForTest)) {
|
||||
(tsHost as any)[name] = augmentHostForTest[name];
|
||||
}
|
||||
}
|
||||
return tsHost;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user