Skip to content

Commit

Permalink
Don't check if React is imported as can import component from other p…
Browse files Browse the repository at this point in the history
…age and never write JSX (#3949)

/cc @bodia-uz
  • Loading branch information
KyleAMathews committed Feb 9, 2018
1 parent 216ed95 commit c70067a
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,20 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
if (!internalPage.component.includes(`/.cache/`)) {
const fileContent = fs.readFileSync(internalPage.component, `utf-8`)
let notEmpty = true
let includesReactImport = true
let includesDefaultExport = true

if (fileContent === ``) {
notEmpty = false
}

if (!fileContent.includes(`React`)) {
includesReactImport = false
}
if (
!fileContent.includes(`export default`) &&
!fileContent.includes(`module.exports`) &&
!fileContent.includes(`exports.default`)
) {
includesDefaultExport = false
}
if (!notEmpty || !includesDefaultExport || !includesReactImport) {
if (!notEmpty || !includesDefaultExport) {
const relativePath = path.relative(
store.getState().program.directory,
internalPage.component
Expand All @@ -230,18 +226,6 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
`The page component at "${relativePath}" didn't pass validation`
)

if (!includesReactImport) {
console.log(``)
console.log(
`You must import React at the top of the file for a React component to be valid`
)
console.log(``)
console.log(`Add the following to the top of the component:`)
console.log(``)
console.log(` import React from 'react'`)
console.log(``)
}

if (!includesDefaultExport) {
console.log(``)
console.log(
Expand Down

0 comments on commit c70067a

Please sign in to comment.