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) (#33570)

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

* a bit more details in case of errors

* defaults for deps

(cherry picked from commit 31d5a5e)

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
  • Loading branch information
GatsbyJS Bot and vladar authored Oct 18, 2021
1 parent a3a1cb9 commit 016bab7
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
Original file line number Diff line number Diff line change
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 016bab7

Please sign in to comment.