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
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ DDIy4xXPW1STWfsmSYJfYW3wa0wk+pJQ3j2cTzkPQQ8gwpvM3U9DJl43uwb37v6I

async function goToPageAndWaitForWS(page: Page, url: string): Promise<void> {
const baseUrl = url.replace(/^http/, 'ws');
const socksRequest =
baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}ng-cli-ws` : `${baseUrl}/ng-cli-ws`;
const socksRequest = baseUrl.at(-1) === '/' ? `${baseUrl}ng-cli-ws` : `${baseUrl}/ng-cli-ws`;
// Create a Chrome dev tools session so that we can capturing websocket request.
// https://github.com/puppeteer/puppeteer/issues/2974

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function executeOnceAndFetch<T>(
let content = undefined;
if (executionResult.result?.success) {
let baseUrl = `${executionResult.result.baseUrl}`;
baseUrl = baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`;
baseUrl = baseUrl.at(-1) === '/' ? baseUrl : `${baseUrl}/`;
const resolvedUrl = new URL(url, baseUrl);
const originalResponse = await fetch(resolvedUrl, options?.request);
response = originalResponse.clone();
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function executeOnceAndGet<T>(
let content = undefined;
if (executionResult.result?.success) {
let baseUrl = `${executionResult.result.baseUrl}`;
baseUrl = baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`;
baseUrl = baseUrl.at(-1) === '/' ? baseUrl : `${baseUrl}/`;
const resolvedUrl = new URL(url, baseUrl);

response = await new Promise<IncomingMessage>((resolve) =>
Expand Down
4 changes: 1 addition & 3 deletions packages/angular/build/src/builders/dev-server/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ export async function* serveWithVite(
const baseHref = result.detail['htmlBaseHref'] as string;
// Remove trailing slash
serverOptions.servePath =
baseHref !== './' && baseHref[baseHref.length - 1] === '/'
? baseHref.slice(0, -1)
: baseHref;
baseHref !== './' && baseHref.at(-1) === '/' ? baseHref.slice(0, -1) : baseHref;
}

assetFiles.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createAngularAssetsMiddleware(
// The base of the URL is unused but required to parse the URL.
const pathname = pathnameWithoutBasePath(req.url, server.config.base);
const extension = extname(pathname);
const pathnameHasTrailingSlash = pathname[pathname.length - 1] === '/';
const pathnameHasTrailingSlash = pathname.at(-1) === '/';

// Rewrite all build assets to a vite raw fs URL
const asset = assets.get(pathname);
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/build/src/utils/project-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { join } from 'node:path';
* @returns A normalized path string.
*/
export function normalizeDirectoryPath(path: string): string {
const last = path[path.length - 1];
const last = path.at(-1);
if (last === '/' || last === '\\') {
return path.slice(0, -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function generateAngularServerAppEngineManifest(

// Remove trailing slash but retain leading slash.
let basePath = baseHref || '/';
if (basePath.length > 1 && basePath[basePath.length - 1] === '/') {
if (basePath.length > 1 && basePath.at(-1) === '/') {
basePath = basePath.slice(0, -1);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/angular/build/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
export function stripTrailingSlash(url: string): string {
// Check if the last character of the URL is a slash
return url.length > 1 && url[url.length - 1] === '/' ? url.slice(0, -1) : url;
return url.length > 1 && url.at(-1) === '/' ? url.slice(0, -1) : url;
}

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ export function addLeadingSlash(url: string): string {
*/
export function addTrailingSlash(url: string): string {
// Check if the URL already end with a slash
return url[url.length - 1] === '/' ? url : `${url}/`;
return url.at(-1) === '/' ? url : `${url}/`;
}

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ export function joinUrlParts(...parts: string[]): string {
if (part[0] === '/') {
normalizedPart = normalizedPart.slice(1);
}
if (part[part.length - 1] === '/') {
if (part.at(-1) === '/') {
normalizedPart = normalizedPart.slice(0, -1);
}
if (normalizedPart !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export async function parseJsonSchemaToOptions(
// Skip any non-property items.
return;
}
const name = ptr[ptr.length - 1];
const name = ptr.at(-1) as string;

const types = getSupportedTypes(current);

Expand Down
2 changes: 1 addition & 1 deletion packages/angular/ssr/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ts_project(
),
args = [
"--lib",
"dom,es2020",
"dom,es2022",
],
data = [
"//packages/angular/ssr/third_party/beasties:beasties_bundled",
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/ssr/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
export function stripTrailingSlash(url: string): string {
// Check if the last character of the URL is a slash
return url.length > 1 && url[url.length - 1] === '/' ? url.slice(0, -1) : url;
return url.length > 1 && url.at(-1) === '/' ? url.slice(0, -1) : url;
}

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ export function addLeadingSlash(url: string): string {
*/
export function addTrailingSlash(url: string): string {
// Check if the URL already end with a slash
return url[url.length - 1] === '/' ? url : `${url}/`;
return url.at(-1) === '/' ? url : `${url}/`;
}

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ export function joinUrlParts(...parts: string[]): string {
if (part[0] === '/') {
normalizedPart = normalizedPart.slice(1);
}
if (part[part.length - 1] === '/') {
if (part.at(-1) === '/') {
normalizedPart = normalizedPart.slice(0, -1);
}
if (normalizedPart !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('SimpleScheduler', () => {
// Might be out of order.
expect(done).toEqual(jasmine.arrayContaining([1, 2, 3, 4, 5, 6, 7]));
// Verify at least partial order.
expect(done[done.length - 1]).toBe(7);
expect(done.at(-1)).toBe(7);
expect(done.indexOf(4)).toBeGreaterThan(done.indexOf(1));
expect(done.indexOf(5)).toBeGreaterThan(done.indexOf(2));
expect(done.indexOf(6)).toBeGreaterThan(done.indexOf(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ async function createProxy(target: string, secure: boolean, ws = true): Promise<

async function goToPageAndWaitForWS(page: Page, url: string): Promise<void> {
const baseUrl = url.replace(/^http/, 'ws');
const socksRequest =
baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}ng-cli-ws` : `${baseUrl}/ng-cli-ws`;
const socksRequest = baseUrl.at(-1) === '/' ? `${baseUrl}ng-cli-ws` : `${baseUrl}/ng-cli-ws`;
// Create a Chrome dev tools session so that we can capturing websocket request.
// https://github.com/puppeteer/puppeteer/issues/2974

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function executeOnceAndFetch<T>(
let content = undefined;
if (executionResult.result?.success) {
let baseUrl = `${executionResult.result.baseUrl}`;
baseUrl = baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`;
baseUrl = baseUrl.at(-1) === '/' ? baseUrl : `${baseUrl}/`;
const resolvedUrl = new URL(url, baseUrl);
const originalResponse = await fetch(resolvedUrl, options?.request);
response = originalResponse.clone();
Expand Down
4 changes: 1 addition & 3 deletions packages/angular_devkit/core/src/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ function templateWithSourceMap(ast: TemplateAst, options?: TemplateOptions): str
]),
);

const end = ast.children.length
? ast.children[ast.children.length - 1].end
: { line: 0, column: 0 };
const end = ast.children.at(-1)?.end ?? { line: 0, column: 0 };
const nodes = ast.children
.reduce((chunk, node) => {
let code: string | SourceNode | (SourceNode | string)[] = '';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/core/src/virtual-fs/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const NormalizedRoot: Path = NormalizedSep;
*/
export function split(path: Path): PathFragment[] {
const fragments = path.split(NormalizedSep).map((x) => fragment(x));
if (fragments[fragments.length - 1].length === 0) {
if (fragments.at(-1)?.length === 0) {
fragments.pop();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/schematics/src/tree/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ActionList implements Iterable<Action> {
this._actions.push({
...(action as Action),
id: _id++,
parent: this._actions[this._actions.length - 1]?.id ?? 0,
parent: this._actions.at(-1)?.id ?? 0,
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/angular_devkit/schematics/src/workflow/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export abstract class BaseWorkflow implements Workflow {
}

get context(): Readonly<WorkflowExecutionContext> {
const maybeContext = this._context[this._context.length - 1];
const maybeContext = this._context.at(-1);
if (!maybeContext) {
throw new Error('Cannot get context when workflow is not executing...');
}
Expand Down Expand Up @@ -146,7 +146,7 @@ export abstract class BaseWorkflow implements Workflow {
execute(
options: Partial<WorkflowExecutionContext> & RequiredWorkflowExecutionContext,
): Observable<void> {
const parentContext = this._context[this._context.length - 1];
const parentContext = this._context.at(-1);

if (!parentContext) {
this._lifeCycle.next({ kind: 'start' });
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const logger = createConsoleLogger(argv.verbose, process.stdout, process.stderr,

const logStack = [logger];
function lastLogger() {
return logStack[logStack.length - 1];
return logStack.at(-1)!;
}

// Under bazel the compiled file (.js) and types (.d.ts) are available.
Expand Down
2 changes: 1 addition & 1 deletion tsconfig-build-esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"compilerOptions": {
"module": "esnext",
"target": "es2022",
"lib": ["es2020"],
"lib": ["es2022"],
// don't auto-discover @types/node, it results in a ///<reference in the .d.ts output
"types": [],
"sourceMap": true,
Expand Down