fix(dlx): use-node-version (#8263)

This commit is contained in:
Khải
2024-07-02 05:37:19 +07:00
committed by GitHub
parent 576f13878e
commit 98f20a70b6
7 changed files with 76 additions and 25 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-script-runners": patch
"pnpm": patch
---
Fix `dlx` not actually using node version specified by `--use-node-version`.

View File

@@ -54,6 +54,7 @@
"@pnpm/lifecycle": "workspace:*",
"@pnpm/log.group": "catalog:",
"@pnpm/package-bins": "workspace:*",
"@pnpm/plugin-commands-env": "workspace:*",
"@pnpm/plugin-commands-installation": "workspace:*",
"@pnpm/read-package-json": "workspace:*",
"@pnpm/read-project-manifest": "workspace:*",

View File

@@ -6,6 +6,7 @@ import { OUTPUT_OPTIONS } from '@pnpm/common-cli-options-help'
import { type Config, types } from '@pnpm/config'
import { createBase32Hash } from '@pnpm/crypto.base32-hash'
import { PnpmError } from '@pnpm/error'
import { node } from '@pnpm/plugin-commands-env'
import { add } from '@pnpm/plugin-commands-installation'
import { readPackageJsonFromDir } from '@pnpm/read-package-json'
import { getBinsFromPackageManifest } from '@pnpm/package-bins'
@@ -64,7 +65,7 @@ export function help (): string {
export type DlxCommandOptions = {
package?: string[]
shellMode?: boolean
} & Pick<Config, 'reporter' | 'userAgent' | 'cacheDir' | 'dlxCacheMaxAge' > & add.AddCommandOptions
} & Pick<Config, 'reporter' | 'userAgent' | 'cacheDir' | 'dlxCacheMaxAge' | 'useNodeVersion' > & add.AddCommandOptions
export async function handler (
opts: DlxCommandOptions,
@@ -94,7 +95,12 @@ export async function handler (
}
const modulesDir = path.join(cacheLink, 'node_modules')
const binsDir = path.join(modulesDir, '.bin')
const env = makeEnv({ userAgent: opts.userAgent, prependPaths: [binsDir] })
const prependPaths = [binsDir]
if (opts.useNodeVersion) {
const nodePath = await node.getNodeBinDir(opts)
prependPaths.push(nodePath)
}
const env = makeEnv({ userAgent: opts.userAgent, prependPaths })
const binName = opts.package
? command
: await getBinName(modulesDir, await getPkgName(cacheLink))

View File

@@ -27,6 +27,9 @@
{
"path": "../../config/config"
},
{
"path": "../../env/plugin-commands-env"
},
{
"path": "../../packages/core-loggers"
},

48
pnpm-lock.yaml generated
View File

@@ -55,8 +55,8 @@ catalogs:
specifier: 0.0.0
version: 0.0.0
'@pnpm/registry-mock':
specifier: 3.33.0
version: 3.33.0
specifier: 3.34.0
version: 3.34.0
'@pnpm/semver-diff':
specifier: ^1.1.0
version: 1.1.0
@@ -715,7 +715,7 @@ importers:
version: 1.0.0
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/tsconfig':
specifier: workspace:*
version: link:__utils__/tsconfig
@@ -830,7 +830,7 @@ importers:
version: link:../../pkg-manager/modules-yaml
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/types':
specifier: workspace:*
version: link:../../packages/types
@@ -864,7 +864,7 @@ importers:
dependencies:
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/store.cafs':
specifier: workspace:*
version: link:../../store/cafs
@@ -2030,7 +2030,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-fixtures':
specifier: workspace:*
version: link:../../__utils__/test-fixtures
@@ -2097,6 +2097,9 @@ importers:
'@pnpm/package-bins':
specifier: workspace:*
version: link:../../pkg-manager/package-bins
'@pnpm/plugin-commands-env':
specifier: workspace:*
version: link:../../env/plugin-commands-env
'@pnpm/plugin-commands-installation':
specifier: workspace:*
version: link:../../pkg-manager/plugin-commands-installation
@@ -2163,7 +2166,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-ipc-server':
specifier: workspace:*
version: link:../../__utils__/test-ipc-server
@@ -3699,7 +3702,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-fixtures':
specifier: workspace:*
version: link:../../__utils__/test-fixtures
@@ -3977,7 +3980,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/store-path':
specifier: workspace:*
version: link:../../store/store-path
@@ -4262,7 +4265,7 @@ importers:
version: link:../read-projects-context
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/store-path':
specifier: workspace:*
version: link:../../store/store-path
@@ -4625,7 +4628,7 @@ importers:
version: 'link:'
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-fixtures':
specifier: workspace:*
version: link:../../__utils__/test-fixtures
@@ -4821,7 +4824,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-fixtures':
specifier: workspace:*
version: link:../../__utils__/test-fixtures
@@ -5414,7 +5417,7 @@ importers:
version: link:../pkg-manifest/read-project-manifest
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/run-npm':
specifier: workspace:*
version: link:../exec/run-npm
@@ -5683,7 +5686,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/workspace.filter-packages-from-dir':
specifier: workspace:*
version: link:../../workspace/filter-packages-from-dir
@@ -5789,7 +5792,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-ipc-server':
specifier: workspace:*
version: link:../../__utils__/test-ipc-server
@@ -6364,7 +6367,7 @@ importers:
version: link:../../pkg-manifest/read-package-json
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-fixtures':
specifier: workspace:*
version: link:../../__utils__/test-fixtures
@@ -6431,7 +6434,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/workspace.filter-packages-from-dir':
specifier: workspace:*
version: link:../../workspace/filter-packages-from-dir
@@ -6522,7 +6525,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@pnpm/test-fixtures':
specifier: workspace:*
version: link:../../__utils__/test-fixtures
@@ -6860,7 +6863,7 @@ importers:
version: link:../../__utils__/prepare
'@pnpm/registry-mock':
specifier: 'catalog:'
version: 3.33.0(encoding@0.1.13)(typanion@3.14.0)
version: 3.34.0(encoding@0.1.13)(typanion@3.14.0)
'@types/archy':
specifier: 'catalog:'
version: 0.0.33
@@ -8441,8 +8444,8 @@ packages:
resolution: {integrity: sha512-MDXuQpYFbabSXzAnqP7VIQqBx5Z1fzOhzB/3YmIXJ+tE7Wue//IR3itMSYlWeaFLo1G5PCJklM2zBdvggRw1nw==}
engines: {node: '>=16.14'}
'@pnpm/registry-mock@3.33.0':
resolution: {integrity: sha512-Y7/QOZ3BPCH5i5OdtglaVTsmEXYZ91ebIxAST3+eBwu8iP0W8AEIw95hYl10jLzWRtUjuIPCph9mTdMWM4h9dg==}
'@pnpm/registry-mock@3.34.0':
resolution: {integrity: sha512-/wANbfGLun8u/ojrvzDJEJjROBcB/ZQMhrufmvV96Yk0VjR2RQ9dXoNrw0BlPyNRYUgG8Hj3Xl9RdZGQW31DYA==}
engines: {node: '>=10.13'}
hasBin: true
@@ -10679,6 +10682,7 @@ packages:
har-validator@5.1.5:
resolution: {integrity: sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==}
engines: {node: '>=6'}
deprecated: this library is no longer supported
hard-rejection@2.1.0:
resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==}
@@ -15238,7 +15242,7 @@ snapshots:
sort-keys: 4.2.0
strip-bom: 4.0.0
'@pnpm/registry-mock@3.33.0(encoding@0.1.13)(typanion@3.14.0)':
'@pnpm/registry-mock@3.34.0(encoding@0.1.13)(typanion@3.14.0)':
dependencies:
anonymous-npm-registry-client: 0.2.0
execa: 5.1.1

View File

@@ -51,7 +51,7 @@ catalog:
"@pnpm/npm-package-arg": ^1.0.0
"@pnpm/os.env.path-extender": ^2.0.0
"@pnpm/patch-package": 0.0.0
"@pnpm/registry-mock": 3.33.0
"@pnpm/registry-mock": 3.34.0
"@pnpm/semver-diff": ^1.1.0
"@pnpm/tabtab": ^0.5.4
"@pnpm/util.lex-comparator": 3.0.0

View File

@@ -240,3 +240,34 @@ test('dlx read registry from .npmrc in the current directory', async () => {
expect(execResult.stdout.toString().trim()).toBe('hello from @pnpm.e2e/needs-auth')
expect(execResult.status).toBe(0)
})
test('dlx uses the node version specified by --use-node-version', async () => {
prepareEmpty()
const pnpmHome = path.resolve('home')
const execResult = execPnpmSync([
'--use-node-version=20.0.0',
`--config.store-dir=${path.resolve('store')}`,
`--config.cache-dir=${path.resolve('cache')}`,
'dlx',
'@pnpm.e2e/print-node-info',
], {
env: {
PNPM_HOME: pnpmHome,
},
stdio: [null, 'pipe', 'inherit'],
})
const nodeInfo = JSON.parse(execResult.stdout.toString())
expect(nodeInfo).toMatchObject({
versions: {
node: '20.0.0',
},
execPath: process.platform === 'win32'
? path.join(pnpmHome, 'nodejs', '20.0.0', 'node.exe')
: path.join(pnpmHome, 'nodejs', '20.0.0', 'bin', 'node'),
})
expect(execResult.status).toBe(0)
})