Commit ccdf1e75 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: convert to commonjs (#3373)

* chore: use fully specified path for non-main imports

* chore: convert to commonjs

- Pin @web3-react to exact cjs versions

* chore: bump to v0.0.18-beta

* chore: fix fonts.css comment

* fix: @ethersproject/providers version skew

* fix: @web3-react state typings
parent c9faafee
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
], ],
"webpack": { "webpack": {
"configPath": "react-scripts/config/webpack.config", "configPath": "react-scripts/config/webpack.config",
"overridePath": "cosmos.override.cjs" "overridePath": "cosmos.override.js"
}, },
"port": 5001 "port": 5001
} }
\ No newline at end of file
{ {
"name": "@uniswap/widgets", "name": "@uniswap/widgets",
"version": "0.0.15-beta", "version": "0.0.18-beta",
"description": "Uniswap Interface", "description": "Uniswap Interface",
"homepage": ".", "homepage": ".",
"type": "module",
"files": [ "files": [
"lib", "lib",
"dist" "dist"
], ],
"exports": { "exports": {
".": { ".": {
"types": "./dist/widgets.d.ts", "types": "./dist/widgets.d.ts",
"import": "./dist/widgets.esm.js", "import": "./dist/widgets.cjs",
"require": "./dist/widgets.js" "require": "./dist/widgets.cjs"
}, },
"./fonts.css": { "./fonts.css": {
"import": "./dist/fonts.css", "import": "./dist/fonts.css",
...@@ -20,8 +19,6 @@ ...@@ -20,8 +19,6 @@
} }
}, },
"types": "./dist/widgets.d.ts", "types": "./dist/widgets.d.ts",
"module": "./dist/widgets.esm.js",
"main": "./dist/widgets.js",
"devDependencies": { "devDependencies": {
"@babel/plugin-transform-runtime": "^7.17.0", "@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11", "@babel/preset-env": "^7.16.11",
...@@ -83,8 +80,8 @@ ...@@ -83,8 +80,8 @@
"@uniswap/v2-periphery": "^1.1.0-beta.0", "@uniswap/v2-periphery": "^1.1.0-beta.0",
"@uniswap/v3-core": "1.0.0", "@uniswap/v3-core": "1.0.0",
"@uniswap/v3-periphery": "^1.1.1", "@uniswap/v3-periphery": "^1.1.1",
"@web3-react/metamask": "8.0.16-alpha.0", "@web3-react/metamask": "8.0.10-beta.0",
"@web3-react/walletconnect": "8.0.16-alpha.0", "@web3-react/walletconnect": "8.0.15-beta.0",
"array.prototype.flat": "^1.2.4", "array.prototype.flat": "^1.2.4",
"array.prototype.flatmap": "^1.2.4", "array.prototype.flatmap": "^1.2.4",
"babel-plugin-macros": "^3.1.0", "babel-plugin-macros": "^3.1.0",
...@@ -166,7 +163,7 @@ ...@@ -166,7 +163,7 @@
"prepublishOnly": "yarn widgets:build", "prepublishOnly": "yarn widgets:build",
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test --env=./custom-test-env.cjs", "test": "react-scripts test --env=./custom-test-env.js",
"test:e2e": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run --record'", "test:e2e": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run --record'",
"widgets:start": "cosmos", "widgets:start": "cosmos",
"widgets:build": "rollup --config --failAfterWarnings --configPlugin typescript2" "widgets:build": "rollup --config --failAfterWarnings --configPlugin typescript2"
...@@ -196,7 +193,7 @@ ...@@ -196,7 +193,7 @@
"@ethersproject/contracts": "^5.4.1", "@ethersproject/contracts": "^5.4.1",
"@ethersproject/experimental": "^5.4.0", "@ethersproject/experimental": "^5.4.0",
"@ethersproject/hash": "^5.4.0", "@ethersproject/hash": "^5.4.0",
"@ethersproject/providers": "5.4.0", "@ethersproject/providers": "^5.4.0",
"@ethersproject/solidity": "^5.4.0", "@ethersproject/solidity": "^5.4.0",
"@ethersproject/strings": "^5.4.0", "@ethersproject/strings": "^5.4.0",
"@ethersproject/units": "^5.4.0", "@ethersproject/units": "^5.4.0",
...@@ -215,11 +212,11 @@ ...@@ -215,11 +212,11 @@
"@uniswap/token-lists": "^1.0.0-beta.27", "@uniswap/token-lists": "^1.0.0-beta.27",
"@uniswap/v2-sdk": "^3.0.1", "@uniswap/v2-sdk": "^3.0.1",
"@uniswap/v3-sdk": "^3.8.2", "@uniswap/v3-sdk": "^3.8.2",
"@web3-react/core": "8.0.16-alpha.0", "@web3-react/core": "8.0.14-beta.0",
"@web3-react/eip1193": "8.0.16-alpha.0", "@web3-react/eip1193": "8.0.9-beta.0",
"@web3-react/empty": "8.0.17-alpha.0", "@web3-react/empty": "8.0.7-beta.0",
"@web3-react/types": "8.0.16-alpha.0", "@web3-react/types": "8.0.7-beta.0",
"@web3-react/url": "8.0.17-alpha.0", "@web3-react/url": "8.0.9-beta.0",
"ajv": "^6.12.3", "ajv": "^6.12.3",
"cids": "^1.0.0", "cids": "^1.0.0",
"immer": "^9.0.6", "immer": "^9.0.6",
......
...@@ -51,7 +51,7 @@ const plugins = [ ...@@ -51,7 +51,7 @@ const plugins = [
// Source code transformation // Source code transformation
replace({ ...REPLACEMENTS, preventAssignment: true }), replace({ ...REPLACEMENTS, preventAssignment: true }),
json(), // imports json; doing so type-checking allows the json to be type-checked json(), // imports json as ES6; doing so enables type-checking and module resolution
] ]
const check = { const check = {
...@@ -76,23 +76,18 @@ const transpile = { ...@@ -76,23 +76,18 @@ const transpile = {
input: 'src/lib/index.tsx', input: 'src/lib/index.tsx',
output: [ output: [
{ {
file: 'dist/widgets.js', file: 'dist/widgets.cjs',
format: 'cjs', format: 'cjs',
sourcemap: true, sourcemap: true,
}, },
{
file: 'dist/widgets.esm.js',
format: 'esm',
sourcemap: true,
},
], ],
plugins: [ plugins: [
...plugins, ...plugins,
// Source code transformation // Source code transformation
url({ include: ASSET_EXTENSIONS.map((extname) => '**/*' + extname) }), // imports assets as data URIs url({ include: ASSET_EXTENSIONS.map((extname) => '**/*' + extname), limit: Infinity }), // imports assets as data URIs
svgr({ exportType: 'named', svgo: false }), // imports svgs as React components svgr({ exportType: 'named', svgo: false }), // imports svgs as React components
sass({ output: 'dist/fonts.css' }), // generates widgets.css sass({ output: 'dist/fonts.css' }), // generates fonts.css
commonjs(), // transforms cjs dependencies into tree-shakeable ES modules commonjs(), // transforms cjs dependencies into tree-shakeable ES modules
babel({ babel({
......
import { Token } from '@uniswap/sdk-core' import { Token } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains' import { SupportedChainId } from 'constants/chains'
import uriToHttp from 'lib/utils/uriToHttp' import uriToHttp from 'lib/utils/uriToHttp'
import Vibrant from 'node-vibrant/lib/bundle' import Vibrant from 'node-vibrant/lib/bundle.js'
import { shade } from 'polished' import { shade } from 'polished'
import { useLayoutEffect, useState } from 'react' import { useLayoutEffect, useState } from 'react'
import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo' import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo'
......
import { initializeConnector, Web3ReactHooks } from '@web3-react/core' import { initializeConnector } from '@web3-react/core'
import { EIP1193 } from '@web3-react/eip1193' import { EIP1193 } from '@web3-react/eip1193'
import { Actions, Connector, Provider as Eip1193Provider } from '@web3-react/types' import { Actions, Connector, Provider as Eip1193Provider } from '@web3-react/types'
import { Url } from '@web3-react/url' import { Url } from '@web3-react/url'
import { SetStateAction } from 'jotai' import { SetStateAction } from 'jotai'
import { RESET, useUpdateAtom } from 'jotai/utils' import { RESET, useUpdateAtom } from 'jotai/utils'
import { injectedAtom, urlAtom } from 'lib/state/web3' import { injectedAtom, urlAtom, Web3ReactState } from 'lib/state/web3'
import { ReactNode, useEffect } from 'react' import { ReactNode, useEffect } from 'react'
interface Web3ProviderProps { interface Web3ProviderProps {
...@@ -16,12 +16,13 @@ interface Web3ProviderProps { ...@@ -16,12 +16,13 @@ interface Web3ProviderProps {
function useConnector<T extends { new (actions: Actions, initializer: I): Connector }, I>( function useConnector<T extends { new (actions: Actions, initializer: I): Connector }, I>(
Connector: T, Connector: T,
initializer: I | undefined, initializer: I | undefined,
setContext: (update: typeof RESET | SetStateAction<[Connector, Web3ReactHooks]>) => void setContext: (update: typeof RESET | SetStateAction<Web3ReactState>) => void
) { ) {
return useEffect(() => { return useEffect(() => {
if (initializer) { if (initializer) {
const [connector, hooks] = initializeConnector((actions) => new Connector(actions, initializer)) const state = initializeConnector((actions) => new Connector(actions, initializer))
setContext([connector, hooks]) state[0].activate()
setContext(state)
} else { } else {
setContext(RESET) setContext(RESET)
} }
......
import { Currency } from '@uniswap/sdk-core' import { Currency } from '@uniswap/sdk-core'
import { useTheme } from 'lib/theme' import { useTheme } from 'lib/theme'
import Vibrant from 'node-vibrant/lib/bundle' import Vibrant from 'node-vibrant/lib/bundle.js'
import { useEffect, useLayoutEffect, useState } from 'react' import { useEffect, useLayoutEffect, useState } from 'react'
import useCurrencyLogoURIs from './useCurrencyLogoURIs' import useCurrencyLogoURIs from './useCurrencyLogoURIs'
......
import { initializeConnector, Web3ReactHooks } from '@web3-react/core' import { initializeConnector, Web3ReactHooks } from '@web3-react/core'
import { EMPTY } from '@web3-react/empty' import { EMPTY } from '@web3-react/empty'
import { Connector } from '@web3-react/types' import { Connector, Web3ReactStore } from '@web3-react/types'
import { atomWithDefault } from 'jotai/utils' import { atomWithDefault } from 'jotai/utils'
const EMPTY_CONNECTOR = initializeConnector(() => EMPTY) export type Web3ReactState = [Connector, Web3ReactHooks, Web3ReactStore]
export type Web3ReactState = [Connector, Web3ReactHooks] const EMPTY_CONNECTOR = initializeConnector(() => EMPTY)
export const urlAtom = atomWithDefault<Web3ReactState>(() => EMPTY_CONNECTOR) export const urlAtom = atomWithDefault<Web3ReactState>(() => EMPTY_CONNECTOR)
export const injectedAtom = atomWithDefault<Web3ReactState>(() => EMPTY_CONNECTOR) export const injectedAtom = atomWithDefault<Web3ReactState>(() => EMPTY_CONNECTOR)
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment