Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): remove dependency on `text-t…
Browse files Browse the repository at this point in the history
…able`

Removes `text-table` from dependencies
  • Loading branch information
alan-agius4 committed Jan 26, 2024
1 parent dbd3984 commit 09c6f5f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
"@types/semver": "^7.3.12",
"@types/shelljs": "^0.8.11",
"@types/tar": "^6.1.2",
"@types/text-table": "^0.2.1",
"@types/watchpack": "^2.4.4",
"@types/yargs": "^17.0.20",
"@types/yargs-parser": "^21.0.0",
Expand Down Expand Up @@ -204,7 +203,6 @@
"symbol-observable": "4.0.0",
"tar": "^6.1.6",
"terser": "5.27.0",
"text-table": "0.2.0",
"tree-kill": "1.2.2",
"ts-node": "^10.9.1",
"tslib": "2.6.2",
Expand Down
2 changes: 0 additions & 2 deletions packages/angular_devkit/build_angular/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ ts_library(
"@npm//@types/node",
"@npm//@types/picomatch",
"@npm//@types/semver",
"@npm//@types/text-table",
"@npm//@types/watchpack",
"@npm//@vitejs/plugin-basic-ssl",
"@npm//@web/test-runner",
Expand Down Expand Up @@ -203,7 +202,6 @@ ts_library(
"@npm//source-map-loader",
"@npm//source-map-support",
"@npm//terser",
"@npm//text-table",
"@npm//tree-kill",
"@npm//tslib",
"@npm//typescript",
Expand Down
1 change: 0 additions & 1 deletion packages/angular_devkit/build_angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"source-map-loader": "5.0.0",
"source-map-support": "0.5.21",
"terser": "5.27.0",
"text-table": "0.2.0",
"tree-kill": "1.2.2",
"tslib": "2.6.2",
"undici": "6.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

import { WebpackLoggingCallback } from '@angular-devkit/build-webpack';
import { logging, tags } from '@angular-devkit/core';
import assert from 'assert';
import * as path from 'path';
import textTable from 'text-table';
import assert from 'node:assert';
import * as path from 'node:path';
import { Configuration, StatsCompilation } from 'webpack';
import { Schema as BrowserBuilderOptions } from '../../../builders/browser/schema';
import { normalizeOptimization } from '../../../utils';
Expand Down Expand Up @@ -88,7 +87,6 @@ export function generateBuildStatsTable(
const r = (x: string) => (colors ? ansiColors.redBright(x) : x);
const y = (x: string) => (colors ? ansiColors.yellowBright(x) : x);
const bold = (x: string) => (colors ? ansiColors.bold(x) : x);
const dim = (x: string) => (colors ? ansiColors.dim(x) : x);

const getSizeColor = (name: string, file?: string, defaultColor = c) => {
const severity = budgets.get(name) || (file && budgets.get(file));
Expand Down Expand Up @@ -216,11 +214,45 @@ export function generateBuildStatsTable(
bundleInfo.push(['Lazy Chunk Files', ...baseTitles].map(bold), ...changedLazyChunksStats);
}

return textTable(bundleInfo, {
hsep: dim(' | '),
stringLength: (s) => removeColor(s).length,
align: tableAlign,
});
return generateTableText(bundleInfo, colors);
}

function generateTableText(bundleInfo: (string | number)[][], colors: boolean): string {
const longest: number[] = [];
for (const item of bundleInfo) {
for (let i = 0; i < item.length; i++) {
if (item[i] === undefined) {
continue;
}

const currentItem = item[i].toString();
const currentLongest = (longest[i] ??= 0);
const currentItemLength = removeColor(currentItem).length;
if (currentLongest < currentItemLength) {
longest[i] = currentItemLength;
}
}
}

const seperator = colors ? ansiColors.dim(' | ') : ' | ';
const outputTable: string[] = [];
for (const item of bundleInfo) {
for (let i = 0; i < longest.length; i++) {
if (item[i] === undefined) {
continue;
}

const currentItem = item[i].toString();
const currentItemLength = removeColor(currentItem).length;
const stringPad = ' '.repeat(longest[i] - currentItemLength);
// Last item is right aligned, thus we add the padding at the start.
item[i] = longest.length === i + 1 ? stringPad + currentItem : currentItem + stringPad;
}

outputTable.push(item.join(seperator));
}

return outputTable.join('\n');
}

function generateBuildStats(hash: string, time: number, colors: boolean): string {
Expand Down
10 changes: 1 addition & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@
tslib "^2.3.0"

"@angular/bazel@https://github.com/angular/bazel-builds.git#a0e463179c1d15995508827d977565031b9ba8fb":
version "17.2.0-next.0+sha-c043128"
uid a0e463179c1d15995508827d977565031b9ba8fb
version "17.2.0-next.0"
resolved "https://github.com/angular/bazel-builds.git#a0e463179c1d15995508827d977565031b9ba8fb"
dependencies:
"@microsoft/api-extractor" "^7.24.2"
Expand All @@ -149,7 +148,6 @@

"@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#103b5c2cf1be1d62b292d3c0a447b0f6918f0770":
version "0.0.0-10788de8a2999c84bc16a132dfe1a0a9bc934604"
uid "103b5c2cf1be1d62b292d3c0a447b0f6918f0770"
resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#103b5c2cf1be1d62b292d3c0a447b0f6918f0770"
dependencies:
"@angular-devkit/build-angular" "17.2.0-next.0"
Expand Down Expand Up @@ -317,7 +315,6 @@

"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#21604aaadd15167ee2be0d89622b7009a13cdac7":
version "0.0.0-10788de8a2999c84bc16a132dfe1a0a9bc934604"
uid "21604aaadd15167ee2be0d89622b7009a13cdac7"
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#21604aaadd15167ee2be0d89622b7009a13cdac7"
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
Expand Down Expand Up @@ -3961,11 +3958,6 @@
"@types/node" "*"
minipass "^4.0.0"

"@types/text-table@^0.2.1":
version "0.2.5"
resolved "https://registry.yarnpkg.com/@types/text-table/-/text-table-0.2.5.tgz#f9c609b81c943e9fc8d73ef82ad2f2a78be5f53b"
integrity sha512-hcZhlNvMkQG/k1vcZ6yHOl6WAYftQ2MLfTHcYRZ2xYZFD8tGVnE3qFV0lj1smQeDSR7/yY0PyuUalauf33bJeA==

"@types/through@*":
version "0.0.33"
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.33.tgz#14ebf599320e1c7851e7d598149af183c6b9ea56"
Expand Down

0 comments on commit 09c6f5f

Please sign in to comment.