An implementation of WICG Import Maps specification

Overview

import_map

Discord Chat

A Rust implementation of WICG Import Maps specification.

This crates is used in Deno project.

The implementation is tested against WPT test suite.

Developing

Make sure to have latest stable version of Rust installed (1.55.0).

// check version
$ rustc --version
rustc 1.55.0 (c8dfcfe04 2021-09-06)

// checkout git submodules
$ git submodule update --init --recursive

// build all targets
$ cargo build --all-targets

// test it
$ cargo test

Opening a pull request

  1. Format code: rustfmt ./src/lib.rs

  2. Check that clippy doesn't produce warnings: cargo clippy --all-targets --all-features --release -- -D clippy::all

Comments
  • feat: allow query string in imports

    feat: allow query string in imports "address"

    • resolve() will append the query string for both exact and prefix mapping
    • import statement query string will override the query string from import map
    • lookup() will not consider any query string

    Closes https://github.com/denoland/import_map/issues/46

    @bartlomieju

    opened by marcushultman 4
  • feat: use Url for the base specifier instead of str

    feat: use Url for the base specifier instead of str

    When I went to go integrate this into Deno, I found that there was some extra complexity we were doing by converting back and forth between Url and str. It's easier to just use Url for the base here.

    opened by dsherret 2
  • feat: add

    feat: add "graph" feature

    This PR adds an optional feature of graph which allows an import map to be used as a Resolver with deno_graph, and thereby be integrated into the CLI.

    opened by kitsonk 2
  • fix: handle npm packages in imports

    fix: handle npm packages in imports

    This commit adds handling of "npm:" specifiers in mapping. Specifically when mapping "packages" it prints out a diagnostics that the target must use "npm:/" instead of "npm:" (because the latter is not a valid base URL).

    opened by bartlomieju 0
  • feat: add TypeScript/Wasm interface

    feat: add TypeScript/Wasm interface

    Needing to add dependency analysis for deno.land/x module documentation and need to be able to resolve specifiers with an import map, so exposing the import map crate as wasm makes sense instead of using something implemented just in JavaScript/TypeScript.

    opened by kitsonk 0
  • fix: use raw key with lookup

    fix: use raw key with lookup

    The lookup API was using the stored key, which when the there is a leading / it stores the key as relative to the base url. Previous versions incorrectly tried to strip just file:// from the key which breaks on windows. This now uses the raw_url of the value which should provide correct output in every scenario.

    opened by kitsonk 0
  • feat: add lookup api

    feat: add lookup api

    This adds a .lookup() API to an ImportMap. This effectively "reverses" a resolution, returning a import specifier string that would resolve to the same url specifier, but via the import map.

    This is part of the journey of allowing the language server to offer quick fixes and auto import completions which identify to the user a situation where an import specifier can be remapped to an import map.

    opened by kitsonk 0
  • feat: basic manipulation and ability to write out import map to JSON

    feat: basic manipulation and ability to write out import map to JSON

    This will be used in deno vendor.

    Adds:

    • with_folder_removed(&self, folder: &Url) -> Self - Ability to remove a certain folder from the import map (will use this in deno vendor to remove the output directory)
    • to_json() -> String - Gets the import map as JSON text.
    • imports_mut().append(key, value)
    • get_or_append_scope_mut(key)
    opened by dsherret 0
  • feat: expose base url

    feat: expose base url

    In deno vendor if someone provides an import map in the vendor folder, then it should be ignored (ex. someone runs deno vendor then does deno vendor --import-map vendor/import_map.json). This will matter more once we have automatic deno.json import map resolution.

    Although the base url could be stored along with the import map in deno's proc state, it's much easier to just add this method here.

    opened by dsherret 0
  • refactor: remove json feature

    refactor: remove json feature

    As it turns out... it was way easier for me to just use the json feature in dnt. My bad! 🙈 I should refrain from opening PRs in other repos until I'm completely done implementing a feature (I have learned my lesson).

    I also agree that there doesn't seem to be a good reason to not use the json method of doing things and so I've refactored this back.

    opened by dsherret 0
  • Add more tests for diagnostic scenarios

    Add more tests for diagnostic scenarios

    We should add tests for the diagnostic scenarios because now it's easily testable. Not critical though and something for the future. Would be a good first issue for someone. Basically, just write more tests that check the diagnostic scenarios:

    https://github.com/denoland/import_map/blob/c505b8397f8ce0c8b88db2a01c8fb8447ae6f717/src/lib.rs#L535-L540

    good first issue help wanted 
    opened by dsherret 0
  • can't map prefixed address with query string

    can't map prefixed address with query string

    Using import_map.json

    {
      "imports": {
        "icons-solid-20/": "https://esm.sh/@heroicons/[email protected]/20/solid/?alias=react:preact/compat"
      }
    }
    

    With script:

    import 'icons-solid-20/BeakerIcon';
    

    Will yield error:

    Import map diagnostics:
      - Invalid target address "https://esm.sh/@heroicons/[email protected]/20/solid/?alias=react:preact/compat" for package specifier "icons-solid-20/". Package address targets must end with "/".
    error: Blocked by null entry for ""icons-solid-20/""
    

    Even when putting in a bogus query parameter that ends with "/", the following error is produced:

    error: The specifier ""icons-solid-20/BeakerIcon"" backtracks above its prefix ""icons-solid-20/""
    
    opened by marcushultman 1
  • Panic upon invalid import involving an import map

    Panic upon invalid import involving an import map

    Under Deno 1.23.3 and 1.24.0, it is possible to produce a panic when running deno check given a particular invalid import configuration.

    See a minimal repro here.

    Panic trace:

    ============================================================
    Deno has panicked. This is a bug in Deno. Please report this
    at https://github.com/denoland/deno/issues/new.
    If you can reliably reproduce this panic, include the
    reproduction steps and re-run with the RUST_BACKTRACE=1 env
    var set and include the backtrace in your report.
    
    Platform: macos aarch64
    Version: 1.24.0
    Args: ["/Users/henx/.deno/bin/deno", "check", "repro.ts"]
    
    thread 'main' panicked at 'assertion failed: resolution_result.to_string().ends_with(\'/\')', /Users/ib/.cargo/registry/src/github.com-1ecc6299db9ec823/import_map-0.12.1/src/lib.rs:942:5
    stack backtrace:
       0: _rust_begin_unwind
       1: core::panicking::panic_fmt
       2: core::panicking::panic
       3: import_map::resolve_imports_match
       4: import_map::ImportMap::resolve
       5: <deno::resolver::ImportMapResolver as deno_graph::source::Resolver>::resolve
       6: deno_graph::graph::resolve
       7: deno_graph::graph::parse_module_from_ast
       8: deno_graph::graph::parse_module
       9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
      10: deno::proc_state::ProcState::prepare_module_load::{{closure}}
      11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
      12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
      13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
      14: deno::main::{{closure}}
      15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
      16: deno_runtime::tokio_util::run_local
      17: deno::main
    
    bug 
    opened by hen-x 1
  • Improve Diagnostics

    Improve Diagnostics

    Diagnostics for an import map should include locations/spans of errors in the source file, to make printing and using the diagnostics in language servers more useful.

    @dsherret just added a strict parse mode to https://crates.io/crates/jsonc-parser, which can be used to parse and walk the JSON structure to improve the diagnostics. We should use that for parsing the import map and generating diagnostics.

    enhancement 
    opened by kitsonk 0
  • Import Maps don't support package address targets with query parameters

    Import Maps don't support package address targets with query parameters

    Reproduce:

    • Deno v1.23.3
    • import_map.json:
    {
      "imports": {
          "@mui/": "https://esm.sh/@mui/[email protected]/?alias=react:preact/compat,react/jsx-runtime:preact/compat/jsx-runtime&[email protected]"
      }
    }
    

    Deno then reports back with:

    Package address targets must end with "/".

    I couldn't find a current code snippet, but for version 1.9.1 I found this check, which doesn't account for esm.sh alias feature, because it just checks the last character of the value string.

    If you have any further questions, please let me know

    opened by NicolaiSchmid 2
  • fix: Make lookup result relative to referrer

    fix: Make lookup result relative to referrer

    Discovered while looking into https://github.com/denoland/deno/issues/15266. The current import-map-relative design could pass as intentional, but that wasn't the way it was being used in cli and I think adjusting to the passed referrer makes more sense.

    Also account for conflicts in lookup_imports(). Choose the least specific matching prefix key, rewrite the specifier with it, make sure the rewritten specifier isn't overrided by some other more specific prefix key. e.g.

    // import_map.json
    {
      "imports": {
        "a/": "https://foo.com/",
        "a/b/": "https://bar.com/"
      }
    }
    

    import_map.lookup("https://foo.com/b/c") should match the first entry, rewrite it to "a/b/c", realise that this conflicts with the second entry (it would be remapped to https://bar.com/c) and discard it.

    opened by nayeemrmn 2
  • Can't use this within a project with `wasm-bindgen` due to cyclic dependency

    Can't use this within a project with `wasm-bindgen` due to cyclic dependency

    • import_map enables serde_json/preserve_order
    • serde_json/preserve_order depends on indexmap (https://docs.rs/crate/serde_json/latest/features)
    • indexmap depends on hashbrown
    • hashbrown depends on ahash by default.
    • ahash depends on const-random

    and the result is

    ❯ cargo check
        Updating crates.io index
    error: cyclic package dependency: package `ahash v0.7.6` depends on itself. Cycle:
    package `ahash v0.7.6`
        ... which satisfies dependency `ahash = "^0.7.0"` of package `hashbrown v0.11.2`
        ... which satisfies dependency `hashbrown = "^0.11"` of package `indexmap v1.8.0`
        ... which satisfies dependency `indexmap = "^1.5"` of package `serde_json v1.0.79`
        ... which satisfies dependency `serde_json = "^1.0"` of package `wasm-bindgen v0.2.79`
        ... which satisfies dependency `wasm-bindgen = "^0.2.79"` of package `js-sys v0.3.56`
        ... which satisfies dependency `js-sys = "^0.3"` of package `getrandom v0.2.3`
        ... which satisfies dependency `getrandom = "^0.2.0"` of package `const-random-macro v0.1.13`
        ... which satisfies dependency `const-random-macro = "^0.1.13"` of package `const-random v0.1.13`
        ... which satisfies dependency `const-random = "^0.1.12"` of package `ahash v0.7.6`
    
    
    opened by kdy1 2
Owner
Deno Land
Deno Land
Didactic implementation of the type checker described in "Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorphism" written in OCaml

bidi-higher-rank-poly Didactic implementation of the type checker described in "Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorph

Søren Nørbæk 23 Oct 18, 2022
A fast R-tree for Rust. Ported from an implementation that's designed for Tile38.

rtree.rs A fast R-tree for Rust. Ported from an implementation that's designed for Tile38. Features Optimized for fast inserts and updates. Ideal for

Josh Baker 102 Dec 30, 2022
AI-TOML Workflow Specification (aiTWS), a comprehensive and flexible specification for defining arbitrary Ai centric workflows.

AI-TOML Workflow Specification (aiTWS) The AI-TOML Workflow Specification (aiTWS) is a flexible and extensible specification for defining arbitrary wo

ruv 20 Apr 8, 2023
browse modules by clicking directly on "import" statements on GitHub ⛺

Module Linker Module Linker adds direct links in the GitHub source code viewer, to any imported modules or files. If you're browsing source code on Gi

fiatjaf 246 Dec 10, 2022
Convert Hygea calendar to an iCal file to easily import it to Google Calendar (Rust version)

Hygea to iCal Goal Hygea provides a calendar via PDF and an application called Recycle. I just wanted to use an iCal file to import it in my calendar.

Guillaume Quittet 2 Oct 28, 2021
import sticker packs from telegram, to be used at the Maunium sticker picker for Matrix

mstickereditor Import sticker packs from telegram, to be used at the Maunium sticker picker for Matrix Requirements: a Stickerpickerserver msrd0/docke

null 11 Dec 27, 2022
Tool for mass import of hosts into Zabbix (and other API functions)

zabbix-tools A CLI tool for interacting with Zabbix API built in Rust. Designed for Zabbix 6.0. Functions added to test API and add hosts manually or

null 1 Apr 21, 2022
Standalone python3.dll import library generator

Standalone python3.dll import library generator Generates import libraries for the Stable ABI Python DLL for MinGW-w64 and MSVC (cross-)compile target

PyO3 7 Oct 9, 2022
Radix Babylon vanity address finder allowing easy import into Radix mobile Wallet.

Rad Vanity address finder for Radix Babylon which you can import directly into your Radix Wallet using QR scanner using Import from a Legacy Wallet fe

Alexander Cyon 6 Nov 13, 2023
Rust library for Self Organising Maps (SOM).

RusticSOM Rust library for Self Organising Maps (SOM). Using this Crate Add rusticsom as a dependency in Cargo.toml [dependencies] rusticsom = "1.1.0"

Avinash Shenoy 26 Oct 17, 2022
Represent large sets and maps compactly with finite state transducers.

fst This crate provides a fast implementation of ordered sets and maps using finite state machines. In particular, it makes use of finite state transd

Andrew Gallant 1.5k Jan 5, 2023
Compile time static maps for Rust

Rust-PHF Documentation Rust-PHF is a library to generate efficient lookup tables at compile time using perfect hash functions. It currently uses the C

null 1.3k Jan 1, 2023
Native Maps for Web, Mobile and Desktop

mapr Native Maps for Web, Mobile and Linux A map rendering library written in Rust. Example | Book | API | Chat in Matrix Space Project State This pro

MapLibre 942 Jan 2, 2023
Generate Rust register maps (`struct`s) from SVD files

svd2rust Generate Rust register maps (structs) from SVD files This project is developed and maintained by the Tools team. Documentation API Minimum Su

Rust Embedded 518 Dec 30, 2022
A simple /proc//{mem,maps} library for Rust

Summary A very simple library that wraps around /proc/pid/mem and /proc/pid/maps to read memory out of a running process on Linux. Usage Basic usage l

null 6 Jul 27, 2022
Game about automating terraformation in 3D maps, ant-style.

Bioengineer Play the game https://jmmut.itch.io/bioengineer At the moment you can play in the browser (playable with mouse and keyboard), and the plan

jmmut 3 Nov 7, 2022
A command line tool and Rust library for working with recombination maps.

RecMap library (and command line tool) for reading and working with recombination maps in Rust A RecMap object can be created from reading in a HapMap

Vince Buffalo 5 Feb 11, 2024
Dynamic, Type-Erased Key-Value Maps in Rust

Dynamic Objects in Rust Do you love Rust but are tired of being constrained by static typing when you need a map to hold values of different types? Do

Travis A. Wagner 12 Feb 25, 2024
A Kubernetes implementation of the Open Application Model specification

Rudr ?? NOTE: Rudr is deprecated in favor of the upcoming open application platform project as its successor. There are no plans to produce future rel

Open Application Model 1.6k Jan 4, 2023
A client and server implementation of the OPC UA specification written in Rust

Introduction This is an OPC UA server / client API implementation for Rust. Linux Windows OPC UA is an industry standard for monitoring of data. It's

null 362 Dec 30, 2022