Skip to content

Modernize for 2.0.0: streaming decoder, prebuilt binaries, ESM and typings - #1

Merged
johangu merged 13 commits into
masterfrom
worktree-modernize
Oct 16, 2026
Merged

johangu merged 13 commits into
masterfrom
worktree-modernize

Conversation

@johangu

@johangu johangu commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Brings the bindings up to date with the latest minimp3 and Node.js, as 2.0.0. See CHANGELOG.md for the user-facing list of fixes and breaking changes.

What changed

  • Streaming decoder rewrite. One decoder state per stream, partial frames carried between chunks, ID3v2/ID3v1 skipped, encoder delay and padding trimmed from the Xing/LAME tag, 'format' event. The published 1.0.0 lost audio when input arrived in small chunks (262656 of 352800 bytes at 4096-byte chunks, 0 at 417) and did not load at all in a clean install (debug was only a devDependency).
  • minimp3 updated to upstream ea99364 (2026-07-27), unmodified copies (lib/UPSTREAM.md).
  • API: Decoder.decodeSync(buffer), ES module entry point next to CommonJS, TypeScript typings for both.
  • Prebuilt binaries (node-gyp-build + prebuildify, N-API): macOS arm64/x64, Linux glibc x64/arm64, Windows x64. Source build remains the fallback.
  • Node.js 22 or later.
  • Tooling: node:test suite with fixtures, ESLint 10 + neostandard, CI, a release workflow with npm trusted publishing (GitHub Actions on Node 24 versions), npm run release -- <major|minor|patch>, CONTRIBUTING.md, README rewrite.

All commits are signed.

Verified

  • CI on this PR passes: lint, and the tests plus type check on Node 22, 24 and 26 on Linux, macOS and Windows, each compiling the addon from source.
  • Locally: output matches ffmpeg's decode of all four fixtures to within +-2 LSB, with identical length, at chunk sizes down to 1 byte. A 3000-round fuzz run did not crash.
  • Installing the packed tarball with --ignore-scripts: macOS arm64 (Node 26) and Linux arm64 (Debian 11 and 12, no compilers) load the prebuilt binary. On Alpine (musl) it fails with a clear message without scripts, and builds from source with them.
  • npm run release was tested end to end against a throwaway local remote (22 checks), never against this repository.

After merging

The Release workflow only runs by hand or on a v* tag, so it has not run yet. It builds the macOS x64, Linux x64 and Windows prebuilds, which have not been exercised, on the macos-15-intel and ubuntu-24.04-arm runners.

  1. Run Release by hand from the Actions tab on master. This is a dry run, the publish job only runs for tags.
  2. On master: npm run release -- major. Pushing the tag publishes 2.0.0 to npm via the trusted publisher.

Replace both headers with unmodified upstream copies and record the pinned commit in lib/UPSTREAM.md. Drops the stray <iostream> include, and ignore build/ and prebuilds/ in git.
Tests for the current Decoder stream. Tests that document known bugs in the original chunk handling (dropped last sample frame, throwing on partial frames) are marked todo until the streaming rewrite lands.
The native Decoder class keeps one mp3dec_t per stream and carries partial frames between chunks, replacing the per-chunk mp3dec_load_buf call that broke on chunk boundaries, leaked its output buffer and dropped the last sample frame. It skips ID3v2 tags, ignores ID3v1 tags, trims encoder delay and padding using the Xing/LAME tag, and reports sample rate and channels. The JS Decoder emits a 'format' event (same shape as node-speaker options) before the first data. Also bump node-addon-api to 8 and stop requiring the dev-only 'debug' package at runtime. Tests now cover four fixtures at several chunk sizes, tags, truncated and corrupt input.
Gives contributors and CI the same dependency tree. It is not published to npm, so consumers are unaffected.
index.mjs wraps the CommonJS module so both require and import work, with named exports. An exports map in package.json selects the entry point and its typings (index.d.cts, index.d.mts). Decoder.decodeSync(buffer) decodes a whole MP3 in memory through the same native decoder as the stream and returns { format, pcm }. Tests cover both module systems and decodeSync, and npm run test:types type-checks the typings for CJS and ESM consumers.
The format now only describes the decoded PCM (sampleRate, channels, bitDepth). The output is always signed little-endian, so the flag added nothing for general consumers. node-speaker still accepts the object as is, since it defaults signed to true for 16-bit.
Document the current API (stream, decodeSync, format event and output format), behaviour notes and limitations. Replace the node-speaker example with generic ones: piping to a file and writing a WAV file from a buffer. Both examples were run against a fixture.
The addon is loaded with node-gyp-build, which uses the binary in prebuilds/ and otherwise compiles from source on install. The binary is N-API based, so one build per platform covers every supported Node version. Linux binaries link libstdc++ statically and are tagged with their libc, so Alpine falls back to compiling instead of failing to load a glibc binary.

CI tests Node 22, 24 and 26 on Linux, macOS and Windows. The release workflow builds prebuilds for macOS (arm64, x64), Linux glibc (x64, arm64, built on Debian 11) and Windows x64, installs the packed tarball with install scripts disabled on each platform, and publishes with provenance when a v* tag is pushed. prepublishOnly refuses to publish unless every prebuild is present. scripts/smoke-install.js installs the tarball the way a user would.

Also: require Node 22 or later, publish an explicit files list, replace the 'bindings' dependency, remove the unused 'debug' dependency and the dead prettier-eslint-cli, update the author email and describe installation in the README.
scripts/release.js bumps the version (major, minor or patch), commits, tags and pushes, which starts the release workflow that publishes to npm. It refuses to run unless on master with a clean, up to date tree and a free tag, runs the tests, and asks for confirmation. --dry-run shows what would happen.
Development setup, how the bundled minimp3 and the prebuilt binaries work, and how to cut a release with npm run release.
Flat config that keeps the standard style the code already follows. Adds npm run lint and lint:fix, a lint job in CI, and runs the linter before npm run release. The old ESLint 5 configuration and plugins are removed.
Describes the fixes, additions and breaking changes relative to the published 1.0.0, with figures from running that version: it fails to load in a clean install, loses audio when the input arrives in smaller chunks and returns extra encoder silence. The changelog is included in the package, and npm run release requires an entry for the version it is making.
checkout v7, setup-node v7, upload-artifact v7 and download-artifact v8, replacing the v4 versions that run on Node 20, which GitHub deprecated. None of the breaking changes since v4 affect how the workflows use them.
@johangu
johangu marked this pull request as ready for review October 16, 2026 10:28
@johangu
johangu merged commit 83ecd15 into master Oct 16, 2026
10 checks passed
@johangu
johangu deleted the worktree-modernize branch October 16, 2026 10:30
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