microsoft / microsoft/TypeScript
Support automatically updating URL import references when using `new URL(<file>, import.meta.url)`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Bug Report
🔎 Search Terms
import.meta.url
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about 4.3.0
⏯ Playground Link
💻 Code
Given the following files:
folder/file1.ts
console.log('file1');
export const foo = 42;
different-folder/file2.ts
new URL('../folder/file1.js', import.meta.url);
import('../folder/file1.js');
export const bar = 5;
- Create a new directory
sub-folder/in root - Move
different-folder/intosub-folder/so that the layout becomessub-folder/different-folder/file2.ts - When prompted for "Update imports for 'different-folder'?" click "Yes"
🙁 Actual behavior
sub-folder/different-folder/file2.ts
new URL('../folder/file1.js', import.meta.url);
import('../../folder/file1.js');
export const bar = 5;
The same is true if folder/file1.js is moved to a different location.
🙂 Expected behavior
Similar to the dynamic import, a file reference based on import.meta.url that points to a different TypeScript file should correctly be renamed accordingly.
sub-folder/different-folder/file2.ts
new URL('../../folder/file1.js', import.meta.url);
import('../../folder/file1.js');
export const bar = 5;
VS Code supports the standard dynamic import to handle file renaming. Since import.meta.url and URL are a standard way of resolving files, I would expect VS Code to natively support it as well. For example, Parcel compatibility is implemented in https://github.com/parcel-bundler/parcel/issues/5473, is implemented in Webpack 5 https://github.com/webpack/webpack/pull/11075 and is scheduled for implementation in ESBuild https://github.com/evanw/esbuild/issues/312#issuecomment-800730525
This issue was originally filed at https://github.com/microsoft/vscode/issues/121391
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione Workbench collegata usando new URL(<file>, import.meta.url) e confrontala con il comportamento di aggiornamento degli import dinamici descritto nel report. Segui il percorso di ridenominazione degli import di VS Code che gestisce l’operazione di spostamento. Il lavoro è completato quando lo spostamento di uno dei file referenziati aggiorna il riferimento URL relativo alla stessa destinazione, come per gli import dinamici.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript, vscode
- Ambito
- developer-experience, tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100