@socketsecurity/lib
Version:
Core utilities and infrastructure for Socket.dev security tools
72 lines (71 loc) • 1.96 kB
TypeScript
/**
* Clear a specific path override.
*/
export declare function clearPath(key: string): void;
/**
* Get a path value, checking overrides first.
*
* Resolution order:
* 1. Test overrides (set via setPath in beforeEach)
* 2. Cached value (for performance)
* 3. Original function call (cached for subsequent calls)
*
* @internal Used by path getters to support test rewiring
*/
export declare function getPathValue(key: string, originalFn: () => string): string;
/**
* Check if a path has been overridden.
*/
export declare function hasOverride(key: string): boolean;
/**
* Invalidate all cached paths.
* Called automatically when setPath/clearPath/resetPaths are used.
* Can also be called manually for advanced testing scenarios.
*
* @internal Primarily for internal use, but exported for advanced testing
*/
export declare function invalidateCaches(): void;
/**
* Register a cache invalidation callback.
* Called by modules that need to clear their caches when paths change.
*
* @internal Used by paths.ts and fs.ts
*/
export declare function registerCacheInvalidation(callback: () => void): void;
/**
* Clear all path overrides and reset caches.
* Useful in afterEach hooks to ensure clean test state.
*
* @example
* ```typescript
* import { resetPaths } from '#paths/rewire'
*
* afterEach(() => {
* resetPaths()
* })
* ```
*/
export declare function resetPaths(): void;
/**
* Set a path override for testing.
* This triggers cache invalidation for path-dependent modules.
*
* @example
* ```typescript
* import { setPath, resetPaths } from '#paths/rewire'
* import { getOsTmpDir } from '#lib/paths'
*
* beforeEach(() => {
* setPath('tmpdir', '/custom/tmp')
* })
*
* afterEach(() => {
* resetPaths()
* })
*
* it('should use custom temp directory', () => {
* expect(getOsTmpDir()).toBe('/custom/tmp')
* })
* ```
*/
export declare function setPath(key: string, value: string | undefined): void;