diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/bun/index.ts | 26 | ||||
| -rw-r--r-- | packages/opencode/test/bun.test.ts | 53 | ||||
| -rw-r--r-- | packages/web/src/content/docs/docs/enterprise.mdx | 27 |
3 files changed, 92 insertions, 14 deletions
diff --git a/packages/opencode/src/bun/index.ts b/packages/opencode/src/bun/index.ts index 99fa4435e..eea467370 100644 --- a/packages/opencode/src/bun/index.ts +++ b/packages/opencode/src/bun/index.ts @@ -66,20 +66,18 @@ export namespace BunProc { return result }) if (parsed.dependencies[pkg] === version) return mod - await BunProc.run( - [ - "add", - "--force", - "--exact", - "--cwd", - Global.Path.cache, - "--registry=https://registry.npmjs.org", - pkg + "@" + version, - ], - { - cwd: Global.Path.cache, - }, - ).catch((e) => { + + // Build command arguments + const args = ["add", "--force", "--exact", "--cwd", Global.Path.cache, pkg + "@" + version] + + // Let Bun handle registry resolution: + // - If .npmrc files exist, Bun will use them automatically + // - If no .npmrc files exist, Bun will default to https://registry.npmjs.org + log.info("installing package using Bun's default registry resolution", { pkg, version }) + + await BunProc.run(args, { + cwd: Global.Path.cache, + }).catch((e) => { throw new InstallFailedError( { pkg, version }, { diff --git a/packages/opencode/test/bun.test.ts b/packages/opencode/test/bun.test.ts new file mode 100644 index 000000000..18f0db6bf --- /dev/null +++ b/packages/opencode/test/bun.test.ts @@ -0,0 +1,53 @@ +import { describe, expect, test } from "bun:test" +import fs from "fs/promises" +import path from "path" + +describe("BunProc registry configuration", () => { + test("should not contain hardcoded registry parameters", async () => { + // Read the bun/index.ts file + const bunIndexPath = path.join(__dirname, "../src/bun/index.ts") + const content = await fs.readFile(bunIndexPath, "utf-8") + + // Verify that no hardcoded registry is present + expect(content).not.toContain("--registry=") + expect(content).not.toContain("hasNpmRcConfig") + expect(content).not.toContain("NpmRc") + }) + + test("should use Bun's default registry resolution", async () => { + // Read the bun/index.ts file + const bunIndexPath = path.join(__dirname, "../src/bun/index.ts") + const content = await fs.readFile(bunIndexPath, "utf-8") + + // Verify that it uses Bun's default resolution + expect(content).toContain("Bun's default registry resolution") + expect(content).toContain("Bun will use them automatically") + expect(content).toContain("No need to pass --registry flag") + }) + + test("should have correct command structure without registry", async () => { + // Read the bun/index.ts file + const bunIndexPath = path.join(__dirname, "../src/bun/index.ts") + const content = await fs.readFile(bunIndexPath, "utf-8") + + // Extract the install function + const installFunctionMatch = content.match(/export async function install[\s\S]*?^ }/m) + expect(installFunctionMatch).toBeTruthy() + + if (installFunctionMatch) { + const installFunction = installFunctionMatch[0] + + // Verify expected arguments are present + expect(installFunction).toContain('"add"') + expect(installFunction).toContain('"--force"') + expect(installFunction).toContain('"--exact"') + expect(installFunction).toContain('"--cwd"') + expect(installFunction).toContain('Global.Path.cache') + expect(installFunction).toContain('pkg + "@" + version') + + // Verify no registry argument is added + expect(installFunction).not.toContain('"--registry"') + expect(installFunction).not.toContain('args.push("--registry') + } + }) +}) diff --git a/packages/web/src/content/docs/docs/enterprise.mdx b/packages/web/src/content/docs/docs/enterprise.mdx index a493dd8a4..0d1ac11b3 100644 --- a/packages/web/src/content/docs/docs/enterprise.mdx +++ b/packages/web/src/content/docs/docs/enterprise.mdx @@ -61,3 +61,30 @@ This can be switched to a centralized authentication system that your organizati The share feature can be self-hosted and the share pages can be made accessible only after the user has been authenticated. + +--- + +### Private NPM registries + +opencode supports private npm registries through Bun's native `.npmrc` file support. If your organization uses a private registry (such as JFrog Artifactory, Nexus, or similar), ensure developers are authenticated before running opencode. + +To set up authentication with your private registry: + +```bash +# Authenticate with your enterprise registry +npm login --registry=https://your-company.jfrog.io/api/npm/npm-virtual/ + +# This creates ~/.npmrc with authentication +# opencode will automatically use it through Bun's native support +``` + +Alternatively, you can manually configure a `.npmrc` file: + +```bash +# ~/.npmrc +registry=https://your-company.jfrog.io/api/npm/npm-virtual/ +//your-company.jfrog.io/api/npm/npm-virtual/:_authToken=${NPM_AUTH_TOKEN} +``` + +**Important**: Developers must be logged into the private registry before running opencode +to ensure packages can be installed from your enterprise registry. |
