Bower Simulator Parsing Syntax Syntax

Bower seems to deviate from the semver spec in that I sometimes see dependencies that look like this (from 2klic-angular / bower.json ):

"dependencies": { "angulargrid": "s-yadav/angulargrid#^0.4.0" } 

This question gives a long way to explain the seven itself, but not so much what happens to the s-yadav / angulargrid # part .

Looking at bower / lib / node_modules / bower-endpoint-parser / index.js

I see the following code:

 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 }; } 

Thus, it seems that the source of the repository can be specified as part of the dependency version, using # as the delimiter.

However, I could not find anything that describes this in the bower docs.

Are there any other caveats that you need to know with interpretation of Bowers testes or is this the only one, and is it enough to split the string by # to find the expression of the requirement?

+5
source share
1 answer

You can find the corresponding code in bower / lib / node_modules / bower-endpoint-parser / index.js in 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); } 

So, what becomes target later is generated by dividing the value from the array of JSON dependencies into # . This target analyzed by resolver , so the actual behavior depends on the resolver used, but a typical resolver uses node-semver if node-semem can analyze it. Otherwise, it uses commit identifiers, branch names, tags, etc.

So splitting a string into # # and trimming spaces after that is enough to find an expression of requirements, but in the end it may not be a semver version.

+1
source

Source: https://habr.com/ru/post/1247894/


All Articles