mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: don't fail when the pnpm CLI executed through piping
This commit is contained in:
6
.changeset/soft-chairs-sort.md
Normal file
6
.changeset/soft-chairs-sort.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/cli-meta": patch
|
||||
"@pnpm/store-connection-manager": patch
|
||||
---
|
||||
|
||||
Don't fail when the code is executed through piping to Node's stdin.
|
||||
@@ -7,15 +7,19 @@ const defaultManifest = {
|
||||
version: '0.0.0',
|
||||
}
|
||||
let pkgJson
|
||||
try {
|
||||
pkgJson = {
|
||||
...defaultManifest,
|
||||
...loadJsonFile.sync<DependencyManifest>(
|
||||
path.join(path.dirname(require.main!.filename), '../package.json')
|
||||
),
|
||||
}
|
||||
} catch (err) {
|
||||
if (!require.main) {
|
||||
pkgJson = defaultManifest
|
||||
} else {
|
||||
try {
|
||||
pkgJson = {
|
||||
...defaultManifest,
|
||||
...loadJsonFile.sync<DependencyManifest>(
|
||||
path.join(path.dirname(require.main.filename), '../package.json')
|
||||
),
|
||||
}
|
||||
} catch (err) {
|
||||
pkgJson = defaultManifest
|
||||
}
|
||||
}
|
||||
|
||||
const packageManager = {
|
||||
|
||||
@@ -135,12 +135,26 @@ test('exit code from plugin is used to end the process', () => {
|
||||
expect(result.stdout.toString()).toMatch(/is-positive/)
|
||||
})
|
||||
|
||||
const PNPM_CLI = path.join(__dirname, '../dist/pnpm.js')
|
||||
|
||||
test('the bundled CLI is independent', async () => {
|
||||
const project = prepare()
|
||||
|
||||
await fs.copyFile(path.join(__dirname, '../dist/pnpm.js'), 'pnpm.js')
|
||||
await fs.copyFile(PNPM_CLI, 'pnpm.js')
|
||||
|
||||
await execa('node', ['./pnpm.js', 'add', 'is-positive'])
|
||||
|
||||
await project.has('is-positive')
|
||||
})
|
||||
|
||||
test('the bundled CLI can be executed from stdin', async () => {
|
||||
const project = prepare()
|
||||
|
||||
const nodeProcess = execa('node', ['-', 'add', 'is-positive'])
|
||||
|
||||
fs.createReadStream(PNPM_CLI).pipe(nodeProcess.stdin!)
|
||||
|
||||
await nodeProcess
|
||||
|
||||
await project.has('is-positive')
|
||||
})
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import PnpmError from '@pnpm/error'
|
||||
import diable = require('@zkochan/diable')
|
||||
|
||||
const pnpm = require.main!.filename
|
||||
|
||||
export default (storePath: string) => {
|
||||
return diable.daemonize(pnpm, ['server', 'start', '--store-dir', storePath], { stdio: 'inherit' })
|
||||
if (!require.main) {
|
||||
throw new PnpmError('CANNOT_START_SERVER', 'pnpm server cannot be started when pnpm is streamed to Node.js')
|
||||
}
|
||||
return diable.daemonize(require.main.filename, ['server', 'start', '--store-dir', storePath], { stdio: 'inherit' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user