Skip to content

Commit

Permalink
fix: Allow runtime registered content scripts to not have matches (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 authored Dec 25, 2024
1 parent 88ff40e commit 62525d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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

0 comments on commit 62525d3

Please sign in to comment.