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

feat: @deno-types map in build options #418

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nayeemrmn
Copy link
Collaborator

@nayeemrmn nayeemrmn commented Mar 17, 2024

Adds support for a deno.json field like:

{
  "types": {
    "npm:express": "npm:@types/express",
    "./file.js": "./file.d.ts"
  }
}

All specifiers written there are resolved through provided resolver with the deno.json as the referrer. So an import-mapped key (or value) will just work:

{
  "imports": {
    "express": "npm:express@^4.18.3"
  },
  "types": {
    "express": "npm:@types/express@^4.17.21"
  }
}

We can make it so that deno add npm:@types/<package> adds the entry to "types" instead of "imports". So deno add npm:@types/express will be the equivalent of npm i --save @types/express.

These mappings will only apply to referrers within the passed 'scope' associated with the deno.json. In CLI we would presumably pass the parent directory of the deno.json file.

JSR will inline these mappings to pragmas on publish. This has parity with the above behaviour.


This is essentially // @deno-types pragmas in config file form. Reasons we want to do this:

  • Deduplicate // @deno-types pragmas for dependencies.
  • Pragmas can't be used for things like compilerOptions.jsxImportSource.
  • NPM @types packages can be referenced and version-pinned in the config file next to their runtime counterparts.

@nayeemrmn nayeemrmn requested a review from dsherret March 17, 2024 06:45
@marvinhagemeister
Copy link
Contributor

I quite like this idea. Makes a lot of sense to put it in the config file for imports defined there 👍

src/lib.rs Show resolved Hide resolved
@nayeemrmn nayeemrmn requested a review from dsherret March 17, 2024 15:02
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

Successfully merging this pull request may close these issues.

None yet

3 participants