Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .changeset/strip-metamask-sdk.md

This file was deleted.

86 changes: 86 additions & 0 deletions examples/basic-react-app/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import { defineOpenZeppelinAdapterViteConfig } from '@openzeppelin/adapters-vite';
// eventemitter3@5 is a dual package whose ESM entry (index.mjs) default-imports
// its own CJS build. Under Vite's dev optimizer the two halves get inconsistent
// CJS→ESM interop, so a wallet dep's `import EventEmitter from 'eventemitter3'`
// throws "does not provide an export named 'default'" and the app fails to init.
// Pinning every import to the ESM entry (which has an explicit `export default`)
// gives one consistent module. Resolved by absolute path because the package's
// `exports` map does not expose the `./index.mjs` subpath.
var require = createRequire(import.meta.url);
var eventemitter3EsmEntry = require.resolve('eventemitter3').replace(/index\.js$/, 'index.mjs');
var viteConfig = defineOpenZeppelinAdapterViteConfig({
ecosystems: ['evm', 'stellar'],
config: {
plugins: [react(), tailwindcss()],
define: {
// Polyfill for Node.js globals used by some wallet dependencies
global: 'globalThis',
},
resolve: {
// Prevent duplicate module instances (causes singleton issues)
dedupe: ['react', 'react-dom', '@openzeppelin/ui-utils', '@openzeppelin/ui-types'],
// Force eventemitter3 to its ESM entry so its default export is consistent
// across the wallet dependency graph in dev mode (see note above).
alias: {
eventemitter3: eventemitter3EsmEntry,
// WalletConnect was removed and its provider is stripped from the install
// tree, but @wagmi/connectors still ships an unreachable walletConnect
// module that dynamically imports it. Rollup resolves dynamic imports even
// when unreachable, so point it at a stub.
'@walletconnect/ethereum-provider': fileURLToPath(new URL('./src/shims/walletconnect-removed.ts', import.meta.url)),
// The MetaMask SDK is stripped from the install tree for licence reasons
// (proprietary, Non-Commercial Use only) and needs the same treatment:
// @wagmi/connectors re-exports an unreachable metaMask module that
// dynamically imports it.
'@metamask/sdk': fileURLToPath(new URL('./src/shims/metamask-removed.ts', import.meta.url)),
},
},
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
},
// Pre-bundle heavy dependencies upfront for faster page loads
include: [
'react',
'react-dom',
'react-dom/client',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'lucide-react',
'@web3icons/react',
'react-hook-form',
'zustand',
'zustand/shallow',
'sonner',
'next-themes',
'@tanstack/react-query',
'react-syntax-highlighter',
'react-syntax-highlighter/dist/esm/styles/prism',
'viem/chains',
'@rainbow-me/rainbowkit',
// Force pre-bundling of eventemitter3 via its package entry so Vite
// synthesizes a CJS→ESM default export. Without this, a wallet dep's
// `import EventEmitter from 'eventemitter3'` fails at runtime with
// "does not provide an export named 'default'". Requires the package to
// be resolvable from this app root (see the workspace-root .npmrc hoist).
'eventemitter3',
],
},
build: {
outDir: 'dist',
sourcemap: true,
target: 'esnext',
},
server: {
port: 3000,
open: true,
},
},
});
export default viteConfig;
33 changes: 33 additions & 0 deletions packages/dev-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# @openzeppelin/ui-dev-cli

## 1.3.0

### Minor Changes

- [#219](https://github.com/OpenZeppelin/openzeppelin-ui/pull/219) [`1c63230`](https://github.com/OpenZeppelin/openzeppelin-ui/commit/1c632305bfd4da5b06b8e2db7df1daf151182e84) Thanks [@pasevin](https://github.com/pasevin)! - The generated `.pnpmfile.cjs` now also strips `@metamask/sdk` from `@wagmi/connectors`,
alongside the existing WalletConnect and Trezor strips.

`@metamask/sdk` is not open source. It ships a proprietary licence — "Copyright ConsenSys
Software Inc. 2022. All rights reserved" — granting only a non-exclusive, non-transferable
licence for **Non-Commercial Use**, whose clause 2 requires any Resulting Program to carry that
same restriction forward. The OpenZeppelin adapters are AGPL-3.0, which forbids conveying the
work under added restrictions, so the two cannot both be satisfied.

The conflict is structural rather than a threshold question — it does not depend on any monthly
active user count — and there is no clean version to pin: no published version of
`@metamask/sdk` declares a `license` field at all. The same 2715-byte licence file ships in
`@metamask/sdk`, `@metamask/sdk-communication-layer` and `@metamask/sdk-install-modal-web`.

`@wagmi/connectors` declares `@metamask/sdk` as a **hard dependency**, not an optional peer, so
it installed whether or not a `metaMask()` connector was registered. Dropping the connector
alone is not sufficient, hence the hook.

The strip targets that one package name exactly, **not** the `@metamask/*` scope. Most of that
scope is MIT or ISC (`utils`, `providers`, `json-rpc-engine`, `rpc-errors`, `superstruct`,
`sdk-analytics`, …) and is legitimately required transitively; a scope-wide strip would break
far more than it fixes.

**Consumer repositories must regenerate their hook** (`oz-ui-dev init`, or by copying the
generated file) to pick this up, and will also need a bundler alias pointing `@metamask/sdk` at
a local stub — `@wagmi/connectors` re-exports an unreachable `metaMask` module containing
`await import('@metamask/sdk')`, and Rollup resolves dynamic imports at build time, so without
the alias the production build fails with "Rollup failed to resolve import".

## 1.2.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@openzeppelin/ui-dev-cli",
"private": false,
"version": "1.2.0",
"version": "1.3.0",
"description": "Shared local development CLI for OpenZeppelin UI consumer applications.",
"type": "module",
"bin": {
Expand Down
Loading