8000 fix: print error on init when cannot find a package.json (#181) · sezna/nps@e52b136 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit e52b136

Browse files
HypercubedKent C. Dodds
authored andcommitted
fix: print error on init when cannot find a package.json (#181)
1 parent 8f8c25c commit e52b136

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/bin-utils/initialize/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ const CORE_SCRIPTS = [
6060
function initialize(configType = 'js') {
6161
/* eslint global-require:0,import/no-dynamic-require:0 */
6262
const packageJsonPath = findUpSync('package.json')
63+
if (packageJsonPath === null) {
64+
return
65+
}
6366
const packageJson = require(packageJsonPath)
6467
const {scripts = {}} = packageJson
6568
packageJson.scripts = getCoreScripts(packageJson.scripts)

src/bin-utils/parser.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ function parse(rawArgv) {
185185
return
186186
}
187187
}
188-
const {packageScriptsPath} = initialize(initArgv.type)
188+
const init = initialize(initArgv.type)
189+
if (!packageScriptsPath) {
190+
log.error(chalk.red('Unable to to find an existing package.json'))
191+
return
192+
}
193+
const packageScriptsPath = init.packageScriptsPath
189194
log.info(
190195
`Your scripts have been saved at ${chalk.green(packageScriptsPath)}`,
191196
)

0 commit comments

Comments
 (0)
0