styled-components-to-stylex-codemod 0.0.43 → 0.0.44

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/index.d.mts CHANGED
@@ -91,6 +91,14 @@ interface RunTransformOptions {
91
91
  * @default false
92
92
  */
93
93
  allowPartialMigration?: boolean;
94
+ /**
95
+ * Also collect per-file outcomes as if each file were transformed by itself,
96
+ * while reusing the same prepass. Useful for candidate finders that recommend
97
+ * files to run individually.
98
+ *
99
+ * @default false
100
+ */
101
+ collectStandaloneFileResults?: boolean;
94
102
  }
95
103
  interface RunTransformResult {
96
104
  /** Number of files that had errors */
@@ -105,6 +113,10 @@ interface RunTransformResult {
105
113
  timeElapsed: number;
106
114
  /** Warnings emitted during transformation */
107
115
  warnings: CollectedWarning[];
116
+ /** Per-file outcomes from isolated transforms, populated when requested. */
117
+ standaloneFileResults?: TransformFileResult[];
118
+ /** Warnings from isolated transforms, populated when requested. */
119
+ standaloneWarnings?: CollectedWarning[];
108
120
  }
109
121
  /**
110
122
  * Run the styled-components to StyleX transform on files matching the glob pattern.
@@ -133,5 +145,9 @@ interface RunTransformResult {
133
145
  * ```
134
146
  */
135
147
  declare function runTransform(options: RunTransformOptions): Promise<RunTransformResult>;
148
+ type TransformFileResult = {
149
+ filePath: string;
150
+ status: "error" | "skipped" | "unchanged" | "transformed";
151
+ };
136
152
  //#endregion
137
153
  export { type AdapterInput, type ImportSource, type MarkerFileContext, defineAdapter, runTransform };
package/dist/index.mjs CHANGED
@@ -317,6 +317,29 @@ async function runTransform(options) {
317
317
  runInBand: true,
318
318
  silent: options.silent ?? false
319
319
  };
320
+ let standaloneResult;
321
+ let standaloneWarnings;
322
+ if (options.collectStandaloneFileResults === true) {
323
+ standaloneResult = await runTransformSequentially(transformModule, filePaths, {
324
+ ...runnerOptions,
325
+ dry: true,
326
+ print: false,
327
+ sidecarFiles: /* @__PURE__ */ new Map(),
328
+ bridgeResults: /* @__PURE__ */ new Map(),
329
+ transformedFiles: /* @__PURE__ */ new Set(),
330
+ transformedFileSources: /* @__PURE__ */ new Map(),
331
+ transientPropRenames: /* @__PURE__ */ new Map(),
332
+ crossFilePrepassResult: {
333
+ ...crossFilePrepassResult,
334
+ transformedFiles: /* @__PURE__ */ new Set()
335
+ },
336
+ silent: true,
337
+ isolateFiles: true
338
+ });
339
+ standaloneWarnings = Logger.createReport().getWarnings();
340
+ Logger._clearCollected();
341
+ Logger.setFileCount(filePaths.length);
342
+ }
320
343
  const result = await runTransformSequentially(transformModule, filePaths, runnerOptions);
321
344
  if (sidecarFiles.size > 0 && !dryRun) for (const [sidecarPath, content] of sidecarFiles) await writeFile(sidecarPath, mergeSidecarContent(sidecarPath, content), "utf-8");
322
345
  if (bridgeResults.size > 0 && !dryRun) {
@@ -368,7 +391,9 @@ async function runTransform(options) {
368
391
  skipped: result.skip,
369
392
  transformed: result.ok,
370
393
  timeElapsed: parseFloat(result.timeElapsed) || 0,
371
- warnings: report.getWarnings()
394
+ warnings: report.getWarnings(),
395
+ standaloneFileResults: standaloneResult?.files,
396
+ standaloneWarnings
372
397
  };
373
398
  }
374
399
  function createAutoPrepassFailureError(err, consumerPatterns, parser) {
@@ -457,7 +482,8 @@ async function runTransformSequentially(transformModule, filePaths, options) {
457
482
  nochange: 0,
458
483
  skip: 0,
459
484
  ok: 0,
460
- timeElapsed: "0"
485
+ timeElapsed: "0",
486
+ files: []
461
487
  };
462
488
  const startedAt = performance.now();
463
489
  const j = jscodeshift.withParser(options.parser);
@@ -470,12 +496,21 @@ async function runTransformSequentially(transformModule, filePaths, options) {
470
496
  }
471
497
  };
472
498
  for (const filePath of filePaths) {
499
+ if (options.isolateFiles === true) {
500
+ options.transformedFiles.clear();
501
+ options.transformedFileSources.clear();
502
+ options.crossFilePrepassResult?.transformedFiles?.clear();
503
+ }
473
504
  let source;
474
505
  try {
475
506
  source = await readFile(filePath, "utf-8");
476
507
  } catch (err) {
477
508
  Logger.logError(`File error: ${err instanceof Error ? err.message : String(err)}`, filePath);
478
509
  aggregate.error += 1;
510
+ aggregate.files.push({
511
+ filePath,
512
+ status: "error"
513
+ });
479
514
  continue;
480
515
  }
481
516
  try {
@@ -486,18 +521,34 @@ async function runTransformSequentially(transformModule, filePaths, options) {
486
521
  if (output !== null) options.transformedFileSources.set(toRealPath(filePath), output);
487
522
  if (output === null) {
488
523
  aggregate.skip += 1;
524
+ aggregate.files.push({
525
+ filePath,
526
+ status: "skipped"
527
+ });
489
528
  continue;
490
529
  }
491
530
  if (output === source) {
492
531
  aggregate.nochange += 1;
532
+ aggregate.files.push({
533
+ filePath,
534
+ status: "unchanged"
535
+ });
493
536
  continue;
494
537
  }
495
538
  if (options.print) process.stdout.write(`${output}\n`);
496
539
  if (!options.dry) await writeFile(filePath, output, "utf-8");
497
540
  aggregate.ok += 1;
541
+ aggregate.files.push({
542
+ filePath,
543
+ status: "transformed"
544
+ });
498
545
  } catch (err) {
499
546
  if (!Logger.isErrorLogged(err)) Logger.logError(`Transformation error: ${err instanceof Error ? err.message : String(err)}`, filePath);
500
547
  aggregate.error += 1;
548
+ aggregate.files.push({
549
+ filePath,
550
+ status: "error"
551
+ });
501
552
  }
502
553
  }
503
554
  aggregate.timeElapsed = ((performance.now() - startedAt) / 1e3).toFixed(3);
@@ -13365,7 +13365,7 @@ function emitStylesAndImports(ctx) {
13365
13365
  {
13366
13366
  const toModuleSpecifier = (from) => {
13367
13367
  assertValidImportSource(from, "import");
13368
- return importSourceToModuleSpecifier(from, String(filePath));
13368
+ return importSourceToModuleSpecifier(from, String(filePath), { stripTsExtension: true });
13369
13369
  };
13370
13370
  const insertImportDecl = (decl) => {
13371
13371
  insertImportDeclarationNearStylex(root, decl);
@@ -36681,7 +36681,7 @@ function collectNewImportMetadata(resolverImports, filePath) {
36681
36681
  const newImportLocalNames = /* @__PURE__ */ new Set();
36682
36682
  const newImportSourcesByLocal = /* @__PURE__ */ new Map();
36683
36683
  for (const imp of resolverImports.values()) {
36684
- const source = importSourceToModuleSpecifier(imp.from, filePath);
36684
+ const source = importSourceToModuleSpecifier(imp.from, filePath, { stripTsExtension: true });
36685
36685
  for (const n of imp.names ?? []) {
36686
36686
  const local = n.local ?? n.imported;
36687
36687
  if (local) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-components-to-stylex-codemod",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "description": "Codemod to transform styled-components to StyleX",
5
5
  "keywords": [
6
6
  "codemod",