### Get Workspace Globs Synchronously and Asynchronously (TypeScript) Source: https://github.com/bycedric/resolve-workspace-root/blob/main/README.md Illustrates how to retrieve workspace globs using `getWorkspaceGlobs` and `getWorkspaceGlobsAsync`. These functions require the workspace root to be resolved first. ```typescript import { getWorkspaceGlobs, getWorkspaceGlobsAsync } from 'resolve-workspace-root'; import { resolveWorkspaceRoot } from 'resolve-workspace-root'; // Synchronous lookup, supporting bun, npm, pnpm, and yarn const workspaces = getWorkspaceGlobs(resolveWorkspaceRoot(__dirname)); // Asynchronous lookup, supporting bun, npm, pnpm, and yarn const workspaces = await getWorkspaceGlobsAsync(resolveWorkspaceRoot(__dirname)); ``` -------------------------------- ### Get Workspace Globs Asynchronously with TypeScript Source: https://context7.com/bycedric/resolve-workspace-root/llms.txt Asynchronously retrieves workspace glob patterns from a monorepo root. This function is useful for discovering package locations within a monorepo, often used in conjunction with finding the monorepo root itself. It can accept an optional configuration object to specify how to find package workspaces. ```typescript import { resolveWorkspaceRootAsync, getWorkspaceGlobsAsync } from 'resolve-workspace-root'; // Get workspace globs asynchronously async function discoverWorkspacePackages() { const root = await resolveWorkspaceRootAsync(process.cwd()); if (!root) { console.log('Not in a workspace'); return []; } const globs = await getWorkspaceGlobsAsync(root); console.log(`Workspace patterns: ${globs}`); // Output: Workspace patterns: packages/*,apps/* return globs; } // Example: Build tool integration async function getMonorepoInfo() { const startDir = process.cwd(); const root = await resolveWorkspaceRootAsync(startDir); if (root) { const globs = await getWorkspaceGlobsAsync(root); return { root, patterns: globs, currentPackage: startDir }; } return null; } // Using with specific workspace type async function getPnpmPackages() { const globs = await getWorkspaceGlobsAsync('/projects/my-pnpm-monorepo', { packageWorkspaces: false // Only check pnpm-workspace.yaml }); return globs; // Output: ['packages/*', 'tools/*'] or null } ``` -------------------------------- ### Get Workspace Glob Patterns (TypeScript/Node.js) Source: https://context7.com/bycedric/resolve-workspace-root/llms.txt Synchronously retrieves the workspace glob patterns defined in the monorepo root. This function requires the root path of the workspace. It can filter globs based on package manager type using options. Returns an array of glob strings or null if no workspace configuration is found. ```typescript import { resolveWorkspaceRoot, getWorkspaceGlobs } from 'resolve-workspace-root'; // Get workspace globs from the monorepo root const root = resolveWorkspaceRoot('/projects/my-monorepo/packages/core'); if (root) { const globs = getWorkspaceGlobs(root); console.log(globs); // Output: ['packages/*', 'apps/*'] } // Direct usage when you know the root path const workspacePatterns = getWorkspaceGlobs('/projects/my-monorepo'); console.log(workspacePatterns); // Output: ['packages/*'] or null if not a workspace // With options - only get pnpm workspace globs const pnpmGlobs = getWorkspaceGlobs('/projects/my-monorepo', { packageWorkspaces: false }); // With options - only get package.json workspace globs const npmGlobs = getWorkspaceGlobs('/projects/my-monorepo', { pnpmWorkspaces: false }); // Returns null if no workspace configuration found const noWorkspace = getWorkspaceGlobs('/home/user'); console.log(noWorkspace); // Output: null ``` -------------------------------- ### Resolve Workspace Root Synchronously and Asynchronously (TypeScript) Source: https://github.com/bycedric/resolve-workspace-root/blob/main/README.md Demonstrates how to use `resolveWorkspaceRoot` and `resolveWorkspaceRootAsync` to find the workspace root. It shows options for supporting all package managers or specific ones like bun, npm, yarn, or pnpm. ```typescript import { resolveWorkspaceRoot, resolveWorkspaceRootAsync } from 'resolve-workspace-root'; // Synchronous lookup, supporting bun, npm, pnpm, and yarn const workspaceRoot = resolveWorkspaceRoot(__dirname); // Synchronous lookup, supporting only bun, npm, and yarn const workspaceRoot = resolveWorkspaceRoot(__dirname, { packageWorkspaces: false }); // Synchronous lookup, supporting only pnpm const workspaceRoot = resolveWorkspaceRoot(__dirname, { pnpmWorkspaces: false }); // Asynchronous lookup, supporting bun, npm, pnpm, and yarn const workspaceRoot = await resolveWorkspaceRootAsync(__dirname); // Asynchronous lookup, supporting only bun, npm, and yarn const workspaceRoot = await resolveWorkspaceRootAsync(__dirname, { packageWorkspaces: false }); // Asynchronous lookup, supporting only pnpm const workspaceRoot = await resolveWorkspaceRootAsync(__dirname, { pnpmWorkspaces: false }); ``` -------------------------------- ### Synchronously Resolve Workspace Root (TypeScript/Node.js) Source: https://context7.com/bycedric/resolve-workspace-root/llms.txt Synchronously resolves the monorepo workspace root by traversing parent directories. It checks for 'workspaces' in package.json or 'pnpm-workspace.yaml'. Returns the root path or null if not found or the directory is not part of a workspace. Accepts an optional options object to disable specific workspace detection methods. ```typescript import { resolveWorkspaceRoot } from 'resolve-workspace-root'; // Basic usage - detect workspace root from current package const workspaceRoot = resolveWorkspaceRoot('/projects/my-monorepo/packages/ui-components'); console.log(workspaceRoot); // Output: '/projects/my-monorepo' // Using current working directory (default) const rootFromCwd = resolveWorkspaceRoot(); console.log(rootFromCwd); // Output: workspace root or null // Disable pnpm workspace detection (only check package.json) const npmOnlyRoot = resolveWorkspaceRoot('/projects/my-monorepo/packages/api', { pnpmWorkspaces: false }); // Disable package.json workspaces (only check pnpm-workspace.yaml) const pnpmOnlyRoot = resolveWorkspaceRoot('/projects/my-monorepo/packages/api', { packageWorkspaces: false }); // Returns null if directory is not part of any workspace const notInWorkspace = resolveWorkspaceRoot('/some/random/directory'); console.log(notInWorkspace); // Output: null ``` -------------------------------- ### Asynchronously Resolve Workspace Root (TypeScript/Node.js) Source: https://context7.com/bycedric/resolve-workspace-root/llms.txt Asynchronously resolves the monorepo workspace root, suitable for non-blocking operations. It traverses parent directories and checks for workspace configurations. Returns a Promise resolving to the root path or null. Options can be passed to customize detection. ```typescript import { resolveWorkspaceRootAsync } from 'resolve-workspace-root'; // Basic async usage async function findWorkspace() { const workspaceRoot = await resolveWorkspaceRootAsync('/projects/my-monorepo/packages/shared'); if (workspaceRoot) { console.log(`Found workspace at: ${workspaceRoot}`); } else { console.log('Not in a workspace'); } } // With options - check only npm/yarn/bun workspaces async function findNpmWorkspace() { const root = await resolveWorkspaceRootAsync(process.cwd(), { pnpmWorkspaces: false }); return root; } // With options - check only pnpm workspaces async function findPnpmWorkspace() { const root = await resolveWorkspaceRootAsync(process.cwd(), { packageWorkspaces: false }); return root; } // Example in a build script async function buildPackage() { const root = await resolveWorkspaceRootAsync(__dirname); if (!root) { throw new Error('This package must be run from within a monorepo workspace'); } console.log(`Building from workspace root: ${root}`); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.