feat(native): add prebuilt Node-API flock support
This commit is contained in:
1 parent
7264906f99
commit
d927cbff99
93 files changed
+1904
-551
No files matched your search
@@ -45,7 +45,7 @@ import * as nodeNet from './builtin_modules/mock/net.ts'
|
||||
import * as nodeSqlite from './builtin_modules/mock/sqlite.ts'
|
||||
import * as nodeVm from './builtin_modules/mock/vm.ts'
|
||||
import * as nodeWorkerThreads from './builtin_modules/mock/worker_threads.ts'
|
||||
import * as fsExt from './external_packages/fs-ext.ts'
|
||||
import * as systemFlock from './external_packages/node-addon-system-flock.ts'
|
||||
import * as koffi from './external_packages/koffi.ts'
|
||||
import * as nodePty from './external_packages/node-pty.ts'
|
||||
import * as piAi from './external_packages/pi-ai.ts'
|
||||
@@ -84,9 +84,9 @@ const BUILTINS: Record<string, StaticModuleFactory> = {
|
||||
zlib: () => nodeZlib,
|
||||
}
|
||||
|
||||
/** External npm packages replaced wholesale (structural not-implemented stubs and fakes). */
|
||||
/** Exact package or subpath specifiers served by worker stubs and fakes. */
|
||||
const EXTERNALS: Record<string, StaticModuleFactory> = {
|
||||
'fs-ext': () => fsExt,
|
||||
'@deepseek-ai/node-addon-system/flock': () => systemFlock,
|
||||
'koffi': () => koffi,
|
||||
'sharp': () => sharp,
|
||||
'node-pty': () => nodePty,
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* `fs-ext` stub: the kernel file-lock bridge the JSONL session backend uses
|
||||
* for cross-process write exclusion. The worker is a single-process
|
||||
* deployment whose in-process write claim already excludes every writer, so
|
||||
* both flock faces succeed immediately; every other entry is loud because
|
||||
* nothing in the worker reaches it.
|
||||
*/
|
||||
import { notImplementedFail } from '../notImplementedFail.ts'
|
||||
|
||||
const MODULE = 'fs-ext'
|
||||
|
||||
/**
|
||||
* Asynchronous flock face; the single-process worker grants every lock.
|
||||
* @param _fd - file descriptor (unused).
|
||||
* @param _flags - lock flags (unused).
|
||||
* @param callback - completion callback, invoked with no error.
|
||||
*/
|
||||
export function flock(_fd: number, _flags: unknown, callback: (error: null) => void): void {
|
||||
queueMicrotask(() => { callback(null) })
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronous flock face; the single-process worker grants every lock.
|
||||
*/
|
||||
export function flockSync(): void {}
|
||||
|
||||
/** Unreached in the worker; loud refusal. */
|
||||
export const fcntl = notImplementedFail(MODULE, 'fcntl')
|
||||
/** Unreached in the worker; loud refusal. */
|
||||
export const fcntlSync = notImplementedFail(MODULE, 'fcntlSync')
|
||||
/** Unreached in the worker; loud refusal. */
|
||||
export const seek = notImplementedFail(MODULE, 'seek')
|
||||
/** Unreached in the worker; loud refusal. */
|
||||
export const seekSync = notImplementedFail(MODULE, 'seekSync')
|
||||
/** Unreached in the worker; loud refusal. */
|
||||
export const statVFS = notImplementedFail(MODULE, 'statVFS')
|
||||
|
||||
/** CommonJS interop marker: the worker loader hands `default` to default imports (see ./builtins.ts). */
|
||||
export const __esModule = true
|
||||
|
||||
/** The fs-ext face its consumers read. */
|
||||
export default { flock, flockSync, fcntl, fcntlSync, seek, seekSync, statVFS }
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Single-process worker replacement for `@deepseek-ai/node-addon-system/flock`.
|
||||
* The JSONL backend's in-process write claim already excludes every writer,
|
||||
* so its kernel-lock request succeeds without acquiring another resource.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Grant the single-process worker's exclusive-lock request immediately.
|
||||
* @param _fd - file descriptor (unused).
|
||||
* @returns an already-fulfilled promise.
|
||||
*/
|
||||
export function tryLockExclusive(_fd: number): Promise<void> {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
/** CommonJS interop marker for the worker module loader. */
|
||||
export const __esModule = true
|
||||
|
||||
/** The native flock API used by the JSONL backend. */
|
||||
export default { tryLockExclusive }
|
||||
+6
-7
@@ -1,16 +1,15 @@
|
||||
/**
|
||||
* Names of external npm packages the worker replaces wholesale. Kept in a module
|
||||
* with no imports so both consumers can read it: the runtime builtin table
|
||||
* (`./builtins.ts`) and the build-time VFS image collector, which must leave
|
||||
* these packages out of the image entirely — the loader answers them from the
|
||||
* bundle before it ever reaches `node_modules`.
|
||||
* Exact package or subpath specifiers served from the worker bundle. Kept
|
||||
* import-free for the runtime builtin table and the VFS image collector.
|
||||
* Whole-package entries are omitted from the image; subpath entries leave
|
||||
* their parent package available to other consumers.
|
||||
*/
|
||||
|
||||
/** External packages served from the worker bundle instead of the VFS. */
|
||||
/** Package or subpath specifiers served from the worker bundle instead of the VFS. */
|
||||
export const REPLACED_EXTERNAL_PACKAGES: readonly string[] = [
|
||||
'@earendil-works/pi-ai',
|
||||
'@vscode/ripgrep',
|
||||
'fs-ext',
|
||||
'@deepseek-ai/node-addon-system/flock',
|
||||
'koffi',
|
||||
'node-pty',
|
||||
'sharp',
|
||||
|
||||
Reference in new issue
Block a user