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

WIP: Content-hash bundle names #829

Closed

Conversation

benhutton
Copy link

@benhutton benhutton commented Feb 16, 2018

Still a long way to go to get this ready for review. And the javascript you see here is that of a Rubyist stumbling into javascript and its asynchronicity. We'll get this cleaned up in the next few days and try to write a few tests and submit a proper PR template.

Fixes #717
Fixes #188

/cc @shanebo

walkBundles(child, indent + '--')
}
}
hash = md5File.sync(bundle.name);
Copy link
Author

Choose a reason for hiding this comment

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

Above this line, we need to do a find and replace on the current file (bundle.name) with the contents of walkedFiles (which has a map from old hashes to new hashes).

@DeMoorJasper DeMoorJasper changed the title Cache Busting Hashed bundle names Feb 16, 2018
@DeMoorJasper DeMoorJasper changed the title Hashed bundle names Content-hash bundle names Feb 16, 2018
@benhutton benhutton force-pushed the feature/cache-busting branch 2 times, most recently from 56793a6 to 5fed71c Compare February 16, 2018 19:20
@benhutton benhutton changed the title Content-hash bundle names WIP: Content-hash bundle names Feb 16, 2018
data = fs.readFileSync(fileName, 'utf8')

hashMap.forEach(function(value, key) {
data = data.replace(new RegExp(key, 'g'), value);
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 somewhat dangerous and would probably end up replacing things we don't want. For example, if you had a file called index.js but some string in the app also contained that but wasn't a reference, we'd end up replacing it too.

Instead of doing it this way, maybe we can store a list of reference locations as part of the asset (e.g. part of the options to addDependency)?

Copy link
Author

Choose a reason for hiding this comment

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

@devongovett in my limited experience, bundle.name has only ever been my entry file (entry.html in my case) or an md5 hash. What are the other possibilities?

Copy link
Member

Choose a reason for hiding this comment

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

For example, if you use the __filename variable in your code, it will be replaced with the current input filename (e.g. index.js). We wouldn't want that to be replaced with the generated bundle name.

Copy link
Author

Choose a reason for hiding this comment

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

@devongovett in my testing, hashMap only contains md5 hashes of things. Are there other non-md5 names that can get assigned to a bundle?

Copy link
Member

Choose a reason for hiding this comment

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

See logic here for how bundles are named: https:/parcel-bundler/parcel/blob/master/src/Asset.js#L178-L213

Copy link
Author

Choose a reason for hiding this comment

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

@devongovett okay....

If a name isn't hashed in generateBundleName(), would we want this new code to hash it? What's the reason for leaving it as-is there and not just hashing everything?

Copy link
Member

@devongovett devongovett Feb 20, 2018

Choose a reason for hiding this comment

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

My point is mostly that doing a search and replace over output files for filenames is somewhat dangerous in that we might end up replacing things we didn't intend. Perhaps generateBundleName could generate something random always (rather than nice looking filenames like index.js) which is much less likely to appear in the source code, and we could use that to replace with the final names here.

Copy link
Author

Choose a reason for hiding this comment

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

@devongovett yeah, if it's safe for generateBundleName to always use hashing, that would be nice.

@@ -200,7 +200,7 @@ class Asset {
const packageName = sanitizeFilename(this.package.name, {
replacement: '-'
});
return packageName + ext;
return md5(packageName) + ext;
Copy link
Author

Choose a reason for hiding this comment

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

@devongovett is all I need to do in this function? My intent is to not do any renaming on the entry file: https:/parcel-bundler/parcel/pull/829/files#diff-784c5f1cd4c785db2834e618a52b438eR35

@devongovett
Copy link
Member

Closing in favor of #1025.

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

Successfully merging this pull request may close these issues.

3 participants