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

Fix node 20 reexports #30

Merged
merged 6 commits into from
Jan 17, 2024
Merged

Conversation

luxaritas
Copy link
Contributor

Resolves #29

@tlhunter
Copy link
Member

tlhunter commented Aug 8, 2023

@luxaritas I see this is a draft... Is it ready to review?

@luxaritas
Copy link
Contributor Author

luxaritas commented Aug 8, 2023

Hey @tlhunter - main reason I left it as a draft is because I'm not confident that my approach here is "correct" - particularly how I'm handling path resolution seems hacky. That said I don't have any pending work on it, really just waiting for input, so I'll mark it as ready for review

@luxaritas luxaritas marked this pull request as ready for review August 8, 2023 18:12
Copy link
Contributor

@trentm trentm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for implementing this!

I found a problem with circular imports that re-export. The current implementation will go into an infinite loop. This patch includes a test case for that and a proposed fix:
https://gist.github.com/trentm/aa10ec6c34a473aa64a2e717b931742c

@luxaritas Would you be willing to add that to your branch?

return Array.from(new Set([
...addDefault(ex.exports),
...(await Promise.all(ex.reexports.map(re => getExports(
re.startsWith('./') || re.startsWith('../')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly this should consider Windows \\ dir separators, if on Windows? I'm not sure how important that is, and it could be done later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest the entire path handling here felt hacky when I wrote it, and I'm not sure if this is the best way to do it, though I didn't immediately come up with a better option. :)

As far as windows dir separators - I suppose? I think I initially thought cjs-module-lexer would normalize this, but in retrospect that's probably not correct. This also made me realize that importing . or .. would currently not be handled correctly either - I'll fix that up

@luxaritas
Copy link
Contributor Author

@trentm Thanks for the patch - looks reasonable to me so I've applied it. (I've marked you as a commit coauthor using git metadata from a recent GitHub commit of yours, let me know if that should be something else!)

@jsumners-nr
Copy link
Contributor

If I'm not mistaken, this is solved by #43.

@pichlermarc
Copy link

If I'm not mistaken, this is solved by #43.

Hmm, I I've tried the fix from #43 (released in 1.7.2) and I think it does not cover the case of CJS re-exports.

@jsumners-nr
Copy link
Contributor

If I'm not mistaken, this is solved by #43.

Hmm, I I've tried the fix from #43 (released in 1.7.2) and I think it does not cover the case of CJS re-exports.

Drat!

@trentm
Copy link
Contributor

trentm commented Dec 18, 2023

This is just speculation, based on commit bb038e9 of this PR handling a circular imports issue: I wonder if this PR would also have resolved #31
I haven't yet had a chance to understand what #43 is doing.

@bengl bengl merged commit 6856bd9 into DataDog:main Jan 17, 2024
45 checks passed
@trentm
Copy link
Contributor

trentm commented Jan 17, 2024

Woot. Thanks very much.

david-luna pushed a commit to elastic/apm-agent-nodejs that referenced this pull request Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getExports used for node v20, v18.19.0 doesn't handle reexports
7 participants