Skip to content
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

Support automatically updating URL import references when using new URL(<file>, import.meta.url) #121391

Closed
TimvdLippe opened this issue Apr 15, 2021 · 4 comments
Assignees
Labels
*extension-candidate Issue identified as good extension implementation

Comments

@TimvdLippe
Copy link

  • VS Code Version:1.55.1
  • OS Version: Darwin x64 20.3.0

Steps to Reproduce:

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;
  1. Create a new directory sub-folder/ in root
  2. Move different-folder/ into sub-folder/ so that the layout becomes sub-folder/different-folder/file2.ts
  3. When prompted for "Update imports for 'different-folder'?" click "Yes"

Expected result:

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;

Actual result:

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.

Does this issue occur when all extensions are disabled?: Yes

@mjbvz mjbvz added the *extension-candidate Issue identified as good extension implementation label Apr 20, 2021
@TimvdLippe
Copy link
Author

I am confused as to why this issue was closed as a candidate for an extension. 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 parcel-bundler/parcel#5473, is implemented in Webpack 5 webpack/webpack#11075 and is scheduled for implementation in ESBuild evanw/esbuild#312 (comment)

@mjbvz Given the above, do you mind reopening the PR given that this is standard way of importing relative files and supported in various bundlers?

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 20, 2021

If you feel this has enough adoption, please file an issue against TypeScript

@TimvdLippe
Copy link
Author

Done: microsoft/TypeScript#43759 Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*extension-candidate Issue identified as good extension implementation
Projects
None yet
Development

No branches or pull requests

3 participants
@TimvdLippe @mjbvz and others