Skip to content

Commit

Permalink
Add warning to users if it looks like they have run npm start wrongly
Browse files Browse the repository at this point in the history
We want to catch what we suspect will be a common case, where the user
runs `npm start` having been used to that from before, and then ends up
with a prototype that isn't working and no idea why. In those
circumstances we should give the users a heads-up by outputting
something to the terminal. While we can't be certain of when this might
have happened, we can make a reasonable guess, and the downside of
logging to a hosting services console erroneously is negligible.
  • Loading branch information
lfdebrux committed Sep 30, 2022
1 parent 7797862 commit cb6a4e7
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,27 @@ const getChosenKitDependency = () => {
}
}
return defaultValue
};
}

// do some heuristics to try and catch situations where a user has run
// `npm start` (the wrong command) locally and warn them.
function warnIfNpmStart (argv, env) {
if (
argv.command === 'start' && // if user ran serve script then assume they know what they want
env.NODE_ENV !== 'production' && // some hosting services set NODE_ENV
env.PORT === undefined && // some hosting services set PORT
env.PASSWORD === undefined // user should have set PASSWORD when setting up hosting
) {
console.warn('Warning: It looks like you may have run the command `npm start` locally')
console.warn('if you are using the kit on a personal machine you should use `npm run dev`')
console.warn()
console.warn('If you are seeing this warning in production, it may indicate that your')
console.warn('hosting service needs further configuration.')
console.warn()
}
}

(async () => {
;(async () => {
if (argv.command === 'create') {
// Install as a two-stage bootstrap process.
//
Expand Down Expand Up @@ -168,6 +186,7 @@ const getChosenKitDependency = () => {
} else if (argv.command === 'dev') {
require('../start')
} else if (argv.command === 'start' || argv.command === 'serve') {
warnIfNpmStart(argv, process.env)
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
generateAssetsSync()
require('../listen-on-port')
Expand Down

0 comments on commit cb6a4e7

Please sign in to comment.