@j-ulrich/release-it-regex-bumper 3.0.2 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/index.js +39 -47
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Regular expression based version read/write plugin for release-it
|
|
4
4
|
|
|
5
|
-

|
|
5
|
+
[](https://github.com/j-ulrich/release-it-regex-bumper/actions/workflows/CI.yml)
|
|
6
6
|
[](https://www.codacy.com/gh/j-ulrich/release-it-regex-bumper/dashboard?utm_source=github.com&utm_medium=referral&utm_content=j-ulrich/release-it-regex-bumper&utm_campaign=Badge_Coverage)
|
|
7
7
|
[](https://www.codacy.com/gh/j-ulrich/release-it-regex-bumper/dashboard?utm_source=github.com&utm_medium=referral&utm_content=j-ulrich/release-it-regex-bumper&utm_campaign=Badge_Grade)
|
|
8
8
|
|
|
@@ -18,6 +18,10 @@ below for details.
|
|
|
18
18
|
|
|
19
19
|
# Installation #
|
|
20
20
|
|
|
21
|
+
> ⚠️ **Note:**
|
|
22
|
+
> Version 4 and later of release-it-regex-bumper require version 15 or later of release-it.
|
|
23
|
+
> When you are using release-it version 14.x or earlier, then use release-it-regex-bumper version 3.x or earlier.
|
|
24
|
+
|
|
21
25
|
```
|
|
22
26
|
npm install --save-dev @j-ulrich/release-it-regex-bumper
|
|
23
27
|
```
|
|
@@ -325,7 +329,7 @@ The template string also supports a set of placeholders:
|
|
|
325
329
|
- `{{prerelease}}` is replaced by the prerelease part of the new version or an empty string if the version does not
|
|
326
330
|
have a prerelease part.
|
|
327
331
|
Since: 1.2.0
|
|
328
|
-
- `{{prefixedPrerelease}}` is replaced by a dash ('-') followed by the prerelease part of the new version or
|
|
332
|
+
- `{{prefixedPrerelease}}` is replaced by a dash ('-') followed by the prerelease part of the new version or an empty
|
|
329
333
|
string if the version does not have a prerelease part.
|
|
330
334
|
Since: 3.0.0
|
|
331
335
|
- `{{build}}` is replaced by the build part of the new version or an empty string if the version does not have a
|
package/index.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const semver = require( 'semver' );
|
|
18
|
-
const { Plugin } = require( 'release-it' );
|
|
19
|
-
const dateFormat = require( 'date-fns/format' );
|
|
20
|
-
const dateFormatIso = require( 'date-fns/formatISO' );
|
|
21
|
-
const diff = optionalRequire( 'diff' );
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const readFile = util.promisify( fs.readFile );
|
|
25
|
-
const writeFile = util.promisify( fs.writeFile );
|
|
1
|
+
|
|
2
|
+
import { readFile as fsReadFile, writeFile as fsWriteFile } from 'fs';
|
|
3
|
+
import { strict as assert } from 'assert';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import glob from 'fast-glob';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import _ from 'lodash';
|
|
8
|
+
import XRegExp from 'xregexp';
|
|
9
|
+
import semver from 'semver';
|
|
10
|
+
import { Plugin } from 'release-it';
|
|
11
|
+
import dateFormat from 'date-fns/format/index.js';
|
|
12
|
+
import dateFormatIso from 'date-fns/formatISO/index.js';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const readFile = promisify( fsReadFile );
|
|
16
|
+
const writeFile = promisify( fsWriteFile );
|
|
26
17
|
|
|
27
18
|
const semanticVersionRegex = XRegExp(
|
|
28
19
|
// eslint-disable-next-line security/detect-unsafe-regex
|
|
@@ -40,7 +31,7 @@ const defaultReplace = '{{version}}';
|
|
|
40
31
|
|
|
41
32
|
|
|
42
33
|
|
|
43
|
-
class RegExBumper extends Plugin {
|
|
34
|
+
export default class RegExBumper extends Plugin {
|
|
44
35
|
|
|
45
36
|
constructor( ...args ) {
|
|
46
37
|
super( ...args );
|
|
@@ -120,7 +111,7 @@ class RegExBumper extends Plugin {
|
|
|
120
111
|
const fileContent = await readFile( file, { encoding: effectiveEncoding } );
|
|
121
112
|
|
|
122
113
|
if ( isDryRun ) {
|
|
123
|
-
this.loadDiff();
|
|
114
|
+
await this.loadDiff();
|
|
124
115
|
if ( this.diff ) {
|
|
125
116
|
const processedFileContent = replaceVersion( fileContent, replacedSearchRegex,
|
|
126
117
|
effectiveReplacement, context );
|
|
@@ -149,12 +140,21 @@ class RegExBumper extends Plugin {
|
|
|
149
140
|
/* eslint-enable no-await-in-loop */
|
|
150
141
|
}
|
|
151
142
|
|
|
152
|
-
loadDiff() {
|
|
153
|
-
if (
|
|
143
|
+
async loadDiff() {
|
|
144
|
+
if ( this.diff ) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const diff = await import( 'diff' );
|
|
149
|
+
if ( !diff || !diff.structuredPatch ) {
|
|
150
|
+
throw new Error( 'diff module no available' );
|
|
151
|
+
}
|
|
152
|
+
this.diff = diff;
|
|
153
|
+
}
|
|
154
|
+
catch ( e ) {
|
|
154
155
|
this.log.info( 'Optional "diff" package not available' );
|
|
155
|
-
this.log.verbose( 'Exception was:',
|
|
156
|
+
this.log.verbose( 'Exception was:', e );
|
|
156
157
|
}
|
|
157
|
-
this.diff = diff;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
diffAndReport( oldContent, newContent, filePath ) {
|
|
@@ -250,15 +250,20 @@ function extractVersion( content, versionRegex, versionCaptureGroup ) {
|
|
|
250
250
|
throw new Error( 'Could not extract version from file' );
|
|
251
251
|
}
|
|
252
252
|
if ( !_.isNil( versionCaptureGroup ) ) {
|
|
253
|
-
if ( hasOwnProperty( match, versionCaptureGroup ) ) {
|
|
253
|
+
if ( typeof versionCaptureGroup === 'number' && hasOwnProperty( match, versionCaptureGroup ) ) {
|
|
254
254
|
// object injection mitigated by checking hasOwnProperty()
|
|
255
255
|
// eslint-disable-next-line security/detect-object-injection
|
|
256
256
|
return match[versionCaptureGroup];
|
|
257
257
|
}
|
|
258
|
+
if ( match.groups && hasOwnProperty( match.groups, versionCaptureGroup ) ) {
|
|
259
|
+
// object injection mitigated by checking hasOwnProperty()
|
|
260
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
261
|
+
return match.groups[versionCaptureGroup];
|
|
262
|
+
}
|
|
258
263
|
}
|
|
259
264
|
else {
|
|
260
|
-
if ( hasOwnProperty( match, 'version' ) ) {
|
|
261
|
-
return match
|
|
265
|
+
if ( match.groups && hasOwnProperty( match.groups, 'version' ) ) {
|
|
266
|
+
return match.groups.version;
|
|
262
267
|
}
|
|
263
268
|
if ( hasOwnProperty( match, 1 ) ) {
|
|
264
269
|
return match[1];
|
|
@@ -430,18 +435,6 @@ function replacePlaceholders( template, placeholderMap ) {
|
|
|
430
435
|
} );
|
|
431
436
|
}
|
|
432
437
|
|
|
433
|
-
function optionalRequire( packageName ) {
|
|
434
|
-
try {
|
|
435
|
-
// eslint-disable-next-line security/detect-non-literal-require
|
|
436
|
-
return require( packageName );
|
|
437
|
-
}
|
|
438
|
-
/* c8 ignore next 4 */
|
|
439
|
-
/* rewiremock can't simulate the absence of a package so we can't test this case */
|
|
440
|
-
catch ( ex ) {
|
|
441
|
-
return ex;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
438
|
function firstNotNil( ...args ) {
|
|
446
439
|
return args.find( ( ele ) => !_.isNil( ele ) );
|
|
447
440
|
}
|
|
@@ -474,4 +467,3 @@ class LineCounter {
|
|
|
474
467
|
}
|
|
475
468
|
}
|
|
476
469
|
|
|
477
|
-
module.exports = RegExBumper;
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j-ulrich/release-it-regex-bumper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "Regular expression based version read/write plugin for release-it",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"files": [
|
|
7
8
|
"index.js"
|
|
8
9
|
],
|
|
9
10
|
"scripts": {
|
|
10
|
-
"test": "
|
|
11
|
-
"test+coverage": "npx c8
|
|
11
|
+
"test": "node --experimental-loader=testdouble ./node_modules/ava/entrypoints/cli.mjs --serial",
|
|
12
|
+
"test+coverage": "npx c8 node --experimental-loader=testdouble ./node_modules/ava/entrypoints/cli.mjs --serial",
|
|
12
13
|
"lint": "npx eslint .",
|
|
13
14
|
"release": "npx release-it"
|
|
14
15
|
},
|
|
@@ -38,33 +39,32 @@
|
|
|
38
39
|
"name": "Jochen Ulrich"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"chalk": "^
|
|
42
|
+
"chalk": "^5.0.0",
|
|
42
43
|
"date-fns": "^2.8.0",
|
|
43
44
|
"fast-glob": "^3.2.0",
|
|
44
45
|
"lodash": "^4.17.20",
|
|
45
46
|
"semver": "^7.3.0",
|
|
46
|
-
"xregexp": "^
|
|
47
|
+
"xregexp": "^5.0.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"release-it": "
|
|
50
|
+
"release-it": "15"
|
|
50
51
|
},
|
|
51
52
|
"optionalDependencies": {
|
|
52
|
-
"diff": "
|
|
53
|
+
"diff": "3 - 5"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@j-ulrich/eslint-config": "^1.0.0",
|
|
56
|
-
"@release-it/keep-a-changelog": "^
|
|
57
|
-
"
|
|
57
|
+
"@release-it/keep-a-changelog": "^3.0.0",
|
|
58
|
+
"ava": "^4.0.1",
|
|
58
59
|
"c8": "^7.3.0",
|
|
59
60
|
"eslint": "^8.6.0",
|
|
60
61
|
"eslint-plugin-security": "^1.4.0",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"temp": "^0.9.4"
|
|
62
|
+
"release-it": "^15.0.0",
|
|
63
|
+
"sinon": "^13.0.2",
|
|
64
|
+
"temp": "^0.9.4",
|
|
65
|
+
"testdouble": "^3.16.4"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
68
|
+
"node": ">=14.9"
|
|
69
69
|
}
|
|
70
70
|
}
|