Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-dev-cli): Correctly catch 404s from NPM when a package hasn't been published yet #28297

Merged
merged 2 commits into from
Nov 26, 2020

Conversation

KyleAMathews
Copy link
Contributor

Can't use gatsby-dev-cli with new package otherwise

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 25, 2020
Comment on lines 64 to 70
got(`https://unpkg.com/${packageName}/package.json`)
.then((error, response) => {
if (response && response.statusCode === 200) {
return resolve(JSON.parse(response.body))
resolve(JSON.parse(response.body))
}

return reject(error)
}
)
})
.catch(e => reject(e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.then handler can only have single argument - so this should be:

got(`https://unpkg.com/${packageName}/package.json`)
  .then(response => {
    if (response && response.statusCode === 200) {
      return resolve(JSON.parse(response.body))
    }

    return reject(new Error(`No response or non 200 code`))
  })
  .catch(e => reject(e))

Seems like migration in #26653 was never actually tested?

Copy link
Contributor

@pvdz pvdz Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering this is inside an async function the whole new Promise expression should be replaced with something like

const response = await got(`https://unpkg.com/${packageName}/package.json`)
if (response?.statusCode !== 200) {
  throw new Error(`No response or non 200 code`)
}
localPKGjson = JSON.parse(response.body)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unless got does not return a proper promise-like?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, you are probably right and await will simplify things - I mostly zoomed in on double args for .then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like migration in #26653 was never actually tested?

Yeah — this isn't a common scenario.

Will change to await 👍

Co-authored-by: Peter van der Zee <209817+pvdz@users.noreply.github.com>
@LekoArts LekoArts added topic: dev tooling and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Nov 26, 2020
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@pieh pieh added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Nov 26, 2020
@gatsbybot gatsbybot merged commit c993d52 into master Nov 26, 2020
@delete-merged-branch delete-merged-branch bot deleted the dev-cli-fix branch November 26, 2020 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants