From 22a8751de8d5a7390cb94b97de4ed6464df271d8 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Thu, 5 Aug 2021 19:22:00 +0800 Subject: [PATCH] fix: hot reload for plugins --- packages/maskbook/src/plugins/Airdrop/index.ts | 5 +++-- packages/maskbook/src/plugins/Collectible/index.ts | 5 +++-- packages/maskbook/src/plugins/External/index.ts | 2 +- packages/maskbook/src/plugins/FileService/Worker/rpc.ts | 2 +- packages/maskbook/src/plugins/FileService/index.ts | 4 ++-- packages/maskbook/src/plugins/Gitcoin/index.ts | 5 +++-- packages/maskbook/src/plugins/GoodGhosting/index.ts | 2 +- packages/maskbook/src/plugins/ITO/index.ts | 5 +++-- packages/maskbook/src/plugins/NFT/index.ts | 2 +- packages/maskbook/src/plugins/Polls/index.ts | 5 +++-- packages/maskbook/src/plugins/PoolTogether/index.ts | 8 +++++--- packages/maskbook/src/plugins/PoolTogether/messages.ts | 2 +- packages/maskbook/src/plugins/RedPacket/index.ts | 5 +++-- packages/maskbook/src/plugins/Snapshot/index.ts | 5 +++-- packages/maskbook/src/plugins/Trader/index.ts | 8 +++++--- packages/maskbook/src/plugins/Transak/index.ts | 5 +++-- packages/maskbook/src/plugins/VCent/index.ts | 2 +- packages/maskbook/src/plugins/Wallet/index.ts | 8 +++++--- packages/maskbook/src/plugins/dHEDGE/index.ts | 8 +++++--- packages/plugin-infra/src/types.ts | 4 ++-- packages/plugins/example/src/index.ts | 8 +++++--- 21 files changed, 59 insertions(+), 41 deletions(-) diff --git a/packages/maskbook/src/plugins/Airdrop/index.ts b/packages/maskbook/src/plugins/Airdrop/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/Airdrop/index.ts +++ b/packages/maskbook/src/plugins/Airdrop/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/Collectible/index.ts b/packages/maskbook/src/plugins/Collectible/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/Collectible/index.ts +++ b/packages/maskbook/src/plugins/Collectible/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/External/index.ts b/packages/maskbook/src/plugins/External/index.ts index b01b58f92969..83cbdd00cbaf 100644 --- a/packages/maskbook/src/plugins/External/index.ts +++ b/packages/maskbook/src/plugins/External/index.ts @@ -6,6 +6,6 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, }) diff --git a/packages/maskbook/src/plugins/FileService/Worker/rpc.ts b/packages/maskbook/src/plugins/FileService/Worker/rpc.ts index 43dcbc3571eb..73d64b1f70a0 100644 --- a/packages/maskbook/src/plugins/FileService/Worker/rpc.ts +++ b/packages/maskbook/src/plugins/FileService/Worker/rpc.ts @@ -1,7 +1,7 @@ import { createPluginMessage, createPluginRPC, createPluginRPCGenerator } from '@masknet/plugin-infra' import { FileServicePluginID } from '../constants' -import.meta.webpackHot?.accept() +import.meta.webpackHot && import.meta.webpackHot.accept() const PluginFileServiceMessage = createPluginMessage<{ _: unknown; _2: unknown }>(FileServicePluginID) diff --git a/packages/maskbook/src/plugins/FileService/index.ts b/packages/maskbook/src/plugins/FileService/index.ts index a902f2667183..69226b786ae4 100644 --- a/packages/maskbook/src/plugins/FileService/index.ts +++ b/packages/maskbook/src/plugins/FileService/index.ts @@ -6,13 +6,13 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => { - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))) + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))) }, }, Worker: { load: () => import('./Worker'), hotModuleReload: (hot) => { - import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))) + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))) }, }, }) diff --git a/packages/maskbook/src/plugins/Gitcoin/index.ts b/packages/maskbook/src/plugins/Gitcoin/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/Gitcoin/index.ts +++ b/packages/maskbook/src/plugins/Gitcoin/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/GoodGhosting/index.ts b/packages/maskbook/src/plugins/GoodGhosting/index.ts index b01b58f92969..83cbdd00cbaf 100644 --- a/packages/maskbook/src/plugins/GoodGhosting/index.ts +++ b/packages/maskbook/src/plugins/GoodGhosting/index.ts @@ -6,6 +6,6 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, }) diff --git a/packages/maskbook/src/plugins/ITO/index.ts b/packages/maskbook/src/plugins/ITO/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/ITO/index.ts +++ b/packages/maskbook/src/plugins/ITO/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/NFT/index.ts b/packages/maskbook/src/plugins/NFT/index.ts index b01b58f92969..83cbdd00cbaf 100644 --- a/packages/maskbook/src/plugins/NFT/index.ts +++ b/packages/maskbook/src/plugins/NFT/index.ts @@ -6,6 +6,6 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, }) diff --git a/packages/maskbook/src/plugins/Polls/index.ts b/packages/maskbook/src/plugins/Polls/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/Polls/index.ts +++ b/packages/maskbook/src/plugins/Polls/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/PoolTogether/index.ts b/packages/maskbook/src/plugins/PoolTogether/index.ts index eb9e9bec4a7c..1d5f0d92d308 100644 --- a/packages/maskbook/src/plugins/PoolTogether/index.ts +++ b/packages/maskbook/src/plugins/PoolTogether/index.ts @@ -6,14 +6,16 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Dashboard: { load: () => import('./Dashboard'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Dashboard', () => hot(import('./Dashboard'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/PoolTogether/messages.ts b/packages/maskbook/src/plugins/PoolTogether/messages.ts index 96b8fbee8b0e..3efbabbd8a09 100644 --- a/packages/maskbook/src/plugins/PoolTogether/messages.ts +++ b/packages/maskbook/src/plugins/PoolTogether/messages.ts @@ -18,7 +18,7 @@ interface PoolTogetherMessages { rpc: unknown } -import.meta.webpackHot?.accept() +import.meta.webpackHot && import.meta.webpackHot.accept() export const PluginPoolTogetherMessages: PluginMessageEmitter = createPluginMessage(POOLTOGETHER_PLUGIN_ID) diff --git a/packages/maskbook/src/plugins/RedPacket/index.ts b/packages/maskbook/src/plugins/RedPacket/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/RedPacket/index.ts +++ b/packages/maskbook/src/plugins/RedPacket/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/Snapshot/index.ts b/packages/maskbook/src/plugins/Snapshot/index.ts index 7dc296937177..eb51ba0afe25 100644 --- a/packages/maskbook/src/plugins/Snapshot/index.ts +++ b/packages/maskbook/src/plugins/Snapshot/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/Trader/index.ts b/packages/maskbook/src/plugins/Trader/index.ts index eb9e9bec4a7c..1d5f0d92d308 100644 --- a/packages/maskbook/src/plugins/Trader/index.ts +++ b/packages/maskbook/src/plugins/Trader/index.ts @@ -6,14 +6,16 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Dashboard: { load: () => import('./Dashboard'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Dashboard', () => hot(import('./Dashboard'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/Transak/index.ts b/packages/maskbook/src/plugins/Transak/index.ts index 84cda5fdf2dd..b1504a953b49 100644 --- a/packages/maskbook/src/plugins/Transak/index.ts +++ b/packages/maskbook/src/plugins/Transak/index.ts @@ -6,10 +6,11 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Dashboard: { load: () => import('./Dashboard'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Dashboard', () => hot(import('./Dashboard'))), }, }) diff --git a/packages/maskbook/src/plugins/VCent/index.ts b/packages/maskbook/src/plugins/VCent/index.ts index b01b58f92969..83cbdd00cbaf 100644 --- a/packages/maskbook/src/plugins/VCent/index.ts +++ b/packages/maskbook/src/plugins/VCent/index.ts @@ -6,6 +6,6 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, }) diff --git a/packages/maskbook/src/plugins/Wallet/index.ts b/packages/maskbook/src/plugins/Wallet/index.ts index 438d31429ffd..ffe51733e1cf 100644 --- a/packages/maskbook/src/plugins/Wallet/index.ts +++ b/packages/maskbook/src/plugins/Wallet/index.ts @@ -6,14 +6,16 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Dashboard: { load: () => import('./Dashboard'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Dashboard', () => hot(import('./Dashboard'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/maskbook/src/plugins/dHEDGE/index.ts b/packages/maskbook/src/plugins/dHEDGE/index.ts index eb9e9bec4a7c..1d5f0d92d308 100644 --- a/packages/maskbook/src/plugins/dHEDGE/index.ts +++ b/packages/maskbook/src/plugins/dHEDGE/index.ts @@ -6,14 +6,16 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Dashboard: { load: () => import('./Dashboard'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Dashboard', () => hot(import('./Dashboard'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, }) diff --git a/packages/plugin-infra/src/types.ts b/packages/plugin-infra/src/types.ts index f452eb156c56..bde6003d9327 100644 --- a/packages/plugin-infra/src/types.ts +++ b/packages/plugin-infra/src/types.ts @@ -13,7 +13,7 @@ export namespace Plugin { * ```ts * const loader = { * load: () => import('./code'), - * hotModuleReload: hot => import.meta.webpackHot?.accept('./code', () => hot(import('./code'))) + * hotModuleReload: hot => import.meta.webpackHot && import.meta.webpackHot.accept('./code', () => hot(import('./code'))) * } * ``` * @@ -32,7 +32,7 @@ export namespace Plugin { /** * This provides the functionality for hot module reload on the plugin. * When the callback is called, the old instance of the plugin will be unloaded, then the new instance will be init. - * @example hotModuleReload: hot => import.meta.webpackHot?.accept('./path', () => hot(import('./path'))) + * @example hotModuleReload: hot => import.meta.webpackHot && import.meta.webpackHot.accept('./path', () => hot(import('./path'))) */ hotModuleReload(onHot: (hot: Promise<{ default: DeferredModule }>) => void): void } diff --git a/packages/plugins/example/src/index.ts b/packages/plugins/example/src/index.ts index eb9e9bec4a7c..1d5f0d92d308 100644 --- a/packages/plugins/example/src/index.ts +++ b/packages/plugins/example/src/index.ts @@ -6,14 +6,16 @@ registerPlugin({ SNSAdaptor: { load: () => import('./SNSAdaptor'), hotModuleReload: (hot) => - import.meta.webpackHot?.accept('./SNSAdaptor/index', () => hot(import('./SNSAdaptor'))), + import.meta.webpackHot && import.meta.webpackHot.accept('./SNSAdaptor', () => hot(import('./SNSAdaptor'))), }, Dashboard: { load: () => import('./Dashboard'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Dashboard/index', () => hot(import('./Dashboard'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Dashboard', () => hot(import('./Dashboard'))), }, Worker: { load: () => import('./Worker'), - hotModuleReload: (hot) => import.meta.webpackHot?.accept('./Worker/index', () => hot(import('./Worker'))), + hotModuleReload: (hot) => + import.meta.webpackHot && import.meta.webpackHot.accept('./Worker', () => hot(import('./Worker'))), }, })