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

feat: allow checkPlatform to override execution environment #65

Merged
merged 5 commits into from
Aug 7, 2023

Conversation

yukukotani
Copy link
Contributor

This PR allows checkPlatform to override execution environment which comes from process.platform and process.arch by default.

This will be required to achieve npm/rfcs#612

References

@yukukotani yukukotani requested a review from a team as a code owner August 5, 2023 00:00
lib/index.js Outdated
if (force) {
return
}

const platform = process.platform
const arch = process.arch
const platform = environment && environment.os ? environment.os : process.platform
Copy link
Member

Choose a reason for hiding this comment

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

Since we're defaulting environment to {} here we don't need the environment && guard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wraithgar Callers of this function may still pass null or undefined for this argument while the default value is {}. How about leaving the environment && guard as it is and changing the default value to undefined?

Copy link
Member

Choose a reason for hiding this comment

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

We typically don't guard against bad input. It (arguably unnecessarily) increases the cognitive load of maintaining this module. This is a style choice inside of the npm codebase, we don't need to support the extra falsey value, folks consuming this can omit the parameter.

Copy link
Contributor Author

@yukukotani yukukotani Aug 7, 2023

Choose a reason for hiding this comment

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

@wraithgar Okay, that makes sense! Let's prioritize the consistency across the codebase. 76b0df6

@wraithgar
Copy link
Member

This is going to need tests.

@yukukotani yukukotani requested a review from wraithgar August 7, 2023 15:28
@yukukotani
Copy link
Contributor Author

I've added tests here: d9b4234

@yukukotani yukukotani changed the title allow checkPlatform to override execution environment feat: allow checkPlatform to override execution environment Aug 7, 2023
@yukukotani
Copy link
Contributor Author

updated the PR title

@wraithgar
Copy link
Member

the PR title linting is broken, had a snafu w/ the template-oss template. Don't worry about it.

test/check-platform.js Outdated Show resolved Hide resolved
Co-authored-by: Gar <wraithgar@github.com>
@yukukotani yukukotani requested a review from wraithgar August 7, 2023 16:08
@wraithgar wraithgar merged commit 7a3f5ed into npm:main Aug 7, 2023
@github-actions github-actions bot mentioned this pull request Aug 7, 2023
@yukukotani yukukotani deleted the platform-override branch August 7, 2023 17:54
@yukukotani
Copy link
Contributor Author

@wraithgar Hi, sorry for bothering you but let me kindly remind.

When is this getting released and included in npm/cli? I'd like to start working on npm/rfcs#612.

@lukekarrys
Copy link
Contributor

@yukukotani This will be released with the next npm 10 prerelease which should go out on 2023-08-16. Our main focus is currently to release npm 10 but once that is complete we will be able to backport this feature to npm 9 as well.

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.

3 participants