@builder.io/dev-tools
Version:
Builder.io Visual CMS Devtools
53 lines (52 loc) • 2.21 kB
TypeScript
import type { WorkspaceFolder, WorkspaceConfiguration } from "@builder.io/ai-utils";
import type { DevToolsSys } from "../../types";
export interface ResolveWorkspacePathOptions {
filePath: string;
forceWorkspace?: boolean;
workspace?: WorkspaceConfiguration;
workingDirectory: string;
sys: DevToolsSys;
canCollapseWorkspace?: boolean;
}
export interface ResolveWorkspacePathResult {
resolvedPath: string;
workspaceFolder?: WorkspaceFolder;
}
/**
* Resolves a workspace file path to its actual file system path.
*
* This function handles various workspace configurations:
* - Single workspace named "." (treats paths as direct relative paths)
* - Multiple workspaces (matches path prefixes to workspace names/folder names)
* - No workspace configuration (falls back to working directory)
*
* @param options Configuration object containing all required parameters
* @param options.filePath A file path that may include a workspace prefix (e.g., "workspace1/path/to/file.js")
* @param options.forceWorkspace If true, will try the first workspace as fallback when no workspace folder is found
* @param options.workspace Optional workspace configuration with folders
* @param options.workingDirectory The base working directory to resolve paths against
* @param options.sys DevToolsSys object providing path resolution functions
* @returns Object containing the resolved file system path and matched workspace folder
*
* @example
* ```typescript
* import { createNodeSys } from '@builder.io/dev-tools/node';
*
* const result = resolveWorkspacePath({
* filePath: 'frontend/src/components/Button.tsx',
* workingDirectory: '/home/user/project',
* sys: createNodeSys(),
* workspace: {
* folders: [
* { name: 'frontend', path: './packages/frontend' },
* { name: 'backend', path: './packages/backend' }
* ]
* }
* });
* // Returns: {
* // resolvedPath: '/home/user/project/packages/frontend/src/components/Button.tsx',
* // workspaceFolder: { name: 'frontend', path: './packages/frontend' }
* // }
* ```
*/
export declare function resolveWorkspacePath(options: ResolveWorkspacePathOptions): ResolveWorkspacePathResult;