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): fix "expected manifest" errors #23871

Merged
merged 3 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions packages/gatsby-dev-cli/src/local-npm-registry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ exports.publishPackagesLocallyAndInstall = async ({

const versionPostFix = Date.now()

const newlyPublishedPackageVersions = {}

for (let packageName of packagesToPublish) {
await publishPackage({
newlyPublishedPackageVersions[packageName] = await publishPackage({
packageName,
packagesToPublish,
root,
Expand All @@ -65,5 +67,9 @@ exports.publishPackagesLocallyAndInstall = async ({

const packagesToInstall = _.intersection(packagesToPublish, localPackages)

await installPackages({ packagesToInstall, yarnWorkspaceRoot })
await installPackages({
packagesToInstall,
yarnWorkspaceRoot,
newlyPublishedPackageVersions,
})
}
12 changes: 10 additions & 2 deletions packages/gatsby-dev-cli/src/local-npm-registry/install-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ const fs = require(`fs-extra`)
const { promisifiedSpawn } = require(`../utils/promisified-spawn`)
const { registryUrl } = require(`./verdaccio-config`)

const installPackages = async ({ packagesToInstall, yarnWorkspaceRoot }) => {
const installPackages = async ({
packagesToInstall,
yarnWorkspaceRoot,
newlyPublishedPackageVersions,
}) => {
console.log(
`Installing packages from local registry:\n${packagesToInstall
.map(packageAndVersion => ` - ${packageAndVersion}`)
Expand Down Expand Up @@ -71,7 +75,10 @@ const installPackages = async ({ packagesToInstall, yarnWorkspaceRoot }) => {
`yarn`,
[
`add`,
...packagesToInstall.map(packageName => `${packageName}@gatsby-dev`),
...packagesToInstall.map(packageName => {
const packageVersion = newlyPublishedPackageVersions[packageName]
return `${packageName}@${packageVersion}`
}),
`--registry=${registryUrl}`,
`--exact`,
],
Expand All @@ -84,6 +91,7 @@ const installPackages = async ({ packagesToInstall, yarnWorkspaceRoot }) => {
console.log(`Installation complete`)
} catch (error) {
console.error(`Installation failed`, error)
process.exit(1)
}
}

Expand Down
18 changes: 16 additions & 2 deletions packages/gatsby-dev-cli/src/local-npm-registry/publish-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const adjustPackageJson = ({
versionPostFix,
packagesToPublish,
ignorePackageJSONChanges,
root,
}) => {
// we need to check if package depend on any other package to will be published and
// adjust version selector to point to dev version of package so local registry is used
Expand All @@ -44,8 +45,19 @@ const adjustPackageJson = ({
monorepoPKGjson.dependencies &&
monorepoPKGjson.dependencies[packageThatWillBePublished]
) {
// change to "gatsby-dev" dist tag
monorepoPKGjson.dependencies[packageThatWillBePublished] = `gatsby-dev`
const currentVersion = JSON.parse(
fs.readFileSync(
getMonorepoPackageJsonPath({
packageName: packageThatWillBePublished,
root,
}),
`utf-8`
)
).version

monorepoPKGjson.dependencies[
packageThatWillBePublished
] = `${currentVersion}-dev-${versionPostFix}`
}
})

Expand Down Expand Up @@ -133,6 +145,8 @@ const publishPackage = async ({

uncreateTemporaryNPMRC()
unadjustPackageJson()

return newPackageVersion
}

exports.publishPackage = publishPackage
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const verdaccioConfig = {
uplinks: {
npmjs: {
url: `https://registry.npmjs.org/`,
// default is 2 max_fails - on flaky networks that cause a lot of failed installations
max_fails: 10,
},
},
}
Expand Down
9 changes: 9 additions & 0 deletions packages/gatsby-dev-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ async function watch(
let allCopies = []
const packagesToPublish = new Set()
let isInitialScan = true
let isPublishing = false

const waitFor = new Set()
let anyPackageNotInstalled = false
Expand Down Expand Up @@ -211,6 +212,12 @@ async function watch(
)

if (relativePackageFile === `package.json`) {
// package.json files will change during publish to adjust version of package (and dependencies), so ignore
// changes during this process
if (isPublishing) {
return
}

// Compare dependencies with local version

const didDepsChangedPromise = checkDepsChanges({
Expand Down Expand Up @@ -292,13 +299,15 @@ async function watch(
if (isInitialScan) {
isInitialScan = false
if (packagesToPublish.size > 0) {
isPublishing = true
await publishPackagesLocallyAndInstall({
packagesToPublish: Array.from(packagesToPublish),
root,
localPackages,
ignorePackageJSONChanges,
})
packagesToPublish.clear()
isPublishing = false
} else if (anyPackageNotInstalled) {
// run `yarn`
const yarnInstallCmd = [`yarn`]
Expand Down