Skip to content

refactor!: modernize codebase, switch to ES Modules, and replace Gulp with Microbundle#22

Open
cougrimes wants to merge 2 commits intoamorey:masterfrom
cougrimes:master
Open

refactor!: modernize codebase, switch to ES Modules, and replace Gulp with Microbundle#22
cougrimes wants to merge 2 commits intoamorey:masterfrom
cougrimes:master

Conversation

@cougrimes
Copy link

What

I have modernized the repository by migrating the source code to ES Modules, replacing the Gulp build system with Microbundle, and implementing an automated documentation pipeline using TypeDoc.

Why

The previous codebase contained invalid JavaScript (top-level return statement) that prevented modern test runners and bundlers from processing the source directly. Additionally, the project relied on deprecated tooling (Bower, Gulp v3) and outdated documentation practices that made maintenance difficult and prevented tree-shaking for end users.

How

  • Source Code: Refactored src/sentinel.js to a standard ES Module (export default), allowing it to be imported directly in modern tools while preserving the global window.sentinel for legacy browser support.
  • Build System: Replaced the complex Gulp build chain and umd-templates/ with Microbundle, which automatically generates optimized UMD, CJS, and ESM formats.
  • Documentation: Implemented TypeDoc and a custom script (scripts/build-docs-data.js) that automatically generates documentation pages from the raw HTML files in examples/, ensuring the docs and code examples never drift apart.
  • Testing: The legacy test suite used Mocha for the test structure (describe, it) and Chai for assertions (assert, expect), relying on global variables in a browser environment. This was migrated to @web/test-runner, enabling faster, browser-native testing without a build step.
  • Cleanup: Removed bower.json and updated package.json entry points (source, module, unpkg) to align with modern standards.

Testing

  1. Unit Tests: Ran npm run test to verify the test suite passes in a headless browser via @web/test-runner.
  2. Build Verification: Ran npm run build and verified that dist/ contains valid sentinel.umd.js (legacy) and sentinel.module.js (modern) files.
  3. Docs Generation: Ran npm run docs:build and visually verified the generated site in docs/index.html correctly lists the API and renders the Examples sidebar.
  4. Legacy Support: Visually inspected the UMD build to ensure it transpiled const/let to var, ensuring syntax compatibility for IE11.

Questions

  • Legacy Browser Support: I have updated the README to officially drop support for IE10, Android 4.4 and iOS 9 and below, as the code listens for standard animationstart events (which these browsers do not support without prefixes). The code is technically syntax-compatible (ES5), but functionally incompatible without polyfills. Is this acceptable?

* **build:** replaced Gulp build system with Microbundle for zero-config, optimized builds.
* **core:** refactored `src/sentinel.js` to a standard ES Module, removing the invalid top-level `return` statement.
* **chore:** removed `bower.json` in favor of NPM and `unpkg` distribution.

### Features

* **core:** refactored source to ES Modules (`export default`), enabling tree-shaking and direct import in modern tools.
* **build:** implemented `microbundle` to auto-generate UMD, CJS, and ESM formats.
* **docs:** added automated pipeline to generate a full documentation website from `examples/` using TypeDoc.
* **legacy:** added explicit `window.sentinel` assignment and `sentinel-load` event dispatch for legacy script tag support.

### Bug Fixes

* **core:** fixed issue where `off()` failed to clear callbacks when no specific callback function was provided.
* **core:** corrected invalid syntax (top-level return) that prevented modern test runners from executing source code directly.

### Documentation

* **readme:** modernized installation instructions, added ES Module usage, and updated CDN links to `unpkg`.
* **readme:** updated Browser Support matrix to accurately reflect modern environment (IE11+ via UMD, dropping IE10/Android 4.4 claims).
* **tsdoc:** added comprehensive TSDoc comments to all public API methods for IDE IntelliSense.
* **examples:** integrated `examples/` directory as first-class documentation pages in the generated site.

### Build

* **test:** migrated test suite to `@web/test-runner` for faster, browser-native testing.
* **config:** updated `package.json` with correct `source`, `module`, `unpkg`, and `types` entry points.
* **chore:** removed outdated dev dependencies (`gulp`, `del`, `jshint`) and legacy templates.
… and import sentinel) for backward compatability.

This does generate a harmless "Consumers of your bundle will have to use `sentinel["default"]` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning". However, smart bundlers already know to look at default... by default.
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

Comments