-
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.
Implement
bun add --peer <pkg>
(#16150)
- Loading branch information
Showing
7 changed files
with
191 additions
and
4 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
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
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 |
---|---|---|
|
@@ -403,6 +403,165 @@ it("should add exact version with --exact", async () => { | |
); | ||
await access(join(package_dir, "bun.lockb")); | ||
}); | ||
it("should add to devDependencies with --dev", async () => { | ||
const urls: string[] = []; | ||
setHandler(dummyRegistry(urls)); | ||
await writeFile( | ||
join(package_dir, "package.json"), | ||
JSON.stringify({ | ||
name: "foo", | ||
version: "0.0.1", | ||
}), | ||
); | ||
const { stdout, stderr, exited } = spawn({ | ||
cmd: [bunExe(), "add", "--dev", "BaR"], | ||
cwd: package_dir, | ||
stdout: "pipe", | ||
stdin: "pipe", | ||
stderr: "pipe", | ||
env, | ||
}); | ||
const err = await new Response(stderr).text(); | ||
expect(err).not.toContain("error:"); | ||
expect(err).toContain("Saved lockfile"); | ||
const out = await new Response(stdout).text(); | ||
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ | ||
expect.stringContaining("bun add v1."), | ||
"", | ||
"installed [email protected]", | ||
"", | ||
"1 package installed", | ||
]); | ||
expect(await exited).toBe(0); | ||
expect(urls.sort()).toEqual([`${root_url}/BaR`, `${root_url}/BaR-0.0.2.tgz`]); | ||
expect(requested).toBe(2); | ||
expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "BaR"]); | ||
expect(await readdirSorted(join(package_dir, "node_modules", "BaR"))).toEqual(["package.json"]); | ||
expect(await file(join(package_dir, "node_modules", "BaR", "package.json")).json()).toEqual({ | ||
name: "bar", | ||
version: "0.0.2", | ||
}); | ||
expect(await file(join(package_dir, "package.json")).text()).toEqual( | ||
JSON.stringify( | ||
{ | ||
name: "foo", | ||
version: "0.0.1", | ||
devDependencies: { | ||
BaR: "^0.0.2", | ||
}, | ||
}, | ||
null, | ||
2, | ||
), | ||
); | ||
await access(join(package_dir, "bun.lockb")); | ||
}); | ||
it("should add to optionalDependencies with --optional", async () => { | ||
const urls: string[] = []; | ||
setHandler(dummyRegistry(urls)); | ||
await writeFile( | ||
join(package_dir, "package.json"), | ||
JSON.stringify({ | ||
name: "foo", | ||
version: "0.0.1", | ||
}), | ||
); | ||
const { stdout, stderr, exited } = spawn({ | ||
cmd: [bunExe(), "add", "--optional", "BaR"], | ||
cwd: package_dir, | ||
stdout: "pipe", | ||
stdin: "pipe", | ||
stderr: "pipe", | ||
env, | ||
}); | ||
const err = await new Response(stderr).text(); | ||
expect(err).not.toContain("error:"); | ||
expect(err).toContain("Saved lockfile"); | ||
const out = await new Response(stdout).text(); | ||
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ | ||
expect.stringContaining("bun add v1."), | ||
"", | ||
"installed [email protected]", | ||
"", | ||
"1 package installed", | ||
]); | ||
expect(await exited).toBe(0); | ||
expect(urls.sort()).toEqual([`${root_url}/BaR`, `${root_url}/BaR-0.0.2.tgz`]); | ||
expect(requested).toBe(2); | ||
expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "BaR"]); | ||
expect(await readdirSorted(join(package_dir, "node_modules", "BaR"))).toEqual(["package.json"]); | ||
expect(await file(join(package_dir, "node_modules", "BaR", "package.json")).json()).toEqual({ | ||
name: "bar", | ||
version: "0.0.2", | ||
}); | ||
expect(await file(join(package_dir, "package.json")).text()).toEqual( | ||
JSON.stringify( | ||
{ | ||
name: "foo", | ||
version: "0.0.1", | ||
optionalDependencies: { | ||
BaR: "^0.0.2", | ||
}, | ||
}, | ||
null, | ||
2, | ||
), | ||
); | ||
await access(join(package_dir, "bun.lockb")); | ||
}); | ||
it("should add to peerDependencies with --peer", async () => { | ||
const urls: string[] = []; | ||
setHandler(dummyRegistry(urls)); | ||
await writeFile( | ||
join(package_dir, "package.json"), | ||
JSON.stringify({ | ||
name: "foo", | ||
version: "0.0.1", | ||
}), | ||
); | ||
const { stdout, stderr, exited } = spawn({ | ||
cmd: [bunExe(), "add", "--peer", "BaR"], | ||
cwd: package_dir, | ||
stdout: "pipe", | ||
stdin: "pipe", | ||
stderr: "pipe", | ||
env, | ||
}); | ||
const err = await new Response(stderr).text(); | ||
expect(err).not.toContain("error:"); | ||
expect(err).toContain("Saved lockfile"); | ||
const out = await new Response(stdout).text(); | ||
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ | ||
expect.stringContaining("bun add v1."), | ||
"", | ||
"installed [email protected]", | ||
"", | ||
"1 package installed", | ||
]); | ||
expect(await exited).toBe(0); | ||
expect(urls.sort()).toEqual([`${root_url}/BaR`, `${root_url}/BaR-0.0.2.tgz`]); | ||
expect(requested).toBe(2); | ||
expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "BaR"]); | ||
expect(await readdirSorted(join(package_dir, "node_modules", "BaR"))).toEqual(["package.json"]); | ||
expect(await file(join(package_dir, "node_modules", "BaR", "package.json")).json()).toEqual({ | ||
name: "bar", | ||
version: "0.0.2", | ||
}); | ||
expect(await file(join(package_dir, "package.json")).text()).toEqual( | ||
JSON.stringify( | ||
{ | ||
name: "foo", | ||
version: "0.0.1", | ||
peerDependencies: { | ||
BaR: "^0.0.2", | ||
}, | ||
}, | ||
null, | ||
2, | ||
), | ||
); | ||
await access(join(package_dir, "bun.lockb")); | ||
}); | ||
|
||
it("should add exact version with install.exact", async () => { | ||
const urls: string[] = []; | ||
|