question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Match on files within top-level depedencies

See original GitHub issue

Folks may want to import files from within packages they depend on. I think we need to include these files, or a subset of these files in the files that we match on. This may end up causing relevance issues, which we might be able to resolve with better ranking, with a stricter opt-in mechanism (see below), or both.

In https://github.com/Galooshi/import-js/issues/340#issuecomment-241788664 I mentioned:

One idea I have is to only consider files in the directories.lib directory specified in the package’s package.json file. This would allow packages to opt in to this behavior which would help us avoid matching on random example files, documentation, test files, and other private modules.

I think we could start by adding this feature and allowing packages to opt in to having the files in their directories.lib directory be matched. We can always expand it later if necessary.

I think we need to do this for 2.0, since we removed lookupPaths.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:20

github_iconTop GitHub Comments

2reactions
hathawshcommented, Sep 11, 2018

Until this issue is solved, here’s a workaround for material-ui imports. I added this option to my .importjs.js:

    importStatementFormatter: (options) => {
      // Adjust material-ui imports to avoid accidentally importing the entire
      // material-ui bundle.
      let stmt = options.importStatement;
      const match = (
        /import \{\s*([A-Za-z,\s]+)\s*\} from '@material-ui\/core';/.exec(stmt));
      if (match) {
        const names = match[1].split(',');
        stmt = names.map((nameWithWhitespace) => {
          const name = nameWithWhitespace.trim();
          return `import ${name} from '@material-ui/core/${name}';`;
        }).join('\n');
      }
      return stmt;
    },

It seems to do the trick.

0reactions
ljharbcommented, Jun 24, 2017

Every single person using lodash 5 and up will be importing deep files from it, for example, and not from within any directory. react-dates also has a number of things that are only accessible via deep imports.

Certainly you’d want to filter out everything that’s not in “main”. Another approach could be, only show things that aren’t required elsewhere, but that’d filter out real entry points too.

As for src, I can see how that’d get tricky when it’s included in the package - but I’d still want those options to show up.

I guess I’d expect the default to be “include all entrypoints from npm-installed modules”, with the option to flip that, and then either an “exclude” or an “include” override list respectively, that was a hash keyed by module name, and with a value that’s a list of patterns.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with determination of top-level dependencies or security ...
Dependabot's detection of how pip-compile files are linked is based on their filenames. It can match a <name>.in file to a <name>.txt file,...
Read more >
Makefile: how to declare a dependency for all targets that ...
I found another trick to do this, under the special case that all relevant files are built via their own particular ...
Read more >
NuGet Package Dependency Resolution - Microsoft Learn
This produces what's called a dependency graph that describes the relationships between packages at all levels.
Read more >
The paket.dependencies file - fsprojects on GitHub
lowest_matching: true means you get the lowest matching version of your direct dependencies. In contrast, a lowest_matching: false will get you the highest...
Read more >
Viewing and debugging dependencies - Gradle User Manual
Indicates which dependency to focus on. It can be a complete group:name , or part of it. If multiple dependencies match, they are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found