Skip to content

Update tool chain to modern Wechaty 2.0 #327

Closed

Description

@huan

@cursor read https://github.com/wechaty/wechaty repo and learn about how it use toolchain, prepare to sync this repo to wechaty:

  1. remove @chatie/tsconfig and use local config
  2. remove tsetse by using node:test
  3. add deno test
  4. replace eslint by the biome
  5. copy the .devcontainer to this repo
  6. any other better practices you think is good for this repo.

only analyze and show plan for my review, do not create PR before my approval

Activity

  1. huan commented on Nov 23, 2026

    @huan
    MemberAuthor

    @cursor only analyze and show plan for my review, do not create PR before my approval

  2. cursor commented on Nov 23, 2026

    @cursor

    Wechaty 2.0 on wechaty/wechaty main (2.0.0-alpha.18) is the source of truth. This is a review plan only. No branch, commits, or pull request until you approve.

    The SDK dependency stays on wechaty ^1.20.2. This pass changes how the repo is linted, typechecked, and tested. It does not move the tutorial onto the 2.0 alpha API. Coverage baselines, the npm and Docker publish workflows, and the release-branch version-bump hook stay in wechaty/wechaty. Gitpod stays as it is.

    1. Local TypeScript config

    Remove @chatie/tsconfig. Replace the root tsconfig.json extends with the compiler options from Wechaty 2.0:

    • module and moduleResolution: NodeNext
    • target: esnext
    • verbatimModuleSyntax, erasableSyntaxOnly, isolatedModules, rewriteRelativeImportExtensions
    • strict plus noUncheckedIndexedAccess, noImplicitOverride, noPropertyAccessFromIndexSignature
    • declaration, declarationMap, sourceMap, skipLibCheck

    outDir stays dist. include becomes the files that actually exist: examples/**/*.ts and tests/**/*.test.ts. There are no local enums, namespaces, or constructor parameter properties, so erasableSyntaxOnly should pass. verbatimModuleSyntax may still require import type fixes. npm run build remains tsc.

    TypeScript moves from ~5.9.3 to the same @typescript/native alias Wechaty uses (typescript@^7). The overrides.typescript pin goes away. A second script, lint:ts (tsc --isolatedModules --noEmit), is the typecheck. Node’s type stripping does not check types.

    Two nested packages still extend @chatie/tsconfig: examples/tensorflow.js/fingerpose and examples/third-parties/codesandbox. Same local config there, in this change, so the repo no longer installs that package.

    2. tstest to node:test

    The four smoke tests import test from tstest and the script runs them with tap. Neither tstest nor tap is a direct dependency. tstest is the Chatie runner this replaces.

    Rename tests/*.spec.ts to tests/*.test.ts. Each file imports test from node:test and assertions from node:assert/strict. t.pass becomes assert.ok. t.teardown becomes t.after. The skip option on the puppet-service test stays. Shebangs become #!/usr/bin/env node.

    test:smoke becomes node --test --test-force-exit --test-timeout=180000 tests. --test-force-exit replaces the process.exit(0) workaround that existed so tap would not hang on open sockets. The timeout matches Wechaty’s integration tests and covers the 100–120 second scan waits.

    npm test becomes npm run lint && npm run test:smoke. npm-run-all can go.

    3. Deno test

    Add the same experimental Deno path Wechaty uses. Deno 2.9.8, continue-on-error: true, so a Deno failure does not fail the workflow.

    Smoke tests need a wider permission set than Wechaty’s unit tests: network, environment, read/write, and spawning Chrome for the web puppet. The script will be test:unit:deno, with NODE_BINARY set the same way, plus --allow-net and --allow-run. lint:ts stays the typecheck. Deno runs with --no-check.

    If Puppeteer cannot start under Deno, the Deno script narrows to tests/wechaty-puppet-mock.test.ts and the browser puppets stay Node-only. The CI job still exists either way.

    4. ESLint to Biome

    Remove @chatie/eslint-config, .eslintrc.cjs, and the eslint.validate VS Code setting.

    Add @biomejs/biome ^2.6.5 and copy biome.json: schema 2.6.5, formatter off, assist off, linter preset none, only the correctness and suspicious rules Wechaty enables. That avoids a format-only diff. lint:biome is biome lint examples tests. lint is lint:biome then lint:ts.

    5. Devcontainer

    Replace .devcontainer/ with the Wechaty directory:

    • devcontainer.json — Ubuntu 24.04 base, Node 26, Deno, the feature set, Claude/Codex/Gemini/gitconfig mounts, postCreateCommand: npm install
    • features/any-packages/
    • features/gh-auto-auth/
    • devcontainer-lock.json if present

    One addition for this repo: customizations.codespaces.openFiles keeps opening examples/ding-dong-bot.ts. The current universal image and the global cross-env install go away.

    6. Runner, lockfile, and scripts

    These match DEVELOPMENT.md and fit this repo.

    • Engines become node >= 26, npm >= 10. CI stays on macOS, Windows, and Ubuntu, with Node 26 only. The weekly cron stays so puppet drift is still caught. Install becomes npm ci once a lockfile exists. Actions can stay on the current v7 checkout and setup-node.
    • Stop ignoring package-lock.json, generate it, and commit it. npm run start and cqrs become node examples/.../*.ts with no ts-node loader. Shebangs on examples/ding-dong-bot.ts, examples/cqrs/ding-dong-bot.ts, examples/advanced/dump-room-member.ts, and examples/professional/speech-to-text-bot.ts match. README and examples/tutorials/google-cloud-shell-tutorial.md drop the npx ts-node lines.
    • Remove ts-node, @chatie/git-scripts, and check-node-version. engines covers the Node check. The pre-push hook becomes a small scripts/pre-push.ts that runs npm run lint only. Puppet smoke tests need network and tokens, so they stay out of the hook. Wechaty’s version-bump hook is not copied.
    • cross-env is used by start:* and is not declared. Add it as a dependency so the Windows CI scripts keep working.
    • Makefile: lint is a real recipe (npm run lint). clean gets a clean script (shx rm -fr dist) or the target is dropped. Today clean calls a script that does not exist, and lint is parsed as dependencies named npm, run, and lint.

    Nested examples/professional/chatgpt-bot and examples/third-parties/codesandbox still start via ts-node. Update those start scripts to node in the same change. Their own dependency trees stay on Wechaty 1.x.

    Risks

    • Node 26 is what Wechaty 2.0 runs. These smoke tests still launch Wechaty 1.20 puppets, including an old Puppeteer. The web puppet already has a macOS arm64 skip. The first CI run is the compatibility check.
    • verbatimModuleSyntax and TypeScript 7 can fail on default imports from qrcode-terminal and puppet packages. Those are fixed in the example sources until npm run lint:ts is clean.
    • Deno plus Puppeteer may not get past startup. The job is experimental and does not block the workflow.
    • The copied devcontainer is the full Wechaty image (Rust, Java, TeX, agent CLIs, home-directory mounts), which is heavier than the current Codespaces universal image.

    Approval needed before any edit

    1. Node 26 and TypeScript 7 while dependencies stay on Wechaty 1.20.
    2. Copy the full .devcontainer, with only the Codespaces open-file added.
    3. Deno smoke job with continue-on-error, narrowed to the mock puppet if Chrome will not start.
    4. Include the fingerpose, codesandbox, and chatgpt-bot packages in this change.
    5. Commit package-lock.json and switch CI to npm ci.

    Say which of those you want changed, and I will implement on a branch and open the PR after that.

    Open in Web Open in Cursor 
  3. huan commented on Nov 23, 2026

    @huan
    MemberAuthor

    @cursor

    remove the fingerpose, codesandbox, and chatgpt-bot packages in this change.
    do not commit package-lock.json - make it deliberate be ignored, put it in DEVELOPMENT.md - because we want to catch errors earlier in this getting started repo if there's any version issues.

    make all source code files in .ts and writes in TypeScript - make sure Node can run ts directly.

    Add shebang to unit tests .ts files so that they can be run directly.

    update plan for my reviewing.

  4. cursor commented on Nov 23, 2026

    @cursor

    Updated plan for review. No branch, no commits, and no pull request until you approve.

    Wechaty 2.0 on wechaty/wechaty main (2.0.0-alpha.18) is still the toolchain source. The SDK dependency stays on wechaty ^1.20.2. This pass changes how the repo is linted, typechecked, tested, and how examples are written. It does not move the tutorial onto the 2.0 alpha API. Coverage baselines, the npm and Docker publish workflows, and the release-branch version-bump hook stay in wechaty/wechaty. Gitpod stays as it is.

    What changed from the last plan

    • Delete the three nested packages: examples/tensorflow.js/fingerpose, examples/third-parties/codesandbox, and examples/professional/chatgpt-bot. examples/tensorflow.js/ goes with fingerpose, because that package is the only thing in it. Their @chatie/tsconfig files go with them. The chatgpt-bot dotenv file only has empty keys.
    • package-lock.json stays gitignored. It is already ignored. CI keeps npm install and package-manager-cache: false. A new root DEVELOPMENT.md records why: a lockfile would hide range conflicts, and this repo should fail on npm install when a range breaks, before a new user hits it. Wechaty itself still commits its lockfile. This repo does not.
    • Every remaining source file is TypeScript. The 31 .js sources outside those three packages are renamed to .ts, given types, and written so Node 26 runs them with built-in type stripping. ts-node and the --loader=ts-node/esm shebangs go away. examples/README.md drops the “vanilla JavaScript” contribution note.
    • The four smoke tests are renamed to tests/*.test.ts, get #!/usr/bin/env node, and the executable bit, so ./tests/wechaty-puppet-mock.test.ts runs that file directly.

    1. Local TypeScript config

    Remove @chatie/tsconfig. Replace the root tsconfig.json extends with the compiler options from Wechaty 2.0:

    • module and moduleResolution: NodeNext
    • target: esnext
    • verbatimModuleSyntax, erasableSyntaxOnly, isolatedModules, rewriteRelativeImportExtensions
    • strict plus noUncheckedIndexedAccess, noImplicitOverride, noPropertyAccessFromIndexSignature
    • declaration, declarationMap, sourceMap, skipLibCheck

    outDir stays dist. include is examples/**/*.ts and tests/**/*.test.ts, excluding examples/third-parties/**. examples/third-parties/maodou and examples/third-parties/xiaoli stay in the repo and become TypeScript, but they keep their own package.json and their own dependencies (bosonnlp, node-schedule, node-fetch, recognizers, Wechaty 0.x ranges). Those modules are not installed by the root npm install, so root tsc does not include them. Each gets "type": "module" and scripts that call node on the .ts file.

    TypeScript moves from ~5.9.3 to the @typescript/native alias Wechaty uses (typescript@^7). The overrides.typescript pin goes away. npm run build remains tsc. lint:ts is tsc --isolatedModules --noEmit. Node’s type stripping does not check types.

    2. All sources are TypeScript, and Node runs them

    Node 26 runs .ts directly. Scripts and shebangs call node, with no loader.

    Entry points that you run get #!/usr/bin/env node and the executable bit. That set is the existing bot and CLI entry points, including examples/ding-dong-bot.ts, examples/cqrs/ding-dong-bot.ts, examples/advanced/dump-room-member.ts, and examples/professional/speech-to-text-bot.ts, plus the .js bots that already had a shebang (busy-bot, room-bot, room-say-cli, maodou, xiaoli) and the other bot entry points that are started with node. Imported modules (listeners, config, gist-bot handlers) are TypeScript and have no shebang.

    Conversion rules, checked by lint:ts:

    • ESM only. module.exports in gist-bot handlers, hot-import listeners, and maodou helpers becomes export.
    • Relative imports use a .ts extension, including gist-bot’s current ./on-message.js and maodou’s ./maodou-course-api.js.
    • Parameters and values get types from wechaty 1.20 (Message, Contact, ScanStatus, and the rest). import type where verbatimModuleSyntax requires it.
    • No new enums, namespaces, or constructor parameter properties.
    • Wechaty.instance() stays where the 1.20 types still export it. A call changes only when lint:ts rejects it, and then it becomes WechatyBuilder.build().

    package.json scripts:

    • start and cqrs become node examples/ding-dong-bot.ts and node examples/cqrs/ding-dong-bot.ts.
    • start:js is removed. There is no JavaScript entry left. examples/basic/ding-dong-bot.ts stays as the short basic example. The root examples/ding-dong-bot.ts stays the npm start bot.
    • start:* keeps cross-env for the Windows CI matrix. cross-env is added as a dependency. It is used today and not declared.
    • README, examples/tutorials/google-cloud-shell-tutorial.md, examples/README.md, examples/professional/blessed-twins-bot/README.md, and the monster-bot and hot-import docs and shell scripts drop npx ts-node and .js paths. The bug-report template’s node yourbot.js becomes node yourbot.ts. Its rm -rf package-lock.json line stays, and it matches this policy.

    Hot import is the one behavior risk. hot-import-bot and monster-bot pass string paths such as './listeners/on-message' to bot.on, and hot-import loads those as JavaScript. The listeners become .ts, and the strings gain the .ts suffix. If hot-import cannot load a .ts file under Node 26, those two examples switch to a normal typed import (import { onMessage } from './listeners/on-message.ts') so node can run them. Listener hot reload would then be gone. I will report which way it landed.

    3. tstest to node:test

    The four smoke tests import test from tstest, and the script runs them with tap. Neither tstest nor tap is a direct dependency.

    Rename tests/*.spec.ts to tests/*.test.ts. Each file imports test from node:test and assertions from node:assert/strict. t.pass becomes assert.ok. t.teardown becomes t.after. The skip option on the puppet-service test stays.

    Shebang on each test file:

    #!/usr/bin/env node

    Git mode 100755, so this works:

    ./tests/wechaty-puppet-mock.test.ts

    test:smoke becomes node --test --test-force-exit --test-timeout=180000 tests. --test-force-exit replaces the process.exit(0) workaround that existed so tap would not hang on open sockets. The timeout matches Wechaty’s integration tests and covers the 100–120 second scan waits.

    npm test becomes npm run lint && npm run test:smoke. npm-run-all goes.

    4. Deno test

    Same experimental Deno path as Wechaty. Deno 2.9.8, continue-on-error: true, so a Deno failure does not fail the workflow.

    Smoke tests need a wider permission set than Wechaty’s unit tests: network, environment, read/write, and spawning Chrome for the web puppet. The script is test:unit:deno, with NODE_BINARY set the same way, plus --allow-net and --allow-run. lint:ts stays the typecheck. Deno runs with --no-check.

    If Puppeteer cannot start under Deno, the Deno script narrows to tests/wechaty-puppet-mock.test.ts and the browser puppets stay Node-only. The CI job still exists either way.

    5. ESLint to Biome

    Remove @chatie/eslint-config, .eslintrc.cjs, and the eslint.validate VS Code setting.

    Add @biomejs/biome ^2.6.5 and copy biome.json: schema 2.6.5, formatter off, assist off, linter preset none, only the correctness and suspicious rules Wechaty enables. That avoids a format-only diff. lint:biome is biome lint examples tests. lint is lint:biome then lint:ts.

    6. Devcontainer

    Replace .devcontainer/ with the Wechaty directory:

    • devcontainer.json — Ubuntu 24.04 base, Node 26, Deno, the feature set, Claude/Codex/Gemini/gitconfig mounts, postCreateCommand: npm install
    • features/any-packages/
    • features/gh-auto-auth/
    • devcontainer-lock.json if present

    One addition for this repo: customizations.codespaces.openFiles keeps opening examples/ding-dong-bot.ts. The current universal image and the global cross-env install go away.

    7. Runner, lockfile, and DEVELOPMENT.md

    • Engines become node >= 26, npm >= 10. CI stays on macOS, Windows, and Ubuntu, with Node 26 only. The weekly cron stays. Install stays npm install. The workflow comment points at DEVELOPMENT.md for the ignored lockfile. Actions stay on the current v7 checkout and setup-node.
    • .gitignore keeps package-lock.json. A generated lockfile is not committed.
    • New DEVELOPMENT.md covers three things: Node 26 runs the .ts sources directly, and lint:ts is the typecheck. package-lock.json is ignored on purpose so a broken range fails in this repo on a fresh npm install. Tests are node:test, with the direct shebang command, and the Deno job is experimental.
    • Remove ts-node, @chatie/git-scripts, and check-node-version. engines covers the Node check. The pre-push hook becomes a small scripts/pre-push.ts that runs npm run lint only. Puppet smoke tests need network and tokens, so they stay out of the hook. Wechaty’s version-bump hook is not copied.
    • Makefile: lint becomes a real recipe (npm run lint). clean gets a clean script (shx rm -fr dist) or the target is dropped. Today clean calls a script that does not exist, and lint is parsed as dependencies named npm, run, and lint.

    Risks

    • Node 26 is what Wechaty 2.0 runs. These smoke tests still launch Wechaty 1.20 puppets, including an old Puppeteer. The web puppet already has a macOS arm64 skip. The first CI run is the compatibility check.
    • verbatimModuleSyntax and TypeScript 7 can fail on default imports from qrcode-terminal and puppet packages, and on the old Wechaty.instance() examples. Those are fixed in the sources until npm run lint:ts is clean.
    • hot-import may be unable to load .ts listeners. The fallback is a static import, and those two examples would no longer hot-reload.
    • maodou and xiaoli typecheck only inside their own directories. Root npm test does not install them.
    • Deno plus Puppeteer may not get past startup. The job is experimental and does not block the workflow.
    • The copied devcontainer is the full Wechaty image (Rust, Java, TeX, agent CLIs, home-directory mounts), which is heavier than the current Codespaces universal image.

    Still needs your approval

    1. Node 26 and TypeScript 7, with dependencies staying on Wechaty 1.20.
    2. Copy the full .devcontainer, with only the Codespaces open-file added.
    3. Deno smoke job with continue-on-error, narrowed to the mock puppet if Chrome will not start.
    4. Delete fingerpose, codesandbox, and chatgpt-bot. Keep maodou and xiaoli as standalone TypeScript packages, outside root tsc.
    5. Leave package-lock.json gitignored and explain that in DEVELOPMENT.md. CI stays on npm install.
    6. Convert every remaining .js source to TypeScript, and put #!/usr/bin/env node on tests and on bot entry points.

    Say which of those you want changed. I will implement on a branch and open the PR after that.

    Open in Web Open in Cursor 
  5. huan commented on Nov 23, 2026

    @huan
    MemberAuthor

    @cursor

    approved.

    Also remove hot-import-bot and monster-bot examples.

  6. cursor commented on Nov 23, 2026

    @cursor

    Taking a look!

    Open in Web Open in Cursor 
  7. huan commented on Nov 23, 2026

    @huan
    MemberAuthor

    @cursor good job!

  8. cursor commented on Nov 23, 2026

    @cursor

    Thanks. Glad the toolchain update landed the way you wanted.

    #328 is merged into main. It brings this repo onto the Wechaty 2 toolchain: local TypeScript config, Biome, node:test, the Deno job, the new devcontainer, and TypeScript examples that Node 26 runs directly. The fingerpose, codesandbox, chatgpt-bot, hot-import-bot, and monster-bot examples are gone, and package-lock.json stays ignored on purpose.

    Open in Web Open in Cursor 
  9. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions