@pob/codemods 0.10.10 → 0.11.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/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.11.0](https://github.com/christophehurpeau/pob/compare/@pob/codemods@0.10.11...@pob/codemods@0.11.0) (2026-04-05)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * node 24
11
+
12
+ ### Features
13
+
14
+ * node 24
15
+
16
+ ## [0.10.11](https://github.com/christophehurpeau/pob/compare/@pob/codemods@0.10.10...@pob/codemods@0.10.11) (2026-03-21)
17
+
18
+ Note: no notable changes
19
+
20
+
6
21
  ## [0.10.10](https://github.com/christophehurpeau/pob/compare/@pob/codemods@0.10.9...@pob/codemods@0.10.10) (2026-03-12)
7
22
 
8
23
  Note: no notable changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pob/codemods",
3
- "version": "0.10.10",
3
+ "version": "0.11.0",
4
4
  "description": "codemods for pob",
5
5
  "keywords": [],
6
6
  "author": "Christophe Hurpeau <302891+christophehurpeau@users.noreply.github.com> (https://christophe.hurpeau.com)",
@@ -13,7 +13,7 @@
13
13
  "homepage": "https://github.com/christophehurpeau/pob",
14
14
  "type": "module",
15
15
  "engines": {
16
- "node": ">=22.18.0"
16
+ "node": ">=24.0.0"
17
17
  },
18
18
  "bin": {
19
19
  "pob-migrate": "./bin/migrate.mjs"
@@ -26,10 +26,16 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
+ "files": [
30
+ "src",
31
+ "build",
32
+ "bin",
33
+ "lib/index.js"
34
+ ],
29
35
  "scripts": {
30
36
  "install-bin": "ln -s $PWD/bin/migrate.mjs /usr/local/bin/pob-migrate",
31
37
  "lint": "yarn run lint:eslint",
32
- "lint:eslint": "yarn ../.. run eslint --quiet '@pob/codemods'"
38
+ "lint:eslint": "yarn '../..' run eslint --quiet '@pob/codemods'"
33
39
  },
34
40
  "pob": {},
35
41
  "prettier": "@pob/root/prettier-config",
@@ -38,6 +44,6 @@
38
44
  },
39
45
  "devDependencies": {
40
46
  "@types/jscodeshift": "17.3.0",
41
- "@types/node": "22.19.13"
47
+ "@types/node": "24.12.0"
42
48
  }
43
49
  }
package/.editorconfig DELETED
@@ -1,13 +0,0 @@
1
- # EditorConfig helps developers define and maintain consistent
2
- # coding styles between different editors and IDEs
3
- # http://editorconfig.org
4
-
5
- root = true
6
-
7
- [*]
8
- indent_style = space
9
- indent_size = 2
10
- end_of_line = lf
11
- charset = utf-8
12
- trim_trailing_whitespace = true
13
- insert_final_newline = true
package/.yo-rc.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "pob": {
3
- "app": {
4
- "type": "node",
5
- "testing": false
6
- },
7
- "project": {
8
- "type": "app"
9
- }
10
- }
11
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- const { run: jscodeshift } = require("jscodeshift/src/Runner");
4
-
5
- module.exports = (...args) => {
6
- return jscodeshift(...args);
7
- };
@@ -1,146 +0,0 @@
1
- /* eslint-disable unicorn/prefer-array-some */
2
- /* eslint-disable unicorn/no-array-method-this-argument */
3
-
4
- "use strict";
5
-
6
- const { prependImport } = require("../utils/prependImport.cjs");
7
-
8
- const jestToNodeGlobalMethods = {
9
- test: "test",
10
- describe: "describe",
11
- it: "it",
12
- beforeAll: "before",
13
- afterAll: "after",
14
- beforeEach: "beforeEach",
15
- afterEach: "afterEach",
16
- };
17
- const propertiesMap = {
18
- toBe: { default: "equal", not: "notEqual" },
19
- toStrictEqual: { default: "equal", not: "notEqual" },
20
- toEqual: { default: "equal", not: "notEqual" },
21
- };
22
-
23
- // const mocks = {
24
- // toHaveBeenCalledTimes: {
25
- // default: 'mock.calls.length',
26
- // },
27
- // };
28
-
29
- module.exports = (file, api, options) => {
30
- if (
31
- !(
32
- file.path.endsWith(".test.js") ||
33
- file.path.endsWith(".test.ts") ||
34
- file.path.endsWith(".test.tsx")
35
- )
36
- ) {
37
- throw new Error(`Invalid file: "${file.path}"`);
38
- }
39
-
40
- const j = api.jscodeshift.withParser("tsx");
41
- const root = j(file.source);
42
-
43
- function updateTopLevelMethods() {
44
- const topLevelMethodsUsed = new Set();
45
-
46
- root
47
- .find(j.CallExpression, {
48
- callee: {
49
- type: j.Identifier.name,
50
- name: (name) => Object.keys(jestToNodeGlobalMethods).includes(name),
51
- },
52
- })
53
- .replaceWith((p) => {
54
- const { value } = p;
55
- const replaceValue = jestToNodeGlobalMethods[value.callee.name];
56
- topLevelMethodsUsed.add(replaceValue);
57
-
58
- return j.callExpression(j.identifier(replaceValue), value.arguments);
59
- });
60
-
61
- if (topLevelMethodsUsed.size > 0) {
62
- prependImport(
63
- j,
64
- root,
65
- j.importDeclaration(
66
- [...topLevelMethodsUsed].map((method) =>
67
- j.importSpecifier(j.identifier(method)),
68
- ),
69
- j.stringLiteral("node:test"),
70
- ),
71
- );
72
- }
73
- }
74
-
75
- function updateAssertions() {
76
- let hasAssertions = false;
77
-
78
- root
79
- .find(j.MemberExpression, {
80
- object: {
81
- callee: { name: "expect" },
82
- },
83
- })
84
- .forEach((memberExpressionPath) => {
85
- const { value: memberExpression, parentPath } = memberExpressionPath;
86
- let memberExpressionPathToReplace = memberExpressionPath;
87
- let propertyName = memberExpression.property.name;
88
- let not = false;
89
- if (propertyName === "not") {
90
- not = true;
91
- memberExpressionPathToReplace = parentPath;
92
- propertyName = parentPath.value.property.name;
93
- }
94
-
95
- if (!propertiesMap[propertyName]) {
96
- console.warn(
97
- `Unsupported expect property: ${propertyName} in ${file.path}`,
98
- );
99
- return;
100
- }
101
-
102
- const assertPropertyName =
103
- propertiesMap[propertyName][not ? "not" : "default"];
104
- const callExpressionPath = memberExpressionPathToReplace.parentPath;
105
-
106
- const value = memberExpression.object.arguments[0];
107
- const expected = callExpressionPath.value.arguments[0];
108
-
109
- hasAssertions = true;
110
- callExpressionPath.value.callee = j.memberExpression(
111
- j.identifier("assert"),
112
- j.identifier(assertPropertyName),
113
- );
114
- callExpressionPath.value.arguments = [value, expected];
115
- });
116
-
117
- if (hasAssertions) {
118
- root
119
- .find(j.ImportDeclaration, { source: { value: "node:assert" } })
120
- .remove();
121
- if (
122
- // eslint-disable-next-line no-constant-condition
123
- (!root.find(j.ImportDeclaration),
124
- { source: { value: "node:assert/strict" } })
125
- ) {
126
- prependImport(
127
- j,
128
- root,
129
- j.importDeclaration(
130
- [j.importDefaultSpecifier(j.identifier("assert"))],
131
- j.stringLiteral("node:assert/strict"),
132
- ),
133
- );
134
- }
135
- }
136
- }
137
-
138
- updateTopLevelMethods();
139
- updateAssertions();
140
-
141
- root
142
- .find(j.ImportDeclaration, { source: { value: "@jest/globals" } })
143
- .remove();
144
-
145
- return root.toSource(options);
146
- };
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable complexity */
4
- module.exports = (file, api, options) => {
5
- const j = api.jscodeshift.withParser("tsx");
6
- const root = j(file.source);
7
- let hasModifications = false;
8
-
9
- function processFunctionComponent(path) {
10
- const node = path.value;
11
- const { returnType } = node;
12
- if (returnType == null) return;
13
- if (returnType.type !== "TSTypeAnnotation") return;
14
- const { typeAnnotation } = returnType;
15
- if (typeAnnotation == null) return;
16
-
17
- if (
18
- typeAnnotation.type === "TSTypeReference" &&
19
- typeAnnotation.typeName &&
20
- typeAnnotation.typeName.type === "Identifier"
21
- ) {
22
- if (typeAnnotation.typeName.name === "ReactElement") {
23
- typeAnnotation.typeName.name = "ReactNode";
24
- hasModifications = true;
25
- }
26
- } else if (
27
- typeAnnotation.type === "TSUnionType" &&
28
- typeAnnotation.types.every((unionTypeItem) => {
29
- if (unionTypeItem.type === "TSTypeReference") {
30
- return (
31
- unionTypeItem.typeName &&
32
- unionTypeItem.typeName.type === "Identifier" &&
33
- unionTypeItem.typeName.name === "ReactElement"
34
- );
35
- }
36
-
37
- if (unionTypeItem.type === "TSNullKeyword") {
38
- return true;
39
- }
40
-
41
- return false;
42
- })
43
- ) {
44
- returnType.typeAnnotation = j.tsTypeReference(j.identifier("ReactNode"));
45
- hasModifications = true;
46
- }
47
- }
48
-
49
- root.find(j.FunctionDeclaration).forEach(processFunctionComponent);
50
-
51
- if (hasModifications) {
52
- root.find(j.ImportDeclaration).forEach((importDeclaration) => {
53
- const { node } = importDeclaration;
54
- if (node.source.value !== "react") return;
55
- if (node.importKind !== "type") return;
56
-
57
- node.specifiers = node.specifiers.filter((importSpecifier) => {
58
- if (importSpecifier.local.name !== "ReactElement") return true;
59
- if (importSpecifier.importKind !== "value") return true;
60
- return (
61
- j(importDeclaration)
62
- .closestScope()
63
- // eslint-disable-next-line unicorn/no-array-method-this-argument -- not an array
64
- .find(j.Identifier, { name: "ReactElement" })
65
- .filter((p) => {
66
- if (p.value.start === importSpecifier.local.start) return false;
67
- if (p.parentPath.value.type === "Property" && p.name === "key") {
68
- return false;
69
- }
70
- if (p.name === "property") return false;
71
- return true;
72
- })
73
- .size() > 0
74
- );
75
- });
76
- if (
77
- !node.specifiers.some(
78
- (specifier) =>
79
- specifier.type === "ImportSpecifier" &&
80
- specifier.imported.name === "ReactNode",
81
- )
82
- ) {
83
- node.specifiers.push(j.importSpecifier(j.identifier("ReactNode")));
84
- }
85
- });
86
- }
87
-
88
- return hasModifications ? root.toSource(options) : null;
89
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- exports.prependImport = (j, source, importDeclaration) => {
4
- const existingImports = source.find(j.ImportDeclaration);
5
- if (existingImports.length > 0) {
6
- const firstImport = existingImports.at(0);
7
- const firstImportNode = firstImport.nodes()[0];
8
- if (firstImportNode?.comments) {
9
- importDeclaration.comments = firstImportNode.comments;
10
- firstImportNode.comments = null;
11
- }
12
-
13
- firstImport.insertBefore(importDeclaration);
14
- return;
15
- }
16
-
17
- const firstNode = source.find(j.Program).get("body", 0).node;
18
- const { comments } = firstNode;
19
- if (comments?.length) {
20
- const comment = comments[0];
21
-
22
- // Only move comments that look like file-level comments. Ignore
23
- // line-level and JSDoc-style comments because these probably belong
24
- // to the first node, rather than the file.
25
- if (
26
- (comment.type === "Block" || comment.type === "CommentBlock") &&
27
- !comment.value.startsWith("*")
28
- ) {
29
- importDeclaration.comments = comments;
30
- firstNode.comments = null;
31
- }
32
- }
33
-
34
- source.get("program", "body").unshift(importDeclaration);
35
- };