-
Notifications
You must be signed in to change notification settings - Fork 25
feat: support nodeModulesResolver
#1516
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Add the resolved content to fsMap with a synthetic path | ||
| // Add .ts extension to ensure it's treated as a module file | ||
| const syntheticPath = `node_modules/${importName}.ts` | ||
| ctx.fsMap[syntheticPath] = fileContent | ||
|
|
||
| // Import the file using the normal flow | ||
| await importLocalFile(syntheticPath, ctx, depth) | ||
|
|
||
| // Map the import name to the resolved module | ||
| preSuppliedImports[importName] = preSuppliedImports[syntheticPath] | ||
|
|
||
| // Also map without node_modules prefix | ||
| const unprefixedPath = syntheticPath.replace(/^node_modules\//, "") | ||
| preSuppliedImports[unprefixedPath] = preSuppliedImports[syntheticPath] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve package directory when injecting resolver output
When the custom nodeModulesResolver returns code for a bare specifier, the module is injected into the virtual FS as node_modules/${importName}.ts (lines 33‑46). That flattens the whole package into a single file at the root of node_modules. importLocalFile resolves relative imports based on dirname(fsPath), so any ./foo inside the fetched module now resolves to node_modules/foo instead of node_modules/<package>/foo. As a result, any real package source that contains relative imports (the common case for CDN bundles) will immediately fail to resolve its own dependencies when loaded via the resolver. The synthetic file needs to live inside a package directory (e.g. node_modules/<spec>/index.ts) so that relative paths match Node semantics.
Useful? React with 👍 / 👎.
seveibar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this work with multi-file node modules?
|
Thank you for your contribution! 🎉 PR Rating: ⭐⭐ Track your contributions and see the leaderboard at: tscircuit Contribution Tracker |
No description provided.