@beinformed/codemod 0.1.1-beta.0 → 1.0.0-beta.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/cli.js CHANGED
@@ -1,17 +1,43 @@
1
1
  #!/usr/bin/env node
2
- import "./chunk-VJQ72WQS.js";
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js
27
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
28
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
3
29
 
4
30
  // src/cli.ts
5
- import fs from "fs";
6
- import path from "path";
7
- import { fileURLToPath } from "url";
8
- import { run } from "jscodeshift/src/Runner";
9
- import yargs from "yargs";
10
- import { hideBin } from "yargs/helpers";
11
- var __filename = fileURLToPath(import.meta.url);
12
- var __dirname = path.dirname(__filename);
31
+ var import_node_fs = __toESM(require("fs"));
32
+ var import_node_path = __toESM(require("path"));
33
+ var import_node_url = require("url");
34
+ var import_Runner = require("jscodeshift/src/Runner");
35
+ var import_yargs = __toESM(require("yargs"));
36
+ var import_helpers = require("yargs/helpers");
37
+ var __filename2 = (0, import_node_url.fileURLToPath)(importMetaUrl);
38
+ var __dirname = import_node_path.default.dirname(__filename2);
13
39
  async function main() {
14
- const argv = await yargs(hideBin(process.argv)).usage("Usage: $0 [options] <path>").option("dry", {
40
+ const argv = await (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).usage("Usage: $0 [options] <path>").option("dry", {
15
41
  alias: "d",
16
42
  type: "boolean",
17
43
  description: "Dry run (no changes made)",
@@ -27,11 +53,11 @@ async function main() {
27
53
  console.error("Please provide a path to run the codemod on.");
28
54
  process.exit(1);
29
55
  }
30
- const transformPath = path.resolve(
56
+ const transformPath = import_node_path.default.resolve(
31
57
  __dirname,
32
58
  "./transforms/migrate-imports.js"
33
59
  );
34
- if (!fs.existsSync(transformPath)) {
60
+ if (!import_node_fs.default.existsSync(transformPath)) {
35
61
  console.error(`Transform not found at ${transformPath}`);
36
62
  process.exit(1);
37
63
  }
@@ -43,11 +69,11 @@ async function main() {
43
69
  ignorePattern: "**/node_modules/**"
44
70
  };
45
71
  try {
46
- await run(transformPath, paths, options);
72
+ await (0, import_Runner.run)(transformPath, paths, options);
47
73
  } catch (error) {
48
74
  console.error("Codemod failed:", error);
49
75
  process.exit(1);
50
76
  }
51
77
  }
52
- await main();
78
+ main();
53
79
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { run } from \"jscodeshift/src/Runner\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nasync function main() {\n const argv = await yargs(hideBin(process.argv))\n .usage(\"Usage: $0 [options] <path>\")\n .option(\"dry\", {\n alias: \"d\",\n type: \"boolean\",\n description: \"Dry run (no changes made)\",\n default: false,\n })\n .option(\"print\", {\n alias: \"p\",\n type: \"boolean\",\n description: \"Print transformed files\",\n default: false,\n })\n .help()\n .alias(\"h\", \"help\")\n .parse();\n\n const paths = argv._ as string[];\n if (paths.length === 0) {\n console.error(\"Please provide a path to run the codemod on.\");\n process.exit(1);\n }\n\n const transformPath = path.resolve(\n __dirname,\n \"./transforms/migrate-imports.js\",\n );\n if (!fs.existsSync(transformPath)) {\n // Fallback for different build structures if necessary\n console.error(`Transform not found at ${transformPath}`);\n process.exit(1);\n }\n\n const options = {\n dry: argv.dry,\n print: argv.print,\n babel: true,\n extensions: \"js,ts,jsx,tsx\",\n ignorePattern: \"**/node_modules/**\",\n };\n\n try {\n await run(transformPath, paths, options);\n } catch (error) {\n console.error(\"Codemod failed:\", error);\n process.exit(1);\n }\n}\n\nawait main();\n"],"mappings":";;;;AACA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,SAAS,WAAW;AACpB,OAAO,WAAW;AAClB,SAAS,eAAe;AAExB,IAAM,aAAa,cAAc,YAAY,GAAG;AAChD,IAAM,YAAY,KAAK,QAAQ,UAAU;AAEzC,eAAe,OAAO;AACpB,QAAM,OAAO,MAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,EAC3C,MAAM,4BAA4B,EAClC,OAAO,OAAO;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS;AAAA,EACX,CAAC,EACA,OAAO,SAAS;AAAA,IACf,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS;AAAA,EACX,CAAC,EACA,KAAK,EACL,MAAM,KAAK,MAAM,EACjB,MAAM;AAET,QAAM,QAAQ,KAAK;AACnB,MAAI,MAAM,WAAW,GAAG;AACtB,YAAQ,MAAM,8CAA8C;AAC5D,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,gBAAgB,KAAK;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,GAAG,WAAW,aAAa,GAAG;AAEjC,YAAQ,MAAM,0BAA0B,aAAa,EAAE;AACvD,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,UAAU;AAAA,IACd,KAAK,KAAK;AAAA,IACV,OAAO,KAAK;AAAA,IACZ,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,EACjB;AAEA,MAAI;AACF,UAAM,IAAI,eAAe,OAAO,OAAO;AAAA,EACzC,SAAS,OAAO;AACd,YAAQ,MAAM,mBAAmB,KAAK;AACtC,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,MAAM,KAAK;","names":[]}
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.0/node_modules/tsup/assets/cjs_shims.js","../src/cli.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","#!/usr/bin/env node\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { run } from \"jscodeshift/src/Runner\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nasync function main() {\n const argv = await yargs(hideBin(process.argv))\n .usage(\"Usage: $0 [options] <path>\")\n .option(\"dry\", {\n alias: \"d\",\n type: \"boolean\",\n description: \"Dry run (no changes made)\",\n default: false,\n })\n .option(\"print\", {\n alias: \"p\",\n type: \"boolean\",\n description: \"Print transformed files\",\n default: false,\n })\n .help()\n .alias(\"h\", \"help\")\n .parse();\n\n const paths = argv._ as string[];\n if (paths.length === 0) {\n console.error(\"Please provide a path to run the codemod on.\");\n process.exit(1);\n }\n\n const transformPath = path.resolve(\n __dirname,\n \"./transforms/migrate-imports.js\",\n );\n if (!fs.existsSync(transformPath)) {\n // Fallback for different build structures if necessary\n console.error(`Transform not found at ${transformPath}`);\n process.exit(1);\n }\n\n const options = {\n dry: argv.dry,\n print: argv.print,\n babel: true,\n extensions: \"js,ts,jsx,tsx\",\n ignorePattern: \"**/node_modules/**\",\n };\n\n try {\n await run(transformPath, paths, options);\n } catch (error) {\n console.error(\"Codemod failed:\", error);\n process.exit(1);\n }\n}\n\nmain();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ACX9D,qBAAe;AACf,uBAAiB;AACjB,sBAA8B;AAE9B,oBAAoB;AACpB,mBAAkB;AAClB,qBAAwB;AAExB,IAAMA,kBAAa,+BAAc,aAAe;AAChD,IAAM,YAAY,iBAAAC,QAAK,QAAQD,WAAU;AAEzC,eAAe,OAAO;AACpB,QAAM,OAAO,UAAM,aAAAE,aAAM,wBAAQ,QAAQ,IAAI,CAAC,EAC3C,MAAM,4BAA4B,EAClC,OAAO,OAAO;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS;AAAA,EACX,CAAC,EACA,OAAO,SAAS;AAAA,IACf,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,SAAS;AAAA,EACX,CAAC,EACA,KAAK,EACL,MAAM,KAAK,MAAM,EACjB,MAAM;AAET,QAAM,QAAQ,KAAK;AACnB,MAAI,MAAM,WAAW,GAAG;AACtB,YAAQ,MAAM,8CAA8C;AAC5D,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,gBAAgB,iBAAAD,QAAK;AAAA,IACzB;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,eAAAE,QAAG,WAAW,aAAa,GAAG;AAEjC,YAAQ,MAAM,0BAA0B,aAAa,EAAE;AACvD,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,UAAU;AAAA,IACd,KAAK,KAAK;AAAA,IACV,OAAO,KAAK;AAAA,IACZ,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,EACjB;AAEA,MAAI;AACF,cAAM,mBAAI,eAAe,OAAO,OAAO;AAAA,EACzC,SAAS,OAAO;AACd,YAAQ,MAAM,mBAAmB,KAAK;AACtC,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,KAAK;","names":["__filename","path","yargs","fs"]}
@@ -1,12 +1,42 @@
1
- import {
2
- __dirname
3
- } from "../chunk-VJQ72WQS.js";
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);
4
29
 
5
30
  // 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"));
31
+ var migrate_imports_exports = {};
32
+ __export(migrate_imports_exports, {
33
+ default: () => transformer
34
+ });
35
+ module.exports = __toCommonJS(migrate_imports_exports);
36
+ var import_node_fs = __toESM(require("fs"));
37
+ var import_node_path = __toESM(require("path"));
38
+ var mappingPath = import_node_path.default.join(__dirname, "..", "static", "mapping.json");
39
+ var rawMapping = JSON.parse(import_node_fs.default.readFileSync(mappingPath, "utf8"));
10
40
  var symbolMappings = rawMapping || {};
11
41
  var renames = {};
12
42
  function transformer(fileInfo, api, options) {
@@ -48,7 +78,7 @@ function transformer(fileInfo, api, options) {
48
78
  const targetModule = importedName == null ? getTargetModuleForSymbol(originalModule) : getTargetModuleForSymbol(importedName);
49
79
  targetModules.add(targetModule);
50
80
  });
51
- const newImports = Array.from(targetModules).map((module) => {
81
+ const newImports = Array.from(targetModules).map((module2) => {
52
82
  const specifiers = (node.specifiers || []).filter((spec) => {
53
83
  let specTarget;
54
84
  if (spec.type === "ImportDefaultSpecifier") {
@@ -62,7 +92,7 @@ function transformer(fileInfo, api, options) {
62
92
  } else {
63
93
  specTarget = getTargetModuleForSymbol(originalModule);
64
94
  }
65
- return specTarget === module;
95
+ return specTarget === module2;
66
96
  }).map((spec) => {
67
97
  const clonedSpec = { ...spec };
68
98
  if (clonedSpec.type === "ImportSpecifier") {
@@ -88,7 +118,7 @@ function transformer(fileInfo, api, options) {
88
118
  }
89
119
  return clonedSpec;
90
120
  });
91
- const newImport = j.importDeclaration(specifiers, j.literal(module));
121
+ const newImport = j.importDeclaration(specifiers, j.literal(module2));
92
122
  const firstKind = specifiers[0]?.importKind;
93
123
  if (firstKind && specifiers.every(
94
124
  (s) => s.importKind === firstKind
@@ -105,9 +135,9 @@ function transformer(fileInfo, api, options) {
105
135
  }
106
136
  j(pathNode).replaceWith(newImports);
107
137
  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);
138
+ const module2 = newImport.source.value;
139
+ if (typeof module2 === "string") {
140
+ const isUnknown = (module2.startsWith("@beinformed/ui") || module2.startsWith("@beinformed/react-")) && !Object.values(symbolMappings).includes(module2);
111
141
  if (isUnknown) {
112
142
  const todoComment = j.commentLine(
113
143
  " TODO: Could not find mapping for this import. Please fix manually.",
@@ -124,27 +154,27 @@ function transformer(fileInfo, api, options) {
124
154
  const allComments = /* @__PURE__ */ new Map();
125
155
  root.find(j.ImportDeclaration).forEach((pathNode) => {
126
156
  const node = pathNode.node;
127
- const module = node.source.value;
128
- if (typeof module !== "string") {
157
+ const module2 = node.source.value;
158
+ if (typeof module2 !== "string") {
129
159
  return;
130
160
  }
131
- if (!mergedImports.has(module)) {
132
- mergedImports.set(module, []);
133
- firstOccurrence.set(module, pathNode);
134
- allComments.set(module, []);
161
+ if (!mergedImports.has(module2)) {
162
+ mergedImports.set(module2, []);
163
+ firstOccurrence.set(module2, pathNode);
164
+ allComments.set(module2, []);
135
165
  }
136
166
  if (node.comments) {
137
- allComments.get(module).push(...node.comments);
167
+ allComments.get(module2).push(...node.comments);
138
168
  }
139
169
  if (node.specifiers) {
140
- mergedImports.get(module).push(...node.specifiers);
170
+ mergedImports.get(module2).push(...node.specifiers);
141
171
  }
142
- if (firstOccurrence.get(module) !== pathNode) {
172
+ if (firstOccurrence.get(module2) !== pathNode) {
143
173
  j(pathNode).remove();
144
174
  }
145
175
  });
146
- mergedImports.forEach((specifiers, module) => {
147
- const pathNode = firstOccurrence.get(module);
176
+ mergedImports.forEach((specifiers, module2) => {
177
+ const pathNode = firstOccurrence.get(module2);
148
178
  if (!pathNode) {
149
179
  return;
150
180
  }
@@ -159,10 +189,10 @@ function transformer(fileInfo, api, options) {
159
189
  }
160
190
  });
161
191
  node.specifiers = uniqueSpecifiers;
162
- if (allComments.has(module) && allComments.get(module).length > 0) {
192
+ if (allComments.has(module2) && allComments.get(module2).length > 0) {
163
193
  const uniqueComments = [];
164
194
  const seenComments = /* @__PURE__ */ new Set();
165
- for (const comment of allComments.get(module)) {
195
+ for (const comment of allComments.get(module2)) {
166
196
  const key = `${comment.type}:${comment.value}:${comment.leading}`;
167
197
  if (!seenComments.has(key)) {
168
198
  uniqueComments.push(comment);
@@ -183,7 +213,4 @@ function transformer(fileInfo, api, options) {
183
213
  });
184
214
  return root.toSource(options || { quote: "double" });
185
215
  }
186
- export {
187
- transformer as default
188
- };
189
216
  //# sourceMappingURL=migrate-imports.js.map
@@ -1 +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\" });\n}\n"],"mappings":";;;;;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAwBjB,IAAM,cAAc,KAAK,KAAK,WAAW,MAAM,UAAU,cAAc;AACvE,IAAM,aAAa,KAAK,MAAM,GAAG,aAAa,aAAa,MAAM,CAAC;AAKlE,IAAM,iBAAyC,cAAc,CAAC;AAC9D,IAAM,UAAkC,CAAC;AAkB1B,SAAR,YACL,UACA,KACA,SACQ;AACR,QAAM,SACJ,SAAS,OAAO,SAAS,OAAO,KAAK,SAAS,KAAK,SAAS,KAAK;AACnE,QAAM,IAAI,IAAI,YAAY,WAAW,SAAS,SAAS,KAAK;AAC5D,QAAM,OAAO,EAAE,SAAS,MAAM;AAE9B,OAAK,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,aAAa;AACnD,UAAM,OAAO,SAAS;AACtB,UAAM,SAAkB,KAAK,OAAO;AAEpC,QAAI,O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I;AAC1B,uBAAe,IAAI,SAAS;AAAA,MAC9B;AAAA,IACF,CAAC;AAED,SAAK,aAAa;AAElB,QAAI,YAAY,IAAI,MAAM,KAAK,YAAY,IAAI,MAAM,EAAG,SAAS,GAAG;AAElE,YAAM,iBAA4B,CAAC;AACnC,YAAM,eAAe,oBAAI,IAAI;AAC7B,iBAAW,WAAW,YAAY,IAAI,MAAM,GAAI;AAC9C,cAAM,MAAM,GAAG,QAAQ,IAAI,IAAI,QAAQ,KAAK,IAAI,QAAQ,OAAO;AAC/D,YAAI,CAAC,aAAa,IAAI,GAAG,GAAG;AAC1B,yBAAe,KAAK,OAAO;AAC3B,uBAAa,IAAI,GAAG;AAAA,QACtB;AAAA,MACF;AACA,WAAK,WAAW;AAAA,IAClB;AAIA,UAAM,4BACJ,iBAAiB,SAAS,KAC1B,iBAAiB;AAAA,MACf,CAAC,MAAM,EAAE,eAAe,iBAAiB,CAAC,EAAE;AAAA,IAC9C;AAEF,QAAI,6BAA6B,iBAAiB,CAAC,EAAE,YAAY;AAC/D,WAAK,aAAa,iBAAiB,CAAC,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":[]}
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\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AAwBjB,IAAM,cAAc,iBAAAA,QAAK,KAAK,WAAW,MAAM,UAAU,cAAc;AACvE,IAAM,aAAa,KAAK,MAAM,eAAAC,QAAG,aAAa,aAAa,MAAM,CAAC;AAKlE,IAAM,iBAAyC,cAAc,CAAC;AAC9D,IAAM,UAAkC,CAAC;AAkB1B,SAAR,YACL,UACA,KACA,SACQ;AACR,QAAM,SACJ,SAAS,OAAO,SAAS,OAAO,KAAK,SAAS,KAAK,SAAS,KAAK;AACnE,QAAM,IAAI,IAAI,YAAY,WAAW,SAAS,SAAS,KAAK;AAC5D,QAAM,OAAO,EAAE,SAAS,MAAM;AAE9B,OAAK,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,aAAa;AACnD,UAAM,OAAO,SAAS;AACtB,UAAM,SAAkB,KAAK,OAAO;AAEpC,QAAI,OAAO,WAAW,UAAU;AAC9B;AAAA,IACF;AAGA,UAAM,gBAAgB,oBAAI,IAAY;AACtC,UAAM,iBAAiB;AAGvB,UAAM,2BAA2B,CAAC,eAA+B;AAC/D,UAAI,cAAc,g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,OAAM,EAAG,SAAS,GAAG;AAElE,YAAM,iBAA4B,CAAC;AACnC,YAAM,eAAe,oBAAI,IAAI;AAC7B,iBAAW,WAAW,YAAY,IAAIA,OAAM,GAAI;AAC9C,cAAM,MAAM,GAAG,QAAQ,IAAI,IAAI,QAAQ,KAAK,IAAI,QAAQ,OAAO;AAC/D,YAAI,CAAC,aAAa,IAAI,GAAG,GAAG;AAC1B,yBAAe,KAAK,OAAO;AAC3B,uBAAa,IAAI,GAAG;AAAA,QACtB;AAAA,MACF;AACA,WAAK,WAAW;AAAA,IAClB;AAIA,UAAM,4BACJ,iBAAiB,SAAS,KAC1B,iBAAiB;AAAA,MACf,CAAC,MAAM,EAAE,eAAe,iBAAiB,CAAC,EAAE;AAAA,IAC9C;AAEF,QAAI,6BAA6B,iBAAiB,CAAC,EAAE,YAAY;AAC/D,WAAK,aAAa,iBAAiB,CAAC,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":["path","fs","module"]}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@beinformed/codemod",
3
- "version": "0.1.1-beta.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "Be Informed UI Codemods",
5
- "type": "module",
6
5
  "bin": {
7
6
  "beinformed-codemod": "./dist/cli.js"
8
7
  },
@@ -1,11 +0,0 @@
1
- // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.0/node_modules/tsup/assets/esm_shims.js
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
- var getFilename = () => fileURLToPath(import.meta.url);
5
- var getDirname = () => path.dirname(getFilename());
6
- var __dirname = /* @__PURE__ */ getDirname();
7
-
8
- export {
9
- __dirname
10
- };
11
- //# sourceMappingURL=chunk-VJQ72WQS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.0/node_modules/tsup/assets/esm_shims.js"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n"],"mappings":";AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAE9B,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AACvD,IAAM,aAAa,MAAM,KAAK,QAAQ,YAAY,CAAC;AAE5C,IAAM,YAA4B,2BAAW;","names":[]}