From 3a3910d75da7e509a8d92df87920424e6f71af83 Mon Sep 17 00:00:00 2001 From: Paul Valladares <85648028+dreyfus92@users.noreply.github.com> Date: Sun, 1 Feb 2026 18:34:25 -0600 Subject: [PATCH 1/2] refactor: remove CJS/ESM dependency tracking and related statistics --- src/analyze/dependencies.ts | 29 ++------ src/analyze/report.ts | 4 +- src/commands/analyze.ts | 9 --- src/test/__snapshots__/cli.test.ts.snap | 70 ++++++++++--------- .../duplicate-dependencies.test.ts.snap | 12 ++-- .../__snapshots__/dependencies.test.ts.snap | 8 --- src/test/analyze/dependencies.test.ts | 2 - src/test/cli.test.ts | 7 +- src/test/custom-manifests.test.ts | 2 - src/test/duplicate-dependencies.test.ts | 8 +-- src/test/plugin-runner.test.ts | 2 +- src/types.ts | 2 - 12 files changed, 56 insertions(+), 99 deletions(-) diff --git a/src/analyze/dependencies.ts b/src/analyze/dependencies.ts index 182af55..ae124c4 100644 --- a/src/analyze/dependencies.ts +++ b/src/analyze/dependencies.ts @@ -1,4 +1,3 @@ -import {analyzePackageModuleType} from '../compute-type.js'; import type { ReportPluginResult, Message, @@ -24,29 +23,11 @@ export async function runDependencyAnalysis( const prodDependencies = Object.keys(pkg.dependencies || {}).length; const devDependencies = Object.keys(pkg.devDependencies || {}).length; - let cjsDependencies = 0; - let esmDependencies = 0; - // Recursively traverse dependencies - async function traverse( - packagePath: string, - depth: number, - pathInTree: string - ) { + async function traverse(packagePath: string, pathInTree: string) { const depPkg = await getPackageJson(context.fs, packagePath); if (!depPkg || !depPkg.name) return; - // Only count CJS/ESM for non-root packages - if (depth > 0) { - const type = analyzePackageModuleType(depPkg); - if (type === 'cjs') cjsDependencies++; - if (type === 'esm') esmDependencies++; - if (type === 'dual') { - cjsDependencies++; - esmDependencies++; - } - } - for (const depName of Object.keys(depPkg.dependencies || {})) { let packageMatch = packageFiles.find((packageFile) => normalizePath(packageFile).endsWith( @@ -65,13 +46,13 @@ export async function runDependencyAnalysis( } if (packageMatch) { - await traverse(packageMatch, depth + 1, pathInTree + ' > ' + depName); + await traverse(packageMatch, pathInTree + ' > ' + depName); } } } // Start traversal from root - await traverse('/package.json', 0, 'root'); + await traverse('/package.json', 'root'); const stats: Partial = { name: pkg.name, @@ -79,9 +60,7 @@ export async function runDependencyAnalysis( installSize, dependencyCount: { production: prodDependencies, - development: devDependencies, - esm: esmDependencies, - cjs: cjsDependencies + development: devDependencies } }; diff --git a/src/analyze/report.ts b/src/analyze/report.ts index da36ced..0acf377 100644 --- a/src/analyze/report.ts +++ b/src/analyze/report.ts @@ -81,9 +81,7 @@ export async function report(options: Options) { version: packageFile.version || '0.0.0', dependencyCount: { production: 0, - development: 0, - cjs: 0, - esm: 0 + development: 0 }, extraStats: [] }; diff --git a/src/commands/analyze.ts b/src/commands/analyze.ts index 13bc580..0f4e876 100644 --- a/src/commands/analyze.ts +++ b/src/commands/analyze.ts @@ -60,11 +60,6 @@ export async function run(ctx: CommandContext) { const totalDeps = stats.dependencyCount.production + stats.dependencyCount.development; - const totalDeepDeps = stats.dependencyCount.cjs + stats.dependencyCount.esm; - const esmPercentage = - totalDeepDeps > 0 - ? Math.floor((stats.dependencyCount.esm / totalDeepDeps) * 100) - : 0; const summaryPairs: Array<[string, string]> = [ ['Package Name', stats.name], ['Version', stats.version], @@ -77,10 +72,6 @@ export async function run(ctx: CommandContext) { [ 'Dependencies', `${totalDeps} (${stats.dependencyCount.production} production, ${stats.dependencyCount.development} development)` - ], - [ - 'ES Modules', - `${esmPercentage}% (${stats.dependencyCount.esm} ESM, ${stats.dependencyCount.cjs} CJS)` ] ]; diff --git a/src/test/__snapshots__/cli.test.ts.snap b/src/test/__snapshots__/cli.test.ts.snap index dae0f6a..d58c3e3 100644 --- a/src/test/__snapshots__/cli.test.ts.snap +++ b/src/test/__snapshots__/cli.test.ts.snap @@ -1,45 +1,49 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`CLI > should display package report 1`] = ` -"e18e (cli ) - -┌ Analyzing... -│ -● Summary -│ Package Name mock-package -│ Version 1.0.0 -│ Install Size 53.0 B -│ Dependencies 1 (1 production, 0 development) -│ ES Modules 100% (1 ESM, 0 CJS) -│ Duplicate Dependency Count 0 -│ -● Results: -│ -│ -└ Done! +"e18e (cli ) + +┌ Analyzing... +│ +● Summary +│ Package Name mock-package +│ Version 1.0.0 +│ Install Size 53.0 B +│ Dependencies 1 (1 production, 0 development) +│ Duplicate Dependency Count 0 +│ +● Results: +│ +│ +└ Done! " `; -exports[`CLI > should display package report 2`] = `""`; +exports[`CLI > should display package report 2`] = `"(node:) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use \`node --trace-warnings ...\` to show where the warning was created) +"`; exports[`CLI > should run successfully with default options 1`] = ` -"e18e (cli ) - -┌ Analyzing... -│ -● Summary -│ Package Name mock-package -│ Version 1.0.0 -│ Install Size 53.0 B -│ Dependencies 1 (1 production, 0 development) -│ ES Modules 100% (1 ESM, 0 CJS) -│ Duplicate Dependency Count 0 -│ -● Results: -│ -│ -└ Done! +"e18e (cli ) + +┌ Analyzing... +│ +● Summary +│ Package Name mock-package +│ Version 1.0.0 +│ Install Size 53.0 B +│ Dependencies 1 (1 production, 0 development) +│ Duplicate Dependency Count 0 +│ +● Results: +│ +│ +└ Done! " `; + +exports[`CLI > should run successfully with default options 2`] = `"(node:) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. +(Use \`node --trace-warnings ...\` to show where the warning was created) +"`; diff --git a/src/test/__snapshots__/duplicate-dependencies.test.ts.snap b/src/test/__snapshots__/duplicate-dependencies.test.ts.snap index 0298ac2..c838663 100644 --- a/src/test/__snapshots__/duplicate-dependencies.test.ts.snap +++ b/src/test/__snapshots__/duplicate-dependencies.test.ts.snap @@ -4,12 +4,12 @@ exports[`Duplicate Dependency Detection > should detect multiple versions 1`] = { "messages": [ { - "message": "[duplicate dependency] shared-lib has 2 installed versions: -1.0.0 via the following 2 package(s) package-a@1.0.0, package-c@1.0.0 -2.0.0 via the following 1 package(s) package-b@1.0.0 -💡 Suggestions -- Consider standardizing on version 1.0.0 as this version is the most commonly used. -- Consider upgrading consuming packages as this may resolve this duplicate version. + "message": "[duplicate dependency] shared-lib has 2 installed versions: +1.0.0 via the following 2 package(s) package-a@1.0.0, package-c@1.0.0 +2.0.0 via the following 1 package(s) package-b@1.0.0 +💡 Suggestions +- Consider standardizing on version 1.0.0 as this version is the most commonly used. +- Consider upgrading consuming packages as this may resolve this duplicate version. ", "score": 0, "severity": "warning", diff --git a/src/test/analyze/__snapshots__/dependencies.test.ts.snap b/src/test/analyze/__snapshots__/dependencies.test.ts.snap index 55f7fde..8c0742d 100644 --- a/src/test/analyze/__snapshots__/dependencies.test.ts.snap +++ b/src/test/analyze/__snapshots__/dependencies.test.ts.snap @@ -5,9 +5,7 @@ exports[`analyzeDependencies (local) > should analyze dependencies correctly 1`] "messages": [], "stats": { "dependencyCount": { - "cjs": 1, "development": 1, - "esm": 1, "production": 2, }, "installSize": 956, @@ -22,9 +20,7 @@ exports[`analyzeDependencies (local) > should handle empty project 1`] = ` "messages": [], "stats": { "dependencyCount": { - "cjs": 0, "development": 0, - "esm": 0, "production": 0, }, "installSize": 0, @@ -39,9 +35,7 @@ exports[`analyzeDependencies (local) > should handle missing node_modules 1`] = "messages": [], "stats": { "dependencyCount": { - "cjs": 0, "development": 0, - "esm": 0, "production": 1, }, "installSize": 0, @@ -56,9 +50,7 @@ exports[`analyzeDependencies (local) > should handle symlinks 1`] = ` "messages": [], "stats": { "dependencyCount": { - "cjs": 0, "development": 0, - "esm": 1, "production": 1, }, "installSize": 297, diff --git a/src/test/analyze/dependencies.test.ts b/src/test/analyze/dependencies.test.ts index 267156d..2eff450 100644 --- a/src/test/analyze/dependencies.test.ts +++ b/src/test/analyze/dependencies.test.ts @@ -28,8 +28,6 @@ describe('analyzeDependencies (local)', () => { name: 'unknown', version: 'unknown', dependencyCount: { - cjs: 0, - esm: 0, production: 0, development: 0 }, diff --git a/src/test/cli.test.ts b/src/test/cli.test.ts index 2261c5a..10faafa 100644 --- a/src/test/cli.test.ts +++ b/src/test/cli.test.ts @@ -11,6 +11,9 @@ const stripVersion = (str: string): string => '(cli )' ); +const normalizeStderr = (str: string): string => + str.replace(/\(node:\d+\)/g, '(node:)'); + beforeAll(async () => { // Create a temporary directory for the test package tempDir = await createTempDir(); @@ -80,13 +83,13 @@ describe('CLI', () => { } expect(code).toBe(0); expect(stripVersion(stdout)).toMatchSnapshot(); - expect(stderr).toBe(''); + expect(normalizeStderr(stderr)).toMatchSnapshot(); }); it('should display package report', async () => { const {stdout, stderr, code} = await runCliProcess(['analyze'], tempDir); expect(code).toBe(0); expect(stripVersion(stdout)).toMatchSnapshot(); - expect(stderr).toMatchSnapshot(); + expect(normalizeStderr(stderr)).toMatchSnapshot(); }); }); diff --git a/src/test/custom-manifests.test.ts b/src/test/custom-manifests.test.ts index 588404f..a233ce5 100644 --- a/src/test/custom-manifests.test.ts +++ b/src/test/custom-manifests.test.ts @@ -23,8 +23,6 @@ describe('Custom Manifests', () => { name: 'unknown', version: 'unknown', dependencyCount: { - cjs: 0, - esm: 0, production: 0, development: 0 }, diff --git a/src/test/duplicate-dependencies.test.ts b/src/test/duplicate-dependencies.test.ts index ce0404e..37c6a7d 100644 --- a/src/test/duplicate-dependencies.test.ts +++ b/src/test/duplicate-dependencies.test.ts @@ -78,9 +78,7 @@ describe('Duplicate Dependency Detection', () => { version: 'unknown', dependencyCount: { production: 0, - development: 0, - esm: 0, - cjs: 0 + development: 0 }, extraStats: [] }, @@ -158,9 +156,7 @@ describe('Duplicate Dependency Detection', () => { version: 'unknown', dependencyCount: { production: 0, - development: 0, - esm: 0, - cjs: 0 + development: 0 }, extraStats: [] }, diff --git a/src/test/plugin-runner.test.ts b/src/test/plugin-runner.test.ts index 02ef9b5..7c68c39 100644 --- a/src/test/plugin-runner.test.ts +++ b/src/test/plugin-runner.test.ts @@ -11,7 +11,7 @@ const fsMock: FileSystem = { fileExists: async () => false }; -const depCounts = {production: 0, development: 0, cjs: 0, esm: 0, duplicate: 0}; +const depCounts = {production: 0, development: 0}; describe('runPlugins', () => { it('should aggregate messages and merge stats with extraStats de-dup', async () => { diff --git a/src/types.ts b/src/types.ts index 4cb3ff9..3c1e88d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,8 +22,6 @@ export interface Stats { dependencyCount: { production: number; development: number; - cjs: number; - esm: number; }; extraStats?: Stat[]; } From 824265df95ade08fe1a07bb1a7f0b9808aabd3fa Mon Sep 17 00:00:00 2001 From: Paul Valladares <85648028+dreyfus92@users.noreply.github.com> Date: Sun, 1 Feb 2026 18:40:12 -0600 Subject: [PATCH 2/2] update: snapshots --- src/test/__snapshots__/cli.test.ts.snap | 68 +++++++++---------- .../duplicate-dependencies.test.ts.snap | 12 ++-- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/test/__snapshots__/cli.test.ts.snap b/src/test/__snapshots__/cli.test.ts.snap index d58c3e3..bd6e3f4 100644 --- a/src/test/__snapshots__/cli.test.ts.snap +++ b/src/test/__snapshots__/cli.test.ts.snap @@ -1,49 +1,45 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`CLI > should display package report 1`] = ` -"e18e (cli ) - -┌ Analyzing... -│ -● Summary -│ Package Name mock-package -│ Version 1.0.0 -│ Install Size 53.0 B -│ Dependencies 1 (1 production, 0 development) -│ Duplicate Dependency Count 0 -│ -● Results: -│ -│ -└ Done! +"e18e (cli ) + +┌ Analyzing... +│ +● Summary +│ Package Name mock-package +│ Version 1.0.0 +│ Install Size 53.0 B +│ Dependencies 1 (1 production, 0 development) +│ Duplicate Dependency Count 0 +│ +● Results: +│ +│ +└ Done! " `; -exports[`CLI > should display package report 2`] = `"(node:) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(Use \`node --trace-warnings ...\` to show where the warning was created) -"`; +exports[`CLI > should display package report 2`] = `""`; exports[`CLI > should run successfully with default options 1`] = ` -"e18e (cli ) - -┌ Analyzing... -│ -● Summary -│ Package Name mock-package -│ Version 1.0.0 -│ Install Size 53.0 B -│ Dependencies 1 (1 production, 0 development) -│ Duplicate Dependency Count 0 -│ -● Results: -│ -│ -└ Done! +"e18e (cli ) + +┌ Analyzing... +│ +● Summary +│ Package Name mock-package +│ Version 1.0.0 +│ Install Size 53.0 B +│ Dependencies 1 (1 production, 0 development) +│ Duplicate Dependency Count 0 +│ +● Results: +│ +│ +└ Done! " `; -exports[`CLI > should run successfully with default options 2`] = `"(node:) Warning: The 'NO_COLOR' env is ignored due to the 'FORCE_COLOR' env being set. -(Use \`node --trace-warnings ...\` to show where the warning was created) -"`; +exports[`CLI > should run successfully with default options 2`] = `""`; diff --git a/src/test/__snapshots__/duplicate-dependencies.test.ts.snap b/src/test/__snapshots__/duplicate-dependencies.test.ts.snap index c838663..0298ac2 100644 --- a/src/test/__snapshots__/duplicate-dependencies.test.ts.snap +++ b/src/test/__snapshots__/duplicate-dependencies.test.ts.snap @@ -4,12 +4,12 @@ exports[`Duplicate Dependency Detection > should detect multiple versions 1`] = { "messages": [ { - "message": "[duplicate dependency] shared-lib has 2 installed versions: -1.0.0 via the following 2 package(s) package-a@1.0.0, package-c@1.0.0 -2.0.0 via the following 1 package(s) package-b@1.0.0 -💡 Suggestions -- Consider standardizing on version 1.0.0 as this version is the most commonly used. -- Consider upgrading consuming packages as this may resolve this duplicate version. + "message": "[duplicate dependency] shared-lib has 2 installed versions: +1.0.0 via the following 2 package(s) package-a@1.0.0, package-c@1.0.0 +2.0.0 via the following 1 package(s) package-b@1.0.0 +💡 Suggestions +- Consider standardizing on version 1.0.0 as this version is the most commonly used. +- Consider upgrading consuming packages as this may resolve this duplicate version. ", "score": 0, "severity": "warning",