From ad3e3877e7384a8d40c666c27be590208f0725e2 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Wed, 12 Apr 2017 18:22:36 +0200 Subject: [PATCH 01/33] Add a note on windows installation --- docs/docs/gatsby-on-windows.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/docs/gatsby-on-windows.md b/docs/docs/gatsby-on-windows.md index 29c6e3e8cb1a4..1f7b1bdd4a005 100644 --- a/docs/docs/gatsby-on-windows.md +++ b/docs/docs/gatsby-on-windows.md @@ -16,3 +16,10 @@ powershell console. On installing this package, it downloads and installs the Visual C++ Build Tools 2015, provided free of charge by Microsoft. These tools are required to compile popular native modules. It will also install Python 2.7, configuring your machine and npm appropriately. + +## Installing dependencies without troubles. + +Even if you love using a pretty terminal as [hyper](https://hyper.is/) with a git bash, +for installing packages without build troubles, it's better to use **a powershell console** + +After `yarn` or `npm i`, you can go back on your favorite terminal :wink: and run `yarn develop` or `npm run develop`! \ No newline at end of file From 9834943608a1282fae83d02b86795ef3223114b5 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Wed, 12 Apr 2017 18:23:10 +0200 Subject: [PATCH 02/33] Add missing dependencies into gatsby-plugin-typescript doc --- packages/gatsby-plugin-typescript/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-typescript/README.md b/packages/gatsby-plugin-typescript/README.md index 4097f06ff68c6..00cce0c5e1e9e 100644 --- a/packages/gatsby-plugin-typescript/README.md +++ b/packages/gatsby-plugin-typescript/README.md @@ -2,7 +2,7 @@ Provides drop-in support for TypeScript and TSX. ## Install -`yarn add gatsby-plugin-typescript` +`yarn add gatsby-plugin-typescript ts-loader typescript` ## How to use 1. Include the plugin in your `gatsby-config.js` file. From e3c4245de89e164b70bb21f1dd073092595e5920 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Thu, 13 Apr 2017 10:51:01 +0200 Subject: [PATCH 03/33] Make HTMLPath configurable --- packages/gatsby/lib/joi-schemas/joi.js | 1 + packages/gatsby/lib/utils/develop.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/lib/joi-schemas/joi.js b/packages/gatsby/lib/joi-schemas/joi.js index 77c1bba4b453c..f11402c495a40 100644 --- a/packages/gatsby/lib/joi-schemas/joi.js +++ b/packages/gatsby/lib/joi-schemas/joi.js @@ -1,6 +1,7 @@ const Joi = require("joi") export const gatsbyConfigSchema = Joi.object().keys({ + htmlPath: Joi.string(), siteMetadata: Joi.object(), linkPrefix: Joi.string(), mapping: Joi.object(), diff --git a/packages/gatsby/lib/utils/develop.js b/packages/gatsby/lib/utils/develop.js index a3e60c2fec925..8aa3cbe96d1d8 100644 --- a/packages/gatsby/lib/utils/develop.js +++ b/packages/gatsby/lib/utils/develop.js @@ -40,10 +40,12 @@ async function startServer(program) { const devConfig = compilerConfig.resolve() const compiler = webpack(devConfig) - const HTMLPath = glob.sync(`${directory}/html.*`)[0] + const HTMLConfig = _.get(store.getState(), "config.htmlPath"); + const HTMLPath = glob.sync(directory + (HTMLConfig || "/html.*"))[0] // Check if we can't find an html component in root of site. if (!HTMLPath) { - throw new Error(`Couldn't find an html.js at the root of your site`) + if (HTMLConfig) throw new Error(`Your htmlPath config is incorrect (file not found)`) + else throw new Error(`Couldn't find an html.js at the root of your site`) } // We use the program port not the webpack-dev-server port as if you import From 1f999dd24c31a8b3f21a07f2c06c0001e2dca75e Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Thu, 13 Apr 2017 14:39:58 +0200 Subject: [PATCH 04/33] Fix dev-cli readme --- packages/gatsby-dev-cli/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-dev-cli/README.md b/packages/gatsby-dev-cli/README.md index d8d1951e9f21d..5a731efad7f10 100644 --- a/packages/gatsby-dev-cli/README.md +++ b/packages/gatsby-dev-cli/README.md @@ -9,7 +9,7 @@ It's a simple cli tool for have easily a functionnal development environment for Fork gatsby repo and clone it. ```bash -$ npm install -g gatsby-cli-tools@canary +$ npm install -g gatsby-dev-cli@canary $ gatsby-dev --set-path-to-repo /path/to/my/cloned/version/gatsby ``` From f45a455c50305d3408aba8d0918e27846902afa9 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Thu, 13 Apr 2017 18:44:18 +0200 Subject: [PATCH 05/33] Use redux to managed program.extensions --- packages/gatsby/lib/bootstrap/index.js | 8 ++++++-- packages/gatsby/lib/redux/reducers/program.js | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/lib/bootstrap/index.js b/packages/gatsby/lib/bootstrap/index.js index 49584002da48d..436573adefeba 100644 --- a/packages/gatsby/lib/bootstrap/index.js +++ b/packages/gatsby/lib/bootstrap/index.js @@ -44,6 +44,7 @@ const glob = Promise.promisify(globCB) const autoPathCreator = async (program: any) => { const pagesDirectory = path.posix.join(program.directory, `pages`) const exts = program.extensions.map(e => `*${e}`).join("|") + const exts = store.getState().program.extensions.map(e => `*${e}`).join("|") // The promisified version wasn't working for some reason // so we'll use sync for now. const files = glob.sync(`${pagesDirectory}/**/?(${exts})`) @@ -272,10 +273,13 @@ module.exports = async (program: any) => { } // Collect resolvable extensions and attach to program. - // TODO refactor this to use Redux. const extensions = [`.js`, `.jsx`] const apiResults = await apiRunnerNode("resolvableExtensions") - program.extensions = apiResults.reduce((a, b) => a.concat(b), extensions) + + store.dispatch({ + type: "SET_PROGRAM_EXTENSIONS", + payload: _.flattenDeep([extensions, apiResults]), + }) // Collect pages. await apiRunnerNode(`createPages`, { diff --git a/packages/gatsby/lib/redux/reducers/program.js b/packages/gatsby/lib/redux/reducers/program.js index fec90c169957b..5ae0cdd144686 100644 --- a/packages/gatsby/lib/redux/reducers/program.js +++ b/packages/gatsby/lib/redux/reducers/program.js @@ -5,6 +5,12 @@ module.exports = (state = { directory: `/` }, action) => { ...action.payload, }; + case "SET_PROGRAM_EXTENSIONS": + return { + ...state, + extensions: action.payload, + }; + default: return state; } From abb03514e7db92a94bc5a35471176c17da7ed830 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 11:47:14 +0200 Subject: [PATCH 06/33] Slashify all paths --- packages/gatsby/lib/bootstrap/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/lib/bootstrap/index.js b/packages/gatsby/lib/bootstrap/index.js index 436573adefeba..58cbb86121301 100644 --- a/packages/gatsby/lib/bootstrap/index.js +++ b/packages/gatsby/lib/bootstrap/index.js @@ -116,7 +116,7 @@ module.exports = async (program: any) => { // Also test adding to redux store. const processPlugin = plugin => { if (_.isString(plugin)) { - const resolvedPath = path.dirname(require.resolve(plugin)) + const resolvedPath = slash(path.dirname(require.resolve(plugin))) const packageJSON = JSON.parse( fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`) ) @@ -138,7 +138,7 @@ module.exports = async (program: any) => { } plugin.options.plugins = subplugins - const resolvedPath = path.dirname(require.resolve(plugin.resolve)) + const resolvedPath = slash(path.dirname(require.resolve(plugin.resolve))) const packageJSON = JSON.parse( fs.readFileSync(`${resolvedPath}/package.json`, `utf-8`) ) @@ -159,7 +159,7 @@ module.exports = async (program: any) => { // Add the site's default "plugin" i.e. gatsby-x files in root of site. plugins.push({ - resolve: process.cwd(), + resolve: slash(process.cwd()), name: `defaultSitePlugin`, version: `n/a`, pluginOptions: { From 3af80ea380aa8588f9cbda638519634a91d14e04 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 11:48:54 +0200 Subject: [PATCH 07/33] Fix relativePath and clean no-used var --- packages/gatsby-source-filesystem/src/gatsby-node.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 2d5e76455a939..2e5a2a7edcf11 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -1,14 +1,8 @@ -import Promise from "bluebird" -import mapLimit from "async/mapLimit" - const path = require("path") const md5File = require("md5-file") -const recursive = require("recursive-readdir") const fs = require("fs") const prettyBytes = require("pretty-bytes") -const u = require("unist-builder") const slash = require("slash") -const _ = require("lodash") const chokidar = require("chokidar") function readFile(file, pluginOptions, cb) { @@ -27,7 +21,7 @@ function readFile(file, pluginOptions, cb) { sourceName: pluginOptions.name, children: [], relativePath: slash( - path.posix.relative(pluginOptions.path, slashedFile.absolutePath) + path.relative(pluginOptions.path, slashedFile.absolutePath) ), extension: slashedFile.ext.slice(1).toLowerCase(), size: stats.size, @@ -52,7 +46,6 @@ exports.sourceNodes = ({ actionCreators }, pluginOptions) => { plugin: `source-filesystem --- ${pluginOptions.name}`, ready: false, }) - let testNode const watcher = chokidar.watch(pluginOptions.path, { ignored: [ `**/*.un~`, From 240f5da17514ac838c5fbbb6f3a9b7cbdfe278f8 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 14:01:07 +0200 Subject: [PATCH 08/33] Get program.extensions from redux --- packages/gatsby/lib/utils/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/lib/utils/webpack.config.js b/packages/gatsby/lib/utils/webpack.config.js index 7a7cd3a2b4743..37b3f6cdff675 100644 --- a/packages/gatsby/lib/utils/webpack.config.js +++ b/packages/gatsby/lib/utils/webpack.config.js @@ -271,7 +271,7 @@ module.exports = async ( function resolve() { return { // use the program's extension list (generated via the 'resolvableExtensions' API hook) - extensions: [``, ...program.extensions], + extensions: [``, ...store.getState().program.extensions], // Hierarchy of directories for Webpack to look for module. // First is the site directory. // Then in the special directory of isomorphic modules Gatsby ships with. From 72e706f5d2bab2eadb7115480c7236da0af74592 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 15:32:26 +0200 Subject: [PATCH 09/33] Add a rootPath config --- packages/gatsby/lib/joi-schemas/joi.js | 2 +- packages/gatsby/lib/utils/develop.js | 7 +++---- packages/gatsby/lib/utils/webpack.config.js | 9 +++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/gatsby/lib/joi-schemas/joi.js b/packages/gatsby/lib/joi-schemas/joi.js index f11402c495a40..a3beb88df9fe9 100644 --- a/packages/gatsby/lib/joi-schemas/joi.js +++ b/packages/gatsby/lib/joi-schemas/joi.js @@ -1,7 +1,7 @@ const Joi = require("joi") export const gatsbyConfigSchema = Joi.object().keys({ - htmlPath: Joi.string(), + rootPath: Joi.string(), siteMetadata: Joi.object(), linkPrefix: Joi.string(), mapping: Joi.object(), diff --git a/packages/gatsby/lib/utils/develop.js b/packages/gatsby/lib/utils/develop.js index 8aa3cbe96d1d8..9e6af0b119487 100644 --- a/packages/gatsby/lib/utils/develop.js +++ b/packages/gatsby/lib/utils/develop.js @@ -40,12 +40,11 @@ async function startServer(program) { const devConfig = compilerConfig.resolve() const compiler = webpack(devConfig) - const HTMLConfig = _.get(store.getState(), "config.htmlPath"); - const HTMLPath = glob.sync(directory + (HTMLConfig || "/html.*"))[0] + const rootPath = _.get(store.getState(), `config.rootPath`, `/`) + const HTMLPath = glob.sync(`${directory}${rootPath}html.*`)[0] // Check if we can't find an html component in root of site. if (!HTMLPath) { - if (HTMLConfig) throw new Error(`Your htmlPath config is incorrect (file not found)`) - else throw new Error(`Couldn't find an html.js at the root of your site`) + throw new Error(`Couldn't find an html.* at the root of your site`) } // We use the program port not the webpack-dev-server port as if you import diff --git a/packages/gatsby/lib/utils/webpack.config.js b/packages/gatsby/lib/utils/webpack.config.js index 37b3f6cdff675..9d40c37e67985 100644 --- a/packages/gatsby/lib/utils/webpack.config.js +++ b/packages/gatsby/lib/utils/webpack.config.js @@ -7,7 +7,7 @@ import ExtractTextPlugin from "extract-text-webpack-plugin" import StaticSiteGeneratorPlugin from "static-site-generator-webpack-plugin" import { StatsWriterPlugin } from "webpack-stats-plugin" // This isn't working right it seems. -//import WebpackStableModuleIdAndHash from 'webpack-stable-module-id-and-hash' +// import WebpackStableModuleIdAndHash from 'webpack-stable-module-id-and-hash' import webpackModifyValidate from "./webpack-modify-validate" @@ -100,7 +100,7 @@ module.exports = async ( } case `build-html`: return { - //main: `${__dirname}/static-entry`, + // main: `${__dirname}/static-entry`, main: `${directory}/.intermediate-representation/static-entry`, } case `build-javascript`: @@ -269,13 +269,14 @@ module.exports = async ( } function resolve() { + const rootPath = _.get(store.getState(), `config.rootPath`, `/`) return { // use the program's extension list (generated via the 'resolvableExtensions' API hook) extensions: [``, ...store.getState().program.extensions], // Hierarchy of directories for Webpack to look for module. // First is the site directory. // Then in the special directory of isomorphic modules Gatsby ships with. - root: [directory, path.resolve(__dirname, `..`, `isomorphic`)], + root: [path.join(directory, rootPath), path.resolve(__dirname, `..`, `isomorphic`)], modulesDirectories: [`${directory}/node_modules`, `node_modules`], } } @@ -417,7 +418,7 @@ module.exports = async ( config.loader(`css`, { test: /\.css$/, exclude: /\.module\.css$/, - //loader: `null`, + // loader: `null`, loader: ExtractTextPlugin.extract([`css`]), }) From d73cda5132047bf47c47050ac4118e91433bc8be Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 15:32:40 +0200 Subject: [PATCH 10/33] Some refactors --- packages/gatsby/lib/utils/api-runner-node.js | 5 +---- packages/gatsby/lib/utils/query-runner.js | 13 +++---------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/gatsby/lib/utils/api-runner-node.js b/packages/gatsby/lib/utils/api-runner-node.js index 87dc9d937ad05..e98b5f51b092c 100644 --- a/packages/gatsby/lib/utils/api-runner-node.js +++ b/packages/gatsby/lib/utils/api-runner-node.js @@ -51,13 +51,10 @@ module.exports = async (api, args = {}) => { if (!filteredPlugins) { filteredPlugins = plugins.filter(plugin => hasAPIFile(plugin)) } - mapSeries( filteredPlugins, (plugin, callback) => { - Promise.resolve(runAPI(plugin, api, args)).then(result => { - callback(null, result) - }) + Promise.resolve(runAPI(plugin, api, args)).asCallback(callback) }, (err, results) => { // Filter out empty responses and return diff --git a/packages/gatsby/lib/utils/query-runner.js b/packages/gatsby/lib/utils/query-runner.js index 8d80cb90da354..0d0d00d2999ff 100644 --- a/packages/gatsby/lib/utils/query-runner.js +++ b/packages/gatsby/lib/utils/query-runner.js @@ -14,7 +14,6 @@ import slash from "slash" import { layoutComponentChunkName, pathChunkName } from "./js-chunk-names" import { graphql as graphqlFunction } from "graphql" -let initialQueriesDone = false let invalidPages = [] store.subscribe(() => { @@ -378,12 +377,6 @@ const q = queue(async ({ file, graphql, directory }, callback) => { }) console.log(`running queries for ${paths.length} paths for ${file}`) - const pathsInfo = { - componentPath: absolutePath, - directory, - paths, - graphql, - } // Handle the result of the GraphQL query. const handleResult = (pathInfo, result = {}) => { @@ -448,15 +441,15 @@ module.exports = async drainCb => { if (_.isFunction(drainCb)) { realDrainCB = drainCb } - const schema = store.getState().schema + const { schema, program, pages } = store.getState() + const graphql = (query, context) => { return graphqlFunction(schema, query, context, context, context) } - const { program } = store.getState() // Get unique array of component paths and then watch them. // When a component is updated, rerun queries. - const components = _.uniq(store.getState().pages.map(page => page.component)) + const components = _.uniq(pages.map(page => page.component)) // If there's no components yet, return if (components.length === 0) { From 871d31c19106cc87bc0294e3ff2176006185b737 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 15:33:35 +0200 Subject: [PATCH 11/33] Run yarn format --- packages/gatsby/lib/redux/__tests__/nodes.js | 26 ++++----- packages/gatsby/lib/redux/__tests__/pages.js | 54 +++++++++---------- .../gatsby/lib/redux/__tests__/site-config.js | 20 +++---- .../__tests__/page-data-dependencies.js | 40 +++++++------- packages/gatsby/lib/redux/reducers/config.js | 24 ++++----- .../lib/redux/reducers/flattened-plugins.js | 6 +-- packages/gatsby/lib/redux/reducers/index.js | 2 +- .../gatsby/lib/redux/reducers/last-action.js | 4 +- packages/gatsby/lib/redux/reducers/nodes.js | 8 +-- .../redux/reducers/page-data-dependencies.js | 18 +++---- packages/gatsby/lib/redux/reducers/pages.js | 14 ++--- packages/gatsby/lib/redux/reducers/plugins.js | 6 +-- packages/gatsby/lib/redux/reducers/program.js | 8 +-- packages/gatsby/lib/redux/reducers/schema.js | 6 +-- packages/gatsby/lib/redux/reducers/status.js | 6 +-- .../schema/__tests__/data-tree-utils-test.js | 18 +++---- 16 files changed, 130 insertions(+), 130 deletions(-) diff --git a/packages/gatsby/lib/redux/__tests__/nodes.js b/packages/gatsby/lib/redux/__tests__/nodes.js index 1bc5656e0351c..e70ff8110cf35 100644 --- a/packages/gatsby/lib/redux/__tests__/nodes.js +++ b/packages/gatsby/lib/redux/__tests__/nodes.js @@ -1,5 +1,5 @@ -const { actions, boundActions } = require("../actions"); -const nodeReducer = require("../reducers/nodes"); +const { actions, boundActions } = require("../actions") +const nodeReducer = require("../reducers/nodes") describe(`Create and update nodes`, () => { // TODO add these back when we stop directly consoleing errors. @@ -23,24 +23,24 @@ describe(`Create and update nodes`, () => { id: `hi`, type: `Test`, pickle: true, - }); - expect(action).toMatchSnapshot(); - expect(nodeReducer(undefined, action)).toMatchSnapshot(); - }); + }) + expect(action).toMatchSnapshot() + expect(nodeReducer(undefined, action)).toMatchSnapshot() + }) it(`allows updating nodes`, () => { const action = actions.createNode({ id: `hi`, type: `Test`, pickle: true, - }); + }) const updateAction = actions.createNode({ id: `hi`, type: `Test`, pickle: false, - }); - let state = nodeReducer(undefined, action); - state = nodeReducer(state, updateAction); - expect(state["hi"].pickle).toEqual(false); - }); -}); + }) + let state = nodeReducer(undefined, action) + state = nodeReducer(state, updateAction) + expect(state["hi"].pickle).toEqual(false) + }) +}) diff --git a/packages/gatsby/lib/redux/__tests__/pages.js b/packages/gatsby/lib/redux/__tests__/pages.js index 76097c4b2028b..8bc6428e004a7 100644 --- a/packages/gatsby/lib/redux/__tests__/pages.js +++ b/packages/gatsby/lib/redux/__tests__/pages.js @@ -1,16 +1,16 @@ -const { store, reducer } = require("../index"); -const { actions, boundActions } = require("../actions"); +const { store, reducer } = require("../index") +const { actions, boundActions } = require("../actions") describe(`Add pages`, () => { it(`allows you to add pages`, () => { const action = actions.upsertPage({ path: `/hi/`, component: `/whatever/index.js`, - }); - const state = reducer({ pages: [] }, action); - expect(action).toMatchSnapshot(); - expect(state).toMatchSnapshot(); - }); + }) + const state = reducer({ pages: [] }, action) + expect(action).toMatchSnapshot() + expect(state).toMatchSnapshot() + }) it(`allows you to add pages with context`, () => { const action = actions.upsertPage({ @@ -19,42 +19,42 @@ describe(`Add pages`, () => { context: { id: 123, }, - }); - const state = reducer({ pages: [] }, action); - expect(action).toMatchSnapshot(); - expect(state).toMatchSnapshot(); - }); + }) + const state = reducer({ pages: [] }, action) + expect(action).toMatchSnapshot() + expect(state).toMatchSnapshot() + }) it(`allows you to add multiple pages`, () => { const action = actions.upsertPage({ path: `/hi/`, component: `/whatever/index.js`, - }); + }) const action2 = actions.upsertPage({ path: `/hi/pizza/`, component: `/whatever/index.js`, - }); - let state = reducer({ pages: [] }, action); - state = reducer(state, action2); - expect(state).toMatchSnapshot(); - expect(state.pages.length).toEqual(2); - }); + }) + let state = reducer({ pages: [] }, action) + state = reducer(state, action2) + expect(state).toMatchSnapshot() + expect(state.pages.length).toEqual(2) + }) it(`allows you to update existing pages (based on path)`, () => { const action = actions.upsertPage({ path: `/hi/`, component: `/whatever/index.js`, - }); + }) // Change the component const action2 = actions.upsertPage({ path: `/hi/`, component: `/whatever2/index.js`, - }); + }) - let state = reducer({ pages: [] }, action); - state = reducer(state, action2); - expect(state).toMatchSnapshot(); - expect(state.pages.length).toEqual(1); - }); -}); + let state = reducer({ pages: [] }, action) + state = reducer(state, action2) + expect(state).toMatchSnapshot() + expect(state.pages.length).toEqual(1) + }) +}) diff --git a/packages/gatsby/lib/redux/__tests__/site-config.js b/packages/gatsby/lib/redux/__tests__/site-config.js index a0e2c258a402a..a1f0dc365dd2a 100644 --- a/packages/gatsby/lib/redux/__tests__/site-config.js +++ b/packages/gatsby/lib/redux/__tests__/site-config.js @@ -1,4 +1,4 @@ -import { store, reducer } from "../index.js"; +import { store, reducer } from "../index.js" describe(`add site config`, () => { it(`allow you to add basic site config`, () => { @@ -7,22 +7,22 @@ describe(`add site config`, () => { title: "yo testing", }, plugins: [], - }; + } const state = reducer( {}, { type: "SET_SITE_CONFIG", payload: config, } - ); - expect(state).toMatchSnapshot(); - }); + ) + expect(state).toMatchSnapshot() + }) it(`Validates configs with unsupported options`, () => { const config = { someRandomThing: "hi people", plugins: [], - }; + } function runReducer() { return reducer( {}, @@ -30,8 +30,8 @@ describe(`add site config`, () => { type: "SET_SITE_CONFIG", payload: config, } - ); + ) } - expect(runReducer).toThrowErrorMatchingSnapshot(); - }); -}); + expect(runReducer).toThrowErrorMatchingSnapshot() + }) +}) diff --git a/packages/gatsby/lib/redux/reducers/__tests__/page-data-dependencies.js b/packages/gatsby/lib/redux/reducers/__tests__/page-data-dependencies.js index cab5b1b01e04d..56a0a83435244 100644 --- a/packages/gatsby/lib/redux/reducers/__tests__/page-data-dependencies.js +++ b/packages/gatsby/lib/redux/reducers/__tests__/page-data-dependencies.js @@ -1,4 +1,4 @@ -const reducer = require("../page-data-dependencies"); +const reducer = require("../page-data-dependencies") describe(`add page data dependency`, () => { it(`lets you add a node dependency`, () => { @@ -8,15 +8,15 @@ describe(`add page data dependency`, () => { path: `/hi/`, nodeId: `123`, }, - }; + } expect(reducer(undefined, action)).toEqual({ connections: {}, nodes: { "123": [`/hi/`], }, - }); - }); + }) + }) it(`lets you add a connection dependency`, () => { const action = { type: `ADD_PAGE_DEPENDENCY`, @@ -24,15 +24,15 @@ describe(`add page data dependency`, () => { path: `/hi/`, connection: `MarkdownRemark`, }, - }; + } expect(reducer(undefined, action)).toEqual({ connections: { MarkdownRemark: ["/hi/"], }, nodes: {}, - }); - }); + }) + }) it(`removes duplicate paths`, () => { const action = { type: `ADD_PAGE_DEPENDENCY`, @@ -41,7 +41,7 @@ describe(`add page data dependency`, () => { nodeId: 1, connection: `MarkdownRemark`, }, - }; + } const action2 = { type: `ADD_PAGE_DEPENDENCY`, payload: { @@ -49,17 +49,17 @@ describe(`add page data dependency`, () => { nodeId: 1, connection: `MarkdownRemark`, }, - }; + } - let state = reducer(undefined, action); + let state = reducer(undefined, action) // Do it again - state = reducer(state, action); + state = reducer(state, action) // Add different action - state = reducer(state, action2); + state = reducer(state, action2) - expect(state.connections["MarkdownRemark"].length).toEqual(2); - expect(state.nodes[1].length).toEqual(2); - }); + expect(state.connections["MarkdownRemark"].length).toEqual(2) + expect(state.nodes[1].length).toEqual(2) + }) it(`lets you add both a node and connection in one action`, () => { const action = { type: `ADD_PAGE_DEPENDENCY`, @@ -68,10 +68,10 @@ describe(`add page data dependency`, () => { connection: `MarkdownRemark`, nodeId: `SuperCoolNode`, }, - }; + } - let state = reducer(undefined, action); + let state = reducer(undefined, action) - expect(state).toMatchSnapshot(); - }); -}); + expect(state).toMatchSnapshot() + }) +}) diff --git a/packages/gatsby/lib/redux/reducers/config.js b/packages/gatsby/lib/redux/reducers/config.js index 498184726708c..137621290319c 100644 --- a/packages/gatsby/lib/redux/reducers/config.js +++ b/packages/gatsby/lib/redux/reducers/config.js @@ -1,29 +1,29 @@ -const Joi = require("joi"); -const chalk = require("chalk"); +const Joi = require("joi") +const chalk = require("chalk") -const { gatsbyConfigSchema } = require("../../joi-schemas/joi"); +const { gatsbyConfigSchema } = require("../../joi-schemas/joi") module.exports = (state = {}, action) => { switch (action.type) { case "SET_SITE_CONFIG": // Validate the config. - const result = Joi.validate(action.payload, gatsbyConfigSchema); + const result = Joi.validate(action.payload, gatsbyConfigSchema) // TODO use Redux for capturing errors from different // parts of Gatsby so a) can capture richer errors and b) be // more flexible how to display them. if (result.error) { console.log( chalk.blue.bgYellow(`The site's gatsby.config.js failed validation`) - ); - console.log(chalk.bold.red(result.error)); - console.log(action.payload); - throw new Error(`The site's gatsby.config.js failed validation`); - return; + ) + console.log(chalk.bold.red(result.error)) + console.log(action.payload) + throw new Error(`The site's gatsby.config.js failed validation`) + return } return { ...action.payload, - }; + } default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/flattened-plugins.js b/packages/gatsby/lib/redux/reducers/flattened-plugins.js index 8efa943a7d9b7..66ca3f181e392 100644 --- a/packages/gatsby/lib/redux/reducers/flattened-plugins.js +++ b/packages/gatsby/lib/redux/reducers/flattened-plugins.js @@ -1,8 +1,8 @@ module.exports = (state = [], action) => { switch (action.type) { case "SET_SITE_FLATTENED_PLUGINS": - return [...action.payload]; + return [...action.payload] default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/index.js b/packages/gatsby/lib/redux/reducers/index.js index 920170c56e374..a966d3e7de607 100644 --- a/packages/gatsby/lib/redux/reducers/index.js +++ b/packages/gatsby/lib/redux/reducers/index.js @@ -9,4 +9,4 @@ module.exports = { schema: require("./schema"), status: require("./status"), pageDataDependencies: require("./page-data-dependencies"), -}; +} diff --git a/packages/gatsby/lib/redux/reducers/last-action.js b/packages/gatsby/lib/redux/reducers/last-action.js index 13fac38578428..409c38e5ea16a 100644 --- a/packages/gatsby/lib/redux/reducers/last-action.js +++ b/packages/gatsby/lib/redux/reducers/last-action.js @@ -1,3 +1,3 @@ module.exports = (state = null, action) => { - return action; -}; + return action +} diff --git a/packages/gatsby/lib/redux/reducers/nodes.js b/packages/gatsby/lib/redux/reducers/nodes.js index 40d94c78f68f4..13b80f13f2c20 100644 --- a/packages/gatsby/lib/redux/reducers/nodes.js +++ b/packages/gatsby/lib/redux/reducers/nodes.js @@ -4,13 +4,13 @@ module.exports = (state = {}, action) => { return { ...state, [action.payload.id]: action.payload, - }; + } case "UPDATE_NODE": return { ...state, [action.payload.id]: action.payload, - }; + } default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/page-data-dependencies.js b/packages/gatsby/lib/redux/reducers/page-data-dependencies.js index 79d76388d3a8f..a0ac827f61f66 100644 --- a/packages/gatsby/lib/redux/reducers/page-data-dependencies.js +++ b/packages/gatsby/lib/redux/reducers/page-data-dependencies.js @@ -1,23 +1,23 @@ -const _ = require("lodash"); +const _ = require("lodash") module.exports = (state = { nodes: {}, connections: {} }, action) => { switch (action.type) { case "ADD_PAGE_DEPENDENCY": if (action.payload.path === "") { - return state; + return state } // If this nodeId not set yet. if (action.payload.nodeId) { if (!_.has(state, `nodes.${action.payload.nodeId}`)) { - state.nodes[action.payload.nodeId] = [action.payload.path]; + state.nodes[action.payload.nodeId] = [action.payload.path] } else { if ( _.includes(state.nodes[action.payload.nodeId], action.payload.path) ) { state.nodes[action.payload.nodeId] = state.nodes[ action.payload.nodeId - ].concat([action.payload.path]); + ].concat([action.payload.path]) } } } @@ -25,7 +25,7 @@ module.exports = (state = { nodes: {}, connections: {} }, action) => { // If this connection not set yet. if (action.payload.connection) { if (!_.has(state, `connections.${action.payload.connection}`)) { - state.connections[action.payload.connection] = [action.payload.path]; + state.connections[action.payload.connection] = [action.payload.path] } else { if ( !_.includes( @@ -35,13 +35,13 @@ module.exports = (state = { nodes: {}, connections: {} }, action) => { ) { state.connections[action.payload.connection] = state.connections[ action.payload.connection - ].concat([action.payload.path]); + ].concat([action.payload.path]) } } } - return state; + return state default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/pages.js b/packages/gatsby/lib/redux/reducers/pages.js index 927357485874b..51198d6878288 100644 --- a/packages/gatsby/lib/redux/reducers/pages.js +++ b/packages/gatsby/lib/redux/reducers/pages.js @@ -1,11 +1,11 @@ -const _ = require("lodash"); +const _ = require("lodash") module.exports = (state = [], action) => { switch (action.type) { case "UPSERT_PAGE": const index = _.findIndex(state, p => { - return p.path === action.payload.path; - }); + return p.path === action.payload.path + }) // If the path already exists, overwrite it. // Otherwise, add it to the end. if (index !== -1) { @@ -14,11 +14,11 @@ module.exports = (state = [], action) => { .slice(0, index) .concat(action.payload) .concat(state.slice(index + 1)), - ]; + ] } else { - return [...state.concat(action.payload)]; + return [...state.concat(action.payload)] } default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/plugins.js b/packages/gatsby/lib/redux/reducers/plugins.js index f19db8c6a762e..78e0eacd456f6 100644 --- a/packages/gatsby/lib/redux/reducers/plugins.js +++ b/packages/gatsby/lib/redux/reducers/plugins.js @@ -1,8 +1,8 @@ module.exports = (state = [], action) => { switch (action.type) { case "SET_SITE_PLUGINS": - return [...action.payload]; + return [...action.payload] default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/program.js b/packages/gatsby/lib/redux/reducers/program.js index 5ae0cdd144686..0d1cee2b19d81 100644 --- a/packages/gatsby/lib/redux/reducers/program.js +++ b/packages/gatsby/lib/redux/reducers/program.js @@ -3,15 +3,15 @@ module.exports = (state = { directory: `/` }, action) => { case "SET_PROGRAM": return { ...action.payload, - }; + } case "SET_PROGRAM_EXTENSIONS": return { ...state, extensions: action.payload, - }; + } default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/schema.js b/packages/gatsby/lib/redux/reducers/schema.js index f72ef3e3770ef..cce0b5f6795db 100644 --- a/packages/gatsby/lib/redux/reducers/schema.js +++ b/packages/gatsby/lib/redux/reducers/schema.js @@ -1,8 +1,8 @@ module.exports = (state = {}, action) => { switch (action.type) { case "SET_SCHEMA": - return action.payload; + return action.payload default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/redux/reducers/status.js b/packages/gatsby/lib/redux/reducers/status.js index d169773034dff..c126055099c87 100644 --- a/packages/gatsby/lib/redux/reducers/status.js +++ b/packages/gatsby/lib/redux/reducers/status.js @@ -4,8 +4,8 @@ module.exports = (state = {}, action) => { return { ...state, [action.payload.plugin]: action.payload.ready, - }; + } default: - return state; + return state } -}; +} diff --git a/packages/gatsby/lib/schema/__tests__/data-tree-utils-test.js b/packages/gatsby/lib/schema/__tests__/data-tree-utils-test.js index 58a5a95716d8f..d4aed27222c4a 100644 --- a/packages/gatsby/lib/schema/__tests__/data-tree-utils-test.js +++ b/packages/gatsby/lib/schema/__tests__/data-tree-utils-test.js @@ -1,7 +1,7 @@ const { extractFieldExamples, buildFieldEnumValues, -} = require("../data-tree-utils"); +} = require("../data-tree-utils") describe(`Gatsby data tree utils`, () => { const nodes = [ @@ -29,17 +29,17 @@ describe(`Gatsby data tree utils`, () => { circle: `happy`, }, }, - ]; + ] it(`builds field examples from an array of nodes`, () => { - expect(extractFieldExamples({ nodes })).toMatchSnapshot(); - }); + expect(extractFieldExamples({ nodes })).toMatchSnapshot() + }) it(`ignores fields that have a null value`, () => { - expect(extractFieldExamples({ nodes }).iAmNull).not.toBeDefined(); - }); + expect(extractFieldExamples({ nodes }).iAmNull).not.toBeDefined() + }) it(`build enum values for fields from array on nodes`, () => { - expect(buildFieldEnumValues(nodes)).toMatchSnapshot(); - }); -}); + expect(buildFieldEnumValues(nodes)).toMatchSnapshot() + }) +}) From 0c71ab9ba623a64c3886acf309edaf054774ab46 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 20:46:24 +0200 Subject: [PATCH 12/33] Deal with config.rootPath for default layout --- packages/gatsby/lib/utils/query-runner.js | 49 ++++++++++----------- packages/gatsby/lib/utils/webpack.config.js | 5 ++- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/packages/gatsby/lib/utils/query-runner.js b/packages/gatsby/lib/utils/query-runner.js index 0d0d00d2999ff..eadf072203f05 100644 --- a/packages/gatsby/lib/utils/query-runner.js +++ b/packages/gatsby/lib/utils/query-runner.js @@ -46,7 +46,7 @@ const pascalCase = _.flow(_.camelCase, _.upperFirst) // Write out routes file. // Loop through all paths and write them out to child-routes.js const writeChildRoutes = () => { - const directory = store.getState().program.directory + const { program, config, pages } = store.getState() let childRoutes = `` let splitChildRoutes = `` @@ -66,13 +66,13 @@ const writeChildRoutes = () => { const genSplitChildRoute = (page, noPath = false) => { const pathName = pathChunkName(page.path) const layoutName = layoutComponentChunkName( - store.getState().program.directory, + program.directory, page.component ) let pathStr = `` if (!noPath) { - if (store.getState().program.prefixLinks) { - pathStr = `path:'${_.get(store.getState().config, `linkPrefix`, ``)}${page.path}',` + if (program.prefixLinks) { + pathStr = `path:'${_.get(config, `linkPrefix`, ``)}${page.path}',` } else { pathStr = `path:'${page.path}',` } @@ -97,12 +97,13 @@ const writeChildRoutes = () => { // Group pages under their layout component (if any). let defaultLayoutExists = true if ( - glob.sync(`${store.getState().program.directory}/layouts/default.*`) - .length === 0 + glob.sync( + `${program.directory}${config.rootPath || `/`}layouts/default.*` + ).length === 0 ) { defaultLayoutExists = false } - const groupedPages = _.groupBy(store.getState().pages, page => { + const groupedPages = _.groupBy(pages, page => { // If is a string we'll assume it's a working layout component. if (_.isString(page.layout)) { return page.layout @@ -136,9 +137,10 @@ const writeChildRoutes = () => { splitRootRoute += splitRoute } else { let indexPage - indexPage = _.first( - _.filter(pages, page => parseFilepath(page.component).name === `index`) + indexPage = pages.find( + page => parseFilepath(page.component).name === `index` ) + // If there's not an index page, just pick the one with the shortest path. // Probably a bad heuristic. if (!indexPage) { @@ -147,20 +149,20 @@ const writeChildRoutes = () => { let route = ` { path: '${indexPage.path}', - component: preferDefault(require('${store.getState().program.directory}/layouts/${layout}')), + component: preferDefault(require('${program.directory}${config.rootPath || `/`}layouts/${layout}')), indexRoute: ${genChildRoute(indexPage, true)} childRoutes: [ ` let pathStr - if (store.getState().program.prefixLinks) { - pathStr = `path:'${_.get(store.getState().config, `linkPrefix`, ``)}${indexPage.path}',` + if (program.prefixLinks) { + pathStr = `path:'${_.get(config, `linkPrefix`, ``)}${indexPage.path}',` } else { pathStr = `path:'${indexPage.path}',` } let splitRoute = ` { ${pathStr} - component: preferDefault(require('${store.getState().program.directory}/layouts/${layout}')), + component: preferDefault(require('${program.directory}${config.rootPath || `/`}layouts/${layout}')), indexRoute: ${genSplitChildRoute(indexPage, true)} childRoutes: [ ` @@ -177,16 +179,14 @@ const writeChildRoutes = () => { }) // Add a fallback 404 route if one is defined. - const notFoundPage = _.find( - store.getState().pages, - page => page.path.indexOf("/404") !== -1 - ) + const notFoundPage = pages.find(page => page.path.indexOf("/404") !== -1) if (notFoundPage) { + const defaultLayout = `preferDefault(require('${program.directory}${config.rootPath || `/`}layouts/default'))` const notFoundPageStr = ` { path: "*", - component: preferDefault(require('${store.getState().program.directory}/layouts/default')), + component: ${defaultLayout}, indexRoute: { component: preferDefault(require('${notFoundPage.component}')), }, @@ -194,13 +194,13 @@ const writeChildRoutes = () => { ` const pathName = pathChunkName(notFoundPage.path) const layoutName = layoutComponentChunkName( - store.getState().program.directory, + program.directory, notFoundPage.component ) const notFoundPageSplitStr = ` { path: "*", - component: preferDefault(require('${store.getState().program.directory}/layouts/default')), + component: ${defaultLayout}, indexRoute: { getComponent (nextState, cb) { require.ensure([], (require) => { @@ -222,9 +222,8 @@ const writeChildRoutes = () => { // Close out object. rootRoute += `]}` splitRootRoute += `]}` - const componentsStr = store - .getState() - .pages.map(page => { + const componentsStr = pages + .map(page => { return `class ${page.internalComponentName} extends React.Component { render () { const Component = preferDefault(require('${page.component}')) @@ -272,11 +271,11 @@ const writeChildRoutes = () => { const rootRoute = ${splitRootRoute} module.exports = rootRoute` fs.writeFileSync( - `${directory}/.intermediate-representation/child-routes.js`, + `${program.directory}/.intermediate-representation/child-routes.js`, childRoutes ) fs.writeFileSync( - `${directory}/.intermediate-representation/split-child-routes.js`, + `${program.directory}/.intermediate-representation/split-child-routes.js`, splitChildRoutes ) } diff --git a/packages/gatsby/lib/utils/webpack.config.js b/packages/gatsby/lib/utils/webpack.config.js index 9d40c37e67985..501e0bc3cc6e0 100644 --- a/packages/gatsby/lib/utils/webpack.config.js +++ b/packages/gatsby/lib/utils/webpack.config.js @@ -276,7 +276,10 @@ module.exports = async ( // Hierarchy of directories for Webpack to look for module. // First is the site directory. // Then in the special directory of isomorphic modules Gatsby ships with. - root: [path.join(directory, rootPath), path.resolve(__dirname, `..`, `isomorphic`)], + root: [ + path.join(directory, rootPath), + path.resolve(__dirname, `..`, `isomorphic`), + ], modulesDirectories: [`${directory}/node_modules`, `node_modules`], } } From 2de4528ebc0109c8fa620ea92c7cc21278c40506 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Fri, 14 Apr 2017 21:19:35 +0200 Subject: [PATCH 13/33] Fix bad rebase --- packages/gatsby/lib/bootstrap/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/gatsby/lib/bootstrap/index.js b/packages/gatsby/lib/bootstrap/index.js index 58cbb86121301..8e898b8f914f3 100644 --- a/packages/gatsby/lib/bootstrap/index.js +++ b/packages/gatsby/lib/bootstrap/index.js @@ -33,7 +33,6 @@ const preferDefault = m => (m && m.default) || m const mkdirs = Promise.promisify(fs.mkdirs) const copy = Promise.promisify(fs.copy) -const removeDir = Promise.promisify(fs.remove) const glob = Promise.promisify(globCB) // Path creator. @@ -43,7 +42,6 @@ const glob = Promise.promisify(globCB) // takes control of that page component in gatsby-node. const autoPathCreator = async (program: any) => { const pagesDirectory = path.posix.join(program.directory, `pages`) - const exts = program.extensions.map(e => `*${e}`).join("|") const exts = store.getState().program.extensions.map(e => `*${e}`).join("|") // The promisified version wasn't working for some reason // so we'll use sync for now. From f4b80ed402da13152aa6d1e16a293b48ede5d8d2 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Sat, 15 Apr 2017 10:28:58 +0200 Subject: [PATCH 14/33] Fix documention style --- docs/docs/gatsby-on-windows.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/docs/gatsby-on-windows.md b/docs/docs/gatsby-on-windows.md index 1f7b1bdd4a005..59832e4051475 100644 --- a/docs/docs/gatsby-on-windows.md +++ b/docs/docs/gatsby-on-windows.md @@ -19,7 +19,4 @@ are required to compile popular native modules. It will also install Python ## Installing dependencies without troubles. -Even if you love using a pretty terminal as [hyper](https://hyper.is/) with a git bash, -for installing packages without build troubles, it's better to use **a powershell console** - -After `yarn` or `npm i`, you can go back on your favorite terminal :wink: and run `yarn develop` or `npm run develop`! \ No newline at end of file +Run `yarn` or `npm i` in **a powershell console** to have a correct build (some issues with sharp and sqlite3 with a bash console) \ No newline at end of file From c8ee94bdcdc7972c3bb190db94ca59f71f4e38c1 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Sat, 15 Apr 2017 15:27:54 +0200 Subject: [PATCH 15/33] Add typescript definition for gatsby-link --- packages/gatsby-link/README.md | 24 +++++++++++++++++++++++- packages/gatsby-link/index.d.ts | 7 +++++++ packages/gatsby-link/package.json | 4 ++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 packages/gatsby-link/index.d.ts diff --git a/packages/gatsby-link/README.md b/packages/gatsby-link/README.md index 151102582e994..355b0aa334a38 100644 --- a/packages/gatsby-link/README.md +++ b/packages/gatsby-link/README.md @@ -21,8 +21,9 @@ Edge), this component will also preload code chunks on these browsers. ## How to use +In javascript: ```jsx -const Link = require('gatsby-link') +import Link from "gatsby-link" render () {
@@ -31,6 +32,27 @@ render () { activeStyle={{ color: 'red' }} + > + Another page +
} ``` + +In typescript: +```jsx +import * as Link from "gatsby-link"; + +render () { +
+ + Another page + +
+} +``` \ No newline at end of file diff --git a/packages/gatsby-link/index.d.ts b/packages/gatsby-link/index.d.ts new file mode 100644 index 0000000000000..ae25bb66da1de --- /dev/null +++ b/packages/gatsby-link/index.d.ts @@ -0,0 +1,7 @@ +import { ClassicComponentClass } from "react"; +import { LinkProps } from "react-router"; + +type GatsbyLink = ClassicComponentClass; +declare const GatsbyLink: GatsbyLink; + +export = GatsbyLink; \ No newline at end of file diff --git a/packages/gatsby-link/package.json b/packages/gatsby-link/package.json index 19080e3508cc9..7e4f4851b444e 100644 --- a/packages/gatsby-link/package.json +++ b/packages/gatsby-link/package.json @@ -3,6 +3,7 @@ "version": "1.0.0-alpha12", "description": "An enhanced Link component for Gatsby sites with support for resource prefetching", "main": "index.js", + "types": "index.d.ts", "scripts": { "build": "babel src --out-dir .", "watch": "babel -w src --out-dir ." @@ -15,5 +16,8 @@ "license": "MIT", "devDependencies": { "babel-cli": "^6.18.0" + }, + "dependencies": { + "@types/react-router": "^2.0.49" } } From d3c99a374c58a6c055df44052fc71676631665e6 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Sat, 15 Apr 2017 18:18:10 +0200 Subject: [PATCH 16/33] Remove superfluous typescript example --- packages/gatsby-link/README.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/gatsby-link/README.md b/packages/gatsby-link/README.md index 355b0aa334a38..55c6f4e0b057f 100644 --- a/packages/gatsby-link/README.md +++ b/packages/gatsby-link/README.md @@ -38,21 +38,3 @@ render () { } ``` - -In typescript: -```jsx -import * as Link from "gatsby-link"; - -render () { -
- - Another page - -
-} -``` \ No newline at end of file From 5501d789b2b84697921c575522364dde75e51f69 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Sat, 15 Apr 2017 19:00:21 +0200 Subject: [PATCH 17/33] Add vscode config to execute prettier on save More info: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode --- .vscode/settings.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000..91146d2fed48a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +// Placez vos paramètres dans ce fichier pour remplacer les paramètres par défaut et les paramètres utilisateur. +{ + "prettier.semi": false, + "prettier.trailingComma": "es5", + "editor.formatOnSave": true +} \ No newline at end of file From 55d14b88dfb3706a27a45206b5e8f8d78b42b118 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Sat, 15 Apr 2017 20:00:06 +0200 Subject: [PATCH 18/33] Imprive joi validation on rootPath --- packages/gatsby/lib/joi-schemas/joi.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/lib/joi-schemas/joi.js b/packages/gatsby/lib/joi-schemas/joi.js index a3beb88df9fe9..3c9442d140e85 100644 --- a/packages/gatsby/lib/joi-schemas/joi.js +++ b/packages/gatsby/lib/joi-schemas/joi.js @@ -1,7 +1,13 @@ const Joi = require("joi") export const gatsbyConfigSchema = Joi.object().keys({ - rootPath: Joi.string(), + rootPath: Joi.string() + .regex(/^\/(?!\.{2}).*\/$/) + .notes([ + `should start with "/"`, + `should finish with "/"`, + `should not have ".." pattern`, + ]), siteMetadata: Joi.object(), linkPrefix: Joi.string(), mapping: Joi.object(), From e85fe81af1b245501eba37a580d7bbdf9a62ba8e Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Sun, 16 Apr 2017 13:48:41 +0200 Subject: [PATCH 19/33] Remove useless tsconfig.json --- packages/gatsby-plugin-typescript/tsconfig.json | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 packages/gatsby-plugin-typescript/tsconfig.json diff --git a/packages/gatsby-plugin-typescript/tsconfig.json b/packages/gatsby-plugin-typescript/tsconfig.json deleted file mode 100644 index ee1eeb25cd004..0000000000000 --- a/packages/gatsby-plugin-typescript/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "rootDir": "src", - "outDir": "./" - }, - "files": [ - "src/gatsby-node.ts", - "src/index.ts" - ] -} \ No newline at end of file From 3d3ce81964506a8855ddc84462769890af927eed Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Mon, 17 Apr 2017 13:04:05 +0200 Subject: [PATCH 20/33] Remove unused var --- packages/gatsby/lib/utils/build.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/gatsby/lib/utils/build.js b/packages/gatsby/lib/utils/build.js index 9518a14f65e5b..ef4b5318e3b30 100644 --- a/packages/gatsby/lib/utils/build.js +++ b/packages/gatsby/lib/utils/build.js @@ -1,19 +1,14 @@ /* @flow */ -import toml from "toml" import fs from "fs" -import os from "os" -import _ from "lodash" import buildCSS from "./build-css" import buildHTML from "./build-html" import buildProductionBundle from "./build-javascript" -import postBuild from "./post-build" import bootstrap from "../bootstrap" import apiRunnerNode from "./api-runner-node" const { store } = require("../redux") async function html(program: any) { - const directory = program.directory const { graphqlRunner } = await bootstrap(program) console.log(`Generating CSS`) From 7c581804d56d4b225dbe1e6b684583e61d5b5102 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Mon, 17 Apr 2017 13:07:55 +0200 Subject: [PATCH 21/33] Use program from redux --- packages/gatsby/lib/bootstrap/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/gatsby/lib/bootstrap/index.js b/packages/gatsby/lib/bootstrap/index.js index 8e898b8f914f3..fb80aec1031f7 100644 --- a/packages/gatsby/lib/bootstrap/index.js +++ b/packages/gatsby/lib/bootstrap/index.js @@ -7,11 +7,8 @@ import _ from "lodash" import slash from "slash" import createPath from "./create-path" import fs from "fs-extra" -import Joi from "joi" -import chalk from "chalk" import apiRunnerNode from "../utils/api-runner-node" import { graphql } from "graphql" -import { layoutComponentChunkName } from "../utils/js-chunk-names" import { store } from "../redux" const { boundActionCreators } = require("../redux/actions") @@ -40,9 +37,14 @@ const glob = Promise.promisify(globCB) // algorithm is glob /pages directory for js/jsx/cjsx files *not* // underscored. Then create url w/ our path algorithm *unless* user // takes control of that page component in gatsby-node. -const autoPathCreator = async (program: any) => { - const pagesDirectory = path.posix.join(program.directory, `pages`) - const exts = store.getState().program.extensions.map(e => `*${e}`).join("|") +const autoPathCreator = async () => { + const { config, program } = store.getState() + const pagesDirectory = path.posix.join( + program.directory, + config.rootPath, + `pages` + ) + const exts = program.extensions.map(e => `*${e}`).join("|") // The promisified version wasn't working for some reason // so we'll use sync for now. const files = glob.sync(`${pagesDirectory}/**/?(${exts})`) @@ -287,7 +289,7 @@ module.exports = async (program: any) => { // TODO move this to own source plugin per component type // (js/cjsx/typescript, etc.). Only do after there's themes // so can cement default /pages setup in default core theme. - autoPathCreator(program) + autoPathCreator() // Copy /404/ to /404.html as many static site hosting companies expect // site 404 pages to be named this. From d2326906aa779f8b06ee08c3c9be8601e77dffce Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Mon, 17 Apr 2017 16:16:13 +0200 Subject: [PATCH 22/33] Improve rootPath config (default config and regex validator) --- packages/gatsby/lib/bootstrap/index.js | 11 +++++++---- packages/gatsby/lib/joi-schemas/joi.js | 3 ++- packages/gatsby/lib/utils/develop.js | 2 +- packages/gatsby/lib/utils/query-runner.js | 11 +++++------ packages/gatsby/lib/utils/webpack.config.js | 10 +++++----- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/gatsby/lib/bootstrap/index.js b/packages/gatsby/lib/bootstrap/index.js index fb80aec1031f7..7eb019283b202 100644 --- a/packages/gatsby/lib/bootstrap/index.js +++ b/packages/gatsby/lib/bootstrap/index.js @@ -91,17 +91,20 @@ module.exports = async (program: any) => { // Try opening the site's gatsby-config.js file. console.time(`open and validate gatsby-config.js`) - let config = {} + let config = { + rootPath: `/`, + } try { - config = require(`${program.directory}/gatsby-config`) + Object.assign( + config, + preferDefault(require(`${program.directory}/gatsby-config`)) + ) } catch (e) { console.log(`Couldn't open your gatsby-config.js file`) console.log(e) process.exit() } - config = preferDefault(config) - store.dispatch({ type: "SET_SITE_CONFIG", payload: config, diff --git a/packages/gatsby/lib/joi-schemas/joi.js b/packages/gatsby/lib/joi-schemas/joi.js index 3c9442d140e85..392e6e51b2775 100644 --- a/packages/gatsby/lib/joi-schemas/joi.js +++ b/packages/gatsby/lib/joi-schemas/joi.js @@ -2,11 +2,12 @@ const Joi = require("joi") export const gatsbyConfigSchema = Joi.object().keys({ rootPath: Joi.string() - .regex(/^\/(?!\.{2}).*\/$/) + .regex(/(^\/$)|(^\/(?!\.{2}).*\/$)/) .notes([ `should start with "/"`, `should finish with "/"`, `should not have ".." pattern`, + `can be "/" (default)`, ]), siteMetadata: Joi.object(), linkPrefix: Joi.string(), diff --git a/packages/gatsby/lib/utils/develop.js b/packages/gatsby/lib/utils/develop.js index 9e6af0b119487..5d1b9fe48841a 100644 --- a/packages/gatsby/lib/utils/develop.js +++ b/packages/gatsby/lib/utils/develop.js @@ -40,7 +40,7 @@ async function startServer(program) { const devConfig = compilerConfig.resolve() const compiler = webpack(devConfig) - const rootPath = _.get(store.getState(), `config.rootPath`, `/`) + const rootPath = store.getState().config.rootPath const HTMLPath = glob.sync(`${directory}${rootPath}html.*`)[0] // Check if we can't find an html component in root of site. if (!HTMLPath) { diff --git a/packages/gatsby/lib/utils/query-runner.js b/packages/gatsby/lib/utils/query-runner.js index eadf072203f05..2df433d97cfc3 100644 --- a/packages/gatsby/lib/utils/query-runner.js +++ b/packages/gatsby/lib/utils/query-runner.js @@ -97,9 +97,8 @@ const writeChildRoutes = () => { // Group pages under their layout component (if any). let defaultLayoutExists = true if ( - glob.sync( - `${program.directory}${config.rootPath || `/`}layouts/default.*` - ).length === 0 + glob.sync(`${program.directory}${config.rootPath}layouts/default.*`) + .length === 0 ) { defaultLayoutExists = false } @@ -149,7 +148,7 @@ const writeChildRoutes = () => { let route = ` { path: '${indexPage.path}', - component: preferDefault(require('${program.directory}${config.rootPath || `/`}layouts/${layout}')), + component: preferDefault(require('${program.directory}${config.rootPath}layouts/${layout}')), indexRoute: ${genChildRoute(indexPage, true)} childRoutes: [ ` @@ -162,7 +161,7 @@ const writeChildRoutes = () => { let splitRoute = ` { ${pathStr} - component: preferDefault(require('${program.directory}${config.rootPath || `/`}layouts/${layout}')), + component: preferDefault(require('${program.directory}${config.rootPath}layouts/${layout}')), indexRoute: ${genSplitChildRoute(indexPage, true)} childRoutes: [ ` @@ -182,7 +181,7 @@ const writeChildRoutes = () => { const notFoundPage = pages.find(page => page.path.indexOf("/404") !== -1) if (notFoundPage) { - const defaultLayout = `preferDefault(require('${program.directory}${config.rootPath || `/`}layouts/default'))` + const defaultLayout = `preferDefault(require('${program.directory}${config.rootPath}layouts/default'))` const notFoundPageStr = ` { path: "*", diff --git a/packages/gatsby/lib/utils/webpack.config.js b/packages/gatsby/lib/utils/webpack.config.js index 501e0bc3cc6e0..7af0f392a15fe 100644 --- a/packages/gatsby/lib/utils/webpack.config.js +++ b/packages/gatsby/lib/utils/webpack.config.js @@ -100,7 +100,6 @@ module.exports = async ( } case `build-html`: return { - // main: `${__dirname}/static-entry`, main: `${directory}/.intermediate-representation/static-entry`, } case `build-javascript`: @@ -180,7 +179,7 @@ module.exports = async ( // common webpack tweaks e.g. lodash? new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), new WebpackMD5Hash(), - //new webpack.optimize.DedupePlugin(), + // new webpack.optimize.DedupePlugin(), // Extract "commons" chunk from the app entry and all // page components. new webpack.optimize.CommonsChunkPlugin({ @@ -269,15 +268,16 @@ module.exports = async ( } function resolve() { - const rootPath = _.get(store.getState(), `config.rootPath`, `/`) + const { program, config } = store.getState() return { // use the program's extension list (generated via the 'resolvableExtensions' API hook) - extensions: [``, ...store.getState().program.extensions], + extensions: [``, ...program.extensions], // Hierarchy of directories for Webpack to look for module. // First is the site directory. // Then in the special directory of isomorphic modules Gatsby ships with. root: [ - path.join(directory, rootPath), + directory, + path.join(directory, config.rootPath), path.resolve(__dirname, `..`, `isomorphic`), ], modulesDirectories: [`${directory}/node_modules`, `node_modules`], From 7d1f7193c445ae7b18f13e249b0f84445b9300a4 Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Mon, 17 Apr 2017 18:19:33 +0200 Subject: [PATCH 23/33] Ensure schema is created even if the project hasn't got any source plugin Fix #811 --- packages/gatsby/lib/schema/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gatsby/lib/schema/index.js b/packages/gatsby/lib/schema/index.js index f6823709d0312..5823de8c8dc0c 100644 --- a/packages/gatsby/lib/schema/index.js +++ b/packages/gatsby/lib/schema/index.js @@ -42,6 +42,7 @@ async function buildSchema() { // an explicit API for them to let Gatsby core know that a sync is complete. const debounceNodeCreation = cb => { const updateNode = _.debounce(cb, 250) + updateNode() // Ensure schema is created even if the project hasn't got any source plugin store.subscribe(() => { const state = store.getState() if ( From 9886ac0a898757d4ecd3dc768b35a685b25b3c6a Mon Sep 17 00:00:00 2001 From: fabien0102 Date: Mon, 17 Apr 2017 19:39:21 +0200 Subject: [PATCH 24/33] Find a webpack config that deals with all env \o/ This configuration works with basics configuration and with a custom `rootPath` (even with a typescript stack) It was tested with build and develop commands --- .../static-entry.js | 20 ++++++++---------- packages/gatsby/lib/utils/webpack.config.js | 21 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/gatsby/lib/intermediate-representation-dir/static-entry.js b/packages/gatsby/lib/intermediate-representation-dir/static-entry.js index 21e3b2a77f9e9..b9b983133ffc5 100644 --- a/packages/gatsby/lib/intermediate-representation-dir/static-entry.js +++ b/packages/gatsby/lib/intermediate-representation-dir/static-entry.js @@ -2,15 +2,13 @@ import React from "react" import { renderToString, renderToStaticMarkup } from "react-dom/server" import { match, RouterContext } from "react-router" import Html from "html" -import _ from "lodash" -//import { prefixLink } from '../isomorphic/gatsby-helpers' -import rootRoute from ".intermediate-representation/child-routes.js" -import pages from "public/tmp-pages.json" -//import { pathChunkName } from './js-chunk-names' -import apiRunner from ".intermediate-representation/api-runner-ssr" +import { kebabCase, get, merge } from "lodash" +import rootRoute from "./child-routes" +import apiRunner from "./api-runner-ssr" +import pages from "../public/tmp-pages.json" const pathChunkName = path => { - const name = path === `/` ? `index` : _.kebabCase(path) + const name = path === `/` ? `index` : kebabCase(path) return `path---${name}` } @@ -59,7 +57,7 @@ module.exports = (locals, callback) => { } // Add the chunk-manifest as a head component. - const chunkManifest = require("!raw!public/chunk-manifest.json") + const chunkManifest = require("!raw!../public/chunk-manifest.json") postBodyComponents.unshift(