`deno vendor`: help with import_map.json changes from deno.land to jsr?

Hi - I'm hoping to get some guidance of best practices of migrating a (n admittedly complicated) import_map.json file from using https://deno.land/std@0.224.0 to jsr Our import map at Quarto currently contains entries like this:
"archive/": "https://deno.land/std@0.224.0/archive/",
"archive/": "https://deno.land/std@0.224.0/archive/",
We use this syntax because it allows us to do imports in our TS code like this: import { Tar } from "archive/tar.ts"; import { Zip } from "archive/zip.ts";, etc. This allows our import map to not worry about which of the tar.ts, zip.ts are going to be ultimately imported in our code. My specific problem is I'm having a hard time converting that to a jsr import, say
"archive/": "jsr:@std/archive@^0.224.0/",
"archive/": "jsr:@std/archive@^0.224.0/",
If I maintain the trailing / in the syntax, I get a failure like this when calling deno vendor:
error: Failed to resolve the specifier ""archive/tar.ts"" as its after-prefix
portion ""tar.ts"" could not be URL-parsed relative to the URL prefix
"jsr:@std/archive@^0.224.0/" mapped to by the prefix "archive/"
error: Failed to resolve the specifier ""archive/tar.ts"" as its after-prefix
portion ""tar.ts"" could not be URL-parsed relative to the URL prefix
"jsr:@std/archive@^0.224.0/" mapped to by the prefix "archive/"
But if I switch to an import_map statement like
"archive": "jsr:@std/archive@^0.224.0",
"archive": "jsr:@std/archive@^0.224.0",
then it seems that I need to declare each of the imports (tar, zip, etc) separately in the import map itself. That would be a big bummer and a source of ongoing maintenance toil for us, because the import_map will become much more brittle than before. Is there a way to import from jsr and retain the flexibility with paths we used to have in import maps and deno vendor? Thanks for the help!
17 Replies
Óscar
Óscar3mo ago
the problem is JSR removed the file extensions. So you have to do import { Tar } from "archive/tar"; (removing the file extension).
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
That doesn't work:
error: Relative import path "archive/tar" not prefixed with / or ./ or ../ and not in import map from "file:///Users/cscheid/repos/github/quarto-dev/quarto-cli/src/publish/common/bundle.ts"
error: Relative import path "archive/tar" not prefixed with / or ./ or ../ and not in import map from "file:///Users/cscheid/repos/github/quarto-dev/quarto-cli/src/publish/common/bundle.ts"
That is the error with the "archive": "jsr:@std/archive@^0.224.0", entry in the import map
Óscar
Óscar3mo ago
you have to add the trailing /
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
With "archive/": "jsr:@std/archive@^0.224.0/", I get a different error:
error: Failed to resolve the specifier ""archive/tar"" as its after-prefix
portion ""tar"" could not be URL-parsed relative to the URL prefix
"jsr:@std/archive@^0.224.0/" mapped to by the prefix "archive/"
error: Failed to resolve the specifier ""archive/tar"" as its after-prefix
portion ""tar"" could not be URL-parsed relative to the URL prefix
"jsr:@std/archive@^0.224.0/" mapped to by the prefix "archive/"
Óscar
Óscar3mo ago
oh I see. That's is because std is now splitted into multiple packages oh, never mind no idea. It should work
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
the message implies that the import map code is expecting a URL and is getting confused by a jsr: prefix
Óscar
Óscar3mo ago
are you using the lastest Deno version?
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
that's on 1.46.3
Óscar
Óscar3mo ago
yeah, I have the same error looks like jsr imports cannot end with trailing slashes. this works to me:
"archive": "jsr:@std/archive@^0.224.0"
"archive": "jsr:@std/archive@^0.224.0"
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
But then you can't do eg import * as tar from "archive/tar"; or even import { Tar } from "archive/tar", which is the point of my original question above.
Óscar
Óscar3mo ago
import { Tar } from "archive/tar"; this works in my end
Óscar
Óscar3mo ago
No description
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
I get
error: Relative import path "archive/tar" not prefixed with / or ./ or ../ and not in import map from "file:///Users/cscheid/repos/github/quarto-dev/quarto-cli/src/publish/common/bundle.ts"
error: Relative import path "archive/tar" not prefixed with / or ./ or ../ and not in import map from "file:///Users/cscheid/repos/github/quarto-dev/quarto-cli/src/publish/common/bundle.ts"
Note that this is specifically a deno vendor question
Óscar
Óscar3mo ago
ah, I think deno vendor is deprecated
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
I apologize - I should have been clearer wrt deno vendor, I now see I only mentioned that in the other post
Óscar
Óscar3mo ago
No description
Carlos Scheidegger
Carlos ScheideggerOP3mo ago
We need deno vendor because we need deno bundle (yes, I know that's also deprecated) And then that syntax you suggest fails with
Import map diagnostics:
- Invalid top-level key "vendor". Only "imports" and "scopes" can be present.
error: Relative import path "archive/tar" not prefixed with / or ./ or ../ and not in import map from "file:///Users/cscheid/repos/github/quarto-dev/quarto-cli/src/publish/common/bundle.ts"
Import map diagnostics:
- Invalid top-level key "vendor". Only "imports" and "scopes" can be present.
error: Relative import path "archive/tar" not prefixed with / or ./ or ../ and not in import map from "file:///Users/cscheid/repos/github/quarto-dev/quarto-cli/src/publish/common/bundle.ts"