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

unable to resolve packages with a nested package.json #1349

Closed
thescientist13 opened this issue Dec 16, 2024 · 0 comments · Fixed by #1356
Closed

unable to resolve packages with a nested package.json #1349

thescientist13 opened this issue Dec 16, 2024 · 0 comments · Fixed by #1356
Assignees
Labels
alpha.2 bug Something isn't working CLI v0.31.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Dec 16, 2024

Type of Change

Bug

Summary

Found a case out in the wild where a package, in this case luxon has a nested package.json in its src/ folder, thus when we recursively walk up from the location returned from import.meta.resolve, we hit this false positive and thus exit the search too early.
https://github.com/thescientist13/import-meta-resolve-luxon?tab=readme-ov-file#demo

  • What we want - file:///Users/path/to/.../node_modules/luxon/
  • What we got - file:///Users/path/to/.../node_modules/luxon/src/

And so in development and building up the import map, we'll get this diagnostic from Greenwood
thescientist13/HP_Stuff#1 (comment)

WARNING: No supported entry point detected for => `luxon`
Learn more about these warnings at => https://greenwoodjs.dev/docs/introduction/web-standards/#import-maps

Details

So seems we need to add some additional heuristics which might now require actually having to read the entire contents of package.json though :/

for (const segment of segments.slice(1)) {
  if (fs.existsSync(new URL('./package.json', root))) {
    const resolvedPackageJson = (await import(new URL('./package.json', root), { with: { type: 'json' } })).default;
    const { name, version, main, module, exports } = resolvedPackageJson;

    // name and version are required fields in a package.json_
    // https://docs.npmjs.com/cli/v10/configuring-npm/package-json
    if ((name && version) && (main || module || exports)) {
      break;
    }
  }

  root = root.replace(`${segment}/`, '');
}
@thescientist13 thescientist13 added bug Something isn't working CLI labels Dec 16, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone Dec 16, 2024
@thescientist13 thescientist13 self-assigned this Dec 16, 2024
@thescientist13 thescientist13 changed the title unable to resolve packages with a nested _package.json_ unable to resolve packages with a nested package.json Dec 16, 2024
@thescientist13 thescientist13 moved this from 🔖 Ready to 🏗 In progress in [Greenwood] Phase 10 - Ecosystem Compat Dec 21, 2024
@thescientist13 thescientist13 moved this from 🏗 In progress to 👀 In review in [Greenwood] Phase 10 - Ecosystem Compat Dec 21, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in [Greenwood] Phase 10 - Ecosystem Compat Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.2 bug Something isn't working CLI v0.31.0
Projects
1 participant