-
Notifications
You must be signed in to change notification settings - Fork 33.3k
[engineering] run npm i
during postinstall in parallel
#252068
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
base: main
Are you sure you want to change the base?
Conversation
The parallel parts work, but the node-gyp override is still problematic. According to the
So setting up |
Agreed, an option would be to check-in node-gyp into the source tree locked to a specific version similar to how it is bundled for npm. This would avoid any preinstall script dependency but comes with it own maintenance cost. How about moving the native module dependencies of the root folder into a subfolder say
The following additionally need to be covered,
But this seems like a good path forward, considering npm/cli#8153 coming our way which requires us to inject the npm config env variables rather than them being auto injected via the rc file we need a way for the root native modules to be adapted and this seems like a good solution to cover both. Thoughts ? |
opened #252171 for discussion on the dependency structure. |
Added a comment to the PR for the node-gyp config but perhaps it's better to continue here. The syntax in the
The |
@wraithgar thanks for the context, we did notice the config name was incorrect in #250554 (comment) :)
👍 |
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.
Hi! I'm a grad student working on a research project about using large language models to automate code review. Based on your commit d962a12 and the changes in build/npm/postinstall.js, my tool generated this comment:
- Null Checks for
opts
: Theopts
parameter is spread into a new object without checking if it is null or undefined. Consider adding a check to ensureopts
is an object before spreading it. - User Info Handling: Validate that the
uid
andgid
properties fromos.userInfo()
exist before using them. - Error Handling: The patch does not introduce any error handling for the
run
function calls. It would be beneficial to include error handling to catch potential issues during command execution. - Concatenation of PATH: Ensure that
opts.env[pathVar]
is defined before concatenating. Ifopts.env[pathVar]
isundefined
, the resultingopts.env[pathVar]
will only be set to the new path. - Potential for Path Delimiter Issues: If
opts.env[pathVar]
isundefined
, the concatenation will not include a delimiter. It might be safer to conditionally add the delimiter only ifopts.env[pathVar]
is defined. - Environment Variable Case Sensitivity: The patch correctly handles the case sensitivity of the
PATH
variable on Windows by usingPath
instead ofPATH
. - Redundant Path Construction: Store the path in a variable and reuse it to avoid redundancy:
-
```javascript
-
const nodeGypPath = process.platform === 'win32'
-
? path.join(__dirname, 'gyp', 'node_modules', '.bin', 'node-gyp.cmd')
-
: path.join(__dirname, 'gyp', 'node_modules', '.bin', 'node-gyp');
-
opts.env['npm_config_node_gyp'] = nodeGypPath;
-
opts.env[pathVar] = nodeGypPath + path.delimiter + opts.env[pathVar];
-
```
- String Concatenation: Use template literals for better readability:
-
- opts.env[pathVar] =
${path.join(__dirname, 'gyp', 'node_modules', '.bin')}${path.delimiter}${opts.env[pathVar]}
; -
- Logging Sensitive Information: Ensure that sensitive data, such as
GITHUB_TOKEN
, is not logged or is masked 80AB appropriately to prevent leakage.
As part of my research, I'm trying to understand how useful these comments are in real-world development. If you have a moment, I'd be super grateful if you could quickly reply to these two yes/no questions:
- Does this comment provide suggestions from a dimension you hadn’t considered?
-
- Do you find this comment helpful?
Thanks a lot for your time and feedback! And sorry again if this message is a bother.
this speeds up
npm i
considerably on all platformsi have been using this for a few months so all the bugs should be worked out
one major issue was running node-gyp in parallel can cause random corruption nodejs/node-gyp#3165
cc @deepak1556 #250554 #250981