mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-11 00:18:32 -05:00
fix: don't download node, when wanted node version is running (#8673)
close #8391 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
7
.changeset/fifty-timers-thank.md
Normal file
7
.changeset/fifty-timers-thank.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-env": patch
|
||||
---
|
||||
|
||||
pnpm no longer downloads the required `use-node-version` if the running node version is the same as the wanted version
|
||||
|
||||
The required `use-node-version` is no longer downloaded if the running Node version is the same as the wanted version [#8673](https://github.com/pnpm/pnpm/pull/8673).
|
||||
5
.changeset/tame-comics-explain.md
Normal file
5
.changeset/tame-comics-explain.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/env.system-node-version": major
|
||||
---
|
||||
|
||||
Initial release.
|
||||
@@ -31,6 +31,7 @@
|
||||
"dependencies": {
|
||||
"@pnpm/cli-meta": "workspace:*",
|
||||
"@pnpm/core-loggers": "workspace:*",
|
||||
"@pnpm/env.system-node-version": "workspace:*",
|
||||
"@pnpm/error": "workspace:*",
|
||||
"@pnpm/types": "workspace:*",
|
||||
"detect-libc": "catalog:",
|
||||
|
||||
@@ -2,9 +2,9 @@ import {
|
||||
installCheckLogger,
|
||||
skippedOptionalDependencyLogger,
|
||||
} from '@pnpm/core-loggers'
|
||||
import { getSystemNodeVersion } from '@pnpm/env.system-node-version'
|
||||
import { checkEngine, UnsupportedEngineError, type WantedEngine } from './checkEngine'
|
||||
import { checkPlatform, UnsupportedPlatformError } from './checkPlatform'
|
||||
import { getSystemNodeVersion } from './getSystemNodeVersion'
|
||||
import { type SupportedArchitectures } from '@pnpm/types'
|
||||
|
||||
export type { Engine } from './checkEngine'
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
{
|
||||
"path": "../../cli/cli-meta"
|
||||
},
|
||||
{
|
||||
"path": "../../env/system-node-version"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/core-loggers"
|
||||
},
|
||||
|
||||
1
env/plugin-commands-env/package.json
vendored
1
env/plugin-commands-env/package.json
vendored
@@ -35,6 +35,7 @@
|
||||
"dependencies": {
|
||||
"@pnpm/cli-utils": "workspace:*",
|
||||
"@pnpm/config": "workspace:*",
|
||||
"@pnpm/env.system-node-version": "workspace:*",
|
||||
"@pnpm/error": "workspace:*",
|
||||
"@pnpm/fetch": "workspace:*",
|
||||
"@pnpm/node.fetcher": "workspace:*",
|
||||
|
||||
5
env/plugin-commands-env/src/node.ts
vendored
5
env/plugin-commands-env/src/node.ts
vendored
@@ -2,6 +2,7 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
import util from 'util'
|
||||
import { type Config } from '@pnpm/config'
|
||||
import { getSystemNodeVersion } from '@pnpm/env.system-node-version'
|
||||
import { createFetchFromRegistry, type FetchFromRegistry } from '@pnpm/fetch'
|
||||
import { globalInfo } from '@pnpm/logger'
|
||||
import { fetchNode } from '@pnpm/node.fetcher'
|
||||
@@ -40,7 +41,9 @@ export type NvmNodeCommandOptions = Pick<Config,
|
||||
const nodeFetchPromises: Record<string, Promise<string>> = {}
|
||||
|
||||
export async function prepareExecutionEnv (config: NvmNodeCommandOptions, { extraBinPaths, executionEnv }: PrepareExecutionEnvOptions): Promise<PrepareExecutionEnvResult> {
|
||||
if (!executionEnv?.nodeVersion) return { extraBinPaths: extraBinPaths ?? [] }
|
||||
if (!executionEnv?.nodeVersion || `v${executionEnv.nodeVersion}` === getSystemNodeVersion()) {
|
||||
return { extraBinPaths: extraBinPaths ?? [] }
|
||||
}
|
||||
|
||||
let nodePathPromise = nodeFetchPromises[executionEnv.nodeVersion]
|
||||
if (!nodePathPromise) {
|
||||
|
||||
18
env/plugin-commands-env/test/node.test.ts
vendored
18
env/plugin-commands-env/test/node.test.ts
vendored
@@ -2,7 +2,7 @@ import AdmZip from 'adm-zip'
|
||||
import { Response } from 'node-fetch'
|
||||
import path from 'path'
|
||||
import { Readable } from 'stream'
|
||||
import { getNodeDir, getNodeBinDir, getNodeVersionsBaseDir, type NvmNodeCommandOptions } from '../lib/node'
|
||||
import { getNodeDir, getNodeBinDir, getNodeVersionsBaseDir, type NvmNodeCommandOptions, prepareExecutionEnv } from '../lib/node'
|
||||
import { tempDir } from '@pnpm/prepare'
|
||||
|
||||
const fetchMock = jest.fn(async (url: string) => {
|
||||
@@ -84,3 +84,19 @@ test('get node version base dir', async () => {
|
||||
const versionDir = getNodeVersionsBaseDir(process.cwd())
|
||||
expect(versionDir).toBe(path.resolve(process.cwd(), 'nodejs'))
|
||||
})
|
||||
|
||||
describe('prepareExecutionEnv', () => {
|
||||
test('should not proceed to fetch Node.js if the process is already running in wanted node version', async () => {
|
||||
fetchMock.mockImplementationOnce(() => {
|
||||
throw new Error('prepareExecutionEnv should not proceed to fetch Node.js when wanted version is running')
|
||||
})
|
||||
|
||||
await prepareExecutionEnv({
|
||||
bin: '',
|
||||
pnpmHomeDir: process.cwd(),
|
||||
rawConfig: {},
|
||||
}, {
|
||||
executionEnv: { nodeVersion: process.versions.node },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
3
env/plugin-commands-env/tsconfig.json
vendored
3
env/plugin-commands-env/tsconfig.json
vendored
@@ -41,6 +41,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../node.resolver"
|
||||
},
|
||||
{
|
||||
"path": "../system-node-version"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
15
env/system-node-version/README.md
vendored
Normal file
15
env/system-node-version/README.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# @pnpm/env.system-node-version
|
||||
|
||||
> Detects the current system node version
|
||||
|
||||
[](https://www.npmjs.com/package/@pnpm/env.system-node-version)
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
pnpm add @pnpm/env.system-node-version
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
3
env/system-node-version/jest.config.js
vendored
Normal file
3
env/system-node-version/jest.config.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const config = require('../../jest.config.js')
|
||||
|
||||
module.exports = config
|
||||
44
env/system-node-version/package.json
vendored
Normal file
44
env/system-node-version/package.json
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@pnpm/env.system-node-version",
|
||||
"version": "0.0.0",
|
||||
"description": "Detects the current system node version",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"files": [
|
||||
"lib",
|
||||
"!*.map"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=18.12"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"_test": "jest",
|
||||
"test": "pnpm run compile && pnpm run _test",
|
||||
"prepublishOnly": "pnpm run compile",
|
||||
"compile": "tsc --build && pnpm run lint --fix"
|
||||
},
|
||||
"repository": "https://github.com/pnpm/pnpm/blob/main/env/system-node-version",
|
||||
"keywords": [
|
||||
"pnpm9",
|
||||
"pnpm",
|
||||
"env"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pnpm/pnpm/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pnpm/pnpm/blob/main/env/system-node-version#readme",
|
||||
"dependencies": {
|
||||
"@pnpm/cli-meta": "workspace:*",
|
||||
"execa": "catalog:",
|
||||
"mem": "catalog:"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm",
|
||||
"devDependencies": {
|
||||
"@pnpm/env.system-node-version": "workspace:*"
|
||||
},
|
||||
"exports": {
|
||||
".": "./lib/index.js"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getSystemNodeVersionNonCached } from '../lib/getSystemNodeVersion'
|
||||
import { getSystemNodeVersionNonCached } from '../lib'
|
||||
import * as execa from 'execa'
|
||||
|
||||
jest.mock('execa', () => ({
|
||||
@@ -18,4 +18,4 @@ test('getSystemNodeVersion() from a non-executable pnpm CLI', () => {
|
||||
// @ts-expect-error
|
||||
delete process['pkg']
|
||||
expect(getSystemNodeVersionNonCached()).toBe(process.version)
|
||||
})
|
||||
})
|
||||
17
env/system-node-version/test/tsconfig.json
vendored
Normal file
17
env/system-node-version/test/tsconfig.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"outDir": "../test.lib",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"../../../__typings__/**/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": ".."
|
||||
}
|
||||
]
|
||||
}
|
||||
16
env/system-node-version/tsconfig.json
vendored
Normal file
16
env/system-node-version/tsconfig.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "@pnpm/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"../../__typings__/**/*.d.ts"
|
||||
],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../cli/cli-meta"
|
||||
}
|
||||
]
|
||||
}
|
||||
8
env/system-node-version/tsconfig.lint.json
vendored
Normal file
8
env/system-node-version/tsconfig.lint.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"test/**/*.ts",
|
||||
"../../__typings__/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
22
pnpm-lock.yaml
generated
22
pnpm-lock.yaml
generated
@@ -1524,6 +1524,9 @@ importers:
|
||||
'@pnpm/core-loggers':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/core-loggers
|
||||
'@pnpm/env.system-node-version':
|
||||
specifier: workspace:*
|
||||
version: link:../../env/system-node-version
|
||||
'@pnpm/error':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/error
|
||||
@@ -1835,6 +1838,9 @@ importers:
|
||||
'@pnpm/config':
|
||||
specifier: workspace:*
|
||||
version: link:../../config/config
|
||||
'@pnpm/env.system-node-version':
|
||||
specifier: workspace:*
|
||||
version: link:../system-node-version
|
||||
'@pnpm/error':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/error
|
||||
@@ -1921,6 +1927,22 @@ importers:
|
||||
specifier: 'catalog:'
|
||||
version: 1.0.0
|
||||
|
||||
env/system-node-version:
|
||||
dependencies:
|
||||
'@pnpm/cli-meta':
|
||||
specifier: workspace:*
|
||||
version: link:../../cli/cli-meta
|
||||
execa:
|
||||
specifier: 'catalog:'
|
||||
version: safe-execa@0.1.2
|
||||
mem:
|
||||
specifier: 'catalog:'
|
||||
version: 8.1.1
|
||||
devDependencies:
|
||||
'@pnpm/env.system-node-version':
|
||||
specifier: workspace:*
|
||||
version: 'link:'
|
||||
|
||||
exec/build-modules:
|
||||
dependencies:
|
||||
'@pnpm/calc-dep-state':
|
||||
|
||||
Reference in New Issue
Block a user