deno icon indicating copy to clipboard operation
deno copied to clipboard

Only authorize import modules listed in the import map

Open udfordria opened this issue 1 year ago • 2 comments

Proposition

Having a way to only authorize dependencies listed in the imports block of the deno.json file.

Examples

This example should NOT work when I run deno run -A main.ts because the dependency is not listed in the imports block.

deno.json

{
  "imports": {}
}

main.ts

import { fib } from "jsr:@phocks/fib"; // Error not listed in deno.json

console.log(fib(3)); 

However, that example must work when I run deno run -A main.ts because the dependency is listed in the imports block.

deno.json

{
  "imports": {
    "fibonacci": "jsr:@phocks/fib"
  }
}

main.ts

import { fib } from "fibonacci"; // import from deno.json

console.log(fib(3)); 

udfordria avatar Oct 31 '24 09:10 udfordria

I'm a bit lost here, could you explain a bit more? Do you mean Deno should not send authorization headers for private registries?

bartlomieju avatar Oct 31 '24 11:10 bartlomieju

What I mean is to have an option to consider "imports" as a bill of materials. If one external dependency is not listed inside the "imports" and is used as import in my typescript code, the program must not work.

udfordria avatar Nov 01 '24 07:11 udfordria

I agree on adding this. It would be nice if this mode also didn't store anything in the lockfile that's not found in the deno.json/package.json

dsherret avatar Nov 23 '24 01:11 dsherret

@dsherret do you have an idea how it would be enabled? I think that banning npm:/jsr:/etc... specifier just by presence of deno.json is too restrictive and something we can't do in v2.x. Starting with an option in deno.json seems easy.

bartlomieju avatar Nov 23 '24 02:11 bartlomieju

I think this would be (at least partially) fixed by https://github.com/denoland/deno_lint/pull/1361.

bartlomieju avatar Nov 29 '24 01:11 bartlomieju