Commit 3f9bc92d authored by Robert Knight's avatar Robert Knight

Fix module load error on pages defining `require`

There are two expressions which reference a global `require` function in
the Browserify prelude. Both of them need to be rewritten to use
`hypothesisRequire` instead. Previously only the first use was
rewritten, which worked as long as the page didn't define its own
`require` function. On https://qa.hypothes.is/search for example, h's
JavaScript bundles do.
parent 1eff5f68
...@@ -135,8 +135,8 @@ module.exports = function createBundle(config, buildOpts) { ...@@ -135,8 +135,8 @@ module.exports = function createBundle(config, buildOpts) {
.readFileSync(defaultPreludePath) .readFileSync(defaultPreludePath)
.toString() .toString()
.replace( .replace(
'var previousRequire = typeof require == "function" && require;', /typeof require == "function" && require/g,
`var previousRequire = typeof ${externalRequireName} == "function" && ${externalRequireName};` `typeof ${externalRequireName} == "function" && ${externalRequireName};`
); );
if (!prelude.includes(externalRequireName)) { if (!prelude.includes(externalRequireName)) {
throw new Error( throw new Error(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment