From 0e90360d0d6571aa2660173ed283684045a0650c Mon Sep 17 00:00:00 2001 From: Dilpreet <92905896+dfordp@users.noreply.github.com> Date: Thu, 29 Aug 2024 22:46:17 +0530 Subject: [PATCH 1/2] added radix-vue codemods --- .../.codemodrc.json | 19 +++ .../.gitignore | 2 + .../LICENSE | 9 ++ .../README.md | 47 ++++++ .../__testfixtures__/fixture1.input.ts | 15 ++ .../__testfixtures__/fixture1.output.ts | 18 +++ .../cdmd_dist/index.cjs | 13 ++ .../package.json | 23 +++ .../src/index.ts | 82 +++++++++++ .../test/test.ts | 40 +++++ .../tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + .../.codemodrc.json | 12 ++ .../radix-vue-tab-v1.9.4-update/.gitignore | 2 + .../radix-vue-tab-v1.9.4-update/LICENSE | 9 ++ .../radix-vue-tab-v1.9.4-update/README.md | 28 ++++ .../__testfixtures__/fixture1.input.ts | 7 + .../__testfixtures__/fixture1.output.ts | 7 + .../cdmd_dist/index.cjs | 13 ++ .../radix-vue-tab-v1.9.4-update/package.json | 23 +++ .../radix-vue-tab-v1.9.4-update/src/index.ts | 41 ++++++ .../radix-vue-tab-v1.9.4-update/test/test.ts | 40 +++++ .../radix-vue-tab-v1.9.4-update/tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + .../.codemodrc.json | 20 +++ .../.gitignore | 2 + .../LICENSE | 9 ++ .../README.md | 138 ++++++++++++++++++ .../__testfixtures__/fixture1.input.ts | 60 ++++++++ .../__testfixtures__/fixture1.output.ts | 63 ++++++++ .../cdmd_dist/index.cjs | 13 ++ .../package.json | 23 +++ .../src/index.ts | 106 ++++++++++++++ .../test/test.ts | 40 +++++ .../tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + .../.codemodrc.json | 19 +++ .../.gitignore | 2 + .../LICENSE | 9 ++ .../README.md | 22 +++ .../__testfixtures__/fixture1.input.ts | 3 + .../__testfixtures__/fixture1.output.ts | 3 + .../cdmd_dist/index.cjs | 13 ++ .../package.json | 23 +++ .../src/index.ts | 22 +++ .../test/test.ts | 40 +++++ .../tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + .../.codemodrc.json | 18 +++ .../.gitignore | 2 + .../LICENSE | 9 ++ .../README.md | 24 +++ .../__testfixtures__/fixture1.input.ts | 5 + .../__testfixtures__/fixture1.output.ts | 5 + .../cdmd_dist/index.cjs | 13 ++ .../package.json | 23 +++ .../src/index.ts | 25 ++++ .../test/test.ts | 40 +++++ .../tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + .../.codemodrc.json | 18 +++ .../.gitignore | 2 + .../LICENSE | 9 ++ .../README.md | 27 ++++ .../__testfixtures__/fixture1.input.ts | 5 + .../__testfixtures__/fixture1.output.ts | 8 + .../cdmd_dist/index.cjs | 13 ++ .../package.json | 23 +++ .../src/index.ts | 50 +++++++ .../test/test.ts | 40 +++++ .../tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + .../.codemodrc.json | 18 +++ .../.gitignore | 2 + .../LICENSE | 9 ++ .../README.md | 40 +++++ .../__testfixtures__/fixture1.input.ts | 7 + .../__testfixtures__/fixture1.output.ts | 17 +++ .../cdmd_dist/index.cjs | 21 +++ .../package.json | 23 +++ .../src/index.ts | 87 +++++++++++ .../test/test.ts | 40 +++++ .../tsconfig.json | 38 +++++ .../vitest.config.ts | 7 + 84 files changed, 2018 insertions(+) create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.gitignore create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/LICENSE create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/README.md create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/package.json create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/src/index.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/test/test.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/tsconfig.json create mode 100644 packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/vitest.config.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.gitignore create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/LICENSE create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/README.md create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/package.json create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/src/index.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/test/test.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/tsconfig.json create mode 100644 packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/vitest.config.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.gitignore create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/LICENSE create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/README.md create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/package.json create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/src/index.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/test/test.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/tsconfig.json create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/vitest.config.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.gitignore create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/LICENSE create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/README.md create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/package.json create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/src/index.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/test/test.ts create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/tsconfig.json create mode 100644 packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/vitest.config.ts create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.gitignore create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/LICENSE create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/README.md create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/package.json create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/src/index.ts create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/test/test.ts create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/tsconfig.json create mode 100644 packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/vitest.config.ts create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.gitignore create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/LICENSE create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/README.md create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/package.json create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/src/index.ts create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/test/test.ts create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/tsconfig.json create mode 100644 packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/vitest.config.ts create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.codemodrc.json create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.gitignore create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/LICENSE create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/README.md create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.input.ts create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.output.ts create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/cdmd_dist/index.cjs create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/package.json create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/src/index.ts create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/test/test.ts create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/tsconfig.json create mode 100644 packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/vitest.config.ts diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.codemodrc.json b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.codemodrc.json new file mode 100644 index 000000000..22ba1306b --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.codemodrc.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "jest-add-root-and-assertions-to-test", + "version": "1.0.1", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "radix", + "vue", + "jest", + "v1.9.4", + "bug fix", + "add root and assertions to test" + ], + "git" : "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.gitignore b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/LICENSE b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/README.md b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/README.md new file mode 100644 index 000000000..c755b353a --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/README.md @@ -0,0 +1,47 @@ +Added Input Root Test Cases to which handle the data disabled case + +## Example + +### Before + +```ts +it('should not be changed when disabled', async () => { + const { input, increment, decrement } = setup({ + defaultValue: 0, + disabled: true, + }); + + await fireEvent.keyDown(input, { key: kbd.ARROW_UP }); + expect(input.value).toBe('0'); + await fireEvent.keyDown(input, { key: kbd.ARROW_DOWN }); + expect(input.value).toBe('0'); + await userEvent.click(increment); + expect(input.value).toBe('0'); + await userEvent.click(decrement); + expect(input.value).toBe('0'); +}); +``` + +### After + +```ts +it('should not be changed when disabled', async () => { + const { root, input, increment, decrement } = setup({ + defaultValue: 0, + disabled: true, + }); + + expect(root.getAttribute('data-disabled')).toBe(''); + expect(input.getAttribute('data-disabled')).toBe(''); + + await fireEvent.keyDown(input, { key: kbd.ARROW_UP }); + expect(input.value).toBe('0'); + await fireEvent.keyDown(input, { key: kbd.ARROW_DOWN }); + expect(input.value).toBe('0'); + await userEvent.click(increment); + expect(input.value).toBe('0'); + await userEvent.click(decrement); + expect(input.value).toBe('0'); +}); +``` + diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..d6bdfc00f --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.input.ts @@ -0,0 +1,15 @@ +it('should not be changed when disabled', async () => { + const { input, increment, decrement } = setup({ + defaultValue: 0, + disabled: true, + }); + + await fireEvent.keyDown(input, { key: kbd.ARROW_UP }); + expect(input.value).toBe('0'); + await fireEvent.keyDown(input, { key: kbd.ARROW_DOWN }); + expect(input.value).toBe('0'); + await userEvent.click(increment); + expect(input.value).toBe('0'); + await userEvent.click(decrement); + expect(input.value).toBe('0'); +}); \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..2f7865d5e --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/__testfixtures__/fixture1.output.ts @@ -0,0 +1,18 @@ +it('should not be changed when disabled', async () => { + const { root, input, increment, decrement } = setup({ + defaultValue: 0, + disabled: true, + }); + + expect(root.getAttribute('data-disabled')).toBe(''); + expect(input.getAttribute('data-disabled')).toBe(''); + + await fireEvent.keyDown(input, { key: kbd.ARROW_UP }); + expect(input.value).toBe('0'); + await fireEvent.keyDown(input, { key: kbd.ARROW_DOWN }); + expect(input.value).toBe('0'); + await userEvent.click(increment); + expect(input.value).toBe('0'); + await userEvent.click(decrement); + expect(input.value).toBe('0'); +}); \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/cdmd_dist/index.cjs new file mode 100644 index 000000000..28409fcfa --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/cdmd_dist/index.cjs @@ -0,0 +1,13 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.VariableDeclarator,{id:{type:"ObjectPattern",properties:props=>props.some(prop=>prop.key.name==="setup")}}).forEach(path=>{const properties=path.node.id.properties;if(!properties.some(prop=>prop.key.name==="root")){properties.unshift(j.property.from({kind:"init",key:j.identifier("root"),value:j.identifier("root"),shorthand:true}));dirtyFlag=true}});root.find(j.CallExpression,{callee:{type:"Identifier",name:"it"}}).forEach(path=>{const body=path.node.arguments[1].body.body;const setupIndex=body.findIndex(statement=>j.VariableDeclaration.check(statement)&&statement.declarations.some(decl=>j.ObjectPattern.check(decl.id)&&decl.id.properties.some(prop=>prop.key.name==="setup")));if(setupIndex!==-1){const newAssertions=[j.expressionStatement(j.callExpression(j.memberExpression(j.callExpression(j.identifier("expect"),[j.callExpression(j.memberExpression(j.identifier("root"),j.identifier("getAttribute")),[j.literal("data-disabled")])]),j.identifier("toBe")),[j.literal("")])),j.expressionStatement(j.callExpression(j.memberExpression(j.callExpression(j.identifier("expect"),[j.callExpression(j.memberExpression(j.identifier("input"),j.identifier("getAttribute")),[j.literal("data-disabled")])]),j.identifier("toBe")),[j.literal("")]))];body.splice(setupIndex+1,0,...newAssertions);dirtyFlag=true}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/package.json b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/package.json new file mode 100644 index 000000000..59e806c77 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/package.json @@ -0,0 +1,23 @@ +{ + "name": "jest-add-root-and-assertions-to-test", + "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": "dfordp" +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/src/index.ts b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/src/index.ts new file mode 100644 index 000000000..2a7e060f3 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/src/index.ts @@ -0,0 +1,82 @@ +export default function transform(file, api) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Find the setup function call and add 'root' to the destructured object + root.find(j.VariableDeclarator, { + id: { + type: 'ObjectPattern', + properties: (props) => props.some(prop => prop.key.name === 'setup') + } + }).forEach(path => { + const properties = path.node.id.properties; + if (!properties.some(prop => prop.key.name === 'root')) { + properties.unshift(j.property.from({ + kind: 'init', + key: j.identifier('root'), + value: j.identifier('root'), + shorthand: true + })); + dirtyFlag = true; + } + }); + + // Find the body of the test function and add the new assertions + root.find(j.CallExpression, { + callee: { + type: 'Identifier', + name: 'it' + } + }).forEach(path => { + const body = path.node.arguments[1].body.body; + const setupIndex = body.findIndex(statement => + j.VariableDeclaration.check(statement) && + statement.declarations.some(decl => + j.ObjectPattern.check(decl.id) && + decl.id.properties.some(prop => prop.key.name === 'setup') + ) + ); + + if (setupIndex !== -1) { + const newAssertions = [ + j.expressionStatement( + j.callExpression( + j.memberExpression( + j.callExpression( + j.identifier('expect'), + [j.callExpression( + j.memberExpression(j.identifier('root'), j.identifier('getAttribute')), + [j.literal('data-disabled')] + )] + ), + j.identifier('toBe') + ), + [j.literal('')] + ) + ), + j.expressionStatement( + j.callExpression( + j.memberExpression( + j.callExpression( + j.identifier('expect'), + [j.callExpression( + j.memberExpression(j.identifier('input'), j.identifier('getAttribute')), + [j.literal('data-disabled')] + )] + ), + j.identifier('toBe') + ), + [j.literal('')] + ) + ) + ]; + + // Insert the new assertions after the setup call + body.splice(setupIndex + 1, 0, ...newAssertions); + dirtyFlag = true; + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/test/test.ts b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/test/test.ts new file mode 100644 index 000000000..94e0d909a --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/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('jest/add-root-and-assertions-to-test', () => { + 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/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/tsconfig.json b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/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/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/vitest.config.ts b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/jest-add-root-and-assertions-to-test-codemod/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/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.codemodrc.json b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.codemodrc.json new file mode 100644 index 000000000..60f796fa9 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.codemodrc.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "vue-v1.9.4-tab-tabs-indicator-position-bug-fix", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": ["radix","vue","radix-vue", "v1.9.4","bug fix","tabs indicator position" ], + "git": "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update.git" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.gitignore b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/LICENSE b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/README.md b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/README.md new file mode 100644 index 000000000..64ee7a39a --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/README.md @@ -0,0 +1,28 @@ +Recalculates tabs indicator position on direction change in the Tab Component + +## Example + +### Before + +```ts +watch( + () => context.modelValue.value, + async (n) => { + await nextTick(); + updateIndicatorStyle(); + }, { immediate: true }, +); +``` + +### After + +```ts +watch( + () => [context.modelValue.value, context?.dir.value], + async () => { + await nextTick(); + updateIndicatorStyle(); + }, { immediate: true }, +); +``` + diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..04b34c25c --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.input.ts @@ -0,0 +1,7 @@ +watch( + () => context.modelValue.value, + async (n) => { + await nextTick(); + updateIndicatorStyle(); + }, { immediate: true }, +); \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..40ad0a2d9 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/__testfixtures__/fixture1.output.ts @@ -0,0 +1,7 @@ +watch( + () => [context.modelValue.value, context?.dir.value], + async () => { + await nextTick(); + updateIndicatorStyle(); + }, { immediate: true }, +); \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/cdmd_dist/index.cjs new file mode 100644 index 000000000..e80712319 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/cdmd_dist/index.cjs @@ -0,0 +1,13 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.CallExpression,{callee:{name:"watch"}}).forEach(path=>{const args=path.value.arguments;if(j.ArrowFunctionExpression.check(args[0])){const firstArg=args[0];if(j.BlockStatement.check(firstArg.body)===false){const newBody=j.arrayExpression([firstArg.body,j.memberExpression(j.optionalMemberExpression(j.identifier("context"),j.identifier("dir"),false,true),j.identifier("value"))]);firstArg.body=newBody;dirtyFlag=true}}if(j.ArrowFunctionExpression.check(args[1])){const secondArg=args[1];if(secondArg.params.length>0){secondArg.params=[];dirtyFlag=true}}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/package.json b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/package.json new file mode 100644 index 000000000..3e1d77d9f --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/package.json @@ -0,0 +1,23 @@ +{ + "name": "vue-3-update-watch-callbacks", + "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": "dfordp" +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/src/index.ts b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/src/index.ts new file mode 100644 index 000000000..a1ee4005a --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/src/index.ts @@ -0,0 +1,41 @@ +export default function transform(file, api) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Find all `watch` function calls + root.find(j.CallExpression, { callee: { name: 'watch' } }).forEach(path => { + const args = path.value.arguments; + + // Ensure the first argument is an arrow function + if (j.ArrowFunctionExpression.check(args[0])) { + const firstArg = args[0]; + + // Ensure the body of the arrow function is a single expression + if (j.BlockStatement.check(firstArg.body) === false) { + const newBody = j.arrayExpression([ + firstArg.body, + j.memberExpression( + j.optionalMemberExpression(j.identifier('context'), j.identifier('dir'), false, true), + j.identifier('value') + ) + ]); + firstArg.body = newBody; + dirtyFlag = true; + } + } + + // Ensure the second argument is an arrow function + if (j.ArrowFunctionExpression.check(args[1])) { + const secondArg = args[1]; + + // Remove the parameter `n` from the second argument + if (secondArg.params.length > 0) { + secondArg.params = []; + dirtyFlag = true; + } + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/test/test.ts b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/test/test.ts new file mode 100644 index 000000000..15c86a0ed --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/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('vue/3/update-watch-callbacks', () => { + 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/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/tsconfig.json b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/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/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/vitest.config.ts b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/radix-vue-tab-v1.9.4-update/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/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.codemodrc.json b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.codemodrc.json new file mode 100644 index 000000000..3d2331ffc --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.codemodrc.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "vue-3-update-navigation-menu-link-emits-and-handle-click", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "radix", + "vue", + "radix-vue", + "v1.9.4", + "bug fix", + "NavigationMenu", + "client-side nav prevented by RouterLink Fix" + ], + "git": "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.gitignore b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/LICENSE b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/README.md b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/README.md new file mode 100644 index 000000000..2e23180e6 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/README.md @@ -0,0 +1,138 @@ + When using `NavigationMenuLink` together with `NuxtLink` according to the documentation the menu does not dismiss when clicking on a link. + + +## Example + +### Before + +```ts +< script lang = "ts" > + import type { PrimitiveProps } from '@/Primitive' +import { useForwardExpose } from '@/shared' + +export type NavigationMenuLinkEmits = { + /** + * Event handler called when the user selects a link (via mouse or keyboard). + * + * Calling `event.preventDefault` in this handler will prevent the navigation menu from closing when selecting that link. + */ + select: [payload: MouseEvent] +} +export interface NavigationMenuLinkProps extends PrimitiveProps { + /** Used to identify the link as the currently active page. */ + active ? : boolean +} < +/script> + +< +script setup lang = "ts" > + import { nextTick } from 'vue' +import { Primitive } from '@/Primitive' +import { EVENT_ROOT_CONTENT_DISMISS } from './utils' +// const LINK_SELECT = "navigationMenu.linkSelect"; + +const props = withDefaults(defineProps < NavigationMenuLinkProps > (), { + as: 'a', +}) +const emits = defineEmits < NavigationMenuLinkEmits > () + +useForwardExpose() + +async function handleClick(ev: MouseEvent) { + + emits('select', linkSelectEvent) + + await nextTick() + if (!ev.defaultPrevented && !ev.metaKey) { + const rootContentDismissEvent = new CustomEvent( + EVENT_ROOT_CONTENT_DISMISS, { + bubbles: true, + cancelable: true, + }, + ) + ev.target?.dispatchEvent(rootContentDismissEvent) + } + } < + /script> + + < + template > + < + Primitive: as = "as": data - active = "active ? '' : undefined": aria - current = "active ? 'page' : undefined": as - child = "props.asChild" +data - radix - vue - collection - item +@click = "handleClick" > + < + slot / > + < + /Primitive> < + /template> +``` + +### After + +```ts +< script lang = "ts" > + import type { PrimitiveProps } from '@/Primitive' +import { useForwardExpose } from '@/shared' + +export type NavigationMenuLinkEmits = { + /** + * Event handler called when the user selects a link (via mouse or keyboard). + * + * Calling `event.preventDefault` in this handler will prevent the navigation menu from closing when selecting that link. + */ + select: [payload: CustomEvent < { originalEvent: Event } > ] +} +export interface NavigationMenuLinkProps extends PrimitiveProps { + /** Used to identify the link as the currently active page. */ + active ? : boolean +} < +/script> + +< +script setup lang = "ts" > + import { Primitive } from '@/Primitive' +import { EVENT_ROOT_CONTENT_DISMISS, LINK_SELECT } from './utils' + +const props = withDefaults(defineProps < NavigationMenuLinkProps > (), { + as: 'a', +}) +const emits = defineEmits < NavigationMenuLinkEmits > () + +useForwardExpose() + +async function handleClick(ev: MouseEvent) { + const linkSelectEvent = new CustomEvent(LINK_SELECT, { + bubbles: true, + cancelable: true, + detail: { + originalEvent: ev, + }, + }) + emits('select', linkSelectEvent) + + if (!linkSelectEvent.defaultPrevented && !ev.metaKey) { + const rootContentDismissEvent = new CustomEvent( + EVENT_ROOT_CONTENT_DISMISS, { + bubbles: true, + cancelable: true, + }, + ) + ev.target?.dispatchEvent(rootContentDismissEvent) + } + } < + /script> + + < + template > + < + Primitive: as = "as": data - active = "active ? '' : undefined": aria - current = "active ? 'page' : undefined": as - child = "props.asChild" +data - radix - vue - collection - item +@click = "handleClick" > + < + slot / > + < + /Primitive> < + /template> +``` + diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..66b45ed02 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.input.ts @@ -0,0 +1,60 @@ +< script lang = "ts" > + import type { PrimitiveProps } from '@/Primitive' +import { useForwardExpose } from '@/shared' + +export type NavigationMenuLinkEmits = { + /** + * Event handler called when the user selects a link (via mouse or keyboard). + * + * Calling `event.preventDefault` in this handler will prevent the navigation menu from closing when selecting that link. + */ + select: [payload: MouseEvent] +} +export interface NavigationMenuLinkProps extends PrimitiveProps { + /** Used to identify the link as the currently active page. */ + active ? : boolean +} < +/script> + +< +script setup lang = "ts" > + import { nextTick } from 'vue' +import { Primitive } from '@/Primitive' +import { EVENT_ROOT_CONTENT_DISMISS } from './utils' +// const LINK_SELECT = "navigationMenu.linkSelect"; + +const props = withDefaults(defineProps < NavigationMenuLinkProps > (), { + as: 'a', +}) +const emits = defineEmits < NavigationMenuLinkEmits > () + +useForwardExpose() + +async function handleClick(ev: MouseEvent) { + + emits('select', linkSelectEvent) + + await nextTick() + if (!ev.defaultPrevented && !ev.metaKey) { + const rootContentDismissEvent = new CustomEvent( + EVENT_ROOT_CONTENT_DISMISS, { + bubbles: true, + cancelable: true, + }, + ) + ev.target?.dispatchEvent(rootContentDismissEvent) + } + } < + /script> + + < + template > + < + Primitive: as = "as": data - active = "active ? '' : undefined": aria - current = "active ? 'page' : undefined": as - child = "props.asChild" +data - radix - vue - collection - item +@click = "handleClick" > + < + slot / > + < + /Primitive> < + /template> \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..154078832 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/__testfixtures__/fixture1.output.ts @@ -0,0 +1,63 @@ +< script lang = "ts" > + import type { PrimitiveProps } from '@/Primitive' +import { useForwardExpose } from '@/shared' + +export type NavigationMenuLinkEmits = { + /** + * Event handler called when the user selects a link (via mouse or keyboard). + * + * Calling `event.preventDefault` in this handler will prevent the navigation menu from closing when selecting that link. + */ + select: [payload: CustomEvent < { originalEvent: Event } > ] +} +export interface NavigationMenuLinkProps extends PrimitiveProps { + /** Used to identify the link as the currently active page. */ + active ? : boolean +} < +/script> + +< +script setup lang = "ts" > + import { Primitive } from '@/Primitive' +import { EVENT_ROOT_CONTENT_DISMISS, LINK_SELECT } from './utils' + +const props = withDefaults(defineProps < NavigationMenuLinkProps > (), { + as: 'a', +}) +const emits = defineEmits < NavigationMenuLinkEmits > () + +useForwardExpose() + +async function handleClick(ev: MouseEvent) { + const linkSelectEvent = new CustomEvent(LINK_SELECT, { + bubbles: true, + cancelable: true, + detail: { + originalEvent: ev, + }, + }) + emits('select', linkSelectEvent) + + if (!linkSelectEvent.defaultPrevented && !ev.metaKey) { + const rootContentDismissEvent = new CustomEvent( + EVENT_ROOT_CONTENT_DISMISS, { + bubbles: true, + cancelable: true, + }, + ) + ev.target?.dispatchEvent(rootContentDismissEvent) + } + } < + /script> + + < + template > + < + Primitive: as = "as": data - active = "active ? '' : undefined": aria - current = "active ? 'page' : undefined": as - child = "props.asChild" +data - radix - vue - collection - item +@click = "handleClick" > + < + slot / > + < + /Primitive> < + /template> \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/cdmd_dist/index.cjs new file mode 100644 index 000000000..41f8e5909 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/cdmd_dist/index.cjs @@ -0,0 +1,13 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.TSTypeAliasDeclaration,{id:{name:"NavigationMenuLinkEmits"}}).forEach(path=>{const selectProperty=path.value.typeAnnotation.members.find(member=>j.TSPropertySignature.check(member)&&j.Identifier.check(member.key)&&member.key.name==="select");if(selectProperty&&j.TSTupleType.check(selectProperty.typeAnnotation)){selectProperty.typeAnnotation.elementTypes=[j.tsTypeReference(j.identifier("CustomEvent"),j.tsTypeParameterInstantiation([j.tsTypeLiteral([j.tsPropertySignature(j.identifier("originalEvent"),j.tsTypeAnnotation(j.tsTypeReference(j.identifier("Event"))))])]))];dirtyFlag=true}});root.find(j.ImportDeclaration,{source:{value:"./utils"}}).forEach(path=>{const hasLinkSelect=path.value.specifiers.some(specifier=>j.ImportSpecifier.check(specifier)&&specifier.imported.name==="LINK_SELECT");if(!hasLinkSelect){path.value.specifiers.push(j.importSpecifier(j.identifier("LINK_SELECT")));dirtyFlag=true}});root.find(j.FunctionDeclaration).filter(path=>j.Identifier.check(path.value.id)&&path.value.id.name==="handleClick").forEach(path=>{const body=path.value.body.body;const nextTickIndex=body.findIndex(statement=>j.ExpressionStatement.check(statement)&&j.AwaitExpression.check(statement.expression)&&j.CallExpression.check(statement.expression.argument)&&j.Identifier.check(statement.expression.argument.callee)&&statement.expression.argument.callee.name==="nextTick");if(nextTickIndex!==-1){body.splice(nextTickIndex,1);dirtyFlag=true}const emitIndex=body.findIndex(statement=>j.ExpressionStatement.check(statement)&&j.CallExpression.check(statement.expression)&&j.Identifier.check(statement.expression.callee)&&statement.expression.callee.name==="emits");if(emitIndex!==-1){const emitCall=body[emitIndex].expression;const linkSelectEvent=j.variableDeclaration("const",[j.variableDeclarator(j.identifier("linkSelectEvent"),j.newExpression(j.identifier("CustomEvent"),[j.identifier("LINK_SELECT"),j.objectExpression([j.property.from({kind:"init",key:j.identifier("bubbles"),value:j.literal(true)}),j.property.from({kind:"init",key:j.identifier("cancelable"),value:j.literal(true)}),j.property.from({kind:"init",key:j.identifier("detail"),value:j.objectExpression([j.property.from({kind:"init",key:j.identifier("originalEvent"),value:j.identifier("ev")})])})])]))]);body.splice(emitIndex,0,linkSelectEvent);emitCall.arguments[1]=j.identifier("linkSelectEvent");dirtyFlag=true}const defaultPreventedCheck=body.find(statement=>j.IfStatement.check(statement)&&j.BinaryExpression.check(statement.test)&&j.MemberExpression.check(statement.test.left)&&j.Identifier.check(statement.test.left.object)&&statement.test.left.object.name==="ev"&&statement.test.left.property.name==="defaultPrevented");if(defaultPreventedCheck){defaultPreventedCheck.test.left.object.name="linkSelectEvent";dirtyFlag=true}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/package.json b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/package.json new file mode 100644 index 000000000..a692d7d92 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/package.json @@ -0,0 +1,23 @@ +{ + "name": "vue-3-update-navigation-menu-link-emits-and-handle-click", + "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": "dfordp" +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/src/index.ts b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/src/index.ts new file mode 100644 index 000000000..17440bec9 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/src/index.ts @@ -0,0 +1,106 @@ +export default function transform(file, api) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Update NavigationMenuLinkEmits type + root.find(j.TSTypeAliasDeclaration, { id: { name: 'NavigationMenuLinkEmits' } }) + .forEach(path => { + const selectProperty = path.value.typeAnnotation.members.find(member => + j.TSPropertySignature.check(member) && j.Identifier.check(member.key) && member.key.name === 'select' + ); + if (selectProperty && j.TSTupleType.check(selectProperty.typeAnnotation)) { + selectProperty.typeAnnotation.elementTypes = [ + j.tsTypeReference( + j.identifier('CustomEvent'), + j.tsTypeParameterInstantiation([ + j.tsTypeLiteral([ + j.tsPropertySignature( + j.identifier('originalEvent'), + j.tsTypeAnnotation(j.tsTypeReference(j.identifier('Event'))) + ) + ]) + ]) + ) + ]; + dirtyFlag = true; + } + }); + + // Add LINK_SELECT import + root.find(j.ImportDeclaration, { source: { value: './utils' } }) + .forEach(path => { + const hasLinkSelect = path.value.specifiers.some(specifier => + j.ImportSpecifier.check(specifier) && specifier.imported.name === 'LINK_SELECT' + ); + if (!hasLinkSelect) { + path.value.specifiers.push(j.importSpecifier(j.identifier('LINK_SELECT'))); + dirtyFlag = true; + } + }); + + // Update handleClick function + root.find(j.FunctionDeclaration) + .filter(path => j.Identifier.check(path.value.id) && path.value.id.name === 'handleClick') + .forEach(path => { + const body = path.value.body.body; + const nextTickIndex = body.findIndex(statement => + j.ExpressionStatement.check(statement) && + j.AwaitExpression.check(statement.expression) && + j.CallExpression.check(statement.expression.argument) && + j.Identifier.check(statement.expression.argument.callee) && + statement.expression.argument.callee.name === 'nextTick' + ); + if (nextTickIndex !== -1) { + body.splice(nextTickIndex, 1); + dirtyFlag = true; + } + + const emitIndex = body.findIndex(statement => + j.ExpressionStatement.check(statement) && + j.CallExpression.check(statement.expression) && + j.Identifier.check(statement.expression.callee) && + statement.expression.callee.name === 'emits' + ); + if (emitIndex !== -1) { + const emitCall = body[emitIndex].expression; + const linkSelectEvent = j.variableDeclaration('const', [ + j.variableDeclarator( + j.identifier('linkSelectEvent'), + j.newExpression(j.identifier('CustomEvent'), [ + j.identifier('LINK_SELECT'), + j.objectExpression([ + j.property.from({ kind: 'init', key: j.identifier('bubbles'), value: j.literal(true) }), + j.property.from({ kind: 'init', key: j.identifier('cancelable'), value: j.literal(true) }), + j.property.from({ + kind: 'init', + key: j.identifier('detail'), + value: j.objectExpression([ + j.property.from({ kind: 'init', key: j.identifier('originalEvent'), value: j.identifier('ev') }) + ]) + }) + ]) + ]) + ) + ]); + body.splice(emitIndex, 0, linkSelectEvent); + emitCall.arguments[1] = j.identifier('linkSelectEvent'); + dirtyFlag = true; + } + + const defaultPreventedCheck = body.find(statement => + j.IfStatement.check(statement) && + j.BinaryExpression.check(statement.test) && + j.MemberExpression.check(statement.test.left) && + j.Identifier.check(statement.test.left.object) && + statement.test.left.object.name === 'ev' && + statement.test.left.property.name === 'defaultPrevented' + ); + if (defaultPreventedCheck) { + defaultPreventedCheck.test.left.object.name = 'linkSelectEvent'; + dirtyFlag = true; + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/test/test.ts b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/test/test.ts new file mode 100644 index 000000000..b0027e487 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/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('vue/3/update-navigation-menu-link-emits-and-handle-click', () => { + 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/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/tsconfig.json b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/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/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/vitest.config.ts b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-3-update-navigation-menu-link-emits-and-handle-click-codemod/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/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.codemodrc.json b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.codemodrc.json new file mode 100644 index 000000000..17d95a018 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.codemodrc.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "vue-v1.9.4-watchPostEffect-placed-update", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "radix", + "vue", + "radix-vue", + "v1.9.4", + "bug fix", + "watchPostEffect placed update" + ], + "git": "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update.git" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.gitignore b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/LICENSE b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/README.md b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/README.md new file mode 100644 index 000000000..bbaee7cf7 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/README.md @@ -0,0 +1,22 @@ +When floating-ui returned isPositioned=true, radix-vue immediately emitted an event to focus on the selected item in the Select component. However, at this point, the PopperContent element did not yet have the correct transform CSS property set, resulting in the Popper being positioned at coordinates (0, -200%) + +Credits to the contributor + +## Example + +### Before + +```ts +import { watchEffect } from 'vue'; + +watchEffect(() => {}); +``` + +### After + +```ts +import { watchPostEffect } from 'vue'; + +watchPostEffect(() => {}); +``` + diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..dc1548b87 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.input.ts @@ -0,0 +1,3 @@ +import { watchEffect } from 'vue'; + +watchEffect(() => {}); \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..cf14998ec --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/__testfixtures__/fixture1.output.ts @@ -0,0 +1,3 @@ +import { watchPostEffect } from 'vue'; + +watchPostEffect(() => {}); \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/cdmd_dist/index.cjs new file mode 100644 index 000000000..1c77be54d --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/cdmd_dist/index.cjs @@ -0,0 +1,13 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.ImportDeclaration,{source:{value:"vue"}}).find(j.ImportSpecifier,{imported:{name:"watchEffect"}}).forEach(path=>{path.replace(j.importSpecifier(j.identifier("watchPostEffect")));dirtyFlag=true});root.find(j.CallExpression,{callee:{name:"watchEffect"}}).forEach(path=>{path.get("callee").replace(j.identifier("watchPostEffect"));dirtyFlag=true});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/package.json b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/package.json new file mode 100644 index 000000000..9f6e9df49 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/package.json @@ -0,0 +1,23 @@ +{ + "name": "vue-3-watch-effect-to-watch-post-effect", + "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": "dfordp" +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/src/index.ts b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/src/index.ts new file mode 100644 index 000000000..2739cc928 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/src/index.ts @@ -0,0 +1,22 @@ +export default function transform(file, api) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Replace import { watchEffect } with { watchPostEffect } + root.find(j.ImportDeclaration, { source: { value: 'vue' } }) + .find(j.ImportSpecifier, { imported: { name: 'watchEffect' } }) + .forEach(path => { + path.replace(j.importSpecifier(j.identifier('watchPostEffect'))); + dirtyFlag = true; + }); + + // Replace watchEffect() calls with watchPostEffect() + root.find(j.CallExpression, { callee: { name: 'watchEffect' } }) + .forEach(path => { + path.get('callee').replace(j.identifier('watchPostEffect')); + dirtyFlag = true; + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/test/test.ts b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/test/test.ts new file mode 100644 index 000000000..da8b205e3 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/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('vue/3/watch-effect-to-watch-post-effect', () => { + 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/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/tsconfig.json b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/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/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/vitest.config.ts b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/radix-vue/v1.9.4/vue-v1.9.4-watchPostEffect-placed-update/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/radix-vue/v2/calender-model-checked-to-v-model-codemod/.codemodrc.json b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.codemodrc.json new file mode 100644 index 000000000..85d661ec9 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.codemodrc.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "rekaUI-v2/searchTerm-props-of-Root-to-Input's-v-model", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "vue", + "radix", + "radix-vue v2", + "searchTerm", + "props-of-Root-to-Input's-v-model" + ], + "git": "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.gitignore b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/LICENSE b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v2/calender-model-checked-to-v-model-codemod/README.md b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/README.md new file mode 100644 index 000000000..31f4f76a3 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/README.md @@ -0,0 +1,24 @@ +Replace searchTerm props of Root to Input's v-model. + +## Example + +### Before + +```ts +< template > + < + CheckboxRoot v - model: checked = 'value' / > + < + /template>; +``` + +### After + +```ts +< template > + < + CheckboxRoot v - model = 'value' / > + < + /template>; +``` + diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..5ddf75b80 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.input.ts @@ -0,0 +1,5 @@ +< template > + < + CheckboxRoot v - model: checked = 'value' / > + < + /template>; \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..d3d6df8c2 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/__testfixtures__/fixture1.output.ts @@ -0,0 +1,5 @@ +< template > + < + CheckboxRoot v - model = 'value' / > + < + /template>; \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/cdmd_dist/index.cjs new file mode 100644 index 000000000..4f27b2c93 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/cdmd_dist/index.cjs @@ -0,0 +1,13 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.JSXElement).forEach(path=>{const openingElement=path.value.openingElement;if(j.JSXIdentifier.check(openingElement.name)&&openingElement.name.name==="CheckboxRoot"){openingElement.attributes.forEach(attr=>{if(j.JSXAttribute.check(attr)&&j.JSXNamespacedName.check(attr.name)&&attr.name.namespace.name==="v-model"&&attr.name.name.name==="checked"){attr.name=j.jsxIdentifier("v-model");dirtyFlag=true}})}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/package.json b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/package.json new file mode 100644 index 000000000..1532c2d0b --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/package.json @@ -0,0 +1,23 @@ +{ + "name": "vue-2-v-model-checked-to-v-model", + "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": "dfordp" +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/src/index.ts b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/src/index.ts new file mode 100644 index 000000000..ff11629a7 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/src/index.ts @@ -0,0 +1,25 @@ +export default function transform(file, api) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Find all JSXElements + root.find(j.JSXElement).forEach(path => { + const openingElement = path.value.openingElement; + + // Check if the element is CheckboxRoot + if (j.JSXIdentifier.check(openingElement.name) && openingElement.name.name === 'CheckboxRoot') { + // Find all attributes + openingElement.attributes.forEach(attr => { + // Check if the attribute is v-model:checked + if (j.JSXAttribute.check(attr) && j.JSXNamespacedName.check(attr.name) && attr.name.namespace.name === 'v-model' && attr.name.name.name === 'checked') { + // Replace v-model:checked with v-model + attr.name = j.jsxIdentifier('v-model'); + dirtyFlag = true; + } + }); + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/test/test.ts b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/test/test.ts new file mode 100644 index 000000000..353d8bde2 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/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('vue/2/v-model-checked-to-v-model', () => { + 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/radix-vue/v2/calender-model-checked-to-v-model-codemod/tsconfig.json b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/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/radix-vue/v2/calender-model-checked-to-v-model-codemod/vitest.config.ts b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/radix-vue/v2/calender-model-checked-to-v-model-codemod/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/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.codemodrc.json b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.codemodrc.json new file mode 100644 index 000000000..d84c01118 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.codemodrc.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "rekaUI-v2/combobox-root-to-combobox-input", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "vue", + "radix", + "radix-vue v2", + "root", + "input" + ], + "git": "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.gitignore b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/LICENSE b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/README.md b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/README.md new file mode 100644 index 000000000..bcfdcdd4b --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/README.md @@ -0,0 +1,27 @@ +Combobox has been refactored and improve to support better custom filtering + +## Example + +### Before + +```ts +< template > + < + ComboboxRoot v - model: search - term = "search": display - value = "(v) => v.name" / > + < + /template> +``` + +### After + +```ts +< template > + < + ComboboxRoot > + < + ComboboxInput v - model = "search": display - value = "(v) => v.name" / > + < + /ComboboxRoot> < + /template> +``` + diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..748991d01 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.input.ts @@ -0,0 +1,5 @@ +< template > + < + ComboboxRoot v - model: search - term = "search": display - value = "(v) => v.name" / > + < + /template> \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..87372bd12 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/__testfixtures__/fixture1.output.ts @@ -0,0 +1,8 @@ +< template > + < + ComboboxRoot > + < + ComboboxInput v - model = "search": display - value = "(v) => v.name" / > + < + /ComboboxRoot> < + /template> \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/cdmd_dist/index.cjs new file mode 100644 index 000000000..f333e7224 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/cdmd_dist/index.cjs @@ -0,0 +1,13 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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.JSXElement,{openingElement:{name:{name:"ComboboxRoot"}}}).forEach(path=>{const openingElement=path.value.openingElement;const children=path.value.children;let searchTermAttr,displayValueAttr;openingElement.attributes=openingElement.attributes.filter(attr=>{if(j.JSXAttribute.check(attr)&&j.JSXIdentifier.check(attr.name)){if(attr.name.name==="v-model:search-term"){searchTermAttr=attr;return false}if(attr.name.name===":display-value"){displayValueAttr=attr;return false}}return true});if(searchTermAttr&&displayValueAttr){dirtyFlag=true;const comboboxInput=j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier("ComboboxInput"),[j.jsxAttribute(j.jsxIdentifier("v-model"),searchTermAttr.value),displayValueAttr]),j.jsxClosingElement(j.jsxIdentifier("ComboboxInput")),children);path.value.children=[j.jsxText("\n "),comboboxInput,j.jsxText("\n ")]}});return dirtyFlag?root.toSource():undefined} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/package.json b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/package.json new file mode 100644 index 000000000..4a41b3191 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/package.json @@ -0,0 +1,23 @@ +{ + "name": "vue-2-combobox-root-to-combobox-input", + "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": "dfordp" +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/src/index.ts b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/src/index.ts new file mode 100644 index 000000000..b8f4992da --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/src/index.ts @@ -0,0 +1,50 @@ +export default function transform(file, api, options) { + const j = api.jscodeshift; + const root = j(file.source); + let dirtyFlag = false; + + // Find all ComboboxRoot elements + root.find(j.JSXElement, { openingElement: { name: { name: "ComboboxRoot" } } }) + .forEach(path => { + const openingElement = path.value.openingElement; + const children = path.value.children; + + // Find v-model:search-term and :display-value attributes + let searchTermAttr, displayValueAttr; + openingElement.attributes = openingElement.attributes.filter(attr => { + if (j.JSXAttribute.check(attr) && j.JSXIdentifier.check(attr.name)) { + if (attr.name.name === 'v-model:search-term') { + searchTermAttr = attr; + return false; + } + if (attr.name.name === ':display-value') { + displayValueAttr = attr; + return false; + } + } + return true; + }); + + if (searchTermAttr && displayValueAttr) { + dirtyFlag = true; + + // Create new ComboboxInput element + const comboboxInput = j.jsxElement( + j.jsxOpeningElement( + j.jsxIdentifier('ComboboxInput'), + [ + j.jsxAttribute(j.jsxIdentifier('v-model'), searchTermAttr.value), + displayValueAttr + ] + ), + j.jsxClosingElement(j.jsxIdentifier('ComboboxInput')), + children + ); + + // Replace children with the new ComboboxInput element + path.value.children = [j.jsxText("\n "), comboboxInput, j.jsxText("\n ")]; + } + }); + + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/test/test.ts b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/test/test.ts new file mode 100644 index 000000000..537fdb364 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/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('vue/2/combobox-root-to-combobox-input', () => { + 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/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/tsconfig.json b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/tsconfig.json new file mode 100644 index 000000000..b27702178 --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/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/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/vitest.config.ts b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/vitest.config.ts new file mode 100644 index 000000000..951b877be --- /dev/null +++ b/packages/codemods/radix-vue/v2/rekaUI-v2-combobox-root-to-combobox-input-codemod/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/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.codemodrc.json b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.codemodrc.json new file mode 100644 index 000000000..a60a6cf91 --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.codemodrc.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", + "name": "rekaUI-v2/add-script-setup-and-update-calendar-components", + "version": "1.0.0", + "engine": "jscodeshift", + "private": false, + "arguments": [], + "meta": { + "tags": [ + "vue", + "radix", + "radix-vue v2", + "calendar", + "script setup and update" + ], + "git": "https://github.com/codemod-com/codemod/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod" + } +} \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.gitignore b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.gitignore new file mode 100644 index 000000000..76add878f --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/LICENSE b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/LICENSE new file mode 100644 index 000000000..b5de24387 --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/README.md b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/README.md new file mode 100644 index 000000000..c17a68674 --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/README.md @@ -0,0 +1,40 @@ +Use prevPage/nextPage props for greater control. + + + +## Example + +### Before + +```ts +< template > + < + CalendarPrev step = 'year' / > + < + CalendarNext step = 'year' / > + < + /template>; +``` + +### After + +```ts +< script setup lang = "ts" > + function pagingFunc(date: DateValue, sign: -1 | 1) { + if (sign === -1) + return date.subtract({ years: 1 }) + return date.add({ years: 1 }) + } < + /script> + + < + template > + < + CalendarPrev: prev - page = "(date: DateValue) => pagingFunc(date, -1)" / > + + < + CalendarNext: next - page = "(date: DateValue) => pagingFunc(date, 1)" / > + < + /template> +``` + diff --git a/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.input.ts b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.input.ts new file mode 100644 index 000000000..097adbb82 --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.input.ts @@ -0,0 +1,7 @@ +< template > + < + CalendarPrev step = 'year' / > + < + CalendarNext step = 'year' / > + < + /template>; \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.output.ts b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.output.ts new file mode 100644 index 000000000..65d0d74a9 --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/__testfixtures__/fixture1.output.ts @@ -0,0 +1,17 @@ +< script setup lang = "ts" > + function pagingFunc(date: DateValue, sign: -1 | 1) { + if (sign === -1) + return date.subtract({ years: 1 }) + return date.add({ years: 1 }) + } < + /script> + + < + template > + < + CalendarPrev: prev - page = "(date: DateValue) => pagingFunc(date, -1)" / > + + < + CalendarNext: next - page = "(date: DateValue) => pagingFunc(date, 1)" / > + < + /template> \ No newline at end of file diff --git a/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/cdmd_dist/index.cjs b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/cdmd_dist/index.cjs new file mode 100644 index 000000000..fad7c22cd --- /dev/null +++ b/packages/codemods/radix-vue/v2/vue-3-add-script-setup-and-update-calendar-components-codemod/cdmd_dist/index.cjs @@ -0,0 +1,21 @@ +/*! @license +The MIT License (MIT) + +Copyright (c) 2024 dfordp + +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){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;const scriptSetupBlock=` + +`;const hasScriptSetup=root.find(j.Program).some(path=>path.node.body.some(node=>j.Literal.check(node)&&node.value.includes(' +`; + + // Check if the script setup block already exists + const hasScriptSetup = root.find(j.Program).some(path => + path.node.body.some(node => + j.Literal.check(node) && node.value.includes('