Repository navigation
Support for proper umd module naming for building external repos from source (such as angular/angular) - #223
gregmagolan wants to merge 1 commit into
Conversation
| } | ||
| } | ||
|
|
||
| // TODO(gmagolan): clean this up |
There was a problem hiding this comment.
This is basically doing a reverse lookup from the tsconfig paths to figure out what the module name should be. When building angular directly from source not all imports are scoped to the module name. The .ngsummary and .ngfactory files from the angular packages are not.
… source (such as angular/angular)
| @@ -310,6 +310,7 @@ export class CompilerHost implements ts.CompilerHost, tsickle.TsickleHost { | |||
| // named by code in that repository. | |||
There was a problem hiding this comment.
this function is getting quite complex, could you add unit tests for it pls?
| } | ||
|
|
||
| // The following handles the case when the filename is outside of | ||
| // bazelOpts.package but still needs to be mapped to the correct |
There was a problem hiding this comment.
it seems like the logic above that uses bazelOpts.package was too specific. Can this general logic replace some of that?
| // For example, when building Angular from source in downstream projects | ||
| // the fileName may be 'packages/common/src/pipes/date_pipe.ngfactory' | ||
| // while the bazelOpts.moduleName is '@angular/platform-browser' and the | ||
| // bazelOpts.package is 'packages/platform-browser'. We still want to map |
There was a problem hiding this comment.
Here's the fundamental problem:
if the file comes from another package, it should have been compiled already in that package
that means we should be seeing .d.ts files for the angular code that we are trying to name
.d.ts files should always have a ///<amd module-name="the correct name"/> pragma at the top
so I don't see why we should ever be in the business of creating a module name for code that came from another package.
Does that make sense? what part of that is going wrong?
There was a problem hiding this comment.
Looking into it. It only happens for ngfactory files from angular. Here's the callstack when CompilerHost.amdModuleName in rules_typescript is called for the ngfactory file external/angular/packages/common/src/location/platform_location.ngfactory when compiling platform-browser (bazelOpts.packageName is packages/platform-browser):
Mapped external/angular/packages/common/src/location/platform_location.ngfactory => @angular/common/src/location/platform_location.ngfactory (package packages/platform-browser) Error
at /private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/build_bazel_rules_typescript/internal/tsc_wrapped/compiler_host.js:366:144
at Array.forEach (<anonymous>)
at _loop_1 (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/build_bazel_rules_typescript/internal/tsc_wrapped/compiler_host.js:361:47)
at CompilerHost.amdModuleName (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/build_bazel_rules_typescript/internal/tsc_wrapped/compiler_host.js:376:25)
at CompilerHost.ngHost.fileNameToModuleName (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/bazel/src/ngc-wrapped/index.js:255:31)
at AotCompiler._fileNameToModuleName (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:546:28)
at Object.importExpr (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:524:42)
at /private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:439:90
at Array.forEach (<anonymous>)
at AotCompiler._createSummary (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:438:22)
at AotCompiler._compileImplFile (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:382:77)
at /private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:374:74
at Array.map (<anonymous>)
at AotCompiler.emitAllImpls (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler/src/aot/compiler.js:374:39)
at AngularCompilerProgram.generateFilesForEmit (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler-cli/src/transformers/program.js:736:46)
at AngularCompilerProgram._emitRender2 (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler-cli/src/transformers/program.js:330:27)
at AngularCompilerProgram.emit (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler-cli/src/transformers/program.js:236:22)
at Object.performCompilation (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/compiler-cli/src/perform_compile.js:194:29)
at compile (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/bazel/src/ngc-wrapped/index.js:294:21)
at runOneBuild (/private/var/tmp/_bazel_greg/2c2a834fcea131eff2d962ffe20e1c87/execroot/angular_bazel_example/bazel-out/host/bin/external/angular/packages/bazel/src/ngc-wrapped/index.js:94:27)
|
Replaced by principled fix: angular/angular#25335 |
|
angular/angular#25335 has unexpected side-effect breaking the angular-cli. Looking at this PR again. I dug through the AOT compiler to see exactly where these filenames that are not able to be mapped to module names are coming from. This happens during the generation step for For example, when generating in
So the AOT compiler asks the typescript compiler host to convert the filename to a module name. This ends up the bazel ngc-wrapped code here: which through which only knows how to convert a filename from the current compilation unit ( This PR appends the logic of amdModuleName function to be able to handle converting filenames to module names for other modules besides the current compilation unit. From the analysis above, the rational for why this is needed is because of the way imports for .ngfactory files are generated with full file paths that need to be converted to their module names for other modules besides the current one being compiled. |
No description provided.