codemod 0.0.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +70 -2
- package/dist/index.cjs +22252 -0
- package/package.json +98 -15
- package/.eslintrc.js +0 -29
- package/.npmignore +0 -2
- package/clean.js +0 -31
- package/file.js +0 -14
- package/findFilesWith.js +0 -19
- package/index.js +0 -19
- package/logger.js +0 -14
- package/print.js +0 -29
- package/writeFileWithImports.js +0 -73
package/package.json
CHANGED
|
@@ -1,22 +1,105 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codemod",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "A codemod engine for Node.js libraries (jscodeshift, ts-morph, etc.)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": null,
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/codemod-com/codemod-engine-node"
|
|
8
10
|
},
|
|
9
11
|
"keywords": [
|
|
10
|
-
"codemod"
|
|
12
|
+
"codemod",
|
|
13
|
+
"jscodeshift",
|
|
14
|
+
"ts-morph",
|
|
15
|
+
"refactor",
|
|
16
|
+
"transform",
|
|
17
|
+
"cli",
|
|
18
|
+
"dependencies",
|
|
19
|
+
"migrate",
|
|
20
|
+
"eslint",
|
|
21
|
+
"prettier",
|
|
22
|
+
"progress",
|
|
23
|
+
"AST",
|
|
24
|
+
"next.js",
|
|
25
|
+
"ember",
|
|
26
|
+
"react"
|
|
11
27
|
],
|
|
12
|
-
"author": "Jahred Hope <jahredhope@gmail.com>",
|
|
13
|
-
"license": "ISC",
|
|
14
28
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
29
|
+
"@babel/core": "^7.20.2",
|
|
30
|
+
"@babel/parser": "^7.22.10",
|
|
31
|
+
"@babel/preset-env": "^7.20.2",
|
|
32
|
+
"@babel/traverse": "7.23.2",
|
|
33
|
+
"@effect/schema": "0.27.0",
|
|
34
|
+
"@intuita-inc/filemod": "2.0.2",
|
|
35
|
+
"@intuita-inc/utilities": "1.1.0",
|
|
36
|
+
"@svgr/hast-util-to-babel-ast": "^7.0.0",
|
|
37
|
+
"applicationinsights": "^2.9.1",
|
|
38
|
+
"ast-types": "^0.14.2",
|
|
39
|
+
"axios": "^1.4.0",
|
|
40
|
+
"cosmiconfig": "^8.3.6",
|
|
41
|
+
"form-data": "^4.0.0",
|
|
42
|
+
"fast-glob": "3.3.2",
|
|
43
|
+
"jscodeshift": "^0.14.0",
|
|
44
|
+
"mdast-util-from-markdown": "^2.0.0",
|
|
45
|
+
"mdast-util-mdx": "^3.0.0",
|
|
46
|
+
"mdast-util-to-markdown": "^2.1.0",
|
|
47
|
+
"memfs": "^4.2.0",
|
|
48
|
+
"micromark-extension-mdxjs": "^2.0.0",
|
|
49
|
+
"minimatch": "^9.0.3",
|
|
50
|
+
"prettier": "^2.8.7",
|
|
51
|
+
"rehype-parse": "^8.0.4",
|
|
52
|
+
"tar": "^6.1.15",
|
|
53
|
+
"terminal-link": "^3.0.0",
|
|
54
|
+
"ts-morph": "18.0.0",
|
|
55
|
+
"unified": "^10.1.2",
|
|
56
|
+
"unist-util-filter": "^5.0.1",
|
|
57
|
+
"unist-util-visit": "^5.0.0",
|
|
58
|
+
"valibot": "^0.24.1",
|
|
59
|
+
"yargs": "^17.6.2"
|
|
60
|
+
},
|
|
61
|
+
"main": "./dist/index.cjs",
|
|
62
|
+
"bin": "./dist/index.cjs",
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/babel__traverse": "^7.20.1",
|
|
65
|
+
"@types/jscodeshift": "^0.11.5",
|
|
66
|
+
"@types/node": "18.11.9",
|
|
67
|
+
"@types/prettier": "^2.7.3",
|
|
68
|
+
"@types/sinon": "^10.0.20",
|
|
69
|
+
"@types/tar": "^6.1.5",
|
|
70
|
+
"@types/yargs": "^17.0.13",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "6.9.1",
|
|
72
|
+
"@typescript-eslint/parser": "6.9.1",
|
|
73
|
+
"@vitest/coverage-v8": "^1.0.1",
|
|
74
|
+
"esbuild": "^0.17.14",
|
|
75
|
+
"eslint": "^8.28.0",
|
|
76
|
+
"eslint-config-prettier": "^8.5.0",
|
|
77
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
78
|
+
"sinon": "^17.0.0",
|
|
79
|
+
"ts-node": "^10.9.1",
|
|
80
|
+
"typescript": "5.2.2",
|
|
81
|
+
"vitest": "^1.0.1"
|
|
82
|
+
},
|
|
83
|
+
"packageManager": "pnpm@8.6.7",
|
|
84
|
+
"pkg": {
|
|
85
|
+
"outputPath": "./package/"
|
|
86
|
+
},
|
|
87
|
+
"author": "Caartaa, Inc.",
|
|
88
|
+
"license": "Apache License, Version 2.0",
|
|
89
|
+
"files": [
|
|
90
|
+
"./dist/index.cjs",
|
|
91
|
+
"LICENSE",
|
|
92
|
+
"README.md"
|
|
93
|
+
],
|
|
94
|
+
"publishConfig": {
|
|
95
|
+
"access": "public"
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "esbuild ./src/index.ts --define:__CODEMODCOM_CLI_VERSION__=\\\"0.8.0\\\" --bundle --platform=node --target=node16 --minify --format=cjs --legal-comments=inline --outfile=./dist/index.cjs",
|
|
99
|
+
"lint:eslint": "eslint src --fix --ext ts",
|
|
100
|
+
"lint:prettier": "prettier --write .",
|
|
101
|
+
"package": "pkg --compress GZip .",
|
|
102
|
+
"test": "TEST=1 vitest run",
|
|
103
|
+
"coverage": "TEST=1 vitest run --coverage"
|
|
21
104
|
}
|
|
22
|
-
}
|
|
105
|
+
}
|
package/.eslintrc.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"env": {
|
|
3
|
-
"es6": true,
|
|
4
|
-
"node": true
|
|
5
|
-
},
|
|
6
|
-
"extends": "eslint:recommended",
|
|
7
|
-
"parserOptions": {
|
|
8
|
-
"sourceType": "module"
|
|
9
|
-
},
|
|
10
|
-
"rules": {
|
|
11
|
-
"indent": [
|
|
12
|
-
"error",
|
|
13
|
-
2
|
|
14
|
-
],
|
|
15
|
-
"linebreak-style": [
|
|
16
|
-
"error",
|
|
17
|
-
"unix"
|
|
18
|
-
],
|
|
19
|
-
"quotes": [
|
|
20
|
-
"error",
|
|
21
|
-
"single"
|
|
22
|
-
],
|
|
23
|
-
"semi": [
|
|
24
|
-
"error",
|
|
25
|
-
"never"
|
|
26
|
-
],
|
|
27
|
-
"no-console": 0
|
|
28
|
-
}
|
|
29
|
-
};
|
package/.npmignore
DELETED
package/clean.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const { log, writeLog } = require('./logger')
|
|
2
|
-
const findFilesWith = require('./findFilesWith')
|
|
3
|
-
|
|
4
|
-
const { readFile, writeFile } = require('./file')
|
|
5
|
-
const babylon = require('babylon')
|
|
6
|
-
|
|
7
|
-
const parse = (contents) => babylon.parse(contents, {
|
|
8
|
-
plugins: ['objectRestSpread']
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
const print = require('./print')
|
|
12
|
-
|
|
13
|
-
log('Cleaning all files')
|
|
14
|
-
|
|
15
|
-
module.exports = (rootDir) => findFilesWith(rootDir, /\.js$/)
|
|
16
|
-
.then(fileNames => {
|
|
17
|
-
fileNames.map(fileName => {
|
|
18
|
-
const contents = readFile(fileName)
|
|
19
|
-
// const tree = parse(contents)
|
|
20
|
-
writeFile(fileName, print(contents))
|
|
21
|
-
return fileName
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
.then(fileNames => {
|
|
25
|
-
if (fileNames && fileNames.length) {
|
|
26
|
-
writeLog(`Cleaned ${fileNames.length} files`)
|
|
27
|
-
} else {
|
|
28
|
-
writeLog('No files cleaned')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
})
|
package/file.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
|
|
3
|
-
const { log } = require('./logger')
|
|
4
|
-
|
|
5
|
-
function writeFile(file, content) {
|
|
6
|
-
log('write file', file, content.length)
|
|
7
|
-
fs.writeFileSync(file, content)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function readFile(file) {
|
|
11
|
-
return fs.readFileSync(file, 'utf8')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = { writeFile, readFile }
|
package/findFilesWith.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const recursive = require('recursive-readdir')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
|
|
4
|
-
module.exports = function findFilesWith(rootDir, fileRegex, contentRegex) {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
const ignoreFunc = (file, stats) => fileRegex && !stats.isDirectory() && !file.match(fileRegex)
|
|
7
|
-
recursive(rootDir, [ignoreFunc], (err, files) => {
|
|
8
|
-
if (err) {
|
|
9
|
-
return reject(err)
|
|
10
|
-
}
|
|
11
|
-
return contentRegex
|
|
12
|
-
? resolve(files.filter(file => {
|
|
13
|
-
const contents = fs.readFileSync(file, 'utf8')
|
|
14
|
-
return contents.match(contentRegex)
|
|
15
|
-
}))
|
|
16
|
-
: resolve(files)
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
}
|
package/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const { writeFile, readFile } = require('./file')
|
|
2
|
-
const writeFileWithImports = require('./writeFileWithImports')
|
|
3
|
-
const findFilesWith = require('./findFilesWith')
|
|
4
|
-
const { log, writeLog } = require('./logger')
|
|
5
|
-
const camelCase = require('camelcase')
|
|
6
|
-
const print = require('./print')
|
|
7
|
-
const clean = require('./clean')
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
writeFileWithImports,
|
|
11
|
-
writeFile,
|
|
12
|
-
readFile,
|
|
13
|
-
findFilesWith,
|
|
14
|
-
log,
|
|
15
|
-
writeLog,
|
|
16
|
-
camelCase,
|
|
17
|
-
print,
|
|
18
|
-
clean
|
|
19
|
-
}
|
package/logger.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
let logOutput = ''
|
|
5
|
-
function log(...args) {
|
|
6
|
-
logOutput += args.join(' ') + '\n'
|
|
7
|
-
}
|
|
8
|
-
function writeLog(...args) {
|
|
9
|
-
log(...args)
|
|
10
|
-
console.log(...args)
|
|
11
|
-
fs.writeFileSync(path.join(__dirname, 'output.log'), logOutput)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = { log, writeLog }
|
package/print.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
const prettier = require("prettier");
|
|
3
|
-
|
|
4
|
-
module.exports = (source) => prettier.format(source, {
|
|
5
|
-
// Fit code within this line limit
|
|
6
|
-
printWidth: 180,
|
|
7
|
-
|
|
8
|
-
// Number of spaces it should use per tab
|
|
9
|
-
tabWidth: 4,
|
|
10
|
-
|
|
11
|
-
// If true, will use single instead of double quotes
|
|
12
|
-
singleQuote: true,
|
|
13
|
-
|
|
14
|
-
// Controls the printing of trailing commas wherever possible. Valid options:
|
|
15
|
-
// "none" - No trailing commas
|
|
16
|
-
// "es5" - Trailing commas where valid in ES5 (objects, arrays, etc)
|
|
17
|
-
// "all" - Trailing commas wherever possible (function arguments)
|
|
18
|
-
trailingComma: 'none',
|
|
19
|
-
|
|
20
|
-
// Controls the printing of spaces inside object literals
|
|
21
|
-
bracketSpacing: true,
|
|
22
|
-
|
|
23
|
-
// If true, puts the `>` of a multi-line jsx element at the end of
|
|
24
|
-
// the last line instead of being alone on the next line
|
|
25
|
-
jsxBracketSameLine: false,
|
|
26
|
-
|
|
27
|
-
// Which parser to use. Valid options are 'flow' and 'babylon'
|
|
28
|
-
parser: 'babylon'
|
|
29
|
-
});
|
package/writeFileWithImports.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Writes a file to the filesystem by first adding any imports given that don't already exist
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const assert = require('assert')
|
|
6
|
-
|
|
7
|
-
const regexImport = /const (\w{3,50}) = require\(["']([^'"]+)["']\);?\n*/g
|
|
8
|
-
const regexNamelessImport = /require\(["']([^'"]+)["']\);?/g
|
|
9
|
-
|
|
10
|
-
const { writeFile } = require('./file')
|
|
11
|
-
|
|
12
|
-
module.exports = (fileName, { content, imports, namelessImports }, replaceOld) => {
|
|
13
|
-
let newContent
|
|
14
|
-
const existingImports = {}
|
|
15
|
-
const existingNamelessImports = new Set()
|
|
16
|
-
|
|
17
|
-
// Look for imports in content
|
|
18
|
-
// Ads imports to existing imports then clears the line
|
|
19
|
-
newContent = content.replace(regexImport, (match, importName, importDirectory) => {
|
|
20
|
-
assert(!existingImports[importName], `import name already exists ${importName} in ${fileName}`)
|
|
21
|
-
existingImports[importName] = importDirectory
|
|
22
|
-
return ''
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
// Look for namelessImports in content
|
|
26
|
-
// Ads imports to existing imports then clears the line
|
|
27
|
-
newContent = newContent.replace(regexNamelessImport, (match, importDirectory) => {
|
|
28
|
-
// assert(!existingNamelessImports.has(importDirectory), `nameless import already exists ${importDirectory} in ${fileName}`)
|
|
29
|
-
existingNamelessImports.add(importDirectory)
|
|
30
|
-
return ''
|
|
31
|
-
})
|
|
32
|
-
// Clear newlines from the start of file
|
|
33
|
-
newContent = newContent.replace(/^\n*/, '')
|
|
34
|
-
|
|
35
|
-
// Combine or replace with new imports
|
|
36
|
-
const newImports = {}
|
|
37
|
-
const newNamelessImports = existingNamelessImports
|
|
38
|
-
if (namelessImports) {
|
|
39
|
-
namelessImports.forEach((namelessImport => { newNamelessImports.add(namelessImport) }))
|
|
40
|
-
}
|
|
41
|
-
if (!replaceOld) {
|
|
42
|
-
Object.assign(newImports, existingImports)
|
|
43
|
-
}
|
|
44
|
-
Object.assign(newImports, imports)
|
|
45
|
-
|
|
46
|
-
// Add imports to newContent
|
|
47
|
-
let importsAsString = Object.entries(newImports)
|
|
48
|
-
.sort(([importNameA], [importNameB]) => importNameA.localeCompare(importNameB))
|
|
49
|
-
.map(([importName, importDirectory]) => `const ${importName} = require('${importDirectory}');`)
|
|
50
|
-
.join('\n')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Add nameless imports to newContent
|
|
54
|
-
const namelessImportsAsString = Array.from(newNamelessImports)
|
|
55
|
-
.sort()
|
|
56
|
-
.map(importDirectory => `require('${importDirectory}');`)
|
|
57
|
-
.join('\n')
|
|
58
|
-
|
|
59
|
-
const contentArray = []
|
|
60
|
-
|
|
61
|
-
if (importsAsString) {
|
|
62
|
-
contentArray.push(importsAsString)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (namelessImportsAsString) {
|
|
66
|
-
contentArray.push(namelessImportsAsString)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
contentArray.push(newContent)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
writeFile(fileName, contentArray.join('\n\n'))
|
|
73
|
-
}
|