-
Notifications
You must be signed in to change notification settings - Fork 110
/
prepare.js
39 lines (32 loc) · 1.33 KB
/
prepare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const path = require('path');
const {move} = require('fs-extra');
const execa = require('execa');
module.exports = async (npmrc, {tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => {
const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;
logger.log('Write version %s to package.json in %s', version, basePath);
const versionResult = execa(
'npm',
['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'],
{
cwd: basePath,
env,
}
);
versionResult.stdout.pipe(stdout, {end: false});
versionResult.stderr.pipe(stderr, {end: false});
await versionResult;
if (tarballDir) {
logger.log('Creating npm package version %s', version);
const packResult = execa('npm', ['pack', basePath, '--userconfig', npmrc], {cwd, env});
packResult.stdout.pipe(stdout, {end: false});
packResult.stderr.pipe(stderr, {end: false});
const tarball = (await packResult).stdout.split('\n').pop();
const tarballSource = path.resolve(cwd, tarball);
const tarballDestination = path.resolve(cwd, tarballDir.trim(), tarball);
// Only move the tarball if we need to
// Fixes: https://github.com/semantic-release/npm/issues/169
if (tarballSource !== tarballDestination) {
await move(tarballSource, tarballDestination);
}
}
};