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: correctly detect the active Node js version during headless installation #7801

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions config/package-is-installable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type { Engine } from './checkEngine'
export type { Platform, WantedPlatform } from './checkPlatform'

export {
getSystemNodeVersion,
UnsupportedEngineError,
UnsupportedPlatformError,
type WantedEngine,
Expand Down
1 change: 1 addition & 0 deletions pkg-manager/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@pnpm/modules-yaml": "workspace:*",
"@pnpm/normalize-registries": "workspace:*",
"@pnpm/npm-package-arg": "^1.0.0",
"@pnpm/package-is-installable": "workspace:*",
"@pnpm/package-requester": "workspace:*",
"@pnpm/parse-wanted-dependency": "workspace:*",
"@pnpm/pkg-manager.direct-dep-linker": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion pkg-manager/core/src/install/extendInstallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { createReadPackageHook } from '@pnpm/hooks.read-package-hook'
import { type Lockfile } from '@pnpm/lockfile-file'
import { type IncludedDependencies } from '@pnpm/modules-yaml'
import { normalizeRegistries, DEFAULT_REGISTRIES } from '@pnpm/normalize-registries'
import { getSystemNodeVersion } from '@pnpm/package-is-installable'
import { type WorkspacePackages } from '@pnpm/resolver-base'
import { type StoreController } from '@pnpm/store-controller-types'
import {
Expand Down Expand Up @@ -187,7 +188,7 @@ const defaults = (opts: InstallOptions) => {
},
lockfileDir: opts.lockfileDir ?? opts.dir ?? process.cwd(),
lockfileOnly: false,
nodeVersion: process.version,
nodeVersion: opts.nodeVersion ?? getSystemNodeVersion(),
Copy link
Member

Choose a reason for hiding this comment

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

This should be enough

Suggested change
nodeVersion: opts.nodeVersion ?? getSystemNodeVersion(),
nodeVersion: opts.nodeVersion,

Copy link
Member

Choose a reason for hiding this comment

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

The issue is that we pass process.version. getSystemNodeVersion will be used anyway inside package-is-installable.

nodeLinker: 'isolated',
overrides: {},
ownLifecycleHooksStdio: 'inherit',
Expand Down
36 changes: 36 additions & 0 deletions pkg-manager/core/test/install/headlessInstallationChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { prepareEmpty } from '@pnpm/prepare'
import { getSystemNodeVersion } from '@pnpm/package-is-installable'
import {
addDependenciesToPackage,
install,
} from '@pnpm/core'
import { testDefaults } from '../utils'

jest.mock('@pnpm/package-is-installable', () => ({
...jest.requireActual('@pnpm/package-is-installable'),
getSystemNodeVersion: jest.fn(() => process.version),
}))

afterEach(() => {
jest.mocked(getSystemNodeVersion).mockRestore()
})

test('do not fail if package supports the system Node and engine-strict = true', async () => {
const project = prepareEmpty()

const manifest = await addDependenciesToPackage({},
[
'@pnpm.e2e/for-legacy-node',
],
testDefaults()
)

const lockfile = project.readLockfile()
expect(lockfile.packages['/@pnpm.e2e/for-legacy-node@1.0.0'].engines).toStrictEqual({ node: '0.10' })

await expect(install(manifest, testDefaults({ engineStrict: true }))).rejects.toThrow()

jest.mocked(getSystemNodeVersion).mockImplementation(() => '0.10.0')

await expect(install(manifest, testDefaults({ engineStrict: true }))).resolves.not.toThrow()
})
3 changes: 3 additions & 0 deletions pkg-manager/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
{
"path": "../../config/normalize-registries"
},
{
"path": "../../config/package-is-installable"
},
{
"path": "../../crypto/object-hasher"
},
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.