Skip to content

Commit

Permalink
Added three.js r168 codemods (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yugal41735 authored Sep 20, 2024
1 parent 4c0f5bb commit 8466809
Show file tree
Hide file tree
Showing 115 changed files with 2,014 additions and 0 deletions.
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"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
9 changes: 9 additions & 0 deletions packages/codemods/three/r168/deactivate-to-disconnect/LICENSE
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 packages/codemods/three/r168/deactivate-to-disconnect/README.md
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();
```

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
taScene.dragControls.deactivate();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
taScene.disconnect();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dragControls.deactivate();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disconnect();
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 packages/codemods/three/r168/deactivate-to-disconnect/package.json
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 packages/codemods/three/r168/deactivate-to-disconnect/src/index.ts
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 packages/codemods/three/r168/deactivate-to-disconnect/test/test.ts
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, ''),
);
});
});
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
}
}
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'],
},
});
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"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
9 changes: 9 additions & 0 deletions packages/codemods/three/r168/drag-controls-to-connect/LICENSE
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 packages/codemods/three/r168/drag-controls-to-connect/README.md
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();
```

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
taScene.dragControls.activate();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
taScene.connect();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dragControls.activate();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
connect();
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 packages/codemods/three/r168/drag-controls-to-connect/package.json
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 packages/codemods/three/r168/drag-controls-to-connect/src/index.ts
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;
}
Loading

0 comments on commit 8466809

Please sign in to comment.