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

fix: only access Node.js globals if available #3501

Merged
merged 2 commits into from
May 9, 2022

Conversation

n1ru4l
Copy link
Contributor

@n1ru4l n1ru4l commented Feb 15, 2022

The process object is only available in Node.js and Node.js-like environments (e.g. webpack).

By introducing this simple change, the code can run in a browser environment without requiring polyfilling Node.js APIs such as the following:

<script>
  window.process = globalThis.process = {
    env: {
      NODE_ENV: "development"
    }
  };
</script>

globalThis is part of the ECMA 2020 specification and is supported on any relevant platform.

The eslint config specifies ecma version 2020 but it seems like the globalThis is not automatically provided. I added the es2020 env. (eslint/eslint#15199 (comment))


Closes #2409

@github-actions
Copy link

The latest changes of this PR are available on NPM as
graphql@16.3.0-canary.pr.3501.1daccf7bfd7fe9ffeabb319f26aa1b9bf5133e4c
Note: no gurantees provided so please use your own discretion.

Also you can depend on latest version built from this PR:
npm install --save graphql@canary-pr-3501

.eslintrc.yml Outdated Show resolved Hide resolved
@netlify
Copy link

netlify bot commented Apr 11, 2022

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 23a59b3
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/6278a3acc985370009db0dd2
😎 Deploy Preview https://deploy-preview-3501--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@saihaj saihaj requested a review from yaacovCR April 11, 2022 14:44
Copy link
Contributor

@yaacovCR yaacovCR left a comment

Choose a reason for hiding this comment

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

To better telegraph the intent in the changelog, you could make this 2 PRs, one updating the eslint with these settings, and a following one with the then-allowed addition of globalThis.

Or, you could rebase these changes into 2 commits that do exactly just that, and then the changes could not be squashed.

But in my meager opinion, that would be gravy and I also approve as is. :)

@saihaj
Copy link
Member

saihaj commented May 8, 2022

@n1ru4l please rebase : )

@n1ru4l
Copy link
Contributor Author

n1ru4l commented May 9, 2022

@saihaj done 🎉

@saihaj saihaj merged commit 97c9512 into graphql:main May 9, 2022
@n1ru4l n1ru4l deleted the browser-compat branch May 9, 2022 12:48
IvanGoncharov added a commit to IvanGoncharov/graphql-js that referenced this pull request May 13, 2022
@IvanGoncharov IvanGoncharov added the PR: bug fix 🐞 requires increase of "patch" version number label May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bug fix 🐞 requires increase of "patch" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants