Socket
Book a DemoInstallSign in
Socket

@itlabs/ts-import-move

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itlabs/ts-import-move

move typescript imports from one package to another

latest
npmnpm
Version
1.0.0-beta.6
Version published
Maintainers
1
Created
Source

@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.

Keywords

package

FAQs

Package last updated on 25 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts