@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e
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/README.md +13 -23
- package/api/build/_adapter.d.mts +5 -0
- package/api/build/_adapter.mjs +49 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +2 -1
- package/api/build/kit/rank.mjs +59 -12
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +238 -31
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +42 -0
- package/api/build/kit/words.mjs +82 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +46 -5
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +26 -2
- package/api/docs/_adapter.mjs +217 -5
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +77 -6
- package/api/doctor/built-checks.mjs +38 -13
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/render/_adapter.mjs +531 -192
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +30 -0
- package/api/render/render.type.mjs +19 -0
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_result.d.mts +5 -5
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +10 -0
- package/api/theme/build/build.d.mts +47 -0
- package/api/theme/build/build.mjs +147 -25
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +48 -0
- package/api/theme-edit/_adapter.mjs +675 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1481 -252
- package/api/theme-edit/_color.d.mts +9 -0
- package/api/theme-edit/_color.mjs +41 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1196 -88
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +536 -1
- package/api/theme-edit/_how-question.d.mts +65 -0
- package/api/theme-edit/_how-question.mjs +4401 -225
- package/api/theme-edit/_how.mjs +104 -4
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +153 -0
- package/api/theme-edit/_normal.mjs +661 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +205 -17
- package/api/theme-edit/_preview.d.mts +64 -8
- package/api/theme-edit/_preview.mjs +447 -89
- package/api/theme-edit/_settings.d.mts +176 -5
- package/api/theme-edit/_settings.mjs +1936 -128
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +32 -1
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/assets/codemods/run-codemod.mjs +73 -6
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +43 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +20 -2
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +22 -14
- package/clients/cli/commands/experimental/render.mjs +32 -1
- package/clients/cli/commands/experimental/theme.mjs +65 -14
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +153 -5
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +27 -2
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +20 -7
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +173 -10
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +163 -53
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/module-loader.d.mts +18 -2
- package/foundation/fs/module-loader.mjs +92 -20
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/render/embedded-imports.d.mts +5 -4
- package/foundation/render/embedded-imports.mjs +7 -16
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +83 -13
- package/foundation/render/render-page.d.mts +34 -2
- package/foundation/render/render-page.mjs +210 -29
- package/foundation/render/source-block.d.mts +73 -6
- package/foundation/render/source-block.mjs +170 -19
- package/foundation/render/ts-paths.d.mts +53 -6
- package/foundation/render/ts-paths.mjs +286 -41
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +10 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +16 -3
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +13 -0
- package/host/index.mjs +8 -6
- package/package.json +6 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A summary of a folder tree's names and of the text of the files it
|
|
5
|
+
* reads, kept between runs while no folder in the tree and no file the
|
|
6
|
+
* summary read has changed.
|
|
7
|
+
*
|
|
8
|
+
* @input A root folder, the kind of summary, the modules whose code makes it,
|
|
9
|
+
* and the function that makes it from the tree's listing.
|
|
10
|
+
* @output The summary: the stored one while every folder and every read file
|
|
11
|
+
* has the stamp it was stored with, else a new one, which is stored. The
|
|
12
|
+
* kept gathers' store holds it (gather-cache.mjs persistedSummary), under
|
|
13
|
+
* that store's rules.
|
|
14
|
+
* @position Used by the docs not-found hint (foundation/discovery) to check
|
|
15
|
+
* one name against Core's sources, the CLI's blocks and each integration's
|
|
16
|
+
* folders without listing every folder on each run.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import * as fs from 'node:fs';
|
|
20
|
+
import * as path from 'node:path';
|
|
21
|
+
import {fileURLToPath} from 'node:url';
|
|
22
|
+
import {persistedSummary} from './gather-cache.mjs';
|
|
23
|
+
import {fileStamp} from './read-record.mjs';
|
|
24
|
+
|
|
25
|
+
/** The module's own file: its code decides every summary's shape. */
|
|
26
|
+
const OWN_FILE = fileURLToPath(import.meta.url);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One folder of the tree: its path from the root (`''` for the root) and its
|
|
30
|
+
* entries, in the order the disk lists them.
|
|
31
|
+
* @typedef {{rel: string, entries: Array<{name: string, isDir: boolean}>}} TreeFolder
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The tree under `root`, folder by folder, outside any folder `skip` names.
|
|
36
|
+
* Each folder's stamp goes into `stamps` before the folder is read, so a
|
|
37
|
+
* change during the read shows as a change. A folder that cannot be read has
|
|
38
|
+
* no entries.
|
|
39
|
+
* @param {string} root
|
|
40
|
+
* @param {(name: string) => boolean} skip
|
|
41
|
+
* @param {Array<[string, string]>} stamps
|
|
42
|
+
* @returns {TreeFolder[]}
|
|
43
|
+
*/
|
|
44
|
+
function walkTree(root, skip, stamps) {
|
|
45
|
+
/** @type {TreeFolder[]} */
|
|
46
|
+
const folders = [];
|
|
47
|
+
/** @param {string} rel */
|
|
48
|
+
const visit = rel => {
|
|
49
|
+
const full = rel === '' ? root : path.join(root, rel);
|
|
50
|
+
stamps.push([rel, fileStamp(full)]);
|
|
51
|
+
/** @type {fs.Dirent[]} */
|
|
52
|
+
let dirents;
|
|
53
|
+
try {
|
|
54
|
+
dirents = fs.readdirSync(full, {withFileTypes: true});
|
|
55
|
+
} catch {
|
|
56
|
+
dirents = [];
|
|
57
|
+
}
|
|
58
|
+
const entries = dirents.map(entry => ({
|
|
59
|
+
name: entry.name,
|
|
60
|
+
isDir: entry.isDirectory(),
|
|
61
|
+
}));
|
|
62
|
+
folders.push({rel, entries});
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
if (entry.isDir && !skip(entry.name)) {
|
|
65
|
+
visit(rel === '' ? entry.name : path.join(rel, entry.name));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
visit('');
|
|
70
|
+
return folders;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** @type {Map<string, string>} each code file's stamp, once per process */
|
|
74
|
+
const codeStamps = new Map();
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Names as one string a lookup can search without parsing a list: each name
|
|
78
|
+
* on its own line. A list when a name holds a line break.
|
|
79
|
+
* @param {Iterable<string>} names
|
|
80
|
+
* @returns {string | string[]}
|
|
81
|
+
*/
|
|
82
|
+
export function nameLines(names) {
|
|
83
|
+
const list = [...new Set(names)];
|
|
84
|
+
return list.some(name => name.includes('\n'))
|
|
85
|
+
? list
|
|
86
|
+
: `\n${list.join('\n')}\n`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Whether `lines` ({@link nameLines}) holds `name`.
|
|
91
|
+
* @param {string | string[]} lines
|
|
92
|
+
* @param {string} name
|
|
93
|
+
* @returns {boolean}
|
|
94
|
+
*/
|
|
95
|
+
export function hasNameLine(lines, name) {
|
|
96
|
+
if (typeof lines !== 'string') return lines.includes(name);
|
|
97
|
+
return !name.includes('\n') && lines.includes(`\n${name}\n`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* One root's tree as a summary reads it: its folders, and `readText`, which
|
|
102
|
+
* reads a file by its path from the root and stamps it.
|
|
103
|
+
* @typedef {{root: string, folders: TreeFolder[], readText: (rel: string) => string}} Tree
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The summary `summarize` makes of the trees under `roots`, or the one a run
|
|
108
|
+
* stored for the same roots, kind and code while every folder it listed and
|
|
109
|
+
* every file it read is unchanged. Any failure to read or store a summary is
|
|
110
|
+
* silent, and the summary is made again.
|
|
111
|
+
* @template T
|
|
112
|
+
* @param {{kind: string, roots: string[], code: string[], skip?: (name: string) => boolean}} options
|
|
113
|
+
* `code`: the files whose code makes the summary; `skip`: folder names the
|
|
114
|
+
* walk does not enter (it is part of `kind`)
|
|
115
|
+
* @param {(trees: Tree[]) => T} summarize gets one tree per root, in order
|
|
116
|
+
* @returns {T}
|
|
117
|
+
*/
|
|
118
|
+
export function keptTreeSummary(
|
|
119
|
+
{kind, roots, code, skip = () => false},
|
|
120
|
+
summarize,
|
|
121
|
+
) {
|
|
122
|
+
const resolved = roots.map(root => path.resolve(root));
|
|
123
|
+
const codeState = [OWN_FILE, ...code].map(file => {
|
|
124
|
+
let stamp = codeStamps.get(file);
|
|
125
|
+
if (stamp === undefined) {
|
|
126
|
+
stamp = fileStamp(file);
|
|
127
|
+
codeStamps.set(file, stamp);
|
|
128
|
+
}
|
|
129
|
+
return [file, stamp];
|
|
130
|
+
});
|
|
131
|
+
return persistedSummary(['kept-tree', kind, resolved, codeState], () => {
|
|
132
|
+
/** @type {[string, string][]} */
|
|
133
|
+
const stamps = [];
|
|
134
|
+
const trees = resolved.map(root => {
|
|
135
|
+
/** @type {Array<[string, string]>} */
|
|
136
|
+
const own = [];
|
|
137
|
+
const folders = walkTree(root, skip, own);
|
|
138
|
+
for (const [rel, stamp] of own) {
|
|
139
|
+
stamps.push([rel === '' ? root : root + path.sep + rel, stamp]);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
root,
|
|
143
|
+
folders,
|
|
144
|
+
/** @param {string} rel */
|
|
145
|
+
readText: rel => {
|
|
146
|
+
const full = rel === '' ? root : root + path.sep + rel;
|
|
147
|
+
stamps.push([full, fileStamp(full)]);
|
|
148
|
+
return fs.readFileSync(full, 'utf8');
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
return {value: summarize(trees), stamps};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -19,11 +19,27 @@
|
|
|
19
19
|
export function importUserModule(file: string, { fresh }?: {
|
|
20
20
|
fresh?: boolean;
|
|
21
21
|
}): Promise<Record<string, unknown>>;
|
|
22
|
+
/**
|
|
23
|
+
* Run a theme module load with every stylesheet that the theme's modules
|
|
24
|
+
* import, at any depth, loaded as an empty module. A theme module can import
|
|
25
|
+
* a stylesheet so that the app's bundler emits it, and Node cannot load a
|
|
26
|
+
* stylesheet. Node resolves each import from the module that writes it, so a
|
|
27
|
+
* missing stylesheet fails like any missing import, and an import that ends
|
|
28
|
+
* in `.css` but names a JavaScript file loads that file. Module loads outside
|
|
29
|
+
* this call's async context do not change. The module hook is installed for
|
|
30
|
+
* the first overlapping load and removed after the last. A Node without module
|
|
31
|
+
* hooks (before 22.15) runs the load unchanged.
|
|
32
|
+
* @template T
|
|
33
|
+
* @param {() => Promise<T>} load
|
|
34
|
+
* @returns {Promise<T>}
|
|
35
|
+
*/
|
|
36
|
+
export function withEmptyStylesheets<T>(load: () => Promise<T>): Promise<T>;
|
|
22
37
|
/**
|
|
23
38
|
* Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
|
|
24
39
|
* Package specifiers resolve from the consumer project, while relative paths
|
|
25
|
-
* resolve from that same project root.
|
|
26
|
-
* loads as an empty module.
|
|
40
|
+
* resolve from that same project root. A stylesheet that a module in the graph
|
|
41
|
+
* imports loads as an empty module (`withEmptyStylesheets`). A target that is
|
|
42
|
+
* itself a stylesheet is not a theme module, and fails as one.
|
|
27
43
|
* @param {string} specifier
|
|
28
44
|
* @param {string} cwd
|
|
29
45
|
* @returns {Promise<Record<string, unknown>>}
|
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* user-authored module (`.ts` via jiti, `.mjs`/`.js` via native dynamic
|
|
8
8
|
* import) and (b) find conventional files by basename in a fixed
|
|
9
9
|
* load-precedence order. Generated theme artifacts also use a dedicated jiti
|
|
10
|
-
* path that resolves extensionless JSX/TSX registry imports
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* path that resolves extensionless JSX/TSX registry imports. On Node 22.15 and
|
|
11
|
+
* later, a theme module load, of a built artifact or of theme source, loads
|
|
12
|
+
* the stylesheets its modules import as empty modules. These helpers
|
|
13
|
+
* centralize that behavior so callers stay in lockstep. A module's stdout
|
|
14
|
+
* writes go to stderr while it loads, so project code that prints cannot
|
|
15
|
+
* corrupt a `--json` envelope.
|
|
15
16
|
*
|
|
16
17
|
* `loadModuleWithParser` builds on these primitives to provide the single
|
|
17
18
|
* load/validation boundary shared by config, integration, codemod, and
|
|
@@ -21,7 +22,7 @@
|
|
|
21
22
|
|
|
22
23
|
import * as path from 'node:path';
|
|
23
24
|
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
24
|
-
import {createRequire} from 'node:module';
|
|
25
|
+
import nodeModule, {createRequire} from 'node:module';
|
|
25
26
|
import {pathToFileURL} from 'node:url';
|
|
26
27
|
import * as fs from 'node:fs';
|
|
27
28
|
import {findPresentFiles} from './present-files.mjs';
|
|
@@ -138,16 +139,80 @@ function resolvesToStylesheet(specifier, from) {
|
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
* Module hooks that run in the loading thread: Node 22.15 and later have them.
|
|
143
|
+
* @type {((hooks: object) => {deregister: () => void}) | undefined}
|
|
144
|
+
*/
|
|
145
|
+
const registerHooks = /** @type {any} */ (nodeModule).registerHooks;
|
|
146
|
+
/** Set in the async context of a theme module load, and only there. */
|
|
147
|
+
const themeModuleLoad = new AsyncLocalStorage();
|
|
148
|
+
let themeModuleLoadsInFlight = 0;
|
|
149
|
+
/** @type {{deregister: () => void} | null} */
|
|
150
|
+
let stylesheetHooks = null;
|
|
151
|
+
|
|
152
|
+
/** @param {string} url */
|
|
153
|
+
function isStylesheetUrl(url) {
|
|
154
|
+
return url.startsWith('file:') && new URL(url).pathname.endsWith('.css');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* In a theme module load, a module that Node resolves to a `.css` file loads
|
|
159
|
+
* as an empty module. Any other module loads unchanged.
|
|
160
|
+
* @param {string} url
|
|
161
|
+
* @param {any} context
|
|
162
|
+
* @param {(url: string, context: any) => any} next
|
|
163
|
+
*/
|
|
164
|
+
function loadStylesheetAsEmptyModule(url, context, next) {
|
|
165
|
+
if (themeModuleLoad.getStore() && isStylesheetUrl(url)) {
|
|
166
|
+
return {format: 'module', source: '', shortCircuit: true};
|
|
167
|
+
}
|
|
168
|
+
return next(url, context);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function removeStylesheetHooks() {
|
|
172
|
+
try {
|
|
173
|
+
stylesheetHooks?.deregister();
|
|
174
|
+
stylesheetHooks = null;
|
|
175
|
+
} catch {
|
|
176
|
+
// A hook that Node cannot remove stays inert: it acts only in a theme
|
|
177
|
+
// module load, and the next load uses it again.
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Run a theme module load with every stylesheet that the theme's modules
|
|
183
|
+
* import, at any depth, loaded as an empty module. A theme module can import
|
|
184
|
+
* a stylesheet so that the app's bundler emits it, and Node cannot load a
|
|
185
|
+
* stylesheet. Node resolves each import from the module that writes it, so a
|
|
186
|
+
* missing stylesheet fails like any missing import, and an import that ends
|
|
187
|
+
* in `.css` but names a JavaScript file loads that file. Module loads outside
|
|
188
|
+
* this call's async context do not change. The module hook is installed for
|
|
189
|
+
* the first overlapping load and removed after the last. A Node without module
|
|
190
|
+
* hooks (before 22.15) runs the load unchanged.
|
|
191
|
+
* @template T
|
|
192
|
+
* @param {() => Promise<T>} load
|
|
193
|
+
* @returns {Promise<T>}
|
|
194
|
+
*/
|
|
195
|
+
export async function withEmptyStylesheets(load) {
|
|
196
|
+
if (typeof registerHooks !== 'function') return await load();
|
|
197
|
+
stylesheetHooks ??= registerHooks({load: loadStylesheetAsEmptyModule});
|
|
198
|
+
themeModuleLoadsInFlight++;
|
|
199
|
+
try {
|
|
200
|
+
return await themeModuleLoad.run(true, load);
|
|
201
|
+
} finally {
|
|
202
|
+
if (--themeModuleLoadsInFlight === 0) removeStylesheetHooks();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The stylesheet rule for a Node without module hooks. An import that ends in
|
|
208
|
+
* `.css` and resolves from the theme module to an existing `.css` file loads
|
|
209
|
+
* as an empty module. Any other import loads as before: a missing stylesheet
|
|
210
|
+
* fails like any missing import, and `./tokens.css` loads `tokens.css.js` when
|
|
211
|
+
* that is the file it names. jiti shows only the import text, so the check
|
|
212
|
+
* resolves it from the theme module's folder, not from the importing module's.
|
|
213
|
+
* A module in another folder fails on a stylesheet it reaches by a different
|
|
214
|
+
* relative path, and passes on a missing stylesheet whose path exists from the
|
|
215
|
+
* theme module's folder.
|
|
151
216
|
* @param {() => string} themeModule returns the theme module's path
|
|
152
217
|
* @returns {Record<string, unknown>}
|
|
153
218
|
*/
|
|
@@ -193,8 +258,9 @@ function isMissingPackageExport(error) {
|
|
|
193
258
|
/**
|
|
194
259
|
* Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
|
|
195
260
|
* Package specifiers resolve from the consumer project, while relative paths
|
|
196
|
-
* resolve from that same project root.
|
|
197
|
-
* loads as an empty module.
|
|
261
|
+
* resolve from that same project root. A stylesheet that a module in the graph
|
|
262
|
+
* imports loads as an empty module (`withEmptyStylesheets`). A target that is
|
|
263
|
+
* itself a stylesheet is not a theme module, and fails as one.
|
|
198
264
|
* @param {string} specifier
|
|
199
265
|
* @param {string} cwd
|
|
200
266
|
* @returns {Promise<Record<string, unknown>>}
|
|
@@ -207,7 +273,9 @@ export async function importThemeArtifact(specifier, cwd) {
|
|
|
207
273
|
jsx: true,
|
|
208
274
|
interopDefault: true,
|
|
209
275
|
extensions: THEME_ARTIFACT_EXTENSIONS,
|
|
210
|
-
|
|
276
|
+
...(typeof registerHooks === 'function'
|
|
277
|
+
? {}
|
|
278
|
+
: {virtualModules: themeArtifactStylesheets(() => themeModule)}),
|
|
211
279
|
});
|
|
212
280
|
let target;
|
|
213
281
|
if (specifier.startsWith('.') || path.isAbsolute(specifier)) {
|
|
@@ -224,7 +292,11 @@ export async function importThemeArtifact(specifier, cwd) {
|
|
|
224
292
|
throw new ThemeArtifactNotFoundError(specifier);
|
|
225
293
|
}
|
|
226
294
|
themeModule = target;
|
|
227
|
-
|
|
295
|
+
/** @type {() => Promise<Record<string, unknown>>} */
|
|
296
|
+
const load = () => loader.import(target);
|
|
297
|
+
return await withStdoutOnStderr(
|
|
298
|
+
isStylesheetSpecifier(target) ? load : () => withEmptyStylesheets(load),
|
|
299
|
+
);
|
|
228
300
|
}
|
|
229
301
|
|
|
230
302
|
/**
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Whether a value is a bare npm package name, as written (lowercase).
|
|
6
|
+
* @param {unknown} name
|
|
7
|
+
* @returns {boolean}
|
|
8
|
+
*/
|
|
9
|
+
export function isPackageName(name: unknown): boolean;
|
|
4
10
|
/**
|
|
5
11
|
* Normalize an npm package name into a ProviderId.
|
|
6
12
|
* @param {string} packageName
|
|
@@ -57,6 +57,15 @@ const DOC_KINDS = new Set([
|
|
|
57
57
|
'icon-definition',
|
|
58
58
|
]);
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Whether a value is a bare npm package name, as written (lowercase).
|
|
62
|
+
* @param {unknown} name
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
export function isPackageName(name) {
|
|
66
|
+
return typeof name === 'string' && PACKAGE_NAME_RE.test(name);
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
/** RFC 3986 path-segment encoding with uppercase escapes. */
|
|
61
70
|
/** @param {string} value @returns {string} */
|
|
62
71
|
function encodeSegment(value) {
|
|
@@ -92,7 +101,7 @@ function normalizeName(value, label) {
|
|
|
92
101
|
*/
|
|
93
102
|
export function normalizeProviderId(packageName) {
|
|
94
103
|
const normalized = normalizeName(packageName, 'Provider ID').toLowerCase();
|
|
95
|
-
if (!
|
|
104
|
+
if (!isPackageName(normalized)) {
|
|
96
105
|
throw new Error(
|
|
97
106
|
`Provider ID "${packageName}" must be a bare npm package name.`,
|
|
98
107
|
);
|
|
@@ -23,12 +23,13 @@ export function importSpecifiers(source: string, file: string): string[];
|
|
|
23
23
|
*/
|
|
24
24
|
export function assetRefsIn(text: string): string[];
|
|
25
25
|
/**
|
|
26
|
-
* The path aliases (`compilerOptions.paths`)
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
26
|
+
* The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
|
|
27
|
+
* written at `file`, by its rules (see ts-paths.mjs). The file and its
|
|
28
|
+
* folders need not exist yet.
|
|
29
|
+
* @param {string} file absolute
|
|
29
30
|
* @returns {import('./ts-paths.mjs').PathPattern[]}
|
|
30
31
|
*/
|
|
31
|
-
export function receivingAliases(
|
|
32
|
+
export function receivingAliases(file: string): import("./ts-paths.mjs").PathPattern[];
|
|
32
33
|
/**
|
|
33
34
|
* @typedef {object} Reach
|
|
34
35
|
* @property {boolean} relative - Reached by a relative import (or it is the
|
|
@@ -13,12 +13,11 @@
|
|
|
13
13
|
* @position foundation/render — used by the render subject's adapter
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import * as fs from 'node:fs';
|
|
17
16
|
import * as path from 'node:path';
|
|
18
17
|
import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
|
|
19
18
|
import {PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
20
19
|
import postcss from 'postcss';
|
|
21
|
-
import {matchPath,
|
|
20
|
+
import {matchPath, pathsFor} from './ts-paths.mjs';
|
|
22
21
|
import {isAssetPath} from './assets.mjs';
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -132,22 +131,14 @@ function scanModule(source, file) {
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
|
-
* The path aliases (`compilerOptions.paths`)
|
|
136
|
-
* `
|
|
137
|
-
*
|
|
134
|
+
* The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
|
|
135
|
+
* written at `file`, by its rules (see ts-paths.mjs). The file and its
|
|
136
|
+
* folders need not exist yet.
|
|
137
|
+
* @param {string} file absolute
|
|
138
138
|
* @returns {import('./ts-paths.mjs').PathPattern[]}
|
|
139
139
|
*/
|
|
140
|
-
export function receivingAliases(
|
|
141
|
-
|
|
142
|
-
while (!fs.existsSync(d) && path.dirname(d) !== d) d = path.dirname(d);
|
|
143
|
-
for (;;) {
|
|
144
|
-
const found = readPathsIn(d);
|
|
145
|
-
if (found) return found;
|
|
146
|
-
if (fs.existsSync(path.join(d, 'package.json'))) return [];
|
|
147
|
-
const up = path.dirname(d);
|
|
148
|
-
if (up === d) return [];
|
|
149
|
-
d = up;
|
|
150
|
-
}
|
|
140
|
+
export function receivingAliases(file) {
|
|
141
|
+
return pathsFor(file);
|
|
151
142
|
}
|
|
152
143
|
|
|
153
144
|
/**
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
* @typedef {object} FileFacts
|
|
6
|
+
* @property {string | null} cli - The CLI version that rendered the file.
|
|
7
|
+
* @property {number} format - The render format of the embedded source.
|
|
8
|
+
* @property {string} file - The rendered file's name.
|
|
9
|
+
* @property {string} page - The page's path from its project's root.
|
|
10
|
+
* @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
|
|
11
|
+
* @property {string[]} files - The embedded files, page first.
|
|
12
|
+
* @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
|
|
13
|
+
* @property {string[]} install - What a render outside a project must install first, as name@version.
|
|
14
|
+
* @property {string} [title] - The title given with --title.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The note at the top of a rendered file.
|
|
18
|
+
* @param {FileFacts} facts
|
|
19
|
+
* @returns {string} an HTML comment on lines of its own
|
|
20
|
+
*/
|
|
21
|
+
export function headerNote(facts: FileFacts): string;
|
|
22
|
+
/**
|
|
23
|
+
* The note after the embedded source.
|
|
24
|
+
* @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
|
|
25
|
+
* @returns {string} an HTML comment on one line
|
|
26
|
+
*/
|
|
27
|
+
export function endNote(facts: Pick<FileFacts, "cli" | "format" | "file">): string;
|
|
28
|
+
export function cliCommand(version: string | null): string;
|
|
29
|
+
export type FileFacts = {
|
|
30
|
+
/**
|
|
31
|
+
* - The CLI version that rendered the file.
|
|
32
|
+
*/
|
|
33
|
+
cli: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* - The render format of the embedded source.
|
|
36
|
+
*/
|
|
37
|
+
format: number;
|
|
38
|
+
/**
|
|
39
|
+
* - The rendered file's name.
|
|
40
|
+
*/
|
|
41
|
+
file: string;
|
|
42
|
+
/**
|
|
43
|
+
* - The page's path from its project's root.
|
|
44
|
+
*/
|
|
45
|
+
page: string;
|
|
46
|
+
/**
|
|
47
|
+
* - Where --reverse writes the page by default, from the rendered file's folder.
|
|
48
|
+
*/
|
|
49
|
+
restored: string;
|
|
50
|
+
/**
|
|
51
|
+
* - The embedded files, page first.
|
|
52
|
+
*/
|
|
53
|
+
files: string[];
|
|
54
|
+
/**
|
|
55
|
+
* - The packages the page rendered with, by name: their versions.
|
|
56
|
+
*/
|
|
57
|
+
packages: Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* - What a render outside a project must install first, as name@version.
|
|
60
|
+
*/
|
|
61
|
+
install: string[];
|
|
62
|
+
/**
|
|
63
|
+
* - The title given with --title.
|
|
64
|
+
*/
|
|
65
|
+
title?: string | undefined;
|
|
66
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {shellArg} from '../text/shell-arg.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file The plain-text notes a rendered file carries for whoever opens it
|
|
7
|
+
* next, a person or an agent with no other context: what made the file, what
|
|
8
|
+
* it carries, and the exact commands that give the page back and render it
|
|
9
|
+
* again. The note at the top sits in <head> after the charset and generator
|
|
10
|
+
* metas, so browsers and older CLIs still find both in the first bytes. The
|
|
11
|
+
* short note at the end follows the embedded source, for a reader that starts
|
|
12
|
+
* at the end of the file.
|
|
13
|
+
*
|
|
14
|
+
* The notes never spell the opening tag of the embedded block: every CLI
|
|
15
|
+
* finds the block by that tag, and the last match wins.
|
|
16
|
+
*
|
|
17
|
+
* @position foundation/render — used by render-page.mjs
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The command that runs one version of the CLI anywhere npm runs.
|
|
22
|
+
* @param {string | null} version
|
|
23
|
+
*/
|
|
24
|
+
export const cliCommand = version => `npx @astryxdesign/cli${version ? `@${version}` : ''}`;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Text that cannot end or nest an HTML comment.
|
|
29
|
+
* @param {string} text
|
|
30
|
+
*/
|
|
31
|
+
const commentSafe = text => text.replace(/--!?>/g, '- ->').replace(/<!--/g, '<!- -');
|
|
32
|
+
|
|
33
|
+
/** The most file names the note at the top lists. */
|
|
34
|
+
const MAX_LISTED = 24;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} FileFacts
|
|
38
|
+
* @property {string | null} cli - The CLI version that rendered the file.
|
|
39
|
+
* @property {number} format - The render format of the embedded source.
|
|
40
|
+
* @property {string} file - The rendered file's name.
|
|
41
|
+
* @property {string} page - The page's path from its project's root.
|
|
42
|
+
* @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
|
|
43
|
+
* @property {string[]} files - The embedded files, page first.
|
|
44
|
+
* @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
|
|
45
|
+
* @property {string[]} install - What a render outside a project must install first, as name@version.
|
|
46
|
+
* @property {string} [title] - The title given with --title.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The note at the top of a rendered file.
|
|
51
|
+
* @param {FileFacts} facts
|
|
52
|
+
* @returns {string} an HTML comment on lines of its own
|
|
53
|
+
*/
|
|
54
|
+
export function headerNote(facts) {
|
|
55
|
+
const run = cliCommand(facts.cli);
|
|
56
|
+
const file = shellArg(facts.file);
|
|
57
|
+
const shown = facts.files.slice(0, MAX_LISTED).join(', ');
|
|
58
|
+
const more = facts.files.length > MAX_LISTED ? `, and ${facts.files.length - MAX_LISTED} more` : '';
|
|
59
|
+
const versions = Object.entries(facts.packages).map(([name, version]) => `${name} ${version}`);
|
|
60
|
+
const core = facts.packages['@astryxdesign/core'];
|
|
61
|
+
// A title with < or > stays out of the note, which other tools read as
|
|
62
|
+
// HTML; step 1 prints the command with it.
|
|
63
|
+
const quotable = facts.title !== undefined && !/[<>]/.test(facts.title);
|
|
64
|
+
const title = quotable ? ` --title ${shellArg(/** @type {string} */ (facts.title))}` : '';
|
|
65
|
+
const lines = [
|
|
66
|
+
`Rendered by Astryx: astryx experimental render, @astryxdesign/cli ${facts.cli ?? '(version unknown)'}, render format ${facts.format}.`,
|
|
67
|
+
'This is one static file. It runs no script and loads nothing from the network.',
|
|
68
|
+
'It also carries the source of the page, so the page can come back exactly.',
|
|
69
|
+
'',
|
|
70
|
+
`Page: ${facts.page}`,
|
|
71
|
+
`Carried files (${facts.files.length}): ${shown}${more}`,
|
|
72
|
+
...(versions.length > 0 ? [`Rendered with: ${versions.join(', ')}`] : []),
|
|
73
|
+
'',
|
|
74
|
+
'To change the page, change its source and render it again. Do not edit this HTML:',
|
|
75
|
+
'the carried source does not get the edits you make here.',
|
|
76
|
+
'Run these commands in the folder that holds this file:',
|
|
77
|
+
` 1. Get the source back. This writes ${facts.restored} and the files it imports`,
|
|
78
|
+
` (into ${facts.restored.split('/')[0]}-2/ and so on when that folder exists; the output names it):`,
|
|
79
|
+
` ${run} experimental render --reverse ${file}`,
|
|
80
|
+
' 2. Edit the restored files.',
|
|
81
|
+
' 3. Render again. A render replaces a file that a render wrote. Step 1 prints this',
|
|
82
|
+
' command with the folder it wrote:',
|
|
83
|
+
` ${run} experimental render ${shellArg(facts.restored)} --out ${file}${title}`,
|
|
84
|
+
...(facts.title !== undefined && !quotable ? [' The page was rendered with --title; step 1 prints the command with it.'] : []),
|
|
85
|
+
`If you have the project, edit ${facts.page} there instead, and render it in the same way.`,
|
|
86
|
+
"Inside a project, the project's own CLI answers these commands. A project CLI older than",
|
|
87
|
+
`${facts.cli ?? 'the one that rendered this file'} writes the page without this note; to keep the note, update that CLI first:`,
|
|
88
|
+
` npm install --save-dev @astryxdesign/cli@${facts.cli ?? 'latest'}`,
|
|
89
|
+
...(facts.install.length > 0
|
|
90
|
+
? [
|
|
91
|
+
'Outside a project, the CLI supplies Astryx, React and StyleX. Install the other packages first:',
|
|
92
|
+
` npm install ${facts.install.join(' ')}`,
|
|
93
|
+
]
|
|
94
|
+
: []),
|
|
95
|
+
...(core
|
|
96
|
+
? [
|
|
97
|
+
`The source was written for @astryxdesign/core ${core}. In a project on a newer Core, update the`,
|
|
98
|
+
"restored code from inside that project (the CLI hands this to the project's own CLI):",
|
|
99
|
+
` ${cliCommand(null)} upgrade --from ${core} --path ${shellArg(facts.restored.split('/')[0])} --apply`,
|
|
100
|
+
]
|
|
101
|
+
: []),
|
|
102
|
+
'Later CLI versions read this file too.',
|
|
103
|
+
'If someone edits this HTML after the render, step 1 still gives back the page as rendered,',
|
|
104
|
+
'and it lists the text that changed, so you can make the same change in the source.',
|
|
105
|
+
'The source is in the script block at the end of this file. Keep it: without it,',
|
|
106
|
+
'step 1 can rebuild only the text and the layout from the markup.',
|
|
107
|
+
];
|
|
108
|
+
return `<!--\n${lines.map(line => (line ? ` ${commentSafe(line)}` : '')).join('\n')}\n-->`.replace(/<(?=\/?script)/gi, '<');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The note after the embedded source.
|
|
113
|
+
* @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
|
|
114
|
+
* @returns {string} an HTML comment on one line
|
|
115
|
+
*/
|
|
116
|
+
export function endNote(facts) {
|
|
117
|
+
return `<!-- Astryx render: the block above is the source of the page (render format ${facts.format}), as JSON; each file is base64 with its SHA-256. Get it back: ${commentSafe(cliCommand(facts.cli))} experimental render --reverse ${commentSafe(shellArg(facts.file))} -->`;
|
|
118
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
* @param {{
|
|
6
|
+
* send: (message: unknown, done: (error: Error | null) => void) => unknown,
|
|
7
|
+
* exit: (code: number) => void,
|
|
8
|
+
* connected: () => boolean,
|
|
9
|
+
* record?: (phase: 'no-channel' | 'sending' | 'sent' | 'send-failed') => void,
|
|
10
|
+
* }} io
|
|
11
|
+
* @returns {(message: unknown) => void}
|
|
12
|
+
*/
|
|
13
|
+
export function makeAnswer({ send, exit, connected, record }: {
|
|
14
|
+
send: (message: unknown, done: (error: Error | null) => void) => unknown;
|
|
15
|
+
exit: (code: number) => void;
|
|
16
|
+
connected: () => boolean;
|
|
17
|
+
record?: (phase: "no-channel" | "sending" | "sent" | "send-failed") => void;
|
|
18
|
+
}): (message: unknown) => void;
|