@suspensive/codemods 3.1.1 → 3.2.1
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: "3.
|
|
32
|
+
version: "3.2.1",
|
|
33
33
|
description: "Codemods for @suspensive.",
|
|
34
34
|
keywords: [
|
|
35
35
|
"suspensive",
|
|
@@ -57,7 +57,7 @@ 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
|
|
60
|
+
clean: "rimraf ./dist ./coverage ./node_modules",
|
|
61
61
|
prepack: "pnpm run build",
|
|
62
62
|
"test:ui": "vitest --ui --coverage --typecheck"
|
|
63
63
|
},
|
|
@@ -96,6 +96,10 @@ var TRANSFORMER_INQUIRER_CHOICES = [
|
|
|
96
96
|
{
|
|
97
97
|
title: "migrate-with-api",
|
|
98
98
|
description: "Migrate wrap API to with API for Suspensive v3"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
title: "remove-networkmode",
|
|
102
|
+
description: "Remove networkMode from Suspense API"
|
|
99
103
|
}
|
|
100
104
|
];
|
|
101
105
|
function onCancel() {
|
|
@@ -50,6 +50,10 @@ var TRANSFORMER_INQUIRER_CHOICES = [
|
|
|
50
50
|
{
|
|
51
51
|
title: "migrate-with-api",
|
|
52
52
|
description: "Migrate wrap API to with API for Suspensive v3"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: "remove-networkmode",
|
|
56
|
+
description: "Remove networkMode from Suspense API"
|
|
53
57
|
}
|
|
54
58
|
];
|
|
55
59
|
function onCancel() {
|
|
@@ -0,0 +1,106 @@
|
|
|
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/remove-networkmode.ts
|
|
31
|
+
var remove_networkmode_exports = {};
|
|
32
|
+
__export(remove_networkmode_exports, {
|
|
33
|
+
default: () => transform
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(remove_networkmode_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/remove-networkmode.ts
|
|
61
|
+
var TARGET_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
62
|
+
"queryOptions",
|
|
63
|
+
"infiniteQueryOptions",
|
|
64
|
+
"useSuspenseQuery",
|
|
65
|
+
"useSuspenseInfiniteQuery",
|
|
66
|
+
"SuspenseQuery",
|
|
67
|
+
"SuspenseInfiniteQuery"
|
|
68
|
+
]);
|
|
69
|
+
function transform(file) {
|
|
70
|
+
const j2 = createParserFromPath(file.path);
|
|
71
|
+
const root = j2(file.source);
|
|
72
|
+
root.find(j2.CallExpression, {
|
|
73
|
+
callee: {
|
|
74
|
+
type: "Identifier"
|
|
75
|
+
}
|
|
76
|
+
}).forEach((path) => {
|
|
77
|
+
if (path.node.callee.type !== "Identifier") {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const calleeName = path.node.callee.name;
|
|
81
|
+
if (!TARGET_FUNCTIONS.has(calleeName)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const args = path.node.arguments;
|
|
85
|
+
if (args.length === 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const firstArg = args[0];
|
|
89
|
+
if (firstArg.type !== "ObjectExpression") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const properties = firstArg.properties;
|
|
93
|
+
const networkModeIndex = properties.findIndex((prop) => {
|
|
94
|
+
if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "networkMode") {
|
|
95
|
+
if (prop.value.type === "StringLiteral" && prop.value.value === "always") {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
});
|
|
101
|
+
if (networkModeIndex !== -1) {
|
|
102
|
+
properties.splice(networkModeIndex, 1);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return root.toSource();
|
|
106
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suspensive/codemods",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Codemods for @suspensive.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"suspensive",
|
|
@@ -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
|
|
48
|
+
"clean": "rimraf ./dist ./coverage ./node_modules",
|
|
49
49
|
"test:ui": "vitest --ui --coverage --typecheck"
|
|
50
50
|
}
|
|
51
51
|
}
|