@nomicfoundation/hardhat-utils
Advanced tools
| export declare const FRAME_INTERVAL_MS = 80; | ||
| export interface ISpinner { | ||
| readonly isEnabled: boolean; | ||
| start(): void; | ||
| stop(): void; | ||
| } | ||
| /** | ||
| * Optional settings when creating a spinner. | ||
| */ | ||
| export interface SpinnerOptions { | ||
| /** | ||
| * Text shown next to the spinner. | ||
| */ | ||
| text?: string; | ||
| /** | ||
| * Stream used to write frames. | ||
| */ | ||
| stream?: NodeJS.WriteStream; | ||
| /** | ||
| * Whether the spinner is enabled. | ||
| */ | ||
| enabled?: boolean; | ||
| } | ||
| /** | ||
| * Create a spinner instance. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const spinner = createSpinner({ text: "Compiling…" }); | ||
| * spinner.start(); | ||
| * | ||
| * try { | ||
| * await compileContracts(); | ||
| * spinner.stop(); | ||
| * console.log("Compiled 12 contracts"); | ||
| * } catch (error) { | ||
| * spinner.stop(); | ||
| * console.error("Compilation failed"); | ||
| * } | ||
| * ``` | ||
| * | ||
| * @param options Optional spinner configuration. | ||
| * @returns {Spinner} A spinner instance. | ||
| */ | ||
| export declare function createSpinner(options?: SpinnerOptions): ISpinner; | ||
| //# sourceMappingURL=spinner.d.ts.map |
| {"version":3,"file":"spinner.d.ts","sourceRoot":"","sources":["../../src/spinner.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAmED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,QAAQ,CAcpE"} |
| const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; | ||
| export const FRAME_INTERVAL_MS = 80; | ||
| /** | ||
| * Spinner that writes frames to a stream. | ||
| */ | ||
| class Spinner { | ||
| isEnabled; | ||
| #text; | ||
| #interval = null; | ||
| #stream; | ||
| constructor(options) { | ||
| this.isEnabled = options.enabled; | ||
| this.#stream = options.stream; | ||
| this.#text = options.text; | ||
| } | ||
| /** | ||
| * Begin rendering frames when enabled. | ||
| */ | ||
| start() { | ||
| if (!this.isEnabled) { | ||
| return; | ||
| } | ||
| this.#stopAnimation(); | ||
| let frameIndex = 0; | ||
| this.#interval = setInterval(() => { | ||
| this.#render(FRAMES[frameIndex]); | ||
| frameIndex = (frameIndex + 1) % FRAMES.length; | ||
| }, FRAME_INTERVAL_MS); | ||
| } | ||
| /** | ||
| * Stop the spinner without printing a final line. | ||
| */ | ||
| stop() { | ||
| this.#stopAnimation(); | ||
| } | ||
| #clearLine() { | ||
| this.#stream.clearLine(0); | ||
| this.#stream.cursorTo(0); | ||
| } | ||
| #render(frame) { | ||
| if (!this.isEnabled) { | ||
| return; | ||
| } | ||
| this.#clearLine(); | ||
| this.#stream.write(`${frame} ${this.#text}`); | ||
| } | ||
| #stopAnimation() { | ||
| if (this.#interval === null) { | ||
| return; | ||
| } | ||
| clearInterval(this.#interval); | ||
| this.#interval = null; | ||
| if (this.isEnabled) { | ||
| this.#clearLine(); | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * Create a spinner instance. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const spinner = createSpinner({ text: "Compiling…" }); | ||
| * spinner.start(); | ||
| * | ||
| * try { | ||
| * await compileContracts(); | ||
| * spinner.stop(); | ||
| * console.log("Compiled 12 contracts"); | ||
| * } catch (error) { | ||
| * spinner.stop(); | ||
| * console.error("Compilation failed"); | ||
| * } | ||
| * ``` | ||
| * | ||
| * @param options Optional spinner configuration. | ||
| * @returns {Spinner} A spinner instance. | ||
| */ | ||
| export function createSpinner(options = {}) { | ||
| const stream = options.stream ?? process.stdout; | ||
| const enabled = stream.isTTY === true && | ||
| process.env.TERM !== "dumb" && | ||
| (options.enabled ?? true); | ||
| const text = options.text ?? ""; | ||
| return new Spinner({ | ||
| enabled, | ||
| stream, | ||
| text, | ||
| }); | ||
| } | ||
| //# sourceMappingURL=spinner.js.map |
| {"version":3,"file":"spinner.js","sourceRoot":"","sources":["../../src/spinner.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AA4BpC;;GAEG;AACH,MAAM,OAAO;IACK,SAAS,CAAU;IAC1B,KAAK,CAAS;IACvB,SAAS,GAA0B,IAAI,CAAC;IAC/B,OAAO,CAAqB;IAErC,YAAY,OAAiC;QAC3C,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAC5B,CAAC;IACD;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;YAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;YACjC,UAAU,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,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ACP,MAAM;QACN,IAAI;KACL,CAAC,CAAC;AACL,CAAC"} |
+130
| const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; | ||
| export const FRAME_INTERVAL_MS = 80; | ||
| export interface ISpinner { | ||
| readonly isEnabled: boolean; | ||
| start(): void; | ||
| stop(): void; | ||
| } | ||
| /** | ||
| * Optional settings when creating a spinner. | ||
| */ | ||
| export interface SpinnerOptions { | ||
| /** | ||
| * Text shown next to the spinner. | ||
| */ | ||
| text?: string; | ||
| /** | ||
| * Stream used to write frames. | ||
| */ | ||
| stream?: NodeJS.WriteStream; | ||
| /** | ||
| * Whether the spinner is enabled. | ||
| */ | ||
| enabled?: boolean; | ||
| } | ||
| /** | ||
| * Spinner that writes frames to a stream. | ||
| */ | ||
| class Spinner implements ISpinner { | ||
| public readonly isEnabled: boolean; | ||
| readonly #text: string; | ||
| #interval: NodeJS.Timeout | null = null; | ||
| readonly #stream: NodeJS.WriteStream; | ||
| constructor(options: Required<SpinnerOptions>) { | ||
| this.isEnabled = options.enabled; | ||
| this.#stream = options.stream; | ||
| this.#text = options.text; | ||
| } | ||
| /** | ||
| * Begin rendering frames when enabled. | ||
| */ | ||
| public start(): void { | ||
| if (!this.isEnabled) { | ||
| return; | ||
| } | ||
| this.#stopAnimation(); | ||
| let frameIndex = 0; | ||
| this.#interval = setInterval(() => { | ||
| this.#render(FRAMES[frameIndex]); | ||
| frameIndex = (frameIndex + 1) % FRAMES.length; | ||
| }, FRAME_INTERVAL_MS); | ||
| } | ||
| /** | ||
| * Stop the spinner without printing a final line. | ||
| */ | ||
| public stop(): void { | ||
| this.#stopAnimation(); | ||
| } | ||
| #clearLine(): void { | ||
| this.#stream.clearLine(0); | ||
| this.#stream.cursorTo(0); | ||
| } | ||
| #render(frame: string): void { | ||
| if (!this.isEnabled) { | ||
| return; | ||
| } | ||
| this.#clearLine(); | ||
| this.#stream.write(`${frame} ${this.#text}`); | ||
| } | ||
| #stopAnimation(): void { | ||
| if (this.#interval === null) { | ||
| return; | ||
| } | ||
| clearInterval(this.#interval); | ||
| this.#interval = null; | ||
| if (this.isEnabled) { | ||
| this.#clearLine(); | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * Create a spinner instance. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const spinner = createSpinner({ text: "Compiling…" }); | ||
| * spinner.start(); | ||
| * | ||
| * try { | ||
| * await compileContracts(); | ||
| * spinner.stop(); | ||
| * console.log("Compiled 12 contracts"); | ||
| * } catch (error) { | ||
| * spinner.stop(); | ||
| * console.error("Compilation failed"); | ||
| * } | ||
| * ``` | ||
| * | ||
| * @param options Optional spinner configuration. | ||
| * @returns {Spinner} A spinner instance. | ||
| */ | ||
| export function createSpinner(options: SpinnerOptions = {}): ISpinner { | ||
| const stream = options.stream ?? process.stdout; | ||
| const enabled = | ||
| stream.isTTY === true && | ||
| process.env.TERM !== "dumb" && | ||
| (options.enabled ?? true); | ||
| const text = options.text ?? ""; | ||
| return new Spinner({ | ||
| enabled, | ||
| stream, | ||
| text, | ||
| }); | ||
| } |
+7
-0
| # @nomicfoundation/hardhat-utils | ||
| ## 3.0.3 | ||
| ### Patch Changes | ||
| - d821a0a: Fix npm artifact cleanup on windows ([#7459](https://github.com/NomicFoundation/hardhat/issues/7459)) | ||
| - b13620a: Add compilation progress spinner to show build progress ([#7460](https://github.com/NomicFoundation/hardhat/pull/7460)) | ||
| ## 3.0.2 | ||
@@ -4,0 +11,0 @@ |
+3
-2
| { | ||
| "name": "@nomicfoundation/hardhat-utils", | ||
| "version": "3.0.2", | ||
| "version": "3.0.3", | ||
| "description": "Utilities for Hardhat and its plugins", | ||
@@ -38,3 +38,4 @@ "homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-utils", | ||
| "./subprocess": "./dist/src/subprocess.js", | ||
| "./synchronization": "./dist/src/synchronization.js" | ||
| "./synchronization": "./dist/src/synchronization.js", | ||
| "./spinner": "./dist/src/spinner.js" | ||
| }, | ||
@@ -41,0 +42,0 @@ "keywords": [ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
382348
2.31%189
2.72%7522
3.41%45
4.65%1
Infinity%