diff --git a/.changeset/real-seahorses-sleep.md b/.changeset/real-seahorses-sleep.md new file mode 100644 index 0000000..05ed8ff --- /dev/null +++ b/.changeset/real-seahorses-sleep.md @@ -0,0 +1,5 @@ +--- +"hereby": minor +--- + +Use `performance.now` instead of `Date.now` diff --git a/.eslintrc.json b/.eslintrc.json index c04a860..b1cc82b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,7 +25,7 @@ "no-inner-declarations": "off", "no-undef": "off", "no-unused-vars": "off", - "no-restricted-globals": ["error", "console", "process"], + "no-restricted-globals": ["error", "console", "process", "Date"], "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", "@typescript-eslint/no-import-type-side-effects": "error", diff --git a/src/cli/index.ts b/src/cli/index.ts index b53c3b0..c6f21fe 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,4 +1,5 @@ import path from "node:path"; +import { performance } from "node:perf_hooks"; import { types } from "node:util"; import pc from "picocolors"; @@ -59,7 +60,7 @@ async function mainWorker(d: D) { const taskNames = tasks.map((task) => pc.blue(task.options.name)).join(", "); d.log(`Using ${pc.yellow(d.simplifyPath(herebyfilePath))} to run ${taskNames}`); - const start = Date.now(); + const start = performance.now(); let errored = false; try { @@ -72,7 +73,7 @@ async function mainWorker(d: D) { // so we don't end up with an unflushed output. d.setExitCode(1); } finally { - const took = Date.now() - start; + const took = performance.now() - start; d.log(`Completed ${taskNames}${errored ? pc.red(" with errors") : ""} in ${d.prettyMilliseconds(took)}`); } } diff --git a/src/cli/runner.ts b/src/cli/runner.ts index 0e4db14..0db05e0 100644 --- a/src/cli/runner.ts +++ b/src/cli/runner.ts @@ -1,3 +1,5 @@ +import { performance } from "node:perf_hooks"; + import pc from "picocolors"; import type { Task } from "../index.js"; @@ -58,7 +60,7 @@ export class Runner { } protected onTaskStart(task: Task): void { - this._startTimes.set(task, Date.now()); + this._startTimes.set(task, performance.now()); if (this._errored) { return; // Skip logging. @@ -72,7 +74,7 @@ export class Runner { return; // Skip logging. } - const took = Date.now() - this._startTimes.get(task)!; + const took = performance.now() - this._startTimes.get(task)!; this._d.log(`Finished ${pc.green(task.options.name)} in ${this._d.prettyMilliseconds(took)}`); } @@ -82,7 +84,7 @@ export class Runner { } this._errored = true; - const took = Date.now() - this._startTimes.get(task)!; + const took = performance.now() - this._startTimes.get(task)!; this._d.error(`Error in ${pc.red(task.options.name)} in ${this._d.prettyMilliseconds(took)}\n${e}`); } }