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

[1.0] During bootstrap, detect if plugins have changed and delete the cache #927

Merged
merged 8 commits into from
May 6, 2017
Next Next commit
Run format
  • Loading branch information
KyleAMathews committed May 5, 2017
commit 66a21bd5e956e5002ee8b82ec62b032742b1444c
9 changes: 6 additions & 3 deletions examples/using-drupal/src/templates/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class ArticleTemplate extends React.Component {
body = article.body.value

// Split text on new lnes and put into paragraph elements.
paragraphedBody = body.split(`\n`).map(split => {
return `<p>${split}</p>`
}).join(``)
paragraphedBody = body
.split(`\n`)
.map(split => {
return `<p>${split}</p>`
})
.join(``)
}
return (
<div>
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-dev-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const argv = require(`yargs`)
You typically only need to configure this once.`
)
.help(`h`)
.alias(`h`, `help`).array(`packages`).argv
.alias(`h`, `help`)
.array(`packages`).argv

const conf = new Configstore(pkg.name)

Expand Down
43 changes: 23 additions & 20 deletions packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ async function responsiveSizes({ file, args = {} }) {
const fallbackSrc = _.minBy(images, image =>
Math.abs(options.maxWidth - image.width)
).src
const srcSet = images.map(image => `${image.src} ${Math.round(image.width)}w`)
const srcSet = images
.map(image => `${image.src} ${Math.round(image.width)}w`)
.join(`,\n`)

return {
Expand Down Expand Up @@ -405,25 +406,27 @@ async function responsiveResolution({ file, args = {} }) {
const base64Image = await base64({ file })

const fallbackSrc = images[0].src
const srcSet = images.map((image, i) => {
let resolution
switch (i) {
case 0:
resolution = `1x`
break
case 1:
resolution = `1.5x`
break
case 2:
resolution = `2x`
break
case 3:
resolution = `3x`
break
default:
}
return `${image.src} ${resolution}`
}).join(`,`)
const srcSet = images
.map((image, i) => {
let resolution
switch (i) {
case 0:
resolution = `1x`
break
case 1:
resolution = `1.5x`
break
case 2:
resolution = `2x`
break
case 3:
resolution = `3x`
break
default:
}
return `${image.src} ${resolution}`
})
.join(`,`)

return {
base64: base64Image.src,
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-remark-copy-linked-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module.exports = ({ files, markdownNode, markdownAST, getNode }) => {
`public`,
`${linkNode.contentDigest}.${linkNode.extension}`
)
const relativePath = path.join(`/${linkNode.contentDigest}.${linkNode.extension}`)
const relativePath = path.join(
`/${linkNode.contentDigest}.${linkNode.extension}`
)
link.url = `${relativePath}`
if (!fsExtra.existsSync(newPath)) {
fsExtra.copy(linkPath, newPath, err => {
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-remark-responsive-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ module.exports = ({
const fallbackSrc = _.minBy(images, image =>
Math.abs(options.maxWidth - image.width)
).src
const srcSet = images.map(
image => `${image.src} ${Math.round(image.width)}w`
).join(`,`)
const srcSet = images
.map(image => `${image.src} ${Math.round(image.width)}w`)
.join(`,`)

// TODO
// add support for sub-plugins having a gatsby-node.js so can add a
Expand Down
6 changes: 4 additions & 2 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ exports.sourceNodes = async (
// Get content digest of node.
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(gatsbyNode)).digest(`hex`)
.update(JSON.stringify(gatsbyNode))
.digest(`hex`)

gatsbyNode.contentDigest = contentDigest

Expand Down Expand Up @@ -145,7 +146,8 @@ exports.sourceNodes = async (
// Get content digest of node.
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(gatsbyUser)).digest(`hex`)
.update(JSON.stringify(gatsbyUser))
.digest(`hex`)

gatsbyUser.contentDigest = contentDigest

Expand Down
15 changes: 11 additions & 4 deletions packages/gatsby-source-hacker-news/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const url = require(`url`)
const _ = require(`lodash`)

const get = query => {
return axios.get(`https://www.graphqlhub.com/graphql?query=${encodeURIComponent(query)}`)
return axios.get(
`https://www.graphqlhub.com/graphql?query=${encodeURIComponent(query)}`
)
}

exports.sourceNodes = async ({
Expand All @@ -20,7 +22,9 @@ exports.sourceNodes = async ({

// Do the initial fetch
console.time(`fetch HN data`)
console.log(`starting to fetch data from the Hacker News GraphQL API. Warning, this can take a long time e.g. 10-20 seconds`)
console.log(
`starting to fetch data from the Hacker News GraphQL API. Warning, this can take a long time e.g. 10-20 seconds`
)
const result = await get(`
{
hn {
Expand Down Expand Up @@ -114,7 +118,8 @@ fragment commentsFragment on HackerNewsItem {
// Get content digest of node.
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(storyNode)).digest(`hex`)
.update(JSON.stringify(storyNode))
.digest(`hex`)

storyNode.contentDigest = contentDigest

Expand All @@ -139,7 +144,9 @@ fragment commentsFragment on HackerNewsItem {
const nodeStr = JSON.stringify(commentNode)

// Get content digest of comment node.
const contentDigest = crypto.createHash(`md5`).update(nodeStr)
const contentDigest = crypto
.createHash(`md5`)
.update(nodeStr)
.digest(`hex`)

commentNode.contentDigest = contentDigest
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-transformer-remark/src/on-node-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = async function onNodeCreate({

const content = await loadNodeContent(node)
const data = grayMatter(content)
const contentDigest = crypto.createHash(`md5`).update(JSON.stringify(data))
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(data))
.digest(`hex`)
const markdownNode = {
id: `${node.id} >>> MarkdownRemark`,
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby/lib/query-runner/file-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ export default class FileParser {
const text = await readFileAsync(file, `utf8`)

if (text.indexOf(`graphql`) === -1) return
const hash = crypto.createHash(`md5`).update(file).update(text)
const hash = crypto
.createHash(`md5`)
.update(file)
.update(text)
.digest(`hex`)

let astDefinitions =
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby/lib/query-runner/query-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class Runner {

let text = filterContextForNode(printContext.getRoot(name), printContext)
.documents()
.map(QueryPrinter.print).join(`\n`)
.map(QueryPrinter.print)
.join(`\n`)

compiledNodes.set(filePath, {
name,
Expand Down
8 changes: 5 additions & 3 deletions packages/gatsby/lib/query-runner/route-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ const writeChildRoutes = () => {
// Close out object.
rootRoute += `]}`
splitRootRoute += `]}`
const componentsStr = pages.map(page => {
return `class ${page.internalComponentName} extends React.Component {
const componentsStr = pages
.map(page => {
return `class ${page.internalComponentName} extends React.Component {
render () {
const Component = preferDefault(require('${page.component}'))
const data = require('./json/${page.jsonName}')
return <Component {...this.props} {...data} />
}
}`
}).join(`\n`)
})
.join(`\n`)

childRoutes = `
import React from 'react'
Expand Down
10 changes: 6 additions & 4 deletions packages/gatsby/lib/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ actions.upsertPage = (page, plugin = ``) => {
actions.updateNode = (node, plugin = ``) => {
if (!_.isObject(node)) {
return console.log(
chalk.bold
.red(`The node passed to the "updateNode" action creator must be an object`)
chalk.bold.red(
`The node passed to the "updateNode" action creator must be an object`
)
)
}
const result = Joi.validate(node, joiSchemas.nodeSchema)
Expand Down Expand Up @@ -93,8 +94,9 @@ actions.touchNode = (nodeId, plugin = ``) => {
actions.createNode = (node, plugin = ``) => {
if (!_.isObject(node)) {
return console.log(
chalk.bold
.red(`The node passed to the "createNode" action creator must be an object`)
chalk.bold.red(
`The node passed to the "createNode" action creator must be an object`
)
)
}
const result = Joi.validate(node, joiSchemas.nodeSchema)
Expand Down
8 changes: 6 additions & 2 deletions packages/gatsby/lib/utils/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ async function startServer(program) {
if (e) {
if (e.code === `EADDRINUSE`) {
// eslint-disable-next-line max-len
console.log(`Unable to start Gatsby on port ${program.port} as there's already a process listing on that port.`)
console.log(
`Unable to start Gatsby on port ${program.port} as there's already a process listing on that port.`
)
} else {
console.log(e)
}
Expand All @@ -147,7 +149,9 @@ async function startServer(program) {
const opn = require(`opn`)
opn(`http://${listener.address().address}:${listener.address().port}`)
}
console.log(`Listening at: http://${listener.address().address}:${listener.address().port}`)
console.log(
`Listening at: http://${listener.address().address}:${listener.address().port}`
)
}
})
})
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/lib/utils/serve-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function startServer(program, launchPort) {
if (e) {
if (e.code === `EADDRINUSE`) {
// eslint-disable-next-line max-len
console.log(`Unable to start Gatsby on port ${serverPort} as there's already a process listing on that port.`)
console.log(
`Unable to start Gatsby on port ${serverPort} as there's already a process listing on that port.`
)
} else {
console.log(e)
}
Expand Down
4 changes: 3 additions & 1 deletion www/src/templates/template-blog-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const BlogPostTemplate = React.createClass({
const twitterLine = post.frontmatter.author.twitter
? ` by ${post.frontmatter.author.twitter}`
: ``
const authorShareText = encodeURIComponent(`“${post.frontmatter.title}”${twitterLine} https://sourceforge.com/blog${post.fileSlug}`)
const authorShareText = encodeURIComponent(
`“${post.frontmatter.title}”${twitterLine} https://sourceforge.com/blog${post.fileSlug}`
)
const BioLine = ({ children }) => (
<p
css={{
Expand Down