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

Conversation

carterworks
Copy link
Contributor

@carterworks carterworks commented Jun 3, 2022

↪️ Pull Request

Fixes issue #8188.

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.

I have included the declarative_net_request property in the manifest.json schema validator. I have also written a portion in @parcel/transformer-webextension that adds JSON files specified in the path property as dependencies of the asset, complete with error message if the specified JSON file does not exist.

This is my first contribution to Parcel, so please let me know what I need to change to align with correct API usage, design, and coding standards.

💻 Examples

See my example repo. Clone it, run npm install, and then npm run build to build the extension. If you check dist/, there is no rules.json file in it. If you load dist/ as an unpacked extension into Chrome, it will throw an error about how rules.json is missing.

🚨 Test instructions

Install my branch into my example repository, then build the extension again. You will see that rules.json has been copied into the dist/ folder.

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@carterworks
Copy link
Contributor Author

@101arrowz I believe you are the Parcel maintainer that has worked on web extensions most recently. Will you look at this?

Copy link
Member

@101arrowz 101arrowz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, just a few suggestions.

@101arrowz
Copy link
Member

Also make sure to fix flow issues (probably just by typecasting).

@carterworks
Copy link
Contributor Author

@101arrowz I've made those changes, including fixing the flow typing issues.

Also, I don't think the test failures (at least on the previous run) are due to anything I've change.

  1) hmr
       hmr runtime
         should handle CSS Modules update correctly:
      AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
'http://127.0.0.1:49512/index.43be9ba8.css'
      + expected - actual
      at Context.<anonymous> (test/hmr.js:976:16)
  2) transpilation
       tests needing the real filesystem
         should compile node_modules when symlinked with a source field in package.json:
      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
  path.join(__dirname, '/integration/babel-core-js/index.js')
      + expected - actual
      -false
      +true
      at Context.<anonymous> (test/transpilation.js:457:7)

@mischnic
Copy link
Member

mischnic commented Jun 7, 2022

Would be nice to include this in the integration test: https://github.com/parcel-bundler/parcel/tree/v2/packages/core/integration-tests/test/integration/webextension

Also, I don't think the test failures (at least on the previous run) are due to anything I've change.

Yes, the tests are flakey... don't worry about them.

@carterworks
Copy link
Contributor Author

Would be nice to include this in the integration test: https://github.com/parcel-bundler/parcel/tree/v2/packages/core/integration-tests/test/integration/webextension

@mischnic I can look into that today or tomorrow.

@carterworks
Copy link
Contributor Author

I've modified packages/core/integration-tests/test/webextension.js, but how can I run the test with the local version of @parcel/transformer-webextension? When I run it with yarn test:integration --grep "webext*", it fails with the message "Invalid WebExtension Manifest".

@mischnic
Copy link
Member

mischnic commented Jun 7, 2022

That should be working (and there's no need to run a build step, Babel register does this on the fly).
So I'd say commit your test how you think it should work and then we can figure out if there's something wrong

(You need to modify packages/core/integration-tests/test/webextension.js and packages/core/integration-tests/test/integration/webextension-mv3/manifest.json)

@carterworks
Copy link
Contributor Author

A passing integration test has been added. I messed up the git history of this branch by rebasing off of main, but the substances is there. Just be sure to do a squash and merge 😅

@101arrowz
Copy link
Member

Think this should be good to go. Thanks for working on this!

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

Successfully merging this pull request may close these issues.

None yet

4 participants