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): resolve correct versions of packages with unpkg #33551

Merged
merged 3 commits into from
Oct 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`
Copy link
Contributor

Choose a reason for hiding this comment

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

monorepoPKGjson.version = `${monorepoPKGjson.version}-dev-${versionPostFix}`

gatsby-dev might set to some version available only locally, so this unpkg would likely fail for those and fallback to using verdaccio which is fine I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This codepath is only active a) for the initial scan b) when there are no local dependencies (so no node_modules). If you have deps already installed with verdaccio, we won't even try to check unpkg.

So I think it should be fine

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`
}