question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

importmap command

See original GitHub issue

add a importmap command to manage the import_map.json:

$ aleph importmap add @npm/react

  -> 17.0.1
  -  16.14.0
  -  16.13.1
  -  other

$ aleph importmap add std/hash
$ aleph importmap add aleph
$ aleph importmap add aleph@1.0.0/mod.ts --name aleph
$ aleph importmap add aleph --cdn nest.land
$ aleph importmap add @npm/react@17.0.1 --cdn skypack
$ aleph importmap update

supported sources:

  • npm packages via esm.sh
  • deno.land/std
  • deno.land/x

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
argonaut0commented, Aug 23, 2021

Currently I have this implemented:

Usage:
    aleph importmap [dir] <...options>

[dir] : Directory of the import map, defaults to current directory.

Options:
____________________________________________________________________________
    -a, --add    <moduleID[@version]>  Add a module to the import map.

        --name   <alias>             Alias to use in import map.

        --path   <address>           Manually specify the address to map to.
                                     Requires --name.

        --rolling                    (NOT RECOMMENDED) Don't pin module to a
                                     specific version (always latest).
____________________________________________________________________________
    -r, --remove <module>            Remove a module from the import map.
____________________________________________________________________________
    -u, --update                     Update all modules in the import map.

        --update <module>            Update a module to the latest version.

Supports esm.sh, deno.land/std/, and deno.land/x/ so far.

The command will query NPM and deno.land respectively to make sure the versions exist. It also queries deno.land to make sure the specific file/folder that is specified actually exists on that version.

I made some assumptions for deno.land module specifier resolution for now, it works like this:

  • If the specifier ends with a ‘/’, it’s assumed to be an alias for a directory
  • If the specifier ends with '.ts, it’s assumed to be an import for a file
  • If the specifier does not end in a ‘/’ or ‘.ts’, ‘mod.ts’ is appended to the end.
    • This should probable change, because if you forget to add the trailing slash when referring to a directory, the tool errors out and tells you the directory does not have a mod.ts in it. However, I don’t know how much we want to magically resolve things, so I just left it like this for now.

Examples:

I probably made other assumptions but this is a good enough mvp for now. Feedback appreciated!

1reaction
shadowtime2000commented, Feb 19, 2021

This could definitely become it’s own /x/ package because of usefulness, but prob best to start off of small by keeping it here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importmap for Rails
bin/importmap command that's added as part of the install to pin, unpin, or update npm packages in your import map. This command uses...
Read more >
Import Maps Under the Hood in Rails 7
importmap is an executable file that loads a config/application.rb file from your project and the import maps commands file. Import maps use the ......
Read more >
Importmaps
bin/importmap command that's added as part of the install to pin , unpin , or update npm packages in your import map. This...
Read more >
How to use Import Maps in Rails 7 (with examples)
If you want to install a library using a JSPM CDN you simply need the pin command and the library name. Run: ./bin/importmap...
Read more >
How to Dynamically Import JavaScript with Import Maps
The command will ask you if you want to install a package. ... An import map is a JavaScript object where the key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found