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

Add PWAManifestTransformer #3404

Closed

Conversation

Drapegnik
Copy link
Contributor

@Drapegnik Drapegnik commented Aug 14, 2019

↪️ Pull Request

Resolves #3362, Resolves #235, Resolves #301

✔️ PR Todo

  • ported WebManifestAsset -> PWAManifestTransformer
  • support .json webmanifest
  • Added/updated unit tests for this change
  • Included links to related issues/PRs

@Drapegnik
Copy link
Contributor Author

Hi, @devongovett! Could you check this please?
If everything is ok, I'll add the rest.

Should I add something for rewriting urls?

@devongovett
Copy link
Member

Looking good so far @Drapegnik! 😄

@Drapegnik
Copy link
Contributor Author

@devongovett,

I decided to divide WebManifestTransformer to PWA & WebExtension transformers, because manifests have different structure, so:

  • everything under rel="manifest marked as env: {context: 'pwa-manifest'}
  • manifest.json without pwa-manifest context is webext-manifest

import nullthrows from 'nullthrows';

const getSrcHandler = (opt = {}) => (asset, dep) => {
dep.src = asset.addURLDependency(dep.src, opt);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add this for urls rewriting and get following from this manifest:

{
  "name": "pwa-webmanifest-example",
  "icons": [
    {
      "src": "1eda49598769bd3a3cd2b1e31d3cfaff",
      "sizes": "100x100",
      "type": "image/png"
    }
  ],
  "screenshots": [
    {
      "src": "f432622196df181e7734bdfd95fa62d0",
      "sizes": "100x100",
      "type": "image/png"
    },
    { "src": "" }
  ],
  "serviceworker": { "src": "d771eacd0fc5e521bf134585524d4727" }
}

Copy link
Member

Choose a reason for hiding this comment

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

Yep, those ids will be replaced later with urls once the final bundle names are known.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How can I test it?

yarn build
parceldev build --no-cache packages/core/integration-tests/test/integration/pwa-manifest/inde
x.html

produces the same file (with ids)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devongovett @DeMoorJasper @padmaia @wbinnssmith,

Could you tell me where is this final replacement (ids -> urls) occurs?
Looks like .webmanifest is ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

never mind, I found - generateDepToBundlePath)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the problem was because .webmanifest was being processed by RawPackager, which returns stream, so typeof contents !== 'string' and generateDepToBundlePath was skipped

I fixed this by adding StringPackager - not sure if this is the best way

@@ -5,6 +5,7 @@
"@parcel/transformer-babel",
"@parcel/transformer-js"
],
"manifest.json": ["@parcel/transformer-webext-manifest"],
Copy link
Member

Choose a reason for hiding this comment

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

This seems dangerous to me. Many things could be called manifest.json in theory. I'd say, keep the web extension transformer as an official plugin, but don't include in the default config. That way, if you're writing a web extension, you can opt-in to the processing of manifest.json, and it won't affect other apps.

Copy link
Contributor Author

@Drapegnik Drapegnik Aug 15, 2019

Choose a reason for hiding this comment

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

So, I add this logic to json-transformer:

    // handle webmanifest .json
    if (asset.env.context === 'pwa-manifest') {
      asset.type = 'webmanifest';
      return [asset];
    }

@Drapegnik Drapegnik changed the title [WIP] Add WebManifestTransformer [WIP] Add PWAManifestTransformer Aug 15, 2019
@Drapegnik Drapegnik changed the title [WIP] Add PWAManifestTransformer Add PWAManifestTransformer Aug 16, 2019
@Drapegnik
Copy link
Contributor Author

Ready to final review.
I'd like to add WebextManifestTransformer in next PR

@Drapegnik
Copy link
Contributor Author

@devongovett, hi!
Could you please review this pr?

@Drapegnik
Copy link
Contributor Author

@devongovett, hey?)

@sygint
Copy link

sygint commented Dec 5, 2019

@Drapegnik looks like it has conflicts now, but I'd love to see @devongovett merge this. This will allow me to move many projects over to parcel and greatly reduce my complexity for my builds

@Drapegnik Drapegnik force-pushed the transformer-webmanifest branch 2 times, most recently from 24cd209 to 5bc521c Compare December 6, 2019 17:00
@Drapegnik
Copy link
Contributor Author

@gnarmedia, I'm also really looking forward to some response from @devongovett.

@@ -129,7 +129,8 @@ export default function collectDependencies(

if (tag === 'link' && attrs.rel === 'manifest' && attrs.href) {
attrs.href = asset.addURLDependency(attrs.href, {
isEntry: true
isEntry: true,
env: {context: 'pwa-manifest'}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did rebase and now get:

Error: Received URL without a pathname.

something with moduleSpecifier (new api?)

How do I properly add manifest dep here?

@DeMoorJasper
Copy link
Member

@Drapegnik could you rebase this on v2 and fix the failing tests? Lemme know if you need any help with fixing tests

@Drapegnik
Copy link
Contributor Author

@DeMoorJasper, hi! after rebase I've got:

  pwa-manifest
    1) should support .webmanifest
    ✓ should support .json webmanifest (87ms)
    2) should treat .webmanifest as an entry module so it doesn't get content hashed
    3) should rename webmanifest *.json to *.webmanifest

with Error: Received URL without a pathname . could you help me with it?

maybe it's due . webmanifest extension? (json manifest somehow passed)

mayppong added a commit to mayppong/ragtag that referenced this pull request Feb 17, 2020
We're current not including this in the HTML file yet since parcel has
an issue bundling a JSON resouce from HTML. There is a PR that looks to
resolve this issue (parcel-bundler/parcel#3404)
@mischnic mischnic mentioned this pull request Mar 11, 2020
@DeMoorJasper
Copy link
Member

DeMoorJasper commented Mar 12, 2020

@Drapegnik apologies for not reaching out sooner and giving feedback on this plugin.

I've tried to get the tests to pass a couple times, but also couldn't figure out why they were failing and deviated too much from this PR in my attempts to fix it to give proper feedback, so I never really got around to writing a structured review to get you going and eventually moved on to other issues...

@mischnic apparently is working on fixing the issues with your PR, not entirely sure if we should close this one and move progress over to that PR?

@Drapegnik
Copy link
Contributor Author

@DeMoorJasper, ok, but what about #3439, which depends on this one?

@DeMoorJasper
Copy link
Member

DeMoorJasper commented Mar 12, 2020

@Drapegnik I assume that one will not be included in @mischnic 's PR

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

Successfully merging this pull request may close these issues.

Parcel 2: Web Manifest transformer 🙋 PWA support 🐛 Problem with loading manifest.json
6 participants