ngcc: webpack support#29092
Conversation
8f88817 to
aabc74c
Compare
ef93573 to
75e9641
Compare
There was a problem hiding this comment.
We need to merge this commit into the previous. Can you mark it as a fixup! commit instead of its own separate thing?
This way it'll rebase separately, but when we actually merge the PR the commits will be combined. Otherwise, we'll have a commit in the repo at which the build will be broken (after the move, but before BUILD file updates, etc).
|
Rebased and renamed the post-move commit to a fixup commit. |
gkalpak
left a comment
There was a problem hiding this comment.
A couple of minor comments - nothing blocking.
Also, there is still a typo in 494679c8d: poth --> path
|
Hi all, I just tested out using the transformed dts with a VE compilation on a basic library seems to be compiling as expected when using Of course this will need further testing when having an application and more complex scenarios. But so far this looks promising. |
Previously we only compiled the typings files, in ngcc, if there was an ES2015 formatted bundle avaiable. This turns out to be an artificial constraint and we can also support typings compilation via ES5 formats too. This commit changes the ngcc compiler to attempt typings compilation via ES5 if necessary. The order of the formats to consider is now: FESM2015, FESM5, ESM2015, ESM5. FW-1122
The `mainNgcc()` function has been refactored to make it easier to call ngcc from JavaScript, rather than via the command line. For example, the `yargs` argument parsing and the exception handling/logging have moved to the `main-ngcc.ts` file so that it is only used for the command line version. FW-1118
You can now, programmatically, specify an entry-point where the ngcc compilation will occur. Only this entry-point and its dependencies will be compiled. FW-1119
You can now specify a list of properties in the package.json that should be considered (in order) to find the path to the format to compile. The build marker system has been updated to store the markers in the package.json rather than an additional external file. Also instead of tracking the underlying bundle format that was compiled, it now tracks the package.json property. BREAKING CHANGE: The `proertiesToConsider` option replaces the previous `formats` option, which specified the final bundle format, rather than the property in the package.json. If you were using this option to compile only specific bundle formats, you must now modify your usage to pass in the properties in the package.json that map to the format that you wish to compile. In the CLI, the `--formats` is no longer available. Instead use the `--properties` option. FW-1120
Now that we are using package.json properties to indicate which entry-point format to compile, it turns out that we don't really need to distinguish between flat and non-flat formats, unless we are compiling `@angular/core`.
By ensuring that EntryPointBundle contains everything that `Transformer.transform()` needs to do its work, we can simplify its signature.
1�7 match By default ngcc will compile all the format properties specified. With this change you can configure ngcc so that it will stop compiling an entry-point after the first property that matches the `propertiesToConsider`.
We want ngcc to test non-AOT builds of the Angular packages, so we filter the tests in using the `no-ivy-aot` tag.
…roviders` functions
In ESM5 code, static methods appear as property assignments onto the constructor
function. For example:
```
var MyClass = (function() {
function MyClass () {}
MyClass.staticMethod = function() {};
return MyClass;
})();
```
This commit teaches ngcc how to process these forms when searching
for `ModuleWithProviders` functions that need to be updated in the typings
files.
Sometimes, in ESM5 code, aliases to exported variables are used internally to refer to the exported value. This prevented some analysis from being able to match up a reference to an export to the actual export itself. For example in the following code: ``` var HttpClientXsrfModule = /** @Class */ (function () { function HttpClientXsrfModule() { } HttpClientXsrfModule_1 = HttpClientXsrfModule; HttpClientXsrfModule.withOptions = function (options) { if (options === void 0) { options = {}; } return { ngModule: HttpClientXsrfModule_1, providers: [], }; }; var HttpClientXsrfModule_1; HttpClientXsrfModule = HttpClientXsrfModule_1 = tslib_1.__decorate([ NgModule({ providers: [], }) ], HttpClientXsrfModule); return HttpClientXsrfModule; }()); ``` We were not able to tell that the `ngModule: HttpClientXsrfModule_1` property assignment was actually meant to refer to the `function HttpClientXrsfModule()` declaration. This caused the `ModuleWithProviders` processing to fail. This commit ensures that we can compile typings files using the ESM5 format, so we can now update the examples boilerplate tool so that it does not need to compile the ESM2015 format at all.
…e provided Previously we always considered all the properties in the package.json if no `propertiesToConsidere` were provided. But this results in computing a new set of properties for each entry-point plus iterating through many of the package.json properties that are not related to bundle-format paths.
…essed` helper Now the public API does not contain internal types, such as `AbsoluteFsPath` and `EntryPointJsonProperty`. Instead we just accept strings and then guard them in `mainNgcc` as appropriate. A new public API function (`hasBeenProcessed`) has been exported to allow programmatic checking of the build marker when the package.json contents are already known.
1�7 with different ngcc Now we check the build-marker version for all the formats rather than just the one we are going to compile. This way we don't get into the situation where one format was built with one version of ngcc and another format was built with another version.
…cc was a noop If `targetEntryPointPath` is provided to `mainNgcc` then we will now mark all the `propertiesToConsider` for that entry-point if we determine that it does not contain code that was compiled by Angular (for instance it has no `...metadata.json` file). The commit also renames `__modified_by_ngcc__` to `__processed_by_ivy_ngcc__`, since there may be entry-points that are marked despite ngcc not actually compiling anything.
This is in preparation of having different file writing strategies.
This commit adds a `NewEntryPointFileWriter` that will be used in webpack integration. Instead of overwriting files in-place, this `FileWriter` will make a copy of the TS program files and write the transformed files there. It also updates the package.json with new properties that can be used to access the new entry-point format. FW-1121
|
Caretaker note: ngcc is excluded from G3. But presubmit was run by @alxhub before the last rebase anyway. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR is a collection of fixes, refactorings and features for ngcc that should allow a webpack plugin to be created that triggers ngcc compilation.
Covers: