styled-components-to-stylex-codemod 0.0.41 → 0.0.42
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/{bridge-consumer-patcher-31jI1854.mjs → bridge-consumer-patcher-DNsxze1l.mjs} +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.mjs +26 -11
- package/dist/{run-prepass-J4t6jkCI.mjs → run-prepass-COJ2IOPl.mjs} +50 -4
- package/dist/sx-surface-DBy6tOUv.mjs +490 -0
- package/dist/{transform-types-Bl-oPkjl.d.mts → transform-types-CQjiY4Yp.d.mts} +56 -0
- package/dist/transform.d.mts +1 -1
- package/dist/transform.mjs +898 -112
- package/dist/typescript-analysis-UWX_ePX0.mjs +619 -0
- package/dist/typescript-metadata-Dubr-x2i.mjs +49 -0
- package/package.json +4 -1
- package/dist/wrapped-component-interface-yvZ-_HMO.mjs +0 -880
- /package/dist/{forwarded-as-consumer-patcher-BYCrqzRm.mjs → forwarded-as-consumer-patcher-DoVqLOgw.mjs} +0 -0
- /package/dist/{prop-usage-D6ZiDfzz.mjs → prop-usage-B6z4WOPr.mjs} +0 -0
- /package/dist/{selector-context-heuristic-6_jSRGkZ.mjs → selector-context-heuristic-CGggN74M.mjs} +0 -0
- /package/dist/{transient-prop-consumer-patcher-DdIYPSFk.mjs → transient-prop-consumer-patcher-BX-LeC2B.mjs} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as toRealPath } from "./path-utils-BIpoL4Ue.mjs";
|
|
2
2
|
import { r as escapeRegex } from "./string-utils-DD9wdRHW.mjs";
|
|
3
|
-
import { t as isSelectorContext } from "./selector-context-heuristic-
|
|
3
|
+
import { t as isSelectorContext } from "./selector-context-heuristic-CGggN74M.mjs";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
//#region src/internal/bridge-consumer-patcher.ts
|
|
6
6
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CollectedWarning, c as MarkerFileContext, l as defineAdapter, n as TransformMode, o as AdapterInput, s as ImportSource } from "./transform-types-
|
|
1
|
+
import { a as CollectedWarning, c as MarkerFileContext, l as defineAdapter, n as TransformMode, o as AdapterInput, s as ImportSource } from "./transform-types-CQjiY4Yp.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/run.d.ts
|
|
4
4
|
interface RunTransformOptions {
|
|
@@ -44,7 +44,11 @@ interface RunTransformOptions {
|
|
|
44
44
|
*/
|
|
45
45
|
print?: boolean;
|
|
46
46
|
/**
|
|
47
|
-
* jscodeshift parser to use
|
|
47
|
+
* jscodeshift parser to use.
|
|
48
|
+
*
|
|
49
|
+
* When set to `"ts"` or `"tsx"` (including the default), runTransform also
|
|
50
|
+
* builds TypeScript compiler metadata for more accurate wrapper interfaces.
|
|
51
|
+
*
|
|
48
52
|
* @default "tsx"
|
|
49
53
|
*/
|
|
50
54
|
parser?: "babel" | "babylon" | "flow" | "ts" | "tsx";
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as describeValue, i as defineAdapter, n as mergeMarkerDeclarations, s as assertValidAdapterInput, t as transformedComponentAcceptsSx } from "./sx-surface-DBy6tOUv.mjs";
|
|
2
2
|
import { a as resolveBarrelReExport, s as Logger } from "./extract-external-interface-B61N1a6q.mjs";
|
|
3
3
|
import { r as extractStyledDefBasesFromSource } from "./compute-leaf-set-Be5Cgxnr.mjs";
|
|
4
4
|
import { n as toRealPath } from "./path-utils-BIpoL4Ue.mjs";
|
|
@@ -149,10 +149,12 @@ async function runTransform(options) {
|
|
|
149
149
|
const { createModuleResolver } = await import("./resolve-imports-DgSAddIF.mjs").then((n) => n.n);
|
|
150
150
|
const sharedResolver = createModuleResolver();
|
|
151
151
|
filePaths = orderFilesByLocalImportDependencies(filePaths, sharedResolver, toRealPath);
|
|
152
|
-
const { runPrepass } = await import("./run-prepass-
|
|
152
|
+
const { runPrepass } = await import("./run-prepass-COJ2IOPl.mjs");
|
|
153
153
|
const absoluteFiles = filePaths.map((f) => resolve(f));
|
|
154
154
|
const absoluteConsumers = consumerFilePaths.map((f) => resolve(f));
|
|
155
155
|
let prepassResult;
|
|
156
|
+
const prepassStartedAt = performance.now();
|
|
157
|
+
Logger.info(`Prepass: starting (${absoluteFiles.length} file${absoluteFiles.length === 1 ? "" : "s"}, ${absoluteConsumers.length} consumer${absoluteConsumers.length === 1 ? "" : "s"}, parser=${parser})\n`);
|
|
156
158
|
try {
|
|
157
159
|
prepassResult = await runPrepass({
|
|
158
160
|
filesToTransform: absoluteFiles,
|
|
@@ -164,9 +166,10 @@ async function runTransform(options) {
|
|
|
164
166
|
leavesOnly,
|
|
165
167
|
resolveBaseComponent: adapterInput.resolveBaseComponent
|
|
166
168
|
});
|
|
169
|
+
Logger.info(`Prepass: completed in ${formatElapsedSeconds(prepassStartedAt)}s\n`);
|
|
167
170
|
} catch (err) {
|
|
168
171
|
if (adapterInput.externalInterface === "auto") throw createAutoPrepassFailureError(err, consumerPatterns, parser);
|
|
169
|
-
Logger.warn(`Prepass failed, continuing without cross-file analysis: ${err instanceof Error ? err.message : String(err)}`);
|
|
172
|
+
Logger.warn(`Prepass failed after ${formatElapsedSeconds(prepassStartedAt)}s, continuing without cross-file analysis: ${err instanceof Error ? err.message : String(err)}`);
|
|
170
173
|
prepassResult = {
|
|
171
174
|
crossFileInfo: {
|
|
172
175
|
selectorUsages: /* @__PURE__ */ new Map(),
|
|
@@ -176,14 +179,16 @@ async function runTransform(options) {
|
|
|
176
179
|
globalLeafKeys: leavesOnly ? /* @__PURE__ */ new Set() : void 0
|
|
177
180
|
},
|
|
178
181
|
consumerAnalysis: void 0,
|
|
179
|
-
forwardedAsConsumers: /* @__PURE__ */ new Map()
|
|
182
|
+
forwardedAsConsumers: /* @__PURE__ */ new Map(),
|
|
183
|
+
typeScriptMetadata: void 0
|
|
180
184
|
};
|
|
181
185
|
}
|
|
182
186
|
const transformedFiles = /* @__PURE__ */ new Set();
|
|
183
187
|
const transformedFileSources = /* @__PURE__ */ new Map();
|
|
184
188
|
const crossFilePrepassResult = {
|
|
185
189
|
...prepassResult.crossFileInfo,
|
|
186
|
-
transformedFiles
|
|
190
|
+
transformedFiles,
|
|
191
|
+
typeScriptMetadata: prepassResult.typeScriptMetadata
|
|
187
192
|
};
|
|
188
193
|
const resolvedAdapter = (() => {
|
|
189
194
|
if (adapterInput.externalInterface === "auto" && prepassResult.consumerAnalysis) {
|
|
@@ -247,11 +252,12 @@ async function runTransform(options) {
|
|
|
247
252
|
const autoInterfaceNames = ctx.importedName === "default" ? [ctx.localName, ctx.importedName] : [ctx.importedName];
|
|
248
253
|
const styledDefinitionNames = getStyledDefinitionNames(definitionSourcePath);
|
|
249
254
|
const sourceComponentNames = ctx.importedName === "default" ? [ctx.localName, getDefaultExportedName(definitionSourcePath)].filter((name) => typeof name === "string") : [ctx.importedName];
|
|
250
|
-
if (sourceComponentNames
|
|
255
|
+
if (findTypedComponentMetadata(prepassResult.typeScriptMetadata, definitionSourcePath, sourceComponentNames)?.supportsSxProp === true) return { acceptsSx: true };
|
|
256
|
+
if (transformedComponentAcceptsSx({
|
|
251
257
|
absolutePath: definitionSourcePath,
|
|
252
|
-
|
|
258
|
+
componentNames: sourceComponentNames,
|
|
253
259
|
sourceOverrides: transformedFileSources
|
|
254
|
-
}))
|
|
260
|
+
})) return { acceptsSx: true };
|
|
255
261
|
if (!transformedFiles.has(toRealPath(definitionSourcePath))) return;
|
|
256
262
|
if (!sourceComponentNames.some((name) => styledDefinitionNames.has(name))) return;
|
|
257
263
|
return autoInterfaceNames.map((name) => lookupAutoExternalInterface(definitionSourcePath, name)).find((result) => result !== void 0)?.styles ? { acceptsSx: true } : void 0;
|
|
@@ -314,7 +320,7 @@ async function runTransform(options) {
|
|
|
314
320
|
const result = await runTransformSequentially(transformModule, filePaths, runnerOptions);
|
|
315
321
|
if (sidecarFiles.size > 0 && !dryRun) for (const [sidecarPath, content] of sidecarFiles) await writeFile(sidecarPath, mergeSidecarContent(sidecarPath, content), "utf-8");
|
|
316
322
|
if (bridgeResults.size > 0 && !dryRun) {
|
|
317
|
-
const { buildConsumerReplacements, patchConsumerFile } = await import("./bridge-consumer-patcher-
|
|
323
|
+
const { buildConsumerReplacements, patchConsumerFile } = await import("./bridge-consumer-patcher-DNsxze1l.mjs");
|
|
318
324
|
const consumerReplacements = buildConsumerReplacements(crossFilePrepassResult.selectorUsages, bridgeResults, transformedFiles);
|
|
319
325
|
const patchedFiles = [];
|
|
320
326
|
for (const [consumerPath, replacements] of consumerReplacements) {
|
|
@@ -327,7 +333,7 @@ async function runTransform(options) {
|
|
|
327
333
|
if (formatterCommands && patchedFiles.length > 0) await runFormatters(formatterCommands, patchedFiles);
|
|
328
334
|
}
|
|
329
335
|
if (prepassResult.forwardedAsConsumers.size > 0 && !dryRun) {
|
|
330
|
-
const { buildForwardedAsReplacements, patchConsumerForwardedAs } = await import("./forwarded-as-consumer-patcher-
|
|
336
|
+
const { buildForwardedAsReplacements, patchConsumerForwardedAs } = await import("./forwarded-as-consumer-patcher-DoVqLOgw.mjs");
|
|
331
337
|
const forwardedAsReplacements = buildForwardedAsReplacements(prepassResult.forwardedAsConsumers, transformedFiles);
|
|
332
338
|
const patchedFiles = [];
|
|
333
339
|
for (const [consumerPath, entries] of forwardedAsReplacements) {
|
|
@@ -340,7 +346,7 @@ async function runTransform(options) {
|
|
|
340
346
|
if (formatterCommands && patchedFiles.length > 0) await runFormatters(formatterCommands, patchedFiles);
|
|
341
347
|
}
|
|
342
348
|
if (transientPropRenames.size > 0 && !dryRun) {
|
|
343
|
-
const { collectTransientPropPatches } = await import("./transient-prop-consumer-patcher-
|
|
349
|
+
const { collectTransientPropPatches } = await import("./transient-prop-consumer-patcher-BX-LeC2B.mjs");
|
|
344
350
|
const patches = collectTransientPropPatches({
|
|
345
351
|
transientPropRenames,
|
|
346
352
|
consumerFilePaths: consumerFilePaths.map((p) => resolve(p)),
|
|
@@ -381,6 +387,15 @@ function createAutoPrepassFailureError(err, consumerPatterns, parser) {
|
|
|
381
387
|
`consumerPaths: ${consumerPatterns.length > 0 ? consumerPatterns.join(", ") : "(none)"}`
|
|
382
388
|
].join("\n"));
|
|
383
389
|
}
|
|
390
|
+
function formatElapsedSeconds(startedAt) {
|
|
391
|
+
return ((performance.now() - startedAt) / 1e3).toFixed(1);
|
|
392
|
+
}
|
|
393
|
+
function findTypedComponentMetadata(metadata, filePath, componentNames) {
|
|
394
|
+
if (!metadata) return;
|
|
395
|
+
const names = new Set(componentNames);
|
|
396
|
+
const resolvedFilePath = toRealPath(filePath);
|
|
397
|
+
return metadata.files.find((file) => file.filePath === resolvedFilePath)?.components.find((component) => names.has(component.name));
|
|
398
|
+
}
|
|
384
399
|
/**
|
|
385
400
|
* Merge new sidecar marker content into an existing .stylex.ts file, preserving
|
|
386
401
|
* user-owned exports (e.g. defineVars). If the file doesn't exist, returns content as-is.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as resolveBarrelReExport, n as fileImportsFrom, o as resolveBarrelReExportBinding, r as findImportSource, s as Logger, t as fileExports } from "./extract-external-interface-B61N1a6q.mjs";
|
|
2
2
|
import { n as extractStyledDefBasesFromAstProgram, r as extractStyledDefBasesFromSource, t as computeGlobalLeafKeys } from "./compute-leaf-set-Be5Cgxnr.mjs";
|
|
3
3
|
import { r as escapeRegex } from "./string-utils-DD9wdRHW.mjs";
|
|
4
|
-
import { a as PLACEHOLDER_RE, i as readStaticJsxLiteral, n as createComponentPropUsageInfo, r as mergeComponentPropUsage, t as KNOWN_NON_ELEMENT_PROPS } from "./prop-usage-
|
|
5
|
-
import { t as isSelectorContext } from "./selector-context-heuristic-
|
|
4
|
+
import { a as PLACEHOLDER_RE, i as readStaticJsxLiteral, n as createComponentPropUsageInfo, r as mergeComponentPropUsage, t as KNOWN_NON_ELEMENT_PROPS } from "./prop-usage-B6z4WOPr.mjs";
|
|
5
|
+
import { t as isSelectorContext } from "./selector-context-heuristic-CGggN74M.mjs";
|
|
6
6
|
import { relative, resolve } from "node:path";
|
|
7
7
|
import { readFileSync, realpathSync } from "node:fs";
|
|
8
8
|
import { execSync } from "node:child_process";
|
|
@@ -438,6 +438,7 @@ async function runPrepass(options) {
|
|
|
438
438
|
const allFilesSet = new Set(allFiles);
|
|
439
439
|
const uniqueAllFiles = [...allFilesSet];
|
|
440
440
|
const parser = createPrepassParser(parserName);
|
|
441
|
+
const enableTypeScriptAnalysis = isTypeScriptParser(parserName);
|
|
441
442
|
const resolveCache = /* @__PURE__ */ new Map();
|
|
442
443
|
const resolve$1 = (specifier, fromFile) => {
|
|
443
444
|
const absFromFile = resolve(fromFile);
|
|
@@ -500,7 +501,7 @@ async function runPrepass(options) {
|
|
|
500
501
|
STYLED_DEF_RE.lastIndex = 0;
|
|
501
502
|
for (const m of source.matchAll(STYLED_DEF_RE)) if (m[1]) addToSetMap(styledDefFiles, filePath, m[1]);
|
|
502
503
|
}
|
|
503
|
-
if (createExternalInterface && hasStyled) {
|
|
504
|
+
if ((createExternalInterface || enableTypeScriptAnalysis) && hasStyled) {
|
|
504
505
|
STYLED_CALL_RE.lastIndex = 0;
|
|
505
506
|
for (const m of source.matchAll(STYLED_CALL_RE)) if (m[1]) styledCallUsages.push({
|
|
506
507
|
file: filePath,
|
|
@@ -652,6 +653,8 @@ async function runPrepass(options) {
|
|
|
652
653
|
}
|
|
653
654
|
const entry = ensure(defFile, exportedName);
|
|
654
655
|
entry.styles = true;
|
|
656
|
+
entry.className = true;
|
|
657
|
+
entry.style = true;
|
|
655
658
|
entry.elementProps = true;
|
|
656
659
|
entry.spreadProps = true;
|
|
657
660
|
}
|
|
@@ -679,6 +682,13 @@ async function runPrepass(options) {
|
|
|
679
682
|
targetPath: defFile
|
|
680
683
|
});
|
|
681
684
|
}
|
|
685
|
+
const typeScriptMetadata = enableTypeScriptAnalysis ? (await loadTypeScriptAnalysis()).analyzeTypeScriptProgram({ files: collectTypeScriptAnalysisFiles({
|
|
686
|
+
transformSet,
|
|
687
|
+
styledCallUsages,
|
|
688
|
+
styledWrapperUsages,
|
|
689
|
+
cachedRead,
|
|
690
|
+
resolve: resolve$1
|
|
691
|
+
}) }) : void 0;
|
|
682
692
|
const propUsageByFile = buildPropUsageByFile({
|
|
683
693
|
styledDefFiles,
|
|
684
694
|
propUsageCandidates,
|
|
@@ -721,7 +731,8 @@ async function runPrepass(options) {
|
|
|
721
731
|
return {
|
|
722
732
|
crossFileInfo,
|
|
723
733
|
consumerAnalysis,
|
|
724
|
-
forwardedAsConsumers
|
|
734
|
+
forwardedAsConsumers,
|
|
735
|
+
typeScriptMetadata
|
|
725
736
|
};
|
|
726
737
|
}
|
|
727
738
|
/** Regex baseline for styled defs, then AST pass overrides/adds rows when parse succeeds. */
|
|
@@ -739,6 +750,41 @@ function mergeLeafStyledDefBasesForFile(filePath, source, parser, styledDefBases
|
|
|
739
750
|
function hasLeavesOnlyPrepassBlocker(source) {
|
|
740
751
|
return source.includes("shouldForwardProp") || hasUniversalSelectorCandidate(source);
|
|
741
752
|
}
|
|
753
|
+
function isTypeScriptParser(parserName) {
|
|
754
|
+
return parserName === void 0 || parserName === "ts" || parserName === "tsx";
|
|
755
|
+
}
|
|
756
|
+
async function loadTypeScriptAnalysis() {
|
|
757
|
+
try {
|
|
758
|
+
return await import("./typescript-analysis-UWX_ePX0.mjs");
|
|
759
|
+
} catch (err) {
|
|
760
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
761
|
+
if (message.includes("typescript") && (message.includes("Cannot find") || message.includes("ERR_MODULE_NOT_FOUND"))) throw new Error(["TypeScript parser runs require the optional `typescript` package for compiler metadata.", "Install TypeScript in the project (supported range: >=5.0.0 <6), or use a non-TypeScript parser."].join("\n"));
|
|
762
|
+
throw err;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function collectTypeScriptAnalysisFiles(args) {
|
|
766
|
+
const { transformSet, styledCallUsages, styledWrapperUsages, cachedRead, resolve } = args;
|
|
767
|
+
const files = new Set(transformSet);
|
|
768
|
+
for (const { file, name } of styledCallUsages) {
|
|
769
|
+
const definition = resolveDefinitionFile({
|
|
770
|
+
file,
|
|
771
|
+
localName: name,
|
|
772
|
+
cachedRead,
|
|
773
|
+
resolve
|
|
774
|
+
});
|
|
775
|
+
if (definition) files.add(definition.defFile);
|
|
776
|
+
}
|
|
777
|
+
for (const { file, wrappedName } of styledWrapperUsages) {
|
|
778
|
+
const definition = resolveDefinitionFile({
|
|
779
|
+
file,
|
|
780
|
+
localName: wrappedName,
|
|
781
|
+
cachedRead,
|
|
782
|
+
resolve
|
|
783
|
+
});
|
|
784
|
+
if (definition) files.add(definition.defFile);
|
|
785
|
+
}
|
|
786
|
+
return [...files].sort();
|
|
787
|
+
}
|
|
742
788
|
function hasUniversalSelectorCandidate(source) {
|
|
743
789
|
return /(?:^|[{\n;])\s*(?:&\s*)?(?:[>+~]\s*)?\*/.test(source);
|
|
744
790
|
}
|