Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Remove extra config read when resolving entry point (#2836)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon authored Nov 9, 2020
1 parent b4087cb commit 023d5f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
11 changes: 7 additions & 4 deletions packages/config/src/paths/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import resolveFrom from 'resolve-from';

import { getConfig } from '../Config';
import { ProjectConfig } from '../Config.types';
import { resolveModule } from '../Modules';
import { getManagedExtensions } from './extensions';

Expand Down Expand Up @@ -37,19 +38,21 @@ export function getAbsolutePathWithProjectRoot(
export function getEntryPoint(
projectRoot: string,
entryFiles: string[],
platforms: string[]
platforms: string[],
projectConfig?: ProjectConfig
): string | null {
const extensions = getManagedExtensions(platforms);
return getEntryPointWithExtensions(projectRoot, entryFiles, extensions);
return getEntryPointWithExtensions(projectRoot, entryFiles, extensions, projectConfig);
}

// Used to resolve the main entry file for a project.
export function getEntryPointWithExtensions(
projectRoot: string,
entryFiles: string[],
extensions: string[]
extensions: string[],
projectConfig?: ProjectConfig
): string {
const { exp, pkg } = getConfig(projectRoot, { skipSDKVersionRequirement: true });
const { exp, pkg } = projectConfig ?? getConfig(projectRoot, { skipSDKVersionRequirement: true });

// This will first look in the `app.json`s `expo.entryPoint` field for a potential main file.
// We check the Expo config first in case you want your project to start differently with Expo then in a standalone environment.
Expand Down
10 changes: 7 additions & 3 deletions packages/xdl/src/Exp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BareAppConfig, ExpoConfig } from '@expo/config';
import { BareAppConfig, ExpoConfig, ProjectConfig } from '@expo/config';
import { getEntryPoint } from '@expo/config/paths';
import JsonFile from '@expo/json-file';
import fs from 'fs-extra';
Expand All @@ -21,7 +21,11 @@ type TemplateConfig = { name: string };
const supportedPlatforms = ['ios', 'android', 'web'];

/** @deprecated use getEntryPoint from @expo/config/paths */
export function determineEntryPoint(projectRoot: string, platform?: string): string {
export function determineEntryPoint(
projectRoot: string,
platform?: string,
projectConfig?: ProjectConfig
): string {
if (platform && !supportedPlatforms.includes(platform)) {
throw new Error(
`Failed to resolve the project's entry file: The platform "${platform}" is not supported.`
Expand All @@ -31,7 +35,7 @@ export function determineEntryPoint(projectRoot: string, platform?: string): str
// const platforms = [platform, 'native'].filter(Boolean) as string[];
const platforms: string[] = [];

const entry = getEntryPoint(projectRoot, ['./index'], platforms);
const entry = getEntryPoint(projectRoot, ['./index'], platforms, projectConfig);
if (!entry)
throw new Error(
`The project entry file could not be resolved. Please either define it in the \`package.json\` (main), \`app.json\` (expo.entryPoint), create an \`index.js\`, or install the \`expo\` package.`
Expand Down
12 changes: 4 additions & 8 deletions packages/xdl/src/project/ManifestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,18 @@ export async function getManifestResponseAsync({
host?: string;
acceptSignature?: string | string[];
}): Promise<{ exp: ExpoConfig; manifestString: string; hostInfo: HostInfo }> {
// Read the config
const projectConfig = getConfig(projectRoot);
const manifest = projectConfig.exp as ExpoAppManifest;
// Read from headers
const hostname = stripPort(host);

// Get project entry point and initial module
const entryPoint = Exp.determineEntryPoint(projectRoot, platform);
const entryPoint = Exp.determineEntryPoint(projectRoot, platform, projectConfig);
const mainModuleName = UrlUtils.guessMainModulePath(entryPoint);

// Gather packager and host info
const hostInfo = await createHostInfoAsync();
const [packagerOpts, bundleUrlPackagerOpts] = await getPackagerOptionsAsync(projectRoot);

// Read the config
const manifest = getConfig(projectRoot).exp as ExpoAppManifest;

// Mutate the manifest
manifest.xde = true; // deprecated
manifest.developer = {
Expand All @@ -216,7 +214,6 @@ export async function getManifestResponseAsync({
manifest.debuggerHost = await UrlUtils.constructDebuggerHostAsync(projectRoot, hostname);
manifest.logUrl = await UrlUtils.constructLogUrlAsync(projectRoot, hostname);
manifest.hostUri = await UrlUtils.constructHostUriAsync(projectRoot, hostname);

// Resolve all assets and set them on the manifest as URLs
await resolveManifestAssets({
projectRoot,
Expand All @@ -225,7 +222,6 @@ export async function getManifestResponseAsync({
return manifest.bundleUrl!.match(/^https?:\/\/.*?\//)![0] + 'assets/' + path;
},
});

// The server normally inserts this but if we're offline we'll do it here
await resolveGoogleServicesFile(projectRoot, manifest);

Expand Down

0 comments on commit 023d5f3

Please sign in to comment.