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

Scoping a Specifier for All Dependencies in Import Maps #23612

Closed
nestarz opened this issue Apr 30, 2024 · 2 comments
Closed

Scoping a Specifier for All Dependencies in Import Maps #23612

nestarz opened this issue Apr 30, 2024 · 2 comments

Comments

@nestarz
Copy link

nestarz commented Apr 30, 2024

I would like to know if import maps can scope a specifier for all its dependencies.

Consider the following example:

...
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "react"
  },
  "scopes": {
    "https://jsr.io/@scope/my-package/0.0.0/": {
      "react/jsx-runtime": "jsr:@scope/my-package/0.0.0/react/jsx-runtime"
    }
  }

This configuration only scopes the specifier for modules that start with "https://jsr.io/@scope/my-package/0.0.0/". However, if my package at "https://jsr.io/@scope/my-package/0.0.0" imports an another JSR package, which needs the same jsx-runtime, it doesn't remap the "react/jsx-runtime" specifier for that package. I would need to add a separate scope for each dependency, which becomes cumbersome, and even so, I can't add a scope inside a scope.

Is there a way to apply the mapping for "react/jsx-runtime" not only to "@scope/my-package/0.0.0" but also to all its dependencies, without having to explicitly define a scope for each dependency? either from the deno.json, or via an app script ?

@lucacasonato
Copy link
Member

You can use the "imports" field.

@nestarz
Copy link
Author

nestarz commented Jun 8, 2024

@lucacasonato I know about the imports field thanks.
It doesn’t address my issue though, I was looking for a way to apply a mapping for a file and all it’s nested dependencies in an isolated fashion.
Scopes only works at one depth (relative to one scope), and imports do it for all. I was looking for a a way to « do it for all » solution but starting a certain specific scope.

For example my use case is the following, I would like all files that have a use client directive to import the client version of react, but also all it’s dependencies without explicitly adding every single of them with a scope into the import map, this is because some dependencies are shared so they also can be imported with a different resolution (server or client). More information here: reactjs/rfcs#227

Let me know if that’s not clear and also I understand if that’s not possible at all or isn't a goal for Deno to support this usecase.

Essentially what im trying to do is:

if specifier A imports specifier B, then specifier B imports C

if specifier X imports specifier B, then specifier B imports not C but D.

where in the configuration file I can state that any specifier C down from X is remapped to D.

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

2 participants