Unverified Commit e763a608 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Don’t read package.scripts if there’s no scripts defined (#5168)

parent 34cb05a8
#!/usr/bin/env node #!/usr/bin/env node
import { resolve, join } from 'path' import { resolve, join } from 'path'
import parseArgs from 'minimist' import parseArgs from 'minimist'
import { existsSync, readFileSync } from 'fs' import { existsSync } from 'fs'
import Server from '../server' import Server from '../server'
import { printAndExit } from '../lib/utils' import { printAndExit } from '../lib/utils'
...@@ -65,9 +65,14 @@ srv.start(argv.port, argv.hostname) ...@@ -65,9 +65,14 @@ srv.start(argv.port, argv.hostname)
const pkgAppPath = require('find-up').sync('package.json', { const pkgAppPath = require('find-up').sync('package.json', {
cwd: dir cwd: dir
}) })
const appPackage = JSON.parse(readFileSync(pkgAppPath, 'utf8')) const appPackage = require(pkgAppPath)
const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next') if (appPackage.scripts) {
if (nextScript) errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p <some other port>\`.` const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next')
if (nextScript) {
errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p <some other port>\`.`
}
}
console.error(errorMessage) console.error(errorMessage)
} else { } else {
console.error(err) console.error(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment