stephenlacy / bump-regex

bump regex with semver
MIT License
13 stars 10 forks source link

Invalid output when server metadata is present on version #18

Closed abhishekdev closed 6 years ago

abhishekdev commented 6 years ago

Given a initial version string that contains some metadata (e.g. 0.1.0-pre.2+meta.0) and bump() is called to set a fixed version that also contains metadata fragment for semver, e.g. 0.2.0+build.1, the logger output differs from the actual replacement that takes place.

Testcase

const bump = require("bump-regex");

const FIXED_VERSION = "0.2.0+build.1";

const results = ["0.1.0-pre+meta", "0.1.0-pre.2+meta.0"].map(semver => {
  const versionString = `"version: ${semver}"`;
  let output;
  bump(
    {
      str: versionString,
      version: FIXED_VERSION
    },
    (err, out) => {
      output = out;
    }
  );

  return {
    versionString,
    output
  };
});

console.log(results);

Output

[
  {
    versionString: '"version: 0.1.0-pre+meta"',
    output: {
      key: "version",
      type: "patch",
      case: false,
      keys: null,
      str: '"version: 0.2.0+build.1+meta"',
      version: "0.2.0+build.1",
      prev: "0.1.0-pre",
      new: "0.2.0+build.1"
    }
  },
  {
    versionString: '"version: 0.1.0-pre.2+meta.0"',
    output: {
      key: "version",
      type: "patch",
      case: false,
      keys: null,
      str: '"version: 0.2.0+build.1+meta.0"',
      version: "0.2.0+build.1",
      prev: "0.1.0-pre.2",
      new: "0.2.0+build.1"
    }
  }
];

Expected Output

Previous Version New version Output Version
0.1.0-pre+meta 0.2.0+build.1 0.2.0+build.1
0.1.0-pre.2+meta.0 0.2.0+build.1 0.2.0+build.1

Actual Output

Previous Version New version Output Version
0.1.0-pre+meta 0.2.0+build.1 0.2.0+build.1+meta.0 :x:
0.1.0-pre.2+meta.0 0.2.0+build.1 0.2.0+build.1+meta.0 :x:

Notice that bump() does not replace the previous metadata fragment and adds a new version before it. This results in an invalid semver. However, the opts.new does correctly reported the expected value.

stephenlacy commented 6 years ago

Beautiful issue, thank you