-
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): check cached
package.json
s (#14899)
- Loading branch information
1 parent
d7710c6
commit 489890d
Showing
4 changed files
with
101 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3056,6 +3056,69 @@ describe("binaries", () => { | |
}); | ||
}); | ||
|
||
test("it should invalid cached package if package.json is missing", async () => { | ||
await Promise.all([ | ||
write( | ||
packageJson, | ||
JSON.stringify({ | ||
name: "foo", | ||
dependencies: { | ||
"no-deps": "2.0.0", | ||
}, | ||
}), | ||
), | ||
]); | ||
|
||
let { out } = await runBunInstall(env, packageDir); | ||
expect(out).toContain("+ [email protected]"); | ||
|
||
// node_modules and cache should be populated | ||
expect( | ||
await Promise.all([ | ||
readdirSorted(join(packageDir, "node_modules", "no-deps")), | ||
readdirSorted(join(packageDir, ".bun-cache", "[email protected]@@localhost@@@1")), | ||
]), | ||
).toEqual([ | ||
["index.js", "package.json"], | ||
["index.js", "package.json"], | ||
]); | ||
|
||
// with node_modules package.json deleted, the package should be reinstalled | ||
await rm(join(packageDir, "node_modules", "no-deps", "package.json")); | ||
({ out } = await runBunInstall(env, packageDir, { savesLockfile: false })); | ||
expect(out).toContain("+ [email protected]"); | ||
|
||
// another install is a no-op | ||
({ out } = await runBunInstall(env, packageDir, { savesLockfile: false })); | ||
expect(out).not.toContain("+ [email protected]"); | ||
|
||
// with cache package.json deleted, install is a no-op and cache is untouched | ||
await rm(join(packageDir, ".bun-cache", "[email protected]@@localhost@@@1", "package.json")); | ||
({ out } = await runBunInstall(env, packageDir, { savesLockfile: false })); | ||
expect(out).not.toContain("+ [email protected]"); | ||
expect( | ||
await Promise.all([ | ||
readdirSorted(join(packageDir, "node_modules", "no-deps")), | ||
readdirSorted(join(packageDir, ".bun-cache", "[email protected]@@localhost@@@1")), | ||
]), | ||
).toEqual([["index.js", "package.json"], ["index.js"]]); | ||
|
||
// now with node_modules package.json deleted, the package AND the cache should | ||
// be repopulated | ||
await rm(join(packageDir, "node_modules", "no-deps", "package.json")); | ||
({ out } = await runBunInstall(env, packageDir, { savesLockfile: false })); | ||
expect(out).toContain("+ [email protected]"); | ||
expect( | ||
await Promise.all([ | ||
readdirSorted(join(packageDir, "node_modules", "no-deps")), | ||
readdirSorted(join(packageDir, ".bun-cache", "[email protected]@@localhost@@@1")), | ||
]), | ||
).toEqual([ | ||
["index.js", "package.json"], | ||
["index.js", "package.json"], | ||
]); | ||
}); | ||
|
||
test("it should install with missing bun.lockb, node_modules, and/or cache", async () => { | ||
// first clean install | ||
await writeFile( | ||
|