Repository navigation
feat: project setup with pnpm + tsup dual ESM/CJS + vitest type tests - #1
Merged
Merged
Conversation
- 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>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bootstraps the missing project configuration for
clippyso the existing source code can be developed, type-checked, built and published as a real library.Tooling
pnpm@9.15.1as package manager (packageManagerpinned,.npmrc)TypeScript 5.7strict —moduleResolution: bundler,ES2022,noUncheckedIndexedAccess,verbatimModuleSyntaxtsupbuilds dual ESM + CJS in one pass:dist/index.mjs(ESM) +dist/index.d.tsdist/index.cjs(CJS) +dist/index.d.ctsexportsmap with conditionalimport/requiretypes so consumers get correct types under anymoduleResolutiontsxforpnpm demoto runexamples/demo.tsTests —
vitestwithtypecheckmode enabledtests/command.test.ts— 7 runtime tests covering boolean flags, value+default+parser, negatable--no-*, variadic, kebab→camel, positional args,createCommandtests/opts-types.test-d.ts— 15 type-level tests foroptsinference and 7 for argument tuple inference, usingexpectTypeOf. Covers:boolean(noundefined)<value>no default →T | undefined<value>with default →T<vals...>→string[] | undefined--no-open→{ open: boolean }(key withoutno-prefix)<arg>/[arg]/<args...>argument inferenceScripts
pnpm buildpnpm devpnpm demoexamples/demo.tsvia tsxpnpm typechecktsc --noEmitpnpm testpnpm test:typespnpm test:watchpnpm cleanCI — 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.
types.ts— stripno-prefix for negatable flag keys.--no-openwas inferring as{ noOpen: boolean }while the runtime puts it onopts.open. The demo (examples/demo.ts) readsopts.open, so the runtime is the source of truth. AddedStripNoPrefix<S>toOptionKey<F>.types.ts—Prettify<T>wrapper aroundAddOption. Without it,optshovered asRecord<never, never> & { port: number } & { host: string } & ...andexpectTypeOfcouldn't compare it to a flat object literal. Now hovers and tests see{ port: number; host: string; ... }.command.ts— variadic option branching.takesValuewas checked beforeisVariadic, 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
pnpm install && pnpm test && pnpm buildand verify all 29 tests pass anddist/index.{mjs,cjs,d.ts,d.cts}are emittedpnpm demo serve --port 4000 --no-open --log-level debugand confirm output matches expectations@acp-code/clippyand licenseMITinpackage.jsonare correct (change if you'd prefer a different scope)exportsmap — ESM consumers getdist/index.mjs+dist/index.d.ts, CJS consumers getdist/index.cjs+dist/index.d.ctsNotes
tsconfig.jsonenablesverbatimModuleSyntaxto enforce explicitimport typefor type-only imports — the existing source already uses it correctly.vitest.config.tsruns typecheck viatscagainst the sametsconfig.jsonto keep one source of truth for type rules.sideEffects: false).Link to Devin session: https://app.devin.ai/sessions/b5493ae504da4a51a53db50b2282c38a
Requested by: @JakiChen