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

[v2] compile cache dir #5637

Merged
merged 5 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions packages/gatsby/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ node_modules

decls
dist
cache-dir
Empty file.
Empty file.
10 changes: 7 additions & 3 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"cross-env": "^5.1.4",
"jest": "^22.4.3",
"lerna": "^2.9.0",
"npm-run-all": "4.1.2",
"nyc": "^7.0.0",
"rimraf": "^2.6.1"
},
Expand Down Expand Up @@ -173,13 +174,16 @@
"graphql": "^0.13.2"
},
"scripts": {
"build": "rimraf dist && npm run build:src && npm run build:internal-plugins && npm run build:rawfiles",
"build": "rimraf dist && rimraf cache-dir && npm-run-all -p build:*",
"build:cache-dir": "babel src/cache-dir --out-dir cache-dir",
"build:internal-plugins": "copyfiles -u 1 src/internal-plugins/**/package.json dist",
"build:rawfiles": "copyfiles -u 1 src/internal-plugins/**/raw_* dist",
"build:src": "babel src --out-dir dist --source-maps --ignore **/gatsby-cli.js,**/raw_*,**/__tests__",
"build:src": "babel src --out-dir dist --source-maps --ignore **/gatsby-cli.js,**/raw_*,**/__tests__,**/cache-dir",
"clean-test-bundles": "find test/ -type f -name bundle.js* -exec rm -rf {} +",
"prepublish": "cross-env NODE_ENV=production npm run build",
"test-coverage": "node_modules/.bin/nyc --reporter=lcov --reporter=text npm test",
"watch": "rimraf dist && mkdir dist && npm run build:internal-plugins && npm run build:rawfiles && npm run build:src -- --watch"
"watch": "rimraf dist && rimraf cache-dir && mkdir dist && npm run build:internal-plugins && npm-run-all -p watch:*",
Copy link
Contributor

Choose a reason for hiding this comment

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

npm run build:rawfiles is missing here. I'll add a commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ops, thanks for catching this!

"watch:cache-dir": "npm run build:cache-dir -- --watch",
"watch:src": "npm run build:src -- --watch"
}
}
6 changes: 6 additions & 0 deletions packages/gatsby/src/cache-dir/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../../../.babel-preset.js", { "browser": true }]
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let fetchNextResource
let fetches

const getDeferred = (result) => {
let resolve;
let resolve
let promise = new Promise(r => {
resolve = () => r(result)
})
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let Html
try {
Html = require(`../src/html`)
} catch (err) {
if (testRequireError(`..\/src\/html`, err)) {
if (testRequireError(`../src/html`, err)) {
Html = require(`./default-html`)
} else {
console.log(`There was an error requiring "src/html.js"\n\n`, err, `\n\n`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React from "react"
import PropTypes from "prop-types"
import Link, { withPrefix, navigateTo } from "gatsby-link"
import pages from "./pages.json"
import loader from "./loader"
import JSONStore from "./json-store"

const PageRenderer = ({ location }) => {
const pageResources = loader.getResourcesForPathname(location.pathname)
const isPage = !!(pageResources && pageResources.component)
return React.createElement(JSONStore, {
pages,
location,
pageResources,
})
}

PageRenderer.propTypes = {
location: PropTypes.shape({
pathname: PropTypes.string.isRequired,
}).isRequired,
}

const StaticQueryContext = React.createContext({})

const StaticQuery = props => (
Expand All @@ -33,6 +39,12 @@ const StaticQuery = props => (
</StaticQueryContext.Consumer>
)

StaticQuery.propTypes = {
data: PropTypes.object,
query: PropTypes.string.isRequired,
render: PropTypes.func.isRequired,
}

export {
Link,
withPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import PageRenderer from "./page-renderer"
import { StaticQueryContext } from "gatsby"
import socketIo, { getStaticQueryData, getPageQueryData } from "./socketIo"

const getPathFromProps = props =>
props.pageResources
? props.pageResources.page
? props.pageResources.page.path
: undefined
: undefined
const getPathFromProps = props => props.pageResources?.page?.path

class JSONStore extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -47,10 +42,9 @@ class JSONStore extends React.Component {
}
}

componentWillReceiveProps(nextProps) {
componentDidUpdate() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure about that change, I've used recomendation from https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops , but it probably means extra render

const { path } = this.state
const newPath = getPathFromProps(nextProps)

const newPath = getPathFromProps(this.props)
if (path !== newPath) {
this.unregisterPath(path)
this.registerPath(newPath)
Expand All @@ -72,7 +66,7 @@ class JSONStore extends React.Component {
}

render() {
const data = this.state.pageQueryData[this.state.path]
const data = this.state.pageQueryData[getPathFromProps(this.props)]
// eslint-disable-next-line
const { pages, ...propsWithoutPages } = this.props
if (!data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,12 @@ export default (pagePath, callback) => {
}

// Create paths to scripts
let runtimeScript
const scriptsAndStyles = flatten(
[`app`, page.componentChunkName].map(s => {
const fetchKey = `assetsByChunkName[${s}]`

let chunks = get(stats, fetchKey)

// Remove the runtime as we always inline that instead
// of loading it.
if (s === `app`) {
runtimeScript = chunks[0]
}

if (!chunks) {
return null
}
Expand Down Expand Up @@ -195,11 +188,6 @@ export default (pagePath, callback) => {
pathPrefix,
})

const runtimeRaw = fs.readFileSync(
join(process.cwd(), `public`, runtimeScript),
`utf-8`
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this isn't currently used anywhere - should it be used?

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks ok to delete - the related code was removed in 7983e27#diff-917ba78a52f29b1a1fe42be34d81fc83

scripts
.slice(0)
.reverse()
Expand Down