denoland / node_shims

npm packages providing shims for the Deno namespace and other globals. Useful for running Deno-first programs on Node.
MIT License
149 stars 29 forks source link

TypeError: dntShim.Deno.seekSync is not a function #142

Open alexgleason opened 1 year ago

alexgleason commented 1 year ago

When trying to transpile with shims, I get the following error:

FAILURES

blocks events that post the same content too quickly
  TypeError: dntShim.Deno.seekSync is not a function
      at js_read (file:///home/alex/Projects/strfry-policies/npm/esm/deps/deno.land/x/sqlite@v3.7.1/build/vfs.js:42:26)
      at wasm://wasm/0027cea2:wasm-function[84]:0x16fc
      at wasm://wasm/0027cea2:wasm-function[379]:0x236f6
      at wasm://wasm/0027cea2:wasm-function[373]:0x22415
      at wasm://wasm/0027cea2:wasm-function[385]:0x23c12
      at wasm://wasm/0027cea2:wasm-function[20]:0xf0f
      at wasm://wasm/0027cea2:wasm-function[1407]:0x9311b
      at file:///home/alex/Projects/strfry-policies/npm/esm/deps/deno.land/x/sqlite@v3.7.1/src/db.js:86:135
      at setStr (file:///home/alex/Projects/strfry-policies/npm/esm/deps/deno.land/x/sqlite@v3.7.1/src/wasm.js:13:24)
      at new DB (file:///home/alex/Projects/strfry-policies/npm/esm/deps/deno.land/x/sqlite@v3.7.1/src/db.js:86:24)error: Uncaught (in promise) Error: npm run test failed with exit code 1
        throw new Error(
              ^
    at runCommand (https://deno.land/x/dnt@0.34.0/lib/utils.ts:57:15)
    at async build (https://deno.land/x/dnt@0.34.0/mod.ts:386:5)
    at async file:///home/alex/Projects/strfry-policies/scripts/npm.ts:5:1
dsherret commented 1 year ago

I looked into this briefly and it seems that Node doesn't have a way to seek from the current position or end of the file. It seems some people do it by adding native bindings (ex. https://github.com/baudehlo/node-fs-ext/blob/3125353321c30bd35fc38e40ce76ffe3872e215b/fs-ext.js#L113).

I tried to at least have seek from the start of the file, but it didn't seem to work: https://github.com/dsherret/node_deno_shims/tree/seek

AlexanderOMara commented 1 week ago

Currently null is being passed to read, so it uses the current file offset.

https://github.com/denoland/node_shims/blob/f8c972520e4286082117729d1ab347aaabaf55af/packages/shim-deno/src/deno/stable/functions/read.ts#L16

In the absence of a way to seek, I think the only way to do this would be to internally track the position instead of passing null.

https://nodejs.org/api/fs.html#fsreadfd-buffer-offset-length-position-callback

Would need to setup some mapping between FD and position.

AlexanderOMara commented 1 week ago

Create a PR to implement seek functions in the only way I think is really possible.

https://github.com/denoland/node_shims/pull/189