Commit Graph

9 Commits

Author SHA1 Message Date
Joey Parrish ac6c0b44de fix: Fix loading with global "define" set to null
It seems that some websites have a global "define" object set to null.
This caused our module loader to break when Shaka Player was loaded.

By checking for "define" to have a "function" type, rather than just
being defined at all, we can avoid this problem.

Closes #2847

Change-Id: I645f61687b9ec298bcc51c8d128398cdad3dd3b9
2020-09-15 22:03:54 +00:00
Joey Parrish f539147d48 fix: Correct license headers in compiled output
This fixes all the license headers in the main library, which corrects
the appearance of the main license in the compiled output.

It seems that the `!` in the header forces the compiler to keep it in
the output.  I believe older compiler releases did this purely based
on `@license`.

Issue #2638

Change-Id: I7f0e918caad10c9af689c9d07672b7fe9be7b2f3
2020-06-09 16:05:09 -07:00
Joey Parrish 300ee8d623 Fix module wrapper to prevent conflicting exports
The module wrapper expects to be in charge of exporting to module
loaders, but so does eme-encryption-scheme-polyfill, which is compiled
into the bundle.  To resolve this, the wrapper can hide the "module"
symbol from the inner part of the bundle, preventing it from doing its
own exports.

In v2.5.x, this was hidden by an apparent compiler bug that resulted
in module.exports being renamed in the compiled bundle.  Since "Unfork
Closure base and update the compiler", Change-Id
I62ec61e82d4edf342b2c576c2d4f89f11562ee65, this is no longer the case.

Closes #2549

Change-Id: Id26002bc1c51ed423d77e7b3e7daf40b714b9f2f
2020-05-05 21:32:35 +00:00
Joey Parrish 1d27c295ee Fix output wrapper for Electron, ESM, and Closure
This updates our wrapper in several ways:
  - Adds comments and whitespace and meaningful variable names
  - Makes the CommonJS loader compatible with Electron, fixing #1463
  - Adds a "global" parameter to the inner scope, fixing #1455
  - Strips whitespace and comments from the wrapper during the build

The wrapper is much more readable and debuggable, which should help
maintain support for these various module loaders in the future.

Tested and working with the new wrapper:
  - CommonJS (NodeJS, etc.)
  - AMD (requirejs)
  - Electron (loads into global scope without loader, no longer
    conflicts with CommonJS)
  - ES modules (partially supported, loads into global scope)

Since the wrapper is now fixed in a way that avoids #1455 and
google/closure-compiler#2957, this also reverts
"Patch Closure Compiler to fix polyfill+wrapper",
commit 962ec0a22d.

Closes #1463

Change-Id: I5d3ac056cb8db04dc714afee0cb069f2a45a456d
2018-06-20 17:41:34 +00:00
Morten Vestergaard Hansen 68f9c76632 Added check for window (#1446)
If nodejs, use global as scope, else use window.

Closes #1445
2018-05-25 08:59:39 -07:00
Patrick Kunka 8743bcfcea Explicitly bind to window for ES5 strict mode compatibility (#1398) 2018-04-09 11:01:59 -07:00
Joey Parrish 3e7014db2b Fix library load and polyfill for old browsers
This will allow support-testing to work on older browsers so that
application developers can still load the library and query for
support to show an appropriate error message.

To accomplish this, we avoid load-time uses of Function.bind, avoid
certain polyfills if modern types are not available, and compile down
to ES3 to avoid errors caused by use of the reserved word "catch" on
Promises.

This has been tested back to IE6, Safari 5.1, iOS 6.0, Firefox 6,
Chrome 15, and Opera 16.

Change-Id: I9deed106a7736758e04452ef85bae40f37c6fe62
2015-12-10 10:49:45 -08:00
Jesper Haug Karsrud 316855e823 Check for define.amd along with typeof(define)
To prevent crashing with other module loaders that support `define`, but are not full AMD module loaders, check for `define.amd` as well before defining the AMD module.
2015-08-24 12:07:54 +02:00
Joey Parrish 5f3a153913 Refactor compilation wrappers.
The new wrapper has been tested using:
 * commonJS in node.js
 * requireJS in node.js
 * requireJS in a browser
 * directly in a browser

This also corrects the exports for commonJS to omit the "shaka"
namespace.  For example, you now get "module.exports.player" instead
of "module.exports.shaka.player".

Change-Id: Idf6b05d7d667aded925818001f730747ceeae2e9
2015-04-10 12:38:07 -07:00