Skip to content

Commit

Permalink
Add docs to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jalal246 committed Mar 4, 2020
1 parent 3885812 commit 635a90c
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/packageSorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ function isDepInSorted(dep) {
}

/**
* Checks if given package should be added to sorted array.
*
* If package dependencies doesn't matched coreDep, then returns true. It
* should be added because it's neutral.
*
* Otherwise, checks, if it exists before, then true to add it, if not false.
* Because we should add the essential dependency first.
* Checks if given package has decency in coreDep.
*
* @param {Object} packageDeps
* @returns {boolean}
*
* @returns {Object} result
* @returns {boolean} result.hasCoreDep
* @returns {Object} result.dep
*/

function isPackageNeedCoreDep(packageDeps) {
let hasCoreDep = false;
let dep;
Expand All @@ -49,6 +45,13 @@ function isPackageNeedCoreDep(packageDeps) {
return { hasCoreDep, dep };
}

/**
* Adds package at(index) to sorted or inSorted.
*
* @param {Array} packages - packages in workspace.
* @param {number} at - index
* @param {boolean} isSorted -
*/
function addTo(packages, at, isSorted) {
const target = isSorted ? sorted : unSorted;

Expand All @@ -65,6 +68,8 @@ function addTo(packages, at, isSorted) {
/**
* Loop into packages. Add package that don't require coreDep first, then add
* coreDep, then other packages.
*
* @param {Array} packages - packages in workspace.
*/
function sort(packages) {
let isAddToSorted = false;
Expand All @@ -86,11 +91,6 @@ function sort(packages) {
*/
isAddToSorted = !hasCoreDep || isDepInSorted(dep);

// console.log("sort -> pkg", pkg.name);
// console.log("sort -> hasCoreDep", hasCoreDep);
// console.log("sort -> isDepInSorted", isDepInSorted(dep));
// console.log("sort -> isAddToSorted", isAddToSorted);

if (isAddToSorted) {
addTo(packages, i, true);

Expand All @@ -100,7 +100,6 @@ function sort(packages) {

/**
* Has hasCoreDep but couldn't add it.
* - Stop looping.
* - Add it to unsorted.
* - remove it form packages.
*/
Expand All @@ -113,10 +112,13 @@ function sort(packages) {
* Sorting packages. Package with no deps will come first, then package that
* depending of package that is built. This is essential for monorepo build.
*
* @param {Array} packages - contains dependencies for each package in workspace.
* @param {Array} packages - packages in workspace.
* @param {string} coreDependency - core package that other packages depend on.
* @returns {Array} - Sorted Array.
*/
*
* @returns {Object} result
* @returns {boolean} result.sorted
* @returns {Object} result.unSorted
* */
function packageSorter(packages = [], coreDependency) {
unSorted = [];

Expand Down

0 comments on commit 635a90c

Please sign in to comment.