Repository navigation
Fix saved package export artifact imports - #307
Conversation
📝 WalkthroughWalkthroughThe module graph now prefers composing imports from pre-published module artifacts for saved packages with Changes
Sequence DiagramsequenceDiagram
participant ModuleGraph as Module Graph
participant ArtifactLoader as Artifact Loader
participant State as State Manager
participant Resolver as Package Resolver
ModuleGraph->>ModuleGraph: detect saved_package.published_commit?
alt published_commit present
ModuleGraph->>ArtifactLoader: loadPublishedBundleArtifactByIdentity(identity)
activate ArtifactLoader
ArtifactLoader-->>ModuleGraph: artifact (or null)
deactivate ArtifactLoader
alt artifact found
ModuleGraph->>State: materialize artifact.modules into\n'__published_bundle__/<export>'
ModuleGraph->>State: record/merge artifact dependencies\n(include packageName via composite key)
ModuleGraph->>ModuleGraph: set proxy target = artifact.mainModule
else artifact null
ModuleGraph->>Resolver: assertPublishedSourceCanRebuildWithoutDeps()
Resolver-->>ModuleGraph: assertion result
alt assertion passes
ModuleGraph->>ModuleGraph: resolve export via\nresolvePackageExportPath + loaded.prefix
else assertion fails
ModuleGraph-->>ModuleGraph: reject with error
end
end
else not published_commit
ModuleGraph->>ModuleGraph: standard resolution path
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🔎 Preview deployed: https://kody-pr-307.kentcdodds.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/worker/src/package-runtime/module-graph.node.test.ts`:
- Around line 28-31: Replace the inline typeof import(...) generic with a named
type import: add a type-only import statement such as "import type * as
PublishedBundleArtifacts from './published-bundle-artifacts.ts'" near the top of
the test and then change the vi.importActual generic to use "typeof
PublishedBundleArtifacts" instead of "typeof
import('./published-bundle-artifacts.ts')"; update the vi.mock block that calls
vi.importActual to reference that named type so the mock behavior is unchanged
and the consistent-type-imports lint rule is satisfied.
In `@packages/worker/src/package-runtime/module-graph.ts`:
- Around line 106-110: The rememberDependency function currently blindly
overwrites state.dependencies with the incoming BundleArtifactDependency, which
can drop an existing packageName; modify rememberDependency to first lookup
state.dependencies.get(createDependencyKey(dependency)) and if an existing
dependency has a packageName but the incoming dependency.packageName is
undefined, copy or merge the existing.packageName into the incoming record (or
keep the existing object) before calling state.dependencies.set so package
identity recorded by ensurePackageLoaded is preserved; ensure you reference the
existing entry from state.dependencies and only override fields that are
intentionally provided by the new dependency.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 752a0bd3-a1af-40a1-9c91-6257b16c2ba3
📒 Files selected for processing (3)
packages/worker/src/package-runtime/module-graph.node.test.tspackages/worker/src/package-runtime/module-graph.tspackages/worker/src/package-runtime/module-graph.workers.test.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 372c2a5. Configure here.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/worker/src/package-runtime/module-graph.ts`:
- Around line 338-352: The current use of sanitizeSpecifier(exportName) to build
artifactPrefix is lossy and can collide (e.g., "./foo.bar" vs "./foo-bar");
change the key used in artifactPrefix to a collision-free representation by
computing a stable encoded or hashed form of the normalized export key (e.g.,
SHA256/base64 or hex) instead of sanitizeSpecifier(exportName). Update the logic
that builds artifactPrefix (where joinPath(input.loaded.prefix,
'.__published_bundle__', sanitizeSpecifier(exportName)) is used) to replace
sanitizeSpecifier(exportName) with the new hash/encoding function applied to
exportName (or its normalized form), ensuring materializeArtifactModuleSource
and the returned main module path still use the new artifactPrefix consistently
so multiple distinct exports can be materialized without overwriting each other.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f383cc3-9966-4e74-8404-64d9312ccc38
📒 Files selected for processing (3)
packages/worker/src/package-registry/manifest.tspackages/worker/src/package-runtime/module-graph.node.test.tspackages/worker/src/package-runtime/module-graph.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/worker/src/package-runtime/module-graph.node.test.ts

Summary
kody:@scope/package/exportimports prefer published module bundle artifacts during execute/runtime compositionpackageNamewhen dependency records are replayed, and switching the test mock to a top-level type importTesting
npx vitest run --config vitest.node.config.ts packages/worker/src/repo/checks.node.test.ts packages/worker/src/package-runtime/module-graph.node.test.ts packages/worker/src/package-runtime/published-bundle-artifacts.node.test.tsnpx vitest run --config vitest.workers.config.ts packages/worker/src/package-runtime/module-graph.workers.test.tsgit push -u origin cursor/kody-saved-package-dependencies-75c5(pre-push hook rannpm run test && npm run test:e2e:runsuccessfully)Summary by CodeRabbit
New Features
Tests