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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
.github
build
node_modules
prebuilds
npm-debug.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
yarn.lock
.vscode
build
prebuilds/
.claude
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:26.5.0-bookworm

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
python3 \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /node-re2

COPY package*.json ./
RUN npm ci --ignore-scripts

COPY . .

ARG JOBS=8
RUN JOBS=$JOBS npx prebuildify \
-t "$(node -p process.versions.node)" \
--napi \
--strip \
--tag-libc \
--arch x64

# PREBUILDS_ONLY makes node-gyp-build ignore build/Release, proving that the
# binary which will be embedded in the npm tarball is independently loadable.
RUN npm run test:prebuild
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @nxtedition/re2

Native [RE2](https://github.com/google/re2) partial matching for Node.js 26 and later. It exposes a small API for matching one expression or many expressions at once without backtracking.

```js
import { RE2, RE2Set } from '@nxtedition/re2'

const expression = new RE2('foo')
expression.test(Buffer.from('before foo after')) // true

const expressions = new RE2Set(['foo', 'bar'])
expressions.test(Buffer.from('bar')) // [1]
```

Patterns may be strings, Buffers, TypedArrays, or DataViews. Input must be a Buffer, TypedArray, or DataView. SharedArrayBuffer-backed views are supported. Both APIs operate on bytes; optional `byteOffset` and `byteLength` values select the input range. Negative values clamp to zero, values past the view clamp to its bounds, and fractional values are truncated.

Invalid RE2 syntax throws during construction. `RE2Set#test()` returns every matching pattern index, or `[]` when nothing matches; index order is unspecified.

## Prebuilds

Release tarballs include Node-API prebuilds for `darwin-arm64` and glibc `linux-x64`. The Linux binary is built in the Node 26 Bookworm image for compatibility with both Bookworm and newer glibc systems, and is libc-tagged so it is never selected on musl. Other platforms fall back to a source build when install scripts are enabled.

`./build.sh` builds and tests the Linux prebuild in Docker. On an arm64 Mac, `./release.sh` builds both supported platforms, tests the current platform with source-build fallback disabled, verifies that both binaries are present in the npm tarball, and then prompts for the version bump before publishing.

## Development

```sh
npm install
npm test
```

`npm test` always rebuilds the native addon before running the JavaScript and TypeScript contract tests.
6 changes: 6 additions & 0 deletions THIRD_PARTY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Third-party sources

The native addon vendors these dependencies as Git submodules:

- RE2 `2025-11-05` (`927f5d53caf8111721e734cf24724686bb745f55`), licensed under the BSD 3-Clause License in `vendor/re2/LICENSE`.
- Abseil LTS `20250814.2` (`0cf0a5c9d12cc3783363ab20f11613e69fd04c9a`), licensed under the Apache License 2.0 in `vendor/abseil-cpp/LICENSE`.
Loading