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

fix(ngcc): capture path-mapped entry-points that start with same string #35592

Conversation

petebacondarwin
Copy link
Member

Previously if there were two path-mapped libraries that are in
different directories but the path of one started with same string
as the path of the other, we would incorrectly return the shorter
path - e.g. dist/my-lib and dist/my-lib-second. This was because
the list of basePaths was searched in ascending alphabetic order and
we were using startsWith() to match the path.

Now the basePaths are searched in reverse alphabetic order so the
longer path will be matched correctly.

// FW-1873

Fixes #35536

@petebacondarwin petebacondarwin added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release comp: ngcc labels Feb 20, 2020
@ngbot ngbot bot modified the milestone: needsTriage Feb 20, 2020
@pullapprove pullapprove bot requested a review from JoostK February 20, 2020 20:05
return true;
// Use `relative()` rather than `startsWith()` to avoid false positives for paths like
// `abc/defg` and `abc/def` since the former is not contained by the latter.
return index === array.length - 1 || relative(value, array[index + 1]).startsWith('../');
Copy link
Member

@gkalpak gkalpak Feb 21, 2020

Choose a reason for hiding this comment

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

  1. AFAICT, relative('/foo/bar', '/foo') will return .. (without a trailing /) and thus the .startsWith('../') check will fail.
    (Although, I may have missed something, because I would expect a test to be failing due to this 😕)

  2. By not checking against all following paths, we will incorrectly retain a/b/d in ['a/b/d', 'a/b/c', 'a/b'].

Copy link
Member Author

Choose a reason for hiding this comment

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

😱

That'll teach me for holiday coding

😇

I'll fix that ASAP

Previously if there were two path-mapped libraries that are in
different directories but the path of one started with same string
as the path of the other, we would incorrectly return the shorter
path - e.g. `dist/my-lib` and `dist/my-lib-second`. This was because
the list of `basePaths` was searched in ascending alphabetic order and
we were using `startsWith()` to match the path.

Now the `basePaths` are searched in reverse alphabetic order so the
longer path will be matched correctly.

// FW-1873

Fixes angular#35536
@petebacondarwin
Copy link
Member Author

@gkalpak - fixed the code and tightened up the test. PTAL

Copy link
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.

👌

* For example:
* Given `['a/b/c', 'a/b/x', 'a/b', 'd/e', 'd/f']` we will end up with `['a/b', 'd/e', 'd/f]`.
* (Note that we do not get `d` even though `d/e` and `d/f` share a base directory, since `d` is not
* one of the base paths.)
Copy link
Member

Choose a reason for hiding this comment

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

💯

@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 24, 2020
mhevery pushed a commit that referenced this pull request Feb 24, 2020
…ng (#35592)

Previously if there were two path-mapped libraries that are in
different directories but the path of one started with same string
as the path of the other, we would incorrectly return the shorter
path - e.g. `dist/my-lib` and `dist/my-lib-second`. This was because
the list of `basePaths` was searched in ascending alphabetic order and
we were using `startsWith()` to match the path.

Now the `basePaths` are searched in reverse alphabetic order so the
longer path will be matched correctly.

// FW-1873

Fixes #35536

PR Close #35592
@mhevery mhevery closed this in 71b5970 Feb 24, 2020
@petebacondarwin petebacondarwin deleted the ngcc-fw-1873-path-mapped-libs branch February 24, 2020 17:22
@fkolar
Copy link

fkolar commented Mar 21, 2020

@petebacondarwin Is this already in 9.0.6. ?

@fkolar
Copy link

fkolar commented Mar 21, 2020

I can confirm this does not fix ##35536, as I need to run ngcc && ngcc -s dist on my local libs so I can use them in apps.

@petebacondarwin
Copy link
Member Author

It was included in 9.0.3 - https://github.com/angular/angular/blob/master/CHANGELOG.md#903-2020-02-27

@fkolar Please provide a reproduction of your problem in a new issue for us to investigate.

@fkolar
Copy link

fkolar commented Mar 21, 2020

Let me comit my changes.. I will create new issues. thanks allot.

fkolar added a commit to ngx-metaui/rules that referenced this pull request Mar 21, 2020
even I need to run
rm -Rf dist && ng build rules && ng build material-rules && npx ngcc && ngcc -s dist

otherwise there is compilation error for the application:
angular/angular#35592
fkolar added a commit to ngx-metaui/rules that referenced this pull request Apr 5, 2020
even I need to run
rm -Rf dist && ng build rules && ng build material-rules && npx ngcc && ngcc -s dist

otherwise there is compilation error for the application:
angular/angular#35592
@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 Apr 21, 2020
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 target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error NG6002, caused by enableIvy with libraries of a specific naming scheme
5 participants