From d5739350a74ab6971db432df2f2f6fd1a2183d1b Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 25 Dec 2024 08:38:05 -0600 Subject: [PATCH 1/2] fix: Allow runtime registered content scripts to not have `matches` --- packages/wxt/src/core/utils/validation.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/wxt/src/core/utils/validation.ts b/packages/wxt/src/core/utils/validation.ts index d8189e85a..331fe80a6 100644 --- a/packages/wxt/src/core/utils/validation.ts +++ b/packages/wxt/src/core/utils/validation.ts @@ -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, }); From 1499304e87f00e6cc809bf95c1d00f921473e093 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 25 Dec 2024 09:21:21 -0600 Subject: [PATCH 2/2] Add tests --- .../core/utils/__tests__/validation.test.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/wxt/src/core/utils/__tests__/validation.test.ts b/packages/wxt/src/core/utils/__tests__/validation.test.ts index 9ca603fc1..24f6fed71 100644 --- a/packages/wxt/src/core/utils/__tests__/validation.test.ts +++ b/packages/wxt/src/core/utils/__tests__/validation.test.ts @@ -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, }, @@ -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, }, @@ -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); + }); }); });