diff --git a/build/tasks/versions.js b/build/tasks/versions.js index 02f5d9d..8d742f5 100644 --- a/build/tasks/versions.js +++ b/build/tasks/versions.js @@ -246,7 +246,20 @@ async function handleBumpVersionWithRegExp(outfile, label, options) { const writeStream = createWriteStream(outfile, { encoding: 'utf8' }); - rl.on('line', (line) => writeStream.write(line.replace(options.key, version) + "\n")); + rl.on('line', (line) => { + const found = line.match(options.key); + + if (found) { + const groups = (found.groups ?? {}); + const replace = found[0].replace( + (groups.build ?? groups.version ?? found[1] ?? found[0]), + version + ); + line = line.replace(found[0], replace); + } + + writeStream.write(line + "\n"); + }); await events.once(rl, 'close'); diff --git a/docs/development.md b/docs/development.md index 37cbffe..de895e7 100644 --- a/docs/development.md +++ b/docs/development.md @@ -387,7 +387,7 @@ The regular expression can be a `RegExp` object or a pattern prefixed with `rege * ```json { - "key": "regexp:(?<=^const ASSETS_VERSION = ')(?\\d+)(?=';$)" + "key": "regexp:(?<=^const ASSETS_VERSION = ')(?\\d+)(?=';$)" } ``` @@ -398,10 +398,14 @@ The regular expression can be a `RegExp` object or a pattern prefixed with `rege ``` * ```js { - key: /(?<=\bconst ASSETS_VERSION = )[^;]+/ + key: /^ \* Version: +(?:.+?)\+(.+?)$/ } ``` +The regular expression pattern will match the first occurrence and replace +the first match in the following order: `build` (named capture), `version` +(named capture), `1` (first capture), or `0` (whole match). + See [`versions.js`](../build/tasks/versions.js) for details. [Autoprefixer]: https://npmjs.com/package/autoprefixer