@j-ulrich/release-it-regex-bumper 3.0.2 → 4.0.0
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 +4 -0
- package/index.js +31 -44
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -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
|
```
|
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 ) {
|
|
@@ -430,18 +430,6 @@ function replacePlaceholders( template, placeholderMap ) {
|
|
|
430
430
|
} );
|
|
431
431
|
}
|
|
432
432
|
|
|
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
433
|
function firstNotNil( ...args ) {
|
|
446
434
|
return args.find( ( ele ) => !_.isNil( ele ) );
|
|
447
435
|
}
|
|
@@ -474,4 +462,3 @@ class LineCounter {
|
|
|
474
462
|
}
|
|
475
463
|
}
|
|
476
464
|
|
|
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.0.0",
|
|
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
|
},
|
|
@@ -46,25 +47,24 @@
|
|
|
46
47
|
"xregexp": "^4.3.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"release-it": "
|
|
50
|
+
"release-it": "15 - 16"
|
|
50
51
|
},
|
|
51
52
|
"optionalDependencies": {
|
|
52
53
|
"diff": "^3.0.0 || ^4.0.0"
|
|
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": "^12.0.1",
|
|
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
|
}
|