@nooeh/cli 0.2.6 → 0.2.8
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 +2 -7
- package/dist/init.js +28 -10
- package/package.json +5 -1
package/dist/doctor.js
CHANGED
|
@@ -55,7 +55,7 @@ async function hasStylexCompiler(projectDirectory) {
|
|
|
55
55
|
"rspack.config.js",
|
|
56
56
|
];
|
|
57
57
|
const sources = await Promise.all(configFileNames.map(async (fileName) => readProjectFile(projectDirectory, fileName)));
|
|
58
|
-
return sources.some((source) => source?.includes("@stylexjs/unplugin") &&
|
|
58
|
+
return sources.some((source) => source?.includes("@stylexjs/unplugin") && /\b(?:stylex|unplugin)\.vite\(/.test(source));
|
|
59
59
|
}
|
|
60
60
|
function hasDependency(packageJson, dependency) {
|
|
61
61
|
return Boolean(packageJson?.dependencies?.[dependency] ?? packageJson?.devDependencies?.[dependency]);
|
|
@@ -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
|
}
|
|
@@ -70,28 +73,43 @@ function configureVite(source) {
|
|
|
70
73
|
async function writeViteFiles(projectDirectory, tokenDirectory, refreshLegacyTokens) {
|
|
71
74
|
const { path: configPath, source: configSource } = await readViteConfig(projectDirectory);
|
|
72
75
|
const configuredVite = configureVite(configSource);
|
|
76
|
+
await addResetImport(projectDirectory);
|
|
73
77
|
await writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTokens);
|
|
74
78
|
await writeFile(configPath, configuredVite, "utf8");
|
|
75
79
|
console.log(`Configured Vite and created ${relative(projectDirectory, tokenDirectory)}.`);
|
|
76
80
|
}
|
|
81
|
+
async function addResetImport(projectDirectory) {
|
|
82
|
+
const cssPath = join(projectDirectory, "src/index.css");
|
|
83
|
+
const resetImport = '@import "@nooeh/ui/reset.css";';
|
|
84
|
+
try {
|
|
85
|
+
const source = await readFile(cssPath, "utf8");
|
|
86
|
+
if (source.includes(resetImport))
|
|
87
|
+
return;
|
|
88
|
+
await writeFile(cssPath, `${resetImport}\n\n${source}`, "utf8");
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
92
|
+
await writeFile(cssPath, `${resetImport}\n`, "utf8");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
77
98
|
async function writeNooehFiles(projectDirectory, tokenDirectory, refreshLegacyTokens = false) {
|
|
78
99
|
await mkdir(tokenDirectory, { recursive: true });
|
|
79
100
|
for (const file of await getTokenFiles()) {
|
|
80
101
|
await writeTokenFile(join(tokenDirectory, file.name), file.content, refreshLegacyTokens, file.name);
|
|
81
102
|
}
|
|
82
103
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return (fileName === "theme-provider.tsx" &&
|
|
88
|
-
source.includes("const styles = stylex.create({") &&
|
|
89
|
-
source.includes("data-theme={resolvedTheme}"));
|
|
104
|
+
function isLegacySemanticSource(fileName, source) {
|
|
105
|
+
return (fileName === "semantic.stylex.ts" &&
|
|
106
|
+
source.includes('bgCanvas: "initial"') &&
|
|
107
|
+
source.includes('overlay: "initial"'));
|
|
90
108
|
}
|
|
91
109
|
async function writeTokenFile(path, source, shouldRefreshLegacySources, fileName) {
|
|
92
110
|
try {
|
|
93
111
|
const currentSource = await readFile(path, "utf8");
|
|
94
|
-
if (shouldRefreshLegacySources &&
|
|
112
|
+
if (shouldRefreshLegacySources && isLegacySemanticSource(fileName, currentSource)) {
|
|
95
113
|
await writeFile(path, source, "utf8");
|
|
96
114
|
}
|
|
97
115
|
}
|
|
@@ -125,7 +143,7 @@ export async function init(projectDirectory, options) {
|
|
|
125
143
|
if (!options["skip-dependencies"]) {
|
|
126
144
|
await installDependencies(projectDirectory, ["@stylexjs/stylex"]);
|
|
127
145
|
if (options.framework === "vite") {
|
|
128
|
-
await installDependencies(projectDirectory, ["@stylexjs/unplugin"], true);
|
|
146
|
+
await installDependencies(projectDirectory, ["@nooeh/ui", "@stylexjs/unplugin"], true);
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
if (options.framework === "vite") {
|