1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import fs from "fs";
import { test, expect } from "bun:test";
import { bunEnv, bunExe } from "harness";
import { join } from "path";
import { mkdtempSync } from "js/node/fs/export-star-from";
import { tmpdir } from "os";
test("migrate from npm during `bun add`", async () => {
const testDir = mkdtempSync(join(tmpdir(), "migrate-"));
fs.writeFileSync(
join(testDir, "package.json"),
JSON.stringify({
name: "test3",
dependencies: {
"svelte": "*",
},
}),
);
fs.cpSync(join(import.meta.dir, "add-while-migrate-fixture.json"), join(testDir, "package-lock.json"));
Bun.spawnSync([bunExe(), "add", "lodash@4.17.21"], {
env: bunEnv,
cwd: testDir,
});
expect(fs.existsSync(join(testDir, "node_modules/lodash"))).toBeTrue();
const svelte_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/svelte/package.json"), "utf8")).version;
expect(svelte_version).toBe("4.0.0");
const lodash_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/lodash/package.json"), "utf8")).version;
expect(lodash_version).toBe("4.17.21");
});
// Currently this upgrades svelte :(
test.todo("migrate workspace from npm during `bun add`", async () => {
const testDir = join(tmpdir(), "migrate-" + Math.random().toString(36).slice(2));
fs.cpSync(join(import.meta.dir, "add-while-migrate-workspace"), testDir, { recursive: true });
Bun.spawnSync([bunExe(), "add", "lodash@4.17.21"], {
env: bunEnv,
cwd: join(testDir, "packages", "a"),
});
expect(fs.existsSync(join(testDir, "node_modules/lodash"))).toBeTrue();
const lodash_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/lodash/package.json"), "utf8")).version;
expect(lodash_version).toBe("4.17.21");
const svelte_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/svelte/package.json"), "utf8")).version;
expect(svelte_version).toBe("3.0.0");
});
|