Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when packages has object as readme property in package.json #107

Closed
ArsArmandi opened this issue Feb 2, 2024 · 0 comments · Fixed by #108
Closed

Crash when packages has object as readme property in package.json #107

ArsArmandi opened this issue Feb 2, 2024 · 0 comments · Fixed by #108

Comments

@ArsArmandi
Copy link
Contributor

ArsArmandi commented Feb 2, 2024

When executing the scanner on certain dependencies, it crashes with error:

/usr/local/lib/node_modules/license-checker-rseidelsohn/lib/indexHelpers.js:163
        currentExtendedPackageJson?.readme?.toLowerCase()?.indexOf('no readme data found') === -1
                                            ^

TypeError: currentExtendedPackageJson?.readme?.toLowerCase is not a function
    at Object.storeReadmeInJsonIfExists (/usr/local/lib/node_modules/license-checker-rseidelsohn/lib/indexHelpers.js:163:45)
    at recursivelyCollectAllDependencies (/usr/local/lib/node_modules/license-checker-rseidelsohn/lib/index.js:123:13)
    at /usr/local/lib/node_modules/license-checker-rseidelsohn/lib/index.js:324:20
    at Array.forEach (<anonymous>)
    at recursivelyCollectAllDependencies (/usr/local/lib/node_modules/license-checker-rseidelsohn/lib/index.js:312:62)
    at /usr/local/lib/node_modules/license-checker-rseidelsohn/lib/index.js:324:20
    at Array.forEach (<anonymous>)
    at recursivelyCollectAllDependencies (/usr/local/lib/node_modules/license-checker-rseidelsohn/lib/index.js:312:62)
    at /usr/local/lib/node_modules/license-checker-rseidelsohn/lib/index.js:422:54
    at /usr/local/lib/node_modules/license-checker-rseidelsohn/node_modules/read-installed-packages/read-installed.js:139:5

Node.js v21.6.1

This happens with the following dependencies:

@commercetools-uikit\constraints
@commercetools-uikit\notifications
@commercetools-frontend\mc-scripts\node_modules@commercetools-uikit\constraints
@commercetools-uikit\async-select-input\node_modules@commercetools-uikit\constraints

This happens, because the license-checker does not check the type of the readme property.
indexHelper.js Line 159:

if (
    typeof modulePath !== 'string' ||
    typeof currentExtendedPackageJson !== 'object' ||
    modulePath === '' ||
    currentExtendedPackageJson?.readme?.toLowerCase()?.indexOf('no readme data found') === -1
) {
    return;
}

In those packages the readme property contains a reference to some other typescript files. I would suggest to overwrite this property with the README.md file, since this is the behavior of the license-checker when the property is not set.

if (
    typeof modulePath !== 'string' ||
    typeof currentExtendedPackageJson !== 'object' ||
    modulePath === '' ||
    (typeof currentExtendedPackageJson?.readme === 'string' &&
        currentExtendedPackageJson?.readme?.toLowerCase()?.indexOf('no readme data found') === -1)
) {
    return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant