Skip to content

feat: project setup with pnpm + tsup dual ESM/CJS + vitest type tests - #1

Merged
JakiChen merged 1 commit into
mainfrom
devin/1777375669-project-setup
Apr 28, 2026
Merged

JakiChen merged 1 commit into
mainfrom
devin/1777375669-project-setup

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

Summary

Bootstraps the missing project configuration for clippy so the existing source code can be developed, type-checked, built and published as a real library.

Tooling

  • pnpm@9.15.1 as package manager (packageManager pinned, .npmrc)
  • TypeScript 5.7 strict — moduleResolution: bundler, ES2022, noUncheckedIndexedAccess, verbatimModuleSyntax
  • tsup builds dual ESM + CJS in one pass:
    • dist/index.mjs (ESM) + dist/index.d.ts
    • dist/index.cjs (CJS) + dist/index.d.cts
    • sourcemaps for both
  • Proper exports map with conditional import/require types so consumers get correct types under any moduleResolution
  • tsx for pnpm demo to run examples/demo.ts

Tests — vitest with typecheck mode enabled

  • tests/command.test.ts — 7 runtime tests covering boolean flags, value+default+parser, negatable --no-*, variadic, kebab→camel, positional args, createCommand
  • tests/opts-types.test-d.ts — 15 type-level tests for opts inference and 7 for argument tuple inference, using expectTypeOf. Covers:
    • boolean flag → boolean (no undefined)
    • <value> no default → T | undefined
    • <value> with default → T
    • parser return type wins
    • variadic <vals...> → string[] | undefined
    • negatable --no-open → { open: boolean } (key without no- prefix)
    • kebab-case → camelCase key
    • <arg> / [arg] / <args...> argument inference

Scripts

script purpose
pnpm build bundle ESM+CJS+types via tsup
pnpm dev tsup watch mode
pnpm demo run examples/demo.ts via tsx
pnpm typecheck tsc --noEmit
pnpm test runtime + type-level tests
pnpm test:types only type-level tests
pnpm test:watch vitest watch
pnpm clean rimraf dist + coverage

CI — GitHub Actions workflow runs typecheck, tests, build, and verifies all 4 dual-output artifacts exist.

Adjacent fixes uncovered while writing tests

These are small, scoped fixes to existing behavior that the new tests revealed. They are needed for the type tests to assert the demo's stated intent.

  1. types.ts — strip no- prefix for negatable flag keys. --no-open was inferring as { noOpen: boolean } while the runtime puts it on opts.open. The demo (examples/demo.ts) reads opts.open, so the runtime is the source of truth. Added StripNoPrefix<S> to OptionKey<F>.
  2. types.ts — Prettify<T> wrapper around AddOption. Without it, opts hovered as Record<never, never> & { port: number } & { host: string } & ... and expectTypeOf couldn't compare it to a flat object literal. Now hovers and tests see { port: number; host: string; ... }.
  3. command.ts — variadic option branching. takesValue was checked before isVariadic, so --vars <a...> only consumed one value (rest fell through as positionals → "Too many arguments" error). Reordered branches in both long-flag and short-flag paths so variadic is checked first.

Review & Testing Checklist for Human

  • Run pnpm install && pnpm test && pnpm build and verify all 29 tests pass and dist/index.{mjs,cjs,d.ts,d.cts} are emitted
  • Try pnpm demo serve --port 4000 --no-open --log-level debug and confirm output matches expectations
  • Confirm the package name @acp-code/clippy and license MIT in package.json are correct (change if you'd prefer a different scope)
  • Double-check the negatable-flag and variadic runtime fixes against any internal expectations you have
  • Sanity-check the exports map — ESM consumers get dist/index.mjs + dist/index.d.ts, CJS consumers get dist/index.cjs + dist/index.d.cts

Notes

  • tsconfig.json enables verbatimModuleSyntax to enforce explicit import type for type-only imports — the existing source already uses it correctly.
  • vitest.config.ts runs typecheck via tsc against the same tsconfig.json to keep one source of truth for type rules.
  • Build artifact size: ESM 33 KB, CJS 34 KB, types 10 KB — fully tree-shakeable (sideEffects: false).

Link to Devin session: https://app.devin.ai/sessions/b5493ae504da4a51a53db50b2282c38a
Requested by: @JakiChen


Open in Devin Review

- pnpm@9.15.1 as package manager
- TypeScript strict config (moduleResolution: bundler, ES2022)
- tsup builds dual ESM (.mjs) + CJS (.cjs) with .d.ts/.d.cts types
- vitest with typecheck mode for runtime + type-level tests
- src/index.ts as entry point
- 7 runtime tests (option parsing, variadic, negatable, kebab→camel, args)
- 22 type-level tests covering opts inference (using expectTypeOf)
- tsx for examples/demo.ts via 'pnpm demo'
- README, GitHub Actions CI

Adjacent type-system fixes uncovered by tests:
- Strip 'no-' prefix from negatable flag keys (--no-open → opts.open)
- Prettify AddOption result so opts hovers as flat object
- Reorder option-parser branches so variadic options work

Co-Authored-By: jakichen <JakiChen@live.cn>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@JakiChen
JakiChen merged commit 8ef0997 into main Apr 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant