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

imports-as-dependencies: package with exports instead of types #1114

Open
regseb opened this issue Jun 6, 2023 · 4 comments
Open

imports-as-dependencies: package with exports instead of types #1114

regseb opened this issue Jun 6, 2023 · 4 comments

Comments

@regseb
Copy link
Contributor

regseb commented Jun 6, 2023

Expected behavior

imports-as-dependencies supports types defined in the exports property.

Actual behavior

imports-as-dependencies reports: import points to package which is not found in dependencies. Because the rule only looks at the types and typings properties. importsAsDependencies.js#L85

Files

package.json

{
  "name": "testcase",
  "dependencies": {
    "eslint": "8.42.0",
    "eslint-plugin-jsdoc": "46.2.4",
    "playwright": "1.34.3"
  },
  "eslintConfig": {
    "plugins": [
      "jsdoc"
    ],
    "rules": {
      "jsdoc/imports-as-dependencies": "error"
    }
  }
}

index.js

/**
 * @type {import("playwright")}
 */
var playwright;

Environment

  • Node version: 18.16.0
  • ESLint version 8.42.0
  • eslint-plugin-jsdoc version: 46.2.4

Additional info

There's a similar problem with ESLint rules checking imports, as they only look at the main property:

@brettz9
Copy link
Collaborator

brettz9 commented Jun 7, 2023

I've filed lukeed/resolve.exports#30 so we can hopefully reuse that package's mechanism for navigating exports (which is not trivial).

@brettz9
Copy link
Collaborator

brettz9 commented Jul 4, 2024

@regseb : If you care to fork the project, I'd be happy to use it. Doesn't look like it is going to be maintained at this rate.

Mephisto5558 added a commit to Mephisto5558/ESLint-Config that referenced this issue Oct 13, 2024
@regseb
Copy link
Contributor Author

regseb commented Nov 27, 2024

I think the resolve-import library can also solve the problem.

import { resolveImport } from 'resolve-import'

// packages resolved according to their exports, main, etc.
// eg: URL(file:///path/node_modules/pkg/dist/mjs/index.js)
console.log(await resolveImport('pkg', '/path/to/y.js'))

But like resolve.exports, the default condition is always present.

Interface ResolveImportOpts

  • conditions: string[] The list of conditions to match on. 'default' is always accepted. Defaults to ['import', 'node'].

An issue would have to be opened?

@brettz9
Copy link
Collaborator

brettz9 commented Nov 27, 2024

Sounds like it, yes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants