@itlabs/ts-import-move
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.6 • Public • Published

@itlabs/ts-import-move

It can be a lot of work to update all imports, if you moved a class, function, component or whatever from one library of your monorepo to another. If you are using relative paths for the imports, tools like visual studio code would ask you to perform these import updates for you. But not if you are using typescript paths aliases in your monorepo e.g.

"paths": {
    "@itlabs/my-package": ["packages/my-package/src/index.ts"],
    "@itlabs/my-new-package": ["packages/my-new-package/src/index.ts"]
}

In this case, you just found the tool that will helps you :)

CLI

A CLI is coming soon.

Library

Just install those two packages npm i -D @itlabs/ts-import-move ts-morph. And copy and adapt this snippet somewhere to your tooling scripts.

import { Project } from 'ts-morph';
import { tsImportMove } from '@itlabs/ts-import-move';

async function move(): Promise<void> {
  const project = new Project({ tsConfigFilePath: 'path/to/tsconfig.json' });

  tsImportMove(project, {
    imports: ['ObjectToMove'],
    sourcePackage: '@itlabs/my-package',
    targetPackage: '@itlabs/my-new-package',
  });

  await project.save();
}

Check the ts-morph docs for further information how to load your typescript project.

Package Sidebar

Install

npm i @itlabs/ts-import-move

Weekly Downloads

9

Version

1.0.0-beta.6

License

MIT

Unpacked Size

7.58 kB

Total Files

11

Last publish

Collaborators

  • ar-itlabs