Skip to content

feat: add WXT plugin#1580

Open
adelin-b wants to merge 1 commit intowebpro-nl:mainfrom
adelin-b:feat/wxt-plugin
Open

feat: add WXT plugin#1580
adelin-b wants to merge 1 commit intowebpro-nl:mainfrom
adelin-b:feat/wxt-plugin

Conversation

@adelin-b
Copy link
Copy Markdown

@adelin-b adelin-b commented Mar 1, 2026

Summary

  • Adds a new plugin for WXT (Web Extension Framework)
  • Resolves modules array entries in wxt.config.ts as dependencies
  • Defines entrypoints/**/* as entry file patterns
  • Prevents false positive "unused dependency" reports for WXT modules (e.g. @wxt-dev/module-react, wxt-module-console-forward)

Motivation

WXT uses a modules array in wxt.config.ts similar to Nuxt's module system. Without this plugin, knip reports these modules as unused devDependencies because they're only referenced in the WXT config and never directly imported in source code.

Implementation

Follows the same pattern as the Nuxt plugin:

  • setup() defines a global defineConfig helper so knip can load the config
  • resolveConfig() extracts string entries from the modules array as dependencies
  • Entry patterns match WXT's conventional entrypoints/ directory

Test plan

  • Plugin test passes (node --test test/plugins/wxt.test.ts)
  • Correctly identifies unused dependencies not in modules
  • Does not flag modules listed in wxt.config.ts as unused

Add plugin for WXT (Web Extension Framework) that:
- Resolves modules from the `modules` array in wxt.config.ts as dependencies
- Defines entrypoints/**/* as entry file patterns
- Enables automatic detection when `wxt` is a dependency

This prevents false positive "unused dependency" reports for WXT modules
like `@wxt-dev/module-react` and `wxt-module-console-forward` that are
referenced in the WXT config but not directly imported in source code.
Copy link
Copy Markdown
Member

@webpro webpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Happy to merge, left a few remarks though.

import { hasDependency } from '../../util/plugin.ts';
import type { WxtConfig } from './types.ts';

// https://wxt.dev/guide/configuration.html
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

404

Comment on lines +17 to +19
const entry = ['entrypoints/**/*.{ts,tsx,js,jsx,html}'];

const production = ['entrypoints/**/*.{ts,tsx,js,jsx,html}'];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Production entries are entry points in default mode as well:

Suggested change
const entry = ['entrypoints/**/*.{ts,tsx,js,jsx,html}'];
const production = ['entrypoints/**/*.{ts,tsx,js,jsx,html}'];
const production = ['entrypoints/**/*'];

This glob should target all files, right?

https://wxt.dev/guide/essentials/entrypoints.html

localConfig?.modules?.reduce<Input[]>((acc, id) => {
if (typeof id === 'string') acc.push(toDependency(id));
return acc;
}, []) ?? [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit hard to read. Perhaps a for..of iteration can do the job.

assert.deepEqual(counters, {
...baseCounters,
files: 1,
dependencies: 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally there are no unused files, as both the config file and the entry point should be consumed by the plugin.

@webpro webpro mentioned this pull request Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants