Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(web-extension): Fix types in vite config #1333

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-bulldogs-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rrweb/web-extension': patch
---

Update `vite.config.ts` to account for all potential entry types.
23 changes: 14 additions & 9 deletions packages/web-extension/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand Down
Loading