Skip to content

Commit

Permalink
Include declarativeNetRequest JSON file rules as dependencies when bu…
Browse files Browse the repository at this point in the history
…ndling web extensions (#8189)
  • Loading branch information
carterworks committed Jun 13, 2022
1 parent 52296ad commit d2d0d33
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Expand Up @@ -26,6 +26,13 @@
"js": ["src/content.js"],
"css": ["src/content.css"]
}],
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset_1",
"enabled": true,
"path": "./rulesets/ruleset_1.json"
}]
},
"dictionaries": {
"en-US": "./dicts/tmp.dic"
},
Expand Down
@@ -0,0 +1 @@
[]
7 changes: 7 additions & 0 deletions packages/core/integration-tests/test/webextension.js
Expand Up @@ -35,6 +35,9 @@ describe('webextension', function () {
{assets: ['devtools.html']},
{assets: ['content.js']},
{assets: ['content.css']},
{
assets: ['ruleset_1.json'],
},
]);
assert(
await outputFS.exists(
Expand All @@ -49,6 +52,10 @@ describe('webextension', function () {
);
const scripts = manifest.background.scripts;
assert.equal(scripts.length, 1);
for (const {path: resourcePath} of manifest.declarative_net_request
?.rule_resources ?? []) {
assert(await outputFS.exists(path.join(distDir, resourcePath)));
}
assert(
(
await outputFS.readFile(path.join(distDir, scripts[0]), 'utf-8')
Expand Down
17 changes: 17 additions & 0 deletions packages/transformers/webextension/src/WebExtensionTransformer.js
Expand Up @@ -218,6 +218,23 @@ async function collectDependencies(
}
program.web_accessible_resources = war;
}
if (program.declarative_net_request) {
const rrs: {|path: string, id: string, enabled: boolean|}[] =
program.declarative_net_request?.rule_resources ?? [];
rrs.forEach((resources, i) => {
resources.path = asset.addURLDependency(resources.path, {
pipeline: 'raw',
loc: {
filePath,
...getJSONSourceLocation(
ptrs[`/declarative_net_request/rule_resources/${i}/path`],
'value',
),
},
});
});
}

for (const loc of DEP_LOCS) {
const location = '/' + loc.join('/');
if (!ptrs[location]) continue;
Expand Down
20 changes: 20 additions & 0 deletions packages/transformers/webextension/src/schema.js
Expand Up @@ -179,6 +179,26 @@ const commonProps = {
required: ['matches'],
},
},
declarative_net_request: ({
type: 'object',
properties: {
rule_resources: {
type: 'array',
items: {
type: 'object',
properties: {
id: string,
enabled: boolean,
path: string,
},
additionalProperties: false,
required: ['id', 'enabled', 'path'],
},
},
},
additionalProperties: false,
required: ['rule_resources'],
}: SchemaEntity),
devtools_page: string,
// looks to be FF only
dictionaries: ({
Expand Down

0 comments on commit d2d0d33

Please sign in to comment.