shadcn-svelte 0.5.0 → 0.6.1

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/index.js CHANGED
@@ -4,9 +4,9 @@
4
4
  import { Command as Command4 } from "commander";
5
5
 
6
6
  // src/commands/add.ts
7
- import { existsSync as existsSync3, promises as fs2 } from "fs";
8
- import path4 from "path";
9
- import chalk2 from "chalk";
7
+ import { existsSync as existsSync2, promises as fs6 } from "fs";
8
+ import path10 from "path";
9
+ import chalk3 from "chalk";
10
10
  import { Command } from "commander";
11
11
  import { execa as execa3 } from "execa";
12
12
  import ora from "ora";
@@ -14,13 +14,447 @@ import prompts2 from "prompts";
14
14
  import { z as z3 } from "zod";
15
15
 
16
16
  // src/utils/get-config.ts
17
- import { existsSync as existsSync2 } from "fs";
18
- import { readFile } from "fs/promises";
19
- import path2 from "path";
17
+ import { promises as fs5 } from "fs";
18
+ import path8 from "path";
19
+ import chalk2 from "chalk";
20
20
  import { execa as execa2 } from "execa";
21
- import { loadConfig } from "tsconfig-paths";
21
+
22
+ // node_modules/.pnpm/tsconfck@2.1.2_typescript@5.3.3/node_modules/tsconfck/dist/index.js
23
+ import path2 from "path";
24
+ import path3 from "path";
25
+ import { promises as fs2 } from "fs";
26
+ import path5 from "path";
27
+ import path6 from "path";
28
+ var sep = path2.sep;
29
+ var singleComment = Symbol("singleComment");
30
+ var multiComment = Symbol("multiComment");
31
+ var POSIX_SEP_RE = new RegExp("\\" + path3.posix.sep, "g");
32
+ var NATIVE_SEP_RE = new RegExp("\\" + path3.sep, "g");
33
+ var PATTERN_REGEX_CACHE = /* @__PURE__ */ new Map();
34
+ var GLOB_ALL_PATTERN = `**/*`;
35
+ var DEFAULT_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
36
+ var DEFAULT_EXTENSIONS_RE_GROUP = `\\.(?:${DEFAULT_EXTENSIONS.map((ext) => ext.substring(1)).join(
37
+ "|"
38
+ )})`;
39
+ var dynamicImportDefault = new Function("path", "return import(path).then(m => m.default)");
40
+ async function loadTS() {
41
+ try {
42
+ return dynamicImportDefault("typescript");
43
+ } catch (e) {
44
+ console.error('typescript must be installed to use "native" functions');
45
+ throw e;
46
+ }
47
+ }
48
+ async function resolveTSConfig(filename) {
49
+ if (path3.extname(filename) !== ".json") {
50
+ return;
51
+ }
52
+ const tsconfig = path3.resolve(filename);
53
+ try {
54
+ const stat = await fs2.stat(tsconfig);
55
+ if (stat.isFile() || stat.isFIFO()) {
56
+ return tsconfig;
57
+ }
58
+ } catch (e) {
59
+ if (e.code !== "ENOENT") {
60
+ throw e;
61
+ }
62
+ }
63
+ throw new Error(`no tsconfig file found for ${filename}`);
64
+ }
65
+ function posix2native(filename) {
66
+ return path3.posix.sep !== path3.sep && filename.includes(path3.posix.sep) ? filename.replace(POSIX_SEP_RE, path3.sep) : filename;
67
+ }
68
+ function native2posix(filename) {
69
+ return path3.posix.sep !== path3.sep && filename.includes(path3.sep) ? filename.replace(NATIVE_SEP_RE, path3.posix.sep) : filename;
70
+ }
71
+ function resolve2posix(dir, filename) {
72
+ if (path3.sep === path3.posix.sep) {
73
+ return dir ? path3.resolve(dir, filename) : path3.resolve(filename);
74
+ }
75
+ return native2posix(
76
+ dir ? path3.resolve(posix2native(dir), posix2native(filename)) : path3.resolve(posix2native(filename))
77
+ );
78
+ }
79
+ function resolveReferencedTSConfigFiles(result) {
80
+ const dir = path3.dirname(result.tsconfigFile);
81
+ return result.tsconfig.references.map((ref) => {
82
+ const refPath = ref.path.endsWith(".json") ? ref.path : path3.join(ref.path, "tsconfig.json");
83
+ return resolve2posix(dir, refPath);
84
+ });
85
+ }
86
+ function resolveSolutionTSConfig(filename, result) {
87
+ if (result.referenced && DEFAULT_EXTENSIONS.some((ext) => filename.endsWith(ext)) && !isIncluded(filename, result)) {
88
+ const solutionTSConfig = result.referenced.find(
89
+ (referenced) => isIncluded(filename, referenced)
90
+ );
91
+ if (solutionTSConfig) {
92
+ return {
93
+ ...solutionTSConfig,
94
+ solution: result
95
+ };
96
+ }
97
+ }
98
+ return result;
99
+ }
100
+ function isIncluded(filename, result) {
101
+ const dir = native2posix(path3.dirname(result.tsconfigFile));
102
+ const files = (result.tsconfig.files || []).map((file) => resolve2posix(dir, file));
103
+ const absoluteFilename = resolve2posix(null, filename);
104
+ if (files.includes(filename)) {
105
+ return true;
106
+ }
107
+ const isIncluded2 = isGlobMatch(
108
+ absoluteFilename,
109
+ dir,
110
+ result.tsconfig.include || (result.tsconfig.files ? [] : [GLOB_ALL_PATTERN])
111
+ );
112
+ if (isIncluded2) {
113
+ const isExcluded = isGlobMatch(absoluteFilename, dir, result.tsconfig.exclude || []);
114
+ return !isExcluded;
115
+ }
116
+ return false;
117
+ }
118
+ function isGlobMatch(filename, dir, patterns) {
119
+ return patterns.some((pattern) => {
120
+ let lastWildcardIndex = pattern.length;
121
+ let hasWildcard = false;
122
+ for (let i = pattern.length - 1; i > -1; i--) {
123
+ if (pattern[i] === "*" || pattern[i] === "?") {
124
+ lastWildcardIndex = i;
125
+ hasWildcard = true;
126
+ break;
127
+ }
128
+ }
129
+ if (lastWildcardIndex < pattern.length - 1 && !filename.endsWith(pattern.slice(lastWildcardIndex + 1))) {
130
+ return false;
131
+ }
132
+ if (pattern.endsWith("*") && !DEFAULT_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
133
+ return false;
134
+ }
135
+ if (pattern === GLOB_ALL_PATTERN) {
136
+ return filename.startsWith(`${dir}/`);
137
+ }
138
+ const resolvedPattern = resolve2posix(dir, pattern);
139
+ let firstWildcardIndex = -1;
140
+ for (let i = 0; i < resolvedPattern.length; i++) {
141
+ if (resolvedPattern[i] === "*" || resolvedPattern[i] === "?") {
142
+ firstWildcardIndex = i;
143
+ hasWildcard = true;
144
+ break;
145
+ }
146
+ }
147
+ if (firstWildcardIndex > 1 && !filename.startsWith(resolvedPattern.slice(0, firstWildcardIndex - 1))) {
148
+ return false;
149
+ }
150
+ if (!hasWildcard) {
151
+ return filename === resolvedPattern;
152
+ }
153
+ if (PATTERN_REGEX_CACHE.has(resolvedPattern)) {
154
+ return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
155
+ }
156
+ const regex2 = pattern2regex(resolvedPattern);
157
+ PATTERN_REGEX_CACHE.set(resolvedPattern, regex2);
158
+ return regex2.test(filename);
159
+ });
160
+ }
161
+ function pattern2regex(resolvedPattern) {
162
+ let regexStr = "^";
163
+ for (let i = 0; i < resolvedPattern.length; i++) {
164
+ const char = resolvedPattern[i];
165
+ if (char === "?") {
166
+ regexStr += "[^\\/]";
167
+ continue;
168
+ }
169
+ if (char === "*") {
170
+ if (resolvedPattern[i + 1] === "*" && resolvedPattern[i + 2] === "/") {
171
+ i += 2;
172
+ regexStr += "(?:[^\\/]*\\/)*";
173
+ continue;
174
+ }
175
+ regexStr += "[^\\/]*";
176
+ continue;
177
+ }
178
+ if ("/.+^${}()|[]\\".includes(char)) {
179
+ regexStr += `\\`;
180
+ }
181
+ regexStr += char;
182
+ }
183
+ if (resolvedPattern.endsWith("*")) {
184
+ regexStr += DEFAULT_EXTENSIONS_RE_GROUP;
185
+ }
186
+ regexStr += "$";
187
+ return new RegExp(regexStr);
188
+ }
189
+ async function findNative(filename) {
190
+ const ts = await loadTS();
191
+ const { findConfigFile, sys } = ts;
192
+ const tsconfigFile = findConfigFile(path5.dirname(path5.resolve(filename)), sys.fileExists);
193
+ if (!tsconfigFile) {
194
+ throw new Error(`no tsconfig file found for ${filename}`);
195
+ }
196
+ return tsconfigFile;
197
+ }
198
+ async function parseNative(filename, options) {
199
+ const cache = options == null ? void 0 : options.cache;
200
+ if (cache == null ? void 0 : cache.has(filename)) {
201
+ return cache.get(filename);
202
+ }
203
+ let tsconfigFile;
204
+ if (options == null ? void 0 : options.resolveWithEmptyIfConfigNotFound) {
205
+ try {
206
+ tsconfigFile = await resolveTSConfig(filename);
207
+ if (!tsconfigFile) {
208
+ tsconfigFile = await findNative(filename);
209
+ }
210
+ } catch (e) {
211
+ const notFoundResult = {
212
+ tsconfigFile: "no_tsconfig_file_found",
213
+ tsconfig: {},
214
+ result: null
215
+ };
216
+ cache == null ? void 0 : cache.set(filename, notFoundResult);
217
+ return notFoundResult;
218
+ }
219
+ } else {
220
+ tsconfigFile = await resolveTSConfig(filename);
221
+ if (!tsconfigFile) {
222
+ tsconfigFile = await findNative(filename);
223
+ }
224
+ }
225
+ let result;
226
+ if (cache == null ? void 0 : cache.has(tsconfigFile)) {
227
+ result = cache.get(tsconfigFile);
228
+ } else {
229
+ const ts = await loadTS();
230
+ result = await parseFile2(tsconfigFile, ts, options);
231
+ await parseReferences2(result, ts, options);
232
+ cache == null ? void 0 : cache.set(tsconfigFile, result);
233
+ }
234
+ result = resolveSolutionTSConfig(filename, result);
235
+ cache == null ? void 0 : cache.set(filename, result);
236
+ return result;
237
+ }
238
+ async function parseFile2(tsconfigFile, ts, options) {
239
+ const cache = options == null ? void 0 : options.cache;
240
+ if (cache == null ? void 0 : cache.has(tsconfigFile)) {
241
+ return cache.get(tsconfigFile);
242
+ }
243
+ const posixTSConfigFile = native2posix(tsconfigFile);
244
+ const { parseJsonConfigFileContent, readConfigFile, sys } = ts;
245
+ const { config, error } = readConfigFile(posixTSConfigFile, sys.readFile);
246
+ if (error) {
247
+ throw new TSConfckParseNativeError(error, tsconfigFile, null);
248
+ }
249
+ const host = {
250
+ useCaseSensitiveFileNames: false,
251
+ readDirectory: sys.readDirectory,
252
+ fileExists: sys.fileExists,
253
+ readFile: sys.readFile
254
+ };
255
+ if (options == null ? void 0 : options.ignoreSourceFiles) {
256
+ config.files = [];
257
+ config.include = [];
258
+ }
259
+ const nativeResult = parseJsonConfigFileContent(
260
+ config,
261
+ host,
262
+ path6.dirname(posixTSConfigFile),
263
+ void 0,
264
+ posixTSConfigFile
265
+ );
266
+ checkErrors(nativeResult, tsconfigFile);
267
+ const result = {
268
+ tsconfigFile,
269
+ tsconfig: result2tsconfig(nativeResult, ts),
270
+ result: nativeResult
271
+ };
272
+ cache == null ? void 0 : cache.set(tsconfigFile, result);
273
+ return result;
274
+ }
275
+ async function parseReferences2(result, ts, options) {
276
+ if (!result.tsconfig.references) {
277
+ return;
278
+ }
279
+ const referencedFiles = resolveReferencedTSConfigFiles(result);
280
+ result.referenced = await Promise.all(
281
+ referencedFiles.map((file) => parseFile2(file, ts, options))
282
+ );
283
+ }
284
+ function checkErrors(nativeResult, tsconfigFile) {
285
+ var _a;
286
+ const ignoredErrorCodes = [
287
+ // see https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
288
+ 18002,
289
+ // empty files list
290
+ 18003
291
+ // no inputs
292
+ ];
293
+ const criticalError = (_a = nativeResult.errors) == null ? void 0 : _a.find(
294
+ (error) => error.category === 1 && !ignoredErrorCodes.includes(error.code)
295
+ );
296
+ if (criticalError) {
297
+ throw new TSConfckParseNativeError(criticalError, tsconfigFile, nativeResult);
298
+ }
299
+ }
300
+ function result2tsconfig(result, ts) {
301
+ const tsconfig = JSON.parse(JSON.stringify(result.raw));
302
+ const ignoredOptions = ["configFilePath", "pathsBasePath"];
303
+ if (result.options && Object.keys(result.options).some((o) => !ignoredOptions.includes(o))) {
304
+ tsconfig.compilerOptions = {
305
+ ...result.options
306
+ };
307
+ for (const ignored of ignoredOptions) {
308
+ delete tsconfig.compilerOptions[ignored];
309
+ }
310
+ }
311
+ const compilerOptions = tsconfig.compilerOptions;
312
+ if (compilerOptions) {
313
+ if (compilerOptions.lib != null) {
314
+ compilerOptions.lib = compilerOptions.lib.map(
315
+ (x) => x.replace(/^lib\./, "").replace(/\.d\.ts$/, "")
316
+ );
317
+ }
318
+ const enumProperties = [
319
+ { name: "importsNotUsedAsValues", enumeration: ts.ImportsNotUsedAsValues },
320
+ { name: "module", enumeration: ts.ModuleKind },
321
+ {
322
+ name: "moduleResolution",
323
+ enumeration: {
324
+ ...ts.ModuleResolutionKind,
325
+ 2: "node"
326
+ /*ts.ModuleResolutionKind uses "Node10" but in tsconfig it is just node"*/
327
+ }
328
+ },
329
+ {
330
+ name: "newLine",
331
+ enumeration: { 0: "crlf", 1: "lf" }
332
+ /*ts.NewLineKind uses different names*/
333
+ },
334
+ { name: "target", enumeration: ts.ScriptTarget }
335
+ ];
336
+ for (const prop of enumProperties) {
337
+ if (compilerOptions[prop.name] != null && typeof compilerOptions[prop.name] === "number") {
338
+ compilerOptions[prop.name] = prop.enumeration[compilerOptions[prop.name]].toLowerCase();
339
+ }
340
+ }
341
+ if (compilerOptions.target === "latest") {
342
+ compilerOptions.target = "esnext";
343
+ }
344
+ }
345
+ if (result.watchOptions) {
346
+ tsconfig.watchOptions = {
347
+ ...result.watchOptions
348
+ };
349
+ }
350
+ const watchOptions = tsconfig.watchOptions;
351
+ if (watchOptions) {
352
+ const enumProperties = [
353
+ { name: "watchFile", enumeration: ts.WatchFileKind },
354
+ { name: "watchDirectory", enumeration: ts.WatchDirectoryKind },
355
+ { name: "fallbackPolling", enumeration: ts.PollingWatchKind }
356
+ ];
357
+ for (const prop of enumProperties) {
358
+ if (watchOptions[prop.name] != null && typeof watchOptions[prop.name] === "number") {
359
+ const enumVal = prop.enumeration[watchOptions[prop.name]];
360
+ watchOptions[prop.name] = enumVal.charAt(0).toLowerCase() + enumVal.slice(1);
361
+ }
362
+ }
363
+ }
364
+ if (tsconfig.compileOnSave === false) {
365
+ delete tsconfig.compileOnSave;
366
+ }
367
+ return tsconfig;
368
+ }
369
+ var TSConfckParseNativeError = class _TSConfckParseNativeError extends Error {
370
+ constructor(diagnostic, tsconfigFile, result) {
371
+ super(diagnostic.messageText);
372
+ Object.setPrototypeOf(this, _TSConfckParseNativeError.prototype);
373
+ this.name = _TSConfckParseNativeError.name;
374
+ this.code = `TS ${diagnostic.code}`;
375
+ this.diagnostic = diagnostic;
376
+ this.result = result;
377
+ this.tsconfigFile = tsconfigFile;
378
+ }
379
+ };
380
+
381
+ // src/utils/get-config.ts
22
382
  import * as z from "zod";
23
383
 
384
+ // src/utils/find-tsconfig.ts
385
+ import { promises as fs } from "fs";
386
+ import path from "path";
387
+ async function find(filename, options) {
388
+ let dir = path.dirname(path.resolve(filename));
389
+ const root = options?.root ? path.resolve(options.root) : null;
390
+ while (dir) {
391
+ const tsconfig = await tsconfigInDir(dir, options);
392
+ if (tsconfig) {
393
+ return tsconfig;
394
+ } else {
395
+ if (root === dir) {
396
+ break;
397
+ }
398
+ const parent = path.dirname(dir);
399
+ if (parent === dir) {
400
+ break;
401
+ } else {
402
+ dir = parent;
403
+ }
404
+ }
405
+ }
406
+ throw new Error(`no tsconfig file found for ${filename}`);
407
+ }
408
+ async function tsconfigInDir(dir, options) {
409
+ const tsconfig = path.join(dir, "tsconfig.json");
410
+ const jsconfig = path.join(dir, "jsconfig.json");
411
+ if (options?.tsConfigPaths) {
412
+ return options.tsConfigPaths.has(tsconfig) ? tsconfig : void 0;
413
+ }
414
+ try {
415
+ const stat = await fs.stat(tsconfig);
416
+ if (stat.isFile() || stat.isFIFO()) {
417
+ return tsconfig;
418
+ }
419
+ } catch (e) {
420
+ if (e.code !== "ENOENT") {
421
+ throw e;
422
+ }
423
+ }
424
+ try {
425
+ let stat = await fs.stat(jsconfig);
426
+ if (stat.isFile() || stat.isFIFO()) {
427
+ return jsconfig;
428
+ }
429
+ } catch (e) {
430
+ if (e.code !== "ENOENT") {
431
+ throw e;
432
+ }
433
+ }
434
+ }
435
+
436
+ // src/utils/get-package-info.ts
437
+ import path4 from "path";
438
+ import { fileURLToPath } from "url";
439
+ import fs3 from "fs-extra";
440
+ function getPackageInfo() {
441
+ const packageJsonPath = getPackageFilePath("../package.json");
442
+ return fs3.readJSONSync(packageJsonPath);
443
+ }
444
+ function getPackageFilePath(filePath) {
445
+ let distPath = fileURLToPath(new URL(`.`, import.meta.url));
446
+ return path4.resolve(distPath, filePath);
447
+ }
448
+ function loadProjectPackageInfo(cwd) {
449
+ const packageJsonPath = path4.resolve(cwd, "package.json");
450
+ return fs3.readJSONSync(packageJsonPath);
451
+ }
452
+ function isUsingSvelteKit(cwd) {
453
+ const packageJSON = loadProjectPackageInfo(cwd);
454
+ const deps = { ...packageJSON.devDependencies, ...packageJSON.dependencies };
455
+ return Object.keys(deps).some((dep) => dep === "@sveltejs/kit");
456
+ }
457
+
24
458
  // node_modules/.pnpm/@antfu+ni@0.21.5/node_modules/@antfu/ni/dist/shared/ni.3ebb7310.mjs
25
459
  import path$3, { join as join$1, dirname, resolve } from "node:path";
26
460
  import process$2 from "node:process";
@@ -31,7 +465,7 @@ import childProcess, { ChildProcess } from "node:child_process";
31
465
  import require$$0$2 from "child_process";
32
466
  import require$$0$1 from "path";
33
467
  import require$$0 from "fs";
34
- import url, { fileURLToPath } from "node:url";
468
+ import url, { fileURLToPath as fileURLToPath2 } from "node:url";
35
469
  import os$1, { constants } from "node:os";
36
470
  import require$$0$3 from "assert";
37
471
  import fs$1, { promises, createWriteStream, createReadStream, existsSync } from "node:fs";
@@ -282,7 +716,7 @@ function checkType(type) {
282
716
  throw new Error(`Invalid type specified: ${type}`);
283
717
  }
284
718
  var matchType = (type, stat) => type === void 0 || stat[typeMappings[type]]();
285
- var toPath$1 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
719
+ var toPath$1 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath2(urlOrPath) : urlOrPath;
286
720
  async function locatePath(paths, {
287
721
  cwd = process$2.cwd(),
288
722
  type = "file",
@@ -302,7 +736,7 @@ async function locatePath(paths, {
302
736
  }
303
737
  }, { concurrency, preserveOrder });
304
738
  }
305
- var toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
739
+ var toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath2(urlOrPath) : urlOrPath;
306
740
  var findUpStop = Symbol("findUpStop");
307
741
  async function findUpMultiple(name, options = {}) {
308
742
  let directory = path$3.resolve(toPath(options.cwd) || "");
@@ -352,8 +786,8 @@ function requireWindows() {
352
786
  hasRequiredWindows = 1;
353
787
  windows = isexe2;
354
788
  isexe2.sync = sync2;
355
- var fs6 = require$$0;
356
- function checkPathExt(path8, options) {
789
+ var fs9 = require$$0;
790
+ function checkPathExt(path13, options) {
357
791
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
358
792
  if (!pathext) {
359
793
  return true;
@@ -364,25 +798,25 @@ function requireWindows() {
364
798
  }
365
799
  for (var i = 0; i < pathext.length; i++) {
366
800
  var p = pathext[i].toLowerCase();
367
- if (p && path8.substr(-p.length).toLowerCase() === p) {
801
+ if (p && path13.substr(-p.length).toLowerCase() === p) {
368
802
  return true;
369
803
  }
370
804
  }
371
805
  return false;
372
806
  }
373
- function checkStat(stat, path8, options) {
807
+ function checkStat(stat, path13, options) {
374
808
  if (!stat.isSymbolicLink() && !stat.isFile()) {
375
809
  return false;
376
810
  }
377
- return checkPathExt(path8, options);
811
+ return checkPathExt(path13, options);
378
812
  }
379
- function isexe2(path8, options, cb) {
380
- fs6.stat(path8, function(er, stat) {
381
- cb(er, er ? false : checkStat(stat, path8, options));
813
+ function isexe2(path13, options, cb) {
814
+ fs9.stat(path13, function(er, stat) {
815
+ cb(er, er ? false : checkStat(stat, path13, options));
382
816
  });
383
817
  }
384
- function sync2(path8, options) {
385
- return checkStat(fs6.statSync(path8), path8, options);
818
+ function sync2(path13, options) {
819
+ return checkStat(fs9.statSync(path13), path13, options);
386
820
  }
387
821
  return windows;
388
822
  }
@@ -394,14 +828,14 @@ function requireMode() {
394
828
  hasRequiredMode = 1;
395
829
  mode = isexe2;
396
830
  isexe2.sync = sync2;
397
- var fs6 = require$$0;
398
- function isexe2(path8, options, cb) {
399
- fs6.stat(path8, function(er, stat) {
831
+ var fs9 = require$$0;
832
+ function isexe2(path13, options, cb) {
833
+ fs9.stat(path13, function(er, stat) {
400
834
  cb(er, er ? false : checkStat(stat, options));
401
835
  });
402
836
  }
403
- function sync2(path8, options) {
404
- return checkStat(fs6.statSync(path8), options);
837
+ function sync2(path13, options) {
838
+ return checkStat(fs9.statSync(path13), options);
405
839
  }
406
840
  function checkStat(stat, options) {
407
841
  return stat.isFile() && checkMode(stat, options);
@@ -429,7 +863,7 @@ if (process.platform === "win32" || commonjsGlobal.TESTING_WINDOWS) {
429
863
  }
430
864
  var isexe_1 = isexe$2;
431
865
  isexe$2.sync = sync;
432
- function isexe$2(path8, options, cb) {
866
+ function isexe$2(path13, options, cb) {
433
867
  if (typeof options === "function") {
434
868
  cb = options;
435
869
  options = {};
@@ -439,7 +873,7 @@ function isexe$2(path8, options, cb) {
439
873
  throw new TypeError("callback not provided");
440
874
  }
441
875
  return new Promise(function(resolve2, reject) {
442
- isexe$2(path8, options || {}, function(er, is) {
876
+ isexe$2(path13, options || {}, function(er, is) {
443
877
  if (er) {
444
878
  reject(er);
445
879
  } else {
@@ -448,7 +882,7 @@ function isexe$2(path8, options, cb) {
448
882
  });
449
883
  });
450
884
  }
451
- core(path8, options || {}, function(er, is) {
885
+ core(path13, options || {}, function(er, is) {
452
886
  if (er) {
453
887
  if (er.code === "EACCES" || options && options.ignoreErrors) {
454
888
  er = null;
@@ -458,9 +892,9 @@ function isexe$2(path8, options, cb) {
458
892
  cb(er, is);
459
893
  });
460
894
  }
461
- function sync(path8, options) {
895
+ function sync(path13, options) {
462
896
  try {
463
- return core.sync(path8, options || {});
897
+ return core.sync(path13, options || {});
464
898
  } catch (er) {
465
899
  if (options && options.ignoreErrors || er.code === "EACCES") {
466
900
  return false;
@@ -632,29 +1066,29 @@ var shebangCommand$1 = (string3 = "") => {
632
1066
  if (!match) {
633
1067
  return null;
634
1068
  }
635
- const [path8, argument] = match[0].replace(/#! ?/, "").split(" ");
636
- const binary = path8.split("/").pop();
1069
+ const [path13, argument] = match[0].replace(/#! ?/, "").split(" ");
1070
+ const binary = path13.split("/").pop();
637
1071
  if (binary === "env") {
638
1072
  return argument;
639
1073
  }
640
1074
  return argument ? `${binary} ${argument}` : binary;
641
1075
  };
642
- var fs = require$$0;
1076
+ var fs4 = require$$0;
643
1077
  var shebangCommand = shebangCommand$1;
644
1078
  function readShebang$1(command) {
645
1079
  const size = 150;
646
1080
  const buffer = Buffer.alloc(size);
647
1081
  let fd;
648
1082
  try {
649
- fd = fs.openSync(command, "r");
650
- fs.readSync(fd, buffer, 0, size, 0);
651
- fs.closeSync(fd);
1083
+ fd = fs4.openSync(command, "r");
1084
+ fs4.readSync(fd, buffer, 0, size, 0);
1085
+ fs4.closeSync(fd);
652
1086
  } catch (e) {
653
1087
  }
654
1088
  return shebangCommand(buffer.toString());
655
1089
  }
656
1090
  var readShebang_1 = readShebang$1;
657
- var path = require$$0$1;
1091
+ var path7 = require$$0$1;
658
1092
  var resolveCommand = resolveCommand_1;
659
1093
  var escape = _escape;
660
1094
  var readShebang = readShebang_1;
@@ -679,7 +1113,7 @@ function parseNonShell(parsed) {
679
1113
  const needsShell = !isExecutableRegExp.test(commandFile);
680
1114
  if (parsed.options.forceShell || needsShell) {
681
1115
  const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
682
- parsed.command = path.normalize(parsed.command);
1116
+ parsed.command = path7.normalize(parsed.command);
683
1117
  parsed.command = escape.command(parsed.command);
684
1118
  parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
685
1119
  const shellCommand = [parsed.command].concat(parsed.args).join(" ");
@@ -815,9 +1249,9 @@ function npmRunPath(options = {}) {
815
1249
  }
816
1250
  function npmRunPathEnv({ env: env2 = process$2.env, ...options } = {}) {
817
1251
  env2 = { ...env2 };
818
- const path8 = pathKey({ env: env2 });
819
- options.path = env2[path8];
820
- env2[path8] = npmRunPath(options);
1252
+ const path13 = pathKey({ env: env2 });
1253
+ options.path = env2[path13];
1254
+ env2[path13] = npmRunPath(options);
821
1255
  return env2;
822
1256
  }
823
1257
  var copyProperty = (to, from, property, ignoreNonConfigurable) => {
@@ -4397,9 +4831,9 @@ var elements = {
4397
4831
  $2.date = (args) => toPrompt("DatePrompt", args);
4398
4832
  $2.confirm = (args) => toPrompt("ConfirmPrompt", args);
4399
4833
  $2.list = (args) => {
4400
- const sep2 = args.separator || ",";
4834
+ const sep3 = args.separator || ",";
4401
4835
  return toPrompt("TextPrompt", args, {
4402
- onSubmit: (str) => str.split(sep2).map((s) => s.trim())
4836
+ onSubmit: (str) => str.split(sep3).map((s) => s.trim())
4403
4837
  });
4404
4838
  };
4405
4839
  $2.toggle = (args) => toPrompt("TogglePrompt", args);
@@ -4502,9 +4936,9 @@ var lib$1 = Object.assign(prompt, { prompt, prompts: prompts$2, inject, override
4502
4936
  var prompts = lib$1;
4503
4937
  var prompts$1 = /* @__PURE__ */ getDefaultExportFromCjs(prompts);
4504
4938
  var isexe = isexe_1;
4505
- var { join, delimiter, sep, posix } = require$$0$1;
4939
+ var { join, delimiter, sep: sep2, posix } = require$$0$1;
4506
4940
  var isWindows = process.platform === "win32";
4507
- var rSlash = new RegExp(`[${posix.sep}${sep === posix.sep ? "" : sep}]`.replace(/(\\)/g, "\\$1"));
4941
+ var rSlash = new RegExp(`[${posix.sep}${sep2 === posix.sep ? "" : sep2}]`.replace(/(\\)/g, "\\$1"));
4508
4942
  var rRel = new RegExp(`^\\.${rSlash.source}`);
4509
4943
  var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
4510
4944
  var getPathInfo = (cmd, {
@@ -4757,15 +5191,31 @@ async function getPackageManager(targetDir) {
4757
5191
  return packageManager ?? "npm";
4758
5192
  }
4759
5193
 
5194
+ // src/utils/logger.ts
5195
+ import chalk from "chalk";
5196
+ var logger = {
5197
+ error(...args) {
5198
+ console.log(chalk.red(...args));
5199
+ },
5200
+ warn(...args) {
5201
+ console.log(chalk.yellow(...args));
5202
+ },
5203
+ info(...args) {
5204
+ console.log(chalk.cyan(...args));
5205
+ },
5206
+ success(...args) {
5207
+ console.log(chalk.green(...args));
5208
+ },
5209
+ highlight(...args) {
5210
+ return chalk.cyan(...args);
5211
+ }
5212
+ };
5213
+
4760
5214
  // src/utils/resolve-imports.ts
4761
5215
  import { createMatchPath } from "tsconfig-paths";
4762
5216
  async function resolveImport(importPath, config) {
4763
5217
  const matchPath = createMatchPath(config.absoluteBaseUrl, config.paths);
4764
- return matchPath(importPath, void 0, () => true, [
4765
- ".ts",
4766
- ".svelte",
4767
- ".js"
4768
- ]);
5218
+ return matchPath(importPath, void 0, () => true, [".ts", ".svelte", ".js"]);
4769
5219
  }
4770
5220
 
4771
5221
  // src/utils/get-config.ts
@@ -4803,8 +5253,8 @@ async function getConfig2(cwd) {
4803
5253
  return await resolveConfigPaths(cwd, config);
4804
5254
  }
4805
5255
  async function resolveConfigPaths(cwd, config) {
4806
- const TSCONFIG_PATH = ".svelte-kit/tsconfig.json";
4807
- if (!existsSync2(TSCONFIG_PATH)) {
5256
+ const isSvelteKit = isUsingSvelteKit(cwd);
5257
+ if (isSvelteKit) {
4808
5258
  const packageManager = await getPackageManager(cwd);
4809
5259
  await execa2(
4810
5260
  packageManager === "npm" ? "npx" : packageManager,
@@ -4814,32 +5264,43 @@ async function resolveConfigPaths(cwd, config) {
4814
5264
  }
4815
5265
  );
4816
5266
  }
4817
- const tsconfigPath = path2.resolve(cwd, TSCONFIG_PATH);
4818
- const tsConfig = loadConfig(tsconfigPath);
4819
- if (tsConfig.resultType === "failed") {
5267
+ const tsconfigPath = await find(path8.resolve(cwd, "package.json"), { root: cwd });
5268
+ if (tsconfigPath === null)
5269
+ throw new Error(`Failed to find ${logger.highlight("tsconfig.json")}.`);
5270
+ const parsedConfig = await parseNative(tsconfigPath);
5271
+ const absoluteBaseUrl = parsedConfig.result.options.pathsBasePath;
5272
+ let paths = parsedConfig.result.options.paths;
5273
+ if (absoluteBaseUrl === void 0 || paths === void 0) {
4820
5274
  throw new Error(
4821
- `Failed to load .svelte-kit/tsconfig.json. Error: ${tsConfig.message ?? ""}`.trim()
5275
+ `Specify a ${logger.highlight("paths")} field in your ${logger.highlight(
5276
+ "tsconfig.json"
5277
+ )} and define your path aliases.
5278
+
5279
+ See: ${chalk2.green(
5280
+ "https://www.shadcn-svelte.com/docs/installation#setup-path-aliases"
5281
+ )}`
4822
5282
  );
4823
5283
  }
4824
- const utilsPath = await resolveImport(config.aliases["utils"], tsConfig);
4825
- const componentsPath = await resolveImport(
4826
- config.aliases["components"],
4827
- tsConfig
4828
- );
5284
+ const importOpts = {
5285
+ absoluteBaseUrl,
5286
+ paths
5287
+ };
5288
+ const utilsPath = await resolveImport(config.aliases.utils, importOpts);
5289
+ const componentsPath = await resolveImport(config.aliases.components, importOpts);
4829
5290
  return configSchema.parse({
4830
5291
  ...config,
4831
5292
  resolvedPaths: {
4832
- tailwindConfig: path2.resolve(cwd, config.tailwind.config),
4833
- tailwindCss: path2.resolve(cwd, config.tailwind.css),
5293
+ tailwindConfig: path8.resolve(cwd, config.tailwind.config),
5294
+ tailwindCss: path8.resolve(cwd, config.tailwind.css),
4834
5295
  utils: utilsPath,
4835
5296
  components: componentsPath
4836
5297
  }
4837
5298
  });
4838
5299
  }
4839
5300
  async function getRawConfig(cwd) {
5301
+ const configPath = path8.resolve(cwd, "components.json");
4840
5302
  try {
4841
- const configPath = path2.resolve(cwd, "components.json");
4842
- const configResult = await readFile(configPath, {
5303
+ const configResult = await fs5.readFile(configPath, {
4843
5304
  encoding: "utf8"
4844
5305
  }).catch((e) => null);
4845
5306
  if (!configResult) {
@@ -4849,7 +5310,7 @@ async function getRawConfig(cwd) {
4849
5310
  return rawConfigSchema.parse(config);
4850
5311
  } catch (error) {
4851
5312
  throw new Error(
4852
- `Invalid configuration found in ${cwd}/components.json.`
5313
+ `Invalid configuration found in ${logger.highlight(configPath)}.`
4853
5314
  );
4854
5315
  }
4855
5316
  }
@@ -4860,42 +5321,24 @@ function getEnvProxy() {
4860
5321
  return HTTP_PROXY || http_proxy;
4861
5322
  }
4862
5323
 
4863
- // src/utils/logger.ts
4864
- import chalk from "chalk";
4865
- var logger = {
4866
- error(...args) {
4867
- console.log(chalk.red(...args));
4868
- },
4869
- warn(...args) {
4870
- console.log(chalk.yellow(...args));
4871
- },
4872
- info(...args) {
4873
- console.log(chalk.cyan(...args));
4874
- },
4875
- success(...args) {
4876
- console.log(chalk.green(...args));
4877
- },
4878
- highlight(...args) {
4879
- return chalk.cyan(...args);
4880
- }
4881
- };
4882
-
4883
5324
  // src/utils/handle-error.ts
4884
5325
  function handleError(error) {
5326
+ const PREFIX = "ERROR: ";
5327
+ logger.error();
4885
5328
  if (typeof error === "string") {
4886
- logger.error(error);
5329
+ logger.error(PREFIX + error);
4887
5330
  process.exit(1);
4888
5331
  }
4889
5332
  if (error instanceof Error) {
4890
- logger.error(error.message);
5333
+ logger.error(PREFIX + error.message);
4891
5334
  process.exit(1);
4892
5335
  }
4893
- logger.error("Something went wrong. Please try again.");
5336
+ logger.error(PREFIX + "Something went wrong. Please try again.");
4894
5337
  process.exit(1);
4895
5338
  }
4896
5339
 
4897
5340
  // src/utils/registry/index.ts
4898
- import path3 from "path";
5341
+ import path9 from "path";
4899
5342
  import { HttpsProxyAgent } from "https-proxy-agent";
4900
5343
  import fetch from "node-fetch";
4901
5344
 
@@ -4906,11 +5349,7 @@ var registryItemSchema = z2.object({
4906
5349
  dependencies: z2.array(z2.string()).optional(),
4907
5350
  registryDependencies: z2.array(z2.string()).optional(),
4908
5351
  files: z2.array(z2.string()),
4909
- type: z2.enum([
4910
- "components:ui",
4911
- "components:component",
4912
- "components:example"
4913
- ])
5352
+ type: z2.enum(["components:ui", "components:component", "components:example"])
4914
5353
  });
4915
5354
  var registryIndexSchema = z2.array(registryItemSchema);
4916
5355
  var registryItemWithContentSchema = registryItemSchema.extend({
@@ -5001,10 +5440,7 @@ async function resolveTree(index, names) {
5001
5440
  }
5002
5441
  tree.push(entry);
5003
5442
  if (entry.registryDependencies) {
5004
- const dependencies = await resolveTree(
5005
- index,
5006
- entry.registryDependencies
5007
- );
5443
+ const dependencies = await resolveTree(index, entry.registryDependencies);
5008
5444
  tree.push(...dependencies);
5009
5445
  }
5010
5446
  }
@@ -5029,7 +5465,7 @@ async function getItemTargetPath(config, item2, override2) {
5029
5465
  if (!(parent in config.resolvedPaths)) {
5030
5466
  return null;
5031
5467
  }
5032
- return path3.join(
5468
+ return path9.join(
5033
5469
  config.resolvedPaths[parent],
5034
5470
  type
5035
5471
  );
@@ -5041,11 +5477,8 @@ async function fetchRegistry(paths) {
5041
5477
  options.agent = new HttpsProxyAgent(proxyUrl);
5042
5478
  }
5043
5479
  const results = await Promise.all(
5044
- paths.map(async (path8) => {
5045
- const response = await fetch(
5046
- `${baseUrl}/registry/${path8}`,
5047
- options
5048
- );
5480
+ paths.map(async (path13) => {
5481
+ const response = await fetch(`${baseUrl}/registry/${path13}`, options);
5049
5482
  return await response.json();
5050
5483
  })
5051
5484
  );
@@ -6116,11 +6549,7 @@ var addOptionsSchema = z3.object({
6116
6549
  nodep: z3.boolean(),
6117
6550
  proxy: z3.string().optional()
6118
6551
  });
6119
- var add = new Command().command("add").description("add components to your project").argument("[components...]", "name of components").option(
6120
- "--nodep",
6121
- "disable adding & installing dependencies (advanced)",
6122
- false
6123
- ).option("-a, --all", "Add all components to your project.", false).option("-y, --yes", "Skip confirmation prompt.", false).option("-o, --overwrite", "overwrite existing files.", false).option("--proxy <proxy>", "fetch components from registry using a proxy.").option(
6552
+ var add = new Command().command("add").description("add components to your project").argument("[components...]", "name of components").option("--nodep", "disable adding & installing dependencies (advanced)", false).option("-a, --all", "Add all components to your project.", false).option("-y, --yes", "Skip confirmation prompt.", false).option("-o, --overwrite", "overwrite existing files.", false).option("--proxy <proxy>", "fetch components from registry using a proxy.").option(
6124
6553
  "-c, --cwd <cwd>",
6125
6554
  "the working directory. defaults to the current directory.",
6126
6555
  process.cwd()
@@ -6131,18 +6560,16 @@ var add = new Command().command("add").description("add components to your proje
6131
6560
  components,
6132
6561
  ...opts
6133
6562
  });
6134
- const cwd = path4.resolve(options.cwd);
6135
- if (!existsSync3(cwd)) {
6136
- logger.error(
6137
- `The path ${cwd} does not exist. Please try again.`
6138
- );
6563
+ const cwd = path10.resolve(options.cwd);
6564
+ if (!existsSync2(cwd)) {
6565
+ logger.error(`The path ${cwd} does not exist. Please try again.`);
6139
6566
  process.exitCode = 1;
6140
6567
  return;
6141
6568
  }
6142
6569
  const config = await getConfig2(cwd);
6143
6570
  if (!config) {
6144
6571
  logger.warn(
6145
- `Configuration is missing. Please run ${chalk2.green(
6572
+ `Configuration is missing. Please run ${chalk3.green(
6146
6573
  `init`
6147
6574
  )} to create a components.json file.`
6148
6575
  );
@@ -6155,7 +6582,7 @@ var add = new Command().command("add").description("add components to your proje
6155
6582
  if (isCustom)
6156
6583
  process.env.HTTP_PROXY = options.proxy;
6157
6584
  logger.warn(
6158
- `You are using a ${isCustom ? "provided" : "system environment"} proxy: ${chalk2.green(chosenProxy)}`
6585
+ `You are using a ${isCustom ? "provided" : "system environment"} proxy: ${chalk3.green(chosenProxy)}`
6159
6586
  );
6160
6587
  }
6161
6588
  const registryIndex = await getRegistryIndex();
@@ -6181,18 +6608,14 @@ var add = new Command().command("add").description("add components to your proje
6181
6608
  }
6182
6609
  const tree = await resolveTree(registryIndex, selectedComponents);
6183
6610
  const payload = await fetchTree(config.style, tree);
6184
- const baseColor = await getRegistryBaseColor(
6185
- config.tailwind.baseColor
6186
- );
6611
+ const baseColor = await getRegistryBaseColor(config.tailwind.baseColor);
6187
6612
  if (!payload.length) {
6188
6613
  logger.warn("Selected components not found. Exiting.");
6189
6614
  process.exitCode = 0;
6190
6615
  return;
6191
6616
  }
6192
- logger.info(
6193
- `Selected components:
6194
- ${highlight(selectedComponents)}`
6195
- );
6617
+ logger.info(`Selected components:
6618
+ ${highlight(selectedComponents)}`);
6196
6619
  if (!options.yes) {
6197
6620
  const { proceed } = await prompts2({
6198
6621
  type: "confirm",
@@ -6213,20 +6636,20 @@ ${highlight(selectedComponents)}`
6213
6636
  const targetDir = await getItemTargetPath(
6214
6637
  config,
6215
6638
  item2,
6216
- options.path ? path4.resolve(cwd, options.path) : void 0
6639
+ options.path ? path10.resolve(cwd, options.path) : void 0
6217
6640
  );
6218
6641
  if (!targetDir) {
6219
6642
  continue;
6220
6643
  }
6221
- if (!existsSync3(targetDir)) {
6222
- await fs2.mkdir(targetDir, { recursive: true });
6644
+ if (!existsSync2(targetDir)) {
6645
+ await fs6.mkdir(targetDir, { recursive: true });
6223
6646
  }
6224
- const componentPath = path4.relative(
6647
+ const componentPath = path10.relative(
6225
6648
  process.cwd(),
6226
- path4.resolve(targetDir, item2.name)
6649
+ path10.resolve(targetDir, item2.name)
6227
6650
  );
6228
6651
  const existingComponent = item2.files.filter(
6229
- (file) => existsSync3(path4.resolve(targetDir, item2.name, file.name))
6652
+ (file) => existsSync2(path10.resolve(targetDir, item2.name, file.name))
6230
6653
  );
6231
6654
  if (existingComponent.length && !options.overwrite) {
6232
6655
  if (selectedComponents.includes(item2.name)) {
@@ -6236,7 +6659,7 @@ Component ${highlight(
6236
6659
  item2.name
6237
6660
  )} already exists at ${highlight(
6238
6661
  componentPath
6239
- )}. Use ${chalk2.green("--overwrite")} to overwrite.`
6662
+ )}. Use ${chalk3.green("--overwrite")} to overwrite.`
6240
6663
  );
6241
6664
  spinner.stop();
6242
6665
  process.exitCode = 1;
@@ -6245,23 +6668,17 @@ Component ${highlight(
6245
6668
  continue;
6246
6669
  }
6247
6670
  for (const file of item2.files) {
6248
- const componentDir = path4.resolve(targetDir, item2.name);
6249
- let filePath = path4.resolve(
6250
- targetDir,
6251
- item2.name,
6252
- file.name
6253
- );
6671
+ const componentDir = path10.resolve(targetDir, item2.name);
6672
+ let filePath = path10.resolve(targetDir, item2.name, file.name);
6254
6673
  const content = transformImport(file.content, config);
6255
- if (!existsSync3(componentDir)) {
6256
- await fs2.mkdir(componentDir, { recursive: true });
6674
+ if (!existsSync2(componentDir)) {
6675
+ await fs6.mkdir(componentDir, { recursive: true });
6257
6676
  }
6258
- await fs2.writeFile(filePath, content);
6677
+ await fs6.writeFile(filePath, content);
6259
6678
  }
6260
6679
  if (item2.dependencies?.length) {
6261
6680
  if (options.nodep) {
6262
- item2.dependencies.forEach(
6263
- (dep) => skippedDeps.add(dep)
6264
- );
6681
+ item2.dependencies.forEach((dep) => skippedDeps.add(dep));
6265
6682
  continue;
6266
6683
  }
6267
6684
  const packageManager = await getPackageManager(cwd);
@@ -6291,9 +6708,7 @@ Component ${highlight(
6291
6708
  spinner.succeed(`Done.`);
6292
6709
  logger.info(
6293
6710
  `Components installed at:
6294
- - ${[...componentPaths].join(
6295
- "\n- "
6296
- )}`
6711
+ - ${[...componentPaths].join("\n- ")}`
6297
6712
  );
6298
6713
  } catch (error) {
6299
6714
  handleError(error);
@@ -6301,9 +6716,9 @@ Component ${highlight(
6301
6716
  });
6302
6717
 
6303
6718
  // src/commands/init.ts
6304
- import { existsSync as existsSync4, promises as fs3 } from "fs";
6305
- import path5 from "path";
6306
- import chalk3 from "chalk";
6719
+ import { existsSync as existsSync3, promises as fs7 } from "fs";
6720
+ import path11 from "path";
6721
+ import chalk4 from "chalk";
6307
6722
  import { Command as Command2 } from "commander";
6308
6723
  import { execa as execa4 } from "execa";
6309
6724
  import ora2 from "ora";
@@ -6439,17 +6854,13 @@ export default config;
6439
6854
  `;
6440
6855
 
6441
6856
  // src/commands/init.ts
6442
- var PROJECT_DEPENDENCIES = [
6443
- "tailwind-variants",
6444
- "clsx",
6445
- "tailwind-merge"
6446
- ];
6857
+ var PROJECT_DEPENDENCIES = ["tailwind-variants", "clsx", "tailwind-merge"];
6447
6858
  var init2 = new Command2().command("init").description("Configure your SvelteKit project.").option("-y, --yes", "Skip confirmation prompt.").option(
6448
6859
  "-c, --cwd <cwd>",
6449
6860
  "the working directory. defaults to the current directory.",
6450
6861
  process.cwd()
6451
6862
  ).action(async (options) => {
6452
- const cwd = path5.resolve(options.cwd);
6863
+ const cwd = path11.resolve(options.cwd);
6453
6864
  logger.warn(
6454
6865
  "This command assumes a SvelteKit project with TypeScript and Tailwind CSS."
6455
6866
  );
@@ -6472,24 +6883,16 @@ var init2 = new Command2().command("init").description("Configure your SvelteKit
6472
6883
  }
6473
6884
  }
6474
6885
  try {
6475
- if (!existsSync4(cwd)) {
6476
- logger.error(
6477
- `The path ${cwd} does not exist. Please try again.`
6478
- );
6886
+ if (!existsSync3(cwd)) {
6887
+ logger.error(`The path ${cwd} does not exist. Please try again.`);
6479
6888
  process.exitCode = 1;
6480
6889
  return;
6481
6890
  }
6482
6891
  const existingConfig = await getConfig2(cwd);
6483
- const config = await promptForConfig(
6484
- cwd,
6485
- existingConfig,
6486
- options.yes
6487
- );
6892
+ const config = await promptForConfig(cwd, existingConfig, options.yes);
6488
6893
  await runInit(cwd, config);
6489
6894
  logger.info("");
6490
- logger.info(
6491
- `${chalk3.green("Success!")} Project initialization completed.`
6492
- );
6895
+ logger.info(`${chalk4.green("Success!")} Project initialization completed.`);
6493
6896
  logger.info("");
6494
6897
  logger.info(
6495
6898
  "Don't forget to add the aliases you configured to your svelte.config.js!"
@@ -6516,9 +6919,7 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6516
6919
  {
6517
6920
  type: "select",
6518
6921
  name: "tailwindBaseColor",
6519
- message: `Which color would you like to use as ${highlight(
6520
- "base color"
6521
- )}?`,
6922
+ message: `Which color would you like to use as ${highlight("base color")}?`,
6522
6923
  choices: baseColors.map((color2) => ({
6523
6924
  title: color2.label,
6524
6925
  value: color2.name
@@ -6530,30 +6931,24 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6530
6931
  message: `Where is your ${highlight("global CSS")} file?`,
6531
6932
  initial: defaultConfig?.tailwind.css ?? DEFAULT_TAILWIND_CSS,
6532
6933
  validate: (value) => {
6533
- if (existsSync4(value)) {
6934
+ if (existsSync3(value)) {
6534
6935
  return true;
6535
6936
  }
6536
- logger.error(
6537
- `${value} does not exist. Please enter a valid path.`
6538
- );
6937
+ logger.error(`${value} does not exist. Please enter a valid path.`);
6539
6938
  return false;
6540
6939
  }
6541
6940
  },
6542
6941
  {
6543
6942
  type: "text",
6544
6943
  name: "tailwindConfig",
6545
- message: `Where is your ${highlight(
6546
- "tailwind.config.[cjs|js|ts]"
6547
- )} located?`,
6944
+ message: `Where is your ${highlight("tailwind.config.[cjs|js|ts]")} located?`,
6548
6945
  initial: defaultConfig?.tailwind.config ?? DEFAULT_TAILWIND_CONFIG,
6549
6946
  validate: (value) => {
6550
- if (existsSync4(value)) {
6947
+ if (existsSync3(value)) {
6551
6948
  return true;
6552
6949
  }
6553
6950
  logger.info("");
6554
- logger.error(
6555
- `${value} does not exist. Please enter a valid path.`
6556
- );
6951
+ logger.error(`${value} does not exist. Please enter a valid path.`);
6557
6952
  logger.info("");
6558
6953
  return false;
6559
6954
  }
@@ -6561,9 +6956,7 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6561
6956
  {
6562
6957
  type: "text",
6563
6958
  name: "components",
6564
- message: `Configure the import alias for ${highlight(
6565
- "components"
6566
- )}:`,
6959
+ message: `Configure the import alias for ${highlight("components")}:`,
6567
6960
  initial: defaultConfig?.aliases["components"] ?? DEFAULT_COMPONENTS
6568
6961
  },
6569
6962
  {
@@ -6590,9 +6983,7 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6590
6983
  const { proceed } = await prompts3({
6591
6984
  type: "confirm",
6592
6985
  name: "proceed",
6593
- message: `Write configuration to ${highlight(
6594
- "components.json"
6595
- )}. Proceed?`,
6986
+ message: `Write configuration to ${highlight("components.json")}. Proceed?`,
6596
6987
  initial: true
6597
6988
  });
6598
6989
  if (!proceed) {
@@ -6600,57 +6991,46 @@ async function promptForConfig(cwd, defaultConfig = null, skip = false) {
6600
6991
  }
6601
6992
  }
6602
6993
  if (config.tailwind.config.endsWith(".cjs")) {
6603
- logger.info(
6604
- "Your tailwind.config.cjs has been renamed to tailwind.config.js."
6605
- );
6606
- const renamedTailwindConfigPath = config.tailwind.config.replace(
6607
- ".cjs",
6608
- ".js"
6609
- );
6994
+ logger.info("Your tailwind.config.cjs has been renamed to tailwind.config.js.");
6995
+ const renamedTailwindConfigPath = config.tailwind.config.replace(".cjs", ".js");
6610
6996
  config.tailwind.config = renamedTailwindConfigPath;
6611
6997
  }
6998
+ const configPaths = await resolveConfigPaths(cwd, config);
6612
6999
  logger.info("");
6613
7000
  const spinner = ora2(`Writing components.json...`).start();
6614
- const targetPath = path5.resolve(cwd, "components.json");
6615
- await fs3.writeFile(targetPath, JSON.stringify(config, null, 2), "utf8");
7001
+ const targetPath = path11.resolve(cwd, "components.json");
7002
+ await fs7.writeFile(targetPath, JSON.stringify(config, null, 2), "utf8");
6616
7003
  spinner.succeed();
6617
- return await resolveConfigPaths(cwd, config);
7004
+ return configPaths;
6618
7005
  }
6619
7006
  async function runInit(cwd, config) {
6620
7007
  const spinner = ora2(`Initializing project...`)?.start();
6621
7008
  for (const [key, resolvedPath] of Object.entries(config.resolvedPaths)) {
6622
- let dirname2 = path5.extname(resolvedPath) ? path5.dirname(resolvedPath) : resolvedPath;
7009
+ let dirname2 = path11.extname(resolvedPath) ? path11.dirname(resolvedPath) : resolvedPath;
6623
7010
  if (key === "utils" && resolvedPath.endsWith("/utils")) {
6624
7011
  dirname2 = dirname2.replace(/\/utils$/, "");
6625
7012
  }
6626
- if (!existsSync4(dirname2) && key !== "utils") {
6627
- await fs3.mkdir(dirname2, { recursive: true });
7013
+ if (!existsSync3(dirname2) && key !== "utils") {
7014
+ await fs7.mkdir(dirname2, { recursive: true });
6628
7015
  }
6629
7016
  }
6630
- await fs3.writeFile(
7017
+ await fs7.writeFile(
6631
7018
  config.resolvedPaths.tailwindConfig,
6632
7019
  TAILWIND_CONFIG_WITH_VARIABLES,
6633
7020
  "utf8"
6634
7021
  );
6635
- const cjsConfig = config.resolvedPaths.tailwindConfig.replace(
6636
- ".js",
6637
- ".cjs"
6638
- );
7022
+ const cjsConfig = config.resolvedPaths.tailwindConfig.replace(".js", ".cjs");
6639
7023
  if (cjsConfig.endsWith(".cjs"))
6640
- await fs3.unlink(cjsConfig).catch((e) => e);
7024
+ await fs7.unlink(cjsConfig).catch((e) => e);
6641
7025
  const baseColor = await getRegistryBaseColor(config.tailwind.baseColor);
6642
7026
  if (baseColor) {
6643
- await fs3.writeFile(
7027
+ await fs7.writeFile(
6644
7028
  config.resolvedPaths.tailwindCss,
6645
7029
  baseColor.cssVarsTemplate,
6646
7030
  "utf8"
6647
7031
  );
6648
7032
  }
6649
- await fs3.writeFile(
6650
- `${config.resolvedPaths.utils}.ts`,
6651
- UTILS,
6652
- "utf8"
6653
- );
7033
+ await fs7.writeFile(`${config.resolvedPaths.utils}.ts`, UTILS, "utf8");
6654
7034
  spinner?.succeed();
6655
7035
  const dependenciesSpinner = ora2(`Installing dependencies...`)?.start();
6656
7036
  const packageManager = await getPackageManager(cwd);
@@ -6658,20 +7038,16 @@ async function runInit(cwd, config) {
6658
7038
  ...PROJECT_DEPENDENCIES,
6659
7039
  config.style === "new-york" ? "radix-icons-svelte" : "lucide-svelte"
6660
7040
  ];
6661
- await execa4(
6662
- packageManager,
6663
- [packageManager === "npm" ? "install" : "add", ...deps],
6664
- {
6665
- cwd
6666
- }
6667
- );
7041
+ await execa4(packageManager, [packageManager === "npm" ? "install" : "add", ...deps], {
7042
+ cwd
7043
+ });
6668
7044
  dependenciesSpinner?.succeed();
6669
7045
  }
6670
7046
 
6671
7047
  // src/commands/update.ts
6672
- import { existsSync as existsSync5, promises as fs4 } from "fs";
6673
- import path6 from "path";
6674
- import chalk4 from "chalk";
7048
+ import { existsSync as existsSync4, promises as fs8 } from "fs";
7049
+ import path12 from "path";
7050
+ import chalk5 from "chalk";
6675
7051
  import { Command as Command3 } from "commander";
6676
7052
  import { execa as execa5 } from "execa";
6677
7053
  import ora3 from "ora";
@@ -6687,12 +7063,8 @@ var update = new Command3().command("update").description("update components in
6687
7063
  "the working directory. defaults to the current directory.",
6688
7064
  process.cwd()
6689
7065
  ).action(async (comps, opts) => {
6690
- logger.warn(
6691
- "Running the following command will overwrite existing files."
6692
- );
6693
- logger.warn(
6694
- "Make sure you have committed your changes before proceeding."
6695
- );
7066
+ logger.warn("Running the following command will overwrite existing files.");
7067
+ logger.warn("Make sure you have committed your changes before proceeding.");
6696
7068
  logger.warn("");
6697
7069
  try {
6698
7070
  const options = updateOptionsSchema.parse({
@@ -6700,18 +7072,16 @@ var update = new Command3().command("update").description("update components in
6700
7072
  ...opts
6701
7073
  });
6702
7074
  const components = options.components;
6703
- const cwd = path6.resolve(options.cwd);
6704
- if (!existsSync5(cwd)) {
6705
- logger.error(
6706
- `The path ${cwd} does not exist. Please try again.`
6707
- );
7075
+ const cwd = path12.resolve(options.cwd);
7076
+ if (!existsSync4(cwd)) {
7077
+ logger.error(`The path ${cwd} does not exist. Please try again.`);
6708
7078
  process.exitCode = 1;
6709
7079
  return;
6710
7080
  }
6711
7081
  const config = await getConfig2(cwd);
6712
7082
  if (!config) {
6713
7083
  logger.warn(
6714
- `Configuration is missing. Please run ${chalk4.green(
7084
+ `Configuration is missing. Please run ${chalk5.green(
6715
7085
  `init`
6716
7086
  )} to create a components.json file.`
6717
7087
  );
@@ -6719,17 +7089,14 @@ var update = new Command3().command("update").description("update components in
6719
7089
  return;
6720
7090
  }
6721
7091
  const registryIndex = await getRegistryIndex();
6722
- const componentDir = path6.resolve(
6723
- config.resolvedPaths.components,
6724
- "ui"
6725
- );
6726
- if (!existsSync5(componentDir)) {
7092
+ const componentDir = path12.resolve(config.resolvedPaths.components, "ui");
7093
+ if (!existsSync4(componentDir)) {
6727
7094
  logger.error(`Component dir '${componentDir}' does not exist.`);
6728
7095
  process.exitCode = 1;
6729
7096
  return;
6730
7097
  }
6731
7098
  const existingComponents = [];
6732
- const files = await fs4.readdir(componentDir, {
7099
+ const files = await fs8.readdir(componentDir, {
6733
7100
  withFileTypes: true
6734
7101
  });
6735
7102
  for (const file of files) {
@@ -6754,9 +7121,7 @@ var update = new Command3().command("update").description("update components in
6754
7121
  );
6755
7122
  }
6756
7123
  if (existingComponents.length === 0) {
6757
- logger.info(
6758
- `No shadcn components detected in '${componentDir}'.`
6759
- );
7124
+ logger.info(`No shadcn components detected in '${componentDir}'.`);
6760
7125
  process.exitCode = 0;
6761
7126
  return;
6762
7127
  }
@@ -6776,16 +7141,14 @@ var update = new Command3().command("update").description("update components in
6776
7141
  }
6777
7142
  if (selectedComponents.find((item2) => item2.name === "utils")) {
6778
7143
  const utilsPath = config.resolvedPaths.utils + ".ts";
6779
- if (!existsSync5(utilsPath)) {
7144
+ if (!existsSync4(utilsPath)) {
6780
7145
  spinner.fail(
6781
- `utils at ${logger.highlight(
6782
- utilsPath
6783
- )} does not exist.`
7146
+ `utils at ${logger.highlight(utilsPath)} does not exist.`
6784
7147
  );
6785
7148
  process.exitCode = 1;
6786
7149
  return;
6787
7150
  }
6788
- await fs4.writeFile(utilsPath, UTILS);
7151
+ await fs8.writeFile(utilsPath, UTILS);
6789
7152
  }
6790
7153
  const tree = await resolveTree(
6791
7154
  registryIndex,
@@ -6798,21 +7161,17 @@ var update = new Command3().command("update").description("update components in
6798
7161
  if (!targetDir) {
6799
7162
  continue;
6800
7163
  }
6801
- if (!existsSync5(targetDir)) {
6802
- await fs4.mkdir(targetDir, { recursive: true });
7164
+ if (!existsSync4(targetDir)) {
7165
+ await fs8.mkdir(targetDir, { recursive: true });
6803
7166
  }
6804
7167
  for (const file of item2.files) {
6805
- const componentDir2 = path6.resolve(targetDir, item2.name);
6806
- let filePath = path6.resolve(
6807
- targetDir,
6808
- item2.name,
6809
- file.name
6810
- );
7168
+ const componentDir2 = path12.resolve(targetDir, item2.name);
7169
+ let filePath = path12.resolve(targetDir, item2.name, file.name);
6811
7170
  const content = transformImport(file.content, config);
6812
- if (!existsSync5(componentDir2)) {
6813
- await fs4.mkdir(componentDir2, { recursive: true });
7171
+ if (!existsSync4(componentDir2)) {
7172
+ await fs8.mkdir(componentDir2, { recursive: true });
6814
7173
  }
6815
- await fs4.writeFile(filePath, content);
7174
+ await fs8.writeFile(filePath, content);
6816
7175
  }
6817
7176
  if (item2.dependencies?.length) {
6818
7177
  const packageManager = await getPackageManager(cwd);
@@ -6848,19 +7207,6 @@ async function promptForComponents(components, message) {
6848
7207
  return selectedComponents;
6849
7208
  }
6850
7209
 
6851
- // src/utils/get-package-info.ts
6852
- import path7 from "path";
6853
- import { fileURLToPath as fileURLToPath2 } from "url";
6854
- import fs5 from "fs-extra";
6855
- function getPackageInfo() {
6856
- const packageJsonPath = getPackageFilePath("../package.json");
6857
- return fs5.readJSONSync(packageJsonPath);
6858
- }
6859
- function getPackageFilePath(filePath) {
6860
- let distPath = fileURLToPath2(new URL(`.`, import.meta.url));
6861
- return path7.resolve(distPath, filePath);
6862
- }
6863
-
6864
7210
  // src/index.ts
6865
7211
  process.on("SIGINT", () => process.exit(0));
6866
7212
  process.on("SIGTERM", () => process.exit(0));