-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4081 from aryaemami59/fix-codemods
Fix codemods to work with TypeScript 4.7+
- Loading branch information
Showing
35 changed files
with
2,321 additions
and
1,210 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
{ | ||
"env": { "node": true }, | ||
"extends": ["eslint:recommended"], | ||
"ignorePatterns": ["node_modules"], | ||
"parserOptions": { "ecmaVersion": "latest" }, | ||
"plugins": ["node"], | ||
"rules": { | ||
"no-unused-vars": [0], | ||
"eol-last": [0] | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,32 @@ | ||
# Dependencies | ||
/node_modules | ||
/.eslintcache | ||
|
||
# Production | ||
/build | ||
|
||
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
|
||
# Misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.cache | ||
.yarnrc | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/releases | ||
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions | ||
.pnp.* | ||
*.tgz | ||
|
||
/.eslintcache |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"printWidth": 80, | ||
"semi": false | ||
} |
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
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 |
---|---|---|
@@ -1,12 +1,39 @@ | ||
#!/usr/bin/env node | ||
const path = require('path'); | ||
import { execaSync } from 'execa' | ||
import { globbySync } from 'globby' | ||
import { createRequire } from 'node:module' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
require('ts-node').register({ | ||
project: path.join(__dirname, './tsconfig.json'), | ||
}); | ||
const require = createRequire(import.meta.url) | ||
|
||
require('codemod-cli').runTransform( | ||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
|
||
const transformerDirectory = path.join( | ||
__dirname, | ||
process.argv[2] /* transform name */, | ||
process.argv.slice(3) /* paths or globs */ | ||
); | ||
'..', | ||
'transforms', | ||
`${process.argv[2]}/index.ts` | ||
) | ||
|
||
const jscodeshiftExecutable = require.resolve('.bin/jscodeshift') | ||
|
||
const extensions = 'ts,js,tsx,jsx' | ||
|
||
execaSync( | ||
jscodeshiftExecutable, | ||
[ | ||
'-t', | ||
transformerDirectory, | ||
'--extensions', | ||
extensions, | ||
...(process.argv.slice(3).length === 1 | ||
? globbySync(process.argv[3]) | ||
: globbySync(process.argv.slice(3))) | ||
], | ||
{ | ||
stdio: 'inherit', | ||
stripFinalNewline: false | ||
} | ||
) |
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,61 +1,68 @@ | ||
import { describe, vi } from 'vitest'; | ||
import type { Transform } from 'jscodeshift'; | ||
import globby from 'globby'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { runInlineTest } from 'jscodeshift/dist/testUtils'; | ||
import { globbySync } from 'globby' | ||
import type { Transform } from 'jscodeshift' | ||
import type { TestOptions } from 'jscodeshift/src/testUtils' | ||
import { runInlineTest } from 'jscodeshift/src/testUtils' | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { describe, it } from 'vitest' | ||
|
||
export function runTransformTest( | ||
export const runTransformTest = ( | ||
name: string, | ||
transform: Transform, | ||
parser: string, | ||
parser: TestOptions['parser'], | ||
fixturePath: string | ||
) { | ||
describe(name, function () { | ||
globby | ||
.sync('**/*.input.*', { | ||
cwd: fixturePath, | ||
absolute: true, | ||
}) | ||
.map((entry) => entry.slice(fixturePath.length)) | ||
) => { | ||
describe(name, () => { | ||
globbySync('**/*.input.*', { | ||
cwd: fixturePath, | ||
absolute: true, | ||
objectMode: true | ||
}) | ||
.map((entry) => entry.name) | ||
.forEach((filename) => { | ||
let extension = path.extname(filename); | ||
let testName = filename.replace(`.input${extension}`, ''); | ||
let testInputPath = path.join(fixturePath, `${testName}${extension}`); | ||
let inputPath = path.join(fixturePath, `${testName}.input${extension}`); | ||
let outputPath = path.join(fixturePath, `${testName}.output${extension}`); | ||
let optionsPath = path.join(fixturePath, `${testName}.options.json`); | ||
let options = fs.pathExistsSync(optionsPath) ? fs.readFileSync(optionsPath) : '{}'; | ||
const extension = path.extname(filename) | ||
const testName = filename.replace(`.input${extension}`, '') | ||
const testInputPath = path.join(fixturePath, `${testName}${extension}`) | ||
const inputPath = path.join( | ||
fixturePath, | ||
`${testName}.input${extension}` | ||
) | ||
const outputPath = path.join( | ||
fixturePath, | ||
`${testName}.output${extension}` | ||
) | ||
|
||
describe(testName, function () { | ||
beforeEach(function () { | ||
process.env.CODEMOD_CLI_ARGS = options; | ||
}); | ||
const inputFileContent = fs.readFileSync(inputPath, 'utf8') | ||
|
||
afterEach(function () { | ||
process.env.CODEMOD_CLI_ARGS = ''; | ||
}); | ||
const expectedOutput = fs.readFileSync(outputPath, 'utf8') | ||
|
||
it('transforms correctly', function () { | ||
describe(`${testName}${extension}`, () => { | ||
it('transforms correctly', () => { | ||
runInlineTest( | ||
transform, | ||
{}, | ||
{ path: testInputPath, source: fs.readFileSync(inputPath, 'utf8') }, | ||
fs.readFileSync(outputPath, 'utf8'), | ||
{ | ||
path: testInputPath, | ||
source: inputFileContent | ||
}, | ||
expectedOutput, | ||
{ parser } | ||
); | ||
}); | ||
) | ||
}) | ||
|
||
it('is idempotent', function () { | ||
it('is idempotent', () => { | ||
runInlineTest( | ||
transform, | ||
{}, | ||
{ path: testInputPath, source: fs.readFileSync(outputPath, 'utf8') }, | ||
fs.readFileSync(outputPath, 'utf8'), | ||
{ | ||
path: testInputPath, | ||
source: inputFileContent | ||
}, | ||
expectedOutput, | ||
{ parser } | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.