From 157ffed3d09c827f86dcf1381c9d2ea8fcb41982 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Wed, 4 Jan 2023 12:08:43 -0500 Subject: [PATCH] fix(expo): fix the buildable library --- e2e/expo/src/expo.test.ts | 18 ++++++++++++++++++ .../library/files/lib/babel.config.json | 16 +++++++++++++++- .../src/generators/library/library.spec.ts | 2 +- .../expo/src/generators/library/library.ts | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/e2e/expo/src/expo.test.ts b/e2e/expo/src/expo.test.ts index d48c40c35f2f8..6dd76a49067fc 100644 --- a/e2e/expo/src/expo.test.ts +++ b/e2e/expo/src/expo.test.ts @@ -1,4 +1,5 @@ import { + checkFilesExist, cleanupProject, expectTestsPass, newProject, @@ -47,4 +48,21 @@ describe('expo', () => { 'Export was successful. Your exported files can be found' ); }, 1000000); + + it('should build publishable library', async () => { + const libName = uniq('lib'); + const componentName = uniq('component'); + + runCLI( + `generate @nrwl/expo:library ${libName} --buildable --publishable --importPath=${proj}/${libName}` + ); + runCLI( + `generate @nrwl/expo:component ${componentName} --project=${libName} --export` + ); + expect(() => { + runCLI(`build ${libName}`); + checkFilesExist(`dist/libs/${libName}/index.js`); + checkFilesExist(`dist/libs/${libName}/src/index.d.ts`); + }).not.toThrow(); + }); }); diff --git a/packages/expo/src/generators/library/files/lib/babel.config.json b/packages/expo/src/generators/library/files/lib/babel.config.json index 7d30f8bf0669a..d0bad96b07ad1 100644 --- a/packages/expo/src/generators/library/files/lib/babel.config.json +++ b/packages/expo/src/generators/library/files/lib/babel.config.json @@ -1,3 +1,17 @@ { - "presets": ["babel-preset-expo"] + "presets": [ + [ + "@nrwl/react/babel", + { + "runtime": "automatic", + "useBuiltIns": "usage" + } + ] + ], + "plugins": [], + "env": { + "test": { + "presets": ["babel-preset-expo"] + } + } } diff --git a/packages/expo/src/generators/library/library.spec.ts b/packages/expo/src/generators/library/library.spec.ts index 8b531be3280d7..858207e4ec166 100644 --- a/packages/expo/src/generators/library/library.spec.ts +++ b/packages/expo/src/generators/library/library.spec.ts @@ -235,7 +235,7 @@ describe('lib', () => { executor: '@nrwl/web:rollup', outputs: ['{options.outputPath}'], options: { - external: ['react/jsx-runtime'], + external: ['react/jsx-runtime', 'react-native'], entryFile: 'libs/my-lib/src/index.ts', outputPath: 'dist/libs/my-lib', project: 'libs/my-lib/package.json', diff --git a/packages/expo/src/generators/library/library.ts b/packages/expo/src/generators/library/library.ts index bdd3ea5b4d2b5..27f7ab54783bd 100644 --- a/packages/expo/src/generators/library/library.ts +++ b/packages/expo/src/generators/library/library.ts @@ -79,7 +79,7 @@ function addProject(host: Tree, options: NormalizedSchema) { if (options.publishable || options.buildable) { const { libsDir } = getWorkspaceLayout(host); - const external = ['react/jsx-runtime']; + const external = ['react/jsx-runtime', 'react-native']; targets.build = { executor: '@nrwl/web:rollup',