From 4d29d4d1d3c7255f5d5a8f1c289b2d52df55816e Mon Sep 17 00:00:00 2001 From: Pablo Giraud-Carrier Date: Tue, 2 Jun 2026 14:12:36 +0200 Subject: [PATCH 1/3] fix: align iOS indices with JS, fix packaging hygiene (v0.2.1) - iOS: return UTF-16 offsets from NSDataDetector instead of grapheme distances so start/end align with JavaScript strings and Android's ML Kit char offsets (broke on emoji/accented/non-BMP text) - android: read version from package.json instead of hardcoded 0.1.0 so it never drifts from the published version again - package.json: add explicit "files" allowlist; stop shipping dev cruft (eslint/prettier/editorconfig/CONTRIBUTING) in the tarball - remove stale .npmignore (listed deleted files, missed new ones) - README: use absolute raw GitHub URL for hero image so it renders on npmjs.com --- .npmignore | 9 --------- README.md | 2 +- android/build.gradle | 6 +++++- ios/ReactNativeDataDetectorModule.swift | 5 +++-- package.json | 11 ++++++++++- 5 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index e9f611a..0000000 --- a/.npmignore +++ /dev/null @@ -1,9 +0,0 @@ -__mocks__ -__tests__ -.eslintrc.js -babel.config.js -tsconfig.json -example/ -*.png -.github/ -.claude/ diff --git a/README.md b/README.md index 1c8cac7..ea1d613 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Cross-platform text data detection for React Native. Uses **NSDataDetector** on iOS and **ML Kit Entity Extraction** on Android to detect phone numbers, URLs, emails, dates, and addresses — returning structured results to JavaScript.

- Data Detector Example + Data Detector Example

## Features diff --git a/android/build.gradle b/android/build.gradle index 220d676..b047d7f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,8 +1,12 @@ apply plugin: 'com.android.library' apply plugin: 'org.jetbrains.kotlin.android' +import groovy.json.JsonSlurper + +def packageJson = new JsonSlurper().parseText(file('../package.json').text) + group = 'expo.modules.datadetector' -version = '0.1.0' +version = packageJson.version android { namespace 'expo.modules.datadetector' diff --git a/ios/ReactNativeDataDetectorModule.swift b/ios/ReactNativeDataDetectorModule.swift index a91fa5b..0ac691d 100644 --- a/ios/ReactNativeDataDetectorModule.swift +++ b/ios/ReactNativeDataDetectorModule.swift @@ -87,8 +87,9 @@ public class ReactNativeDataDetectorModule: Module { continue } - let start = text.distance(from: text.startIndex, to: matchRange.lowerBound) - let end = text.distance(from: text.startIndex, to: matchRange.upperBound) + // Return UTF-16 offsets so indices align with JavaScript strings (and Android's ML Kit char offsets). + let start = match.range.location + let end = match.range.location + match.range.length results.append([ "type": type, diff --git a/package.json b/package.json index f1f460c..c277891 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-data-detector", - "version": "0.2.0", + "version": "0.2.1", "description": "Cross-platform text data detection for React Native. Uses NSDataDetector on iOS and ML Kit Entity Extraction on Android to detect phone numbers, URLs, emails, dates, and addresses.", "keywords": [ "react-native", @@ -28,6 +28,15 @@ "type": "commonjs", "main": "build/index.js", "types": "build/index.d.ts", + "files": [ + "src", + "build", + "android", + "ios", + "expo-module.config.json", + "README.md", + "LICENSE" + ], "scripts": { "build": "expo-module build", "clean": "expo-module clean", From 0b14be15005df1972b66bcf89d722d22df722abc Mon Sep 17 00:00:00 2001 From: Pablo Giraud-Carrier Date: Tue, 2 Jun 2026 15:46:11 +0200 Subject: [PATCH 2/3] ci: add tag-triggered release workflow; keep version at 0.2.0 Decouple releasing from merging: fixes land in main at 0.2.0 (the last published version) and accumulate under CHANGELOG [Unreleased]. Publishing is gated on pushing a v* tag, not on merge. - add .github/workflows/release.yml: npm publish --provenance on v* tags, with a guard that the tag matches package.json version - add CHANGELOG.md (Keep a Changelog format) - revert version 0.2.1 -> 0.2.0; release happens later via npm version + tag --- .github/workflows/release.yml | 43 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 32 ++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8f81103 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: Release + +# Publishing is gated on pushing a version tag (e.g. v0.2.1), NOT on merging to +# main. Merge freely; main accumulates unreleased changes. When you're ready to +# ship, run `npm version patch|minor|major` and `git push --follow-tags`. +on: + push: + tags: + - 'v*' + +jobs: + publish: + name: Publish to npm + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # required for npm provenance + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: npm + registry-url: 'https://registry.npmjs.org' + + - run: npm ci + + - name: Verify tag matches package.json version + run: | + PKG_VERSION="v$(node -p "require('./package.json').version")" + if [ "$PKG_VERSION" != "$GITHUB_REF_NAME" ]; then + echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $PKG_VERSION" + exit 1 + fi + + - run: npm run lint + - run: npm run test + - run: npm run build + + - name: Publish + run: npm publish --provenance + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..158ff87 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,32 @@ +# Changelog + +All notable changes to this project are documented here. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Fixed + +- iOS: return UTF-16 offsets from `NSDataDetector` instead of grapheme-cluster + distances, so `start`/`end` align with JavaScript string indices and Android's + ML Kit char offsets. Previously mismatched on text containing emoji, accented, + or non-BMP characters. +- Android: read the library version from `package.json` instead of a hardcoded + value, so `build.gradle` can no longer drift from the published version. + +### Changed + +- Ship an explicit `files` allowlist in `package.json` and drop the stale + `.npmignore`; development config (ESLint, Prettier, EditorConfig, CONTRIBUTING) + is no longer included in the published tarball. +- README hero image now uses an absolute URL so it renders on npmjs.com. + +## [0.2.0] + +- Initial public release: cross-platform text data detection using + `NSDataDetector` on iOS and ML Kit Entity Extraction on Android. + +[Unreleased]: https://github.com/pablogdcr/react-native-data-detector/compare/v0.2.0...HEAD +[0.2.0]: https://github.com/pablogdcr/react-native-data-detector/releases/tag/v0.2.0 diff --git a/package.json b/package.json index c277891..2532069 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-data-detector", - "version": "0.2.1", + "version": "0.2.0", "description": "Cross-platform text data detection for React Native. Uses NSDataDetector on iOS and ML Kit Entity Extraction on Android to detect phone numbers, URLs, emails, dates, and addresses.", "keywords": [ "react-native", From 6773a76eb5506c4fe7844cc1a34e403b51f5b73e Mon Sep 17 00:00:00 2001 From: Pablo Giraud-Carrier Date: Tue, 2 Jun 2026 15:59:10 +0200 Subject: [PATCH 3/3] ci: publish via OIDC Trusted Publishing instead of NPM_TOKEN - drop NODE_AUTH_TOKEN/NPM_TOKEN secret; auth now via id-token (OIDC) trusted publisher configured on npmjs.com - upgrade npm to latest on the runner (OIDC needs >= 11.5.1) - provenance is generated automatically under trusted publishing, so the explicit --provenance flag is no longer needed --- .github/workflows/release.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8f81103..11989fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - id-token: write # required for npm provenance + id-token: write # required for OIDC Trusted Publishing + provenance steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -23,6 +23,9 @@ jobs: cache: npm registry-url: 'https://registry.npmjs.org' + # Trusted Publishing (OIDC) requires npm >= 11.5.1; the bundled npm may be older. + - run: npm install -g npm@latest + - run: npm ci - name: Verify tag matches package.json version @@ -37,7 +40,8 @@ jobs: - run: npm run test - run: npm run build + # No NODE_AUTH_TOKEN: auth is via OIDC Trusted Publishing (configured on + # npmjs.com). npm mints a short-lived token from the id-token permission + # and generates provenance automatically. - name: Publish - run: npm publish --provenance - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish