Skip to content

Commit

Permalink
Parse dependency versions (#7)
Browse files Browse the repository at this point in the history
Parse dependency versions
  • Loading branch information
gaborcsardi authored Nov 21, 2019
2 parents c4768f8 + 850bacb commit 4a3967e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ rdesc(stream, function(err, d) {
})
```

```json
{ Package: 'sysreqs',
```js
{
Package: 'sysreqs',
Title: 'Install SystemRequirements of Packages',
Version: '1.0.0.9000',
Author: 'Gábor Csárdi',
Maintainer: 'Gábor Csárdi <[email protected]>',
Description:
'Automatically download and install system requirements of R packages.',
Author: 'Gabor Csardi',
Maintainer: 'Gabor Csardi <[email protected]>',
Description: 'Automatically download and install system requirements of R packages.',
License: 'MIT + file LICENSE',
LazyData: 'true',
URL: 'https://github.com/r-hub/sysreqs',
BugReports: 'https://github.com/r-hub/sysreqs/issues',
RoxygenNote: '6.1.1',
Suggests: [ 'testthat' ],
Imports: [ 'debugme', 'desc', 'jsonlite', 'processx', 'utils' ],
Encoding: 'UTF-8',
Roxygen: 'list(markdown = TRUE)' }
RoxygenNote: '5.0.1.9000',
Suggests: [ { package: 'testthat' } ],
Imports: [ { package: 'debugme' }, { package: 'desc' }, { package: 'utils' } ]
}
```

### Parse `DESCRIPTION` file
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ function parse_desc_stream(descstream, callback) {
}

function parse_dep(str) {
return str.split(/,[\s]*/).map(normalize_ws);
return str.split(/,[\s]*/s).filter(function(str){
return str.trim(); //filter out empty strings
}).map(function(str){
return str.match(/\(.+\)/s) ?
{
package: normalize_ws(str.replace(/\(.+\)/s, '')),
version: normalize_ws(str.replace(/.*\((.+)\)/s, '$1'))
} : {
package: normalize_ws(str)
};
});
}

function parse_remotes(str) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rdesc-parser",
"version": "2.0.4",
"version": "3.0.0",
"description": "Parser for R package DESCRIPTION files.",
"main": "index.js",
"scripts": {
Expand All @@ -16,6 +16,9 @@
"parser"
],
"author": "Gabor Csardi",
"contributors": [
"Jeroen Ooms"
],
"license": "ISC",
"bugs": {
"url": "https://github.com/r-hub/rdesc-parser/issues"
Expand Down
9 changes: 7 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ test.cb('D2', function(t) {
t.is(err, null);
t.is(d.Package, 'roxygen2');
t.is(d.Depends.length, 1);
t.is(d.Depends[0], 'R (>= 3.0.2)');
t.end();
t.is(d.Imports.length, 8);
t.deepEqual(d.Depends[0], {package: 'R', version: '>= 3.0.2'});
t.deepEqual(d.Imports[0], {package: 'stringr', version: '>= 0.5'});
t.deepEqual(d.Imports[1], {package: 'stringi'});
t.deepEqual(d.Imports[5], {package: 'Rcpp', version: '>= 0.11.0'});
t.deepEqual(d.Suggests[0], {package: 'testthat', version: '>= 0.8.0'});
t.end();
});
});

Expand Down
10 changes: 6 additions & 4 deletions test/D2
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ Authors@R: c(
person("RStudio", role = "cph")
)
Depends:
R (>= 3.0.2)
R (>= 3.0.2),
Imports:
stringr (>= 0.5) ,
stringi,
stringr
(>=
0.5)
, stringi,
brew,
digest,
methods ,
Rcpp (>= 0.11.0),
commonmark,
xml2
xml2,
Suggests:
testthat (>= 0.8.0),
knitr,
Expand Down

0 comments on commit 4a3967e

Please sign in to comment.