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

[wip] revert compling cache-dir and remove non standard code from cache-dir #6183

Merged
merged 11 commits into from
Jul 2, 2018
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pkgs = glob.sync(`./packages/*`).map(p => p.replace(/^\./, `<rootDir>`))

const reGatsby = /gatsby$/
const gatsbyDir = pkgs.find(p => reGatsby.exec(p))
const gatsbyBuildDirs = [`dist`, `cache-dir`].map(dir => path.join(gatsbyDir, dir))
const gatsbyBuildDirs = [`dist`].map(dir => path.join(gatsbyDir, dir))
const builtTestsDirs = pkgs.map(p => path.join(p, `__tests__`))

const ignoreDirs = [].concat(gatsbyBuildDirs, builtTestsDirs)
Expand Down
4 changes: 0 additions & 4 deletions packages/gatsby/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ node_modules

decls
dist
cache-dir

# Never ignore the src cache-dir (https://github.com/gatsbyjs/gatsby/pull/5863)
!/src/cache-dir
41 changes: 41 additions & 0 deletions packages/gatsby/cache-dir/__tests__/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
babelrc: false,
presets: [
[
"@babel/preset-env",
{
loose: true,
modules: false,
useBuiltIns: "usage",
shippedProposals: true,
targets: {
browsers: [">0.25%", "not dead"],
},
},
],
[
"@babel/preset-react",
{
useBuiltIns: true,
pragma: "React.createElement",
},
],
],
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
loose: true,
},
],
"@babel/plugin-syntax-dynamic-import",
[
"@babel/plugin-transform-runtime",
{
helpers: true,
regenerator: true,
polyfill: false,
},
],
],
}
30 changes: 30 additions & 0 deletions packages/gatsby/cache-dir/__tests__/minimal-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require(`path`)
const child = require(`child_process`)

it(`Builds cache-dir with minimal config`, done => {
const args = [
require.resolve(`@babel/cli/bin/babel.js`),
path.join(__dirname, `..`),
`--config-file`,
path.join(__dirname, `.babelrc`),
]

const spawn = child.spawn(process.execPath, args)

let stderr = ``
let stdout = ``

spawn.stderr.on(`data`, function (chunk) {
stderr += chunk
})

spawn.stdout.on(`data`, function (chunk) {
stdout += chunk
})

spawn.on(`close`, function () {
expect(stderr).toEqual(``)
expect(stdout).not.toEqual(``)
done()
})
}, 30000)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import PageRenderer from "./page-renderer"
import { StaticQueryContext } from "gatsby"
import socketIo, { getStaticQueryData, getPageQueryData } from "./socketIo"

const getPathFromProps = props => props.pageResources?.page?.path
const getPathFromProps = props =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why revert this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I don't need to revert this, I thought this needed something like transform-optional-chaining plugin. I'll re-check it.

Copy link
Contributor Author

@pieh pieh Jun 29, 2018

Choose a reason for hiding this comment

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

Yeah, so after reverting and running my WIP test ( pieh/gatsby@9a5b113...pieh:ie11-promise-test ) for this:

$ jest minimal-config
 FAIL  packages\gatsby\cache-dir\__tests__\minimal-config.js
  × Builds cache-dir with minimal config (913ms)

  ● Builds cache-dir with minimal config

    expect(received).toEqual(expected)

    Expected value to equal:
      ""
    Received:
      "{ SyntaxError: D:\\dev\\gatsby-v2\\packages\\gatsby\\cache-dir\\json-store.js: Support for the experimental syntax 'optionalChaining' isn't currently
enabled (7:54):

       5 | import socketIo, { getStaticQueryData, getPageQueryData } from \"./socketIo\"
       6 |
    >  7 | const getPathFromProps = props => props.pageResources?.page?.path
         |                                                      ^
       8 |
       9 | class JSONStore extends React.Component {
      10 |   constructor(props) {

    Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.

This was fine previously because I was applying same babel config used to build packages for cache-dir (which includes @babel/plugin-proposal-optional-chaining )

props.pageResources && props.pageResources.page
? props.pageResources.page.path
: undefined

class JSONStore extends React.Component {
constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
// @flow

type PrefetcherOptions = {
fetchNextResource: () => ?Promise,
}

module.exports = ({ fetchNextResource }: PrefetcherOptions) => {
module.exports = ({ fetchNextResource }) => {
let pagesLoading = []
let current = null
const clearCurrent = () => {
Expand Down
10 changes: 3 additions & 7 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
"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 @@ -179,17 +178,14 @@
"graphql": "^0.13.2"
},
"scripts": {
"build": "rimraf dist && rimraf cache-dir && npm-run-all -p build:*",
"build:cache-dir": "babel src/cache-dir --out-dir cache-dir",
"build": "rimraf dist && npm run build:src && npm run build:internal-plugins && npm run build:rawfiles",
"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__,**/cache-dir",
"build:src": "babel src --out-dir dist --source-maps --ignore **/gatsby-cli.js,**/raw_*,**/__tests__",
"clean-test-bundles": "find test/ -type f -name bundle.js* -exec rm -rf {} +",
"prepare": "cross-env NODE_ENV=production npm run build",
"test-coverage": "node_modules/.bin/nyc --reporter=lcov --reporter=text npm test",
"watch": "rimraf dist && rimraf cache-dir && mkdir dist && npm run build:internal-plugins && npm run build:rawfiles && npm-run-all -p watch:*",
"watch:cache-dir": "npm run build:cache-dir -- --watch",
"watch:src": "npm run build:src -- --watch"
"watch": "rimraf dist && mkdir dist && npm run build:internal-plugins && npm run build:rawfiles && npm run build:src -- --watch"
},
"types": "index.d.ts"
}
6 changes: 0 additions & 6 deletions packages/gatsby/src/cache-dir/.babelrc

This file was deleted.