Skip to content

fix(iife): make the TimePicker global the class, and check the packed tarball in browsers - #78

Merged
jonataswalker merged 1 commit into
masterfrom
test/packed-browser-checks
Nov 14, 2026
Merged

jonataswalker merged 1 commit into
masterfrom
test/packed-browser-checks

Conversation

@jonataswalker

Copy link
Copy Markdown
Owner

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.TimePicker was { Events, InternalEvents, default }. The README's CDN snippet, new TimePicker('#click-trigger', …), threw a TypeError, and only new 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 with default, Events and InternalEvents attached. new TimePicker(…) works as documented, and existing TimePicker.default code keeps working. The ESM build (exports), its export names and timepicker.d.ts are unchanged. The .d.ts is byte-identical to 4.1.0's.

build is now two Vite passes, like ol-contextmenu's: the ESM build with declarations, then --mode iife.

New check: scripts/check-consumers.mjs (in check:package, so in verify)

The script runs npm pack and installs the tarball into a scratch copy of tests/consumer under .pack-check/ (gitignored). Then it checks:

Entry point Check
Declarations Root TypeScript 7 tsc compiles a strict consumer (main.ts) under bundler and under nodenext resolution
ESM through a bundler Root Vite 8 builds the consumer. In Chromium and Firefox, focusing the input opens one picker, which has position: absolute from the injected CSS. Hour 10 and minute 30 set the input to 10:30, the picker closes, and open fired once.
IIFE from a script tag dist/timepicker.iife.js loads from a <script>. In both browsers, typeof TimePicker === 'function', TimePicker.default === TimePicker, and Events / InternalEvents deep-equal their current values. A picker built with new TimePicker and one built with new TimePicker.default each select a time.

Both pages must also log no page errors. The pages are served over a local node:http server, because Chromium blocks module scripts from file://.

The check catches the bug. With src/iife.ts reverted to the old namespace export, it fails with "type": "object" and "defaultIsSelf": false.

Also

  • The README's CDN URL changes from timepicker.iife.min.js to the shipped timepicker.iife.js, as review asked. jsDelivr serves both, because it minifies on request.
  • tsconfig.json excludes tests/consumer and .pack-check. The fixture imports timepicker.js by package name, which only resolves inside the scratch consumer.
  • The dev server's optimizeDeps.entries is limited to index.html. Otherwise Playwright's dev server scans the fixture's index.html and warns that it can't resolve timepicker.js.

Gate

npm run verify exits 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: types passes, and chromium and firefox both open and select a time.

🤖 Generated with Claude Code

… 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>
@jonataswalker
jonataswalker merged commit 5cfaa18 into master Nov 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant