commit-and-tag-version 12.7.1 → 13.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.
Files changed (54) hide show
  1. package/.github/workflows/ci.yaml +8 -15
  2. package/.github/workflows/release-please.yml +7 -5
  3. package/CHANGELOG.md +36 -0
  4. package/MIGRATION.md +51 -0
  5. package/README.md +22 -21
  6. package/bin/cli.js +2 -2
  7. package/command.js +9 -4
  8. package/defaults.js +5 -3
  9. package/eslint.config.mjs +52 -42
  10. package/index.js +12 -12
  11. package/lib/checkpoint.js +5 -5
  12. package/lib/configuration.js +9 -6
  13. package/lib/detect-package-manager.js +4 -8
  14. package/lib/format-commit-message.js +2 -2
  15. package/lib/latest-semver-tag.js +30 -30
  16. package/lib/lifecycles/bump.js +97 -65
  17. package/lib/lifecycles/changelog.js +48 -60
  18. package/lib/lifecycles/commit.js +8 -8
  19. package/lib/lifecycles/tag.js +10 -10
  20. package/lib/preset-loader.js +73 -9
  21. package/lib/print-error.js +3 -3
  22. package/lib/run-exec.js +6 -5
  23. package/lib/run-execFile.js +6 -5
  24. package/lib/run-lifecycle-script.js +6 -6
  25. package/lib/stringify-package.js +1 -5
  26. package/lib/updaters/index.js +25 -12
  27. package/lib/updaters/types/csproj.js +4 -4
  28. package/lib/updaters/types/gradle.js +4 -4
  29. package/lib/updaters/types/json.js +9 -9
  30. package/lib/updaters/types/maven.js +25 -8
  31. package/lib/updaters/types/openapi.js +6 -6
  32. package/lib/updaters/types/plain-text.js +4 -4
  33. package/lib/updaters/types/python.js +4 -4
  34. package/lib/updaters/types/yaml.js +6 -6
  35. package/lib/write-file.js +3 -3
  36. package/package.json +25 -15
  37. package/test/commit-message-config.integration-test.js +23 -10
  38. package/test/config-files.integration-test.js +25 -10
  39. package/test/config-keys.integration-test.js +20 -7
  40. package/test/core.spec.js +103 -37
  41. package/test/git.integration-test.js +23 -15
  42. package/test/invalid-config.integration-test.js +19 -9
  43. package/test/mocks/pom-6.3.1-attrs-lf.xml +28 -0
  44. package/test/mocks/pom-6.4.0-attrs-lf.xml +29 -0
  45. package/test/mocks/vitest-mocks.js +260 -0
  46. package/test/package.json +3 -0
  47. package/test/pre-commit-hook.integration-test.js +22 -14
  48. package/test/preset.integration-test.js +7 -5
  49. package/test/setup-coverage.js +47 -0
  50. package/test/stringify-package.spec.js +1 -3
  51. package/test/utils.spec.js +3 -4
  52. package/vitest.config.js +26 -0
  53. package/jest.config.js +0 -28
  54. package/test/mocks/jest-mocks.js +0 -66
@@ -1,34 +1,34 @@
1
- const gitSemverTags = require('git-semver-tags');
2
- const semver = require('semver');
1
+ import { ConventionalGitClient } from '@conventional-changelog/git-client';
2
+ import semver from 'semver';
3
3
 
4
- module.exports = function ({ tagPrefix, prerelease }) {
5
- return new Promise((resolve, reject) => {
6
- gitSemverTags({ tagPrefix }, function (err, tags) {
7
- if (err) return reject(err);
8
- else if (!tags.length) return resolve('1.0.0');
9
- // Respect tagPrefix
10
- tags = tags.map((tag) => tag.replace(new RegExp('^' + tagPrefix), ''));
11
- if (prerelease) {
12
- // ignore any other prelease tags
13
- tags = tags.filter((tag) => {
14
- if (!semver.valid(tag)) return false;
15
- if (!semver.prerelease(tag)) {
16
- // include all non-prerelease versions
17
- return true;
18
- }
19
- // check if the name of the prerelease matches the one we are looking for
20
- if (semver.prerelease(tag)[0] === prerelease) {
21
- return true;
22
- }
23
- return false;
24
- });
4
+ export default async function ({ tagPrefix, prerelease }) {
5
+ const gitClient = new ConventionalGitClient(process.cwd());
6
+ let tags = [];
7
+ for await (const tag of gitClient.getSemverTags({ prefix: tagPrefix })) {
8
+ tags.push(tag);
9
+ }
10
+ if (!tags.length) return '1.0.0';
11
+ // Respect tagPrefix
12
+ tags = tags.map((tag) => tag.replace(new RegExp('^' + tagPrefix), ''));
13
+ if (prerelease) {
14
+ // ignore any other prelease tags
15
+ tags = tags.filter((tag) => {
16
+ if (!semver.valid(tag)) return false;
17
+ if (!semver.prerelease(tag)) {
18
+ // include all non-prerelease versions
19
+ return true;
25
20
  }
26
- // ensure that the largest semver tag is at the head.
27
- tags = tags.map((tag) => {
28
- return semver.clean(tag);
29
- });
30
- tags.sort(semver.rcompare);
31
- return resolve(tags[0]);
21
+ // check if the name of the prerelease matches the one we are looking for
22
+ if (semver.prerelease(tag)[0] === prerelease) {
23
+ return true;
24
+ }
25
+ return false;
32
26
  });
27
+ }
28
+ // ensure that the largest semver tag is at the head.
29
+ tags = tags.map((tag) => {
30
+ return semver.clean(tag);
33
31
  });
34
- };
32
+ tags.sort(semver.rcompare);
33
+ return tags[0];
34
+ }
@@ -1,19 +1,17 @@
1
- 'use strict';
2
-
3
- const chalk = require('chalk');
4
- const checkpoint = require('../checkpoint');
5
- const conventionalRecommendedBump = require('conventional-recommended-bump');
6
- const figures = require('figures');
7
- const fs = require('fs');
8
- const DotGitignore = require('dotgitignore');
9
- const path = require('path');
10
- const presetLoader = require('../preset-loader');
11
- const runLifecycleScript = require('../run-lifecycle-script');
12
- const semver = require('semver');
13
- const writeFile = require('../write-file');
14
- const { resolveUpdaterObjectFromArgument } = require('../updaters');
15
- const gitSemverTags = require('git-semver-tags');
16
- const addBangNotes = require('conventional-changelog-conventionalcommits/add-bang-notes');
1
+ import chalk from 'chalk';
2
+ import { Bumper, packagePrefix } from 'conventional-recommended-bump';
3
+ import figures from 'figures';
4
+ import fs from 'fs';
5
+ import DotGitignore from 'dotgitignore';
6
+ import path from 'path';
7
+ import semver from 'semver';
8
+ import { ConventionalGitClient } from '@conventional-changelog/git-client';
9
+ import checkpoint from '../checkpoint.js';
10
+ import presetLoader from '../preset-loader.js';
11
+ import runLifecycleScript from '../run-lifecycle-script.js';
12
+ import writeFile from '../write-file.js';
13
+ import { resolveUpdaterObjectFromArgument } from '../updaters/index.js';
14
+
17
15
  let configsToUpdate = {};
18
16
  const sanitizeQuotesRegex = /['"]+/g;
19
17
 
@@ -24,7 +22,6 @@ function noBumpWhenEmptyChanges(config, commits) {
24
22
  let fix = 0;
25
23
 
26
24
  commits.forEach((commit) => {
27
- addBangNotes(commit);
28
25
  if (commit.notes.length > 0) {
29
26
  breakings += commit.notes.length;
30
27
  level = 0;
@@ -43,7 +40,44 @@ function noBumpWhenEmptyChanges(config, commits) {
43
40
  level++;
44
41
  }
45
42
 
46
- if (!breakings && !features && !fix) return {};
43
+ if (!breakings && !features && !fix) return null;
44
+
45
+ return {
46
+ level,
47
+ reason:
48
+ breakings === 1
49
+ ? `There is ${breakings} BREAKING CHANGE and ${features} features`
50
+ : `There are ${breakings} BREAKING CHANGES and ${features} features`,
51
+ };
52
+ }
53
+
54
+ /**
55
+ * The `whatBump` implementation of conventional-changelog-conventionalcommits
56
+ * before v10: the release is always at least a patch, even when there are no
57
+ * relevant commits. From v10 the preset only recommends a bump when there is
58
+ * at least one commit of a type with the 'bump' effect, so we keep the
59
+ * historical behaviour here (`--no-bump-when-empty-changes` opts out of it).
60
+ */
61
+ function legacyWhatBump(config, commits) {
62
+ let level = 2;
63
+ let breakings = 0;
64
+ let features = 0;
65
+
66
+ commits.forEach((commit) => {
67
+ if (commit.notes.length > 0) {
68
+ breakings += commit.notes.length;
69
+ level = 0;
70
+ } else if (commit.type === 'feat' || commit.type === 'feature') {
71
+ features += 1;
72
+ if (level === 2) {
73
+ level = 1;
74
+ }
75
+ }
76
+ });
77
+
78
+ if (config.preMajor && level < 2) {
79
+ level++;
80
+ }
47
81
 
48
82
  return {
49
83
  level,
@@ -231,47 +265,45 @@ function getTypePriority(type) {
231
265
  return TypeList.indexOf(type);
232
266
  }
233
267
 
234
- function bumpVersion(releaseAs, currentVersion, args) {
235
- return new Promise((resolve, reject) => {
236
- if (releaseAs) {
237
- return resolve({
238
- releaseType: releaseAs,
239
- });
240
- } else {
241
- const presetOptions = presetLoader(args);
242
- if (typeof presetOptions === 'object') {
243
- if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true;
244
- }
245
- conventionalRecommendedBump(
246
- {
247
- preset: presetOptions,
248
- path: args.path,
249
- tagPrefix: args.tagPrefix,
250
- lernaPackage: args.lernaPackage,
251
- ...(args.verbose
252
- ? {
253
- debug: console.info.bind(
254
- console,
255
- 'conventional-recommended-bump',
256
- ),
257
- }
258
- : {}),
259
- ...(args.noBumpWhenEmptyChanges
260
- ? {
261
- whatBump(commits) {
262
- return noBumpWhenEmptyChanges(presetOptions, commits);
263
- },
264
- }
265
- : {}),
266
- },
267
- args.parserOpts,
268
- function (err, release) {
269
- if (err) return reject(err);
270
- else return resolve(release);
271
- },
272
- );
273
- }
274
- });
268
+ async function bumpVersion(releaseAs, currentVersion, args) {
269
+ if (releaseAs) {
270
+ return {
271
+ releaseType: releaseAs,
272
+ };
273
+ }
274
+
275
+ const presetOptions = presetLoader(args);
276
+ // `whatBump` stays undefined for third-party presets so that the preset's
277
+ // own recommendation logic is used.
278
+ let whatBump;
279
+ if (typeof presetOptions === 'object') {
280
+ if (semver.lt(currentVersion, '1.0.0')) presetOptions.preMajor = true;
281
+ whatBump = args.noBumpWhenEmptyChanges
282
+ ? (commits) => noBumpWhenEmptyChanges(presetOptions, commits)
283
+ : (commits) => legacyWhatBump(presetOptions, commits);
284
+ } else if (args.noBumpWhenEmptyChanges) {
285
+ whatBump = (commits) => noBumpWhenEmptyChanges({}, commits);
286
+ }
287
+
288
+ const bumper = new Bumper()
289
+ .loadPreset(presetOptions)
290
+ .tag({
291
+ prefix: args.lernaPackage
292
+ ? packagePrefix(args.lernaPackage)
293
+ : args.tagPrefix,
294
+ })
295
+ .commits({ path: args.path }, args.parserOpts);
296
+
297
+ if (args.verbose) {
298
+ bumper.options({
299
+ debug: console.info.bind(console, 'conventional-recommended-bump'),
300
+ });
301
+ }
302
+
303
+ const release = await bumper.bump(whatBump);
304
+ // A recommendation without a releaseType means no bump is warranted;
305
+ // normalize to the empty object the caller expects.
306
+ return release.releaseType ? release : {};
275
307
  }
276
308
 
277
309
  /**
@@ -321,7 +353,7 @@ function updateConfigs(args, newVersion) {
321
353
  });
322
354
  }
323
355
 
324
- module.exports = Bump;
356
+ export default Bump;
325
357
 
326
358
  /**
327
359
  * Ensure prerelease version uniqueness by checking existing git tags.
@@ -353,11 +385,11 @@ async function resolveUniquePrereleaseVersion(
353
385
  }
354
386
  }
355
387
 
356
- const tags = await new Promise((resolve, reject) => {
357
- gitSemverTags({ tagPrefix }, (err, t) =>
358
- err ? reject(err) : resolve(t || []),
359
- );
360
- });
388
+ const tags = [];
389
+ const gitClient = new ConventionalGitClient(process.cwd());
390
+ for await (const tag of gitClient.getSemverTags({ prefix: tagPrefix })) {
391
+ tags.push(tag);
392
+ }
361
393
 
362
394
  // strip prefix and clean
363
395
  const cleaned = tags
@@ -1,10 +1,11 @@
1
- const chalk = require('chalk');
2
- const checkpoint = require('../checkpoint');
3
- const conventionalChangelog = require('conventional-changelog');
4
- const fs = require('fs');
5
- const presetLoader = require('../preset-loader');
6
- const runLifecycleScript = require('../run-lifecycle-script');
7
- const writeFile = require('../write-file');
1
+ import chalk from 'chalk';
2
+ import { ConventionalChangelog } from 'conventional-changelog';
3
+ import fs from 'fs';
4
+ import checkpoint from '../checkpoint.js';
5
+ import presetLoader from '../preset-loader.js';
6
+ import runLifecycleScript from '../run-lifecycle-script.js';
7
+ import writeFile from '../write-file.js';
8
+
8
9
  const START_OF_LAST_RELEASE_PATTERN =
9
10
  /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
10
11
 
@@ -17,7 +18,7 @@ async function Changelog(args, newVersion) {
17
18
 
18
19
  Changelog.START_OF_LAST_RELEASE_PATTERN = START_OF_LAST_RELEASE_PATTERN;
19
20
 
20
- module.exports = Changelog;
21
+ export default Changelog;
21
22
 
22
23
  /**
23
24
  * Front matter is only extracted and therefore retained in final output where Changelog "header" begins with #Changelog,
@@ -40,64 +41,51 @@ function extractChangelogBody(oldContent) {
40
41
  : oldContent;
41
42
  }
42
43
 
43
- function outputChangelog(args, newVersion) {
44
- return new Promise((resolve, reject) => {
45
- createIfMissing(args);
46
- const header = args.header;
44
+ async function outputChangelog(args, newVersion) {
45
+ createIfMissing(args);
46
+ const header = args.header;
47
47
 
48
- const oldContent =
49
- args.dryRun || args.releaseCount === 0
50
- ? ''
51
- : fs.readFileSync(args.infile, 'utf-8');
48
+ const oldContent =
49
+ args.dryRun || args.releaseCount === 0
50
+ ? ''
51
+ : fs.readFileSync(args.infile, 'utf-8');
52
52
 
53
- const oldContentBody = extractChangelogBody(oldContent);
53
+ const oldContentBody = extractChangelogBody(oldContent);
54
54
 
55
- const changelogFrontMatter = extractFrontMatter(oldContent);
55
+ const changelogFrontMatter = extractFrontMatter(oldContent);
56
56
 
57
- let content = '';
58
- const context = { version: newVersion };
59
- const changelogStream = conventionalChangelog(
60
- {
61
- preset: presetLoader(args),
62
- tagPrefix: args.tagPrefix,
63
- releaseCount: args.releaseCount,
64
- ...(args.verbose
65
- ? {
66
- debug: console.info.bind(
67
- console,
68
- 'conventional-recommended-bump',
69
- ),
70
- }
71
- : {}),
72
- },
73
- context,
74
- { merges: null, path: args.path, showSignature: false },
75
- args.parserOpts,
76
- args.writerOpts,
77
- ).on('error', function (err) {
78
- return reject(err);
79
- });
57
+ const generator = new ConventionalChangelog()
58
+ .readPackage()
59
+ .loadPreset(presetLoader(args))
60
+ .tags({ prefix: args.tagPrefix })
61
+ .options({
62
+ releaseCount: args.releaseCount,
63
+ ...(args.verbose
64
+ ? {
65
+ debug: console.info.bind(console, 'conventional-changelog'),
66
+ }
67
+ : {}),
68
+ })
69
+ .context({ version: newVersion })
70
+ .commits({ merges: null, path: args.path }, args.parserOpts)
71
+ .writer(args.writerOpts || {});
80
72
 
81
- changelogStream.on('data', function (buffer) {
82
- content += buffer.toString();
83
- });
73
+ let content = '';
74
+ for await (const chunk of generator.write()) {
75
+ content += chunk;
76
+ }
84
77
 
85
- changelogStream.on('end', function () {
86
- checkpoint(args, 'outputting changes to %s', [args.infile]);
87
- if (args.dryRun)
88
- console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`);
89
- else
90
- writeFile(
91
- args,
92
- args.infile,
93
- changelogFrontMatter +
94
- header +
95
- '\n' +
96
- (content + oldContentBody).replace(/\n+$/, '\n'),
97
- );
98
- return resolve();
99
- });
100
- });
78
+ checkpoint(args, 'outputting changes to %s', [args.infile]);
79
+ if (args.dryRun) console.info(`\n---\n${chalk.gray(content.trim())}\n---\n`);
80
+ else
81
+ writeFile(
82
+ args,
83
+ args.infile,
84
+ changelogFrontMatter +
85
+ header +
86
+ '\n' +
87
+ (content + oldContentBody).replace(/\n+$/, '\n'),
88
+ );
101
89
  }
102
90
 
103
91
  function createIfMissing(args) {
@@ -1,17 +1,17 @@
1
- const bump = require('../lifecycles/bump');
2
- const checkpoint = require('../checkpoint');
3
- const formatCommitMessage = require('../format-commit-message');
4
- const path = require('path');
5
- const runExecFile = require('../run-execFile');
6
- const runLifecycleScript = require('../run-lifecycle-script');
1
+ import path from 'path';
2
+ import bump from '../lifecycles/bump.js';
3
+ import checkpoint from '../checkpoint.js';
4
+ import formatCommitMessage from '../format-commit-message.js';
5
+ import runExecFile from '../run-execFile.js';
6
+ import runLifecycleScript from '../run-lifecycle-script.js';
7
7
 
8
- module.exports = async function (args, newVersion) {
8
+ export default async function (args, newVersion) {
9
9
  if (args.skip.commit) return;
10
10
  const message = await runLifecycleScript(args, 'precommit');
11
11
  if (message && message.length) args.releaseCommitMessageFormat = message;
12
12
  await execCommit(args, newVersion);
13
13
  await runLifecycleScript(args, 'postcommit');
14
- };
14
+ }
15
15
 
16
16
  async function execCommit(args, newVersion) {
17
17
  let msg = 'committing %s';
@@ -1,18 +1,18 @@
1
- const bump = require('../lifecycles/bump');
2
- const chalk = require('chalk');
3
- const checkpoint = require('../checkpoint');
4
- const figures = require('figures');
5
- const formatCommitMessage = require('../format-commit-message');
6
- const runExecFile = require('../run-execFile');
7
- const runLifecycleScript = require('../run-lifecycle-script');
8
- const { detectPMByLockFile } = require('../detect-package-manager');
1
+ import chalk from 'chalk';
2
+ import figures from 'figures';
3
+ import bump from '../lifecycles/bump.js';
4
+ import checkpoint from '../checkpoint.js';
5
+ import formatCommitMessage from '../format-commit-message.js';
6
+ import runExecFile from '../run-execFile.js';
7
+ import runLifecycleScript from '../run-lifecycle-script.js';
8
+ import { detectPMByLockFile } from '../detect-package-manager.js';
9
9
 
10
- module.exports = async function (newVersion, pkgPrivate, args) {
10
+ export default async function (newVersion, pkgPrivate, args) {
11
11
  if (args.skip.tag) return;
12
12
  await runLifecycleScript(args, 'pretag');
13
13
  await execTag(newVersion, pkgPrivate, args);
14
14
  await runLifecycleScript(args, 'posttag');
15
- };
15
+ }
16
16
 
17
17
  async function detectPublishHint() {
18
18
  const npmClientName = await detectPMByLockFile();
@@ -1,19 +1,83 @@
1
1
  // TODO: this should be replaced with an object we maintain and
2
2
  // describe in: https://github.com/conventional-changelog/conventional-changelog-config-spec
3
- const spec = require('conventional-changelog-config-spec');
4
-
5
- module.exports = (args) => {
6
- const defaultPreset = require.resolve(
7
- 'conventional-changelog-conventionalcommits',
8
- );
9
- let preset = args.preset || defaultPreset;
10
- if (preset === defaultPreset) {
3
+ import spec from 'conventional-changelog-config-spec';
4
+
5
+ const DEFAULT_PRESET = 'conventional-changelog-conventionalcommits';
6
+
7
+ /**
8
+ * Expand a conventional-changelog-config-spec URL format template
9
+ * (e.g. "{{host}}/{{owner}}/{{repository}}/issues/{{id}}") using the
10
+ * variables available at render time.
11
+ */
12
+ function expandTemplate(template, variables) {
13
+ return template.replace(/{{\s*(\w+)\s*}}/g, (_, key) => variables[key] ?? '');
14
+ }
15
+
16
+ /**
17
+ * conventional-changelog-conventionalcommits >= 10 dropped support for the
18
+ * config-spec's declarative options in favour of new equivalents. Translate
19
+ * the config-spec options so existing user configuration keeps working:
20
+ *
21
+ * - `types[].hidden` (boolean) became `types[].effect`
22
+ * ('bump' | 'changelog' | 'hidden')
23
+ * - `commitUrlFormat`, `compareUrlFormat`, `issueUrlFormat` and
24
+ * `userUrlFormat` (handlebars-style template strings) became the
25
+ * `formatCommitUrl`, `formatCompareUrl`, `formatIssueUrl` and
26
+ * `formatUserUrl` functions
27
+ */
28
+ function translateSpecOptionsToPresetConfig(preset) {
29
+ if (Array.isArray(preset.types)) {
30
+ preset.types = preset.types.map((entry) => {
31
+ if (typeof entry !== 'object' || entry === null || entry.effect) {
32
+ return entry;
33
+ }
34
+ const { hidden, ...rest } = entry;
35
+ return { ...rest, effect: hidden ? 'hidden' : 'bump' };
36
+ });
37
+ }
38
+
39
+ if (preset.commitUrlFormat && !preset.formatCommitUrl) {
40
+ const template = preset.commitUrlFormat;
41
+ preset.formatCommitUrl = (context, commit) =>
42
+ expandTemplate(template, { ...context, hash: commit.hash });
43
+ }
44
+
45
+ if (preset.compareUrlFormat && !preset.formatCompareUrl) {
46
+ const template = preset.compareUrlFormat;
47
+ preset.formatCompareUrl = (context) => expandTemplate(template, context);
48
+ }
49
+
50
+ if (preset.issueUrlFormat && !preset.formatIssueUrl) {
51
+ const template = preset.issueUrlFormat;
52
+ preset.formatIssueUrl = (context, reference) =>
53
+ expandTemplate(template, {
54
+ ...context,
55
+ id: reference.issue,
56
+ prefix: reference.prefix,
57
+ });
58
+ }
59
+
60
+ if (preset.userUrlFormat && !preset.formatUserUrl) {
61
+ const template = preset.userUrlFormat;
62
+ preset.formatUserUrl = (context, user) =>
63
+ expandTemplate(template, { ...context, user });
64
+ }
65
+
66
+ return preset;
67
+ }
68
+
69
+ export default (args) => {
70
+ let preset = args.preset || DEFAULT_PRESET;
71
+ if (preset === DEFAULT_PRESET) {
11
72
  preset = {
12
- name: defaultPreset,
73
+ name: DEFAULT_PRESET,
13
74
  };
14
75
  Object.keys(spec.properties).forEach((key) => {
15
76
  if (args[key] !== undefined) preset[key] = args[key];
16
77
  });
17
78
  }
79
+ if (typeof preset === 'object') {
80
+ preset = translateSpecOptionsToPresetConfig(preset);
81
+ }
18
82
  return preset;
19
83
  };
@@ -1,6 +1,6 @@
1
- const chalk = require('chalk');
1
+ import chalk from 'chalk';
2
2
 
3
- module.exports = function (args, msg, opts) {
3
+ export default function (args, msg, opts) {
4
4
  if (!args.silent) {
5
5
  opts = Object.assign(
6
6
  {
@@ -12,4 +12,4 @@ module.exports = function (args, msg, opts) {
12
12
 
13
13
  console[opts.level](chalk[opts.color](msg));
14
14
  }
15
- };
15
+ }
package/lib/run-exec.js CHANGED
@@ -1,9 +1,10 @@
1
- const { promisify } = require('util');
2
- const printError = require('./print-error');
1
+ import { promisify } from 'util';
2
+ import childProcess from 'child_process';
3
+ import printError from './print-error.js';
3
4
 
4
- const exec = promisify(require('child_process').exec);
5
+ const exec = promisify(childProcess.exec);
5
6
 
6
- module.exports = async function (args, cmd) {
7
+ export default async function (args, cmd) {
7
8
  if (args.dryRun) return;
8
9
  try {
9
10
  const { stderr, stdout } = await exec(cmd);
@@ -15,4 +16,4 @@ module.exports = async function (args, cmd) {
15
16
  printError(args, error.stderr || error.message);
16
17
  throw error;
17
18
  }
18
- };
19
+ }
@@ -1,9 +1,10 @@
1
- const { promisify } = require('util');
2
- const printError = require('./print-error');
1
+ import { promisify } from 'util';
2
+ import childProcess from 'child_process';
3
+ import printError from './print-error.js';
3
4
 
4
- const execFile = promisify(require('child_process').execFile);
5
+ const execFile = promisify(childProcess.execFile);
5
6
 
6
- module.exports = async function (args, cmd, cmdArgs) {
7
+ export default async function (args, cmd, cmdArgs) {
7
8
  if (args.dryRun) return;
8
9
  try {
9
10
  const { stderr, stdout } = await execFile(cmd, cmdArgs);
@@ -15,4 +16,4 @@ module.exports = async function (args, cmd, cmdArgs) {
15
16
  printError(args, error.stderr || error.message);
16
17
  throw error;
17
18
  }
18
- };
19
+ }
@@ -1,9 +1,9 @@
1
- const chalk = require('chalk');
2
- const checkpoint = require('./checkpoint');
3
- const figures = require('figures');
4
- const runExec = require('./run-exec');
1
+ import chalk from 'chalk';
2
+ import figures from 'figures';
3
+ import checkpoint from './checkpoint.js';
4
+ import runExec from './run-exec.js';
5
5
 
6
- module.exports = function (args, hookName) {
6
+ export default function (args, hookName) {
7
7
  const scripts = args.scripts;
8
8
  if (!scripts || !scripts[hookName]) return Promise.resolve();
9
9
  const command = scripts[hookName];
@@ -15,4 +15,4 @@ module.exports = function (args, hookName) {
15
15
  chalk.blue(figures.info),
16
16
  );
17
17
  return runExec(args, command);
18
- };
18
+ }
@@ -16,15 +16,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
16
  https://github.com/npm/stringify-package/blob/main/LICENSE
17
17
  */
18
18
 
19
- 'use strict';
20
-
21
- module.exports = stringifyPackage;
22
-
23
19
  const DEFAULT_INDENT = 2;
24
20
  const CRLF = '\r\n';
25
21
  const LF = '\n';
26
22
 
27
- function stringifyPackage(data, indent, newline) {
23
+ export default function stringifyPackage(data, indent, newline) {
28
24
  indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT);
29
25
  const json = JSON.stringify(data, null, indent);
30
26