-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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): improve packages recognition when the package version is an external package #29529
fix(core): improve packages recognition when the package version is an external package #29529
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
View your CI Pipeline Execution ↗ for commit 69027a1.
☁️ Nx Cloud last updated this comment at |
@Cammisuli can this PR be reviewed, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe having the npm specific checks in the project graph builder is the best place for this. The reason for this is that the builder itself should be technology/package agnostic. The project graph will contain much more types of external nodes than just npm. For example, there could be cargo, gradle, pip, etc.
We should fix the area that is actually adding the external nodes which would be in the js plugin here:
nx/packages/nx/src/plugins/js/index.ts
Lines 63 to 80 in 21a1f4e
if (!lockFileNeedsReprocessing(lockFileHash)) { | |
const nodes = readCachedParsedLockFile().externalNodes; | |
parsedLockFile.externalNodes = nodes; | |
return { | |
externalNodes: nodes, | |
}; | |
} | |
const externalNodes = getLockFileNodes( | |
packageManager, | |
lockFileContents, | |
lockFileHash, | |
context | |
); | |
parsedLockFile.externalNodes = externalNodes; | |
return { | |
externalNodes, | |
}; |
@Cammisuli , @meeroslav , hi, please, point me in a write direction. From what I understand the issue happens because of this line, which overrides the map key, so that key My idea was to make a copy of external node (which has an "npm:" prefix in And my question wdyt about such solution. If I'm going in a wrong direction, please point me. Subject: [PATCH] fix(core): improve packages recognition when version is and external
---
Index: nx-fork/packages/nx/src/plugins/js/lock-file/yarn-parser.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/nx-fork/packages/nx/src/plugins/js/lock-file/yarn-parser.ts b/nx-fork/packages/nx/src/plugins/js/lock-file/yarn-parser.ts
--- a/nx-fork/packages/nx/src/plugins/js/lock-file/yarn-parser.ts (revision cb4a93e87217a99244160063b8993dc65d977716)
+++ b/nx-fork/packages/nx/src/plugins/js/lock-file/yarn-parser.ts (date 1739214631533)
@@ -176,7 +176,12 @@
for (const [packageName, versionMap] of nodes.entries()) {
const hoistedNode = findHoistedNode(packageName, versionMap, combinedDeps);
if (hoistedNode) {
- hoistedNode.name = `npm:${packageName}`;
+ if (hoistedNode.data.version.startsWith('npm:')) {
+ const name = <const>`npm:${packageName}`;
+ versionMap.set(name, { ...hoistedNode, name });
+ } else {
+ hoistedNode.name = `npm:${packageName}`;
+ }
}
versionMap.forEach((node) => { |
@newsiberian did you look at modifying the
You can probably do additional checks in there to handle the |
ae7459c
to
5777536
Compare
thanks. Yes, I did some tweaks to allow parent func to know whether the node has an alias or not. The important thing to note is that this code: if (hoistedNode) {
hoistedNode.name = `npm:${packageName}`;
} actually affects on that map: // we use key => node map to avoid duplicate work when parsing keys
let keyMap = new Map<string, ProjectGraphExternalNode>(); because they share the same nodes and first code, actually mutates the shared node. Which was quite unsuspected. |
@newsiberian awesome! It looks good on my side. Rebase the PR to get the latest things from master, and then we can get this in. Thank you very much! |
@Cammisuli perfect! I think, I'd like to check a bit later whether the case must also be covered for npm/pnpm |
…and stop passing `keyMap` as a func argument since it is declared in a global scope already
5777536
to
69027a1
Compare
@Cammisuli it looks like npm, pnpm are not affected. so no additional changes from my side. Synced w/ master, though |
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
After updating from [email protected] to [email protected] our docusaurus dep starts blocking us from running any nx command because of the error described in the linked issue
Expected Behavior
Packages with such deps, like:
"react-helmet-async": "npm:@slorber/react-helmet-async@*"
shouldn't break any nx commandRelated Issue(s)
Fixes #27285