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

feat: replace global with globalThis #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rtritto
Copy link

@rtritto rtritto commented Oct 5, 2024

globalThis references with compatibilities:

It's introduced from Node 12 (this plugin is Node >= 14) and it's the unified way to access the "global" object.

This has the benefit of making code more cross-platform and more consistent.

Old

  • window.foo; // Browser
  • self.foo; // Web Worker
  • global.foo; // Node.js

New

  • globalThis.foo;

Currently globalThis need to be pollyfilled in Karma context (tests fails).
I did these tries but didn't work:

  1. test directory

    // /test/polyfill-globalthis.js
    (function() {
      if (typeof globalThis === 'undefined') {
        globalThis = (function() {
          if (typeof self !== 'undefined') { return self; }
          if (typeof window !== 'undefined') { return window; }
          if (typeof global !== 'undefined') { return global; }
          throw new Error('Unable to locate global object');
        })();
      }
    })();
    // /test/karma.config.js
        files: [
    +     'test/polyfill-globalthis.js',
          'node_modules/video.js/dist/video-js.css',
          'dist/videojs-mobile-ui.css',
    
          'node_modules/sinon/pkg/sinon.js',
          'node_modules/video.js/dist/video.js',
          'test/dist/bundle.js'
        ],
  2. scripts directory

    // /scripts/polyfill-globalthis.js
    (function() {
      if (typeof globalThis === 'undefined') {
        globalThis = (function() {
          if (typeof self !== 'undefined') { return self; }
          if (typeof window !== 'undefined') { return window; }
          if (typeof global !== 'undefined') { return global; }
          throw new Error('Unable to locate global object');
        })();
      }
    })();
    // /scripts/karma.config.js
    -  const options = {};
    +  const options = {
    +    files: [
    +      'scripts/polyfill-globalthis.js',
    +      'node_modules/video.js/dist/video-js.css',
    +      'dist/*.css',
    +      'node_modules/sinon/pkg/sinon.js',
    +      'node_modules/video.js/dist/video.js',
    +      'test/dist/bundle.js'
    +    ]
    +  };

Copy link

netlify bot commented Oct 5, 2024

Deploy Preview for effervescent-moonbeam-e4210e failed.

Name Link
🔨 Latest commit 9029690
🔍 Latest deploy log https://app.netlify.com/sites/effervescent-moonbeam-e4210e/deploys/6701522c137f020008b8ae0c

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.

1 participant