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: Allow runtime registered content scripts to not have matches #1306

Merged
merged 2 commits into from
Dec 25, 2024
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
25 changes: 23 additions & 2 deletions packages/wxt/src/core/utils/__tests__/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ describe('Validation Utils', () => {
expect(actual).toEqual(expected);
});

it("should return an error when content scripts don't have a matches", () => {
it('should return an error when "registration: manifest" content scripts don\'t have matches', () => {
const entrypoint = fakeContentScriptEntrypoint({
options: {
registration: 'manifest',
// @ts-expect-error
matches: null,
},
Expand All @@ -83,7 +84,8 @@ describe('Validation Utils', () => {
errors: [
{
type: 'error',
message: '`matches` is required',
message:
'`matches` is required for manifest registered content scripts',
value: null,
entrypoint,
},
Expand All @@ -96,5 +98,24 @@ describe('Validation Utils', () => {

expect(actual).toEqual(expected);
});

it('should allow "registration: runtime" content scripts to not have matches', () => {
const entrypoint = fakeContentScriptEntrypoint({
options: {
registration: 'runtime',
// @ts-expect-error
matches: null,
},
});
const expected = {
errors: [],
errorCount: 0,
warningCount: 0,
};

const actual = validateEntrypoints([entrypoint]);

expect(actual).toEqual(expected);
});
});
});
7 changes: 5 additions & 2 deletions packages/wxt/src/core/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ function validateContentScriptEntrypoint(
definition: ContentScriptEntrypoint,
): ValidationResult[] {
const errors = validateBaseEntrypoint(definition);
if (definition.options.matches == null) {
if (
definition.options.registration !== 'runtime' &&
definition.options.matches == null
) {
errors.push({
type: 'error',
message: '`matches` is required',
message: '`matches` is required for manifest registered content scripts',
value: definition.options.matches,
entrypoint: definition,
});
Expand Down