Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpecifierMappings and JSR import map not working #437

Open
AlexanderOMara opened this issue Nov 17, 2024 · 2 comments
Open

SpecifierMappings and JSR import map not working #437

AlexanderOMara opened this issue Nov 17, 2024 · 2 comments

Comments

@AlexanderOMara
Copy link

AlexanderOMara commented Nov 17, 2024

As best as I can tell, this should be the correct mapping:

build({
  importMap: 'deno.json',
  mappings: {
    'jsr:@hqtsm/dataview': {
       name: '@hqtsm/dataview',
    },
  },
  // ...
}
{
  "imports": {
    "@hqtsm/dataview": "jsr:@hqtsm/dataview@^1.0.0"
  }
}

To map an import like this to an npm package:

import { getInt24, getUint24, setInt24, setUint24 } from '@hqtsm/dataview';

But it does not work:

[dnt] Transforming...
error: Uncaught (in promise) "The following specifiers were indicated to be mapped to a package, but were not found:\n  * jsr:@hqtsm/dataview"

Similarly it does not work with:

import { getInt24, getUint24, setInt24, setUint24 } from 'jsr:@hqtsm/dataview';

I also tried many other variants in mappings, but no luck:

  • jsr:@hqtsm/dataview@^1.0.0 Same
  • jsr:@hqtsm/dataview@1.0.0 Same
  • @hqtsm/dataview: Errors out saying it couldn't find file:///...

For some reason it seems it does not find the imports to replace, like it must be doing when it rewrites to use the deps directory.

Am I doing something wrong? I found some seemingly related issues and pull requests, but it's unclear if it's the same issue, or what the status on it is:

@AlexanderOMara
Copy link
Author

Looked into this a little more. The existing test cases only checked a full URL and a relative import.

Tried creating a test case and confirmed the same issue is present.

AlexanderOMara@9700b72

$ deno task test --filter 'jsr package mappings'
Task test deno test -A "--filter" "jsr package mappings"
running 1 test from ./tests/integration.test.ts
should build with jsr package mappings ...
------- post-test output -------
[dnt] Transforming...
----- post-test output end -----
should build with jsr package mappings ... FAILED (132ms)

 ERRORS

should build with jsr package mappings => ./tests/integration.test.ts:1134:6
error: "The following specifiers were indicated to be mapped to a package, but were not found:\n  * jsr:@david/code-block-writer"

 FAILURES

should build with jsr package mappings => ./tests/integration.test.ts:1134:6

FAILED | 0 passed | 1 failed | 83 filtered out (643ms)

error: Test failed

@AlexanderOMara
Copy link
Author

AlexanderOMara commented Nov 18, 2024

Digging into this some more, it looks like the issue is that the mapping it's making it into specifiers.mapped_packages in get_specifiers here:

https://github.com/denoland/dnt/blob/0.41.3/rs-lib/src/specifiers.rs#L67

specifiers comes from loader.into_specifiers() in build_with_specifiers here:

https://github.com/denoland/dnt/blob/0.41.3/rs-lib/src/graph.rs#L120

For some reason it appears deno_graph::ModuleGraph is not including it when build is called earlier in the same function (like it does for a mapped URL):

https://github.com/denoland/dnt/blob/0.41.3/rs-lib/src/graph.rs#L71-L95

Unfortunately, this is where it crosses into the deno_graph library and continuing to debug gets harder.

Since there is few places touching mapped_packages (none in deno_graph itself) I think this section is probably relevant:

https://github.com/denoland/dnt/blob/0.41.3/rs-lib/src/loader/mod.rs#L83-L116


Not sure if this is relevant, but this verbose mapping almost seemed like it would work:

      "https://jsr.io/@david/code-block-writer/13.0.3/mod.ts": {
        name: "code-block-writer",
        version: "=13.0.3",
      }

But it panics elsewhere:

panicked at rs-lib/src/mappings.rs:134:11:
dnt bug - Could not find the mapping for https://jsr.io/@david/code-block-writer/13.0.3/mod.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant