Skip to content

Commit

Permalink
fix(setup): fail gracefully when package.json cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jun 5, 2017
1 parent 770619e commit 7dd3e37
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bin/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ var isInstallIntoApp = /node_modules/.test(process.cwd())
// This block only executes if Hoodie is installed with as a dependency
if (isInstallIntoApp) {
var pathToAppRoot = path.resolve('..', '..')
var packageJson = require(path.join(pathToAppRoot, 'package.json'))

// log warning if package.json cannot be found (hoodiehq/hoodie#751)
try {
var packageJson = require(path.join(pathToAppRoot, 'package.json'))
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
throw error
}
log.warn('setup', 'Could not find package.json at ' + path.join(pathToAppRoot, 'package.json'))
log.warn('setup', 'You must manually set the start script in your app’s package.json to "hoodie" in order for "npm start" to work')

process.exit(0)
}

packageJson.scripts = packageJson.scripts || {}

Expand Down

0 comments on commit 7dd3e37

Please sign in to comment.