@astryxdesign/cli 0.6.6-canary.a9b5c3d → 0.6.6-canary.bbeffca

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.
Files changed (57) hide show
  1. package/README.md +83 -83
  2. package/api/build/_adapter.d.mts +15 -0
  3. package/api/build/_adapter.mjs +22 -0
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.type.d.mts +4 -0
  6. package/api/build/build.type.mjs +1 -0
  7. package/api/build/help/help.mjs +1 -1
  8. package/api/build/kit/kit.mjs +12 -1
  9. package/api/doctor/theme-checks.mjs +1 -1
  10. package/api/init/run/run.mjs +1 -0
  11. package/api/layout/check/check.d.mts +1 -0
  12. package/api/layout/check/check.mjs +1 -0
  13. package/api/layout/expand/expand.d.mts +1 -0
  14. package/api/layout/expand/expand.mjs +1 -0
  15. package/api/layout/grammar/grammar.d.mts +1 -0
  16. package/api/layout/grammar/grammar.mjs +1 -0
  17. package/api/layout/layoutCheck.doc.mjs +1 -1
  18. package/api/layout/layoutExpand.doc.mjs +1 -1
  19. package/api/layout/layoutGrammar.doc.mjs +1 -1
  20. package/api/template/copy/copy.mjs +12 -0
  21. package/api/template/template.doc.mjs +1 -1
  22. package/api/template/template.type.d.mts +3 -0
  23. package/api/template/template.type.mjs +3 -0
  24. package/api/theme/build/build.d.mts +70 -0
  25. package/api/theme/build/build.mjs +205 -41
  26. package/api/theme/build/font-warning.d.mts +11 -0
  27. package/api/theme/build/font-warning.mjs +28 -3
  28. package/assets/docs/author-a-theme.doc.mjs +1 -1
  29. package/assets/docs/styling-overview.doc.mjs +1 -1
  30. package/assets/docs/theme.doc.dense.mjs +1 -1
  31. package/assets/docs/theme.doc.zh.mjs +1 -1
  32. package/assets/docs/use-a-theme.doc.mjs +1 -1
  33. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  34. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  35. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  36. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  37. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  38. package/clients/cli/commands/build-theme.mjs +68 -18
  39. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  40. package/clients/cli/commands/build.mjs +1 -0
  41. package/clients/cli/commands/layout-check.doc.mjs +1 -0
  42. package/clients/cli/commands/layout-expand.doc.mjs +1 -0
  43. package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
  44. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
  45. package/clients/cli/commands/layout.doc.mjs +1 -0
  46. package/clients/cli/commands/layout.mjs +6 -11
  47. package/clients/cli/commands/template.mjs +2 -1
  48. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  49. package/clients/cli/index.mjs +1 -1
  50. package/clients/cli/lib/define-command.mjs +4 -0
  51. package/foundation/agent-docs/agent-docs.mjs +4 -1
  52. package/foundation/agent-docs/agent-docs.test.mjs +18 -0
  53. package/foundation/discovery/template-needs.d.mts +31 -0
  54. package/foundation/discovery/template-needs.mjs +156 -0
  55. package/foundation/discovery/template-needs.test.mjs +203 -0
  56. package/foundation/response/response-types.doc.mjs +4 -4
  57. package/package.json +9 -9
@@ -0,0 +1,140 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Deprecation lifecycle coverage for the layout command group (DEP-0006).
5
+ *
6
+ * Mirrors the DEP-0005 theme-add-lifecycle tests: pins the JSON
7
+ * `meta.deprecations` entry, the human-mode stderr warning, the help label,
8
+ * and the docs reference pages.
9
+ */
10
+
11
+ import {describe, it, expect} from 'vitest';
12
+ import {runCli} from '../../../test-utils/run-cli.mjs';
13
+
14
+ const SLOW = 30_000;
15
+
16
+ describe('layout DEP-0006 lifecycle', () => {
17
+ it('JSON mode carries meta.deprecations with DEP-0006 and its replacements', async () => {
18
+ const result = await runCli(['layout', 'grammar', '--json']);
19
+ expect(result.status).toBe(0);
20
+ const envelope = JSON.parse(result.stdout);
21
+ expect(envelope.meta).toBeDefined();
22
+ expect(envelope.meta.deprecations).toEqual([
23
+ {
24
+ id: 'DEP-0006',
25
+ replacements: ['build', 'template', 'docs layout'],
26
+ },
27
+ ]);
28
+ // Canonical data is unchanged
29
+ expect(envelope.type).toBe('layout.grammar');
30
+ expect(envelope.data.text).toBeDefined();
31
+ expect(envelope.data.aliases).toBeDefined();
32
+ }, SLOW);
33
+
34
+ it('human mode emits one stderr deprecation warning', async () => {
35
+ const result = await runCli(['layout', 'grammar']);
36
+ expect(result.status).toBe(0);
37
+ expect(result.stderr).toContain('[DEP-0006]');
38
+ expect(result.stderr).toContain('astryx layout is deprecated');
39
+ expect(result.stderr).toContain('astryx build');
40
+ expect(result.stderr).toContain('astryx template');
41
+ expect(result.stderr).toContain('astryx docs layout');
42
+ }, SLOW);
43
+
44
+ it('JSON mode does NOT emit the stderr warning', async () => {
45
+ const result = await runCli(['layout', 'grammar', '--json']);
46
+ expect(result.stderr).not.toContain('[DEP-0006]');
47
+ }, SLOW);
48
+
49
+ it('layout --help labels the command as deprecated', async () => {
50
+ const result = await runCli(['layout', '--help']);
51
+ expect(result.stdout).toContain('DEPRECATED');
52
+ expect(result.stdout).toContain('DEP-0006');
53
+ });
54
+
55
+ it('layout expand --json carries the same meta.deprecations', async () => {
56
+ const result = await runCli([
57
+ 'layout', 'expand', 'V[g6] > C*2', '--json',
58
+ ]);
59
+ expect(result.status).toBe(0);
60
+ const envelope = JSON.parse(result.stdout);
61
+ expect(envelope.meta.deprecations).toEqual([
62
+ {
63
+ id: 'DEP-0006',
64
+ replacements: ['build', 'template', 'docs layout'],
65
+ },
66
+ ]);
67
+ expect(envelope.type).toBe('layout.expand');
68
+ }, SLOW);
69
+
70
+ it('layout check --json carries the same meta.deprecations', async () => {
71
+ const result = await runCli([
72
+ 'layout', 'check', 'V[g6] > C*2', '--json',
73
+ ]);
74
+ expect(result.status).toBe(0);
75
+ const envelope = JSON.parse(result.stdout);
76
+ expect(envelope.meta.deprecations).toEqual([
77
+ {
78
+ id: 'DEP-0006',
79
+ replacements: ['build', 'template', 'docs layout'],
80
+ },
81
+ ]);
82
+ expect(envelope.type).toBe('layout.check');
83
+ }, SLOW);
84
+
85
+ // FR29d: every reference page names DEP-0006 and the replacements.
86
+ // Removing the label from any single page must fail this test.
87
+ describe('docs reference pages name DEP-0006', () => {
88
+ const COMMAND_PAGES = [
89
+ 'cli/commands/layout',
90
+ 'cli/commands/layout-expand',
91
+ 'cli/commands/layout-check',
92
+ 'cli/commands/layout-grammar',
93
+ ];
94
+
95
+ const FUNCTION_PAGES = [
96
+ 'cli/api/functions/layout-expand',
97
+ 'cli/api/functions/layout-check',
98
+ 'cli/api/functions/layout-grammar',
99
+ ];
100
+
101
+ for (const page of COMMAND_PAGES) {
102
+ it(`${page} names DEP-0006 and replacements`, async () => {
103
+ const result = await runCli(['docs', page, '--json']);
104
+ expect(result.status, result.stderr).toBe(0);
105
+ const body = result.stdout;
106
+ expect(body).toContain('DEP-0006');
107
+ expect(body).toContain('build');
108
+ expect(body).toContain('template');
109
+ expect(body).toContain('docs layout');
110
+ }, SLOW);
111
+ }
112
+
113
+ for (const page of FUNCTION_PAGES) {
114
+ it(`${page} names DEP-0006 and replacements`, async () => {
115
+ const result = await runCli(['docs', page, '--json']);
116
+ expect(result.status, result.stderr).toBe(0);
117
+ const body = result.stdout;
118
+ expect(body).toContain('DEP-0006');
119
+ expect(body).toContain('build');
120
+ expect(body).toContain('template');
121
+ expect(body).toContain('docs layout');
122
+ }, SLOW);
123
+ }
124
+ });
125
+
126
+ it('response-types reference names DEP-0006 in each layout entry description', async () => {
127
+ const result = await runCli(['docs', 'cli/api/enums/response-types', '--json']);
128
+ expect(result.status, result.stderr).toBe(0);
129
+ const envelope = JSON.parse(result.stdout);
130
+ // The enum page has a table in its content; each row is [value, description].
131
+ const tables = envelope.data.content.filter(b => b.type === 'table');
132
+ const rows = tables.flatMap(t => t.rows || []);
133
+ for (const type of ['layout.expand', 'layout.check', 'layout.grammar']) {
134
+ const row = rows.find(r => r[0] && r[0].includes(type));
135
+ expect(row, `${type} not found in response-types table`).toBeDefined();
136
+ expect(row[1], `${type} description missing DEP-0006`).toContain('DEP-0006');
137
+ expect(row[1], `${type} description missing replacements`).toContain('replacement');
138
+ }
139
+ }, SLOW);
140
+ });
@@ -31,5 +31,6 @@ export const doc = {
31
31
  {code: 1, when: 'no subcommand (help is printed) or an unknown subcommand'},
32
32
  ],
33
33
  deprecated: 'DEP-0006: Use `astryx build` to start from a template, `astryx template` to scaffold, and `astryx docs layout` for guidance.',
34
+ notes: [{"type": "prose", "text": "**Deprecated (DEP-0006).** Use `astryx build` to choose the template to start from, `astryx template` to scaffold it, and `astryx docs layout` for layout guidance. This command will be removed in a future minor release."}],
34
35
  related: ['template', 'build'],
35
36
  };
@@ -63,17 +63,12 @@ import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
63
63
  * DEP-0006: the `astryx layout` command group is deprecated.
64
64
  *
65
65
  * Human mode: one stderr warning per invocation.
66
- * JSON mode: `meta.deprecation` in the response envelope.
66
+ * JSON mode: `meta.deprecations` array in the response envelope.
67
67
  */
68
- const DEPRECATION = {
68
+ const LAYOUT_DEPRECATION = Object.freeze({
69
69
  id: 'DEP-0006',
70
- cleanup: 'CLN-0006',
71
- replacement: [
72
- 'astryx build "<idea>" — choose the template to start from',
73
- 'astryx template <name> <path> — scaffold it',
74
- 'astryx docs layout — layout guidance',
75
- ],
76
- };
70
+ replacements: ['build', 'template', 'docs layout'],
71
+ });
77
72
 
78
73
  function warnDeprecated() {
79
74
  if (!isJsonMode()) {
@@ -91,10 +86,10 @@ function warnDeprecated() {
91
86
  * Add deprecation metadata to a JSON response before output.
92
87
  * Canonical stdout (type, data) is unchanged; the metadata sits in `meta`.
93
88
  * @param {{type: string, data: unknown}} result
94
- * @returns {{type: string, data: unknown, meta: {deprecation: typeof DEPRECATION}}}
89
+ * @returns {{type: string, data: unknown, meta: {deprecations: [typeof LAYOUT_DEPRECATION]}}}
95
90
  */
96
91
  function withDeprecation(result) {
97
- return {...result, meta: {deprecation: DEPRECATION}};
92
+ return {...result, meta: {deprecations: [LAYOUT_DEPRECATION]}};
98
93
  }
99
94
 
100
95
  /** The largest layout expression read from --file or stdin. */
@@ -220,7 +220,7 @@ export function registerTemplate(program) {
220
220
  }
221
221
 
222
222
  case 'template.copy': {
223
- const {outputDir, fileName, demoMediaReplaced} = result.data;
223
+ const {outputDir, fileName, demoMediaReplaced, notes} = result.data;
224
224
  const file = `${outputDir}/${fileName}`;
225
225
  emit(
226
226
  text(`Copied template to ${file}`),
@@ -230,6 +230,7 @@ export function registerTemplate(program) {
230
230
  `Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'} in ${file}: ` +
231
231
  'images now show a neutral placeholder and videos have an empty source. Supply your own media there.',
232
232
  ),
233
+ ...notes.map(/** @param {string} note */ note => text(note)),
233
234
  );
234
235
  break;
235
236
  }
@@ -21,7 +21,9 @@ export const doc = {
21
21
  'theme. --family combines one selected extension tree into the three files named by ' +
22
22
  'the required --family-key, ready for one CSS load and identity-only switching. ' +
23
23
  'With --check it writes nothing and reports source drift. --icons-specifier keeps ' +
24
- 'its existing generated-module behavior.',
24
+ 'its existing generated-module behavior. It prints one line per built theme and ' +
25
+ 'one line naming fonts the themes do not load; --detail full adds the install ' +
26
+ 'example and the font recipe, once for a batch.',
25
27
  fn: 'themeBuild',
26
28
  args: [{name: 'files', param: 'file', required: true, variadic: true}],
27
29
  options: [
@@ -362,7 +362,7 @@ export async function createProgram() {
362
362
  .addOption(
363
363
  new Option(
364
364
  '--detail <level>',
365
- 'Detail level for component, hook, and docs tree reads (e.g. docs cli/commands/build). Lists default to brief',
365
+ 'Detail level for component, hook, and docs tree reads (e.g. docs cli/commands/build), and for theme build reports. Lists default to brief; theme build prints one line per built theme unless full, which adds the install example and font recipe',
366
366
  )
367
367
  .choices(['full', 'compact', 'brief'])
368
368
  .default('full'),
@@ -122,6 +122,10 @@ export function defineCommand(parent, doc, {fn, action} = {}) {
122
122
  const cmd = parent.command(argSpec ? `${token} ${argSpec}` : token);
123
123
  Object.defineProperty(cmd, COMMAND_DOCS, {value: {doc, fn}, configurable: true});
124
124
  if (doc.summary) cmd.description(doc.summary);
125
+ if (doc.deprecated) {
126
+ const base = cmd.description() || '';
127
+ cmd.description(`${base} [DEPRECATED: ${doc.deprecated}]`);
128
+ }
125
129
 
126
130
  const paramDesc = (/** @type {string | undefined} */ name) =>
127
131
  (fn?.params ?? []).find(p => p.name === name)?.description ?? '';
@@ -335,6 +335,9 @@ export function detectStylingSystem(targetDir) {
335
335
  // Key off a StyleX *compiler* plugin — the runtime alone won't render.
336
336
  const stylexCompilers = [
337
337
  '@stylexjs/babel-plugin',
338
+ '@stylexjs/rollup-plugin',
339
+ '@stylexjs/webpack-plugin',
340
+ '@stylexjs/nextjs-plugin',
338
341
  'vite-plugin-stylex',
339
342
  'unplugin-stylex',
340
343
  '@stylexswc/unplugin',
@@ -452,7 +455,7 @@ export function generateCompressedIndex(
452
455
  } else if (stylingSystem === 'tailwind') {
453
456
  lines.push('- Style with component props first, then Tailwind utilities backed by tokens. No raw hex/px.');
454
457
  } else {
455
- lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes.");
458
+ lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes directly. Some templates use StyleX and need a compiler plugin; see `astryx docs styling-overview`.");
456
459
  }
457
460
  lines.push('- Palettes and custom colors go through the theme, never :root overrides. See `astryx docs theme`.');
458
461
  // Self-check — post-generation pass. Validated via vibe tests (internal/vibe-tests/
@@ -89,6 +89,9 @@ describe('generateCompressedIndex', () => {
89
89
  expect(result).not.toMatch(/xstyle prop/);
90
90
  // Must warn that no compiler is present.
91
91
  expect(result).toMatch(/No StyleX\/Tailwind compiler/);
92
+ // Must acknowledge that some templates use StyleX and point at the doc.
93
+ expect(result).toMatch(/templates.*StyleX/i);
94
+ expect(result).toMatch(/styling-overview/);
92
95
  });
93
96
 
94
97
  it('recommends xstyle when StyleX is configured', () => {
@@ -371,6 +374,21 @@ describe('detectStylingSystem', () => {
371
374
  expect(detectStylingSystem(tmpDir)).toBe('stylex');
372
375
  });
373
376
 
377
+ it('detects the official Rollup/Vite plugin', () => {
378
+ writePkg({'@stylexjs/rollup-plugin': '0.10.0'});
379
+ expect(detectStylingSystem(tmpDir)).toBe('stylex');
380
+ });
381
+
382
+ it('detects the official Webpack plugin', () => {
383
+ writePkg({'@stylexjs/webpack-plugin': '0.10.0'});
384
+ expect(detectStylingSystem(tmpDir)).toBe('stylex');
385
+ });
386
+
387
+ it('detects the official Next.js plugin', () => {
388
+ writePkg({'@stylexjs/nextjs-plugin': '0.10.0'});
389
+ expect(detectStylingSystem(tmpDir)).toBe('stylex');
390
+ });
391
+
374
392
  it('detects tailwind when tailwindcss is present', () => {
375
393
  writePkg({tailwindcss: '4.0.0'});
376
394
  expect(detectStylingSystem(tmpDir)).toBe('tailwind');
@@ -0,0 +1,31 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Extract bare (non-relative) package names from ES import statements.
6
+ *
7
+ * @param {string} source Template source code
8
+ * @returns {Set<string>} Unique package names (scoped packages normalized to
9
+ * `@scope/name`, unscoped to the first path segment).
10
+ */
11
+ export function extractImportedPackages(source: string): Set<string>;
12
+ /**
13
+ * Analyze what a template source needs that the target project lacks.
14
+ *
15
+ * Returns a `notes` array of human-readable setup notes, a structured
16
+ * `missingPackages` list, and an `installCommand` string ready to print.
17
+ * Each note is one actionable line.
18
+ *
19
+ * @param {string} source Template source code
20
+ * @param {string} cwd Target project directory
21
+ * @returns {{
22
+ * notes: string[],
23
+ * missingPackages: string[],
24
+ * installCommand: string | null,
25
+ * }}
26
+ */
27
+ export function analyzeTemplateNeeds(source: string, cwd: string): {
28
+ notes: string[];
29
+ missingPackages: string[];
30
+ installCommand: string | null;
31
+ };
@@ -0,0 +1,156 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Analyze what a scaffolded template needs that the target project lacks.
5
+ *
6
+ * Derives needs from the template's own source — its bare import specifiers —
7
+ * rather than from a hand-maintained list. Every import that is not an Astryx
8
+ * package, react/react-dom, or @stylexjs/stylex is external; the source is the
9
+ * only authority on what a template uses.
10
+ *
11
+ * Shared between `api/template/copy` (the scaffold receipt) and
12
+ * `api/build/kit` (the start recommendation).
13
+ *
14
+ * @position packages/cli/foundation/discovery — template discovery helpers;
15
+ * consumed by the template and build API leaves.
16
+ */
17
+
18
+ import * as fs from 'node:fs';
19
+ import * as path from 'node:path';
20
+ import module from 'node:module';
21
+ import {CLI_ROOT} from '../fs/paths.mjs';
22
+ import {detectStylingSystem} from '../agent-docs/agent-docs.mjs';
23
+
24
+ // ── Known packages that a template may import without the user installing them.
25
+ // react and react-dom are the framework; @astryxdesign/* is the design system
26
+ // the CLI already told the user to install; @stylexjs/stylex is a peer of Core.
27
+ const FRAMEWORK_PREFIXES = ['react', 'react-dom'];
28
+ const DESIGN_SYSTEM_SCOPE = '@astryxdesign/';
29
+ const STYLEX_RUNTIME = '@stylexjs/stylex';
30
+
31
+ // Node builtins: anything with a `node:` prefix or in builtinModules.
32
+ const NODE_BUILTINS = new Set(module.builtinModules);
33
+
34
+ /**
35
+ * Extract bare (non-relative) package names from ES import statements.
36
+ *
37
+ * @param {string} source Template source code
38
+ * @returns {Set<string>} Unique package names (scoped packages normalized to
39
+ * `@scope/name`, unscoped to the first path segment).
40
+ */
41
+ export function extractImportedPackages(source) {
42
+ // Matches `import … from '<specifier>'`, `import '<specifier>'`, and
43
+ // dynamic `import('<specifier>')`. Only bare specifiers (not starting with
44
+ // `.` or `/`).
45
+ const re = /(?:from\s+|import\s*\(?)['"]((?:@[^/'"]+\/)?[^./'"@][^'"]*)['"]/g;
46
+ /** @type {Set<string>} */
47
+ const pkgs = new Set();
48
+ let m;
49
+ while ((m = re.exec(source)) !== null) {
50
+ const spec = m[1];
51
+ // Skip Node builtins: `node:fs`, `fs`, `fs/promises`, etc.
52
+ if (spec.startsWith('node:')) continue;
53
+ const name = spec.startsWith('@')
54
+ ? spec.split('/').slice(0, 2).join('/')
55
+ : spec.split('/')[0];
56
+ if (NODE_BUILTINS.has(name)) continue;
57
+ pkgs.add(name);
58
+ }
59
+ return pkgs;
60
+ }
61
+
62
+ /**
63
+ * Detect which package manager the project uses, from its lockfile.
64
+ * @param {string} cwd Project root
65
+ * @returns {'pnpm add' | 'yarn add' | 'bun add' | 'npm install'}
66
+ */
67
+ function detectInstallCommand(cwd) {
68
+ if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml'))) return 'pnpm add';
69
+ if (fs.existsSync(path.join(cwd, 'yarn.lock'))) return 'yarn add';
70
+ if (fs.existsSync(path.join(cwd, 'bun.lockb'))) return 'bun add';
71
+ return 'npm install';
72
+ }
73
+
74
+ /**
75
+ * Read the CLI package's own devDependencies for authoritative version ranges
76
+ * of external packages the templates use.
77
+ * @returns {Record<string, string>}
78
+ */
79
+ function cliPackageRanges() {
80
+ try {
81
+ const pkgPath = path.join(CLI_ROOT, 'package.json');
82
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
83
+ return {...pkg.devDependencies};
84
+ } catch {
85
+ return {};
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Analyze what a template source needs that the target project lacks.
91
+ *
92
+ * Returns a `notes` array of human-readable setup notes, a structured
93
+ * `missingPackages` list, and an `installCommand` string ready to print.
94
+ * Each note is one actionable line.
95
+ *
96
+ * @param {string} source Template source code
97
+ * @param {string} cwd Target project directory
98
+ * @returns {{
99
+ * notes: string[],
100
+ * missingPackages: string[],
101
+ * installCommand: string | null,
102
+ * }}
103
+ */
104
+ export function analyzeTemplateNeeds(source, cwd) {
105
+ const imported = extractImportedPackages(source);
106
+
107
+ // ── External packages (not framework / design system / stylex runtime) ──
108
+ const external = [...imported].filter(
109
+ name =>
110
+ !FRAMEWORK_PREFIXES.includes(name) &&
111
+ !name.startsWith(DESIGN_SYSTEM_SCOPE) &&
112
+ name !== STYLEX_RUNTIME,
113
+ );
114
+
115
+ // Read the project's installed packages.
116
+ /** @type {Record<string, string>} */
117
+ let projectDeps = {};
118
+ try {
119
+ const pkg = JSON.parse(
120
+ fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'),
121
+ );
122
+ projectDeps = {...pkg.dependencies, ...pkg.devDependencies};
123
+ } catch {
124
+ // No package.json or unreadable — treat everything as missing.
125
+ }
126
+
127
+ const missing = external.filter(p => !(p in projectDeps));
128
+
129
+ // Build the install command with version ranges from the CLI workspace.
130
+ let installCommand = null;
131
+ if (missing.length > 0) {
132
+ const pm = detectInstallCommand(cwd);
133
+ const ranges = cliPackageRanges();
134
+ const specs = missing.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
135
+ installCommand = `${pm} ${specs.join(' ')}`;
136
+ }
137
+
138
+ // ── StyleX compiler ────────────────────────────────────────────────────
139
+ const usesStylex = imported.has(STYLEX_RUNTIME);
140
+ const stylexCompilerNeeded =
141
+ usesStylex && detectStylingSystem(cwd) !== 'stylex';
142
+
143
+ // ── Notes ──────────────────────────────────────────────────────────────
144
+ /** @type {string[]} */
145
+ const notes = [];
146
+ if (missing.length > 0) {
147
+ notes.push(`Install missing dependencies: ${installCommand}`);
148
+ }
149
+ if (stylexCompilerNeeded) {
150
+ notes.push(
151
+ 'This template uses StyleX. Your project needs a StyleX compiler plugin \u2014 see `astryx docs styling-overview` for setup steps.',
152
+ );
153
+ }
154
+
155
+ return {notes, missingPackages: missing, installCommand};
156
+ }