Skip to content

Commit

Permalink
Support info.xml toolkit dependency version ranges (#48)
Browse files Browse the repository at this point in the history
* The package will be able to read intervals for the toolkit dependencies from the info.xml file (ex: [2.0.0,3.0.0))

* Update source-archive-utils.js

The package will be able to read intervals for the toolkit dependencies from the info.xml file (ex: [2.0.0,3.0.0))

* parsing toolkits versions will check the version format first

* changed the forEach to a map

* updated map
  • Loading branch information
Kyrellos-Salib authored and Christian Guy committed Jun 24, 2019
1 parent 9a256c7 commit 7911053
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions lib/util/source-archive-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,39 @@ async function buildSourceArchive(
return { archivePromise: Promise.reject(err), archivePath: outputFilePath, buildId }; /* eslint-disable-line compat/compat */
}
}

function parseToolkitVersions(dependencies) {
return dependencies.map((dep) => {
const vr = dep.version.split(',');
let range = '';
if (vr.length === 2) {
const regex = RegExp(/[[,(]\d+\.\d+\.\d+,\d+\.\d+\.\d+[\],)]/);
if (!regex.test(dep.version)) {
throw new Error(`invalid toolkit version: ${dep.version}`);
}
range = '';
if (vr[0].charAt(0) === '[') {
vr[0] = vr[0].slice(1);
range += `>=${vr[0]}`;
} else {
vr[0] = vr[0].slice(1);
range += `>${vr[0]}`;
}
if (vr[1].charAt(vr[1].length - 1) === ')') {
vr[1] = vr[1].substr(0, vr.length - 1);
range += ` <${vr[1]}`;
} else {
vr[1] = vr[1].slice(0, vr.length - 1);
range += ` <=${vr[1]}`;
}
} else if (vr.length === 1) {
range = `>=${vr[0]}`;
} else {
throw new Error(`invalid toolkit version: ${dep.version}`);
}
const parsedDep = { name: dep.name, version: range };
return parsedDep;
});
}
function getToolkits(toolkitCacheDir, toolkitPathSetting, appRoot) {
const allToolkits = StreamsToolkitsUtils.getAllToolkits(toolkitCacheDir, toolkitPathSetting);

Expand All @@ -185,8 +217,9 @@ function getToolkits(toolkitCacheDir, toolkitPathSetting, appRoot) {
name: node.valueWithPath('common:name'),
version: node.valueWithPath('common:version')
}));
const parsedDependencies = parseToolkitVersions(dependencies);
const newestLocalToolkits = StreamsToolkitsUtils.filterNewestToolkits(allToolkits).filter(tk => tk.isLocal);
const toolkitsToInclude = _.intersectionWith(newestLocalToolkits, dependencies, (tk, dependency) => tk.name === dependency.name && semver.gte(tk.version, dependency.version));
const toolkitsToInclude = _.intersectionWith(newestLocalToolkits, parsedDependencies, (tk, dependency) => tk.name === dependency.name && semver.satisfies(tk.version, dependency.version));
return toolkitsToInclude.map(tk => ({ name: tk.name, tkPath: path.dirname(tk.indexPath) }));
}
}
Expand Down

0 comments on commit 7911053

Please sign in to comment.