Skip to content

Instantly share code, notes, and snippets.

@guest271314
Created December 31, 2023 13:18
Show Gist options
  • Save guest271314/c65965017b4e394cb7f40c7044e41f60 to your computer and use it in GitHub Desktop.
Save guest271314/c65965017b4e394cb7f40c7044e41f60 to your computer and use it in GitHub Desktop.
Install repositories from GitHub to node_modules for Deno

Deno doesn't have a way to install repositories from GitHub to the local node_modules folder.

// Creates node_modules folder in pwd
// import "npm:esbuild";
// import ...
const decoder = new TextDecoder();
// Download GitHub repository to node_modules/.deno, link in node_modules
async function installRepositoryFromGitHubToNodeModules(url) {
return new Deno.Command("/bin/bash", {
/*
cd node_modules/.deno
git clone "$1"
cd ..
ln -s "`pwd`/.deno/$2" "`pwd`"
*/
args: [
"install_from_github.sh",
url,
url.split("/").pop(),
],
}).output();
}
const { code, stdout, stderr } = await installRepositoryFromGitHubToNodeModules(
"https://github.com/guest271314/wbn-sign-webcrypto",
);
console.log([stdout, stderr].map((result) => decoder.decode(result)));
cd node_modules/.deno # Assumes node_modules folder exists in pwd
git clone "$1"
cd ..
ln -s "`pwd`/.deno/$2" "`pwd`"
@guest271314
Copy link
Author

I did not follow how Deno does that for import "npm:..." completely. I omitted creating a nested node_modules folder in node_modules/.deno/<module_name>/node_modules/<actual_module>. The code just creates node_modules/.deno/<actual_module> and links to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment