diff options
author | 2023-08-31 03:35:28 +0300 | |
---|---|---|
committer | 2023-08-30 17:35:28 -0700 | |
commit | 037463fc48a96cfdacb647ba44e021abd5e4769e (patch) | |
tree | 2c8f39f90e7ecb9c013981f26a494033a24b27c0 /test | |
parent | 04215e2f3a8c11d9e2b5f336eee40e6f7ebf11c9 (diff) | |
download | bun-037463fc48a96cfdacb647ba44e021abd5e4769e.tar.gz bun-037463fc48a96cfdacb647ba44e021abd5e4769e.tar.zst bun-037463fc48a96cfdacb647ba44e021abd5e4769e.zip |
[install] fix stale root life-cycle script in lockfile (#4411)
fixes #4319
Diffstat (limited to 'test')
-rw-r--r-- | test/cli/install/bun-install.test.ts | 170 |
1 files changed, 169 insertions, 1 deletions
diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index a530cac38..a98c22e3b 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -857,7 +857,141 @@ it("should handle life-cycle scripts during re-installation", async () => { await access(join(package_dir, "bun.lockb")); }); -it("should use updated life-cycle scripts during re-installation", async () => { +it("should use updated life-cycle scripts in root during re-installation", async () => { + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "Foo", + scripts: { + install: [bunExe(), "foo.js"].join(" "), + }, + workspaces: ["bar"], + }), + ); + await writeFile(join(package_dir, "foo.js"), 'console.log("[scripts:run] Foo");'); + await mkdir(join(package_dir, "bar")); + await writeFile( + join(package_dir, "bar", "package.json"), + JSON.stringify({ + name: "Bar", + scripts: { + preinstall: [bunExe(), "bar.js"].join(" "), + }, + }), + ); + await writeFile(join(package_dir, "bar", "bar.js"), 'console.log("[scripts:run] Bar");'); + const { + stdout: stdout1, + stderr: stderr1, + exited: exited1, + } = spawn({ + cmd: [bunExe(), "install"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr1).toBeDefined(); + const err1 = await new Response(stderr1).text(); + expect(err1).not.toContain("error:"); + expect(err1).toContain("Saved lockfile"); + expect(stdout1).toBeDefined(); + const out1 = await new Response(stdout1).text(); + expect(out1.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + "[scripts:run] Bar", + " + Bar@workspace:bar", + "[scripts:run] Foo", + "", + " 1 packages installed", + ]); + expect(await exited1).toBe(0); + expect(requested).toBe(0); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "Bar"]); + expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar")); + await access(join(package_dir, "bun.lockb")); + // Perform `bun install` with outdated lockfile + await rm(join(package_dir, "node_modules"), { force: true, recursive: true }); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "Foo", + scripts: { + install: [bunExe(), "moo.js"].join(" "), + postinstall: [bunExe(), "foo.js"].join(" "), + }, + workspaces: ["bar"], + }), + ); + await writeFile(join(package_dir, "moo.js"), 'console.log("[scripts:run] Moo");'); + const { + stdout: stdout2, + stderr: stderr2, + exited: exited2, + } = spawn({ + cmd: [bunExe(), "install"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr2).toBeDefined(); + const err2 = await new Response(stderr2).text(); + expect(err2).not.toContain("error:"); + expect(err2).toContain("Saved lockfile"); + expect(stdout2).toBeDefined(); + const out2 = await new Response(stdout2).text(); + expect(out2.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + "[scripts:run] Bar", + " + Bar@workspace:bar", + "[scripts:run] Moo", + "[scripts:run] Foo", + "", + " 1 packages installed", + ]); + expect(await exited2).toBe(0); + expect(requested).toBe(0); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "Bar"]); + expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar")); + await access(join(package_dir, "bun.lockb")); + // Perform `bun install --production` with lockfile from before + const bun_lockb = await file(join(package_dir, "bun.lockb")).arrayBuffer(); + await rm(join(package_dir, "node_modules"), { force: true, recursive: true }); + const { + stdout: stdout3, + stderr: stderr3, + exited: exited3, + } = spawn({ + cmd: [bunExe(), "install", "--production"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr3).toBeDefined(); + const err3 = await new Response(stderr3).text(); + expect(err3).not.toContain("error:"); + expect(err3).not.toContain("Saved lockfile"); + expect(stdout3).toBeDefined(); + const out3 = await new Response(stdout3).text(); + expect(out3.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + "[scripts:run] Bar", + " + Bar@workspace:bar", + "[scripts:run] Moo", + "[scripts:run] Foo", + "", + " 1 packages installed", + ]); + expect(await exited3).toBe(0); + expect(requested).toBe(0); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual(["Bar"]); + expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar")); + expect(await file(join(package_dir, "bun.lockb")).arrayBuffer()).toEqual(bun_lockb); +}); + +it("should use updated life-cycle scripts in dependency during re-installation", async () => { await writeFile( join(package_dir, "package.json"), JSON.stringify({ @@ -954,6 +1088,40 @@ it("should use updated life-cycle scripts during re-installation", async () => { expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "Bar"]); expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar")); await access(join(package_dir, "bun.lockb")); + // Perform `bun install --production` with lockfile from before + const bun_lockb = await file(join(package_dir, "bun.lockb")).arrayBuffer(); + await rm(join(package_dir, "node_modules"), { force: true, recursive: true }); + const { + stdout: stdout3, + stderr: stderr3, + exited: exited3, + } = spawn({ + cmd: [bunExe(), "install", "--production"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr3).toBeDefined(); + const err3 = await new Response(stderr3).text(); + expect(err3).not.toContain("error:"); + expect(err3).not.toContain("Saved lockfile"); + expect(stdout3).toBeDefined(); + const out3 = await new Response(stdout3).text(); + expect(out3.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + "[scripts:run] Baz", + " + Bar@workspace:bar", + "[scripts:run] Foo", + "[scripts:run] Bar", + "", + " 1 packages installed", + ]); + expect(await exited3).toBe(0); + expect(requested).toBe(0); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual(["Bar"]); + expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar")); + expect(await file(join(package_dir, "bun.lockb")).arrayBuffer()).toEqual(bun_lockb); }); it("should ignore workspaces within workspaces", async () => { |