active.ts 826 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * Process-wide slot holding the mounted filesystem. Kept apart from any
  3. * backend implementation: the `node:fs` proxy depends on the slot, not on
  4. * which backend the worker entry mounted.
  5. * @module @deepseek-ai/dsh-experimental-webworker-runtime/src/storage/active
  6. */
  7. import type { Vfs } from './types.ts'
  8. let active: Vfs | undefined
  9. /**
  10. * Publish the filesystem the `node:fs` proxy reads.
  11. * @param vfs - Filesystem mounted by the worker entry.
  12. */
  13. export function setActiveVfs(vfs: Vfs): void {
  14. active = vfs
  15. }
  16. /**
  17. * Read the mounted filesystem.
  18. * @returns The active filesystem.
  19. */
  20. export function requireActiveVfs(): Vfs {
  21. if (active === undefined) {
  22. throw new Error('webworker vfs: no filesystem is mounted; the worker entry must call setActiveVfs before any node:fs access')
  23. }
  24. return active
  25. }