and*_*rew 5 semantic-versioning bower
Bower似乎偏离了semver规范,因为我有时会看到这样的依赖关系(来自2klic-angular/bower.json):
"dependencies": {
"angulargrid": "s-yadav/angulargrid#^0.4.0"
}
Run Code Online (Sandbox Code Playgroud)
这个问题在解释semver本身方面还有很长的路要走,但对于s-yadav/angulargrid#部分的解释却并非如此.
查看bower/lib/node_modules/bower-endpoint-parser/index.js
我看到以下代码:
function decompose(endpoint) {
// Note that we allow spaces in targets and sources but they are trimmed
var regExp = /^(?:([\w\-]|(?:[\w\.\-]+[\w\-])?)=)?([^\|#]+)(?:#(.*))?$/;
var matches = endpoint.match(regExp);
var target;
var error;
if (!matches) {
error = new Error('Invalid endpoint: ' + endpoint);
error.code = 'EINVEND';
throw error;
}
target = trim(matches[3]);
return {
name: trim(matches[1]),
source: trim(matches[2]),
target: isWildcard(target) ? '*' : target
};
}
Run Code Online (Sandbox Code Playgroud)
因此,似乎可以使用#作为分隔符将存储库源指定为依赖关系版本的一部分.
但是我无法在凉亭文档中找到任何描述这一点的内容.
Bowers对semver的解释是否有任何其他注意事项或者这是唯一的注意事项,是否足以将字符串拆分为#以找到需求表达式?
您可以在 Bower/lib/node_modules/bower-endpoint-parser/index.js 中找到相关代码json2decomposed
:
function json2decomposed(key, value) {
...
key = trim(key);
value = trim(value);
...
endpoint = key + '=';
split = value.split('#').map(trim);
// If # was found, the source was specified
if (split.length > 1) {
endpoint += (split[0] || key) + '#' + split[1];
// Check if value looks like a source
} else if (isSource(value)) {
endpoint += value + '#*';
// Otherwise use the key as the source
} else {
endpoint += key + '#' + split[0];
}
return decompose(endpoint);
}
Run Code Online (Sandbox Code Playgroud)
因此,后来的 是target
通过将 JSON 依赖项数组中的值拆分为 来生成的#
。这是由解析器target
解析的,因此实际行为取决于所使用的解析器,但典型的解析器使用node-semver(如果node-semver可以解析它)。否则它使用提交 ID、分支名称、标签等。
因此,用“#”分割字符串并随后修剪空格足以找到需求表达式,但它毕竟可能不是 semver 版本。
归档时间: |
|
查看次数: |
120 次 |
最近记录: |