Skip to content

Commit 16d67b0

Browse files
authored
refactor: remove ESM/CJS stats (#157)
* refactor: remove CJS/ESM dependency tracking and related statistics * update: snapshots
1 parent b609dea commit 16d67b0

File tree

11 files changed

+15
-62
lines changed

11 files changed

+15
-62
lines changed

src/analyze/dependencies.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {analyzePackageModuleType} from '../compute-type.js';
21
import type {
32
ReportPluginResult,
43
Message,
@@ -24,29 +23,11 @@ export async function runDependencyAnalysis(
2423
const prodDependencies = Object.keys(pkg.dependencies || {}).length;
2524
const devDependencies = Object.keys(pkg.devDependencies || {}).length;
2625

27-
let cjsDependencies = 0;
28-
let esmDependencies = 0;
29-
3026
// Recursively traverse dependencies
31-
async function traverse(
32-
packagePath: string,
33-
depth: number,
34-
pathInTree: string
35-
) {
27+
async function traverse(packagePath: string, pathInTree: string) {
3628
const depPkg = await getPackageJson(context.fs, packagePath);
3729
if (!depPkg || !depPkg.name) return;
3830

39-
// Only count CJS/ESM for non-root packages
40-
if (depth > 0) {
41-
const type = analyzePackageModuleType(depPkg);
42-
if (type === 'cjs') cjsDependencies++;
43-
if (type === 'esm') esmDependencies++;
44-
if (type === 'dual') {
45-
cjsDependencies++;
46-
esmDependencies++;
47-
}
48-
}
49-
5031
for (const depName of Object.keys(depPkg.dependencies || {})) {
5132
let packageMatch = packageFiles.find((packageFile) =>
5233
normalizePath(packageFile).endsWith(
@@ -65,23 +46,21 @@ export async function runDependencyAnalysis(
6546
}
6647

6748
if (packageMatch) {
68-
await traverse(packageMatch, depth + 1, pathInTree + ' > ' + depName);
49+
await traverse(packageMatch, pathInTree + ' > ' + depName);
6950
}
7051
}
7152
}
7253

7354
// Start traversal from root
74-
await traverse('/package.json', 0, 'root');
55+
await traverse('/package.json', 'root');
7556

7657
const stats: Partial<Stats> = {
7758
name: pkg.name,
7859
version: pkg.version,
7960
installSize,
8061
dependencyCount: {
8162
production: prodDependencies,
82-
development: devDependencies,
83-
esm: esmDependencies,
84-
cjs: cjsDependencies
63+
development: devDependencies
8564
}
8665
};
8766

src/analyze/report.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ export async function report(options: Options) {
8181
version: packageFile.version || '0.0.0',
8282
dependencyCount: {
8383
production: 0,
84-
development: 0,
85-
cjs: 0,
86-
esm: 0
84+
development: 0
8785
},
8886
extraStats: []
8987
};

src/commands/analyze.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ export async function run(ctx: CommandContext<typeof meta>) {
6060

6161
const totalDeps =
6262
stats.dependencyCount.production + stats.dependencyCount.development;
63-
const totalDeepDeps = stats.dependencyCount.cjs + stats.dependencyCount.esm;
64-
const esmPercentage =
65-
totalDeepDeps > 0
66-
? Math.floor((stats.dependencyCount.esm / totalDeepDeps) * 100)
67-
: 0;
6863
const summaryPairs: Array<[string, string]> = [
6964
['Package Name', stats.name],
7065
['Version', stats.version],
@@ -77,10 +72,6 @@ export async function run(ctx: CommandContext<typeof meta>) {
7772
[
7873
'Dependencies',
7974
`${totalDeps} (${stats.dependencyCount.production} production, ${stats.dependencyCount.development} development)`
80-
],
81-
[
82-
'ES Modules',
83-
`${esmPercentage}% (${stats.dependencyCount.esm} ESM, ${stats.dependencyCount.cjs} CJS)`
8475
]
8576
];
8677

src/test/__snapshots__/cli.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exports[`CLI > should display package report 1`] = `
1010
│ Version 1.0.0
1111
│ Install Size 53.0 B
1212
│ Dependencies 1 (1 production, 0 development)
13-
│ ES Modules 100% (1 ESM, 0 CJS)
1413
│ Duplicate Dependency Count 0
1514
│
1615
● Results:
@@ -33,7 +32,6 @@ exports[`CLI > should run successfully with default options 1`] = `
3332
│ Version 1.0.0
3433
│ Install Size 53.0 B
3534
│ Dependencies 1 (1 production, 0 development)
36-
│ ES Modules 100% (1 ESM, 0 CJS)
3735
│ Duplicate Dependency Count 0
3836
│
3937
● Results:
@@ -43,3 +41,5 @@ exports[`CLI > should run successfully with default options 1`] = `
4341
4442
"
4543
`;
44+
45+
exports[`CLI > should run successfully with default options 2`] = `""`;

src/test/analyze/__snapshots__/dependencies.test.ts.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ exports[`analyzeDependencies (local) > should analyze dependencies correctly 1`]
55
"messages": [],
66
"stats": {
77
"dependencyCount": {
8-
"cjs": 1,
98
"development": 1,
10-
"esm": 1,
119
"production": 2,
1210
},
1311
"installSize": 956,
@@ -22,9 +20,7 @@ exports[`analyzeDependencies (local) > should handle empty project 1`] = `
2220
"messages": [],
2321
"stats": {
2422
"dependencyCount": {
25-
"cjs": 0,
2623
"development": 0,
27-
"esm": 0,
2824
"production": 0,
2925
},
3026
"installSize": 0,
@@ -39,9 +35,7 @@ exports[`analyzeDependencies (local) > should handle missing node_modules 1`] =
3935
"messages": [],
4036
"stats": {
4137
"dependencyCount": {
42-
"cjs": 0,
4338
"development": 0,
44-
"esm": 0,
4539
"production": 1,
4640
},
4741
"installSize": 0,
@@ -56,9 +50,7 @@ exports[`analyzeDependencies (local) > should handle symlinks 1`] = `
5650
"messages": [],
5751
"stats": {
5852
"dependencyCount": {
59-
"cjs": 0,
6053
"development": 0,
61-
"esm": 1,
6254
"production": 1,
6355
},
6456
"installSize": 297,

src/test/analyze/dependencies.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ describe('analyzeDependencies (local)', () => {
2828
name: 'unknown',
2929
version: 'unknown',
3030
dependencyCount: {
31-
cjs: 0,
32-
esm: 0,
3331
production: 0,
3432
development: 0
3533
},

src/test/cli.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const stripVersion = (str: string): string =>
1111
'(cli <version>)'
1212
);
1313

14+
const normalizeStderr = (str: string): string =>
15+
str.replace(/\(node:\d+\)/g, '(node:<pid>)');
16+
1417
beforeAll(async () => {
1518
// Create a temporary directory for the test package
1619
tempDir = await createTempDir();
@@ -80,13 +83,13 @@ describe('CLI', () => {
8083
}
8184
expect(code).toBe(0);
8285
expect(stripVersion(stdout)).toMatchSnapshot();
83-
expect(stderr).toBe('');
86+
expect(normalizeStderr(stderr)).toMatchSnapshot();
8487
});
8588

8689
it('should display package report', async () => {
8790
const {stdout, stderr, code} = await runCliProcess(['analyze'], tempDir);
8891
expect(code).toBe(0);
8992
expect(stripVersion(stdout)).toMatchSnapshot();
90-
expect(stderr).toMatchSnapshot();
93+
expect(normalizeStderr(stderr)).toMatchSnapshot();
9194
});
9295
});

src/test/custom-manifests.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ describe('Custom Manifests', () => {
2323
name: 'unknown',
2424
version: 'unknown',
2525
dependencyCount: {
26-
cjs: 0,
27-
esm: 0,
2826
production: 0,
2927
development: 0
3028
},

src/test/duplicate-dependencies.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ describe('Duplicate Dependency Detection', () => {
7878
version: 'unknown',
7979
dependencyCount: {
8080
production: 0,
81-
development: 0,
82-
esm: 0,
83-
cjs: 0
81+
development: 0
8482
},
8583
extraStats: []
8684
},
@@ -158,9 +156,7 @@ describe('Duplicate Dependency Detection', () => {
158156
version: 'unknown',
159157
dependencyCount: {
160158
production: 0,
161-
development: 0,
162-
esm: 0,
163-
cjs: 0
159+
development: 0
164160
},
165161
extraStats: []
166162
},

src/test/plugin-runner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fsMock: FileSystem = {
1111
fileExists: async () => false
1212
};
1313

14-
const depCounts = {production: 0, development: 0, cjs: 0, esm: 0, duplicate: 0};
14+
const depCounts = {production: 0, development: 0};
1515

1616
describe('runPlugins', () => {
1717
it('should aggregate messages and merge stats with extraStats de-dup', async () => {

0 commit comments

Comments
 (0)