From 55d21a027c2621cd01d00add488f393c94f99117 Mon Sep 17 00:00:00 2001 From: Rodrigo Moyle Date: Tue, 23 Apr 2019 16:14:44 -0300 Subject: [PATCH] Make `manifest.env` available in publish and export commands --- packages/xdl/src/Project.js | 22 ------------------- packages/xdl/src/project/ProjectUtils.js | 27 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/xdl/src/Project.js b/packages/xdl/src/Project.js index ae375bdad1..6c7a3ce836 100644 --- a/packages/xdl/src/Project.js +++ b/packages/xdl/src/Project.js @@ -1656,22 +1656,6 @@ export async function stopReactNativeServerAsync(projectRoot: string) { }); } -let blacklistedEnvironmentVariables = new Set([ - 'EXPO_APPLE_PASSWORD', - 'EXPO_ANDROID_KEY_PASSWORD', - 'EXPO_ANDROID_KEYSTORE_PASSWORD', - 'EXPO_IOS_DIST_P12_PASSWORD', - 'EXPO_IOS_PUSH_P12_PASSWORD', - 'EXPO_CLI_PASSWORD', -]); - -function shouldExposeEnvironmentVariableInManifest(key) { - if (blacklistedEnvironmentVariables.has(key.toUpperCase())) { - return false; - } - return key.startsWith('REACT_NATIVE_') || key.startsWith('EXPO_'); -} - export async function startExpoServerAsync(projectRoot: string) { _assertValidProjectRoot(projectRoot); await stopExpoServerAsync(projectRoot); @@ -1713,12 +1697,6 @@ export async function startExpoServerAsync(projectRoot: string) { projectRoot, }; manifest.packagerOpts = packagerOpts; - manifest.env = {}; - for (let key of Object.keys(process.env)) { - if (shouldExposeEnvironmentVariableInManifest(key)) { - manifest.env[key] = process.env[key]; - } - } let entryPoint = await Exp.determineEntryPointAsync(projectRoot); let platform = req.headers['exponent-platform'] || 'ios'; entryPoint = UrlUtils.getPlatformSpecificBundleUrl(entryPoint, platform); diff --git a/packages/xdl/src/project/ProjectUtils.js b/packages/xdl/src/project/ProjectUtils.js index 28a7ba7543..2085d7df78 100644 --- a/packages/xdl/src/project/ProjectUtils.js +++ b/packages/xdl/src/project/ProjectUtils.js @@ -23,6 +23,22 @@ function _getLogger(projectRoot: string) { return logger; } +let blacklistedEnvironmentVariables = new Set([ + 'EXPO_APPLE_PASSWORD', + 'EXPO_ANDROID_KEY_PASSWORD', + 'EXPO_ANDROID_KEYSTORE_PASSWORD', + 'EXPO_IOS_DIST_P12_PASSWORD', + 'EXPO_IOS_PUSH_P12_PASSWORD', + 'EXPO_CLI_PASSWORD', +]); + +function shouldExposeEnvironmentVariableInManifest(key) { + if (blacklistedEnvironmentVariables.has(key.toUpperCase())) { + return false; + } + return key.startsWith('REACT_NATIVE_') || key.startsWith('EXPO_'); +} + export function logWithLevel( projectRoot: string, level: string, @@ -133,7 +149,16 @@ export async function readConfigJsonAsync( projectRoot: string ): Promise<{ exp?: Object, pkg?: Object, rootConfig?: Object }> { try { - return await ConfigUtils.readConfigJsonAsync(projectRoot); + let { exp, pkg } = await ConfigUtils.readConfigJsonAsync(projectRoot); + + exp.env = {}; + for (let key of Object.keys(process.env)) { + if (shouldExposeEnvironmentVariableInManifest(key)) { + exp.env[key] = process.env[key]; + } + } + + return { exp, pkg }; } catch (error) { logError(projectRoot, 'expo', error.message); return { exp: null, pkg: null };