mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
* [install] allow parallel execution of `postinstall` scripts - fixes spurious exit code 42 from `spawn()` * postinstall to a pipe * feat(install): include top 500 packages as defaults for postinstall * windows newline handling* *i did not test it * stuff * cool * a * fix merge * set `has_trusted_dependencies` * fix a bunch of tests * fix merge * remove `PackageManager` * remove commented code * change to function * Update lockfile.zig * run scripts if added to `trustedDependencies` after install * packages without `resolved` properties * node-gyp scripts * node-gyp script in the root * another test * git deps run prepare scripts * fix merge * run lifecycle scripts during installation * Update lockfile.zig * always increment * 🏗️ * update tests * tickWIthoutIdle * const uws * loop forwards through trees * single buffer bitset list * tag.isGit * windows path separators * `bun.sys.read` and enable/disable buffering * fix test and waiter thread * waiter thread and tests * Update bun-install-registry.test.ts * workspace exclude `preprepare` and `postprepare` * Create esbuild.test.ts * make sure length is the same * remove deferred binlinks, add estrella test * test with another version * address some comments * remove .verdaccio-db.json * ooops * fix build * use `pid` to wait * dont register pid_poll when using waiter thread * stress test * free * fix failing tests * fix linux crash, snapshot stress test * oops * concurrent scripts * activate as soon as possible * test * delete stress test packages * remove unused packages * comment stress test and maybe fix segfault * delete snapshot * fix assertion * use cpu_count * 2 for default concurrent scripts * gear emoji * add --concurrent-scripts to docs * more docs --------- Co-authored-by: alexlamsl <alexlamsl@gmail.com> Co-authored-by: dave caruso <me@paperdave.net> Co-authored-by: Dylan Conway <33744874+MilesWright7@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
190 lines
5.1 KiB
TypeScript
190 lines
5.1 KiB
TypeScript
import { mkdtempSync } from "fs";
|
|
import { join } from "path";
|
|
import { tmpdir } from "os";
|
|
import { readFileSync, writeFileSync } from "fs";
|
|
import { bunEnv, bunExe } from "harness";
|
|
|
|
function install(cwd: string, args: string[]) {
|
|
const exec = Bun.spawnSync({
|
|
cmd: [bunExe(), ...args],
|
|
cwd,
|
|
stdout: "ignore",
|
|
stdin: "ignore",
|
|
stderr: "ignore",
|
|
env: bunEnv,
|
|
});
|
|
if (exec.exitCode !== 0) {
|
|
throw new Error(`bun install exited with code ${exec.exitCode}`);
|
|
}
|
|
return exec;
|
|
}
|
|
|
|
function installExpectFail(cwd: string, args: string[]) {
|
|
const exec = Bun.spawnSync({
|
|
cmd: [bunExe(), ...args],
|
|
cwd,
|
|
stdout: "ignore",
|
|
stdin: "ignore",
|
|
stderr: "ignore",
|
|
env: bunEnv,
|
|
});
|
|
if (exec.exitCode === 0) {
|
|
throw new Error(`bun install exited with code ${exec.exitCode}, (expected failure)`);
|
|
}
|
|
return exec;
|
|
}
|
|
|
|
function versionOf(cwd: string, path: string) {
|
|
const data = readFileSync(join(cwd, path));
|
|
const json = JSON.parse(data.toString());
|
|
return json.version;
|
|
}
|
|
|
|
function ensureLockfileDoesntChangeOnBunI(cwd: string) {
|
|
install(cwd, ["install"]);
|
|
const lockb_hash = new Bun.CryptoHasher("sha256").update(readFileSync(join(cwd, "bun.lockb"))).digest();
|
|
install(cwd, ["install", "--frozen-lockfile"]);
|
|
install(cwd, ["install", "--force"]);
|
|
const lockb_hash2 = new Bun.CryptoHasher("sha256").update(readFileSync(join(cwd, "bun.lockb"))).digest();
|
|
expect(lockb_hash).toEqual(lockb_hash2);
|
|
}
|
|
|
|
test("overrides affect your own packages", async () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "bun-pm-test"));
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
dependencies: {},
|
|
overrides: {
|
|
lodash: "4.0.0",
|
|
},
|
|
}),
|
|
);
|
|
install(tmp, ["install", "lodash"]);
|
|
expect(versionOf(tmp, "node_modules/lodash/package.json")).toBe("4.0.0");
|
|
|
|
ensureLockfileDoesntChangeOnBunI(tmp);
|
|
});
|
|
|
|
test("overrides affects all dependencies", async () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "bun-pm-test"));
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
dependencies: {},
|
|
overrides: {
|
|
bytes: "1.0.0",
|
|
},
|
|
}),
|
|
);
|
|
install(tmp, ["install", "express@4.18.2"]);
|
|
expect(versionOf(tmp, "node_modules/bytes/package.json")).toBe("1.0.0");
|
|
|
|
ensureLockfileDoesntChangeOnBunI(tmp);
|
|
});
|
|
|
|
test("overrides being set later affects all dependencies", async () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "bun-pm-test"));
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
dependencies: {},
|
|
}),
|
|
);
|
|
install(tmp, ["install", "express@4.18.2"]);
|
|
expect(versionOf(tmp, "node_modules/bytes/package.json")).not.toBe("1.0.0");
|
|
|
|
ensureLockfileDoesntChangeOnBunI(tmp);
|
|
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
...JSON.parse(readFileSync(join(tmp, "package.json")).toString()),
|
|
overrides: {
|
|
bytes: "1.0.0",
|
|
},
|
|
}),
|
|
);
|
|
install(tmp, ["install"]);
|
|
expect(versionOf(tmp, "node_modules/bytes/package.json")).toBe("1.0.0");
|
|
|
|
ensureLockfileDoesntChangeOnBunI(tmp);
|
|
});
|
|
|
|
test("overrides to npm specifier", async () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "bun-pm-test"));
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
dependencies: {},
|
|
overrides: {
|
|
bytes: "npm:lodash@4.0.0",
|
|
},
|
|
}),
|
|
);
|
|
install(tmp, ["install", "express@4.18.2"]);
|
|
|
|
// BUG: the npm specifier is hoisted https://github.com/oven-sh/bun/issues/6433
|
|
// const bytes = JSON.parse(readFileSync(join(tmp, "node_modules/bytes/package.json"), "utf-8"));
|
|
const bytes = JSON.parse(
|
|
readFileSync(join(tmp, "node_modules/body-parser/node_modules/bytes/package.json"), "utf-8"),
|
|
);
|
|
|
|
expect(bytes.name).toBe("lodash");
|
|
expect(bytes.version).toBe("4.0.0");
|
|
|
|
ensureLockfileDoesntChangeOnBunI(tmp);
|
|
});
|
|
|
|
test("changing overrides makes the lockfile changed, prevent frozen install", async () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "bun-pm-test"));
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
dependencies: {},
|
|
overrides: {
|
|
bytes: "1.0.0",
|
|
},
|
|
}),
|
|
);
|
|
install(tmp, ["install", "express@4.18.2"]);
|
|
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
...JSON.parse(readFileSync(join(tmp, "package.json")).toString()),
|
|
overrides: {
|
|
bytes: "1.0.1",
|
|
},
|
|
}),
|
|
);
|
|
|
|
installExpectFail(tmp, ["install", "--frozen-lockfile"]);
|
|
});
|
|
|
|
test("overrides reset when removed", async () => {
|
|
const tmp = mkdtempSync(join(tmpdir(), "bun-pm-test"));
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
overrides: {
|
|
bytes: "1.0.0",
|
|
},
|
|
}),
|
|
);
|
|
install(tmp, ["install", "express@4.18.2"]);
|
|
expect(versionOf(tmp, "node_modules/bytes/package.json")).toBe("1.0.0");
|
|
|
|
writeFileSync(
|
|
join(tmp, "package.json"),
|
|
JSON.stringify({
|
|
...JSON.parse(readFileSync(join(tmp, "package.json")).toString()),
|
|
overrides: undefined,
|
|
}),
|
|
);
|
|
install(tmp, ["install"]);
|
|
expect(versionOf(tmp, "node_modules/bytes/package.json")).not.toBe("1.0.0");
|
|
|
|
ensureLockfileDoesntChangeOnBunI(tmp);
|
|
});
|