jspm / generator.jspm.io

8 stars 6 forks source link

Question: Support multiple versions of the same library? #32

Open zachsa opened 9 months ago

zachsa commented 9 months ago

Is it possible to include multiple versions of the same library within a single importmap? For example, something like this:

<script type="importmap">
  {
    "imports": {
      "react@17": "https://ga.jspm.io/npm:react@17.0.2/index.js",
      "react@18": "https://ga.jspm.io/npm:react@18.2.0/index.js"
    },
    "scopes": {
      "https://ga.jspm.io/": {
        "object-assign": "https://ga.jspm.io/npm:object-assign@4.1.1/index.js"
      }
    }
  }
</script>

I can see on the generator.jspm.io site that this is not possible (that is why I've posting this here), and I'm wondering if this is an importmap thing or a JSPM generator thing?

I'm thinking about this after playing with external import maps using the es-module-shim library. If multiple applications reference the same import map, it seems like this would need to be supported.

guybedford commented 8 months ago

Yes this is supported via jspm install react17=react@17 react 18=react@18 kind of thing. The online generator doesn't currently support the = syntax like the CLI, but we certainly could if someone was interested in adding that feature.

zachsa commented 8 months ago

Thanks - that CLI actually makes it a little easier to work with external import maps. The link for updating import maps provided by the generator has to be copy/pasted somewhere manually since JSON files can't include comments:

// This doesn't work
{ "imports": { ... }, }

And while I can copy the edit link and include that in a comment field in the JSON that is a manual process. So in other words going beyond some initial experimentation I would probably not use the online generator all that much, and that may be indicative of most generator users.

Having said that, I did get the impression that this was not actually supported by import maps at all. A rookie error...