release-it 0.0.0-pl.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +421 -0
  3. package/bin/release-it.js +42 -0
  4. package/config/release-it.json +70 -0
  5. package/lib/cli.js +44 -0
  6. package/lib/config.js +139 -0
  7. package/lib/index.js +152 -0
  8. package/lib/log.js +69 -0
  9. package/lib/plugin/GitBase.js +125 -0
  10. package/lib/plugin/GitRelease.js +58 -0
  11. package/lib/plugin/Plugin.js +73 -0
  12. package/lib/plugin/factory.js +89 -0
  13. package/lib/plugin/git/Git.js +220 -0
  14. package/lib/plugin/git/prompts.js +19 -0
  15. package/lib/plugin/github/GitHub.js +403 -0
  16. package/lib/plugin/github/prompts.js +16 -0
  17. package/lib/plugin/github/util.js +39 -0
  18. package/lib/plugin/gitlab/GitLab.js +277 -0
  19. package/lib/plugin/gitlab/prompts.js +9 -0
  20. package/lib/plugin/npm/npm.js +281 -0
  21. package/lib/plugin/npm/prompts.js +12 -0
  22. package/lib/plugin/version/Version.js +129 -0
  23. package/lib/prompt.js +33 -0
  24. package/lib/shell.js +91 -0
  25. package/lib/spinner.js +29 -0
  26. package/lib/util.js +109 -0
  27. package/package.json +122 -0
  28. package/test/cli.js +20 -0
  29. package/test/config.js +144 -0
  30. package/test/git.init.js +250 -0
  31. package/test/git.js +358 -0
  32. package/test/github.js +487 -0
  33. package/test/gitlab.js +252 -0
  34. package/test/log.js +143 -0
  35. package/test/npm.js +417 -0
  36. package/test/plugin-name.js +9 -0
  37. package/test/plugins.js +238 -0
  38. package/test/prompt.js +97 -0
  39. package/test/resources/file-v2.0.1.txt +1 -0
  40. package/test/resources/file-v2.0.2.txt +1 -0
  41. package/test/resources/file1 +1 -0
  42. package/test/shell.js +74 -0
  43. package/test/spinner.js +58 -0
  44. package/test/stub/config/default/.release-it.json +5 -0
  45. package/test/stub/config/invalid-config-rc +1 -0
  46. package/test/stub/config/invalid-config-txt +2 -0
  47. package/test/stub/config/merge/.release-it.json +5 -0
  48. package/test/stub/config/merge/package.json +7 -0
  49. package/test/stub/config/toml/.release-it.toml +2 -0
  50. package/test/stub/config/yaml/.release-it.yaml +2 -0
  51. package/test/stub/config/yml/.release-it.yml +2 -0
  52. package/test/stub/github.js +130 -0
  53. package/test/stub/gitlab.js +44 -0
  54. package/test/stub/plugin-context.js +36 -0
  55. package/test/stub/plugin-replace.js +9 -0
  56. package/test/stub/plugin.js +39 -0
  57. package/test/stub/shell.js +24 -0
  58. package/test/tasks.interactive.js +208 -0
  59. package/test/tasks.js +585 -0
  60. package/test/util/helpers.js +32 -0
  61. package/test/util/index.js +78 -0
  62. package/test/util/setup.js +5 -0
  63. package/test/utils.js +97 -0
  64. package/test/version.js +173 -0
@@ -0,0 +1,208 @@
1
+ import path from 'node:path';
2
+ import test from 'ava';
3
+ import sh from 'shelljs';
4
+ import _ from 'lodash';
5
+ import sinon from 'sinon';
6
+ import Log from '../lib/log.js';
7
+ import Spinner from '../lib/spinner.js';
8
+ import Prompt from '../lib/prompt.js';
9
+ import Config from '../lib/config.js';
10
+ import runTasks from '../lib/index.js';
11
+ import { mkTmpDir, gitAdd } from './util/helpers.js';
12
+ import ShellStub from './stub/shell.js';
13
+ import { interceptPublish as interceptGitLabPublish } from './stub/gitlab.js';
14
+ import { interceptCreate as interceptGitHubCreate } from './stub/github.js';
15
+
16
+ const noop = Promise.resolve();
17
+
18
+ const sandbox = sinon.createSandbox();
19
+
20
+ const testConfig = {
21
+ ci: false,
22
+ config: false
23
+ };
24
+
25
+ const log = sandbox.createStubInstance(Log);
26
+ const spinner = sandbox.createStubInstance(Spinner);
27
+ spinner.show.callsFake(({ enabled = true, task }) => (enabled ? task() : noop));
28
+
29
+ const defaultInquirer = {
30
+ prompt: sandbox.stub().callsFake(([options]) => {
31
+ const answer = options.type === 'list' ? options.choices[0].value : options.name === 'version' ? '0.0.1' : true;
32
+ return { [options.name]: answer };
33
+ })
34
+ };
35
+
36
+ const getContainer = (options, inquirer = defaultInquirer) => {
37
+ const config = new Config(Object.assign({}, testConfig, options));
38
+ const shell = new ShellStub({ container: { log, config } });
39
+ const prompt = new Prompt({ container: { inquirer } });
40
+ return {
41
+ log,
42
+ spinner,
43
+ config,
44
+ shell,
45
+ prompt
46
+ };
47
+ };
48
+
49
+ const getHooks = plugins => {
50
+ const hooks = {};
51
+ ['before', 'after'].forEach(prefix => {
52
+ plugins.forEach(ns => {
53
+ ['init', 'beforeBump', 'bump', 'beforeRelease', 'release', 'afterRelease'].forEach(lifecycle => {
54
+ hooks[`${prefix}:${lifecycle}`] = `echo ${prefix}:${lifecycle}`;
55
+ hooks[`${prefix}:${ns}:${lifecycle}`] = `echo ${prefix}:${ns}:${lifecycle}`;
56
+ });
57
+ });
58
+ });
59
+ return hooks;
60
+ };
61
+
62
+ test.before(t => {
63
+ t.timeout(90 * 1000);
64
+ });
65
+
66
+ test.serial.beforeEach(t => {
67
+ const bare = mkTmpDir();
68
+ const target = mkTmpDir();
69
+ sh.pushd('-q', bare);
70
+ sh.exec(`git init --bare .`);
71
+ sh.exec(`git clone ${bare} ${target}`);
72
+ sh.pushd('-q', target);
73
+ gitAdd('line', 'file', 'Add file');
74
+ t.context = { bare, target };
75
+ });
76
+
77
+ test.serial.afterEach(() => {
78
+ sandbox.resetHistory();
79
+ });
80
+
81
+ test.serial('should run tasks without throwing errors', async t => {
82
+ sh.mv('.git', 'foo');
83
+ const { name, latestVersion, version } = await runTasks({}, getContainer());
84
+ t.is(version, '0.0.1');
85
+ t.true(log.obtrusive.firstCall.args[0].includes(`release ${name} (currently at ${latestVersion})`));
86
+ t.regex(log.log.lastCall.args[0], /Done \(in [0-9]+s\.\)/);
87
+ });
88
+
89
+ test.serial('should not run hooks for disabled release-cycle methods', async t => {
90
+ const hooks = getHooks(['version', 'git', 'github', 'gitlab', 'npm']);
91
+
92
+ const container = getContainer({
93
+ hooks,
94
+ git: { push: false },
95
+ github: { release: false },
96
+ gitlab: { release: false },
97
+ npm: { publish: false }
98
+ });
99
+
100
+ const exec = sandbox.spy(container.shell, 'execFormattedCommand');
101
+
102
+ await runTasks({}, container);
103
+
104
+ const commands = _.flatten(exec.args).filter(arg => typeof arg === 'string' && arg.startsWith('echo'));
105
+
106
+ t.true(commands.includes('echo before:init'));
107
+ t.true(commands.includes('echo after:afterRelease'));
108
+
109
+ t.false(commands.includes('echo after:git:release'));
110
+ t.false(commands.includes('echo after:github:release'));
111
+ t.false(commands.includes('echo after:gitlab:release'));
112
+ t.false(commands.includes('echo after:npm:release'));
113
+ });
114
+
115
+ test.serial('should not run hooks for cancelled release-cycle methods', async t => {
116
+ const { target } = t.context;
117
+ const pkgName = path.basename(target);
118
+ gitAdd(`{"name":"${pkgName}","version":"1.0.0"}`, 'package.json', 'Add package.json');
119
+ sh.exec('git tag 1.0.0');
120
+
121
+ const hooks = getHooks(['version', 'git', 'github', 'gitlab', 'npm']);
122
+ const inquirer = { prompt: sandbox.stub().callsFake(([options]) => ({ [options.name]: false })) };
123
+
124
+ const container = getContainer(
125
+ {
126
+ increment: 'minor',
127
+ hooks,
128
+ github: { release: true, skipChecks: true },
129
+ gitlab: { release: true, skipChecks: true },
130
+ npm: { publish: true, skipChecks: true }
131
+ },
132
+ inquirer
133
+ );
134
+
135
+ const exec = sandbox.stub(container.shell, 'execFormattedCommand').callThrough();
136
+
137
+ await runTasks({}, container);
138
+
139
+ const commands = _.flatten(exec.args).filter(arg => typeof arg === 'string' && arg.startsWith('echo'));
140
+
141
+ t.true(commands.includes('echo before:init'));
142
+ t.true(commands.includes('echo after:afterRelease'));
143
+ t.true(commands.includes('echo after:git:bump'));
144
+ t.true(commands.includes('echo after:npm:bump'));
145
+
146
+ t.false(commands.includes('echo after:git:release'));
147
+ t.false(commands.includes('echo after:github:release'));
148
+ t.false(commands.includes('echo after:gitlab:release'));
149
+ t.false(commands.includes('echo after:npm:release'));
150
+
151
+ exec.restore();
152
+ });
153
+
154
+ test.serial('should run "after:*:release" plugin hooks', async t => {
155
+ const { bare, target } = t.context;
156
+ const project = path.basename(bare);
157
+ const pkgName = path.basename(target);
158
+ const owner = path.basename(path.dirname(bare));
159
+ gitAdd(`{"name":"${pkgName}","version":"1.0.0"}`, 'package.json', 'Add package.json');
160
+ sh.exec('git tag 1.0.0');
161
+ const sha = gitAdd('line', 'file', 'More file');
162
+
163
+ interceptGitHubCreate({
164
+ owner,
165
+ project,
166
+ body: { tag_name: '1.1.0', name: 'Release 1.1.0', body: `* More file (${sha})` }
167
+ });
168
+
169
+ interceptGitLabPublish({
170
+ owner,
171
+ project,
172
+ body: {
173
+ name: 'Release 1.1.0',
174
+ tag_name: '1.1.0',
175
+ description: `* More file (${sha})`
176
+ }
177
+ });
178
+
179
+ const hooks = getHooks(['version', 'git', 'github', 'gitlab', 'npm']);
180
+
181
+ const container = getContainer({
182
+ increment: 'minor',
183
+ hooks,
184
+ github: { release: true, pushRepo: `https://github.com/${owner}/${project}`, skipChecks: true },
185
+ gitlab: { release: true, pushRepo: `https://gitlab.com/${owner}/${project}`, skipChecks: true },
186
+ npm: { name: pkgName, skipChecks: true }
187
+ });
188
+
189
+ const exec = sandbox.spy(container.shell, 'execFormattedCommand');
190
+
191
+ await runTasks({}, container);
192
+
193
+ const commands = _.flatten(exec.args).filter(arg => typeof arg === 'string' && arg.startsWith('echo'));
194
+
195
+ t.true(commands.includes('echo after:git:bump'));
196
+ t.true(commands.includes('echo after:npm:bump'));
197
+ t.true(commands.includes('echo after:git:release'));
198
+ t.true(commands.includes('echo after:github:release'));
199
+ t.true(commands.includes('echo after:gitlab:release'));
200
+ t.true(commands.includes('echo after:npm:release'));
201
+ });
202
+
203
+ test.serial('should show only version prompt', async t => {
204
+ const config = { ci: false, 'only-version': true };
205
+ await runTasks({}, getContainer(config));
206
+ t.true(defaultInquirer.prompt.calledOnce);
207
+ t.is(defaultInquirer.prompt.firstCall.args[0][0].name, 'incrementList');
208
+ });