Skip to content

Commit

Permalink
fix: Inline WXT modules inside WxtVitest plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Oct 30, 2023
1 parent a56face commit b75c553
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
WxtDevServer,
} from '~/types';
import * as vite from 'vite';
import { Scripting } from 'webextension-polyfill';
import type { Scripting } from 'webextension-polyfill';
import {
getEntrypointBundlePath,
getEntrypointOutputFile,
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/building/rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manifest } from 'webextension-polyfill';
import type { Manifest } from 'webextension-polyfill';
import { BuildOutput, EntrypointGroup, InternalConfig } from '~/types';
import { findEntrypoints } from './find-entrypoints';
import { generateTypesDir } from './generate-wxt-dir';
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/content-scripts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manifest } from 'webextension-polyfill';
import type { Manifest } from 'webextension-polyfill';
import { ContentScriptEntrypoint, InternalConfig } from '~/types';
import { resolvePerBrowserOption } from './entrypoints';

Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Manifest } from 'webextension-polyfill';
import type { Manifest } from 'webextension-polyfill';
import {
Entrypoint,
BackgroundEntrypoint,
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/testing/fake-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolve } from 'path';
import { faker } from '@faker-js/faker';
import merge from 'lodash.merge';
import { Rollup } from 'vite';
import { Manifest } from 'webextension-polyfill';
import type { Manifest } from 'webextension-polyfill';
import {
FsCache,
InternalConfig,
Expand Down
1 change: 1 addition & 0 deletions src/core/vite-plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './cssEntrypoints';
export * from './bundleAnalysis';
export * from './globals';
export * from './webextensionPolyfillAlias';
export * from './webextensionPolyfillInlineDeps';
24 changes: 24 additions & 0 deletions src/core/vite-plugins/webextensionPolyfillInlineDeps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as vite from 'vite';

/**
* Add all deps that import `webextension-polyfill` to `test.server.deps.inline`.
*
* TODO: Auto-detect non-wxt dependencies via `npm list`.
*/
export function webextensionPolyfillInlineDeps(): vite.PluginOption {
return {
name: 'wxt:testing-inline-deps',
config() {
const wxtModules = ['wxt/browser', 'wxt/client'];
return {
test: {
server: {
deps: {
inline: [...wxtModules],
},
},
},
};
},
};
}
2 changes: 2 additions & 0 deletions src/testing/wxt-vitest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
tsconfigPaths,
globals,
webextensionPolyfillAlias,
webextensionPolyfillInlineDeps,
} from '../core/vite-plugins';
import { getInternalConfig } from '~/core/utils/building';
import { InlineConfig } from '../types';
Expand All @@ -27,6 +28,7 @@ import { InlineConfig } from '../types';
export function WxtVitest(inlineConfig?: InlineConfig): vite.PluginOption {
return getInternalConfig(inlineConfig ?? {}, 'serve').then((config) => [
webextensionPolyfillAlias(config),
webextensionPolyfillInlineDeps(),
unimport(config),
globals(config),
download(config),
Expand Down

0 comments on commit b75c553

Please sign in to comment.