From 219b006c4035eb73a4cc820afb052c29403671c6 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Sat, 14 Sep 2024 20:02:54 +0000 Subject: [PATCH 1/4] Replace lodash with es-toolkit --- package.json | 3 +-- src/ink.tsx | 17 ++++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 55f9a8ea..d027842a 100644 --- a/package.json +++ b/package.json @@ -52,9 +52,9 @@ "cli-cursor": "^4.0.0", "cli-truncate": "^4.0.0", "code-excerpt": "^4.0.0", + "es-toolkit": "^1.19.0", "indent-string": "^5.0.0", "is-in-ci": "^0.1.0", - "lodash": "^4.17.21", "patch-console": "^2.0.0", "react-reconciler": "^0.29.0", "scheduler": "^0.23.0", @@ -72,7 +72,6 @@ "@faker-js/faker": "^8.3.1", "@sindresorhus/tsconfig": "^5.0.0", "@types/benchmark": "^2.1.2", - "@types/lodash": "^4.14.202", "@types/ms": "^0.7.31", "@types/node": "^20.10.4", "@types/react": "^18.2.43", diff --git a/src/ink.tsx b/src/ink.tsx index 8f816112..b3bc12d3 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -1,7 +1,6 @@ import process from 'node:process'; import React, {type ReactNode} from 'react'; -import throttle from 'lodash/throttle.js'; -import {type DebouncedFunc} from 'lodash'; +import {throttle} from 'es-toolkit/compat'; import ansiEscapes from 'ansi-escapes'; import isInCi from 'is-in-ci'; import autoBind from 'auto-bind'; @@ -28,10 +27,12 @@ export type Options = { waitUntilExit?: () => Promise; }; +type ThrottledFunc void> = ReturnType>; + export default class Ink { private readonly options: Options; private readonly log: LogUpdate; - private readonly throttledLog: LogUpdate | DebouncedFunc; + private readonly throttledLog: LogUpdate | ThrottledFunc; // Ignore last render after unmounting a tree to prevent empty output before exit private isUnmounted: boolean; private lastOutput: string; @@ -53,19 +54,13 @@ export default class Ink { this.rootNode.onRender = options.debug ? this.onRender - : throttle(this.onRender, 32, { - leading: true, - trailing: true, - }); + : throttle(this.onRender, 32); this.rootNode.onImmediateRender = this.onRender; this.log = logUpdate.create(options.stdout); this.throttledLog = options.debug ? this.log - : throttle(this.log, undefined, { - leading: true, - trailing: true, - }); + : throttle(this.log, undefined); // Ignore last render after unmounting a tree to prevent empty output before exit this.isUnmounted = false; From e0cbe0337ce4e44a80e811f40b237d5dd3f54b92 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Sun, 29 Sep 2024 16:31:42 +0200 Subject: [PATCH 2/4] Update es-toolkit, bring back options --- package.json | 2 +- src/ink.tsx | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d027842a..1467e897 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "cli-cursor": "^4.0.0", "cli-truncate": "^4.0.0", "code-excerpt": "^4.0.0", - "es-toolkit": "^1.19.0", + "es-toolkit": "^1.22.0", "indent-string": "^5.0.0", "is-in-ci": "^0.1.0", "patch-console": "^2.0.0", diff --git a/src/ink.tsx b/src/ink.tsx index b3bc12d3..00abe1ae 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -54,13 +54,19 @@ export default class Ink { this.rootNode.onRender = options.debug ? this.onRender - : throttle(this.onRender, 32); + : throttle(this.onRender, 32, { + leading: true, + trailing: true, + }); this.rootNode.onImmediateRender = this.onRender; this.log = logUpdate.create(options.stdout); this.throttledLog = options.debug ? this.log - : throttle(this.log, undefined); + : throttle(this.log, undefined, { + leading: true, + trailing: true, + }); // Ignore last render after unmounting a tree to prevent empty output before exit this.isUnmounted = false; From d760f434e2842e485a1f11e459a980add040c02f Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Sun, 29 Sep 2024 16:39:18 +0200 Subject: [PATCH 3/4] Replace ThrottledFunc with type assertion --- src/ink.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ink.tsx b/src/ink.tsx index 00abe1ae..f59fa9f0 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -27,12 +27,10 @@ export type Options = { waitUntilExit?: () => Promise; }; -type ThrottledFunc void> = ReturnType>; - export default class Ink { private readonly options: Options; private readonly log: LogUpdate; - private readonly throttledLog: LogUpdate | ThrottledFunc; + private readonly throttledLog: LogUpdate; // Ignore last render after unmounting a tree to prevent empty output before exit private isUnmounted: boolean; private lastOutput: string; @@ -66,7 +64,7 @@ export default class Ink { : throttle(this.log, undefined, { leading: true, trailing: true, - }); + }) as unknown as LogUpdate; // Ignore last render after unmounting a tree to prevent empty output before exit this.isUnmounted = false; From df60d3c00f40441bb3f64142b0d98edb98c08e96 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Mon, 30 Sep 2024 21:39:29 +0200 Subject: [PATCH 4/4] Make linter happy again --- src/ink.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ink.tsx b/src/ink.tsx index f59fa9f0..7b88589c 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -61,10 +61,10 @@ export default class Ink { this.log = logUpdate.create(options.stdout); this.throttledLog = options.debug ? this.log - : throttle(this.log, undefined, { + : (throttle(this.log, undefined, { leading: true, trailing: true, - }) as unknown as LogUpdate; + }) as unknown as LogUpdate); // Ignore last render after unmounting a tree to prevent empty output before exit this.isUnmounted = false;