@astralkit/cli 4.2.3 → 4.3.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to the `@astralkit/cli` package.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.3.0] — 2026-04-22
9
+
10
+ ### Fixed
11
+ - **No more silent modification of `layout.tsx`.** When a component pulls in a side-effect import package (e.g. `@phosphor-icons/web` registering its font CSS), the CLI previously injected `import '@phosphor-icons/web/regular'` lines into `src/app/layout.tsx` without asking. Root layout is one of the most critical files in a Next.js app — silent edits broke trust with users installing into mature projects. The CLI now prints the exact diff and prompts with a default of **No**; declining leaves the component files in place and prints the imports so the user can add them by hand.
12
+ - **Phosphor icon conflict detection.** `@phosphor-icons/web` (CSS classes) and `@phosphor-icons/react` (React components) are separate packages that ship two different icon systems. Installing both in one codebase bloats the bundle and splits the icon convention. If the host project already has `@phosphor-icons/react` as a dependency, the CLI now warns and asks before installing `@phosphor-icons/web` — and if the user declines, skips both the dependency install and the layout-file edit.
13
+ - **End-of-install summary.** After any `astralkit add`, the CLI now prints a grouped summary of Created files, Modified files (with reason), Installed deps, Already-satisfied deps, and Skipped items — so users don't have to run `git diff` to see what changed.
14
+
15
+ ### Compatibility
16
+ - No breaking changes. All new behavior is additive (prompts where there was silent action) and defaults bias toward user consent.
17
+
8
18
  ## [4.2.3] — 2026-04-19
9
19
 
10
20
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralkit/cli",
3
- "version": "4.2.3",
3
+ "version": "4.3.0",
4
4
  "description": "AstralKit CLI — Install and manage UI components in your project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -143,6 +143,27 @@ function resolveExtension(framework) {
143
143
  return isTS ? '.tsx' : '.jsx';
144
144
  }
145
145
 
146
+ // Read the target project's package.json. Used to detect package conflicts
147
+ // (e.g. host already uses @phosphor-icons/react and we're about to add the
148
+ // separate @phosphor-icons/web). Returns null if the file is unreadable.
149
+ function readHostPackageJson() {
150
+ try {
151
+ const raw = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8');
152
+ return JSON.parse(raw);
153
+ } catch {
154
+ return null;
155
+ }
156
+ }
157
+
158
+ function hostHasDep(pkg, name) {
159
+ if (!pkg) return false;
160
+ return Boolean(
161
+ pkg.dependencies?.[name] ||
162
+ pkg.devDependencies?.[name] ||
163
+ pkg.optionalDependencies?.[name]
164
+ );
165
+ }
166
+
146
167
  async function addComponent(componentSlug, options) {
147
168
  if (!validateSlug(componentSlug)) process.exit(1);
148
169
  if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) {
@@ -150,6 +171,17 @@ async function addComponent(componentSlug, options) {
150
171
  return;
151
172
  }
152
173
 
174
+ // Tracked across the full install so the end-of-run summary can tell the
175
+ // user exactly what changed in their project (created files, modified
176
+ // files, installed deps, anything skipped by user confirmation).
177
+ const installSummary = {
178
+ created: [], // relative file paths written
179
+ modified: [], // { path, note }
180
+ installed: [], // dep names
181
+ alreadySatisfied: [], // dep names
182
+ skipped: [], // { what, reason }
183
+ };
184
+
153
185
  const ora = (await import('ora')).default;
154
186
  const framework = resolveFramework(options);
155
187
  const ext = resolveExtension(framework);
@@ -202,16 +234,16 @@ async function addComponent(componentSlug, options) {
202
234
  for (const file of filesToWrite) {
203
235
  if (!isSafePath(dir, file.path)) {
204
236
  console.log(pc.red(` Skipping suspicious path: ${file.path}`));
237
+ installSummary.skipped.push({ what: file.path, reason: 'unsafe path' });
205
238
  continue;
206
239
  }
207
240
  const filePath = path.resolve(dir, file.path);
208
241
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
209
242
  fs.writeFileSync(filePath, file.content);
243
+ installSummary.created.push(path.join(componentsDir, file.path).replace(/\\/g, '/'));
210
244
  }
211
245
 
212
246
  spinner.succeed(`Added ${pc.cyan(data.name || componentSlug)} (${FRAMEWORK_LABELS[framework]})`);
213
- console.log(pc.gray(` ${componentsDir}/`));
214
- for (const file of filesToWrite) console.log(pc.gray(` ${file.path}`));
215
247
 
216
248
  if (!isAstralkitInstalled()) {
217
249
  p.log.warn('Run ' + pc.cyan('astralkit init') + ' to set up design tokens.');
@@ -227,13 +259,42 @@ async function addComponent(componentSlug, options) {
227
259
 
228
260
  // Detect if component uses Phosphor Icons (CSS class-based icons)
229
261
  const componentCode = data.files?.map(f => f.content).join('') || '';
230
- const usesPhosphorCss = componentCode.includes('class="ph ') || componentCode.includes("class='ph ") || componentCode.includes('"ph ph-') || componentCode.includes("'ph ph-");
262
+ let usesPhosphorCss = componentCode.includes('class="ph ') || componentCode.includes("class='ph ") || componentCode.includes('"ph ph-') || componentCode.includes("'ph ph-");
263
+
264
+ // Phosphor conflict guard: @phosphor-icons/web and @phosphor-icons/react
265
+ // are SEPARATE packages (CSS classes vs React components). Installing both
266
+ // ships two icon systems in the same codebase — bundle bloat and a
267
+ // long-term consistency tax. If the host already uses the React package,
268
+ // warn loudly and let the user opt out of auto-installing web.
269
+ if (usesPhosphorCss) {
270
+ const hostPkg = readHostPackageJson();
271
+ if (hostHasDep(hostPkg, '@phosphor-icons/react')) {
272
+ p.log.warn(`This component uses ${pc.cyan('@phosphor-icons/web')} (CSS class-based icons).`);
273
+ p.log.warn(`Your project already uses ${pc.cyan('@phosphor-icons/react')} (React components) — a ${pc.bold('separate package')} from the same vendor.`);
274
+ p.log.warn(`Installing both ships two icon systems side by side.`);
275
+
276
+ const proceed = await p.confirm({
277
+ message: 'Install @phosphor-icons/web anyway?',
278
+ initialValue: false,
279
+ });
280
+ if (p.isCancel(proceed) || !proceed) {
281
+ p.log.info('Skipping @phosphor-icons/web and the layout.tsx import.');
282
+ p.log.info(pc.gray('Adapt the component\'s <i className="ph ph-*"> tags to @phosphor-icons/react React components.'));
283
+ usesPhosphorCss = false;
284
+ installSummary.skipped.push({
285
+ what: '@phosphor-icons/web',
286
+ reason: 'host project uses @phosphor-icons/react; user declined',
287
+ });
288
+ }
289
+ }
290
+ }
231
291
 
232
292
  if (data.dependencies?.length || usesPhosphorCss) {
233
293
  const pm = detectPackageManager();
234
294
  const rawDepList = (data.dependencies || []).filter(d => d !== 'astralkit' && d !== 'clsx' && d !== 'tailwind-merge');
235
295
 
236
296
  // Auto-add @phosphor-icons/web if component uses CSS-based Phosphor icons
297
+ // AND we didn't skip it above due to a @phosphor-icons/react conflict.
237
298
  if (usesPhosphorCss && !rawDepList.includes('@phosphor-icons/web')) {
238
299
  rawDepList.push('@phosphor-icons/web');
239
300
  }
@@ -247,21 +308,46 @@ async function addComponent(componentSlug, options) {
247
308
  }
248
309
 
249
310
  if (depList.length > 0) {
250
- // Always ask before running npm install — mirrors the booster flow.
251
- const install = await p.confirm({
252
- message: `Install dependencies? (${depList.join(', ')})`,
253
- initialValue: true,
254
- });
255
- if (!p.isCancel(install) && install) {
256
- const s = ora(`Installing ${depList.join(', ')}...`).start();
257
- const result = await runInstall(pm, process.cwd(), depList);
258
- if (result.success) s.succeed(`Installed ${depList.join(', ')}`);
259
- else { s.fail(sanitizeForTerminal(result.error || 'Install failed')); if (result.hint) console.log(pc.gray(` ${sanitizeForTerminal(result.hint)}`)); }
311
+ // Split into already-present vs to-install so the user sees both in
312
+ // the end-of-install summary.
313
+ const hostPkg = readHostPackageJson();
314
+ const toInstall = depList.filter(d => !hostHasDep(hostPkg, d));
315
+ const alreadyThere = depList.filter(d => hostHasDep(hostPkg, d));
316
+ for (const d of alreadyThere) installSummary.alreadySatisfied.push(d);
317
+
318
+ if (toInstall.length > 0) {
319
+ // Always ask before running npm install — mirrors the booster flow.
320
+ const install = await p.confirm({
321
+ message: `Install dependencies? (${toInstall.join(', ')})`,
322
+ initialValue: true,
323
+ });
324
+ if (!p.isCancel(install) && install) {
325
+ const s = ora(`Installing ${toInstall.join(', ')}...`).start();
326
+ const result = await runInstall(pm, process.cwd(), toInstall);
327
+ if (result.success) {
328
+ s.succeed(`Installed ${toInstall.join(', ')}`);
329
+ for (const d of toInstall) installSummary.installed.push(d);
330
+ } else {
331
+ s.fail(sanitizeForTerminal(result.error || 'Install failed'));
332
+ if (result.hint) console.log(pc.gray(` ${sanitizeForTerminal(result.hint)}`));
333
+ for (const d of toInstall) {
334
+ installSummary.skipped.push({ what: d, reason: 'install failed' });
335
+ }
336
+ }
337
+ } else {
338
+ for (const d of toInstall) {
339
+ installSummary.skipped.push({ what: d, reason: 'user declined install' });
340
+ }
341
+ }
260
342
  }
261
343
  }
262
344
 
263
345
  // Auto-add JS imports for icon/font packages in layout file
264
- // (CSS @import doesn't resolve node_modules exports in Next.js PostCSS)
346
+ // (CSS @import doesn't resolve node_modules exports in Next.js PostCSS).
347
+ // This modifies a user-owned file — one of the most critical in a
348
+ // Next.js app — so we now show the exact diff and prompt for consent
349
+ // with a default of NO. Silent modification of layout.tsx was a
350
+ // reported trust issue (CLI feedback 2026-04-22).
265
351
  const JS_DEPENDENCY_IMPORTS = {
266
352
  '@phosphor-icons/web': [
267
353
  "import '@phosphor-icons/web/regular'",
@@ -269,10 +355,15 @@ async function addComponent(componentSlug, options) {
269
355
  ],
270
356
  };
271
357
 
358
+ // Only consider packages we actually installed (or that were already
359
+ // present) — no point prompting about imports for a dep the user skipped.
360
+ const effectiveDeps = new Set([
361
+ ...installSummary.installed,
362
+ ...installSummary.alreadySatisfied,
363
+ ]);
272
364
  for (const [pkg, imports] of Object.entries(JS_DEPENDENCY_IMPORTS)) {
273
- if (!depList.includes(pkg)) continue;
365
+ if (!effectiveDeps.has(pkg)) continue;
274
366
 
275
- // Find the layout file
276
367
  const layoutCandidates = [
277
368
  'src/app/layout.tsx', 'src/app/layout.jsx', 'src/app/layout.js',
278
369
  'app/layout.tsx', 'app/layout.jsx', 'app/layout.js',
@@ -291,30 +382,88 @@ async function addComponent(componentSlug, options) {
291
382
 
292
383
  const layoutContent = fs.readFileSync(layoutFile.path, 'utf8');
293
384
  const missing = imports.filter(imp => !layoutContent.includes(imp));
294
- if (missing.length > 0) {
295
- // Add after the first import line
296
- const lines = layoutContent.split('\n');
297
- let lastImportIdx = -1;
298
- for (let i = 0; i < lines.length; i++) {
299
- if (lines[i].trim().startsWith('import ')) lastImportIdx = i;
300
- }
301
- if (lastImportIdx >= 0) {
302
- lines.splice(lastImportIdx + 1, 0, ...missing);
303
- } else {
304
- lines.unshift(...missing);
305
- }
306
- fs.writeFileSync(layoutFile.path, lines.join('\n'));
307
- p.log.success(`Added ${pc.cyan(pkg)} imports to ${pc.cyan(layoutFile.relative)}`);
385
+ if (missing.length === 0) continue;
386
+
387
+ // Show the exact diff we want to apply — never silently modify.
388
+ p.log.warn(`${pc.cyan(pkg)} needs these side-effect imports in your root layout:`);
389
+ console.log(pc.gray(` ${layoutFile.relative}`));
390
+ for (const imp of missing) console.log(` ${pc.green('+')} ${imp}`);
391
+
392
+ const proceed = await p.confirm({
393
+ message: `Add these imports to ${layoutFile.relative}?`,
394
+ initialValue: false,
395
+ });
396
+
397
+ if (p.isCancel(proceed) || !proceed) {
398
+ p.log.info(`Skipped ${layoutFile.relative} edit. Add these lines manually to enable icons:`);
399
+ for (const imp of missing) console.log(pc.gray(` ${imp}`));
400
+ installSummary.skipped.push({
401
+ what: `${layoutFile.relative} imports (${pkg})`,
402
+ reason: 'user declined',
403
+ });
404
+ continue;
405
+ }
406
+
407
+ const lines = layoutContent.split('\n');
408
+ let lastImportIdx = -1;
409
+ for (let i = 0; i < lines.length; i++) {
410
+ if (lines[i].trim().startsWith('import ')) lastImportIdx = i;
411
+ }
412
+ if (lastImportIdx >= 0) {
413
+ lines.splice(lastImportIdx + 1, 0, ...missing);
414
+ } else {
415
+ lines.unshift(...missing);
308
416
  }
417
+ fs.writeFileSync(layoutFile.path, lines.join('\n'));
418
+ installSummary.modified.push({
419
+ path: layoutFile.relative,
420
+ note: `+${missing.length} ${missing.length === 1 ? 'import' : 'imports'} (${pkg})`,
421
+ });
422
+ p.log.success(`Added ${pc.cyan(pkg)} imports to ${pc.cyan(layoutFile.relative)}`);
309
423
  }
310
424
  }
311
425
 
426
+ printInstallSummary(installSummary);
427
+
312
428
  } catch (err) {
313
429
  spinner.fail('Failed to add component.');
314
430
  handleAddError(err, componentSlug, framework);
315
431
  }
316
432
  }
317
433
 
434
+ // End-of-install summary. Prints what the CLI did to the user's project so
435
+ // they never have to run `git diff` just to find out what was touched. Split
436
+ // into Created / Modified / Installed / Skipped so each category is scannable.
437
+ function printInstallSummary(s) {
438
+ const hasAny =
439
+ s.created.length || s.modified.length || s.installed.length ||
440
+ s.alreadySatisfied.length || s.skipped.length;
441
+ if (!hasAny) return;
442
+
443
+ console.log('');
444
+ p.log.step(pc.bold('What changed in your project'));
445
+ if (s.created.length) {
446
+ console.log(pc.green(' Created:'));
447
+ for (const f of s.created) console.log(pc.gray(` ${f}`));
448
+ }
449
+ if (s.modified.length) {
450
+ console.log(pc.yellow(' Modified:'));
451
+ for (const m of s.modified) console.log(pc.gray(` ${m.path} ${pc.dim(m.note)}`));
452
+ }
453
+ if (s.installed.length) {
454
+ console.log(pc.cyan(' Installed:'));
455
+ for (const d of s.installed) console.log(pc.gray(` ${d}`));
456
+ }
457
+ if (s.alreadySatisfied.length) {
458
+ console.log(pc.gray(' Already satisfied:'));
459
+ for (const d of s.alreadySatisfied) console.log(pc.gray(` ${d}`));
460
+ }
461
+ if (s.skipped.length) {
462
+ console.log(pc.gray(' Skipped:'));
463
+ for (const k of s.skipped) console.log(pc.gray(` ${k.what} ${pc.dim(`(${k.reason})`)}`));
464
+ }
465
+ }
466
+
318
467
  async function addBooster(slug, options) {
319
468
  if (!validateSlug(slug, 'booster name')) process.exit(1);
320
469