Skip to content

Commit 04de1f0

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular/cli): remove circular dependency in command module
This commit extracts shared definitions to `definitions.ts` to resolve a circular dependency between `analytics.ts` and `command-module.ts`.
1 parent c236d45 commit 04de1f0

File tree

4 files changed

+52
-45
lines changed

4 files changed

+52
-45
lines changed

goldens/circular-deps/packages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,5 @@
3030
[
3131
"packages/angular/build/src/tools/esbuild/utils.ts",
3232
"packages/angular/build/src/utils/server-rendering/manifest.ts"
33-
],
34-
[
35-
"packages/angular/cli/src/analytics/analytics.ts",
36-
"packages/angular/cli/src/command-builder/command-module.ts"
3733
]
3834
]

packages/angular/cli/src/analytics/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { json, tags } from '@angular-devkit/core';
1010
import { randomUUID } from 'node:crypto';
11-
import type { CommandContext } from '../command-builder/command-module';
11+
import type { CommandContext } from '../command-builder/definitions';
1212
import { colors } from '../utilities/color';
1313
import { getWorkspace } from '../utilities/config';
1414
import { analyticsDisabled } from '../utilities/environment-options';

packages/angular/cli/src/command-builder/command-module.ts

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
import { logging, schema } from '@angular-devkit/core';
1010
import { readFileSync } from 'node:fs';
1111
import * as path from 'node:path';
12-
import type {
13-
ArgumentsCamelCase,
14-
Argv,
15-
CamelCaseKey,
16-
CommandModule as YargsCommandModule,
17-
} from 'yargs';
12+
import type { ArgumentsCamelCase, Argv, CommandModule as YargsCommandModule } from 'yargs';
1813
import { Parser as yargsParser } from 'yargs/helpers';
1914
import { getAnalyticsUserId } from '../analytics/analytics';
2015
import { AnalyticsCollector } from '../analytics/analytics-collector';
@@ -23,42 +18,11 @@ import { considerSettingUpAutocompletion } from '../utilities/completion';
2318
import { AngularWorkspace } from '../utilities/config';
2419
import { memoize } from '../utilities/memoize';
2520
import { PackageManagerUtils } from '../utilities/package-manager';
21+
import { CommandContext, CommandScope, Options, OtherOptions } from './definitions';
2622
import { Option, addSchemaOptionsToCommand } from './utilities/json-schema';
2723

28-
export type Options<T> = { [key in keyof T as CamelCaseKey<key>]: T[key] };
29-
30-
export enum CommandScope {
31-
/** Command can only run inside an Angular workspace. */
32-
In,
33-
34-
/** Command can only run outside an Angular workspace. */
35-
Out,
36-
37-
/** Command can run inside and outside an Angular workspace. */
38-
Both,
39-
}
40-
41-
export interface CommandContext {
42-
currentDirectory: string;
43-
root: string;
44-
workspace?: AngularWorkspace;
45-
globalConfiguration: AngularWorkspace;
46-
logger: logging.Logger;
47-
packageManager: PackageManagerUtils;
48-
yargsInstance: Argv<{}>;
49-
50-
/** Arguments parsed in free-from without parser configuration. */
51-
args: {
52-
positional: string[];
53-
options: {
54-
help: boolean;
55-
jsonHelp: boolean;
56-
getYargsCompletions: boolean;
57-
} & Record<string, unknown>;
58-
};
59-
}
60-
61-
export type OtherOptions = Record<string, unknown>;
24+
export { CommandScope };
25+
export type { CommandContext, Options, OtherOptions };
6226

6327
export interface CommandModuleImplementation<T extends {} = {}> extends Omit<
6428
YargsCommandModule<{}, T>,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { logging } from '@angular-devkit/core';
10+
import type { Argv, CamelCaseKey } from 'yargs';
11+
import { AngularWorkspace } from '../utilities/config';
12+
import { PackageManagerUtils } from '../utilities/package-manager';
13+
14+
export enum CommandScope {
15+
/** Command can only run inside an Angular workspace. */
16+
In,
17+
18+
/** Command can only run outside an Angular workspace. */
19+
Out,
20+
21+
/** Command can run inside and outside an Angular workspace. */
22+
Both,
23+
}
24+
25+
export interface CommandContext {
26+
currentDirectory: string;
27+
root: string;
28+
workspace?: AngularWorkspace;
29+
globalConfiguration: AngularWorkspace;
30+
logger: logging.Logger;
31+
packageManager: PackageManagerUtils;
32+
yargsInstance: Argv<{}>;
33+
34+
/** Arguments parsed in free-from without parser configuration. */
35+
args: {
36+
positional: string[];
37+
options: {
38+
help: boolean;
39+
jsonHelp: boolean;
40+
getYargsCompletions: boolean;
41+
} & Record<string, unknown>;
42+
};
43+
}
44+
45+
export type Options<T> = { [key in keyof T as CamelCaseKey<key>]: T[key] };
46+
47+
export type OtherOptions = Record<string, unknown>;

0 commit comments

Comments
 (0)