Skip to content

Commit 0583ba8

Browse files
chrispaderclaude
andcommitted
build: publish built JavaScript so apps don't compile the specs
The package's react-native and source fields pointed at src, so apps compiled the decorated .nitro.ts specs with their own Babel config, which React Native's default preset can't parse. The entry points now point at lib, and bob parses the specs through per-target Babel configs. main points at the CommonJS build that bob validates it against, and CI builds the package so a broken build shows up before a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c02fcda commit 0583ba8

7 files changed

Lines changed: 49 additions & 9 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ jobs:
129129
(cd packages/react-native-nitro-sqlite-vec && ../../node_modules/.bin/jest --coverage --runInBand)
130130
(cd example && ../node_modules/.bin/jest --config jest.mocha.config.js --runInBand --watchman=false)
131131
node --test example/macos/scripts/test-macos.test.mjs
132+
- name: Build the library package
133+
if: steps.select.outputs.typescript == 'true'
134+
run: bun --cwd packages/react-native-nitro-sqlite run build
132135
- name: Format C++
133136
if: steps.select.outputs.cpp_format == 'true'
134137
run: |

‎example/babel.config.shared.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ function createExampleBabelConfig(projectRoot) {
77
const aliases = {
88
[libraryPackage.name]: path.join(
99
__dirname,
10-
'../packages/react-native-nitro-sqlite',
11-
libraryPackage.source,
10+
'../packages/react-native-nitro-sqlite/src/index',
1211
),
1312
'stream': 'readable-stream',
1413
'react-native-sqlite-storage': libraryPackage.name,

‎packages/react-native-nitro-sqlite/.eslintrc.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module.exports = {
22
root: true,
33
extends: '../../config/.eslintrc.js',
4+
// bob's per-target Babel configs sit outside the TypeScript project, like babel.config.js.
5+
ignorePatterns: ['babel.config.*.js'],
46
parserOptions: {
57
project: true,
68
tsconfigRootDir: __dirname,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// bob builds the commonjs target with this config so it can parse the decorated .nitro.ts specs.
2+
module.exports = {
3+
presets: [
4+
[
5+
'react-native-builder-bob/babel-preset',
6+
{ modules: 'commonjs', esm: true },
7+
],
8+
],
9+
parserOpts: { plugins: ['decorators'] },
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// bob builds the module target with this config so it can parse the decorated .nitro.ts specs.
2+
module.exports = {
3+
presets: [
4+
[
5+
'react-native-builder-bob/babel-preset',
6+
{ modules: 'preserve', esm: true },
7+
],
8+
],
9+
parserOpts: { plugins: ['decorators'] },
10+
}

‎packages/react-native-nitro-sqlite/package.json‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
"name": "react-native-nitro-sqlite",
33
"version": "10.2.0",
44
"description": "Fast SQLite library for React Native built using Nitro Modules",
5-
"main": "./lib/module/index",
5+
"main": "./lib/commonjs/index",
66
"module": "./lib/module/index",
77
"types": "./lib/typescript/module/index.d.ts",
8-
"source": "./src/index",
9-
"react-native": "./src/index",
8+
"react-native": "./lib/module/index",
109
"exports": {
1110
".": {
12-
"react-native": "./src/index.ts",
1311
"import": {
1412
"types": "./lib/typescript/module/index.d.ts",
1513
"default": "./lib/module/index.js"
@@ -20,7 +18,6 @@
2018
}
2119
},
2220
"./errors": {
23-
"react-native": "./src/errors.ts",
2421
"import": {
2522
"types": "./lib/typescript/module/errors.d.ts",
2623
"default": "./lib/module/errors.js"
@@ -157,13 +154,15 @@
157154
[
158155
"commonjs",
159156
{
160-
"esm": true
157+
"esm": true,
158+
"configFile": "./babel.config.commonjs.js"
161159
}
162160
],
163161
[
164162
"module",
165163
{
166-
"esm": true
164+
"esm": true,
165+
"configFile": "./babel.config.module.js"
167166
}
168167
],
169168
[

‎packages/react-native-nitro-sqlite/src/__tests__/entrypoints.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jest.mock('react-native-nitro-modules', () => ({
1010
},
1111
}))
1212

13+
import { readFileSync } from 'node:fs'
14+
import { join } from 'node:path'
1315
import { NitroModules } from 'react-native-nitro-modules'
1416
import {
1517
NitroSQLite,
@@ -53,4 +55,19 @@ describe('entrypoints', () => {
5355
.find((value) => 'init' in value)
5456
expect(onLoad?.init).toHaveBeenCalledTimes(1)
5557
})
58+
59+
it('publishes built entry points so apps never compile the decorated specs', () => {
60+
const manifest = JSON.parse(
61+
readFileSync(join(__dirname, '../../package.json'), 'utf8'),
62+
) as Record<string, unknown>
63+
const entryPoints = JSON.stringify([
64+
manifest.main,
65+
manifest.module,
66+
manifest['react-native'],
67+
manifest.source,
68+
manifest.exports,
69+
])
70+
71+
expect(entryPoints).not.toContain('src/')
72+
})
5673
})

0 commit comments

Comments
 (0)