-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(install): use ssh keys for private git repos (#11917)
Co-authored-by: Dylan Conway <[email protected]>
- Loading branch information
1 parent
8c548d2
commit 087b83c
Showing
6 changed files
with
167 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,12 +117,16 @@ Bun reads this field and will run lifecycle scripts for `my-trusted-package`. | |
|
||
## Git dependencies | ||
|
||
To add a dependency from a git repository: | ||
To add a dependency from a public or private git repository: | ||
|
||
```bash | ||
$ bun add [email protected]:moment/moment.git | ||
``` | ||
|
||
{% callout %} | ||
**Note** — To install private repositories, your system needs the appropriate SSH credentials to access the repository. | ||
{% /callout %} | ||
|
||
Bun supports a variety of protocols, including [`github`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#github-urls), [`git`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#git-urls-as-dependencies), `git+ssh`, `git+https`, and many more. | ||
|
||
```json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4519,6 +4519,42 @@ it("should fail on invalid Git URL", async () => { | |
} | ||
}); | ||
|
||
it("should fail on ssh Git URL if invalid credentials", async () => { | ||
const urls: string[] = []; | ||
setHandler(dummyRegistry(urls)); | ||
await writeFile( | ||
join(package_dir, "package.json"), | ||
JSON.stringify({ | ||
name: "Foo", | ||
version: "0.0.1", | ||
dependencies: { | ||
"private-install": "git+ssh://[email protected]/kaizenmedia/private-install-test.git", | ||
}, | ||
}), | ||
); | ||
const { stdout, stderr, exited } = spawn({ | ||
cmd: [bunExe(), "install"], | ||
cwd: package_dir, | ||
stdout: "pipe", | ||
stdin: "ignore", | ||
stderr: "pipe", | ||
env: { ...env, "GIT_ASKPASS": "echo" }, | ||
}); | ||
const err = await new Response(stderr).text(); | ||
expect(err.split(/\r?\n/)).toContain('error: "git clone" for "private-install" failed'); | ||
const out = await new Response(stdout).text(); | ||
expect(out).toBeEmpty(); | ||
expect(await exited).toBe(1); | ||
expect(urls.sort()).toBeEmpty(); | ||
expect(requested).toBe(0); | ||
try { | ||
await access(join(package_dir, "bun.lockb")); | ||
expect(() => {}).toThrow(); | ||
} catch (err: any) { | ||
expect(err.code).toBe("ENOENT"); | ||
} | ||
}); | ||
|
||
it("should fail on Git URL with invalid committish", async () => { | ||
const urls: string[] = []; | ||
setHandler(dummyRegistry(urls)); | ||
|