release-it 15.0.0-esm.3 → 15.0.0-esm.6

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.
Files changed (49) hide show
  1. package/README.md +16 -9
  2. package/config/release-it.json +3 -0
  3. package/lib/config.js +7 -15
  4. package/lib/index.js +27 -33
  5. package/lib/log.js +1 -1
  6. package/lib/plugin/GitBase.js +1 -1
  7. package/lib/plugin/GitRelease.js +1 -1
  8. package/lib/plugin/Plugin.js +1 -1
  9. package/lib/plugin/factory.js +5 -5
  10. package/lib/plugin/git/Git.js +3 -2
  11. package/lib/plugin/github/GitHub.js +14 -8
  12. package/lib/plugin/gitlab/GitLab.js +68 -14
  13. package/lib/plugin/npm/npm.js +3 -2
  14. package/lib/plugin/version/Version.js +5 -1
  15. package/lib/shell.js +2 -2
  16. package/lib/util.js +2 -2
  17. package/package.json +25 -32
  18. package/test/config.js +19 -26
  19. package/test/git.init.js +32 -7
  20. package/test/git.js +5 -2
  21. package/test/github.js +42 -13
  22. package/test/gitlab.js +69 -18
  23. package/test/log.js +1 -1
  24. package/test/npm.js +12 -3
  25. package/test/plugins.js +33 -21
  26. package/test/spinner.js +1 -2
  27. package/test/stub/config/default/.release-it.json +5 -0
  28. package/test/stub/config/invalid-config-rc +1 -0
  29. package/test/stub/config/invalid-config-txt +2 -0
  30. package/test/stub/config/merge/.release-it.json +5 -0
  31. package/test/stub/config/merge/package.json +7 -0
  32. package/test/stub/config/toml/.release-it.toml +2 -0
  33. package/test/stub/config/yaml/.release-it.yaml +2 -0
  34. package/test/stub/config/yml/.release-it.yml +2 -0
  35. package/test/stub/github.js +26 -10
  36. package/test/stub/gitlab.js +15 -7
  37. package/test/stub/shell.js +2 -2
  38. package/test/tasks.interactive.js +2 -3
  39. package/test/tasks.js +3 -4
  40. package/test/util/helpers.js +6 -6
  41. package/test/util/index.js +14 -19
  42. package/test/utils.js +1 -1
  43. package/test/version.js +9 -4
  44. package/config/.codecov.yml +0 -5
  45. package/config/deprecated.json +0 -1
  46. package/lib/deprecated.js +0 -22
  47. package/lib/metrics.js +0 -76
  48. package/test/deprecated.js +0 -11
  49. package/test/metrics.js +0 -17
package/test/plugins.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { join } from 'node:path';
1
2
  import test from 'ava';
2
3
  import sh from 'shelljs';
3
4
  import sinon from 'sinon';
@@ -12,16 +13,13 @@ import ContextPlugin from './stub/plugin-context.js';
12
13
  import { mkTmpDir } from './util/helpers.js';
13
14
  import ShellStub from './stub/shell.js';
14
15
 
15
- const rootDir = new URL('..', import.meta.url);
16
-
17
16
  const noop = Promise.resolve();
18
17
 
19
18
  const sandbox = sinon.createSandbox();
20
19
 
21
20
  const testConfig = {
22
21
  ci: true,
23
- config: false,
24
- 'disable-metrics': true
22
+ config: false
25
23
  };
26
24
 
27
25
  const log = sandbox.createStubInstance(Log);
@@ -39,6 +37,11 @@ const getContainer = options => {
39
37
  };
40
38
  };
41
39
 
40
+ test.serial.before(t => {
41
+ t.timeout(60 * 1000);
42
+ sh.exec('npm link');
43
+ });
44
+
42
45
  test.serial.beforeEach(t => {
43
46
  const dir = mkTmpDir();
44
47
  sh.pushd('-q', dir);
@@ -50,23 +53,28 @@ test.serial.afterEach(() => {
50
53
  });
51
54
 
52
55
  test.serial('should instantiate plugins and execute all release-cycle methods', async t => {
53
- sh.ShellString(JSON.stringify({ name: 'project', version: '1.0.0', type: 'module' })).toEnd('package.json');
54
- sh.exec(`npm install ${rootDir}`);
56
+ const { dir } = t.context;
55
57
 
56
58
  const pluginDir = mkTmpDir();
57
59
  sh.pushd('-q', pluginDir);
58
- sh.ShellString(JSON.stringify({ name: 'my-plugin', version: '1.0.0', type: 'module' })).toEnd('package.json');
59
- sh.exec(`npm install ${rootDir}`);
60
+ sh.ShellString(JSON.stringify({ name: 'my-plugin', version: '1.0.0', type: 'module' })).toEnd(
61
+ join(pluginDir, 'package.json')
62
+ );
63
+ sh.exec(`npm link release-it`);
60
64
  const content = "import { Plugin } from 'release-it'; " + MyPlugin.toString() + '; export default MyPlugin;';
61
- sh.ShellString(content).toEnd('index.js');
62
- sh.popd();
65
+ sh.ShellString(content).toEnd(join(pluginDir, 'index.js'));
63
66
 
67
+ sh.pushd('-q', dir);
64
68
  sh.mkdir('-p', 'my/plugin');
65
69
  sh.pushd('-q', 'my/plugin');
66
- sh.ShellString(content).toEnd('index.js');
67
- sh.popd();
70
+ sh.ShellString(content).toEnd(join(dir, 'my', 'plugin', 'index.js'));
68
71
 
72
+ sh.pushd('-q', dir);
73
+ sh.ShellString(JSON.stringify({ name: 'project', version: '1.0.0', type: 'module' })).toEnd(
74
+ join(dir, 'package.json')
75
+ );
69
76
  sh.exec(`npm install ${pluginDir}`);
77
+ sh.exec(`npm link release-it`);
70
78
 
71
79
  const config = {
72
80
  plugins: {
@@ -114,14 +122,16 @@ test.serial('should instantiate plugins and execute all release-cycle methods',
114
122
  });
115
123
 
116
124
  test.serial('should disable core plugins', async t => {
117
- sh.ShellString(JSON.stringify({ name: 'project', version: '1.0.0' })).toEnd('package.json');
118
- sh.exec(`npm install release-it@^14`);
119
- const content = "const { Plugin } = require('release-it'); module.exports = " + ReplacePlugin.toString();
120
- sh.ShellString(content).toEnd('replace-plugin.js');
125
+ const { dir } = t.context;
126
+ sh.ShellString(JSON.stringify({ name: 'project', version: '1.0.0' })).toEnd(join(dir, 'package.json'));
127
+ const content =
128
+ "import { Plugin } from 'release-it'; " + ReplacePlugin.toString() + '; export default ReplacePlugin;';
129
+ sh.ShellString(content).toEnd(join(dir, 'replace-plugin.mjs'));
130
+ sh.exec(`npm link release-it`);
121
131
 
122
132
  const config = {
123
133
  plugins: {
124
- './replace-plugin.js': {}
134
+ './replace-plugin.mjs': {}
125
135
  }
126
136
  };
127
137
  const container = getContainer(config);
@@ -137,12 +147,14 @@ test.serial('should disable core plugins', async t => {
137
147
  });
138
148
 
139
149
  test.serial('should expose context to execute commands', async t => {
140
- sh.ShellString(JSON.stringify({ name: 'pkg-name', version: '1.0.0', type: 'module' })).toEnd('package.json');
141
- sh.exec(`npm install ${rootDir}`);
142
-
150
+ const { dir } = t.context;
151
+ sh.ShellString(JSON.stringify({ name: 'pkg-name', version: '1.0.0', type: 'module' })).toEnd(
152
+ join(dir, 'package.json')
153
+ );
143
154
  const content =
144
155
  "import { Plugin } from 'release-it'; " + ContextPlugin.toString() + '; export default ContextPlugin;';
145
- sh.ShellString(content).toEnd('context-plugin.js');
156
+ sh.ShellString(content).toEnd(join(dir, 'context-plugin.js'));
157
+ sh.exec(`npm link release-it`);
146
158
 
147
159
  const repo = parseGitUrl('https://github.com/user/pkg');
148
160
 
package/test/spinner.js CHANGED
@@ -10,8 +10,7 @@ test.beforeEach(t => {
10
10
  const getConfig = options => {
11
11
  const testConfig = {
12
12
  ci: false,
13
- config: false,
14
- 'disable-metrics': true
13
+ config: false
15
14
  };
16
15
  return new Config(Object.assign({}, testConfig, options));
17
16
  };
@@ -0,0 +1,5 @@
1
+ {
2
+ "github": {
3
+ "release": true
4
+ }
5
+ }
@@ -0,0 +1 @@
1
+ foo=bar
@@ -0,0 +1,2 @@
1
+ foo
2
+ bar\baz
@@ -0,0 +1,5 @@
1
+ {
2
+ "github": {
3
+ "release": true
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "release-it": {
3
+ "git": {
4
+ "push": false
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,2 @@
1
+ [foo]
2
+ bar=1
@@ -0,0 +1,2 @@
1
+ foo:
2
+ bar: 1
@@ -0,0 +1,2 @@
1
+ foo:
2
+ bar: 1
@@ -1,16 +1,19 @@
1
1
  import nock from 'nock';
2
2
 
3
- const interceptAuthentication = ({ api = 'https://api.github.com', username = 'john' } = {}) =>
3
+ const interceptAuthentication = ({ api = 'https://api.github.com', username = 'john' } = {}) => {
4
4
  nock(api).get('/user').reply(200, {
5
5
  login: username
6
6
  });
7
+ };
7
8
 
8
9
  const interceptCollaborator = ({
9
10
  api = 'https://api.github.com',
10
11
  owner = 'user',
11
12
  project = 'repo',
12
13
  username = 'john'
13
- } = {}) => nock(api).get(`/repos/${owner}/${project}/collaborators/${username}`).reply(204);
14
+ } = {}) => {
15
+ nock(api).get(`/repos/${owner}/${project}/collaborators/${username}`).reply(204);
16
+ };
14
17
 
15
18
  const interceptListReleases = ({
16
19
  host = 'github.com',
@@ -18,7 +21,7 @@ const interceptListReleases = ({
18
21
  owner = 'user',
19
22
  project = 'repo',
20
23
  tag_name
21
- } = {}) =>
24
+ } = {}) => {
22
25
  nock(api)
23
26
  .get(`/repos/${owner}/${project}/releases?per_page=1&page=1`)
24
27
  .reply(200, [
@@ -34,16 +37,24 @@ const interceptListReleases = ({
34
37
  prerelease: false
35
38
  }
36
39
  ]);
40
+ };
37
41
 
38
42
  const interceptCreate = ({
39
43
  api = 'https://api.github.com',
40
44
  host = 'github.com',
41
45
  owner = 'user',
42
46
  project = 'repo',
43
- body: { tag_name, name = '', body = null, prerelease = false, draft = false }
44
- } = {}) =>
47
+ body: { tag_name, name = '', generate_release_notes = false, body = null, prerelease = false, draft = false }
48
+ } = {}) => {
45
49
  nock(api)
46
- .post(`/repos/${owner}/${project}/releases`, { tag_name, name, body, prerelease, draft })
50
+ .post(`/repos/${owner}/${project}/releases`, {
51
+ tag_name,
52
+ name,
53
+ body,
54
+ prerelease,
55
+ draft,
56
+ generate_release_notes
57
+ })
47
58
  .reply(() => {
48
59
  const id = 1;
49
60
  const responseBody = {
@@ -53,21 +64,23 @@ const interceptCreate = ({
53
64
  body,
54
65
  prerelease,
55
66
  draft,
67
+ generate_release_notes,
56
68
  upload_url: `https://uploads.${host}/repos/${owner}/${project}/releases/${id}/assets{?name,label}`,
57
69
  html_url: `https://${host}/${owner}/${project}/releases/tag/${tag_name}`
58
70
  };
59
71
  return [200, responseBody, { location: `${api}/repos/${owner}/${project}/releases/${id}` }];
60
72
  });
73
+ };
61
74
 
62
75
  const interceptUpdate = ({
63
76
  host = 'github.com',
64
77
  api = 'https://api.github.com',
65
78
  owner = 'user',
66
79
  project = 'repo',
67
- body: { tag_name, name = '', body = null, prerelease = false, draft = false }
68
- } = {}) =>
80
+ body: { tag_name, name = '', body = null, prerelease = false, draft = false, generate_release_notes = false }
81
+ } = {}) => {
69
82
  nock(api)
70
- .patch(`/repos/${owner}/${project}/releases/1`, { tag_name, name, body, draft, prerelease })
83
+ .patch(`/repos/${owner}/${project}/releases/1`, { tag_name, name, body, draft, prerelease, generate_release_notes })
71
84
  .reply(200, {
72
85
  id: 1,
73
86
  tag_name,
@@ -75,9 +88,11 @@ const interceptUpdate = ({
75
88
  body,
76
89
  prerelease,
77
90
  draft,
91
+ generate_release_notes,
78
92
  upload_url: `https://uploads.${host}/repos/${owner}/${project}/releases/1/assets{?name,label}`,
79
93
  html_url: `https://${host}/${owner}/${project}/releases/tag/${tag_name}`
80
94
  });
95
+ };
81
96
 
82
97
  const interceptAsset = ({
83
98
  api = 'https://api.github.com',
@@ -86,7 +101,7 @@ const interceptAsset = ({
86
101
  project = 'repo',
87
102
  tagName,
88
103
  body = {}
89
- } = {}) =>
104
+ } = {}) => {
90
105
  nock(`https://uploads.${host}`)
91
106
  .post(`/repos/${owner}/${project}/releases/1/assets`, body)
92
107
  .query(true)
@@ -103,6 +118,7 @@ const interceptAsset = ({
103
118
  browser_download_url: `https://${host}/${owner}/${project}/releases/download/${tagName}/${name}`
104
119
  };
105
120
  });
121
+ };
106
122
 
107
123
  export {
108
124
  interceptAuthentication,
@@ -11,16 +11,24 @@ export let interceptCollaborator = (
11
11
  .get(`/api/v4/projects/${group ? `${group}%2F` : ''}${owner}%2F${project}/members/all/${userId}`)
12
12
  .reply(200, { id: userId, username: owner, access_level: 30 });
13
13
 
14
- export let interceptCollaboratorFallback = (
15
- { host = 'https://gitlab.com', owner = 'user', project = 'repo', group, userId = 1 } = {},
14
+ export let interceptPublish = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', body } = {}, options) =>
15
+ nock(host, options).post(`/api/v4/projects/${owner}%2F${project}/releases`, body).reply(200, {});
16
+
17
+ export let interceptMilestones = (
18
+ { host = 'https://gitlab.com', owner = 'user', project = 'repo', query = {}, milestones = [] } = {},
16
19
  options
17
20
  ) =>
18
21
  nock(host, options)
19
- .get(`/api/v4/projects/${group ? `${group}%2F` : ''}${owner}%2F${project}/members/${userId}`)
20
- .reply(200, { id: userId, username: owner, access_level: 30 });
21
-
22
- export let interceptPublish = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', body } = {}, options) =>
23
- nock(host, options).post(`/api/v4/projects/${owner}%2F${project}/releases`, body).reply(200, {});
22
+ .get(`/api/v4/projects/${owner}%2F${project}/milestones`)
23
+ .query(
24
+ Object.assign(
25
+ {
26
+ include_parent_milestones: true
27
+ },
28
+ query
29
+ )
30
+ )
31
+ .reply(200, JSON.stringify(milestones));
24
32
 
25
33
  export let interceptAsset = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo' } = {}) =>
26
34
  nock(host)
@@ -1,7 +1,7 @@
1
- import _debug from 'debug';
1
+ import util from 'node:util';
2
2
  import Shell from '../../lib/shell.js';
3
3
 
4
- const debug = _debug('release-it:shell-stub');
4
+ const debug = util.debug('release-it:shell-stub');
5
5
 
6
6
  class ShellStub extends Shell {
7
7
  exec(command) {
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
  import test from 'ava';
3
3
  import sh from 'shelljs';
4
4
  import _ from 'lodash';
@@ -19,8 +19,7 @@ const sandbox = sinon.createSandbox();
19
19
 
20
20
  const testConfig = {
21
21
  ci: false,
22
- config: false,
23
- 'disable-metrics': true
22
+ config: false
24
23
  };
25
24
 
26
25
  const log = sandbox.createStubInstance(Log);
package/test/tasks.js CHANGED
@@ -1,4 +1,4 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
  import test from 'ava';
3
3
  import sh from 'shelljs';
4
4
  import _ from 'lodash';
@@ -30,8 +30,7 @@ const sandbox = sinon.createSandbox();
30
30
 
31
31
  const testConfig = {
32
32
  ci: true,
33
- config: false,
34
- 'disable-metrics': true
33
+ config: false
35
34
  };
36
35
 
37
36
  const log = sandbox.createStubInstance(Log);
@@ -358,7 +357,7 @@ test.serial('should initially publish non-private scoped npm package privately',
358
357
  test.serial('should use pkg.publishConfig.registry', async t => {
359
358
  const { target } = t.context;
360
359
  const pkgName = path.basename(target);
361
- const registry = 'https://my-registry.com';
360
+ const registry = 'https://my-registry.example.org';
362
361
 
363
362
  gitAdd(
364
363
  JSON.stringify({
@@ -1,14 +1,14 @@
1
- import { promises as fs } from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
3
4
  import sh from 'shelljs';
4
- import tmp from 'tmp';
5
5
 
6
6
  const mkTmpDir = () => {
7
- const dir = tmp.dirSync({ prefix: 'release-it-' });
8
- return dir.name;
7
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'release-it-'));
8
+ return dir;
9
9
  };
10
10
 
11
- const readFile = file => fs.readFile(path.resolve(file), 'utf8');
11
+ const readFile = file => fs.promises.readFile(path.resolve(file), 'utf8');
12
12
 
13
13
  const gitAdd = (content, file, message) => {
14
14
  sh.ShellString(content).toEnd(file);
@@ -30,23 +30,14 @@ export let factory = (Definition, { namespace, options = {}, container = {} } =
30
30
  });
31
31
  };
32
32
 
33
- const getIncrement = (plugin, { latestVersion }) => {
34
- return (
35
- plugin.getIncrement({
36
- latestVersion,
37
- increment: plugin.options.increment,
38
- isPreRelease: false,
39
- preReleaseId: null
40
- }) ||
41
- plugin.getContext('increment') ||
42
- plugin.config.getContext('increment')
43
- );
44
- };
33
+ const getIncrement = plugin =>
34
+ plugin.getIncrement(plugin.options) || plugin.getContext('increment') || plugin.config.getContext('increment');
45
35
 
46
- const getVersion = async (plugin, { latestVersion, increment }) => {
36
+ const getVersion = async (plugin, options) => {
37
+ const { latestVersion, increment } = options;
47
38
  return (
48
- (await plugin.getIncrementedVersionCI({ latestVersion, increment })) ||
49
- (await plugin.getIncrementedVersion({ latestVersion, increment })) ||
39
+ (await plugin.getIncrementedVersionCI(options)) ||
40
+ (await plugin.getIncrementedVersion(options)) ||
50
41
  (increment !== false ? semver.inc(latestVersion, increment || 'patch') : latestVersion)
51
42
  );
52
43
  };
@@ -56,12 +47,16 @@ export let runTasks = async plugin => {
56
47
 
57
48
  const name = (await plugin.getName()) || '__test__';
58
49
  const latestVersion = (await plugin.getLatestVersion()) || '1.0.0';
59
- const changelog = (await plugin.getChangelog()) || null;
60
- const increment = getIncrement(plugin, { latestVersion });
50
+ const latestTag = plugin.config.getContext('latestTag');
51
+ const changelog = (await plugin.getChangelog(latestVersion)) || null;
52
+ const increment = getIncrement(plugin);
61
53
 
62
- plugin.config.setContext({ name, latestVersion, latestTag: latestVersion, changelog });
54
+ plugin.config.setContext({ name, latestVersion, latestTag, changelog });
63
55
 
64
- const version = await getVersion(plugin, { latestVersion, increment });
56
+ const { preRelease } = plugin.config.options;
57
+ const isPreRelease = Boolean(preRelease);
58
+ const preReleaseId = typeof preRelease === 'string' ? preRelease : null;
59
+ const version = await getVersion(plugin, { latestVersion, increment, isPreRelease, preReleaseId });
65
60
 
66
61
  plugin.config.setContext(parseVersion(version));
67
62
 
package/test/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { EOL } from 'os';
1
+ import { EOL } from 'node:os';
2
2
  import test from 'ava';
3
3
  import mockStdIo from 'mock-stdio';
4
4
  import stripAnsi from 'strip-ansi';
package/test/version.js CHANGED
@@ -148,17 +148,22 @@ test('should run tasks without errors', async t => {
148
148
  await runTasks(v);
149
149
 
150
150
  t.is(getIncrement.callCount, 1);
151
- t.deepEqual(getIncrement.firstCall.args[0], {
151
+ t.deepEqual(getIncrement.firstCall.args[0], { increment: 'minor' });
152
+ t.is(getIncrementedVersionCI.callCount, 1);
153
+ t.deepEqual(getIncrementedVersionCI.firstCall.args[0], {
152
154
  latestVersion: '1.0.0',
153
155
  increment: 'minor',
154
156
  isPreRelease: false,
155
157
  preReleaseId: null
156
158
  });
157
- t.is(getIncrementedVersionCI.callCount, 1);
158
- t.deepEqual(getIncrementedVersionCI.firstCall.args[0], { latestVersion: '1.0.0', increment: 'minor' });
159
159
  t.is(await incrementVersion.firstCall.returnValue, '1.1.0');
160
160
  t.is(incrementVersion.callCount, 1);
161
- t.deepEqual(incrementVersion.firstCall.args[0], { latestVersion: '1.0.0', increment: 'minor' });
161
+ t.deepEqual(incrementVersion.firstCall.args[0], {
162
+ latestVersion: '1.0.0',
163
+ increment: 'minor',
164
+ isPreRelease: false,
165
+ preReleaseId: null
166
+ });
162
167
  t.is(incrementVersion.firstCall.returnValue, '1.1.0');
163
168
  const { latestVersion, version, isPreRelease, preReleaseId } = v.config.getContext();
164
169
  t.is(latestVersion, '1.0.0');
@@ -1,5 +0,0 @@
1
- coverage:
2
- parsers:
3
- javascript:
4
- enable_partials: yes
5
- comment: false
@@ -1 +0,0 @@
1
- {}
package/lib/deprecated.js DELETED
@@ -1,22 +0,0 @@
1
- import Deprecated from 'deprecated-obj';
2
- import { readJSON } from './util.js';
3
- import Log from './log.js';
4
-
5
- const deprecated = readJSON(new URL('../config/deprecated.json', import.meta.url));
6
-
7
- export default (config, log = new Log()) => {
8
- const deprecations = new Deprecated(deprecated, config);
9
- const compliant = deprecations.getCompliant();
10
- const violations = deprecations.getViolations();
11
- if (Object.keys(violations).length > 0) {
12
- log.warn(`Deprecated configuration options found. Please migrate before the next major release.`);
13
- }
14
- for (const d in violations) {
15
- log.warn(
16
- `The "${d}" option is deprecated. ${
17
- violations[d] ? (/^[A-Z]/.test(violations[d]) ? violations[d] : `Please use "${violations[d]}" instead.`) : ''
18
- }`
19
- );
20
- }
21
- return compliant;
22
- };
package/lib/metrics.js DELETED
@@ -1,76 +0,0 @@
1
- import { EOL } from 'os';
2
- import got from 'got';
3
- import { v4 as uuidv4 } from 'uuid';
4
- import osName from 'os-name';
5
- import isCi from 'is-ci';
6
- import _debug from 'debug';
7
- import { readJSON } from './util.js';
8
-
9
- const debug = _debug('release-it:metrics');
10
- const pkg = readJSON(new URL('../package.json', import.meta.url));
11
-
12
- const noop = Promise.resolve();
13
-
14
- const cast = value => (value ? 1 : 0);
15
-
16
- const cid = uuidv4();
17
-
18
- const payload = config => ({
19
- v: 1,
20
- tid: 'UA-108828841-1',
21
- cid,
22
- cd1: pkg.version,
23
- cd2: process.version,
24
- cd3: osName(),
25
- cd4: cast(!config.isCI),
26
- cd5: cast(config.isDryRun),
27
- cd6: cast(config.isVerbose),
28
- cd7: cast(config.isDebug),
29
- cd8: null,
30
- cd9: config.preReleaseId,
31
- cd11: cast(isCi),
32
- cd12: cast(config.git.tag),
33
- cd13: cast(config.npm.publish),
34
- cd14: cast(config.github.release),
35
- cd15: config.increment,
36
- cd16: cast(config.gitlab.release)
37
- });
38
-
39
- class Metrics {
40
- constructor({ isEnabled = true, request = got } = {}) {
41
- this.isEnabled = isEnabled;
42
- this.request = request;
43
- }
44
- send(payload) {
45
- return !this.isEnabled
46
- ? noop
47
- : this.request('http://www.google-analytics.com/collect', {
48
- timeout: 300,
49
- retries: 0,
50
- method: 'POST',
51
- form: payload
52
- })
53
- .then(res => {
54
- const { url, statusCode, statusMessage } = res;
55
- debug({ url, statusCode, statusMessage, payload: new URLSearchParams(payload).toString() });
56
- })
57
- .catch(debug);
58
- }
59
- trackEvent(action, config) {
60
- return this.send(
61
- Object.assign(config ? payload(config) : {}, {
62
- t: 'event',
63
- ec: 'session',
64
- ea: action
65
- })
66
- );
67
- }
68
- trackException(err) {
69
- return this.send({
70
- t: 'exception',
71
- exd: err.toString().split(EOL)[0]
72
- });
73
- }
74
- }
75
-
76
- export default Metrics;
@@ -1,11 +0,0 @@
1
- import test from 'ava';
2
- import sinon from 'sinon';
3
- import deprecated from '../lib/deprecated.js';
4
- import Log from '../lib/log.js';
5
-
6
- test('should show deprecation warnings and return compliant object', t => {
7
- const log = sinon.createStubInstance(Log);
8
- const config = deprecated({ keep: 1 }, log);
9
- t.is(log.warn.callCount, 0);
10
- t.deepEqual(config, { keep: 1 });
11
- });
package/test/metrics.js DELETED
@@ -1,17 +0,0 @@
1
- import test from 'ava';
2
- import sinon from 'sinon';
3
- import Metrics from '../lib/metrics.js';
4
-
5
- test('should send metrics', async t => {
6
- const stub = sinon.stub().resolves();
7
- const metrics = new Metrics({ request: stub });
8
- await metrics.trackEvent('test');
9
- t.true(stub.calledWithMatch(/google-analytics.com\/collect/, sinon.match.object));
10
- });
11
-
12
- test('should not send metrics when disabled', async t => {
13
- const stub = sinon.stub().resolves();
14
- const metrics = new Metrics({ isEnabled: false, request: stub });
15
- await metrics.trackEvent('test');
16
- t.true(stub.notCalled);
17
- });