Skip to content

Commit

Permalink
refactor: reduce dependencies on @angular-devkit/core
Browse files Browse the repository at this point in the history
By converting schemas from TypeScript `interfaces` to `types`, we can minimize the reliance on `json.JsonObject`. This approach avoids the error "Type 'Schema' does not satisfy the constraint 'JsonObject'" caused by the missing index signature for type 'string' in 'Schema'.

(cherry picked from commit e7413d3)
  • Loading branch information
alan-agius4 committed Jan 21, 2025
1 parent bce32c1 commit 5165265
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 62 deletions.
16 changes: 8 additions & 8 deletions goldens/public-api/angular/build/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ApplicationBuilderExtensions {
}

// @public
export interface ApplicationBuilderOptions {
export type ApplicationBuilderOptions = {
allowedCommonJsDependencies?: string[];
aot?: boolean;
appShell?: boolean;
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface ApplicationBuilderOptions {
verbose?: boolean;
watch?: boolean;
webWorkerTsConfig?: string;
}
};

// @public
export function buildApplication(options: ApplicationBuilderOptions, context: BuilderContext, extensions?: ApplicationBuilderExtensions): AsyncIterable<BuilderOutput>;
Expand Down Expand Up @@ -107,7 +107,7 @@ export enum BuildOutputFileType {
}

// @public
export interface DevServerBuilderOptions {
export type DevServerBuilderOptions = {
buildTarget: string;
headers?: {
[key: string]: string;
Expand All @@ -127,7 +127,7 @@ export interface DevServerBuilderOptions {
sslKey?: string;
verbose?: boolean;
watch?: boolean;
}
};

// @public
export interface DevServerBuilderOutput extends BuilderOutput {
Expand All @@ -153,21 +153,21 @@ export function executeExtractI18nBuilder(options: ExtractI18nBuilderOptions, co
export function executeNgPackagrBuilder(options: NgPackagrBuilderOptions, context: BuilderContext): AsyncIterableIterator<BuilderOutput>;

// @public
export interface ExtractI18nBuilderOptions {
export type ExtractI18nBuilderOptions = {
buildTarget?: string;
format?: Format;
outFile?: string;
outputPath?: string;
progress?: boolean;
}
};

// @public
export interface NgPackagrBuilderOptions {
export type NgPackagrBuilderOptions = {
poll?: number;
project: string;
tsConfig?: string;
watch?: boolean;
}
};

// (No @packageDocumentation comment for this package)

Expand Down
59 changes: 27 additions & 32 deletions goldens/public-api/angular_devkit/build_angular/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Configuration } from 'webpack';
import { DevServerBuilderOutput } from '@angular/build';
import type http from 'node:http';
import { IndexHtmlTransform } from '@angular/build/private';
import { json } from '@angular-devkit/core';
import { Observable } from 'rxjs';
import type { Plugin as Plugin_2 } from 'esbuild';
import webpack from 'webpack';
Expand All @@ -25,16 +24,16 @@ export { ApplicationBuilderOptions }
export type AssetPattern = AssetPatternObject | string;

// @public (undocumented)
export interface AssetPatternObject {
export type AssetPatternObject = {
followSymlinks?: boolean;
glob: string;
ignore?: string[];
input: string;
output?: string;
}
};

// @public
export interface BrowserBuilderOptions {
export type BrowserBuilderOptions = {
allowedCommonJsDependencies?: string[];
aot?: boolean;
assets?: AssetPattern[];
Expand Down Expand Up @@ -75,7 +74,7 @@ export interface BrowserBuilderOptions {
verbose?: boolean;
watch?: boolean;
webWorkerTsConfig?: string;
}
};

// @public
export type BrowserBuilderOutput = BuilderOutput & {
Expand All @@ -89,7 +88,7 @@ export type BrowserBuilderOutput = BuilderOutput & {
};

// @public (undocumented)
export interface Budget {
export type Budget = {
baseline?: string;
error?: string;
maximumError?: string;
Expand All @@ -99,7 +98,7 @@ export interface Budget {
name?: string;
type: Type;
warning?: string;
}
};

export { buildApplication }

Expand All @@ -114,7 +113,7 @@ export enum CrossOrigin {
}

// @public
export interface DevServerBuilderOptions {
export type DevServerBuilderOptions = {
allowedHosts?: string[];
buildTarget: string;
disableHostCheck?: boolean;
Expand All @@ -138,7 +137,7 @@ export interface DevServerBuilderOptions {
sslKey?: string;
verbose?: boolean;
watch?: boolean;
}
};

export { DevServerBuilderOutput }

Expand Down Expand Up @@ -189,28 +188,24 @@ export function executeSSRDevServerBuilder(options: SSRDevServerBuilderOptions,
export type ExecutionTransformer<T> = (input: T) => T | Promise<T>;

// @public
export interface ExtractI18nBuilderOptions {
export type ExtractI18nBuilderOptions = {
buildTarget?: string;
format?: Format;
outFile?: string;
outputPath?: string;
progress?: boolean;
}
};

// @public (undocumented)
export interface FileReplacement {
// (undocumented)
export type FileReplacement = {
replace?: string;
// (undocumented)
replaceWith?: string;
// (undocumented)
src?: string;
// (undocumented)
with?: string;
}
};

// @public
export interface KarmaBuilderOptions {
export type KarmaBuilderOptions = {
assets?: AssetPattern_2[];
browsers?: Browsers;
builderMode?: BuilderMode;
Expand All @@ -234,7 +229,7 @@ export interface KarmaBuilderOptions {
tsConfig: string;
watch?: boolean;
webWorkerTsConfig?: string;
}
};

// @public (undocumented)
export type KarmaConfigOptions = ConfigOptions & {
Expand All @@ -243,19 +238,19 @@ export type KarmaConfigOptions = ConfigOptions & {
};

// @public
export interface NgPackagrBuilderOptions {
export type NgPackagrBuilderOptions = {
poll?: number;
project: string;
tsConfig?: string;
watch?: boolean;
}
};

// @public (undocumented)
export interface OptimizationObject {
export type OptimizationObject = {
fonts?: FontsUnion;
scripts?: boolean;
styles?: StylesUnion;
}
};

// @public
export type OptimizationUnion = boolean | OptimizationObject;
Expand All @@ -273,7 +268,7 @@ export enum OutputHashing {
}

// @public
export interface ProtractorBuilderOptions {
export type ProtractorBuilderOptions = {
baseUrl?: string;
devServerTarget?: string;
grep?: string;
Expand All @@ -284,10 +279,10 @@ export interface ProtractorBuilderOptions {
specs?: string[];
suite?: string;
webdriverUpdate?: boolean;
}
};

// @public (undocumented)
export interface ServerBuilderOptions {
export type ServerBuilderOptions = {
assets?: AssetPattern_3[];
buildOptimizer?: boolean;
deleteOutputPath?: boolean;
Expand Down Expand Up @@ -315,7 +310,7 @@ export interface ServerBuilderOptions {
vendorChunk?: boolean;
verbose?: boolean;
watch?: boolean;
}
};

// @public
export type ServerBuilderOutput = BuilderOutput & {
Expand All @@ -328,18 +323,18 @@ export type ServerBuilderOutput = BuilderOutput & {
};

// @public (undocumented)
export interface SourceMapObject {
export type SourceMapObject = {
hidden?: boolean;
scripts?: boolean;
styles?: boolean;
vendor?: boolean;
}
};

// @public
export type SourceMapUnion = boolean | SourceMapObject;

// @public (undocumented)
export type SSRDevServerBuilderOptions = Schema & json.JsonObject;
export type SSRDevServerBuilderOptions = Schema;

// @public (undocumented)
export type SSRDevServerBuilderOutput = BuilderOutput & {
Expand All @@ -348,9 +343,9 @@ export type SSRDevServerBuilderOutput = BuilderOutput & {
};

// @public
export interface StylePreprocessorOptions {
export type StylePreprocessorOptions = {
includePaths?: string[];
}
};

// @public
export enum Type {
Expand Down
4 changes: 1 addition & 3 deletions packages/angular/build/src/builders/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { Builder, BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect';
import { json } from '@angular-devkit/core';
import assert from 'node:assert';
import fs from 'node:fs/promises';
import path from 'node:path';
Expand Down Expand Up @@ -260,7 +259,6 @@ function generateFullPath(
return fullFilePath;
}

const builder: Builder<ApplicationBuilderOptions & json.JsonObject> =
createBuilder(buildApplication);
const builder: Builder<ApplicationBuilderOptions> = createBuilder(buildApplication);

export default builder;
3 changes: 1 addition & 2 deletions packages/angular/build/src/builders/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { Builder, createBuilder } from '@angular-devkit/architect';
import { json } from '@angular-devkit/core';
import { execute } from './builder';
import type { DevServerBuilderOutput } from './output';
import type { Schema as DevServerBuilderOptions } from './schema';
Expand All @@ -17,7 +16,7 @@ export {
type DevServerBuilderOutput,
execute as executeDevServerBuilder,
};
const builder: Builder<DevServerBuilderOptions & json.JsonObject> = createBuilder<
const builder: Builder<DevServerBuilderOptions> = createBuilder<
DevServerBuilderOptions,
DevServerBuilderOutput
>(execute);
Expand Down
3 changes: 1 addition & 2 deletions packages/angular/build/src/builders/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
*/

import { Builder, createBuilder } from '@angular-devkit/architect';
import { json } from '@angular-devkit/core';
import { execute } from './builder';
import type { Schema as ExtractI18nBuilderOptions } from './schema';

export { ExtractI18nBuilderOptions, execute };

const builder: Builder<ExtractI18nBuilderOptions & json.JsonObject> =
const builder: Builder<ExtractI18nBuilderOptions> =
createBuilder<ExtractI18nBuilderOptions>(execute);

export default builder;
4 changes: 1 addition & 3 deletions packages/angular/build/src/builders/ng-packagr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
*/

import { Builder, createBuilder } from '@angular-devkit/architect';
import { json } from '@angular-devkit/core';
import { execute } from './builder';
import type { Schema as NgPackagrBuilderOptions } from './schema';

export { type NgPackagrBuilderOptions, execute };

const builder: Builder<NgPackagrBuilderOptions & json.JsonObject> =
createBuilder<NgPackagrBuilderOptions>(execute);
const builder: Builder<NgPackagrBuilderOptions> = createBuilder<NgPackagrBuilderOptions>(execute);

export default builder;
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { setupApplicationTarget, setupBrowserTarget } from './setup';

const optionSchemaCache = new Map<string, json.schema.JsonSchema>();

export function describeServeBuilder<T>(
builderHandler: BuilderHandlerFn<T & json.JsonObject>,
export function describeServeBuilder<T extends json.JsonObject>(
builderHandler: BuilderHandlerFn<T>,
options: { name?: string; schemaPath: string },
specDefinitions: ((
harness: JasmineBuilderHarness<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
createBuilder,
targetFromTargetString,
} from '@angular-devkit/architect';
import { json, tags } from '@angular-devkit/core';
import { tags } from '@angular-devkit/core';
import { resolve } from 'path';
import * as url from 'url';
import { runModuleAsObservableFork } from '../../utils';
Expand Down Expand Up @@ -118,7 +118,7 @@ export async function execute(
const overrides = {
watch: false,
liveReload: false,
} as DevServerBuilderOptions & json.JsonObject;
} as DevServerBuilderOptions;

if (options.host !== undefined) {
overrides.host = options.host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const IGNORED_STDOUT_MESSAGES = [
'Angular is running in development mode. Call enableProdMode() to enable production mode.',
];

export type SSRDevServerBuilderOptions = Schema & json.JsonObject;
export type SSRDevServerBuilderOptions = Schema;
export type SSRDevServerBuilderOutput = BuilderOutput & {
baseUrl?: string;
port?: string;
Expand Down
1 change: 0 additions & 1 deletion packages/angular_devkit/build_webpack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ ts_project(
module_name = "@angular-devkit/build-webpack",
deps = [
":node_modules/@angular-devkit/architect",
":node_modules/@angular-devkit/core",
"//:node_modules/@types/node",
"//:node_modules/rxjs",
"//:node_modules/webpack",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { Builder, BuilderContext, createBuilder } from '@angular-devkit/architect';
import { json } from '@angular-devkit/core';
import { resolve as pathResolve } from 'path';
import { Observable, from, isObservable, of, switchMap } from 'rxjs';
import webpack from 'webpack';
Expand Down Expand Up @@ -125,7 +124,7 @@ export function runWebpackDevServer(
);
}

const builder: Builder<WebpackDevServerBuilderSchema & json.JsonObject> = createBuilder<
const builder: Builder<WebpackDevServerBuilderSchema> = createBuilder<
WebpackDevServerBuilderSchema,
DevServerBuildOutput
>((options, context) => {
Expand Down
Loading

0 comments on commit 5165265

Please sign in to comment.