styled-components-to-stylex-codemod 0.0.23 → 0.0.24
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-C2mFaVmd.mjs → bridge-consumer-patcher-yD2M8NhV.mjs} +8 -19
- package/dist/{forwarded-as-consumer-patcher-CIOAJ-51.mjs → forwarded-as-consumer-patcher-DobBjqdG.mjs} +2 -11
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +5 -5
- package/dist/path-utils-CTsuWb5f.mjs +22 -0
- package/dist/{run-prepass-DV-4A_Ci.mjs → run-prepass-Dl49r3ug.mjs} +3 -5
- package/dist/transform.d.mts +1 -1
- package/dist/transform.mjs +337 -368
- package/dist/{transient-prop-consumer-patcher-iofVVX40.mjs → transient-prop-consumer-patcher-DAX9HWDH.mjs} +2 -8
- package/package.json +1 -1
- /package/dist/{logger-Cml101qs.d.mts → logger-CPjmdPhU.d.mts} +0 -0
- /package/dist/{resolve-imports-4bFqrkrQ.mjs → resolve-imports-CN7ulI4X.mjs} +0 -0
- /package/dist/{selector-context-heuristic-Cki9_tTH.mjs → selector-context-heuristic-CQgP_0dH.mjs} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { n as escapeRegex } from "./string-utils-J3iaDsXd.mjs";
|
|
2
|
+
import { t as toRealPath } from "./path-utils-CTsuWb5f.mjs";
|
|
3
|
+
import { t as isSelectorContext } from "./selector-context-heuristic-CQgP_0dH.mjs";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
4
5
|
|
|
5
6
|
//#region src/internal/bridge-consumer-patcher.ts
|
|
6
7
|
/**
|
|
@@ -71,9 +72,9 @@ function patchConsumerFile(filePath, replacements) {
|
|
|
71
72
|
let modified = source;
|
|
72
73
|
for (const [importSource, reps] of bySource) {
|
|
73
74
|
const varNames = reps.map((r) => r.globalSelectorVarName);
|
|
74
|
-
const importRegex = new RegExp(`(import\\s+(?:(?:\\{[^}]*\\}|[^;{]+)\\s+from\\s+['"]${
|
|
75
|
+
const importRegex = new RegExp(`(import\\s+(?:(?:\\{[^}]*\\}|[^;{]+)\\s+from\\s+['"]${escapeRegex(importSource)}['"])\\s*;?)`);
|
|
75
76
|
if (modified.match(importRegex)) {
|
|
76
|
-
const namedImportRegex = new RegExp(`(import\\s+(?:[\\w$]+\\s*,\\s*)?\\{)([^}]*)(\\}\\s+from\\s+['"]${
|
|
77
|
+
const namedImportRegex = new RegExp(`(import\\s+(?:[\\w$]+\\s*,\\s*)?\\{)([^}]*)(\\}\\s+from\\s+['"]${escapeRegex(importSource)}['"]\\s*;?)`);
|
|
77
78
|
const namedMatch = modified.match(namedImportRegex);
|
|
78
79
|
if (namedMatch) {
|
|
79
80
|
const existingNames = namedMatch[2];
|
|
@@ -96,7 +97,7 @@ function patchConsumerFile(filePath, replacements) {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
for (const r of replacements) {
|
|
99
|
-
const templateExprRegex = new RegExp(`(\\$\\{\\s*)${
|
|
100
|
+
const templateExprRegex = new RegExp(`(\\$\\{\\s*)${escapeRegex(r.localName)}(\\s*\\})`, "g");
|
|
100
101
|
modified = modified.replace(templateExprRegex, (match, prefix, suffix, offset) => {
|
|
101
102
|
if (isInStyledTemplateSelectorContext(modified, offset, match.length)) return `${prefix}${r.globalSelectorVarName}${suffix}`;
|
|
102
103
|
return match;
|
|
@@ -117,19 +118,7 @@ function isInStyledTemplateSelectorContext(source, offset, length) {
|
|
|
117
118
|
}
|
|
118
119
|
/** Check if a name appears as a distinct identifier in an import specifier list string. */
|
|
119
120
|
function hasExactImportName(importSpecifiers, name) {
|
|
120
|
-
return new RegExp(`(?:^|[^A-Za-z0-9_$])${
|
|
121
|
-
}
|
|
122
|
-
function escapeRegExp(s) {
|
|
123
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
124
|
-
}
|
|
125
|
-
/** Resolve symlinks so paths match the keys in transformedFiles (which uses realpathSync). */
|
|
126
|
-
function toRealPath(filePath) {
|
|
127
|
-
const resolved = resolve(filePath);
|
|
128
|
-
try {
|
|
129
|
-
return realpathSync(resolved);
|
|
130
|
-
} catch {
|
|
131
|
-
return resolved;
|
|
132
|
-
}
|
|
121
|
+
return new RegExp(`(?:^|[^A-Za-z0-9_$])${escapeRegex(name)}(?:$|[^A-Za-z0-9_$])`).test(importSpecifiers);
|
|
133
122
|
}
|
|
134
123
|
|
|
135
124
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as escapeRegex } from "./string-utils-J3iaDsXd.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { readFileSync
|
|
2
|
+
import { t as toRealPath } from "./path-utils-CTsuWb5f.mjs";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
4
|
|
|
5
5
|
//#region src/internal/forwarded-as-consumer-patcher.ts
|
|
6
6
|
/**
|
|
@@ -77,15 +77,6 @@ function patchAttrsAsProp(source, componentName) {
|
|
|
77
77
|
return `${before}forwardedAs${after}`;
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
/** Resolve symlinks so paths match the keys in transformedFiles. */
|
|
81
|
-
function toRealPath(filePath) {
|
|
82
|
-
const resolved = resolve(filePath);
|
|
83
|
-
try {
|
|
84
|
-
return realpathSync(resolved);
|
|
85
|
-
} catch {
|
|
86
|
-
return resolved;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
80
|
|
|
90
81
|
//#endregion
|
|
91
82
|
export { buildForwardedAsReplacements, patchConsumerForwardedAs };
|
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -141,9 +141,9 @@ async function runTransform(options) {
|
|
|
141
141
|
`Pattern(s): ${consumerPatterns.join(", ")}`,
|
|
142
142
|
"Check that the glob pattern is correct and files exist."
|
|
143
143
|
].join("\n"));
|
|
144
|
-
const { createModuleResolver } = await import("./resolve-imports-
|
|
144
|
+
const { createModuleResolver } = await import("./resolve-imports-CN7ulI4X.mjs");
|
|
145
145
|
const sharedResolver = createModuleResolver();
|
|
146
|
-
const { runPrepass } = await import("./run-prepass-
|
|
146
|
+
const { runPrepass } = await import("./run-prepass-Dl49r3ug.mjs");
|
|
147
147
|
const absoluteFiles = filePaths.map((f) => resolve(f));
|
|
148
148
|
const absoluteConsumers = consumerFilePaths.map((f) => resolve(f));
|
|
149
149
|
let prepassResult;
|
|
@@ -234,7 +234,7 @@ async function runTransform(options) {
|
|
|
234
234
|
});
|
|
235
235
|
if (sidecarFiles.size > 0 && !dryRun) for (const [sidecarPath, content] of sidecarFiles) await writeFile(sidecarPath, mergeSidecarContent(sidecarPath, content), "utf-8");
|
|
236
236
|
if (bridgeResults.size > 0 && !dryRun) {
|
|
237
|
-
const { buildConsumerReplacements, patchConsumerFile } = await import("./bridge-consumer-patcher-
|
|
237
|
+
const { buildConsumerReplacements, patchConsumerFile } = await import("./bridge-consumer-patcher-yD2M8NhV.mjs");
|
|
238
238
|
const consumerReplacements = buildConsumerReplacements(crossFilePrepassResult.selectorUsages, bridgeResults, transformedFiles);
|
|
239
239
|
const patchedFiles = [];
|
|
240
240
|
for (const [consumerPath, replacements] of consumerReplacements) {
|
|
@@ -247,7 +247,7 @@ async function runTransform(options) {
|
|
|
247
247
|
if (formatterCommands && patchedFiles.length > 0) await runFormatters(formatterCommands, patchedFiles);
|
|
248
248
|
}
|
|
249
249
|
if (prepassResult.forwardedAsConsumers.size > 0 && !dryRun) {
|
|
250
|
-
const { buildForwardedAsReplacements, patchConsumerForwardedAs } = await import("./forwarded-as-consumer-patcher-
|
|
250
|
+
const { buildForwardedAsReplacements, patchConsumerForwardedAs } = await import("./forwarded-as-consumer-patcher-DobBjqdG.mjs");
|
|
251
251
|
const forwardedAsReplacements = buildForwardedAsReplacements(prepassResult.forwardedAsConsumers, transformedFiles);
|
|
252
252
|
const patchedFiles = [];
|
|
253
253
|
for (const [consumerPath, entries] of forwardedAsReplacements) {
|
|
@@ -260,7 +260,7 @@ async function runTransform(options) {
|
|
|
260
260
|
if (formatterCommands && patchedFiles.length > 0) await runFormatters(formatterCommands, patchedFiles);
|
|
261
261
|
}
|
|
262
262
|
if (transientPropRenames.size > 0 && !dryRun) {
|
|
263
|
-
const { collectTransientPropPatches } = await import("./transient-prop-consumer-patcher-
|
|
263
|
+
const { collectTransientPropPatches } = await import("./transient-prop-consumer-patcher-DAX9HWDH.mjs");
|
|
264
264
|
const patches = collectTransientPropPatches({
|
|
265
265
|
transientPropRenames,
|
|
266
266
|
consumerFilePaths: consumerFilePaths.map((p) => resolve(p)),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/utilities/path-utils.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared path utilities for symlink resolution and path normalization.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a file path to its real (symlink-resolved) absolute path.
|
|
10
|
+
* Falls back to pathResolve if realpathSync fails (e.g. file doesn't exist yet).
|
|
11
|
+
*/
|
|
12
|
+
function toRealPath(filePath) {
|
|
13
|
+
const resolved = resolve(filePath);
|
|
14
|
+
try {
|
|
15
|
+
return realpathSync(resolved);
|
|
16
|
+
} catch {
|
|
17
|
+
return resolved;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { toRealPath as t };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { n as escapeRegex } from "./string-utils-J3iaDsXd.mjs";
|
|
1
2
|
import { t as PLACEHOLDER_RE } from "./styled-css-BJH7gntu.mjs";
|
|
2
|
-
import { t as isSelectorContext } from "./selector-context-heuristic-
|
|
3
|
+
import { t as isSelectorContext } from "./selector-context-heuristic-CQgP_0dH.mjs";
|
|
3
4
|
import path, { relative, resolve } from "node:path";
|
|
4
5
|
import { readFileSync, realpathSync } from "node:fs";
|
|
5
6
|
import { execSync } from "node:child_process";
|
|
@@ -738,14 +739,11 @@ function collectImportDeclarationText(source) {
|
|
|
738
739
|
function importTextMentionsIdentifier(importText, identifier) {
|
|
739
740
|
let re = IMPORT_IDENTIFIER_RE_CACHE.get(identifier);
|
|
740
741
|
if (!re) {
|
|
741
|
-
re = new RegExp(`(?:^|[^A-Za-z0-9_$])${
|
|
742
|
+
re = new RegExp(`(?:^|[^A-Za-z0-9_$])${escapeRegex(identifier)}(?:$|[^A-Za-z0-9_$])`);
|
|
742
743
|
IMPORT_IDENTIFIER_RE_CACHE.set(identifier, re);
|
|
743
744
|
}
|
|
744
745
|
return re.test(importText);
|
|
745
746
|
}
|
|
746
|
-
function escapeRegexForRegExp(s) {
|
|
747
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
748
|
-
}
|
|
749
747
|
/** Quick pre-check: does this source mention className or style in a JSX prop context? */
|
|
750
748
|
const CLASSNAME_STYLE_QUICK_RE = /\b(className|style)\s*[={]/;
|
|
751
749
|
/** Matches `import { Original as Local, ... }` — captures original and local names. */
|
package/dist/transform.d.mts
CHANGED