chore(core): move relativeCwd out of workspaces (#18229)
This commit is contained in:
parent
64492ece8c
commit
6b43833d2c
@ -3,6 +3,7 @@ import type { ExecutorContext } from 'nx/src/config/misc-interfaces';
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
import { combineOptionsForExecutor } from 'nx/src/utils/params';
|
import { combineOptionsForExecutor } from 'nx/src/utils/params';
|
||||||
import { requireNx } from '../../nx';
|
import { requireNx } from '../../nx';
|
||||||
|
import { relative } from 'path';
|
||||||
|
|
||||||
const { Workspaces, getExecutorInformation, calculateDefaultProjectName } =
|
const { Workspaces, getExecutorInformation, calculateDefaultProjectName } =
|
||||||
requireNx();
|
requireNx();
|
||||||
@ -21,6 +22,7 @@ export function readTargetOptions<T = any>(
|
|||||||
).projects[project];
|
).projects[project];
|
||||||
const targetConfiguration = projectConfiguration.targets[target];
|
const targetConfiguration = projectConfiguration.targets[target];
|
||||||
|
|
||||||
|
// TODO(v18): remove Workspaces.
|
||||||
const ws = new Workspaces(context.root);
|
const ws = new Workspaces(context.root);
|
||||||
const [nodeModule, executorName] = targetConfiguration.executor.split(':');
|
const [nodeModule, executorName] = targetConfiguration.executor.split(':');
|
||||||
const { schema } = getExecutorInformation
|
const { schema } = getExecutorInformation
|
||||||
@ -48,6 +50,6 @@ export function readTargetOptions<T = any>(
|
|||||||
targetConfiguration,
|
targetConfiguration,
|
||||||
schema,
|
schema,
|
||||||
defaultProject,
|
defaultProject,
|
||||||
ws.relativeCwd(context.cwd)
|
relative(context.cwd, context.root)
|
||||||
) as T;
|
) as T;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import {
|
|||||||
ProjectsConfigurations,
|
ProjectsConfigurations,
|
||||||
} from '../config/workspace-json-project-json';
|
} from '../config/workspace-json-project-json';
|
||||||
import { renamePropertyWithStableKeys } from '../config/workspaces';
|
import { renamePropertyWithStableKeys } from '../config/workspaces';
|
||||||
import { workspaceRoot } from '../utils/workspace-root';
|
|
||||||
|
|
||||||
export function shouldMergeAngularProjects(
|
export function shouldMergeAngularProjects(
|
||||||
root: string,
|
root: string,
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import * as chalk from 'chalk';
|
import * as chalk from 'chalk';
|
||||||
import { prompt } from 'enquirer';
|
import { prompt } from 'enquirer';
|
||||||
|
import { relative } from 'path';
|
||||||
|
|
||||||
import { readNxJson } from '../../config/configuration';
|
import { readNxJson } from '../../config/configuration';
|
||||||
import { ProjectsConfigurations } from '../../config/workspace-json-project-json';
|
import { ProjectsConfigurations } from '../../config/workspace-json-project-json';
|
||||||
import { Workspaces } from '../../config/workspaces';
|
|
||||||
import { FileChange, flushChanges, FsTree } from '../../generators/tree';
|
import { FileChange, flushChanges, FsTree } from '../../generators/tree';
|
||||||
import {
|
import {
|
||||||
createProjectGraphAsync,
|
createProjectGraphAsync,
|
||||||
@ -51,7 +51,6 @@ export function printChanges(fileChanges: FileChange[]) {
|
|||||||
|
|
||||||
async function promptForCollection(
|
async function promptForCollection(
|
||||||
generatorName: string,
|
generatorName: string,
|
||||||
ws: Workspaces,
|
|
||||||
interactive: boolean,
|
interactive: boolean,
|
||||||
projectsConfiguration: ProjectsConfigurations
|
projectsConfiguration: ProjectsConfigurations
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
@ -202,7 +201,6 @@ function parseGeneratorString(value: string): {
|
|||||||
|
|
||||||
async function convertToGenerateOptions(
|
async function convertToGenerateOptions(
|
||||||
generatorOptions: { [p: string]: any },
|
generatorOptions: { [p: string]: any },
|
||||||
ws: Workspaces,
|
|
||||||
defaultCollectionName: string,
|
defaultCollectionName: string,
|
||||||
mode: 'generate' | 'new',
|
mode: 'generate' | 'new',
|
||||||
projectsConfiguration?: ProjectsConfigurations
|
projectsConfiguration?: ProjectsConfigurations
|
||||||
@ -221,7 +219,6 @@ async function convertToGenerateOptions(
|
|||||||
} else if (!defaultCollectionName) {
|
} else if (!defaultCollectionName) {
|
||||||
const generatorString = await promptForCollection(
|
const generatorString = await promptForCollection(
|
||||||
generatorDescriptor,
|
generatorDescriptor,
|
||||||
ws,
|
|
||||||
interactive,
|
interactive,
|
||||||
projectsConfiguration
|
projectsConfiguration
|
||||||
);
|
);
|
||||||
@ -302,7 +299,6 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
|
|||||||
}
|
}
|
||||||
const verbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
const verbose = process.env.NX_VERBOSE_LOGGING === 'true';
|
||||||
|
|
||||||
const ws = new Workspaces(workspaceRoot);
|
|
||||||
const nxJsonConfiguration = readNxJson();
|
const nxJsonConfiguration = readNxJson();
|
||||||
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
|
const projectGraph = await createProjectGraphAsync({ exitOnError: true });
|
||||||
const projectsConfigurations =
|
const projectsConfigurations =
|
||||||
@ -311,7 +307,6 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
|
|||||||
return handleErrors(verbose, async () => {
|
return handleErrors(verbose, async () => {
|
||||||
const opts = await convertToGenerateOptions(
|
const opts = await convertToGenerateOptions(
|
||||||
args,
|
args,
|
||||||
ws,
|
|
||||||
readDefaultCollection(nxJsonConfiguration),
|
readDefaultCollection(nxJsonConfiguration),
|
||||||
'generate',
|
'generate',
|
||||||
projectsConfigurations
|
projectsConfigurations
|
||||||
@ -366,7 +361,7 @@ export async function generate(cwd: string, args: { [k: string]: any }) {
|
|||||||
projectsConfigurations,
|
projectsConfigurations,
|
||||||
nxJsonConfiguration
|
nxJsonConfiguration
|
||||||
),
|
),
|
||||||
ws.relativeCwd(cwd),
|
relative(cwd, workspaceRoot),
|
||||||
verbose
|
verbose
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,10 @@ import {
|
|||||||
Schema,
|
Schema,
|
||||||
} from '../../utils/params';
|
} from '../../utils/params';
|
||||||
import { printHelp } from '../../utils/print-help';
|
import { printHelp } from '../../utils/print-help';
|
||||||
import { Workspaces } from '../../config/workspaces';
|
|
||||||
import { NxJsonConfiguration } from '../../config/nx-json';
|
import { NxJsonConfiguration } from '../../config/nx-json';
|
||||||
import { readJsonFile } from '../../utils/fileutils';
|
import { readJsonFile } from '../../utils/fileutils';
|
||||||
import { buildTargetFromScript, PackageJson } from '../../utils/package-json';
|
import { buildTargetFromScript, PackageJson } from '../../utils/package-json';
|
||||||
import { join } from 'path';
|
import { join, relative } from 'path';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import {
|
import {
|
||||||
loadNxPlugins,
|
loadNxPlugins,
|
||||||
@ -111,7 +110,6 @@ function createImplicitTargetConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function parseExecutorAndTarget(
|
async function parseExecutorAndTarget(
|
||||||
ws: Workspaces,
|
|
||||||
{ project, target, configuration }: Target,
|
{ project, target, configuration }: Target,
|
||||||
root: string,
|
root: string,
|
||||||
projectsConfigurations: ProjectsConfigurations,
|
projectsConfigurations: ProjectsConfigurations,
|
||||||
@ -147,9 +145,7 @@ async function printTargetRunHelpInternal(
|
|||||||
projectsConfigurations: ProjectsConfigurations,
|
projectsConfigurations: ProjectsConfigurations,
|
||||||
nxJsonConfiguration: NxJsonConfiguration
|
nxJsonConfiguration: NxJsonConfiguration
|
||||||
) {
|
) {
|
||||||
const ws = new Workspaces(root);
|
|
||||||
const { executor, nodeModule, schema } = await parseExecutorAndTarget(
|
const { executor, nodeModule, schema } = await parseExecutorAndTarget(
|
||||||
ws,
|
|
||||||
{ project, target, configuration },
|
{ project, target, configuration },
|
||||||
root,
|
root,
|
||||||
projectsConfigurations,
|
projectsConfigurations,
|
||||||
@ -176,10 +172,8 @@ async function runExecutorInternal<T extends { success: boolean }>(
|
|||||||
): Promise<AsyncIterableIterator<T>> {
|
): Promise<AsyncIterableIterator<T>> {
|
||||||
validateProject(projectsConfigurations, project);
|
validateProject(projectsConfigurations, project);
|
||||||
|
|
||||||
const ws = new Workspaces(root);
|
|
||||||
const { executor, implementationFactory, nodeModule, schema, targetConfig } =
|
const { executor, implementationFactory, nodeModule, schema, targetConfig } =
|
||||||
await parseExecutorAndTarget(
|
await parseExecutorAndTarget(
|
||||||
ws,
|
|
||||||
{ project, target, configuration },
|
{ project, target, configuration },
|
||||||
root,
|
root,
|
||||||
projectsConfigurations,
|
projectsConfigurations,
|
||||||
@ -193,7 +187,7 @@ async function runExecutorInternal<T extends { success: boolean }>(
|
|||||||
targetConfig,
|
targetConfig,
|
||||||
schema,
|
schema,
|
||||||
project,
|
project,
|
||||||
ws.relativeCwd(cwd),
|
relative(cwd, root),
|
||||||
isVerbose
|
isVerbose
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -27,10 +27,6 @@ export class Workspaces {
|
|||||||
|
|
||||||
constructor(private root: string) {}
|
constructor(private root: string) {}
|
||||||
|
|
||||||
relativeCwd(cwd: string) {
|
|
||||||
return path.relative(this.root, cwd).replace(/\\/g, '/') || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user