denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.4k stars 5.33k forks source link

Deno cache on a lock file #9950

Open KotlinIsland opened 3 years ago

KotlinIsland commented 3 years ago

I want to be able to pre-cache my dynamic dependencies, I have pre locked my dependencies but no way to cache them ahead of time.

deno cache lock.json should cache all dependencies specified in the file.

nayeemrmn commented 3 years ago

What command do you use to update your lock file? The command to cache all of the entries there should be the same / similar.

KotlinIsland commented 3 years ago

deno run --lock-write --lock lock.json mod.ts

nayeemrmn commented 3 years ago

So then deno cache mod.ts would cache everything in the lock file. What's the need for this feature?

KotlinIsland commented 3 years ago

deno cache mod.ts only caches the static dependencies, not the dynamic dependencies. deno run --lock-write mod.ts locks static and dynamic dependencies.

nayeemrmn commented 3 years ago

Ah didn't see it said deno run.

This isn't the correct way of locking dynamic dependencies, having to run the program is unreasonable for that. You should make a dummy module dynamic_imports.ts which imports every dynamically imported script used by your project. You can then update the lock file by running deno cache --lock-write --lock lock.json mod.ts dynamic_imports.ts, and cache with deno cache --lock lock.json mod.ts dynamic_imports.ts.

KotlinIsland commented 3 years ago

Sure that could be a good solution, but in my case it's a dependency that has dynamic dependencies, so I would have to deno run lock mod than copy paste the entries from the lock file into the dependencies.ts file. That's a lot of manual effort and duplication when it seems straightforward what deno cache lock.json would do.

tv42 commented 2 years ago

I wrote this terrible kludge:

import lock from "./lock.json" assert { type: "json" };

const child = Deno.run({
  cmd: [
    "deno",
    "cache",
    // Assume we're run from the top-level directory.
    "--lock=./lock.json",
    "--",
    ...Object.keys(lock),
  ],
});

const status = await child.status();
if (!status.success) {
  console.log(`error: exit code ${status.code}`);
  Deno.exit(status.code);
}