• Robert Knight's avatar
    Use custom name for global `require` function · 047a34d0
    Robert Knight authored
    Browserify bundles that make their modules available for other bundles
    to consume define a global `require` function. This is then imported by
    other bundles and used to resolve module lookups.
    
    This `require` name can clash with web pages that use eg. `RequireJS`.
    Most of the time this isn't a problem because all of the page's own code
    has run by the time Hypothesis loads. If however the page loads
    additional scripts after Hypothesis has been loaded, they will end up
    finding Hypothesis's `require` instead of their own.
    
    This commit resolves the issue by renaming the global `require` function
    to `hypothesisRequire` in two steps:
    
     - The `externalRequireName` Browserify option changes the _exported_
       name.
     - A custom transform stream post-processes the Browserify bundle code
       to change the _imported_ name, since Browserify doesn't have an
       option for this itself.
    
    A small fix was needed to the `boot.js` script build to avoid stripping
    lines _after_ the sourcemap URL comment, instead of just that comment.
    
    Fixes #779
    047a34d0
Name
Last commit
Last update
.github Loading commit data...
docs Loading commit data...
images Loading commit data...
scripts Loading commit data...
src Loading commit data...
.babelrc Loading commit data...
.eslintignore Loading commit data...
.eslintrc Loading commit data...
.gitignore Loading commit data...
.npmignore Loading commit data...
.npmrc Loading commit data...
.travis.yml Loading commit data...
CHANGELOG.md Loading commit data...
CODE_OF_CONDUCT Loading commit data...
Jenkinsfile Loading commit data...
LICENSE Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
gulpfile.js Loading commit data...
package.json Loading commit data...
requirements-dev.in Loading commit data...
yarn.lock Loading commit data...