Scale-reference 1.0: TypeScript, built package, named functions - #3
Merged
Merged
Conversation
- Write the package in TypeScript and publish built code: CommonJS and ES modules with their own type declarations behind an exports map (react-native-builder-bob). It now loads from Node require/import, Jest with default settings and strict TypeScript (node16 and bundler). - Replace the static ScaleReference class with named functions and frozen constants; scaleFromEllipse always returns a frozen Scale union, with 'invalid_input' instead of null. - CI: ESLint (typescript-eslint strict), Prettier, tsc, Jest with 100% coverage, publint, arethetypeswrong, and a consumer check that installs the packed tarball with npm, Yarn 1, Yarn 4 PnP and node-modules, pnpm and Bun. - Release requires a CHANGELOG section and builds once before publishing. - Dependabot, CHANGELOG, README and CONTRIBUTING for 1.0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
publint packs without running prepack, so on a fresh checkout it found no lib/. Locally an earlier build hid this. Co-Authored-By: Claude Opus 5 <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.
This is the pilot for the 1.0 redesign that followed the critical review. scale-reference goes first because it is pure logic with no native code. Once this is merged, health-data and photo-quality follow the same pattern.
Why
The review tested the 0.2.0 package from the outside:
require/importERR_MODULE_NOT_FOUND(extensionless ESM source shipped as-is)SyntaxError: Unexpected token 'export'TS7016, no typesWhat changes
Packaging:
noUncheckedIndexedAccess.lib/commonjsandlib/module, each with its own type declarations.exportsmap withimportandrequireconditions, plussideEffects: false,enginesand"type": "commonjs".prepackbuilds the package, sonpm packandnpm publishalways contain freshlib/.API (1.0, breaking; nothing was published):
scaleFromEllipse,toMillimetres,toSquareMillimetres,scalesAreComparable,explainRefusal. Constants areDEFAULT_OPTIONSandREFERENCE_OBJECTS. These can be tree-shaken and mocked, and can't be reassigned.scaleFromEllipsealways returns a frozenScale, which is a discriminated union.mmPerPixelis anumberonly after checkingusable.reason: 'invalid_input'instead ofnull. Numeric strings are no longer silently accepted.TypeErrorfor an unknown or invalid option). A photo that can't be measured is a result.scalesAreComparabletakes{tolerance}and validates it.Quality gates (CI):
check: ESLint (typescript-eslint strict type-checked) + Prettier,tsc, Jest with a 100% coverage threshold, and the build.package:publint --strict,arethetypeswrong --pack, and the tarball allowlist, updated forlib/.consumer(new): packs the package, installs it in a fresh project and loads it withrequireandimport, once each with npm, Yarn 1, Yarn 4 Plug'n'Play, Yarn 4 node-modules, pnpm and Bun. The npm run also checks Jest with default settings, and strict TypeScript innode16(CommonJS and ESM files) andbundlerresolution, including thatmmPerPixelcan't be used before checkingusable.Release: the version must have a CHANGELOG section. The workflow runs lint, types, tests and package checks, builds once, then publishes with
--ignore-scriptsthrough trusted publishing. Publishing to npm covers every package manager and Expo, and the README now shows the install command for each.Docs: README (install for all managers, a compatibility table, API table, upgrading from 0.x), CONTRIBUTING (design rules, commands), and a new CHANGELOG.
How it was checked (locally)
tscare clean. 28 tests pass at 100% statements, branches, functions and lines.publint --strict: no errors.attw --pack: "No problems found", with node10, node16 from CommonJS, node16 from ESM and bundler all green.requireandimport. The npm run also passes the default-settings Jest project and strict TypeScript innode16andbundlerresolution.package.jsonis"type": "module", and bob giveslib/commonjsits owncommonjsmarker. Without the root marker, Yarn 4 Plug'n'Play generates no ESM loader, and a plainimportfailed withERR_MODULE_NOT_FOUND. I reproduced that, confirmedpnpEnableEsmLoader: truefixes it, and chose the root marker so consumers need no Yarn setting. The Jest-only Babel config isbabel.config.cjsas a result.5496930, including every package manager on Linux. The first run failed the package job: publint packs without runningprepack, so a fresh checkout had nolib/, which a leftover local build had hidden.check:packagenow builds first, and I re-checked it from a clean copy.For the app
The MoleCare app only uses this package in its own
ScaleReferencetest. After merge, a small app PR updates that test and the adapter to the new names and bumps the pin.🤖 Generated with Claude Code