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: special version node check #6509

Merged
merged 4 commits into from May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,5 @@
---
"@pnpm/config": major
---

fix special node version check
2 changes: 1 addition & 1 deletion config/package-is-installable/src/getSystemNodeVersion.ts
Expand Up @@ -6,7 +6,7 @@ export function getSystemNodeVersionNonCached () {
if (process['pkg'] != null) {
return execa.sync('node', ['--version']).stdout.toString()
}
return process.version
return process.version.replace(/-.*$/, '')
Copy link
Member

Choose a reason for hiding this comment

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

why is this change required? Is it because it currently fails when checking if the node.js version satisfies the range in the engines field? I think in that case this change should be done before passing the version to semver. This function may be used also to print the node.js version and in that case I think we should return the correct version. Also, the way you did it, doesn't cover line 7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I installed version v21.0.0-nightly20230429c968361829 to test a function of node. When I run the project, its engine.node field value ^14.18.0 || >=16.0.0 check will fail. Running it with npm will work fine.

I think in that case this change should be done before passing the version to semver.

You mean maybe we should change here?

if (wantedEngine.node && !semver.satisfies(currentEngine.node, wantedEngine.node)) {

This function may be used also to print the node.js version and in that case I think we should return the correct version. Also, the way you did it, doesn't cover line 7.

I was negligent, I didn't think about these before. If we modify it in the above way, there is no need to change it here.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that looks like the right place for the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, let me modify it.

}

export const getSystemNodeVersion = mem(getSystemNodeVersionNonCached)
18 changes: 18 additions & 0 deletions config/package-is-installable/test/getSystemNodeVersion.test.ts
Expand Up @@ -7,6 +7,18 @@ jest.mock('execa', () => ({
})),
}))

const originProcess = process
let i = 0
beforeEach(() => {
i++
if (i === 3) {
global.process = { ...originProcess, version: 'v21.0.0-nightly20230429c968361829' }
}
})
afterEach(() => {
global.process = originProcess
})

test('getSystemNodeVersion() executed from an executable pnpm CLI', () => {
// @ts-expect-error
process['pkg'] = {}
Expand All @@ -19,3 +31,9 @@ test('getSystemNodeVersion() from a non-executable pnpm CLI', () => {
delete process['pkg']
expect(getSystemNodeVersionNonCached()).toBe(process.version)
})

test('getSystemNodeVersion() a special version number', () => {
// @ts-expect-error
delete process['pkg']
expect(getSystemNodeVersionNonCached()).toBe('v21.0.0')
})