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

fix srcset parsing #8671

Merged
merged 14 commits into from Dec 20, 2022
Merged

fix srcset parsing #8671

merged 14 commits into from Dec 20, 2022

Conversation

christianhaller
Copy link
Contributor

↪️ Pull Request

When I was using some URLs with a comma separated query param to a srcset,
my parcel tried to resolve the wrong url.
It was splitting the srcset string on the wrong comma.

@parcel/resolver-default: Cannot load file './9.739075709034898&markers=size:tiny|52.345519011208346' in './src/content

I found a package which is parsing the srcset correctly.
I added a test for the affected method.

@christianhaller christianhaller marked this pull request as draft December 11, 2022 22:54
@mischnic
Copy link
Member

We don't really use unit tests, so please create an integration test instead (see #7918).

@christianhaller christianhaller marked this pull request as ready for review December 13, 2022 08:11
@mischnic
Copy link
Member

  • Please remove packages/transformers/html/test/dependencies.test.js (and unexport collectSrcSetDependencies)
  • We might as well leverage the stringify function of that package now, instead of the manual w/x appending, e.g. like this:
import * as srcset from 'srcset';

function collectSrcSetDependencies(asset, v, opts) {
  let parsed = srcset.parse(v).map(({url, ...v}) => ({
    url: asset.addURLDependency(url, opts),
    ...v,
  }));
  return srcset.stringify(parsed);
}
  • Please add this file at flow-libs/srcset.js.flow:
// @flow
declare module 'srcset' {
  declare type SrcSetDefinition = {|
    url: string,
    width?: number,
    density?: number,
  |};

  declare type Options = {|
    strict?: boolean,
  |};

  declare export function parse(
    srcset: string,
    options?: Options,
  ): SrcSetDefinition[];
  declare export function stringify(
    srcSetDefinitions: SrcSetDefinition[],
    options?: Options,
  ): string;
}

@christianhaller
Copy link
Contributor Author

Thank you for the review Niklas!
Good point with the stringify method. This looks much better :-)

@mischnic
Copy link
Member

Looks like you have some npm registry override configured for Yarn. There shouldn't be that many changed lines in the lockfile

@christianhaller
Copy link
Contributor Author

Looks like you have some npm registry override configured for Yarn. There shouldn't be that many changed lines in the lockfile

It took me hours to fix this 😵

Copy link
Member

@mischnic mischnic left a comment

Choose a reason for hiding this comment

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

Thanks!

@mischnic mischnic merged commit eed1e2c into parcel-bundler:v2 Dec 20, 2022
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

2 participants