mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58: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>
120 lines
4.3 KiB
TypeScript
120 lines
4.3 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import { test, expect, describe, beforeAll } from "bun:test";
|
|
import { bunEnv, bunExe } from "harness";
|
|
import { tmpdir } from "os";
|
|
import { join } from "path";
|
|
|
|
let cwd = join(tmpdir(), "complex-workspace-test" + Math.random().toString(36).slice(2, 8));
|
|
|
|
function validate(packageName: string, version: string, realPackageName?: string) {
|
|
test(`${packageName} is ${realPackageName ? `${realPackageName}@${version}` : version}`, () => {
|
|
if (!cwd) throw new Error("install failed");
|
|
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, packageName, "package.json"), "utf8"));
|
|
expect(pkg.version).toBe(version);
|
|
if (realPackageName) {
|
|
expect(pkg.name).toBe(realPackageName);
|
|
}
|
|
});
|
|
}
|
|
|
|
function mustExist(filePath: string) {
|
|
test(`${filePath} exists`, () => {
|
|
if (!cwd) throw new Error("install failed");
|
|
if (!fs.existsSync(path.join(cwd, filePath))) {
|
|
throw new Error(`File ${filePath} was not found`);
|
|
}
|
|
});
|
|
}
|
|
|
|
function mustNotExist(filePath: string) {
|
|
test(`${filePath} does not exist`, () => {
|
|
if (!cwd) throw new Error("install failed");
|
|
if (fs.existsSync(path.join(cwd, filePath))) {
|
|
throw new Error(`File ${filePath} was found`);
|
|
}
|
|
});
|
|
}
|
|
|
|
beforeAll(() => {
|
|
fs.cpSync(path.join(import.meta.dir, "complex-workspace"), cwd, { recursive: true });
|
|
});
|
|
|
|
test("the install succeeds", async () => {
|
|
var subprocess = Bun.spawn([bunExe(), "reset.ts"], {
|
|
env: bunEnv,
|
|
cwd,
|
|
stdio: ["ignore", "ignore", "ignore"],
|
|
});
|
|
await subprocess.exited;
|
|
if (subprocess.exitCode != 0) {
|
|
cwd = false as any;
|
|
throw new Error("Failed to install");
|
|
}
|
|
|
|
subprocess = Bun.spawn([bunExe(), "install"], {
|
|
env: bunEnv,
|
|
cwd,
|
|
stdio: ["ignore", "ignore", "ignore"],
|
|
});
|
|
|
|
await subprocess.exited;
|
|
if (subprocess.exitCode != 0) {
|
|
cwd = false as any;
|
|
throw new Error("Failed to install");
|
|
}
|
|
}, 10000);
|
|
|
|
// bun-types
|
|
validate("node_modules/bun-types", "1.0.0");
|
|
mustExist("node_modules/bun-types/isfake.txt");
|
|
// NOTE: ???
|
|
// validate("node_modules/bun-types/node_modules/bun-types", "1.0.0");
|
|
mustNotExist("node_modules/bun-types/node_modules/bun-types/isfake.txt");
|
|
|
|
// svelte
|
|
validate("node_modules/svelte", "4.1.2");
|
|
validate("packages/second/node_modules/svelte", "4.1.0");
|
|
validate("packages/with-postinstall/node_modules/svelte", "3.50.0");
|
|
// validate("packages/body-parser/node_modules/svelte", "0.2.0", "public-install-test");
|
|
// NOTE: bun hoists this dependency higher than npm
|
|
// npm places this in node_modules/express
|
|
validate("packages/second/node_modules/express", "1.0.0", "svelte");
|
|
|
|
// install test
|
|
// validate("node_modules/install-test", "0.3.0", "publicinstalltest");
|
|
// mustExist("node_modules/install-test/src/index.js");
|
|
validate("node_modules/install-test1", "0.2.0", "install-test");
|
|
mustExist("node_modules/install-test1/index.js");
|
|
// validate("node_modules/public-install-test", "0.2.0", "public-install-test");
|
|
// mustExist("node_modules/public-install-test/index.js");
|
|
|
|
// hello
|
|
validate("node_modules/hello", "0.3.2");
|
|
mustExist("node_modules/hello/version.txt");
|
|
mustNotExist("packages/second/node_modules/hello/version.txt");
|
|
|
|
// body parser
|
|
validate("node_modules/body-parser", "200.0.0");
|
|
// NOTE: bun hoists this dependency higher than npm
|
|
// npm places this in node_modules/not-body-parser
|
|
validate("packages/second/node_modules/not-body-parser", "200.0.0", "body-parser");
|
|
// NOTE: bun install doesnt properly handle npm aliased dependencies
|
|
// validate("packages/second/node_modules/connect", "200.0.0", "body-parser");
|
|
validate("packages/second/node_modules/body-parser", "3.21.2", "express");
|
|
// NOTE: bun does not hoist this properly, but it is extremely unlikely to be a real use case
|
|
// validate("packages/second/node_modules/body-parser/node_modules/body-parser", "1.13.3", "body-parser");
|
|
|
|
// connect
|
|
// mustNotExist("node_modules/connect");
|
|
// validate("packages/second/node_modules/body-parser/node_modules/connect", "2.30.2", "connect");
|
|
|
|
// sharp
|
|
validate("node_modules/sharp", "0.32.6");
|
|
|
|
// iconv-lite
|
|
mustNotExist("packages/second/node_modules/body-parser/node_modules/body-parser/node_modules/iconv-lite");
|
|
mustNotExist("packages/second/node_modules/body-parser/node_modules/iconv-lite");
|
|
mustNotExist("packages/second/node_modules/iconv-lite");
|
|
mustNotExist("node_modules/iconv-lite");
|