-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'codemod-com:main' into electron-v33
- Loading branch information
Showing
343 changed files
with
12,378 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
packages/codemods/jasmine/5.0/handling_env-execute/.codemodrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", | ||
"name": "jasmine/v5/handling-env-execute-callbacks", | ||
"version": "1.0.2", | ||
"engine": "jscodeshift", | ||
"private": false, | ||
"arguments": [], | ||
"meta": { | ||
"tags": ["jasmine", "migration", "v5"], | ||
"git": "https://github.com/codemod-com/codemod/pull/1319/files" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/codemods/jasmine/5.0/handling_env-execute/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 yugal41735 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
28 changes: 28 additions & 0 deletions
28
packages/codemods/jasmine/5.0/handling_env-execute/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
This codemod migrates `Env.execute` callbacks to await. | ||
|
||
## Example | ||
|
||
### Before | ||
|
||
```ts | ||
try { | ||
env.execute(null, function () { | ||
console.log("Test suite finished."); | ||
}); | ||
} catch (e) { | ||
console.log("Failed to start the test suite."); | ||
} | ||
|
||
``` | ||
|
||
### After | ||
|
||
```ts | ||
try { | ||
await env.execute(); | ||
} catch (e) { | ||
console.log("Failed to start the test suite."); | ||
} | ||
|
||
``` | ||
|
1 change: 1 addition & 0 deletions
1
packages/codemods/jasmine/5.0/handling_env-execute/__testfixtures__/fixture1.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const toReplace = "hello"; |
1 change: 1 addition & 0 deletions
1
packages/codemods/jasmine/5.0/handling_env-execute/__testfixtures__/fixture1.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const replacement = "hello"; |
28 changes: 28 additions & 0 deletions
28
packages/codemods/jasmine/5.0/handling_env-execute/cdmd_dist/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = function (fileInfo, api) { | ||
const j = api.jscodeshift; | ||
const root = j(fileInfo.source); | ||
|
||
// Find all CallExpressions where env.execute is called with a callback | ||
root.find(j.CallExpression, { | ||
callee: { | ||
type: 'MemberExpression', | ||
object: { name: 'env' }, | ||
property: { name: 'execute' } | ||
}, | ||
arguments: (args) => args.length === 2 && j.FunctionExpression.check(args[1]), | ||
}).forEach((path) => { | ||
const callExpression = path.node; | ||
|
||
// Replace the function expression argument with async/await syntax | ||
callExpression.arguments = []; | ||
|
||
// Wrap in an await expression | ||
const awaitExpression = j.awaitExpression(callExpression); | ||
|
||
// Replace the old statement with await env.execute() | ||
j(path).replaceWith(awaitExpression); | ||
}); | ||
|
||
return root.toSource(); | ||
}; | ||
|
23 changes: 23 additions & 0 deletions
23
packages/codemods/jasmine/5.0/handling_env-execute/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "handling-env-execute", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "20.9.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^1.0.1", | ||
"@codemod.com/codemod-utils": "*", | ||
"jscodeshift": "^0.15.1", | ||
"@types/jscodeshift": "^0.11.10" | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"test:watch": "vitest watch" | ||
}, | ||
"files": [ | ||
"README.md", | ||
".codemodrc.json", | ||
"/dist/index.cjs" | ||
], | ||
"type": "module", | ||
"author": "yugal41735" | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/codemods/jasmine/5.0/handling_env-execute/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
|
||
export default function transformer(fileInfo: FileInfo, api: API) { | ||
const j = api.jscodeshift; | ||
const root = j(fileInfo.source); | ||
|
||
// Find all CallExpressions where env.execute is called with a callback | ||
root.find(j.CallExpression, { | ||
callee: { | ||
type: 'MemberExpression', | ||
object: { name: 'env' }, | ||
property: { name: 'execute' } | ||
}, | ||
arguments: (args: any[]) => args.length === 2 && j.FunctionExpression.check(args[1]), | ||
}).forEach((path) => { | ||
const callExpression = path.node; | ||
|
||
// Replace the function expression argument with async/await syntax | ||
callExpression.arguments = []; | ||
|
||
// Wrap in an await expression | ||
const awaitExpression = j.awaitExpression(callExpression); | ||
|
||
// Replace the old statement with await env.execute() | ||
j(path).replaceWith(awaitExpression); | ||
}); | ||
|
||
return root.toSource(); | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/codemods/jasmine/5.0/handling_env-execute/test/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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('handling_env-execute', () => { | ||
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, ''), | ||
); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/codemods/jasmine/5.0/handling_env-execute/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"target": "ESNext", | ||
"moduleResolution": "NodeNext", | ||
"lib": [ | ||
"ESNext", | ||
"DOM" | ||
], | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true, | ||
"allowSyntheticDefaultImports": true, | ||
"isolatedModules": true, | ||
"jsx": "react-jsx", | ||
"useDefineForClassFields": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"preserveWatchOutput": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"incremental": true, | ||
"noUncheckedIndexedAccess": true, | ||
"noPropertyAccessFromIndexSignature": false, | ||
"allowJs": true | ||
}, | ||
"include": [ | ||
"./src/**/*.ts", | ||
"./src/**/*.js", | ||
"./test/**/*.ts", | ||
"./test/**/*.js" | ||
], | ||
"exclude": ["node_modules", "./dist/**/*"], | ||
"ts-node": { | ||
"transpileOnly": true | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/codemods/jasmine/5.0/handling_env-execute/vitest.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { configDefaults, defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: [...configDefaults.include, '**/test/*.ts'], | ||
}, | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/codemods/jasmine/5.0/jasmine_migration_recipe/.codemodrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", | ||
"name": "jasmine/v5/migration-recipe", | ||
"version": "1.0.1", | ||
"engine": "recipe", | ||
"private": false, | ||
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.vue"], | ||
"applicability": { | ||
"from": [["jasmine", ">=", "4.0.0"], ["jasmine", "<", "5.0.0"]], | ||
"to": [["jasmine", ">=", "5.0.0"]] | ||
}, | ||
"arguments": [], | ||
"meta": { | ||
"tags": ["migration", "jasmine", "v5"], | ||
"git": "https://github.com/codemod-com/codemod/pull/1319/files" | ||
}, | ||
"names": [ | ||
"jasmine/v5/handling-env-execute-callbacks", | ||
"jasmine/v5/node-boot-removal" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/codemods/jasmine/5.0/jasmine_migration_recipe/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This recipe is a set of codemods that will help migrate to jasmine v5 from jasmine 4.x . | ||
|
||
The recipe includes the following codemods: | ||
|
||
|
||
- jasmine/v5/handling-env-execute-callbacks | ||
- jasmine/v5/node-boot-removal |
6 changes: 6 additions & 0 deletions
6
packages/codemods/jasmine/5.0/jasmine_migration_recipe/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@codemod/jasmine-v5-migration-recipe", | ||
"files": ["./README.md", "./.codemodrc.json"], | ||
"type": "module", | ||
"private": true | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/codemods/jasmine/5.0/node-boot-removal/.codemodrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json", | ||
"name": "jasmine/v5/node-boot-removal", | ||
"version": "1.0.1", | ||
"engine": "jscodeshift", | ||
"private": false, | ||
"arguments": [], | ||
"meta": { | ||
"tags": ["jasmine", "migration", "v5"], | ||
"git": "https://github.com/codemod-com/codemod/pull/1319/files" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 yugal41735 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
This codemod remove `node_boot.js` as it is no longer supported in jasmin 5.0 | ||
|
||
|
||
## Example | ||
|
||
### Before | ||
|
||
```ts | ||
const boot = require('jasmine-core/node_boot.js'); | ||
``` | ||
|
||
### After | ||
|
||
```ts | ||
const boot = require('jasmine-core').boot; | ||
``` | ||
|
1 change: 1 addition & 0 deletions
1
packages/codemods/jasmine/5.0/node-boot-removal/__testfixtures__/fixture1.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const boot = require('jasmine-core/node_boot.js'); |
1 change: 1 addition & 0 deletions
1
packages/codemods/jasmine/5.0/node-boot-removal/__testfixtures__/fixture1.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const boot = require('jasmine-core').boot; |
13 changes: 13 additions & 0 deletions
13
packages/codemods/jasmine/5.0/node-boot-removal/cdmd_dist/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/*! @license | ||
The MIT License (MIT) | ||
Copyright (c) 2024 yugal41735 | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"default",{enumerable:true,get:function(){return transform}});function transform(file,api,options){const j=api.jscodeshift;const root=j(file.source);let dirtyFlag=false;root.find(j.VariableDeclarator,{init:{callee:{name:"require"},arguments:[{value:"jasmine-core/node_boot.js"}]}}).forEach(path=>{const requireCall=path.value.init;if(j.CallExpression.check(requireCall)&&requireCall.arguments.length===1){const arg=requireCall.arguments[0];if(j.Literal.check(arg)&&arg.value==="jasmine-core/node_boot.js"){path.value.init=j.memberExpression(j.callExpression(j.identifier("require"),[j.literal("jasmine-core")]),j.identifier("boot"));dirtyFlag=true}}});return dirtyFlag?root.toSource():undefined} |
Oops, something went wrong.