ventgrey
ventgrey
DDeno
Created by ventgrey on 10/9/2024 in #help
2.0 node_modules directory approach breaks when using private npm packages.
For some reason Deno 1.0 wasn't able to directly install private npm packages when using deno add. An alternative solution using .npmrc configuration files and enabling nodeModulesDir inside deno.json made it simpler as you would only need to deno cache <entrypoint.ts> to download your private npm package to the projects node_modules directory. If such package is not present at that time inside the directory the deno compile command would fail when building container images. This is why node_modules/ is needed. However, Deno 2.0 changed this and now, no matter what approach you take, you end up with a container constantly erroring out saying: error: Unable to load /tmp/deno-compile-example_app/app/node_modules/.deno/@my-org+mylib@1.0.0/node_modules/@my-org/mylib/index.js imported from file:///tmp/deno-compile-example_app/app/src/app.ts. Is there a way to force things to work using a deno.json file? I see that the option can now be set to manual, but why on earth would I want to go back to a package.json file? Should I just manually copy cache directories at build time inside the image to trick deno into symlinking them into the node_modules directory?
4 replies
DDeno
Created by ventgrey on 7/25/2024 in #help
Help with FFI strings
I've been testing with the deno FFI to see if it's powerful enough to leverage the power of other languages into Deno. This however has been very unfruitful as FFI documentations seems to be "everywhere" when it comes to types, take for example anything that returns a char*. There are very few hints on how is one supposed to handle such returns. I was working with a function similar to this: extern char* searchByDinoSpecies(char* dinosaursString, char* species); You can assume the dinosaurString to be a JSON string or a YAML string, idk. Whatever your compiled C-grandson language lets you handle In my search I found this article: https://medium.com/deno-the-complete-reference/calling-c-functions-from-deno-part-2-pass-buffers-ad168a3b6cc7 However, two problems arise from here: 1. You cannot use the pointer type in parameters: [] when loading my dylib because I'll get a TypeError: Invalid FFI pointer type, expected null, or External Reading the official Deno docs, the documentation states:
buffer type accepts TypedArrays as parameter, but it always returns a pointer object or null when used as result type like the pointer type.
- Source: https://docs.deno.com/runtime/manual/runtime/ffi_api/ Okay, so maybe everything as a buffer should work? Well, both parameters sure work when setting buffer but another problem arises. The output, either pointer or buffer is completely useless. The previous Medium Post shows something like this:
const ret = dylib.symbols.toAndFroBuffer(buffer);
const dataView = new Deno.UnsafePointerView(ret);
const ret = dylib.symbols.toAndFroBuffer(buffer);
const dataView = new Deno.UnsafePointerView(ret);
However, when tried to replicate this, another TypeError arises:
Argument of type 'PointerValue<unknown>' is not assignable to parameter of type 'PointerObject<unknown>'.
Type 'null' is not assignable to type 'PointerObject<unknown>'
Argument of type 'PointerValue<unknown>' is not assignable to parameter of type 'PointerObject<unknown>'.
Type 'null' is not assignable to type 'PointerObject<unknown>'
Discord has an awfully lame limit, continuing in the comments (?)
13 replies