stera-ui 0.3.2 → 0.3.3

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.
@@ -66,14 +66,22 @@ var TYPE_TO_ALIAS = {
66
66
  };
67
67
  function resolveAlias(alias, projectRoot) {
68
68
  const tsConfig = loadConfig(projectRoot);
69
- if (tsConfig.resultType === "success") {
70
- const match = createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths);
71
- const resolved = match(alias, void 0, () => true, [".ts", ".tsx"]);
72
- if (resolved) {
73
- return path.relative(projectRoot, resolved);
69
+ if (tsConfig.resultType === "success" && Object.keys(tsConfig.paths).length > 0) {
70
+ const hasMatchingPrefix = Object.keys(tsConfig.paths).some((key) => {
71
+ const prefix = key.replace(/\/\*$/, "");
72
+ return alias === prefix || alias.startsWith(`${prefix}/`);
73
+ });
74
+ if (hasMatchingPrefix) {
75
+ const match = createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths);
76
+ const resolved = match(alias, void 0, () => true, [".ts", ".tsx"]);
77
+ if (resolved) {
78
+ return path.relative(projectRoot, resolved);
79
+ }
74
80
  }
75
81
  }
76
- return alias.replace(/^@\//, "");
82
+ throw new Error(
83
+ `Could not resolve alias "${alias}" from tsconfig.json. Ensure compilerOptions.paths defines a mapping for it (e.g. "${alias}/*"), then re-run. See https://ui.stera.sh/docs/installation.`
84
+ );
77
85
  }
78
86
  function resolveOutputPath(config, projectRoot, file) {
79
87
  const alias = TYPE_TO_ALIAS[file.type];
@@ -129,6 +137,7 @@ function loadConfig2(cwd) {
129
137
  // src/utils/detect-project.ts
130
138
  import fs2 from "fs";
131
139
  import path3 from "path";
140
+ import { loadConfig as loadConfig3 } from "tsconfig-paths";
132
141
  function hasFile(cwd, filenames) {
133
142
  return filenames.some((f) => fs2.existsSync(path3.join(cwd, f)));
134
143
  }
@@ -182,6 +191,24 @@ function detectProject(cwd) {
182
191
  }
183
192
  return { hasSrc, framework, rsc, existingCssFile, layoutFile };
184
193
  }
194
+ function detectAliasPrefix(cwd) {
195
+ let tsConfig;
196
+ try {
197
+ tsConfig = loadConfig3(cwd);
198
+ } catch {
199
+ return null;
200
+ }
201
+ if (tsConfig.resultType !== "success" || Object.keys(tsConfig.paths).length === 0) {
202
+ return null;
203
+ }
204
+ for (const [alias, targets] of Object.entries(tsConfig.paths)) {
205
+ if (targets.includes("./*") || targets.includes("./src/*") || targets.includes("./app/*")) {
206
+ return alias.replace(/\/\*$/, "");
207
+ }
208
+ }
209
+ const first = Object.keys(tsConfig.paths)[0];
210
+ return first ? first.replace(/\/\*$/, "") : null;
211
+ }
185
212
 
186
213
  // src/utils/detect-globals.ts
187
214
  import fs3 from "fs";
@@ -192,7 +219,15 @@ function hasGlobalsCss(config, projectRoot) {
192
219
  return false;
193
220
  }
194
221
  const steraPath = path4.join(path4.dirname(cssPath), "stera-ui.css");
195
- return fs3.existsSync(steraPath);
222
+ if (fs3.existsSync(steraPath)) {
223
+ return true;
224
+ }
225
+ try {
226
+ const contents = fs3.readFileSync(cssPath, "utf-8");
227
+ return contents.includes("--color-bg-surface");
228
+ } catch {
229
+ return false;
230
+ }
196
231
  }
197
232
 
198
233
  // src/utils/install-deps.ts
@@ -679,6 +714,7 @@ export {
679
714
  findConfigPath,
680
715
  loadConfig2 as loadConfig,
681
716
  detectProject,
717
+ detectAliasPrefix,
682
718
  hasGlobalsCss,
683
719
  brand,
684
720
  dim,
package/dist/cli.js CHANGED
@@ -111,14 +111,22 @@ var TYPE_TO_ALIAS = {
111
111
  };
112
112
  function resolveAlias(alias, projectRoot) {
113
113
  const tsConfig = loadConfig2(projectRoot);
114
- if (tsConfig.resultType === "success") {
115
- const match = createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths);
116
- const resolved = match(alias, void 0, () => true, [".ts", ".tsx"]);
117
- if (resolved) {
118
- return path2.relative(projectRoot, resolved);
114
+ if (tsConfig.resultType === "success" && Object.keys(tsConfig.paths).length > 0) {
115
+ const hasMatchingPrefix = Object.keys(tsConfig.paths).some((key) => {
116
+ const prefix = key.replace(/\/\*$/, "");
117
+ return alias === prefix || alias.startsWith(`${prefix}/`);
118
+ });
119
+ if (hasMatchingPrefix) {
120
+ const match = createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths);
121
+ const resolved = match(alias, void 0, () => true, [".ts", ".tsx"]);
122
+ if (resolved) {
123
+ return path2.relative(projectRoot, resolved);
124
+ }
119
125
  }
120
126
  }
121
- return alias.replace(/^@\//, "");
127
+ throw new Error(
128
+ `Could not resolve alias "${alias}" from tsconfig.json. Ensure compilerOptions.paths defines a mapping for it (e.g. "${alias}/*"), then re-run. See https://ui.stera.sh/docs/installation.`
129
+ );
122
130
  }
123
131
  function resolveOutputPath(config, projectRoot, file) {
124
132
  const alias = TYPE_TO_ALIAS[file.type];
@@ -363,7 +371,15 @@ function hasGlobalsCss(config, projectRoot) {
363
371
  return false;
364
372
  }
365
373
  const steraPath = path5.join(path5.dirname(cssPath), "stera-ui.css");
366
- return fs4.existsSync(steraPath);
374
+ if (fs4.existsSync(steraPath)) {
375
+ return true;
376
+ }
377
+ try {
378
+ const contents = fs4.readFileSync(cssPath, "utf-8");
379
+ return contents.includes("--color-bg-surface");
380
+ } catch {
381
+ return false;
382
+ }
367
383
  }
368
384
 
369
385
  // src/commands/add.ts
@@ -469,6 +485,7 @@ import { select } from "@inquirer/prompts";
469
485
  // src/utils/detect-project.ts
470
486
  import fs5 from "fs";
471
487
  import path7 from "path";
488
+ import { loadConfig as loadConfig3 } from "tsconfig-paths";
472
489
  function hasFile(cwd, filenames) {
473
490
  return filenames.some((f) => fs5.existsSync(path7.join(cwd, f)));
474
491
  }
@@ -522,6 +539,24 @@ function detectProject(cwd) {
522
539
  }
523
540
  return { hasSrc, framework, rsc, existingCssFile, layoutFile };
524
541
  }
542
+ function detectAliasPrefix(cwd) {
543
+ let tsConfig;
544
+ try {
545
+ tsConfig = loadConfig3(cwd);
546
+ } catch {
547
+ return null;
548
+ }
549
+ if (tsConfig.resultType !== "success" || Object.keys(tsConfig.paths).length === 0) {
550
+ return null;
551
+ }
552
+ for (const [alias, targets] of Object.entries(tsConfig.paths)) {
553
+ if (targets.includes("./*") || targets.includes("./src/*") || targets.includes("./app/*")) {
554
+ return alias.replace(/\/\*$/, "");
555
+ }
556
+ }
557
+ const first = Object.keys(tsConfig.paths)[0];
558
+ return first ? first.replace(/\/\*$/, "") : null;
559
+ }
525
560
 
526
561
  // src/utils/detect-fonts.ts
527
562
  import fs6 from "fs";
@@ -954,7 +989,7 @@ function parseTemplateLiteralToCnArgs(templateLiteral) {
954
989
 
955
990
  // src/commands/init.ts
956
991
  var DEFAULT_FONT_NAMES = ["font-geist", "font-geist-mono"];
957
- function buildConfig(project, strategy) {
992
+ function buildConfig(project, strategy, aliasPrefix) {
958
993
  let cssPath;
959
994
  if (project.existingCssFile) {
960
995
  cssPath = project.existingCssFile;
@@ -968,11 +1003,11 @@ function buildConfig(project, strategy) {
968
1003
  version: 1,
969
1004
  css: cssPath,
970
1005
  aliases: {
971
- components: "@/components",
972
- utils: "@/lib/utils",
973
- ui: "@/components/ui",
974
- lib: "@/lib",
975
- hooks: "@/hooks"
1006
+ components: `${aliasPrefix}/components`,
1007
+ utils: `${aliasPrefix}/lib/utils`,
1008
+ ui: `${aliasPrefix}/components/ui`,
1009
+ lib: `${aliasPrefix}/lib`,
1010
+ hooks: `${aliasPrefix}/hooks`
976
1011
  },
977
1012
  fonts: {
978
1013
  strategy
@@ -1149,6 +1184,19 @@ async function init(options) {
1149
1184
  process.exit(1);
1150
1185
  }
1151
1186
  const project = detectProject(cwd);
1187
+ const aliasPrefix = detectAliasPrefix(cwd);
1188
+ if (!aliasPrefix) {
1189
+ console.error("");
1190
+ console.error(" Error: No import alias found in your tsconfig.json file.");
1191
+ console.error(
1192
+ ' Stera UI requires a path alias (e.g. "@/*": ["./src/*"]) in compilerOptions.paths.'
1193
+ );
1194
+ console.error(
1195
+ " See https://ui.stera.sh/docs/installation for setup instructions per framework."
1196
+ );
1197
+ console.error("");
1198
+ process.exit(1);
1199
+ }
1152
1200
  const frameworkName = project.framework === "next" ? "Next.js" : project.framework === "vite" ? "Vite" : null;
1153
1201
  const parts = [];
1154
1202
  if (frameworkName) parts.push(frameworkName);
@@ -1162,7 +1210,7 @@ async function init(options) {
1162
1210
  detectedFonts,
1163
1211
  options.yes ?? false
1164
1212
  );
1165
- const config = buildConfig(project, strategy);
1213
+ const config = buildConfig(project, strategy, aliasPrefix);
1166
1214
  const configPath = path10.join(cwd, CONFIG_FILE);
1167
1215
  fs9.writeFileSync(
1168
1216
  configPath,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { fetchRegistryIndex, fetchRegistryItem, getAllComponents, getComponent, resolveDependencies } from './registry/index.js';
2
2
  export { RegistryFontItem, RegistryIndex, RegistryItem, RegistryItemFile, RegistryItemFont, RegistryItemType, SteraConfig, configSchema, registryIndexSchema, registryItemFileSchema, registryItemFontSchema, registryItemSchema, registryItemTypeSchema } from './schema/index.js';
3
- export { CHECK, CONFIG_FILE, CROSS, LOGO, ProjectInfo, TransformContext, TransformFn, WARN, WriteOptions, WriteResult, applyTransforms, brand, createSpinner, detectPackageManager, detectProject, dim, findConfigPath, hasGlobalsCss, installDependencies, loadConfig, massageTreeForFonts, resolveOutputPath, transformImports, updateFonts, writeComponentFiles } from './utils/index.js';
3
+ export { CHECK, CONFIG_FILE, CROSS, LOGO, ProjectInfo, TransformContext, TransformFn, WARN, WriteOptions, WriteResult, applyTransforms, brand, createSpinner, detectAliasPrefix, detectPackageManager, detectProject, dim, findConfigPath, hasGlobalsCss, installDependencies, loadConfig, massageTreeForFonts, resolveOutputPath, transformImports, updateFonts, writeComponentFiles } from './utils/index.js';
4
4
  import 'zod';
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  applyTransforms,
23
23
  brand,
24
24
  createSpinner,
25
+ detectAliasPrefix,
25
26
  detectPackageManager,
26
27
  detectProject,
27
28
  dim,
@@ -34,7 +35,7 @@ import {
34
35
  transformImports,
35
36
  updateFonts,
36
37
  writeComponentFiles
37
- } from "./chunk-26HP67ZM.js";
38
+ } from "./chunk-QD7FOI3A.js";
38
39
  export {
39
40
  CHECK,
40
41
  CONFIG_FILE,
@@ -45,6 +46,7 @@ export {
45
46
  brand,
46
47
  configSchema,
47
48
  createSpinner,
49
+ detectAliasPrefix,
48
50
  detectPackageManager,
49
51
  detectProject,
50
52
  dim,
@@ -67,10 +67,21 @@ interface ProjectInfo {
67
67
  * - Existing Tailwind CSS entry file
68
68
  */
69
69
  declare function detectProject(cwd: string): ProjectInfo;
70
+ /**
71
+ * Detect the alias prefix (e.g. "@" or "~") from the project's tsconfig.json
72
+ * `compilerOptions.paths`. Mirrors shadcn's approach.
73
+ *
74
+ * Returns null when tsconfig can't be loaded or defines no path mappings —
75
+ * `init` should surface a clear error in that case rather than templating
76
+ * aliases that won't resolve.
77
+ */
78
+ declare function detectAliasPrefix(cwd: string): string | null;
70
79
 
71
80
  /**
72
81
  * Check if Stera has already been initialised in the user's project.
73
- * Looks for the presence of `stera-ui.css` alongside the user's CSS file.
82
+ * Returns true if either a sibling `stera-ui.css` exists (existing-CSS init
83
+ * path) or the user's CSS file itself contains Stera tokens inline
84
+ * (no-existing-CSS init path, or a hand-rolled setup).
74
85
  */
75
86
  declare function hasGlobalsCss(config: SteraConfig, projectRoot: string): boolean;
76
87
 
@@ -132,4 +143,4 @@ declare function updateFonts(fonts: RegistryFontItem[], project: ProjectInfo, cw
132
143
  silent?: boolean;
133
144
  }): Promise<void>;
134
145
 
135
- export { CHECK, CONFIG_FILE, CROSS, LOGO, type ProjectInfo, type TransformContext, type TransformFn, WARN, type WriteOptions, type WriteResult, applyTransforms, brand, createSpinner, detectPackageManager, detectProject, dim, findConfigPath, hasGlobalsCss, installDependencies, loadConfig, massageTreeForFonts, resolveOutputPath, transformImports, updateFonts, writeComponentFiles };
146
+ export { CHECK, CONFIG_FILE, CROSS, LOGO, type ProjectInfo, type TransformContext, type TransformFn, WARN, type WriteOptions, type WriteResult, applyTransforms, brand, createSpinner, detectAliasPrefix, detectPackageManager, detectProject, dim, findConfigPath, hasGlobalsCss, installDependencies, loadConfig, massageTreeForFonts, resolveOutputPath, transformImports, updateFonts, writeComponentFiles };
@@ -7,6 +7,7 @@ import {
7
7
  applyTransforms,
8
8
  brand,
9
9
  createSpinner,
10
+ detectAliasPrefix,
10
11
  detectPackageManager,
11
12
  detectProject,
12
13
  dim,
@@ -19,7 +20,7 @@ import {
19
20
  transformImports,
20
21
  updateFonts,
21
22
  writeComponentFiles
22
- } from "../chunk-26HP67ZM.js";
23
+ } from "../chunk-QD7FOI3A.js";
23
24
  export {
24
25
  CHECK,
25
26
  CONFIG_FILE,
@@ -29,6 +30,7 @@ export {
29
30
  applyTransforms,
30
31
  brand,
31
32
  createSpinner,
33
+ detectAliasPrefix,
32
34
  detectPackageManager,
33
35
  detectProject,
34
36
  dim,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stera-ui",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "description": "Add Stera UI components to your project.",
6
6
  "license": "MIT",