From 548c85986a2f3e9ebfbe031af08c2d4f5a7a949e Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 26 Aug 2022 10:06:50 +0200 Subject: [PATCH 1/2] refactor --- package.json | 2 +- src/index.ts | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 638a9b3..36440f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@defstudio/vite-livewire-plugin", - "version": "0.2.5", + "version": "0.2.6", "author": { "name": "Fabio Ivona" }, diff --git a/src/index.ts b/src/index.ts index 5cccfc2..c1692e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -245,32 +245,22 @@ export default function livewire(config?: PluginConfig | string | string[]): Liv for (const pattern of pluginConfig.watch) { if (minimatch(ctx.file, pattern)) { - - //Fix unwanted full reloads - if (ctx.modules[0]?.importers && ctx.modules[0].importers.size === 1) { - const dummyModule = {...ctx.modules[0]}; - dummyModule.importers = new Set; - dummyModule.isSelfAccepting = true; - ctx.modules[0].importers.add(dummyModule); - } - - const refreshList = [...pluginConfig.refresh.filter(path => { if(ctx.modules.length === 0 || !ctx.modules[0]){ return true } - let includeInRefresh = true; ctx.modules[0].importers.forEach(importer => { - includeInRefresh = importer.file?.endsWith(path) ?? false; + includeInRefresh = !importer.file?.endsWith(path) ?? false; }); return includeInRefresh; })]; triggerUpdates(ctx, refreshList); - refresh(ctx, pluginConfig) + + return [...ctx.modules[0].importers, ...ctx.modules.slice(1)]; } } } From f3c95901e5bdd433e4b042c4c4f2ef0534a7820d Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 26 Aug 2022 10:09:32 +0200 Subject: [PATCH 2/2] fix tests --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c1692e0..f45380b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -260,7 +260,7 @@ export default function livewire(config?: PluginConfig | string | string[]): Liv triggerUpdates(ctx, refreshList); refresh(ctx, pluginConfig) - return [...ctx.modules[0].importers, ...ctx.modules.slice(1)]; + return [...ctx.modules[0]?.importers ?? [], ...ctx.modules.slice(1)]; } } }