From 57bff2d055db06822913746f922c54ef9b625631 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Thu, 22 Oct 2026 18:19:45 +0100 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 3 +++ example/babel.config.shared.js | 3 +-- packages/react-native-nitro-sqlite/.eslintrc.js | 2 ++ .../babel.config.commonjs.js | 10 ++++++++++ .../babel.config.module.js | 10 ++++++++++ packages/react-native-nitro-sqlite/package.json | 13 ++++++------- .../src/__tests__/entrypoints.test.ts | 17 +++++++++++++++++ 7 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 packages/react-native-nitro-sqlite/babel.config.commonjs.js create mode 100644 packages/react-native-nitro-sqlite/babel.config.module.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e98d3f0..3ac78716 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,6 +129,9 @@ jobs: (cd packages/react-native-nitro-sqlite-vec && ../../node_modules/.bin/jest --coverage --runInBand) (cd example && ../node_modules/.bin/jest --config jest.mocha.config.js --runInBand --watchman=false) node --test example/macos/scripts/test-macos.test.mjs + - name: Build the library package + if: steps.select.outputs.typescript == 'true' + run: bun --cwd packages/react-native-nitro-sqlite run build - name: Format C++ if: steps.select.outputs.cpp_format == 'true' run: | diff --git a/example/babel.config.shared.js b/example/babel.config.shared.js index 76bc9e07..05fb6fc7 100644 --- a/example/babel.config.shared.js +++ b/example/babel.config.shared.js @@ -7,8 +7,7 @@ function createExampleBabelConfig(projectRoot) { const aliases = { [libraryPackage.name]: path.join( __dirname, - '../packages/react-native-nitro-sqlite', - libraryPackage.source, + '../packages/react-native-nitro-sqlite/src/index', ), 'stream': 'readable-stream', 'react-native-sqlite-storage': libraryPackage.name, diff --git a/packages/react-native-nitro-sqlite/.eslintrc.js b/packages/react-native-nitro-sqlite/.eslintrc.js index 0d3e3482..ac7bb4c2 100644 --- a/packages/react-native-nitro-sqlite/.eslintrc.js +++ b/packages/react-native-nitro-sqlite/.eslintrc.js @@ -1,6 +1,8 @@ module.exports = { root: true, extends: '../../config/.eslintrc.js', + // bob's per-target Babel configs sit outside the TypeScript project, like babel.config.js. + ignorePatterns: ['babel.config.*.js'], parserOptions: { project: true, tsconfigRootDir: __dirname, diff --git a/packages/react-native-nitro-sqlite/babel.config.commonjs.js b/packages/react-native-nitro-sqlite/babel.config.commonjs.js new file mode 100644 index 00000000..e7f1b5fd --- /dev/null +++ b/packages/react-native-nitro-sqlite/babel.config.commonjs.js @@ -0,0 +1,10 @@ +// bob builds the commonjs target with this config so it can parse the decorated .nitro.ts specs. +module.exports = { + presets: [ + [ + 'react-native-builder-bob/babel-preset', + { modules: 'commonjs', esm: true }, + ], + ], + parserOpts: { plugins: ['decorators'] }, +} diff --git a/packages/react-native-nitro-sqlite/babel.config.module.js b/packages/react-native-nitro-sqlite/babel.config.module.js new file mode 100644 index 00000000..18983497 --- /dev/null +++ b/packages/react-native-nitro-sqlite/babel.config.module.js @@ -0,0 +1,10 @@ +// bob builds the module target with this config so it can parse the decorated .nitro.ts specs. +module.exports = { + presets: [ + [ + 'react-native-builder-bob/babel-preset', + { modules: 'preserve', esm: true }, + ], + ], + parserOpts: { plugins: ['decorators'] }, +} diff --git a/packages/react-native-nitro-sqlite/package.json b/packages/react-native-nitro-sqlite/package.json index ea0fb92a..546e2194 100644 --- a/packages/react-native-nitro-sqlite/package.json +++ b/packages/react-native-nitro-sqlite/package.json @@ -2,14 +2,12 @@ "name": "react-native-nitro-sqlite", "version": "10.2.0", "description": "Fast SQLite library for React Native built using Nitro Modules", - "main": "./lib/module/index", + "main": "./lib/commonjs/index", "module": "./lib/module/index", "types": "./lib/typescript/module/index.d.ts", - "source": "./src/index", - "react-native": "./src/index", + "react-native": "./lib/module/index", "exports": { ".": { - "react-native": "./src/index.ts", "import": { "types": "./lib/typescript/module/index.d.ts", "default": "./lib/module/index.js" @@ -20,7 +18,6 @@ } }, "./errors": { - "react-native": "./src/errors.ts", "import": { "types": "./lib/typescript/module/errors.d.ts", "default": "./lib/module/errors.js" @@ -157,13 +154,15 @@ [ "commonjs", { - "esm": true + "esm": true, + "configFile": "./babel.config.commonjs.js" } ], [ "module", { - "esm": true + "esm": true, + "configFile": "./babel.config.module.js" } ], [ diff --git a/packages/react-native-nitro-sqlite/src/__tests__/entrypoints.test.ts b/packages/react-native-nitro-sqlite/src/__tests__/entrypoints.test.ts index 9991477f..efac7896 100644 --- a/packages/react-native-nitro-sqlite/src/__tests__/entrypoints.test.ts +++ b/packages/react-native-nitro-sqlite/src/__tests__/entrypoints.test.ts @@ -10,6 +10,8 @@ jest.mock('react-native-nitro-modules', () => ({ }, })) +import { readFileSync } from 'node:fs' +import { join } from 'node:path' import { NitroModules } from 'react-native-nitro-modules' import { NitroSQLite, @@ -53,4 +55,19 @@ describe('entrypoints', () => { .find((value) => 'init' in value) expect(onLoad?.init).toHaveBeenCalledTimes(1) }) + + it('publishes built entry points so apps never compile the decorated specs', () => { + const manifest = JSON.parse( + readFileSync(join(__dirname, '../../package.json'), 'utf8'), + ) as Record + const entryPoints = JSON.stringify([ + manifest.main, + manifest.module, + manifest['react-native'], + manifest.source, + manifest.exports, + ]) + + expect(entryPoints).not.toContain('src/') + }) })