@suspensive/codemods 0.2.0 → 0.3.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.
@@ -29,7 +29,7 @@ var import_extra_typings = require("@commander-js/extra-typings");
29
29
  // package.json
30
30
  var package_default = {
31
31
  name: "@suspensive/codemods",
32
- version: "0.2.0",
32
+ version: "0.3.0",
33
33
  description: "Codemods for @suspensive.",
34
34
  keywords: [
35
35
  "suspensive",
@@ -57,13 +57,13 @@ var package_default = {
57
57
  "ci:publint": "publint --strict",
58
58
  "ci:test": "vitest run --coverage --typecheck",
59
59
  "ci:type": "tsc --noEmit",
60
- clean: "rimraf ./dist && rimraf ./coverage",
61
- prepack: "pnpm build",
60
+ clean: "rimraf ./dist && rimraf ./coverage && rimraf ./node_modules",
61
+ prepack: "pnpm run build",
62
62
  "test:ui": "vitest --ui --coverage --typecheck"
63
63
  },
64
64
  dependencies: {
65
- "@commander-js/extra-typings": "^12.1.0",
66
- commander: "^12.1.0",
65
+ "@commander-js/extra-typings": "^13.0.0",
66
+ commander: "^13.0.0",
67
67
  execa: "^5.1.1",
68
68
  jscodeshift: "^17.0.0",
69
69
  prompts: "^2.4.2"
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/transforms/migrate-query-client-consumer-props.ts
31
+ var migrate_query_client_consumer_props_exports = {};
32
+ __export(migrate_query_client_consumer_props_exports, {
33
+ default: () => transform
34
+ });
35
+ module.exports = __toCommonJS(migrate_query_client_consumer_props_exports);
36
+
37
+ // src/transforms/utils/createParserFromPath.ts
38
+ var import_jscodeshift = __toESM(require("jscodeshift"), 1);
39
+ var import_babylon = __toESM(require("jscodeshift/parser/babylon"), 1);
40
+ var import_tsOptions = __toESM(require("jscodeshift/parser/tsOptions"), 1);
41
+ function createParserFromPath(filePath) {
42
+ const isDeclarationFile = /\.d\.[mc]?ts$/.test(filePath);
43
+ if (isDeclarationFile) {
44
+ return import_jscodeshift.default.withParser(
45
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
46
+ (0, import_babylon.default)({
47
+ ...import_tsOptions.default,
48
+ plugins: [
49
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
50
+ ...import_tsOptions.default.plugins.filter((plugin) => plugin !== "typescript"),
51
+ ["typescript", { dts: true }]
52
+ ]
53
+ })
54
+ );
55
+ }
56
+ const isTsFile = /\.[mc]?ts$/.test(filePath);
57
+ return isTsFile ? import_jscodeshift.default.withParser("ts") : import_jscodeshift.default.withParser("tsx");
58
+ }
59
+
60
+ // src/transforms/migrate-query-client-consumer-props.ts
61
+ function transform(file) {
62
+ const j2 = createParserFromPath(file.path);
63
+ const root = j2(file.source);
64
+ root.find(j2.JSXElement, {
65
+ openingElement: {
66
+ name: { name: "QueryClientConsumer" }
67
+ }
68
+ }).forEach((path) => {
69
+ const attributes = path.node.openingElement.attributes || [];
70
+ const contextIndex = attributes.findIndex((attr) => attr.type === "JSXAttribute" && attr.name.name === "context");
71
+ if (contextIndex !== -1) {
72
+ attributes.splice(contextIndex, 1);
73
+ const newAttr = j2.jsxAttribute(
74
+ j2.jsxIdentifier("queryClient"),
75
+ j2.jsxExpressionContainer(j2.identifier("queryClient"))
76
+ );
77
+ attributes.push(newAttr);
78
+ }
79
+ });
80
+ return root.toSource();
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suspensive/codemods",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Codemods for @suspensive.",
5
5
  "keywords": [
6
6
  "suspensive",
@@ -22,8 +22,8 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@commander-js/extra-typings": "^12.1.0",
26
- "commander": "^12.1.0",
25
+ "@commander-js/extra-typings": "^13.0.0",
26
+ "commander": "^13.0.0",
27
27
  "execa": "^5.1.1",
28
28
  "jscodeshift": "^17.0.0",
29
29
  "prompts": "^2.4.2"
@@ -45,7 +45,7 @@
45
45
  "ci:publint": "publint --strict",
46
46
  "ci:test": "vitest run --coverage --typecheck",
47
47
  "ci:type": "tsc --noEmit",
48
- "clean": "rimraf ./dist && rimraf ./coverage",
48
+ "clean": "rimraf ./dist && rimraf ./coverage && rimraf ./node_modules",
49
49
  "test:ui": "vitest --ui --coverage --typecheck"
50
50
  }
51
51
  }