mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-09 15:38:39 -05:00
fix(exec): pnpm exec should work outside of Node.js projects (#3597)
This commit is contained in:
5
.changeset/large-moose-walk.md
Normal file
5
.changeset/large-moose-walk.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
---
|
||||
|
||||
`pnpm exec` should work outside of Node.js projects.
|
||||
@@ -3,8 +3,9 @@ import { RecursiveSummary, throwOnCommandFail } from '@pnpm/cli-utils'
|
||||
import { Config, types } from '@pnpm/config'
|
||||
import { makeNodeRequireOption } from '@pnpm/lifecycle'
|
||||
import logger from '@pnpm/logger'
|
||||
import readProjectManifest from '@pnpm/read-project-manifest'
|
||||
import { tryReadProjectManifest } from '@pnpm/read-project-manifest'
|
||||
import sortPackages from '@pnpm/sort-packages'
|
||||
import { Project } from '@pnpm/types'
|
||||
import execa from 'execa'
|
||||
import pLimit from 'p-limit'
|
||||
import PATH from 'path-name'
|
||||
@@ -87,14 +88,17 @@ export async function handler (
|
||||
: [Object.keys(opts.selectedProjectsGraph).sort()]
|
||||
} else {
|
||||
chunks = [[opts.dir]]
|
||||
opts.selectedProjectsGraph = {
|
||||
[opts.dir]: {
|
||||
dependencies: [],
|
||||
package: {
|
||||
...await readProjectManifest(opts.dir),
|
||||
dir: opts.dir,
|
||||
const project = await tryReadProjectManifest(opts.dir)
|
||||
if (project.manifest != null) {
|
||||
opts.selectedProjectsGraph = {
|
||||
[opts.dir]: {
|
||||
dependencies: [],
|
||||
package: {
|
||||
...project,
|
||||
dir: opts.dir,
|
||||
} as Project,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
const existsPnp = existsInDir.bind(null, '.pnp.cjs')
|
||||
@@ -118,7 +122,7 @@ export async function handler (
|
||||
path.join(opts.dir, 'node_modules/.bin'),
|
||||
process.env[PATH],
|
||||
].join(path.delimiter),
|
||||
PNPM_PACKAGE_NAME: opts.selectedProjectsGraph[prefix].package.manifest.name,
|
||||
PNPM_PACKAGE_NAME: opts.selectedProjectsGraph?.[prefix]?.package.manifest.name,
|
||||
},
|
||||
stdio: 'inherit',
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from 'path'
|
||||
import PnpmError from '@pnpm/error'
|
||||
import { readProjects } from '@pnpm/filter-workspace-packages'
|
||||
import { exec } from '@pnpm/plugin-commands-script-runners'
|
||||
import prepare, { preparePackages } from '@pnpm/prepare'
|
||||
import prepare, { prepareEmpty, preparePackages } from '@pnpm/prepare'
|
||||
import rimraf from '@zkochan/rimraf'
|
||||
import execa from 'execa'
|
||||
import { DEFAULT_OPTS, REGISTRY } from './utils'
|
||||
@@ -308,6 +308,20 @@ test('pnpm exec on single project', async () => {
|
||||
expect(outputs).toStrictEqual([])
|
||||
})
|
||||
|
||||
test('pnpm exec outside of projects', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await exec.handler({
|
||||
...DEFAULT_OPTS,
|
||||
dir: process.cwd(),
|
||||
recursive: false,
|
||||
selectedProjectsGraph: {},
|
||||
}, ['node', '-e', 'require("fs").writeFileSync("output.json", "[]", "utf8")'])
|
||||
|
||||
const { default: outputs } = await import(path.resolve('output.json'))
|
||||
expect(outputs).toStrictEqual([])
|
||||
})
|
||||
|
||||
test('pnpm recursive exec works with PnP', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user