Skip to content

Commit 105dbdc

Browse files
sea-snakeCopilot
andauthored
chore: Remove dfinity utils (#3663)
Remove dfinity utils dependency, given that it's only used for nullish checks and a json replacer/reviver in one place. # Changes - Remove `@dfinity/utils` dependency. - Rewrite all usages of `isNullish` and `nonNullish` to plain JS (based on TS value type being either `undefined`, `null` or `undefined | null`). # Tests All existing tests should pass as-is. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ff194ab commit 105dbdc

File tree

74 files changed

+379
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+379
-345
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
},
8686
"dependencies": {
8787
"@dfinity/internet-identity-vc-api": "*",
88-
"@dfinity/utils": "^3.1.0",
8988
"@icp-sdk/auth": "^4.0.1",
9089
"@icp-sdk/core": "^4.0.4",
9190
"@lingui/core": "^5.5.1",

src/frontend/src/hooks.server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { injectCanisterIdAndConfigPlugin } from "@dfinity/internet-identity-vite-plugins";
2-
import { nonNullish } from "@dfinity/utils";
32
import type { Handle, ServerInit } from "@sveltejs/kit";
43
import { localeStore } from "$lib/stores/locale.store";
54

@@ -12,7 +11,7 @@ const transformHtml =
1211
export const handle: Handle = async ({ event, resolve }) => {
1312
const response = await resolve(event);
1413
if (
15-
nonNullish(transformHtml) &&
14+
transformHtml !== undefined &&
1615
response.headers.get("Content-Type") === "text/html" &&
1716
response.ok
1817
) {

src/frontend/src/lib/components/ui/Alert.svelte

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
XIcon,
88
} from "@lucide/svelte";
99
import Button from "$lib/components/ui/Button.svelte";
10-
import { isNullish, nonNullish } from "@dfinity/utils";
1110
import ProgressRing from "$lib/components/ui/ProgressRing.svelte";
1211
1312
type Props = HTMLAttributes<HTMLDivElement> & {
@@ -50,7 +49,7 @@
5049
<ProgressRing class="text-fg-brand-primary" />
5150
{/if}
5251
</div>
53-
{#if nonNullish(onClose)}
52+
{#if onClose !== undefined}
5453
<Button
5554
onclick={onClose}
5655
variant="tertiary"
@@ -70,20 +69,20 @@
7069
direction === "horizontal"
7170
? "col-start-2 row-span-2 row-start-1"
7271
: "col-span-3",
73-
direction === "horizontal" && isNullish(onClose) && "col-span-2",
72+
direction === "horizontal" && onClose === undefined && "col-span-2",
7473
]}
7574
>
7675
<div class="text-text-primary text-sm font-semibold">
7776
{title}
7877
</div>
79-
{#if nonNullish(description) || nonNullish(children)}
78+
{#if description !== undefined || children !== undefined}
8079
<div class="flex flex-col gap-3">
81-
{#if nonNullish(description)}
80+
{#if description !== undefined}
8281
<div class="text-text-tertiary text-sm font-medium">
8382
{description}
8483
</div>
8584
{/if}
86-
{#if nonNullish(children)}
85+
{#if children !== undefined}
8786
<div class="flex gap-3">
8887
{@render children()}
8988
</div>

src/frontend/src/lib/components/ui/Checkbox.svelte

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import type { HTMLInputAttributes } from "svelte/elements";
33
import { CheckIcon, MinusIcon } from "@lucide/svelte";
4-
import { nonNullish } from "@dfinity/utils";
54
65
type Size = "sm" | "md";
76
@@ -48,7 +47,7 @@
4847
sm: "size-4",
4948
md: "size-5",
5049
}[size],
51-
(nonNullish(label) || nonNullish(hint)) && "mt-0.5",
50+
(label !== undefined || hint !== undefined) && "mt-0.5",
5251
]}
5352
>
5453
{#if checked}
@@ -67,9 +66,9 @@
6766
{/if}
6867
{/if}
6968
</div>
70-
{#if nonNullish(label) || nonNullish(hint)}
69+
{#if label !== undefined || hint !== undefined}
7170
<div class="flex flex-col">
72-
{#if nonNullish(label)}
71+
{#if label !== undefined}
7372
<p
7473
class={[
7574
"text-text-secondary font-medium select-none",
@@ -79,7 +78,7 @@
7978
{label}
8079
</p>
8180
{/if}
82-
{#if nonNullish(hint)}
81+
{#if hint !== undefined}
8382
<p
8483
class={[
8584
"text-text-tertiary select-none",

src/frontend/src/lib/components/ui/CodeInput.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import Input from "$lib/components/ui/Input.svelte";
33
import type { HTMLAttributes } from "svelte/elements";
4-
import { nonNullish } from "@dfinity/utils";
54
65
interface Props extends HTMLAttributes<HTMLDivElement> {
76
element: HTMLInputElement | undefined;
@@ -85,16 +84,16 @@
8584
}
8685
onkeydown={(event) => handleKeyDown(event, index)}
8786
onpaste={handlePaste}
88-
errorBorder={nonNullish(error)}
87+
errorBorder={error !== undefined}
8988
{disabled}
9089
/>
9190
{/each}
9291
</div>
93-
{#if nonNullish(error) || nonNullish(hint)}
92+
{#if error !== undefined || hint !== undefined}
9493
<div
9594
class={[
9695
"text-sm",
97-
nonNullish(error) ? "text-text-error-primary" : "text-text-tertiary",
96+
error !== undefined ? "text-text-error-primary" : "text-text-tertiary",
9897
]}
9998
>
10099
{error ?? hint}

src/frontend/src/lib/components/ui/Dialog.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { onMount } from "svelte";
33
import { scale, fly } from "svelte/transition";
44
import type { ClassValue, HTMLAttributes } from "svelte/elements";
5-
import { nonNullish } from "@dfinity/utils";
65
import { XIcon } from "@lucide/svelte";
76
import { t } from "$lib/stores/locale.store";
87
@@ -18,8 +17,8 @@
1817
children,
1918
onClose,
2019
class: className,
21-
closeOnOutsideClick = nonNullish(onClose),
22-
showCloseButton = nonNullish(onClose),
20+
closeOnOutsideClick = onClose !== undefined,
21+
showCloseButton = onClose !== undefined,
2322
backdrop = true,
2423
contentClass,
2524
...props
@@ -185,7 +184,7 @@
185184
]}
186185
>
187186
{@render children?.()}
188-
{#if showCloseButton && nonNullish(onClose)}
187+
{#if showCloseButton && onClose !== undefined}
189188
<button
190189
class="btn btn-tertiary btn-lg btn-icon absolute end-2 top-2 z-2 !rounded-full"
191190
onclick={onClose}

src/frontend/src/lib/components/ui/Input.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import type { ClassValue, HTMLInputAttributes } from "svelte/elements";
3-
import { nonNullish } from "@dfinity/utils";
43
import type { Snippet } from "svelte";
54
65
type Size = "sm" | "md";
@@ -25,13 +24,13 @@
2524
value = $bindable(),
2625
size = "md",
2726
error,
28-
errorBorder = nonNullish(error),
27+
errorBorder = error !== undefined,
2928
...restProps
3029
}: Props = $props();
3130
</script>
3231

3332
<div class={["flex flex-col gap-1.5", className]}>
34-
{#if nonNullish(label)}
33+
{#if label !== undefined}
3534
<label for={id} class="text-text-secondary text-sm font-medium">
3635
{label}
3736
</label>
@@ -56,20 +55,20 @@
5655
]}
5756
/>
5857
</div>
59-
{#if nonNullish(error) || nonNullish(hint)}
58+
{#if error !== undefined || hint !== undefined}
6059
<div
6160
class={[
6261
"text-sm",
63-
nonNullish(error) ? "text-text-error-primary" : "text-text-tertiary",
62+
error !== undefined ? "text-text-error-primary" : "text-text-tertiary",
6463
]}
6564
>
66-
{#if nonNullish(error)}
65+
{#if error !== undefined}
6766
{#if typeof error === "string"}
6867
{error}
6968
{:else}
7069
{@render error()}
7170
{/if}
72-
{:else if nonNullish(hint)}
71+
{:else if hint !== undefined}
7372
{#if typeof hint === "string"}
7473
{hint}
7574
{:else}

src/frontend/src/lib/components/ui/LandingCard.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import type { HTMLAttributes } from "svelte/elements";
3-
import { nonNullish } from "@dfinity/utils";
43
54
type Props = HTMLAttributes<HTMLDivElement> & {
65
header: string;
@@ -16,7 +15,7 @@
1615
>
1716
<p class="text-text-tertiary text-sm uppercase">{header}</p>
1817
<div class="grid h-[280px] place-items-center">
19-
{#if nonNullish(children)}
18+
{#if children !== undefined}
2019
{@render children()}
2120
{/if}
2221
</div>

src/frontend/src/lib/components/ui/Popover.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import type { HTMLAttributes } from "svelte/elements";
33
import { fade } from "svelte/transition";
44
import Dialog from "$lib/components/ui/Dialog.svelte";
5-
import { nonNullish } from "@dfinity/utils";
65
76
type Direction = "up" | "right" | "down" | "left";
87
type Align = "start" | "center" | "end";
@@ -39,7 +38,7 @@
3938
let tracking = true;
4039
4140
const track = () => {
42-
if (nonNullish(anchorRef) && nonNullish(popoverRef)) {
41+
if (anchorRef !== undefined && popoverRef !== undefined) {
4342
const anchorRect = anchorRef.getBoundingClientRect();
4443
const popoverRect = popoverRef.getBoundingClientRect();
4544

0 commit comments

Comments
 (0)