collections: Repeat runs with collections adds duplicates
Currently, repeated calls to metalsmith.build()
is non-idempotent because metalsmith-collections will find the same files that belongs to a collection, and add them to the same array as exists in memory from the previous run.
This is due to metalsmith storing collections in the global metadata object. Maybe it should empty out the collections arrays every time it runs?
My workaround right now is essentially
metalsmith.build(function(err, files) {
if (err) throw err;
metalsmith.metadata(origMetadata);
});
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 5
- Comments: 25 (4 by maintainers)
Commits related to this issue
- Closes #27 by adding a test for repeat builds — committed to metalsmith/collections by webketje 2 years ago
Forked this for now and added the
metadata[key]
fix mentioned by @deltamualphahttps://github.com/spacedawwwg/metalsmith-collections
use this forked version by adding
to your
package.json
I’ve submitted a pull request, but I’ll keep the fork updated until this finally gets fixed (it has been a year since this issue was posted)
Here’s another fix to force the metadata to reset every build. Similar idea to @AndyOGo.
@AndyOGo please see the commit 891b24c which adds a test for this. In the latest published version, I did quite some refactoring and suspected I incidentally fixed it (I think it was even fixed long ago but just in a messy way and without updating this issue) See also https://github.com/metalsmith/collections/blob/master/lib/index.js#L91
EDIT: My test should have been sequential, not parallel. Updated locally, but the conclusion remains, yes it’s fixed.
To avoid this issue, install by
https
the new version of metalsmith-collections.This will be install the latest version of plugin, since metalsmith org still does not have permission to push to
NPM
yet.Did this ever get fixed @spacedawwwg ? BTW - thanks for the temp fix.
Another quickfix is to monkey patch the build method, like:
This whipes it after every build and works with
metalsmith-browser-sync
too👍 fixed it locally by checking the
metadata[key]
array for the same file before adding it. A real fix would be nice.