thesmartwon
thesmartwon3w ago

Read dependency directory

Is it possible for a library to read its own non-importable files? I'm publishing some static files in a library. I'd like for that library to copy the files wherever the user wants. Is there a way without transforming those files into importable JSON or JS files? Library:
Deno.statSync(import.meta.resolve("./static").replace("file://", ""));
Deno.statSync(import.meta.resolve("./static").replace("file://", ""));
This works great inside the library. However, outside it will error:
error: Uncaught (in promise) NotFound: No such file or directory (os error 2): stat 'https:/jsr.io/@scope/package/version/static'
Deno.statSync(Deno.statSync(import.meta.resolve("./static").replace("file://", "")););
^
at Object.statSync (ext:deno_fs/30_fs.js:415:3)
...
error: Uncaught (in promise) NotFound: No such file or directory (os error 2): stat 'https:/jsr.io/@scope/package/version/static'
Deno.statSync(Deno.statSync(import.meta.resolve("./static").replace("file://", "")););
^
at Object.statSync (ext:deno_fs/30_fs.js:415:3)
...
2 Replies
Óscar
Óscar3w ago
I think it's only possible with fetch
thesmartwon
thesmartwonOP3w ago
fetch is a dirty workaround that requires enumerating all the files in the directory and being online. Using NPM to host the library and "nodeModulesDir": "auto" works. However, I've now run into another issue:
error: TSX files are not supported in npm packages
error: TSX files are not supported in npm packages
I hate to say this, but this is the straw that broke my back. I've had a lot of module interop problems (even on the ESM + JSR happy path...). I'm moving all my packages off Deno and JSR.

Did you find this page helpful?