Default to using Bun instead of Node.js.
- Use
bun <file>instead ofnode <file>orts-node <file> - Use
bun testinstead ofjestorvitest - Use
bun build <file.html|file.ts|file.css>instead ofwebpackoresbuild - Use
bun installinstead ofnpm installoryarn installorpnpm install - Use
bun run <script>instead ofnpm run <script>oryarn run <script>orpnpm run <script> - Use
bunx <package> <command>instead ofnpx <package> <command> - Bun automatically loads .env, so don't use dotenv.
- Use
bun run format(oxfmt). - Formatting rules: single quotes, no semicolons.
- Formatter config lives in
oxfmtrc.json.
- Prefer
Bun.fileovernode:fs's readFile/writeFile - Bun.$
lsinstead of execa.
- Plugin entrypoint:
src/index.ts(default export is the plugin). - Redaction logic lives in
src/redact.tsand AST caching insrc/ast.ts. - Helper utilities for blackbox gating are in
src/blackbox-utils.ts. - Tests live in
tests/with fixtures intests/fixtures. - The formatter config is
oxfmtrc.json.
Use bun test to run tests.
import { test, expect } from 'bun:test'
test('hello world', () => {
expect(1).toBe(1)
})When working with ts-morph AST nodes:
-
Avoid
astype assertions - Use ts-morph's built-in narrowing methods instead:node.asKind(SyntaxKind.X)returns the narrowed type orundefinednode.asKindOrThrow(SyntaxKind.X)returns the narrowed type or throwsnode.isKind(SyntaxKind.X)is a type guard that narrowsthis
-
Avoid
'property' in nodechecks - Use ts-morph's static type guards:Node.isModifierable(node)- checks if node hashasModifier()methodNode.isExpression(node)- checks if node is anExpressionNode.isBodied(node)- checks if node hasgetBody()method- See
Node.is*methods in ts-morph for the full list
-
Import
Nodeas a value (nottype Node) when using static type guards likeNode.isExpression()