Skip to content

Commit

Permalink
[v2] Misc fixes necessary to get gatsbyjs.org (mostly) working (#3975)
Browse files Browse the repository at this point in the history
* WIP

* webpack 3 is much more strict about not mixing es6 and commonjs

* Update gatsby-plugin-glamor for babel 7 + add @babel/preset-flow

* Add uglifyjs-webpack-plugin as a dependency so we're getting the latest version w/ es6 support

* MISC

* Change reference page queries to not rely on path info being in the ID

* Switch to using pageContext instead of pathContext

* Ignore the compiled index.js file

* Update peerDependencies for gatsby v2

* Update yarn.lock

* Add peerDependencies to gatsby-link

* Remove test code

* Update gatsby-link dependency

* Fix some tests
  • Loading branch information
KyleAMathews authored Feb 15, 2018
1 parent 52d893f commit 6ab8487
Show file tree
Hide file tree
Showing 60 changed files with 401 additions and 177 deletions.
1 change: 1 addition & 0 deletions Breaking Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Remove postcss plugins (cssnext, cssimport) from default css loader config
* change webpack api
* Source & transformer plugins now use UUIDs for ids. If you used glob or regex to query nodes by id then you'll need to query something else.
* Mixed commonjs/es6 modules fail
1 change: 0 additions & 1 deletion packages/babel-plugin-remove-graphql-queries/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/*.js
!index.js
yarn.lock
11 changes: 4 additions & 7 deletions packages/babel-plugin-remove-graphql-queries/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,19 @@ function getGraphQLTag(path) {
}
}

function BabelPluginRemoveGraphQLQueries({ types: t }) {
export default function({ types: t }) {
return {
visitor: {
TaggedTemplateExpression(path, state) {
const ast = getGraphQLTag(path)

if (!ast) return null

return path.replaceWith(
t.StringLiteral(`** extracted graphql fragment **`)
)
path.replaceWith(t.StringLiteral(`** extracted graphql fragment **`))
return null
},
},
}
}

BabelPluginRemoveGraphQLQueries.getGraphQLTag = getGraphQLTag

module.exports = BabelPluginRemoveGraphQLQueries
export { getGraphQLTag }
5 changes: 4 additions & 1 deletion packages/gatsby-link/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-link",
"version": "1.6.34",
"version": "1.6.36",
"description": "An enhanced Link component for Gatsby sites with support for resource prefetching",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -25,5 +25,8 @@
"@babel/runtime": "^7.0.0-beta.38",
"prop-types": "^15.5.8",
"ric": "^1.3.0"
},
"peerDependencies": {
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-canonical-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"@babel/runtime": "^7.0.0-beta.38"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-catch-links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"@babel/runtime": "^7.0.0-beta.38"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"rss": "^1.2.2"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-glamor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"peerDependencies": {
"glamor": "^2.20.29",
"gatsby": "^1.0.0"
"gatsby": ">2.0.0-alpha"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.38",
Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby-plugin-glamor/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ exports.modifyWebpackConfig = ({ actions, plugins }) =>

// Add Glamor support
exports.modifyBabelrc = ({ babelrc }) => {
const clonedPresets = [...babelrc.presets]
clonedPresets.find(pre =>
/babel\/preset-react/.test(pre[0])
)[1].pragma = `Glamor.createElement`

return {
...babelrc,
presets: clonedPresets,
plugins: babelrc.plugins.concat([
[`transform-react-jsx`, { pragma: `Glamor.createElement` }],
`glamor/babel-hoist`,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"@babel/runtime": "^7.0.0-beta.38"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-lodash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"cross-env": "^5.0.5"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-manifest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-plugin-manifest",
"version": "1.0.13",
"version": "2.0.0",
"description": "Gatsby plugin which adds a manifest.json to make sites progressive web apps",
"main": "index.js",
"scripts": {
Expand All @@ -27,6 +27,6 @@
"bluebird": "^3.5.0"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-manifest/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { withPrefix } from "gatsby-link"
import { withPrefix } from "gatsby"

exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
setHeadComponents([
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"cross-env": "^5.0.5"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-nprogress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"nprogress": "^0.2.0"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-offline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"sw-precache": "^5.0.0"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-react-helmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@babel/runtime": "^7.0.0-beta.38"
},
"peerDependencies": {
"gatsby": "^1.0.0",
"gatsby": ">1.9.0 || >2.0.0-alpha",
"react-helmet": ">=5.1.3"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"cross-env": "^5.0.5"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
},
"keywords": [
"gatsby",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"sitemap": "^1.12.0"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-twitter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"@babel/runtime": "^7.0.0-beta.38"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-typography/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"cross-env": "^5.0.5"
},
"peerDependencies": {
"gatsby": "^1.0.0"
"gatsby": ">1.0.0 || >2.0.0-alpha"
}
}
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/__tests__/find-page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const pageFinderFactory = require(`../find-page`)
const pageFinderFactory = require(`../find-page`).default

let findPage

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/develop-static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ try {

Html = Html && Html.__esModule ? Html.default : Html

module.exports = (locals, callback) => {
export default (locals, callback) => {
// const apiRunner = require(`${directory}/.cache/api-runner-ssr`)
let headComponents = []
let htmlAttributes = {}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/find-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import stripPrefix from "./strip-prefix"

const pageCache = {}

module.exports = (pages, pathPrefix = ``) => rawPathname => {
export default (pages, pathPrefix = ``) => rawPathname => {
let pathname = decodeURIComponent(rawPathname)

// Remove the pathPrefix from the pathname.
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { apiRunner } from "./api-runner-browser"
const pluginResponses = apiRunner(`replaceHistory`)
const replacementHistory = pluginResponses[0]
const history = replacementHistory || createHistory()
module.exports = history
export default history
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getLayout = page => {

const createElement = React.createElement

module.exports = (locals, callback) => {
export default (locals, callback) => {
let pathPrefix = `/`
if (__PREFIX_PATHS__) {
pathPrefix = `${__PATH_PREFIX__}/`
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"front-matter": "^2.1.0",
"fs-extra": "^5.0.0",
"gatsby-cli": "^1.1.28",
"gatsby-link": "^1.6.36",
"gatsby-module-loader": "^2.0.0-alpha.1",
"gatsby-react-router-scroll": "^1.0.8",
"glob": "^7.1.1",
Expand Down Expand Up @@ -104,6 +105,7 @@
"string-similarity": "^1.2.0",
"style-loader": "^0.19.1",
"type-of": "^2.0.1",
"uglifyjs-webpack-plugin": "^1.1.8",
"url-loader": "^0.5.7",
"uuid": "^3.1.0",
"v8-compile-cache": "^1.1.0",
Expand Down Expand Up @@ -143,7 +145,7 @@
"website"
],
"license": "MIT",
"main": "index.js",
"main": "dist/browser.js",
"peerDependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ Array [
Object {
"id": "Plugin query-runner",
"name": "query-runner",
"nodeAPIs": Array [],
"nodeAPIs": Array [
"onCreatePage",
"onCreateLayout",
],
"pluginOptions": Object {
"plugins": Array [],
},
Expand Down Expand Up @@ -160,7 +163,10 @@ Array [
Object {
"id": "Plugin query-runner",
"name": "query-runner",
"nodeAPIs": Array [],
"nodeAPIs": Array [
"onCreatePage",
"onCreateLayout",
],
"pluginOptions": Object {
"plugins": Array [],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const crypto = require(`crypto`)
const del = require(`del`)

const apiRunnerNode = require(`../utils/api-runner-node`)
const testRequireError = require(`../utils/test-require-error`)
const testRequireError = require(`../utils/test-require-error`).default
const { graphql } = require(`graphql`)
const { store, emitter } = require(`../redux`)
const loadPlugins = require(`./load-plugins`)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const glob = require(`glob`)

const { store } = require(`../redux`)
const nodeAPIs = require(`../utils/api-node-docs`)
const testRequireError = require(`../utils/test-require-error`)
const testRequireError = require(`../utils/test-require-error`).default
const report = require(`gatsby-cli/lib/reporter`)

function createFileContentHash(root, globPattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const crypto = require(`crypto`)
// Traverse is a es6 module...
import traverse from "babel-traverse"
const babylon = require(`babylon`)
const { getGraphQLTag } = require(`babel-plugin-remove-graphql-queries`)
const getGraphQLTag = require(`babel-plugin-remove-graphql-queries`)
.getGraphQLTag
const report = require(`gatsby-cli/lib/reporter`)

import type { DocumentNode, DefinitionNode } from "graphql"
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/__tests__/test-require-error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const testRequireError = require(`../test-require-error`)
const testRequireError = require(`../test-require-error`).default

describe(`test-require-error`, () => {
it(`detects require errors`, () => {
Expand Down
16 changes: 12 additions & 4 deletions packages/gatsby/src/utils/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ module.exports = async function babelConfig(program, stage) {
loose: true,
modules: false,
useBuiltIns: `usage`,
sourceType: `unambiguous`,
shippedProposals: true, // includes async/await and Object spread/rest
targets: { browsers: program.browserslist },
},
],
`@babel/react`,
[
require.resolve(`@babel/preset-react`),
{
pragma: `React.createElement`,
},
],
require.resolve(`@babel/preset-flow`),
],
plugins: [
require.resolve(`@babel/plugin-proposal-class-properties`),
Expand All @@ -96,9 +103,10 @@ module.exports = async function babelConfig(program, stage) {
if (stage === `develop`) {
// TODO: maybe this should be left to the user?
babelrc.plugins.unshift(require.resolve(`react-hot-loader/babel`))
babelrc.plugins.unshift(
require.resolve(`@babel/transform-react-jsx-source`)
)
// TODO figure out what this was — if left in it breaks builds
// babelrc.plugins.unshift(
// require.resolve(`@babel/transform-react-jsx-source`)
// )
}

babelrc.plugins.unshift(
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/test-require-error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This module is also copied into the .cache directory some modules copied there
// from cache-dir can also use this module.
module.exports = (moduleName, err) => {
export default (moduleName, err) => {
const regex = new RegExp(`Error: Cannot find module\\s.${moduleName}`)
const firstLine = err.toString().split(`\n`)[0]
return regex.test(firstLine)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/webpack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ module.exports = async ({
compress: {
drop_console: true,
},
ecma: 8,
ie8: false,
...uglifyOptions,
},
Expand Down
Loading

0 comments on commit 6ab8487

Please sign in to comment.