microsoft / microsoft/TypeScript

Add (relative) URL imports for modules

オープン
#41,730 コメント 2 件 リアクション 6 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Search Terms

  • import url
  • relative url import

Suggestion

Add a new moduleResolution mode (e.g. "url") that treats non-bare specifiers in import statements and -expressions as URLs, matching the behavior of browser and node ESM. Mostly for relative URLs but potentially also for absolute URLs. It likely shouldn't change the resolution of require calls.

There's a similar issue (Add support for URI style import) that focusses on HTTP URLs but I would consider supporting HTTP URLs out of scope for this issue. It may be possible to layer HTTP support on top of the basic feature, so they aren't mutually exclusive.

Use Cases

Write code that works as-is in browsers and node, using filenames that contain characters that would typically be URL encoded (like spaces).

Examples

Right now the "classic" and "node" (~CommonJS/babel) resolution modes treat relative specifiers as file system paths and don't support absolute file:// URLs at all. For browser ESM and node ESM, these should typically be treated as relative URLs. E.g.:

// main.ts
import {name} from './dep%20file.js';
console.log(name);

// dep file.ts:
export const name = 'Robin';

TypeScript generates working code for this (if emit on error is allowed) but it will fail to trace the import correctly because it expects an imported filename that contains the literal string "%20".

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、moduleResolution モードが相対 import 文と import 式をどのように扱うかを追跡し、既存の classic と node の動作を比較します。URL 指向のモードが './dep%20file.js' のような相対 URL 指定子を正しく解決し、require の解決を変更せず、HTTP URL のサポートも必要としない状態になれば作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。