1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Pass through arguments of the next cli correctly (#6327)

Arguments that held the same name as one of the default commands were filtered out, causing issues.

For example `next build build` would get rid of the second `build` parameter.

Fixes #6263
This commit is contained in:
Tim Neutkens 2019-02-17 20:13:10 +01:00 committed by GitHub
parent dd9811b206
commit a1ccc19a1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 3 deletions

View file

@ -42,7 +42,7 @@ if (args['--version']) {
}
// Check if we are running `next <subcommand>` or `next`
const foundCommand = args._.find((cmd) => commands.includes(cmd))
const foundCommand = commands.includes(args._[0])
// Makes sure the `next <subcommand> --help` case is covered
// This help message is only showed for `next --help`
@ -73,8 +73,8 @@ if (args['--inspect']) {
nodeArguments.push('--inspect')
}
const command = foundCommand || defaultCommand
const forwardedArgs = args._.filter((arg) => arg !== command)
const command = foundCommand ? args._[0] : defaultCommand
const forwardedArgs = foundCommand ? args._.slice(1) : args._
// Make sure the `next <subcommand> --help` case is covered
if (args['--help']) {

View file

@ -0,0 +1 @@
export default () => <div>Hello World</div>

View file

@ -0,0 +1,69 @@
/* eslint-env jest */
/* global jasmine */
import { dirname, join } from 'path'
import {
nextServer,
startApp,
stopApp,
renderViaHTTP
} from 'next-test-utils'
import spawn from 'cross-spawn'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
function runNextCommand (argv, options = {}) {
return new Promise((resolve, reject) => {
console.log(`Running command "next ${argv.join(' ')}"`)
const instance = spawn('node', [join(dirname(require.resolve('next/package')), 'dist/bin/next'), ...argv], { ...options.spawnOptions, cwd: join(__dirname, '..'), stdio: ['ignore', 'pipe', 'pipe'] })
let stderrOutput = ''
if (options.stderr) {
instance.stderr.on('data', function (chunk) {
stderrOutput += chunk
})
}
let stdoutOutput = ''
if (options.stdout) {
instance.stdout.on('data', function (chunk) {
stdoutOutput += chunk
})
}
instance.on('close', () => {
resolve({
stdout: stdoutOutput,
stderr: stderrOutput
})
})
instance.on('error', (err) => {
err.stdout = stdoutOutput
err.stderr = stderrOutput
reject(err)
})
})
}
describe('Production Custom Build Directory', () => {
describe('With basic usage', () => {
it('should render the page', async () => {
const result = await runNextCommand(['build', 'build'], {stdout: true, stderr: true})
expect(result.stderr).toBe('')
const app = nextServer({
dir: join(__dirname, '../build'),
dev: false,
quiet: true
})
const server = await startApp(app)
const appPort = server.address().port
const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/Hello World/)
await stopApp(server)
})
})
})