@beinformed/codemod 0.1.1-beta.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/LICENSE.md +1 -0
- package/dist/chunk-VJQ72WQS.js +11 -0
- package/dist/chunk-VJQ72WQS.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +53 -0
- package/dist/cli.js.map +1 -0
- package/dist/generate_mapping.js +208 -0
- package/dist/mapping.json +691 -0
- package/dist/transforms/migrate-imports.d.ts +26 -0
- package/dist/transforms/migrate-imports.js +189 -0
- package/dist/transforms/migrate-imports.js.map +1 -0
- package/package.json +39 -0
- package/usage.md +43 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { JSCodeshift } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* jscodeshift transform to migrate imports from the old
|
|
5
|
+
* '@beinformed/ui/*' structure to the new '@beinformed/...' packages.
|
|
6
|
+
*
|
|
7
|
+
* - Detects whether to use Flow or TSX parser based on the file extension (.js) or the presence of @flow pragma.
|
|
8
|
+
* - Uses the mapping.json file to determine the new package for each imported symbol.
|
|
9
|
+
* - For symbols not found in mapping.json, keeps the import and adds a warning comment.
|
|
10
|
+
* - Combines multiple imports that resolve to the same target package into a single import declaration.
|
|
11
|
+
* - Preserves comments and pragmas.
|
|
12
|
+
*
|
|
13
|
+
* The mapping.json is expected to be a flat object:
|
|
14
|
+
* {
|
|
15
|
+
* "SymbolName": "@beinformed/new-package-path",
|
|
16
|
+
* ...
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
declare function transformer(fileInfo: {
|
|
20
|
+
path: string;
|
|
21
|
+
source: string;
|
|
22
|
+
}, api: {
|
|
23
|
+
jscodeshift: JSCodeshift;
|
|
24
|
+
}, options?: unknown): string;
|
|
25
|
+
|
|
26
|
+
export { transformer as default };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__dirname
|
|
3
|
+
} from "../chunk-VJQ72WQS.js";
|
|
4
|
+
|
|
5
|
+
// src/transforms/migrate-imports.ts
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
8
|
+
var mappingPath = path.join(__dirname, "..", "static", "mapping.json");
|
|
9
|
+
var rawMapping = JSON.parse(fs.readFileSync(mappingPath, "utf8"));
|
|
10
|
+
var symbolMappings = rawMapping || {};
|
|
11
|
+
var renames = {};
|
|
12
|
+
function transformer(fileInfo, api, options) {
|
|
13
|
+
const isFlow = fileInfo.source.includes("@flow") || fileInfo.path.endsWith(".js");
|
|
14
|
+
const j = api.jscodeshift.withParser(isFlow ? "flow" : "tsx");
|
|
15
|
+
const root = j(fileInfo.source);
|
|
16
|
+
root.find(j.ImportDeclaration).forEach((pathNode) => {
|
|
17
|
+
const node = pathNode.node;
|
|
18
|
+
const source = node.source.value;
|
|
19
|
+
if (typeof source !== "string") {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const targetModules = /* @__PURE__ */ new Set();
|
|
23
|
+
const originalModule = source;
|
|
24
|
+
const getTargetModuleForSymbol = (symbolName) => {
|
|
25
|
+
if (symbolName in symbolMappings) {
|
|
26
|
+
return symbolMappings[symbolName];
|
|
27
|
+
}
|
|
28
|
+
return originalModule;
|
|
29
|
+
};
|
|
30
|
+
const isOldModule = source.startsWith("@beinformed/ui") || source.startsWith("@beinformed/react-");
|
|
31
|
+
if (!isOldModule) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!node.specifiers || node.specifiers.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
node.specifiers.forEach((spec) => {
|
|
38
|
+
let importedName;
|
|
39
|
+
if (spec.type === "ImportDefaultSpecifier") {
|
|
40
|
+
importedName = "default";
|
|
41
|
+
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
42
|
+
importedName = "*";
|
|
43
|
+
} else if (spec.type === "ImportSpecifier") {
|
|
44
|
+
importedName = spec.imported.name ?? spec.imported.value ?? null;
|
|
45
|
+
} else {
|
|
46
|
+
importedName = null;
|
|
47
|
+
}
|
|
48
|
+
const targetModule = importedName == null ? getTargetModuleForSymbol(originalModule) : getTargetModuleForSymbol(importedName);
|
|
49
|
+
targetModules.add(targetModule);
|
|
50
|
+
});
|
|
51
|
+
const newImports = Array.from(targetModules).map((module) => {
|
|
52
|
+
const specifiers = (node.specifiers || []).filter((spec) => {
|
|
53
|
+
let specTarget;
|
|
54
|
+
if (spec.type === "ImportDefaultSpecifier") {
|
|
55
|
+
specTarget = getTargetModuleForSymbol("default");
|
|
56
|
+
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
57
|
+
specTarget = getTargetModuleForSymbol("*");
|
|
58
|
+
} else if (spec.type === "ImportSpecifier") {
|
|
59
|
+
specTarget = getTargetModuleForSymbol(
|
|
60
|
+
spec.imported.name || ""
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
specTarget = getTargetModuleForSymbol(originalModule);
|
|
64
|
+
}
|
|
65
|
+
return specTarget === module;
|
|
66
|
+
}).map((spec) => {
|
|
67
|
+
const clonedSpec = { ...spec };
|
|
68
|
+
if (clonedSpec.type === "ImportSpecifier") {
|
|
69
|
+
const currentImportedName = clonedSpec.imported.name;
|
|
70
|
+
if (currentImportedName && renames[currentImportedName]) {
|
|
71
|
+
const newName = renames[currentImportedName];
|
|
72
|
+
clonedSpec.imported = {
|
|
73
|
+
...clonedSpec.imported,
|
|
74
|
+
name: newName
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
+
};
|
|
77
|
+
if (!clonedSpec.local || clonedSpec.local.name === currentImportedName) {
|
|
78
|
+
clonedSpec.local = {
|
|
79
|
+
...clonedSpec.local,
|
|
80
|
+
name: newName
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (node.importKind && !clonedSpec.importKind) {
|
|
87
|
+
clonedSpec.importKind = node.importKind;
|
|
88
|
+
}
|
|
89
|
+
return clonedSpec;
|
|
90
|
+
});
|
|
91
|
+
const newImport = j.importDeclaration(specifiers, j.literal(module));
|
|
92
|
+
const firstKind = specifiers[0]?.importKind;
|
|
93
|
+
if (firstKind && specifiers.every(
|
|
94
|
+
(s) => s.importKind === firstKind
|
|
95
|
+
)) {
|
|
96
|
+
newImport.importKind = firstKind;
|
|
97
|
+
specifiers.forEach((s) => {
|
|
98
|
+
delete s.importKind;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return newImport;
|
|
102
|
+
});
|
|
103
|
+
if (node.comments && node.comments.length > 0) {
|
|
104
|
+
newImports[0].comments = node.comments;
|
|
105
|
+
}
|
|
106
|
+
j(pathNode).replaceWith(newImports);
|
|
107
|
+
newImports.forEach((newImport) => {
|
|
108
|
+
const module = newImport.source.value;
|
|
109
|
+
if (typeof module === "string") {
|
|
110
|
+
const isUnknown = (module.startsWith("@beinformed/ui") || module.startsWith("@beinformed/react-")) && !Object.values(symbolMappings).includes(module);
|
|
111
|
+
if (isUnknown) {
|
|
112
|
+
const todoComment = j.commentLine(
|
|
113
|
+
" TODO: Could not find mapping for this import. Please fix manually.",
|
|
114
|
+
true,
|
|
115
|
+
false
|
|
116
|
+
);
|
|
117
|
+
newImport.comments = [...newImport.comments || [], todoComment];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
const mergedImports = /* @__PURE__ */ new Map();
|
|
123
|
+
const firstOccurrence = /* @__PURE__ */ new Map();
|
|
124
|
+
const allComments = /* @__PURE__ */ new Map();
|
|
125
|
+
root.find(j.ImportDeclaration).forEach((pathNode) => {
|
|
126
|
+
const node = pathNode.node;
|
|
127
|
+
const module = node.source.value;
|
|
128
|
+
if (typeof module !== "string") {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (!mergedImports.has(module)) {
|
|
132
|
+
mergedImports.set(module, []);
|
|
133
|
+
firstOccurrence.set(module, pathNode);
|
|
134
|
+
allComments.set(module, []);
|
|
135
|
+
}
|
|
136
|
+
if (node.comments) {
|
|
137
|
+
allComments.get(module).push(...node.comments);
|
|
138
|
+
}
|
|
139
|
+
if (node.specifiers) {
|
|
140
|
+
mergedImports.get(module).push(...node.specifiers);
|
|
141
|
+
}
|
|
142
|
+
if (firstOccurrence.get(module) !== pathNode) {
|
|
143
|
+
j(pathNode).remove();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
mergedImports.forEach((specifiers, module) => {
|
|
147
|
+
const pathNode = firstOccurrence.get(module);
|
|
148
|
+
if (!pathNode) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const node = pathNode.node;
|
|
152
|
+
const uniqueSpecifiers = [];
|
|
153
|
+
const seenLocalNames = /* @__PURE__ */ new Set();
|
|
154
|
+
specifiers.forEach((spec) => {
|
|
155
|
+
const localName = spec.local?.name;
|
|
156
|
+
if (localName && !seenLocalNames.has(localName)) {
|
|
157
|
+
uniqueSpecifiers.push(spec);
|
|
158
|
+
seenLocalNames.add(localName);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
node.specifiers = uniqueSpecifiers;
|
|
162
|
+
if (allComments.has(module) && allComments.get(module).length > 0) {
|
|
163
|
+
const uniqueComments = [];
|
|
164
|
+
const seenComments = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const comment of allComments.get(module)) {
|
|
166
|
+
const key = `${comment.type}:${comment.value}:${comment.leading}`;
|
|
167
|
+
if (!seenComments.has(key)) {
|
|
168
|
+
uniqueComments.push(comment);
|
|
169
|
+
seenComments.add(key);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
node.comments = uniqueComments;
|
|
173
|
+
}
|
|
174
|
+
const allSpecifiersHaveSameKind = uniqueSpecifiers.length > 0 && uniqueSpecifiers.every(
|
|
175
|
+
(s) => s.importKind === uniqueSpecifiers[0].importKind
|
|
176
|
+
);
|
|
177
|
+
if (allSpecifiersHaveSameKind && uniqueSpecifiers[0].importKind) {
|
|
178
|
+
node.importKind = uniqueSpecifiers[0].importKind;
|
|
179
|
+
uniqueSpecifiers.forEach((s) => {
|
|
180
|
+
delete s.importKind;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
return root.toSource(options || { quote: "double" });
|
|
185
|
+
}
|
|
186
|
+
export {
|
|
187
|
+
transformer as default
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=migrate-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transforms/migrate-imports.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport type {\n ASTPath,\n CommentBlock,\n CommentLine,\n ImportDeclaration,\n ImportDefaultSpecifier,\n ImportNamespaceSpecifier,\n ImportSpecifier,\n JSCodeshift,\n} from \"jscodeshift\";\n\ntype Comment = CommentLine | CommentBlock;\n\ntype ExtendedImportSpecifier = (\n | ImportSpecifier\n | ImportDefaultSpecifier\n | ImportNamespaceSpecifier\n) & {\n importKind?: \"value\" | \"type\" | \"typeof\" | null;\n};\n\n// Load mapping.json once for all files\nconst mappingPath = path.join(__dirname, \"..\", \"static\", \"mapping.json\");\nconst rawMapping = JSON.parse(fs.readFileSync(mappingPath, \"utf8\")) as Record<\n string,\n string\n>;\n\nconst symbolMappings: Record<string, string> = rawMapping || {};\nconst renames: Record<string, string> = {};\n\n/**\n * jscodeshift transform to migrate imports from the old\n * '@beinformed/ui/*' structure to the new '@beinformed/...' packages.\n *\n * - Detects whether to use Flow or TSX parser based on the file extension (.js) or the presence of @flow pragma.\n * - Uses the mapping.json file to determine the new package for each imported symbol.\n * - For symbols not found in mapping.json, keeps the import and adds a warning comment.\n * - Combines multiple imports that resolve to the same target package into a single import declaration.\n * - Preserves comments and pragmas.\n *\n * The mapping.json is expected to be a flat object:\n * {\n * \"SymbolName\": \"@beinformed/new-package-path\",\n * ...\n * }\n */\nexport default function transformer(\n fileInfo: { path: string; source: string },\n api: { jscodeshift: JSCodeshift },\n options?: unknown,\n): string {\n const isFlow =\n fileInfo.source.includes(\"@flow\") || fileInfo.path.endsWith(\".js\");\n const j = api.jscodeshift.withParser(isFlow ? \"flow\" : \"tsx\");\n const root = j(fileInfo.source);\n\n root.find(j.ImportDeclaration).forEach((pathNode) => {\n const node = pathNode.node;\n const source: unknown = node.source.value;\n\n if (typeof source !== \"string\") {\n return;\n }\n\n // Determine target modules for this declaration\n const targetModules = new Set<string>();\n const originalModule = source;\n\n // Helper: find target module for a given imported symbol\n const getTargetModuleForSymbol = (symbolName: string): string => {\n if (symbolName in symbolMappings) {\n return symbolMappings[symbolName];\n }\n return originalModule;\n };\n\n const isOldModule =\n source.startsWith(\"@beinformed/ui\") ||\n source.startsWith(\"@beinformed/react-\");\n\n if (!isOldModule) {\n return;\n }\n\n if (!node.specifiers || node.specifiers.length === 0) {\n return;\n }\n\n node.specifiers.forEach((spec) => {\n let importedName: string | null;\n if (spec.type === \"ImportDefaultSpecifier\") {\n importedName = \"default\";\n } else if (spec.type === \"ImportNamespaceSpecifier\") {\n importedName = \"*\";\n } else if (spec.type === \"ImportSpecifier\") {\n importedName =\n (spec.imported as { name?: string }).name ??\n (spec.imported as { value?: string }).value ??\n null;\n } else {\n importedName = null;\n }\n\n const targetModule =\n importedName == null\n ? getTargetModuleForSymbol(originalModule)\n : getTargetModuleForSymbol(importedName);\n targetModules.add(targetModule);\n });\n\n const newImports = Array.from(targetModules).map((module) => {\n const specifiers = (node.specifiers || [])\n .filter((spec) => {\n let specTarget: string;\n if (spec.type === \"ImportDefaultSpecifier\") {\n specTarget = getTargetModuleForSymbol(\"default\");\n } else if (spec.type === \"ImportNamespaceSpecifier\") {\n specTarget = getTargetModuleForSymbol(\"*\");\n } else if (spec.type === \"ImportSpecifier\") {\n specTarget = getTargetModuleForSymbol(\n (spec.imported as { name?: string }).name || \"\",\n );\n } else {\n specTarget = getTargetModuleForSymbol(originalModule);\n }\n return specTarget === module;\n })\n .map((spec) => {\n const clonedSpec: ExtendedImportSpecifier = { ...spec };\n if (clonedSpec.type === \"ImportSpecifier\") {\n const currentImportedName = (\n clonedSpec.imported as { name?: string }\n ).name;\n if (currentImportedName && renames[currentImportedName]) {\n const newName = renames[currentImportedName];\n clonedSpec.imported = {\n ...clonedSpec.imported,\n name: newName,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n if (\n !clonedSpec.local ||\n (clonedSpec.local as { name?: string }).name ===\n currentImportedName\n ) {\n clonedSpec.local = {\n ...clonedSpec.local,\n name: newName,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any;\n }\n }\n }\n\n if (node.importKind && !clonedSpec.importKind) {\n clonedSpec.importKind = node.importKind;\n }\n\n return clonedSpec;\n });\n\n const newImport = j.importDeclaration(specifiers, j.literal(module));\n\n const firstKind = (specifiers[0] as ExtendedImportSpecifier)?.importKind;\n if (\n firstKind &&\n specifiers.every(\n (s: ExtendedImportSpecifier) => s.importKind === firstKind,\n )\n ) {\n newImport.importKind = firstKind;\n specifiers.forEach((s: ExtendedImportSpecifier) => {\n delete s.importKind;\n });\n }\n\n return newImport;\n });\n\n // Assign comments to the first new import\n if (node.comments && node.comments.length > 0) {\n newImports[0].comments = node.comments;\n }\n\n j(pathNode).replaceWith(newImports);\n\n // Add TODO comments for unknown symbols\n newImports.forEach((newImport) => {\n const module = newImport.source.value;\n if (typeof module === \"string\") {\n const isUnknown =\n (module.startsWith(\"@beinformed/ui\") ||\n module.startsWith(\"@beinformed/react-\")) &&\n !Object.values(symbolMappings).includes(module);\n\n if (isUnknown) {\n const todoComment = j.commentLine(\n \" TODO: Could not find mapping for this import. Please fix manually.\",\n true,\n false,\n );\n newImport.comments = [...(newImport.comments || []), todoComment];\n }\n }\n });\n });\n\n // Second pass: Merge imports with the same path\n const mergedImports = new Map<string, ExtendedImportSpecifier[]>();\n const firstOccurrence = new Map<string, ASTPath<ImportDeclaration>>();\n const allComments = new Map<string, Comment[]>();\n\n root.find(j.ImportDeclaration).forEach((pathNode) => {\n const node = pathNode.node;\n const module = node.source.value;\n\n if (typeof module !== \"string\") {\n return;\n }\n\n if (!mergedImports.has(module)) {\n mergedImports.set(module, []);\n firstOccurrence.set(module, pathNode);\n allComments.set(module, []);\n }\n\n if (node.comments) {\n allComments.get(module)!.push(...(node.comments as Comment[]));\n }\n\n if (node.specifiers) {\n mergedImports\n .get(module)!\n .push(...(node.specifiers as ExtendedImportSpecifier[]));\n }\n\n if (firstOccurrence.get(module) !== pathNode) {\n j(pathNode).remove();\n }\n });\n\n mergedImports.forEach((specifiers, module) => {\n const pathNode = firstOccurrence.get(module);\n if (!pathNode) {\n return;\n }\n const node = pathNode.node;\n\n const uniqueSpecifiers: ExtendedImportSpecifier[] = [];\n const seenLocalNames = new Set<string>();\n specifiers.forEach((spec) => {\n const localName = (spec.local as { name?: string })?.name;\n if (localName && !seenLocalNames.has(localName)) {\n uniqueSpecifiers.push(spec);\n seenLocalNames.add(localName);\n }\n });\n\n node.specifiers = uniqueSpecifiers;\n\n if (allComments.has(module) && allComments.get(module)!.length > 0) {\n // De-duplicate comments if they were merged multiple times\n const uniqueComments: Comment[] = [];\n const seenComments = new Set();\n for (const comment of allComments.get(module)!) {\n const key = `${comment.type}:${comment.value}:${comment.leading}`;\n if (!seenComments.has(key)) {\n uniqueComments.push(comment);\n seenComments.add(key);\n }\n }\n node.comments = uniqueComments;\n }\n\n // Restore declaration-level importKind if all specifiers have it,\n // OR if it was already set (e.g. from splitting)\n const allSpecifiersHaveSameKind =\n uniqueSpecifiers.length > 0 &&\n uniqueSpecifiers.every(\n (s) => s.importKind === uniqueSpecifiers[0].importKind,\n );\n\n if (allSpecifiersHaveSameKind && uniqueSpecifiers[0].importKind) {\n node.importKind = uniqueSpecifiers[0].importKind;\n uniqueSpecifiers.forEach((s) => {\n delete s.importKind;\n });\n }\n });\n\n return root.toSource(options || { quote: \"double\" });\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EAAE;AACtC,uBAAiB,QAAQ,CAAC,MAAM;AAC9B,eAAO,EAAE;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAED,SAAO,KAAK,SAAS,WAAW,EAAE,OAAO,SAAS,CAAC;AACrD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@beinformed/codemod",
|
|
3
|
+
"version": "0.1.1-beta.0",
|
|
4
|
+
"description": "Be Informed UI Codemods",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"beinformed-codemod": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"usage.md",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"globby": "^16.1.0",
|
|
16
|
+
"jscodeshift": "^17.3.0",
|
|
17
|
+
"yargs": "^18.0.0",
|
|
18
|
+
"@beinformed/ui": "2.0.0-beta.1"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/jscodeshift": "^17.3.0",
|
|
22
|
+
"@types/node": "^25.2.1",
|
|
23
|
+
"@types/yargs": "^17.0.35",
|
|
24
|
+
"tsup": "^8.5.1",
|
|
25
|
+
"@beinformed/typescript-config": "0.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"dev": "tsup --watch",
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"clean:build": "rimraf ./dist",
|
|
31
|
+
"lint": "eslint .",
|
|
32
|
+
"lint:ci": "eslint . --ext .ts,.tsx --format junit -o ./reports/eslint-report-codemod.xml",
|
|
33
|
+
"lint:fix": "pnpm lint --fix",
|
|
34
|
+
"prettier": "prettier --write .",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:ci": "vitest run --reporter=junit --outputFile=./reports/vitest-report-codemod.xml",
|
|
37
|
+
"typecheck": "tsc --noEmit"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/usage.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Be Informed Codemod Usage
|
|
2
|
+
|
|
3
|
+
This package provides codemods to help migrate Be Informed UI code to newer versions.
|
|
4
|
+
|
|
5
|
+
## Running with npx
|
|
6
|
+
|
|
7
|
+
You can run the codemod directly using `npx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @beinformed/codemod ./src
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Options
|
|
14
|
+
|
|
15
|
+
- `--dry`, `-d`: Dry run. Shows what changes would be made without actually modifying files.
|
|
16
|
+
- `--print`, `-p`: Prints the transformed code to the console.
|
|
17
|
+
- `--help`, `-h`: Show help information.
|
|
18
|
+
|
|
19
|
+
## Available Transforms
|
|
20
|
+
|
|
21
|
+
### `migrate-imports`
|
|
22
|
+
|
|
23
|
+
This is the default transform. It migrates imports from old `@beinformed/ui/*` and `@beinformed/react-*` packages to the new unified package structure.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx @beinformed/codemod ./src
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Manual Installation
|
|
32
|
+
|
|
33
|
+
If you prefer to install it globally or as a dev dependency:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Global
|
|
37
|
+
npm install -g @beinformed/codemod
|
|
38
|
+
beinformed-codemod ./src
|
|
39
|
+
|
|
40
|
+
# Dev dependency
|
|
41
|
+
npm install --save-dev @beinformed/codemod
|
|
42
|
+
npx beinformed-codemod ./src
|
|
43
|
+
```
|