Skip to content

Commit

Permalink
chore(devkit): move all internal nx imports to requireNx (nrwl#18639)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Aug 16, 2023
1 parent 54496e8 commit 2034cdd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
7 changes: 4 additions & 3 deletions packages/devkit/src/executors/parse-target-string.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Target } from 'nx/src/command-line/run/run';
import type { ProjectGraph } from 'nx/src/config/project-graph';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { splitTarget } from 'nx/src/utils/split-target';
import { requireNx } from '../../nx';

const { readCachedProjectGraph } = requireNx();
let { readCachedProjectGraph, splitTarget } = requireNx();

// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
splitTarget = splitTarget ?? require('nx/src/utils/split-target').splitTarget;

/**
* @deprecated(v17) A project graph should be passed to parseTargetString for best accuracy.
Expand Down
15 changes: 11 additions & 4 deletions packages/devkit/src/executors/read-target-options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { Target } from 'nx/src/command-line/run/run';
import type { ExecutorContext } from 'nx/src/config/misc-interfaces';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { combineOptionsForExecutor } from 'nx/src/utils/params';
import { requireNx } from '../../nx';
import { relative } from 'path';

const { Workspaces, getExecutorInformation, calculateDefaultProjectName } =
requireNx();
let {
Workspaces,
getExecutorInformation,
calculateDefaultProjectName,
combineOptionsForExecutor,
} = requireNx();

// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
combineOptionsForExecutor =
combineOptionsForExecutor ??
require('nx/src/utils/params').combineOptionsForExecutor;

/**
* Reads and combines options for a given target.
Expand Down
8 changes: 5 additions & 3 deletions packages/devkit/src/generators/format-files.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { Tree } from 'nx/src/generators/tree';
import * as path from 'path';
import type * as Prettier from 'prettier';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { sortObjectByKeys } from 'nx/src/utils/object-sort';
import { requireNx } from '../../nx';

const { updateJson, readJson } = requireNx();
let { updateJson, readJson, sortObjectByKeys } = requireNx();

// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
sortObjectByKeys =
sortObjectByKeys ?? require('nx/src/utils/object-sort').sortObjectByKeys;

/**
* Formats all the created or updated files using Prettier
Expand Down
3 changes: 1 addition & 2 deletions packages/devkit/src/utils/get-workspace-layout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line @nx/enforce-module-boundaries
import { createTreeWithEmptyWorkspace } from 'nx/src/generators/testing-utils/create-tree-with-empty-workspace';
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports';
import { getWorkspaceLayout } from './get-workspace-layout';

describe('getWorkspaceLayout', () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/devkit/src/utils/invoke-nx-generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { stripIndent } from 'nx/src/utils/logger';
import type {
FileChange,
Tree,
Expand All @@ -13,7 +11,10 @@ import { join, relative } from 'path';
import type { Mode } from 'fs';
import { requireNx } from '../../nx';

const { logger } = requireNx();
let { logger, stripIndent } = requireNx();

// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
stripIndent = stripIndent ?? require('nx/src/utils/logger').stripIndent;

class RunCallbackTask {
constructor(private callback: GeneratorCallback) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { WorkspaceLibrarySecondaryEntryPoint } from './models';
import { dirname, join, relative } from 'path';
import { existsSync, lstatSync, readdirSync } from 'fs';

// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { PackageJson, readModulePackageJson } from 'nx/src/utils/package-json';
import type { PackageJson } from 'nx/src/utils/package-json';
import { requireNx } from '../../../nx';

const { readJsonFile, joinPathFragments, workspaceRoot } = requireNx();
let { readJsonFile, joinPathFragments, workspaceRoot, readModulePackageJson } =
requireNx();

// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
readModulePackageJson =
readModulePackageJson ??
require('nx/src/utils/package-json').readModulePackageJson;

export function collectWorkspaceLibrarySecondaryEntryPoints(
library: WorkspaceLibrary,
Expand Down
1 change: 0 additions & 1 deletion packages/nx/src/adapter/compat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { logger } from '../utils/logger';
import {
createProjectGraphAsync,
readProjectsConfigurationFromProjectGraph,
Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/devkit-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export { getExecutorInformation } from './command-line/run/executor-utils';
export { readNxJson as readNxJsonFromDisk } from './config/nx-json';
export { calculateDefaultProjectName } from './config/calculate-default-project-name';
export { retrieveProjectConfigurationsWithAngularProjects } from './project-graph/utils/retrieve-workspace-files';
export { splitTarget } from './utils/split-target';
export { combineOptionsForExecutor } from './utils/params';
export { sortObjectByKeys } from './utils/object-sort';
export { stripIndent } from './utils/logger';
export { readModulePackageJson } from './utils/package-json';

0 comments on commit 2034cdd

Please sign in to comment.