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(core): prefer project specific external deps #23307

Merged
merged 25 commits into from
May 30, 2024

Conversation

JamesHenry
Copy link
Collaborator

@JamesHenry JamesHenry commented May 10, 2024

Current Behavior

We only ever discover one version of an external dependency for the file-map.json. This means the @nx/dependency-checks lint rule can produce incorrect failures when multiple copies of a dependency exist within a workspace.

Expected Behavior

In the file-map.json the project specific version of a package (if multiple exist) is preferred and therefore the lint rule produces accurate results.


For example, in a repo where the root package.json has lodash@4.0.0 (which becomes npm:lodash on graph) and the foo project has lodash@3.0.0:

Before

image

After

image

Performance

NX_ISOLATE_PLUGINS=true NX_PERF_LOGGING=true NX_DAEMON=false nx show project nx --json false

** Before **

Time for 'build typescript dependencies' 505.52144700009376

** After **

Time for 'build typescript dependencies' 701.247584999539

Copy link

vercel bot commented May 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview May 30, 2024 1:35pm

@JamesHenry JamesHenry changed the title Project external nodes fix(core): prefer project specific external deps May 10, 2024
@JamesHenry JamesHenry force-pushed the project-external-nodes branch 3 times, most recently from 4e86fce to fb21b87 Compare May 10, 2024 17:31
@JamesHenry JamesHenry marked this pull request as ready for review May 10, 2024 18:17
@JamesHenry JamesHenry requested a review from a team as a code owner May 10, 2024 18:18
@JamesHenry JamesHenry requested review from Cammisuli and FrozenPandaz and removed request for Cammisuli May 10, 2024 18:18
@JamesHenry JamesHenry self-assigned this May 10, 2024
@JamesHenry JamesHenry enabled auto-merge (squash) May 11, 2024 09:38
@JamesHenry JamesHenry requested a review from a team as a code owner May 16, 2024 13:02
@JamesHenry JamesHenry requested a review from meeroslav May 16, 2024 13:02
@JamesHenry JamesHenry marked this pull request as draft May 16, 2024 13:03
auto-merge was automatically disabled May 16, 2024 13:03

Pull request was converted to draft

@JamesHenry JamesHenry marked this pull request as ready for review May 17, 2024 14:17
@JamesHenry JamesHenry requested a review from a team as a code owner May 17, 2024 14:17
@JamesHenry JamesHenry requested a review from jaysoo May 17, 2024 14:17
@JamesHenry
Copy link
Collaborator Author

@FrozenPandaz Please take another look

* NOTE: Unit testing this code is currently impractical as it is not possible to mock
* require.resolve in jest https://github.com/jestjs/jest/issues/9543
*/
export function findExternalPackageJsonPath(

This comment was marked as resolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It exists in its own file so that it can be mocked in tests, per the note there we cannot mock the inner require.resolve calls so we need something we can mock that wraps it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Wait... rereading that:

I think this can move into the TargetProjectLocator

I understood this sentence to mean into the class implementation, but do you actually mean just into the target-project-locator.ts file? That is doable if so

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, the file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is not mockable when taking that approach because the function is referenced within the TargetProjectLocator directly so there is no longer an import boundary to mock. It needs to stay in a separate file.

Copy link
Collaborator

@FrozenPandaz FrozenPandaz left a comment

Choose a reason for hiding this comment

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

We will want to profile how this does on the nx repo to ensure there isn't a large performance regression for finding dependencies.

'./libs/proj1234-child/index.ts': 'export const a = 12345',
};
vol.fromJSON(fsJson, '/root');
ctx = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was unused

expect(result2).toEqual('npm:npm-package');
});

it('should be able to resolve paths that have similar names', () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was the test we agreed to remove

@FrozenPandaz FrozenPandaz merged commit 7001e35 into master May 30, 2024
6 checks passed
@FrozenPandaz FrozenPandaz deleted the project-external-nodes branch May 30, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants