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

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Jun 27, 2018

#5637 might be to aggressive to transpile it - right now @babel/preset-env doesn't know it needs to polyfill Promise used in cache-dir, which breaks runtime in ie 11 ( #6103 )

This attempt just removes flow types and move cache-dir to same place it was before.

closes #6103
closes #6102

@pieh
Copy link
Contributor Author

pieh commented Jun 27, 2018

/cc @KyleAMathews @jquense

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 27, 2018

Deploy preview for using-drupal ready!

Built with commit 9a5b113

https://deploy-preview-6183--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit fb8efee

https://deploy-preview-6183--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 27, 2018

Deploy preview for gatsbygram ready!

Built with commit 500886e

https://deploy-preview-6183--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit fb8efee

https://deploy-preview-6183--gatsbygram.netlify.com

@pieh
Copy link
Contributor Author

pieh commented Jun 27, 2018

Actually, because we don't use flow extensively in cache-dir, removing flow stuff manually from cache-dir would yield same result without need for "build" step for it - so I'll manually edit cache-dir to not contain flow and move it from src to root gatsby dir

@jquense
Copy link
Contributor

jquense commented Jun 27, 2018

It'd be cool if there was like an eslint plguin for only allowing stuff preset-env can compile, like nothing that isn't standardized or implemented

@pieh
Copy link
Contributor Author

pieh commented Jun 27, 2018

It'd be cool if there was like an eslint plguin for only allowing stuff preset-env can compile, like nothing that isn't standardized or implemented

I didn't find anything like that for eslint, but maybe we could add test to try to run babel on cache-dir with minimal config to catch changes that would add any non standard stuff?

@pieh
Copy link
Contributor Author

pieh commented Jun 27, 2018

@jquense how about something like pieh/gatsby@9a5b113...pieh:ie11-promise-test (proof of concept)
it would fail when there would be (for example) flow types:

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

  ● Builds cache-dir with minimal config

    expect(received).toEqual(expected)

    Expected value to equal:
      ""
    Received:
      "{ SyntaxError: D:\\dev\\gatsby-v2\\packages\\gatsby\\cache-dir\\prefetcher.js: Unexpected token, expected \";\" (3:5)

      1 | // @flow
      2 |
    > 3 | type PrefetcherOptions = {
        |      ^
      4 |   fetchNextResource: () => ?Promise,
      5 | }
      6 |
        at _class.raise (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:3893:15)
        at _class.unexpected (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:5222:16)
        at _class.semicolon (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:5206:40)
        at _class.parseExpressionStatement (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:7635:10)
        at _class.parseStatementContent (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:7234:19)
        at _class.parseStatement (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:7115:17)
        at _class.parseBlockOrModuleBlockBody (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:7666:23)
        at _class.parseBlockBody (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:7653:10)
        at _class.parseTopLevel (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:7080:10)
        at _class.parse (D:\\dev\\gatsby-v2\\node_modules\\@babel\\parser\\lib\\index.js:8466:17)
      pos: 17,
      loc: Position { line: 3, column: 5 },
      code: 'BABEL_PARSE_ERROR' }
    "

      26 |
      27 |   spawn.on(`close`, function () {
    > 28 |     expect(stderr).toEqual(``)
      29 |     expect(stdout).toEqual(
      30 |       expect.stringMatching(`Successfully compiled`),
      31 |     )

      at ChildProcess.<anonymous> (packages/gatsby/cache-dir/__tests__/minimal-config.js:28:20)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.695s

@pieh pieh changed the title [wip] don't transpile cache-dir, just remove flow types [wip] revert compling cache-dir and remove non standard code from cache-dir Jun 28, 2018
KyleAMathews
KyleAMathews previously approved these changes Jun 28, 2018
Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Looks good! This will fix #6102 as well once in.

@@ -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 )

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

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

🙏 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] IE 11 'Promise' is undefined error [v2] provide non-traspiled version of default-html.js to copy from
5 participants