Skip to content

ngcc: webpack support#29092

Closed
petebacondarwin wants to merge 20 commits into
angular:masterfrom
petebacondarwin:ngcc-webpack-support
Closed

ngcc: webpack support#29092
petebacondarwin wants to merge 20 commits into
angular:masterfrom
petebacondarwin:ngcc-webpack-support

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@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 Label used to distinguish feature request from other issues 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
Comment thread scripts/build-packages-dist.sh Outdated
Comment thread scripts/build-packages-dist.sh Outdated
@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 March 5, 2019 12:06
Comment thread packages/common/BUILD.bazel Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread packages/compiler-cli/ngcc/src/packages/entry_point_finder.ts Outdated
@petebacondarwin
Copy link
Copy Markdown
Contributor Author

Rebased and renamed the post-move commit to a fixup commit.
Over to you @gkalpak!

@matsko
Copy link
Copy Markdown
Contributor

matsko commented Mar 19, 2019

Copy link
Copy Markdown
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor comments - nothing blocking.
Also, there is still a typo in 494679c8d: poth --> path

Comment thread packages/compiler-cli/ngcc/src/main.ts Outdated
Comment thread packages/compiler-cli/ngcc/src/packages/entry_point.ts Outdated
Comment thread packages/compiler-cli/ngcc/src/main.ts Outdated
Comment thread packages/compiler-cli/ngcc/src/main.ts Outdated
Comment thread packages/compiler-cli/ngcc/main-ngcc.ts Outdated
@alan-agius4
Copy link
Copy Markdown
Contributor

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

Of course this will need further testing when having an application and more complex scenarios. But so far this looks promising.

Comment thread packages/compiler-cli/ngcc/src/main.ts Outdated
Comment thread packages/compiler-cli/ngcc/index.ts Outdated
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
@petebacondarwin
Copy link
Copy Markdown
Contributor Author

Caretaker note: ngcc is excluded from G3. But presubmit was run by @alxhub before the last rebase anyway.

@angular-automatic-lock-bot
Copy link
Copy Markdown

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.

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 Label used to distinguish feature request from other issues 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.

9 participants