Skip to content

Commit da8ee4e

Browse files
committed
Use package entry point terminology
1 parent 4a3e748 commit da8ee4e

25 files changed

Lines changed: 140 additions & 134 deletions

.changeset/clean-cats-import.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'package-build-stats': minor
33
---
44

5-
Add public import-point discovery and allow package stats to target one validated import point.
5+
Add package entry-point discovery and allow package stats to target one validated entry point.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ To build a package and get stats about exports that are exposed out of the packa
3232
curl 'localhost:3000/exports?p=<package-name>'
3333
```
3434

35-
To list public package import points –
35+
To list package entry points –
3636

3737
```bash
38-
curl 'localhost:3000/import-points?p=<package-name>'
38+
curl 'localhost:3000/entry-points?p=<package-name>'
3939
```
4040

4141
To build a package and get stats about size of various exports that are exposed out of the package –

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ const results = await getPackageStats('moment')
2626
const results = await getPackageStats('moment@2.24.0')
2727
```
2828

29-
##### Discovering and building public import points
29+
##### Discovering and building package entry points
3030

3131
```js
32-
import { getPackageImportPoints, getPackageStats } from 'package-build-stats'
32+
import { getPackageEntryPoints, getPackageStats } from 'package-build-stats'
3333

34-
const importPoints = await getPackageImportPoints('react-dom@19.2.0')
34+
const entryPoints = await getPackageEntryPoints('react-dom@19.2.0')
3535
// ['react-dom', 'react-dom/client', 'react-dom/profiling', ...]
3636

3737
const results = await getPackageStats('react-dom@19.2.0', {
38-
importPoint: 'react-dom/client',
38+
entryPoint: 'react-dom/client',
3939
})
4040
```
4141

42-
`importPoint` only accepts an exact value returned by
43-
`getPackageImportPoints()` for that package version. This keeps generated build
42+
`entryPoint` only accepts an exact value returned by
43+
`getPackageEntryPoints()` for that package version. This keeps generated build
4444
entries limited to discovered package imports while respecting `exports`
4545
encapsulation when it is present.
4646

@@ -77,7 +77,7 @@ const results = await getBuiltPackageStats('moment', options)
7777
| limitConcurrency | `true` or `false` | `false` | When using `yarn` as the client, use the network mutex to limit concurrency |
7878
| networkConcurrency | `number` | `false` | When using `yarn` or `bun` as client, limit simultaneous installs to this number. |
7979
| customImports | `Array<string>` | `null` | By default, the default export is used for calculating sizes. Setting this option allows calculation of package stats based on more granular top-level exports. |
80-
| importPoint | `string` | package root | Public package import to bundle. Must exactly match a value returned by `getPackageImportPoints()`. |
80+
| entryPoint | `string` | package root | Package entry point to bundle. Must exactly match a value returned by `getPackageEntryPoints()`. |
8181
| minifier | `terser` or `esbuild` | `terser` | ESbuild is faster, albeit with marginally larger file sizes |
8282
| installTimeout | number (ms) | 30000 | Timeout for package install |
8383

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getPackageStats,
1010
getPackageExportSizes,
1111
getAllPackageExports,
12-
getPackageImportPoints,
12+
getPackageEntryPoints,
1313
} from './build/index.js'
1414

1515
const PORT = Number(process.env.PORT ?? 3000)
@@ -144,8 +144,8 @@ const application = await server({ port: PORT }, [
144144
packageRoute('/exports', (packageString, query) =>
145145
getAllPackageExports(packageString, { debug: !!query.debug }),
146146
),
147-
packageRoute('/import-points', (packageString, query) =>
148-
getPackageImportPoints(packageString, { debug: !!query.debug }),
147+
packageRoute('/entry-points', (packageString, query) =>
148+
getPackageEntryPoints(packageString, { debug: !!query.debug }),
149149
),
150150
get('/__debug/memory', async () => json(getMemorySnapshot())),
151151
get('/__debug/heapdump', async () => {

src/common.types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export type PackageManager = (typeof packageManagers)[number]
33

44
type AllOptions = {
55
customImports?: Array<string>
6-
importPoint?: string
6+
entryPoint?: string
77
splitCustomImports?: boolean
88
debug?: boolean
99
minify?: boolean
@@ -21,7 +21,7 @@ type AllOptions = {
2121
export type BuildPackageOptions = Pick<
2222
AllOptions,
2323
| 'customImports'
24-
| 'importPoint'
24+
| 'entryPoint'
2525
| 'splitCustomImports'
2626
| 'debug'
2727
| 'minify'
@@ -32,7 +32,7 @@ export type BuildPackageOptions = Pick<
3232

3333
export type CreateEntryPointOptions = Pick<
3434
AllOptions,
35-
'esm' | 'customImports' | 'importPoint' | 'entryFilename'
35+
'esm' | 'customImports' | 'entryPoint' | 'entryFilename'
3636
>
3737
export type InstallPackageOptions = Pick<
3838
AllOptions,
@@ -53,7 +53,7 @@ export type GetPackageStatsOptions = Pick<
5353
| 'networkConcurrency'
5454
| 'debug'
5555
| 'customImports'
56-
| 'importPoint'
56+
| 'entryPoint'
5757
| 'installTimeout'
5858
| 'minify'
5959
| 'signal'

src/errors/CustomError.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ export class EntryPointError extends CustomError {
4242
}
4343
}
4444

45-
export class InvalidImportPointError extends CustomError<{
46-
importPoint: string
45+
export class InvalidPackageEntryPointError extends CustomError<{
46+
entryPoint: string
4747
}> {
48-
constructor(importPoint: string) {
48+
constructor(entryPoint: string) {
4949
super(
50-
'InvalidImportPointError',
51-
`Import point ${JSON.stringify(importPoint)} is not exported by this package`,
52-
{ importPoint },
50+
'InvalidPackageEntryPointError',
51+
`Package entry point ${JSON.stringify(entryPoint)} is not importable`,
52+
{ entryPoint },
5353
)
5454
}
5555
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import path from 'node:path'
22
import type { InstallPackageOptions } from './common.types.js'
33
import InstallationUtils from './utils/installation.utils.js'
44
import { parsePackageString, throwIfAborted } from './utils/common.utils.js'
5-
import { getImportPointsFromPackage } from './utils/importPoints.utils.js'
5+
import { getEntryPointsFromPackage } from './utils/packageEntryPoints.utils.js'
66

7-
export default async function getPackageImportPoints(
7+
export default async function getPackageEntryPoints(
88
packageString: string,
99
options: InstallPackageOptions = {},
1010
) {
@@ -24,7 +24,7 @@ export default async function getPackageImportPoints(
2424
throwIfAborted(options.signal)
2525

2626
const packagePath = path.join(installPath, 'node_modules', packageName)
27-
return await getImportPointsFromPackage(
27+
return await getEntryPointsFromPackage(
2828
packageName,
2929
packagePath,
3030
options.signal,

src/getPackageStats.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {
1414
import InstallationUtils from './utils/installation.utils.js'
1515
import BuildUtils from './utils/build.utils.js'
1616
import {
17-
InvalidImportPointError,
17+
InvalidPackageEntryPointError,
1818
UnexpectedBuildError,
1919
} from './errors/CustomError.js'
2020
import type { GetPackageStatsOptions } from './common.types.js'
2121
import Telemetry from './utils/telemetry.utils.js'
22-
import { getImportPointsFromPackage } from './utils/importPoints.utils.js'
22+
import { getEntryPointsFromPackage } from './utils/packageEntryPoints.utils.js'
2323

2424
function getPackageJSONDetails(packageName: string, installPath: string) {
2525
const startTime = performance.now()
@@ -90,15 +90,15 @@ export default async function getPackageStats(
9090
timings.install = performance.now() - installStart
9191
console.log(`[PERF] installPackage: ${timings.install.toFixed(2)}ms`)
9292

93-
if (options.importPoint) {
93+
if (options.entryPoint) {
9494
const packagePath = path.join(installPath, 'node_modules', packageName)
95-
const importPoints = await getImportPointsFromPackage(
95+
const entryPoints = await getEntryPointsFromPackage(
9696
packageName,
9797
packagePath,
9898
options.signal,
9999
)
100-
if (!importPoints.includes(options.importPoint)) {
101-
throw new InvalidImportPointError(options.importPoint)
100+
if (!entryPoints.includes(options.entryPoint)) {
101+
throw new InvalidPackageEntryPointError(options.entryPoint)
102102
}
103103
}
104104

@@ -119,7 +119,7 @@ export default async function getPackageStats(
119119
debug: options.debug,
120120
minify: options.minify !== false,
121121
customImports: options.customImports,
122-
importPoint: options.importPoint,
122+
entryPoint: options.entryPoint,
123123
includeDependencySizes: true,
124124
signal: options.signal,
125125
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { default as getPackageStats } from './getPackageStats.js'
2-
export { default as getPackageImportPoints } from './getPackageImportPoints.js'
2+
export { default as getPackageEntryPoints } from './getPackageEntryPoints.js'
33
export * from './errors/CustomError.js'
44
export * from './getPackageExportSizes.js'
55
export { emitter as eventQueue } from './utils/telemetry.utils.js'

src/utils/build.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const BuildUtils = {
122122
)
123123

124124
let importStatement: string
125-
const moduleSpecifier = JSON.stringify(options.importPoint ?? packageName)
125+
const moduleSpecifier = JSON.stringify(options.entryPoint ?? packageName)
126126

127127
if (options.esm) {
128128
if (options.customImports) {
@@ -274,7 +274,7 @@ const BuildUtils = {
274274
entry['main'] = BuildUtils.createEntryPoint(packageName, installPath, {
275275
esm: true,
276276
customImports: options.customImports,
277-
importPoint: options.importPoint,
277+
entryPoint: options.entryPoint,
278278
})
279279
}
280280

0 commit comments

Comments
 (0)