Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
branches: [master]
pull_request:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: npm ci --ignore-scripts
- run: npm run lint

test:
name: Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [22, 24, 26]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
# No prebuilds are checked in, so this compiles the addon from source
- run: npm ci
- run: npm test
- run: npm run test:types
116 changes: 116 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Release

# Builds the prebuilt binaries on every platform, checks that the packed
# tarball installs and works from them alone, and, for a version tag, publishes.
#
# Release: bump "version" in package.json, commit, then push a tag `v<version>`.
# Run by hand (workflow_dispatch) to check the whole pipeline without publishing.
on:
push:
tags: ['v*']
workflow_dispatch:

permissions:
contents: read

jobs:
# Built in Debian 11 (glibc 2.31) so the binary loads on any glibc that Node supports
prebuild-linux:
name: Prebuild ${{ matrix.target }}
runs-on: ${{ matrix.os }}
container: node:22-bullseye
strategy:
fail-fast: false
matrix:
include:
- { target: linux-x64, os: ubuntu-latest }
- { target: linux-arm64, os: ubuntu-24.04-arm }
steps:
- uses: actions/checkout@v7
# Without scripts, so that the tests below load the prebuilt binary
- run: npm ci --ignore-scripts
- run: npm run prebuildify
- run: npm test
- name: Check the binary needs no newer glibc than Node itself does (2.28)
run: |
highest=$(objdump -T prebuilds/${{ matrix.target }}/*.node | grep -oE 'GLIBC_[0-9.]+' | sort -Vu | tail -n 1)
echo "requires $highest"
test "$(printf '%s\n' "$highest" GLIBC_2.28 | sort -V | tail -n 1)" = GLIBC_2.28
- uses: actions/upload-artifact@v7
with:
name: prebuilds-${{ matrix.target }}
path: prebuilds/
if-no-files-found: error

prebuild:
name: Prebuild ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { target: darwin-arm64, os: macos-latest }
- { target: darwin-x64, os: macos-15-intel }
- { target: win32-x64, os: windows-latest }
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
- run: npm ci --ignore-scripts
- run: npm run prebuildify
- run: npm test
- uses: actions/upload-artifact@v7
with:
name: prebuilds-${{ matrix.target }}
path: prebuilds/
if-no-files-found: error

# Installs the packed tarball, without running install scripts, on each
# platform and Node version: only a working prebuilt binary passes.
smoke:
name: Install on Node ${{ matrix.node }}, ${{ matrix.os }}
needs: [prebuild-linux, prebuild]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-15-intel, windows-latest]
node: [22, 26]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
- uses: actions/download-artifact@v8
with:
pattern: prebuilds-*
path: prebuilds/
merge-multiple: true
- run: npm ci --ignore-scripts
- run: npm run test:install

publish:
name: Publish to npm
if: startsWith(github.ref, 'refs/tags/v')
needs: smoke
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # npm trusted publishing and provenance
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: The tag matches the version in package.json
run: test "v$(node -p "require('./package.json').version")" = "$GITHUB_REF_NAME"
- uses: actions/download-artifact@v8
with:
pattern: prebuilds-*
path: prebuilds/
merge-multiple: true
- run: npm ci --ignore-scripts
# prepublishOnly refuses to publish unless every prebuild is present
- run: npm publish --provenance --access public
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ bower_components
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
build/

# Prebuilt binaries, produced by CI
prebuilds/

# Dependency directories
node_modules/
Expand Down
57 changes: 57 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Changelog

## 2.0.0

A rewrite of the decoder. The `Decoder` stream is used the same way, but its output
is different, and often correct where it was not before. Please read **Changed**.

### Fixed

- `1.0.0` could not be loaded after installing it from npm: `require('minimp3')`
threw `Cannot find module 'debug'`, because `debug` was only a development
dependency.
- The stream decoded every chunk of input on its own, so frames that straddled a
chunk boundary were lost, without an error. For a 2 second file, which should
give 352800 bytes of audio, `1.0.0` gave 262656 bytes with 4096 byte chunks and
nothing at all with chunks of 417 bytes. The decoder now keeps its state from one
chunk to the next, and the output is the same whatever the chunk sizes are.
- The decoded audio was not freed, which leaked memory for every chunk.
- The audio included the silence that encoders add at the start and the end. If the
file has a Xing/Info/LAME tag, which most encoders write, it is trimmed now, so
the output is as long as the original audio (352800 instead of 364032 bytes for the
file above).
- ID3v2 tags at the start and ID3v1 tags at the end of the file are skipped,
wherever the chunk boundaries fall.

### Added

- The `'format'` event and `decoder.format`, with the sample rate, the number of
channels and the bit depth of the audio.
- `Decoder.decodeSync(buffer)` to decode a complete MP3 in memory.
- An ES module entry point (`import Decoder, { decodeSync } from 'minimp3'`), and
TypeScript typings for both module systems.
- Prebuilt binaries for macOS (arm64, x64), Linux with glibc (x64, arm64) and
Windows (x64). Installing no longer needs a compiler on those platforms, and it
works with `--ignore-scripts`. Other platforms still build from source when the
package is installed.

### Changed

- **Node.js 22 or later is required.**
- **The output is different** from `1.0.0`: it is the exact audio, as described
above, and not the audio with extra silence. Code that relied on the old lengths
needs to be updated.
- Input that is not MP3 data produces no output and no error. `1.0.0` threw
`Unknown failure` in some cases.
- A change of sample rate, number of channels or MPEG layer in the middle of a
stream is an error, emitted as an `'error'` event.
- The options passed to `new Decoder(options)` are passed on to the `Transform`
stream. They were ignored before. `objectMode` is always off.
- Debug logging uses Node's own `NODE_DEBUG=minimp3` and not `DEBUG=minimp3`.
- minimp3 is updated from the 2019 version to
[`ea99364`](https://github.com/lieff/minimp3/commit/ea99364f61c14656440e8d77e9c233ccf3124633)
(2026-07-27), which includes its security hardening since then.

### Removed

- The `debug` and `bindings` packages are no longer used.
62 changes: 62 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Contributing

## Development

You need Node.js 22 or later, plus Python 3, make and a C++ compiler to build the
addon (Xcode command line tools on macOS, `build-essential` on Debian/Ubuntu, Visual
Studio Build Tools on Windows).

```sh
npm install # installs and compiles the addon from source
npm run build # recompile after changing lib/minimp3.cc
npm run lint # code style ("standard", through neostandard); lint:fix repairs most of it
npm test # unit tests (node:test)
npm run test:coverage # the same, with coverage of the JavaScript
npm run test:types # type-checks the typings with CommonJS and ESM consumers
```

The test fixtures in `test/fixtures` are described in the README next to them.

### The bundled minimp3

`lib/minimp3.h` and `lib/minimp3_ex.h` are unmodified copies of
[lieff/minimp3](https://github.com/lieff/minimp3). To update them, download both
files from the commit you want and record its SHA in `lib/UPSTREAM.md`. Then run
the tests and compare the output of the fixtures with ffmpeg's.

### Prebuilt binaries

The package ships prebuilt binaries (see `.github/workflows/release.yml`), so
nothing is compiled when users install it. They are only built in CI. To try
building one on your machine:

```sh
npm run prebuildify # writes prebuilds/<platform>-<arch>/
npm run test:install # packs the package and installs it into an empty project
# without running any install script
```

## Releasing

Releases are made from `master`, with a clean working tree. Update `CHANGELOG.md`
(if there is one) with an entry for the new version, commit it, then run:

```sh
npm run release -- patch # or minor, or major
```

(The `--` is needed for npm to pass the argument on. Add `--dry-run` to see what
would happen without changing anything.)

It checks that `master` is up to date with `origin`, runs the tests, asks for
confirmation, bumps the version in `package.json` and the lockfile, commits it as
"Release x.y.z", tags it `vx.y.z` and pushes both.

Pushing the tag starts the **Release** workflow, which builds the binaries for every
platform, installs the packed package on each of them, and publishes it to npm with
provenance. Publishing uses npm's trusted publishing, so there is no token to
manage: the package's settings on npmjs.com name this repository and
`release.yml`.

You can run the **Release** workflow by hand from the Actions tab to test the whole
pipeline without publishing.
Loading
Loading