Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import type { WorkspaceConfig } from "@turbo/utils";
import { getWorkspaceConfigs } from "@turbo/utils";
import { getWorkspaceConfigs, forEachTaskDef } from "@turbo/utils";
import type { PipelineV1, RootSchemaV1, RootSchemaV2 } from "@turbo/types";
import { forEachTaskDef } from "@turbo/utils/src/getTurboConfigs";
import { dotEnv } from "./dotenv-processing";
import { wildcardTests } from "./wildcard-processing";

Expand Down
3 changes: 3 additions & 0 deletions packages/turbo-utils/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const config = {
transformIgnorePatterns: ["/node_modules/(?!(ansi-regex)/)"],
verbose: process.env.RUNNER_DEBUG === "1",
silent: process.env.RUNNER_DEBUG !== "1",
moduleNameMapper: {
"^(\\./.+)\\.js$": "$1",
},
} as const satisfies Config;

export default config;
20 changes: 17 additions & 3 deletions packages/turbo-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@
"bugs": {
"url": "https://github.com/vercel/turborepo/issues"
},
"module": "src/index.ts",
"main": "src/index.ts",
"types": "src/index.ts",
"type": "module",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
},
"scripts": {
"build": "pnpm build:esm && pnpm build:cjs && pnpm build:types && pnpm post-build",
"post-build": "echo '{ \"type\": \"commonjs\" }' > dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:types": "tsc -p tsconfig.types.json",
"test": "jest",
"lint": "eslint src/",
"check-types": "tsc --noEmit",
Expand Down
10 changes: 5 additions & 5 deletions packages/turbo-utils/src/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import path from "node:path";
import retry from "async-retry";
import picocolors from "picocolors";
import fs from "fs-extra";
import * as logger from "./logger";
import * as logger from "./logger.js";
import {
downloadAndExtractExample,
downloadAndExtractRepo,
getRepoInfo,
existsInRepo,
hasRepo,
type RepoInfo,
} from "./examples";
import { isWriteable } from "./isWriteable";
import { isFolderEmpty } from "./isFolderEmpty";
import type { PackageJson } from "./types";
} from "./examples.js";
import { isWriteable } from "./isWriteable.js";
import { isFolderEmpty } from "./isFolderEmpty.js";
import type { PackageJson } from "./types.js";

function isErrorLike(err: unknown): err is { message: string } {
return (
Expand Down
4 changes: 3 additions & 1 deletion packages/turbo-utils/src/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { promisify } from "node:util";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { createWriteStream, promises as fs } from "node:fs";
import { x as extract } from "tar";
import tar from "tar";
import got from "got";

const { x: extract } = tar;

const pipeline = promisify(Stream.pipeline);

export interface RepoInfo {
Expand Down
14 changes: 8 additions & 6 deletions packages/turbo-utils/src/getTurboConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import yaml from "js-yaml";
import { sync } from "fast-glob";
import glob from "fast-glob";
import JSON5 from "json5";
import type {
BaseSchemaV1,
Expand All @@ -10,9 +10,11 @@ import type {
BaseSchemaV2,
PipelineV2,
} from "@turbo/types";
import * as logger from "./logger";
import { getTurboRoot } from "./getTurboRoot";
import type { PackageJson, PNPMWorkspaceConfig } from "./types";
import * as logger from "./logger.js";
import { getTurboRoot } from "./getTurboRoot.js";
import type { PackageJson, PNPMWorkspaceConfig } from "./types.js";

const { sync } = glob;

const ROOT_GLOB = "{turbo.json,turbo.jsonc}";
const ROOT_WORKSPACE_GLOB = "package.json";
Expand Down Expand Up @@ -115,7 +117,7 @@ export function getTurboConfigs(cwd?: string, opts?: Options): TurboConfigs {
if (turboRoot) {
const workspaceGlobs = getWorkspaceGlobs(turboRoot);
const workspaceConfigGlobs = workspaceGlobs.map(
(glob) => `${glob}/${ROOT_GLOB}`
(workspaceGlob) => `${workspaceGlob}/${ROOT_GLOB}`
);

const configPaths = sync([ROOT_GLOB, ...workspaceConfigGlobs], {
Expand Down Expand Up @@ -200,7 +202,7 @@ export function getWorkspaceConfigs(
if (turboRoot) {
const workspaceGlobs = getWorkspaceGlobs(turboRoot);
const workspaceConfigGlobs = workspaceGlobs.map(
(glob) => `${glob}/package.json`
(workspaceGlob) => `${workspaceGlob}/package.json`
);

const configPaths = sync([ROOT_WORKSPACE_GLOB, ...workspaceConfigGlobs], {
Expand Down
3 changes: 1 addition & 2 deletions packages/turbo-utils/src/getTurboRoot.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { Schema } from "@turbo/types";
import { findRootSync } from "@manypkg/find-root";
import json5 from "json5";
import { searchUp } from "./searchUp";
import { searchUp } from "./searchUp.js";

interface Options {
cache?: boolean;
}

function contentCheck(content: string): boolean {
// eslint-disable-next-line import/no-named-as-default-member -- json5 exports different objects depending on if you're using esm or cjs (https://github.com/json5/json5/issues/240)
const result: Schema | undefined = json5.parse(content);
return !(result && "extends" in result);
}
Expand Down
28 changes: 14 additions & 14 deletions packages/turbo-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
// utils
export { getTurboRoot } from "./getTurboRoot";
export { getTurboRoot } from "./getTurboRoot.js";
export {
getTurboConfigs,
getWorkspaceConfigs,
forEachTaskDef,
} from "./getTurboConfigs";
export { searchUp } from "./searchUp";
} from "./getTurboConfigs.js";
export { searchUp } from "./searchUp.js";
export {
getAvailablePackageManagers,
getPackageManagersBinPaths,
} from "./managers";
export { isFolderEmpty } from "./isFolderEmpty";
export { validateDirectory } from "./validateDirectory";
} from "./managers.js";
export { isFolderEmpty } from "./isFolderEmpty.js";
export { validateDirectory } from "./validateDirectory.js";
export {
isUrlOk,
getRepoInfo,
hasRepo,
existsInRepo,
downloadAndExtractRepo,
downloadAndExtractExample,
} from "./examples";
export { isWriteable } from "./isWriteable";
export { createProject, DownloadError } from "./createProject";
export { convertCase } from "./convertCase";
} from "./examples.js";
export { isWriteable } from "./isWriteable.js";
export { createProject, DownloadError } from "./createProject.js";
export { convertCase } from "./convertCase.js";

export * as logger from "./logger";
export * as logger from "./logger.js";

// types
export type { RepoInfo } from "./examples";
export type { RepoInfo } from "./examples.js";
export type {
TurboConfig,
TurboConfigs,
WorkspaceConfig,
} from "./getTurboConfigs";
export * from "./types";
} from "./getTurboConfigs.js";
export * from "./types.js";
10 changes: 3 additions & 7 deletions packages/turbo-utils/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
reset,
bold as pcBold,
underline as pcUnderline,
gray,
dim,
} from "picocolors";
import pc from "picocolors";
import ora from "ora";
import gradient from "gradient-string";

const { reset, bold: pcBold, underline: pcUnderline, gray, dim } = pc;

const BLUE = "#0099F7";
const RED = "#F11712";
const YELLOW = "#FFFF00";
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-utils/src/managers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from "node:os";
import type { Options } from "execa";
import execa from "execa";
import type { PackageManager } from "./types";
import type { PackageManager } from "./types.js";

async function exec(command: string, args: Array<string> = [], opts?: Options) {
// run the check from tmpdir to avoid corepack conflicting -
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-utils/src/validateDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import fs from "fs-extra";
import picocolors from "picocolors";
import { isFolderEmpty } from "./isFolderEmpty";
import { isFolderEmpty } from "./isFolderEmpty.js";

export function validateDirectory(directory: string): {
valid: boolean;
Expand Down
18 changes: 18 additions & 0 deletions packages/turbo-utils/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@turbo/tsconfig/library.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist/cjs",
"module": "CommonJS",
"moduleResolution": "node",
"target": "ES2020",
"lib": ["ES2020"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
"ts-node": {
"esm": false
}
}
10 changes: 8 additions & 2 deletions packages/turbo-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"extends": "@turbo/tsconfig/library.json",
"compilerOptions": {
"rootDir": "."
}
"rootDir": "src",
"outDir": "dist/esm",
"module": "ESNext",
"moduleResolution": "bundler",
"target": "ESNext",
"lib": ["ESNext"]
},
"include": ["src/**/*"]
}
14 changes: 14 additions & 0 deletions packages/turbo-utils/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "@turbo/tsconfig/library.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist/types",
"declaration": true,
"emitDeclarationOnly": true,
"module": "ESNext",
"moduleResolution": "bundler",
"target": "ESNext",
"lib": ["ESNext"]
},
"include": ["src/**/*"]
}
Loading