callmephilip
callmephilip2w ago

Cannot access files inside package when running from jsr

I have the following "init" script populating new project using files in project-template
import path from "node:path";

// ...

if (import.meta.main) {
copySync(new URL("../project-template", import.meta.url), projectPath, {
overwrite: false,
});
}
import path from "node:path";

// ...

if (import.meta.main) {
copySync(new URL("../project-template", import.meta.url), projectPath, {
overwrite: false,
});
}
When invoked locally it works as expected. However, if I attempt to run it from jsr like so
deno run -R -W jsr:@myorg/stuff/init
deno run -R -W jsr:@myorg/stuff/init
It fails since meta resolves as https://jsr.io/@myorg/stuff/0.1.21/project-template. How can I get this to work consistently both locally and remotely? How do you guys usually handle this sorts of stuff?
2 Replies
callmephilip
callmephilipOP2w ago
Looking at how fresh does it - https://github.com/denoland/fresh/blob/main/init/src/init.ts. Not a huge fan of this approach tbh
GitHub
fresh/init/src/init.ts at main · denoland/fresh
The next-gen web framework. Contribute to denoland/fresh development by creating an account on GitHub.
Leokuma
Leokuma2w ago
If it's a simple init script that doesn't depend on an import map or deno.json, you can try to run it via HTTPS:
deno run https://jsr.io/@myorg/stuff/0.1.21/project-template/init.ts
deno run https://jsr.io/@myorg/stuff/0.1.21/project-template/init.ts
If it does depend on deno.json, I don't know how to make it work

Did you find this page helpful?