Skip to content

feat: support bare specifiers in mappings - #508

Merged
dsherret merged 3 commits into
denoland:mainfrom
dsherret:feat_mapping_bare_specifiers
Jul 26, 2026
Merged

feat: support bare specifiers in mappings#508
dsherret merged 3 commits into
denoland:mainfrom
dsherret:feat_mapping_bare_specifiers

Conversation

@dsherret

@dsherret dsherret commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Closes #357

A mappings key had to be a path or url, so a specifier that only exists in the deno.json's imports couldn't be mapped by the name that appears in the code. Now a bare specifier key is resolved via the config file's import map:

// deno.json
{
  "imports": {
    "my-lib": "https://deno.land/x/my-lib@39.0.0/src/index.ts"
  }
}
await build({
  // ...etc...
  mappings: {
    "my-lib": {
      name: "npm-target-for-my-lib",
      version: "^39.0.0",
    },
  },
});

Details:

  • A key is treated as a path when it has a scheme, when it's relative or absolute, or when it exists on disk (so a key like mod.ts keeps resolving to a file). Everything else is a bare specifier, which means package names containing a dot like chart.js work.
  • Urls are still used as-is rather than being run through the import map, which keeps existing mappings resolving the way they always have.
  • Resolution uses each entry point as the referrer in turn (main entry points then test entry points) with the referrer's resolution mode, so mappings still resolve when the first entry point isn't the relevant workspace member.
  • The "indicated to be mapped ... but were not found" error now shows the key that was specified along with what it resolved to.
  • Two mappings that resolve to the same specifier is now an error instead of one silently winning.

dsherret added 3 commits July 26, 2026 18:44
A mapping key that isn't a path or url is now resolved via the config
file's import map, so a specifier in a deno.json's `imports` can be
mapped to an npm package:

```jsonc
// deno.json
{
  "imports": {
    "my-lib": "https://deno.land/x/my-lib@39.0.0/src/index.ts"
  }
}
```

```ts
await build({
  // ...etc...
  mappings: {
    "my-lib": {
      name: "npm-target-for-my-lib",
      version: "^39.0.0",
    },
  },
});
```

Closes denoland#357

Claude-Session: https://claude.ai/code/session_01SqfDuWeEek5XnHSbXxCUE9
- only treat a mapping key as a path when it has a scheme, is relative
  or absolute, or exists on disk, so that a bare specifier with an
  extension works (ex. `chart.js`)
- resolve using the referrer's resolution mode and fall back to the
  other entry points
- show the key the user specified in the "not found" error
- error when two mappings resolve to the same specifier
- resolve in a deterministic order

Claude-Session: https://claude.ai/code/session_01SqfDuWeEek5XnHSbXxCUE9
@dsherret
dsherret merged commit 7d311ec into denoland:main Jul 26, 2026
5 checks passed
@dsherret
dsherret deleted the feat_mapping_bare_specifiers branch July 26, 2026 23:17
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.

mapping should consider the contents of deno.json

1 participant