Why does Deno use a lock file like deno.lock when managing dependencies?
Think about how to keep your project stable and avoid surprises when dependencies change.
A lock file records the exact versions and cryptographic hashes of dependencies. This ensures that every time you run or build your project, you use the same code, preventing unexpected bugs from updated dependencies.
Given a deno.lock file exists, what will happen if you run deno run script.ts without --lock=deno.lock?
Consider if the lock file is automatically enforced or requires explicit use.
Deno requires the --lock flag to enforce the lock file. Without it, Deno fetches dependencies as usual, ignoring the lock file, which can lead to different versions being used.
Select the command that creates or updates the deno.lock file based on current dependencies.
Look for the flag that both uses and writes the lock file during execution.
The --lock-write flag tells Deno to write or update the lock file. It must be combined with --lock=deno.lock to specify the file. This command runs the script and updates the lock file accordingly.
You run deno run --lock=deno.lock script.ts but get an error about lock file mismatch. What is the most likely cause?
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"; serve(() => new Response("Hello"));
Think about what happens if dependencies change but the lock file stays the same.
If dependencies or their versions change but the lock file is not updated using --lock-write, Deno detects a mismatch and refuses to run to protect integrity.
Consider you have a deno.lock file and run deno run --lock=deno.lock script.ts without --lock-write. What happens if a dependency's remote code has changed since the lock file was created?
Think about how lock files protect against unexpected changes in dependencies.
When using --lock without --lock-write, Deno verifies that the fetched dependencies match the hashes in the lock file. If they differ, Deno refuses to run to prevent using unverified code.
