fix: pnpm test|start|stop should allow the same options as pnpm run test|start|stop

PR #2814
This commit is contained in:
Zoltan Kochan
2020-09-01 15:44:39 +03:00
committed by GitHub
parent 9f1a29ff9e
commit de61940a57
9 changed files with 30 additions and 142 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---
`pnpm test|start|stop` support the same options as `pnpm run test|start|stop`.

View File

@@ -0,0 +1,7 @@
---
"@pnpm/plugin-commands-script-runners": major
---
The start and stop script commands are removed.
There is no reason to define separate handlers for shorthand commands
as any unknown command is automatically converted to a script.

View File

@@ -1,8 +1,11 @@
import * as exec from './exec'
import * as restart from './restart'
import * as run from './run'
import * as start from './start'
import * as stop from './stop'
import * as test from './test'
import * as _test from './test'
export { exec, restart, run, start, stop, test }
const test = {
...run,
..._test,
}
export { exec, restart, run, test }

View File

@@ -5,8 +5,6 @@ import {
IF_PRESENT_OPTION_HELP,
RunOpts,
} from './run'
import { handler as start } from './start'
import { handler as stop } from './stop'
import R = require('ramda')
import renderHelp = require('render-help')
@@ -44,7 +42,7 @@ export async function handler (
opts: RunOpts,
params: string[]
) {
await stop(opts, params)
await run(opts, ['stop', ...params])
await run(opts, ['restart', ...params])
await start(opts, params)
await run(opts, ['start', ...params])
}

View File

@@ -1,50 +0,0 @@
import { docsUrl } from '@pnpm/cli-utils'
import { types as allTypes } from '@pnpm/config'
import {
handler as run,
IF_PRESENT_OPTION,
IF_PRESENT_OPTION_HELP,
RunOpts,
} from './run'
import R = require('ramda')
import renderHelp = require('render-help')
export function rcOptionsTypes () {
return {
...R.pick([
'npm-path',
], allTypes),
}
}
export function cliOptionsTypes () {
return IF_PRESENT_OPTION
}
export const commandNames = ['start']
export function help () {
return renderHelp({
description: '\
Runs an arbitrary command specified in the package\'s "start" property of its "scripts" object. \
If no "start" property is specified on the "scripts" object, it will run node server.js.',
descriptionLists: [
{
title: 'Options',
list: [
IF_PRESENT_OPTION_HELP,
],
},
],
url: docsUrl('start'),
usages: ['pnpm start [-- <args>...]'],
})
}
export function handler (
opts: RunOpts,
params: string[]
) {
return run(opts, ['start', ...params])
}

View File

@@ -1,48 +0,0 @@
import { docsUrl } from '@pnpm/cli-utils'
import { types as allTypes } from '@pnpm/config'
import {
handler as run,
IF_PRESENT_OPTION,
IF_PRESENT_OPTION_HELP,
RunOpts,
} from './run'
import R = require('ramda')
import renderHelp = require('render-help')
export function rcOptionsTypes () {
return {
...R.pick([
'npm-path',
], allTypes),
}
}
export function cliOptionsTypes () {
return IF_PRESENT_OPTION
}
export const commandNames = ['stop']
export function help () {
return renderHelp({
description: 'Runs a package\'s "stop" script, if one was provided.',
descriptionLists: [
{
title: 'Options',
list: [
IF_PRESENT_OPTION_HELP,
],
},
],
url: docsUrl('stop'),
usages: ['pnpm stop [-- <args>...]'],
})
}
export function handler (
opts: RunOpts,
params: string[]
) {
return run(opts, ['stop', ...params])
}

View File

@@ -1,29 +1,8 @@
import { docsUrl } from '@pnpm/cli-utils'
import { FILTERING } from '@pnpm/common-cli-options-help'
import { types as allTypes } from '@pnpm/config'
import { handler as run, RunOpts } from './run'
import R = require('ramda')
import * as run from './run'
import renderHelp = require('render-help')
export function rcOptionsTypes () {
return R.pick([
'npm-path',
'unsafe-perm',
'workspace-concurrency',
], allTypes)
}
export function cliOptionsTypes () {
return {
...rcOptionsTypes(),
...R.pick([
'bail',
'sort',
], allTypes),
recursive: Boolean,
}
}
export const commandNames = ['test', 't', 'tst']
export function help () {
@@ -53,8 +32,8 @@ For options that may be used with `-r`, see "pnpm help recursive"',
}
export function handler (
opts: RunOpts,
opts: run.RunOpts,
params: string[] = []
) {
return run(opts, ['test', ...params])
return run.handler(opts, ['test', ...params])
}

View File

@@ -2,8 +2,6 @@
import {
restart,
run,
start,
stop,
test as testCommand,
} from '@pnpm/plugin-commands-script-runners'
import prepare from '@pnpm/prepare'
@@ -128,7 +126,7 @@ test('test: pass the args to the command that is specfied in the build script of
t.end()
})
test('start: pass the args to the command that is specfied in the build script of a package.yaml manifest', async (t) => {
test('run start: pass the args to the command that is specfied in the build script of a package.yaml manifest', async (t) => {
prepare(t, {
scripts: {
poststart: 'node recordArgs',
@@ -139,11 +137,11 @@ test('start: pass the args to the command that is specfied in the build script o
await fs.writeFile('args.json', '[]', 'utf8')
await fs.writeFile('recordArgs.js', RECORD_ARGS_FILE, 'utf8')
await start.handler({
await run.handler({
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
}, ['arg', '--flag=true', '--help', '-h'])
}, ['start', 'arg', '--flag=true', '--help', '-h'])
const args = await import(path.resolve('args.json'))
t.deepEqual(args, [
@@ -155,7 +153,7 @@ test('start: pass the args to the command that is specfied in the build script o
t.end()
})
test('stop: pass the args to the command that is specfied in the build script of a package.yaml manifest', async (t) => {
test('run stop: pass the args to the command that is specfied in the build script of a package.yaml manifest', async (t) => {
prepare(t, {
scripts: {
poststop: 'node recordArgs',
@@ -166,11 +164,11 @@ test('stop: pass the args to the command that is specfied in the build script of
await fs.writeFile('args.json', '[]', 'utf8')
await fs.writeFile('recordArgs.js', RECORD_ARGS_FILE, 'utf8')
await stop.handler({
await run.handler({
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
}, ['arg', '--flag=true', '--help', '-h'])
}, ['stop', 'arg', '--flag=true', '--help', '-h'])
const args = await import(path.resolve('args.json'))
t.deepEqual(args, [

View File

@@ -11,8 +11,6 @@ import {
exec,
restart,
run,
start,
stop,
test,
} from '@pnpm/plugin-commands-script-runners'
import { server } from '@pnpm/plugin-commands-server'
@@ -75,8 +73,6 @@ const commands: Array<{
root,
run,
server,
start,
stop,
store,
test,
unlink,