Skip to content

Commit a2caf44

Browse files
Verify npm packaging and test integrity (#18)
- Migrate deprecated Js.* APIs to new ReScript 12 builtins (Promise, Dict, Array, etc.) - Update @rescript/react to 0.14.0 with React 19 peer dependencies - Fix ReactDOM.Style.make -> inline style objects for new React bindings - Update rescript.json: bs-dependencies -> dependencies - Fix Promise API usage (then/catch argument order) - Fix typeof usage for Type.t variants - Add --no-check to Deno test script for npm module resolution - Optimize npm package files list (reduced from 1.9MB to 428KB) - Update main entry point to lib/es6/src/Tea.res.mjs Co-authored-by: Claude <noreply@anthropic.com>
1 parent fabbd56 commit a2caf44

17 files changed

Lines changed: 312 additions & 320 deletions

examples/01_counter/Counter.res

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,47 +48,50 @@ let update = (msg, model) => {
4848

4949
let view = (model, dispatch) => {
5050
<div
51-
style={ReactDOM.Style.make(
52-
~display="flex",
53-
~flexDirection="column",
54-
~alignItems="center",
55-
~gap="16px",
56-
~padding="32px",
57-
~fontFamily="system-ui, sans-serif",
58-
(),
59-
)}>
51+
style={{
52+
display: "flex",
53+
flexDirection: "column",
54+
alignItems: "center",
55+
gap: "16px",
56+
padding: "32px",
57+
fontFamily: "system-ui, sans-serif",
58+
}}
59+
>
6060
<h1> {React.string("Counter")} </h1>
6161
<div
62-
style={ReactDOM.Style.make(
63-
~display="flex",
64-
~alignItems="center",
65-
~gap="16px",
66-
(),
67-
)}>
62+
style={{
63+
display: "flex",
64+
alignItems: "center",
65+
gap: "16px",
66+
}}
67+
>
6868
<button
6969
onClick={_ => dispatch(Decrement)}
70-
style={ReactDOM.Style.make(~padding="8px 16px", ~fontSize="18px", ~cursor="pointer", ())}>
70+
style={{padding: "8px 16px", fontSize: "18px", cursor: "pointer"}}
71+
>
7172
{React.string("-")}
7273
</button>
7374
<span
74-
style={ReactDOM.Style.make(
75-
~fontSize="48px",
76-
~fontWeight="bold",
77-
~minWidth="80px",
78-
~textAlign="center",
79-
(),
80-
)}>
81-
{model.count->Belt.Int.toString->React.string}
75+
style={{
76+
fontSize: "48px",
77+
fontWeight: "bold",
78+
minWidth: "80px",
79+
textAlign: "center",
80+
}}
81+
>
82+
{model.count->Int.toString->React.string}
8283
</span>
8384
<button
8485
onClick={_ => dispatch(Increment)}
85-
style={ReactDOM.Style.make(~padding="8px 16px", ~fontSize="18px", ~cursor="pointer", ())}>
86+
style={{padding: "8px 16px", fontSize: "18px", cursor: "pointer"}}
87+
>
8688
{React.string("+")}
8789
</button>
8890
</div>
8991
<button
9092
onClick={_ => dispatch(Reset)}
91-
style={ReactDOM.Style.make(~padding="8px 24px", ~fontSize="14px", ~cursor="pointer", ())}>
93+
style={{padding: "8px 24px", fontSize: "14px", cursor: "pointer"}}
94+
>
9295
{React.string("Reset")}
9396
</button>
9497
</div>
@@ -124,6 +127,6 @@ let mount = () => {
124127
let rootElement = ReactDOM.Client.createRoot(root)
125128
rootElement->ReactDOM.Client.Root.render(<App flags=() />)
126129
}
127-
| None => Js.Console.error("Could not find #root element")
130+
| None => Console.error("Could not find #root element")
128131
}
129132
}

examples/02_http/HttpExample.res

Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ type remoteData<'a, 'e> =
2525
| Success('a)
2626
| Failure('e)
2727

28-
type model = {
29-
users: remoteData<array<user>, string>,
30-
}
28+
type model = {users: remoteData<array<user>, string>}
3129

3230
type msg =
3331
| FetchUsers
@@ -51,10 +49,7 @@ let usersDecoder: Json.decoder<array<user>> = Json.array(userDecoder)
5149
// Init
5250
// ============================================================================
5351

54-
let init = _ => (
55-
{users: NotAsked},
56-
Cmd.none,
57-
)
52+
let init = _ => ({users: NotAsked}, Cmd.none)
5853

5954
// ============================================================================
6055
// Update
@@ -63,15 +58,13 @@ let init = _ => (
6358
let update = (msg, model) => {
6459
switch msg {
6560
| FetchUsers => (
66-
{...model, users: Loading},
67-
Http.getJson(
68-
"https://jsonplaceholder.typicode.com/users",
69-
usersDecoder,
70-
result => GotUsers(result),
71-
),
61+
{users: Loading},
62+
Http.getJson("https://jsonplaceholder.typicode.com/users", usersDecoder, result => GotUsers(
63+
result,
64+
)),
7265
)
73-
| GotUsers(Ok(users)) => ({...model, users: Success(users)}, Cmd.none)
74-
| GotUsers(Error(err)) => ({...model, users: Failure(Http.errorToString(err))}, Cmd.none)
66+
| GotUsers(Ok(users)) => ({users: Success(users)}, Cmd.none)
67+
| GotUsers(Error(err)) => ({users: Failure(Http.errorToString(err))}, Cmd.none)
7568
}
7669
}
7770

@@ -81,46 +74,40 @@ let update = (msg, model) => {
8174

8275
let viewUser = (user: user) => {
8376
<div
84-
key={Belt.Int.toString(user.id)}
85-
style={ReactDOM.Style.make(
86-
~padding="12px",
87-
~marginBottom="8px",
88-
~backgroundColor="#f5f5f5",
89-
~borderRadius="4px",
90-
(),
91-
)}>
92-
<div style={ReactDOM.Style.make(~fontWeight="bold", ~marginBottom="4px", ())}>
93-
{React.string(user.name)}
94-
</div>
95-
<div style={ReactDOM.Style.make(~fontSize="14px", ~color="#666", ())}>
96-
{React.string(`@${user.username}`)}
97-
</div>
98-
<div style={ReactDOM.Style.make(~fontSize="14px", ~color="#888", ())}>
99-
{React.string(user.email)}
100-
</div>
77+
key={Int.toString(user.id)}
78+
style={{
79+
padding: "12px",
80+
marginBottom: "8px",
81+
backgroundColor: "#f5f5f5",
82+
borderRadius: "4px",
83+
}}
84+
>
85+
<div style={{fontWeight: "bold", marginBottom: "4px"}}> {React.string(user.name)} </div>
86+
<div style={{fontSize: "14px", color: "#666"}}> {React.string(`@${user.username}`)} </div>
87+
<div style={{fontSize: "14px", color: "#888"}}> {React.string(user.email)} </div>
10188
</div>
10289
}
10390

10491
let view = (model, dispatch) => {
10592
<div
106-
style={ReactDOM.Style.make(
107-
~maxWidth="600px",
108-
~margin="0 auto",
109-
~padding="20px",
110-
~fontFamily="system-ui, sans-serif",
111-
(),
112-
)}>
93+
style={{
94+
maxWidth: "600px",
95+
margin: "0 auto",
96+
padding: "20px",
97+
fontFamily: "system-ui, sans-serif",
98+
}}
99+
>
113100
<h1> {React.string("Users")} </h1>
114101
<button
115102
onClick={_ => dispatch(FetchUsers)}
116103
disabled={model.users == Loading}
117-
style={ReactDOM.Style.make(
118-
~padding="10px 20px",
119-
~fontSize="16px",
120-
~cursor="pointer",
121-
~marginBottom="20px",
122-
(),
123-
)}>
104+
style={{
105+
padding: "10px 20px",
106+
fontSize: "16px",
107+
cursor: "pointer",
108+
marginBottom: "20px",
109+
}}
110+
>
124111
{React.string(
125112
switch model.users {
126113
| Loading => "Loading..."
@@ -129,30 +116,27 @@ let view = (model, dispatch) => {
129116
)}
130117
</button>
131118
{switch model.users {
132-
| NotAsked =>
133-
<p style={ReactDOM.Style.make(~color="#666", ())}>
134-
{React.string("Click the button to fetch users")}
135-
</p>
119+
| NotAsked => <p style={{color: "#666"}}> {React.string("Click the button to fetch users")} </p>
136120
| Loading =>
137-
<div style={ReactDOM.Style.make(~textAlign="center", ~padding="40px", ())}>
121+
<div style={{textAlign: "center", padding: "40px"}}>
138122
<div> {React.string("Loading...")} </div>
139123
</div>
140124
| Success(users) =>
141125
<div>
142-
<p style={ReactDOM.Style.make(~color="#666", ~marginBottom="16px", ())}>
143-
{React.string(`Loaded ${Belt.Int.toString(Belt.Array.length(users))} users`)}
126+
<p style={{color: "#666", marginBottom: "16px"}}>
127+
{React.string(`Loaded ${Int.toString(Array.length(users))} users`)}
144128
</p>
145-
{users->Belt.Array.map(viewUser)->React.array}
129+
{users->Array.map(viewUser)->React.array}
146130
</div>
147131
| Failure(error) =>
148132
<div
149-
style={ReactDOM.Style.make(
150-
~color="#d32f2f",
151-
~padding="16px",
152-
~backgroundColor="#ffebee",
153-
~borderRadius="4px",
154-
(),
155-
)}>
133+
style={{
134+
color: "#d32f2f",
135+
padding: "16px",
136+
backgroundColor: "#ffebee",
137+
borderRadius: "4px",
138+
}}
139+
>
156140
<strong> {React.string("Error: ")} </strong>
157141
{React.string(error)}
158142
</div>
@@ -190,6 +174,6 @@ let mount = () => {
190174
let rootElement = ReactDOM.Client.createRoot(root)
191175
rootElement->ReactDOM.Client.Root.render(<App flags=() />)
192176
}
193-
| None => Js.Console.error("Could not find #root element")
177+
| None => Console.error("Could not find #root element")
194178
}
195179
}

package-lock.json

Lines changed: 5 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,33 @@
1616
"type": "git",
1717
"url": "https://gitlab.com/hyperpolymath/rescript-tea"
1818
},
19-
"main": "src/Tea.res.mjs",
19+
"main": "lib/es6/src/Tea.res.mjs",
20+
"files": [
21+
"src",
22+
"lib/es6/src",
23+
"lib/bs/src",
24+
"lib/bs/compiler-info.json",
25+
"lib/rescript.lock",
26+
"rescript.json",
27+
"README.adoc",
28+
"LICENSE.txt"
29+
],
2030
"scripts": {
2131
"build": "rescript",
2232
"clean": "rescript clean",
2333
"dev": "rescript -w",
24-
"test": "npx deno test --allow-read lib/es6/test/Tea_Cmd_test.res.mjs lib/es6/test/Tea_Json_test.res.mjs"
34+
"test": "npx deno test --no-check --allow-read lib/es6/test/Tea_Cmd_test.res.mjs lib/es6/test/Tea_Json_test.res.mjs"
2535
},
2636
"peerDependencies": {
27-
"@rescript/react": ">=0.12.0",
28-
"react": ">=18.0.0",
29-
"react-dom": ">=18.0.0",
37+
"@rescript/react": ">=0.14.0",
38+
"react": ">=19.0.0",
39+
"react-dom": ">=19.0.0",
3040
"rescript": ">=11.0.0"
3141
},
3242
"devDependencies": {
3343
"@rescript/react": "^0.14.0",
34-
"react": "^18.2.0",
35-
"react-dom": "^18.2.0",
44+
"react": "^19.0.0",
45+
"react-dom": "^19.0.0",
3646
"rescript": "^12.0.2"
3747
}
3848
}

rescript.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
}
2424
],
2525
"suffix": ".res.mjs",
26-
"bs-dependencies": [
26+
"dependencies": [
2727
"@rescript/react"
2828
],
29-
"bs-dev-dependencies": [],
29+
"dev-dependencies": [],
3030
"jsx": {
3131
"version": 4,
3232
"mode": "automatic"

0 commit comments

Comments
 (0)