@latticexyz/gas-report
Advanced tools
Comparing version 2.0.0-main-fa74f25e to 2.0.0-main-fc5748b1
#!/usr/bin/env node | ||
import{a as r}from"./chunk-P7EYZ5QJ.js";import i from"yargs";import{hideBin as s}from"yargs/helpers";import*as a from"dotenv";import e from"chalk";a.config();r.command="$0";i(s(process.argv)).scriptName("gas-report").command(r).strict().fail((o,n)=>{console.error(e.red(o)),o.includes("Missing required argument")&&console.log(e.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`)),process.exit(1)}).alias({h:"help"}).argv; | ||
import{a as r}from"./chunk-OPZOQG5Z.js";import i from"yargs";import{hideBin as s}from"yargs/helpers";import*as a from"dotenv";import e from"chalk";a.config();r.command="$0";i(s(process.argv)).scriptName("gas-report").command(r).strict().fail((o,n)=>{console.error(e.red(o)),o.includes("Missing required argument")&&console.log(e.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`)),process.exit(1)}).alias({h:"help"}).argv; | ||
//# sourceMappingURL=gas-report.js.map |
@@ -1,2 +0,2 @@ | ||
import{a}from"./chunk-P7EYZ5QJ.js";export{a as default}; | ||
import{a}from"./chunk-OPZOQG5Z.js";export{a as default}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@latticexyz/gas-report", | ||
"version": "2.0.0-main-fa74f25e", | ||
"version": "2.0.0-main-fc5748b1", | ||
"description": "Gas reporter for specific lines within forge tests", | ||
@@ -29,2 +29,3 @@ "repository": { | ||
"execa": "^7.0.0", | ||
"stream-to-array": "^2.3.0", | ||
"strip-ansi": "^7.1.0", | ||
@@ -36,2 +37,3 @@ "table": "^6.8.1", | ||
"@types/node": "^18.15.11", | ||
"@types/stream-to-array": "^2.3.1", | ||
"@types/yargs": "^17.0.10", | ||
@@ -38,0 +40,0 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", |
@@ -7,2 +7,3 @@ import type { CommandModule } from "yargs"; | ||
import stripAnsi from "strip-ansi"; | ||
import toArray from "stream-to-array"; | ||
@@ -35,2 +36,3 @@ /** | ||
compare?: string; | ||
stdin?: boolean; | ||
}; | ||
@@ -57,9 +59,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) { | ||
@@ -72,2 +78,3 @@ console.error(error); | ||
// If this gas report should be compared to an existing one, load the existing one | ||
let { compare } = options; | ||
if (compare) { | ||
@@ -91,3 +98,3 @@ try { | ||
// Save gas report to file if requested | ||
if (save) saveGasReport(gasReport, save); | ||
if (options.save) saveGasReport(gasReport, options.save); | ||
@@ -100,3 +107,3 @@ process.exit(0); | ||
async function runGasReport(): Promise<GasReport> { | ||
async function runGasReport(options: Options): Promise<GasReport> { | ||
console.log("Running gas report"); | ||
@@ -106,10 +113,18 @@ 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 and pipe them to stdout for visibility | ||
console.log("Waiting for stdin..."); | ||
process.stdin.pipe(process.stdout); | ||
logs = (await toArray(process.stdin)).map((chunk) => chunk.toString()).join("\n"); | ||
console.log("Done reading stdin"); | ||
} 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) { | ||
@@ -122,3 +137,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+) (.*)$/; | ||
@@ -125,0 +140,0 @@ const testFunctionPattern = /^\[(?:PASS|FAIL).*\] (\w+)\(\)/; |
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
29248
226
7
7
+ Addedstream-to-array@^2.3.0
+ Addedany-promise@1.3.0(transitive)
+ Addedstream-to-array@2.3.0(transitive)