Skip to content

Commit

Permalink
chore(core): move relativeCwd out of workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jul 20, 2023
1 parent 5f17f63 commit bf3bf03
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
5 changes: 2 additions & 3 deletions packages/devkit/src/executors/read-target-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ExecutorContext } from 'nx/src/config/misc-interfaces';
import { combineOptionsForExecutor } from 'nx/src/utils/params';
import { requireNx } from '../../nx';

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

/**
Expand All @@ -21,7 +21,6 @@ export function readTargetOptions<T = any>(
).projects[project];
const targetConfiguration = projectConfiguration.targets[target];

const ws = new Workspaces(context.root);
const [nodeModule, executorName] = targetConfiguration.executor.split(':');
const { schema } = getExecutorInformation(
nodeModule,
Expand All @@ -42,6 +41,6 @@ export function readTargetOptions<T = any>(
targetConfiguration,
schema,
defaultProject,
ws.relativeCwd(context.cwd)
relativeCwd(context.cwd, context.root)
) as T;
}
3 changes: 2 additions & 1 deletion packages/nx/src/command-line/generate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getLocalWorkspacePlugins } from '../../utils/plugins/local-plugins';
import { printHelp } from '../../utils/print-help';
import { workspaceRoot } from '../../utils/workspace-root';
import { NxJsonConfiguration } from '../../config/nx-json';
import { relativeCwd } from '../../config/relative-cwd';
import { calculateDefaultProjectName } from '../../config/calculate-default-project-name';
import { findInstalledPlugins } from '../../utils/plugins/installed-plugins';
import type { Arguments } from 'yargs';
Expand Down Expand Up @@ -366,7 +367,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
projectsConfigurations,
nxJsonConfiguration
),
ws.relativeCwd(cwd),
relativeCwd(cwd, workspaceRoot),
verbose
);

Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/command-line/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '../../project-graph/project-graph';
import { ProjectGraph } from '../../config/project-graph';
import { readNxJson } from '../../config/configuration';
import { relativeCwd } from '../../config/relative-cwd';
import {
getLastValueFromAsyncIterableIterator,
isAsyncIterator,
Expand Down Expand Up @@ -193,7 +194,7 @@ async function runExecutorInternal<T extends { success: boolean }>(
targetConfig,
schema,
project,
ws.relativeCwd(cwd),
relativeCwd(cwd, root),
isVerbose
);

Expand Down
5 changes: 5 additions & 0 deletions packages/nx/src/config/relative-cwd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { relative } from 'path';

export function relativeCwd(cwd: string, root: string): string | null {
return relative(this.root, cwd).replace(/\\/g, '/') || null;
}
1 change: 1 addition & 0 deletions packages/nx/src/devkit-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export { createTempNpmDirectory } from './utils/package-manager';
export { getExecutorInformation } from './command-line/run/executor-utils';
export { calculateDefaultProjectName } from './config/calculate-default-project-name';
export { relativeCwd } from './config/relative-cwd';

0 comments on commit bf3bf03

Please sign in to comment.