@nooeh/cli 0.2.6 → 0.2.7
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/doctor.js +1 -6
- package/dist/init.js +9 -9
- package/package.json +5 -1
package/dist/doctor.js
CHANGED
|
@@ -81,12 +81,7 @@ export async function doctor(projectDirectory) {
|
|
|
81
81
|
name: "UI path",
|
|
82
82
|
status: "pass",
|
|
83
83
|
});
|
|
84
|
-
const tokenFiles = [
|
|
85
|
-
"color-palette.stylex.ts",
|
|
86
|
-
"semantic.stylex.ts",
|
|
87
|
-
"themes.stylex.ts",
|
|
88
|
-
"theme-provider.tsx",
|
|
89
|
-
];
|
|
84
|
+
const tokenFiles = ["color-palette.stylex.ts", "semantic.stylex.ts", "themes.stylex.ts"];
|
|
90
85
|
const hasTokenFiles = await Promise.all(tokenFiles.map(async (fileName) => {
|
|
91
86
|
try {
|
|
92
87
|
await access(resolve(tokenDirectory, fileName));
|
package/dist/init.js
CHANGED
|
@@ -36,9 +36,10 @@ async function readViteConfig(projectDirectory) {
|
|
|
36
36
|
function configureVite(source) {
|
|
37
37
|
const importLine = 'import stylex from "@stylexjs/unplugin";';
|
|
38
38
|
const pluginPattern = /plugins:\s*\[([^\]]*)\]/s;
|
|
39
|
-
const stylexPlugin =
|
|
39
|
+
const stylexPlugin = 'stylex.vite({ unstable_moduleResolution: { type: "commonJS" } })';
|
|
40
40
|
const legacyStylexPluginPattern = /stylex\.vite\(\{\s*useCSSLayers:\s*true\s*\}\)/;
|
|
41
41
|
const emptyStylexPluginPattern = /stylex\.vite\(\)/;
|
|
42
|
+
const moduleResolutionPluginPattern = /stylex\.vite\(\{\s*unstable_moduleResolution:\s*\{\s*type:\s*["']commonJS["']\s*\},?\s*\}\)/s;
|
|
42
43
|
const nooehStylexPluginPattern = /stylex\.vite\(\{\s*(?:\/\/[^\n]*\s*)?(?:useCSSLayers:\s*true,?\s*)?aliases:\s*\{[^}]*\},\s*unstable_moduleResolution:\s*\{\s*type:\s*["']commonJS["'],\s*rootDir:\s*new URL\(["']\.["'],\s*import\.meta\.url\)\.pathname,?\s*\},\s*\}\)/s;
|
|
43
44
|
if (!source.includes("stylex.vite(") && !pluginPattern.test(source)) {
|
|
44
45
|
throw new Error("Could not safely update the Vite plugins array. Add stylex.vite() manually.");
|
|
@@ -46,6 +47,8 @@ function configureVite(source) {
|
|
|
46
47
|
if (nooehStylexPluginPattern.test(source)) {
|
|
47
48
|
return source.replace(nooehStylexPluginPattern, stylexPlugin);
|
|
48
49
|
}
|
|
50
|
+
if (moduleResolutionPluginPattern.test(source))
|
|
51
|
+
return source;
|
|
49
52
|
if (source.includes("unstable_moduleResolution")) {
|
|
50
53
|
throw new Error("Could not safely simplify the existing StyleX plugin. Remove Nooeh's aliases and unstable_moduleResolution manually, then use stylex.vite().");
|
|
51
54
|
}
|
|
@@ -80,18 +83,15 @@ async function writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTo
|
|
|
80
83
|
await writeTokenFile(join(tokenDirectory, file.name), file.content, refreshLegacyTokens, file.name);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return (fileName === "theme-provider.tsx" &&
|
|
88
|
-
source.includes("const styles = stylex.create({") &&
|
|
89
|
-
source.includes("data-theme={resolvedTheme}"));
|
|
86
|
+
function isLegacySemanticSource(fileName, source) {
|
|
87
|
+
return (fileName === "semantic.stylex.ts" &&
|
|
88
|
+
source.includes('bgCanvas: "initial"') &&
|
|
89
|
+
source.includes('overlay: "initial"'));
|
|
90
90
|
}
|
|
91
91
|
async function writeTokenFile(path, source, shouldRefreshLegacySources, fileName) {
|
|
92
92
|
try {
|
|
93
93
|
const currentSource = await readFile(path, "utf8");
|
|
94
|
-
if (shouldRefreshLegacySources &&
|
|
94
|
+
if (shouldRefreshLegacySources && isLegacySemanticSource(fileName, currentSource)) {
|
|
95
95
|
await writeFile(path, source, "utf8");
|
|
96
96
|
}
|
|
97
97
|
}
|