Skip to content

Commit

Permalink
fix(react): replace invalid characters in chunk name
Browse files Browse the repository at this point in the history
We're using base64 to generate short chunk names, unfortunately this
means that we need to replace some characters which are invalid
characters in file names.
We replace `/` with `-`, `+` with `_` and `=` with an empty string.
Replacing `=` with an empty string shouldn't occur in real life,
because we're only using the first four characters.
  • Loading branch information
ZauberNerd committed Feb 22, 2022
1 parent 2f1a58a commit bf735bd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/react/import-component/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ module.exports = ({ types: t }) => ({
const hasher = crypto.createHash('md4');
hasher.update(nodePath.relative(this.opts.rootDir, state.filename));
hasher.update(importedComponent);
const hash = hasher.digest('base64').slice(0, 4);
const hash = hasher
.digest('base64')
.replace('/', '-')
.replace('+', '_')
.replace('=', '')
.slice(0, 4);

t.addComment(
argPath.node,
Expand Down

0 comments on commit bf735bd

Please sign in to comment.