Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[httpx/exception] drop node 16 - reduce drastically bundle size #667

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-hairs-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@httpx/exception': minor
---

Minimum node version is 18.12. Move to es2022.
63 changes: 63 additions & 0 deletions .changeset/young-yaks-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
'@httpx/exception': minor
---

Reduce drastically bundle size (use es2022)

Importing a single exception starts at 377 bytes, subsequent ones will add less than 50 bytes in average.
Importing all exceptions (excluding typeguards...) will top at 1400 bytes.

Code should be faster too.

> PS: if you use exceptions outside of nodejs and need to support legacy browsers
> a lot of frameworks allows to transpile modules (ie nextjs).

```
✔ Adding to empty webpack project

ESM (import everything *)
Package size is 395 B less than limit
Size limit: 2.46 kB
Size: 2.06 kB with all dependencies, minified and gzipped

ESM (only HttpNotFound exception)
Package size is 965 B less than limit
Size limit: 1.42 kB
Size: 450 B with all dependencies, minified and gzipped

ESM (two exceptions: HttpNotFound + HttpInternalServerError)
Package size is 935 B less than limit
Size limit: 1.44 kB
Size: 505 B with all dependencies, minified and gzipped

ESM (only isHttpException)
Package size is 1.03 kB less than limit
Size limit: 1.41 kB
Size: 377 B with all dependencies, minified and gzipped

ESM (only createHttpException)
Package size is 571 B less than limit
Size limit: 2 kB
Size: 1.43 kB with all dependencies, minified and gzipped

ESM ({ toJson })
Package size is 1.11 kB less than limit
Size limit: 1.89 kB
Size: 779 B with all dependencies, minified and gzipped

ESM ({ fromJson })
Package size is 607 B less than limit
Size limit: 2.5 kB
Size: 1.89 kB with all dependencies, minified and gzipped

CJS (require everything *)
Package size is 416 B less than limit
Size limit: 3.05 kB
Size: 2.63 kB with all dependencies, minified and gzipped

CJS (only isHttpException)
Package size is 598 B less than limit
Size limit: 2.5 kB
Size: 1.9 kB with all dependencies, minified and gzipped

```
16 changes: 8 additions & 8 deletions packages/exception/.size-limit.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check

const fullEsmMaxSize = "2455B";
const fullCjsMaxSize = "3050B";
const fullEsmMaxSize = "2070B";
const fullCjsMaxSize = "2700B";

/**
* Will ensure esm tree-shakeability and total size are within expectations.
Expand All @@ -23,38 +23,38 @@ module.exports = [
name: "ESM (only HttpNotFound exception)",
path: ["dist/index.mjs"],
import: "{ HttpNotFound }",
limit: "1415B",
limit: "460B",
},
{
name: "ESM (two exceptions: HttpNotFound + HttpInternalServerError)",
path: ["dist/index.mjs"],
import: "{ HttpNotFound, HttpInternalServerError }",
limit: "1440B",
limit: "510B",
},
{
name: "ESM (only isHttpException)",
path: ["dist/index.mjs"],
import: "{ isHttpException }",
limit: "1410B",
limit: "400B",
},
{
name: "ESM (only createHttpException)",
path: ["dist/index.mjs"],
import: "{ createHttpException }",
limit: "2000B", // Will import all server/client exceptions
limit: "1500B", // Will import all server/client exceptions
},

{
name: "ESM ({ toJson })",
path: ["dist/serializer/index.mjs"],
import: "{ toJson }",
limit: "1890B",
limit: "800B",
},
{
name: "ESM ({ fromJson })",
path: ["dist/serializer/index.mjs"],
import: "{ fromJson }",
limit: "2500B",
limit: "2000B",
},
// ###################################################
// Commonjs full bundle
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ purposes.
[![size](https://img.shields.io/bundlephobia/minzip/@httpx/exception@latest?label=Max&style=for-the-badge&labelColor=333&color=informational)](https://bundlephobia.com/package/@httpx/exception@latest)
[![bundles](https://img.shields.io/static/v1?label=&message=cjs|esm|treeshake&logo=webpack&style=for-the-badge&labelColor=444&color=informational)](https://github.com/belgattitude/httpx/blob/main/packages/exception/.size-limit.cjs)
[![browserslist](https://img.shields.io/static/v1?label=Browser&message=>99%&logo=googlechrome&style=for-the-badge&labelColor=444&color=informational)](https://browserslist.dev/?q=PiAwLjAxJSwgbm90IGRlYWQ%3D)
![node](https://img.shields.io/static/v1?label=Node&message=16%2b&logo=node.js&style=for-the-badge&labelColor=444&color=informational)]
![node](https://img.shields.io/static/v1?label=Node&message=18%2b&logo=node.js&style=for-the-badge&labelColor=444&color=informational)
[![techdebt](https://img.shields.io/codeclimate/tech-debt/belgattitude/httpx?label=TechDebt&logo=code-climate&style=for-the-badge&labelColor=444)](https://codeclimate.com/github/belgattitude/httpx)
[![maintainability](https://img.shields.io/codeclimate/maintainability/belgattitude/httpx?label=Maintainability&logo=code-climate&style=for-the-badge&labelColor=444)](https://codeclimate.com/github/belgattitude/httpx)
[![npm](https://img.shields.io/npm/dt/@httpx/exception?style=for-the-badge)](https://www.npmjs.com/package/@httpx/exception)
Expand Down
6 changes: 3 additions & 3 deletions packages/exception/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
"lint-timing": "cross-env TIMING=1 run lint",
"typecheck": "tsc --project ./tsconfig.json --noEmit",
"check-dist": "run-s check-dist-esm check-dist-cjs",
"check-dist-cjs": "es-check --not './dist/cjs/*.map.js' -v es2018 './dist/**/*.cjs'",
"check-dist-esm": "es-check --not './dist/esm/*.map.js' -v es2018 --module './dist/**/*.mjs'",
"check-dist-cjs": "es-check --not './dist/cjs/*.map.js' -v es2022 './dist/**/*.cjs'",
"check-dist-esm": "es-check --not './dist/esm/*.map.js' -v es2022 --module './dist/**/*.mjs'",
"check-size": "size-limit",
"check-pub": "run-p check-pub-publint check-pub-attw",
"check-pub-publint": "publint --strict",
Expand Down Expand Up @@ -140,6 +140,6 @@
"webpack": "5.89.0"
},
"engines": {
"node": ">=16.12"
"node": ">=18"
}
}
8 changes: 4 additions & 4 deletions packages/exception/tsup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export default defineConfig((options) => {
clean: true,
dts: true,
format: ['esm', 'cjs'],
minifySyntax: false,
minifyWhitespace: false,
minifyIdentifiers: false,
minifySyntax: true,
minifyWhitespace: true,
minifyIdentifiers: true,
cjsInterop: true,
outExtension({ format }) {
return {
js: `.${format === 'cjs' ? 'cjs' : 'mjs'}`,
};
},
platform: 'browser',
target: ['es2018', ...browserslistToEsbuild()],
target: ['es2022', ...browserslistToEsbuild()],
tsconfig: './tsconfig.build.json',
sourcemap: !options.watch,
minify: !options.watch,
Expand Down