fix: Properly handle reexports when detecting CJS exports#69
Merged
Conversation
FrederikBolding
commented
Dec 1, 2024
FrederikBolding
commented
Dec 1, 2024
| packageSpecifier, | ||
| parentUrl, | ||
| system, | ||
| // We assume that if the packageSpecifier is relative, we are traversing a specific file looking for CJS imports |
Contributor
Author
There was a problem hiding this comment.
We aren't interested in TypeScript files since those aren't marked as commonjs and won't be parsable
Mrtenz
reviewed
Dec 1, 2024
packages/cli/src/module-resolver.ts
Outdated
| const resolvedReexports = reexports.flatMap((reexport: string) => | ||
| getCommonJsExports(reexport, system, path), | ||
| ); | ||
| return [...new Set([...exports, ...resolvedReexports])]; |
Contributor
There was a problem hiding this comment.
Is it necessary to turn this back into an array? Can we just return a Set?
Contributor
Author
There was a problem hiding this comment.
Definitely, I was just keeping the existing API, but we can change the return type
Contributor
There was a problem hiding this comment.
Fine to change it since it's an internal API.
Mrtenz
reviewed
Dec 1, 2024
Mrtenz
reviewed
Dec 1, 2024
FrederikBolding
commented
Dec 1, 2024
packages/cli/src/module-resolver.ts
Outdated
| return [...exports, ...reexports]; | ||
|
|
||
| // Re-exports are paths to exports that must be resolved themselves | ||
| const resolvedReexports = reexports.flatMap((reexport: string) => |
Contributor
Author
There was a problem hiding this comment.
Should we account for export cycles here? Not sure if those realistically will occur
Mrtenz
approved these changes
Dec 1, 2024
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug where reexports were not properly traversed and therefore not included in the return value from
getImports. This would cause issues with importing from packages that use the__exportStarpattern. For these packagescjs-module-lexerreturns relative paths to the exports that must be traversed recursively to fully uncover the exports (at least this is what I gathered from https://github.com/nodejs/node/blob/3fb2ea8689250a3d39d9c66afd7301c7caa644c2/lib/internal/modules/esm/translators.js#L313-L346).Sanity check welcome!