Skip to content

Commit 7883292

Browse files
committed
test(core): cover node_modules ancestor anchors and document prefix-pin deviation (anomalyco#44062)
1 parent dab35af commit 7883292

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎packages/core/src/npm-config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const load = (dir: string) =>
2121
// package.json/node_modules, and when an ancestor contains either
2222
// (commonly the user's home directory on Windows), `dir/.npmrc` is
2323
// silently ignored and installs fall back to the default registry.
24+
// This intentionally deviates from npm's nearest-anchor walk: callers
25+
// pass opencode-managed cache directories, not user project roots.
2426
argv: [process.execPath, process.execPath, `--prefix=${dir}`],
2527
execPath: process.execPath,
2628
platform: process.platform,

‎packages/core/test/npm-config.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ describe("NpmConfig.load", () => {
3131
expect(config.registry).toBe("https://project.example.test/")
3232
})
3333

34+
test("prefers the requested directory over ancestor node_modules anchors", async () => {
35+
await using tmp = await tmpdir()
36+
await mkdir(path.join(tmp.path, "node_modules"))
37+
await Bun.write(path.join(tmp.path, ".npmrc"), "registry=https://ancestor.example.test/\n")
38+
39+
const dir = path.join(tmp.path, "project")
40+
await mkdir(dir)
41+
await Bun.write(path.join(dir, ".npmrc"), "registry=https://project.example.test/\n")
42+
43+
const config = await Effect.runPromise(NpmConfig.load(dir))
44+
45+
expect(config.registry).toBe("https://project.example.test/")
46+
})
47+
3448
test("reads scoped registries from project .npmrc", async () => {
3549
await using tmp = await tmpdir()
3650
await Bun.write(path.join(tmp.path, ".npmrc"), "@acme:registry=https://npm.acme.test/\n")

0 commit comments

Comments
 (0)