Skip to content

Strip ?search query off module names #43082

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

Closed
wants to merge 2 commits into from
Closed

Strip ?search query off module names #43082

wants to merge 2 commits into from

Conversation

TomasHubelbauer
Copy link

This patch allows relative files in the module import syntax (import something from './mod';) to include a search query part and still resolve to the correct file on disk, as if they relative path was not a part but a URL. Full ESM import URL support is discussed in #41730 and full-support would be ideal! This patch implements only a mid-step towards the full solution, in the form of a special-case for those module names which contain the search query. I use this syntax, but it is otherwise extremely niche, in fact, it is possible no one but me would benefit from this. Still, I figured since I've already written the code, I might as well offer it for upstreaming. The scenario this patch enables that didn't work before is this:

import something from './mod?argument';

The imported module case use the search query value through import.meta.url. This works both in Node and browser runtimes.

  • There is an associated issue in the Backlog milestone (required): I'm here to collect feedback, so no ticket in the backlog, but Add (relative) URL imports for modules #41730 is the most relevant ticket for this patch
  • Code is up-to-date with the master branch
  • You've successfully run gulp runtests locally (npm test is the same thing, right?)
  • There are new or updated unit tests validating the change: not yet, I'd like some help with identifying where to add those

Thanks for your feedback.

@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Mar 4, 2021
@TomasHubelbauer
Copy link
Author

I've developed a VS Code extension that serves as a work-around for the lack of this feature in TS:
https://github.com/TomasHubelbauer/vscode-esm-url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants