Working rules for @stackpress/lib.
@stackpress/lib is the shared low-level TypeScript utility package for
Stackpress projects. It is a standalone package repo, not the main monorepo.
src/: source of truthtests/: mocha/ts-mocha testsdocs/: API docscjs/,esm/: generated build outputtsconfig/: published presetssrc/index.ts: public re-export surfacesrc/types.ts: shared typespackage.json: exports, scripts, publish surface
src/data/: nested data, readonly wrappers, parserssrc/emitter/: event emitterssrc/queue/: queue primitivessrc/router/: request, response, session, terminal, routersrc/system/: filesystem and module loading
If a change is public, check src/index.ts and package.json exports.
Use Node.js >=22. Do not assume the default node on PATH qualifies.
Prefer this lookup order before running Node commands:
- Check
nvm. - Prefer a Node
22+binary from the NVM versions directory. - If needed, use
nvmitself to inspect/select Node22+. - Fall back to common install paths.
- Inspect
PATH,NVM_DIR, and related env vars. - If no Node
22+is found, stop and ask the user.
Use yarn, not npm, unless the user explicitly asks otherwise.
Key commands:
yarn testyarn buildyarn build:tsc:cjsyarn build:tsc:esm
Tests run with ts-mocha -r tsx. Tests import from ../src/... without
extensions. Source files use local ESM imports with .js extensions.
- Edit
src/,tests/,docs/, and package metadata as needed. - Do not hand-edit
cjs/oresm/; regenerate them withyarn build. - Keep
src/index.ts,package.jsonexports, andtypesVersionsaligned. - Preserve the existing subsystem layout. Put new code in the closest module.
- Prefer small focused classes and helpers.
- Comments should be sparse and only explain non-obvious behavior.
- Behavioral changes usually need matching tests.
When behavior changes:
- add or update targeted tests in
tests/ - run
yarn test - run
yarn buildif exports, types, or module wiring changed
Be careful around:
src/types.tssrc/index.tspackage.jsonexports- router/emitter interactions
- parsers in
src/data/processors/
Start here by topic:
- data:
src/data/Nest.ts,src/data/Map.ts,src/data/Set.ts - routing:
src/router/Router.ts,src/router/Request.ts,src/router/Response.ts - events:
src/emitter/EventEmitter.ts,src/emitter/ExpressEmitter.ts,src/emitter/RouteEmitter.ts - file loading:
src/system/FileLoader.ts,src/system/NodeFS.ts - public API:
src/index.ts,package.json
Helpful tests:
tests/Router.test.tstests/EventEmitter.test.tstests/FileLoader.test.tstests/Nest.test.ts
- Check
git statusbefore editing. - Avoid overwriting unrelated local work.
- Prefer minimal changes with matching tests over broad refactors.
- If you add a public entry point, update docs and exports in the same pass.
- If docs and code disagree, trust tests and source first.