Skip to content

Rework for TS6#39

Open
stephenoid wants to merge 1 commit into
mainfrom
ts6
Open

Rework for TS6#39
stephenoid wants to merge 1 commit into
mainfrom
ts6

Conversation

@stephenoid

@stephenoid stephenoid commented Jul 1, 2026

Copy link
Copy Markdown
Member

Align the template to recent work in external endpoints in anticipation
of upgrading to TS6/7.

  • Add CI workflow to template. I think this will really help a lot of
    people catch mistakes when they happen. As a bonus, they'll catch
    errors in the template too.
  • Add Biome to flag floating promises and format. Unfortunately, most
    settings default to off so a config file is necessary. Added two new
    NPM scripts too: lint and format.
  • Rework all TypeScript configs to best support TS6/7. I've tried to
    lean on the new defaults as much as possible. Where possible, I've
    colocated the configs so if you walk up from any file you find the
    config.
  • Demo unit tests.
  • Drop tools/ scaffolding. Too much boilerplate. This removes localhost
    development and inlines scripts into package.json.
  • Drop login NPM script since tooling will log you in.
  • Rename deploy NPM script to publish which matches NPM (and Devvit)
    naming. Clean before building and drop double build step in
    devvit.json.
  • Rename dev to playtest, invoke watch, and reserve dev for dev
    usage.
  • Remove redundant post and server defaults in devvit.json.
  • Split fetch and database responsibilities to separate files.
  • Drop .npmrc. NPM prints a warning on engine mismatch. Strict engines
    is an error which doesn't seem necessary?
  • Set VSCode to use installed TypeScript version and Biome formatter.
  • Tweak router paths to be more hierarchical.
  • Consolidate the increment and decrement requests. Demoing multiple
    request types is good but this was two of the same thing.
  • Move both devvit and @devvit/web to devDependencies. The former
    was causing Node.js typing to leak into client types and the latter is
    technically bundled.
  • Improve splash screen a11y.
  • Go modestly on styles and just assume folks will vibe these out.
  • Add AnyRsp union in server. This should be in api.ts but some
    of the types are unfortunately server only.
  • Tweak the naming in server:
    • The top-level API is "_on_Req" but then it routes to everything
      else. I'm hoping this is more intuitive.
    • Distinguish IncomingMessage / ServerResponse as "Msg" and the bodies
      as "req" or "rsp".
  • Fix a couple initialisms to match Api council guidance.
  • Upgrade all dependencies.

Sorry for the crappy delta!

For testing, I ran:

$ git clone ~/work/reddit/src/templates/devvit-template-bare snntest20260629c
$ cd snntest20260629c
$ npm install
$ npx devvit init

I then tried each NPM script.

See https://www.reddit.com/r/snntest20260629c_dev.

I tested the CI config in the
old repo.

Comment thread .github/workflows/ci.yaml
@@ -0,0 +1,30 @@
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add CI workflow to template. I think this will really help a lot of
people catch mistakes when they happen. As a bonus, they'll catch
errors in the template too.

Comment thread .vscode/settings.json
{
"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {"source.organizeImports.biome": "explicit"},
"js/ts.tsdk.path": "node_modules/typescript/lib"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use installed TypeScript version.

Comment thread public/game.css Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go modestly on styles and just assume folks will vibe these out.

Image Image

Comment thread public/splash.html
/>
<title>devvit</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve splash screen a11y. here i'm demoing a non-game.

Comment thread src/client/fetch.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split fetch responsibiltiies

Comment thread src/client/fetch.ts
export async function fetchIncCounter(
amount: number,
): Promise<IncCounterRsp | undefined> {
const req: IncCounterReq = {amount}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidate the increment and decrement requests. Demoing multiple request types is good but this was two of the same thing. GetCounter is a second request type.

Comment thread biome.jsonc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Biome to flag floating promises and format. Unfortunately, most
settings default to off so a config file is necessary. Added two new
NPM scripts too: lint and format.

Comment thread biome.jsonc
"recommended": true
},
"style": {"noInferrableTypes": "off"},
"suspicious": {"noImplicitAnyLet": "off"}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems crazy to me but the recommend rule is to require explicit let local typing which is often overtyping in my opinion

Comment thread devvit.json
}
}
},
"server": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant post and server defaults in devvit.json.

Comment thread devvit.json
"$schema": "https://developers.reddit.com/schema/config-file.v1.json",
"name": "<% name %>",
"post": {
"dir": "public",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default

Comment thread devvit.json
"dir": "public",
"entrypoints": {
"default": {
"inline": true,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default

Comment thread devvit.json
},
"triggers": {
"onAppInstall": "/internal/on-app-install"
"onAppInstall": "/internal/on/app/install"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweak router paths to be more hierarchical.

Comment thread tsconfig.base.json
@@ -0,0 +1,24 @@
{

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rework all TypeScript configs to best support TS6/7. I've tried to
lean on the new defaults as much as possible. Where possible, I've
colocated the configs so if you walk up from any file you find the
config.

Comment thread src/server/server.test.ts

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo unit tests.

Comment thread tools/build.ts Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop tools/ scaffolding. Too much boilerplate. This removes localhost
development and inlines scripts into package.json.

Comment thread package.json
"build": "node --experimental-strip-types ./tools/build.ts --minify",
"deploy": "npm run build && devvit upload",
"dev": "devvit playtest",
"login": "devvit login",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop login NPM script since tooling will log you in.

Comment thread package.json
"test": "npm run test:types && npm run lint && npm run test:unit && npm run build",
"test:types": "tsc --build",
"test:unit": "node --experimental-strip-types --no-warnings=ExperimentalWarning --test src/**/*.test.ts",
"publish": "npm run clean && npm run build && devvit publish",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename deploy NPM script to publish which matches NPM (and Devvit)
naming. Clean before building and drop double build step in
devvit.json.

Comment thread package.json
"clean": "rm -rf dist/ public/*.js*",
"format": "npm run lint -- --fix",
"lint": "biome check --error-on-warnings",
"playtest": "devvit playtest",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename dev to playtest, invoke watch, and reserve dev for dev
usage.

Comment thread package.json
"engines": {
"node": ">=22.6.0"
},
"dependencies": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move both devvit and @devvit/web to devDependencies. The former
was causing Node.js typing to leak into client types and the latter is
technically bundled.

Comment thread src/server/server.ts
return JSON.parse(`${Buffer.concat(chunks)}`)
}

function writeJSON<T extends PartialJsonValue>(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix a couple initialisms to match Api council guidance.

Comment thread package.json
"publish": "npm run clean && npm run build && devvit publish",
"watch": "sh -c 'trap \"kill 0\" exit; npm run build:client -- --watch=forever& npm run build:server -- --watch=forever& wait' --"
},
"devDependencies": {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade all dependencies.

Align the template to recent work in external endpoints in anticipation
of upgrading to TS6/7.

- Add CI workflow to template. I think this will really help a lot of
  people catch mistakes when they happen. As a bonus, they'll catch
  errors in the template too.
- Add Biome to flag floating promises and format. Unfortunately, most
  settings default to off so a config file is necessary. Added two new
  NPM scripts too: `lint` and `format`.
- Rework all TypeScript configs to best support TS6/7. I've tried to
  lean on the new defaults as much as possible. Where possible, I've
  colocated the configs so if you walk up from any file you find the
  config.
- Demo unit tests.
- Drop tools/ scaffolding. Too much boilerplate. This removes localhost
  development and inlines scripts into `package.json`.
- Drop `login` NPM script since tooling will log you in.
- Rename `deploy` NPM script to `publish` which matches NPM (and Devvit)
  naming. Clean before building and drop double build step in
  `devvit.json`.
- Rename `dev` to `playtest`, invoke `watch`, and reserve `dev` for dev
  usage.
- Remove redundant `post` and `server` defaults in `devvit.json`.
- Split fetch and database responsibilities to separate files.
- Drop `.npmrc`. NPM prints a warning on engine mismatch. Strict engines
  is an error which doesn't seem necessary?
- Set VSCode to use installed TypeScript version and Biome formatter.
- Tweak router paths to be more hierarchical.
- Consolidate the increment and decrement requests. Demoing multiple
  request types is good but this was two of the same thing.
- Move both `devvit` and `@devvit/web` to `devDependencies`. The former
  was causing Node.js typing to leak into client types and the latter is
  technically bundled.
- Improve splash screen a11y.
- Go modestly on styles and just assume folks will vibe these out.
- Add `AnyResponse` union in server. This should be in `api.ts` but some
  of the types are unfortunately server only.
- Tweak the naming in server:
  - The top-level API is "_on_Req" but then it _routes_ to everything
    else. I'm hoping this is more intuitive.
  - Distinguish IncomingMessage / ServerResponse as "Msg" and the bodies
    as "req" or "rsp".
- Fix a couple initialisms to match Api council guidance.
- Upgrade all dependencies.

For testing, I ran:

```
$ git clone ~/work/reddit/src/templates/devvit-template-bare snntest20260629c
$ cd snntest20260629c
$ npm install
$ npx devvit init
```

I then tried each NPM script.

I tested the CI config in the
[old repo](https://github.com/niedzielski/devvit-template-simple).
Comment thread src/server/server.ts
} from '../shared/api.ts'
import {dbGetCounter, dbIncCounter} from './db.ts'

type AnyRsp =

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add AnyRsp union in server. This should be in api.ts but some
of the types are unfortunately server only.

Comment thread src/server/server.ts
}

async function onMenuNewPost(): Promise<UiResponse> {
const post = await reddit.submitCustomPost({ title: context.appName });

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appName is deprecated

Comment thread .npmrc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop .npmrc. NPM prints a warning on engine mismatch. Strict engines
is an error which doesn't seem necessary?

Comment thread package.json
Comment on lines +8 to +10
"build": "npm run build:client -- --metafile=dist/client.meta.json --minify && npm run build:server -- --metafile=dist/server.meta.json --minify",
"build:client": "esbuild --bundle --log-level=warning --sourcemap=linked --target=es2023 --format=esm --outdir=public --platform=browser src/client/splash.ts src/client/game.ts",
"build:server": "esbuild --bundle --log-level=warning --sourcemap=linked --target=es2023 --format=cjs --outdir=dist/server --platform=node src/server/index.ts",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inlined from tools/build.ts

Comment thread README.md

> Make sure you have Node 22 downloaded on your machine before running!

1. Run `npm create devvit@latest --template=hello-world`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong template

@stephenoid stephenoid requested a review from ben-harris-5 July 1, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants