Skip to content

Commit 47b2695

Browse files
committed
init: Initial commit
0 parents  commit 47b2695

12 files changed

Lines changed: 6297 additions & 0 deletions

File tree

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 2
12+
charset = utf-8

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
.idea
61+
.history

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/test/
2+
.editorconfig
3+
.gitignore
4+
manualRun.ts
5+
yarn.lock
6+
*.log

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Andrey Los
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# import-move-codemod
2+
3+
Codemod to move imports from one module to another. Super useful in huge monorepos or huge migrations of 3rd party packages.
4+
5+
## Usage
6+
7+
Inside your project root run
8+
For `npm`
9+
```
10+
npm i import-move-codemod --save-dev
11+
```
12+
or for `yarn`
13+
```
14+
yarn add import-move-codemod --dev
15+
```
16+
or for `pnpm`
17+
```
18+
pnpm add import-move-codemod --D
19+
```
20+
21+
Before the run you need to create a file with a config, let say `codemod.json`
22+
```json
23+
{
24+
"module": {
25+
"from": "one",
26+
"to": "two"
27+
},
28+
"specifiers": ["One"]
29+
}
30+
```
31+
32+
Then for example to run codemod against all the files in `/src` run
33+
```
34+
npx @codemod/cli --p import-move-codemod -o import-move-codemod=@codemod.json --printer prettier /src
35+
```
36+
37+
38+
39+
40+
## What refactorings are available
41+
42+
### Move of one or multiple named imports from one module to another
43+
44+
```
45+
{
46+
module: {
47+
from: "one",
48+
to: "two"
49+
},
50+
specifiers: ["One"]
51+
}
52+
```
53+
54+
```ts
55+
import { One } from 'one'
56+
57+
// ↓ ↓ ↓ ↓ ↓ ↓
58+
59+
import { One } from 'two';
60+
```
61+
62+
```
63+
{
64+
module: {
65+
from: "one",
66+
to: "two"
67+
},
68+
specifiers: ["One", "Two"]
69+
}
70+
```
71+
72+
```ts
73+
import { One, Two } from 'one'
74+
75+
// ↓ ↓ ↓ ↓ ↓ ↓
76+
77+
import { One, Two } from 'two';
78+
```
79+
80+
```ts
81+
import { One as OneA, Two as TwoA } from 'one'
82+
83+
// ↓ ↓ ↓ ↓ ↓ ↓
84+
85+
import { One as OneA, Two as TwoA } from 'two';
86+
87+
```
88+
89+
```
90+
{
91+
module: {
92+
from: "one",
93+
to: "two"
94+
},
95+
specifiers: ["Two"]
96+
}
97+
```
98+
99+
```ts
100+
import { One, Two } from 'one'
101+
102+
// ↓ ↓ ↓ ↓ ↓ ↓
103+
104+
import { Two } from 'two';
105+
import { One } from 'one';
106+
```
107+
108+
### Move named imports and default in one go
109+
110+
```
111+
{
112+
module: {
113+
from: "one",
114+
to: "two"
115+
},
116+
specifiers: ["default", "One", "Two"]
117+
}
118+
```
119+
120+
121+
```ts
122+
import ADefault, { One, Two, Three } from 'one'
123+
124+
// ↓ ↓ ↓ ↓ ↓ ↓
125+
126+
import ADefault, { One, Two } from 'two';
127+
import { Three } from 'one';
128+
```
129+
130+
```
131+
{
132+
module: {
133+
from: "one",
134+
to: "two"
135+
},
136+
specifiers: ["default", "Two"]
137+
}
138+
```
139+
140+
```ts
141+
import One, { Two } from 'one'
142+
143+
// ↓ ↓ ↓ ↓ ↓ ↓
144+
145+
import One, { Two } from 'two';
146+
```
147+
148+
### Move everything i.e. module rename
149+
150+
```
151+
{
152+
module: {
153+
from: "one",
154+
to: "two"
155+
},
156+
specifiers: ["*"]
157+
}
158+
```
159+
160+
```ts
161+
import ADefault, { One, Two, Three } from 'one'
162+
163+
// ↓ ↓ ↓ ↓ ↓ ↓
164+
165+
import ADefault, { One, Two, Three } from 'two';
166+
167+
```
168+
169+
### Move named imports and rename them
170+
171+
```
172+
{
173+
module: {
174+
from: "one",
175+
to: "two"
176+
},
177+
specifiers: {
178+
One: "OneR",
179+
Two: "TwoR"
180+
}
181+
}
182+
```
183+
184+
```ts
185+
import ADefault, { One, Two } from 'one'
186+
187+
// ↓ ↓ ↓ ↓ ↓ ↓
188+
189+
import { OneR, TwoR } from 'two';
190+
import ADefault from 'one';
191+
```
192+
193+
```ts
194+
import { One, Two } from 'one'
195+
196+
// ↓ ↓ ↓ ↓ ↓ ↓
197+
198+
import { OneR, TwoR } from 'two';
199+
```
200+
201+
### Move default import to named
202+
```
203+
{
204+
module: {
205+
from: "one",
206+
to: "two"
207+
},
208+
specifiers: { default: "One" }
209+
}
210+
```
211+
212+
```ts
213+
import One, { Two } from 'one'
214+
215+
// ↓ ↓ ↓ ↓ ↓ ↓
216+
217+
import { One } from 'two';
218+
import { Two } from 'one';
219+
```
220+
221+
```ts
222+
import One from 'one'
223+
224+
// ↓ ↓ ↓ ↓ ↓ ↓
225+
226+
import { One } from 'two';
227+
```
228+
229+
### Move only default import
230+
231+
```
232+
{
233+
module: {
234+
from: "one",
235+
to: "two"
236+
},
237+
specifiers: ["default"]
238+
}
239+
```
240+
241+
```ts
242+
import ADefault, { One, Two, Three } from 'one'
243+
244+
// ↓ ↓ ↓ ↓ ↓ ↓
245+
246+
import ADefault from 'two';
247+
import { One, Two, Three } from 'one';
248+
```
249+
250+
```ts
251+
import One from 'one'
252+
253+
// ↓ ↓ ↓ ↓ ↓ ↓
254+
255+
import One from 'two';
256+
```
257+
258+
### Make default import from named
259+
260+
```
261+
{
262+
module: {
263+
from: "one",
264+
to: "two"
265+
},
266+
specifiers: {
267+
One: "default"
268+
}
269+
}
270+
```
271+
272+
```ts
273+
import { One } from 'one'
274+
275+
// ↓ ↓ ↓ ↓ ↓ ↓
276+
277+
import One from 'two';
278+
```

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};

0 commit comments

Comments
 (0)