Skip to content

Conversation

@imrishabh18
Copy link
Member

No description provided.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines +33 to +46
// 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]

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@imrishabh18 imrishabh18 requested a review from seveibar November 13, 2025 14:23
Copy link
Contributor

@seveibar seveibar left a 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?

@imrishabh18 imrishabh18 merged commit 68338b2 into main Nov 14, 2025
11 checks passed
@imrishabh18 imrishabh18 deleted the add-nodeModulesResolver branch November 14, 2025 08:03
@tscircuitbot
Copy link
Contributor


Thank you for your contribution! 🎉

PR Rating: ⭐⭐
Impact: Minor

Track your contributions and see the leaderboard at: tscircuit Contribution Tracker


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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants