2017-10-25 08:11:11 +00:00
|
|
|
module.exports = {
|
|
|
|
extractDependencies,
|
|
|
|
};
|
|
|
|
|
2018-05-03 16:09:18 +00:00
|
|
|
function extractDependencies(content) {
|
2017-10-25 08:11:11 +00:00
|
|
|
let deps = [];
|
2018-05-03 16:09:18 +00:00
|
|
|
const npmDepends = content.match(/Npm\.depends\({([\s\S]*?)}\);/);
|
|
|
|
if (!npmDepends) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-25 08:11:11 +00:00
|
|
|
try {
|
2018-05-03 16:09:18 +00:00
|
|
|
deps = npmDepends[1]
|
2017-10-25 08:11:11 +00:00
|
|
|
.replace(/(\s|\\n|\\t|'|")/g, '')
|
|
|
|
.split(',')
|
2018-03-27 13:46:29 +00:00
|
|
|
.map(dep => dep.trim())
|
|
|
|
.filter(dep => dep.length)
|
2017-10-25 08:11:11 +00:00
|
|
|
.map(dep => dep.split(/:(.*)/))
|
2018-03-27 12:00:29 +00:00
|
|
|
.map(arr => {
|
2018-06-04 03:48:20 +00:00
|
|
|
const [depName, currentValue] = arr;
|
2018-03-27 12:00:29 +00:00
|
|
|
// istanbul ignore if
|
2018-06-04 03:48:20 +00:00
|
|
|
if (!(depName && currentValue)) {
|
2018-05-03 16:09:18 +00:00
|
|
|
logger.warn({ content }, 'Incomplete npm.depends match');
|
2018-03-27 12:00:29 +00:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
depName,
|
2018-06-04 03:48:20 +00:00
|
|
|
currentValue,
|
2018-05-31 20:21:28 +00:00
|
|
|
purl: `pkg:npm/${depName.replace('@', '%40')}`,
|
2018-06-03 17:13:39 +00:00
|
|
|
versionScheme: 'semver',
|
2018-03-27 12:00:29 +00:00
|
|
|
};
|
|
|
|
})
|
2018-06-04 03:48:20 +00:00
|
|
|
.filter(dep => dep.depName && dep.currentValue);
|
2018-05-03 16:09:18 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
|
|
|
logger.warn({ content }, 'Failed to parse meteor package.js');
|
|
|
|
}
|
|
|
|
// istanbul ignore if
|
|
|
|
if (!deps.length) {
|
|
|
|
return null;
|
2017-10-25 08:11:11 +00:00
|
|
|
}
|
2018-05-03 16:09:18 +00:00
|
|
|
return { deps };
|
2017-10-25 08:11:11 +00:00
|
|
|
}
|