mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-11-22 06:09:55 +00:00
build(web,sign): drop vite-plugin-node-polyfills and its elliptic dependency (#70)
vite-plugin-node-polyfills depends on node-stdlib-browser, which always installs crypto-browserify -> browserify-sign/create-ecdh -> elliptic (GHSA-848j-6mx2-7j84, no patched release). No module in either bundle ever imported the crypto polyfill; what the plugin actually provided was three injected globals and the `events` alias. sign: the only call sites were @pezkuwi/x-global (`global`, after a globalThis check), shared/lib env helpers (`process`, typeof-guarded) and bn.js's optional Buffer probe (try/catch; BN#toBuffer has no callers). The plugin, the process shim alias and the `buffer` pre-bundle entry are removed outright. web: WalletConnect calls `Buffer.from` unguarded and imports `events`, so the globals are still needed. src/lib/node-globals.ts now provides Buffer/global/process, injected as scoped imports by @rollup/plugin-inject in the build and by esbuild's inject in the dev pre-bundle - the same 18 modules the plugin injected into, and still nothing written onto globalThis. `events` becomes a direct dependency. The unused shim files, the vitest shim aliases and the `elliptic` override are removed.
This commit is contained in:
1 parent
d703331d85
commit
11fbe41a8a
16 files changed
+62
-3079
No files matched your search
Generated
+1
-1905
File diff suppressed because it is too large.
Load diff
+1
-2
@@ -26,7 +26,6 @@
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react-swc": "^3.5.0",
|
||||
"typescript": "^5.6.3",
|
||||
"vite": "^6.4.5",
|
||||
"vite-plugin-node-polyfills": "^0.25.0"
|
||||
"vite": "^6.4.5"
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// Production Rollup alias for vite-plugin-node-polyfills/shims/process (mirrors web/'s copy -
|
||||
// see its comment for why: Rollup can't resolve the plugin's virtual module during a real
|
||||
// build, only in dev). IMPORTANT: must not reference the `process` identifier at runtime -
|
||||
// vite-plugin-node-polyfills rewrites it to `__process_polyfill`, creating a circular TDZ. Use
|
||||
// bracket notation so the plugin leaves this file alone.
|
||||
const g: Record<string, unknown> =
|
||||
typeof globalThis !== 'undefined' ? (globalThis as Record<string, unknown>)
|
||||
: typeof window !== 'undefined' ? (window as unknown as Record<string, unknown>)
|
||||
: {};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export default (g['process'] ?? { env: {} }) as any;
|
||||
+6
-17
@@ -1,41 +1,30 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react-swc';
|
||||
import path from 'path';
|
||||
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||
|
||||
// Deliberately minimal compared to web/vite.config.ts: this app has exactly one job (gate +
|
||||
// sign multisig operations), so it carries none of web/'s SPA routing, i18n, or UI-kit
|
||||
// machinery - fewer dependencies is itself a security property for a signing-critical site.
|
||||
export default defineConfig(({ command }) => ({
|
||||
export default defineConfig({
|
||||
server: {
|
||||
host: '::',
|
||||
port: 8090,
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
nodePolyfills({
|
||||
globals: { Buffer: true, global: true, process: true },
|
||||
protocolImports: true,
|
||||
}),
|
||||
],
|
||||
// No Node polyfills: nothing here imports a Node builtin, and the few dependency call sites
|
||||
// that touch `global`/`process`/`Buffer` all guard with a typeof check first.
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
mainFields: ['browser', 'module', 'main', 'exports'],
|
||||
alias: {
|
||||
// Rollup cannot resolve the plugin's virtual shim module in production - alias to a real
|
||||
// file (mirrors web/vite.config.ts's identical workaround). Dev mode leaves the plugin's
|
||||
// own virtual module handling it.
|
||||
...(command === 'build'
|
||||
? { 'vite-plugin-node-polyfills/shims/process': path.resolve(__dirname, './src/lib/process-shim.ts') }
|
||||
: {}),
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
'@pezkuwi/lib': path.resolve(__dirname, '../shared/lib'),
|
||||
},
|
||||
dedupe: ['react', '@pezkuwi/util-crypto', '@pezkuwi/util', '@pezkuwi/api', '@pezkuwi/extension-dapp', '@pezkuwi/keyring'],
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: ['@pezkuwi/util-crypto', '@pezkuwi/util', '@pezkuwi/api', '@pezkuwi/extension-dapp', '@pezkuwi/keyring', 'buffer'],
|
||||
include: ['@pezkuwi/util-crypto', '@pezkuwi/util', '@pezkuwi/api', '@pezkuwi/extension-dapp', '@pezkuwi/keyring'],
|
||||
},
|
||||
build: {
|
||||
chunkSizeWarningLimit: 600,
|
||||
},
|
||||
}));
|
||||
});
|
||||
Reference in new issue
Block a user