Skip to content

Commit 24c8de1

Browse files
committed
ci: wip add script to install, build, and typecheck examples
Signed-off-by: Logan McAnsh <[email protected]>
1 parent dd6ee55 commit 24c8de1

File tree

17 files changed

+311
-49
lines changed

17 files changed

+311
-49
lines changed

.github/workflows/changed.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Typecheck changed examples
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
typecheck:
11+
if: github.repository == 'remix-run/examples'
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: 🛑 Cancel Previous Runs
16+
uses: styfle/[email protected]
17+
18+
- name: ⬇️ Checkout repo
19+
uses: actions/checkout@v3
20+
21+
- name: ⎔ Setup node
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version-file: ".nvmrc"
25+
cache: "yarn"
26+
27+
- name: 📥 Install deps
28+
run: yarn --frozen-lockfile
29+
30+
- name: install, build, typecheck
31+
run: node ./scripts/test.mjs

dataloader/app/data.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
interface User {
1+
export interface User {
22
id: string;
33
email: string;
44
name: string;

dataloader/app/loaders/userLoader.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { DataFunctionArgs } from "@remix-run/node";
12
import DataLoader from "dataloader";
23

34
import { db } from "~/data.server";
45

56
export const createUsersByIdLoader = () =>
67
new DataLoader(async (ids: Readonly<string[]>) => {
7-
const users = await db.user.findMany({
8+
const users = db.user.findMany({
89
where: {
910
id: {
1011
in: ids,
@@ -14,3 +15,11 @@ export const createUsersByIdLoader = () =>
1415
const userMap = new Map(users.map((user) => [user.id, user]));
1516
return ids.map((id) => userMap.get(id) ?? null);
1617
});
18+
19+
export interface DataLoaderArgs extends DataFunctionArgs {
20+
context: {
21+
loaders: {
22+
usersById: ReturnType<typeof createUsersByIdLoader>;
23+
};
24+
};
25+
}

dataloader/app/routes/users.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import type { LoaderArgs } from "@remix-run/node";
21
import { json } from "@remix-run/node";
32
import { Outlet, useLoaderData } from "@remix-run/react";
3+
import { User } from "~/data.server";
4+
import { DataLoaderArgs } from "~/loaders/userLoader";
45

5-
export const loader = async ({ context }: LoaderArgs) => {
6+
export const loader = async ({ context }: DataLoaderArgs) => {
67
const users = await context.loaders.usersById.loadMany([
78
"ef3fcb93-0623-4d10-adbf-4dd865d6688c",
89
"2cbad877-2da6-422d-baa6-c6a96a9e085f",
910
]);
10-
return json({ users });
11+
return json({ users: users.filter((u): u is User => !!u) });
1112
};
1213

1314
export default function UserNames() {

dataloader/app/routes/users/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { LoaderArgs } from "@remix-run/node";
21
import { json } from "@remix-run/node";
32
import { useLoaderData } from "@remix-run/react";
3+
import { DataLoaderArgs } from "~/loaders/userLoader";
44

5-
export const loader = async ({ context }: LoaderArgs) => {
5+
export const loader = async ({ context }: DataLoaderArgs) => {
66
/*
77
* For demo purposes:
88
* Batching & caching also works with multiple calls to `DataLoader#load`

dataloader/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
"cross-env": "^7.0.3",
1717
"dataloader": "^2.0.0",
1818
"express": "^4.17.3",
19-
"morgan": "^1.10.0",
2019
"isbot": "^3.6.5",
20+
"morgan": "^1.10.0",
2121
"react": "^18.2.0",
2222
"react-dom": "^18.2.0"
2323
},
2424
"devDependencies": {
2525
"@remix-run/dev": "*",
2626
"@remix-run/eslint-config": "*",
27+
"@types/compression": "1.7.2",
28+
"@types/express": "4.17.15",
29+
"@types/morgan": "1.9.3",
2730
"@types/react": "^18.0.25",
2831
"@types/react-dom": "^18.0.8",
2932
"esbuild-register": "^3.3.2",

dataloader/server/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const path = require("path");
1+
import path from "path";
22

3-
const express = require("express");
4-
const compression = require("compression");
5-
const morgan = require("morgan");
6-
const { createRequestHandler } = require("@remix-run/express");
3+
import express from "express";
4+
import compression from "compression";
5+
import morgan from "morgan";
6+
import { createRequestHandler } from "@remix-run/express";
77

8-
const { createUsersByIdLoader } = require("../app/loaders/userLoader");
8+
import { createUsersByIdLoader } from "../app/loaders/userLoader";
99

1010
const MODE = process.env.NODE_ENV;
1111
const BUILD_DIR = path.join(process.cwd(), "server/build");

dataloader/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx", "server/index.ts"],
33
"compilerOptions": {
4+
"allowJs": true,
5+
"forceConsistentCasingInFileNames": true,
46
"lib": ["DOM", "DOM.Iterable", "ES2019"],
57
"isolatedModules": true,
68
"esModuleInterop": true,

file-and-cloudinary-upload/app/routes/cloudinary-upload.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const action = async ({ request }: ActionArgs) => {
3333
};
3434

3535
export default function Index() {
36-
const data = useActionData<typeof action>();
36+
const actionData = useActionData<typeof action>();
3737

3838
return (
3939
<>
@@ -44,12 +44,15 @@ export default function Index() {
4444
<input id="img-desc" type="text" name="desc" />
4545
<button type="submit">upload to cloudinary</button>
4646
</Form>
47-
{data?.error ? <h2>{data.error}</h2> : null}
47+
{actionData && "error" in actionData ? <h2>{actionData.error}</h2> : null}
4848

49-
{data?.imgSrc ? (
49+
{actionData && "imgSrc" in actionData ? (
5050
<>
5151
<h2>uploaded image</h2>
52-
<img src={data.imgSrc} alt={data.imgDesc || "Upload result"} />
52+
<img
53+
src={actionData.imgSrc}
54+
alt={actionData.imgDesc || "Upload result"}
55+
/>
5356
</>
5457
) : null}
5558
</>

file-and-cloudinary-upload/app/routes/local-upload.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ export const action = async ({ request }: ActionArgs) => {
2626
};
2727

2828
export default function Index() {
29-
const data = useActionData<typeof action>();
29+
const actionData = useActionData<typeof action>();
3030

3131
return (
3232
<>
3333
<Form method="post" encType="multipart/form-data">
3434
<input type="file" name="img" accept="image/*" />
3535
<button type="submit">upload image</button>
3636
</Form>
37-
{data?.error ? <h2>{data.error}</h2> : null}
37+
{actionData && "error" in actionData ? <h2>{actionData.error}</h2> : null}
3838

39-
{data?.imgSrc ? (
39+
{actionData && "imgSrc" in actionData ? (
4040
<>
4141
<h2>uploaded image</h2>
42-
<img alt="uploaded" src={data.imgSrc} />
42+
<img alt="uploaded" src={actionData.imgSrc} />
4343
</>
4444
) : null}
4545
</>

0 commit comments

Comments
 (0)