esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

CLI assumes `import_map.json` even if `deno.json` has `imports`

Open farsightsoftware opened this issue 1 year ago • 4 comments

In a project using the imports key in deno.json/deno.jsonc instead of using importMap, the CLI still tries to use import_map.json instead. Running it always creates an import_map.json (whether you use add, update, or remove -- the last two just create an empty import map), Deno won't use an external import map if there's an imports (or scopes) section in the deno.json/deno.jsonc file.

Instead, it should look to see if imports is being used in deno.json, and manage entries in that section rather than import_map.json. If the file is a deno.jsonc, it should preserve comments.

As I mentioned in #686, I've found the jsonc-parser package that could be used for this. If I get time, would a PR using that to manage imports be welcome?

farsightsoftware avatar Jul 20 '23 08:07 farsightsoftware

I would recommend using the Deno standard library's jsonc parser (https://github.com/denoland/deno_std/tree/main/jsonc).

lino-levan avatar Jul 20 '23 14:07 lino-levan

@lino-levan The problem with that is that it just discards comments. See more on this in the other linked issue: #686. :-)

farsightsoftware avatar Jul 20 '23 14:07 farsightsoftware

@farsightsoftware does the parser of the std jsonc module discard comments or the stringifier?

Can you add an example to this Issue I made on the deno std lib repo?

https://github.com/denoland/deno_std/issues/3502

I'm currently a little short on time, otherwise I'd check it myself. Maybe you haven an example already?

bjesuiter avatar Jul 24 '23 09:07 bjesuiter

(I've replied here.)

farsightsoftware avatar Jul 24 '23 10:07 farsightsoftware