ck86 / main-bower-files

Getting all main bower files
583 stars 56 forks source link

Skips dependencies if there is no main property in the bower.json #166

Open redbugz opened 7 years ago

redbugz commented 7 years ago

The main property is listed as recommended but not required by the bower.json spec, but if a dependency chooses to not list a main file, all of it's dependencies are skipped.

It is because of this code in package.js (https://github.com/ck86/main-bower-files/blob/master/lib/package.js#L46):

                if (prev && prev.main) {
                    return prev;
                }

                if (!exists(curr)) {
                    return prev;
                }

                try {
                    return JSON.parse(readFile(curr, 'utf8'));
                } catch (e) {
                    return null;
                }
            }, null);

In our particular case, it skipped the .bower.json and bower.json dependencies because prev.main was undefined for bower, and dropped to the package.json dependencies because component.json (curr) did not exist, returning the package.json dependencies, not the bower.json dependencies which is not what we wanted.

It treats the main property as required.

Should it use prev.name instead which is a required attribute, or check for prev.main or prev.dependencies since if either of those exists there is something to do at the next step of the function?