@j-ulrich/release-it-regex-bumper 2.0.0 → 3.0.2

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/.release-it.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "hooks": {
3
- "before:init": "npm test"
4
- },
5
- "plugins": {
6
- "./index.js": {
7
- "out": {
8
- "file": "README.md",
9
- "search": "Copyright (.*) (\\d{4}-)?\\d{4}",
10
- "replace": "Copyright $1 ${2}{{now:yyyy}}"
11
- }
12
- }
13
- }
14
- }
package/CHANGELOG.md DELETED
@@ -1,132 +0,0 @@
1
- # Changelog #
2
- This is the changelog of the release-it-regex-bumper plugin.
3
-
4
- This project adheres to [Semantic Versioning](https://semver.org).
5
- This changelog follows the [Keep a Changelog](https://keepachangelog.com) format.
6
-
7
-
8
- ---
9
-
10
-
11
- ## [2.0.0] - 2021-04-22 ##
12
-
13
- ### Changed ###
14
-
15
- #### Breaking Changes ####
16
- - [[#1]] Replaced Moment.js with date-fns. This means the format syntax for the date/time formatting has changed.
17
- See https://date-fns.org/v2.8.0/docs/format for the new syntax.
18
- ⚠️ Especially note that the year and day patterns now use lower case letters (for example `yyyy` and `dd`).
19
- See also https://git.io/fxCyr.
20
-
21
-
22
- ---
23
-
24
-
25
- ## [1.2.6] - 2021-04-22 ##
26
-
27
- ### Fixed ###
28
- - Version declaration of release-it peerDependency was too strict since older versions are supported as well.
29
-
30
-
31
- ---
32
-
33
-
34
- ## [1.2.5] - 2021-04-16 ##
35
-
36
- ### Fixed ###
37
- - [[#2]] Declared release-it as a peerDependency instead of a regular dependency.
38
-
39
-
40
- ---
41
-
42
-
43
- ## [1.2.4] - 2021-04-07 ##
44
-
45
- ### Fixed ###
46
- - Reverted unnecessary increase of dependency requirements in package.json.
47
-
48
-
49
- ---
50
-
51
-
52
- ## [1.2.3] - 2021-04-07 ##
53
-
54
- ### Security ###
55
- - Updated dependencies to remove vulnerability CVE-2020-28498.
56
-
57
-
58
- ---
59
-
60
-
61
- ## [1.2.2] - 2021-04-07 ##
62
-
63
- ### Security ###
64
- - Updated dependencies to remove vulnerability CVE-2020-7774.
65
-
66
-
67
- ---
68
-
69
-
70
- ## [1.2.1] - 2020-01-29 ##
71
-
72
- ### Fixed ###
73
- - Missing documentation of global `encoding` option.
74
- - Error in the example in the documentation.
75
-
76
- ### Security ###
77
- - Updated dependencies to remove low severity vulnerability CVE-2020-7788.
78
-
79
-
80
- ---
81
-
82
-
83
- ## [1.2.0] - 2020-09-10 ##
84
-
85
- ### Added ###
86
- - Placeholders `{{major}}`, `{{minor}}`, `{{patch}}`, `{{prerelease}}`, `{{build}}`,
87
- `{{versionWithoutBuild}}`, `{{versionWithoutPrerelease}}` and `{{{}}`.
88
-
89
- ### Fixed ###
90
- - Set maximum supported release-it version.
91
-
92
-
93
- ---
94
-
95
-
96
- ## [1.1.1] - 2020-09-03 ##
97
-
98
- ### Fixed ###
99
- - Incompatibility with release-it 14.x due to removed `global` property.
100
-
101
-
102
- ---
103
-
104
-
105
- ## [1.1.0] - 2020-09-02 ##
106
-
107
- ### Added ###
108
- - `out.files` option
109
-
110
-
111
- ---
112
-
113
-
114
- ## [1.0.0] - 2020-08-28 ##
115
- Initial release.
116
-
117
-
118
-
119
- [2.0.0]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/2.0.0
120
- [1.2.6]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.6
121
- [1.2.5]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.5
122
- [1.2.4]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.4
123
- [1.2.3]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.3
124
- [1.2.2]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.2
125
- [1.2.1]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.1
126
- [1.2.0]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.2.0
127
- [1.1.1]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.1.1
128
- [1.1.0]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.1.0
129
- [1.0.0]: https://github.com/j-ulrich/release-it-regex-bumper/releases/tag/1.0.0
130
-
131
- [#2]: https://github.com/j-ulrich/release-it-regex-bumper/issues/2
132
- [#1]: https://github.com/j-ulrich/release-it-regex-bumper/issues/1
package/test.js DELETED
@@ -1,484 +0,0 @@
1
- const fs = require( 'fs' );
2
- const dateFns = require( 'date-fns' );
3
- const crypto = require( 'crypto' );
4
- const assert = require( 'assert' ).strict;
5
- const test = require( 'bron' );
6
- const mockFs = require( 'mock-fs' );
7
- const rewiremock = require( 'rewiremock/node' );
8
- const { factory, runTasks } = require( 'release-it/test/util' );
9
- const semver = require( 'semver' );
10
- const releaseItVersion = semver.parse( require( 'release-it/package.json' ).version );
11
- const PluginWithoutDiff = rewiremock.proxy ( () => require( '.' ), mock => {
12
- return {
13
- 'diff': mock.with( null )
14
- };
15
- } );
16
- const Plugin = require( '.' );
17
-
18
- const namespace = '@j-ulrich/release-it-regex-bumper';
19
-
20
- const readFile = ( file, encoding ) => fs.readFileSync( file ).toString( encoding );
21
- const writeFile = ( file, content, encoding ) => fs.writeFileSync( file, content, { encoding } );
22
-
23
- mockFs();
24
-
25
- const setupTestDir = () => {
26
- const dirName = 'testDir_' + crypto.randomBytes( 4 ).readUInt32LE( 0 );
27
- fs.mkdirSync( dirName );
28
- writeFile( dirName + '/versions.txt', 'some: 1.0.0\nthis: 1.0.1\nother: 2.0.0\n' );
29
- writeFile( dirName + '/VERSION', '1.0.1' );
30
- writeFile( dirName + '/copyright.txt', 'Copyright (c) 2019 Foo Bar' );
31
- writeFile( dirName + '/unrelated.txt', 'nothing to see here.' );
32
- return dirName;
33
- };
34
-
35
- const it = ( description, testFunc ) => {
36
- test( description, async () => {
37
- const testDir = setupTestDir();
38
- try {
39
- const result = await testFunc( testDir );
40
- return result;
41
- }
42
- catch( e ) {
43
- if ( e instanceof SkipException ) {
44
- console.warn( `⚠️ Skipped test '${description}'\n Reason: ${e.message}\n ${e.stack}` );
45
- return null;
46
- }
47
- throw e;
48
- }
49
- } );
50
- };
51
-
52
- const skip = ( message ) => {
53
- const stackEntry = new Error().stack.split( '\n' )[ 2 ];
54
- throw new SkipException( message, stackEntry );
55
- };
56
-
57
- class SkipException {
58
- constructor( message, stack ) {
59
- this.message = message;
60
- this.stack = stack;
61
- }
62
- }
63
-
64
-
65
- const setupPlugin = ( pluginOptions, generalOptions, pluginModule = Plugin ) => {
66
- const options = Object.assign( { [namespace]: pluginOptions }, generalOptions );
67
- let container = {};
68
- const plugin = factory( pluginModule, { namespace, options, container } );
69
- return { plugin, container };
70
- };
71
-
72
- const assertLogMessage = ( logType, messageRegEx, failMessage ) => {
73
- assert( logType.args.findIndex( args => messageRegEx.test( args[ 0 ] ) ) > -1, failMessage );
74
- };
75
-
76
-
77
- //####### GetLatestVersion (Input) Tests #######
78
-
79
- it( 'should throw if in file is not specified', async () => {
80
- const pluginOptions = { in: {} };
81
- const { plugin } = setupPlugin( pluginOptions );
82
- await assert.rejects( plugin.getLatestVersion(), Error );
83
- } );
84
-
85
- it( 'should throw if in file cannot be read', async () => {
86
- const pluginOptions = { in: 'file_which_does_not_exist.txt' };
87
- const { plugin } = setupPlugin( pluginOptions );
88
- await assert.rejects( plugin.getLatestVersion(), Error );
89
- } );
90
-
91
- it( 'should throw if version cannot be extracted', async ( testDir ) => {
92
- const pluginOptions = { in: testDir+'/unrelated.txt' };
93
- const { plugin } = setupPlugin( pluginOptions );
94
- await assert.rejects( plugin.getLatestVersion(), err => {
95
- assert( /could not extract version/i.test( err.message ) );
96
- return true;
97
- } );
98
- } );
99
-
100
- const testGetLatestVersion = async ( pluginOptions, expectedVersion ) => {
101
- const { plugin } = setupPlugin( pluginOptions );
102
- const actualVersion = await plugin.getLatestVersion();
103
- assert.equal( actualVersion, expectedVersion );
104
- };
105
-
106
- it( 'should return latest version from file', async ( testDir ) => {
107
- const options = { in: testDir+'/versions.txt' };
108
- await testGetLatestVersion( options, '1.0.0' );
109
- });
110
-
111
- it( 'should return latest version from file using custom pattern', async ( testDir ) => {
112
- const options = { in: { file: testDir+'/versions.txt', search: 'this: ([0-9.]+)' } };
113
- await testGetLatestVersion( options, '1.0.1' );
114
- });
115
-
116
- it( 'should return latest version from file using custom pattern with null version capture group', async ( testDir ) => {
117
- const options = { in: { file: testDir+'/versions.txt', search: { pattern: 'this: ([0-9.]+)', versionCaptureGroup: null } } };
118
- await testGetLatestVersion( options, '1.0.1' );
119
- });
120
-
121
- it( 'should return latest version from file using custom pattern with null flags', async ( testDir ) => {
122
- const options = { in: { file: testDir+'/versions.txt', search: { pattern: 'this: ([0-9.]+)', flags: null } } };
123
- await testGetLatestVersion( options, '1.0.1' );
124
- });
125
-
126
- it( 'should return latest version from file using null search', async ( testDir ) => {
127
- const options = { in: { file: testDir+'/versions.txt', search: null } };
128
- await testGetLatestVersion( options, '1.0.0' );
129
- });
130
-
131
- it( 'should return latest version from file using custom pattern with named capturing group', async ( testDir ) => {
132
- const options = { in: { file: testDir+'/versions.txt', search: '(this): (?<version>[0-9.]+)' } };
133
- await testGetLatestVersion( options, '1.0.1' );
134
- });
135
-
136
- it( 'should return latest version from file using custom pattern with multiple capturing groups', async ( testDir ) => {
137
- const options = { in: { file: testDir+'/versions.txt', search: { pattern: '(this): ([0-9.]+)', versionCaptureGroup: 2 } } };
138
- await testGetLatestVersion( options, '1.0.1' );
139
- });
140
-
141
- it( 'should return latest version from file using custom pattern and versionCaptureGroup 0', async ( testDir ) => {
142
- const options = { in: { file: testDir+'/versions.txt', search: { pattern: '([0-9]+)\.([0-9]+)\.([0-9]+)', versionCaptureGroup: 0 } } };
143
- await testGetLatestVersion( options, '1.0.0' );
144
- });
145
-
146
- it( 'should return latest version from file using custom pattern and named versionCaptureGroup', async ( testDir ) => {
147
- const options = { in: { file: testDir+'/versions.txt', search: { pattern: '(this): (?<special>[0-9.]+)', versionCaptureGroup: 'special' } } };
148
- await testGetLatestVersion( options, '1.0.1' );
149
- });
150
-
151
- it( 'should return latest version from file using custom pattern with flags', async ( testDir ) => {
152
- const options = { in: { file: testDir+'/versions.txt', search: { pattern: 'THIS: ([0-9.]+)', flags: 'i' } } };
153
- await testGetLatestVersion( options, '1.0.1' );
154
- });
155
-
156
- it( 'should return latest version from file using global pattern with flags', async ( testDir ) => {
157
- const options = { search: { pattern: 'THIS: ([0-9.]+)', flags: 'i' }, in: testDir+'/versions.txt' };
158
- await testGetLatestVersion( options, '1.0.1' );
159
- });
160
-
161
- it( 'should return latest version from file with given encoding', async ( testDir ) => {
162
- writeFile( testDir+'/version.txt', '1.0.1', 'ucs2' );
163
- const options = { in: { file: testDir+'/version.txt', encoding: 'ucs2' } };
164
- await testGetLatestVersion( options, '1.0.1' );
165
- });
166
-
167
-
168
- //####### Bump (Output) Tests #######
169
-
170
- it( 'should write version to file', async ( testDir ) => {
171
- const pluginOptions = { out: testDir+'/versions.txt' };
172
- const { plugin } = setupPlugin( pluginOptions );
173
- await plugin.bump( '1.2.3' );
174
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
175
- } );
176
-
177
- it( 'should write version to file using null search and replace', async ( testDir ) => {
178
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: null, replace: null } };
179
- const { plugin } = setupPlugin( pluginOptions );
180
- await plugin.bump( '1.2.3' );
181
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
182
- } );
183
-
184
- it( 'should throw if out file cannot be read', async () => {
185
- const pluginOptions = { out: 'file_which_does_not_exist.txt' };
186
- const { plugin } = setupPlugin( pluginOptions );
187
- await assert.rejects( plugin.bump( '1.2.3' ), Error );
188
- } );
189
-
190
- it( 'should warn if out file did not change', async ( testDir ) => {
191
- const pluginOptions = { out: testDir+'/unrelated.txt' };
192
- const { plugin, container } = setupPlugin( pluginOptions );
193
- await assert.doesNotReject( plugin.bump( '1.2.3' ) );
194
- assert.equal( readFile( testDir+'/unrelated.txt' ), 'nothing to see here.' );
195
- assert( container.log.warn.called, 'No warning was logged' );
196
- assertLogMessage( container.log.warn, /\/unrelated\.txt" did not change/, 'warning regarding unchanged file was not logged' );
197
- } );
198
-
199
- const testBump = async ( testDir, pluginOptions, expectedContent, newVersion='1.2.3' ) => {
200
- const { plugin } = setupPlugin( pluginOptions );
201
- await plugin.bump( newVersion );
202
- assert.equal( readFile( testDir+'/versions.txt' ), expectedContent );
203
- };
204
-
205
- const testBumpThisVersion = async ( testDir, pluginOptions ) => {
206
- await testBump( testDir, pluginOptions, 'some: 1.0.0\nthis: 1.2.3\nother: 2.0.0\n' );
207
- };
208
-
209
- it( 'should write version to file using custom pattern', async ( testDir ) => {
210
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: '(?<=this: )([0-9.]+)' } };
211
- await testBumpThisVersion( testDir, pluginOptions );
212
- } );
213
-
214
- it( 'should write version to file using custom pattern with flags', async ( testDir ) => {
215
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: { pattern: '(?<=THIS: )([0-9.]+)', flags: 'i' } } };
216
- await testBumpThisVersion( testDir, pluginOptions );
217
- } );
218
-
219
- it( 'should write version to file using global pattern', async ( testDir ) => {
220
- const pluginOptions = { search: '(?<=this: )([0-9.]+)', out: { file: testDir+'/versions.txt' } };
221
- await testBumpThisVersion( testDir, pluginOptions );
222
- } );
223
-
224
- it( 'should write version to file using global pattern with flags', async ( testDir ) => {
225
- const pluginOptions = { search: { pattern: '(?<=THIS: )([0-9.]+)', flags: 'i' }, out: testDir+'/versions.txt' };
226
- await testBumpThisVersion( testDir, pluginOptions );
227
- } );
228
-
229
- it( 'should write version to file using global pattern and global replace', async ( testDir ) => {
230
- const pluginOptions = { search: '(this:) ([0-9.]+)', replace: '$1 {{version}}', out: testDir+'/versions.txt' };
231
- await testBumpThisVersion( testDir, pluginOptions );
232
- } );
233
-
234
- it( 'should write version to file using custom pattern and custom replace', async ( testDir ) => {
235
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: 'this: [0-9.]+', replace: 'this: {{version}}' } };
236
- await testBumpThisVersion( testDir, pluginOptions );
237
- } );
238
-
239
- it( 'should write version to file using custom pattern and custom replace with capturing group', async ( testDir ) => {
240
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: '(this:) [0-9.]+', replace: '$1 {{version}}' } };
241
- await testBumpThisVersion( testDir, pluginOptions );
242
- } );
243
-
244
- it( 'should write version to file using custom pattern and custom replace with named capturing group', async ( testDir ) => {
245
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: '(?<prefix>this:) [0-9.]+', replace: '${prefix} {{version}}' } };
246
- await testBumpThisVersion( testDir, pluginOptions );
247
- } );
248
-
249
- it( 'should write version to all matches in file', async ( testDir ) => {
250
- const pluginOptions = { out: { file: testDir+'/versions.txt', search: { pattern: '([0-9.]+)', flags: 'g' } } };
251
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.2.3\nother: 1.2.3\n' );
252
- } );
253
-
254
- it( 'should write version to different matches in same file', async ( testDir ) => {
255
- const pluginOptions = { out: [ { file: testDir+'/versions.txt', search: '(?<=this: )([0-9.]+)' }, { file: testDir+'/versions.txt', search: '(?<=other: )([0-9.]+)' } ] };
256
- await testBump( testDir, pluginOptions, 'some: 1.0.0\nthis: 1.2.3\nother: 1.2.3\n' );
257
- } );
258
-
259
- it( 'should write version to multiple files', async ( testDir ) => {
260
- const pluginOptions = { out: [ testDir+'/versions.txt', testDir+'/VERSION' ] };
261
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
262
- assert.equal( readFile( testDir+'/VERSION' ), '1.2.3' );
263
- } );
264
-
265
- it( 'should write version to multiple files using glob pattern', async ( testDir ) => {
266
- writeFile( testDir + '/version.txt', '1.0.1' );
267
- const pluginOptions = { out: [ testDir+'/version*.txt', testDir+'/VERSION' ] };
268
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
269
- assert.equal( readFile( testDir+'/version.txt' ), '1.2.3' );
270
- assert.equal( readFile( testDir+'/VERSION' ), '1.2.3' );
271
- } );
272
-
273
- it( 'should write version to multiple files using same options', async ( testDir ) => {
274
- const pluginOptions = { out: { files: [ testDir+'/versions.txt', testDir+'/VERSION' ], replace: '{{version}}-dev' } };
275
- await testBump( testDir, pluginOptions, 'some: 1.2.3-dev\nthis: 1.0.1\nother: 2.0.0\n' );
276
- assert.equal( readFile( testDir+'/VERSION' ), '1.2.3-dev' );
277
- } );
278
-
279
- it( 'should write version to multiple files using glob pattern and same options', async ( testDir ) => {
280
- writeFile( testDir + '/version.txt', '1.0.1' );
281
- const pluginOptions = { out: { files: [ testDir+'/version*.txt', testDir+'/VERSION' ], replace: '{{version}}-dev' } };
282
- await testBump( testDir, pluginOptions, 'some: 1.2.3-dev\nthis: 1.0.1\nother: 2.0.0\n' );
283
- assert.equal( readFile( testDir+'/version.txt' ), '1.2.3-dev' );
284
- assert.equal( readFile( testDir+'/VERSION' ), '1.2.3-dev' );
285
- } );
286
-
287
- it( 'should write version to out.file and out.files', async ( testDir ) => {
288
- const pluginOptions = { out: { file: testDir+'/versions.txt', files: testDir+'/VERSION' } };
289
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
290
- assert.equal( readFile( testDir+'/VERSION' ), '1.2.3' );
291
- } );
292
-
293
- it( 'should write version to out.file if out.files is null', async ( testDir ) => {
294
- const pluginOptions = { out: { file: testDir+'/versions.txt', files: null } };
295
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
296
- } );
297
-
298
- it( 'should write version to out.files if out.file is null', async ( testDir ) => {
299
- const pluginOptions = { out: { file: null, files: testDir+'/versions.txt' } };
300
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n' );
301
- } );
302
-
303
- it( 'should write version to multiple files using different patterns', async ( testDir ) => {
304
- const pluginOptions = { out: [ { file: testDir+'/versions.txt', search: '(?<=this: )([0-9.]+)' }, testDir+'/VERSION' ] };
305
- await testBump( testDir, pluginOptions, 'some: 1.0.0\nthis: 1.2.3\nother: 2.0.0\n' );
306
- assert.equal( readFile( testDir+'/VERSION' ), '1.2.3' );
307
- } );
308
-
309
- it( 'should write date to file', async ( testDir ) => {
310
- const pluginOptions = { out: { file: testDir+'/copyright.txt', search: '\\d{4}', replace: '{{now}}' } };
311
- const { plugin } = setupPlugin( pluginOptions );
312
- await plugin.bump( '1.2.3' );
313
- const fileContent = await readFile( testDir+'/copyright.txt' );
314
- const fileContentMatch = /^Copyright \(c\) (.+) Foo Bar$/.exec( fileContent );
315
- assert( fileContentMatch );
316
- assert( fileContentMatch[ 1 ] );
317
- const date = dateFns.parseISO( fileContentMatch[ 1 ] );
318
- assert( dateFns.isValid( date ) );
319
- assert( dateFns.differenceInSeconds( new Date(), date ) < 5 );
320
- } );
321
-
322
- it( 'should write date to file using format', async ( testDir ) => {
323
- const pluginOptions = { out: { file: testDir+'/copyright.txt', search: '\\d{4}', replace: '{{now:yyyy}}' } };
324
- const { plugin } = setupPlugin( pluginOptions );
325
- await plugin.bump( '1.2.3' );
326
- assert.equal( readFile( testDir+'/copyright.txt' ), `Copyright (c) ${dateFns.format( new Date(), 'yyyy' )} Foo Bar` );
327
- } );
328
-
329
- it( 'should throw when using Moment.js date format', async ( testDir ) => {
330
- const pluginOptions = { out: { file: testDir+'/copyright.txt', search: '\\d{4}', replace: '{{now:YYYY}}' } };
331
- const { plugin } = setupPlugin( pluginOptions );
332
- await assert.rejects( plugin.bump( '1.2.3' ), RangeError );
333
- } );
334
-
335
- it( 'should write main version placeholders to file', async ( testDir ) => {
336
- const pluginOptions = { out: { file: testDir+'/versions.txt', replace: '{{major}}.{{minor}}.{{patch}}' } };
337
- await testBump( testDir, pluginOptions, 'some: 1.2.3\nthis: 1.0.1\nother: 2.0.0\n', '1.2.3-alpha.1+build.17' );
338
- } );
339
-
340
- it( 'should write secondary version placeholders to file', async ( testDir ) => {
341
- const pluginOptions = { out: { file: testDir+'/versions.txt', replace: '-{{prerelease}}+{{build}}' } };
342
- await testBump( testDir, pluginOptions, 'some: -alpha.1+build.17\nthis: 1.0.1\nother: 2.0.0\n', '1.2.3-alpha.1+build.17' );
343
- } );
344
-
345
- it( 'should write custom version placeholders to file', async ( testDir ) => {
346
- const pluginOptions = { out: { file: testDir+'/versions.txt', replace: '{{versionWithoutPrerelease}}/{{versionWithoutBuild}}' } };
347
- await testBump( testDir, pluginOptions, 'some: 1.2.3/1.2.3-alpha.1\nthis: 1.0.1\nother: 2.0.0\n', '1.2.3-alpha.1+build.17' );
348
- } );
349
-
350
- it( 'should write literal curly brace to file', async ( testDir ) => {
351
- const pluginOptions = { out: { file: testDir+'/versions.txt', replace: '{{{}}{foo}}' } };
352
- await testBump( testDir, pluginOptions, 'some: {{foo}}\nthis: 1.0.1\nother: 2.0.0\n', '1.2.3-alpha.1+build.17' );
353
- } );
354
-
355
- it( 'should write literal curly brace to file', async ( testDir ) => {
356
- const pluginOptions = { out: { file: testDir+'/versions.txt', replace: '{{{}}{foo}}' } };
357
- await testBump( testDir, pluginOptions, 'some: {{foo}}\nthis: 1.0.1\nother: 2.0.0\n', '1.2.3-alpha.1+build.17' );
358
- } );
359
-
360
- it( 'should write version to file with given encoding', async ( testDir ) => {
361
- writeFile( testDir+'/version.txt', '1.0.1', 'ucs2' );
362
- const pluginOptions = { out: { file: testDir+'/version.txt', encoding: 'ucs2' } };
363
- const { plugin } = setupPlugin( pluginOptions );
364
- await plugin.bump( '1.2.3' );
365
- assert.equal( readFile( testDir+'/version.txt', 'ucs2' ), '1.2.3' );
366
- } );
367
-
368
- const testDryRunBump = async ( testDir, pluginOptions ) => {
369
- const { plugin, container } = setupPlugin( pluginOptions, { 'dry-run': true } );
370
- await assert.doesNotReject( plugin.bump( '1.2.3' ) );
371
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.0.0\nthis: 1.0.1\nother: 2.0.0\n' );
372
- assert.equal( readFile( testDir+'/VERSION' ), '1.0.1' );
373
- assert.equal( readFile( testDir+'/unrelated.txt' ), 'nothing to see here.' );
374
- return container;
375
- };
376
-
377
- it( 'should not write in dry run', async ( testDir ) => {
378
- const pluginOptions = { out: testDir+'/versions.txt' };
379
- const container = await testDryRunBump( testDir, pluginOptions );
380
- assert( !container.log.warn.called, `Unexpected warnings: ${container.log.warn.args}` );
381
- assert( container.log.exec.called, 'no diff was logged' );
382
- assertLogMessage( container.log.exec, /-some: 1\.0\.0/ );
383
- assertLogMessage( container.log.exec, /\+some: 1\.2\.3/ );
384
- } );
385
-
386
- it( 'should report all changes in dry run', async ( testDir ) => {
387
- const pluginOptions = { search: { pattern: '([0-9.]+)', flags: 'g' }, out: [ testDir+'/versions.txt', testDir+'/VERSION' ] };
388
- const container = await testDryRunBump( testDir, pluginOptions );
389
- assert( container.log.exec.called, 'no diff was logged' );
390
- assertLogMessage( container.log.info, /Updating .*\/versions.txt/ );
391
- assertLogMessage( container.log.exec, /-some: 1\.0\.0/ );
392
- assertLogMessage( container.log.exec, /\+some: 1\.2\.3/ );
393
- assertLogMessage( container.log.exec, /-this: 1\.0\.1/ );
394
- assertLogMessage( container.log.exec, /\+this: 1\.2\.3/ );
395
- assertLogMessage( container.log.exec, /-other: 2\.0\.0/ );
396
- assertLogMessage( container.log.exec, /\+other: 1\.2\.3/ );
397
- assertLogMessage( container.log.info, /Updating .*\/VERSION/ );
398
- assertLogMessage( container.log.exec, /-1\.0\.1/ );
399
- assertLogMessage( container.log.exec, /\+1\.2\.3/ );
400
- } );
401
-
402
- it( 'should warn in dry run if out file would not change', async ( testDir ) => {
403
- const pluginOptions = { out: testDir+'/unrelated.txt' };
404
- const container = await testDryRunBump( testDir, pluginOptions );
405
- assert( container.log.warn.called, 'no warnings were logged' );
406
- assertLogMessage( container.log.warn, /\/unrelated\.txt" did not change/, 'warning regarding unchanged file was not logged' );
407
- } );
408
-
409
- it( 'should report all changes in dry run without diff', async ( testDir ) => {
410
- const pluginOptions = { search: { pattern: '([0-9.]+)', flags: 'g' }, out: [ testDir+'/versions.txt', testDir+'/VERSION' ] };
411
- const { plugin, container } = setupPlugin( pluginOptions, { 'dry-run': true }, PluginWithoutDiff );
412
- await plugin.bump( '1.2.3' );
413
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.0.0\nthis: 1.0.1\nother: 2.0.0\n' );
414
- assert.equal( readFile( testDir+'/VERSION' ), '1.0.1' );
415
- assert( container.log.exec.called, 'no diff was logged' );
416
- assertLogMessage( container.log.info, /Updating .*\/versions.txt/ );
417
- assertLogMessage( container.log.exec, /.*line 1[\s\S]*1\.0\.0/ );
418
- assertLogMessage( container.log.exec, /.*line 2[\s\S]*1\.0\.1/ );
419
- assertLogMessage( container.log.exec, /.*line 3[\s\S]*2\.0\.0/ );
420
- assertLogMessage( container.log.info, /Updating .*\/VERSION/ );
421
- assertLogMessage( container.log.exec, /.*line 1[\s\S]*1\.0\.1/ );
422
- } );
423
-
424
- it( 'should warn in dry run without diff if out file would not change', async ( testDir ) => {
425
- const pluginOptions = { out: testDir+'/unrelated.txt' };
426
- const { plugin, container } = setupPlugin( pluginOptions, { 'dry-run': true }, PluginWithoutDiff );
427
- await assert.doesNotReject( plugin.bump( '1.2.3' ) );
428
- assert.equal( readFile( testDir+'/unrelated.txt' ), 'nothing to see here.' );
429
- assert( container.log.warn.called, 'no warnings were logged' );
430
- assertLogMessage( container.log.warn, /\/unrelated\.txt" did not change/, 'warning regarding unchanged file was not logged' );
431
- } );
432
-
433
-
434
- //####### End-to-End Tests #######
435
-
436
- const runPlugin = pluginOptions => {
437
- const { plugin } = setupPlugin( pluginOptions );
438
- return runTasks( plugin );
439
- };
440
-
441
- it( 'should not throw if nothing is configured', async () => {
442
- const pluginOptions = {};
443
- await assert.doesNotReject( runPlugin( pluginOptions ) );
444
- } );
445
-
446
- it( 'should not throw if in and out is null', async () => {
447
- const pluginOptions = { in: null, out: null };
448
- await assert.doesNotReject( runPlugin( pluginOptions ) );
449
- } );
450
-
451
- it( 'should read and write same file', async ( testDir ) => {
452
- const pluginOptions = { in: testDir+'/VERSION', out: testDir+'/VERSION' };
453
- await runPlugin( pluginOptions );
454
- assert.equal( readFile( testDir+'/VERSION' ), '1.0.2' );
455
- } );
456
-
457
- it( 'should read and write different files', async ( testDir ) => {
458
- const pluginOptions = { in: testDir+'/VERSION', out: testDir+'/versions.txt' };
459
- await runPlugin( pluginOptions );
460
- assert.equal( readFile( testDir+'/VERSION' ), '1.0.1' );
461
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.0.2\nthis: 1.0.1\nother: 2.0.0\n' );
462
- } );
463
-
464
- it( 'should read and write multiple files', async ( testDir ) => {
465
- const pluginOptions = { in: testDir+'/VERSION', out: [ testDir+'/VERSION', { file: testDir+'/versions.txt', search: 'this: [0-9.]+', replace: 'this: {{version}}' } ] };
466
- await runPlugin( pluginOptions );
467
- assert.equal( readFile( testDir+'/VERSION' ), '1.0.2' );
468
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.0.0\nthis: 1.0.2\nother: 2.0.0\n' );
469
- } );
470
-
471
- it( 'should write latest version to file', async ( testDir ) => {
472
- const pluginOptions = { in: testDir+'/VERSION', out: { file: testDir+'/versions.txt', replace: '{{latestVersion}}' } };
473
- await runPlugin( pluginOptions );
474
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.0.1\nthis: 1.0.1\nother: 2.0.0\n' );
475
- } );
476
-
477
- it( 'should write latest tag to file', async ( testDir ) => {
478
- if( semver.lt( releaseItVersion, '13.5.8' ) ) {
479
- skip( '`latestTag` is not available in tests before release-it 13.5.8' );
480
- }
481
- const pluginOptions = { in: testDir+'/VERSION', out: { file: testDir+'/versions.txt', replace: '{{latestTag}}' } };
482
- await runPlugin( pluginOptions );
483
- assert.equal( readFile( testDir+'/versions.txt' ), 'some: 1.0.1\nthis: 1.0.1\nother: 2.0.0\n' );
484
- } );