From a38a37efe6ffd723efb902f26e8e8e9dddb1c99f Mon Sep 17 00:00:00 2001 From: Yugal Agarwal Date: Mon, 9 Sep 2024 21:32:09 +0530 Subject: [PATCH] Added three.js r168 codemods --- .../deactivate-to-disconnect/.codemodrc.json | 15 ++++ .../r168/deactivate-to-disconnect/.gitignore | 2 + .../r168/deactivate-to-disconnect/LICENSE | 9 +++ .../r168/deactivate-to-disconnect/README.md | 28 +++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../__testfixtures__/fixture2.input.ts | 1 + .../__testfixtures__/fixture2.output.ts | 1 + .../cdmd_dist/index.cjs | 13 ++++ .../deactivate-to-disconnect/package.json | 23 ++++++ .../deactivate-to-disconnect/src/index.ts | 36 +++++++++ .../deactivate-to-disconnect/test/test.ts | 57 ++++++++++++++ .../deactivate-to-disconnect/tsconfig.json | 38 ++++++++++ .../deactivate-to-disconnect/vitest.config.ts | 7 ++ .../drag-controls-to-connect/.codemodrc.json | 15 ++++ .../r168/drag-controls-to-connect/.gitignore | 2 + .../r168/drag-controls-to-connect/LICENSE | 9 +++ .../r168/drag-controls-to-connect/README.md | 28 +++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../__testfixtures__/fixture2.input.ts | 1 + .../__testfixtures__/fixture2.output.ts | 1 + .../cdmd_dist/index.cjs | 13 ++++ .../drag-controls-to-connect/package.json | 23 ++++++ .../drag-controls-to-connect/src/index.ts | 24 ++++++ .../drag-controls-to-connect/test/test.ts | 57 ++++++++++++++ .../drag-controls-to-connect/tsconfig.json | 38 ++++++++++ .../drag-controls-to-connect/vitest.config.ts | 7 ++ .../.codemodrc.json | 15 ++++ .../.gitignore | 2 + .../LICENSE | 9 +++ .../README.md | 43 +++++++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../__testfixtures__/fixture2.input.ts | 1 + .../__testfixtures__/fixture2.output.ts | 1 + .../__testfixtures__/fixture3.input.ts | 1 + .../__testfixtures__/fixture3.output.ts | 1 + .../cdmd_dist/index.cjs | 13 ++++ .../package.json | 23 ++++++ .../src/index.ts | 40 ++++++++++ .../test/test.ts | 74 +++++++++++++++++++ .../tsconfig.json | 38 ++++++++++ .../vitest.config.ts | 7 ++ .../.codemodrc.json | 15 ++++ .../.gitignore | 2 + .../replace-dragcontrols-getraycaster/LICENSE | 9 +++ .../README.md | 45 +++++++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../__testfixtures__/fixture2.input.ts | 1 + .../__testfixtures__/fixture2.output.ts | 1 + .../__testfixtures__/fixture3.input.ts | 3 + .../__testfixtures__/fixture3.output.ts | 3 + .../cdmd_dist/index.cjs | 13 ++++ .../package.json | 23 ++++++ .../src/index.ts | 45 +++++++++++ .../test/test.ts | 74 +++++++++++++++++++ .../tsconfig.json | 38 ++++++++++ .../vitest.config.ts | 7 ++ .../.codemodrc.json | 15 ++++ .../.gitignore | 2 + .../LICENSE | 9 +++ .../README.md | 32 ++++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../__testfixtures__/fixture2.input.ts | 1 + .../__testfixtures__/fixture2.output.ts | 1 + .../cdmd_dist/index.cjs | 13 ++++ .../package.json | 23 ++++++ .../src/index.ts | 26 +++++++ .../test/test.ts | 57 ++++++++++++++ .../tsconfig.json | 38 ++++++++++ .../vitest.config.ts | 7 ++ .../.codemodrc.json | 15 ++++ .../.gitignore | 2 + .../LICENSE | 9 +++ .../README.md | 28 +++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../__testfixtures__/fixture2.input.ts | 1 + .../__testfixtures__/fixture2.output.ts | 1 + .../cdmd_dist/index.cjs | 13 ++++ .../package.json | 23 ++++++ .../src/index.ts | 30 ++++++++ .../test/test.ts | 57 ++++++++++++++ .../tsconfig.json | 38 ++++++++++ .../vitest.config.ts | 7 ++ .../three_migration_recipe/.codemodrc.json | 54 ++++++++++++++ .../r168/three_migration_recipe/README.md | 13 ++++ .../r168/three_migration_recipe/package.json | 6 ++ .../transform_logluvloader/.codemodrc.json | 16 ++++ .../r168/transform_logluvloader/.gitignore | 2 + .../three/r168/transform_logluvloader/LICENSE | 9 +++ .../r168/transform_logluvloader/README.md | 41 ++++++++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../cdmd_dist/index.cjs | 56 ++++++++++++++ .../r168/transform_logluvloader/package.json | 23 ++++++ .../r168/transform_logluvloader/src/index.ts | 57 ++++++++++++++ .../r168/transform_logluvloader/test/test.ts | 40 ++++++++++ .../r168/transform_logluvloader/tsconfig.json | 38 ++++++++++ .../transform_logluvloader/vitest.config.ts | 7 ++ .../uniforms-to-uniformarray/.codemodrc.json | 16 ++++ .../r168/uniforms-to-uniformarray/.gitignore | 2 + .../r168/uniforms-to-uniformarray/LICENSE | 9 +++ .../r168/uniforms-to-uniformarray/README.md | 17 +++++ .../__testfixtures__/fixture1.input.ts | 1 + .../__testfixtures__/fixture1.output.ts | 1 + .../cdmd_dist/index.cjs | 20 +++++ .../uniforms-to-uniformarray/package.json | 23 ++++++ .../uniforms-to-uniformarray/src/index.ts | 21 ++++++ .../uniforms-to-uniformarray/test/test.ts | 40 ++++++++++ .../uniforms-to-uniformarray/tsconfig.json | 38 ++++++++++ .../uniforms-to-uniformarray/vitest.config.ts | 7 ++ 115 files changed, 2014 insertions(+) create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/.codemodrc.json create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/.gitignore create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/LICENSE create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/README.md create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.input.ts create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.output.ts create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/package.json create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/src/index.ts create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/test/test.ts create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/tsconfig.json create mode 100644 packages/codemods/three/r168/deactivate-to-disconnect/vitest.config.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/.codemodrc.json create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/.gitignore create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/LICENSE create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/README.md create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.input.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.output.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/package.json create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/src/index.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/test/test.ts create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/tsconfig.json create mode 100644 packages/codemods/three/r168/drag-controls-to-connect/vitest.config.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.codemodrc.json create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.gitignore create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/LICENSE create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/README.md create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.input.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.output.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.input.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.output.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/package.json create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/src/index.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/test/test.ts create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/tsconfig.json create mode 100644 packages/codemods/three/r168/pointer-lock-controls-to-controls-object/vitest.config.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/.codemodrc.json create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/.gitignore create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/LICENSE create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/README.md create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.input.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.output.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.input.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.output.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/package.json create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/src/index.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/test/test.ts create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/tsconfig.json create mode 100644 packages/codemods/three/r168/replace-dragcontrols-getraycaster/vitest.config.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.codemodrc.json create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.gitignore create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/LICENSE create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/README.md create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.input.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.output.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/package.json create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/src/index.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/test/test.ts create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/tsconfig.json create mode 100644 packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/vitest.config.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.codemodrc.json create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.gitignore create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/LICENSE create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/README.md create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.input.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.output.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/package.json create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/src/index.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/test/test.ts create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/tsconfig.json create mode 100644 packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/vitest.config.ts create mode 100644 packages/codemods/three/r168/three_migration_recipe/.codemodrc.json create mode 100644 packages/codemods/three/r168/three_migration_recipe/README.md create mode 100644 packages/codemods/three/r168/three_migration_recipe/package.json create mode 100644 packages/codemods/three/r168/transform_logluvloader/.codemodrc.json create mode 100644 packages/codemods/three/r168/transform_logluvloader/.gitignore create mode 100644 packages/codemods/three/r168/transform_logluvloader/LICENSE create mode 100644 packages/codemods/three/r168/transform_logluvloader/README.md create mode 100644 packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/transform_logluvloader/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/transform_logluvloader/package.json create mode 100644 packages/codemods/three/r168/transform_logluvloader/src/index.ts create mode 100644 packages/codemods/three/r168/transform_logluvloader/test/test.ts create mode 100644 packages/codemods/three/r168/transform_logluvloader/tsconfig.json create mode 100644 packages/codemods/three/r168/transform_logluvloader/vitest.config.ts create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/.codemodrc.json create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/.gitignore create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/LICENSE create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/README.md create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/cdmd_dist/index.cjs create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/package.json create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/src/index.ts create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/test/test.ts create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/tsconfig.json create mode 100644 packages/codemods/three/r168/uniforms-to-uniformarray/vitest.config.ts diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/.codemodrc.json b/packages/codemods/three/r168/deactivate-to-disconnect/.codemodrc.json new file mode 100644 index 000000000..37db2e948 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/.codemodrc.json @@ -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" + ] + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/.gitignore b/packages/codemods/three/r168/deactivate-to-disconnect/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/LICENSE b/packages/codemods/three/r168/deactivate-to-disconnect/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/README.md b/packages/codemods/three/r168/deactivate-to-disconnect/README.md new file mode 100644 index 000000000..6ee6bc2db --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/README.md @@ -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(); +``` + diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..ce0cb2d06 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +taScene.dragControls.deactivate(); \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..9bccfc7a7 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +taScene.disconnect(); \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.input.ts b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.input.ts new file mode 100644 index 000000000..b1ddb194e --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.input.ts @@ -0,0 +1 @@ +dragControls.deactivate(); \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.output.ts b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.output.ts new file mode 100644 index 000000000..b2bae6253 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/__testfixtures__/fixture2.output.ts @@ -0,0 +1 @@ +disconnect(); \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/cdmd_dist/index.cjs b/packages/codemods/three/r168/deactivate-to-disconnect/cdmd_dist/index.cjs new file mode 100644 index 000000000..dfe9ca42f --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/cdmd_dist/index.cjs @@ -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} \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/package.json b/packages/codemods/three/r168/deactivate-to-disconnect/package.json new file mode 100644 index 000000000..c2244ab01 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/package.json @@ -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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/src/index.ts b/packages/codemods/three/r168/deactivate-to-disconnect/src/index.ts new file mode 100644 index 000000000..a3a037a10 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/src/index.ts @@ -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; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/test/test.ts b/packages/codemods/three/r168/deactivate-to-disconnect/test/test.ts new file mode 100644 index 000000000..1bd72040c --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/test/test.ts @@ -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, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/tsconfig.json b/packages/codemods/three/r168/deactivate-to-disconnect/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/deactivate-to-disconnect/vitest.config.ts b/packages/codemods/three/r168/deactivate-to-disconnect/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/deactivate-to-disconnect/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/.codemodrc.json b/packages/codemods/three/r168/drag-controls-to-connect/.codemodrc.json new file mode 100644 index 000000000..e91364d07 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/.codemodrc.json @@ -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" + ] + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/.gitignore b/packages/codemods/three/r168/drag-controls-to-connect/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/LICENSE b/packages/codemods/three/r168/drag-controls-to-connect/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/drag-controls-to-connect/README.md b/packages/codemods/three/r168/drag-controls-to-connect/README.md new file mode 100644 index 000000000..c30cb7229 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/README.md @@ -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(); +``` + diff --git a/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..eda629798 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +taScene.dragControls.activate(); \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..9ed9611d2 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +taScene.connect(); \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.input.ts b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.input.ts new file mode 100644 index 000000000..20ba2fc64 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.input.ts @@ -0,0 +1 @@ +dragControls.activate(); \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.output.ts b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.output.ts new file mode 100644 index 000000000..defe713d5 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/__testfixtures__/fixture2.output.ts @@ -0,0 +1 @@ +connect(); \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/cdmd_dist/index.cjs b/packages/codemods/three/r168/drag-controls-to-connect/cdmd_dist/index.cjs new file mode 100644 index 000000000..8d534c9a8 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/cdmd_dist/index.cjs @@ -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} \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/package.json b/packages/codemods/three/r168/drag-controls-to-connect/package.json new file mode 100644 index 000000000..1e510b308 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/package.json @@ -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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/src/index.ts b/packages/codemods/three/r168/drag-controls-to-connect/src/index.ts new file mode 100644 index 000000000..afcbaad60 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/src/index.ts @@ -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; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/test/test.ts b/packages/codemods/three/r168/drag-controls-to-connect/test/test.ts new file mode 100644 index 000000000..c92a32879 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/test/test.ts @@ -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('drag-controls-to-connect', () => { + 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, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/tsconfig.json b/packages/codemods/three/r168/drag-controls-to-connect/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/drag-controls-to-connect/vitest.config.ts b/packages/codemods/three/r168/drag-controls-to-connect/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/drag-controls-to-connect/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.codemodrc.json b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.codemodrc.json new file mode 100644 index 000000000..eca657cb2 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.codemodrc.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/pointerlockcontrols-object-to-controls-object", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "three", + "migration", + "r168" + ] + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.gitignore b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/LICENSE b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/README.md b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/README.md new file mode 100644 index 000000000..f76e1dfc2 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/README.md @@ -0,0 +1,43 @@ +This codemod helps in transforming `PointerLockControls.getObject()` to `controls.object` + + +## Example + +### Before + +```ts +pointerLockControls.getObject().translateX(translationVelocity.x * delta); +``` + +### After + +```ts +controls.object.translateX(translationVelocity.x * delta); +``` + + +### Before + +```ts +pointerLockControls.getObject().translateY(translationVelocity.y * delta); +``` + +### After + +```ts +controls.object.translateY(translationVelocity.y * delta); +``` + + +### Before + +```ts +pointerLockControls.getObject().translateZ(translationVelocity.z * delta); +``` + +### After + +```ts +controls.object.translateZ(translationVelocity.z * delta); +``` + diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..192024a0e --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +pointerLockControls.getObject().translateX(translationVelocity.x * delta); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..55ef955d1 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +controls.object.translateX(translationVelocity.x * delta); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.input.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.input.ts new file mode 100644 index 000000000..e20af376b --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.input.ts @@ -0,0 +1 @@ +pointerLockControls.getObject().translateY(translationVelocity.y * delta); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.output.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.output.ts new file mode 100644 index 000000000..6134f2208 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture2.output.ts @@ -0,0 +1 @@ +controls.object.translateY(translationVelocity.y * delta); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.input.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.input.ts new file mode 100644 index 000000000..923b97a52 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.input.ts @@ -0,0 +1 @@ +pointerLockControls.getObject().translateZ(translationVelocity.z * delta); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.output.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.output.ts new file mode 100644 index 000000000..c2f61df19 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/__testfixtures__/fixture3.output.ts @@ -0,0 +1 @@ +controls.object.translateZ(translationVelocity.z * delta); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/cdmd_dist/index.cjs b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/cdmd_dist/index.cjs new file mode 100644 index 000000000..3e6f27418 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/cdmd_dist/index.cjs @@ -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).forEach(path=>{const{callee}=path.node;if(j.MemberExpression.check(callee)){const{object,property}=callee;if(j.CallExpression.check(object)){const{callee:innerCallee}=object;if(j.MemberExpression.check(innerCallee)){const{object:innerObject,property:innerProperty}=innerCallee;if(j.Identifier.check(innerObject)&&innerObject.name==="pointerLockControls"){if(j.Identifier.check(innerProperty)&&innerProperty.name==="getObject"){path.node.callee=j.memberExpression(j.memberExpression(j.identifier("controls"),j.identifier("object")),property);dirtyFlag=true}}}}}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/package.json b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/package.json new file mode 100644 index 000000000..1d5a3b61c --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/package.json @@ -0,0 +1,23 @@ +{ + "name": "three-js-pointer-lock-controls-to-controls-object", + "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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/src/index.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/src/index.ts new file mode 100644 index 000000000..53edc23df --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/src/index.ts @@ -0,0 +1,40 @@ +export default function transform(file, api, options) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Find all CallExpressions + root.find(j.CallExpression).forEach(path => { + const { callee } = path.node; + + // Check if the callee is a MemberExpression + if (j.MemberExpression.check(callee)) { + const { object, property } = callee; + + // Check if the object is another CallExpression + if (j.CallExpression.check(object)) { + const { callee: innerCallee } = object; + + // Check if the inner callee is a MemberExpression + if (j.MemberExpression.check(innerCallee)) { + const { object: innerObject, property: innerProperty } = innerCallee; + + // Check if the inner object is an Identifier named 'pointerLockControls' + if (j.Identifier.check(innerObject) && innerObject.name === 'pointerLockControls') { + // Check if the inner property is an Identifier named 'getObject' + if (j.Identifier.check(innerProperty) && innerProperty.name === 'getObject') { + // Replace 'pointerLockControls.getObject()' with 'controls.object' + path.node.callee = j.memberExpression( + j.memberExpression(j.identifier('controls'), j.identifier('object')), + property + ); + dirtyFlag = true; + } + } + } + } + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/test/test.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/test/test.ts new file mode 100644 index 000000000..9275b4172 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/test/test.ts @@ -0,0 +1,74 @@ +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('three-js/pointer-lock-controls-to-controls-object', () => { + 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, ''), + ); + }); + + it('test #3', async () => { + const INPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture3.input.ts'), 'utf-8'); + const OUTPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture3.output.ts'), 'utf-8'); + + const actualOutput = transform({ + path: 'index.js', + source: INPUT, + }, + buildApi('tsx'), {} + ); + + assert.deepEqual( + actualOutput?.replace(/W/gm, ''), + OUTPUT.replace(/W/gm, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/tsconfig.json b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/vitest.config.ts b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/pointer-lock-controls-to-controls-object/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/.codemodrc.json b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/.codemodrc.json new file mode 100644 index 000000000..7062b7be5 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/.codemodrc.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/dragcontrols-getraycaster-to-controls-raycaster", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "three", + "migration", + "r168" + ] + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/.gitignore b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/LICENSE b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/README.md b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/README.md new file mode 100644 index 000000000..f3593dfd7 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/README.md @@ -0,0 +1,45 @@ +This codemod renames DragControls.getRaycaster() to controls.raycaster + + +## Example + +### Before + +```ts +taScene.dragcontrols.getRaycaster(); +``` + +### After + +```ts +taScene.controls.raycaster; +``` + +### Before + +```ts +dragcontrols.getRaycaster(); +``` + +### After + +```ts +controls.raycaster; +``` + +### Before + +```ts +if (something) { + anything.dragcontrols.getRaycaster(); +} +``` + +### After + +```ts +if (something) { + anything.controls.raycaster; +} +``` + diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..4f7b51678 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +taScene.dragcontrols.getRaycaster(); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..9818137fa --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +taScene.controls.raycaster; \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.input.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.input.ts new file mode 100644 index 000000000..72c2da956 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.input.ts @@ -0,0 +1 @@ +dragcontrols.getRaycaster(); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.output.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.output.ts new file mode 100644 index 000000000..e03e6ea10 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture2.output.ts @@ -0,0 +1 @@ +controls.raycaster; \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.input.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.input.ts new file mode 100644 index 000000000..0b1d46e79 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.input.ts @@ -0,0 +1,3 @@ +if (something) { + anything.dragcontrols.getRaycaster(); +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.output.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.output.ts new file mode 100644 index 000000000..72e1e3083 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/__testfixtures__/fixture3.output.ts @@ -0,0 +1,3 @@ +if (something) { + anything.controls.raycaster; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/cdmd_dist/index.cjs b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/cdmd_dist/index.cjs new file mode 100644 index 000000000..08972d1e5 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/cdmd_dist/index.cjs @@ -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:{object:{name:"dragcontrols"},property:{name:"getRaycaster"}}}).forEach(path=>{j(path).replaceWith(j.memberExpression(j.identifier("controls"),j.identifier("raycaster")));dirtyFlag=true});root.find(j.MemberExpression,{object:{type:"MemberExpression",property:{name:"dragcontrols"}},property:{name:"getRaycaster"}}).forEach(path=>{j(path).replaceWith(j.memberExpression(j.memberExpression(path.node.object.object,j.identifier("controls")),j.identifier("raycaster")));dirtyFlag=true});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/package.json b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/package.json new file mode 100644 index 000000000..24c4175a0 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/package.json @@ -0,0 +1,23 @@ +{ + "name": "threejs-replace-dragcontrols-getraycaster", + "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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/src/index.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/src/index.ts new file mode 100644 index 000000000..f2976fa4d --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/src/index.ts @@ -0,0 +1,45 @@ +export default function transform(file, api, options) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Find all CallExpressions + root.find(j.CallExpression, { + callee: { + object: { name: 'dragcontrols' }, + property: { name: 'getRaycaster' } + } + }).forEach(path => { + // Replace with MemberExpression + j(path).replaceWith( + j.memberExpression( + j.identifier('controls'), + j.identifier('raycaster') + ) + ); + dirtyFlag = true; + }); + + // Find all MemberExpressions with dragcontrols.getRaycaster() + root.find(j.MemberExpression, { + object: { + type: 'MemberExpression', + property: { name: 'dragcontrols' } + }, + property: { name: 'getRaycaster' } + }).forEach(path => { + // Replace with MemberExpression + j(path).replaceWith( + j.memberExpression( + j.memberExpression( + path.node.object.object, + j.identifier('controls') + ), + j.identifier('raycaster') + ) + ); + dirtyFlag = true; + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/test/test.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/test/test.ts new file mode 100644 index 000000000..0217f213c --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/test/test.ts @@ -0,0 +1,74 @@ +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('threejs/replace-dragcontrols-getraycaster', () => { + 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, ''), + ); + }); + + it('test #3', async () => { + const INPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture3.input.ts'), 'utf-8'); + const OUTPUT = await readFile(join(__dirname, '..', '__testfixtures__/fixture3.output.ts'), 'utf-8'); + + const actualOutput = transform({ + path: 'index.js', + source: INPUT, + }, + buildApi('tsx'), {} + ); + + assert.deepEqual( + actualOutput?.replace(/W/gm, ''), + OUTPUT.replace(/W/gm, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/tsconfig.json b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-dragcontrols-getraycaster/vitest.config.ts b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/replace-dragcontrols-getraycaster/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.codemodrc.json b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.codemodrc.json new file mode 100644 index 000000000..c1caf8659 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.codemodrc.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/viewportBottomLeft-to-viewportUV.flipY()", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "three", + "migration", + "r168" + ] + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.gitignore b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/LICENSE b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/README.md b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/README.md new file mode 100644 index 000000000..b6c4e3795 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/README.md @@ -0,0 +1,32 @@ +This codemod replaces viewportBottomLeft with viewportUV.flipY() + + +## Example + +Additional Information: But keep in mind we have to remove viewportBottomLeft manually from the import statement. +In this version it does not remove viewportBottomLeft from import statements. + +### Before + +```ts +backgroundNode = texture(background, viewportBottomLeft).setUpdateMatrix(true); +``` + +### After + +```ts +backgroundNode = texture(background, viewportUV.flipY()).setUpdateMatrix(true); +``` + +### Before + +```ts +nodeUV = viewportBottomLeft; +``` + +### After + +```ts +nodeUV = viewportUV.flipY(); +``` + diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..d91d94681 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +backgroundNode = texture(background, viewportBottomLeft).setUpdateMatrix(true); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..100e3f926 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +backgroundNode = texture(background, viewportUV.flipY()).setUpdateMatrix(true); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.input.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.input.ts new file mode 100644 index 000000000..851c47518 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.input.ts @@ -0,0 +1 @@ +nodeUV = viewportBottomLeft; \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.output.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.output.ts new file mode 100644 index 000000000..c7887e13d --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/__testfixtures__/fixture2.output.ts @@ -0,0 +1 @@ +nodeUV = viewportUV.flipY(); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/cdmd_dist/index.cjs b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/cdmd_dist/index.cjs new file mode 100644 index 000000000..1e1a4d100 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/cdmd_dist/index.cjs @@ -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.Identifier,{name:"viewportBottomLeft"}).forEach(path=>{const parent=path.parent.node;if(j.AssignmentExpression.check(parent)||j.VariableDeclarator.check(parent)||j.CallExpression.check(parent)){j(path).replaceWith(j.callExpression(j.memberExpression(j.identifier("viewportUV"),j.identifier("flipY")),[]));dirtyFlag=true}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/package.json b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/package.json new file mode 100644 index 000000000..bd194b980 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/package.json @@ -0,0 +1,23 @@ +{ + "name": "replace-viewport-bottom-left-with-viewportuv-flipy", + "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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/src/index.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/src/index.ts new file mode 100644 index 000000000..091fd57a4 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/src/index.ts @@ -0,0 +1,26 @@ +export default function transform(file, api, options) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Replace instances of `viewportBottomLeft` with `viewportUV.flipY()` + root.find(j.Identifier, { name: 'viewportBottomLeft' }).forEach(path => { + const parent = path.parent.node; + + // Ensure the parent node is an appropriate type for replacement + if (j.AssignmentExpression.check(parent) || j.VariableDeclarator.check(parent) || j.CallExpression.check(parent)) { + j(path).replaceWith( + j.callExpression( + j.memberExpression( + j.identifier('viewportUV'), + j.identifier('flipY') + ), + [] + ) + ); + dirtyFlag = true; + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/test/test.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/test/test.ts new file mode 100644 index 000000000..d1624c268 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/test/test.ts @@ -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('replace-viewport-bottom-left-with-viewportuv-flipy', () => { + 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, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/tsconfig.json b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/vitest.config.ts b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-bottom-left-with-viewportuv-flipy/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.codemodrc.json b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.codemodrc.json new file mode 100644 index 000000000..ed3777b1e --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.codemodrc.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/viewportTopLeft-to-viewportUV", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "three", + "migration", + "r168" + ] + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.gitignore b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/LICENSE b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/README.md b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/README.md new file mode 100644 index 000000000..0fe25a35e --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/README.md @@ -0,0 +1,28 @@ +This codemod replaces viewportTopLeft with viewportUV + +## Example + +### Before + +```ts +import { toneMapping, color, viewportTopLeft } from 'three/nodes'; +``` + +### After + +```ts +import { toneMapping, color, viewportUV } from 'three/nodes'; +``` + +### Before + +```ts +scene.backgroundNode = viewportTopLeft.y.mix(color(0x66bbff), color(0x4466ff)); +``` + +### After + +```ts +scene.backgroundNode = viewportUV.y.mix(color(0x66bbff), color(0x4466ff)); +``` + diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..4ce782934 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +import { toneMapping, color, viewportTopLeft } from 'three/nodes'; \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..a9bb4fcd9 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +import { toneMapping, color, viewportUV } from 'three/nodes'; \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.input.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.input.ts new file mode 100644 index 000000000..d9a5af6f3 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.input.ts @@ -0,0 +1 @@ +scene.backgroundNode = viewportTopLeft.y.mix(color(0x66bbff), color(0x4466ff)); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.output.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.output.ts new file mode 100644 index 000000000..cdd994d9c --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/__testfixtures__/fixture2.output.ts @@ -0,0 +1 @@ +scene.backgroundNode = viewportUV.y.mix(color(0x66bbff), color(0x4466ff)); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/cdmd_dist/index.cjs b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/cdmd_dist/index.cjs new file mode 100644 index 000000000..ba95ecd18 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/cdmd_dist/index.cjs @@ -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.Identifier,{name:"viewportTopLeft"}).replaceWith(path=>{dirtyFlag=true;return j.identifier("viewportUV")});root.find(j.ImportDeclaration).forEach(path=>{const specifiers=path.node.specifiers;let importChanged=false;specifiers.forEach(specifier=>{if(j.ImportSpecifier.check(specifier)&&specifier.imported.name==="viewportTopLeft"){specifier.imported=j.identifier("viewportUV");importChanged=true}});if(importChanged){dirtyFlag=true}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/package.json b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/package.json new file mode 100644 index 000000000..f9dedf70d --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/package.json @@ -0,0 +1,23 @@ +{ + "name": "replace-viewport-top-left-with-viewport-uv", + "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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/src/index.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/src/index.ts new file mode 100644 index 000000000..2da1be965 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/src/index.ts @@ -0,0 +1,30 @@ +export default function transform(file, api, options) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Replace all instances of `viewportTopLeft` with `viewportUV` + root.find(j.Identifier, { name: 'viewportTopLeft' }).replaceWith(path => { + dirtyFlag = true; + return j.identifier('viewportUV'); + }); + + // Update the import statement if necessary + root.find(j.ImportDeclaration).forEach(path => { + const specifiers = path.node.specifiers; + let importChanged = false; + + specifiers.forEach(specifier => { + if (j.ImportSpecifier.check(specifier) && specifier.imported.name === 'viewportTopLeft') { + specifier.imported = j.identifier('viewportUV'); + importChanged = true; + } + }); + + if (importChanged) { + dirtyFlag = true; + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/test/test.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/test/test.ts new file mode 100644 index 000000000..187d70faa --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/test/test.ts @@ -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('replace-viewport-top-left-with-viewport-uv', () => { + 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, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/tsconfig.json b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/vitest.config.ts b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/replace-viewport-top-left-with-viewport-uv/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/three_migration_recipe/.codemodrc.json b/packages/codemods/three/r168/three_migration_recipe/.codemodrc.json new file mode 100644 index 000000000..5622e1526 --- /dev/null +++ b/packages/codemods/three/r168/three_migration_recipe/.codemodrc.json @@ -0,0 +1,54 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/migration-recipe", + "version": "1.0.2", + "engine": "recipe", + "private": false, + "include": [ + "**/*.js", + "**/*.jsx", + "**/*.ts", + "**/*.tsx", + "**/*.vue" + ], + "applicability": { + "from": [ + [ + "three", + ">=", + "0.167.0" + ], + [ + "meteor", + "<", + "0.168.0" + ] + ], + "to": [ + [ + "meteor", + ">=", + "0.168.0" + ] + ] + }, + "arguments": [], + "meta": { + "tags": [ + "migration", + "three", + "r168" + ], + "git": "https://github.com/Yugal41735/deno-webgpu-window-demos.git" + }, + "names": [ + "three/r168/uniforms-to-uniformarray", + "three/r168/logluvloader-to-ultraHDRLoader", + "three/r168/pointerlockcontrols-object-to-controls-object", + "three/r168/dragcontrols-getraycaster-to-controls-raycaster", + "three/r168/dragcontrols.deactivate-to-disconnect", + "three/r168/dragcontrols.activate-to-connect", + "three/r168/viewportBottomLeft-to-viewportUV.flipY()", + "three/r168/viewportTopLeft-to-viewportUV" + ] +} \ No newline at end of file diff --git a/packages/codemods/three/r168/three_migration_recipe/README.md b/packages/codemods/three/r168/three_migration_recipe/README.md new file mode 100644 index 000000000..65670eb06 --- /dev/null +++ b/packages/codemods/three/r168/three_migration_recipe/README.md @@ -0,0 +1,13 @@ +This recipe is a set of codemods that will help migrate to three r168 from three r167 . + +The recipe includes the following codemods: + + +- three/r168/uniforms-to-uniformarray +- three/r168/logluvloader-to-ultraHDRLoader +- three/r168/pointerlockcontrols-object-to-controls-object +- three/r168/dragcontrols-getraycaster-to-controls-raycaster +- three/r168/dragcontrols.deactivate-to-disconnect +- three/r168/dragcontrols.activate-to-connect +- three/r168/viewportBottomLeft-to-viewportUV.flipY() +- three/r168/viewportTopLeft-to-viewportUV diff --git a/packages/codemods/three/r168/three_migration_recipe/package.json b/packages/codemods/three/r168/three_migration_recipe/package.json new file mode 100644 index 000000000..a72cd743c --- /dev/null +++ b/packages/codemods/three/r168/three_migration_recipe/package.json @@ -0,0 +1,6 @@ +{ + "name": "@codemod/three-r168-migration-recipe", + "files": ["./README.md", "./.codemodrc.json"], + "type": "module", + "private": true +} diff --git a/packages/codemods/three/r168/transform_logluvloader/.codemodrc.json b/packages/codemods/three/r168/transform_logluvloader/.codemodrc.json new file mode 100644 index 000000000..6368e8ca7 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/.codemodrc.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/logluvloader-to-ultraHDRLoader", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "three", + "migration", + "r168" + ], + "git": "https://github.com/Yugal41735/Codemod-Test.git" + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/.gitignore b/packages/codemods/three/r168/transform_logluvloader/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/LICENSE b/packages/codemods/three/r168/transform_logluvloader/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/transform_logluvloader/README.md b/packages/codemods/three/r168/transform_logluvloader/README.md new file mode 100644 index 000000000..4cd4c8740 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/README.md @@ -0,0 +1,41 @@ +This codemod removes `LogLuvLoader`, and replaces it with `UltraHDRLoader` + +## Example + + +### Before + +```ts +import { LogLuvLoade } from "three/examples/jsm/loaders/LogLuvLoader.js"; +``` + +### After + +```ts +import { UltraHDRLoader } from "three/examples/jsm/loaders/UltraHDRLoader.js"; +``` + +### Before + +```ts +export * from "./loaders/UltraHDRLoader.js"; +``` + +### After + +```ts +export * from "./loadersLogLuvLoader.js"; +``` + +### Before + +```ts +case 'logluv': return new LogLuvLoader(this.loadingManager); +``` + +### After + +```ts +case 'logluv': return new UltraHDRLoader(this.loadingManager); +``` + diff --git a/packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..ff213f8c4 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +const toReplace = "hello"; \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..48d3cad80 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +const replacement = "hello"; \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/cdmd_dist/index.cjs b/packages/codemods/three/r168/transform_logluvloader/cdmd_dist/index.cjs new file mode 100644 index 000000000..b97384558 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/cdmd_dist/index.cjs @@ -0,0 +1,56 @@ +module.exports = function (fileInfo, api) { + const j = api.jscodeshift; + const root = j(fileInfo.source); + + // Replace import declarations + root.find(j.ImportDeclaration).forEach(path => { + path.node.specifiers.forEach(specifier => { + if (specifier.imported && specifier.imported.name === 'LogLuvLoader') { + specifier.imported.name = 'UltraHDRLoader'; + specifier.local.name = 'UltraHDRLoader'; + } + }); + + // Also replace the source path if it contains LogLuvLoader + if (path.node.source.value.includes('LogLuvLoader')) { + path.node.source.value = path.node.source.value.replace('LogLuvLoader', 'UltraHDRLoader'); + } + }); + + // Replace export statements + root.find(j.ExportAllDeclaration).forEach(path => { + if (path.node.source && path.node.source.value.includes('LogLuvLoader')) { + path.node.source.value = path.node.source.value.replace('LogLuvLoader', 'UltraHDRLoader'); + } + }); + + // Replace New Expressions (instantiation) + root.find(j.NewExpression, { callee: { name: 'LogLuvLoader' } }).forEach(path => { + path.node.callee.name = 'UltraHDRLoader'; + }); + + // Replace identifiers and any other usage + root.find(j.Identifier, { name: 'LogLuvLoader' }).forEach(path => { + path.node.name = 'UltraHDRLoader'; + }); + + // Replace strings that contain 'LogLuvLoader' + root.find(j.Literal) + .filter(path => typeof path.node.value === 'string' && path.node.value.includes('LogLuvLoader')) + .forEach(path => { + path.node.value = path.node.value.replace(/LogLuvLoader/g, 'UltraHDRLoader'); + }); + + // Replace Template Literals that contain 'LogLuvLoader' + root.find(j.TemplateLiteral).forEach(path => { + path.node.quasis.forEach(quasi => { + if (quasi.value.raw.includes('LogLuvLoader')) { + quasi.value.raw = quasi.value.raw.replace(/LogLuvLoader/g, 'UltraHDRLoader'); + quasi.value.cooked = quasi.value.cooked.replace(/LogLuvLoader/g, 'UltraHDRLoader'); + } + }); + }); + + return root.toSource(); + }; + \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/package.json b/packages/codemods/three/r168/transform_logluvloader/package.json new file mode 100644 index 000000000..f1c537b3c --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/package.json @@ -0,0 +1,23 @@ +{ + "name": "three-transform-logluvloader", + "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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/src/index.ts b/packages/codemods/three/r168/transform_logluvloader/src/index.ts new file mode 100644 index 000000000..28c42ebba --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/src/index.ts @@ -0,0 +1,57 @@ +import { API, FileInfo } from 'jscodeshift'; + +export default function transformer(fileInfo: FileInfo, api: API) { + const j = api.jscodeshift; + const root = j(fileInfo.source); + + // Replace import declarations + root.find(j.ImportDeclaration).forEach(path => { + path.node.specifiers.forEach(specifier => { + if (specifier.imported && specifier.imported.name === 'LogLuvLoader') { + specifier.imported.name = 'UltraHDRLoader'; + specifier.local.name = 'UltraHDRLoader'; + } + }); + + // Also replace the source path if it contains LogLuvLoader + if (path.node.source.value.includes('LogLuvLoader')) { + path.node.source.value = path.node.source.value.replace('LogLuvLoader', 'UltraHDRLoader'); + } + }); + + // Replace export statements + root.find(j.ExportAllDeclaration).forEach(path => { + if (path.node.source && path.node.source.value.includes('LogLuvLoader')) { + path.node.source.value = path.node.source.value.replace('LogLuvLoader', 'UltraHDRLoader'); + } + }); + + // Replace New Expressions (instantiation) + root.find(j.NewExpression, { callee: { name: 'LogLuvLoader' } }).forEach(path => { + path.node.callee.name = 'UltraHDRLoader'; + }); + + // Replace identifiers and any other usage + root.find(j.Identifier, { name: 'LogLuvLoader' }).forEach(path => { + path.node.name = 'UltraHDRLoader'; + }); + + // Replace strings that contain 'LogLuvLoader' + root.find(j.Literal) + .filter(path => typeof path.node.value === 'string' && path.node.value.includes('LogLuvLoader')) + .forEach(path => { + path.node.value = path.node.value.replace(/LogLuvLoader/g, 'UltraHDRLoader'); + }); + + // Replace Template Literals that contain 'LogLuvLoader' + root.find(j.TemplateLiteral).forEach(path => { + path.node.quasis.forEach(quasi => { + if (quasi.value.raw.includes('LogLuvLoader')) { + quasi.value.raw = quasi.value.raw.replace(/LogLuvLoader/g, 'UltraHDRLoader'); + quasi.value.cooked = quasi.value.cooked.replace(/LogLuvLoader/g, 'UltraHDRLoader'); + } + }); + }); + + return root.toSource(); +} diff --git a/packages/codemods/three/r168/transform_logluvloader/test/test.ts b/packages/codemods/three/r168/transform_logluvloader/test/test.ts new file mode 100644 index 000000000..a5bae64aa --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/test/test.ts @@ -0,0 +1,40 @@ +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('three_transform_logluvloader', () => { + 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, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/tsconfig.json b/packages/codemods/three/r168/transform_logluvloader/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/transform_logluvloader/vitest.config.ts b/packages/codemods/three/r168/transform_logluvloader/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/transform_logluvloader/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/.codemodrc.json b/packages/codemods/three/r168/uniforms-to-uniformarray/.codemodrc.json new file mode 100644 index 000000000..7659d60e1 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/.codemodrc.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "three/r168/uniforms-to-uniformarray", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "three", + "migration", + "r168" + ], + "git": "https://github.com/Yugal41735/deno-webgpu-window-demos.git" + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/.gitignore b/packages/codemods/three/r168/uniforms-to-uniformarray/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/LICENSE b/packages/codemods/three/r168/uniforms-to-uniformarray/LICENSE new file mode 100644 index 000000000..eead6d696 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/LICENSE @@ -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. diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/README.md b/packages/codemods/three/r168/uniforms-to-uniformarray/README.md new file mode 100644 index 000000000..bee52f27f --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/README.md @@ -0,0 +1,17 @@ +This codemod renames uniforms() function, to uniformsArray() + + +## Example + +### Before + +```ts +this.emit('update', this.uniforms()); +``` + +### After + +```ts +this.emit('update', this.uniformsArray()); +``` + diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.input.ts b/packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..ff213f8c4 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.input.ts @@ -0,0 +1 @@ +const toReplace = "hello"; \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.output.ts b/packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..48d3cad80 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/__testfixtures__/fixture1.output.ts @@ -0,0 +1 @@ +const replacement = "hello"; \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/cdmd_dist/index.cjs b/packages/codemods/three/r168/uniforms-to-uniformarray/cdmd_dist/index.cjs new file mode 100644 index 000000000..cd3cecf34 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/cdmd_dist/index.cjs @@ -0,0 +1,20 @@ +module.exports = function (fileInfo, api) { + const j = api.jscodeshift; + const root = j(fileInfo.source); + + // Find all CallExpressions where .uniforms() is called + root.find(j.CallExpression, { + callee: { + type: 'MemberExpression', + property: { + name: 'uniforms', + }, + }, + }).forEach((path) => { + // Replace 'uniforms' with 'uniformArray' + path.node.callee.property.name = 'uniformArray'; + }); + + return root.toSource(); + }; + \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/package.json b/packages/codemods/three/r168/uniforms-to-uniformarray/package.json new file mode 100644 index 000000000..3b2d5f7e7 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/package.json @@ -0,0 +1,23 @@ +{ + "name": "three-r168-uniforms-to-uniformarray", + "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" +} \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/src/index.ts b/packages/codemods/three/r168/uniforms-to-uniformarray/src/index.ts new file mode 100644 index 000000000..1eb0bdf1b --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/src/index.ts @@ -0,0 +1,21 @@ +import { API, FileInfo } from 'jscodeshift'; + +export default function transformer(fileInfo: FileInfo, api: API) { + const j = api.jscodeshift; + const root = j(fileInfo.source); + + // Find all CallExpressions where .uniforms() is called + root.find(j.CallExpression, { + callee: { + type: 'MemberExpression', + property: { + name: 'uniforms', + }, + }, + }).forEach((path) => { + // Replace 'uniforms' with 'uniformArray' + path.node.callee.property.name = 'uniformArray'; + }); + + return root.toSource(); +} diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/test/test.ts b/packages/codemods/three/r168/uniforms-to-uniformarray/test/test.ts new file mode 100644 index 000000000..1415913d8 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/test/test.ts @@ -0,0 +1,40 @@ +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('three/r168/uniforms-to-uniformarray', () => { + 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, ''), + ); + }); +}); \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/tsconfig.json b/packages/codemods/three/r168/uniforms-to-uniformarray/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/tsconfig.json @@ -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 + } +} \ No newline at end of file diff --git a/packages/codemods/three/r168/uniforms-to-uniformarray/vitest.config.ts b/packages/codemods/three/r168/uniforms-to-uniformarray/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/three/r168/uniforms-to-uniformarray/vitest.config.ts @@ -0,0 +1,7 @@ +import { configDefaults, defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + include: [...configDefaults.include, '**/test/*.ts'], + }, +}); \ No newline at end of file