ump 2.1.4 → 3.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/.eslintrc.cjs ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ extends: 'kswedberg',
3
+ env: {
4
+ mocha: true,
5
+ },
6
+ };
package/.snyk CHANGED
@@ -1,5 +1,5 @@
1
1
  # Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2
- version: v1.14.1
2
+ version: v1.22.1
3
3
  # ignores vulnerabilities until expiry date; change duration by modifying expiry date
4
4
  ignore:
5
5
  SNYK-JS-Y18N-1021887:
package/README.md CHANGED
@@ -29,7 +29,7 @@ For programmatic use (i.e. requiring it as a module in a node.js script), instal
29
29
  The only required option is `files`, which takes an array of files. All other options are the same as the command-line long-hand options: `message, release, publish, debug` (not `help`).
30
30
 
31
31
  ```js
32
- const ump = require('ump');
32
+ import ump from 'ump';
33
33
 
34
34
  ump({
35
35
  files: [
package/bin/ump.js CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('../lib/notifier');
4
- // const parser = require('nomnom');
5
- const ump = require('../ump');
6
-
7
- const yargs = require('yargs/yargs')(process.argv.slice(2));
8
- const options = require('../lib/config').cliOptions;
3
+ import('../lib/notifier.js');
4
+ import yarg from 'yargs/yargs.js';
5
+ import ump from '../ump.js';
6
+ import {config} from '../lib/config.js';
9
7
 
8
+ const options = config.cliOptions;
9
+ const yargs = yarg(process.argv.slice(2));
10
10
  const argv = yargs
11
11
  .usage('Usage: $0 <releaseType> [files]... [options]')
12
12
  .usage(`
package/lib/commands.js CHANGED
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
- const path = require('path');
4
- const Promises = require('bluebird');
5
- const fs = require('fs-extra');
6
- const {promisify} = require('util');
7
- const childProcess = require('child_process');
3
+ import path from 'path';
4
+ import Promises from 'bluebird';
5
+ import fs from 'fs-extra';
6
+ import {promisify} from 'util';
7
+ import childProcess from 'child_process';
8
+ import {utils} from './utils.js';
9
+ import {config} from './config.js';
10
+ import {log} from './log.js';
11
+
8
12
  const exec = promisify(childProcess.exec);
9
- const utils = require('./utils');
10
- const config = require('./config');
11
- const log = require('./log');
12
13
 
13
14
  const getFlags = (obj) => {
14
15
  return Object.entries(obj || {})
@@ -65,12 +66,13 @@ const commands = {
65
66
  return console.log(`Skipping version updates to ${files.join(', ')}`);
66
67
  }
67
68
 
68
- return files.forEach((file) => {
69
- const data = utils.readJSON(file);
69
+ return Promise.all(files.map(async(file) => {
70
+ const data = await utils.readJSON(file);
70
71
 
71
72
  data.version = newVersion;
72
73
  utils.writeJSON(file, data);
73
- });
74
+ }));
75
+
74
76
  },
75
77
  };
76
78
  },
@@ -83,9 +85,9 @@ const commands = {
83
85
  cmd: function() {
84
86
  return Promises.each(opts.extras, (item) => {
85
87
  const file = item.file || item;
86
- const prefix = item.prefix || config.defaults.regexPrefix;
87
- const replace = item.replaced || config.defaults.regexReplace;
88
- const flags = item.flags || config.defaults.regexFlags;
88
+ const prefix = typeof item.prefix !== 'undefined' ? item.prefix : config.defaults.regexPrefix;
89
+ const replace = typeof item.replaced !== 'undefined' ? item.replaced : config.defaults.regexReplace;
90
+ const flags = typeof item.flags !== 'undefined' ? item.flags : config.defaults.regexFlags;
89
91
  const pattern = new RegExp(`(${prefix})(${replace})`, flags);
90
92
 
91
93
  return fs.readFile(file, 'utf8')
@@ -111,8 +113,7 @@ const commands = {
111
113
  `git add ${files.join(' ')}`,
112
114
  `git commit -m "${msg}"`,
113
115
  `git tag ${newVersion} -f -a -m "${msg}"`,
114
- 'git push',
115
- 'git push --tags',
116
+ 'git push --follow-tags',
116
117
  ];
117
118
 
118
119
  if (opts.publish) {
@@ -175,4 +176,4 @@ const commands = {
175
176
  },
176
177
  };
177
178
 
178
- module.exports = commands;
179
+ export {commands};
package/lib/config.js CHANGED
@@ -1,12 +1,15 @@
1
- const path = require('path');
1
+ import path from 'path';
2
+ import fs from 'fs-extra';
3
+
2
4
  let pkg = {};
3
5
 
4
6
  try {
5
- pkg = require(path.join(process.cwd(), 'package.json'));
7
+ pkg = fs.readJsonSync(path.join(process.cwd(), 'package.json'));
6
8
  } catch (err) {
7
9
  pkg = {name: ''};
8
10
  }
9
- let config = {
11
+
12
+ const config = {
10
13
  defaults: {
11
14
  sourceFile: 'package.json',
12
15
  message: 'Release %s',
@@ -25,6 +28,7 @@ let config = {
25
28
  noRepo: 'You cannot "release" this version. You are not in a git repository.',
26
29
  noSource: 'The specified source file does not exist.',
27
30
  },
31
+
28
32
  releaseTypes: [
29
33
  'major',
30
34
  'minor',
@@ -33,14 +37,15 @@ let config = {
33
37
  'preminor',
34
38
  'prepatch',
35
39
  ],
36
- confirm: [
37
40
 
41
+ confirm: [
38
42
  {
39
43
  message: 'Are you sure you want to continue?',
40
44
  name: 'run',
41
45
  type: 'confirm',
42
46
  },
43
47
  ],
48
+
44
49
  publishPrompts: [
45
50
  {
46
51
  name: 'access',
@@ -57,7 +62,7 @@ let config = {
57
62
  ],
58
63
  };
59
64
 
60
- config = Object.assign(config, {
65
+ Object.assign(config, {
61
66
  cliOptions: {
62
67
  // releaseType: {
63
68
  // position: 0,
@@ -94,4 +99,4 @@ config = Object.assign(config, {
94
99
  },
95
100
  });
96
101
 
97
- module.exports = config;
102
+ export {config};
package/lib/log.js CHANGED
@@ -1,12 +1,9 @@
1
- const chalk = require('chalk');
1
+ import chalk from 'chalk';
2
2
 
3
3
  const log = {
4
4
  color: function(str, color) {
5
- let txt = str;
5
+ const txt = color ? chalk[color](str) : str;
6
6
 
7
- if (color) {
8
- txt = chalk[color](txt);
9
- }
10
7
  console.log(txt);
11
8
  },
12
9
  bump: function(opts) {
@@ -28,4 +25,4 @@ const log = {
28
25
  },
29
26
  };
30
27
 
31
- module.exports = log;
28
+ export {log};
package/lib/notifier.js CHANGED
@@ -1,6 +1,11 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import {utils} from './utils.js';
4
+ import updateNotifier from 'update-notifier';
1
5
 
2
- const updateNotifier = require('update-notifier');
3
- const pkg = require('../package.json');
6
+ // @ts-ignore
7
+ const dirname = utils.getDirName(import.meta.url);
8
+ const pkg = fs.readJsonSync(path.resolve(dirname, '..', 'package.json'));
4
9
 
5
10
  updateNotifier({
6
11
  packageName: pkg.name,
package/lib/utils.js CHANGED
@@ -1,18 +1,25 @@
1
1
  'use strict';
2
2
 
3
- const path = require('path');
4
- const Promises = require('bluebird');
5
- const fs = require('fs-extra');
6
- const exec = Promises.promisify(require('child_process').exec);
7
- const glob = require('glob');
8
- const chalk = require('chalk');
9
- const rc = require('rc');
10
- const semver = require('semver');
11
- const config = require('./config');
12
- const log = require('./log');
3
+ import path from 'path';
4
+ import childProcess from 'child_process';
5
+ import Promises from 'bluebird';
6
+ import fs from 'fs-extra';
7
+ import glob from 'glob';
8
+ import chalk from 'chalk';
9
+ import rc from 'rc';
10
+ import semver from 'semver';
11
+ import {config} from './config.js';
12
+ import {log} from './log.js';
13
+
14
+ const exec = Promises.promisify(childProcess.exec);
13
15
 
14
16
  const utils = {
15
- escapeQuotes: function(str) {
17
+ getDirName(url) {
18
+ const moduleURL = new URL(url);
19
+
20
+ return moduleURL.pathname.replace(/\/[^/]+$/, '');
21
+ },
22
+ escapeQuotes(str) {
16
23
  if (typeof str === 'string') {
17
24
  return str.replace(/(["$`\\])/g, '\\$1');
18
25
  }
@@ -21,7 +28,7 @@ const utils = {
21
28
 
22
29
  },
23
30
 
24
- getFiles: function(items) {
31
+ getFiles(items) {
25
32
  const files = items ? [].concat(items) : ['package.json'];
26
33
  const list = [];
27
34
 
@@ -41,14 +48,17 @@ const utils = {
41
48
  return unique;
42
49
  },
43
50
 
44
- readJSON: function(file) {
51
+ async readJSON(file) {
45
52
  try {
46
- return require(path.resolve('./', file));
53
+ const json = await fs.readJson(path.resolve(process.cwd(), file));
54
+
55
+ return json;
47
56
  } catch (err) {
48
57
  return {};
49
58
  }
50
59
  },
51
- writeJSON: function writeJSON(file, input) {
60
+
61
+ writeJSON(file, input) {
52
62
  let json = input;
53
63
 
54
64
  if (typeof json === 'object') {
@@ -58,7 +68,7 @@ const utils = {
58
68
  fs.writeFileSync(file, json);
59
69
  },
60
70
 
61
- getBumpError: function getBumpError(opts) {
71
+ getBumpError(opts) {
62
72
  let err = null;
63
73
 
64
74
  if (typeof opts.releaseType === 'undefined') {
@@ -78,11 +88,9 @@ const utils = {
78
88
  return err;
79
89
  },
80
90
 
81
- bumpError: function bumpError(opts) {
82
- let isErr = utils.getBumpError(opts);
83
- let def = '_default';
84
- let label = 'version';
85
- let value = opts.version;
91
+ bumpError(opts) {
92
+ const isErr = utils.getBumpError(opts);
93
+ const def = '_default';
86
94
 
87
95
  // Special case for no releaseType (user just types "ump")
88
96
  if (isErr === 'noRelease') {
@@ -99,13 +107,13 @@ const utils = {
99
107
  return isErr;
100
108
  },
101
109
 
102
- error: function error(err) {
110
+ error(err) {
103
111
  throw err;
104
112
  },
105
113
 
106
- debug: function debug(obj) {
107
- let debugOutput = JSON.stringify(obj, null, 2);
108
- let file = '.ump.debug.json';
114
+ debug(obj) {
115
+ const debugOutput = JSON.stringify(obj, null, 2);
116
+ const file = '.ump.debug.json';
109
117
 
110
118
  return fs.writeFile(file, debugOutput)
111
119
  .then(() => {
@@ -117,7 +125,7 @@ const utils = {
117
125
  extend: function extend(...args) {
118
126
  let arg, prop;
119
127
  let al = args.length;
120
- let firstArg = al === 1 ? {} : args.shift();
128
+ const firstArg = al === 1 ? {} : args.shift();
121
129
 
122
130
  while (--al > -1) {
123
131
  arg = args[al];
@@ -134,11 +142,11 @@ const utils = {
134
142
  return firstArg;
135
143
  },
136
144
 
137
- repoDirty: function repoDirty(stdout, files) {
138
- let lines = stdout.trim().split('\n')
145
+ repoDirty: function(stdout, files) {
146
+ const lines = stdout
147
+ .trim().split('\n')
139
148
  .filter((line) => {
140
- let file = line.replace(/.{1,2}\s+/, '');
141
-
149
+ const file = line.replace(/.{1,2}\s+/, '');
142
150
 
143
151
  return line.trim() && !file.match(/^\?\? /) && files.indexOf(file) === -1;
144
152
  })
@@ -149,17 +157,17 @@ const utils = {
149
157
  return lines;
150
158
  },
151
159
 
152
- resetVersion: function resetVersion(opts) {
160
+ resetVersion: function(opts) {
153
161
  log.color('Did not execute commands. Resetting version.', 'red');
154
- opts.files.forEach((file) => {
155
- let json = utils.readJSON(file);
162
+ Promise.all(opts.files.map(async(file) => {
163
+ const json = await utils.readJSON(file);
156
164
 
157
165
  json.version = opts.version;
158
166
  utils.writeJSON(file, json);
159
- });
167
+ }));
160
168
  },
161
169
 
162
- getNewVersion: function getNewVersion(opts) {
170
+ getNewVersion: function(opts) {
163
171
  // semver release type
164
172
  if (config.releaseTypes.indexOf(opts.releaseType) !== -1) {
165
173
  return semver.inc(opts.version, opts.releaseType);
@@ -169,10 +177,10 @@ const utils = {
169
177
  return opts.releaseType;
170
178
  },
171
179
 
172
- buildOptions: function buildOptions(options) {
173
- let appName = options.appName || 'ump';
174
- let rcOptions = rc(appName);
175
- let opts = utils.extend(config.defaults, rcOptions, options);
180
+ buildOptions: async function(options) {
181
+ const appName = options.appName || 'ump';
182
+ const rcOptions = rc(appName);
183
+ const opts = utils.extend(config.defaults, rcOptions, options);
176
184
 
177
185
  opts.files = utils.getFiles(opts.files);
178
186
  opts.extraFiles = utils.getFiles(opts.extras || []);
@@ -183,7 +191,9 @@ const utils = {
183
191
  opts.release = true;
184
192
  }
185
193
 
186
- opts.version = utils.readJSON(opts.sourceFile).version;
194
+ const src = await utils.readJSON(opts.sourceFile);
195
+
196
+ opts.version = src.version;
187
197
 
188
198
  if (utils.bumpError(opts)) {
189
199
  return Object.assign(opts, {error: true});
@@ -193,20 +203,6 @@ const utils = {
193
203
 
194
204
  return opts;
195
205
  },
196
-
197
- // Taken from https://github.com/inikulin/publish-please/blob/master/src/publish.js
198
- checkNodeNpm: function checkNodeNpm() {
199
- return exec('npm version --json')
200
- .then((versions) => {
201
- const npmVersion = JSON.parse(versions).npm;
202
- const isNode6 = semver.gte(process.version, '6.0.0');
203
- const isSafeNpmVersion = semver.satisfies(npmVersion, '>=2.15.8 <3.0.0 || >=3.10.1');
204
-
205
- if (isNode6 && !isSafeNpmVersion) {
206
- throw new Error(`npm@${npmVersion} has known issues publishing when running Node.js 6. Please upgrade npm or downgrade Node and publish again. See: https://github.com/npm/npm/issues/5082`);
207
- }
208
- });
209
- },
210
206
  };
211
207
 
212
- module.exports = utils;
208
+ export {utils};
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "ump",
3
3
  "title": "ump",
4
- "version": "2.1.4",
4
+ "version": "3.0.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.js ump.js bin lib test",
11
+ "lint": "eslint --config .eslintrc.cjs *.js bin lib test",
12
12
  "snyk-protect": "snyk protect",
13
13
  "prepare": "npm run snyk-protect"
14
14
  },
@@ -16,6 +16,7 @@
16
16
  "type": "git",
17
17
  "url": "git@github.com:kswedberg/ump.git"
18
18
  },
19
+ "type": "module",
19
20
  "main": "ump.js",
20
21
  "bin": {
21
22
  "ump": "bin/ump.js"
@@ -26,26 +27,26 @@
26
27
  "url": "https://karlswedberg.com/"
27
28
  },
28
29
  "engines": {
29
- "node": ">= 8.6.0"
30
+ "node": ">=14"
30
31
  },
31
32
  "dependencies": {
32
- "bluebird": "^3.7.1",
33
- "chalk": "^4.1.2",
33
+ "bluebird": "^3.7.2",
34
+ "chalk": "^5.0.0",
34
35
  "fs-extra": "^10.0.0",
35
- "git-config": "0.0.7",
36
- "glob": "^7.1.4",
37
- "inquirer": "^7.3.2",
36
+ "git-config": "^0.0.7",
37
+ "glob": "^7.2.0",
38
+ "inquirer": "^8.2.0",
38
39
  "rc": "^1.2.8",
39
- "semver": "^6.3.0",
40
- "snyk": "^1.675.0",
41
- "update-notifier": "^4.0.0",
40
+ "semver": "^7.3.5",
41
+ "snyk": "^1.812.0",
42
+ "update-notifier": "^5.1.0",
42
43
  "yargs": "^13.3.2"
43
44
  },
44
45
  "devDependencies": {
45
- "chai": "^4.2.0",
46
- "eslint": "^6.8.0",
47
- "eslint-config-kswedberg": "^3.1.1",
48
- "mocha": "^7.2.0"
46
+ "chai": "^4.3.4",
47
+ "eslint": "^8.5.0",
48
+ "eslint-config-kswedberg": "^5.1.1",
49
+ "mocha": "^9.1.3"
49
50
  },
50
51
  "license": "MIT",
51
52
  "snyk": true
package/test/test.js CHANGED
@@ -1,8 +1,14 @@
1
- const Promises = require('bluebird');
2
- const fs = require('fs-extra');
3
- const path = require('path');
4
- const ump = require('../ump');
5
- const expect = require('chai').expect;
1
+ import path from 'path';
2
+ import Promises from 'bluebird';
3
+ import fs from 'fs-extra';
4
+ import ump from '../ump.js';
5
+ import {utils} from '../lib/utils.js';
6
+ import {commands} from '../lib/commands.js';
7
+
8
+ import {expect} from 'chai';
9
+
10
+ // @ts-ignore
11
+ const dirname = utils.getDirName(import.meta.url);
6
12
 
7
13
  const settings = {
8
14
  inquire: false,
@@ -24,13 +30,10 @@ const pkg = {
24
30
  version: '1.0.0',
25
31
  };
26
32
 
27
- const utils = require('../lib/utils');
33
+ let opts = {};
28
34
 
29
35
  const tests = {
30
- utils: function() {
31
-
32
- const opts = utils.buildOptions(settings);
33
-
36
+ utils() {
34
37
  it('should build options object', () => {
35
38
  expect(opts.sourceFile).to.equal(settings.files[0]);
36
39
  expect(opts.newVersion).to.equal('1.0.1');
@@ -49,9 +52,8 @@ const tests = {
49
52
  expect(opts.extraFiles.length).to.equal(2);
50
53
  });
51
54
  },
52
- commands: function() {
53
- const opts = utils.buildOptions(settings);
54
- const commands = require('../lib/commands');
55
+
56
+ commands() {
55
57
  const extras = commands.extras(opts);
56
58
 
57
59
  it('should have correct log info', () => {
@@ -76,7 +78,6 @@ const tests = {
76
78
  },
77
79
  };
78
80
 
79
-
80
81
  const files = [
81
82
  {
82
83
  file: 'package.json',
@@ -111,16 +112,22 @@ const files = [
111
112
  },
112
113
  ];
113
114
 
114
- Promises.each(files, (file) => {
115
- return fs.writeFile(path.join(__dirname, 'testarea/', file.file), file.content);
116
- })
117
- .then(() => {
118
- describe('ump', () => {
119
- Object.keys(tests).forEach((test) => {
120
- describe(test, tests[test]);
115
+ const runTests = async() => {
116
+ try {
117
+ await Promises.each(files, (file) => {
118
+ return fs.writeFile(path.join(dirname, 'testarea/', file.file), file.content);
121
119
  });
122
- });
123
120
 
121
+ opts = await utils.buildOptions(settings);
122
+ describe('ump', () => {
123
+ Object.entries(tests).forEach(([name, test]) => {
124
+ describe(name, test);
125
+ });
126
+ });
127
+ } catch (err) {
128
+ console.error(err);
129
+ }
124
130
  run();
125
- })
126
- .catch(run);
131
+ };
132
+
133
+ runTests();
package/ump.js CHANGED
@@ -1,25 +1,21 @@
1
1
  'use strict';
2
2
 
3
- const path = require('path');
4
- const Promises = require('bluebird');
5
- const inquirer = require('inquirer');
6
- const semver = require('semver');
7
-
8
- const utils = require('./lib/utils');
9
- const commands = require('./lib/commands');
10
- const log = require('./lib/log');
11
- const config = require('./lib/config');
3
+ import Promises from 'bluebird';
4
+ import inquirer from 'inquirer';
5
+
6
+ import {utils} from './lib/utils.js';
7
+ import {commands} from './lib/commands.js';
8
+ import {log} from './lib/log.js';
9
+ import {config} from './lib/config.js';
10
+
12
11
  const sequence = [];
13
12
 
14
13
  const runCommands = function(sequence, options) {
15
- return utils.checkNodeNpm()
14
+ return Promises.each(sequence, (command) => {
15
+ return command.cmd(options);
16
+ })
16
17
  .then(() => {
17
- return Promises.each(sequence, (command) => {
18
- return command.cmd(options);
19
- })
20
- .then(() => {
21
- log.color('*** DONE! ***', 'green');
22
- });
18
+ log.color('*** DONE! ***', 'green');
23
19
  })
24
20
  .catch((err) => {
25
21
  console.error(err);
@@ -28,7 +24,7 @@ const runCommands = function(sequence, options) {
28
24
  };
29
25
 
30
26
  const ump = async function(options) {
31
- const opts = utils.buildOptions(options);
27
+ const opts = await utils.buildOptions(options);
32
28
 
33
29
  if (opts.error) {
34
30
  return;
@@ -70,4 +66,4 @@ const ump = async function(options) {
70
66
  runCommands(sequence, opts);
71
67
  };
72
68
 
73
- module.exports = ump;
69
+ export default ump;
package/.eslintrc.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- 'extends': 'kswedberg',
3
- env: {
4
- mocha: true
5
- }
6
- };