Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngcc: webpack support #29092

Closed

Conversation

petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Mar 4, 2019

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:

  • FW-1118 ngcc - expose the programmatic API
  • FW-1119 ngcc should be able to compile an individual entry-point (and its dependencies)
  • FW-1120 ngcc should accept a fallback list of formats
  • FW-1122 ngcc should attempt to use a given format to compute the DTS changes

@petebacondarwin petebacondarwin added feature Issue that requests a new feature state: WIP effort2: days freq2: medium severity2: inconvenient area: core Issues related to the framework runtime target: major This PR is targeted for the next major release risk: low labels Mar 4, 2019
@ngbot ngbot bot added this to the Backlog milestone Mar 4, 2019
@petebacondarwin petebacondarwin force-pushed the ngcc-webpack-support branch 4 times, most recently from 8f88817 to aabc74c Compare March 4, 2019 15:50
@petebacondarwin petebacondarwin force-pushed the ngcc-webpack-support branch 6 times, most recently from ef93573 to 75e9641 Compare March 5, 2019 12:06
@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Mar 5, 2019
@petebacondarwin petebacondarwin marked this pull request as ready for review March 5, 2019 12:06
@petebacondarwin petebacondarwin requested review from a team as code owners March 5, 2019 12:06
matsko pushed a commit that referenced this pull request Mar 20, 2019
…cc was a noop (#29092)

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.

PR Close #29092
matsko pushed a commit that referenced this pull request Mar 20, 2019
This is in preparation of having different file writing strategies.

PR Close #29092
matsko pushed a commit that referenced this pull request Mar 20, 2019
…at (#29092)

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

PR Close #29092
@kara kara added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Mar 20, 2019
@petebacondarwin petebacondarwin deleted the ngcc-webpack-support branch March 28, 2019 09:54
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
)

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

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
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

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
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

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…es (angular#29092)

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

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…lar#29092)

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`.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…9092)

By ensuring that EntryPointBundle contains everything that `Transformer.transform()`
needs to do its work, we can simplify its signature.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
… match (angular#29092)

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`.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
We want ngcc to test non-AOT builds of the Angular packages,
so we filter the tests in using the `no-ivy-aot` tag.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…roviders` functions (angular#29092)

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.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…gular#29092)

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.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…e provided (angular#29092)

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.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…essed` helper (angular#29092)

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.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
… with different ngcc (angular#29092)

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.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…cc was a noop (angular#29092)

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.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…29092)

This is in preparation of having different file writing strategies.

PR Close angular#29092
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 17, 2019
…at (angular#29092)

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

PR Close angular#29092
gkalpak added a commit to gkalpak/angular that referenced this pull request Aug 5, 2019
In commit 7b55ba5 (part of PR angular#29092), the implementation of
`makeEntryPointBundle()` was changed such that it now always return
`EntryPointBundle` (and not `null`).
However, the return type was not updated and as result we continued to
unnecessarily handle `null` as a potential return value in some places.

This commit fixes the return type to reflect the implementation and
removes the redundant code that was dealing with `null`.
gkalpak added a commit to gkalpak/angular that referenced this pull request Aug 6, 2019
In commit 7b55ba5 (part of PR angular#29092), the implementation of
`makeEntryPointBundle()` was changed such that it now always return
`EntryPointBundle` (and not `null`).
However, the return type was not updated and as result we continued to
unnecessarily handle `null` as a potential return value in some places.

This commit fixes the return type to reflect the implementation and
removes the redundant code that was dealing with `null`.
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
…gular#32052)

In commit 7b55ba5 (part of PR angular#29092), the implementation of
`makeEntryPointBundle()` was changed such that it now always return
`EntryPointBundle` (and not `null`).
However, the return type was not updated and as result we continued to
unnecessarily handle `null` as a potential return value in some places.

This commit fixes the return type to reflect the implementation and
removes the redundant code that was dealing with `null`.

PR Close angular#32052
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes effort2: days feature Issue that requests a new feature freq2: medium merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note risk: low target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants