Skip to content

Commit ac58f57

Browse files
committed
feat: reuse installed packages across analyses
1 parent 3c65912 commit ac58f57

9 files changed

Lines changed: 402 additions & 255 deletions

.changeset/calm-dragons-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'package-build-stats': major
3+
---
4+
5+
Add reusable installed-package handles so multiple analyses can share one workspace, and rename `getAllPackageExports` to `getPackageExports`.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ const results = await getPackageStats('lodash', { client: 'pnpm' })
4545
const results = await getPackageStats('lodash', { client: 'yarn' })
4646
```
4747

48+
#### Reusing an installation
49+
50+
The analysis functions install and clean up packages automatically. Services
51+
that run several analyses for the same package can reuse one installation:
52+
53+
```js
54+
import {
55+
disposePackage,
56+
getPackageExportSizes,
57+
getPackageExports,
58+
getPackageStats,
59+
installPackage,
60+
} from 'package-build-stats'
61+
62+
const installedPackage = await installPackage('lodash@4.17.21')
63+
64+
try {
65+
const stats = await getPackageStats(installedPackage)
66+
const exports = await getPackageExports(installedPackage)
67+
const exportSizes = await getPackageExportSizes(installedPackage)
68+
} finally {
69+
await disposePackage(installedPackage)
70+
}
71+
```
72+
73+
Run analyses sharing an installation sequentially because they share a build
74+
workspace.
75+
4876
#### Passing options to the build
4977

5078
```js

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { json, status } = server.reply
88
import {
99
getPackageStats,
1010
getPackageExportSizes,
11-
getAllPackageExports,
11+
getPackageExports,
1212
} from './build/index.js'
1313

1414
const PORT = Number(process.env.PORT ?? 3000)
@@ -141,7 +141,7 @@ const application = await server({ port: PORT }, [
141141
}),
142142
),
143143
packageRoute('/exports', (packageString, query) =>
144-
getAllPackageExports(packageString, { debug: !!query.debug }),
144+
getPackageExports(packageString, { debug: !!query.debug }),
145145
),
146146
get('/__debug/memory', async () => json(getMemorySnapshot())),
147147
get('/__debug/heapdump', async () => {

0 commit comments

Comments
 (0)