Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import js from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import header from 'eslint-plugin-header';
import header from '@tony.ganchev/eslint-plugin-header';
import _import from 'eslint-plugin-import';
import globals from 'globals';

Expand All @@ -22,9 +22,6 @@ const compat = new FlatCompat({
allConfig: js.configs.all,
});

// See: https://github.com/Stuk/eslint-plugin-header/issues/57
header.rules.header.meta.schema = false;

export default [
{
ignores: [
Expand Down Expand Up @@ -59,7 +56,7 @@ export default [
'@stylistic': stylistic,
'@typescript-eslint': fixupPluginRules(typescriptEslint),
import: fixupPluginRules(_import),
header,
'@tony.ganchev': header,
},

languageOptions: {
Expand Down Expand Up @@ -106,7 +103,7 @@ export default [
'@typescript-eslint/no-unused-expressions': 'error',
curly: 'error',

'header/header': [
'@tony.ganchev/header': [
'error',
'block',
[
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@
"@bazel/buildifier": "8.2.1",
"@eslint/compat": "2.0.2",
"@eslint/eslintrc": "3.3.3",
"@eslint/js": "9.39.2",
"@eslint/js": "10.0.1",
"@rollup/plugin-alias": "^6.0.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "16.0.3",
"@stylistic/eslint-plugin": "^5.0.0",
"@tony.ganchev/eslint-plugin-header": "~3.2.4",
"@types/babel__core": "7.20.5",
"@types/babel__generator": "^7.6.8",
"@types/browser-sync": "^2.27.0",
Expand Down Expand Up @@ -95,9 +96,8 @@
"buffer": "6.0.3",
"esbuild": "0.27.3",
"esbuild-wasm": "0.27.3",
"eslint": "9.39.2",
"eslint": "10.0.2",
"eslint-config-prettier": "10.1.8",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-import": "2.32.0",
"express": "5.2.1",
"fast-glob": "3.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ export function injectKarmaReporter(
private startWatchingBuild() {
void (async () => {
// This is effectively "for await of but skip what's already consumed".
let isDone = false; // to mark the loop condition as "not constant".
while (!isDone) {
while (true) {
const { done, value: buildOutput } = await buildIterator.next();
if (done) {
isDone = true;
break;
}

Expand Down
10 changes: 6 additions & 4 deletions packages/angular/build/src/builders/unit-test/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ async function loadTestRunner(runnerName: string): Promise<TestRunner> {
} catch (e) {
assertIsError(e);
if (e.code === 'ERR_MODULE_NOT_FOUND') {
throw new Error(`Unknown test runner "${runnerName}".`);
throw new Error(`Unknown test runner "${runnerName}".`, { cause: e });
}
throw new Error(
`Failed to load the '${runnerName}' test runner. The package may be corrupted or improperly installed.\n` +
`Error: ${e.message}`,
`Failed to load the '${runnerName}' test runner. The package may be corrupted or improperly installed.`,
{ cause: e },
);
}

Expand Down Expand Up @@ -370,7 +370,9 @@ async function transformNgPackagrOptions(
ngPackageJson = JSON.parse(await readFile(ngPackagePath, 'utf-8'));
} catch (e) {
assertIsError(e);
throw new Error(`Could not read ng-package.json at ${ngPackagePath}: ${e.message}`);
throw new Error(`Could not read ng-package.json at ${ngPackagePath}`, {
cause: e,
});
}

const lib = ngPackageJson['lib'] || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class VitestExecutor implements TestExecutor {
}
throw new Error(
'The `vitest` package was not found. Please install the package and rerun the test command.',
{ cause: error },
);
}
const { startVitest } = vitestNodeModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ function getEsBuildCommonPolyfillsOptions(
cache: loadResultCache,
loadContent: async (_, build) => {
let polyfillPaths = polyfills;
let warnings: PartialMessage[] | undefined;

if (tryToResolvePolyfillsAsRelative) {
polyfillPaths = await Promise.all(
Expand Down Expand Up @@ -736,7 +735,6 @@ function getEsBuildCommonPolyfillsOptions(
return {
contents,
loader: 'js',
warnings,
resolveDir: workspaceRoot,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ async function transformWithBabel(
// Which makes it hard to find the actual error message.
const index = error.message.indexOf(')\n');
const msg = index !== -1 ? error.message.slice(0, index + 1) : error.message;
throw new Error(`${msg}\nAn error occurred inlining file "${options.filename}"`);
throw new Error(`${msg}\nAn error occurred inlining file "${options.filename}"`, {
cause: error,
});
}

if (!ast) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function normalizeAssetPatterns(
}

let glob: string, input: string;
let isDirectory = false;
let isDirectory: boolean;

try {
isDirectory = statSync(resolvedAssetPath).isDirectory();
Expand Down
10 changes: 5 additions & 5 deletions packages/angular/build/src/utils/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.dev/license
*/

import type {
Config,
Filesystem,
} from '@angular/service-worker/config' with { 'resolution-mode': 'import' };
import type { Config, Filesystem } from '@angular/service-worker/config' with {
'resolution-mode': 'import',
};
import * as crypto from 'node:crypto';
import { existsSync, promises as fsPromises } from 'node:fs';
import * as path from 'node:path';
Expand Down Expand Up @@ -149,6 +148,7 @@ export async function augmentAppWithServiceWorker(
'Error: Expected to find an ngsw-config.json configuration file' +
` in the ${appRoot} folder. Either provide one or` +
' disable Service Worker in the angular.json configuration file.',
{ cause: error },
);
} else {
throw error;
Expand Down Expand Up @@ -200,7 +200,7 @@ export async function augmentAppWithServiceWorkerEsbuild(
workspaceRoot,
configPath,
)}" could not be found.`;
throw new Error(message);
throw new Error(message, { cause: error });
} else {
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/commands/mcp/tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function runBuild(input: BuildToolInput, context: McpToolContext) {
const args = ['build', projectName, '-c', input.configuration ?? DEFAULT_CONFIGURATION];

let status: BuildStatus = 'success';
let logs: string[] = [];
let logs: string[];
let outputPath: string | undefined;

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/commands/mcp/tools/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function runE2e(input: E2eToolInput, host: Host, context: McpToolCo
const args = ['e2e', projectName];

let status: E2eStatus = 'success';
let logs: string[] = [];
let logs: string[];

try {
logs = (await host.runCommand('ng', args, { cwd: workspacePath })).logs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function discoverAndCategorizeFiles(
isDirectory = statSync(fileOrDirPath).isDirectory();
} catch (e) {
// Re-throw to be handled by the main function as a user input error
throw new Error(`Failed to access path: ${fileOrDirPath}`);
throw new Error(`Failed to access path: ${fileOrDirPath}`, { cause: e });
}

if (isDirectory) {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/commands/mcp/tools/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function runTest(input: TestToolInput, context: McpToolContext) {
}

let status: TestStatus = 'success';
let logs: string[] = [];
let logs: string[];

try {
logs = (await context.host.runCommand('ng', args, { cwd: workspacePath })).logs;
Expand Down
12 changes: 2 additions & 10 deletions packages/angular/cli/src/commands/mcp/workspace-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ export async function resolveWorkspaceAndProject({
try {
workspace = await AngularWorkspace.load(configPath);
} catch (e) {
throw new Error(
`Failed to load workspace configuration at ${configPath}: ${
e instanceof Error ? e.message : e
}`,
);
throw new Error(`Failed to load workspace configuration at ${configPath}`, { cause: e });
}
} else if (mcpWorkspace) {
workspace = mcpWorkspace;
Expand All @@ -146,11 +142,7 @@ export async function resolveWorkspaceAndProject({
try {
workspace = await AngularWorkspace.load(configPath);
} catch (e) {
throw new Error(
`Failed to load workspace configuration at ${configPath}: ${
e instanceof Error ? e.message : e
}`,
);
throw new Error(`Failed to load workspace configuration at ${configPath}.`, { cause: e });
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/angular/cli/src/commands/update/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,13 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
packageManager: PackageManager,
): Promise<number | void> {
const { logger } = this.context;
let packageDependency = rootDependencies.get(packageName);
const packageDependency = rootDependencies.get(packageName);
let packagePath = packageDependency?.path;
let packageNode: PackageManifest | undefined;

if (!packageDependency) {
const installed = await packageManager.getInstalledPackage(packageName);
if (installed) {
packageDependency = installed;
packagePath = installed.path;
}
}
Expand Down Expand Up @@ -450,7 +449,7 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
for (const { identifier: requestIdentifier, node } of requests) {
const packageName = requestIdentifier.name;

let manifest: PackageManifest | null = null;
let manifest: PackageManifest | null;
try {
manifest = await packageManager.getManifest(requestIdentifier);
} catch (e) {
Expand Down
6 changes: 4 additions & 2 deletions packages/angular/cli/src/commands/update/schematic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ function _usageMessage(
logger.info(
' ' + ['Name', 'Version', 'Command to update'].map((x, i) => x.padEnd(pads[i])).join(''),
);
logger.info(' ' + '-'.repeat(pads.reduce((s, x) => (s += x), 0) + 20));

const totalWidth = pads.reduce((sum, width) => sum + width, 20);
logger.info(` ${'-'.repeat(totalWidth)}`);

packagesToUpdate.forEach((fields) => {
if (!fields) {
Expand Down Expand Up @@ -681,7 +683,7 @@ function _addPackageGroup(
if (!packageGroup) {
return;
}
let packageGroupNormalized: Record<string, string> = {};
let packageGroupNormalized: Record<string, string>;
if (Array.isArray(packageGroup) && !packageGroup.some((x) => typeof x != 'string')) {
packageGroupNormalized = packageGroup.reduce(
(acc, curr) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/src/utilities/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export async function initializeAutocomplete(): Promise<string> {
);
} catch (err) {
assertIsError(err);
throw new Error(`Failed to append autocompletion setup to \`${rcFile}\`:\n${err.message}`);
throw new Error(`Failed to append autocompletion setup to \`${rcFile}\`.`, { cause: err });
}

return rcFile;
Expand Down
5 changes: 1 addition & 4 deletions packages/angular/cli/src/utilities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,7 @@ export async function getWorkspace(

return workspace;
} catch (error) {
throw new Error(
`Workspace config file cannot be loaded: ${configPath}` +
`\n${error instanceof Error ? error.message : error}`,
);
throw new Error(`Workspace config file cannot be loaded: ${configPath}`, { cause: error });
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/angular_devkit/architect/src/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ describe('architect', () => {

// Use an invalid target and check for error.
target.target = 'invalid';
options = {};

// This should not error.
const run2 = await architect.scheduleBuilder('package:getTargetOptions', {});
Expand Down Expand Up @@ -375,7 +374,6 @@ describe('architect', () => {

// Use an invalid target and check for error.
target.target = 'invalid';
actualBuilderName = '';

// This should not error.
const run2 = await architect.scheduleBuilder('package:do-it', {});
Expand Down
9 changes: 6 additions & 3 deletions packages/angular_devkit/architect/src/jobs/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import { Readwrite } from './types';
/**
* A JobDispatcher can be used to dispatch between multiple jobs.
*/
export interface JobDispatcher<A extends JsonValue, I extends JsonValue, O extends JsonValue>
extends JobHandler<A, I, O> {
export interface JobDispatcher<
A extends JsonValue,
I extends JsonValue,
O extends JsonValue,
> extends JobHandler<A, I, O> {
/**
* Set the default job if all conditionals failed.
* @param name The default name if all conditions are false.
Expand Down Expand Up @@ -43,7 +46,7 @@ export function createDispatcher<A extends JsonValue, I extends JsonValue, O ext
const job: JobHandler<JsonValue, JsonValue, JsonValue> = Object.assign(
(argument: JsonValue, context: JobHandlerContext) => {
const maybeDelegate = conditionalDelegateList.find(([predicate]) => predicate(argument));
let delegate: Job<JsonValue, JsonValue, JsonValue> | null = null;
let delegate: Job<JsonValue, JsonValue, JsonValue>;

if (maybeDelegate) {
delegate = context.scheduler.schedule(maybeDelegate[1], argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async function checkForEsbuild(
// If we can't find a development builder, we can't use 'detect'.
throw new Error(
'Failed to detect the builder used by the application. Please set builderMode explicitly.',
{ cause: e },
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function statsToString(
const w = (x: string) => (colors ? ansiColors.bold.white(x) : x);

const changedChunksStats: BundleStats[] = [];
let unchangedChunkNumber = 0;
let hasEstimatedTransferSizes = false;

const isFirstRun = !runsCache.has(json.outputPath || '');
Expand Down Expand Up @@ -109,7 +108,7 @@ function statsToString(
}
changedChunksStats.push(generateBundleStats({ ...chunk, rawSize, estimatedTransferSize }));
}
unchangedChunkNumber = json.chunks.length - changedChunksStats.length;
const unchangedChunkNumber = json.chunks.length - changedChunksStats.length;

runsCache.add(json.outputPath || '');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function normalizeAssetPatterns(
}

let glob: string, input: string;
let isDirectory = false;
let isDirectory: boolean;

try {
isDirectory = statSync(resolvedAssetPath).isDirectory();
Expand Down
Loading