-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: don't create empty node_modules when no dependencies exist #24573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,60 @@ | ||||||||||||
| import { expect, test } from "bun:test"; | ||||||||||||
| import { bunEnv, bunExe, tempDir } from "harness"; | ||||||||||||
| import * as fs from "node:fs"; | ||||||||||||
|
|
||||||||||||
| test("bun install should not create node_modules when there are no dependencies - issue #5392", async () => { | ||||||||||||
| using dir = tempDir("issue-5392", { | ||||||||||||
| "package.json": JSON.stringify({ | ||||||||||||
| name: "bun-install-test", | ||||||||||||
| module: "index.ts", | ||||||||||||
| type: "module", | ||||||||||||
| devDependencies: {}, | ||||||||||||
| peerDependencies: {}, | ||||||||||||
| }), | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| await using proc = Bun.spawn({ | ||||||||||||
| cmd: [bunExe(), "install"], | ||||||||||||
| env: bunEnv, | ||||||||||||
| cwd: String(dir), | ||||||||||||
| stderr: "pipe", | ||||||||||||
| stdout: "pipe", | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Verify stderr and stdout or remove unused variables. The test captures Example enhancement: - const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
+ const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]);
+
+ // Optionally verify no errors in output
+ expect(stderr).not.toContain("error:");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| // node_modules should not exist | ||||||||||||
| const nodeModulesPath = `${dir}/node_modules`; | ||||||||||||
| const nodeModulesExists = fs.existsSync(nodeModulesPath); | ||||||||||||
|
|
||||||||||||
| expect(nodeModulesExists).toBe(false); | ||||||||||||
| expect(exitCode).toBe(0); | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| test("bun install should create node_modules when there are dependencies", async () => { | ||||||||||||
| using dir = tempDir("issue-5392-with-deps", { | ||||||||||||
| "package.json": JSON.stringify({ | ||||||||||||
| name: "bun-install-test-with-deps", | ||||||||||||
| dependencies: { | ||||||||||||
| "is-odd": "^3.0.1", | ||||||||||||
| }, | ||||||||||||
| }), | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| await using proc = Bun.spawn({ | ||||||||||||
| cmd: [bunExe(), "install"], | ||||||||||||
| env: bunEnv, | ||||||||||||
| cwd: String(dir), | ||||||||||||
| stderr: "pipe", | ||||||||||||
| stdout: "pipe", | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Verify stderr and stdout or remove unused variables. Same as test 1: the test captures 🤖 Prompt for AI Agents |
||||||||||||
|
|
||||||||||||
| // node_modules should exist | ||||||||||||
| const nodeModulesPath = `${dir}/node_modules`; | ||||||||||||
| const nodeModulesExists = fs.existsSync(nodeModulesPath); | ||||||||||||
|
|
||||||||||||
| expect(nodeModulesExists).toBe(true); | ||||||||||||
| expect(exitCode).toBe(0); | ||||||||||||
| }); | ||||||||||||
|
Comment on lines
+5
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider adding edge case tests for comprehensive coverage. The current tests cover the primary scenarios well. To enhance robustness, consider adding tests for:
Example additional test case: test("bun install should not create node_modules with only empty dependencies object", async () => {
using dir = tempDir("issue-5392-empty-deps", {
"package.json": JSON.stringify({
name: "test",
dependencies: {},
}),
});
await using proc = Bun.spawn({
cmd: [bunExe(), "install"],
env: bunEnv,
cwd: String(dir),
stderr: "pipe",
stdout: "pipe",
});
await proc.exited;
expect(fs.existsSync(`${dir}/node_modules`)).toBe(false);
});🤖 Prompt for AI Agents |
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Remove unnecessary empty dependency objects.
Explicitly specifying empty
peerDependenciesis unnecessary. Consider removing lines 11-12 to simplify the test case and focus on the core scenario.name: "bun-install-test", module: "index.ts", type: "module", devDependencies: {}, - peerDependencies: {}, }),📝 Committable suggestion
🤖 Prompt for AI Agents