簡體   English   中英

npm 版本更新到特定版本

[英]npm version update to specific version

我想更新我的本地版本,所以我運行 npm 版本補丁。 這將更新如下版本: - 1.0.0 -> 1.0.1 -> 1.0.2 -> 1.0.3

我想設置像 1.0.x 這樣的特定版本,你知道怎么做嗎?

謝謝

我找不到使用方法

npm version patch <my version>

令人失望的npm 版本不需要額外的參數。

相反,在將結果傳遞給 npm 版本之前,我不得不廢棄當前版本、拆分它並自己更新補丁。

我的 Jenkinsfile 使用類似

pipeline {
    agent none
    options {
        timestamps ()
    }
    stages {
        stage("Promote?") {
            when {
                branch 'master'
            }
            input {
                message "Create Installers?"
            }
            agent {
                label 'mac'
            }
            steps {
                obtainVersion()
            }
        }
        stage("Installers") {
            parallel {
                stage("OSx") {
                    agent {
                        label 'mac'
                    }
                    steps {
                        sh "npm version ${newVersion} --no-git-tag-version"
                    }
                }
                stage("Windows") {
                    agent {
                        label 'win'
                    }
                    steps {
                        bat "npm version ${newVersion} --no-git-tag-version"
                    }
                }
            }
        }
    }
}

// Store the version for use when creating the installers
def newVersion;

def obtainVersion() {
    println "Obtaining the build version"
    def version = sh script:"node -p \"require('./package.json').version\"", returnStdout: true
    println "version in repo is ${version}"
    def versionParts = version.tokenize( '.' )
    newVersion = "${versionParts[0]}.${versionParts[1]}.${currentBuild.number}"
    println "new version for build is ${newVersion}"
}
npm version ${newVersion} --no-git-tag-version

首先清理 NPM 緩存。 您可以使用。

須藤 npm 緩存清潔 -f

使用以下命令全局安裝節點助手 (n)。

須藤 npm install -gn

一旦安裝了節點助手。 您可以使用以下方法獲取最新的穩定版本

須藤穩定

或者,如果您想要像我需要 0.11.10 這樣的特定版本,那么您可以使用它。

須藤 n 0.11.10

升級后,您可以使用 node –version 或 node -v 檢查 node 的最新版本。

默認情況下,運行npm install <name>將轉換為npm install <name>@latest (或 semver 兼容版本,如果在包含 package.json 的文件夾中運行),您可以使用npm install <name>@<version>選擇確切版本文檔

當我需要將 npm 升級到特定版本而不僅僅是最新版本時,這對我有用。

使用 npm 本身升級/降級版本

npm install -g npm@<version>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM