@suspensive/codemods 0.1.1 → 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.
package/dist/bin/codemods.cjs
CHANGED
|
@@ -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.
|
|
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": "^
|
|
66
|
-
commander: "^
|
|
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"
|
|
@@ -95,12 +95,12 @@ function onCancel() {
|
|
|
95
95
|
}
|
|
96
96
|
var jscodeshiftExecutable = require.resolve(".bin/jscodeshift");
|
|
97
97
|
var transformerDirectory = (0, import_node_path.join)(__dirname, "../", "../", "dist", "transforms");
|
|
98
|
-
async function transformRunner(transform, path) {
|
|
98
|
+
async function transformRunner(transform, path, options) {
|
|
99
99
|
let transformer = transform ?? "";
|
|
100
100
|
let directory = path ?? "";
|
|
101
101
|
if (transform && !TRANSFORMER_INQUIRER_CHOICES.find((x) => x.title === transform)) {
|
|
102
102
|
console.error("Invalid transform choice, pick one of:");
|
|
103
|
-
console.error(TRANSFORMER_INQUIRER_CHOICES.map((x) =>
|
|
103
|
+
console.error(TRANSFORMER_INQUIRER_CHOICES.map((x) => `- ${+x.title}`).join("\n"));
|
|
104
104
|
process.exit(1);
|
|
105
105
|
}
|
|
106
106
|
if (!transform) {
|
|
@@ -134,6 +134,12 @@ async function transformRunner(transform, path) {
|
|
|
134
134
|
directory = res.path;
|
|
135
135
|
}
|
|
136
136
|
const args = [];
|
|
137
|
+
if (options?.dry) {
|
|
138
|
+
args.push("--dry");
|
|
139
|
+
}
|
|
140
|
+
if (options?.print) {
|
|
141
|
+
args.push("--print");
|
|
142
|
+
}
|
|
137
143
|
args.push("--no-babel");
|
|
138
144
|
args.push("--ignore-pattern=**/node_modules/**");
|
|
139
145
|
args.push("--ignore-pattern=**/.next/**");
|
|
@@ -172,5 +178,5 @@ async function transformRunner(transform, path) {
|
|
|
172
178
|
|
|
173
179
|
// src/bin/codemods.ts
|
|
174
180
|
var program = new import_extra_typings.Command(package_default.name);
|
|
175
|
-
program.description(package_default.description).version(package_default.version, "-v, --version", "Output the current version of @suspensive/codemods.").argument("[codemod]",
|
|
181
|
+
program.description(package_default.description).version(package_default.version, "-v, --version", "Output the current version of @suspensive/codemods.").argument("[codemod]", 'Codemod slug to run. See "https://suspensive.org/docs/codemods/motivation"').argument("[path]", "Path to source directory.").usage("[codemod] [path]").helpOption("-h, --help", "Display this help message.").option("-d, --dry", "Dry run (no changes are made to files)").option("-p, --print", "Print transformed files to stdout, useful for development").action(transformRunner);
|
|
176
182
|
program.parse(process.argv);
|
|
@@ -49,12 +49,12 @@ function onCancel() {
|
|
|
49
49
|
}
|
|
50
50
|
var jscodeshiftExecutable = require.resolve(".bin/jscodeshift");
|
|
51
51
|
var transformerDirectory = (0, import_node_path.join)(__dirname, "../", "../", "dist", "transforms");
|
|
52
|
-
async function transformRunner(transform, path) {
|
|
52
|
+
async function transformRunner(transform, path, options) {
|
|
53
53
|
let transformer = transform ?? "";
|
|
54
54
|
let directory = path ?? "";
|
|
55
55
|
if (transform && !TRANSFORMER_INQUIRER_CHOICES.find((x) => x.title === transform)) {
|
|
56
56
|
console.error("Invalid transform choice, pick one of:");
|
|
57
|
-
console.error(TRANSFORMER_INQUIRER_CHOICES.map((x) =>
|
|
57
|
+
console.error(TRANSFORMER_INQUIRER_CHOICES.map((x) => `- ${+x.title}`).join("\n"));
|
|
58
58
|
process.exit(1);
|
|
59
59
|
}
|
|
60
60
|
if (!transform) {
|
|
@@ -88,6 +88,12 @@ async function transformRunner(transform, path) {
|
|
|
88
88
|
directory = res.path;
|
|
89
89
|
}
|
|
90
90
|
const args = [];
|
|
91
|
+
if (options?.dry) {
|
|
92
|
+
args.push("--dry");
|
|
93
|
+
}
|
|
94
|
+
if (options?.print) {
|
|
95
|
+
args.push("--print");
|
|
96
|
+
}
|
|
91
97
|
args.push("--no-babel");
|
|
92
98
|
args.push("--ignore-pattern=**/node_modules/**");
|
|
93
99
|
args.push("--ignore-pattern=**/.next/**");
|
|
@@ -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.
|
|
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": "^
|
|
26
|
-
"commander": "^
|
|
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
|
}
|