@astryxdesign/cli 0.7.14 → 0.7.15-canary.g79b95eb
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/api/doctor/_adapter.d.mts +1 -0
- package/api/doctor/_adapter.mjs +8 -0
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.mjs +20 -9
- package/api/theme/build/build.d.mts +15 -1
- package/api/theme/build/build.mjs +132 -32
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +14 -1
- package/api/theme/themeBuild.doc.mjs +6 -3
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +372 -109
- package/api/theme-edit/_check.d.mts +6 -3
- package/api/theme-edit/_check.mjs +665 -87
- package/api/theme-edit/_color.mjs +4 -2
- package/api/theme-edit/_compiler.d.mts +2 -1
- package/api/theme-edit/_compiler.mjs +27 -13
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +47 -8
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +484 -66
- package/api/theme-edit/_how-commands.d.mts +33 -7
- package/api/theme-edit/_how-commands.mjs +57 -45
- package/api/theme-edit/_how-question.d.mts +4 -0
- package/api/theme-edit/_how-question.mjs +1004 -223
- package/api/theme-edit/_how.mjs +96 -9
- package/api/theme-edit/_palette.d.mts +38 -13
- package/api/theme-edit/_palette.mjs +620 -223
- package/api/theme-edit/_parts.mjs +63 -7
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +6 -0
- package/api/theme-edit/_preview-app.mjs +1194 -207
- package/api/theme-edit/_preview.mjs +2 -2
- package/api/theme-edit/_project.d.mts +12 -1
- package/api/theme-edit/_project.mjs +37 -6
- package/api/theme-edit/_settings.d.mts +104 -33
- package/api/theme-edit/_settings.mjs +818 -118
- package/api/theme-edit/_tables.d.mts +7 -0
- package/api/theme-edit/_tables.mjs +61 -0
- package/api/theme-edit/theme-edit.type.d.mts +11 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs.generated.json +2 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/theme.mjs +178 -78
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme.mjs +118 -22
- package/clients/cli/index.mjs +9 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +6 -0
- package/foundation/discovery/template-needs.mjs +20 -1
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +2 -8
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +12 -11
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +716 -0
- package/foundation/fs/module-loader.mjs +7 -1
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +93 -6
- package/foundation/integrations/validate-contributions.mjs +24 -11
- package/foundation/release/cache.d.mts +11 -2
- package/foundation/release/cache.mjs +59 -10
- package/foundation/release/folder-lock.d.mts +21 -0
- package/foundation/release/folder-lock.mjs +171 -0
- package/package.json +8 -6
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
programPath,
|
|
39
39
|
traverseTemplateSource,
|
|
40
40
|
writtenNames,
|
|
41
|
+
TEMPLATE_COMPONENTS_FILE,
|
|
41
42
|
} from './template-source-tree.mjs';
|
|
42
43
|
|
|
43
44
|
const require = createRequire(import.meta.url);
|
|
@@ -358,10 +359,41 @@ export function stripTemplateAssetRefs(source) {
|
|
|
358
359
|
* @returns {{source: string, demoMediaReplaced: number}}
|
|
359
360
|
*/
|
|
360
361
|
export function replaceDemoMedia(source, {videoPlaceholder = ''} = {}) {
|
|
362
|
+
const {source: output, replaced} = mapFixtureRefs(source, ({kind}) =>
|
|
363
|
+
kind === 'video' ? videoPlaceholder : PLACEHOLDER_IMAGE,
|
|
364
|
+
);
|
|
365
|
+
return {source: output, demoMediaReplaced: replaced};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* One Astryx template fixture reference in template source.
|
|
370
|
+
* @typedef {object} FixtureRef
|
|
371
|
+
* @property {string} reference - The whole reference, query and fragment
|
|
372
|
+
* included.
|
|
373
|
+
* @property {'image' | 'video'} kind - What the suffix of its last path
|
|
374
|
+
* segment names.
|
|
375
|
+
* @property {boolean} isValue - Whether the reference is a whole quoted or
|
|
376
|
+
* `url()` value. False for a mention in text.
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Replace each Astryx template fixture reference with what `map` returns for
|
|
381
|
+
* it. This is the one scanner for fixture references: a copy replaces them
|
|
382
|
+
* with placeholders ({@link replaceDemoMedia}), and the docsite's preview
|
|
383
|
+
* build points them at its image optimizer. It finds and refuses references
|
|
384
|
+
* as {@link stripTemplateAssetRefs} describes.
|
|
385
|
+
*
|
|
386
|
+
* @param {string} source - Template source code.
|
|
387
|
+
* @param {(ref: FixtureRef) => string | null} map - The replacement text, or
|
|
388
|
+
* null to keep the reference as written.
|
|
389
|
+
* @returns {{source: string, replaced: number}} `replaced` counts the
|
|
390
|
+
* references that `map` replaced.
|
|
391
|
+
*/
|
|
392
|
+
export function mapFixtureRefs(source, map) {
|
|
361
393
|
const needle = `/${FIXTURE_SEGMENT}`;
|
|
362
394
|
let output = '';
|
|
363
395
|
let copied = 0;
|
|
364
|
-
let
|
|
396
|
+
let replaced = 0;
|
|
365
397
|
/** @type {Array<[number, number]> | undefined} */
|
|
366
398
|
let comments;
|
|
367
399
|
let at = source.indexOf(needle);
|
|
@@ -373,7 +405,7 @@ export function replaceDemoMedia(source, {videoPlaceholder = ''} = {}) {
|
|
|
373
405
|
/** @type {{text: string, end: number} | null} */
|
|
374
406
|
let edit;
|
|
375
407
|
try {
|
|
376
|
-
edit = fixtureEdit(source, start, at, end,
|
|
408
|
+
edit = fixtureEdit(source, start, at, end, map);
|
|
377
409
|
} catch (err) {
|
|
378
410
|
comments ??= commentRanges(source);
|
|
379
411
|
if (!comments.some(([from, to]) => from <= at && at < to)) throw err;
|
|
@@ -382,11 +414,11 @@ export function replaceDemoMedia(source, {videoPlaceholder = ''} = {}) {
|
|
|
382
414
|
if (edit) {
|
|
383
415
|
output += source.slice(copied, start) + edit.text;
|
|
384
416
|
copied = edit.end;
|
|
385
|
-
|
|
417
|
+
replaced += 1;
|
|
386
418
|
}
|
|
387
419
|
at = source.indexOf(needle, end);
|
|
388
420
|
}
|
|
389
|
-
return {source: output + source.slice(copied),
|
|
421
|
+
return {source: output + source.slice(copied), replaced};
|
|
390
422
|
}
|
|
391
423
|
|
|
392
424
|
/**
|
|
@@ -911,15 +943,15 @@ function fixtureSegments(reference) {
|
|
|
911
943
|
/**
|
|
912
944
|
* The replacement for the fixture reference in the URL token [start, end),
|
|
913
945
|
* which contains FIXTURE_SEGMENT's path at `at`; null when the token is not a
|
|
914
|
-
* fixture reference
|
|
946
|
+
* fixture reference, is a prose mention, or `map` keeps it.
|
|
915
947
|
* @param {string} source
|
|
916
948
|
* @param {number} start
|
|
917
949
|
* @param {number} at
|
|
918
950
|
* @param {number} end
|
|
919
|
-
* @param {string}
|
|
951
|
+
* @param {(ref: FixtureRef) => string | null} map
|
|
920
952
|
* @returns {{text: string, end: number} | null}
|
|
921
953
|
*/
|
|
922
|
-
function fixtureEdit(source, start, at, end,
|
|
954
|
+
function fixtureEdit(source, start, at, end, map) {
|
|
923
955
|
const token = source.slice(start, end);
|
|
924
956
|
if (ABSOLUTE_URL.test(token)) return null;
|
|
925
957
|
if (!token.startsWith('/')) {
|
|
@@ -987,11 +1019,17 @@ function fixtureEdit(source, start, at, end, videoPlaceholder) {
|
|
|
987
1019
|
.extname(segments[segments.length - 1])
|
|
988
1020
|
.slice(1)
|
|
989
1021
|
.toLowerCase();
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
if (IMAGE_EXTENSIONS.has(ext))
|
|
994
|
-
|
|
1022
|
+
/** @type {FixtureRef['kind'] | null} */
|
|
1023
|
+
let kind = null;
|
|
1024
|
+
if (VIDEO_EXTENSIONS.has(ext)) kind = 'video';
|
|
1025
|
+
else if (IMAGE_EXTENSIONS.has(ext)) kind = 'image';
|
|
1026
|
+
if (kind) {
|
|
1027
|
+
const text = map({
|
|
1028
|
+
reference: source.slice(start, referenceEnd),
|
|
1029
|
+
kind,
|
|
1030
|
+
isValue: whole,
|
|
1031
|
+
});
|
|
1032
|
+
return text === null ? null : {text, end: referenceEnd};
|
|
995
1033
|
}
|
|
996
1034
|
if (whole || ext) {
|
|
997
1035
|
throw new Error(
|
|
@@ -2109,13 +2147,7 @@ export function componentsInSource(src) {
|
|
|
2109
2147
|
return parsedComponents(src);
|
|
2110
2148
|
}
|
|
2111
2149
|
|
|
2112
|
-
|
|
2113
|
-
export const TEMPLATE_COMPONENTS_FILE = path.join(
|
|
2114
|
-
CLI_ROOT,
|
|
2115
|
-
'assets',
|
|
2116
|
-
'templates',
|
|
2117
|
-
'components.generated.json',
|
|
2118
|
-
);
|
|
2150
|
+
export {TEMPLATE_COMPONENTS_FILE} from './template-source-tree.mjs';
|
|
2119
2151
|
|
|
2120
2152
|
/**
|
|
2121
2153
|
* The components a template source composes, read from its syntax tree (see
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
* `@scope/name`, unscoped to the first path segment).
|
|
17
17
|
*/
|
|
18
18
|
export function extractImportedPackages(source: string): Set<string>;
|
|
19
|
+
/**
|
|
20
|
+
* moduleSpecifiers, read from the source's syntax tree.
|
|
21
|
+
* @param {string} source
|
|
22
|
+
* @returns {string[]}
|
|
23
|
+
*/
|
|
24
|
+
export function parsedSpecifiers(source: string): string[];
|
|
19
25
|
/**
|
|
20
26
|
* Analyze what a template source needs that the target project lacks.
|
|
21
27
|
*
|
|
@@ -18,7 +18,12 @@
|
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
19
|
import * as path from 'node:path';
|
|
20
20
|
import module from 'node:module';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
parseTemplateSource,
|
|
23
|
+
TEMPLATE_COMPONENTS_FILE,
|
|
24
|
+
walk,
|
|
25
|
+
} from './template-source-tree.mjs';
|
|
26
|
+
import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
|
|
22
27
|
import {CLI_ROOT, findWorkspaceRoot} from '../fs/paths.mjs';
|
|
23
28
|
import {detectStylingSystem} from '../agent-docs/agent-docs.mjs';
|
|
24
29
|
import {
|
|
@@ -81,6 +86,20 @@ export function extractImportedPackages(source) {
|
|
|
81
86
|
* @returns {string[]}
|
|
82
87
|
*/
|
|
83
88
|
function moduleSpecifiers(source) {
|
|
89
|
+
// A template Astryx ships answers from what parsing it returned at publish.
|
|
90
|
+
const stored = readStore(TEMPLATE_COMPONENTS_FILE).get(
|
|
91
|
+
`imports:${storedKey(source)}`,
|
|
92
|
+
);
|
|
93
|
+
if (Array.isArray(stored)) return [...stored];
|
|
94
|
+
return parsedSpecifiers(source);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* moduleSpecifiers, read from the source's syntax tree.
|
|
99
|
+
* @param {string} source
|
|
100
|
+
* @returns {string[]}
|
|
101
|
+
*/
|
|
102
|
+
export function parsedSpecifiers(source) {
|
|
84
103
|
let file;
|
|
85
104
|
try {
|
|
86
105
|
file = parseTemplateSource(source, {errorRecovery: true});
|
|
@@ -50,3 +50,10 @@ export function isReference(node: any, parent: any, key: string): any;
|
|
|
50
50
|
* @returns {Set<string>}
|
|
51
51
|
*/
|
|
52
52
|
export function writtenNames(file: any): Set<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Where what parsing returns for each template Astryx ships is stored at
|
|
55
|
+
* publish (scripts/generate-template-components.mjs): its component list
|
|
56
|
+
* under its source's key, and the module specifiers it imports under
|
|
57
|
+
* `imports:` and that key.
|
|
58
|
+
*/
|
|
59
|
+
export const TEMPLATE_COMPONENTS_FILE: string;
|
|
@@ -12,6 +12,21 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import {createRequire} from 'node:module';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Where what parsing returns for each template Astryx ships is stored at
|
|
20
|
+
* publish (scripts/generate-template-components.mjs): its component list
|
|
21
|
+
* under its source's key, and the module specifiers it imports under
|
|
22
|
+
* `imports:` and that key.
|
|
23
|
+
*/
|
|
24
|
+
export const TEMPLATE_COMPONENTS_FILE = path.join(
|
|
25
|
+
CLI_ROOT,
|
|
26
|
+
'assets',
|
|
27
|
+
'templates',
|
|
28
|
+
'components.generated.json',
|
|
29
|
+
);
|
|
15
30
|
|
|
16
31
|
const require = createRequire(import.meta.url);
|
|
17
32
|
|
|
@@ -147,7 +147,7 @@ export function discoverIntegrationThemes(integration: import("../integrations/i
|
|
|
147
147
|
export const BUNDLED_THEME_PACKAGE: "@astryxdesign/cli";
|
|
148
148
|
export const THEMES_DIR: string;
|
|
149
149
|
export const THEME_DOC_SUFFIX: ".doc.mjs";
|
|
150
|
-
export
|
|
150
|
+
export { THEME_MODULE_EXTENSIONS };
|
|
151
151
|
/** A theme directory's name: lower-kebab, starting with a letter. */
|
|
152
152
|
export const THEME_SLUG_RE: RegExp;
|
|
153
153
|
export type DiscoveredTheme = {
|
|
@@ -196,3 +196,4 @@ export type UnmigratedThemeCopy = {
|
|
|
196
196
|
exportName: string;
|
|
197
197
|
descriptor: string;
|
|
198
198
|
};
|
|
199
|
+
import { THEME_MODULE_EXTENSIONS } from './theme-module-extensions.mjs';
|
|
@@ -26,6 +26,7 @@ import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
|
26
26
|
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
27
27
|
import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
28
28
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
29
|
+
import {THEME_MODULE_EXTENSIONS} from './theme-module-extensions.mjs';
|
|
29
30
|
|
|
30
31
|
export const BUNDLED_THEME_PACKAGE = '@astryxdesign/cli';
|
|
31
32
|
export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
|
|
@@ -114,14 +115,7 @@ function resolveThemePath(value, root, label) {
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
export
|
|
118
|
-
'.mjs',
|
|
119
|
-
'.js',
|
|
120
|
-
'.mts',
|
|
121
|
-
'.ts',
|
|
122
|
-
'.tsx',
|
|
123
|
-
'.jsx',
|
|
124
|
-
];
|
|
118
|
+
export {THEME_MODULE_EXTENSIONS};
|
|
125
119
|
|
|
126
120
|
/** A theme directory's name: lower-kebab, starting with a letter. */
|
|
127
121
|
export const THEME_SLUG_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
@@ -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
|
+
* @file The file extensions a theme source module can have.
|
|
6
|
+
*
|
|
7
|
+
* @input none
|
|
8
|
+
* @output THEME_MODULE_EXTENSIONS and THEME_SOURCE_EXTENSIONS
|
|
9
|
+
* @position read by theme discovery (which theme sources it accepts) and by
|
|
10
|
+
* `theme build` (which inputs it loads), so both accept the same files
|
|
11
|
+
*/
|
|
12
|
+
/** The extensions of a discoverable theme source, `<name>Theme.<ext>`. */
|
|
13
|
+
export const THEME_MODULE_EXTENSIONS: string[];
|
|
14
|
+
/**
|
|
15
|
+
* The extensions `theme build` loads as a theme source: the discoverable ones,
|
|
16
|
+
* and their CommonJS forms, which a theme may also be written in.
|
|
17
|
+
*/
|
|
18
|
+
export const THEME_SOURCE_EXTENSIONS: string[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The file extensions a theme source module can have.
|
|
5
|
+
*
|
|
6
|
+
* @input none
|
|
7
|
+
* @output THEME_MODULE_EXTENSIONS and THEME_SOURCE_EXTENSIONS
|
|
8
|
+
* @position read by theme discovery (which theme sources it accepts) and by
|
|
9
|
+
* `theme build` (which inputs it loads), so both accept the same files
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** The extensions of a discoverable theme source, `<name>Theme.<ext>`. */
|
|
13
|
+
export const THEME_MODULE_EXTENSIONS = [
|
|
14
|
+
'.mjs',
|
|
15
|
+
'.js',
|
|
16
|
+
'.mts',
|
|
17
|
+
'.ts',
|
|
18
|
+
'.tsx',
|
|
19
|
+
'.jsx',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The extensions `theme build` loads as a theme source: the discoverable ones,
|
|
24
|
+
* and their CommonJS forms, which a theme may also be written in.
|
|
25
|
+
*/
|
|
26
|
+
export const THEME_SOURCE_EXTENSIONS = [
|
|
27
|
+
...THEME_MODULE_EXTENSIONS,
|
|
28
|
+
'.cjs',
|
|
29
|
+
'.cts',
|
|
30
|
+
];
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import * as fs from 'node:fs';
|
|
28
28
|
import {pathToFileURL} from 'node:url';
|
|
29
|
-
import {
|
|
29
|
+
import {createRequire} from 'node:module';
|
|
30
30
|
import {importUrl} from '../fs/import-url.mjs';
|
|
31
31
|
import {
|
|
32
32
|
importUserModule,
|
|
@@ -34,12 +34,15 @@ import {
|
|
|
34
34
|
readInTurn,
|
|
35
35
|
} from '../fs/module-loader.mjs';
|
|
36
36
|
import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
import {readStore, storedKey, STORED_DOCS_FILE} from './stored-docs.mjs';
|
|
38
|
+
|
|
39
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* jiti, loaded on first use: only TypeScript doc files need it.
|
|
43
|
+
* @type {typeof import('jiti').createJiti}
|
|
44
|
+
*/
|
|
45
|
+
const createJiti = (...args) => requireFromHere('jiti').createJiti(...args);
|
|
43
46
|
|
|
44
47
|
/** @type {ReturnType<typeof createJiti> | undefined} */
|
|
45
48
|
let jsxJiti;
|
|
@@ -101,16 +104,14 @@ function loadFirst(file, load) {
|
|
|
101
104
|
const storedModules = new Map();
|
|
102
105
|
|
|
103
106
|
/**
|
|
104
|
-
* The module of a
|
|
107
|
+
* The module of a doc file whose text has stored exports: an object
|
|
105
108
|
* shaped as its namespace (no prototype, the export names in order, tagged
|
|
106
109
|
* `Module`, closed to new names). Null for any other file.
|
|
107
110
|
* @param {string} file
|
|
108
111
|
* @returns {Record<string, unknown> | null}
|
|
109
112
|
*/
|
|
110
113
|
function storedModule(file) {
|
|
111
|
-
if (!file.
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
+
if (!file.endsWith('.doc.mjs')) return null;
|
|
114
115
|
let text;
|
|
115
116
|
try {
|
|
116
117
|
text = fs.readFileSync(file, 'utf-8');
|
|
@@ -5,23 +5,29 @@
|
|
|
5
5
|
* The key of a source file's text in a store written at publish (the stored
|
|
6
6
|
* docs, the stored template component lists): a hash of the text, so an
|
|
7
7
|
* edited or unknown file is never answered from a store.
|
|
8
|
-
* @param {string} text
|
|
8
|
+
* @param {string | Buffer} text
|
|
9
9
|
* @returns {string}
|
|
10
10
|
*/
|
|
11
|
-
export function storedKey(text: string): string;
|
|
11
|
+
export function storedKey(text: string | Buffer): string;
|
|
12
12
|
/**
|
|
13
|
-
* A store written at publish, by key, read once per process. A
|
|
14
|
-
*
|
|
13
|
+
* A store written at publish, by key, read once per process. A store is
|
|
14
|
+
* either one JSON object of key to value, or (the stored docs) a first line
|
|
15
|
+
* mapping each key to its byte range, then the values: a lookup parses only
|
|
16
|
+
* the value it reads. A missing or unreadable file reads as empty, so every
|
|
17
|
+
* source is worked out as before.
|
|
15
18
|
* @param {string} file
|
|
16
|
-
* @returns {
|
|
19
|
+
* @returns {{get: (key: string) => any}}
|
|
17
20
|
*/
|
|
18
|
-
export function readStore(file: string):
|
|
21
|
+
export function readStore(file: string): {
|
|
22
|
+
get: (key: string) => any;
|
|
23
|
+
};
|
|
19
24
|
/**
|
|
20
|
-
* Where the exports of the doc files Astryx ships
|
|
21
|
-
* imports nothing,
|
|
22
|
-
* hash of its text.
|
|
23
|
-
* file
|
|
25
|
+
* Where the exports of the doc files Astryx ships (the CLI's and Core's) are
|
|
26
|
+
* stored: each doc that imports nothing, reads nothing of where it sits, and
|
|
27
|
+
* exports only plain data, by a hash of its text. Such a doc's exports depend
|
|
28
|
+
* on its text alone, so any file with that exact text reads them; an edited
|
|
29
|
+
* or unknown file is imported as before. The first line maps each key to the
|
|
30
|
+
* byte range of its exports, as JSON, in the rest of the file, so a read
|
|
31
|
+
* parses only the docs it needs.
|
|
24
32
|
*/
|
|
25
33
|
export const STORED_DOCS_FILE: string;
|
|
26
|
-
/** The folder of the files Astryx ships; only its doc files are stored. */
|
|
27
|
-
export const SHIPPED_ASSETS: string;
|
|
@@ -15,10 +15,13 @@ import * as path from 'node:path';
|
|
|
15
15
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Where the exports of the doc files Astryx ships
|
|
19
|
-
* imports nothing,
|
|
20
|
-
* hash of its text.
|
|
21
|
-
* file
|
|
18
|
+
* Where the exports of the doc files Astryx ships (the CLI's and Core's) are
|
|
19
|
+
* stored: each doc that imports nothing, reads nothing of where it sits, and
|
|
20
|
+
* exports only plain data, by a hash of its text. Such a doc's exports depend
|
|
21
|
+
* on its text alone, so any file with that exact text reads them; an edited
|
|
22
|
+
* or unknown file is imported as before. The first line maps each key to the
|
|
23
|
+
* byte range of its exports, as JSON, in the rest of the file, so a read
|
|
24
|
+
* parses only the docs it needs.
|
|
22
25
|
*/
|
|
23
26
|
export const STORED_DOCS_FILE = path.join(
|
|
24
27
|
CLI_ROOT,
|
|
@@ -26,40 +29,70 @@ export const STORED_DOCS_FILE = path.join(
|
|
|
26
29
|
'docs.generated.json',
|
|
27
30
|
);
|
|
28
31
|
|
|
29
|
-
/** The folder of the files Astryx ships; only its doc files are stored. */
|
|
30
|
-
export const SHIPPED_ASSETS = path.join(CLI_ROOT, 'assets') + path.sep;
|
|
31
|
-
|
|
32
32
|
/**
|
|
33
33
|
* The key of a source file's text in a store written at publish (the stored
|
|
34
34
|
* docs, the stored template component lists): a hash of the text, so an
|
|
35
35
|
* edited or unknown file is never answered from a store.
|
|
36
|
-
* @param {string} text
|
|
36
|
+
* @param {string | Buffer} text
|
|
37
37
|
* @returns {string}
|
|
38
38
|
*/
|
|
39
39
|
export function storedKey(text) {
|
|
40
40
|
return createHash('sha256').update(text).digest('hex').slice(0, 32);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
/** @type {Map<string,
|
|
43
|
+
/** @type {Map<string, {get: (key: string) => any}>} */
|
|
44
44
|
const stores = new Map();
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* A store written at publish, by key, read once per process. A
|
|
48
|
-
*
|
|
47
|
+
* A store written at publish, by key, read once per process. A store is
|
|
48
|
+
* either one JSON object of key to value, or (the stored docs) a first line
|
|
49
|
+
* mapping each key to its byte range, then the values: a lookup parses only
|
|
50
|
+
* the value it reads. A missing or unreadable file reads as empty, so every
|
|
51
|
+
* source is worked out as before.
|
|
49
52
|
* @param {string} file
|
|
50
|
-
* @returns {
|
|
53
|
+
* @returns {{get: (key: string) => any}}
|
|
51
54
|
*/
|
|
52
55
|
export function readStore(file) {
|
|
53
56
|
let store = stores.get(file);
|
|
54
57
|
if (!store) {
|
|
55
|
-
|
|
56
|
-
store = new Map(
|
|
57
|
-
Object.entries(JSON.parse(fs.readFileSync(file, 'utf-8'))),
|
|
58
|
-
);
|
|
59
|
-
} catch {
|
|
60
|
-
store = new Map();
|
|
61
|
-
}
|
|
58
|
+
store = openStore(file);
|
|
62
59
|
stores.set(file, store);
|
|
63
60
|
}
|
|
64
61
|
return store;
|
|
65
62
|
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {string} file
|
|
66
|
+
* @returns {{get: (key: string) => any}}
|
|
67
|
+
*/
|
|
68
|
+
function openStore(file) {
|
|
69
|
+
/** @type {Buffer} */
|
|
70
|
+
let bytes;
|
|
71
|
+
try {
|
|
72
|
+
bytes = fs.readFileSync(file);
|
|
73
|
+
} catch {
|
|
74
|
+
return new Map();
|
|
75
|
+
}
|
|
76
|
+
const end = bytes.indexOf(0x0a);
|
|
77
|
+
try {
|
|
78
|
+
if (end !== -1 && end < bytes.length - 1) {
|
|
79
|
+
/** @type {Map<string, [number, number]>} */
|
|
80
|
+
const ranges = new Map(
|
|
81
|
+
Object.entries(JSON.parse(bytes.toString('utf-8', 0, end))),
|
|
82
|
+
);
|
|
83
|
+
const data = bytes.subarray(end + 1);
|
|
84
|
+
return {
|
|
85
|
+
get(key) {
|
|
86
|
+
const range = ranges.get(key);
|
|
87
|
+
if (!range) return undefined;
|
|
88
|
+
return JSON.parse(
|
|
89
|
+
data.toString('utf-8', range[0], range[0] + range[1]),
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return new Map(Object.entries(JSON.parse(bytes.toString('utf-8'))));
|
|
95
|
+
} catch {
|
|
96
|
+
return new Map();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
* The current user's id, or null where the system has none (Windows).
|
|
6
|
+
* @returns {number | null}
|
|
7
|
+
*/
|
|
8
|
+
export function currentUid(): number | null;
|
|
9
|
+
/**
|
|
10
|
+
* Whether `dir` is a real folder (not a link) that the current user owns and
|
|
11
|
+
* no one else can reach, so nothing in it can have been planted by another
|
|
12
|
+
* account. False where the system has no user ids (Windows): ownership cannot
|
|
13
|
+
* be checked there, so such a folder is never used.
|
|
14
|
+
* @param {string} dir
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
export function isPrivateDir(dir: string): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The check a folder of cached code or data must pass before the CLI
|
|
5
|
+
* reads from it: Node's compile cache (clients/cli/bin/astryx.mjs) and the
|
|
6
|
+
* kept search catalogs (foundation/fs/gather-cache.mjs). Built-ins only, so
|
|
7
|
+
* the bin can load it before anything else.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The current user's id, or null where the system has none (Windows).
|
|
14
|
+
* @returns {number | null}
|
|
15
|
+
*/
|
|
16
|
+
export function currentUid() {
|
|
17
|
+
return typeof process.getuid === 'function' ? process.getuid() : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether `dir` is a real folder (not a link) that the current user owns and
|
|
22
|
+
* no one else can reach, so nothing in it can have been planted by another
|
|
23
|
+
* account. False where the system has no user ids (Windows): ownership cannot
|
|
24
|
+
* be checked there, so such a folder is never used.
|
|
25
|
+
* @param {string} dir
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function isPrivateDir(dir) {
|
|
29
|
+
const uid = currentUid();
|
|
30
|
+
if (uid == null) return false;
|
|
31
|
+
try {
|
|
32
|
+
const stat = fs.lstatSync(dir);
|
|
33
|
+
return (
|
|
34
|
+
stat.isDirectory() &&
|
|
35
|
+
!stat.isSymbolicLink() &&
|
|
36
|
+
stat.uid === uid &&
|
|
37
|
+
(stat.mode & 0o077) === 0
|
|
38
|
+
);
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
* The running recorded run's reads and variables, for tests: null outside one.
|
|
6
|
+
* @returns {{reads: Map<string, string>, env: Map<string, string | null>} | null}
|
|
7
|
+
*/
|
|
8
|
+
export function recordedRun(): {
|
|
9
|
+
reads: Map<string, string>;
|
|
10
|
+
env: Map<string, string | null>;
|
|
11
|
+
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* The outcome of the last kept gather in this process: whether it was a hit,
|
|
14
|
+
* and why it missed. Null when no kept gather ran.
|
|
15
|
+
* @returns {{hit: boolean, reason: string} | null}
|
|
16
|
+
*/
|
|
17
|
+
export function gatherCacheOutcome(): {
|
|
18
|
+
hit: boolean;
|
|
19
|
+
reason: string;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* The kept catalogs' folder, or null when it is missing or cannot be used:
|
|
23
|
+
* not a real folder, owned by someone else, open to others, or on a system
|
|
24
|
+
* with no user ids, where ownership cannot be checked (see isPrivateDir).
|
|
25
|
+
* @returns {string | null}
|
|
26
|
+
*/
|
|
27
|
+
export function gatherCacheDir(): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Run `fn`, recording what it reads, when the arguments ask for a command
|
|
30
|
+
* whose gather is kept and the CLI can keep one. Otherwise run it as is.
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {string[]} argv
|
|
33
|
+
* @param {() => Promise<T>} fn
|
|
34
|
+
* @returns {Promise<T>}
|
|
35
|
+
*/
|
|
36
|
+
export function recordRunFor<T>(argv: string[], fn: () => Promise<T>): Promise<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Run `fn` as a recorded run (see `run`), armed from its start. Exported for
|
|
39
|
+
* tests; `recordRunFor` decides which runs are recorded.
|
|
40
|
+
* @template T
|
|
41
|
+
* @param {() => Promise<T>} fn
|
|
42
|
+
* @returns {Promise<T>}
|
|
43
|
+
*/
|
|
44
|
+
export function recordRun<T>(fn: () => Promise<T>): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* The gather `load` returns, or the one a run with the same key stored while
|
|
47
|
+
* every input it read is unchanged (see the file header).
|
|
48
|
+
* @template T, E
|
|
49
|
+
* @param {unknown[]} key - What else decides the gather: its folder (a real
|
|
50
|
+
* path) and options.
|
|
51
|
+
* @param {() => Promise<T>} load
|
|
52
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec - A
|
|
53
|
+
* plain-JSON form of the value and back.
|
|
54
|
+
* @param {(value: T) => boolean} [keep] whether a fresh gather may be
|
|
55
|
+
* stored: one that depends on something its stamps cannot see (a retry
|
|
56
|
+
* that waits on time) is used for this run only
|
|
57
|
+
* @returns {Promise<T>}
|
|
58
|
+
*/
|
|
59
|
+
export function persistedGather<T, E>(key: unknown[], load: () => Promise<T>, codec: {
|
|
60
|
+
encode: (value: T) => E;
|
|
61
|
+
decode: (stored: E) => T;
|
|
62
|
+
}, keep?: (value: T) => boolean): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* A value derived from what a kept gather holds, kept beside the gather: it
|
|
65
|
+
* is a function of `key`, of the CLI's code and of `inputs` (with this CLI
|
|
66
|
+
* build), so a stored value is used as it is. The code is the CLI's own files
|
|
67
|
+
* the run's kept gather depends on (each by its stamp, so an edit misses the
|
|
68
|
+
* gather and the value alike), with `inputs`: the files the computation reads
|
|
69
|
+
* that the gather may not have, such as its own module and its weights. An
|
|
70
|
+
* edit to any of them in an installed copy, where the build id stays the
|
|
71
|
+
* same, is a new key. Kept only after a kept gather in the run (a search or
|
|
72
|
+
* build of an installed CLI whose cache folder exists); anywhere else, or on
|
|
73
|
+
* any read or write error, `compute` runs as before.
|
|
74
|
+
* @template T, E
|
|
75
|
+
* @param {unknown[]} key - Everything the value is computed from.
|
|
76
|
+
* @param {() => T} compute
|
|
77
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec
|
|
78
|
+
* @param {string[]} [inputs] - Files the computation reads, by path.
|
|
79
|
+
* @returns {T}
|
|
80
|
+
*/
|
|
81
|
+
export function persistedDerived<T, E>(key: unknown[], compute: () => T, codec: {
|
|
82
|
+
encode: (value: T) => E;
|
|
83
|
+
decode: (stored: E) => T;
|
|
84
|
+
}, inputs?: string[]): T;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this run is under Yarn Plug'n'Play's loader (`yarn astryx` in a PnP
|
|
87
|
+
* project): Node's module hooks hand PnP's resolver options it refuses, so
|
|
88
|
+
* such a run keeps and uses no catalogs. The plain `astryx` command in the
|
|
89
|
+
* same project keeps them.
|
|
90
|
+
* @returns {boolean}
|
|
91
|
+
*/
|
|
92
|
+
export function runsUnderPnp(): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* The cache folder and how much it holds, for `doctor`: null when the CLI
|
|
95
|
+
* keeps no gathers (a checkout) or has no usable folder.
|
|
96
|
+
* @returns {{dir: string, bytes: number, entries: number, pnp: boolean} | null}
|
|
97
|
+
* `pnp`: whether this run is under Yarn Plug'n'Play's loader (runsUnderPnp)
|
|
98
|
+
*/
|
|
99
|
+
export function gatherCacheSummary(): {
|
|
100
|
+
dir: string;
|
|
101
|
+
bytes: number;
|
|
102
|
+
entries: number;
|
|
103
|
+
pnp: boolean;
|
|
104
|
+
} | null;
|
|
105
|
+
/** Where `prepack` writes the id of the package's exact contents. */
|
|
106
|
+
export const BUILD_ID_FILE: string;
|
|
107
|
+
/** The most the folder holds; the oldest entries go first past it. */
|
|
108
|
+
export const CACHE_LIMIT_BYTES: number;
|