@usalyt/cli 0.0.0-stage → 0.0.2

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.
@@ -0,0 +1,297 @@
1
+ import { lstatSync, realpathSync } from "node:fs";
2
+ import path from "node:path";
3
+ import type { UsalytConfig } from "./config";
4
+ import { rewriteRelativeImports } from "./imports";
5
+ import { assertWithinRoot, isWithinRoot, resolveAliasWithinRoot, UnsafePathError } from "./paths";
6
+ import { detectTsconfigPathMapping, type TsconfigPathMapping } from "./project";
7
+ import type { Registry, RegistryItem } from "./registry";
8
+
9
+ export class UnknownItemsError extends Error {
10
+ readonly names: string[];
11
+
12
+ constructor(names: string[]) {
13
+ super(`unknown component(s): ${names.join(", ")}`);
14
+ this.name = "UnknownItemsError";
15
+ this.names = names;
16
+ }
17
+ }
18
+
19
+ export class UnsupportedItemError extends Error {
20
+ constructor(message: string) {
21
+ super(message);
22
+ this.name = "UnsupportedItemError";
23
+ }
24
+ }
25
+
26
+ export interface PlannedWrite {
27
+ item: string;
28
+ destination: string;
29
+ relativeDestination: string;
30
+ content: string;
31
+ }
32
+
33
+ export interface InstallPlan {
34
+ writes: PlannedWrite[];
35
+ skipped: PlannedWrite[];
36
+ dependencies: string[];
37
+ conflicts: string[];
38
+ }
39
+
40
+ const SAFE_ITEM_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
41
+ const SAFE_FILE_BASENAME = /^[A-Za-z0-9._-]+$/;
42
+ const REWRITE_EXTENSIONS = /\.(tsx?|jsx?|mts?|cts?)$/;
43
+ const USE_CLIENT_DIRECTIVE = /^\s*["']use client["'];?\r?\n\r?\n?/;
44
+
45
+ function collectRegistryDependencies(
46
+ targets: string[],
47
+ itemsByName: ReadonlyMap<string, RegistryItem>
48
+ ): string[] {
49
+ const planned = new Set<string>();
50
+ const ordered: string[] = [];
51
+
52
+ const visit = (name: string): void => {
53
+ if (planned.has(name)) {
54
+ return;
55
+ }
56
+ const item = itemsByName.get(name);
57
+ if (!item) {
58
+ return;
59
+ }
60
+ planned.add(name);
61
+ for (const dependency of [...item.registryDependencies].sort()) {
62
+ visit(dependency);
63
+ }
64
+ ordered.push(name);
65
+ };
66
+
67
+ for (const target of targets) {
68
+ visit(target);
69
+ }
70
+ return ordered;
71
+ }
72
+
73
+ function relativeDisplayPath(root: string, destination: string): string {
74
+ return path.relative(root, destination).split(path.sep).join("/");
75
+ }
76
+
77
+ function extensionOf(alias: string): string {
78
+ return path.extname(alias);
79
+ }
80
+
81
+ function transformSourceContent(options: {
82
+ content: string;
83
+ sourcePath: string;
84
+ destPath: string;
85
+ sourceToDest: ReadonlyMap<string, string>;
86
+ root: string;
87
+ rsc: boolean;
88
+ tsconfigPaths: TsconfigPathMapping | null;
89
+ }): string {
90
+ let result = rewriteRelativeImports({
91
+ content: options.content,
92
+ sourcePath: options.sourcePath,
93
+ destPath: options.destPath,
94
+ sourceToDest: options.sourceToDest,
95
+ root: options.root,
96
+ tsconfigPaths: options.tsconfigPaths,
97
+ });
98
+ if (!options.rsc) {
99
+ result = result.replace(USE_CLIENT_DIRECTIVE, "");
100
+ }
101
+ return result;
102
+ }
103
+
104
+ /**
105
+ * Build every destination and its rewritten content before touching the
106
+ * filesystem. Unknown items, unsafe destinations, directory collisions, and
107
+ * conflicts on explicitly requested items are detected before any write.
108
+ * Existing transitive registry dependencies are skipped rather than failing
109
+ * subsequent installs.
110
+ */
111
+ export function buildInstallPlan(options: {
112
+ registry: Registry;
113
+ config: UsalytConfig;
114
+ root: string;
115
+ targets: string[];
116
+ overwrite: boolean;
117
+ tsconfigPaths?: TsconfigPathMapping | null;
118
+ }): InstallPlan {
119
+ const { registry, config, root, targets, overwrite } = options;
120
+ const tsconfigPaths =
121
+ options.tsconfigPaths !== undefined
122
+ ? options.tsconfigPaths
123
+ : detectTsconfigPathMapping(root);
124
+ const requestedSet = new Set(targets);
125
+ const itemsByName = new Map(registry.items.map((item) => [item.name, item]));
126
+ const unknown = targets.filter((target) => !itemsByName.has(target));
127
+ if (unknown.length > 0) {
128
+ throw new UnknownItemsError(unknown);
129
+ }
130
+
131
+ const plannedNames = collectRegistryDependencies(targets, itemsByName);
132
+ const componentsDir = resolveAliasWithinRoot(
133
+ root,
134
+ config.aliases.components,
135
+ "components",
136
+ tsconfigPaths
137
+ );
138
+ const blocksDir = config.aliases.blocks
139
+ ? resolveAliasWithinRoot(root, config.aliases.blocks, "blocks", tsconfigPaths)
140
+ : componentsDir;
141
+
142
+ const utilsAlias = config.aliases.utils;
143
+ let utilsDestination = resolveAliasWithinRoot(root, utilsAlias, "utils", tsconfigPaths);
144
+ const utilsExtension = extensionOf(utilsAlias);
145
+ if (utilsExtension === "") {
146
+ utilsDestination = `${utilsDestination}.ts`;
147
+ assertWithinRoot(root, utilsDestination, "utils");
148
+ }
149
+
150
+ const cssEntryRelative = (config.tailwind?.css || "src/styles/globals.css")
151
+ .replace(/\\/g, "/")
152
+ .replace(/^\.?\//, "");
153
+ const themeDestination = path.join(
154
+ path.dirname(path.resolve(root, cssEntryRelative)),
155
+ "usalyt-theme.css"
156
+ );
157
+
158
+ const sourceToDest = new Map<string, string>();
159
+ const destinationOwner = new Map<string, { sourcePath: string; itemName: string }>();
160
+
161
+ for (const name of plannedNames) {
162
+ const item = itemsByName.get(name)!;
163
+ if (!SAFE_ITEM_NAME.test(item.name)) {
164
+ throw new UnsupportedItemError(
165
+ `Registry item "${item.name}" has an unsafe name and cannot be installed.`
166
+ );
167
+ }
168
+
169
+ for (const file of item.files) {
170
+ const baseName = path.posix.basename(file.path);
171
+ if (!SAFE_FILE_BASENAME.test(baseName) || baseName === "." || baseName === "..") {
172
+ throw new UnsupportedItemError(
173
+ `Registry item "${item.name}" contains an unsafe file path: ${file.path}`
174
+ );
175
+ }
176
+
177
+ let destination: string;
178
+ if (file.path.startsWith("lib/")) {
179
+ if (item.name !== "utils") {
180
+ throw new UnsupportedItemError(
181
+ `Registry item "${item.name}" targets the shared lib directory, which is reserved for the "utils" item.`
182
+ );
183
+ }
184
+ destination = utilsDestination;
185
+ } else if (file.path.startsWith("styles/")) {
186
+ destination = themeDestination;
187
+ } else if (item.type === "registry:block") {
188
+ destination = path.join(blocksDir, item.name, baseName);
189
+ } else {
190
+ destination = path.join(componentsDir, item.name, baseName);
191
+ }
192
+
193
+ assertWithinRoot(root, destination, `"${item.name}"`);
194
+
195
+ const owner = destinationOwner.get(destination);
196
+ if (owner !== undefined && owner.sourcePath !== file.path) {
197
+ throw new UnsupportedItemError(
198
+ `Registry files "${owner.sourcePath}" and "${file.path}" resolve to the same destination: ${destination}`
199
+ );
200
+ }
201
+ destinationOwner.set(destination, { sourcePath: file.path, itemName: item.name });
202
+ sourceToDest.set(file.path, destination);
203
+ }
204
+ }
205
+
206
+ const conflicts: string[] = [];
207
+ const skippedDestinations = new Set<string>();
208
+
209
+ for (const [destination, owner] of destinationOwner.entries()) {
210
+ let entry;
211
+ try {
212
+ entry = lstatSync(destination);
213
+ } catch {
214
+ continue;
215
+ }
216
+
217
+ if (entry.isSymbolicLink()) {
218
+ let realDestination: string;
219
+ try {
220
+ realDestination = realpathSync(destination);
221
+ } catch {
222
+ throw new UnsupportedItemError(
223
+ `Cannot write "${destination}" because it is a symbolic link with a missing target.`
224
+ );
225
+ }
226
+ const realRoot = realpathSync(root);
227
+ if (!isWithinRoot(realRoot, realDestination)) {
228
+ throw new UnsafePathError(
229
+ owner.sourcePath,
230
+ destination,
231
+ `The destination "${destination}" resolves outside the consumer root ${root} through a symbolic link.`
232
+ );
233
+ }
234
+ }
235
+
236
+ if (entry.isDirectory()) {
237
+ throw new UnsupportedItemError(
238
+ `Cannot write "${destination}" because a directory already exists at that path.`
239
+ );
240
+ }
241
+ if (!overwrite) {
242
+ if (requestedSet.has(owner.itemName)) {
243
+ conflicts.push(relativeDisplayPath(root, destination));
244
+ } else {
245
+ skippedDestinations.add(destination);
246
+ }
247
+ }
248
+ }
249
+
250
+ const rsc = config.rsc !== false;
251
+ const writes: PlannedWrite[] = [];
252
+ const skipped: PlannedWrite[] = [];
253
+
254
+ for (const name of plannedNames) {
255
+ const item = itemsByName.get(name)!;
256
+ for (const file of item.files) {
257
+ const destination = sourceToDest.get(file.path)!;
258
+ const content = REWRITE_EXTENSIONS.test(file.path)
259
+ ? transformSourceContent({
260
+ content: file.content,
261
+ sourcePath: file.path,
262
+ destPath: destination,
263
+ sourceToDest,
264
+ root,
265
+ rsc,
266
+ tsconfigPaths,
267
+ })
268
+ : file.content;
269
+ const planned: PlannedWrite = {
270
+ item: item.name,
271
+ destination,
272
+ relativeDestination: relativeDisplayPath(root, destination),
273
+ content,
274
+ };
275
+ if (skippedDestinations.has(destination)) {
276
+ skipped.push(planned);
277
+ } else {
278
+ writes.push(planned);
279
+ }
280
+ }
281
+ }
282
+
283
+ const dependencies = new Set<string>();
284
+ for (const name of plannedNames) {
285
+ const item = itemsByName.get(name)!;
286
+ for (const dependency of item.dependencies) {
287
+ dependencies.add(dependency);
288
+ }
289
+ }
290
+
291
+ return {
292
+ writes,
293
+ skipped,
294
+ dependencies: [...dependencies].sort(),
295
+ conflicts: conflicts.sort(),
296
+ };
297
+ }
@@ -0,0 +1,7 @@
1
+ import pc from "picocolors";
2
+
3
+ /** Print an actionable error to stderr and mark the process as failed. */
4
+ export function printError(message: string): void {
5
+ console.error(pc.red(`usalyt: ${message}`));
6
+ process.exitCode = 1;
7
+ }
@@ -0,0 +1,125 @@
1
+ import { existsSync, realpathSync } from "node:fs";
2
+ import path from "node:path";
3
+ import type { TsconfigPathMapping } from "./project";
4
+
5
+ export class UnsafePathError extends Error {
6
+ readonly destination: string;
7
+ readonly alias: string;
8
+
9
+ constructor(alias: string, destination: string, message: string) {
10
+ super(message);
11
+ this.name = "UnsafePathError";
12
+ this.alias = alias;
13
+ this.destination = destination;
14
+ }
15
+ }
16
+
17
+ const WINDOWS_ABSOLUTE = /^[A-Za-z]:[\\/]/;
18
+
19
+ /** Strip the configured prefix (or `@/`/`~/`) and return the root-relative alias path. */
20
+ export function aliasToRelativePath(
21
+ alias: string,
22
+ label: string,
23
+ tsconfigPaths?: TsconfigPathMapping | null
24
+ ): string {
25
+ if (typeof alias !== "string" || alias.trim() === "") {
26
+ throw new UnsafePathError(alias, "", `The ${label} alias must be a non-empty string.`);
27
+ }
28
+
29
+ const original = alias.trim();
30
+ let value = original;
31
+ let matchedPrefix: string | null = null;
32
+ if (tsconfigPaths && value.startsWith(tsconfigPaths.prefix)) {
33
+ matchedPrefix = tsconfigPaths.prefix;
34
+ value = value.slice(tsconfigPaths.prefix.length);
35
+ } else if (value.startsWith("@/") || value.startsWith("~/")) {
36
+ matchedPrefix = value.slice(0, 2);
37
+ value = value.slice(2);
38
+ }
39
+
40
+ if (value.includes("\0")) {
41
+ throw new UnsafePathError(
42
+ original,
43
+ "",
44
+ `The ${label} alias contains a null byte and cannot be used.`
45
+ );
46
+ }
47
+ if (path.isAbsolute(value) || WINDOWS_ABSOLUTE.test(value)) {
48
+ throw new UnsafePathError(
49
+ original,
50
+ value,
51
+ `The ${label} alias "${original}" is absolute. Aliases must resolve inside the consumer root.`
52
+ );
53
+ }
54
+
55
+ if (
56
+ matchedPrefix &&
57
+ tsconfigPaths &&
58
+ matchedPrefix === tsconfigPaths.prefix &&
59
+ tsconfigPaths.targetDir !== "" &&
60
+ value !== tsconfigPaths.targetDir &&
61
+ !value.startsWith(`${tsconfigPaths.targetDir}/`)
62
+ ) {
63
+ value = path.posix.join(tsconfigPaths.targetDir, value);
64
+ }
65
+
66
+ return value === "" ? "." : value;
67
+ }
68
+
69
+ export function isWithinRoot(root: string, destination: string): boolean {
70
+ const relative = path.relative(root, destination);
71
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
72
+ }
73
+
74
+ /**
75
+ * Resolve an existing ancestor through `realpath` and append the missing
76
+ * segments, so a symlinked parent that points outside the root is detected
77
+ * before any directory or file is created.
78
+ */
79
+ function realpathAllowMissing(target: string): string {
80
+ let current = target;
81
+ const missing: string[] = [];
82
+ while (!existsSync(current)) {
83
+ const parent = path.dirname(current);
84
+ if (parent === current) {
85
+ break;
86
+ }
87
+ missing.unshift(path.basename(current));
88
+ current = parent;
89
+ }
90
+ const base = existsSync(current) ? realpathSync(current) : current;
91
+ return path.join(base, ...missing);
92
+ }
93
+
94
+ export function assertWithinRoot(root: string, destination: string, label: string): void {
95
+ if (!isWithinRoot(root, destination)) {
96
+ throw new UnsafePathError(
97
+ label,
98
+ destination,
99
+ `The ${label} destination "${destination}" resolves outside the consumer root ${root}.`
100
+ );
101
+ }
102
+
103
+ const realRoot = realpathSync(root);
104
+ const realDestination = realpathAllowMissing(destination);
105
+ if (!isWithinRoot(realRoot, realDestination)) {
106
+ throw new UnsafePathError(
107
+ label,
108
+ destination,
109
+ `The ${label} destination "${destination}" resolves outside the consumer root ${root} through a symbolic link.`
110
+ );
111
+ }
112
+ }
113
+
114
+ /** Resolve a configured alias against the consumer root and enforce containment. */
115
+ export function resolveAliasWithinRoot(
116
+ root: string,
117
+ alias: string,
118
+ label: string,
119
+ tsconfigPaths?: TsconfigPathMapping | null
120
+ ): string {
121
+ const relative = aliasToRelativePath(alias, label, tsconfigPaths);
122
+ const destination = path.resolve(root, relative);
123
+ assertWithinRoot(root, destination, label);
124
+ return destination;
125
+ }
@@ -0,0 +1,218 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { assertWithinRoot } from "./paths";
4
+
5
+ export type PackageManager = "pnpm" | "npm" | "yarn" | "bun";
6
+
7
+ export interface TsconfigPathMapping {
8
+ prefix: string;
9
+ targetDir: string;
10
+ }
11
+
12
+ const CSS_CANDIDATES = [
13
+ "src/index.css",
14
+ "src/app/globals.css",
15
+ "app/globals.css",
16
+ "src/styles/globals.css",
17
+ "src/globals.css",
18
+ ];
19
+
20
+ /** Detect the consumer's package manager from lockfiles (defaults to pnpm). */
21
+ export function detectPackageManager(root: string): PackageManager {
22
+ if (existsSync(path.join(root, "pnpm-lock.yaml"))) return "pnpm";
23
+ if (existsSync(path.join(root, "bun.lock")) || existsSync(path.join(root, "bun.lockb"))) {
24
+ return "bun";
25
+ }
26
+ if (existsSync(path.join(root, "yarn.lock"))) return "yarn";
27
+ if (existsSync(path.join(root, "package-lock.json"))) return "npm";
28
+ return "pnpm";
29
+ }
30
+
31
+ /** Build the shell command to add npm dependencies with the detected package manager. */
32
+ export function formatInstallCommand(pm: PackageManager, dependencies: string[]): string {
33
+ const args = formatInstallArgs(pm, dependencies);
34
+ return `${pm} ${args.join(" ")}`;
35
+ }
36
+
37
+ export function formatInstallArgs(pm: PackageManager, dependencies: string[]): string[] {
38
+ if (pm === "npm") {
39
+ return ["install", ...dependencies];
40
+ }
41
+ return ["add", ...dependencies];
42
+ }
43
+
44
+ /** Read dependency names already declared in the consumer's package.json. */
45
+ export function readInstalledDependencies(root: string): Set<string> {
46
+ const pkgPath = path.join(root, "package.json");
47
+ if (!existsSync(pkgPath)) {
48
+ return new Set();
49
+ }
50
+ try {
51
+ const parsed = JSON.parse(readFileSync(pkgPath, "utf8")) as Record<string, unknown>;
52
+ const installed = new Set<string>();
53
+ for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
54
+ const group = parsed[field];
55
+ if (group && typeof group === "object" && !Array.isArray(group)) {
56
+ for (const name of Object.keys(group as Record<string, unknown>)) {
57
+ installed.add(name);
58
+ }
59
+ }
60
+ }
61
+ return installed;
62
+ } catch {
63
+ return new Set();
64
+ }
65
+ }
66
+
67
+ function stripJsonCommentsAndTrailingCommas(raw: string): string {
68
+ let out = "";
69
+ let inString = false;
70
+ let escaped = false;
71
+ for (let i = 0; i < raw.length; i += 1) {
72
+ const ch = raw[i];
73
+ const next = raw[i + 1];
74
+ if (inString) {
75
+ out += ch;
76
+ if (escaped) {
77
+ escaped = false;
78
+ } else if (ch === "\\") {
79
+ escaped = true;
80
+ } else if (ch === '"') {
81
+ inString = false;
82
+ }
83
+ continue;
84
+ }
85
+ if (ch === '"') {
86
+ inString = true;
87
+ out += ch;
88
+ continue;
89
+ }
90
+ if (ch === "/" && next === "/") {
91
+ while (i < raw.length && raw[i] !== "\n") i += 1;
92
+ out += "\n";
93
+ continue;
94
+ }
95
+ if (ch === "/" && next === "*") {
96
+ i += 2;
97
+ while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/")) i += 1;
98
+ i += 1;
99
+ continue;
100
+ }
101
+ out += ch;
102
+ }
103
+ return out.replace(/,\s*([}\]])/g, "$1");
104
+ }
105
+
106
+ /**
107
+ * Inspect `tsconfig.json` (and `tsconfig.app.json`) for a wildcard path alias
108
+ * such as `"@/*": ["./src/*"]` or `"~/*": ["./src/*"]`.
109
+ */
110
+ export function detectTsconfigPathMapping(root: string): TsconfigPathMapping | null {
111
+ for (const filename of ["tsconfig.json", "tsconfig.app.json"]) {
112
+ const filePath = path.join(root, filename);
113
+ if (!existsSync(filePath)) continue;
114
+ try {
115
+ const parsed = JSON.parse(
116
+ stripJsonCommentsAndTrailingCommas(readFileSync(filePath, "utf8"))
117
+ ) as {
118
+ compilerOptions?: {
119
+ baseUrl?: string;
120
+ paths?: Record<string, string[]>;
121
+ };
122
+ };
123
+ const paths = parsed.compilerOptions?.paths;
124
+ if (!paths || typeof paths !== "object") continue;
125
+
126
+ const baseUrl = parsed.compilerOptions?.baseUrl ?? ".";
127
+ for (const [pattern, targets] of Object.entries(paths)) {
128
+ if (!pattern.endsWith("/*") || !Array.isArray(targets) || targets.length === 0) {
129
+ continue;
130
+ }
131
+ const firstTarget = targets[0];
132
+ if (typeof firstTarget !== "string" || !firstTarget.endsWith("/*")) {
133
+ continue;
134
+ }
135
+ const prefix = pattern.slice(0, -1); // e.g. "@/"
136
+ const rawTarget = firstTarget.slice(0, -2); // e.g. "./src" or "."
137
+ const normalized = path.posix
138
+ .normalize(path.posix.join(baseUrl.replace(/\\/g, "/"), rawTarget.replace(/\\/g, "/")))
139
+ .replace(/^\.\/?/, "")
140
+ .replace(/\/$/, "");
141
+ return { prefix, targetDir: normalized };
142
+ }
143
+ } catch {
144
+ continue;
145
+ }
146
+ }
147
+ return null;
148
+ }
149
+
150
+ /** Detect an existing Tailwind CSS entry point, or return the default path. */
151
+ export function detectCssEntry(root: string): string {
152
+ for (const candidate of CSS_CANDIDATES) {
153
+ if (existsSync(path.join(root, candidate))) {
154
+ return candidate;
155
+ }
156
+ }
157
+ return "src/styles/globals.css";
158
+ }
159
+
160
+ export interface ThemeInjectionResult {
161
+ themeFile: string;
162
+ cssEntry: string;
163
+ cssUpdated: boolean;
164
+ }
165
+
166
+ /**
167
+ * Write `usalyt-theme.css` next to the configured Tailwind CSS entry and ensure
168
+ * that entry imports it so copied components have working design tokens without
169
+ * installing `@usalyt/ui`.
170
+ */
171
+ export function injectThemeStylesheet(options: {
172
+ root: string;
173
+ cssEntryRelative: string;
174
+ themeCss: string;
175
+ overwriteTheme?: boolean;
176
+ }): ThemeInjectionResult {
177
+ const { root, cssEntryRelative, themeCss, overwriteTheme = false } = options;
178
+ const normalizedEntry = cssEntryRelative.replace(/\\/g, "/").replace(/^\.?\//, "");
179
+ const cssEntryAbs = path.resolve(root, normalizedEntry);
180
+ assertWithinRoot(root, cssEntryAbs, "tailwind.css");
181
+
182
+ const themeFileAbs = path.join(path.dirname(cssEntryAbs), "usalyt-theme.css");
183
+ assertWithinRoot(root, themeFileAbs, "theme stylesheet");
184
+
185
+ mkdirSync(path.dirname(themeFileAbs), { recursive: true });
186
+ if (overwriteTheme || !existsSync(themeFileAbs)) {
187
+ writeFileSync(themeFileAbs, themeCss, "utf8");
188
+ }
189
+
190
+ const importStatement = '@import "./usalyt-theme.css";';
191
+ let cssUpdated = false;
192
+
193
+ if (existsSync(cssEntryAbs)) {
194
+ const existing = readFileSync(cssEntryAbs, "utf8");
195
+ if (!existing.includes("usalyt-theme.css")) {
196
+ const tailwindImport = /^@import\s+["']tailwindcss["']\s*;\s*$/m;
197
+ const updated = tailwindImport.test(existing)
198
+ ? existing.replace(tailwindImport, (line) => `${line}\n${importStatement}`)
199
+ : `${importStatement}\n${existing}`;
200
+ writeFileSync(cssEntryAbs, updated, "utf8");
201
+ cssUpdated = true;
202
+ }
203
+ } else {
204
+ mkdirSync(path.dirname(cssEntryAbs), { recursive: true });
205
+ writeFileSync(
206
+ cssEntryAbs,
207
+ `@import "tailwindcss";\n${importStatement}\n`,
208
+ "utf8"
209
+ );
210
+ cssUpdated = true;
211
+ }
212
+
213
+ return {
214
+ themeFile: path.relative(root, themeFileAbs).split(path.sep).join("/"),
215
+ cssEntry: path.relative(root, cssEntryAbs).split(path.sep).join("/"),
216
+ cssUpdated,
217
+ };
218
+ }