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

Files with autogenerated id in their names are always removed then added #449

Open
tleunen opened this issue Jan 20, 2022 · 4 comments
Open

Comments

@tleunen
Copy link

tleunen commented Jan 20, 2022

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

The page breakdown keeps showing the file being removed, then added, while it's the same file. This adds complexity seeing the overall change to the file.

image

If the current behavior is a bug, please provide the steps to reproduce.

Create a bundle with an auto-generated id in the name, such as:

{
      "path": "build/*-main-split.js",
      "compression": "brotli",
      "maxSize": "100 kB"
    },

What is the expected behavior?

Bundlewatch should compare the 2 files with different generated id instead of showing one as removed and the other as added.

Please mention other relevant information such as the browser version, Node.js version, bundlewatch version, and Operating System.

Is there a way to clear the cache or something on the bundlewatch side?

@tleunen
Copy link
Author

tleunen commented Jan 20, 2022

Looks like the option normalizeFilenames can resolve this by removing the auto generated name. But when I use the option, only the files having that generated id get reported.

All other files get lost in the process and are reported with an empty string instead

PASS  : 184KB < 250KB (brotli)

@tleunen
Copy link
Author

tleunen commented Jan 20, 2022

The problem seems to be this line

.split(normalizeFilenames)

As if there's no group being found, split returns the whole path

@tleunen
Copy link
Author

tleunen commented Jan 20, 2022

Making my group optional in my regex kind of fixes the issue... But it makes the split function returning an undefined value and we do a replace on an undefined (my files don't have undefined so it's alright I guess).

Might be worth it to replace the split with a match instead and really check the results.

Something along these lines maybe

let normalizedFilePath = filePath;
if (normalizeFilenames) {
  const match = filePath.match(normalizeFilenames);
  if (match != null) {
    const [, matches] = match;
    normalizedFilePath = matches.reduce((acc, m) => acc.replace(m, ''), filePath);
  }
}

@charpeni
Copy link
Member

charpeni commented Feb 2, 2022

Thanks for reporting this. This is definitely annoying when all your files aren't matching with normalizeFilenames, I encountered this recently and I had to do like you said, use an optional group.

Would you like to send a pull request with tests? I will be happy to review it.

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

No branches or pull requests

2 participants