momocow / webpack-userscript

A Webpack plugin for userscript projects. 🙈
https://cow.moe/webpack-userscript/
MIT License
200 stars 21 forks source link

Custom buildNo transformation function #54

Closed StrikeAgainst closed 3 years ago

StrikeAgainst commented 3 years ago

I have a feature request regarding the automated buildNo incrementation for hot development. While I very much like this feature, I sometimes have issues updating the script in FireMonkey, as the internal version comparison logic for FireMonkey seemingly cannot deal with growing figures; e.g. when I'm updating the build from 3.3.1.9 to 3.3.1.10, then no update is registered, forcing me to tweak the version number manually to trigger an update. While this is just a minor complaint, it would provide some ease of use if we could supply a function which would allow us to process the provided buildNo before it's integrated into the version. In my case I would pad the number with zeroes to work around the issue with the figures.

momocow commented 3 years ago

Hi, you can provide a HeaderProvider in the headers config which is already a function executed each time the header is computed.

The function will receive an object of DataObject as the only argument, which contains the desired buildNo field.

You can read the buildNo and tweak the version yourself.

An simple example as follows,

module.exports = {
  plugins: [
    new WebpackUserscript({
      headers (data) {
        const paddedBuildNo = String(data.buildNo).padStart(3, “0”)
        return {
          version: `${data.version}-build.${paddedBuildNo}`
        }
      }
    })
  ]
}
momocow commented 3 years ago

I’ll close the issue since the current API can already fulfill the requirement.

Feel free to reopen this if it is still an issue to you. 🤗