From 6c7488411ed321f047b23dc8d16bccba86f6bf81 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 23 Oct 2023 16:22:17 -0400 Subject: [PATCH 1/3] fix(web-extension): Fix types in vite config --- packages/web-extension/vite.config.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/web-extension/vite.config.ts b/packages/web-extension/vite.config.ts index 95809cb727..6deff56e9d 100644 --- a/packages/web-extension/vite.config.ts +++ b/packages/web-extension/vite.config.ts @@ -1,9 +1,4 @@ -import { - defineConfig, - LibraryFormats, - LibraryOptions, - PluginOption, -} from 'vite'; +import { defineConfig, LibraryFormats, PluginOption } from 'vite'; import webExtension, { readJsonFile } from 'vite-plugin-web-extension'; import zip from 'vite-plugin-zip-pack'; import * as path from 'path'; @@ -17,9 +12,19 @@ function useSpecialFormat( return { name: 'use-special-format', config(config) { - const shouldUse = entriesToUse.includes( - (config.build?.lib as LibraryOptions)?.entry, - ); + // entry can be string | string[] | {[entryAlias: string]: string} + const entry = config.build?.lib && config.build.lib.entry; + let shouldUse = false; + + if (typeof entry === 'string') { + shouldUse = entriesToUse.includes(entry); + } else if (Array.isArray(entry)) { + shouldUse = entriesToUse.some(e => entry.includes(e)); + } else if (entry && typeof entry === 'object') { + const entryKeys = Object.keys(entry); + shouldUse = entriesToUse.some(e => entryKeys.includes(e)); + } + if (shouldUse) { config.build = config.build ?? {}; // @ts-expect-error: lib needs to be an object, forcing it. From 52aabf78186316245e234be4e26f98bfd137b9aa Mon Sep 17 00:00:00 2001 From: billyvg Date: Mon, 23 Oct 2023 20:24:25 +0000 Subject: [PATCH 2/3] Apply formatting changes --- packages/web-extension/vite.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web-extension/vite.config.ts b/packages/web-extension/vite.config.ts index 6deff56e9d..76d2c631a3 100644 --- a/packages/web-extension/vite.config.ts +++ b/packages/web-extension/vite.config.ts @@ -19,10 +19,10 @@ function useSpecialFormat( if (typeof entry === 'string') { shouldUse = entriesToUse.includes(entry); } else if (Array.isArray(entry)) { - shouldUse = entriesToUse.some(e => entry.includes(e)); + shouldUse = entriesToUse.some((e) => entry.includes(e)); } else if (entry && typeof entry === 'object') { const entryKeys = Object.keys(entry); - shouldUse = entriesToUse.some(e => entryKeys.includes(e)); + shouldUse = entriesToUse.some((e) => entryKeys.includes(e)); } if (shouldUse) { From 618d04f7ac3908a332af475ba5518ca44caa1731 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 23 Oct 2023 16:38:41 -0400 Subject: [PATCH 3/3] changeset --- .changeset/mighty-bulldogs-begin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/mighty-bulldogs-begin.md diff --git a/.changeset/mighty-bulldogs-begin.md b/.changeset/mighty-bulldogs-begin.md new file mode 100644 index 0000000000..b2623ab7c8 --- /dev/null +++ b/.changeset/mighty-bulldogs-begin.md @@ -0,0 +1,5 @@ +--- +'@rrweb/web-extension': patch +--- + +Update `vite.config.ts` to account for all potential entry types.