Skip to content

Commit df46f86

Browse files
vveerrggclaude
andcommitted
fix(deps): replace webpack with esbuild for browser bundling
Eliminates serialize-javascript RCE vulnerability (transitive via webpack → terser-webpack-plugin). IIFE format with globalName is functionally equivalent to UMD for script-tag usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0f31dc3 commit df46f86

6 files changed

Lines changed: 113 additions & 1628 deletions

File tree

dist/browser/nostr-nsec-seedphrase.min.js

Lines changed: 43 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/nostr-nsec-seedphrase.min.js.map

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esbuild.browser.mjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { build } from 'esbuild';
2+
import path from 'path';
3+
4+
// Plugin to stub Node builtins that aren't needed in browser
5+
const emptyNodeBuiltins = {
6+
name: 'empty-node-builtins',
7+
setup(build) {
8+
const builtins = ['crypto', 'stream', 'os', 'fs', 'http', 'https',
9+
'util', 'zlib', 'vm', 'assert', 'net', 'tls', 'child_process'];
10+
const filter = new RegExp(`^(${builtins.join('|')})$`);
11+
12+
build.onResolve({ filter }, (args) => ({
13+
path: args.path,
14+
namespace: 'empty-node-builtin',
15+
}));
16+
17+
build.onLoad({ filter: /.*/, namespace: 'empty-node-builtin' }, () => ({
18+
contents: 'export default {};',
19+
loader: 'js',
20+
}));
21+
},
22+
};
23+
24+
const result = await build({
25+
entryPoints: ['src/browser.ts'],
26+
bundle: true,
27+
minify: true,
28+
sourcemap: true,
29+
format: 'iife',
30+
globalName: 'NostrNsecSeedphrase',
31+
outfile: 'dist/browser/nostr-nsec-seedphrase.min.js',
32+
target: ['es2020'],
33+
platform: 'browser',
34+
alias: {
35+
// Force CJS build of nostr-crypto-utils (its ESM output lacks .mjs extensions)
36+
'nostr-crypto-utils': path.resolve('node_modules/nostr-crypto-utils/dist/cjs/index.js'),
37+
},
38+
define: {
39+
'process.env.NODE_ENV': '"production"',
40+
'global': 'globalThis',
41+
},
42+
plugins: [emptyNodeBuiltins],
43+
metafile: true,
44+
});
45+
46+
const output = Object.entries(result.metafile.outputs)
47+
.filter(([k]) => k.endsWith('.js'))
48+
.map(([k, v]) => `${k}: ${(v.bytes / 1024).toFixed(1)}KB`);
49+
console.log('Browser bundle built:', output.join(', '));

0 commit comments

Comments
 (0)