From e29afbbdd1d3e74f448841d1acb8aa9b43b56779 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Thu, 2 Apr 2026 18:39:25 +0200 Subject: [PATCH] chore: updates deps; configure TS better --- package-lock.json | 17 +++++++++-------- package.json | 7 ++++--- src/__fixtures__/small.json | 7 +++++++ src/components.ts | 23 ++++++++++------------- src/program.ts | 9 ++++++--- src/smoke.test.ts | 3 ++- src/types.ts | 4 ++++ tsconfig.json | 6 ++++-- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8f9f418..872806a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.0.0", "license": "MIT", "dependencies": { - "@projectwallace/css-analyzer": "^9.3.0" + "@projectwallace/css-analyzer": "^9.6.0" }, "bin": { "wallace": "dist/bin.mjs" @@ -18,7 +18,7 @@ "@types/node": "^22.0.0", "@vitest/coverage-v8": "^4.1.0", "oxfmt": "^0.43.0", - "oxlint": "^1.51.0", + "oxlint": "^1.58.0", "publint": "^0.3.18", "tsdown": "^0.21.4", "typescript": "^6.0.2", @@ -808,9 +808,10 @@ } }, "node_modules/@projectwallace/css-analyzer": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/@projectwallace/css-analyzer/-/css-analyzer-9.4.0.tgz", - "integrity": "sha512-JBx/HvLFCbmg9DV9gZe8/RfuQfD0XhWxmgeeGXTlUpoeMjfGxKuaGBX4Q3CFu4/+glkG2LRb1tOCYPSzIEU2tg==", + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/@projectwallace/css-analyzer/-/css-analyzer-9.6.0.tgz", + "integrity": "sha512-rhLqi9B+tpBjEvjS5ROdva63MZ/NgAc4dqzje6//2fcVZX8QPSuCyDD1zrODwwYIQUh2l3+E7u9KvVgB4VQL2g==", + "license": "MIT", "dependencies": { "@projectwallace/css-parser": "^0.13.8" }, @@ -3355,9 +3356,9 @@ "optional": true }, "@projectwallace/css-analyzer": { - "version": "9.4.0", - "resolved": "https://registry.npmjs.org/@projectwallace/css-analyzer/-/css-analyzer-9.4.0.tgz", - "integrity": "sha512-JBx/HvLFCbmg9DV9gZe8/RfuQfD0XhWxmgeeGXTlUpoeMjfGxKuaGBX4Q3CFu4/+glkG2LRb1tOCYPSzIEU2tg==", + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/@projectwallace/css-analyzer/-/css-analyzer-9.6.0.tgz", + "integrity": "sha512-rhLqi9B+tpBjEvjS5ROdva63MZ/NgAc4dqzje6//2fcVZX8QPSuCyDD1zrODwwYIQUh2l3+E7u9KvVgB4VQL2g==", "requires": { "@projectwallace/css-parser": "^0.13.8" } diff --git a/package.json b/package.json index 201c335..37ec865 100644 --- a/package.json +++ b/package.json @@ -35,16 +35,17 @@ "test": "vitest run --coverage", "build": "tsdown", "lint-package": "publint", - "lint": "oxlint; oxfmt --check" + "lint": "oxlint; oxfmt --check", + "check": "tsc --noEmit" }, "dependencies": { - "@projectwallace/css-analyzer": "^9.3.0" + "@projectwallace/css-analyzer": "^9.6.0" }, "devDependencies": { "@types/node": "^22.0.0", "@vitest/coverage-v8": "^4.1.0", "oxfmt": "^0.43.0", - "oxlint": "^1.51.0", + "oxlint": "^1.58.0", "publint": "^0.3.18", "tsdown": "^0.21.4", "typescript": "^6.0.2", diff --git a/src/__fixtures__/small.json b/src/__fixtures__/small.json index c63a7e7..3492eda 100644 --- a/src/__fixtures__/small.json +++ b/src/__fixtures__/small.json @@ -438,6 +438,13 @@ "content": 1, "zoom": 1 }, + "shorthands": { + "total": 0, + "totalUnique": 0, + "unique": {}, + "uniquenessRatio": 0, + "ratio": 0 + }, "uniquenessRatio": 1, "prefixed": { "total": 0, diff --git a/src/components.ts b/src/components.ts index bdc2a25..a242709 100644 --- a/src/components.ts +++ b/src/components.ts @@ -1,13 +1,10 @@ -import type { analyze } from '@projectwallace/css-analyzer' import { to_filesize, to_number, to_percentage, pad_end, pad_start } from './formatters.js' -import type { Colors } from './types.js' - -type Stats = ReturnType +import type { Colors, CssAnalysis } from './types.js' const columns = [19, 12, 12, 12] const width = columns.reduce((total, num) => (total += num), 0) + columns.length -export function Analytics(stats: Stats, style: Colors): string { +export function Analytics(stats: CssAnalysis, style: Colors): string { function Row(...tds: unknown[]): string { return tds .map((td, index) => { @@ -23,7 +20,7 @@ export function Analytics(stats: Stats, style: Colors): string { return style.dim(''.padEnd(width, '─')) } - function Summary(stats: Stats): string { + function Summary(stats: CssAnalysis): string { return [ Hr(), ['Lines of Code', 'Filesize', 'Rules', 'Selectors', 'Declarations'].join(style.dim(' │ ')), @@ -40,7 +37,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function Stylesheet(stylesheet: Stats['stylesheet']): string { + function Stylesheet(stylesheet: CssAnalysis['stylesheet']): string { return [ Row( 'Comments', @@ -55,7 +52,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function Rules(rules: Stats['rules']): string { + function Rules(rules: CssAnalysis['rules']): string { let empty_count = to_number(rules.empty.total) return [ Row( @@ -85,7 +82,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function Selectors(selectors: Stats['selectors']): string { + function Selectors(selectors: CssAnalysis['selectors']): string { return [ Row( style.underline('Selectors'), @@ -134,7 +131,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function AtRules(atrules: Stats['atrules']): string { + function AtRules(atrules: CssAnalysis['atrules']): string { const { media, supports, fontface, import: imports, keyframes, container, property } = atrules return [ @@ -189,7 +186,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function Declarations(declarations: Stats['declarations']): string { + function Declarations(declarations: CssAnalysis['declarations']): string { return [ Row( style.underline('Declarations'), @@ -207,7 +204,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function Properties(properties: Stats['properties']): string { + function Properties(properties: CssAnalysis['properties']): string { return [ Row( style.underline('Properties'), @@ -242,7 +239,7 @@ export function Analytics(stats: Stats, style: Colors): string { ].join('\n') } - function Values(values: Stats['values']): string { + function Values(values: CssAnalysis['values']): string { function ValueRow( title: string, total: number, diff --git a/src/program.ts b/src/program.ts index b20b3ef..8b656c3 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3,7 +3,7 @@ import { parseArgs } from 'node:util' import { help } from './help.js' import { Analytics } from './components.js' export type { Colors } from './types.js' -import type { Colors } from './types.js' +import type { Colors, CssAnalysis } from './types.js' type ProgramOptions = { args: string[] @@ -49,7 +49,7 @@ export async function Program({ return help(terminal_colors) } - const stats = analyze(css) + const stats = analyze(css, { useLocations: false }) delete (stats as Record).__meta__ // Format as JSON if user asked for it @@ -57,5 +57,8 @@ export async function Program({ return JSON.stringify(stats) } - return Analytics(stats, terminal_colors) + // The analyze function has overloads and TypeScript's ReturnType only captures the last overload's return type, + // making the two variants structurally incompatible for a direct cast. + // The as unknown as CssAnalysis double assertion is the standard escape hatch for this. + return Analytics(stats as unknown as CssAnalysis, terminal_colors) } diff --git a/src/smoke.test.ts b/src/smoke.test.ts index 3a2d51b..af387c7 100644 --- a/src/smoke.test.ts +++ b/src/smoke.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest' import { readFile } from 'node:fs/promises' import { analyze } from '@projectwallace/css-analyzer' import { Analytics } from './components.js' +import { CssAnalysis } from './types.js' // import { writeFileSync } from 'node:fs' const terminal_colors = { @@ -24,7 +25,7 @@ describe('Smoke Tests', () => { readFile(`./src/__fixtures__/${fileName}.css`, 'utf-8'), readFile(`./src/__fixtures__/${fileName}.txt`, 'utf-8'), ]) - const stats = analyze(css) + const stats = analyze(css) as unknown as CssAnalysis const actual = Analytics(stats, terminal_colors) // writeFileSync(`./src/__fixtures__/${fileName}.txt`, actual) expect(actual).toEqual(expected) diff --git a/src/types.ts b/src/types.ts index f7ede83..be6b15e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,7 @@ +import { analyze } from '@projectwallace/css-analyzer' + +export type CssAnalysis = ReturnType + export type Colors = { bold: (str: string) => string dim: (str: string) => string diff --git a/tsconfig.json b/tsconfig.json index a14b5fd..768f7a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,10 @@ "moduleResolution": "NodeNext", "strict": true, "skipLibCheck": true, - "outDir": "./dist" + "outDir": "./dist", + "rootDir": "src", + "types": ["node"] }, "include": ["src/**/*.ts"], - "exclude": ["src/**/*.test.ts", "node_modules"] + "exclude": ["node_modules"] }