Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polyfill buffer for WalletConnect on RainbowKit #166

Merged
merged 6 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/protocol-frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<link href="/src/assets/favicon.png" rel="icon" type="image/svg+xml" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>Govrn</title>
<script>
window.global = window;
</script>
</head>
<body>
<div id="root"></div>
<script src="/src/main.tsx" type="module"></script>
<script>
window.global = window;
</script>
</body>
</html>
14 changes: 7 additions & 7 deletions apps/protocol-frontend/src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Polyfill stable language features. These imports will be optimized by `@babel/preset-env`.
*
* See: https://github.com/zloirock/core-js#babel
*/
import 'core-js/stable';
import 'regenerator-runtime/runtime';
scottrepreneur marked this conversation as resolved.
Show resolved Hide resolved
import { Buffer } from 'buffer';


window.Buffer = window.Buffer ?? Buffer;
window.process = window.process ?? { env: {} }; // Minimal process polyfill

export { };
44 changes: 15 additions & 29 deletions apps/protocol-frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
import GlobalPolyFill from '@esbuild-plugins/node-globals-polyfill';
import { defineConfig } from 'vite';
import { resolve } from 'path';
import tsconfigPaths from 'vite-tsconfig-paths';
import { viteExternalsPlugin } from 'vite-plugin-externals';

const externalPlugin = viteExternalsPlugin({
...{
electron: 'electron',
'electron-fetch': 'electron-fetch',
},
});

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
tsconfigPaths({
root: '../..',
}),
externalPlugin,
],
resolve: {
alias: {
stream: 'stream-browserify',
url: 'url-browserify',
http: 'http-browserify',
https: 'http-browserify',
process: 'process-es6',
'~~': resolve(__dirname, 'src'),
},
},
build: {
target: 'esnext',
commonjsOptions: {
transformMixedEsModules: true,
},
},
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis',
// my fix
'globalThis.process.env.NODE_ENV': 'development',
},
plugins: [
GlobalPolyFill({
process: true,
buffer: true,
}),
],
},
},
resolve: {
alias: {
process: 'process/browser',
stream: 'stream-browserify',
zlib: 'browserify-zlib',
util: 'util',
},
},
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@chakra-ui/react": "^1.8.8",
"@emotion/react": "^11.9.3",
"@emotion/styled": "^11.9.3",
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to grab your attention that this lib is not well maintained and have some issues.
You can find more here

https://github.com/remorses/esbuild-plugins/blob/63b1ee1f47c7b0deb46bd71ec13d4a538e443d4d/node-modules-polyfill/src/index.ts#L39-L44

Simply put: it just paste couple of imports to every file which can lead to complex implications.

CC: @alexkeating @jonathanprozzi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you seeing a viable solution within these? Should we log this as debt and revisit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't have a viable solution to suggest.
We need Keating & JP's input on that.

"@fontsource/inter": "^4.5.10",
"@graphprotocol/graph-ts": "^0.27.0",
"@graphql-codegen/cli": "^2.6.2",
Expand All @@ -34,7 +35,7 @@
"@nx-tools/nx-docker": "^2.3.0",
"@prisma/client": "^3.12.0",
"@qualifyze/airtable": "^2.0.1",
"@rainbow-me/rainbowkit": "^0.4.5",
"@rainbow-me/rainbowkit": "^0.4.7",
"@rollup/plugin-strip": "^2.1.0",
"@stablelib/random": "^1.0.1",
"@types/express-session": "^1.17.4",
Expand All @@ -48,6 +49,7 @@
"airtable": "^0.11.2",
"apg-js": "^4.1.2",
"axios": "^0.26.0",
"buffer": "^6.0.3",
"class-validator": "^0.13.2",
"cookie-session": "^2.0.0",
"core-js": "^3.6.5",
Expand Down Expand Up @@ -134,7 +136,7 @@
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "~5.10.0",
"@typescript-eslint/parser": "~5.10.0",
"@vitejs/plugin-react": "^1.2.0",
"@vitejs/plugin-react": "^1.3.0",
"babel-jest": "27.2.3",
"babel-loader": "8.1.0",
"buffer-es6": "^4.9.3",
Expand Down Expand Up @@ -172,7 +174,7 @@
"typescript": "^4.7.4",
"url-loader": "^3.0.0",
"url-polyfill": "^1.1.12",
"vite": "^2.8.0",
"vite": "^2.9.9",
"vite-plugin-eslint": "1.3.0"
}
}