ump 3.1.0 → 3.2.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/lib/commands.js CHANGED
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  import path from 'path';
4
- import Promises from 'bluebird';
5
4
  import fs from 'fs-extra';
6
5
  import {promisify} from 'util';
7
6
  import childProcess from 'child_process';
8
- import {utils} from './utils.js';
7
+ import {utils, peach} from './utils.js';
9
8
  import {config} from './config.js';
10
9
  import {log} from './log.js';
11
10
 
@@ -29,13 +28,13 @@ const commands = {
29
28
  // Need to pull before mucking with files, so we can stop it if git branch isn't clean.
30
29
  // Otherwise files will be bumped and committed but not pushed and things will get messed up.
31
30
  // **We can autostash on pull because we handle existence of uncommitted files later
32
- const pullRebase = 'git pull --rebase --autostash';
31
+ const pullAutostash = 'git pull --autostash';
33
32
 
34
33
  return {
35
- log: pullRebase,
34
+ log: pullAutostash,
36
35
  cmd: function() {
37
36
 
38
- return exec(pullRebase)
37
+ return exec(pullAutostash)
39
38
  .then(({stdout, stderr}) => {
40
39
  console.log(stdout);
41
40
 
@@ -45,6 +44,8 @@ const commands = {
45
44
  } else {
46
45
  utils.error(config.messages.gitPull);
47
46
  }
47
+ } else {
48
+ log.color(`Executed ${pullAutostash}`, 'cyan');
48
49
  }
49
50
  })
50
51
  .catch((err) => {
@@ -83,7 +84,7 @@ const commands = {
83
84
  return {
84
85
  log: `* Update version (using RegEx) to ${newVersion} in ${opts.extraFiles.join(', ')}`,
85
86
  cmd: function() {
86
- return Promises.each(opts.extras, (item) => {
87
+ return peach(opts.extras, (item) => {
87
88
  const file = item.file || item;
88
89
  const prefix = typeof item.prefix !== 'undefined' ? item.prefix : config.defaults.regexPrefix;
89
90
  const replace = typeof item.replaced !== 'undefined' ? item.replaced : config.defaults.regexReplace;
@@ -157,20 +158,22 @@ const commands = {
157
158
  utils.error(`Git working directory not clean:\n\t${lines.join('\n\t')}`);
158
159
  }
159
160
 
160
- return Promises.each(releaseSteps, (command) => {
161
+ try {
162
+ const ret = await peach(releaseSteps, (command) => {
163
+ return exec(command)
164
+ .then(() => {
165
+ log.color(`Executed ${command}`, 'cyan');
166
+ })
167
+ .catch(utils.error);
168
+ });
161
169
 
162
- return exec(command)
163
- .then(() => {
164
- log.color(`Executed ${command}`, 'cyan');
165
- })
166
- .catch(utils.error);
167
- })
168
- .catch((error) => {
170
+ return ret;
171
+ } catch (error) {
169
172
  const err = error || config.messages.noRepo;
170
173
 
171
174
  log.color(err, 'red');
172
175
  utils.error(opts);
173
- });
176
+ }
174
177
  },
175
178
  };
176
179
  },
package/lib/utils.js CHANGED
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  import path from 'path';
4
- import childProcess from 'child_process';
5
- import Promises from 'bluebird';
6
4
  import fs from 'fs';
7
5
  import util from 'util';
8
6
  import glob from 'glob';
@@ -231,4 +229,39 @@ const utils = {
231
229
  },
232
230
  };
233
231
 
234
- export {utils};
232
+ /**
233
+ * @callback ArrayCallback
234
+ * @param {any} item
235
+ * @param {number} [index]
236
+ * @param {array} [array]
237
+ * @returns {Promise}
238
+ */
239
+
240
+ /**
241
+ * "Promised `each()`" for iterating over an array of items, calling a function that returns a promise for each one. So, each one waits for the previous one to resolve before being called
242
+ * @function peach
243
+ * @param {array} arr Array to iterate over
244
+ * @param {ArrayCallback} fn Function that is called for each element in the array, each returning a promise
245
+ * @returns {Array.<Promise>} Array of promises
246
+ */
247
+ const peach = (arr, fn) => {
248
+ const originalArray = [...arr];
249
+ const funcs = arr.map((item, i) => {
250
+ return () => fn(item, i, originalArray);
251
+ });
252
+
253
+ // @ts-ignore
254
+ return funcs.reduce((promise, func) => {
255
+ return promise
256
+ .then((result) => {
257
+ const called = func();
258
+ // If the function doesn't return a "then-able", create one with Promise.resolve():
259
+
260
+ return (typeof called.then === 'function' ? called : Promise.resolve(called))
261
+ .then([].concat.bind(result));
262
+ });
263
+
264
+ }, Promise.resolve([]));
265
+ };
266
+
267
+ export {utils, peach};
package/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "ump",
3
3
  "title": "ump",
4
- "version": "3.1.0",
4
+ "version": "3.2.0",
5
5
  "description": "Bump without the B",
6
6
  "scripts": {
7
7
  "test": "npm run test:clean && npm run test:pre && npm run test:run",
8
8
  "test:clean": "rm -rf ./test/testarea",
9
9
  "test:pre": "npm run lint && mkdir -p \"./test/testarea\"",
10
10
  "test:run": "node_modules/.bin/mocha --delay --reporter spec",
11
- "lint": "eslint --config .eslintrc.cjs *.js bin lib test",
12
- "snyk-protect": "snyk protect",
13
- "prepare": "npm run snyk-protect"
11
+ "lint": "eslint --config .eslintrc.cjs *.js bin lib test"
14
12
  },
15
13
  "repository": {
16
14
  "type": "git",
@@ -30,24 +28,22 @@
30
28
  "node": ">=14"
31
29
  },
32
30
  "dependencies": {
33
- "bluebird": "^3.7.2",
34
- "chalk": "^5.0.0",
35
- "fs-extra": "^10.0.0",
31
+ "chalk": "^5.1.2",
32
+ "fs-extra": "^10.1.0",
36
33
  "git-config": "^0.0.7",
37
- "glob": "^7.2.0",
38
- "inquirer": "^8.2.0",
34
+ "glob": "^8.0.3",
35
+ "inquirer": "^9.1.4",
39
36
  "rc": "^1.2.8",
40
- "semver": "^7.3.5",
41
- "snyk": "^1.812.0",
37
+ "semver": "^7.3.8",
42
38
  "update-notifier": "^6.0.2",
43
- "yargs": "^17.3.1"
39
+ "yargs": "^17.6.2"
44
40
  },
45
41
  "devDependencies": {
46
- "chai": "^4.3.4",
47
- "eslint": "^8.5.0",
48
- "eslint-config-kswedberg": "^5.1.1",
42
+ "@types/mocha": "^10.0.0",
43
+ "chai": "^4.3.7",
44
+ "eslint": "^8.27.0",
45
+ "eslint-config-kswedberg": "^5.1.2",
49
46
  "mocha": "^9.1.3"
50
47
  },
51
- "license": "MIT",
52
- "snyk": true
48
+ "license": "MIT"
53
49
  }
package/test/test.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from 'path';
2
- import Promises from 'bluebird';
2
+
3
3
  import fs from 'fs-extra';
4
4
  import ump from '../ump.js';
5
- import {utils} from '../lib/utils.js';
5
+ import {utils, peach} from '../lib/utils.js';
6
6
  import {commands} from '../lib/commands.js';
7
7
 
8
8
  import {expect} from 'chai';
@@ -114,7 +114,7 @@ const files = [
114
114
 
115
115
  const runTests = async() => {
116
116
  try {
117
- await Promises.each(files, (file) => {
117
+ await peach(files, (file) => {
118
118
  return fs.writeFile(path.join(dirname, 'testarea/', file.file), file.content);
119
119
  });
120
120
 
package/ump.js CHANGED
@@ -1,26 +1,25 @@
1
1
  'use strict';
2
2
 
3
- import Promises from 'bluebird';
4
3
  import inquirer from 'inquirer';
5
4
 
6
- import {utils} from './lib/utils.js';
5
+ import {utils, peach} from './lib/utils.js';
7
6
  import {commands} from './lib/commands.js';
8
7
  import {log} from './lib/log.js';
9
8
  import {config} from './lib/config.js';
10
9
 
11
10
  const sequence = [];
12
11
 
13
- const runCommands = function(sequence, options) {
14
- return Promises.each(sequence, (command) => {
15
- return command.cmd(options);
16
- })
17
- .then(() => {
12
+ const runCommands = async function(sequence, options) {
13
+ try {
14
+ await peach(sequence, (command) => {
15
+ return command.cmd(options);
16
+ });
17
+
18
18
  log.color('*** DONE! ***', 'green');
19
- })
20
- .catch((err) => {
19
+ } catch (err) {
21
20
  console.error(err);
22
21
  utils.resetVersion(options);
23
- });
22
+ }
24
23
  };
25
24
 
26
25
  const ump = async function(options) {
package/.snyk DELETED
@@ -1,13 +0,0 @@
1
- # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2
- version: v1.22.1
3
- # ignores vulnerabilities until expiry date; change duration by modifying expiry date
4
- ignore:
5
- SNYK-JS-Y18N-1021887:
6
- - snyk > snyk-config > nconf > yargs > y18n:
7
- reason: None given
8
- expires: '2020-12-31T17:48:39.548Z'
9
- # patches apply the minimum changes required to fix a vulnerability
10
- patch:
11
- SNYK-JS-LODASH-567746:
12
- - inquirer > lodash:
13
- patched: '2020-05-01T14:59:08.279Z'