Skip to content

Commit

Permalink
fix(gatsby-dev-cli): resolve correct versions of packages with unpkg (#…
Browse files Browse the repository at this point in the history
…33551)

* fix(gatsby-dev-cli): resolve correct versions of packages with unpkg

* a bit more details in case of errors

* defaults for deps
  • Loading branch information
vladar committed Oct 18, 2021
1 parent 5110074 commit 31d5a5e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/gatsby-dev-cli/src/utils/check-deps-changes.js
Expand Up @@ -60,16 +60,16 @@ exports.checkDepsChanges = async ({
// this allow us to not publish to local repository
// and save some time/work
try {
const response = await got(
`https://unpkg.com/${packageName}/package.json`
)
const version = getPackageVersion(packageName)
const url = `https://unpkg.com/${packageName}@${version}/package.json`
const response = await got(url)
if (response?.statusCode !== 200) {
throw new Error(`No response or non 200 code`)
throw new Error(`No response or non 200 code for ${url}`)
}
localPKGjson = JSON.parse(response.body)
} catch {
} catch (e) {
console.log(
`'${packageName}' doesn't seem to be installed and is not published on NPM.`
`'${packageName}' doesn't seem to be installed and is not published on NPM. Error: ${e.message}`
)
return {
didDepsChanged: true,
Expand Down Expand Up @@ -182,3 +182,12 @@ exports.checkDepsChanges = async ({
packageNotInstalled,
}
}

function getPackageVersion(packageName) {
const projectPackageJson = JSON.parse(
fs.readFileSync(`./package.json`, `utf-8`)
)
const { dependencies = {}, devDependencies = {} } = projectPackageJson
const version = dependencies[packageName] || devDependencies[packageName]
return version || `latest`
}

0 comments on commit 31d5a5e

Please sign in to comment.