-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: switch to tsx cli from esbuild-register and to mitata from ben…
…chmark.js (#107)
- Loading branch information
1 parent
2b6bcbd
commit 5906367
Showing
7 changed files
with
1,747 additions
and
1,100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import "./build.mts"; | ||
|
||
import os from "os"; | ||
import path from "path"; | ||
import fs from "fs/promises"; | ||
import cp from "child_process"; | ||
import { promisify } from "util"; | ||
|
||
import degit from "degit"; | ||
import { group, bench, run } from "mitata"; | ||
|
||
const exec = promisify(cp.exec); | ||
const api = (await import("./dist/index.mjs")) as unknown as typeof import("./src"); | ||
const FIXTURES = path.resolve("src/__tests__/fixtures"); | ||
const GREP = new RegExp(process.env.GREP || ".", "g"); | ||
const COMPARE = process.env.COMPARE; | ||
let compareAPI: undefined | typeof api; | ||
|
||
if (COMPARE) { | ||
const cwd = path.join(os.tmpdir(), `htmljs-bench-${COMPARE}`); | ||
const exists = await fs.mkdir(cwd).catch(() => true); | ||
if (!exists) { | ||
await degit(`marko-js/htmljs-parser#${COMPARE}`).clone(cwd); | ||
await exec("npm ci && npm run --if-present build", { cwd }); | ||
} | ||
|
||
const pkg = JSON.parse( | ||
await fs.readFile(path.join(cwd, "package.json"), "utf-8") | ||
); | ||
compareAPI = await import( | ||
path.join(cwd, pkg.exports?.["."].import ?? pkg.main) | ||
); | ||
} | ||
|
||
for (const entry of await fs.readdir(FIXTURES)) { | ||
if (!GREP.test(entry)) continue; | ||
const filename = path.join(FIXTURES, entry, "input.marko"); | ||
const src = await fs.readFile(filename, "utf-8"); | ||
const check = (mod: typeof api) => () => mod.createParser({}).parse(src); | ||
if (compareAPI) { | ||
group(() => { | ||
bench(entry, check(api)); | ||
bench(`${entry}#${COMPARE}`, check(compareAPI)); | ||
}); | ||
} else { | ||
bench(entry, check(api)); | ||
} | ||
} | ||
|
||
await run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { build, BuildOptions } from "esbuild"; | ||
|
||
const opts: BuildOptions = { | ||
bundle: true, | ||
outdir: "dist", | ||
platform: "node", | ||
target: ["node14"], | ||
entryPoints: ["src/index.ts"], | ||
}; | ||
|
||
await Promise.all([ | ||
build({ | ||
...opts, | ||
format: "cjs", | ||
}), | ||
build({ | ||
...opts, | ||
format: "esm", | ||
outExtension: { ".js": ".mjs" }, | ||
}), | ||
]); |
Oops, something went wrong.