Skip to content

Commit 8bc3144

Browse files
authored
fix: align iOS indices with JS + packaging hygiene; add release workflow (#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 * 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 * 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
1 parent 855e74e commit 8bc3144

7 files changed

Lines changed: 97 additions & 13 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Release
2+
3+
# Publishing is gated on pushing a version tag (e.g. v0.2.1), NOT on merging to
4+
# main. Merge freely; main accumulates unreleased changes. When you're ready to
5+
# ship, run `npm version patch|minor|major` and `git push --follow-tags`.
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
publish:
13+
name: Publish to npm
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
id-token: write # required for OIDC Trusted Publishing + provenance
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 24
23+
cache: npm
24+
registry-url: 'https://registry.npmjs.org'
25+
26+
# Trusted Publishing (OIDC) requires npm >= 11.5.1; the bundled npm may be older.
27+
- run: npm install -g npm@latest
28+
29+
- run: npm ci
30+
31+
- name: Verify tag matches package.json version
32+
run: |
33+
PKG_VERSION="v$(node -p "require('./package.json').version")"
34+
if [ "$PKG_VERSION" != "$GITHUB_REF_NAME" ]; then
35+
echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $PKG_VERSION"
36+
exit 1
37+
fi
38+
39+
- run: npm run lint
40+
- run: npm run test
41+
- run: npm run build
42+
43+
# No NODE_AUTH_TOKEN: auth is via OIDC Trusted Publishing (configured on
44+
# npmjs.com). npm mints a short-lived token from the id-token permission
45+
# and generates provenance automatically.
46+
- name: Publish
47+
run: npm publish

‎.npmignore‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎CHANGELOG.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Changelog
2+
3+
All notable changes to this project are documented here.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- iOS: return UTF-16 offsets from `NSDataDetector` instead of grapheme-cluster
13+
distances, so `start`/`end` align with JavaScript string indices and Android's
14+
ML Kit char offsets. Previously mismatched on text containing emoji, accented,
15+
or non-BMP characters.
16+
- Android: read the library version from `package.json` instead of a hardcoded
17+
value, so `build.gradle` can no longer drift from the published version.
18+
19+
### Changed
20+
21+
- Ship an explicit `files` allowlist in `package.json` and drop the stale
22+
`.npmignore`; development config (ESLint, Prettier, EditorConfig, CONTRIBUTING)
23+
is no longer included in the published tarball.
24+
- README hero image now uses an absolute URL so it renders on npmjs.com.
25+
26+
## [0.2.0]
27+
28+
- Initial public release: cross-platform text data detection using
29+
`NSDataDetector` on iOS and ML Kit Entity Extraction on Android.
30+
31+
[Unreleased]: https://github.com/pablogdcr/react-native-data-detector/compare/v0.2.0...HEAD
32+
[0.2.0]: https://github.com/pablogdcr/react-native-data-detector/releases/tag/v0.2.0

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
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.
66

77
<p align="center">
8-
<img src="data-detector.png" alt="Data Detector Example" width="500" />
8+
<img src="https://raw.githubusercontent.com/pablogdcr/react-native-data-detector/main/data-detector.png" alt="Data Detector Example" width="500" />
99
</p>
1010

1111
## Features

‎android/build.gradle‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'org.jetbrains.kotlin.android'
33

4+
import groovy.json.JsonSlurper
5+
6+
def packageJson = new JsonSlurper().parseText(file('../package.json').text)
7+
48
group = 'expo.modules.datadetector'
5-
version = '0.1.0'
9+
version = packageJson.version
610

711
android {
812
namespace 'expo.modules.datadetector'

‎ios/ReactNativeDataDetectorModule.swift‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public class ReactNativeDataDetectorModule: Module {
8787
continue
8888
}
8989

90-
let start = text.distance(from: text.startIndex, to: matchRange.lowerBound)
91-
let end = text.distance(from: text.startIndex, to: matchRange.upperBound)
90+
// Return UTF-16 offsets so indices align with JavaScript strings (and Android's ML Kit char offsets).
91+
let start = match.range.location
92+
let end = match.range.location + match.range.length
9293

9394
results.append([
9495
"type": type,

‎package.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
"type": "commonjs",
2929
"main": "build/index.js",
3030
"types": "build/index.d.ts",
31+
"files": [
32+
"src",
33+
"build",
34+
"android",
35+
"ios",
36+
"expo-module.config.json",
37+
"README.md",
38+
"LICENSE"
39+
],
3140
"scripts": {
3241
"build": "expo-module build",
3342
"clean": "expo-module clean",

0 commit comments

Comments
 (0)