@astryxdesign/cli 0.7.4-canary.b25f95e → 0.7.4-canary.e5c5a87

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.
@@ -164,10 +164,50 @@ export function installCommandFor(cwd: string): ((name: string) => string) | nul
164
164
  * @returns {boolean}
165
165
  */
166
166
  export function insideProjectElsewhere(cwd: string): boolean;
167
+ /**
168
+ * The absolute path `doctor --built` checks, or null when it does not exist.
169
+ * @param {string} cwd
170
+ * @param {string} target
171
+ * @returns {string | null}
172
+ */
173
+ export function resolveBuiltPath(cwd: string, target: string): string | null;
174
+ /**
175
+ * The files under a `doctor --built` path, in a stable order: each with its
176
+ * path relative to the folder (a file's own name when the path is one file),
177
+ * whether it sits in build output, and a reader that returns its text, or
178
+ * null when it cannot be read or is over 5 MB. Installs and version control
179
+ * are skipped; at most BUILT_FILE_LIMIT files are listed.
180
+ * @param {string} target an existing absolute path
181
+ * @returns {{files: {rel: string, built: boolean, read: () => string | null}[], truncated: boolean, missing?: number}}
182
+ */
183
+ export function readBuiltPath(target: string): {
184
+ files: {
185
+ rel: string;
186
+ built: boolean;
187
+ read: () => string | null;
188
+ }[];
189
+ truncated: boolean;
190
+ missing?: number;
191
+ };
192
+ /**
193
+ * The integration packages whose components count as Astryx for a `--built`
194
+ * path, read without running anything: each dependency the nearest
195
+ * package.json above the path declares whose installed copy, resolved the way
196
+ * the CLI autolinks integrations (a workspace root's hoisted copy included),
197
+ * holds an integration manifest. Every `@astryxdesign/*` package counts
198
+ * beside them.
199
+ * @param {string} target the path as given
200
+ * @param {string} cwd
201
+ * @returns {string[]}
202
+ */
203
+ export function builtIntegrationPackages(target: string, cwd: string): string[];
167
204
  export { resolveRecordedTheme } from "../theme/theme.mjs";
168
205
  export { collectUnloadedFonts } from "../theme/build/font-warning.mjs";
169
206
  export const SOURCE_EXTENSIONS: Set<string>;
170
207
  export { displayHomePath };
208
+ /** `doctor --built` reads at most this many files, of at most this size. */
209
+ export const BUILT_FILE_LIMIT: 20000;
210
+ export const BUILT_FILE_MAX_MB: 5;
171
211
  import { globalBehind } from '../../foundation/release/notices.mjs';
172
212
  import { projectLag } from '../../foundation/release/notices.mjs';
173
213
  import { lastNoticeSkip } from '../../foundation/release/notices.mjs';
@@ -26,7 +26,10 @@ import {
26
26
  } from '../../foundation/release/choose.mjs';
27
27
  import {readReleaseFacts} from '../../foundation/release/project.mjs';
28
28
  import {astryxCommandsOnSearchPath} from '../../foundation/env/search-path.mjs';
29
- import {readDeclaredDependencies} from '../../foundation/integrations/autolink.mjs';
29
+ import {
30
+ readDeclaredDependencies,
31
+ scanAutolinkCandidates,
32
+ } from '../../foundation/integrations/autolink.mjs';
30
33
  import {
31
34
  computerSkillFile,
32
35
  displayHomePath,
@@ -437,3 +440,170 @@ export function installCommandFor(cwd) {
437
440
  export function insideProjectElsewhere(cwd) {
438
441
  return installFolder(cwd)?.moved === true;
439
442
  }
443
+
444
+ /** Folders `doctor --built` never reads: installs and version control. */
445
+ const BUILT_SKIPPED_DIRS = new Set(['node_modules', '.git', '.hg', '.sl']);
446
+
447
+ /** Folders that hold build output: read for stylesheets, never as source. */
448
+ const BUILD_OUTPUT_DIRS = new Set(['.next', 'dist', 'build', 'out', '.output']);
449
+
450
+ /** `doctor --built` reads at most this many files, of at most this size. */
451
+ export const BUILT_FILE_LIMIT = 20000;
452
+ export const BUILT_FILE_MAX_MB = 5;
453
+ const BUILT_FILE_MAX_BYTES = BUILT_FILE_MAX_MB * 1024 * 1024;
454
+
455
+ /**
456
+ * The absolute path `doctor --built` checks, or null when it does not exist.
457
+ * @param {string} cwd
458
+ * @param {string} target
459
+ * @returns {string | null}
460
+ */
461
+ export function resolveBuiltPath(cwd, target) {
462
+ const resolved = path.resolve(cwd, target);
463
+ return fs.existsSync(resolved) ? resolved : null;
464
+ }
465
+
466
+ /**
467
+ * The files under a `doctor --built` path, in a stable order: each with its
468
+ * path relative to the folder (a file's own name when the path is one file),
469
+ * whether it sits in build output, and a reader that returns its text, or
470
+ * null when it cannot be read or is over 5 MB. Installs and version control
471
+ * are skipped; at most BUILT_FILE_LIMIT files are listed.
472
+ * @param {string} target an existing absolute path
473
+ * @returns {{files: {rel: string, built: boolean, read: () => string | null}[], truncated: boolean, missing?: number}}
474
+ */
475
+ export function readBuiltPath(target) {
476
+ /** @param {string} file */
477
+ const reader = file => () => {
478
+ try {
479
+ if (fs.statSync(file).size > BUILT_FILE_MAX_BYTES) return null;
480
+ return fs.readFileSync(file, 'utf8');
481
+ } catch {
482
+ return null;
483
+ }
484
+ };
485
+ if (!fs.statSync(target).isDirectory()) {
486
+ const inBuild = path
487
+ .dirname(target)
488
+ .split(path.sep)
489
+ .some(part => BUILD_OUTPUT_DIRS.has(part));
490
+ /** @type {{rel: string, built: boolean, read: () => string | null}[]} */
491
+ const files = [
492
+ {rel: path.basename(target), built: inBuild, read: reader(target)},
493
+ ];
494
+ let missing = 0;
495
+ // A built page carries its styles and scripts in files it links: read
496
+ // the local ones beside it, as built output.
497
+ if (/\.html?$/iu.test(target)) {
498
+ // A link inside an HTML comment is not one the page loads.
499
+ const page = (reader(target)() ?? '').replace(/<!--[\s\S]*?-->/g, ' ');
500
+ const seen = new Set([path.resolve(target)]);
501
+ for (const match of page.matchAll(
502
+ /<(?:link|script)\b[^>]*?\b(?:href|src)\s*=\s*(?:"([^"#?]+)|'([^'#?]+)|([^\s"'#?>]+))/giu,
503
+ )) {
504
+ const href = match[1] ?? match[2] ?? match[3];
505
+ if (/^(?:[a-z][\w+.-]*:|\/\/)/iu.test(href)) continue;
506
+ // A root-relative link names a file from the build root: the page's
507
+ // folder or the nearest folder above it that holds the file.
508
+ let file = path.resolve(path.dirname(target), href.replace(/^\//u, ''));
509
+ if (href.startsWith('/')) {
510
+ for (let dir = path.dirname(target); ; dir = path.dirname(dir)) {
511
+ const candidate = path.join(dir, href);
512
+ if (fs.existsSync(candidate)) {
513
+ file = candidate;
514
+ break;
515
+ }
516
+ if (path.dirname(dir) === dir) break;
517
+ }
518
+ }
519
+ if (seen.has(file)) continue;
520
+ if (!fs.existsSync(file)) {
521
+ // Only a missing stylesheet could have held Astryx styles; a
522
+ // missing favicon or manifest changes nothing.
523
+ if (
524
+ /\.css$/iu.test(href) ||
525
+ /\brel\s*=\s*["']?stylesheet/iu.test(match[0])
526
+ ) {
527
+ missing++;
528
+ }
529
+ continue;
530
+ }
531
+ seen.add(file);
532
+ files.push({
533
+ rel: path
534
+ .relative(path.dirname(target), file)
535
+ .split(path.sep)
536
+ .join('/'),
537
+ built: true,
538
+ read: reader(file),
539
+ });
540
+ }
541
+ }
542
+ return {files, truncated: false, missing};
543
+ }
544
+ /** @type {{rel: string, built: boolean, read: () => string | null}[]} */
545
+ const files = [];
546
+ // A path that is itself build output (`--built dist`) is read as built.
547
+ /** @type {{dir: string, built: boolean}[]} */
548
+ const stack = [
549
+ {dir: target, built: BUILD_OUTPUT_DIRS.has(path.basename(target))},
550
+ ];
551
+ while (stack.length > 0) {
552
+ const {dir, built} = /** @type {{dir: string, built: boolean}} */ (
553
+ stack.pop()
554
+ );
555
+ let entries;
556
+ try {
557
+ entries = fs.readdirSync(dir, {withFileTypes: true});
558
+ } catch {
559
+ continue;
560
+ }
561
+ entries.sort((a, b) => a.name.localeCompare(b.name));
562
+ for (const entry of entries) {
563
+ const full = path.join(dir, entry.name);
564
+ if (entry.isDirectory()) {
565
+ if (BUILT_SKIPPED_DIRS.has(entry.name)) continue;
566
+ stack.push({
567
+ dir: full,
568
+ built: built || BUILD_OUTPUT_DIRS.has(entry.name),
569
+ });
570
+ } else if (entry.isFile()) {
571
+ if (files.length >= BUILT_FILE_LIMIT) return {files, truncated: true};
572
+ files.push({
573
+ rel: path.relative(target, full).split(path.sep).join('/'),
574
+ built,
575
+ read: reader(full),
576
+ });
577
+ }
578
+ }
579
+ }
580
+ return {files, truncated: false};
581
+ }
582
+
583
+ /**
584
+ * The integration packages whose components count as Astryx for a `--built`
585
+ * path, read without running anything: each dependency the nearest
586
+ * package.json above the path declares whose installed copy, resolved the way
587
+ * the CLI autolinks integrations (a workspace root's hoisted copy included),
588
+ * holds an integration manifest. Every `@astryxdesign/*` package counts
589
+ * beside them.
590
+ * @param {string} target the path as given
591
+ * @param {string} cwd
592
+ * @returns {string[]}
593
+ */
594
+ export function builtIntegrationPackages(target, cwd) {
595
+ let dir = path.resolve(cwd, target);
596
+ try {
597
+ if (!fs.statSync(dir).isDirectory()) dir = path.dirname(dir);
598
+ } catch {
599
+ dir = path.resolve(cwd);
600
+ }
601
+ for (let at = dir; ; at = path.dirname(at)) {
602
+ if (fs.existsSync(path.join(at, 'package.json'))) {
603
+ return [
604
+ ...new Set(scanAutolinkCandidates(at).map(candidate => candidate.spec)),
605
+ ];
606
+ }
607
+ if (path.dirname(at) === at) return [];
608
+ }
609
+ }
@@ -0,0 +1,85 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Read a path and gather the evidence both checks judge.
6
+ * @param {string} target an existing file or folder
7
+ * @param {readonly string[]} packages package names whose components count as
8
+ * Astryx, beside every `@astryxdesign/*` package
9
+ * @returns {BuiltScan}
10
+ */
11
+ export function scanBuilt(target: string, packages: readonly string[]): BuiltScan;
12
+ /**
13
+ * The two checks for a path.
14
+ * @param {string} target as the caller gave it
15
+ * @param {{cwd: string, packages: readonly string[]}} options `packages`: the
16
+ * integration packages whose components count as Astryx
17
+ * @returns {import('./doctor.type.mjs').DoctorCheck[]}
18
+ */
19
+ export function checkBuilt(target: string, { cwd, packages }: {
20
+ cwd: string;
21
+ packages: readonly string[];
22
+ }): import("./doctor.type.mjs").DoctorCheck[];
23
+ export type BuiltFinding = {
24
+ /**
25
+ * the rubric category: `Astryx components`,
26
+ * `Icons` or `Styling`
27
+ */
28
+ category: string;
29
+ /**
30
+ * relative to the checked path
31
+ */
32
+ file: string;
33
+ /**
34
+ * 1-based
35
+ */
36
+ line: number;
37
+ message: string;
38
+ };
39
+ export type BuiltScan = {
40
+ sourceFiles: number;
41
+ /**
42
+ * source files whose JSX was inspected
43
+ */
44
+ jsxFiles: number;
45
+ builtFiles: number;
46
+ /**
47
+ * imports from Astryx packages
48
+ */
49
+ imports: number;
50
+ /**
51
+ * files with one
52
+ */
53
+ importFiles: number;
54
+ /**
55
+ * JSX uses of names imported from them
56
+ */
57
+ componentUses: number;
58
+ /**
59
+ * the Astryx packages imported, sorted
60
+ */
61
+ packages: string[];
62
+ /**
63
+ * built files with an Astryx stylesheet
64
+ */
65
+ stylesheets: string[];
66
+ findings: BuiltFinding[];
67
+ /**
68
+ * whether the file limit cut the read short
69
+ */
70
+ truncated: boolean;
71
+ /**
72
+ * source files over the size limit, unreadable, or
73
+ * not parsed
74
+ */
75
+ unread: number;
76
+ /**
77
+ * those files, relative to the path
78
+ */
79
+ unreadFiles: string[];
80
+ /**
81
+ * local files a built page links that are not
82
+ * there
83
+ */
84
+ missingLinks: number;
85
+ };