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

chore: replace 'global' with 'globalThis' #701

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

bradenmacdonald
Copy link
Contributor

The global keyword is a non-standard NodeJS specific keyword. But since 2019, we can use globalThis instead, which works in every runtime. For example, globalThis has the same consistent meaning in both browsers and NodeJS, whereas global does not work in browsers unless you use some build process to rewrite it to window.

Details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#description

Example from Chrome console:
Screenshot of chrome browser console

@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 3, 2024
Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.41%. Comparing base (9d2e727) to head (d331922).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #701   +/-   ##
=======================================
  Coverage   83.41%   83.41%           
=======================================
  Files          40       40           
  Lines        1073     1073           
  Branches      197      197           
=======================================
  Hits          895      895           
  Misses        166      166           
  Partials       12       12           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

Seems reasonable. LGTM!

@adamstankiewicz adamstankiewicz merged commit 5c1b87d into openedx:master Jun 18, 2024
7 checks passed
@openedx-webhooks
Copy link

@bradenmacdonald 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@bradenmacdonald bradenmacdonald deleted the braden/remove-global branch June 18, 2024 17:11
@@ -3,6 +3,7 @@ const { getBaseConfig } = require('@openedx/frontend-build');

const config = getBaseConfig('eslint');

config.globals = { globalThis: 'readonly' };
Copy link
Member

Choose a reason for hiding this comment

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

@bradenmacdonald [curious] Lots of repos use global today; I'm wondering if we should update the base ESLint config defined in @openedx/frontend-build so each consuming shared JS library and/or MFE doesn't need to specify this config across many different repos. Curious your two cents.

On a similar note, I wonder if it'd be more acceptable to extend the shared ESLint config's env option to include es2020 so that other similar syntax is deemed acceptable as well? @openedx/frontend-build relies on the env defined in @edx/eslint-config here. Setting es2020 in env would in place of configuring the globals for globalThis explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm definitely in favor of setting es2020 in env as a default!

Copy link
Member

Choose a reason for hiding this comment

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

@bradenmacdonald Opened a PR to the base shared ESLint configuration (@edx/eslint-config): openedx/eslint-config#153

I believe having es2020 in there would eliminate the need to keep es6, since the environments (as far as I can tell) are cumulative/additive, where a later environment supersedes an earlier one. That said, I'm opting to keep es6 in there for now just in case that is not true.

Let me know your thoughts; will also share in FWG Slack :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants