Skip to content

Commit dec2756

Browse files
author
Peter Hauge
committed
docs: document version management decision
NodeJsDev implemented single-source-of-truth version management using ESM import attributes to read from package.json at runtime. - Created decisions.md with version management pattern - Updated NodeJsDev history with implementation details - Decision: Use 'with { type: 'json' }' import syntax for Node 22+
1 parent 1d25e86 commit dec2756

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

.squad/agents/nodejsdev/history.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,32 @@
9494
- Unknown commands log error to stderr and exit with code 1
9595
- Build and lint pass without errors
9696

97+
### 2026-04-29: Version Management Pattern — Single Source of Truth
98+
99+
**Problem:** Version was maintained in two places: `package.json` ("0.1.3-alpha.0") and hardcoded in `src/cli/index.ts` (".version('0.1.0')"). This caused version drift and required manual updates in both locations.
100+
101+
**Solution:** Import version from `package.json` using ESM import attributes (Node 22+ with TypeScript):
102+
```typescript
103+
import packageJson from '../../package.json' with { type: 'json' };
104+
program.version(packageJson.version);
105+
```
106+
107+
**Key Implementation Notes:**
108+
1. **Import syntax:** Use `with { type: 'json' }` (not `assert`) — TypeScript TS2880 error enforces the newer import attributes syntax
109+
2. **Path resolution:** From `src/cli/index.ts`, use `../../package.json` — when compiled to `dist/cli/index.js`, this resolves correctly to root `package.json`
110+
3. **tsconfig requirement:** `resolveJsonModule: true` (already configured) enables JSON imports in TypeScript
111+
4. **Node version:** Requires Node 22+ for import attributes support (already enforced via `"engines": {"node": ">=22.0.0"}`)
112+
113+
**Benefits:**
114+
- Single source of truth: `package.json` version is the canonical version
115+
- Automated versioning: `npm version` updates package.json, CLI automatically reflects the change
116+
- Eliminates drift: No manual synchronization required between files
117+
- Standard pattern: Follows Node.js ecosystem conventions for CLI tools
118+
119+
**Verification:**
120+
- Build passes: `npm run build` compiles successfully
121+
- Version output correct: `node dist/cli/index.js --version` displays "0.1.3-alpha.0" from package.json
122+
- No runtime dependencies: Uses native Node ESM features, no additional packages required
123+
97124
<!-- Append new learnings here after each session -->
98125

.squad/decisions/decisions.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Technical Decisions
2+
3+
All architectural and implementation decisions for apiops-cli.
4+
5+
---
6+
7+
### 2026-04-29: CLI version uses package.json as single source of truth via ESM import attributes
8+
**By:** NodeJsDev
9+
**Status:** Implemented
10+
**What:** The CLI version displayed by `apiops --version` is imported from `package.json` using ESM import attributes: `import packageJson from '../../package.json' with { type: 'json' }`. The Commander program uses `program.version(packageJson.version)` instead of a hardcoded string.
11+
**Why:** Eliminates version drift between package.json and CLI output. Previously, version was hardcoded in `src/cli/index.ts` (".version('0.1.0')") while package.json had "0.1.3-alpha.0". Now `npm version` automatically updates the CLI version with no manual synchronization required. This is the standard pattern for Node.js CLI tools and requires no runtime dependencies — uses native Node 22+ ESM features with TypeScript's `resolveJsonModule: true`.
12+
**Note:** Import syntax must use `with { type: 'json' }` not `assert { type: 'json' }` — TypeScript enforces the newer import attributes syntax (TS2880 error if using `assert`).
13+
14+
---

0 commit comments

Comments
 (0)