@kamaalio/codemod-kit 0.0.25 → 0.0.26
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/dist/codemods/index.d.ts +1 -1
- package/dist/codemods/utils.d.ts +4 -2
- package/dist/index.cjs +22 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -1
- package/package.json +2 -2
package/dist/codemods/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { runCodemods, runCodemod, commitEditModifications, findAndReplace, findAndReplaceEdits, findAndReplaceConfig, findAndReplaceConfigModifications, } from './utils.js';
|
|
1
|
+
export { runCodemods, runCodemod, commitEditModifications, findAndReplace, findAndReplaceEdits, findAndReplaceConfig, findAndReplaceConfigModifications, traverseUp, } from './utils.js';
|
|
2
2
|
export type { Codemod, Modifications, FindAndReplaceConfig } from './types.js';
|
package/dist/codemods/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Result } from 'neverthrow';
|
|
2
|
-
import { type Edit, type SgRoot } from '@ast-grep/napi';
|
|
3
|
-
import type { TypesMap } from '@ast-grep/napi/types/staticTypes.js';
|
|
2
|
+
import { type Edit, type SgRoot, type SgNode } from '@ast-grep/napi';
|
|
3
|
+
import type { Kinds, TypesMap } from '@ast-grep/napi/types/staticTypes.js';
|
|
4
4
|
import type { NapiLang } from '@ast-grep/napi/types/lang.js';
|
|
5
|
+
import { type types } from '@kamaalio/kamaal';
|
|
5
6
|
import type { Codemod, FindAndReplaceConfig, Modifications } from './types.js';
|
|
6
7
|
type RunCodemodHooks<C extends Codemod> = {
|
|
7
8
|
targetFiltering?: (filepath: string, codemod: C) => boolean;
|
|
@@ -21,6 +22,7 @@ export declare function runCodemod<C extends Codemod>(codemod: C, transformation
|
|
|
21
22
|
hasChanges: boolean;
|
|
22
23
|
content: string;
|
|
23
24
|
}, Error>>>;
|
|
25
|
+
export declare function traverseUp(node: SgNode<TypesMap, Kinds<TypesMap>>, until: (node: SgNode<TypesMap, Kinds<TypesMap>>) => boolean): types.Optional<SgNode<TypesMap, Kinds<TypesMap>>>;
|
|
24
26
|
export declare function findAndReplaceConfigModifications(modifications: Modifications, config: Array<FindAndReplaceConfig>): Promise<Modifications>;
|
|
25
27
|
export declare function findAndReplaceConfig(content: SgRoot<TypesMap>, lang: NapiLang, config: Array<FindAndReplaceConfig>): Promise<string>;
|
|
26
28
|
export declare function findAndReplaceEdits(content: SgRoot<TypesMap>, rule: FindAndReplaceConfig['rule'], transformer: FindAndReplaceConfig['transformer']): Array<Edit>;
|
package/dist/index.cjs
CHANGED
|
@@ -33,13 +33,14 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
findAndReplace: ()=>findAndReplace,
|
|
37
|
+
findAndReplaceConfig: ()=>findAndReplaceConfig,
|
|
36
38
|
commitEditModifications: ()=>commitEditModifications,
|
|
37
|
-
runCodemods: ()=>runCodemods,
|
|
38
39
|
runCodemod: ()=>runCodemod,
|
|
39
|
-
findAndReplace: ()=>findAndReplace,
|
|
40
40
|
findAndReplaceConfigModifications: ()=>findAndReplaceConfigModifications,
|
|
41
41
|
findAndReplaceEdits: ()=>findAndReplaceEdits,
|
|
42
|
-
|
|
42
|
+
runCodemods: ()=>runCodemods,
|
|
43
|
+
traverseUp: ()=>traverseUp
|
|
43
44
|
});
|
|
44
45
|
const external_node_path_namespaceObject = require("node:path");
|
|
45
46
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
@@ -131,6 +132,21 @@ async function runCodemod(codemod, transformationPath, options) {
|
|
|
131
132
|
}
|
|
132
133
|
}));
|
|
133
134
|
}
|
|
135
|
+
function traverseUp(node, until) {
|
|
136
|
+
let current = node.parent();
|
|
137
|
+
if (null == current) return null;
|
|
138
|
+
while(null != current){
|
|
139
|
+
const next = current.parent();
|
|
140
|
+
if (null == next) break;
|
|
141
|
+
if (until(next)) {
|
|
142
|
+
current = next;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
current = next;
|
|
146
|
+
}
|
|
147
|
+
if (!until(current)) return null;
|
|
148
|
+
return current;
|
|
149
|
+
}
|
|
134
150
|
async function findAndReplaceConfigModifications(modifications, config) {
|
|
135
151
|
let currentModifications = {
|
|
136
152
|
...modifications
|
|
@@ -266,6 +282,7 @@ exports.findAndReplaceConfigModifications = __webpack_exports__.findAndReplaceCo
|
|
|
266
282
|
exports.findAndReplaceEdits = __webpack_exports__.findAndReplaceEdits;
|
|
267
283
|
exports.runCodemod = __webpack_exports__.runCodemod;
|
|
268
284
|
exports.runCodemods = __webpack_exports__.runCodemods;
|
|
285
|
+
exports.traverseUp = __webpack_exports__.traverseUp;
|
|
269
286
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
270
287
|
"commitEditModifications",
|
|
271
288
|
"findAndReplace",
|
|
@@ -273,7 +290,8 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
273
290
|
"findAndReplaceConfigModifications",
|
|
274
291
|
"findAndReplaceEdits",
|
|
275
292
|
"runCodemod",
|
|
276
|
-
"runCodemods"
|
|
293
|
+
"runCodemods",
|
|
294
|
+
"traverseUp"
|
|
277
295
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
278
296
|
Object.defineProperty(exports, '__esModule', {
|
|
279
297
|
value: true
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { runCodemods, runCodemod, commitEditModifications, findAndReplace, findAndReplaceEdits, findAndReplaceConfig, findAndReplaceConfigModifications, type Codemod, type Modifications, type FindAndReplaceConfig, } from './codemods/index.js';
|
|
1
|
+
export { runCodemods, runCodemod, commitEditModifications, findAndReplace, findAndReplaceEdits, findAndReplaceConfig, findAndReplaceConfigModifications, traverseUp, type Codemod, type Modifications, type FindAndReplaceConfig, } from './codemods/index.js';
|
package/dist/index.js
CHANGED
|
@@ -85,6 +85,21 @@ async function runCodemod(codemod, transformationPath, options) {
|
|
|
85
85
|
}
|
|
86
86
|
}));
|
|
87
87
|
}
|
|
88
|
+
function traverseUp(node, until) {
|
|
89
|
+
let current = node.parent();
|
|
90
|
+
if (null == current) return null;
|
|
91
|
+
while(null != current){
|
|
92
|
+
const next = current.parent();
|
|
93
|
+
if (null == next) break;
|
|
94
|
+
if (until(next)) {
|
|
95
|
+
current = next;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
current = next;
|
|
99
|
+
}
|
|
100
|
+
if (!until(current)) return null;
|
|
101
|
+
return current;
|
|
102
|
+
}
|
|
88
103
|
async function findAndReplaceConfigModifications(modifications, config) {
|
|
89
104
|
let currentModifications = {
|
|
90
105
|
...modifications
|
|
@@ -213,4 +228,4 @@ function defaultedHooks(hooks) {
|
|
|
213
228
|
preCodemodRun
|
|
214
229
|
};
|
|
215
230
|
}
|
|
216
|
-
export { commitEditModifications, findAndReplace, findAndReplaceConfig, findAndReplaceConfigModifications, findAndReplaceEdits, runCodemod, runCodemods };
|
|
231
|
+
export { commitEditModifications, findAndReplace, findAndReplaceConfig, findAndReplaceConfigModifications, findAndReplaceEdits, runCodemod, runCodemods, traverseUp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamaalio/codemod-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Kamaal Farah",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@ast-grep/napi": "^0.38.5",
|
|
23
|
-
"@kamaalio/kamaal": "^0.7.
|
|
23
|
+
"@kamaalio/kamaal": "^0.7.8",
|
|
24
24
|
"fast-glob": "^3.3.3",
|
|
25
25
|
"neverthrow": "^8.2.0"
|
|
26
26
|
},
|