Skip to content

Commit af39e97

Browse files
committed
fix: preserve existing package analysis APIs
1 parent 2116651 commit af39e97

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

.changeset/calm-dragons-share.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
'package-build-stats': major
2+
'package-build-stats': minor
33
---
44

5-
Add reusable installed-package handles so multiple analyses can share one workspace, and rename `getAllPackageExports` to `getPackageExports`.
5+
Add reusable installed-package handles so multiple analyses can share one workspace, and add `getPackageExports` as the canonical name while preserving `getAllPackageExports` as a deprecated alias.

src/getPackageExportSizes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export async function getPackageExports(
6666
return getExportsForInstalledPackage(packageInput, options, startTime)
6767
}
6868

69+
/**
70+
* @deprecated Use `getPackageExports`; this alias preserves the existing API.
71+
*/
72+
export const getAllPackageExports = getPackageExports
73+
6974
async function analyzePackageExportSizes(
7075
installation: InstalledPackage,
7176
options: GetPackageStatsOptions = {},

src/getPackageStats.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,14 @@ export default async function getPackageStats(
143143
) {
144144
const startTime = performance.now()
145145
if (typeof packageInput === 'string') {
146-
return withInstalledPackage(packageInput, options, installedPackage =>
147-
getStatsForInstalledPackage(installedPackage, options, startTime),
146+
return withInstalledPackage(
147+
packageInput,
148+
options,
149+
installedPackage =>
150+
getStatsForInstalledPackage(installedPackage, options, startTime),
151+
// Preserve the existing debug contract: retain the workspace so callers
152+
// can inspect emitted source maps and intermediate build artifacts.
153+
!options.debug,
148154
)
149155
}
150156

src/installedPackage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ export async function withInstalledPackage<TResult>(
6464
packageString: string,
6565
options: InstallPackageOptions,
6666
analyze: (installedPackage: InstalledPackage) => Promise<TResult>,
67+
disposeAfterAnalysis = true,
6768
) {
6869
const installedPackage = await installPackage(packageString, options)
6970

7071
try {
7172
return await analyze(installedPackage)
7273
} finally {
73-
await disposePackage(installedPackage)
74+
if (disposeAfterAnalysis) {
75+
await disposePackage(installedPackage)
76+
}
7477
}
7578
}

tests/slow/export-sizes.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import path from 'path'
99
import {
10+
getAllPackageExports,
1011
getPackageExports,
1112
getPackageExportSizes,
1213
} from '../../src/getPackageExportSizes'
@@ -31,6 +32,10 @@ vi.mock('../../src/utils/common.utils.js', async importOriginal => {
3132
})
3233

3334
describe('getPackageExports', () => {
35+
test('keeps the previous getAllPackageExports API as an alias', () => {
36+
expect(getAllPackageExports).toBe(getPackageExports)
37+
})
38+
3439
test('should get exports from package with multiple exports', async () => {
3540
const fixturePath = path.resolve(
3641
__dirname,

0 commit comments

Comments
 (0)