Repository navigation
fix(iife): make the TimePicker global the class, and check the packed tarball in browsers - #78
Merged
Merged
Conversation
… tarball in browsers
The IIFE build exposed the module namespace, so the global TimePicker
was { Events, InternalEvents, default }. The README's CDN usage, `new
TimePicker(...)`, threw a TypeError, and only `new TimePicker.default()`
worked. 4.1.0 ships the same shape.
The IIFE now builds from src/iife.ts. That entry exports the class with
`default`, `Events` and `InternalEvents` attached, so both forms work.
The ESM build and timepicker.d.ts are unchanged.
`check:package` now runs scripts/check-consumers.mjs against the packed
tarball, installed into a scratch consumer (tests/consumer):
- tsc 7 compiles a strict consumer of the declarations under bundler
and nodenext resolution.
- Vite bundles the ESM import. In Chromium and Firefox, a picker opens
with its injected CSS and selecting a time fires `change`.
- A script tag loads dist/timepicker.iife.js. The global is a function,
`TimePicker.default === TimePicker`, Events and InternalEvents keep
their values, and pickers built with `new TimePicker` and `new
TimePicker.default` both select a time.
With the old namespace global, the check fails on `type: "object"`.
The README's CDN URL now names the shipped file, timepicker.iife.js.
The dev server's dependency scan is limited to the demo index.html, so
it no longer scans the consumer fixture.
Co-Authored-By: Claude Opus 5.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.
Spec #246 step 5: checks the packed tarball in real browsers and fixes the one gap the check found.
Gap: the script-tag global wasn't the class
The IIFE build exposed the module namespace, so
window.TimePickerwas{ Events, InternalEvents, default }. The README's CDN snippet,new TimePicker('#click-trigger', …), threw a TypeError, and onlynew TimePicker.default(…)worked. 4.1.0 ships the same shape.Fix: the IIFE now builds from its own entry,
src/iife.ts, which exports the class withdefault,EventsandInternalEventsattached.new TimePicker(…)works as documented, and existingTimePicker.defaultcode keeps working. The ESM build (exports), its export names andtimepicker.d.tsare unchanged. The.d.tsis byte-identical to 4.1.0's.buildis now two Vite passes, like ol-contextmenu's: the ESM build with declarations, then--mode iife.New check:
scripts/check-consumers.mjs(incheck:package, so inverify)The script runs
npm packand installs the tarball into a scratch copy oftests/consumerunder.pack-check/(gitignored). Then it checks:tsccompiles a strict consumer (main.ts) underbundlerand undernodenextresolutionposition: absolutefrom the injected CSS. Hour 10 and minute 30 set the input to10:30, the picker closes, andopenfired once.dist/timepicker.iife.jsloads from a<script>. In both browsers,typeof TimePicker === 'function',TimePicker.default === TimePicker, andEvents/InternalEventsdeep-equal their current values. A picker built withnew TimePickerand one built withnew TimePicker.defaulteach select a time.Both pages must also log no page errors. The pages are served over a local
node:httpserver, because Chromium blocks module scripts fromfile://.The check catches the bug. With
src/iife.tsreverted to the old namespace export, it fails with"type": "object"and"defaultIsSelf": false.Also
timepicker.iife.min.jsto the shippedtimepicker.iife.js, as review asked. jsDelivr serves both, because it minifies on request.tsconfig.jsonexcludestests/consumerand.pack-check. The fixture importstimepicker.jsby package name, which only resolves inside the scratch consumer.optimizeDeps.entriesis limited toindex.html. Otherwise Playwright's dev server scans the fixture'sindex.htmland warns that it can't resolvetimepicker.js.Gate
npm run verifyexits 0 locally (Node 26.13.1, npm 12.2.2). That covers 39 Playwright tests, attw, publint, the 6-file tarball list, and the consumer checks:typespasses, andchromiumandfirefoxboth open and select a time.🤖 Generated with Claude Code