-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added three.js r168 codemods (#1315)
- Loading branch information
1 parent
4c0f5bb
commit 8466809
Showing
115 changed files
with
2,014 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/codemods/three/r168/deactivate-to-disconnect/.codemodrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", | ||
"name": "three/r168/dragcontrols.deactivate-to-disconnect", | ||
"version": "1.0.0", | ||
"engine": "jscodeshift", | ||
"private": false, | ||
"arguments": [], | ||
"meta": { | ||
"tags": [ | ||
"three", | ||
"migration", | ||
"r168" | ||
] | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/codemods/three/r168/deactivate-to-disconnect/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
9 changes: 9 additions & 0 deletions
9
packages/codemods/three/r168/deactivate-to-disconnect/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 yugal41735 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
28 changes: 28 additions & 0 deletions
28
packages/codemods/three/r168/deactivate-to-disconnect/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
This codemod renames dragcontrols.deactivate() to disconnect() | ||
|
||
## Example | ||
|
||
### Before | ||
|
||
```ts | ||
taScene.dragControls.deactivate(); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
taScene.disconnect(); | ||
``` | ||
|
||
### Before | ||
|
||
```ts | ||
dragControls.deactivate(); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
disconnect(); | ||
``` | ||
|
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
taScene.dragControls.deactivate(); |
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
taScene.disconnect(); |
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dragControls.deactivate(); |
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
disconnect(); |
13 changes: 13 additions & 0 deletions
13
packages/codemods/three/r168/deactivate-to-disconnect/cdmd_dist/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*! @license | ||
The MIT License (MIT) | ||
Copyright (c) 2024 yugal41735 | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return transform}});function transform(file,api,options){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.CallExpression,{callee:{type:"MemberExpression",property:{name:"deactivate"}}}).forEach(path=>{const memberExpr=path.node.callee;if(j.MemberExpression.check(memberExpr)){const object=memberExpr.object;if(j.MemberExpression.check(object)){path.replace(j.callExpression(j.memberExpression(object.object,j.identifier("disconnect")),[]));dirtyFlag=true}}});root.find(j.CallExpression,{callee:{type:"MemberExpression",object:{type:"Identifier",name:"dragControls"},property:{name:"deactivate"}}}).forEach(path=>{path.replace(j.callExpression(j.identifier("disconnect"),[]));dirtyFlag=true});return dirtyFlag?root.toSource():undefined} |
23 changes: 23 additions & 0 deletions
23
packages/codemods/three/r168/deactivate-to-disconnect/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "deactivate-to-disconnect", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "20.9.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^1.0.1", | ||
"@codemod.com/codemod-utils": "*", | ||
"jscodeshift": "^0.15.1", | ||
"@types/jscodeshift": "^0.11.10" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"test:watch": "vitest watch" | ||
}, | ||
"files": [ | ||
"README.md", | ||
".codemodrc.json", | ||
"/dist/index.cjs" | ||
], | ||
"type": "module", | ||
"author": "yugal41735" | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/codemods/three/r168/deactivate-to-disconnect/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export default function transform(file, api, options) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
let dirtyFlag = false; | ||
|
||
// Replace taScene.dragControls.deactivate() with taScene.disconnect() | ||
root.find(j.CallExpression, { | ||
callee: { | ||
type: 'MemberExpression', | ||
property: { name: 'deactivate' } | ||
} | ||
}).forEach(path => { | ||
const memberExpr = path.node.callee; | ||
if (j.MemberExpression.check(memberExpr)) { | ||
const object = memberExpr.object; | ||
if (j.MemberExpression.check(object)) { | ||
path.replace(j.callExpression(j.memberExpression(object.object, j.identifier('disconnect')), [])); | ||
dirtyFlag = true; | ||
} | ||
} | ||
}); | ||
|
||
// Replace dragControls.deactivate() with disconnect() | ||
root.find(j.CallExpression, { | ||
callee: { | ||
type: 'MemberExpression', | ||
object: { type: 'Identifier', name: 'dragControls' }, | ||
property: { name: 'deactivate' } | ||
} | ||
}).forEach(path => { | ||
path.replace(j.callExpression(j.identifier('disconnect'), [])); | ||
dirtyFlag = true; | ||
}); | ||
|
||
return dirtyFlag ? root.toSource() : undefined; | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/codemods/three/r168/deactivate-to-disconnect/test/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { describe, it } from 'vitest'; | ||
import jscodeshift, { type API } from 'jscodeshift'; | ||
import transform from '../src/index.js'; | ||
import assert from 'node:assert'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
|
||
const buildApi = (parser: string | undefined): API => ({ | ||
j: parser ? jscodeshift.withParser(parser) : jscodeshift, | ||
jscodeshift: parser ? jscodeshift.withParser(parser) : jscodeshift, | ||
stats: () => { | ||
console.error( | ||
'The stats function was called, which is not supported on purpose', | ||
); | ||
}, | ||
report: () => { | ||
console.error( | ||
'The report function was called, which is not supported on purpose', | ||
); | ||
}, | ||
}); | ||
|
||
describe('deactivate-to-disconnect', () => { | ||
it('test #1', async () => { | ||
const INPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture1.input.ts'), 'utf-8'); | ||
const OUTPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture1.output.ts'), 'utf-8'); | ||
|
||
const actualOutput = transform({ | ||
path: 'index.js', | ||
source: INPUT, | ||
}, | ||
buildApi('tsx'), {} | ||
); | ||
|
||
assert.deepEqual( | ||
actualOutput?.replace(/W/gm, ''), | ||
OUTPUT.replace(/W/gm, ''), | ||
); | ||
}); | ||
|
||
it('test #2', async () => { | ||
const INPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture2.input.ts'), 'utf-8'); | ||
const OUTPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture2.output.ts'), 'utf-8'); | ||
|
||
const actualOutput = transform({ | ||
path: 'index.js', | ||
source: INPUT, | ||
}, | ||
buildApi('tsx'), {} | ||
); | ||
|
||
assert.deepEqual( | ||
actualOutput?.replace(/W/gm, ''), | ||
OUTPUT.replace(/W/gm, ''), | ||
); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/codemods/three/r168/deactivate-to-disconnect/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"target": "ESNext", | ||
"moduleResolution": "NodeNext", | ||
"lib": [ | ||
"ESNext", | ||
"DOM" | ||
], | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true, | ||
"allowSyntheticDefaultImports": true, | ||
"isolatedModules": true, | ||
"jsx": "react-jsx", | ||
"useDefineForClassFields": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"preserveWatchOutput": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"incremental": true, | ||
"noUncheckedIndexedAccess": true, | ||
"noPropertyAccessFromIndexSignature": false, | ||
"allowJs": true | ||
}, | ||
"include": [ | ||
"./src/**/*.ts", | ||
"./src/**/*.js", | ||
"./test/**/*.ts", | ||
"./test/**/*.js" | ||
], | ||
"exclude": ["node_modules", "./dist/**/*"], | ||
"ts-node": { | ||
"transpileOnly": true | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/codemods/three/r168/deactivate-to-disconnect/vitest.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { configDefaults, defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: [...configDefaults.include, '**/test/*.ts'], | ||
}, | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/codemods/three/r168/drag-controls-to-connect/.codemodrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", | ||
"name": "three/r168/dragcontrols.activate-to-connect", | ||
"version": "1.0.0", | ||
"engine": "jscodeshift", | ||
"private": false, | ||
"arguments": [], | ||
"meta": { | ||
"tags": [ | ||
"three", | ||
"migration", | ||
"r168" | ||
] | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/codemods/three/r168/drag-controls-to-connect/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
9 changes: 9 additions & 0 deletions
9
packages/codemods/three/r168/drag-controls-to-connect/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 yugal41735 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
28 changes: 28 additions & 0 deletions
28
packages/codemods/three/r168/drag-controls-to-connect/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
This codemod renames dragcontrols.activate() to connect(). | ||
|
||
## Example | ||
|
||
### Before | ||
|
||
```ts | ||
taScene.dragControls.activate(); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
taScene.connect(); | ||
``` | ||
|
||
### Before | ||
|
||
```ts | ||
dragControls.activate(); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
connect(); | ||
``` | ||
|
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
taScene.dragControls.activate(); |
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
taScene.connect(); |
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dragControls.activate(); |
1 change: 1 addition & 0 deletions
1
packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
connect(); |
13 changes: 13 additions & 0 deletions
13
packages/codemods/three/r168/drag-controls-to-connect/cdmd_dist/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*! @license | ||
The MIT License (MIT) | ||
Copyright (c) 2024 yugal41735 | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return transform}});function transform(file,api,options){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.CallExpression,{callee:{type:"MemberExpression",property:{name:"activate"}}}).forEach(path=>{const{object}=path.node.callee;if(j.Identifier.check(object)&&object.name==="dragControls"){j(path).replaceWith(j.callExpression(j.identifier("connect"),[]));dirtyFlag=true}else if(j.MemberExpression.check(object)&&object.property.name==="dragControls"){j(path).replaceWith(j.callExpression(j.memberExpression(object.object,j.identifier("connect")),[]));dirtyFlag=true}});return dirtyFlag?root.toSource():undefined} |
23 changes: 23 additions & 0 deletions
23
packages/codemods/three/r168/drag-controls-to-connect/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "drag-controls-to-connect", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "20.9.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^1.0.1", | ||
"@codemod.com/codemod-utils": "*", | ||
"jscodeshift": "^0.15.1", | ||
"@types/jscodeshift": "^0.11.10" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"test:watch": "vitest watch" | ||
}, | ||
"files": [ | ||
"README.md", | ||
".codemodrc.json", | ||
"/dist/index.cjs" | ||
], | ||
"type": "module", | ||
"author": "yugal41735" | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/codemods/three/r168/drag-controls-to-connect/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export default function transform(file, api, options) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
let dirtyFlag = false; | ||
|
||
// Replace `dragControls.activate()` with `connect()` | ||
root.find(j.CallExpression, { | ||
callee: { | ||
type: 'MemberExpression', | ||
property: { name: 'activate' } | ||
} | ||
}).forEach(path => { | ||
const { object } = path.node.callee; | ||
if (j.Identifier.check(object) && object.name === 'dragControls') { | ||
j(path).replaceWith(j.callExpression(j.identifier('connect'), [])); | ||
dirtyFlag = true; | ||
} else if (j.MemberExpression.check(object) && object.property.name === 'dragControls') { | ||
j(path).replaceWith(j.callExpression(j.memberExpression(object.object, j.identifier('connect')), [])); | ||
dirtyFlag = true; | ||
} | ||
}); | ||
|
||
return dirtyFlag ? root.toSource() : undefined; | ||
} |
Oops, something went wrong.