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

Add support for module specifier "aliases" (tsconfig.paths mappings) when moving files/folders. #1494

Open
tryggvigy opened this issue Jan 26, 2024 · 0 comments

Comments

@tryggvigy
Copy link

tryggvigy commented Jan 26, 2024

tl;dr Add support for module specifier "aliases" (tsconfig.paths mappings) when moving files/folders.


Let's say your tsconfig contains a paths mapping like this:

    "paths": {
      "Root/*": ["./*"]
    },

I noticed that

project.createDirectory('someDir');
const srcFile = project.getSourceFileOrThrow('someFile.ts');
srcFile.moveToDirectory('someDir');

will update all relative import/export specifiers referencing 'someFile.ts' but not if the specifier used an alias such as

import * from 'Root/someFile';

I expected ts-morph to update the specifier to import * from 'Root/someDir/someFile'; but it doesn't.
I think it would be nice feature to support this. VSCode can handle paths mapped import/exports when moving files.

Describe the solution you'd like

I think the problem is that updateStringLiteralReferences(nodeReferences: ReadonlyArray<[StringLiteral, SourceFile]>) { only updates the module specifier if it's a relative path like '../someFile' not if it's an module specifier alias like 'Root/someFile'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant