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
7 changes: 5 additions & 2 deletions packages/create-turbo/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import childProcess from "node:child_process";
import chalk from "chalk";
import { setupTestFixtures, spyConsole, spyExit } from "@turbo/test-utils";
import { logger } from "@turbo/utils";
import type { PackageManager } from "@turbo/workspaces";
import type { PackageManager } from "@turbo/utils";
// imports for mocks
import * as turboWorkspaces from "@turbo/workspaces";
import * as turboUtils from "@turbo/utils";
Expand All @@ -29,6 +29,7 @@ describe("create-turbo", () => {
{ packageManager: "yarn" },
{ packageManager: "npm" },
{ packageManager: "pnpm" },
{ packageManager: "bun" },
])(
"outputs expected console messages when using $packageManager",
async ({ packageManager }) => {
Expand All @@ -42,6 +43,7 @@ describe("create-turbo", () => {
npm: "8.19.2",
yarn: "1.22.10",
pnpm: "7.22.2",
bun: "1.0.1",
});

const mockCreateProject = jest
Expand Down Expand Up @@ -98,7 +100,7 @@ describe("create-turbo", () => {
}
);

test.only("throws correct error message when a download error is encountered", async () => {
test("throws correct error message when a download error is encountered", async () => {
const { root } = useFixture({ fixture: `create-turbo` });
const packageManager = "pnpm";
const mockAvailablePackageManagers = jest
Expand All @@ -107,6 +109,7 @@ describe("create-turbo", () => {
npm: "8.19.2",
yarn: "1.22.10",
pnpm: "7.22.2",
bun: "1.0.1",
});

const mockCreateProject = jest
Expand Down
2 changes: 1 addition & 1 deletion packages/create-turbo/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import { PackageManager } from "@turbo/workspaces";
import type { PackageManager } from "@turbo/utils";

export function getWorkspaceDetailsMockReturnValue({
root,
Expand Down
15 changes: 10 additions & 5 deletions packages/create-turbo/src/commands/create/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PackageManager } from "@turbo/workspaces";
import type { PackageManager } from "@turbo/utils";
import { getAvailablePackageManagers, validateDirectory } from "@turbo/utils";
import inquirer from "inquirer";
import type { CreateCommandArgument } from "./types";
Expand Down Expand Up @@ -52,10 +52,15 @@ export async function packageManager({
// prompt for package manager if it wasn't provided as an argument, or if it was
// provided, but isn't available (always allow npm)
!manager || !availablePackageManagers[manager as PackageManager],
choices: ["npm", "pnpm", "yarn"].map((p) => ({
name: p,
value: p,
disabled: availablePackageManagers[p as PackageManager]
choices: [
{ pm: "npm", label: "npm workspaces" },
{ pm: "pnpm", label: "pnpm workspaces" },
{ pm: "yarn", label: "yarn workspaces" },
{ pm: "bun", label: "bun workspaces (beta)" },
].map(({ pm, label }) => ({
name: label,
value: pm,
disabled: availablePackageManagers[pm as PackageManager]
? false
: `not installed`,
})),
Expand Down
4 changes: 2 additions & 2 deletions packages/create-turbo/src/transforms/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RepoInfo } from "@turbo/utils";
import type { Project, PackageManager } from "@turbo/workspaces";
import type { RepoInfo, PackageManager } from "@turbo/utils";
import type { Project } from "@turbo/workspaces";
import type { CreateCommandOptions } from "../commands/create/types";

export interface TransformInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface TestCase {
name: string;
fixture: string;
existingPackageManagerString: string | undefined;
packageManager: turboWorkspaces.PackageManager;
packageManager: turboUtils.PackageManager;
packageManagerVersion: string;
options: TransformerOptions;
result: TransformerResults;
Expand Down Expand Up @@ -153,6 +153,7 @@ describe("add-package-manager-2", () => {
pnpm: packageManager === "pnpm" ? packageManagerVersion : undefined,
npm: packageManager === "npm" ? packageManagerVersion : undefined,
yarn: packageManager === "yarn" ? packageManagerVersion : undefined,
bun: packageManager === "bun" ? packageManagerVersion : undefined,
});

const mockGetWorkspaceDetails = jest
Expand Down Expand Up @@ -243,6 +244,7 @@ describe("add-package-manager-2", () => {
pnpm: undefined,
npm: undefined,
yarn: undefined,
bun: undefined,
});

const mockGetWorkspaceDetails = jest
Expand Down Expand Up @@ -290,6 +292,7 @@ describe("add-package-manager-2", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});

const mockGetWorkspaceDetails = jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock("@turbo/workspaces", () => ({

interface TestCase {
version: string;
packageManager: turboWorkspaces.PackageManager;
packageManager: turboUtils.PackageManager;
packageManagerVersion: string;
fixture: string;
expected: string;
Expand Down Expand Up @@ -457,13 +457,15 @@ describe("get-turbo-upgrade-command", () => {
pnpm: undefined,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockGetAvailablePackageManagers = jest
.spyOn(turboUtils, "getAvailablePackageManagers")
.mockResolvedValue({
pnpm: packageManager === "pnpm" ? packageManagerVersion : undefined,
npm: packageManager === "npm" ? packageManagerVersion : undefined,
yarn: packageManager === "yarn" ? packageManagerVersion : undefined,
bun: packageManager === "bun" ? packageManagerVersion : undefined,
});

const project = getWorkspaceDetailsMockReturnValue({
Expand Down Expand Up @@ -517,6 +519,7 @@ describe("get-turbo-upgrade-command", () => {
pnpm: `/global/pnpm/bin`,
npm: `/global/npm/bin`,
yarn: `/global/yarn/bin`,
bun: `/global/bun/bin`,
});

const mockGetAvailablePackageManagers = jest
Expand All @@ -525,6 +528,7 @@ describe("get-turbo-upgrade-command", () => {
pnpm: packageManager === "pnpm" ? packageManagerVersion : undefined,
npm: packageManager === "npm" ? packageManagerVersion : undefined,
yarn: packageManager === "yarn" ? packageManagerVersion : undefined,
bun: packageManager === "bun" ? packageManagerVersion : undefined,
});

const project = getWorkspaceDetailsMockReturnValue({
Expand Down Expand Up @@ -571,6 +575,7 @@ describe("get-turbo-upgrade-command", () => {
pnpm: "8.0.0",
npm: undefined,
yarn: undefined,
bun: undefined,
});

const project = getWorkspaceDetailsMockReturnValue({
Expand Down Expand Up @@ -626,6 +631,7 @@ describe("get-turbo-upgrade-command", () => {
pnpm: "8.0.0",
npm: undefined,
yarn: undefined,
bun: undefined,
});

const project = getWorkspaceDetailsMockReturnValue({
Expand Down
7 changes: 7 additions & 0 deletions packages/turbo-codemod/__tests__/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down Expand Up @@ -134,6 +135,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down Expand Up @@ -202,6 +204,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down Expand Up @@ -286,6 +289,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down Expand Up @@ -489,6 +493,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down Expand Up @@ -596,6 +601,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down Expand Up @@ -832,6 +838,7 @@ describe("migrate", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});
const mockedGetWorkspaceDetails = jest
.spyOn(turboWorkspaces, "getWorkspaceDetails")
Expand Down
3 changes: 2 additions & 1 deletion packages/turbo-codemod/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from "node:path";
import type { PackageManager, Project } from "@turbo/workspaces";
import type { PackageManager } from "@turbo/utils";
import type { Project } from "@turbo/workspaces";

export function getWorkspaceDetailsMockReturnValue({
root,
Expand Down
2 changes: 2 additions & 0 deletions packages/turbo-codemod/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("transform", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});

const mockGetWorkspaceDetails = jest
Expand Down Expand Up @@ -93,6 +94,7 @@ describe("transform", () => {
pnpm: packageManagerVersion,
npm: undefined,
yarn: undefined,
bun: undefined,
});

const mockGetWorkspaceDetails = jest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import {
getAvailablePackageManagers,
getPackageManagersBinPaths,
logger,
type PackageManager,
type PackageJson,
} from "@turbo/utils";
import { type Project, type PackageManager } from "@turbo/workspaces";
import type { Project } from "@turbo/workspaces";
import { exec } from "../utils";

type InstallType = "dependencies" | "devDependencies";
Expand All @@ -23,6 +24,8 @@ function getGlobalUpgradeCommand(
return `npm install turbo@${to} --global`;
case "pnpm":
return `pnpm add turbo@${to} --global`;
case "bun":
return `bun add turbo@${to} --global`;
}
}

Expand Down Expand Up @@ -78,6 +81,13 @@ function getLocalUpgradeCommand({
installType === "devDependencies" && "--save-dev",
isUsingWorkspaces && "-w",
]);
case "bun":
return renderCommand([
"bun",
"add",
`turbo@${to}`,
installType === "devDependencies" && "--dev",
]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/turbo-gen/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import { PackageManager } from "@turbo/workspaces";
import path from "node:path";
import type { PackageManager } from "@turbo/utils";

export function getWorkspaceDetailsMockReturnValue({
root,
Expand Down
1 change: 0 additions & 1 deletion packages/turbo-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export { convertCase } from "./convertCase";
export * as logger from "./logger";

// types
export type { PackageManagerAvailable } from "./managers";
export type { RepoInfo } from "./examples";
export type {
TurboConfig,
Expand Down
15 changes: 7 additions & 8 deletions packages/turbo-utils/src/managers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import os from "node:os";
import type { Options } from "execa";
import execa from "execa";

export type PackageManager = "npm" | "yarn" | "pnpm";
export interface PackageManagerAvailable {
available: boolean;
version?: string;
}
import type { PackageManager } from "./types";

async function exec(command: string, args: Array<string> = [], opts?: Options) {
// run the check from tmpdir to avoid corepack conflicting -
Expand All @@ -28,31 +23,35 @@ async function exec(command: string, args: Array<string> = [], opts?: Options) {
export async function getAvailablePackageManagers(): Promise<
Record<PackageManager, string | undefined>
> {
const [yarn, npm, pnpm] = await Promise.all([
const [yarn, npm, pnpm, bun] = await Promise.all([
exec("yarnpkg", ["--version"]),
exec("npm", ["--version"]),
exec("pnpm", ["--version"]),
exec("bun", ["--version"]),
]);

return {
yarn,
pnpm,
npm,
bun,
};
}

export async function getPackageManagersBinPaths(): Promise<
Record<PackageManager, string | undefined>
> {
const [yarn, npm, pnpm] = await Promise.all([
const [yarn, npm, pnpm, bun] = await Promise.all([
exec("yarnpkg", ["global", "bin"]),
exec("npm", ["config", "get", "prefix"]),
exec("pnpm", ["bin", "--global"]),
exec("bun", ["pm", "--g", "bin"]),
]);

return {
yarn,
pnpm,
npm,
bun,
};
}
2 changes: 2 additions & 0 deletions packages/turbo-utils/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Schema } from "@turbo/types";

export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";

export type DependencyList = Record<string, string>;

export interface DependencyGroups {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "docs",
"version": "0.0.0",
"private": true,
"dependencies": {
"ui": "*"
},
"devDependencies": {
"tsconfig": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "web",
"version": "0.0.0",
"private": true,
"dependencies": {
"ui": "*"
},
"devDependencies": {
"tsconfig": "*"
}
}
Binary file not shown.
Loading