From ec2312f46d0b918ccbfe9e3d61e6f479846dabd6 Mon Sep 17 00:00:00 2001 From: aptt Date: Mon, 16 Dec 2024 19:36:40 +0100 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20=F0=9F=90=9B=20don't=20externa?= =?UTF-8?q?lize=20mirror=20node=20client=20dependency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/lib/hedera/MirrorNodeClient.ts | 2 +- frontend/src/lib/hedera/collection/get.ts | 2 +- frontend/src/lib/hedera/getNfts.ts | 2 +- .../lib/mirrorNode/virtual:mirrorNode.d.ts | 3 --- .../src/lib/mirrorNode/virtualMirrorNode.ts | 19 ------------------- frontend/vite.config.ts | 6 ++++-- 6 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 frontend/src/lib/mirrorNode/virtual:mirrorNode.d.ts delete mode 100644 frontend/src/lib/mirrorNode/virtualMirrorNode.ts diff --git a/frontend/src/lib/hedera/MirrorNodeClient.ts b/frontend/src/lib/hedera/MirrorNodeClient.ts index 8a3f947..06ceb81 100644 --- a/frontend/src/lib/hedera/MirrorNodeClient.ts +++ b/frontend/src/lib/hedera/MirrorNodeClient.ts @@ -1,5 +1,5 @@ import { LedgerId } from '@hashgraph/sdk' -import type { Client, Params } from 'virtual:mirrorNode' +import type { Client, Params } from '@tikz/hedera-mirror-node-ts' export const getMirrorNodeUrl = (ledgerId: LedgerId) => { switch (ledgerId) { diff --git a/frontend/src/lib/hedera/collection/get.ts b/frontend/src/lib/hedera/collection/get.ts index ee5327f..5db6d34 100644 --- a/frontend/src/lib/hedera/collection/get.ts +++ b/frontend/src/lib/hedera/collection/get.ts @@ -1,5 +1,5 @@ import { AccountId, LedgerId } from '@hashgraph/sdk' -import { TokenTypeFilter, tokenUtils as getTokenUtils } from 'virtual:mirrorNode' +import { TokenTypeFilter, tokenUtils as getTokenUtils } from '@tikz/hedera-mirror-node-ts' import { MirrorNodeClient } from '../MirrorNodeClient' export interface TokenInfo { diff --git a/frontend/src/lib/hedera/getNfts.ts b/frontend/src/lib/hedera/getNfts.ts index 5ccff41..72ed93b 100644 --- a/frontend/src/lib/hedera/getNfts.ts +++ b/frontend/src/lib/hedera/getNfts.ts @@ -1,7 +1,7 @@ import { PUBLIC_IPFS_GATEWAY_BASE_URL } from '$env/static/public' import type { IpfsUri, Nft } from '$lib/nft' import { LedgerId, TokenId } from '@hashgraph/sdk' -import { nftUtils as getNftUtils } from 'virtual:mirrorNode' +import { nftUtils as getNftUtils } from '@tikz/hedera-mirror-node-ts' import { MirrorNodeClient } from './MirrorNodeClient' export type GetNfts = (options: { diff --git a/frontend/src/lib/mirrorNode/virtual:mirrorNode.d.ts b/frontend/src/lib/mirrorNode/virtual:mirrorNode.d.ts deleted file mode 100644 index c85193a..0000000 --- a/frontend/src/lib/mirrorNode/virtual:mirrorNode.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'virtual:mirrorNode' { - export * from '@tikz/hedera-mirror-node-ts' -} diff --git a/frontend/src/lib/mirrorNode/virtualMirrorNode.ts b/frontend/src/lib/mirrorNode/virtualMirrorNode.ts deleted file mode 100644 index be5df96..0000000 --- a/frontend/src/lib/mirrorNode/virtualMirrorNode.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { type Plugin } from 'vite' - -/** - * a compatibility layer to import `@tikz/hedera-mirror-node-ts` through vite instead of allowing sveltekit to process it - * - * `@tikz/hedera-mirror-node-ts` can't be imported by node directly because it uses imports without extensions in its dist files. importing through sveltekit code doesn't work because of this, because sveltekit's processing is not as forgiving as vite's. but we can circumvent this by creating a virtual module that uses vite's module resolution to create a working bundle of `@tikz/hedera-mirror-node-ts` (as a pre-bundled dependency). - */ -export const getVirtualMirrorNodePlugin = (): Plugin => { - const virtualModuleId = 'virtual:mirrorNode' - - return { - name: 'virtual-mirror-node', // required, will show up in warnings and errors - async resolveId(id) { - if (id === virtualModuleId) { - return await this.resolve('@tikz/hedera-mirror-node-ts') - } - }, - } -} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 0eb2c4d..434fbc8 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,8 +1,10 @@ import { sveltekit } from '@sveltejs/kit/vite' import { defineConfig } from 'vite' import { getVirtualHashConnectPlugin } from './src/lib/hashconnect/virtualHashConnect' -import { getVirtualMirrorNodePlugin } from './src/lib/mirrorNode/virtualMirrorNode' export default defineConfig({ - plugins: [getVirtualHashConnectPlugin(), getVirtualMirrorNodePlugin(), sveltekit()], + plugins: [getVirtualHashConnectPlugin(), sveltekit()], + ssr: { + noExternal: ['@tikz/hedera-mirror-node-ts'], + }, })