Lesson 5 of 9 · 26m
Dependency Security, Lockfiles, and JSR
Treat Deno dependencies as executable supply chain: pin versions, freeze lockfiles, review package provenance, and audit install-time behavior.
Deno removes node_modules as a visible pile of chaos, which creates the comforting illusion that dependency management is clean. The cache being tidy does not make the supply chain benign. Every remote module is still executable code selected by a version resolution process. Your job is to make that process reproducible, reviewable, and boring.
Understand the specifier landscape
import { serve } from "jsr:@std/http@^1.0.0/server";
import express from "npm:express@^4.21.0";
import helper from "./lib/helper.ts";JSR is a modern registry designed around ESM and TypeScript. npm is the compatibility ecosystem. Relative files are local. URL imports exist, but production teams usually centralize dependencies in deno.json rather than scattering registry decisions across source files.
Lockfiles are production controls
Generate and commit the lockfile:
deno cache --lock=deno.lock main.ts
git add deno.lock deno.json
deno run --frozen --allow-net=api.internal:443 main.ts--frozen tells Deno not to update the lockfile implicitly. This is the difference between reproducible deployment and "CI passed because it downloaded a different graph yesterday." Review lockfile diffs with the same suspicion you apply to code diffs.
Permissions do not protect install time
A package can execute code during installation or resolution before your carefully scoped runtime permissions matter. npm lifecycle scripts are the obvious example. Review dependency additions for:
postinstall scripts
native binary downloads
unexpected transitive dependencies
new maintainers or ownership changes
typosquat-adjacent names
network calls outside documented package registriesDeno can disable lifecycle scripts in some workflows, but the security decision belongs in dependency policy, not folklore.
Audit dependency purpose, not just vulnerability feeds
CVE scanners are useful but incomplete. Ask what a package does, how often it changes, whether it is maintained, and whether you need it at all. A ten-line helper dependency with forty transitive packages is not free because it has no known CVE today.
deno info main.ts
deno info --json main.ts | jq '.modules | length'Use dependency graph output in review. If a small feature adds hundreds of modules, that is a design decision and should be discussed as one.
Pin runtime versions too
Dependencies are only half of reproducibility. Deno itself evolves. Record the runtime version in CI, containers, or .tool-versions/mise configuration. A lockfile cannot protect you from behavior changes introduced by upgrading the runtime carelessly.
Field notes
- Commit
deno.lockfor deployable applications and enforce--frozenin release pipelines. - Review lockfile churn; unexpected transitive changes are a supply-chain signal.
- Prefer scoped host permissions even when dependency integrity is perfect — integrity is not intent.
- URL imports should be exceptional in production applications because they diffuse version governance.
- Vendoring centralizes review but makes update discipline more important, not less.
Was this lesson helpful?