在我的Gulp文件中加入2个字符串会产生无意义的错误?

xmjla07d  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(115)

在OSX上使用节点16.2.0。我是Gulp的新手。
我想更新我的package.json文件中的version,如果在功能分支上,它将包含Git哈希,所以我在我的Gulp文件中有这个

// pkg is defined somewhere else to be my Gulp file
// I have a "semVer" key in my package.json file
const {src, dest} = require('gulp');
const semver = require('semver');
...
const semVer = semver.parse(pkg.semVer);

// Functions getBranch() and getHash() are defined somewhere else,
// and they return the Git branch and hash respectively.
function manageVersion() {
  var newVersion = semver.inc(semVer, 'patch');
  var hash = "";
  if (getBranch().includes('feature')) {
    hash = getHash().toString();
    newVersion = [newVersion, hash].join('-');
  }
  src(['../package*.json'])
    .pipe(gulp_bump({
      version: newVersion
    }))
    .pipe(dest('./'));
}
exports.manageVersion = manageVersion

然后我这样做,得到无意义的错误

$ gulp manageVersion -f gulpfiles/version.js

[16:20:20] Working directory changed to /path/gulpfiles
[16:20:20] Using gulpfile /path/gulpfiles/version.js
[16:20:20] Starting 'manageVersion'...
[16:20:20] Finished 'manageVersion' after 99 ms
/path/node_modules/semver/semver.js:564
        if (v1[key] !== v2[key]) {
                          ^

TypeError: Cannot read property 'major' of null
    at Function.diff (/path/node_modules/semver/semver.js:564:27)
    at /path/node_modules/bump-regex/index.js:66:26
    at String.replace (<anonymous>)
    at module.exports (/path/node_modules/bump-regex/index.js:54:23)
    at DestroyableTransform._transform (/path/node_modules/gulp-bump/index.js:29:5)
    at DestroyableTransform.Transform._read (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:334:11)

我已经检查了newVersionhash的所有值,它们都是有效的字符串。我遗漏了什么?

k97glaaz

k97glaaz1#

我不得不从getHash()函数中删除字符串

hash = getHash().trim();

相关问题