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

Include declarativeNetRequest JSON file rules as dependencies when bundling web extensions #8189

Merged
merged 22 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d78f12c
Add declarative_net_request to manifest.json schema
carterworks Jun 3, 2022
027375a
Add rule_resource path json files to webext dependencies
carterworks Jun 3, 2022
2cbfb6e
Add error message for missing path
carterworks Jun 3, 2022
c680b4e
Make rules dependency isolated instead of raw
carterworks Jun 3, 2022
af3b005
Mark rule_resources as required in manifest schema
carterworks Jun 3, 2022
97e2d96
Make error message more robust
carterworks Jun 3, 2022
1a5e7cd
Remove unnecessary properties and checks
carterworks Jun 3, 2022
f508999
Fix flow typing errors
carterworks Jun 3, 2022
48bd780
Add declarative_net_request to manifest.json schema
carterworks Jun 3, 2022
b40d64a
Add rule_resource path json files to webext dependencies
carterworks Jun 3, 2022
cdb5e47
Add error message for missing path
carterworks Jun 3, 2022
a6c9d5d
Make rules dependency isolated instead of raw
carterworks Jun 3, 2022
2c88939
Mark rule_resources as required in manifest schema
carterworks Jun 3, 2022
bdd2654
Make error message more robust
carterworks Jun 3, 2022
c2652c2
Remove unnecessary properties and checks
carterworks Jun 3, 2022
e7d30f9
Fix flow typing errors
carterworks Jun 3, 2022
a596ca3
Remove custom error handling for DNR in manifest.json
carterworks Jun 8, 2022
be00f6e
Add integration test for DNR
carterworks Jun 8, 2022
9d7c4e1
Merge branch 'webext-dnr-rules' of https://github.com/carterworks/par…
carterworks Jun 8, 2022
f534cd7
Change webext dependency pipeline to 'raw'
carterworks Jun 8, 2022
98a0577
Remove needsStableName from ruleset assets
carterworks Jun 8, 2022
971cc3f
Merge branch 'v2' into webext-dnr-rules
devongovett Jun 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'],
101arrowz marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
additionalProperties: false,
required: ['rule_resources'],
}: SchemaEntity),
devtools_page: string,
// looks to be FF only
dictionaries: ({
Expand Down