mirror of
https://github.com/privacy-scaling-explorations/emp-wasm.git
synced 2026-01-07 01:03:50 -05:00
fix nextjs by preventing static analysis of import
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "emp-wasm",
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "emp-wasm",
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ee-typed": "^0.1.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "emp-wasm",
|
||||
"version": "0.2.2",
|
||||
"version": "0.2.3",
|
||||
"description": "Wasm build of authenticated garbling from [emp-toolkit/emp-ag2pc](https://github.com/emp-toolkit/emp-ag2pc).",
|
||||
"type": "module",
|
||||
"main": "dist/src/ts/index.js",
|
||||
|
||||
@@ -111,6 +111,8 @@ async function fixEmscriptenCode(gitRoot: string) {
|
||||
const path = join(gitRoot, 'dist/build/jslib.js');
|
||||
let content = await fs.readFile(path, 'utf-8');
|
||||
|
||||
content = `function echo(x) { return x; }\n${content}`;
|
||||
|
||||
content = replace(
|
||||
content,
|
||||
['function intArrayFromBase64(s) { if (typeof ENVIRONMENT_IS_NODE'],
|
||||
@@ -134,14 +136,17 @@ async function fixEmscriptenCode(gitRoot: string) {
|
||||
// This doesn't really affect behavior, but it fixes a nextjs issue where
|
||||
// it analyzes the require statically and fails even when the code works as
|
||||
// a whole.
|
||||
// FIXME: I can no longer reproduce nextjs failing without this replacement.
|
||||
// It's easier to just leave it in for now but in future this should help
|
||||
// motivate its removal if nextjs still doesn't seem to need it anymore.
|
||||
'var fs=(()=>{try{return require("fs")}catch(e){throw e}})();'
|
||||
);
|
||||
|
||||
// For deno compatibility
|
||||
// For deno and nextjs compatibility
|
||||
content = replace(
|
||||
content,
|
||||
['import("module")', "import('module')"],
|
||||
'import("node:module")',
|
||||
'import(echo("node:module"))',
|
||||
);
|
||||
|
||||
await fs.writeFile(path, content);
|
||||
|
||||
Reference in New Issue
Block a user