Skip to content

Commit 9e71e18

Browse files
authored
docs: add pkg metadata comparison (#28)
* docs: add pkg metadata comparison * test: update size-limit
1 parent f1bc601 commit 9e71e18

11 files changed

Lines changed: 186 additions & 43 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ buildstamp.json
1414
package-main.json
1515

1616
# Temp
17+
tmp
1718
temp
1819
test-results
1920

.size-limit.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"LICENSE",
1010
"package-main.json"
1111
],
12-
"limit": "60.31 kB",
12+
"limit": "60.40 kB",
1313
"brotli": false,
1414
"gzip": false
1515
},
@@ -32,7 +32,7 @@
3232
"LICENSE",
3333
"package-main.json"
3434
],
35-
"limit": "18.30 kB",
35+
"limit": "18.32 kB",
3636
"gzip": true
3737
},
3838
{

COHERENCE.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# Coherence across libraries
2-
> Autogenerated by `src/scripts/build-coherence-md.ts`
2+
> Autogenerated by [`src/scripts/build-coherence-md.ts`](./src/scripts/build-coherence-md.ts)
33
## IPv4
4-
Address | node:net | [`ip`](https://github.com/indutny/node-ip) | [`@webpod/ip`](https://github.com/webpod/ip) | [`@webpod/ip/core`](https://github.com/webpod/ip) | [`is-ip`](https://github.com/sindresorhus/is-ip) | [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | [`ip-address`](https://github.com/beaugunderson/ip-address) | [`ip2buf`](https://github.com/reklatsmasters/ip2buf) | [`neoip`](https://github.com/Zaptic/neoip) | Comment
4+
Address | node:net | [`@webpod/ip`](https://github.com/webpod/ip) | [`@webpod/ip/core`](https://github.com/webpod/ip) | [`ip`](https://github.com/indutny/node-ip) | [`is-ip`](https://github.com/sindresorhus/is-ip) | [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | [`ip-address`](https://github.com/beaugunderson/ip-address) | [`ip2buf`](https://github.com/reklatsmasters/ip2buf) | [`neoip`](https://github.com/Zaptic/neoip) | Comment
55
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
66
`127.0.0.1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | localhost
77
`192.168.1.1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | private LAN
88
`255.255.255.255` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | broadcast
99
`0.0.0.0` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | unspecified
1010
`8.8.8.8` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | Google DNS
11-
`256.1.1.1` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | octet out of range
11+
`256.1.1.1` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | octet out of range
1212
`192.168.1` | ✓ | ✓ | ✓ | ✓ | ✓ | ❌ | ✓ | ✓ | ✓ | not enough octets
1313
`192.168.1.1.1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | too many octets
14-
`192.168.01.1` | ✓ | | ✓ | | ✓ | ❌ | ❌ | ❌ | ✓ | leading octet zero
14+
`192.168.01.1` | ✓ | | ✓ | | ✓ | ❌ | ❌ | ❌ | ✓ | leading octet zero
1515
`abc.def.gha.bcd` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | non-numeric
1616
`...` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | empty octets
1717
`1..2.3` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | empty middle octet
1818
`` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | empty string
1919
## IPv6
20-
Address | node:net | [`ip`](https://github.com/indutny/node-ip) | [`@webpod/ip`](https://github.com/webpod/ip) | [`@webpod/ip/core`](https://github.com/webpod/ip) | [`is-ip`](https://github.com/sindresorhus/is-ip) | [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | [`ip-address`](https://github.com/beaugunderson/ip-address) | [`ip2buf`](https://github.com/reklatsmasters/ip2buf) | [`neoip`](https://github.com/Zaptic/neoip) | Comment
20+
Address | node:net | [`@webpod/ip`](https://github.com/webpod/ip) | [`@webpod/ip/core`](https://github.com/webpod/ip) | [`ip`](https://github.com/indutny/node-ip) | [`is-ip`](https://github.com/sindresorhus/is-ip) | [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | [`ip-address`](https://github.com/beaugunderson/ip-address) | [`ip2buf`](https://github.com/reklatsmasters/ip2buf) | [`neoip`](https://github.com/Zaptic/neoip) | Comment
2121
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
2222
`::1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | loopback
2323
`::` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | unspecified
@@ -26,26 +26,26 @@ Address | node:net | [`ip`](https://github.com/indutny/node-ip) | [`@webpod/ip`]
2626
`::ffff:192.0.2.128` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | IPv4-mapped IPv6
2727
`2001:0db8:85a3:0000:0000:8a2e:0370:7334` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | full form
2828
`0:0:0:0:0:0:0:1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | expanded loopback
29-
`2001::85a3::7334` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | multiple ::
30-
`12345::` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | hextet too long
29+
`2001::85a3::7334` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | multiple ::
30+
`12345::` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | hextet too long
3131
`abcd:efgh::1` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | non-hex character
32-
`1:2:3:4:5:6:7` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ❌ | ✓ | too few hextets
32+
`1:2:3:4:5:6:7` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ❌ | ✓ | too few hextets
3333
`1:2:3:4:5:6:7:8:9` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | too many hextets
34-
`:1:2:3:4:5:6:7` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | leading colon without ::
35-
`1:2:3:4:5:6:7:` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | trailing colon without ::
36-
`1:2:3::4:5:6:7:8` | ✓ | | ✓ | | ✓ | ❌ | ✓ | ✓ | ✓ | too many hextets with ::
37-
`1:2::4:5::8` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | multiple compressors ::
38-
`:::` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | triple colon not allowed
34+
`:1:2:3:4:5:6:7` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | leading colon without ::
35+
`1:2:3:4:5:6:7:` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | trailing colon without ::
36+
`1:2:3::4:5:6:7:8` | ✓ | | ✓ | | ✓ | ❌ | ✓ | ✓ | ✓ | too many hextets with ::
37+
`1:2::4:5::8` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | multiple compressors ::
38+
`:::` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | triple colon not allowed
3939
`::g` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | invalid hex digit after compression
4040
`2001:db8:85a3:0:0:8a2e:37023:7334` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | hextet exceeds 16 bits
41-
`::ffff:999.0.2.128` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | invalid embedded IPv4
41+
`::ffff:999.0.2.128` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | invalid embedded IPv4
4242
`::ffff:192.0.2` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | truncated IPv4 in mapped address
43-
`2001:db8:::` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | extra colon at end
44-
`` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | empty string
43+
`2001:db8:::` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | extra colon at end
44+
`` | ✓ | | ✓ | | ✓ | ✓ | ✓ | ✓ | ✓ | empty string
4545
## Private IP
46-
Address | [`ip`](https://github.com/indutny/node-ip) | [`@webpod/ip`](https://github.com/webpod/ip) | [`@webpod/ip/core`](https://github.com/webpod/ip) | [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | [`neoip`](https://github.com/Zaptic/neoip) | Comment
46+
Address | [`@webpod/ip`](https://github.com/webpod/ip) | [`@webpod/ip/core`](https://github.com/webpod/ip) | [`ip`](https://github.com/indutny/node-ip) | [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | [`neoip`](https://github.com/Zaptic/neoip) | Comment
4747
--- | --- | --- | --- | --- | --- | ---
48-
`0.0.0.0` | | ✓ | | ✓ | ✓ | unspecified
48+
`0.0.0.0` | | ✓ | | ✓ | ✓ | unspecified
4949
`127.0.0.1` | ✓ | ✓ | ✓ | ✓ | ✓ | loopback
5050
`127.0.0.2` | ✓ | ✓ | ✓ | ✓ | ✓ | loopback range
5151
`127.1.1.1` | ✓ | ✓ | ✓ | ✓ | ✓ | loopback shorthand
@@ -64,7 +64,7 @@ Address | [`ip`](https://github.com/indutny/node-ip) | [`@webpod/ip`](https://gi
6464
`10.0.2.3` | ✓ | ✓ | ✓ | ✓ | ✓ | private 10/8
6565
`10.1.23.45` | ✓ | ✓ | ✓ | ✓ | ✓ | private 10/8
6666
`12.1.2.3` | ✓ | ✓ | ✓ | ✓ | ✓ | public, outside 10/8
67-
`198.18.0.0` | | ✓ | | ❌ | ✓ | benchmark range
67+
`198.18.0.0` | | ✓ | | ❌ | ✓ | benchmark range
6868
`fd12:3456:789a:1::1` | ✓ | ✓ | ✓ | ✓ | ✓ | ULA fc00::/7
6969
`fe80::f2de:f1ff:fe3f:307e` | ✓ | ✓ | ✓ | ✓ | ✓ | link-local fe80::/10
7070
`::ffff:10.100.1.42` | ✓ | ✓ | ✓ | ❌ | ✓ | IPv4-mapped private
@@ -75,14 +75,14 @@ Address | [`ip`](https://github.com/indutny/node-ip) | [`@webpod/ip`](https://gi
7575
`::1` | ✓ | ✓ | ✓ | ✓ | ✓ | loopback
7676
`fe80::1` | ✓ | ✓ | ✓ | ✓ | ✓ | link-local
7777
`0x7f.1` | ✓ | ✓ | ✓ | ✓ | ✓ | CVE-2023-42282: hex loopback
78-
`127.1` | | ✓ | | ✓ | ✓ | CVE-2024-29415: short loopback
78+
`127.1` | | ✓ | | ✓ | ✓ | CVE-2024-29415: short loopback
7979
`2130706433` | ✓ | ✓ | ✓ | ✓ | ✓ | CVE-2024-29415: integer loopback
80-
`::fFFf:127.0.0.1` | | ✓ | | ❌ | ✓ | CVE-2024-29415: IPv6-mapped loopback
81-
`::0:ffff:127.0.0.1` | | ✓ | | ❌ | ✓ | ↑
82-
`0::0:ffff:127.0.0.1` | | ✓ | | ❌ | ✓ | ↑
83-
`0:0:0:0:0:ffff:127.0.0.1` | | ✓ | | ❌ | ✓ | ↑
84-
`017700000001` | ✓ | n/a | n/a | ❌ | ❌ | octal 127.0.0.1
85-
`01200034567` | ✓ | n/a | n/a | ❌ | ❌ | invalid: octal-style
86-
`012.1.2.3` | ✓ | n/a | n/a | ❌ | ❌ | invalid: octal-style IPv4
87-
`000:0:0000::01` | | ✓ | | ✓ | ✓ | valid: zero-compression
88-
`::fFFf:127.255.255.256` | ✓ | n/a | n/a | n/a | ✓ | invalid: IPv4 overflow
80+
`::fFFf:127.0.0.1` | | ✓ | | ❌ | ✓ | CVE-2024-29415: IPv6-mapped loopback
81+
`::0:ffff:127.0.0.1` | | ✓ | | ❌ | ✓ | ↑
82+
`0::0:ffff:127.0.0.1` | | ✓ | | ❌ | ✓ | ↑
83+
`0:0:0:0:0:ffff:127.0.0.1` | | ✓ | | ❌ | ✓ | ↑
84+
`017700000001` | n/a | n/a | ✓ | ❌ | ❌ | octal 127.0.0.1
85+
`01200034567` | n/a | n/a | ✓ | ❌ | ❌ | invalid: octal-style
86+
`012.1.2.3` | n/a | n/a | ✓ | ❌ | ❌ | invalid: octal-style IPv4
87+
`000:0:0000::01` | | ✓ | | ✓ | ✓ | valid: zero-compression
88+
`::fFFf:127.255.255.256` | n/a | n/a | ✓ | n/a | ✓ | invalid: IPv4 overflow

META.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Package meta across libraries
2+
> Autogenerated by [`src/scripts/build-meta-md.ts`](./src/scripts/build-meta-md.ts)
3+
4+
| Package | Publish size | Install size | Node.js | Modules | Types |
5+
| --- | ---: | ---: | ---: | ---: | ---: |
6+
| [`@webpod/ip`](https://github.com/webpod/ip) | 59.1 kB | 56.1 kB | \>= 10 | ESM, CJS ||
7+
| [`ip`](https://github.com/indutny/node-ip) | 15.1 kB | 15.1 kB | n/a | CJS ||
8+
| [`is-ip`](https://github.com/sindresorhus/is-ip) | 4.9 kB | 42.7 kB | \>=14.16 | ESM ||
9+
| [`ipaddr.js`](https://github.com/whitequark/ipaddr.js/) | 60.8 kB | 60.8 kB | \>= 10 | CJS ||
10+
| [`ip-address`](https://github.com/beaugunderson/ip-address) | 172.4 kB | 172.4 kB | \>= 12 | CJS ||
11+
| [`ip2buf`](https://github.com/reklatsmasters/ip2buf) | n/a | n/a | \>=6 | CJS ||
12+
| [`neoip`](https://github.com/Zaptic/neoip) | 40.3 kB | 40.3 kB | n/a | ESM, CJS ||

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Address.isSpecial('1.2.3.4') // false
135135
```
136136

137137
## Alternatives
138-
Follow [coherence.md](./COHERENCE.md) and [benchmark.md](./BENCHMARK.md) to explore suitable options.
138+
Follow [coherence.md](./COHERENCE.md), [benchmark.md](./BENCHMARK.md) and [meta.md](./META.md) to explore suitable options.
139139

140140
## License
141141
MIT

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "Lite IP tools",
55
"type": "module",
66
"main": "target/cjs/index.cjs",
7+
"module": "target/esm/index.mjs",
8+
"types": "target/dts/index.d.ts",
9+
"browser": "target/esm/core.mjs",
710
"exports": {
811
".": {
912
"types": "./target/dts/index.d.ts",
@@ -23,14 +26,15 @@
2326
"require": "./target/cjs/index.cjs"
2427
}
2528
},
26-
"module": "target/esm/index.mjs",
27-
"types": "target/dts/index.d.ts",
2829
"files": [
2930
"target/cjs",
3031
"target/esm",
3132
"target/dts",
3233
"lib"
3334
],
35+
"engines": {
36+
"node": ">=10"
37+
},
3438
"scripts": {
3539
"build": "concurrently 'npm:build:*'",
3640
"build:js": "node ./src/scripts/build.mjs --entry='src/main/ts/core.ts:src/main/ts/index.ts'",
@@ -42,6 +46,7 @@
4246
"build:pkgjson": "node ./src/scripts/build-pkgjson.ts",
4347
"_build:bench": "node ./src/scripts/build-bench-md.ts",
4448
"_build:coh": "node ./src/scripts/build-coherence-md.ts",
49+
"_build:meta": "node ./src/scripts/build-meta-md.ts",
4550
"test": "concurrently 'npm:test:*'",
4651
"test:target": "git diff --exit-code --quiet || (echo 'Uncommitted changes' && exit 1)",
4752
"test:size": "size-limit",

src/scripts/build-bench-md.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function toMarkdown(results: NamedResult[]): string {
5757

5858

5959
let output = `# Performance across libraries
60-
> Autogenerated by \`src/scripts/build-bench-md.ts\`
60+
> Autogenerated by [\`src/scripts/build-bench-md.ts\`](./src/scripts/build-bench-md.ts)
6161
6262
${systemNote()}
6363
`

src/scripts/build-coherence-md.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const suites: {title: string, method: string, cases: [string, boolean, st
128128
]
129129

130130
let output = `# Coherence across libraries
131-
> Autogenerated by \`src/scripts/build-coherence-md.ts\`
131+
> Autogenerated by [\`src/scripts/build-coherence-md.ts\`](./src/scripts/build-coherence-md.ts)
132132
`
133133

134134
for (const {title, method, cases} of suites) {

src/scripts/build-meta-md.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import path from 'node:path'
2+
import fs from 'node:fs'
3+
import cp from 'node:child_process'
4+
import { tools } from '../test/bench/stand/index.ts'
5+
6+
const __dirname = path.dirname(new URL(import.meta.url).pathname)
7+
const outfile = path.resolve(__dirname, '../../META.md')
8+
const tmpbase = path.resolve(__dirname, '../../tmp')
9+
10+
interface PackageInfo {
11+
name: string
12+
size: string // unpacked size of package
13+
installSize: string // unpacked size + deps
14+
node: string
15+
browser: boolean
16+
moduleTypes: string[]
17+
types: boolean
18+
}
19+
20+
function formatSize(bytes: number): string {
21+
if (!bytes) return 'n/a'
22+
if (bytes > 1024 * 1024) return (bytes / 1024 / 1024).toFixed(1) + ' MB'
23+
return (bytes / 1024).toFixed(1) + ' kB'
24+
}
25+
26+
async function getNpmMetadata(pkg: string) {
27+
const res = await fetch(`https://registry.npmjs.org/${pkg}`)
28+
if (!res.ok) throw new Error(`Failed to fetch ${pkg}`)
29+
return res.json()
30+
}
31+
32+
async function getPackageInfo(pkg: string, repo: string): Promise<PackageInfo> {
33+
console.log(`fetching ${pkg} meta...`)
34+
35+
const tmp = path.join(tmpbase, pkg.replace('/', '-'))
36+
await fs.promises.mkdir(tmp, { recursive: true })
37+
await fs.promises.writeFile(path.join(tmp, 'package.json'), JSON.stringify({dependencies: { [pkg]: 'latest' }}))
38+
39+
const {promise, resolve, reject} = Promise.withResolvers()
40+
cp.exec('npm install --prefer-offline --no-audit --no-fund --ignore-scripts --package-lock-only', { cwd: tmp }, (err) => err ? reject(err) : resolve(true))
41+
await promise
42+
43+
const pkgLock = JSON.parse(await fs.promises.readFile(path.join(tmp, 'package-lock.json'), 'utf-8'))
44+
45+
const meta = await getNpmMetadata(pkg)
46+
const latest = meta['dist-tags'].latest
47+
const pkgInfo = meta.versions[latest]
48+
const unpackedSize = pkgInfo.dist?.unpackedSize ?? 0
49+
50+
let installSize = 0
51+
for (const [location, {version}] of Object.entries(pkgLock.packages as Record<string, {version?: string}> ?? {})) {
52+
try {
53+
if (!version) continue
54+
const name = location === '' ? pkg : location.replace('node_modules/', '')
55+
const depMeta = await getNpmMetadata(name)
56+
installSize += depMeta.versions[version]?.dist?.unpackedSize ?? 0
57+
} catch {
58+
/* ignore missing dep sizes */
59+
}
60+
}
61+
62+
const engines = pkgInfo.engines?.node ?? 'n/a'
63+
const browser = !!pkgInfo.browser
64+
const hasTypes =
65+
!!pkgInfo.types ||
66+
!!pkgInfo.typings ||
67+
(pkgInfo.devDependencies && Object.keys(pkgInfo.devDependencies).some(d => d.startsWith('@types/')))
68+
69+
const moduleTypes: string[] = []
70+
if (pkgInfo.type === 'module' || pkgInfo.module || pkgInfo.exports?.['.']?.import) {
71+
moduleTypes.push('ESM')
72+
}
73+
if (pkgInfo.main || pkgInfo.exports?.['.']?.require) {
74+
moduleTypes.push('CJS')
75+
}
76+
77+
return {
78+
name: `[\`${pkg}\`](${repo})`,
79+
size: formatSize(unpackedSize),
80+
installSize: formatSize(installSize),
81+
node: engines.replace('>', '\\>').replace('<', '\\<'),
82+
browser,
83+
moduleTypes,
84+
types: hasTypes,
85+
}
86+
}
87+
88+
function toMarkdown(pkgs: PackageInfo[]): string {
89+
const headers = [
90+
'Package',
91+
'Publish size',
92+
'Install size',
93+
'Node.js',
94+
'Modules',
95+
'Types',
96+
]
97+
const table = [
98+
`| ${headers.join(' | ')} |`,
99+
`| ${headers.map((_, i) => '---' + (i > 0 ? ':' : '')).join(' | ')} |`,
100+
...pkgs.map(p =>
101+
`| ${p.name} | ${p.size} | ${p.installSize} | ${p.node} | ${p.moduleTypes.join(', ')} | ${p.types ? '✓' : '❌'} |`
102+
),
103+
]
104+
return table.join('\n')
105+
}
106+
107+
let output = `# Package meta across libraries
108+
> Autogenerated by [\`src/scripts/build-meta-md.ts\`](./src/scripts/build-meta-md.ts)
109+
110+
`
111+
112+
const packages = Object.keys(tools).filter((k) => k !== 'node:net' && k !== '@webpod/ip/core')
113+
const results: PackageInfo[] = []
114+
for (const pkg of packages) {
115+
try {
116+
results.push(await getPackageInfo(pkg, tools[pkg]?.ref as string || `https://www.npmjs.com/package/${pkg}`))
117+
} catch (err) {
118+
console.error(`Failed to fetch ${pkg}:`, err)
119+
}
120+
}
121+
output += toMarkdown(results)
122+
123+
fs.writeFileSync(outfile, output)

0 commit comments

Comments
 (0)