Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(expo): add to project package.json for install command #26500

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion e2e/expo/src/expo-legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,26 @@ describe('@nx/expo (legacy)', () => {

it('should install', async () => {
// run install command
const installResults = await runCLIAsync(
let installResults = await runCLIAsync(
`install ${appName} --no-interactive`
);
expect(installResults.combinedOutput).toContain(
'Successfully ran target install'
);

installResults = await runCLIAsync(
`install ${appName} --packages=@react-native-async-storage/async-storage,react-native-image-picker --no-interactive`
);
expect(installResults.combinedOutput).toContain(
'Successfully ran target install'
);
const packageJson = readJson(join('apps', appName, 'package.json'));
expect(packageJson).toMatchObject({
dependencies: {
'@react-native-async-storage/async-storage': '*',
'react-native-image-picker': '*',
},
});
});

it('should start', async () => {
Expand Down
24 changes: 24 additions & 0 deletions e2e/expo/src/expo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ describe('@nx/expo', () => {
);
});

it('should install', async () => {
// run install command
let installResults = await runCLIAsync(
`install ${appName} --no-interactive`
);
expect(installResults.combinedOutput).toContain(
'Successfully ran target install'
);

installResults = await runCLIAsync(
`install ${appName} --packages=@react-native-async-storage/async-storage,react-native-image-picker --no-interactive`
);
expect(installResults.combinedOutput).toContain(
'Successfully ran target install'
);
const packageJson = readJson(join(appName, 'package.json'));
expect(packageJson).toMatchObject({
dependencies: {
'@react-native-async-storage/async-storage': '*',
'react-native-image-picker': '*',
},
});
});

it('should run e2e for cypress', async () => {
if (runE2ETests()) {
const results = runCLI(`e2e ${appName}-e2e`);
Expand Down
3 changes: 1 addition & 2 deletions packages/expo/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ function buildExpoTargets(
outputs: [getOutputs(projectRoot, 'dist')],
},
[options.installTargetName]: {
command: `expo install`,
options: { cwd: workspaceRoot }, // install at workspace root
executor: '@nx/expo:install',
},
[options.prebuildTargetName]: {
executor: `@nx/expo:prebuild`,
Expand Down
46 changes: 41 additions & 5 deletions packages/expo/src/executors/install/install.impl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { ExecutorContext, names } from '@nx/devkit';
import { readJsonFile } from 'nx/src/utils/fileutils';
import { ChildProcess, fork } from 'child_process';

import { ExpoInstallOptions } from './schema';
import { join } from 'path';
import {
displayNewlyAddedDepsMessage,
syncDeps,
} from '../sync-deps/sync-deps.impl';

export interface ExpoInstallOutput {
success: boolean;
Expand All @@ -13,12 +19,8 @@ export default async function* installExecutor(
options: ExpoInstallOptions,
context: ExecutorContext
): AsyncGenerator<ExpoInstallOutput> {
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;

try {
await installAsync(context.root, options);

await installAndUpdatePackageJson(context, options);
yield {
success: true,
};
Expand All @@ -29,6 +31,40 @@ export default async function* installExecutor(
}
}

export async function installAndUpdatePackageJson(
context: ExecutorContext,
options: ExpoInstallOptions
) {
await installAsync(context.root, options);

const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
const workspacePackageJsonPath = join(context.root, 'package.json');
const projectPackageJsonPath = join(
context.root,
projectRoot,
'package.json'
);

const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
const projectPackageJson = readJsonFile(projectPackageJsonPath);
const packages =
typeof options.packages === 'string'
? options.packages.split(',')
: options.packages;
displayNewlyAddedDepsMessage(
context.projectName,
await syncDeps(
context.projectName,
projectPackageJson,
projectPackageJsonPath,
workspacePackageJson,
context.projectGraph,
packages
)
);
}

export function installAsync(
workspaceRoot: string,
options: ExpoInstallOptions
Expand Down
35 changes: 6 additions & 29 deletions packages/expo/src/executors/update/update.impl.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { ExecutorContext, names, readJsonFile } from '@nx/devkit';
import { join, resolve as pathResolve } from 'path';
import { ExecutorContext, names } from '@nx/devkit';
import { resolve as pathResolve } from 'path';
import { ChildProcess, fork } from 'child_process';

import { resolveEas } from '../../utils/resolve-eas';
import {
displayNewlyAddedDepsMessage,
syncDeps,
} from '../sync-deps/sync-deps.impl';
import { installAsync } from '../install/install.impl';
import { installAndUpdatePackageJson } from '../install/install.impl';

import { ExpoEasUpdateOptions } from './schema';

Expand All @@ -23,30 +19,11 @@ export default async function* buildExecutor(
): AsyncGenerator<ReactNativeUpdateOutput> {
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
const workspacePackageJsonPath = join(context.root, 'package.json');
const projectPackageJsonPath = join(
context.root,
projectRoot,
'package.json'
);

const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
const projectPackageJson = readJsonFile(projectPackageJsonPath);

await installAsync(context.root, { packages: ['expo-updates'] });
displayNewlyAddedDepsMessage(
context.projectName,
await syncDeps(
context.projectName,
projectPackageJson,
projectPackageJsonPath,
workspacePackageJson,
context.projectGraph,
['expo-updates']
)
);

try {
await installAndUpdatePackageJson(context, {
packages: ['expo-updates'],
});
await runCliUpdate(context.root, projectRoot, options);
yield { success: true };
} finally {
Expand Down