@latticexyz/gas-report
Advanced tools
Comparing version 2.0.0-main-939916bc to 2.0.0-main-94d7f1ee
@@ -1,2 +0,2 @@ | ||
import{a}from"./chunk-P7EYZ5QJ.js";export{a as default}; | ||
import{a}from"./chunk-JCAUKVNQ.js";export{a as default}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@latticexyz/gas-report", | ||
"version": "2.0.0-main-939916bc", | ||
"version": "2.0.0-main-94d7f1ee", | ||
"description": "Gas reporter for specific lines within forge tests", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"bin": { | ||
"mud-gas-report": "./dist/mud-gas-report.js" | ||
"gas-report": "./dist/gas-report.js" | ||
}, | ||
@@ -47,4 +47,5 @@ "dependencies": { | ||
"dev": "tsup --watch", | ||
"test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests && forge test" | ||
"test": "vitest typecheck --run --passWithNoTests && vitest --run --passWithNoTests && forge test", | ||
"test:ci": "pnpm run test" | ||
} | ||
} |
@@ -23,5 +23,5 @@ # Gas Report | ||
```console | ||
pnpm mud-gas-report --save gas-report.json | ||
pnpm gas-report --save gas-report.json | ||
``` | ||
Run `pnpm mud-gas-report --help` for more details. | ||
Run `pnpm gas-report --help` for more details. |
@@ -34,2 +34,3 @@ import type { CommandModule } from "yargs"; | ||
compare?: string; | ||
stdin?: boolean; | ||
}; | ||
@@ -56,9 +57,13 @@ | ||
compare: { type: "string", desc: "Compare to an existing gas report" }, | ||
stdin: { | ||
type: "boolean", | ||
desc: "Parse the gas report logs from stdin instead of running an internal test command", | ||
}, | ||
}); | ||
}, | ||
async handler({ save, compare }) { | ||
async handler(options) { | ||
let gasReport: GasReport; | ||
try { | ||
gasReport = await runGasReport(); | ||
gasReport = await runGasReport(options); | ||
} catch (error) { | ||
@@ -71,2 +76,3 @@ console.error(error); | ||
// If this gas report should be compared to an existing one, load the existing one | ||
let { compare } = options; | ||
if (compare) { | ||
@@ -90,3 +96,3 @@ try { | ||
// Save gas report to file if requested | ||
if (save) saveGasReport(gasReport, save); | ||
if (options.save) saveGasReport(gasReport, options.save); | ||
@@ -99,3 +105,3 @@ process.exit(0); | ||
async function runGasReport(): Promise<GasReport> { | ||
async function runGasReport(options: Options): Promise<GasReport> { | ||
console.log("Running gas report"); | ||
@@ -105,10 +111,15 @@ const gasReport: GasReport = []; | ||
// Extract the logs from the child process | ||
let stdout: string; | ||
let logs: string; | ||
try { | ||
// Run the generated file using forge | ||
const child = execa("forge", ["test", "-vvv"], { | ||
stdio: ["inherit", "pipe", "inherit"], | ||
env: { GAS_REPORTER_ENABLED: "true" }, | ||
}); | ||
stdout = (await child).stdout; | ||
if (options.stdin) { | ||
// Read the logs from stdin | ||
logs = await readStdIn(); | ||
} else { | ||
// Run the default test command to capture the logs | ||
const child = execa("forge", ["test", "-vvv"], { | ||
stdio: ["inherit", "pipe", "inherit"], | ||
env: { GAS_REPORTER_ENABLED: "true" }, | ||
}); | ||
logs = (await child).stdout; | ||
} | ||
} catch (error: any) { | ||
@@ -121,3 +132,3 @@ console.log(error.stdout ?? error); | ||
// Extract the gas reports from the logs | ||
const lines = stdout.split("\n").map(stripAnsi); | ||
const lines = logs.split("\n").map(stripAnsi); | ||
const gasReportPattern = /^\s*GAS REPORT: (\d+) (.*)$/; | ||
@@ -201,1 +212,15 @@ const testFunctionPattern = /^\[(?:PASS|FAIL).*\] (\w+)\(\)/; | ||
} | ||
function readStdIn(): Promise<string> { | ||
return new Promise((resolve) => { | ||
let data = ""; | ||
process.stdin.on("data", (chunk) => { | ||
data += chunk; | ||
}); | ||
process.stdin.on("end", () => { | ||
resolve(data); | ||
}); | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29126
232