Skip to content

Commit

Permalink
Cut down on size-limit config
Browse files Browse the repository at this point in the history
- Cut down on `size-limit` config to not go through every single entry point.
  • Loading branch information
aryaemami59 committed Sep 13, 2024
1 parent d2c593a commit 0263163
Showing 1 changed file with 1 addition and 50 deletions.
51 changes: 1 addition & 50 deletions .size-limit.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,6 @@ const allNodeEnvs = ['development', 'production'] as const
*/
type NodeEnv = (typeof allNodeEnvs)[number]

/**
* Set of entry points from the `package.json` file.
*/
const packageJsonEntryPoints = new Set<string>()

/**
* Recursively collects entry points from the `package.json` exports field.
*
* @param packageJsonExports - The exports field from `package.json`.
* @returns A set of package entry points.
*/
const collectPackageJsonExports = (
packageJsonExports:
| string
| Record<string, any>
| null
| typeof import('./package.json').exports,
) => {
if (
typeof packageJsonExports === 'string' &&
packageJsonExports.endsWith('js')
) {
packageJsonEntryPoints.add(
packageJsonExports.startsWith('./')
? packageJsonExports
: `./${packageJsonExports}`,
)
} else if (packageJsonExports && typeof packageJsonExports === 'object') {
Object.values(packageJsonExports).forEach(collectPackageJsonExports)
}

return packageJsonEntryPoints
}

/**
* Gets all package entry points from the `package.json` file.
*
* @returns A promise that resolves to an array of unique package entry points.
*/
const getAllPackageEntryPoints = async () => {
const packageJson = (
await import('./package.json', { with: { type: 'json' } })
).default

const packageExports = collectPackageJsonExports(packageJson.exports)

return [...packageExports]
}

/**
* Gets all import configurations for a given entry point.
* This function dynamically imports the specified entry point and
Expand Down Expand Up @@ -121,7 +72,7 @@ const setNodeEnv = (nodeEnv: NodeEnv) => {
* @returns A promise that resolves to a size limit configuration object.
*/
const getAllImportsWithNodeEnv = async (nodeEnv: NodeEnv) => {
const allPackageEntryPoints = await getAllPackageEntryPoints()
const allPackageEntryPoints = ['./dist/react-redux.mjs']

const allImportsFromAllEntryPoints = (
await Promise.all(allPackageEntryPoints.map(getAllImportsForEntryPoint))
Expand Down

0 comments on commit 0263163

Please sign in to comment.