fix(core): infer codex environment and use default tasks runner (#31359)

This commit is contained in:
James Henry 2025-05-28 16:12:17 +04:00 committed by GitHub
parent c7a9c71c07
commit 9ab5d820ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { NxJsonConfiguration } from '@nx/devkit'; import { NxJsonConfiguration, readJsonFile, workspaceRoot } from '@nx/devkit';
import { import {
cleanupProject, cleanupProject,
exists, exists,
@ -459,7 +459,11 @@ Update the independent packages with a patch, preminor, and prerelease.
expect(exists(join(versionPlansDir, 'bump-fixed.md'))).toBe(true); expect(exists(join(versionPlansDir, 'bump-fixed.md'))).toBe(true);
expect(exists(join(versionPlansDir, 'bump-independent.md'))).toBe(true); expect(exists(join(versionPlansDir, 'bump-independent.md'))).toBe(true);
packageInstall('yargs', null, 'latest', 'dev'); // Reference the same version of yargs as nx uses to avoid compatibility issues
const nxPackageJson = readJsonFile(
join(workspaceRoot, 'packages/nx/package.json')
);
packageInstall('yargs', null, nxPackageJson.dependencies.yargs, 'dev');
await writeFile( await writeFile(
tmpProjPath('release.js'), tmpProjPath('release.js'),

View File

@ -1154,6 +1154,18 @@ function getTasksRunnerPath(
runner: string, runner: string,
nxJson: NxJsonConfiguration<string[] | '*'> nxJson: NxJsonConfiguration<string[] | '*'>
) { ) {
// If running inside of Codex, there will be no internet access, so we cannot use the cloud runner, regardless of other config.
// We can infer this scenario by checking for certain environment variables defined in their base image: https://github.com/openai/codex-universal
if (process.env.CODEX_ENV_NODE_VERSION) {
output.warn({
title: 'Codex environment detected, using default tasks runner',
bodyLines: [
'Codex does not have internet access when it runs tasks, so Nx will use the default tasks runner and only leverage local caching.',
],
});
return defaultTasksRunnerPath;
}
const isCloudRunner = const isCloudRunner =
// No tasksRunnerOptions for given --runner // No tasksRunnerOptions for given --runner
nxJson.nxCloudAccessToken || nxJson.nxCloudAccessToken ||