diff --git a/README.md b/README.md index 27d9886..dd18a6b 100644 --- a/README.md +++ b/README.md @@ -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 ', - Description: - 'Automatically download and install system requirements of R packages.', + Author: 'Gabor Csardi', + Maintainer: 'Gabor Csardi ', + 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 diff --git a/index.js b/index.js index dc05bfa..610a4a3 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/package.json b/package.json index 1bdca5f..1d4d0e0 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -16,6 +16,9 @@ "parser" ], "author": "Gabor Csardi", + "contributors": [ + "Jeroen Ooms" + ], "license": "ISC", "bugs": { "url": "https://github.com/r-hub/rdesc-parser/issues" diff --git a/test.js b/test.js index c3508a1..8275c7b 100644 --- a/test.js +++ b/test.js @@ -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(); }); }); diff --git a/test/D2 b/test/D2 index dbf38e4..ae6f849 100644 --- a/test/D2 +++ b/test/D2 @@ -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,