Skip to content

Commit da39ce8

Browse files
committed
Patch eval calls from emscripten code to use an indirect call enabling bundlers to better minify
1 parent 532fdff commit da39ce8

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const indirectEval = (globalThis || window).eval;
2+
export { indirectEval as eval };

packages/pglite/tsup.config.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
import { defineConfig } from 'tsup'
2-
import path from 'path'
3-
import { fileURLToPath } from 'url'
1+
import { defineConfig } from "tsup";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
44

5-
const thisFile = fileURLToPath(new URL(import.meta.url))
6-
const root = path.dirname(thisFile)
5+
const thisFile = fileURLToPath(new URL(import.meta.url));
6+
const root = path.dirname(thisFile);
77

88
let replaceAssertPlugin = {
9-
name: 'replace-assert',
9+
name: "replace-assert",
1010
setup(build: any) {
1111
// Resolve `assert` to a blank file
1212
build.onResolve({ filter: /^assert$/ }, (args: any) => {
13-
return { path: path.join(root, 'src', 'polyfills', 'blank.ts') }
14-
})
13+
return { path: path.join(root, "src", "polyfills", "blank.ts") };
14+
});
1515
},
16-
}
16+
};
1717

1818
const entryPoints = [
19-
'src/index.ts',
20-
'src/worker/index.ts',
21-
'src/worker/process.ts',
22-
'src/vector/index.ts',
23-
]
19+
"src/index.ts",
20+
"src/worker/index.ts",
21+
"src/worker/process.ts",
22+
"src/vector/index.ts",
23+
];
2424

2525
export default defineConfig({
2626
entry: entryPoints,
2727
sourcemap: true,
2828
dts: {
2929
entry: entryPoints,
30-
resolve: true
30+
resolve: true,
3131
},
3232
clean: true,
33-
format: ['esm'],
33+
format: ["esm"],
3434
esbuildOptions(options, context) {
35-
options.inject = ['src/polyfills/buffer.ts']
35+
options.inject = [
36+
"src/polyfills/buffer.ts",
37+
"src/polyfills/indirectEval.ts",
38+
];
3639
},
37-
esbuildPlugins: [
38-
replaceAssertPlugin,
39-
],
40+
esbuildPlugins: [replaceAssertPlugin],
4041
minify: true,
41-
})
42+
});

0 commit comments

Comments
 (0)