absolute-version / commit-and-tag-version

Fork of the excellent standard-version. Automate versioning and CHANGELOG generation, with semver.org and conventionalcommits.org :trophy:
ISC License
421 stars 40 forks source link

Issue with custom updaters #22

Closed wcl-onespan closed 2 years ago

wcl-onespan commented 2 years ago

Describe the bug When creating performing a version bump using NPX. We are seeing an error with our custom updater configuration. Specifically the error has that the file is an unsupported file, but yet it performs the version update anyways.

Current behavior When running the following command: npx -p commit-and-tag-version -c "commit-and-tag-version --prerelease build" --yes

with an .versionrc.js file that contains the following configuration:

const dotEnvFileUpdater = {
    filename: ".env",
    updater: {
        readVersion: (contents) => {
            const regex = /GSOL_VERSION=?([a-zA-Z0-9\-_.]*)?/;
            const found = contents.match(regex);
            if (found === null) {
                throw new Error("GSOL_VERSION is not present.");
            }
            if (typeof found[1] === "undefined" || found[1] === "") {
                throw new Error("GSOL_VERSION is empty.");
            }
            return found[1];
        },
        writeVersion: (contents, version) => {
            const regex = /GSOL_VERSION=?([a-zA-Z0-9\-_.]*)?/;
            const newContents = contents.replace(regex, `GSOL_VERSION=${version}`);
            return newContents;
        }
    }
}
module.exports= {
    "header": "# Changelog",
    "types": [
        {"type": "feat", "section": "⚡️ Features", "hidden": false},
        {"type": "fix", "section": "🐛 Bug Fixes", "hidden": false}
    ],
    "bumpFiles": [
        {
            "filename": "package.json",
            "type": "json"
        },
        {
            "filename": "package-lock.json",
            "type": "json"
        },
            dotEnvFileUpdater
    ]
}

The .env file will correctly get updated, however the following error will be seen while NPM is running:

Unable to obtain updater for: {"filename":".env","updater":{}}
 - Error: Unsupported file (.env) provided for bumping.
 Please specify the updater `type` or use a custom `updater`.

Expected behavior

The expectation is that the error is not thrown. We believe the problem is the fact that we are including a file name and the updater as an object, and the filename check is throwing the error while the updater is correctly running.

Environment

TimothyJones commented 2 years ago

Thanks for the detailed report! I’ll take a look in the next couple of days

TimothyJones commented 2 years ago

Now releasing 10.0.1 which should fix this. Can you give it a go and let me know if it works?

TimothyJones commented 2 years ago

I'll close this assuming it works, please reopen if you need anything further

wcl-onespan commented 2 years ago

Thank you Timothy, I can confirm this is working just fine now. We have implemented the library into our CICD, and it is working very well.