Skip to content
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
38 changes: 28 additions & 10 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/lockfiles/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Vitest package: `bun test` fails fast here (scripts/bun-test-guard.ts).
[test]
preload = ["../../scripts/bun-test-guard.ts"]
28 changes: 28 additions & 0 deletions lib/lockfiles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@maple/lockfiles",
"private": true,
"type": "module",
"sideEffects": false,
"exports": {
".": "./src/index.ts"
},
"scripts": {
"typecheck": "tsrs --noEmit",
"test": "vitest run",
"bench": "bun scripts/bench.ts",
"fixtures:generate": "bash scripts/generate-fixtures.sh"
},
"dependencies": {
"effect": "catalog:effect",
"smol-toml": "^1.9.1",
"yaml": "^2.9.1"
},
"devDependencies": {
"@types/node": "catalog:tooling",
"@types/semver": "^7.7.1",
"fast-check": "^4.10.2",
"semver": "^7.8.1",
"typescript": "catalog:tooling",
"vitest": "catalog:"
}
}
41 changes: 41 additions & 0 deletions lib/lockfiles/scripts/bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Parses each lockfile given on the command line and prints its package count and parse time.
* Usage: bun lib/lockfiles/scripts/bench.ts bun.lock [more lockfiles...]
*/
import { readFileSync } from "node:fs"
import { Effect } from "effect"
import { parseLockfile } from "../src/index.ts"

const RUNS = 5

const benchOne = (path: string) =>
Effect.gen(function* () {
const content = readFileSync(path, "utf8")
const timings = yield* Effect.forEach(Array.from({ length: RUNS }), () =>
Effect.gen(function* () {
const start = performance.now()
const parsed = yield* parseLockfile({ path, content })
return { parsed, ms: performance.now() - start }
}),
)
const sorted = timings.map((t) => t.ms).sort((a, b) => a - b)
const first = timings[0]
if (first === undefined) return
const { parsed } = first
// Without manifests some formats (yarn) cannot tell direct dependencies apart.
const direct = parsed.packages.some((p) => p.relation === "unknown")
? "unknown"
: String(parsed.packages.filter((p) => p.relation === "direct").length)
yield* Effect.log(
`${path}: ${parsed.kind}, ${parsed.packages.length} packages (${direct} direct), ${(content.length / 1024).toFixed(0)} KiB, ` +
`first ${first.ms.toFixed(1)} ms, median ${(sorted[Math.floor(RUNS / 2)] ?? 0).toFixed(1)} ms over ${RUNS} runs` +
(parsed.warnings.length > 0 ? `, warnings: ${parsed.warnings.join("; ")}` : ""),
)
})

const paths = process.argv.slice(2)
await Effect.runPromise(
paths.length === 0
? Effect.logError("usage: bun scripts/bench.ts <lockfile> [...]")
: Effect.forEach(paths, benchOne, { discard: true }),
)
Loading
Loading