Skip to content

Modernize node-re2 for Node 26 - #2

Merged
ronag merged 1 commit into
mainfrom
codex/node26-maintenance
Jul 12, 2026
Merged

Modernize node-re2 for Node 26#2
ronag merged 1 commit into
mainfrom
codex/node26-maintenance

Conversation

@ronag

@ronag ronag commented Jul 12, 2026

Copy link
Copy Markdown
Member

Summary

  • modernize the native addon for Node 26 and N-API 10
  • update RE2, Abseil, node-gyp, TypeScript, and packaging dependencies
  • make byte-range handling safe for buffers, typed arrays, data views, empty inputs, and large or infinite bounds
  • report invalid regular expressions and RE2 set execution failures consistently
  • replace host-specific native flags with portable C++20 builds and complete Abseil linkage
  • add runtime, type, symbol, package, prebuild, and release checks
  • add native arm64 plus Docker linux/x64 build and prebuild tooling

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

6569a9a927f5d5 (14 commits), ending at the 2025-11-05 release:

  • optimizes the BitState matcher hot path by hoisting repeated text, visited-state, and list-head loads; matching semantics are unchanged
  • adds explicit rules_cc Bazel loads, a small-test suite, and Bazel 9 compatibility fixes
  • adds RE2_INSTALL so CMake consumers can disable installation rules
  • contains no RE2 public API break in this range; re2/bitstate.cc is the only matcher runtime source changed

Abseil

8e776750cf0a5c (5 commits), ending at 20250814.2:

  • adopts the August 2025 LTS inline namespace and records patch level 2, providing a stable versioned ABI boundary
  • Patch 1 fixes CHECK_* compilation and streamability detection on older GCC versions and restores missing build-rule metadata
  • Patch 2 fixes sign extension and negative-byte indexing in absl::HexStringToBytes()
  • includes LTS build metadata and dependency updates; none intentionally change node-re2's JavaScript API

Validation

  • macOS arm64, Node 26.5.0: npm ci --ignore-scripts, native build, 14/14 runtime tests, TypeScript tests, and unresolved-symbol check passed
  • Docker linux/amd64 on an arm64 host, Node 26.5.0: clean dependency install, native build, 14/14 runtime tests, and TypeScript tests passed
  • exact vendored revisions verified in both environments: RE2 927f5d53caf8111721e734cf24724686bb745f55, Abseil 0cf0a5c9d12cc3783363ab20f11613e69fd04c9a
  • dependency audit: 0 vulnerabilities

@ronag
ronag requested a review from Copilot July 12, 2026 10:51
@ronag
ronag marked this pull request as ready for review July 12, 2026 10:53
@ronag
ronag merged commit 81d5de5 into main Jul 12, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 - byteOffset can produce NaN (e.g., when callers pass NaN/Infinity as byteOffset), which the native clamp logic will treat as length 0. Using the full buffer.byteLength here 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 - byteOffset can yield NaN for non-finite offsets, which clamps to 0 in the native code. Passing buffer.byteLength and letting the native layer clamp against view.size - offset keeps 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 thread test.js
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' })
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.

2 participants