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] Fix graphql compiler on typescript #949

Merged
merged 16 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this not being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My VSCode tell me that is not used, but you can recheck ;) (I try to remove unused code when I see it)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jquense you know what this was used for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well if no code is calling it whatevers. We can recover it later if it's needed for something.

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