From bf718230ac9a9d56a1cf1fd99f0f8e955da13aae Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo <satyajit.happy@gmail.com> Date: Thu, 27 Mar 2025 15:20:02 +0100 Subject: [PATCH] fix: fix configuration for fabric view templates fixes #788 --- docs/pages/faq.md | 2 +- packages/create-react-native-library/src/index.ts | 2 +- packages/create-react-native-library/src/input.ts | 10 +++++----- .../templates/common/$package.json | 10 +++++++++- .../src/__tests__/__snapshots__/init.test.ts.snap | 3 ++- packages/react-native-builder-bob/src/init.ts | 6 +----- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/pages/faq.md b/docs/pages/faq.md index ce77bc099..b4e2410b1 100644 --- a/docs/pages/faq.md +++ b/docs/pages/faq.md @@ -150,7 +150,7 @@ If you have a reason to not ship Codegen generated scaffold code with your libra ] ``` -3. Add `package.json` to the `exports` field in your `package.json`: +3. If you have an `exports` field in your `package.json`, ensure that it contains `./package.json`: ```diff "exports": { diff --git a/packages/create-react-native-library/src/index.ts b/packages/create-react-native-library/src/index.ts index f109da151..631095e4e 100644 --- a/packages/create-react-native-library/src/index.ts +++ b/packages/create-react-native-library/src/index.ts @@ -20,7 +20,7 @@ import { import { getDependencyVersionsFromExampleApp } from './exampleApp/dependencies'; import { printErrorHelp, printNextSteps, printUsedRNVersion } from './inform'; -const FALLBACK_BOB_VERSION = '0.36.0'; +const FALLBACK_BOB_VERSION = '0.38.3'; const FALLBACK_NITRO_MODULES_VERSION = '0.22.1'; yargs diff --git a/packages/create-react-native-library/src/input.ts b/packages/create-react-native-library/src/input.ts index 3d9c8f885..23620d1a1 100644 --- a/packages/create-react-native-library/src/input.ts +++ b/packages/create-react-native-library/src/input.ts @@ -90,17 +90,17 @@ const TYPE_CHOICES: { value: 'turbo-module', description: 'integration for native APIs to JS', }, + { + title: 'Fabric view', + value: 'fabric-view', + description: 'integration for native views to JS', + }, { title: 'Nitro module', value: 'nitro-module', description: 'type-safe, fast integration for native APIs to JS (experimental)', }, - { - title: 'Fabric view', - value: 'fabric-view', - description: 'integration for native views to JS', - }, { title: 'Legacy Native module', value: 'legacy-module', diff --git a/packages/create-react-native-library/templates/common/$package.json b/packages/create-react-native-library/templates/common/$package.json index cd773f352..6d4828be9 100644 --- a/packages/create-react-native-library/templates/common/$package.json +++ b/packages/create-react-native-library/templates/common/$package.json @@ -15,7 +15,8 @@ "types": "./lib/typescript/commonjs/src/index.d.ts", "default": "./lib/commonjs/index.js" } - } + }, + "./package.json": "./package.json" }, "files": [ "src", @@ -234,6 +235,13 @@ "android": { "javaPackageName": "com.<%- project.package %>" <% if (example === 'vanilla') { -%> + <% if (project.viewConfig === 'fabric-view') { -%> + }, + "ios": { + "componentProvider": { + "<%- project.name -%>View": "<%- project.name -%>View" + } + <% } -%> }, "includesGeneratedCode": true <% } else { -%> diff --git a/packages/react-native-builder-bob/src/__tests__/__snapshots__/init.test.ts.snap b/packages/react-native-builder-bob/src/__tests__/__snapshots__/init.test.ts.snap index e6fa0fad3..0128456a7 100644 --- a/packages/react-native-builder-bob/src/__tests__/__snapshots__/init.test.ts.snap +++ b/packages/react-native-builder-bob/src/__tests__/__snapshots__/init.test.ts.snap @@ -17,7 +17,8 @@ exports[`initializes the configuration 1`] = ` "types": "./lib/typescript/commonjs/src/index.d.ts", "default": "./lib/commonjs/index.js" } - } + }, + "./package.json": "./package.json" }, "source": "./src/index.ts", "main": "./lib/commonjs/index.js", diff --git a/packages/react-native-builder-bob/src/init.ts b/packages/react-native-builder-bob/src/init.ts index f7bab44ed..facc3c00b 100644 --- a/packages/react-native-builder-bob/src/init.ts +++ b/packages/react-native-builder-bob/src/init.ts @@ -242,6 +242,7 @@ export async function init() { const exportsField = { '.': {}, + './package.json': './package.json', }; const importField = { @@ -265,11 +266,6 @@ export async function init() { exportsField['.'] = importField; } - if (pkg.codegenConfig && !pkg.codegenConfig.includesGeneratedCode) { - // @ts-expect-error The exports is not strictly types therefore it doesn't know about the package.json property - exportsField['./package.json'] = './package.json'; - } - if ( pkg.exports && JSON.stringify(pkg.exports) !== JSON.stringify(exportsField)