Modernize node-re2 for Node 26 - #2
Merged
Merged
Conversation
ronag
marked this pull request as ready for review
July 12, 2026 10:53
There was a problem hiding this comment.
Pull request overview
Modernizes the @nxtedition/re2 native addon and package for Node.js 26 / N-API 10, updates vendored dependencies, and tightens runtime/type/build validation (including prebuild production + verification).
Changes:
- Updated the native binding to N-API 10, improved binary-view handling (Buffer/TypedArray/DataView/SharedArrayBuffer-backed views) and byte-range clamping semantics, and made RE2/RE2Set error reporting more consistent.
- Refreshed package metadata (exports/engines/files), TypeScript typings + contract type-tests, and expanded runtime tests.
- Added Docker + scripts for reproducible linux-x64 prebuild creation, prebuild verification, and release automation.
Reviewed changes
Copilot reviewed 14 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
binding.cc |
N-API 10 migration; robust view + byte-range handling; better RE2/RE2Set error surfacing. |
binding.gyp |
C++20 build settings; updated RE2/Abseil source list and platform compiler settings. |
binding.js |
Uses direct node-gyp-build import for binding resolution. |
index.js |
Public JS API now accepts ArrayBufferView patterns/inputs; enforces binary views and forwards range args. |
index.d.ts |
Typings updated to support BinaryView and new API contracts. |
test.js |
Expanded runtime coverage (byte ranges, invalid patterns, shared views, set errors) + symbol check. |
type-tests/index.ts |
Adds TS contract tests ensuring the intended public typing surface. |
tsconfig.json |
Strict TS config for type-tests + declarations checking. |
package.json |
Node >=26 targeting; conditional exports; updated deps/devDeps and scripts for build/test/prebuild/release. |
package-lock.json |
Lockfile updates for the new dependency set. |
Dockerfile |
Reproducible linux-x64 prebuild build + test in Node 26 Bookworm. |
build.sh |
Docker-driven linux-x64 prebuild extraction into prebuilds/. |
scripts/verify-prebuilds.mjs |
Verifies required prebuilds exist and are included in the npm tarball. |
release.sh |
Automates multi-platform prebuild generation, verification, version bump, and publishing. |
README.md |
Updated usage docs and prebuild/release workflow documentation. |
THIRD_PARTY.md |
Documents vendored RE2 and Abseil submodule revisions/licenses. |
.dockerignore |
Avoids copying unnecessary build artifacts into Docker context. |
.gitignore |
Ignores generated prebuilds/ artifacts. |
Comments suppressed due to low confidence (2)
index.js:50
- Defaulting byteLength to
buffer.byteLength - byteOffsetcan produceNaN(e.g., when callers passNaN/Infinityas byteOffset), which the native clamp logic will treat as length 0. Using the fullbuffer.byteLengthhere lets the native layer clamp length relative to the (clamped) offset, preserving the intended default range semantics even for non-finite offsets.
if (byteOffset === undefined) {
byteOffset = 0
}
if (byteLength === undefined) {
byteLength = buffer.byteLength - byteOffset
}
return binding.regex_test(this.#context, buffer, byteOffset, byteLength)
index.js:83
- Same as RE2#test(): defaulting byteLength to
buffer.byteLength - byteOffsetcan yieldNaNfor non-finite offsets, which clamps to 0 in the native code. Passingbuffer.byteLengthand letting the native layer clamp againstview.size - offsetkeeps defaults correct for all numeric inputs.
if (byteOffset === undefined) {
byteOffset = 0
}
if (byteLength === undefined) {
byteLength = buffer.byteLength - byteOffset
}
return binding.set_test(this.#context, buffer, byteOffset, byteLength)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+150
to
+154
| test('native addon has no unresolved vendored symbols', { | ||
| skip: process.platform === 'win32' ? 'nm is not available on Windows' : false | ||
| }, () => { | ||
| const bindingPath = nodeGypBuild.path(import.meta.dirname) | ||
| const symbols = spawnSync('nm', ['-u', bindingPath], { encoding: 'utf8' }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root causes addressed
The previous binding truncated offsets through signed 32-bit conversions, could form invalid pointers for empty inputs, ignored RE2 set execution errors, logged invalid patterns instead of surfacing JavaScript errors, and built with CPU-specific flags and an incomplete Abseil source set. The package metadata, dependency pins, typings, and test coverage were also stale for the Node 26 target.
Impact
The public CommonJS API remains supported. Native builds now target Node 26, reject unsupported runtimes through package metadata, and use N-API-compatible prebuild lookup. Consumers get corrected byte semantics, deterministic errors, refreshed typings, and portable arm64/x64 build paths.
Dependency changelog
These notes describe the exact gitlink deltas in this PR, rather than attributing earlier upstream changes that were already present in the previous snapshots.
RE2
6569a9a→927f5d5(14 commits), ending at the2025-11-05release:rules_ccBazel loads, a small-test suite, and Bazel 9 compatibility fixesRE2_INSTALLso CMake consumers can disable installation rulesre2/bitstate.ccis the only matcher runtime source changedAbseil
8e77675→0cf0a5c(5 commits), ending at20250814.2:CHECK_*compilation and streamability detection on older GCC versions and restores missing build-rule metadataabsl::HexStringToBytes()Validation
npm ci --ignore-scripts, native build, 14/14 runtime tests, TypeScript tests, and unresolved-symbol check passedlinux/amd64on an arm64 host, Node 26.5.0: clean dependency install, native build, 14/14 runtime tests, and TypeScript tests passed927f5d53caf8111721e734cf24724686bb745f55, Abseil0cf0a5c9d12cc3783363ab20f11613e69fd04c9a