Ship generated types, fix Legend scale prop, publish as @dave-hillier/replot - #138
Merged
Conversation
…/replot Closes #135, #136, #137. #135 — emit real declarations instead of resolving types to sources. tsconfig.build.json emits declaration-only output into dist/types, and scripts/copy-declarations.mjs overlays the 35 hand-written .d.ts that tsc would otherwise infer weakly from the plain .js sources. The exports "types" conditions now point there, so a consumer's compiler never opens replot's implementation. Measured against a strict Vite template app: 263 errors before, 0 after, with tsc --listFiles confirming only dist/types enters the program. #136 — LegendProps was missing the plot-scoped scale prop, which LegendDisplay read through an as-any cast. It is now a discriminated union, so the plot-scoped and standalone forms cannot be mixed: that combination leaked the scale string into <Swatches> via the spread and threw at render. The runtime guard is kept for untyped callers, and an unresolvable legend now renders nothing and no longer forces figure mode, matching imperative plot.legend(). #137 — publish as @dave-hillier/replot; the bare name is taken on npm by an unrelated package. Metadata moves off Observable's while keeping the upstream ISC copyright in LICENSE. publint caught that main, module and the root default condition all pointed at src/index.js, which does not exist — the file is src/index.ts, so the root entry was broken for any consumer not going through tsx or the docs alias. The UMD paths pointed at dist/plot.umd.min.js while the build writes dist/replot.umd.min.js. Both fixed, with publint and arethetypeswrong wired into yarn test. Verified by packing a real tarball and installing it into a fresh Vite React app: tsc -b and vite build both pass, with no optimizeDeps workaround needed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
CI runs yarn --frozen-lockfile, which fails until the two new devDependencies are resolved. Generated in a scratch copy so the shared node_modules was left alone. Co-Authored-By: Claude Opus 5 (1M context) <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.
Closes #135, closes #136, closes #137.
Found while building a Vite + React consumer app against replot; all three are things that only show up from outside the repo.
#135 — generated declarations
tsconfig.build.jsonemits declaration-only output intodist/types, wired intobundle(and soprepublishOnly) via a newbuild:typesscript.scripts/copy-declarations.mjsoverlays the 35 hand-written.d.tson top, because tsc infers much weaker declarations from the plain.jssources — it deliberately skipssrc/react/index.d.ts, theexport * from "./index.js"stub at the heart of the bug.The
typesconditions now point at emitted files, so a consumer's compiler never opens replot's implementation.Measured against a stock strict Vite template app: 263 errors before, 0 after, with
tsc --listFilesconfirming onlydist/types/**enters the consumer's program. Verified against a real packed tarball — 144 declarations, no relative path escapingdist.#136 —
<Legend scale="color">LegendPropswasLegendScales, whileLegendDisplayreadprops.scalethrough anas any. Addingscaleas a plain intersection turned out to bless a shape that crashes, so it is now a discriminated union:LegendOptionsis exactly the "no scale specs" prop set, so the plot-scoped branch keepslegend="ramp",label,columns,filletc. Mixing the two forms previously leaked thescalestring into<Swatches>through the spread and threwswatches legend requires ordinal or threshold color scale. The runtime guard is kept for untyped JS callers.Also: an unresolvable legend now renders nothing and no longer forces figure mode, matching imperative
plot.legend()returningundefined.#137 — publishing
Published name is
@dave-hillier/replot; the barereplotis taken on npm by an unrelated dormant package. Version0.1.0-alpha.0withpublishConfig.tag: "next", so an alpha cannot accidentally becomelatest.LICENSEkeeps Observable's copyright and adds a derivative-work line — the port is derived from Observable Plot and that attribution stays.Two real bugs came out of adding
publintandarethetypeswrong:main,moduleandexports["."].defaultall pointed at./src/index.js, which does not exist — the file issrc/index.ts. The root entry was broken for any consumer not going throughtsxor the docs alias.jsdelivr,unpkgandexports["."].umdpointed atdist/plot.umd.min.js, while the build writesdist/replot.umd.min.js.Both validators now pass (
publint --strictclean,attw --pack --profile esm-onlygreen) and run as part ofyarn test.Needs a decision from you
.github/workflows/publish.ymlis deleted. It published onrelease: publishedusingsecrets.NPM_TOKEN. The newrelease.ymlpublishes on av*tag via OIDC trusted publishing with no token, and keeping both would leave two publish paths. Say the word and it comes back.0.1.0-alpha.0reads as a step backwards. Left alone deliberately.yarn installis still needed to writepublintand@arethetypeswrong/cliintoyarn.lock; the agents worked against a sharednode_modulessymlink and deliberately did not mutate it. The scripts usenpx --yesso they work either way.Verification
yarn test:mocha1563 passing, 2 pending, 0 failing (up from 1560)yarn test:tsc,yarn test:lint,yarn test:prettier,yarn docs:buildall cleannpm pack→ 326 files / 640 kB, extracted and inspected: correct scoped name,dist/types/**present, both UMD files present, no tests or docs shippednpm create vite --template react-tsapp:tsc -bexit 0,vite buildsucceeds, dev server serves — nooptimizeDepsworkaround neededManual steps after merge
yarn installto updateyarn.lock.npm login && npm publish) — trusted publishing can only be configured against a package that already exists.dave-hillier/replot, workflowrelease.yml.v0.1.0-alpha.1and confirm the workflow publishes withoutNPM_TOKEN; then delete theNPM_TOKENsecret.../replot-vite-exampleis untouched; it needs the dependency name and itsfrom "replot/react"imports updating once this lands.🤖 Generated with Claude Code