@astryxdesign/cli 0.7.7-canary.ab90555 → 0.7.7-canary.ae97fa8

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.
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
4
+ export const doc = {
5
+ type: 'block',
6
+ exampleFor: 'useOutlineFromMarkdown',
7
+ name: 'useOutlineFromMarkdown — Docs Article',
8
+ displayName: 'useOutlineFromMarkdown — Docs Article',
9
+ description:
10
+ 'A docs-style article with an Outline next to it, built from the same Markdown string through useOutlineFromMarkdown. "Add section" appends a heading to the string, and a new entry that links to it appears in the outline.',
11
+ isReady: true,
12
+ aspectRatio: 16 / 9,
13
+ componentsUsed: ['Markdown', 'Outline', 'ScrollableArea', 'Button', 'Layout'],
14
+ };
@@ -0,0 +1,69 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useRef, useState} from 'react';
6
+ import {Button} from '@astryxdesign/core/Button';
7
+ import {HStack, VStack} from '@astryxdesign/core/Layout';
8
+ import {Markdown} from '@astryxdesign/core/Markdown';
9
+ import {Outline, useOutlineFromMarkdown} from '@astryxdesign/core/Outline';
10
+ import {ScrollableArea} from '@astryxdesign/core/ScrollableArea';
11
+
12
+ const ARTICLE = `## Before you start
13
+
14
+ Check that your project builds on the current release. Commit your work, so
15
+ that you can compare the result of the upgrade.
16
+
17
+ ## Run the upgrade
18
+
19
+ Update the packages, then rebuild the project. The upgrade changes no source
20
+ files.
21
+
22
+ ### Update the packages
23
+
24
+ Install the new version of every package at the same time. Mixed versions fail
25
+ the build.
26
+
27
+ ### Rebuild the project
28
+
29
+ Delete the build output first. A stale cache can hide a real error.
30
+
31
+ ## Check the result
32
+
33
+ Open the pages that you use most, and compare them with the earlier build.
34
+ `;
35
+
36
+ const NEW_SECTION = `
37
+ ## New section
38
+
39
+ The button added this heading to the Markdown string.
40
+ `;
41
+
42
+ export default function UseOutlineFromMarkdownHookUsage() {
43
+ const [markdown, setMarkdown] = useState(ARTICLE);
44
+ const items = useOutlineFromMarkdown(markdown);
45
+ const articleRef = useRef<HTMLDivElement>(null);
46
+
47
+ return (
48
+ <HStack gap={6} align="start" width="100%">
49
+ <ScrollableArea
50
+ ref={articleRef}
51
+ label="Article"
52
+ height={320}
53
+ width="100%">
54
+ <Markdown>{markdown}</Markdown>
55
+ </ScrollableArea>
56
+ <VStack gap={3} align="start" width={220}>
57
+ {/* A non-zero offset moves only the article. With 0, a click also moves
58
+ the page around the article. */}
59
+ <Outline items={items} scrollContainerRef={articleRef} offset={8} />
60
+ <Button
61
+ label="Add section"
62
+ variant="secondary"
63
+ size="sm"
64
+ onClick={() => setMarkdown(current => current + NEW_SECTION)}
65
+ />
66
+ </VStack>
67
+ </HStack>
68
+ );
69
+ }
@@ -45,6 +45,7 @@ import {
45
45
  TYPESCRIPT_FIX,
46
46
  unusableTypeScriptReason,
47
47
  } from './project-typescript.mjs';
48
+ import {keepSourceFiles} from './source-file-cache.mjs';
48
49
 
49
50
  /**
50
51
  * @typedef {'components' | 'hooks' | 'templates' | 'docs' | 'docs-overlay' | 'themes' | 'icon-sets'} DocRoot
@@ -1035,8 +1036,9 @@ export async function checkDocTypes(files, options) {
1035
1036
  paths: {[AUTHORING]: [AUTHORING_TYPES]},
1036
1037
  };
1037
1038
  const host = ts.createCompilerHost(options_);
1038
- const getSourceFile = host.getSourceFile.bind(host);
1039
- // Every other file is parsed once, so a later pass reuses it.
1039
+ // Every other file is parsed once, so a later pass reuses it; and once per
1040
+ // process for these options, so a later check does too.
1041
+ const getSourceFile = keepSourceFiles(ts, host, options_);
1040
1042
  /** @type {Map<string, any>} */
1041
1043
  const parsed = new Map();
1042
1044
  host.getSourceFile = (
@@ -54,6 +54,7 @@ import {
54
54
  TYPESCRIPT_FIX,
55
55
  unusableTypeScriptReason,
56
56
  } from './project-typescript.mjs';
57
+ import {keepSourceFiles} from './source-file-cache.mjs';
57
58
  import {judgeType} from './type-match.mjs';
58
59
  import {typeTextTooOld} from './type-text.mjs';
59
60
  import {
@@ -1802,6 +1803,10 @@ export function comparePropTables(tables, options) {
1802
1803
  typesNotCompared: [],
1803
1804
  };
1804
1805
  }
1806
+ // Parsed once per process for these options: every check reads the same
1807
+ // library and package declarations.
1808
+ const host = ts.createCompilerHost(project.options);
1809
+ host.getSourceFile = keepSourceFiles(ts, host, project.options);
1805
1810
  const program = ts.createProgram({
1806
1811
  rootNames: [
1807
1812
  ...new Set([
@@ -1810,6 +1815,7 @@ export function comparePropTables(tables, options) {
1810
1815
  ]),
1811
1816
  ],
1812
1817
  options: project.options,
1818
+ host,
1813
1819
  });
1814
1820
  const checker = program.getTypeChecker();
1815
1821
  const isOwnFile = ownFileTest(root);
@@ -0,0 +1,15 @@
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
+ * `host.getSourceFile`, keeping each file it parses while the file's stamp is
6
+ * the same, for every program whose options parse and bind a file as
7
+ * `options` do. A kept file still counts as read by the running operation
8
+ * (`recordContentRead`), as a parse would. On a TypeScript older than 5.3 the
9
+ * host's own `getSourceFile` is returned.
10
+ * @param {any} ts the project's own `typescript`
11
+ * @param {any} host
12
+ * @param {any} options the compiler options of the programs that use it
13
+ * @returns {(fileName: string, languageVersionOrOptions: any, onError?: any, shouldCreate?: boolean) => any}
14
+ */
15
+ export function keepSourceFiles(ts: any, host: any, options: any): (fileName: string, languageVersionOrOptions: any, onError?: any, shouldCreate?: boolean) => any;
@@ -0,0 +1,140 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file source-file-cache.mjs
5
+ * @input A TypeScript compiler host, the project's own `typescript`, and the
6
+ * compiler options its programs use
7
+ * @output `keepSourceFiles`: the host's `getSourceFile`, keeping each parsed
8
+ * file while its stamp (`fileStamp`) is the same, for every program in this
9
+ * process whose options parse and bind a file alike.
10
+ * @position The props comparison (./prop-drift.mjs) and the doc types check
11
+ * (./doc-types.mjs) build a program for every check, and each parsed the
12
+ * same declarations again: the TypeScript library's, React's, the
13
+ * authoring types. A process that checks more than once (a test run, a
14
+ * long-running caller, a check over several roots) now parses each once.
15
+ * TypeScript's language service shares parsed files between programs the
16
+ * same way; from 5.3 a program keeps what it resolved for a file itself, not
17
+ * on the file, which is what makes sharing them safe across programs.
18
+ */
19
+
20
+ import path from 'node:path';
21
+ import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
22
+
23
+ /**
24
+ * The files kept, per TypeScript and per how the options parse and bind a
25
+ * file (`settingsKey`), the most recently used options last.
26
+ * @type {WeakMap<object, Map<string, Map<string, {stamp: string, sourceFile: any}>>>}
27
+ */
28
+ const kept = new WeakMap();
29
+
30
+ /** The most files kept for one key; the oldest go first. */
31
+ const MAX_FILES = 5000;
32
+
33
+ /**
34
+ * The most keys kept per TypeScript; the least recently used go first. Each
35
+ * holds its own parse of the TypeScript library's declarations, the largest
36
+ * files a program reads.
37
+ */
38
+ const MAX_KEYS = 8;
39
+
40
+ /** @type {WeakMap<object, any>} one document registry per TypeScript */
41
+ const registries = new WeakMap();
42
+
43
+ /**
44
+ * What in `options` decides how a file parses and binds: the key TypeScript's
45
+ * language service shares parsed files by (its document registry's), and
46
+ * whether a script binds in strict mode, which that key reads only from an
47
+ * explicit `alwaysStrict`. Options that only resolve or check (`paths`,
48
+ * `types`, `lib`, the strict checks) do not change it.
49
+ * @param {any} ts
50
+ * @param {any} options
51
+ * @returns {string}
52
+ */
53
+ function settingsKey(ts, options) {
54
+ let registry = registries.get(ts);
55
+ if (registry == null) {
56
+ registry = ts.createDocumentRegistry();
57
+ registries.set(ts, registry);
58
+ }
59
+ const strict =
60
+ typeof ts.getStrictOptionValue === 'function'
61
+ ? ts.getStrictOptionValue(options, 'alwaysStrict')
62
+ : (options.alwaysStrict ?? options.strict ?? false);
63
+ return `${registry.getKeyForCompilationSettings(options)}|${strict ? 1 : 0}`;
64
+ }
65
+
66
+ /**
67
+ * Whether this TypeScript keeps a program's module resolutions on the program
68
+ * (5.3 and later) rather than on the parsed files it shares.
69
+ * @param {any} ts
70
+ */
71
+ function sharesSafely(ts) {
72
+ const [major, minor] = String(ts.versionMajorMinor ?? '0.0')
73
+ .split('.')
74
+ .map(Number);
75
+ return major > 5 || (major === 5 && minor >= 3);
76
+ }
77
+
78
+ /**
79
+ * `host.getSourceFile`, keeping each file it parses while the file's stamp is
80
+ * the same, for every program whose options parse and bind a file as
81
+ * `options` do. A kept file still counts as read by the running operation
82
+ * (`recordContentRead`), as a parse would. On a TypeScript older than 5.3 the
83
+ * host's own `getSourceFile` is returned.
84
+ * @param {any} ts the project's own `typescript`
85
+ * @param {any} host
86
+ * @param {any} options the compiler options of the programs that use it
87
+ * @returns {(fileName: string, languageVersionOrOptions: any, onError?: any, shouldCreate?: boolean) => any}
88
+ */
89
+ export function keepSourceFiles(ts, host, options) {
90
+ const getSourceFile = host.getSourceFile.bind(host);
91
+ if (!sharesSafely(ts)) return getSourceFile;
92
+ let bySettings = kept.get(ts);
93
+ if (bySettings == null) {
94
+ bySettings = new Map();
95
+ kept.set(ts, bySettings);
96
+ }
97
+ const settings = settingsKey(ts, options);
98
+ const byFile = bySettings.get(settings) ?? new Map();
99
+ // Most recently used last; past MAX_KEYS, the least recently used go.
100
+ bySettings.delete(settings);
101
+ bySettings.set(settings, byFile);
102
+ if (bySettings.size > MAX_KEYS) {
103
+ bySettings.delete(/** @type {string} */ (bySettings.keys().next().value));
104
+ }
105
+ return (fileName, languageVersionOrOptions, onError, shouldCreate) => {
106
+ // How the file parses: its language version and, from TypeScript 5.0,
107
+ // its module format and JSDoc parsing (the module detection the options
108
+ // give is in `settings`).
109
+ const parse =
110
+ languageVersionOrOptions != null &&
111
+ typeof languageVersionOrOptions === 'object'
112
+ ? [
113
+ languageVersionOrOptions.languageVersion,
114
+ languageVersionOrOptions.impliedNodeFormat,
115
+ languageVersionOrOptions.jsDocParsingMode,
116
+ ]
117
+ : [languageVersionOrOptions];
118
+ const key = `${path.resolve(fileName)}\0${JSON.stringify(parse)}`;
119
+ const stamp = fileStamp(fileName);
120
+ const seen = byFile.get(key);
121
+ if (seen != null && stamp !== '-' && seen.stamp === stamp) {
122
+ recordContentRead(fileName);
123
+ return seen.sourceFile;
124
+ }
125
+ const sourceFile = getSourceFile(
126
+ fileName,
127
+ languageVersionOrOptions,
128
+ onError,
129
+ shouldCreate,
130
+ );
131
+ byFile.delete(key);
132
+ if (sourceFile != null && stamp !== '-') {
133
+ byFile.set(key, {stamp, sourceFile});
134
+ if (byFile.size > MAX_FILES) {
135
+ byFile.delete(/** @type {string} */ (byFile.keys().next().value));
136
+ }
137
+ }
138
+ return sourceFile;
139
+ };
140
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.7-canary.ab90555",
3
+ "version": "0.7.7-canary.ae97fa8",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -124,10 +124,10 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/charts": "0.7.7-canary.ab90555",
128
- "@astryxdesign/core": "0.7.7-canary.ab90555",
129
- "@astryxdesign/lab": "0.7.7-canary.ab90555",
130
- "@astryxdesign/theme-neutral": "0.7.7-canary.ab90555"
127
+ "@astryxdesign/charts": "0.7.7-canary.ae97fa8",
128
+ "@astryxdesign/core": "0.7.7-canary.ae97fa8",
129
+ "@astryxdesign/lab": "0.7.7-canary.ae97fa8",
130
+ "@astryxdesign/theme-neutral": "0.7.7-canary.ae97fa8"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@astryxdesign/charts": {
@@ -144,10 +144,10 @@
144
144
  }
145
145
  },
146
146
  "devDependencies": {
147
- "@astryxdesign/charts": "0.7.7-canary.ab90555",
148
- "@astryxdesign/core": "0.7.7-canary.ab90555",
149
- "@astryxdesign/lab": "0.7.7-canary.ab90555",
150
- "@astryxdesign/theme-neutral": "0.7.7-canary.ab90555",
147
+ "@astryxdesign/charts": "0.7.7-canary.ae97fa8",
148
+ "@astryxdesign/core": "0.7.7-canary.ae97fa8",
149
+ "@astryxdesign/lab": "0.7.7-canary.ae97fa8",
150
+ "@astryxdesign/theme-neutral": "0.7.7-canary.ae97fa8",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",