v3: dual ESM/CJS + TypeScript rewrite and full toolchain modernization#29
Open
Roman991 wants to merge 7 commits into
Open
v3: dual ESM/CJS + TypeScript rewrite and full toolchain modernization#29Roman991 wants to merge 7 commits into
Roman991 wants to merge 7 commits into
Conversation
This PR improves the internal structure of isbn3 without changing any public API behavior. All existing tests pass (66/66) and a regression test suite (Regrets) confirms zero behavioral changes. ## Changes ### Decomposition - **audit.js** (118 → 30 lines): Extracted clue-generating helpers to `lib/audit_clues.js`. Each function now has a single responsibility and JSDoc documentation. ### Cohesion — Inline functions → dedicated modules - **hyphenate**: Extracted from inline arrow function in isbn.js to `lib/hyphenate.js` - **asIsbn13**: Extracted from inline arrow function in isbn.js to `lib/as_isbn13.js` - **asIsbn10**: Extracted from inline arrow function in isbn.js to `lib/as_isbn10.js` ### Naming — Honest names - **fill.js → complete_isbn_data.js**: The old name was vague. The new name clearly describes that this module completes ISBN data objects with computed check digits and formatted versions. ### Single Responsibility - **normalize**: Extracted from audit.js private function to `lib/normalize.js` — useful as a standalone utility. ### Bug Fix (Typo) - `lookForPossibleInvalityCauses` → `lookForPossibleInvalidityCauses` ## Verification All changes were verified with three independent methods: 1. **Regrets regression testing**: 5 clusters, all GREEN, zero drift 2. **Direct output comparison**: All 15 function outputs identical to pre-refactor baseline 3. **Fingerprint cross-match**: All 5 fingerprints match pre-refactor contract
- Introduced TypeScript definitions in `src/types.ts` for better type safety. - Replaced JavaScript test files with TypeScript test files for `asIsbn10`, `asIsbn13`, `audit`, `getGroup`, `groups`, `hyphenate`, and `parse`. - Removed outdated JavaScript test files to streamline the codebase. - Added `tsconfig.json` for TypeScript configuration. - Created `tsdown.config.ts` for building the package with TypeScript.
…18/20 The build toolchain (tsdown) requires Node >= 22.18, so the previous compat job failed trying to build on Node 18/20. Split CI into: source lint/typecheck/ test on Node 22/24, a single build job that uploads dist/ as an artifact, and a compat job that smoke-tests the prebuilt ESM/CJS output on Node 18/20 (the emitted bundles target Node 18). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
I spent a few tokens to modernize this library, which I've been using for many years, to make it easier to maintain over time.
I've already tested it on four projects in CJS and ESM without having to make any changes to the src.
Summary
This PR modernizes isbn3 to a v3 release: the source is rewritten in TypeScript, the package now ships a dual ESM + CommonJS build with generated type declarations, and the legacy toolchain (babel + browserify + uglify + mocha + should + standard + node-fetch) is replaced with a single modern stack.
No runtime behavior change: same functions, same output shape. The existing test suite was ported 1:1 and all 66 tests pass.
What changed
Packaging & modules
Language & source layout
Toolchain
CI & infra
Code cleanups (behavior-preserving)
Removed
import (https://cdn.jsdelivr.net/npm/isbn3@3/+esm); index.html and README updated accordingly.
Pros of merging
Cons / risks of merging
branches (mitigated by the CDN ESM path).
--legacy-peer-deps. Verified that .d.ts generation works correctly with TS 6.
Verification