New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

import-codemod

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

import-codemod

Codemod for smushing imports

latest
Source
npmnpm
Version
2.0.2
Version published
Maintainers
1
Created
Source

npm Travis

import-codemod

Flexible codemod for moving around imports.

It's super useful for migrating giant codebases to react-primitives. It might be useful for some other things.

Usage

Create a config file (or use the included src/configs/config.primitives.js)

yarn global add jscodeshift
yarn add import-codemod

jscodeshift <path> -t ./node_modules/import-codemod/lib/index.js --config path-to-config.js

Things it can do

Move select named imports from one module to another

import { Text, View } from 'react-native';
// ->
import { Text, View } from 'react-primitives';

config.js

module.exports = {
  mappings: [
    module: {
      from: 'react-native',
      to: 'react-primitives',
    },
    specifiers: [
      'Text',
      'View',
    ],
  },
}

Move all named imports from one module to another

import { Text, View, lots, of, others } from 'react-native';
// ->
import { Text, View, lots, of, others } from 'react-primitives';

config.js

module.exports = {
  mappings: [
    module: {
      from: 'react-native',
      to: 'react-primitives',
    },
    specifiers: [
      '*',
    ],
  ],
}

Move and rename named imports from one module to another

import { Text, View } from 'react-native';
// ->
import { Words, Box } from 'react-primitives';

config.js

module.exports = {
  mappings: [
    module: {
      from: 'react-native',
      to: 'react-primitives',
    },
    specifiers: {
      'Text': 'Words',
      'View': 'Box',
    },
  ],
}

Move default imports from one module to another

import Foo from 'foo';
// ->
import Foo from 'bar';

config.js

module.exports = {
  mappings: [
    module: {
      from: 'react-native',
      to: 'react-primitives',
    },
    specifiers: ['default'],
  ],
}

Move default imports from one module to named imports of another

import Foo from 'foo';
// ->
import { Foo } from 'bar';

config.js

module.exports = {
  mappings: [
    module: {
      from: 'react-native',
      to: 'react-primitives',
    },
    specifiers: {
      'default': 'Foo'
    },
  ],
}

Exclude files from being transformed

// @ignoreMe

config.js

module.exports = {
  ignoreMark: '@ignoreMe',
  mappings: [],
}

FAQs

Package last updated on 28 Oct 2017

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