fix: resolve vendor dependencies using node module resolution#691
fix: resolve vendor dependencies using node module resolution#691
Conversation
|
Claude finished @rexxars's task in 2m 51s —— View job Review1. Fallback path in
const normalizedName = normalize(moduleName)
const idx = mainPath.lastIndexOf(normalizedName)
The fix is to anchor the search to a directory segment: const marker = `${path.sep}${normalizedName}${path.sep}`
const idx = mainPath.lastIndexOf(marker)
if (idx === -1) throw new Error(`Could not determine package directory for '${moduleName}'`)
return mainPath.slice(0, idx + marker.length - 1)In practice this fallback only fires when a package doesn't export The test at line 216–229 uses 2.
const isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory()
let isExistingDirectory = false
try {
isExistingDirectory = existsSync(resolved) && statSync(resolved).isDirectory()
} catch {
isExistingDirectory = false
} |
Coverage Delta
Comparing 3 changed files against main @ Overall Coverage
|
Description
buildVendorDependenciesresolved vendor entry points (react, react-dom, styled-components) using a naivenode_modules/relative path:This breaks in monorepos with hoisted dependencies (npm/yarn workspaces) where packages live in the root
node_modules/rather than the workspace's local one. The result is a Rollup error duringsanity deploy:The fix extracts a
getLocalPackageDir()function that usesimport-meta-resolveto find the actual filesystem location of a package - the same resolution strategygetLocalPackageVersionalready used for reading versions. This handles hoisted packages, pnpm symlinks, and other non-standardnode_moduleslayouts.Fixes #639 (comment)
What to review
getLocalPackageVersion.ts- the newgetLocalPackageDir()function and the refactoredgetLocalPackageVersion()that now delegates to it. The fallback path for packages that don't export./package.jsonis worth a look.buildVendorDependencies.ts- the one-line change fromresolve(...)topath.join(packageDir, relativeEntryPoint)readPackageJsonnow receives a string path instead of a URL) plus newgetLocalPackageDirtests.Testing
Updated existing
getLocalPackageVersiontests and added tests forgetLocalPackageDircovering:package.jsonresolution (happy path)node_modules/./package.jsonisn't in the package exports mapThe monorepo scenario itself is hard to test in an automated way without setting up a real workspace fixture - the test mocks
moduleResolveto return a hoisted path, which validates the logic but not the end-to-end resolution.