bombillazo
bombillazo15mo ago

How can one patch a Deno dependency?

Hello, We're used to working with node and using patch-package to override and fix packages fairly easily. However, we're now using Deno due to using Supabase edge functions and have not figure a way to get the same dev experience. Is there any guide or way one can patch a dependency in Deno?
6 Replies
Mark G
Mark G15mo ago
You can use import maps to map pretty much any module URL, lets say for example you want to use 0.200.0 of std lib everywhere, but some libs are using an older version, say 0.192.0, you can add this into your import map:
"imports": {
"https://deno.land/std@0.192.0/": "https://deno.land/std@0.200.0/"
}
"imports": {
"https://deno.land/std@0.192.0/": "https://deno.land/std@0.200.0/"
}
can also target individual modules, eg:
"imports": {
"https://deno.land/std@0.161.0/encoding/base64.ts": "https://deno.land/std@0.200.0/encoding/base64.ts"
}
"imports": {
"https://deno.land/std@0.161.0/encoding/base64.ts": "https://deno.land/std@0.200.0/encoding/base64.ts"
}
Mark G
Mark G15mo ago
you can also use "scopes" in the import map to limit the scope of the mapping too... https://github.com/WICG/import-maps#scoping-examples ... although I've never needed to resort to this
GitHub
GitHub - WICG/import-maps: How to control the behavior of JavaScrip...
How to control the behavior of JavaScript imports. Contribute to WICG/import-maps development by creating an account on GitHub.
Mark G
Mark G15mo ago
oh, you mentioned patching though, in which case if you want to override a library module with a local one you can do that too...
"https://blahblah/foo/iffy-module.ts": "./patched/iffy-module.ts"
"https://blahblah/foo/iffy-module.ts": "./patched/iffy-module.ts"
bombillazo
bombillazoOP15mo ago
Hey, thanks for the info! So if I use an import_map.json and set a imports key to another version, all depedencies and sub dependencis that use the original verison will now point to the new one? Ok I guess I can answer my own question: yes hence the need/use of "scopes"
Leokuma
Leokuma15mo ago
Also have a look at the command deno vendor. It downloads all deps into a folder
bombillazo
bombillazoOP15mo ago
Thanks! I ended up using deno vendor to pull the deps into a folder then using that to create our patched version and import it locally. 😁