Skip to content

feat(ivy): implement listing lazy routes for specific entry point in ngtsc - #28542

Closed
gkalpak wants to merge 10 commits into
angular:masterfrom
gkalpak:feat-ivy-list-partial-lazy-routes
Closed

gkalpak wants to merge 10 commits into
angular:masterfrom
gkalpak:feat-ivy-list-partial-lazy-routes

Conversation

@gkalpak

@gkalpak gkalpak commented Feb 5, 2019

Copy link
Copy Markdown
Member

PR Checklist

PR Type

  • Feature

What is the current behavior?

ngtsc's listLazyRoutes() does not support listing routes for a specific entry point. @angular/cli calls this API to get a list of lazy-loaded entry points (routes) so that the bundler can create separate bundles for each. Under certain circumstances (e.g. jit mode), the cli may need to list routes for a specific root entry point only.

Jira issue: FW-860

What is the new behavior?

ngtsc's listLazyRoutes() supports listing routes for a specific entry point.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Related: angular/angular-cli#13532

@gkalpak
gkalpak requested a review from IgorMinar as a code owner February 5, 2019 15:02
@gkalpak
gkalpak requested a review from a team February 5, 2019 15:02
@gkalpak gkalpak added feature Label used to distinguish feature request from other issues action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release comp: ivy labels Feb 5, 2019
@ngbot ngbot Bot added this to the needsTriage milestone Feb 5, 2019
}

fixmeIvy('FW-629: ngtsc lists lazy routes').it('should list lazy routes recursively', () => {
fit('should list lazy routes recursively', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oopsie

@gkalpak gkalpak Feb 5, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I know, I know 😃 (This is not really ready for review - sorry for the misleading label 😞)

@gkalpak gkalpak added state: WIP and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 5, 2019
@gkalpak
gkalpak force-pushed the feat-ivy-list-partial-lazy-routes branch 2 times, most recently from 78194fb to 0d0b1e4 Compare February 7, 2019 16:24
@gkalpak
gkalpak force-pushed the feat-ivy-list-partial-lazy-routes branch 2 times, most recently from 64f8b97 to 80eb608 Compare February 7, 2019 17:05
@gkalpak gkalpak added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Feb 7, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ngtsc complained about non-existent component.

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.

As well it should!

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome PR. Some really nice computation.
A few Qs and suggestions but looks good.

Do we need to worry about / test routes that point to files that are in a different source root folder?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These toString() methods are really helpful when debugging and in errors. I accept that there is no real need for the abstract version since all Objects have this method defined already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Happy to bring that back then 😃

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't believe you need the as 'ngtsc' here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without it, the type of the object ends up as {enabledIvy: false | string}, which TS complains is not assignable to 'ngtsc' | boolean | ....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really? That is not what I see. {enableIvy: ivyEnabled && 'ngtsc'} appears to be enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, you are right. Originally, I had it as a separate variable:

const overrideOptions = {enableIvy: ivyEnabled && 'ngtsc' as 'ngtsc'};
const options = testSupport.createCompilerOptions(overrideOptions);

In that case, TS complains without the as 'ngtsc', but when using the object literal directly, it is not necessary 🎉
Good catch!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this fixmeIvy be removed if this commit is fixing something to work with ivy?

@gkalpak gkalpak Feb 8, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed it in a subsequent commit, because this commit (although enough to make routes work in cli projects) was not enough to fix the test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this error message should have a bit more context. Perhaps:

Resolution of relative paths to lazy routes is not supported.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My initial intention was to keep this close to the old AotCompilerHost implementation, but I don't see any reason to 😁
I'll add more info to the error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't find defining such functions via fat arrows very readable. Although I accept that the terrible automated formatting is partly to blame.

This is what it would look like as a normal function:

function lazyRouteMatching(
    route: string, fromModulePath: RegExp, fromModuleName: string, toModulePath: RegExp,
    toModuleName: string) {
  return {
    route: route, module: jasmine.objectContaining(
                      {name: fromModuleName, filePath: jasmine.stringMatching(fromModulePath)}),
        referencedModule: jasmine.objectContaining(
            {name: toModuleName, filePath: jasmine.stringMatching(toModulePath)}),
  }
  as unknown as LazyRoute;
}

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.

Feel free to turn off the clang-formatter and do a better job of making the body readable :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that this is testing "all" routes, should we not have more than one route in the test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. I was just refactoring what was there before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need to have components for the compilation to work? If not is this unnecessary noise in this test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is to ensure that having other things than NgModules in the exports does not throw the RouteAnalyzer off.
I can split it out into a separate test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice comment, thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should ignore and not throw? Is that the specified behaviour? I guess this would throw later if you tried to navigate to that route?

@gkalpak gkalpak Feb 8, 2019 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good question. Not sure what it should do (but added a test for what it actually does right now).

I chose the current behavior (not to throw if it doesn't know about a lazy route's module), because that is somewhat similar to what would happen if listLazyRoutes() was called without an entry point: It would list all routes found in the know modules, but it would not complain if a lazy route points to an unknown module.

I can be convinced otherwise, though 😃

@kara kara added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 7, 2019
@kara kara added the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 7, 2019
@kara kara assigned alxhub and gkalpak and unassigned gkalpak Feb 7, 2019

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.

As well it should!

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.

I'm actually planning on doing that soon anyway, for all of the tests in it. Stay tuned!

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.

Feel free to turn off the clang-formatter and do a better job of making the body readable :)

@kara kara removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 8, 2019
@gkalpak
gkalpak force-pushed the feat-ivy-list-partial-lazy-routes branch from 80eb608 to 242976c Compare February 11, 2019 13:18
@gkalpak

gkalpak commented Feb 11, 2019

Copy link
Copy Markdown
Member Author

Addressed the feedback in fixup and added a new commit with some tests with multiple rootDirs (to cover #28542 (review)).

Still need to decide #28542 (comment) is what we want.

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great! I don't know what the answer to #28542 (comment) is though.

@alxhub

alxhub commented Feb 11, 2019

Copy link
Copy Markdown
Member

Presubmit

@kara kara added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Feb 11, 2019
@kara kara unassigned alxhub and gkalpak Feb 11, 2019
@mhevery mhevery closed this in 5db3a6b Feb 12, 2019
mhevery pushed a commit that referenced this pull request Feb 12, 2019
…y routes (#28542)

This will make it easier to retrieve routes for specific entry points in
`listLazyRoutes()` (which is necessary for CLI integration but not yet
implemented).

PR Close #28542
mhevery pushed a commit that referenced this pull request Feb 12, 2019
mhevery pushed a commit that referenced this pull request Feb 12, 2019
mhevery pushed a commit that referenced this pull request Feb 12, 2019
…point in `ngtsc` (#28542)

I don't know of any use of this API with a project-root-relative path
(i.e. the cli will always call it with an absolute path), but keeping
the API backwards compatible just in case.

PR Close #28542
@gkalpak
gkalpak deleted the feat-ivy-list-partial-lazy-routes branch February 12, 2019 07:39
@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.

@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 cla: yes feature Label used to distinguish feature request from other issues target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants