From d673de263da760697f77aba3e26131acb541e42d Mon Sep 17 00:00:00 2001 From: Ruben Medina Date: Sun, 9 Apr 2023 16:20:01 -0700 Subject: [PATCH] feat!: optimize web accessible resources (#89) adds an optimizeWebAccessibleResources option that, in Manifest V3, will merge web accessible resource definitions that have matching non-`resource` properties and dedupe and sort `resources`. In Manifest V2, will sort web accessible resources. --- README.md | 6 + src/manifestParser/manifestParser.ts | 8 + src/manifestParser/manifestV2.ts | 13 + src/manifestParser/manifestV3.ts | 35 +++ ...InputsScriptsChunkedImport.v2.test.ts.snap | 4 +- ...InputsScriptsChunkedImport.v3.test.ts.snap | 13 +- ...ionalInputsScriptsNoImport.v3.test.ts.snap | 10 +- ...ditionalInputsScriptsTypes.v3.test.ts.snap | 10 +- ...putsScriptsUnchunkedImport.v3.test.ts.snap | 10 +- ...dditionalInputsStylesTypes.v3.test.ts.snap | 10 +- ...itionalInputsWebAccessible.v2.test.ts.snap | 16 +- ...itionalInputsWebAccessible.v3.test.ts.snap | 49 +-- ...AccessibleExcludeEntryFile.v2.test.ts.snap | 14 +- ...AccessibleExcludeEntryFile.v3.test.ts.snap | 58 +--- .../chunkCssRewrite.v2.test.ts.snap | 4 +- .../chunkCssRewrite.v3.test.ts.snap | 10 - .../contentScriptPaths.v2.test.ts.snap | 2 +- .../contentScriptPaths.v3.test.ts.snap | 14 +- .../contentWithChunkedImport.v2.test.ts.snap | 2 +- .../contentWithChunkedImport.v3.test.ts.snap | 18 +- .../contentWithDynamicImport.v2.test.ts.snap | 2 +- .../contentWithDynamicImport.v3.test.ts.snap | 18 +- .../fullExtension.v2.test.ts.snap | 6 +- ...ccessibleResourcesDisabled.v2.test.ts.snap | 261 +++++++++++++++ ...ccessibleResourcesDisabled.v3.test.ts.snap | 296 ++++++++++++++++++ ...AccessibleResourcesEnabled.v2.test.ts.snap | 261 +++++++++++++++ ...AccessibleResourcesEnabled.v3.test.ts.snap | 269 ++++++++++++++++ ...ccessibleResourcesDisabled.v3.test.ts.snap | 32 +- ...AccessibleResourcesEnabled.v3.test.ts.snap | 35 +-- ...eWebAccessibleResourcesDisabled.v2.test.ts | 25 ++ ...eWebAccessibleResourcesDisabled.v3.test.ts | 25 ++ ...zeWebAccessibleResourcesEnabled.v2.test.ts | 24 ++ ...zeWebAccessibleResourcesEnabled.v3.test.ts | 24 ++ .../content1.js | 3 + .../content2.js | 3 + .../optimizeWebAccessibleResources/script1.js | 3 + .../optimizeWebAccessibleResources/script2.js | 3 + types/index.d.ts | 16 +- 38 files changed, 1331 insertions(+), 281 deletions(-) create mode 100644 test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v2.test.ts.snap create mode 100644 test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v3.test.ts.snap create mode 100644 test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v2.test.ts.snap create mode 100644 test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v3.test.ts.snap create mode 100644 test/manifest/optimizeWebAccessibleResourcesDisabled.v2.test.ts create mode 100644 test/manifest/optimizeWebAccessibleResourcesDisabled.v3.test.ts create mode 100644 test/manifest/optimizeWebAccessibleResourcesEnabled.v2.test.ts create mode 100644 test/manifest/optimizeWebAccessibleResourcesEnabled.v3.test.ts create mode 100644 test/manifest/resources/optimizeWebAccessibleResources/content1.js create mode 100644 test/manifest/resources/optimizeWebAccessibleResources/content2.js create mode 100644 test/manifest/resources/optimizeWebAccessibleResources/script1.js create mode 100644 test/manifest/resources/optimizeWebAccessibleResources/script2.js diff --git a/README.md b/README.md index 91ed66c..ac6ee00 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,12 @@ useDynamicUrlWebAccessibleResources (optional) - Default: `true` - Adds the `use_dynamic_url` property to web accessible resources generated by the plugin +optimizeWebAccessibleResources (optional) + +- Type: `boolean` +- Default: `true` +- On build, in Manifest V3, merge web accessible resource definitions that have matching non-`resource` properties and dedupe and sort `resources`. In Manifest V2, sort web accessible resources. + devHtmlTransform (optional) - Type: `boolean` diff --git a/src/manifestParser/manifestParser.ts b/src/manifestParser/manifestParser.ts index 815bb1c..b7064db 100644 --- a/src/manifestParser/manifestParser.ts +++ b/src/manifestParser/manifestParser.ts @@ -80,6 +80,10 @@ export default abstract class ManifestParser< result = await parseMethod(result, bundle); } + if (this.pluginOptions.optimizeWebAccessibleResources !== false) { + result = this.optimizeWebAccessibleResources(result); + } + result.emitFiles.push({ type: "asset", fileName: "manifest.json", @@ -116,6 +120,10 @@ export default abstract class ManifestParser< bundle: OutputBundle ): Promise>; + protected abstract optimizeWebAccessibleResources( + result: ParseResult + ): ParseResult; + protected parseInputAdditionalInputs( result: ParseResult ): ParseResult { diff --git a/src/manifestParser/manifestV2.ts b/src/manifestParser/manifestV2.ts index 8d2c634..049cb15 100644 --- a/src/manifestParser/manifestV2.ts +++ b/src/manifestParser/manifestV2.ts @@ -120,4 +120,17 @@ export default class ManifestV2 extends ManifestParser { return result; } + + protected optimizeWebAccessibleResources( + result: ParseResult + ): ParseResult { + if (!result.manifest.web_accessible_resources) { + return result; + } + + result.manifest.web_accessible_resources = + result.manifest.web_accessible_resources.sort(); + + return result; + } } diff --git a/src/manifestParser/manifestV3.ts b/src/manifestParser/manifestV3.ts index 33ff29a..f5eff65 100644 --- a/src/manifestParser/manifestV3.ts +++ b/src/manifestParser/manifestV3.ts @@ -207,4 +207,39 @@ export default class ManifestV3 extends ManifestParser { return result; } + + protected optimizeWebAccessibleResources( + result: ParseResult + ): ParseResult { + if (!result.manifest.web_accessible_resources) { + return result; + } + + const resourceMap = new Map(); + + result.manifest.web_accessible_resources.forEach((resource) => { + const resourceKey = JSON.stringify({ + ...resource, + resources: [], + }); + + if (resourceMap.has(resourceKey)) { + const existingEntry = resourceMap.get(resourceKey); + + resourceMap.set(resourceKey, { + ...existingEntry, + ...resource, + resources: [ + ...new Set([...existingEntry.resources, ...resource.resources]), + ].sort(), + }); + } else { + resourceMap.set(resourceKey, resource); + } + }); + + result.manifest.web_accessible_resources = [...resourceMap.values()]; + + return result; + } } diff --git a/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v2.test.ts.snap b/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v2.test.ts.snap index 11765ee..e822cbf 100644 --- a/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v2.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v2.test.ts.snap @@ -140,10 +140,10 @@ export { \\"name\\": \\"Manifest Name\\", \\"manifest_version\\": 2, \\"web_accessible_resources\\": [ - \\"assets/test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", + \\"assets/test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", \\"assets/test/manifest/resources/additionalInputsScriptsChunkedImport/script2.js\\", + \\"test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", \\"test/manifest/resources/additionalInputsScriptsChunkedImport/script2.js\\" ] }", diff --git a/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v3.test.ts.snap index b64cfa6..4faaa30 100644 --- a/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsScriptsChunkedImport.v3.test.ts.snap @@ -142,19 +142,10 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"assets/test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"assets/test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", \\"assets/test/manifest/resources/additionalInputsScriptsChunkedImport/script2.js\\", - \\"assets/log.js\\", + \\"test/manifest/resources/additionalInputsScriptsChunkedImport/script1.js\\", \\"test/manifest/resources/additionalInputsScriptsChunkedImport/script2.js\\" ], \\"matches\\": [ diff --git a/test/manifest/__snapshots__/additionalInputsScriptsNoImport.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsScriptsNoImport.v3.test.ts.snap index 02ce150..cdb1c8a 100644 --- a/test/manifest/__snapshots__/additionalInputsScriptsNoImport.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsScriptsNoImport.v3.test.ts.snap @@ -26,15 +26,7 @@ exports[`additionalInputsScriptsNoImport - Manifest V3 1`] = ` \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsScriptsNoImport/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"test/manifest/resources/additionalInputsScriptsNoImport/script1.js\\", \\"test/manifest/resources/additionalInputsScriptsNoImport/script2.js\\" ], \\"matches\\": [ diff --git a/test/manifest/__snapshots__/additionalInputsScriptsTypes.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsScriptsTypes.v3.test.ts.snap index e945f22..e043c85 100644 --- a/test/manifest/__snapshots__/additionalInputsScriptsTypes.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsScriptsTypes.v3.test.ts.snap @@ -26,15 +26,7 @@ exports[`additionalInputsScriptsTypes - Manifest V3 1`] = ` \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsScriptsTypes/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"test/manifest/resources/additionalInputsScriptsTypes/script1.js\\", \\"test/manifest/resources/additionalInputsScriptsTypes/script2.js\\" ], \\"matches\\": [ diff --git a/test/manifest/__snapshots__/additionalInputsScriptsUnchunkedImport.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsScriptsUnchunkedImport.v3.test.ts.snap index c1d2d5c..f016754 100644 --- a/test/manifest/__snapshots__/additionalInputsScriptsUnchunkedImport.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsScriptsUnchunkedImport.v3.test.ts.snap @@ -29,15 +29,7 @@ log(\\"script1\\"); \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsScriptsUnchunkedImport/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"test/manifest/resources/additionalInputsScriptsUnchunkedImport/script1.js\\", \\"test/manifest/resources/additionalInputsScriptsUnchunkedImport/script2.js\\" ], \\"matches\\": [ diff --git a/test/manifest/__snapshots__/additionalInputsStylesTypes.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsStylesTypes.v3.test.ts.snap index f64efb8..a4d1d26 100644 --- a/test/manifest/__snapshots__/additionalInputsStylesTypes.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsStylesTypes.v3.test.ts.snap @@ -29,15 +29,7 @@ exports[`additionalInputsStylesTypes - Manifest V3 1`] = ` \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsStylesTypes/style1.css\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"test/manifest/resources/additionalInputsStylesTypes/style1.css\\", \\"test/manifest/resources/additionalInputsStylesTypes/style2.css\\" ], \\"matches\\": [ diff --git a/test/manifest/__snapshots__/additionalInputsWebAccessible.v2.test.ts.snap b/test/manifest/__snapshots__/additionalInputsWebAccessible.v2.test.ts.snap index eb95cfb..4ae96b5 100644 --- a/test/manifest/__snapshots__/additionalInputsWebAccessible.v2.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsWebAccessible.v2.test.ts.snap @@ -219,17 +219,17 @@ export { \\"name\\": \\"Manifest Name\\", \\"manifest_version\\": 2, \\"web_accessible_resources\\": [ - \\"test/manifest/resources/additionalInputsWebAccessible/script1.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/script3.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/script4.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\", - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\" + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script1.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script3.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script4.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\" ] }", "type": "asset", diff --git a/test/manifest/__snapshots__/additionalInputsWebAccessible.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsWebAccessible.v3.test.ts.snap index 6d246a6..faa976a 100644 --- a/test/manifest/__snapshots__/additionalInputsWebAccessible.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsWebAccessible.v3.test.ts.snap @@ -221,15 +221,7 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsWebAccessible/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"test/manifest/resources/additionalInputsWebAccessible/script1.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script3.js\\" ], \\"matches\\": [ @@ -239,38 +231,12 @@ export { }, { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsWebAccessible/script4.js\\" - ], - \\"matches\\": [ - \\"https://example.com/\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\" - ], - \\"extension_ids\\": [ - \\"oilkjaldkfjlasdf\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\" - ], - \\"matches\\": [ - \\"https://example.com/\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", - \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\" + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script4.js\\" ], \\"matches\\": [ \\"https://example.com/\\" @@ -279,9 +245,10 @@ export { }, { \\"resources\\": [ - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\" + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\" ], \\"extension_ids\\": [ \\"oilkjaldkfjlasdf\\" diff --git a/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v2.test.ts.snap b/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v2.test.ts.snap index 23ba00e..c1f928a 100644 --- a/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v2.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v2.test.ts.snap @@ -233,17 +233,17 @@ export { \\"name\\": \\"Manifest Name\\", \\"manifest_version\\": 2, \\"web_accessible_resources\\": [ + \\"assets/log.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script1.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script2.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script3.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/script6.js\\", - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", - \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\" + \\"test/manifest/resources/additionalInputsWebAccessible/script6.js\\" ] }", "type": "asset", diff --git a/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v3.test.ts.snap b/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v3.test.ts.snap index f879d54..1576473 100644 --- a/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v3.test.ts.snap +++ b/test/manifest/__snapshots__/additionalInputsWebAccessibleExcludeEntryFile.v3.test.ts.snap @@ -244,15 +244,13 @@ export { }, { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsWebAccessible/script2.js\\" - ], - \\"matches\\": [ - \\"https://example.com/\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"assets/log.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", + \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", + \\"test/manifest/resources/additionalInputsWebAccessible/script2.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script3.js\\" ], \\"matches\\": [ @@ -262,53 +260,13 @@ export { }, { \\"resources\\": [ - \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\" - ], - \\"extension_ids\\": [ - \\"oilkjaldkfjlasdf\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ + \\"test/manifest/resources/additionalInputsWebAccessible/script5.js\\", \\"test/manifest/resources/additionalInputsWebAccessible/script6.js\\" ], \\"extension_ids\\": [ \\"oilkjaldkfjlasdf\\" ], \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\", - \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript1.js\\" - ], - \\"matches\\": [ - \\"https://example.com/\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\", - \\"assets/log.js\\", - \\"test/manifest/resources/additionalInputsWebAccessible/chunkedScript2.js\\" - ], - \\"matches\\": [ - \\"https://example.com/\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/additionalInputsWebAccessible/chunkedScript3.js\\", - \\"assets/log.js\\" - ], - \\"matches\\": [ - \\"https://example.com/\\" - ], - \\"use_dynamic_url\\": true } ] }", diff --git a/test/manifest/__snapshots__/chunkCssRewrite.v2.test.ts.snap b/test/manifest/__snapshots__/chunkCssRewrite.v2.test.ts.snap index 7a37463..dc7a95b 100644 --- a/test/manifest/__snapshots__/chunkCssRewrite.v2.test.ts.snap +++ b/test/manifest/__snapshots__/chunkCssRewrite.v2.test.ts.snap @@ -90,8 +90,8 @@ console.log([\\"assets/content2.css\\",\\"assets/contentShared.css\\"]); ], \\"web_accessible_resources\\": [ \\"assets/content1.css\\", - \\"assets/contentShared.css\\", - \\"assets/content2.css\\" + \\"assets/content2.css\\", + \\"assets/contentShared.css\\" ] }", "type": "asset", diff --git a/test/manifest/__snapshots__/chunkCssRewrite.v3.test.ts.snap b/test/manifest/__snapshots__/chunkCssRewrite.v3.test.ts.snap index b5a4b0e..9e72236 100644 --- a/test/manifest/__snapshots__/chunkCssRewrite.v3.test.ts.snap +++ b/test/manifest/__snapshots__/chunkCssRewrite.v3.test.ts.snap @@ -92,16 +92,6 @@ console.log([\\"assets/content2.css\\",\\"assets/contentShared.css\\"]); { \\"resources\\": [ \\"assets/content1.css\\", - \\"assets/contentShared.css\\" - ], - \\"matches\\": [ - \\"https://*/*\\", - \\"http://*/*\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ \\"assets/content2.css\\", \\"assets/contentShared.css\\" ], diff --git a/test/manifest/__snapshots__/contentScriptPaths.v2.test.ts.snap b/test/manifest/__snapshots__/contentScriptPaths.v2.test.ts.snap index 1d948f1..018f358 100644 --- a/test/manifest/__snapshots__/contentScriptPaths.v2.test.ts.snap +++ b/test/manifest/__snapshots__/contentScriptPaths.v2.test.ts.snap @@ -160,8 +160,8 @@ export { } ], \\"web_accessible_resources\\": [ - \\"assets/test/manifest/resources/contentWithChunkedImport/content1.js\\", \\"assets/log.js\\", + \\"assets/test/manifest/resources/contentWithChunkedImport/content1.js\\", \\"assets/test/manifest/resources/contentWithChunkedImport/content2.js\\" ] }", diff --git a/test/manifest/__snapshots__/contentScriptPaths.v3.test.ts.snap b/test/manifest/__snapshots__/contentScriptPaths.v3.test.ts.snap index c218b82..23308ae 100644 --- a/test/manifest/__snapshots__/contentScriptPaths.v3.test.ts.snap +++ b/test/manifest/__snapshots__/contentScriptPaths.v3.test.ts.snap @@ -162,19 +162,9 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ + \\"assets/log.js\\", \\"assets/test/manifest/resources/contentWithChunkedImport/content1.js\\", - \\"assets/log.js\\" - ], - \\"matches\\": [ - \\"https://*/*\\", - \\"http://*/*\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/contentWithChunkedImport/content2.js\\", - \\"assets/log.js\\" + \\"assets/test/manifest/resources/contentWithChunkedImport/content2.js\\" ], \\"matches\\": [ \\"https://*/*\\", diff --git a/test/manifest/__snapshots__/contentWithChunkedImport.v2.test.ts.snap b/test/manifest/__snapshots__/contentWithChunkedImport.v2.test.ts.snap index 5fb967d..3972f02 100644 --- a/test/manifest/__snapshots__/contentWithChunkedImport.v2.test.ts.snap +++ b/test/manifest/__snapshots__/contentWithChunkedImport.v2.test.ts.snap @@ -160,8 +160,8 @@ export { } ], \\"web_accessible_resources\\": [ - \\"assets/test/manifest/resources/contentWithChunkedImport/content1.js\\", \\"assets/log.js\\", + \\"assets/test/manifest/resources/contentWithChunkedImport/content1.js\\", \\"assets/test/manifest/resources/contentWithChunkedImport/content2.js\\" ] }", diff --git a/test/manifest/__snapshots__/contentWithChunkedImport.v3.test.ts.snap b/test/manifest/__snapshots__/contentWithChunkedImport.v3.test.ts.snap index 61c11e7..1c442ea 100644 --- a/test/manifest/__snapshots__/contentWithChunkedImport.v3.test.ts.snap +++ b/test/manifest/__snapshots__/contentWithChunkedImport.v3.test.ts.snap @@ -170,23 +170,9 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ + \\"assets/log.js\\", \\"assets/test/manifest/resources/contentWithChunkedImport/content1.js\\", - \\"assets/log.js\\" - ], - \\"matches\\": [ - \\"*://*/*\\", - \\"https://*/*\\", - \\"*://example.com/\\", - \\"https://example.com/\\", - \\"*://example.com/*\\", - \\"https://example.com/*\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/contentWithChunkedImport/content2.js\\", - \\"assets/log.js\\" + \\"assets/test/manifest/resources/contentWithChunkedImport/content2.js\\" ], \\"matches\\": [ \\"*://*/*\\", diff --git a/test/manifest/__snapshots__/contentWithDynamicImport.v2.test.ts.snap b/test/manifest/__snapshots__/contentWithDynamicImport.v2.test.ts.snap index 568f717..5796419 100644 --- a/test/manifest/__snapshots__/contentWithDynamicImport.v2.test.ts.snap +++ b/test/manifest/__snapshots__/contentWithDynamicImport.v2.test.ts.snap @@ -164,8 +164,8 @@ export { } ], \\"web_accessible_resources\\": [ - \\"assets/test/manifest/resources/contentWithDynamicImport/content1.js\\", \\"assets/log.js\\", + \\"assets/test/manifest/resources/contentWithDynamicImport/content1.js\\", \\"assets/test/manifest/resources/contentWithDynamicImport/content2.js\\" ] }", diff --git a/test/manifest/__snapshots__/contentWithDynamicImport.v3.test.ts.snap b/test/manifest/__snapshots__/contentWithDynamicImport.v3.test.ts.snap index ac3efd1..95035c8 100644 --- a/test/manifest/__snapshots__/contentWithDynamicImport.v3.test.ts.snap +++ b/test/manifest/__snapshots__/contentWithDynamicImport.v3.test.ts.snap @@ -174,23 +174,9 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ + \\"assets/log.js\\", \\"assets/test/manifest/resources/contentWithDynamicImport/content1.js\\", - \\"assets/log.js\\" - ], - \\"matches\\": [ - \\"*://*/*\\", - \\"https://*/*\\", - \\"*://example.com/\\", - \\"https://example.com/\\", - \\"*://example.com/*\\", - \\"https://example.com/*\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/contentWithDynamicImport/content2.js\\", - \\"assets/log.js\\" + \\"assets/test/manifest/resources/contentWithDynamicImport/content2.js\\" ], \\"matches\\": [ \\"*://*/*\\", diff --git a/test/manifest/__snapshots__/fullExtension.v2.test.ts.snap b/test/manifest/__snapshots__/fullExtension.v2.test.ts.snap index fcceac0..cc97e39 100644 --- a/test/manifest/__snapshots__/fullExtension.v2.test.ts.snap +++ b/test/manifest/__snapshots__/fullExtension.v2.test.ts.snap @@ -3409,11 +3409,11 @@ img { \\"*://*/*\\" ], \\"web_accessible_resources\\": [ - \\"test/manifest/resources/fullExtension/src/lib.js\\", - \\"assets/test/manifest/resources/fullExtension/src/entries/contentScript/primary/main.js\\", \\"assets/logo.js\\", \\"assets/logo.svg\\", - \\"assets/main.css\\" + \\"assets/main.css\\", + \\"assets/test/manifest/resources/fullExtension/src/entries/contentScript/primary/main.js\\", + \\"test/manifest/resources/fullExtension/src/lib.js\\" ] }", "type": "asset", diff --git a/test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v2.test.ts.snap b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v2.test.ts.snap new file mode 100644 index 0000000..87dac80 --- /dev/null +++ b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v2.test.ts.snap @@ -0,0 +1,261 @@ +// Vitest Snapshot v1 + +exports[`optimizeWebAccessibleResourcesDisabled - Manifest V2 1`] = ` +[ + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js": { + "code": "log(\\"content\\");", + "originalLength": 52, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js": { + "code": "log(\\"content2\\");", + "originalLength": 53, + "removedExports": [], + "renderedExports": [], + "renderedLength": 16, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script1\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js": { + "code": "log(\\"script1\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js": { + "code": "log(\\"script2\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "function log(message) { + console.log(message); +} +export { + log as l +}; +", + "dynamicImports": [], + "exports": [ + "l", + ], + "facadeModuleId": null, + "fileName": "assets/log.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/shared/log.js": { + "code": "function log(message) { + console.log(message); +}", + "originalLength": 65, + "removedExports": [], + "renderedExports": [ + "default", + ], + "renderedLength": 49, + }, + }, + "name": "log", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "manifest.json", + "name": undefined, + "source": "{ + \\"version\\": \\"1.0.0\\", + \\"name\\": \\"Manifest Name\\", + \\"manifest_version\\": 2, + \\"content_scripts\\": [ + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content1.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + }, + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content2.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + } + ], + \\"web_accessible_resources\\": [ + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"assets/log.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script2.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\" + ] +}", + "type": "asset", + }, +] +`; diff --git a/test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v3.test.ts.snap b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v3.test.ts.snap new file mode 100644 index 0000000..1dc5e0d --- /dev/null +++ b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesDisabled.v3.test.ts.snap @@ -0,0 +1,296 @@ +// Vitest Snapshot v1 + +exports[`optimizeWebAccessibleResourcesDisabled - Manifest V3 1`] = ` +[ + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js": { + "code": "log(\\"content\\");", + "originalLength": 52, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js": { + "code": "log(\\"content2\\");", + "originalLength": 53, + "removedExports": [], + "renderedExports": [], + "renderedLength": 16, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script1\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js": { + "code": "log(\\"script1\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js": { + "code": "log(\\"script2\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "function log(message) { + console.log(message); +} +export { + log as l +}; +", + "dynamicImports": [], + "exports": [ + "l", + ], + "facadeModuleId": null, + "fileName": "assets/log.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/shared/log.js": { + "code": "function log(message) { + console.log(message); +}", + "originalLength": 65, + "removedExports": [], + "renderedExports": [ + "default", + ], + "renderedLength": 49, + }, + }, + "name": "log", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "manifest.json", + "name": undefined, + "source": "{ + \\"version\\": \\"1.0.0\\", + \\"name\\": \\"Manifest Name\\", + \\"manifest_version\\": 3, + \\"content_scripts\\": [ + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content1.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + }, + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content2.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + } + ], + \\"web_accessible_resources\\": [ + { + \\"resources\\": [ + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"assets/log.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script1.js\\" + ], + \\"matches\\": [ + \\"\\" + ], + \\"use_dynamic_url\\": true + }, + { + \\"resources\\": [ + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\", + \\"assets/log.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script2.js\\" + ], + \\"matches\\": [ + \\"\\" + ], + \\"use_dynamic_url\\": true + }, + { + \\"resources\\": [ + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\", + \\"assets/log.js\\" + ], + \\"matches\\": [ + \\"\\" + ], + \\"use_dynamic_url\\": true + }, + { + \\"resources\\": [ + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\", + \\"assets/log.js\\" + ], + \\"matches\\": [ + \\"\\" + ], + \\"use_dynamic_url\\": true + } + ] +}", + "type": "asset", + }, +] +`; diff --git a/test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v2.test.ts.snap b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v2.test.ts.snap new file mode 100644 index 0000000..ede7665 --- /dev/null +++ b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v2.test.ts.snap @@ -0,0 +1,261 @@ +// Vitest Snapshot v1 + +exports[`optimizeWebAccessibleResourcesEnabled - Manifest V2 1`] = ` +[ + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js": { + "code": "log(\\"content\\");", + "originalLength": 52, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js": { + "code": "log(\\"content2\\");", + "originalLength": 53, + "removedExports": [], + "renderedExports": [], + "renderedLength": 16, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script1\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js": { + "code": "log(\\"script1\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js": { + "code": "log(\\"script2\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "function log(message) { + console.log(message); +} +export { + log as l +}; +", + "dynamicImports": [], + "exports": [ + "l", + ], + "facadeModuleId": null, + "fileName": "assets/log.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/shared/log.js": { + "code": "function log(message) { + console.log(message); +}", + "originalLength": 65, + "removedExports": [], + "renderedExports": [ + "default", + ], + "renderedLength": 49, + }, + }, + "name": "log", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "manifest.json", + "name": undefined, + "source": "{ + \\"version\\": \\"1.0.0\\", + \\"name\\": \\"Manifest Name\\", + \\"manifest_version\\": 2, + \\"content_scripts\\": [ + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content1.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + }, + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content2.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + } + ], + \\"web_accessible_resources\\": [ + \\"assets/log.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script2.js\\" + ] +}", + "type": "asset", + }, +] +`; diff --git a/test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v3.test.ts.snap b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v3.test.ts.snap new file mode 100644 index 0000000..61417d0 --- /dev/null +++ b/test/manifest/__snapshots__/optimizeWebAccessibleResourcesEnabled.v3.test.ts.snap @@ -0,0 +1,269 @@ +// Vitest Snapshot v1 + +exports[`optimizeWebAccessibleResourcesEnabled - Manifest V3 1`] = ` +[ + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content1.js": { + "code": "log(\\"content\\");", + "originalLength": 52, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"content2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/content2.js": { + "code": "log(\\"content2\\");", + "originalLength": 53, + "removedExports": [], + "renderedExports": [], + "renderedLength": 16, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/content2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script1\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script1.js": { + "code": "log(\\"script1\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script1", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "import { l as log } from \\"../../../../log.js\\"; +log(\\"script2\\"); +", + "dynamicImports": [], + "exports": [], + "facadeModuleId": "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "fileName": "assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "implicitlyLoadedBefore": [], + "importedBindings": { + "assets/log.js": [ + "l", + ], + }, + "imports": [ + "assets/log.js", + ], + "isDynamicEntry": false, + "isEntry": true, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/optimizeWebAccessibleResources/script2.js": { + "code": "log(\\"script2\\");", + "originalLength": 50, + "removedExports": [], + "renderedExports": [], + "renderedLength": 15, + }, + }, + "name": "test/manifest/resources/optimizeWebAccessibleResources/script2", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "code": "function log(message) { + console.log(message); +} +export { + log as l +}; +", + "dynamicImports": [], + "exports": [ + "l", + ], + "facadeModuleId": null, + "fileName": "assets/log.js", + "implicitlyLoadedBefore": [], + "importedBindings": {}, + "imports": [], + "isDynamicEntry": false, + "isEntry": false, + "isImplicitEntry": false, + "map": null, + "modules": { + "vite-plugin-web-extension/test/manifest/resources/shared/log.js": { + "code": "function log(message) { + console.log(message); +}", + "originalLength": 65, + "removedExports": [], + "renderedExports": [ + "default", + ], + "renderedLength": 49, + }, + }, + "name": "log", + "referencedFiles": [], + "type": "chunk", + "viteMetadata": { + "importedAssets": Set {}, + "importedCss": Set {}, + }, + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/script2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content1.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\"))})();", + "type": "asset", + }, + { + "fileName": "test/manifest/resources/optimizeWebAccessibleResources/content2.js", + "name": undefined, + "source": "(async()=>{await import(chrome.runtime.getURL(\\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\"))})();", + "type": "asset", + }, + { + "fileName": "manifest.json", + "name": undefined, + "source": "{ + \\"version\\": \\"1.0.0\\", + \\"name\\": \\"Manifest Name\\", + \\"manifest_version\\": 3, + \\"content_scripts\\": [ + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content1.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + }, + { + \\"js\\": [ + \\"test/manifest/resources/optimizeWebAccessibleResources/content2.js\\" + ], + \\"matches\\": [ + \\"\\" + ] + } + ], + \\"web_accessible_resources\\": [ + { + \\"resources\\": [ + \\"assets/log.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content1.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/content2.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"assets/test/manifest/resources/optimizeWebAccessibleResources/script2.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script1.js\\", + \\"test/manifest/resources/optimizeWebAccessibleResources/script2.js\\" + ], + \\"matches\\": [ + \\"\\" + ], + \\"use_dynamic_url\\": true + } + ] +}", + "type": "asset", + }, +] +`; diff --git a/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesDisabled.v3.test.ts.snap b/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesDisabled.v3.test.ts.snap index 06033e7..81f3f2f 100644 --- a/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesDisabled.v3.test.ts.snap +++ b/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesDisabled.v3.test.ts.snap @@ -248,37 +248,13 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\", - \\"assets/log.js\\", - \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ] - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\" - ], - \\"matches\\": [ - \\"\\" - ] - }, - { - \\"resources\\": [ \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/content1.js\\", - \\"assets/log.js\\" - ], - \\"matches\\": [ - \\"\\" - ] - }, - { - \\"resources\\": [ \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/content2.js\\", - \\"assets/log.js\\" + \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\", + \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\", + \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\", + \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\" ], \\"matches\\": [ \\"\\" diff --git a/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesEnabled.v3.test.ts.snap b/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesEnabled.v3.test.ts.snap index 7f03025..120a2ed 100644 --- a/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesEnabled.v3.test.ts.snap +++ b/test/manifest/__snapshots__/useDynamicUrlWebAccessibleResourcesEnabled.v3.test.ts.snap @@ -248,40 +248,13 @@ export { \\"web_accessible_resources\\": [ { \\"resources\\": [ - \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\", - \\"assets/log.js\\", - \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ - \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\", \\"assets/log.js\\", - \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/content1.js\\", - \\"assets/log.js\\" - ], - \\"matches\\": [ - \\"\\" - ], - \\"use_dynamic_url\\": true - }, - { - \\"resources\\": [ \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/content2.js\\", - \\"assets/log.js\\" + \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\", + \\"assets/test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\", + \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script1.js\\", + \\"test/manifest/resources/useDynamicUrlWebAccessibleResources/script2.js\\" ], \\"matches\\": [ \\"\\" diff --git a/test/manifest/optimizeWebAccessibleResourcesDisabled.v2.test.ts b/test/manifest/optimizeWebAccessibleResourcesDisabled.v2.test.ts new file mode 100644 index 0000000..fee89ba --- /dev/null +++ b/test/manifest/optimizeWebAccessibleResourcesDisabled.v2.test.ts @@ -0,0 +1,25 @@ +import { getResourceDir, runManifestV2Test } from "./manifestTestUtils"; + +const resourceDir = getResourceDir("optimizeWebAccessibleResources"); + +runManifestV2Test( + "optimizeWebAccessibleResourcesDisabled", + () => ({ + content_scripts: [ + { + js: [`${resourceDir}/content1.js`], + matches: [""], + }, + { + js: [`${resourceDir}/content2.js`], + matches: [""], + }, + ], + }), + { + additionalInputs: { + scripts: [`${resourceDir}/script1.js`, `${resourceDir}/script2.js`], + }, + optimizeWebAccessibleResources: false, + } +); diff --git a/test/manifest/optimizeWebAccessibleResourcesDisabled.v3.test.ts b/test/manifest/optimizeWebAccessibleResourcesDisabled.v3.test.ts new file mode 100644 index 0000000..094ab16 --- /dev/null +++ b/test/manifest/optimizeWebAccessibleResourcesDisabled.v3.test.ts @@ -0,0 +1,25 @@ +import { getResourceDir, runManifestV3Test } from "./manifestTestUtils"; + +const resourceDir = getResourceDir("optimizeWebAccessibleResources"); + +runManifestV3Test( + "optimizeWebAccessibleResourcesDisabled", + () => ({ + content_scripts: [ + { + js: [`${resourceDir}/content1.js`], + matches: [""], + }, + { + js: [`${resourceDir}/content2.js`], + matches: [""], + }, + ], + }), + { + additionalInputs: { + scripts: [`${resourceDir}/script1.js`, `${resourceDir}/script2.js`], + }, + optimizeWebAccessibleResources: false, + } +); diff --git a/test/manifest/optimizeWebAccessibleResourcesEnabled.v2.test.ts b/test/manifest/optimizeWebAccessibleResourcesEnabled.v2.test.ts new file mode 100644 index 0000000..4afaa39 --- /dev/null +++ b/test/manifest/optimizeWebAccessibleResourcesEnabled.v2.test.ts @@ -0,0 +1,24 @@ +import { getResourceDir, runManifestV2Test } from "./manifestTestUtils"; + +const resourceDir = getResourceDir("optimizeWebAccessibleResources"); + +runManifestV2Test( + "optimizeWebAccessibleResourcesEnabled", + () => ({ + content_scripts: [ + { + js: [`${resourceDir}/content1.js`], + matches: [""], + }, + { + js: [`${resourceDir}/content2.js`], + matches: [""], + }, + ], + }), + { + additionalInputs: { + scripts: [`${resourceDir}/script1.js`, `${resourceDir}/script2.js`], + }, + } +); diff --git a/test/manifest/optimizeWebAccessibleResourcesEnabled.v3.test.ts b/test/manifest/optimizeWebAccessibleResourcesEnabled.v3.test.ts new file mode 100644 index 0000000..4af7969 --- /dev/null +++ b/test/manifest/optimizeWebAccessibleResourcesEnabled.v3.test.ts @@ -0,0 +1,24 @@ +import { getResourceDir, runManifestV3Test } from "./manifestTestUtils"; + +const resourceDir = getResourceDir("optimizeWebAccessibleResources"); + +runManifestV3Test( + "optimizeWebAccessibleResourcesEnabled", + () => ({ + content_scripts: [ + { + js: [`${resourceDir}/content1.js`], + matches: [""], + }, + { + js: [`${resourceDir}/content2.js`], + matches: [""], + }, + ], + }), + { + additionalInputs: { + scripts: [`${resourceDir}/script1.js`, `${resourceDir}/script2.js`], + }, + } +); diff --git a/test/manifest/resources/optimizeWebAccessibleResources/content1.js b/test/manifest/resources/optimizeWebAccessibleResources/content1.js new file mode 100644 index 0000000..b490659 --- /dev/null +++ b/test/manifest/resources/optimizeWebAccessibleResources/content1.js @@ -0,0 +1,3 @@ +import log from "./../shared/log"; + +log("content"); diff --git a/test/manifest/resources/optimizeWebAccessibleResources/content2.js b/test/manifest/resources/optimizeWebAccessibleResources/content2.js new file mode 100644 index 0000000..a56055e --- /dev/null +++ b/test/manifest/resources/optimizeWebAccessibleResources/content2.js @@ -0,0 +1,3 @@ +import log from "./../shared/log"; + +log("content2"); diff --git a/test/manifest/resources/optimizeWebAccessibleResources/script1.js b/test/manifest/resources/optimizeWebAccessibleResources/script1.js new file mode 100644 index 0000000..b913f7f --- /dev/null +++ b/test/manifest/resources/optimizeWebAccessibleResources/script1.js @@ -0,0 +1,3 @@ +import log from "../shared/log"; + +log("script1"); diff --git a/test/manifest/resources/optimizeWebAccessibleResources/script2.js b/test/manifest/resources/optimizeWebAccessibleResources/script2.js new file mode 100644 index 0000000..6726bf9 --- /dev/null +++ b/test/manifest/resources/optimizeWebAccessibleResources/script2.js @@ -0,0 +1,3 @@ +import log from "../shared/log"; + +log("script2"); diff --git a/types/index.d.ts b/types/index.d.ts index 18d62cc..c24e027 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -31,16 +31,22 @@ interface ViteWebExtensionOptions { manifest: chrome.runtime.Manifest; /** - * In dev mode, apply Vite plugins to manifest HTML files by calling transformIndexHtml on them - * Default: false + * Sets the use_dynamic_url property on web accessible resources generated by the plugin + * Default: true */ - devHtmlTransform?: boolean; + useDynamicUrlWebAccessibleResources?: boolean; /** - * Sets the use_dynamic_url property on web accessible resources generated by the plugin + * On build, in Manifest V3, merge web accessible resource definitions that have matching non-`resource` properties and dedupe and sort `resources`. In Manifest V2, sort web accessible resources. * Default: true */ - useDynamicUrlWebAccessibleResources?: boolean; + optimizeWebAccessibleResources?: boolean; + + /** + * In dev mode, apply Vite plugins to manifest HTML files by calling transformIndexHtml on them + * Default: false + */ + devHtmlTransform?: boolean; /** * Additional input files that should be processed and treated as web extension inputs.