Skip to content

Commit

Permalink
fix(expo): fix the prebuild command in expo (#14922)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Feb 13, 2023
1 parent b90ac66 commit b1b36e9
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion e2e/expo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceRoot": "e2e/expo",
"projectType": "application",
"targets": {
"e2e": {},
"e2e-macos": {},
"run-e2e-tests": {}
},
"implicitDependencies": ["expo"]
Expand Down
37 changes: 31 additions & 6 deletions e2e/expo/src/expo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import {
cleanupProject,
expectTestsPass,
newProject,
readJson,
readResolvedConfiguration,
runCLI,
runCLIAsync,
uniq,
updateFile,
} from '@nrwl/e2e/utils';
import { join } from 'path';

describe('expo', () => {
let proj: string;
Expand All @@ -17,15 +20,15 @@ describe('expo', () => {
);
afterEach(() => cleanupProject());

it('should test, lint and export', async () => {
it('should test, lint, export and prebuild', async () => {
const appName = uniq('my-app');
const libName = uniq('lib');
const componentName = uniq('component');

runCLI(`generate @nrwl/expo:application ${appName}`);
runCLI(`generate @nrwl/expo:library ${libName}`);
runCLI(`generate @nrwl/expo:application ${appName} --no-interactive`);
runCLI(`generate @nrwl/expo:library ${libName} --no-interactive`);
runCLI(
`generate @nrwl/expo:component ${componentName} --project=${libName} --export`
`generate @nrwl/expo:component ${componentName} --project=${libName} --export --no-interactive`
);
expectTestsPass(await runCLIAsync(`test ${appName}`));
expectTestsPass(await runCLIAsync(`test ${libName}`));
Expand All @@ -43,11 +46,33 @@ describe('expo', () => {
const libLintResults = await runCLIAsync(`lint ${libName}`);
expect(libLintResults.combinedOutput).toContain('All files pass linting.');

const exportResults = await runCLIAsync(`export ${appName}`);
const exportResults = await runCLIAsync(
`export ${appName} --no-interactive`
);
expect(exportResults.combinedOutput).toContain(
'Export was successful. Your exported files can be found'
);
}, 1000000);

// set a mock package name for ios and android in expo's app.json
const workspace = readResolvedConfiguration();
const root = workspace.projects[appName].root;
const appJsonPath = join(root, `app.json`);
const appJson = await readJson(appJsonPath);
if (appJson.expo.ios) {
appJson.expo.ios.bundleIdentifier = 'nx.test';
}
if (appJson.expo.android) {
appJson.expo.android.package = 'nx.test';
}
updateFile(appJsonPath, JSON.stringify(appJson));

// run prebuild command with git check disable
process.env['EXPO_NO_GIT_STATUS'] = 'true';
const prebuildResult = await runCLIAsync(
`prebuild ${appName} --no-interactive`
);
expect(prebuildResult.combinedOutput).toContain('Config synced');
}, 1_000_000);

it('should build publishable library', async () => {
const libName = uniq('lib');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function runCliBuild(
childProcess = fork(
join(workspaceRoot, './node_modules/expo-cli/bin/expo.js'),
['build:android', ...createRunOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/build-ios/build-ios.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function runCliBuildIOS(
childProcess = fork(
join(workspaceRoot, './node_modules/expo-cli/bin/expo.js'),
['build:ios', ...createRunOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/build-list/build-list.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function runCliBuildList(
`./node_modules/eas-cli/bin/run build:list ${createBuildListOptions(
options
).join(' ')}`,
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
).toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function runCliBuild(
childProcess = fork(
join(workspaceRoot, './node_modules/expo-cli/bin/expo.js'),
['build:status', ...createRunOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/build-web/build-web.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function runCliBuild(
childProcess = fork(
join(workspaceRoot, './node_modules/expo-cli/bin/expo.js'),
['build:web', ...createRunOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function runCliBuild(
childProcess = fork(
join(workspaceRoot, './node_modules/eas-cli/bin/run'),
['build', ...createBuildOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/export/export.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function exportAsync(
'.',
...createExportOptions(options),
],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/install/install.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function installAsync(
childProcess = fork(
join(workspaceRoot, './node_modules/@expo/cli/build/bin/cli'),
['install', ...createInstallOptions(options)],
{ cwd: workspaceRoot }
{ cwd: workspaceRoot, env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
6 changes: 3 additions & 3 deletions packages/expo/src/executors/prebuild/prebuild.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function prebuildAsync(
childProcess = fork(
join(workspaceRoot, './node_modules/@expo/cli/build/bin/cli'),
['prebuild', ...createPrebuildOptions(options), '--no-install'],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand All @@ -71,13 +71,13 @@ function prebuildAsync(
});
}

const nxOptions = ['install'];
const nxOptions = ['install', 'interactive'];
// options from https://github.com/expo/expo/blob/main/packages/%40expo/cli/src/prebuild/index.ts
function createPrebuildOptions(options: ExpoPrebuildOptions) {
return Object.keys(options).reduce((acc, k) => {
if (!nxOptions.includes(k)) {
const v = options[k];
acc.push(`--${names(k).fileName}`, v);
acc.push(`--${names(k).fileName}=${v}`);
}
return acc;
}, []);
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/start/start.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function startAsync(
childProcess = fork(
join(workspaceRoot, './node_modules/@expo/cli/build/bin/cli'),
['start', ...createStartOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/executors/update/update.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function runCliUpdate(
childProcess = fork(
join(workspaceRoot, './node_modules/eas-cli/bin/run'),
['update', ...createUpdateOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/executors/bundle/bundle.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function runCliBuild(
childProcess = fork(
join(workspaceRoot, './node_modules/react-native/cli.js'),
['bundle', ...cliOptions],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/executors/start/start.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function startAsync(
childProcess = fork(
join(workspaceRoot, './node_modules/react-native/cli.js'),
['start', ...createStartOptions(options)],
{ cwd: join(workspaceRoot, projectRoot) }
{ cwd: join(workspaceRoot, projectRoot), env: process.env }
);

// Ensure the child process is killed when the parent exits
Expand Down

0 comments on commit b1b36e9

Please sign in to comment.