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

Don't check if React is imported as can import component from other page and never write JSX #3949

Merged
merged 1 commit into from
Feb 9, 2018
Merged
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
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