Deno import maps and lock file

Viewed 731

As far as I know, Deno lock files can only be created when using a TypeScript (or JavaScript) file with all the imports on it — usually from a deps.ts file.

I would like to be able to use (the unstable yet) import maps and also generate that lock file based on it.

Is it possible to generate that lock file from an import_map.json file? If it's not possible, is there any other way to use a deps.ts file, for instance, an be able to map the dependencies in order to import them without using (the infamous) ./.. everywhere?

Moreover, looks like using the paths feature on a tsconfig.json file wouldn't do since I don't have any idea how to refer to any module on it.

2 Answers

You cannot directly generate a lock file based on an import map yet. But you can pass the entry file of your program along with the import map to generate a lock file.

Here's an example.

log.ts:

import { green } from "colors";
console.log(`Status: ${green("OK")}`);

deps.json (import map):

{
  "imports": {
    "colors": "https://deno.land/std@0.88.0/fmt/colors.ts"
  }
}

Now run the following command to generate a lock file.

deno cache --import-map=deps.json --unstable --lock=lock.json --lock-write log.ts

The content of lock.json might look like below.

{
  "https://deno.land/std@0.88.0/fmt/colors.ts": "db22b314a2ae9430ae7460ce005e0a7130e23ae1c999157e3bb77cf55800f7e4"
}

Another solution that works very closely or better since it actually scans through all the dependencies the project uses is to run: deno test --no-run --import-map import-map.json --lock lock.json --lock-write.

Related