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

moveToDirectory loses the import statements' extension #1612

Open
shinebayar-g opened this issue Feb 6, 2025 · 1 comment
Open

moveToDirectory loses the import statements' extension #1612

shinebayar-g opened this issue Feb 6, 2025 · 1 comment

Comments

@shinebayar-g
Copy link

shinebayar-g commented Feb 6, 2025

Describe the bug

Version: 25.0.1

When moveToDirectory is used, the import statements' extensions are lost.

To Reproduce

import { Project } from "ts-morph";

const project = new Project({
    tsConfigFilePath: path.join(packagePath, 'tsconfig.json'),
    manipulationSettings: {
        indentationText: IndentationText.TwoSpaces,
        quoteKind: QuoteKind.Double,
        insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
        useTrailingCommas: true,
    },
});

sourceFile.addImportDeclaration({
    moduleSpecifier: '../App.js',
    namedImports: ['App'],
});

sourceFile.moveToDirectory('subDir');

Expected behavior

Without moveToDirectory is used, import statement looks like this.

import { App } from '../App.js';

After

import { App } from '../../App'; // .js extension is lost.

Other move methods like moveImmediately also seems to be affected.

tsconfig

{
  "compilerOptions": {
    "lib": ["ES2022"],
    "target": "ES2022",
    "module": "Node16",
    "moduleResolution": "node16",
    "declaration": true,
    "strict": true,
    "skipLibCheck": true,
    "noFallthroughCasesInSwitch": true,
    "noEmitOnError": true
  }
}
@shinebayar-g
Copy link
Author

It became a blocker for users who have "moduleResolution": "nodenext" in their tsconfig.

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