Skip to content

Commit ccbb963

Browse files
committed
refactor(@angular-devkit/architect): update to support building with isolated declarations
The `@angular-devkit/architect` package can now be built with the TypeScript `isolatedDeclarations` option enabled. The changes were type only and mainly related to function return types and module level variable types additions.
1 parent dcf356f commit ccbb963

File tree

11 files changed

+34
-28
lines changed

11 files changed

+34
-28
lines changed

packages/angular_devkit/architect/builders/all-of.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { json } from '@angular-devkit/core';
109
import { EMPTY, from, map, mergeMap, of } from 'rxjs';
11-
import { BuilderOutput, BuilderRun, createBuilder } from '../src';
10+
import { Builder, BuilderOutput, BuilderRun, createBuilder } from '../src';
1211
import { Schema as OperatorSchema } from './operator-schema';
1312

14-
export default createBuilder<json.JsonObject & OperatorSchema>((options, context) => {
13+
const builder: Builder<OperatorSchema> = createBuilder((options, context) => {
1514
const allRuns: Promise<[number, BuilderRun]>[] = [];
1615

1716
context.reportProgress(
@@ -66,3 +65,5 @@ export default createBuilder<json.JsonObject & OperatorSchema>((options, context
6665
}),
6766
);
6867
});
68+
69+
export default builder;

packages/angular_devkit/architect/builders/concat.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { json } from '@angular-devkit/core';
109
import { concatMap, first, from, last, map, of, switchMap } from 'rxjs';
11-
import { BuilderOutput, BuilderRun, createBuilder } from '../src';
10+
import { Builder, BuilderOutput, BuilderRun, createBuilder } from '../src';
1211
import { Schema as OperatorSchema } from './operator-schema';
1312

14-
export default createBuilder<json.JsonObject & OperatorSchema>((options, context) => {
13+
const builder: Builder<OperatorSchema> = createBuilder((options, context) => {
1514
const allRuns: (() => Promise<BuilderRun>)[] = [];
1615

1716
context.reportProgress(
@@ -61,3 +60,5 @@ export default createBuilder<json.JsonObject & OperatorSchema>((options, context
6160
last(),
6261
);
6362
});
63+
64+
export default builder;

packages/angular_devkit/architect/builders/false.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { createBuilder } from '../src';
9+
import { type Builder, createBuilder } from '../src';
1010

11-
export default createBuilder(() => ({
11+
const builder: Builder<{}> = createBuilder(() => ({
1212
success: false,
1313
error: 'False builder always errors.',
1414
}));
15+
16+
export default builder;

packages/angular_devkit/architect/builders/true.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import { createBuilder } from '../src';
9+
import { type Builder, createBuilder } from '../src';
1010

11-
export default createBuilder(() => ({ success: true }));
11+
const builder: Builder<{}> = createBuilder(() => ({ success: true }));
12+
13+
export default builder;

packages/angular_devkit/architect/node/node-modules-architect-host.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
121121
}
122122
}
123123

124-
async getBuilderNameForTarget(target: Target) {
124+
async getBuilderNameForTarget(target: Target): Promise<string> {
125125
return this.workspaceHost.getBuilderName(target.project, target.target);
126126
}
127127

@@ -134,7 +134,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
134134
*/
135135
resolveBuilder(
136136
builderStr: string,
137-
basePath = this._root,
137+
basePath: string = this._root,
138138
seenBuilders?: Set<string>,
139139
): Promise<NodeModulesBuilderInfo> {
140140
if (seenBuilders?.has(builderStr)) {
@@ -228,11 +228,11 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
228228
});
229229
}
230230

231-
async getCurrentDirectory() {
231+
async getCurrentDirectory(): Promise<string> {
232232
return process.cwd();
233233
}
234234

235-
async getWorkspaceRoot() {
235+
async getWorkspaceRoot(): Promise<string> {
236236
return this._root;
237237
}
238238

packages/angular_devkit/architect/src/architect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export class Architect {
364364
this._scheduler = new SimpleScheduler(jobRegistry, registry);
365365
}
366366

367-
has(name: JobName) {
367+
has(name: JobName): Observable<boolean> {
368368
return this._scheduler.has(name);
369369
}
370370

packages/angular_devkit/architect/src/internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import { JobDescription, JobHandler } from './jobs';
1919
* Using Symbol.for() as it's a global registry that's the same for all installations of
2020
* Architect (if some libraries depends directly on architect instead of sharing the files).
2121
*/
22-
export const BuilderSymbol = Symbol.for('@angular-devkit/architect:builder');
22+
export const BuilderSymbol: unique symbol = Symbol.for('@angular-devkit/architect:builder');
2323

2424
/**
2525
* BuilderVersionSymbol used for knowing which version of the library createBuilder() came from.
2626
* This is to make sure we don't try to use an incompatible builder.
2727
* Using Symbol.for() as it's a global registry that's the same for all installations of
2828
* Architect (if some libraries depends directly on architect instead of sharing the files).
2929
*/
30-
export const BuilderVersionSymbol = Symbol.for('@angular-devkit/architect:version');
30+
export const BuilderVersionSymbol: unique symbol = Symbol.for('@angular-devkit/architect:version');
3131

3232
/**
3333
* A Specialization of the JobHandler type. This exposes BuilderDescription as the job description

packages/angular_devkit/architect/src/jobs/fallback-registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class FallbackRegistry<
2727
>[] = [],
2828
) {}
2929

30-
addFallback(registry: Registry) {
30+
addFallback(registry: Registry): void {
3131
this._fallbacks.push(registry);
3232
}
3333

packages/angular_devkit/architect/src/jobs/simple-scheduler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class SimpleScheduler<
185185
* @param name The name of the job.
186186
* @returns A description, or null if the job is not registered.
187187
*/
188-
getDescription(name: JobName) {
188+
getDescription(name: JobName): Observable<JobDescription | null> {
189189
return concat(
190190
this._getInternalDescription(name).pipe(map((x) => x && x.jobDescription)),
191191
of(null),
@@ -197,7 +197,7 @@ export class SimpleScheduler<
197197
* @param name The name of the job.
198198
* @returns True if the job exists, false otherwise.
199199
*/
200-
has(name: JobName) {
200+
has(name: JobName): Observable<boolean> {
201201
return this.getDescription(name).pipe(map((x) => x !== null));
202202
}
203203

@@ -209,7 +209,7 @@ export class SimpleScheduler<
209209
*
210210
* Jobs already running are NOT paused. This is pausing the scheduler only.
211211
*/
212-
pause() {
212+
pause(): () => void {
213213
let called = false;
214214
this._pauseCounter++;
215215

packages/angular_devkit/architect/testing/test-project-host.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ export class TestProjectHost extends NodeJsSyncHost {
126126
});
127127
}
128128

129-
replaceInFile(path: string, match: RegExp | string, replacement: string) {
129+
replaceInFile(path: string, match: RegExp | string, replacement: string): void {
130130
const content = virtualFs.fileBufferToString(this.scopedSync().read(normalize(path)));
131131
this.scopedSync().write(
132132
normalize(path),
133133
virtualFs.stringToFileBuffer(content.replace(match, replacement)),
134134
);
135135
}
136136

137-
appendToFile(path: string, str: string) {
137+
appendToFile(path: string, str: string): void {
138138
const content = virtualFs.fileBufferToString(this.scopedSync().read(normalize(path)));
139139
this.scopedSync().write(normalize(path), virtualFs.stringToFileBuffer(content.concat(str)));
140140
}
@@ -147,7 +147,7 @@ export class TestProjectHost extends NodeJsSyncHost {
147147
return fileName || undefined;
148148
}
149149

150-
copyFile(from: string, to: string) {
150+
copyFile(from: string, to: string): void {
151151
const content = this.scopedSync().read(normalize(from));
152152
this.scopedSync().write(normalize(to), content);
153153
}

packages/angular_devkit/architect/testing/testing-architect-host.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class TestingArchitectHost implements ArchitectHost {
2323
*/
2424
constructor(
2525
public workspaceRoot = '',
26-
public currentDirectory = workspaceRoot,
26+
public currentDirectory: string = workspaceRoot,
2727
private _backendHost: ArchitectHost | null = null,
2828
) {}
2929

@@ -32,11 +32,11 @@ export class TestingArchitectHost implements ArchitectHost {
3232
builder: Builder,
3333
description = 'Testing only builder.',
3434
optionSchema: json.schema.JsonSchema = { type: 'object' },
35-
) {
35+
): void {
3636
this._builderImportMap.set(builderName, builder);
3737
this._builderMap.set(builderName, { builderName, description, optionSchema });
3838
}
39-
async addBuilderFromPackage(packageName: string) {
39+
async addBuilderFromPackage(packageName: string): Promise<void> {
4040
const packageJson = await import(packageName + '/package.json');
4141
if (!('builders' in packageJson)) {
4242
throw new Error('Invalid package.json, builders key not found.');
@@ -64,7 +64,7 @@ export class TestingArchitectHost implements ArchitectHost {
6464
this.addBuilder(`${packageJson.name}:${builderName}`, handler, b.description, optionsSchema);
6565
}
6666
}
67-
addTarget(target: Target, builderName: string, options: json.JsonObject = {}) {
67+
addTarget(target: Target, builderName: string, options: json.JsonObject = {}): void {
6868
this._targetMap.set(targetStringFromTarget(target), { builderName, options });
6969
}
7070

0 commit comments

Comments
 (0)