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

@parcel/transformers-webextension does not detect declarative_net_request. rule_resources[].path json files dependencies in manifest.json #8188

Closed
carterworks opened this issue Jun 2, 2022 · 1 comment

Comments

@carterworks
Copy link
Contributor

carterworks commented Jun 2, 2022

🐛 bug report

The declarativeNetRequest extension API requires that the developer define the Rulesets in the manifest.json. Each ruleset has a path property, which is "the path of the JSON ruleset relative to the extension directory." In other words, it's the path to a JSON file that needs to be copy over to the output directory when building the extension. Currently, this does not happen.

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  // …
  "scripts": {
    "build": "parcel build --config @parcel/config-webextension manifest.json"
  },
  "devDependencies": {
    "@parcel/config-webextension": "2.6.0",
    "@parcel/core": "2.6.0"
  }
}

manifest.json

{
  "name": "parcel example",
  "description": "Parcel WebExt example, with declarativeNetRequest",
  "version": "1.0",
  "manifest_version": 3,
  "permissions": ["declarativeNetRequest"],
  "declarative_net_request": {
    "rule_resources": [
      {
        "id": "ruleset_1",
        "enabled": true,
        "path": "rules.json"
      }
    ]
  }
}

rules.json

[]

🤔 Expected Behavior

The rules.json file should be copied to the dist/ folder when building the extension.

😯 Current Behavior

rules.json is not copied to the dist/ folder when building. This causes the extension to be invalid, when loaded unpacked into the browser.

💁 Possible Solution

Fix packages/transformers/webextension/src/WebExtensionTransformer.js to pick up those json dependencies.

Maybe something like this in collectDependencies()

  if (program.declarative_net_request?.rule_resources) {
    const rrs = program.declarative_net_request?.rule_resources ?? [];
    for (const { path } of rrs) {
      asset.addURLDependency(path, {
        needsStableName: true,
        pipeline: "raw"
      });
    }
  }

It should have more error checking, but this works. I'd make the PR myself, but I can't get my local parcel build environment to work correctly.

🔦 Context

I'm trying to create a Chrome web extension that uses the declarativeNetRequest API.

🌍 Your Environment

Software Version(s)
Parcel 2.6.0
Node 16.14.2
npm/Yarn npm 8.5.0
Operating System macOS 12.3.1 21E258 x86_64
@carterworks carterworks changed the title Parcel ignores declarative_net_request. rule_resources[].path json files in manifest.json @parcel/transformers-webextension does not detect declarative_net_request. rule_resources[].path json files dependencies in manifest.json Jun 2, 2022
@101arrowz
Copy link
Member

Added in #8189.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants