microsoft / microsoft/TypeScript
Add support for URI style import
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Search Terms
browser es module import url
Suggestion
Related issues: #28985, #19942
In browser and deno, import from a "package" is different from the node style.
// it's valid in browser but not in TypeScript
import lodash from "https://unpkg.com/lodash-es@4.17.15/lodash.js";
// it's valid in deno but not in TypeScript
import { serve } from "https://deno.land/std@v0.24.0/http/server.ts";
Currently there is no way to let TypeScript automatically map the URI to another place like @types/* or $DENO_DIR/deps/https/deno.land/*
The current path can map a simple pattern of import module specifier to another place, but in the URI style import, a more flexible way to map the URI is required.
Proposal
(maybe add a new moduleResolution: browser)
Add a new uriPaths that allows to map from a RegExp to a local path. It will NOT effect the emitted code. Just a way to find the type definition for those URIs.
I'm willing to implement this feature but I'm not sure if TypeScript will accept this.
Use Cases
For TypeScript to find definition file for imports like https://unpkg.com/lodash
Examples
{
"compilerOptions": {
"uriPaths": {
"https://unpkg.com/(.+?)@.+?/.+": "./node_modules/@types/$1",
"https://deno.land/(.+?)@v.+?/(.+?)/(.+)": "$DENO_DIR/deps/https/deno.land/$1/$2/$3",
"std:(.+)": "./node_modules/builtin-module-types/$1"
}
}
}
This rule map https://unpkg.com/lodash-es@4.17.15/lodash.js to @types/lodash-es
Map https://deno.land/std@v0.24.0/http/server.ts to $DENO_DIR/deps/https/deno.land/std/http/server.ts.
$DENO_DIR is an environment variable.
By default, on Windows, it's ~\AppData\Local\deno\deps\https\deno.land\std\http\server.ts.
By default on Linux, it is ~/.deno/deps/https/deno.land/std/http/server.ts.
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Durchsicht der verwandten Issues #28985 und #19942 und untersuche anschließend, wie die vorgeschlagenen uriPaths sowie die Modulauflösung durch den Browser oder Deno in das bestehende Pfad-Mapping des Compilers passen würden. Definiere das akzeptierte Mapping-Verhalten, die Behandlung von Umgebungsvariablen und die nicht emittierenden Auflösungssemantiken; abgeschlossen ist die Aufgabe, wenn ein abgestimmtes Design und die entsprechende Abdeckung für die URI-Beispiele vorliegen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- deno, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100