Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/huge-apples-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---

When executing the `pnpm create` command, must verify whether the node version is supported even if a cache already exists.
1 change: 1 addition & 0 deletions exec/plugin-commands-script-runners/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@pnpm/logger": "catalog:"
},
"devDependencies": {
"@pnpm/env.system-node-version": "workspace:*",
"@pnpm/filter-workspace-packages": "workspace:*",
"@pnpm/logger": "workspace:*",
"@pnpm/plugin-commands-script-runners": "workspace:*",
Expand Down
16 changes: 8 additions & 8 deletions exec/plugin-commands-script-runners/src/dlx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs, { type Stats } from 'fs'
import path from 'path'
import util from 'util'
import { docsUrl } from '@pnpm/cli-utils'
import { docsUrl, readProjectManifestOnly } from '@pnpm/cli-utils'
import { createResolver } from '@pnpm/client'
import { parseWantedDependency } from '@pnpm/parse-wanted-dependency'
import { OUTPUT_OPTIONS } from '@pnpm/common-cli-options-help'
Expand All @@ -11,7 +11,7 @@ import { PnpmError } from '@pnpm/error'
import { add } from '@pnpm/plugin-commands-installation'
import { readPackageJsonFromDir } from '@pnpm/read-package-json'
import { getBinsFromPackageManifest } from '@pnpm/package-bins'
import { type PnpmSettings, type SupportedArchitectures } from '@pnpm/types'
import { type PackageManifest, type PnpmSettings, type SupportedArchitectures } from '@pnpm/types'
import { lexCompare } from '@pnpm/util.lex-comparator'
import execa from 'execa'
import pick from 'ramda/src/pick'
Expand Down Expand Up @@ -138,15 +138,14 @@ export async function handler (
}
}
}
const modulesDir = path.join(cachedDir, 'node_modules')
const binsDir = path.join(modulesDir, '.bin')
const binsDir = path.join(cachedDir, 'node_modules/.bin')
const env = makeEnv({
userAgent: opts.userAgent,
prependPaths: [binsDir, ...opts.extraBinPaths],
})
const binName = opts.package
? command
: await getBinName(modulesDir, await getPkgName(cachedDir))
: await getBinName(cachedDir, opts)
try {
await execa(binName, args, {
cwd: process.cwd(),
Expand Down Expand Up @@ -174,9 +173,10 @@ async function getPkgName (pkgDir: string): Promise<string> {
return dependencyNames[0]
}

async function getBinName (modulesDir: string, pkgName: string): Promise<string> {
const pkgDir = path.join(modulesDir, pkgName)
const manifest = await readPackageJsonFromDir(pkgDir)
async function getBinName (cachedDir: string, opts: Pick<DlxCommandOptions, 'engineStrict'>): Promise<string> {
const pkgName = await getPkgName(cachedDir)
const pkgDir = path.join(cachedDir, 'node_modules', pkgName)
const manifest = await readProjectManifestOnly(pkgDir, opts) as PackageManifest
const bins = await getBinsFromPackageManifest(manifest, pkgDir)
if (bins.length === 0) {
throw new PnpmError('DLX_NO_BIN', `No binaries found in ${pkgName}`)
Expand Down
15 changes: 15 additions & 0 deletions exec/plugin-commands-script-runners/test/dlx.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import path from 'path'
import { add } from '@pnpm/plugin-commands-installation'
import { dlx } from '@pnpm/plugin-commands-script-runners'
import * as systemNodeVersion from '@pnpm/env.system-node-version'
import { prepareEmpty } from '@pnpm/prepare'
import { DLX_DEFAULT_OPTS as DEFAULT_OPTS } from './utils'

Expand Down Expand Up @@ -235,6 +236,20 @@ test('dlx with cache', async () => {
expect(spy).not.toHaveBeenCalled()

spy.mockRestore()

// Specify a node version that [email protected] does not support. Currently supported versions are >= 6.
const spySystemNodeVersion = jest.spyOn(systemNodeVersion, 'getSystemNodeVersion').mockReturnValue('v4.0.0')

await expect(dlx.handler({
...DEFAULT_OPTS,
engineStrict: true,
dir: path.resolve('project'),
storeDir: path.resolve('store'),
cacheDir: path.resolve('cache'),
dlxCacheMaxAge: Infinity,
}, ['[email protected]', 'touch', 'foo'])).rejects.toThrow('Unsupported engine for')

spySystemNodeVersion.mockRestore()
})

test('dlx does not reuse expired cache', async () => {
Expand Down
3 changes: 3 additions & 0 deletions exec/plugin-commands-script-runners/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
{
"path": "../../env/plugin-commands-env"
},
{
"path": "../../env/system-node-version"
},
{
"path": "../../packages/core-loggers"
},
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.

Loading