Skip to content

Commit

Permalink
fix(core): remove axios import from main code loading (#28230)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
`axios` is loaded before tasks are run which causes a 30 ms delay.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

`axios` is not loaded before tasks are run.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit 3b278e6)
  • Loading branch information
FrozenPandaz committed Oct 2, 2024
1 parent 952629b commit b8ac136
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 18 deletions.
14 changes: 12 additions & 2 deletions packages/nx/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"no-restricted-imports": [
"error",
{
"name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead."
"paths": [
{
"name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead."
}
],
"patterns": [
{
"group": ["**/devkit-exports"],
"message": "Do not import from devkit-exports from the nx package"
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ProjectGraph } from '../../../devkit-exports';
import { IMPLICIT_DEFAULT_RELEASE_GROUP, NxReleaseConfig } from './config';
import { DEFAULT_CONVENTIONAL_COMMITS_CONFIG } from './conventional-commits';
import { filterReleaseGroups } from './filter-release-groups';
import type { ProjectGraph } from '../../../config/project-graph';

describe('filterReleaseGroups()', () => {
let projectGraph: ProjectGraph;
Expand Down
8 changes: 3 additions & 5 deletions packages/nx/src/command-line/release/utils/print-changes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as chalk from 'chalk';
import { diff } from 'jest-diff';
import { readFileSync } from 'node:fs';
import {
joinPathFragments,
logger,
workspaceRoot,
} from '../../../devkit-exports';
import { Tree, flushChanges } from '../../../generators/tree';
import { workspaceRoot } from '../../../utils/workspace-root';
import { joinPathFragments } from '../../../utils/path';
import { logger } from '../../../utils/logger';

// jest-diff does not export this constant
const NO_DIFF_MESSAGE = 'Compared values have no visual difference.';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync } from 'node:fs';
import { relative } from 'node:path';
import { joinPathFragments, workspaceRoot } from '../../../devkit-exports';
import { joinPathFragments } from '../../../utils/path';
import { workspaceRoot } from '../../../utils/workspace-root';

export async function resolveNxJsonConfigErrorMessage(
propPath: string[]
Expand Down
6 changes: 2 additions & 4 deletions packages/nx/src/nx-cloud/utilities/axios.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosRequestConfig } from 'axios';
import type { AxiosRequestConfig } from 'axios';
import { join } from 'path';
import {
ACCESS_TOKEN,
Expand All @@ -7,8 +7,6 @@ import {
} from './environment';
import { CloudTaskRunnerOptions } from '../nx-cloud-tasks-runner-shell';

const axios = require('axios');

export function createApiAxiosInstance(options: CloudTaskRunnerOptions) {
let axiosConfigBuilder = (axiosConfig: AxiosRequestConfig) => axiosConfig;
const baseUrl =
Expand All @@ -31,7 +29,7 @@ export function createApiAxiosInstance(options: CloudTaskRunnerOptions) {
axiosConfigBuilder = nxCloudProxyConfig ?? axiosConfigBuilder;
}

return axios.create(
return require('axios').create(
axiosConfigBuilder({
baseURL: baseUrl,
timeout: NX_CLOUD_NO_TIMEOUTS ? UNLIMITED_TIMEOUT : 10000,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/nx-cloud/utilities/onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readNxJson } from '../../devkit-exports';
import type { Tree } from '../../generators/tree';
import { NxCloudOnBoardingStatus } from '../models/onboarding-status';
import { isWorkspaceClaimed } from './is-workspace-claimed';
import { createNxCloudOnboardingURL } from './url-shorten';
import { getRunnerOptions } from '../../tasks-runner/run-command';
import { readNxJson } from '../../generators/utils/nx-json';

export async function createNxCloudOnboardingURLForWelcomeApp(
tree: Tree,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/nx-cloud/utilities/url-shorten.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger } from '../../devkit-exports';
import { logger } from '../../utils/logger';
import { getGithubSlugOrNull } from '../../utils/git-utils';
import { getCloudUrl } from './get-cloud-options';

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/project-graph/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { globWithWorkspaceContextSync } from '../utils/workspace-context';
import { buildProjectFromProjectJson } from '../plugins/project-json/build-nodes/project-json';
import { PackageJson } from '../utils/package-json';
import { NxJsonConfiguration } from '../devkit-exports';
import { NxJsonConfiguration } from '../config/nx-json';

export interface Change {
type: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from '../utils/project-graph-utils';
import { Task, TaskGraph } from '../config/task-graph';
import { TargetDefaults, TargetDependencies } from '../config/nx-json';
import { TargetDependencyConfig } from '../devkit-exports';
import { output } from '../utils/output';
import { TargetDependencyConfig } from '../config/workspace-json-project-json';

const DUMMY_TASK_TARGET = '__nx_dummy_task__';

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/utils/git-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { exec, ExecOptions, execSync } from 'child_process';
import { dirname, join, posix, sep } from 'path';
import { logger } from '../devkit-exports';
import { logger } from './logger';

function execAsync(command: string, execOptions: ExecOptions) {
return new Promise<string>((res, rej) => {
Expand Down

0 comments on commit b8ac136

Please sign in to comment.