Skip to content

Commit

Permalink
fix(gatsby-dev-cli): add missing awaits and other various fixes (gats…
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored Jun 4, 2019
1 parent af9fae3 commit a2c55a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-dev-cli/src/local-npm-registry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ exports.publishPackagesLocallyAndInstall = async ({

const packagesToInstall = _.intersection(packagesToPublish, localPackages)

installPackages({ packagesToInstall })
await installPackages({ packagesToInstall })
}
35 changes: 25 additions & 10 deletions packages/gatsby-dev-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const quit = () => {
process.exit()
}

const MAX_COPY_RETRIES = 3

/*
* non-existant packages break on('ready')
* See: https://github.com/paulmillr/chokidar/issues/449
Expand All @@ -29,18 +31,28 @@ function watch(
let afterPackageInstallation = false
let queuedCopies = []

const realCopyPath = ({ oldPath, newPath, quiet, resolve, reject }) => {
const realCopyPath = arg => {
const { oldPath, newPath, quiet, resolve, reject, retry = 0 } = arg
fs.copy(oldPath, newPath, err => {
if (err) {
console.error(err)
return reject(err)
if (retry >= MAX_COPY_RETRIES) {
console.error(err)
reject(err)
return
} else {
setTimeout(
() => realCopyPath({ ...arg, retry: retry + 1 }),
500 * Math.pow(2, retry)
)
return
}
}

numCopied += 1
if (!quiet) {
console.log(`Copied ${oldPath} to ${newPath}`)
}
return resolve()
resolve()
})
}

Expand Down Expand Up @@ -69,12 +81,14 @@ function watch(
}, new Set())

await Promise.all(
[...packagesToClear].map(async packageToClear => {
await del([
`node_modules/${packageToClear}/**/*.{js,js.map}`,
`!node_modules/${packageToClear}/node_modules/**/*.{js,js.map}`,
])
})
[...packagesToClear].map(
async packageToClear =>
await del([
`node_modules/${packageToClear}/**/*.{js,js.map}`,
`!node_modules/${packageToClear}/node_modules/**/*.{js,js.map}`,
`!node_modules/${packageToClear}/src/**/*.{js,js.map}`,
])
)
)
}
// check packages deps and if they depend on other packages from monorepo
Expand Down Expand Up @@ -113,6 +127,7 @@ function watch(
/\.git/i,
/\.DS_Store/,
/[/\\]__tests__[/\\]/i,
/\.npmrc/i,
].concat(
allPackagesToWatch.map(p => new RegExp(`${p}[\\/\\\\]src[\\/\\\\]`, `i`))
)
Expand Down

0 comments on commit a2c55a7

Please sign in to comment.