@kamaalio/codemod-kit 0.0.6 → 0.0.8

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, codemod: Codemod) => boolean;
5
- preCodemodRun?: (codemod: Codemod) => Promise<void>;
6
- postTransform?: (transformedContent: string, codemod: Codemod) => 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
@@ -81,8 +81,6 @@ async function runCodemod(codemod, transformationPath, options) {
81
81
  }, []));
82
82
  const targets = globItems.filter((filepath)=>{
83
83
  if (!hooks.targetFiltering(filepath, codemod)) return false;
84
- const projectName = filepath.split('/')[0];
85
- if (null == projectName) throw new Error('Invariant found, project name should be present');
86
84
  return collectionIsEmpty(extensions) || extensions.has(external_node_path_default().extname(filepath));
87
85
  });
88
86
  if (0 === targets.length) return [];
package/dist/index.js CHANGED
@@ -40,8 +40,6 @@ async function runCodemod(codemod, transformationPath, options) {
40
40
  }, []));
41
41
  const targets = globItems.filter((filepath)=>{
42
42
  if (!hooks.targetFiltering(filepath, codemod)) return false;
43
- const projectName = filepath.split('/')[0];
44
- if (null == projectName) throw new Error('Invariant found, project name should be present');
45
43
  return collectionIsEmpty(extensions) || extensions.has(node_path.extname(filepath));
46
44
  });
47
45
  if (0 === targets.length) return [];
@@ -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.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "author": "Kamaal Farah",
6
6
  "license": "MIT",