xtask/npm/
util.rs

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::process::{Command, Stdio};

use anyhow::{Context, Result};
use semver::Version;

use crate::util::{repository_root, wrap};

pub fn set_version(version: &Version) -> Result<()> {
    wrap(|| {
        let mut c = Command::new("npm");
        c.current_dir(repository_root()?).stderr(Stdio::inherit());
        c.arg("version")
            .arg(version.to_string())
            .arg("--no-git-tag-version")
            .arg("--allow-same-version");

        c.status()?;

        Ok(())
    })
    .with_context(|| format!("failed to set version of @swc/core to v{}", version))?;

    wrap(|| {
        let mut c = Command::new("npm");
        c.current_dir(repository_root()?.join("packages").join("minifier"))
            .stderr(Stdio::inherit());
        c.arg("version")
            .arg(version.to_string())
            .arg("--no-git-tag-version")
            .arg("--allow-same-version");

        c.status()?;

        Ok(())
    })
    .with_context(|| format!("failed to set version of @swc/minifier to v{}", version))?;

    wrap(|| {
        let mut c = Command::new("cargo");
        c.current_dir(repository_root()?.join("bindings"))
            .stderr(Stdio::inherit());
        c.arg("set-version")
            .arg(version.to_string())
            .arg("-p")
            .arg("binding_core_wasm")
            .arg("-p")
            .arg("binding_minifier_wasm");

        c.status()?;
        Ok(())
    })
    .with_context(|| format!("failed to set version of Wasm packages to v{}", version))?;

    Ok(())
}

pub fn bump_swc_cli() -> Result<()> {
    let mut c = Command::new("cargo");
    c.current_dir(repository_root()?.join("bindings"))
        .stderr(Stdio::inherit());
    c.arg("set-version")
        .arg("--bump")
        .arg("patch")
        .arg("-p")
        .arg("swc_cli");

    c.status()?;

    Ok(())
}