diff --git a/packages/react-native/src/generators/application/application.ts b/packages/react-native/src/generators/application/application.ts index 2c99ccfbd9a74..99cde0f49908d 100644 --- a/packages/react-native/src/generators/application/application.ts +++ b/packages/react-native/src/generators/application/application.ts @@ -23,7 +23,7 @@ export async function reactNativeApplicationGenerator( host: Tree, schema: Schema ): Promise { - const options = normalizeOptions(host, schema); + const options = normalizeOptions(schema); createApplicationFiles(host, options); addProject(host, options); diff --git a/packages/react-native/src/generators/application/files/app/android/app/build.gradle.template b/packages/react-native/src/generators/application/files/app/android/app/build.gradle.template index 80c48f176b73f..58a3c8e6f2dee 100644 --- a/packages/react-native/src/generators/application/files/app/android/app/build.gradle.template +++ b/packages/react-native/src/generators/application/files/app/android/app/build.gradle.template @@ -79,7 +79,7 @@ import com.android.build.OutputFile */ project.ext.react = [ - entryFile: "<%= entryFile %>", + entryFile: "<%= entryFileRelativeToRoot %>", enableHermes: false, // clean and rebuild if changing ] diff --git a/packages/react-native/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template b/packages/react-native/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template index b359fb901cc85..de79447df4a1a 100644 --- a/packages/react-native/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +++ b/packages/react-native/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template @@ -212,7 +212,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "set -e\n\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; + shellScript = "set -e\n\nexport NODE_BINARY=node\nexport ENTRY_FILE=${PROJECT_DIR}/..<%= entryFile %>\n../node_modules/react-native/scripts/react-native-xcode.sh\n"; }; 589CD817700AC23390FB1CF7 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; diff --git a/packages/react-native/src/generators/application/lib/add-project.ts b/packages/react-native/src/generators/application/lib/add-project.ts index 558001ff91800..01a83c8ea4c0d 100644 --- a/packages/react-native/src/generators/application/lib/add-project.ts +++ b/packages/react-native/src/generators/application/lib/add-project.ts @@ -56,7 +56,7 @@ function getTargets(options: NormalizedSchema) { executor: '@nrwl/react-native:bundle', outputs: [`${options.appProjectRoot}/build`], options: { - entryFile: options.entryFile, + entryFile: options.entryFileRelativeToRoot, platform: 'ios', bundleOutput: `dist/${options.appProjectRoot}/ios/main.jsbundle`, }, @@ -79,7 +79,7 @@ function getTargets(options: NormalizedSchema) { architect['bundle-android'] = { executor: '@nrwl/react-native:bundle', options: { - entryFile: options.entryFile, + entryFile: options.entryFileRelativeToRoot, platform: 'android', bundleOutput: `dist/${options.appProjectRoot}/android/main.jsbundle`, }, diff --git a/packages/react-native/src/generators/application/lib/nomalize-options.spec.ts b/packages/react-native/src/generators/application/lib/nomalize-options.spec.ts index 9e0e38f30a7af..a8803237a1525 100644 --- a/packages/react-native/src/generators/application/lib/nomalize-options.spec.ts +++ b/packages/react-native/src/generators/application/lib/nomalize-options.spec.ts @@ -1,23 +1,15 @@ -import { Tree } from '@nrwl/devkit'; -import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { Linter } from '@nrwl/linter'; import { Schema } from '../schema'; import { normalizeOptions } from './normalize-options'; describe('Normalize Options', () => { - let appTree: Tree; - - beforeEach(() => { - appTree = createTreeWithEmptyWorkspace(); - }); - it('should normalize options with name in kebab case', () => { const schema: Schema = { name: 'my-app', linter: Linter.EsLint, e2eTestRunner: 'none', }; - const options = normalizeOptions(appTree, schema); + const options = normalizeOptions(schema); expect(options).toEqual({ androidProjectRoot: 'apps/my-app/android', appProjectRoot: 'apps/my-app', @@ -29,8 +21,8 @@ describe('Normalize Options', () => { parsedTags: [], projectName: 'my-app', linter: Linter.EsLint, - entryFile: 'apps/my-app/src/main.tsx', - entryFileAbsolutePath: '/virtual/apps/my-app/src/main.tsx', + entryFile: '/src/main.tsx', + entryFileRelativeToRoot: 'apps/my-app/src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'jest', }); @@ -41,7 +33,7 @@ describe('Normalize Options', () => { name: 'myApp', e2eTestRunner: 'none', }; - const options = normalizeOptions(appTree, schema); + const options = normalizeOptions(schema); expect(options).toEqual({ androidProjectRoot: 'apps/my-app/android', appProjectRoot: 'apps/my-app', @@ -52,8 +44,8 @@ describe('Normalize Options', () => { name: 'my-app', parsedTags: [], projectName: 'my-app', - entryFile: 'apps/my-app/src/main.tsx', - entryFileAbsolutePath: '/virtual/apps/my-app/src/main.tsx', + entryFile: '/src/main.tsx', + entryFileRelativeToRoot: 'apps/my-app/src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'jest', }); @@ -65,7 +57,7 @@ describe('Normalize Options', () => { directory: 'directory', e2eTestRunner: 'none', }; - const options = normalizeOptions(appTree, schema); + const options = normalizeOptions(schema); expect(options).toEqual({ androidProjectRoot: 'apps/directory/my-app/android', appProjectRoot: 'apps/directory/my-app', @@ -77,8 +69,8 @@ describe('Normalize Options', () => { directory: 'directory', parsedTags: [], projectName: 'directory-my-app', - entryFile: 'apps/directory/my-app/src/main.tsx', - entryFileAbsolutePath: '/virtual/apps/directory/my-app/src/main.tsx', + entryFile: '/src/main.tsx', + entryFileRelativeToRoot: 'apps/directory/my-app/src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'jest', }); @@ -89,7 +81,7 @@ describe('Normalize Options', () => { name: 'directory/my-app', e2eTestRunner: 'none', }; - const options = normalizeOptions(appTree, schema); + const options = normalizeOptions(schema); expect(options).toEqual({ androidProjectRoot: 'apps/directory/my-app/android', appProjectRoot: 'apps/directory/my-app', @@ -100,8 +92,8 @@ describe('Normalize Options', () => { name: 'directory/my-app', parsedTags: [], projectName: 'directory-my-app', - entryFile: 'apps/directory/my-app/src/main.tsx', - entryFileAbsolutePath: '/virtual/apps/directory/my-app/src/main.tsx', + entryFile: '/src/main.tsx', + entryFileRelativeToRoot: 'apps/directory/my-app/src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'jest', }); @@ -113,7 +105,7 @@ describe('Normalize Options', () => { displayName: 'My App', e2eTestRunner: 'none', }; - const options = normalizeOptions(appTree, schema); + const options = normalizeOptions(schema); expect(options).toEqual({ androidProjectRoot: 'apps/my-app/android', appProjectRoot: 'apps/my-app', @@ -124,8 +116,8 @@ describe('Normalize Options', () => { name: 'my-app', parsedTags: [], projectName: 'my-app', - entryFile: 'apps/my-app/src/main.tsx', - entryFileAbsolutePath: '/virtual/apps/my-app/src/main.tsx', + entryFile: '/src/main.tsx', + entryFileRelativeToRoot: 'apps/my-app/src/main.tsx', e2eTestRunner: 'none', unitTestRunner: 'jest', }); diff --git a/packages/react-native/src/generators/application/lib/normalize-options.ts b/packages/react-native/src/generators/application/lib/normalize-options.ts index 4418c9a7a26d1..7c701a1aad799 100644 --- a/packages/react-native/src/generators/application/lib/normalize-options.ts +++ b/packages/react-native/src/generators/application/lib/normalize-options.ts @@ -11,13 +11,10 @@ export interface NormalizedSchema extends Schema { androidProjectRoot: string; parsedTags: string[]; entryFile: string; - entryFileAbsolutePath: string; + entryFileRelativeToRoot: string; } -export function normalizeOptions( - host: Tree, - options: Schema -): NormalizedSchema { +export function normalizeOptions(options: Schema): NormalizedSchema { const { fileName, className } = names(options.name); const directoryName = options.directory @@ -37,12 +34,8 @@ export function normalizeOptions( ? options.tags.split(',').map((s) => s.trim()) : []; - const entryFile = join( - appProjectRoot, - options.js ? '/src/main.js' : '/src/main.tsx' - ); - - const entryFileAbsolutePath = join(host.root, entryFile); + const entryFile = options.js ? '/src/main.js' : '/src/main.tsx'; + const entryFileRelativeToRoot = join(appProjectRoot, entryFile); /** * if options.name is "my-app" @@ -64,6 +57,6 @@ export function normalizeOptions( androidProjectRoot, parsedTags, entryFile, - entryFileAbsolutePath, + entryFileRelativeToRoot, }; }