relion 0.1.1 → 0.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.
Files changed (37) hide show
  1. package/package.json +84 -73
  2. package/src/cli.js +6 -0
  3. package/src/commands.js +16 -30
  4. package/src/defaults.js +6 -14
  5. package/src/index.js +48 -125
  6. package/src/lib/checkpoint.js +10 -10
  7. package/src/lib/configuration.js +21 -21
  8. package/src/lib/detect-package-manager.js +21 -18
  9. package/src/lib/format-commit-message.js +2 -2
  10. package/src/lib/latest-semver-tag.js +17 -17
  11. package/src/lib/lifecycles/bump.js +99 -91
  12. package/src/lib/lifecycles/changelog.js +47 -46
  13. package/src/lib/lifecycles/commit.js +34 -34
  14. package/src/lib/lifecycles/tag.js +32 -30
  15. package/src/lib/print-error.js +4 -4
  16. package/src/lib/run-exec.js +13 -12
  17. package/src/lib/run-execFile.js +13 -12
  18. package/src/lib/run-lifecycle-script.js +11 -11
  19. package/src/lib/stringify-package.js +9 -9
  20. package/src/lib/updaters/index.js +57 -54
  21. package/src/lib/updaters/types/csproj.js +6 -6
  22. package/src/lib/updaters/types/gradle.js +7 -7
  23. package/src/lib/updaters/types/json.js +12 -12
  24. package/src/lib/updaters/types/maven.js +22 -22
  25. package/src/lib/updaters/types/openapi.js +8 -8
  26. package/src/lib/updaters/types/plain-text.js +3 -3
  27. package/src/lib/updaters/types/python.js +19 -19
  28. package/src/lib/updaters/types/yaml.js +8 -8
  29. package/src/lib/write-file.js +4 -4
  30. package/src/preset/constants.js +1 -1
  31. package/src/preset/index.js +8 -8
  32. package/src/preset/parser.js +2 -2
  33. package/src/preset/templates/index.js +8 -8
  34. package/src/preset/whatBump.js +14 -13
  35. package/src/preset/writer.js +19 -19
  36. package/CHANGELOG.md +0 -47
  37. package/bin/cli.js +0 -9
@@ -1,61 +1,61 @@
1
- import bump from '../lifecycles/bump.js';
2
- import checkpoint from '../checkpoint.js';
3
- import formatCommitMessage from '../format-commit-message.js';
4
- import path from 'path';
5
- import runExecFile from '../run-execFile.js';
6
- import runLifecycleScript from '../run-lifecycle-script.js';
1
+ import bump from '../lifecycles/bump.js'
2
+ import checkpoint from '../checkpoint.js'
3
+ import formatCommitMessage from '../format-commit-message.js'
4
+ import path from 'path'
5
+ import runExecFile from '../run-execFile.js'
6
+ import runLifecycleScript from '../run-lifecycle-script.js'
7
7
 
8
8
  export default async function (args, newVersion) {
9
- const message = await runLifecycleScript(args, 'precommit');
10
- if (message && message.length) args.preset.releaseCommitMessageFormat = message;
11
- await execCommit(args, newVersion);
12
- await runLifecycleScript(args, 'postcommit');
9
+ const message = await runLifecycleScript(args, 'precommit')
10
+ if (message && message.length) args.preset.releaseCommitMessageFormat = message
11
+ await execCommit(args, newVersion)
12
+ await runLifecycleScript(args, 'postcommit')
13
13
  }
14
14
 
15
- async function execCommit(args, newVersion) {
16
- let msg = 'committing %s';
17
- let paths = [];
18
- const verify = args.verify === false || args.n ? ['--no-verify'] : [];
19
- const sign = args.sign ? ['-S'] : [];
20
- const signoff = args.signoff ? ['--signoff'] : [];
21
- const toAdd = [];
15
+ async function execCommit(args) {
16
+ let msg = 'committing %s'
17
+ let paths = []
18
+ const verify = args.verify === false || args.n ? ['--no-verify'] : []
19
+ const sign = args.sign ? ['-S'] : []
20
+ const signoff = args.signoff ? ['--signoff'] : []
21
+ const toAdd = []
22
22
 
23
23
  // only start with a pre-populated paths list when CHANGELOG processing is not skipped
24
24
  if (args.changelog) {
25
- paths = [args.infile];
26
- toAdd.push(args.infile);
25
+ paths = [args.infile]
26
+ toAdd.push(args.infile)
27
27
  }
28
28
 
29
29
  // commit any of the config files that we've updated
30
30
  // the version # for.
31
31
  Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
32
- paths.unshift(p);
33
- toAdd.push(path.relative(process.cwd(), p));
32
+ paths.unshift(p)
33
+ toAdd.push(path.relative(process.cwd(), p))
34
34
 
35
35
  // account for multiple files in the output message
36
36
  if (paths.length > 1) {
37
- msg += ' and %s';
37
+ msg += ' and %s'
38
38
  }
39
- });
39
+ })
40
40
 
41
41
  if (args.commitAll) {
42
- msg += ' and %s';
43
- paths.push('all staged files');
42
+ msg += ' and %s'
43
+ paths.push('all staged files')
44
44
  }
45
45
 
46
- checkpoint(args, msg, paths);
46
+ checkpoint(args, msg, paths)
47
47
 
48
48
  // nothing to do, exit without commit anything
49
49
  if (
50
- !args.commitAll &&
51
- !args.changelog &&
52
- !args.bump &&
53
- toAdd.length === 0
50
+ !args.commitAll
51
+ && !args.changelog
52
+ && !args.bump
53
+ && toAdd.length === 0
54
54
  ) {
55
- return;
55
+ return
56
56
  }
57
57
 
58
- await runExecFile(args, 'git', ['add'].concat(toAdd));
58
+ await runExecFile(args, 'git', ['add'].concat(toAdd))
59
59
  await runExecFile(
60
60
  args,
61
61
  'git',
@@ -63,5 +63,5 @@ async function execCommit(args, newVersion) {
63
63
  '-m',
64
64
  `${formatCommitMessage(args)}`,
65
65
  ]),
66
- );
67
- }
66
+ )
67
+ }
@@ -1,59 +1,61 @@
1
- import bump from '../lifecycles/bump.js';
2
- import chalk from 'chalk';
3
- import checkpoint from '../checkpoint.js';
4
- import figures from 'figures';
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';
1
+ import bump from '../lifecycles/bump.js'
2
+ import chalk from 'chalk'
3
+ import checkpoint from '../checkpoint.js'
4
+ import figures from 'figures'
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
10
  export default async function (newVersion, pkgPrivate, args) {
11
- await runLifecycleScript(args, 'pretag');
12
- await execTag(newVersion, pkgPrivate, args);
13
- await runLifecycleScript(args, 'posttag');
11
+ await runLifecycleScript(args, 'pretag')
12
+ await execTag(newVersion, pkgPrivate, args)
13
+ await runLifecycleScript(args, 'posttag')
14
14
  }
15
15
 
16
16
  async function detectPublishHint() {
17
- const npmClientName = await detectPMByLockFile();
18
- const publishCommand = 'publish';
19
- return `${npmClientName} ${publishCommand}`;
17
+ const npmClientName = await detectPMByLockFile()
18
+ const publishCommand = 'publish'
19
+ return `${npmClientName} ${publishCommand}`
20
20
  }
21
21
 
22
22
  async function execTag(newVersion, pkgPrivate, args) {
23
- const tagOption = [];
23
+ const tagOption = []
24
24
  if (args.sign) {
25
- tagOption.push('-s');
26
- } else {
27
- tagOption.push('-a');
25
+ tagOption.push('-s')
26
+ }
27
+ else {
28
+ tagOption.push('-a')
28
29
  }
29
30
  if (args.tagForce) {
30
- tagOption.push('-f');
31
+ tagOption.push('-f')
31
32
  }
32
- checkpoint(args, 'tagging release %s%s', [args.tagPrefix, newVersion]);
33
+ checkpoint(args, 'tagging release %s%s', [args.tagPrefix, newVersion])
33
34
  await runExecFile(args, 'git', [
34
35
  'tag',
35
36
  ...tagOption,
36
37
  args.tagPrefix + newVersion,
37
38
  '-m',
38
39
  `${formatCommitMessage(args)}`,
39
- ]);
40
+ ])
40
41
  const currentBranch = await runExecFile('', 'git', [
41
42
  'rev-parse',
42
43
  '--abbrev-ref',
43
44
  'HEAD',
44
- ]);
45
- let message = 'git push --follow-tags origin ' + currentBranch.trim();
45
+ ])
46
+ let message = 'git push --follow-tags origin ' + currentBranch.trim()
46
47
  if (pkgPrivate !== true && bump.getUpdatedConfigs()['package.json']) {
47
- const npmPublishHint = args.npmPublishHint || (await detectPublishHint());
48
- message += ` && ${npmPublishHint}`;
48
+ const npmPublishHint = args.npmPublishHint || (await detectPublishHint())
49
+ message += ` && ${npmPublishHint}`
49
50
  if (args.prerelease !== undefined) {
50
51
  if (args.prerelease === '') {
51
- message += ' --tag prerelease';
52
- } else {
53
- message += ' --tag ' + args.prerelease;
52
+ message += ' --tag prerelease'
53
+ }
54
+ else {
55
+ message += ' --tag ' + args.prerelease
54
56
  }
55
57
  }
56
58
  }
57
59
 
58
- checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info));
59
- }
60
+ checkpoint(args, 'Run `%s` to publish', [message], chalk.blue(figures.info))
61
+ }
@@ -1,4 +1,4 @@
1
- import chalk from 'chalk';
1
+ import chalk from 'chalk'
2
2
 
3
3
  export default function (args, msg, opts) {
4
4
  if (!args.silent) {
@@ -8,8 +8,8 @@ export default function (args, msg, opts) {
8
8
  color: 'red',
9
9
  },
10
10
  opts,
11
- );
11
+ )
12
12
 
13
- console[opts.level](chalk[opts.color](msg));
13
+ console[opts.level](chalk[opts.color](msg))
14
14
  }
15
- }
15
+ }
@@ -1,19 +1,20 @@
1
- import { promisify } from 'util';
2
- import printError from './print-error.js';
3
- import { exec as execCb } from 'child_process';
1
+ import { promisify } from 'util'
2
+ import printError from './print-error.js'
3
+ import { exec as execCb } from 'child_process'
4
4
 
5
- const exec = promisify(execCb);
5
+ const exec = promisify(execCb)
6
6
 
7
7
  export default async function (args, cmd) {
8
- if (args.dryRun) return;
8
+ if (args.dryRun) return
9
9
  try {
10
- const { stderr, stdout } = await exec(cmd);
10
+ const { stderr, stdout } = await exec(cmd)
11
11
  // If exec returns content in stderr, but no error, print it as a warning
12
- if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' });
13
- return stdout;
14
- } catch (error) {
12
+ if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' })
13
+ return stdout
14
+ }
15
+ catch (error) {
15
16
  // If exec returns an error, print it and exit with return code 1
16
- printError(args, error.stderr || error.message);
17
- throw error;
17
+ printError(args, error.stderr || error.message)
18
+ throw error
18
19
  }
19
- }
20
+ }
@@ -1,19 +1,20 @@
1
- import { promisify } from 'util';
2
- import printError from './print-error.js';
3
- import { execFile as execFileCb } from 'child_process';
1
+ import { promisify } from 'util'
2
+ import printError from './print-error.js'
3
+ import { execFile as execFileCb } from 'child_process'
4
4
 
5
- const execFile = promisify(execFileCb);
5
+ const execFile = promisify(execFileCb)
6
6
 
7
7
  export default async function (args, cmd, cmdArgs) {
8
- if (args.dryRun) return;
8
+ if (args.dryRun) return
9
9
  try {
10
- const { stderr, stdout } = await execFile(cmd, cmdArgs);
10
+ const { stderr, stdout } = await execFile(cmd, cmdArgs)
11
11
  // If execFile returns content in stderr, but no error, print it as a warning
12
- if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' });
13
- return stdout;
14
- } catch (error) {
12
+ if (stderr) printError(args, stderr, { level: 'warn', color: 'yellow' })
13
+ return stdout
14
+ }
15
+ catch (error) {
15
16
  // If execFile returns an error, print it and exit with return code 1
16
- printError(args, error.stderr || error.message);
17
- throw error;
17
+ printError(args, error.stderr || error.message)
18
+ throw error
18
19
  }
19
- }
20
+ }
@@ -1,18 +1,18 @@
1
- import chalk from 'chalk';
2
- import checkpoint from './checkpoint.js';
3
- import figures from 'figures';
4
- import runExec from './run-exec.js';
1
+ import chalk from 'chalk'
2
+ import checkpoint from './checkpoint.js'
3
+ import figures from 'figures'
4
+ import runExec from './run-exec.js'
5
5
 
6
6
  export default function (args, hookName) {
7
- const scripts = args.scripts;
8
- if (!scripts || !scripts[hookName]) return Promise.resolve();
9
- const command = scripts[hookName];
10
- checkpoint(args, 'Running lifecycle script "%s"', [hookName]);
7
+ const scripts = args.scripts
8
+ if (!scripts || !scripts[hookName]) return Promise.resolve()
9
+ const command = scripts[hookName]
10
+ checkpoint(args, 'Running lifecycle script "%s"', [hookName])
11
11
  checkpoint(
12
12
  args,
13
13
  '- execute command: "%s"',
14
14
  [command],
15
15
  chalk.blue(figures.info),
16
- );
17
- return runExec(args, command);
18
- }
16
+ )
17
+ return runExec(args, command)
18
+ }
@@ -16,19 +16,19 @@ 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';
19
+ 'use strict'
20
20
 
21
- const DEFAULT_INDENT = 2;
22
- const CRLF = '\r\n';
23
- const LF = '\n';
21
+ const DEFAULT_INDENT = 2
22
+ const CRLF = '\r\n'
23
+ const LF = '\n'
24
24
 
25
25
  export default function stringifyPackage(data, indent, newline) {
26
- indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT);
27
- const json = JSON.stringify(data, null, indent);
26
+ indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT)
27
+ const json = JSON.stringify(data, null, indent)
28
28
 
29
29
  if (newline === CRLF) {
30
- return json.replace(/\n/g, CRLF) + CRLF;
30
+ return json.replace(/\n/g, CRLF) + CRLF
31
31
  }
32
32
 
33
- return json + LF;
34
- }
33
+ return json + LF
34
+ }
@@ -1,76 +1,76 @@
1
- import path from 'path';
2
- import defaults from '../../defaults.js';
3
- import * as jsonUpdater from './types/json.js';
4
- import * as plainTextUpdater from './types/plain-text.js';
5
- import * as mavenUpdater from './types/maven.js';
6
- import * as gradleUpdater from './types/gradle.js';
7
- import * as csprojUpdater from './types/csproj.js';
8
- import * as yamlUpdater from './types/yaml.js';
9
- import * as openapiUpdater from './types/openapi.js';
10
- import * as pythonUpdater from './types/python.js';
1
+ import path from 'path'
2
+ import defaults from '../../defaults.js'
3
+ import * as jsonUpdater from './types/json.js'
4
+ import * as plainTextUpdater from './types/plain-text.js'
5
+ import * as mavenUpdater from './types/maven.js'
6
+ import * as gradleUpdater from './types/gradle.js'
7
+ import * as csprojUpdater from './types/csproj.js'
8
+ import * as yamlUpdater from './types/yaml.js'
9
+ import * as openapiUpdater from './types/openapi.js'
10
+ import * as pythonUpdater from './types/python.js'
11
11
 
12
- const JSON_BUMP_FILES = defaults.bumpFiles;
12
+ const JSON_BUMP_FILES = defaults.bumpFiles
13
13
  const updatersByType = {
14
- json: jsonUpdater,
14
+ 'json': jsonUpdater,
15
15
  'plain-text': plainTextUpdater,
16
- maven: mavenUpdater,
17
- gradle: gradleUpdater,
18
- csproj: csprojUpdater,
19
- yaml: yamlUpdater,
20
- openapi: openapiUpdater,
21
- python: pythonUpdater,
22
- };
23
- const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt'];
16
+ 'maven': mavenUpdater,
17
+ 'gradle': gradleUpdater,
18
+ 'csproj': csprojUpdater,
19
+ 'yaml': yamlUpdater,
20
+ 'openapi': openapiUpdater,
21
+ 'python': pythonUpdater,
22
+ }
23
+ const PLAIN_TEXT_BUMP_FILES = ['VERSION.txt', 'version.txt']
24
24
 
25
25
  function getUpdaterByType(type) {
26
- const updater = updatersByType[type];
26
+ const updater = updatersByType[type]
27
27
  if (!updater) {
28
- throw Error(`Unable to locate updater for provided type (${type}).`);
28
+ throw Error(`Unable to locate updater for provided type (${type}).`)
29
29
  }
30
- return updater;
30
+ return updater
31
31
  }
32
32
 
33
33
  function getUpdaterByFilename(filename) {
34
34
  if (JSON_BUMP_FILES.includes(path.basename(filename))) {
35
- return getUpdaterByType('json');
35
+ return getUpdaterByType('json')
36
36
  }
37
37
  if (PLAIN_TEXT_BUMP_FILES.includes(filename)) {
38
- return getUpdaterByType('plain-text');
38
+ return getUpdaterByType('plain-text')
39
39
  }
40
40
  if (/pom.xml/.test(filename)) {
41
- return getUpdaterByType('maven');
41
+ return getUpdaterByType('maven')
42
42
  }
43
43
  if (/build.gradle/.test(filename)) {
44
- return getUpdaterByType('gradle');
44
+ return getUpdaterByType('gradle')
45
45
  }
46
46
  if (filename.endsWith('.csproj')) {
47
- return getUpdaterByType('csproj');
47
+ return getUpdaterByType('csproj')
48
48
  }
49
49
  if (/openapi.yaml/.test(filename)) {
50
- return getUpdaterByType('openapi');
50
+ return getUpdaterByType('openapi')
51
51
  }
52
52
  if (/\.ya?ml$/.test(filename)) {
53
- return getUpdaterByType('yaml');
53
+ return getUpdaterByType('yaml')
54
54
  }
55
55
  if (/pyproject.toml/.test(filename)) {
56
- return getUpdaterByType('python');
56
+ return getUpdaterByType('python')
57
57
  }
58
58
  throw Error(
59
59
  `Unsupported file (${filename}) provided for bumping.\n Please specify the updater \`type\` or use a custom \`updater\`.`,
60
- );
60
+ )
61
61
  }
62
62
 
63
63
  async function getCustomUpdaterFromPath(updater) {
64
64
  if (typeof updater === 'string') {
65
- return (await import(path.resolve(process.cwd(), updater))).default;
65
+ return (await import(path.resolve(process.cwd(), updater))).default
66
66
  }
67
67
  if (
68
- typeof updater.readVersion === 'function' &&
69
- typeof updater.writeVersion === 'function'
68
+ typeof updater.readVersion === 'function'
69
+ && typeof updater.writeVersion === 'function'
70
70
  ) {
71
- return updater;
71
+ return updater
72
72
  }
73
- throw new Error('Updater must be a string path or an object with readVersion and writeVersion methods');
73
+ throw new Error('Updater must be a string path or an object with readVersion and writeVersion methods')
74
74
  }
75
75
 
76
76
  /**
@@ -78,10 +78,10 @@ async function getCustomUpdaterFromPath(updater) {
78
78
  */
79
79
  function isValidUpdater(obj) {
80
80
  return (
81
- obj &&
82
- typeof obj.readVersion === 'function' &&
83
- typeof obj.writeVersion === 'function'
84
- );
81
+ obj
82
+ && typeof obj.readVersion === 'function'
83
+ && typeof obj.writeVersion === 'function'
84
+ )
85
85
  }
86
86
 
87
87
  export async function resolveUpdaterObjectFromArgument(arg) {
@@ -89,39 +89,42 @@ export async function resolveUpdaterObjectFromArgument(arg) {
89
89
  * If an Object was not provided, we assume it's the path/filename
90
90
  * of the updater.
91
91
  */
92
- let updater = arg;
92
+ let updater = arg
93
93
  if (isValidUpdater(updater)) {
94
- return updater;
94
+ return updater
95
95
  }
96
96
  if (typeof updater !== 'object') {
97
97
  updater = {
98
98
  filename: arg,
99
- };
99
+ }
100
100
  }
101
101
 
102
102
  if (!isValidUpdater(updater.updater)) {
103
103
  try {
104
104
  if (typeof updater.updater === 'string') {
105
- updater.updater = await getCustomUpdaterFromPath(updater.updater);
106
- } else if (updater.type) {
107
- updater.updater = getUpdaterByType(updater.type);
108
- } else {
109
- updater.updater = getUpdaterByFilename(updater.filename);
105
+ updater.updater = await getCustomUpdaterFromPath(updater.updater)
106
+ }
107
+ else if (updater.type) {
108
+ updater.updater = getUpdaterByType(updater.type)
110
109
  }
111
- } catch (err) {
110
+ else {
111
+ updater.updater = getUpdaterByFilename(updater.filename)
112
+ }
113
+ }
114
+ catch (err) {
112
115
  if (err.code !== 'ENOENT')
113
116
  console.warn(
114
117
  `Unable to obtain updater for: ${JSON.stringify(arg)}\n - Error: ${err.message
115
118
  }\n - Skipping...`,
116
- );
119
+ )
117
120
  }
118
121
  }
119
122
  /**
120
123
  * We weren't able to resolve an updater for the argument.
121
124
  */
122
125
  if (!isValidUpdater(updater.updater)) {
123
- return false;
126
+ return false
124
127
  }
125
128
 
126
- return updater;
127
- }
129
+ return updater
130
+ }
@@ -1,13 +1,13 @@
1
- const versionRegex = /<Version>(.*)<\/Version>/;
1
+ const versionRegex = /<Version>(.*)<\/Version>/
2
2
 
3
3
  export function readVersion(contents) {
4
- const matches = versionRegex.exec(contents);
4
+ const matches = versionRegex.exec(contents)
5
5
  if (matches === null || matches.length !== 2) {
6
- throw new Error('Failed to read the Version field in your csproj file - is it present?');
6
+ throw new Error('Failed to read the Version field in your csproj file - is it present?')
7
7
  }
8
- return matches[1];
8
+ return matches[1]
9
9
  }
10
10
 
11
11
  export function writeVersion(contents, version) {
12
- return contents.replace(versionRegex, `<Version>${version}</Version>`);
13
- }
12
+ return contents.replace(versionRegex, `<Version>${version}</Version>`)
13
+ }
@@ -1,16 +1,16 @@
1
- const versionRegex = /^version\s+=\s+['"]([\d.]+)['"]/m;
1
+ const versionRegex = /^version\s+=\s+['"]([\d.]+)['"]/m
2
2
 
3
3
  export function readVersion(contents) {
4
- const matches = versionRegex.exec(contents);
4
+ const matches = versionRegex.exec(contents)
5
5
  if (matches === null) {
6
- throw new Error('Failed to read the version field in your gradle file - is it present?');
6
+ throw new Error('Failed to read the version field in your gradle file - is it present?')
7
7
  }
8
8
 
9
- return matches[1];
9
+ return matches[1]
10
10
  }
11
11
 
12
12
  export function writeVersion(contents, version) {
13
13
  return contents.replace(versionRegex, () => {
14
- return `version = "${version}"`;
15
- });
16
- }
14
+ return `version = "${version}"`
15
+ })
16
+ }
@@ -1,25 +1,25 @@
1
- import stringifyPackage from '../../stringify-package.js';
2
- import detectIndent from 'detect-indent';
3
- import { detectNewline } from 'detect-newline';
1
+ import stringifyPackage from '../../stringify-package.js'
2
+ import detectIndent from 'detect-indent'
3
+ import { detectNewline } from 'detect-newline'
4
4
 
5
5
  export function readVersion(contents) {
6
- return JSON.parse(contents).version;
6
+ return JSON.parse(contents).version
7
7
  }
8
8
 
9
9
  export function writeVersion(contents, version) {
10
- const json = JSON.parse(contents);
11
- const indent = detectIndent(contents).indent;
12
- const newline = detectNewline(contents);
13
- json.version = version;
10
+ const json = JSON.parse(contents)
11
+ const indent = detectIndent(contents).indent
12
+ const newline = detectNewline(contents)
13
+ json.version = version
14
14
 
15
15
  if (json.packages && json.packages['']) {
16
16
  // package-lock v2 stores version there too
17
- json.packages[''].version = version;
17
+ json.packages[''].version = version
18
18
  }
19
19
 
20
- return stringifyPackage(json, indent, newline);
20
+ return stringifyPackage(json, indent, newline)
21
21
  }
22
22
 
23
23
  export function isPrivate(contents) {
24
- return JSON.parse(contents).private;
25
- }
24
+ return JSON.parse(contents).private
25
+ }