0

i.e. currently we use a type OldType from an npm package @old-package in our code base.

We want to replace it with our own type NewType, which can be imported via @new-package.

Example

Old imports

import {
  AnyImport,
  OldType,
  AnotherImport
} from '@old-package';

should be updated to:

New imports

import {
  AnyImport,
  AnotherImport
} from '@old-package';
import { NewType } from '@new-package';

How can we do this refactoring in IntelliJ, so that the import statements are correctly updated?

Notes:

  • I think a simple replace RegEx will not work, because the old import may be one of many on multiple lines
  • I checked the IntelliJ Migrate feature, but it seems this only works for Java code
  • I checked the Structural search and replace feature, but cannot make it work for my case

Since this is a on-off operation it's also okay, if this can be done in another IDE or via a command-line tool, etc.

1

1 Answer 1

1

Structural searching for imports is not supported/implemented at this time (related feature request: IDEA-285199). You can try some solutions available on the web, see https://www.npmjs.com/package/refactor-imports?activeTab=readme, for example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.