Files
deepseek-harness/packages/experimental/webworker-runtime/src/node/notImplementedFail.ts
T
imccyu f47b1ecac2 feat(webworker): browser worker host runtime and the vfs image packer
Two private experimental packages run the whole harness tree inside one
dedicated Web Worker. dsh-experimental-webworker-runtime owns the in-memory
VFS (BigInt stats with per-path identity and strictly increasing mtimes),
the CommonJS wrapper loader over a lazily-evaluated builtin table whose
shims typecheck against Node's own module types, the postMessage tunnel
speaking plain HTTP, the AsyncLocalStorage runtime, and the worker
assembly. dsh-experimental-webworker-packer lowers every module body at
pack time against the shared wrapper contract, sweeps the profile closure
by static reachability, and writes a deterministically gzip-compressed tar
the worker inflates through the browser's native DecompressionStream while
it downloads.
2026-08-21 20:35:32 +08:00

45 lines
2.1 KiB
TypeScript

/**
* Structural not-implemented stubs: a replaced module must expose every symbol
* its importers name (a missing CommonJS symbol degrades to `undefined` at call
* time instead of failing at link time), and every one of those symbols must
* report exactly what is unavailable when it is finally called.
*/
/**
* Build a function that throws naming its module and symbol. The refusal is
* also written to the console before it propagates: callers routinely swallow
* these errors far from their cause, and the console line is what places the
* failure while debugging a worker session.
*
* `Face` is the Node declaration this stub stands in for, so the replaced module
* publishes the type its importers compile against. The value is one throwing
* function whatever that declaration says: a caller reaches the throw before any
* declared parameter, return value, or `new` result exists, so the assertion
* below cannot be observed as a lie. It is a function expression rather than an
* arrow because a stub standing in for a class must refuse under `new` too, and
* an arrow has no construct behavior to reach.
* @param module - module specifier being stubbed.
* @param symbol - exported symbol name.
* @returns the throwing stand-in, typed as the member it replaces.
*/
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- only the return position carries the Node declaration
export function notImplementedFail<Face = (...args: never[]) => never>(module: string, symbol: string): Face {
return (function refuse(): never {
throw notAvailableError(module, symbol)
}) as Face
}
/**
* Build the refusal error and write it to the console first, for stubs that
* cannot be a plain throwing function (constructors, methods on structural
* fakes).
* @param module - module specifier being stubbed.
* @param symbol - unavailable member, named as the importer sees it.
* @returns the error to throw.
*/
export function notAvailableError(module: string, symbol: string): Error {
const message = `web-preview: ${module}.${symbol} is not available in the worker host`
console.error(message)
return new Error(message)
}