Repository navigation
feat: publish a browser global build loadable with a classic script tag - #441
Merged
Merged
Conversation
Add dist/twd.global.js, an IIFE build that exposes window.TWD with initTWD, the test API and the runner in one file, for environments that block import maps and module scripts. Built from a separate config so the existing ESM and bundled outputs are unchanged. Closes #440
With src/global.ts next to src/global.d.ts, TypeScript treated the .d.ts as the declaration file of the .ts and dropped the window augmentations, which broke lint (no-unsafe-assignment in pace.ts) and the dts build.
Merged
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 #440
What
Adds
dist/twd.global.js, an IIFE build that exposeswindow.TWD. One classic<script src>gives you what three ESM imports give you today:initTWD(fromtwd-js/bundled)twd,userEvent,screenDom,screenDomGlobal,expect(fromtwd-js)describe,it,beforeEach,afterEach(fromtwd-js/runner)It is meant for environments that run classic scripts but block import maps and module scripts, such as Slack's mobile preview of attached HTML prototypes.
How
src/browser-global.ts: new entry that only re-exports existing modules. Everything sits in one module graph, so the runner and the sidebar share the same state.vite.global.config.ts: separate config (formats: ["iife"],name: "TWD", Preact preset, no dts plugin). It runs as an extra step innpm run build.process.env.NODE_ENVis defined at build time. Lib mode leaves it for the consumer's bundler, but an IIFE has none, andreact-is(via@testing-library/dom) reads it unguarded, which threwprocess is not definedin the browser.unpkg/jsdelivrfields inpackage.jsonpoint at the new file, so the bare CDN URL works.docs/frameworks.md.Request mocking is out of scope for this build: it needs
mock-sw.json the page's origin, which these environments can't provide. The docs say to useserviceWorker: false.Impact on existing outputs
None. I hashed every file in
dist/before and after: all 27 existing files are byte-identical, and the only difference is the newtwd.global.js.exportsis unchanged.Size: 381 KB, 96.7 KB gzipped (the esbuild prototype in the issue was 558 KB / 135 KB, because it resolved to React instead of Preact).
Testing
src/tests/global/browser-global.spec.tschecks that the entry exposes the full API. It was written first and failed before the entry existed.window.TWD, that the sidebar renders the test, and that Run All runs it and it passes. This is the check that caught theprocessissue.Release
Needs a minor release (1.13.0) for the CDN URL to exist. The docs example already uses that version.