Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 104 additions & 2 deletions packages/turbo-workspaces/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import path from "node:path";
import execa from "execa";
import * as turboUtils from "@turbo/utils";
import { setupTestFixtures } from "@turbo/test-utils";
import { describe, it, expect, jest } from "@jest/globals";
import { getWorkspaceDetails, convert } from "../src";
import { describe, it, expect, jest, beforeEach } from "@jest/globals";
import { getWorkspaceDetails, convert, install } from "../src";
import { generateConvertMatrix } from "./test-utils";

jest.mock("execa", () => jest.fn());
Expand All @@ -13,6 +13,108 @@ describe("Node entrypoint", () => {
directory: path.join(__dirname, "../"),
});

beforeEach(() => {
jest.clearAllMocks();
(execa as jest.MockedFunction<typeof execa>).mockResolvedValue({
stdout: "",
stderr: "",
exitCode: 0,
command: "",
failed: false,
timedOut: false,
isCanceled: false,
killed: false,
} as any);
});

describe("install", () => {
it("should use shell option on Windows for all package managers", async () => {
const originalPlatform = process.platform;
Object.defineProperty(process, "platform", {
value: "win32",
});

const { root } = useFixture({
fixture: `./bun/monorepo`,
});

const mockProject = {
name: "test-project",
description: undefined,
packageManager: "bun" as const,
paths: {
root,
packageJson: path.join(root, "package.json"),
lockfile: path.join(root, "bun.lockb"),
nodeModules: path.join(root, "node_modules"),
},
workspaceData: {
globs: ["apps/*", "packages/*"],
workspaces: [],
},
};

await install({
project: mockProject,
to: { name: "bun", version: "1.0.1" },
options: { dry: false },
});

expect(execa).toHaveBeenCalledWith("bun", ["install"], {
cwd: root,
preferLocal: true,
shell: true,
});

Object.defineProperty(process, "platform", {
value: originalPlatform,
});
});

it("should not use shell option on non-Windows platforms", async () => {
const originalPlatform = process.platform;
Object.defineProperty(process, "platform", {
value: "darwin",
});

const { root } = useFixture({
fixture: `./bun/monorepo`,
});

const mockProject = {
name: "test-project",
description: undefined,
packageManager: "bun" as const,
paths: {
root,
packageJson: path.join(root, "package.json"),
lockfile: path.join(root, "bun.lockb"),
nodeModules: path.join(root, "node_modules"),
},
workspaceData: {
globs: ["apps/*", "packages/*"],
workspaces: [],
},
};

await install({
project: mockProject,
to: { name: "bun", version: "1.0.1" },
options: { dry: false },
});

expect(execa).toHaveBeenCalledWith("bun", ["install"], {
cwd: root,
preferLocal: true,
shell: false,
});

Object.defineProperty(process, "platform", {
value: originalPlatform,
});
});
});

describe("convert", () => {
it.each(generateConvertMatrix())(
"detects $fixtureType project using $fixtureManager and converts to $toManager (interactive=$interactive dry=$dry install=$install)",
Expand Down
2 changes: 2 additions & 0 deletions packages/turbo-workspaces/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export async function install(args: InstallArgs) {
try {
await execa(packageManager.command, packageManager.installArgs, {
cwd: args.project.paths.root,
preferLocal: true,
shell: process.platform === "win32",
});
if (spinner) {
spinner.stop();
Expand Down
2 changes: 2 additions & 0 deletions packages/turbo-workspaces/src/managers/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ async function convertLock(args: ConvertArgs): Promise<void> {
await execa(PACKAGE_MANAGER_DETAILS.name, ["import"], {
stdio: "ignore",
cwd: project.paths.root,
preferLocal: true,
shell: process.platform === "win32",
});
} catch (err) {
// do nothing
Expand Down
2 changes: 2 additions & 0 deletions packages/turbo-workspaces/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ async function bunLockToYarnLock({
const { stdout } = await execa("bun", ["bun.lockb"], {
stdin: "ignore",
cwd: project.paths.root,
preferLocal: true,
shell: process.platform === "win32",
});
// write the yarn lockfile
await writeFile(path.join(project.paths.root, "yarn.lock"), stdout);
Expand Down
Loading