Skip to content

chore: replace custom build and test scripts with tsc, esbuild and tsx - #2052

Closed
luwes wants to merge 5 commits into
feat/resolve-adapter-typefrom
chore/simplify-tooling
Closed

luwes wants to merge 5 commits into
feat/resolve-adapter-typefrom
chore/simplify-tooling

Conversation

@luwes

@luwes luwes commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #2050 (which is stacked on #2049), because the tests it touches only exist on the v10 branches. No changes to the published library's API or behavior.

Changes

Build and test scripts. scripts/builder and scripts/tester wrapped esbuild in ~180 lines of option parsing. They're replaced by the tools themselves:

Script Before After
build:esm builder (esbuild, per file) tsc, which already emitted the declarations (target es2019, matching the old builder default)
build:demo, start builder esbuild CLI (--bundle --splitting --watch --servedir are built in)
test tester: bundle each file with esbuild, then run it node --import tsx --test test/*.test.tsx test/*/*.test.*
types tsc folded into build:esm

Tests

  • Removed dead tests: test/react-player-tests.tsx (all commented out), test/ReactPlayer/instanceMethods.js (commented-out tests for removed instance methods) and test/ReactPlayer/render.js (only test.skip).
  • Merged test/Player.tsx into test/Player.test.tsx; test files are now all *.test.*.
  • Tests run on Node 22 without NODE_OPTIONS=--no-experimental-global-navigator. server-safe-globals defines its shims with Object.defineProperty (navigator is a getter-only global since Node 21), loads zora before the window shim, and stubs the two DOM APIs react-dom touches when loaded unbundled.

Dependencies

  • Removed builder, tester, cross-env (unused), codecov (deprecated uploader) and rimraf (now rm -rf, like the existing cp -r).
  • Added tsx. Bumped esbuild to ~0.28 so it dedupes with tsx's copy.

CI

  • Coverage is uploaded with codecov/codecov-action@v5 (the README badge had no uploader). It needs a CODECOV_TOKEN repository secret; without one the step logs an error but doesn't fail the job.
  • Test on Node 18 and 22; build on 18/20/22. Node 16 is dropped because esbuild 0.28 requires Node 18+.

Testing

  • npm run clean && npm run build (tsc + demo), npm run lint and npm run test:coverage pass on Node 22.19 with no flags.
  • Same 54 assertions pass as before, and a failing assertion exits non-zero.
  • dist/ has the same files as before (JS + .d.ts per source file, "use client" and webpack chunk-name comments preserved), and import('react-player') works from the build.
  • esbuild … --watch=forever --servedir=demo serves the demo.

luwes added 5 commits October 1, 2026 17:53
The shim replaced the global URL with a plain object, which breaks code that parses URLs with new URL(), such as resolveAdapterType from @videojs/react. Subclass the real URL and keep the mocked createObjectURL.
Replace the URL regexes in patterns.ts with resolveAdapterType and resolveMimeType from @videojs/react, so ReactPlayer recognizes the same sources as the Video.js v10 media components it renders.

- YouTube, Vimeo, Wistia, Mux, Spotify, Twitch, TikTok and DASH sources are matched by adapter type.
- Mux stream URLs ending in .m3u8 still play with hls.js.
- File playback keeps AUDIO_EXTENSIONS and VIDEO_EXTENSIONS as a fallback for extensions Video.js does not recognize (m4v, m4b, weba, oga, spx, ...).

Newly recognized sources:
- localized Spotify URLs (open.spotify.com/intl-de/track/...) and spotify: URIs
- youtube/<id> and vimeo/<id> shorthands
- .flac files

Breaking changes:
- react-player/patterns no longer exports HLS_EXTENSIONS, DASH_EXTENSIONS, MATCH_URL_MUX, MATCH_URL_YOUTUBE, MATCH_URL_VIMEO, MATCH_URL_WISTIA, MATCH_URL_SPOTIFY, MATCH_URL_TWITCH or MATCH_URL_TIKTOK. Use resolveAdapterType from @videojs/react instead.
- These URLs are no longer matched to a service player and fall back to the HTML player: youtube.com/user/..., music.youtube.com, vimeo.com/channels/..., vimeo.com/showcase/... and player.twitch.tv/?video=...

BREAKING CHANGE: URL pattern exports were removed from react-player/patterns in favor of resolveAdapterType from @videojs/react, and some URLs now resolve to a different player.
Every built-in player key is a Video.js adapter type (plus html), so patterns.ts resolves a URL to its player key once and canPlay(key) compares against it, instead of a table of per-player predicates. The Mux .m3u8 -> hls.js rule and the extension fallback for the HTML player are unchanged; player selection is identical for every URL compared. Also removes canPlayFile, which handled arrays of sources that src no longer accepts.

Breaking changes:
- react-player/patterns exports canPlay as a function of the player key: canPlay.youtube(url) becomes canPlay('youtube')(url).

BREAKING CHANGE: canPlay in react-player/patterns is now canPlay(key)(url) instead of canPlay[key](url).
- test/react-player-tests.tsx was entirely commented out.
- test/ReactPlayer/instanceMethods.js only had commented-out tests for the removed instance methods.
- test/ReactPlayer/render.js only had skipped tests.
- test/Player.tsx and test/Player.test.tsx both tested Player; merge them into Player.test.tsx.
…d tsx

scripts/builder and scripts/tester wrapped esbuild in ~180 lines of option parsing. Use the tools directly instead:

- build:esm: tsc emits the JS next to the declarations it already emitted (target es2019, matching the old builder default).
- build:demo / start: the esbuild CLI, which supports --bundle, --splitting, --watch and --servedir itself.
- test: node --test runs each test file through tsx. Test files are named *.test.* so one glob finds them.

Tests now run on Node 22 without NODE_OPTIONS=--no-experimental-global-navigator: server-safe-globals defines the shims with Object.defineProperty (navigator is a getter-only global in Node 21+), loads zora before the window shim so it starts in Node mode, and stubs the few DOM APIs react-dom touches when it is loaded unbundled.

Also:
- Remove the unused cross-env, the deprecated codecov uploader and rimraf (rm -rf).
- Bump esbuild to ~0.28 so it dedupes with tsx's copy.
- CI: upload coverage with codecov/codecov-action, test on Node 18 and 22, and build on Node 18/20/22 (esbuild 0.28 needs Node 18+).
@luwes

luwes commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Superseded by the pnpm + Vite+ tooling migration in a424322 on #2049 (vp pack / vp test / Oxlint + Oxfmt / tsgo), which replaces the same scripts/builder and scripts/tester setup and converts the tests to Vitest (they pass on Node 22 without flags). Closing.

Not carried over: removing the dead tests (test/react-player-tests.tsx, the commented-out test/ReactPlayer/instanceMethods.js, and the skipped tests in test/ReactPlayer/render.test.jsx). That can be a small follow-up.

@luwes luwes closed this Oct 2, 2026

This branch was successfully deployed

1 active deployment
github-preview — 1e781d81 Deployed Oct 2, 2026 by luwes via deploy-preview #267
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