mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
fix(install): workspace version added to package.json (#11241)
This commit is contained in:
@@ -7088,14 +7088,16 @@ pub const PackageManager = struct {
|
||||
},
|
||||
}
|
||||
}
|
||||
break :brk null;
|
||||
|
||||
break :brk try allocator.dupe(u8, request.version.literal.slice(request.version_buf));
|
||||
},
|
||||
.uninitialized => switch (request.version.tag) {
|
||||
.uninitialized => try allocator.dupe(u8, latest),
|
||||
else => null,
|
||||
else => try allocator.dupe(u8, request.version.literal.slice(request.version_buf)),
|
||||
},
|
||||
else => null,
|
||||
} orelse try allocator.dupe(u8, request.version.literal.slice(request.version_buf));
|
||||
.workspace => try allocator.dupe(u8, "workspace:*"),
|
||||
else => try allocator.dupe(u8, request.version.literal.slice(request.version_buf)),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { spawnSync } from "bun";
|
||||
import { bunExe, bunEnv as env, runBunInstall, tmpdirSync, toMatchNodeModulesAt } from "harness";
|
||||
import { join } from "path";
|
||||
import { writeFileSync, mkdirSync, rmSync } from "fs";
|
||||
import { writeFile, mkdir } from "fs/promises";
|
||||
import { beforeEach, test, expect } from "bun:test";
|
||||
import { install_test_helpers } from "bun:internal-for-testing";
|
||||
const { parseLockfile } = install_test_helpers;
|
||||
@@ -147,3 +148,57 @@ test("dependency on same name as workspace and dist-tag", async () => {
|
||||
expect(lockfile).toMatchNodeModulesAt(packageDir);
|
||||
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual(["", "3 packages installed"]);
|
||||
});
|
||||
|
||||
test("adding workspace in workspace edits package.json with correct version (workspace:*)", async () => {
|
||||
await writeFile(
|
||||
join(packageDir, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "foo",
|
||||
workspaces: ["packages/*", "apps/*"],
|
||||
}),
|
||||
);
|
||||
|
||||
await mkdir(join(packageDir, "packages", "pkg1"), { recursive: true });
|
||||
await writeFile(
|
||||
join(packageDir, "packages", "pkg1", "package.json"),
|
||||
JSON.stringify({
|
||||
name: "pkg1",
|
||||
version: "1.0.0",
|
||||
}),
|
||||
);
|
||||
|
||||
await mkdir(join(packageDir, "apps", "pkg2"), { recursive: true });
|
||||
await writeFile(
|
||||
join(packageDir, "apps", "pkg2", "package.json"),
|
||||
JSON.stringify({
|
||||
name: "pkg2",
|
||||
version: "1.0.0",
|
||||
}),
|
||||
);
|
||||
|
||||
const { stdout, exited } = Bun.spawn({
|
||||
cmd: [bunExe(), "add", "pkg2@workspace:*"],
|
||||
cwd: join(packageDir, "packages", "pkg1"),
|
||||
stdout: "pipe",
|
||||
stderr: "inherit",
|
||||
env,
|
||||
});
|
||||
const out = await Bun.readableStreamToText(stdout);
|
||||
|
||||
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
|
||||
"",
|
||||
"installed pkg2@workspace:apps/pkg2",
|
||||
"",
|
||||
"2 packages installed",
|
||||
]);
|
||||
|
||||
expect(await exited).toBe(0);
|
||||
|
||||
expect(await Bun.file(join(packageDir, "packages", "pkg1", "package.json")).json()).toEqual({
|
||||
name: "pkg1",
|
||||
version: "1.0.0",
|
||||
dependencies: {
|
||||
pkg2: "workspace:*",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user