Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): remove axios import from main code loading #28230

Merged
merged 1 commit into from
Oct 2, 2024
Merged
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
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';

export class ProcessTasks {
private readonly seen = new Set<string>();
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