Zicklag
Zicklag•2w ago

I have a JSR Package: Can I Import it From My Filesystem Instead of jsr.io?

Hello! 👋 I have a JSR package, but I'm doing some local development and I have an app that imports my SDK JSR package, and the SDK imports more library packages in a Deno workspace. I need to be able to test my local changes without having to publish a new version of the JSR package each time, but I'm not sure how to do that. I tried to use "patch", but one of my JSR libs also depends on an NPM package, and it seems that the NPM package is not properly loaded. Specifically, I have a workspace with some libraries on GitHub: muni-town/leaf, and I have an SDK that uses a library in that workspace muni-town/roomy-sdk. I can't figure out how to open the Roomy SDK repo, and have it use my local version of Leaf so that the package appears to type correctly in VSCode.
8 Replies
Zicklag
ZicklagOP•2w ago
I've tried just switching my imports map in the Roomy SDK to specify the index.ts of the package it's trying to import, the issue is that index.ts imports loro-crdt which is in its import map, and the import maps are not merged. I.e. there's no way for me to add another package on my local filesystem as a dependency by specifying, for example, it's jsr.json file or deno.json file, so that it properly handles the module exports, and import maps.
Doctor 🤖
Doctor 🤖•2w ago
I can't speak for the typings in your IDE, but the actual running should be done via the "patch" property deno.json of package to import:
{
"name": "@img/png",
"version": "0.1.3",
"exports": "./mod.ts"
}
{
"name": "@img/png",
"version": "0.1.3",
"exports": "./mod.ts"
}
deno.json of package being ran:
{
"imports": {
"@img/png": "jsr:@img/png@0.1.3",
},
"patch": ["path to directory of other deno.json"]
}
{
"imports": {
"@img/png": "jsr:@img/png@0.1.3",
},
"patch": ["path to directory of other deno.json"]
}
The versions must match or it won't patch it
i_use_arch_btw
i_use_arch_btw•2w ago
I wish Deno can resolve "path" dependencies in a similar way as Cargo does (or Elixir's Mix). Without dealing with patches, just specify path to a Deno project and it will do the magic for you.
duesabati
duesabati•2w ago
If you are using workspaces it works without any configurations
Zicklag
ZicklagOP•2w ago
Yeah, the workspace worked really nice for the repo with a bunch of libraries in it, but it doesn't work when I have code in two different Git repos. Trying that it tells me that it requires an unstable npm-patch flag because the lib I'm patching depends on an NPM package, and then if I add that flag and try to run the project it says:
error: Could not find "loro-crdt" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `deno install`?
at file:///home/zicklag/git/muni-town/leaf/packages/leaf/index.ts:22:15
error: Could not find "loro-crdt" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `deno install`?
at file:///home/zicklag/git/muni-town/leaf/packages/leaf/index.ts:22:15
It appears that it's not installing the npm package that is depended on by the library I'm patching. Ahhh, just figured it out, I need to also set the nodeModulesDir setting to "auto". Finally it works! Thanks folks!
marvinh.
marvinh.•2w ago
@i_use_arch_btw that's exactly what the patch feature in deno.json does. It works the same way as path in Cargo. We just picked a different name that is more familiar to JS devs
i_use_arch_btw
i_use_arch_btw•2w ago
Wow, this is amazing then!
Doctor 🤖
Doctor 🤖•2w ago
The last I looked, which was a while ago, there isn't a lot of documentation on the patch property.

Did you find this page helpful?