Skip to content
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This is the log of notable changes to EAS CLI and related packages.
### 🛠 Breaking changes

- [build-tools] Use production mode for app config, prebuild, Expo Doctor, and Expo Updates commands. ([#4180](https://github.com/expo/eas-cli/pull/4180) by [@ramonclaudio](https://github.com/ramonclaudio))
- [eas-cli] Use production mode for runtime version resolution and Expo Updates config sync. ([#4229](https://github.com/expo/eas-cli/pull/4229) by [@ramonclaudio](https://github.com/ramonclaudio))

### 🎉 New features

Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/project/resolveRuntimeVersionAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function resolveRuntimeVersionUsingCLIAsync({
const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(
projectDir,
['runtimeversion:resolve', '--platform', platform, '--workflow', workflow, ...extraArgs],
{ env, cwd }
{ env, cwd, mode: 'production' }
);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);

Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/update/android/UpdatesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function syncUpdatesConfigurationAsync({
await expoUpdatesCommandAsync(
projectDir,
['configuration:syncnative', '--platform', 'android', '--workflow', workflow],
{ env }
{ env, mode: 'production' }
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/src/update/ios/UpdatesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function syncUpdatesConfigurationAsync({
await expoUpdatesCommandAsync(
projectDir,
['configuration:syncnative', '--platform', 'ios', '--workflow', workflow],
{ env }
{ env, mode: 'production' }
);
return;
}
Expand Down
73 changes: 73 additions & 0 deletions packages/eas-cli/src/utils/__tests__/expoUpdatesCli-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import spawnAsync from '@expo/spawn-async';
import { silent as silentResolveFrom } from 'resolve-from';

import { expoUpdatesCommandAsync } from '../expoUpdatesCli';

jest.mock('@expo/spawn-async', () => ({
__esModule: true,
default: jest.fn().mockResolvedValue({ stdout: '' }),
}));

jest.mock('resolve-from', () => ({
__esModule: true,
default: jest.fn(),
silent: jest.fn(),
}));

describe(expoUpdatesCommandAsync, () => {
it('passes production mode to the Expo Updates child process and keeps the input env unchanged', async () => {
jest.mocked(silentResolveFrom).mockReturnValue('/project/node_modules/expo-updates/bin/cli');
const originalProcessEnv = process.env;
const env = {
NODE_ENV: 'staging',
__EXPO_CONFIG_MODE: 'staging',
DOTENV_VALUE: 'from-command',
FROM_COMMAND: 'true',
__EXPO_ENV_LOADED: '["DOTENV_VALUE"]',
};
const processEnv = {
NODE_ENV: 'development',
__EXPO_CONFIG_MODE: 'development',
FROM_PROCESS: 'true',
PARENT_DOTENV_VALUE: 'from-parent',
__EXPO_ENV_LOADED: '["PARENT_DOTENV_VALUE"]',
};
process.env = processEnv;

try {
await expoUpdatesCommandAsync('/project', ['runtimeversion:resolve'], {
env,
cwd: '/working-directory',
mode: 'production',
});
expect(process.env).toBe(processEnv);
expect(process.env.PARENT_DOTENV_VALUE).toBe('from-parent');
expect(process.env.__EXPO_ENV_LOADED).toBe('["PARENT_DOTENV_VALUE"]');
} finally {
process.env = originalProcessEnv;
}

expect(spawnAsync).toHaveBeenCalledWith(
'/project/node_modules/expo-updates/bin/cli',
['runtimeversion:resolve'],
{
stdio: 'pipe',
env: {
NODE_ENV: 'production',
__EXPO_CONFIG_MODE: 'production',
FROM_PROCESS: 'true',
DOTENV_VALUE: 'from-command',
FROM_COMMAND: 'true',
},
cwd: '/working-directory',
}
);
expect(env).toEqual({
NODE_ENV: 'staging',
__EXPO_CONFIG_MODE: 'staging',
DOTENV_VALUE: 'from-command',
FROM_COMMAND: 'true',
__EXPO_ENV_LOADED: '["DOTENV_VALUE"]',
});
});
});
26 changes: 26 additions & 0 deletions packages/eas-cli/src/utils/__tests__/originalEnv-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getEnvWithoutInheritedDotenvValues } from '../originalEnv';

describe(getEnvWithoutInheritedDotenvValues, () => {
it('keeps a dotenv value allowed by the shell', () => {
const env = {
EXPO_UNSAFE_DOTENV_KEYS: 'ALLOWED_VALUE',
ALLOWED_VALUE: 'keep',
__EXPO_ENV_LOADED: '["ALLOWED_VALUE"]',
};

expect(getEnvWithoutInheritedDotenvValues(env)).toEqual({
EXPO_UNSAFE_DOTENV_KEYS: 'ALLOWED_VALUE',
ALLOWED_VALUE: 'keep',
});
});

it('removes an unsafe-key list inherited from the parent process', () => {
const env = {
EXPO_UNSAFE_DOTENV_KEYS: 'DOTENV_VALUE',
DOTENV_VALUE: 'remove',
__EXPO_ENV_LOADED: '["EXPO_UNSAFE_DOTENV_KEYS","DOTENV_VALUE"]',
};

expect(getEnvWithoutInheritedDotenvValues(env)).toEqual({});
});
});
17 changes: 15 additions & 2 deletions packages/eas-cli/src/utils/expoUpdatesCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import spawnAsync from '@expo/spawn-async';
import resolveFrom, { silent as silentResolveFrom } from 'resolve-from';

import { link } from '../log';
import { getEnvWithoutInheritedDotenvValues } from './originalEnv';

export class ExpoUpdatesCLIModuleNotFoundError extends Error {}
export class ExpoUpdatesCLIInvalidCommandError extends Error {}
export class ExpoUpdatesCLICommandFailedError extends Error {}

type EnvMode = 'development' | 'production';

export async function expoUpdatesCommandAsync(
projectDir: string,
args: string[],
options: { env: Env | undefined; cwd?: string }
options: { env: Env | undefined; cwd?: string; mode: EnvMode }
): Promise<string> {
let expoUpdatesCli;
try {
Expand All @@ -30,10 +33,20 @@ export async function expoUpdatesCommandAsync(
}

try {
const commandEnv = {
...getEnvWithoutInheritedDotenvValues(process.env),
...options.env,
};
delete commandEnv.__EXPO_ENV_LOADED;

return (
await spawnAsync(expoUpdatesCli, args, {
stdio: 'pipe',
env: { ...process.env, ...options.env },
env: {
...commandEnv,
NODE_ENV: options.mode,
__EXPO_CONFIG_MODE: options.mode,
},
cwd: options.cwd,
})
).stdout;
Expand Down
34 changes: 34 additions & 0 deletions packages/eas-cli/src/utils/originalEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { LOADED_ENV_NAME } from '@expo/env';

// TODO(@ramonclaudio): Use `getOriginalEnv()` from `@expo/env` after EAS CLI
// requires Node 20.12.0 or newer.
/** Remove dotenv values listed by an inherited `__EXPO_ENV_LOADED` marker. */
export function getEnvWithoutInheritedDotenvValues(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const result = { ...env };
const loadedKeys = getLoadedEnvKeys(result[LOADED_ENV_NAME]);
const unsafeAllowedKeys = loadedKeys.includes('EXPO_UNSAFE_DOTENV_KEYS')
? new Set<string>()
: new Set(result.EXPO_UNSAFE_DOTENV_KEYS?.split(',').filter(key => key.length > 0));

for (const key of loadedKeys) {
if (!unsafeAllowedKeys.has(key)) {
delete result[key];
}
}
delete result[LOADED_ENV_NAME];
return result;
}

function getLoadedEnvKeys(marker: string | undefined): string[] {
if (!marker) {
return [];
}
try {
const loadedKeys = JSON.parse(marker);
return Array.isArray(loadedKeys)
? loadedKeys.filter((key): key is string => typeof key === 'string')
: [];
} catch {
return [];
}
}
Loading