VSCode move-imports Extension
Just move/rename folder or file in VSCode
Automatically move/rename imports when you rename/move your project files
- Support multiple file extensions (although actual module renaming is only available in
js, jsx, ts, tsx
files) - Support webpack assets (Add your assets extensions to extension list)
- Support ES6/TS imports and commonjs
require()
- Supports custom call expressions, such as
jest.mock("../myfile")
- Seamlessly integrated into VSCode UI
Due to lack of VSCode API, this extension is checking files by checking content hashes of old/moved file. That means if you have 2 files or more with same content the extension will work only with first of them. Actually this is not common case for your working files. If you're on Mac/Windows (Sorry Linux users) you can set move-imports.useCreationDateForHash
setting to true
(see below) to cover 99% cases. If you're on Linux, please don't enable this, otherwise the extension won't work.
This extension contributes the following settings:
move-imports.extensions
: Array of file extensions which will be handled by extension. Webpack users may add assets extensions (i.e.png, jpg, etc...
) heremove-imports.excludeGlobs
: List of glob expressions (for example:[node_modules, public, src/**/*.js]
) to exclude from reference replacing/indexingmove-imports.useGitIgnoreForExclude
: Read glob expressions for excluding from top-level.gitignore
file. These globs will be prepened toexcludeGlobs
move-imports.expressionReferences
: Array of call expressions to treat them as module reference. This includesrequire()
and for example jest module mocks, such asjest.mock
move-imports.useCreationDateForHash
: Prepend file creation date after calculating file content hashes. If a new file with some content hash appears and this content hash is stored internally with different file name, then extension is treating this as 'move/rename file' operation and perform reference lookup & replace. The drawback is only when you have 2 files with same content. Setting this to true will handle 99,9% cases since you'll probably never have 2 files with same creation date and same content. Actually this setting won't work on Linux since Linux doesn't store this attribute in filesystem and even break extension because birthdate will be substituted with access time (and you'll get always different hashes)move-imports.warnAboutSameContentFiles
: Display warning when you have files with same content. Set to false to disablemove-imports.confirmMoveReferences
: Display confirmation dialog before performing any module reference replacing. Set to false to rename without confirmation
- Fixed incorrect reference paths in files inside moved directory, for ex.
import { A } from "../a"
in./__tests__/a_spec
and moving directory with botha
and./__tests__/a_spec
- Fixed issue when negative glob pattern (i.e. !myfile.ts) is excluding all files
- removed excludedRegexp, added exludeGlobs array instead
- read .gitignore for additional exludeGlobs (true by default), fixes issue #2
- process directories reference, i.e.
import { a } from "./dir";
where { a } will be imported from "./dir/index.{js, ts}", fixes issue #3 - process and rewrite ES6 re-export statements, such as
export * from "./abc";
- process and rewrite reference in both moved file and files which reference to this file (previously it was updating only files which had references to moved file)
- Fix windows paths (#1)
- Fix unable to apply reference edits due to wrong path
- Initial release of move-imports