Skip to content

Commit b110dc6

Browse files
authored
set up metro bundler for canvas (#1)
* clean up configs * fix resolutions, use vendorized metro-resolver that supports imports field in package.json * add polyfills for canvas
1 parent a5f6e87 commit b110dc6

File tree

6 files changed

+113
-202
lines changed

6 files changed

+113
-202
lines changed

apps/expo/metro.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ const config = getDefaultConfig(projectRoot)
1313

1414
// 1. Watch all files within the monorepo
1515
config.watchFolders = [workspaceRoot]
16+
1617
// 2. Let Metro know where to resolve packages and in what order
1718
config.resolver.nodeModulesPaths = [
1819
path.resolve(projectRoot, 'node_modules'),
1920
path.resolve(workspaceRoot, 'node_modules'),
2021
]
21-
// 3. Force Metro to resolve (sub)dependencies only from the `nodeModulesPaths`
22+
23+
// 3. Force Metro to resolve (sub)dependencies only from `nodeModulesPaths`
2224
config.resolver.disableHierarchicalLookup = true
2325

26+
// 4. Read the `exports` field, instead of just `main`, in package.json
27+
config.resolver.unstable_enablePackageExports = true
28+
2429
config.transformer = { ...config.transformer, unstable_allowRequireContext: true }
2530
config.transformer.minifierPath = require.resolve('metro-minify-terser')
2631

apps/expo/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@ipld/dag-cbor": "^9.2.2",
1717
"@libp2p/interface": "^2.2.0",
1818
"@my/ui": "0.0.1",
19+
"@react-native-masked-view/masked-view": "^0.3.2",
1920
"app": "0.0.0",
2021
"babel-plugin-module-resolver": "^5.0.2",
2122
"burnt": "^0.12.2",
@@ -49,9 +50,5 @@
4950
},
5051
"browser": {
5152
"crypto": false
52-
},
53-
"resolutions": {
54-
"metro": "git+ssh://[email protected]/facebook/metro.git#78db442",
55-
"metro-resolver": "git+ssh://[email protected]/facebook/metro.git#78db442"
5653
}
5754
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"react-dom": "^18.3.1",
2828
"react-refresh": "^0.14.0",
2929
"react-native-svg": "15.3.0",
30-
"react-native-web": "~0.19.12"
30+
"react-native-web": "~0.19.12",
31+
"metro": "0.81.0",
32+
"metro-resolver": "git+ssh://[email protected]/raykyri/metro.git#7a4c6a1854891387c77dbc7cfcb9ac9b4db475b5"
3133
},
3234
"dependencies": {
3335
"@babel/runtime": "^7.24.6",

packages/app/features/home/screen.tsx

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,50 @@ import { ChevronDown, ChevronUp, X } from '@tamagui/lucide-icons'
1919
import { useState } from 'react'
2020
import { Platform } from 'react-native'
2121
import { useLink } from 'solito/navigation'
22+
23+
import 'event-target-polyfill'
24+
import 'fast-text-encoding'
2225
import { useCanvas } from '@canvas-js/hooks'
2326

2427
export function HomeScreen({ pagesMode = false }: { pagesMode?: boolean }) {
2528
const linkTarget = pagesMode ? '/pages-example-user' : '/user'
2629

2730
const [itemHistory, setItemHistory] = useState([
28-
{ username: "max", user: "Max", item: "The Strokes" },
29-
{ username: "max", user: "Max", item: "The Inner Game of Tennis" },
30-
{ username: "raymond", user: "Raymond", item: "Designing Data-Driven Applications" },
31-
{ username: "raymond", user: "Raymond", item: "Intermezzo" },
31+
{ username: 'max', user: 'Max', item: 'The Strokes' },
32+
{ username: 'max', user: 'Max', item: 'The Inner Game of Tennis' },
33+
{ username: 'raymond', user: 'Raymond', item: 'Designing Data-Driven Applications' },
34+
{ username: 'raymond', user: 'Raymond', item: 'Intermezzo' },
3235
])
3336

3437
const { app } = useCanvas(null, {
3538
contract: {
3639
models: {
3740
profiles: {
38-
did: "primary",
39-
name: "string",
40-
items: "@items[]", // TODO
41-
image: "string?", // TODO
41+
did: 'primary',
42+
name: 'string',
43+
items: '@items[]', // TODO
44+
image: 'string?', // TODO
4245
},
4346
items: {
44-
id: "primary",
45-
name: "string",
46-
image: "string?",
47-
children: "@items[]", // TODO
48-
parent: "@items", // TODO
49-
}
47+
id: 'primary',
48+
name: 'string',
49+
image: 'string?',
50+
children: '@items[]', // TODO
51+
parent: '@items', // TODO
52+
},
5053
},
5154
actions: {
5255
createProfile(db, name) {
5356
const { did } = this
54-
db.create("profiles", { did, name, items: [], image: null })
57+
db.create('profiles', { did, name, items: [], image: null })
5558
},
5659
updateProfile(db, name) {
5760
const { did } = this
58-
db.update("profiles", { did, name })
59-
}
60-
}
61+
db.update('profiles', { did, name })
62+
},
63+
},
6164
},
62-
topic: "refs.canvas.xyz"
65+
topic: 'refs.canvas.xyz',
6366
})
6467

6568
return (
@@ -98,26 +101,32 @@ export function HomeScreen({ pagesMode = false }: { pagesMode?: boolean }) {
98101
const itemLinkProps = useLink({
99102
href: `${linkTarget}/${item.username}`,
100103
})
101-
104+
102105
return (
103-
<XStack
104-
key={index}
105-
gap="$3"
106-
ai="center"
107-
p="$2"
108-
br="$4"
109-
bw={1}
106+
<XStack
107+
key={index}
108+
gap="$3"
109+
ai="center"
110+
p="$2"
111+
br="$4"
112+
bw={1}
110113
borderColor="$gray8"
111114
pressStyle={{ opacity: 0.8 }}
112115
{...itemLinkProps}
113116
>
114117
<Avatar circular size="$3">
115118
<Avatar.Image source={{ uri: `https://i.pravatar.cc/150?u=${item.user}` }} />
116-
<Avatar.Fallback bc="$gray5"><Text>{item.user[0]}</Text></Avatar.Fallback>
119+
<Avatar.Fallback bc="$gray5">
120+
<Text>{item.user[0]}</Text>
121+
</Avatar.Fallback>
117122
</Avatar>
118123
<YStack>
119-
<Paragraph size="$3" fontWeight="bold">{item.user}</Paragraph>
120-
<Paragraph size="$2" col="$gray11">{item.item}</Paragraph>
124+
<Paragraph size="$3" fontWeight="bold">
125+
{item.user}
126+
</Paragraph>
127+
<Paragraph size="$2" col="$gray11">
128+
{item.item}
129+
</Paragraph>
121130
</YStack>
122131
</XStack>
123132
)

packages/app/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
"@tamagui/shorthands": "^1.116.12",
2121
"@tamagui/themes": "^1.116.12",
2222
"burnt": "^0.12.2",
23+
"event-target-polyfill": "^0.0.4",
2324
"expo-constants": "~16.0.2",
2425
"expo-linking": "~6.3.1",
26+
"fast-text-encoding": "^1.0.6",
2527
"react-native-safe-area-context": "4.10.4",
2628
"solito": "^4.2.2"
2729
},
2830
"devDependencies": {
31+
"@types/fast-text-encoding": "^1",
2932
"@types/react": "^18.3.3",
3033
"@types/react-native": "^0.73.0"
3134
}

0 commit comments

Comments
 (0)