-
Notifications
You must be signed in to change notification settings - Fork 110
/
prepare.js
44 lines (37 loc) · 1.39 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
40
41
42
43
44
import path from "path";
import { move } from "fs-extra";
import { execa } from "execa";
export default async function (
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,
preferLocal: true,
}
);
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, preferLocal: true });
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);
}
}
}