Skip to content

Commit

Permalink
[1.0] Fix graphql compiler on typescript (gatsbyjs#949)
Browse files Browse the repository at this point in the history
* Remove unused var

* Fix indent

* Add babel to typescript plugin

It's usefull to parse any graphql queries

* Let `parseEverything` really parse everything

* Exclude tests, declarations and stories

* Run yarn format

* Don't filter tests and stories

* Fix building schema console.time

* Fix create-path on windows

* Deal with `@` into keys

This is to avoid conflit with `@types/{packageName}` pattern into packages.json

* Add tests and refactor create-path

* Fix types of gatsby-link

* Add ts and tsx into query-watcher

* Only take babel-plugin-extract-graphql plugin
  • Loading branch information
fabien0102 authored and KyleAMathews committed Jun 15, 2017
1 parent 7a5d693 commit 1639377
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 34 deletions.
11 changes: 6 additions & 5 deletions packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ClassicComponentClass } from "react";
import { LinkProps } from "react-router";
import * as React from "react";

type GatsbyLink = ClassicComponentClass<LinkProps>;
declare const GatsbyLink: GatsbyLink;
export interface GatsbyLinkProps {
to: string;
onClick?: (event: any) => void
}

export = GatsbyLink;
export default class GatbyLink extends React.Component<GatsbyLinkProps, void>;
1 change: 0 additions & 1 deletion packages/gatsby-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"babel-cli": "^6.24.1"
},
"dependencies": {
"@types/react-router": "^2.0.49",
"prop-types": "^15.5.8",
"ric": "^1.3.0"
}
Expand Down
15 changes: 0 additions & 15 deletions packages/gatsby-link/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
# yarn lockfile v1


"@types/history@^2":
version "2.0.48"
resolved "https://registry.yarnpkg.com/@types/history/-/history-2.0.48.tgz#7e2868c3ad73d83c482f1d68f148c4fdc79c8a79"

"@types/react-router@^2.0.49":
version "2.0.49"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-2.0.49.tgz#96f8ad51f07a5890ab35fd55f05170efd132552a"
dependencies:
"@types/history" "^2"
"@types/react" "*"

"@types/react@*":
version "15.0.23"
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.23.tgz#f3facbef5290610f54242f00308759d3a3c27346"

abbrev@1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
Expand Down
11 changes: 10 additions & 1 deletion packages/gatsby-plugin-typescript/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { transpileModule } = require(`typescript`)
const path = require(`path`)

const test = /\.tsx?$/
const compilerDefaults = {
Expand All @@ -14,12 +15,20 @@ module.exports.modifyWebpackConfig = ({ config }, { compilerOptions }) => {
const copts = Object.assign({}, compilerDefaults, compilerOptions, {
module: `commonjs`,
})

// React-land is rather undertyped; nontrivial TS projects will most likely
// error (i.e., not build) at something or other.
const opts = { compilerOptions: copts, transpileOnly: true }

// Load gatsby babel plugin to extract graphql query
const extractQueryPlugin = path.resolve(__dirname, `../gatsby/dist/utils/babel-plugin-extract-graphql.js`)

config.loader(`typescript`, {
test,
loader: `ts-loader?` + JSON.stringify(opts),
loaders: [
`babel?${JSON.stringify({ plugins:[extractQueryPlugin] })}`,
`ts-loader?${JSON.stringify(opts)}`,
],
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ data
console.timeEnd(`initial sourcing and transforming nodes`)

// Create Schema.
console.time(`building schema`)
await require(`../schema`)()
console.timeEnd(`building schema`)

// Collect resolvable extensions and attach to program.
const extensions = [`.js`, `.jsx`]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const crypto = require(`crypto`)

// Traverse is a es6 module...
import traverse from "babel-traverse"
import * as types from "babel-types"
const babylon = require(`babylon`)
const Bluebird = require(`bluebird`)

Expand All @@ -15,14 +14,6 @@ import type { DocumentNode, DefinitionNode } from "graphql"

const readFileAsync = Bluebird.promisify(fs.readFile)

function getAssignedIdenifier(path) {
let property = path.parentPath
while (property) {
if (types.isVariableDeclarator(property)) return property.node.id.name
property = property.parentPath
}
}

async function parseToAst(filePath, fileStr) {
let ast

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class Runner {
}

async parseEverything() {
let files = await globp(`${this.baseDir}/**/*.js`)
let files = await globp(`${this.baseDir}/**/*.+(t|j)s?(x)`)
files = files.filter(d => !d.match(/\.d\.ts$/))
files = files.map(normalize)
// Ensure all page components added as they're not necessarily in the
// pages directory e.g. a plugin could add a page component. Plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports.watch = rootDir => {
}, 100)

watcher = chokidar
.watch(`${rootDir}/src/**/*.{js,jsx}`)
.watch(`${rootDir}/src/**/*.{js,jsx,ts,tsx}`)
.on(`change`, path => {
debounceCompile()
})
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby/src/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module.exports = async () => {
}),
})

console.timeEnd(`building schema`)
store.dispatch({
type: `SET_SCHEMA`,
payload: schema,
Expand Down

0 comments on commit 1639377

Please sign in to comment.