Skip to content

Commit

Permalink
bugfix(react-native): add ENTRY_FILE relative to PROJECT_DIR in iOS s…
Browse files Browse the repository at this point in the history
…hell script (#9222)
  • Loading branch information
xiongemi authored and FrozenPandaz committed Mar 21, 2022
1 parent 8681d12 commit e43748c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 40 deletions.
Expand Up @@ -23,7 +23,7 @@ export async function reactNativeApplicationGenerator(
host: Tree,
schema: Schema
): Promise<GeneratorCallback> {
const options = normalizeOptions(host, schema);
const options = normalizeOptions(schema);

createApplicationFiles(host, options);
addProject(host, options);
Expand Down
Expand Up @@ -79,7 +79,7 @@ import com.android.build.OutputFile
*/

project.ext.react = [
entryFile: "<%= entryFile %>",
entryFile: "<%= entryFileRelativeToRoot %>",
enableHermes: false, // clean and rebuild if changing
]

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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`,
},
Expand All @@ -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`,
},
Expand Down
@@ -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',
Expand All @@ -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',
});
Expand All @@ -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',
Expand All @@ -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',
});
Expand All @@ -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',
Expand All @@ -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',
});
Expand All @@ -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',
Expand All @@ -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',
});
Expand All @@ -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',
Expand All @@ -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',
});
Expand Down
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -64,6 +57,6 @@ export function normalizeOptions(
androidProjectRoot,
parsedTags,
entryFile,
entryFileAbsolutePath,
entryFileRelativeToRoot,
};
}

0 comments on commit e43748c

Please sign in to comment.