license-checker icon indicating copy to clipboard operation
license-checker copied to clipboard

'direct' option is nor working as expected

Open poluripradeep opened this issue 6 years ago • 23 comments

'direct' option is nor working as expected

poluripradeep avatar Feb 20 '19 16:02 poluripradeep

I'm noticing the same thing.

In my case license-checker --direct is listing packages which are not included in my package.json dependencies. I guess the issue is related to how newer versions of npm structures the node_modules folder.

aeirola avatar Feb 25 '19 07:02 aeirola

Would be nice to get this working!

imraazrally avatar Mar 17 '19 20:03 imraazrally

Hi! I am experiencing similar issues. I stepped through it, apparently this is an issue with read-installed. The depth option is simply being ignored.

https://github.com/npm/read-installed/issues/47

sebastianhaas avatar Mar 18 '19 16:03 sebastianhaas

Hi! Same issue, --direct doesn't as expected!

eugeniosegala avatar Mar 25 '19 17:03 eugeniosegala

bump. same for me, --direct displays the same output as without this flag

Forfold avatar Apr 17 '19 21:04 Forfold

having the same issue here

yonida avatar Apr 18 '19 08:04 yonida

Any update on this? Has anyone been able to get it working?

jakevossen5 avatar Jul 18 '19 14:07 jakevossen5

I got it working by downgrading to npm 2, that uses a different folder structure for node_modules as @aeirola said.

npm i -g npm@2
// remove node_modules
npm i
license-checker --direct

valterkraemer avatar Aug 22 '19 07:08 valterkraemer

Having the same issue .. any update?

froston avatar Sep 03 '19 13:09 froston

Hi all, same for me. Any changes? Thanks.

obrejla avatar Sep 20 '19 11:09 obrejla

Same here

defusioner avatar Sep 30 '19 08:09 defusioner

As I mentioned above, the issue is https://github.com/npm/read-installed. It relies on the old, layered node_modules format and does not work with the present flat node_modules, so it regards all packages inside node_modules as direct dependencies. We would have to rewrite this program to not use read-installed anymore.

sebastianhaas avatar Sep 30 '19 12:09 sebastianhaas

I hacked together an ugly workaround for anyone who's interested. You'd need to adjust it to your needs, but this is the gist of it:

const checker = require('license-checker');

const packageJson = require('./package.json');

const dependencies = packageJson.dependencies;
const devDependencies = packageJson.devDependencies;

checker.init({
  start: '.',
}, function (err, packages) {
  const output = {
    dependencies: {},
    devDependencies: {},
  };

  if (err) {
    console.error(err);
  } else {
    Object.keys(packages).forEach((pkg) => {
      const pkgName = pkg.replace(/@[^@]+$/, '');
      if (dependencies[pkgName]) {
        output.dependencies[pkgName] = packages[pkg];
      }
      if (devDependencies[pkgName]) {
        output.devDependencies[pkgName] = packages[pkg];
      }
    });

    console.log(JSON.stringify(output, null, 2));
  }
});

It just loads your package.json and filters the packages based on ones listed there.

tasn avatar Nov 21 '19 08:11 tasn

Have the same issue that direct is not working.

@tasn

Did something similar like you, but the downside of this solution is that this hack does not detect sub dependencies which are also defined in the package.json as main version.

Example: In the package.json the package foo is in version 1.2.3, but the package bar has foo as a sub dependency in version 1.5.8. The output with this hack would be foo twice, in version 1.23 and 1.5.8

msteller-connyun avatar Mar 03 '20 09:03 msteller-connyun

Not with my solution... I use a hash based on the package name so it will only include one of them. Try the code above...

tasn avatar Mar 03 '20 09:03 tasn

Oh yes, that's right, but you still down’t know which is the right version to include (main dependency or sub dependency).

msteller-connyun avatar Mar 03 '20 09:03 msteller-connyun

That's correct, though it doesn't matter in my use-case, as I only use it for attribution and don't even use the version number.

tasn avatar Mar 03 '20 09:03 tasn

Any update on this?

woteska avatar Jun 02 '20 11:06 woteska

webpack-license-plugin seems like an interesting alternative. It is a webpack plugin which seems to result in it doing tree shaking, only including licenses for what you would distribute.

I'm a legal noob but maybe we only need to include licenses of what we distribute?

peteruithoven avatar Sep 04 '20 16:09 peteruithoven

npm-license-crawler with the --onlyDirectDependencies flag seems to work

daniel-shuy avatar Mar 02 '21 09:03 daniel-shuy

npm-license-crawler is working fine in order to get direct dependencies but here the issue is, we don't have an option like "--failOn", which is available in license-checker. It is typically useful in the pipeline where you want to fail the job/build where specific licenses available in the given source. Do we have any alternate in npm-license-crawler? Thanks in advance.

mayankmodi83 avatar May 24 '21 12:05 mayankmodi83

same here, bump

zacyang avatar Jan 26 '22 23:01 zacyang

I invite all of you to go and try my fork of license-checker in it's latest version 3.0.1 that hopefully finally fixed this issue.

RSeidelsohn avatar Feb 02 '22 13:02 RSeidelsohn