alex-ketch / metalsmith-renamer

A Metalsmith plugin that renames files matching a given pattern.
MIT License
5 stars 3 forks source link

If renamedEntry==file the File is Deleted #4

Closed emmercm closed 5 years ago

emmercm commented 5 years ago

I'm attempting to use this plugin like:

    // Lowercase extensions
    .use(renamer({
        lowercase: {
            pattern: '**/*.*',
            rename: file => {
                const split = file.split('.');
                return split.slice(0, split.length - 1).join('.') + '.' + split[split.length-1].toLowerCase();
            }
        }
    }))

But because of the line in the plugin:

        files[renamedEntry] = files[file];
        delete files[file];

Any filenames that don't change end up getting removed from the file list.

I'd expect them to not be removed.

alex-ketch commented 5 years ago

Hi @emmercm, thanks for reporting this! I actually haven't used metalsmith in a while, and can't make promises of when I'll get to working on this as it will take me a bit to refresh my memory. Would you feel comfortable in making a PR?

If I understood you correctly, the problem arises when renamedEntry === file, is that right?

emmercm commented 5 years ago

I can definitely make the PR, though it might take me a couple extra days.

That's right - the thought is I'd only delete files[file] if file !== renamedEntry.

alex-ketch commented 5 years ago

Closed by #5