Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async prepareProjectInfo(): Promise {
// always use local json to unify behaviour between regular apps and self hosted ones
const { exp } = await readConfigJsonAsync(this.projectDir);
this.manifest = exp;
this.user = await UserManager.ensureLoggedInAsync();
await this.checkProjectConfig();
}
async function getConfigAsync(
projectRoot: string,
options: {
current?: boolean;
mode?: string;
platform?: 'android' | 'ios' | 'all';
expIds?: Array;
type?: string;
releaseChannel?: string;
bundleIdentifier?: string;
publicUrl?: string;
} = {}
) {
if (!options.publicUrl) {
// get the manifest from the project directory
const { exp, pkg } = await readConfigJsonAsync(projectRoot);
const configName = configFilename(projectRoot);
return {
exp,
pkg,
configName: configFilename(projectRoot),
configPrefix: configName === 'app.json' ? 'expo.' : '',
};
} else {
// get the externally hosted manifest
return {
exp: await ThirdParty.getManifest(options.publicUrl, options),
configName: options.publicUrl,
configPrefix: '',
pkg: {},
};
}
opts = defaultOpts;
} else {
opts = Object.assign({}, defaultOpts, opts);
}
let packagerInfo = await ProjectSettings.readPackagerInfoAsync(projectRoot);
let protocol;
if (opts.urlType === 'http') {
protocol = 'http';
} else if (opts.urlType === 'no-protocol') {
protocol = null;
} else {
protocol = 'exp';
let { exp } = await readConfigJsonAsync(projectRoot);
if (exp.detach) {
if (exp.scheme && Versions.gteSdkVersion(exp, '27.0.0')) {
protocol = exp.scheme;
} else if (exp.detach.scheme) {
// must keep this fallback in place for older projects
// and those detached with an older version of xdl
protocol = exp.detach.scheme;
}
}
}
let hostname;
let port;
const proxyURL = isPackager
? process.env.EXPO_PACKAGER_PROXY_URL
export async function startReactNativeServerAsync(
projectRoot: string,
options: StartOptions = {},
verbose: boolean = true
): Promise {
_assertValidProjectRoot(projectRoot);
await stopReactNativeServerAsync(projectRoot);
await Watchman.addToPathAsync(); // Attempt to fix watchman if it's hanging
await Watchman.unblockAndGetVersionAsync(projectRoot);
let { exp } = await readConfigJsonAsync(projectRoot);
let packagerPort = await _getFreePortAsync(19001); // Create packager options
const customLogReporterPath: string = require.resolve(path.join(__dirname, 'reporter'));
let packagerOpts: { [key: string]: any } = {
port: packagerPort,
customLogReporterPath,
// TODO: Bacon: Support .mjs (short-lived JS modules extension that some packages use)
sourceExts: getManagedExtensions([], { isTS: true, isReact: true, isModern: false }),
};
if (options.nonPersistent && Versions.lteSdkVersion(exp, '32.0.0')) {
packagerOpts.nonPersistent = true;
}
export async function validatorFromProjectRoot(projectRoot: string): Promise {
const { exp } = await ConfigUtils.readConfigJsonAsync(projectRoot);
if (!exp.sdkVersion) throw new Error(`Couldn't read local manifest`);
const schema = await getSchemaAsync(exp.sdkVersion);
const validator = new Schemer(schema);
return validator;
}
const printUsage = async (projectDir, options = {}) => {
const { dev } = await ProjectSettings.readAsync(projectDir);
const { exp } = await readConfigJsonAsync(projectDir);
const openDevToolsAtStartup = await UserSettings.getAsync('openDevToolsAtStartup', true);
const username = await UserManager.getCurrentUsernameAsync();
const devMode = dev ? 'development' : 'production';
const androidInfo = `${b`a`} to run on ${u`A`}ndroid device/emulator`;
const iosInfo = process.platform === 'darwin' ? `${b`i`} to run on ${u`i`}OS simulator` : '';
const webInfo = exp.platforms.includes('web') ? `${b`w`} to run on ${u`w`}eb` : '';
const platformInfo = [androidInfo, iosInfo, webInfo].filter(Boolean).join(', or ');
log.nested(`
\u203A Press ${platformInfo}.
\u203A Press ${b`c`} to show info on ${u`c`}onnecting new devices.
\u203A Press ${b`d`} to open DevTools in the default web browser.
\u203A Press ${b`shift-d`} to ${
openDevToolsAtStartup ? 'disable' : 'enable'
} automatically opening ${u`D`}evTools at startup.${
options.webOnly ? '' : `\n \u203A Press ${b`e`} to send an app link with ${u`e`}mail.`
}
async function installAsync(packages: string[], options: PackageManager.CreateForProjectOptions) {
const { projectRoot, workflow } = await findProjectRootAsync(process.cwd());
const packageManager = PackageManager.createForProject(projectRoot, {
npm: options.npm,
yarn: options.yarn,
log,
});
if (workflow === 'bare') {
return await packageManager.addAsync(...packages);
}
const { exp } = await ConfigUtils.readConfigJsonAsync(projectRoot);
if (!Versions.gteSdkVersion(exp, '33.0.0')) {
throw new CommandError(
'UNSUPPORTED_SDK_VERSION',
`expo install is only available for managed apps using Expo SDK version 33 or higher. Current version: ${exp.sdkVersion}.`
);
}
if (!fs.existsSync(path.join(exp.nodeModulesPath || projectRoot, 'node_modules'))) {
log.warn(`node_modules not found, running ${packageManager.name} install command.`);
await packageManager.installAsync();
}
const bundledNativeModules = await JsonFile.readAsync(
ConfigUtils.resolveModule('expo/bundledNativeModules.json', projectRoot, exp)
);
export async function getProjectNameAsync(projectRoot: string): Promise {
const { exp } = await ConfigUtils.readConfigJsonAsync(projectRoot, true);
const { webName } = ConfigUtils.getNameFromConfig(exp);
return webName;
}