jspm / generator

JSPM Import Map Generator
Apache License 2.0
166 stars 21 forks source link

fix: respect package.json when installing bare specifiers, fix some type bugs #213

Closed Bubblyworld closed 1 year ago

Bubblyworld commented 1 year ago

When resolving a package in generator.install(...), if there are no version constraints then the constraints in the package.json are used, rather than the current behaviour which is to use the latest version.

Also fixes a bug where InstallTargets were being put in the installer's constraint map instead of PackageTargets, which caused a crash during my local testing.

Bubblyworld commented 1 year ago

By the way, there's a rare race condition in tests/html/multi.test.js that seems to have been around for at least since 41bcad4. Causes intermittent failures, haven't managed to isolate the root cause yet.

guybedford commented 1 year ago

Here's a case that isn't working for this:

package.json

{
  "name": "app",
  "exports": "./app.js",
  "dependencies": {
    "es-module-lexer": "^1"
  }
}

importmap.json

{
  "imports": {
    "es-module-lexer": "https://ga.jspm.io/npm:es-module-lexer@0.10.5/dist/lexer.js"
  }
}

Then running node ../jspm.js link app -o sub/test.html gives the HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JSPM example</title>
    <script async src="https://ga.jspm.io/npm:es-module-shims@1.6.3/dist/es-module-shims.js" crossorigin="anonymous"></script>
<script type="importmap">
{
  "imports": {
    "app": "file:///C:/Users/Guy/Projects/jspm/a/app.js"
  },
  "scopes": {
    "file:///": {
      "es-module-lexer": "https://ga.jspm.io/npm:es-module-lexer@1.1.1/dist/lexer.js"
    }
  }
}
</script>
  </head>
  <body>
  </body>
</html>

This surfaces a couple of issues: