@kamaalio/codemod-kit 0.0.5 → 0.0.7

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.
@@ -1,15 +1,15 @@
1
1
  import { type Result } from 'neverthrow';
2
2
  import type { Codemod, Modifications } from './types.js';
3
- type RunCodemodHooks = {
4
- targetFiltering?: (filepath: string) => boolean;
5
- preCodemodRun?: (codemod: Codemod) => Promise<void>;
6
- postTransform?: (transformedContent: string) => Promise<string>;
3
+ type RunCodemodHooks<C extends Codemod> = {
4
+ targetFiltering?: (filepath: string, codemod: C) => boolean;
5
+ preCodemodRun?: (codemod: C) => Promise<void>;
6
+ postTransform?: (transformedContent: string, codemod: C) => Promise<string>;
7
7
  };
8
- type RunCodemodOptions = {
9
- hooks?: RunCodemodHooks;
8
+ type RunCodemodOptions<C extends Codemod> = {
9
+ hooks?: RunCodemodHooks<C>;
10
10
  log?: boolean;
11
11
  dry?: boolean;
12
12
  };
13
- export declare function runCodemods(codemods: Array<Codemod>, transformationPath: string, options?: RunCodemodOptions): Promise<Record<string, Array<Result<Modifications, Error>>>>;
14
- export declare function runCodemod(codemod: Codemod, transformationPath: string, options?: RunCodemodOptions): Promise<Array<Result<Modifications, Error>>>;
13
+ export declare function runCodemods<C extends Codemod>(codemods: Array<C>, transformationPath: string, options?: RunCodemodOptions<C>): Promise<Record<string, Array<Result<Modifications, Error>>>>;
14
+ export declare function runCodemod<C extends Codemod>(codemod: C, transformationPath: string, options?: RunCodemodOptions<C>): Promise<Array<Result<Modifications, Error>>>;
15
15
  export {};
package/dist/index.cjs CHANGED
@@ -80,7 +80,7 @@ async function runCodemod(codemod, transformationPath, options) {
80
80
  return acc.concat(Array.from(mappedExtensions));
81
81
  }, []));
82
82
  const targets = globItems.filter((filepath)=>{
83
- if (!hooks.targetFiltering(filepath)) return false;
83
+ if (!hooks.targetFiltering(filepath, codemod)) return false;
84
84
  const projectName = filepath.split('/')[0];
85
85
  if (null == projectName) throw new Error('Invariant found, project name should be present');
86
86
  return collectionIsEmpty(extensions) || extensions.has(external_node_path_default().extname(filepath));
@@ -95,7 +95,7 @@ async function runCodemod(codemod, transformationPath, options) {
95
95
  });
96
96
  const modifications = await codemod.transformer(content, fullPath);
97
97
  if (modifications.report.changesApplied > 0) {
98
- const transformedContent = await hooks.postTransform(modifications.ast.root().text());
98
+ const transformedContent = await hooks.postTransform(modifications.ast.root().text(), codemod);
99
99
  if (!runInDryMode) await promises_default().writeFile(fullPath, transformedContent);
100
100
  if (enableLogging) console.log(`\u{1F680} finished '${codemod.name}'`, {
101
101
  filename: filepath,
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ async function runCodemod(codemod, transformationPath, options) {
39
39
  return acc.concat(Array.from(mappedExtensions));
40
40
  }, []));
41
41
  const targets = globItems.filter((filepath)=>{
42
- if (!hooks.targetFiltering(filepath)) return false;
42
+ if (!hooks.targetFiltering(filepath, codemod)) return false;
43
43
  const projectName = filepath.split('/')[0];
44
44
  if (null == projectName) throw new Error('Invariant found, project name should be present');
45
45
  return collectionIsEmpty(extensions) || extensions.has(node_path.extname(filepath));
@@ -54,7 +54,7 @@ async function runCodemod(codemod, transformationPath, options) {
54
54
  });
55
55
  const modifications = await codemod.transformer(content, fullPath);
56
56
  if (modifications.report.changesApplied > 0) {
57
- const transformedContent = await hooks.postTransform(modifications.ast.root().text());
57
+ const transformedContent = await hooks.postTransform(modifications.ast.root().text(), codemod);
58
58
  if (!runInDryMode) await promises.writeFile(fullPath, transformedContent);
59
59
  if (enableLogging) console.log(`\u{1F680} finished '${codemod.name}'`, {
60
60
  filename: filepath,
@@ -1 +1,4 @@
1
1
  export type Optional<T> = T | undefined | null;
2
+ export type ReplaceObjectProperty<A extends Record<string, unknown>, K extends keyof A, B> = Omit<A, K> & {
3
+ [P in K]: B;
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kamaalio/codemod-kit",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "author": "Kamaal Farah",
6
6
  "license": "MIT",