@astryxdesign/cli 0.7.15 → 0.7.16-canary.g07c77c0
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 +5 -3
- package/api/build/_adapter.d.mts +1 -0
- package/api/build/blocks/blocks.d.mts +1 -0
- package/api/build/blocks/blocks.mjs +18 -1
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +43 -0
- package/api/doctor/built-checks.mjs +1 -1
- package/api/doctor/doctor.mjs +18 -4
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/integration/add-contribution.mjs +3 -3
- package/api/integration/pack-check.mjs +14 -8
- package/api/integration/validate-integration.mjs +1 -1
- package/api/search/_adapter.mjs +15 -16
- package/api/search/_entries.d.mts +2 -1
- package/api/search/_entries.mjs +28 -1
- package/api/swizzle/_moduleGraph.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/_fork.mjs +1 -1
- package/api/theme/build/build.d.mts +116 -32
- package/api/theme/build/build.mjs +449 -102
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +32 -2
- package/api/theme-edit/_adapter.mjs +213 -36
- package/api/theme-edit/_check.d.mts +69 -3
- package/api/theme-edit/_check.mjs +1517 -218
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +29 -0
- package/api/theme-edit/_context.mjs +426 -40
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1300 -135
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +33 -0
- package/api/theme-edit/_parts.mjs +138 -9
- package/api/theme-edit/_png.d.mts +18 -0
- package/api/theme-edit/_png.mjs +95 -14
- package/api/theme-edit/_preview-app.d.mts +9 -0
- package/api/theme-edit/_preview-app.mjs +1191 -71
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +335 -30
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +240 -5
- package/api/theme-edit/_settings.mjs +2561 -115
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/codemods/parse.mjs +2 -2
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/authoring/shadcn/source-variants.d.mts +1 -1
- package/authoring/shadcn/source-variants.mjs +32 -10
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +237 -45
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
- 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 +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +190 -46
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +72 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
- package/foundation/agent-docs/agent-docs-target.mjs +9 -17
- package/foundation/agent-docs/agent-docs.mjs +3 -2
- package/foundation/config/config-writer.mjs +2 -2
- package/foundation/config/project.mjs +60 -14
- package/foundation/discovery/component-discovery.mjs +5 -17
- package/foundation/discovery/icon-set-writer.mjs +1 -1
- package/foundation/discovery/module-exports.mjs +1 -15
- package/foundation/discovery/template-adapter.mjs +44 -19
- package/foundation/discovery/template-source-tree.mjs +3 -16
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +30 -35
- package/foundation/fs/exact-codec.d.mts +35 -0
- package/foundation/fs/exact-codec.mjs +148 -0
- package/foundation/fs/gather-cache.d.mts +15 -5
- package/foundation/fs/gather-cache.mjs +123 -30
- package/foundation/fs/paths.d.mts +39 -0
- package/foundation/fs/paths.mjs +44 -11
- package/foundation/fs/read-record.mjs +11 -1
- package/foundation/integrations/contribution-fixes.mjs +1 -16
- package/foundation/integrations/may-have-integrations.mjs +3 -2
- package/foundation/integrations/public-imports.mjs +1 -1
- package/foundation/render/embedded-imports.mjs +1 -1
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/runtime/lazy-dependencies.d.mts +14 -0
- package/foundation/runtime/lazy-dependencies.mjs +82 -0
- package/foundation/xle/browser.d.mts +2 -2
- package/package.json +7 -6
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
* Whether `value` is plain data that JSON, with `undefined` stood in for,
|
|
6
|
+
* carries exactly: finite numbers but -0, strings, booleans, null, arrays
|
|
7
|
+
* with no holes or other properties, and objects of Object's own prototype
|
|
8
|
+
* whose properties are all enumerable, plain, and string-keyed, with no
|
|
9
|
+
* object reached twice. `undefined` counts only inside an object or array.
|
|
10
|
+
* @param {unknown} value
|
|
11
|
+
* @param {Set<object>} [seen]
|
|
12
|
+
* @param {boolean} [inside]
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
export function isPlain(value: unknown, seen?: Set<object>, inside?: boolean): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether two plain values are the same, key order included: what
|
|
18
|
+
* isDeepStrictEqual does not check.
|
|
19
|
+
* @param {unknown} a
|
|
20
|
+
* @param {unknown} b
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*/
|
|
23
|
+
export function sameExactly(a: unknown, b: unknown): boolean;
|
|
24
|
+
export namespace EXACT_CODEC {
|
|
25
|
+
/**
|
|
26
|
+
* @param {unknown} value
|
|
27
|
+
* @returns {unknown}
|
|
28
|
+
*/
|
|
29
|
+
function encode(value: unknown): unknown;
|
|
30
|
+
/**
|
|
31
|
+
* @param {unknown} stored
|
|
32
|
+
* @returns {any}
|
|
33
|
+
*/
|
|
34
|
+
function decode(stored: unknown): any;
|
|
35
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A codec for kept values (foundation/fs/gather-cache.mjs) that reads
|
|
5
|
+
* back exactly what it was given, or refuses to encode it.
|
|
6
|
+
* @input Plain data: objects, arrays, strings, numbers, booleans, null, and
|
|
7
|
+
* `undefined` as a property value or array item, which JSON drops.
|
|
8
|
+
* @output `EXACT_CODEC`: `encode` turns such a value into JSON-safe data, with
|
|
9
|
+
* each `undefined` as a reserved string (and a real string that begins with
|
|
10
|
+
* that string's first character escaped); `decode` restores it in place,
|
|
11
|
+
* key order kept. `encode` throws, keeping nothing, unless the value is
|
|
12
|
+
* plain data (isPlain) and reads back the same, key order included
|
|
13
|
+
* (sameExactly): so a function, a Map, a Date, a class instance, an Error,
|
|
14
|
+
* a symbol key, an accessor or hidden property, an array hole, -0, NaN, an
|
|
15
|
+
* infinity, or an object reached twice (shared or in a cycle) is never
|
|
16
|
+
* kept, and the value is worked out as without the cache.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** The first character of every reserved string: no plain text holds it. */
|
|
20
|
+
const MARK = '\u0000';
|
|
21
|
+
|
|
22
|
+
/** What stands for `undefined`. */
|
|
23
|
+
const UNDEFINED = `${MARK}u`;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} key
|
|
27
|
+
* @param {unknown} value
|
|
28
|
+
* @returns {unknown}
|
|
29
|
+
*/
|
|
30
|
+
function replace(key, value) {
|
|
31
|
+
if (value === undefined) return UNDEFINED;
|
|
32
|
+
if (typeof value === 'string' && value.startsWith(MARK)) return MARK + value;
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Put back what `replace` stood in for, in place.
|
|
38
|
+
* @param {unknown} value
|
|
39
|
+
* @returns {unknown}
|
|
40
|
+
*/
|
|
41
|
+
function restore(value) {
|
|
42
|
+
if (typeof value === 'string' && value.startsWith(MARK)) {
|
|
43
|
+
return value === UNDEFINED ? undefined : value.slice(1);
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
for (let i = 0; i < value.length; i++) value[i] = restore(value[i]);
|
|
47
|
+
} else if (value !== null && typeof value === 'object') {
|
|
48
|
+
const object = /** @type {Record<string, unknown>} */ (value);
|
|
49
|
+
for (const key of Object.keys(object)) object[key] = restore(object[key]);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether `value` is plain data that JSON, with `undefined` stood in for,
|
|
56
|
+
* carries exactly: finite numbers but -0, strings, booleans, null, arrays
|
|
57
|
+
* with no holes or other properties, and objects of Object's own prototype
|
|
58
|
+
* whose properties are all enumerable, plain, and string-keyed, with no
|
|
59
|
+
* object reached twice. `undefined` counts only inside an object or array.
|
|
60
|
+
* @param {unknown} value
|
|
61
|
+
* @param {Set<object>} [seen]
|
|
62
|
+
* @param {boolean} [inside]
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
export function isPlain(value, seen = new Set(), inside = false) {
|
|
66
|
+
if (value === undefined) return inside;
|
|
67
|
+
if (value === null) return true;
|
|
68
|
+
switch (typeof value) {
|
|
69
|
+
case 'string':
|
|
70
|
+
case 'boolean':
|
|
71
|
+
return true;
|
|
72
|
+
case 'number':
|
|
73
|
+
return Number.isFinite(value) && !Object.is(value, -0);
|
|
74
|
+
case 'object':
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const object = /** @type {object} */ (value);
|
|
80
|
+
if (seen.has(object)) return false;
|
|
81
|
+
seen.add(object);
|
|
82
|
+
const keys = Reflect.ownKeys(object);
|
|
83
|
+
if (Array.isArray(object)) {
|
|
84
|
+
if (Object.getPrototypeOf(object) !== Array.prototype) return false;
|
|
85
|
+
// Its indexes and `length`, nothing else, and no holes.
|
|
86
|
+
if (keys.length !== object.length + 1) return false;
|
|
87
|
+
for (let i = 0; i < object.length; i++) {
|
|
88
|
+
if (!Object.hasOwn(object, i)) return false;
|
|
89
|
+
const d = Object.getOwnPropertyDescriptor(object, i);
|
|
90
|
+
if (!d || !('value' in d) || !d.enumerable) return false;
|
|
91
|
+
if (!isPlain(d.value, seen, true)) return false;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (Object.getPrototypeOf(object) !== Object.prototype) return false;
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
if (typeof key !== 'string') return false;
|
|
98
|
+
const d = Object.getOwnPropertyDescriptor(object, key);
|
|
99
|
+
if (!d || !('value' in d) || !d.enumerable) return false;
|
|
100
|
+
if (!isPlain(d.value, seen, true)) return false;
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Whether two plain values are the same, key order included: what
|
|
107
|
+
* isDeepStrictEqual does not check.
|
|
108
|
+
* @param {unknown} a
|
|
109
|
+
* @param {unknown} b
|
|
110
|
+
* @returns {boolean}
|
|
111
|
+
*/
|
|
112
|
+
export function sameExactly(a, b) {
|
|
113
|
+
if (Object.is(a, b)) return true;
|
|
114
|
+
if (typeof a !== 'object' || typeof b !== 'object' || !a || !b) return false;
|
|
115
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
116
|
+
const ka = Object.keys(a);
|
|
117
|
+
const kb = Object.keys(b);
|
|
118
|
+
if (ka.length !== kb.length) return false;
|
|
119
|
+
for (let i = 0; i < ka.length; i++) {
|
|
120
|
+
if (ka[i] !== kb[i]) return false;
|
|
121
|
+
const x = /** @type {Record<string, unknown>} */ (a)[ka[i]];
|
|
122
|
+
const y = /** @type {Record<string, unknown>} */ (b)[kb[i]];
|
|
123
|
+
if (!sameExactly(x, y)) return false;
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const EXACT_CODEC = {
|
|
129
|
+
/**
|
|
130
|
+
* @param {unknown} value
|
|
131
|
+
* @returns {unknown}
|
|
132
|
+
*/
|
|
133
|
+
encode(value) {
|
|
134
|
+
if (!isPlain(value)) throw new Error('not plain data');
|
|
135
|
+
const text = JSON.stringify(value, replace);
|
|
136
|
+
if (!sameExactly(restore(JSON.parse(text)), value)) {
|
|
137
|
+
throw new Error('does not read back exactly');
|
|
138
|
+
}
|
|
139
|
+
return JSON.parse(text);
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* @param {unknown} stored
|
|
143
|
+
* @returns {any}
|
|
144
|
+
*/
|
|
145
|
+
decode(stored) {
|
|
146
|
+
return restore(stored);
|
|
147
|
+
},
|
|
148
|
+
};
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* The running recorded run's reads and variables,
|
|
5
|
+
* The running recorded run's reads and variables, or null outside one: for
|
|
6
|
+
* tests, and for a caller that keeps a value only in a recorded run (doctor's
|
|
7
|
+
* kept checks).
|
|
6
8
|
* @returns {{reads: Map<string, string>, env: Map<string, string | null>} | null}
|
|
7
9
|
*/
|
|
8
10
|
export function recordedRun(): {
|
|
@@ -39,9 +41,14 @@ export function recordRunFor<T>(argv: string[], fn: () => Promise<T>): Promise<T
|
|
|
39
41
|
* tests; `recordRunFor` decides which runs are recorded.
|
|
40
42
|
* @template T
|
|
41
43
|
* @param {() => Promise<T>} fn
|
|
44
|
+
* @param {{armedThroughout?: boolean}} [options] - `armedThroughout`: record
|
|
45
|
+
* modules and variables until the run ends, not only until each gather
|
|
46
|
+
* ends, for a run whose later gathers read modules loaded in between.
|
|
42
47
|
* @returns {Promise<T>}
|
|
43
48
|
*/
|
|
44
|
-
export function recordRun<T>(fn: () => Promise<T
|
|
49
|
+
export function recordRun<T>(fn: () => Promise<T>, { armedThroughout }?: {
|
|
50
|
+
armedThroughout?: boolean;
|
|
51
|
+
}): Promise<T>;
|
|
45
52
|
/**
|
|
46
53
|
* The gather `load` returns, or the one a run with the same key stored while
|
|
47
54
|
* every input it read is unchanged (see the file header).
|
|
@@ -49,8 +56,9 @@ export function recordRun<T>(fn: () => Promise<T>): Promise<T>;
|
|
|
49
56
|
* @param {unknown[]} key - What else decides the gather: its folder (a real
|
|
50
57
|
* path) and options.
|
|
51
58
|
* @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
|
|
59
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T, valid?: (value: T) => boolean}} codec - A
|
|
60
|
+
* plain-JSON form of the value and back, and optionally the shape a decoded
|
|
61
|
+
* value must have to be used (anything else is a miss).
|
|
54
62
|
* @param {(value: T) => boolean} [keep] whether a fresh gather may be
|
|
55
63
|
* stored: one that depends on something its stamps cannot see (a retry
|
|
56
64
|
* that waits on time) is used for this run only
|
|
@@ -59,6 +67,7 @@ export function recordRun<T>(fn: () => Promise<T>): Promise<T>;
|
|
|
59
67
|
export function persistedGather<T, E>(key: unknown[], load: () => Promise<T>, codec: {
|
|
60
68
|
encode: (value: T) => E;
|
|
61
69
|
decode: (stored: E) => T;
|
|
70
|
+
valid?: (value: T) => boolean;
|
|
62
71
|
}, keep?: (value: T) => boolean): Promise<T>;
|
|
63
72
|
/**
|
|
64
73
|
* A value derived from what a kept gather holds, kept beside the gather: it
|
|
@@ -74,13 +83,14 @@ export function persistedGather<T, E>(key: unknown[], load: () => Promise<T>, co
|
|
|
74
83
|
* @template T, E
|
|
75
84
|
* @param {unknown[]} key - Everything the value is computed from.
|
|
76
85
|
* @param {() => T} compute
|
|
77
|
-
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec
|
|
86
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T, valid?: (value: T) => boolean}} codec
|
|
78
87
|
* @param {string[]} [inputs] - Files the computation reads, by path.
|
|
79
88
|
* @returns {T}
|
|
80
89
|
*/
|
|
81
90
|
export function persistedDerived<T, E>(key: unknown[], compute: () => T, codec: {
|
|
82
91
|
encode: (value: T) => E;
|
|
83
92
|
decode: (stored: E) => T;
|
|
93
|
+
valid?: (value: T) => boolean;
|
|
84
94
|
}, inputs?: string[]): T;
|
|
85
95
|
/**
|
|
86
96
|
* Whether this run is under Yarn Plug'n'Play's loader (`yarn astryx` in a PnP
|
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
* gathers fresh and stores that.
|
|
14
14
|
* @position Used by search's adapter (api/search/_adapter.mjs) for the
|
|
15
15
|
* catalog `search` and `build` rank, and by the project
|
|
16
|
-
* (foundation/config/project.mjs) for
|
|
17
|
-
* results
|
|
18
|
-
*
|
|
16
|
+
* (foundation/config/project.mjs) for its integration issues: each
|
|
17
|
+
* integration's contribution-check results and the whole list (with the
|
|
18
|
+
* template and component replacement passes), which `component`,
|
|
19
|
+
* `template`, `theme`, `discover` and `search` report, by template
|
|
20
|
+
* discovery (foundation/discovery/template-adapter.mjs) for its records,
|
|
21
|
+
* and by `doctor` (api/doctor/_adapter.mjs) for its file-only docs checks,
|
|
22
|
+
* in a run that records modules and variables to its end. Gathers are kept only once the folder exists: the first such run
|
|
19
23
|
* on a machine just makes it, so a one-off run pays nothing to store one. Only a published CLI stores anything:
|
|
20
24
|
* its build id (clients/cli/build-id.generated.json, written at `prepack`)
|
|
21
25
|
* names its exact code, so a checkout, whose code may change between runs
|
|
@@ -49,8 +53,10 @@ import {
|
|
|
49
53
|
} from './read-record.mjs';
|
|
50
54
|
|
|
51
55
|
/**
|
|
52
|
-
* The kept commands whose
|
|
53
|
-
*
|
|
56
|
+
* The kept commands whose kept gathers are worth recording only where an
|
|
57
|
+
* integration can load (its check results, and template discovery, whose
|
|
58
|
+
* records hold Core's templates too but which costs little without one): a
|
|
59
|
+
* project with no integration records none of them.
|
|
54
60
|
*/
|
|
55
61
|
const INTEGRATION_COMMANDS = new Set([
|
|
56
62
|
'component',
|
|
@@ -67,6 +73,8 @@ const KEPT_COMMANDS = new Set([
|
|
|
67
73
|
'template',
|
|
68
74
|
'theme',
|
|
69
75
|
'discover',
|
|
76
|
+
// The project check alone (no subcommand): its docs checks are kept.
|
|
77
|
+
'doctor',
|
|
70
78
|
]);
|
|
71
79
|
|
|
72
80
|
/** Where `prepack` writes the id of the package's exact contents. */
|
|
@@ -91,13 +99,16 @@ const UNSET = null;
|
|
|
91
99
|
* their states, modules it loaded with theirs, and environment variables with
|
|
92
100
|
* their values. Files and folders are recorded for the whole run; modules and
|
|
93
101
|
* variables only while the run is armed: from its start to the end of its
|
|
94
|
-
* first gather, and during each later gather
|
|
95
|
-
*
|
|
102
|
+
* first gather, and during each later gather, or, in a run armed throughout
|
|
103
|
+
* (`doctor`), to its end. Null outside a recorded run.
|
|
104
|
+
* @type {{reads: Map<string, string>, env: Map<string, string | null>, arm: () => boolean, disarm: () => void, armedThroughout: boolean, realEnv: NodeJS.ProcessEnv} | null}
|
|
96
105
|
*/
|
|
97
106
|
let run = null;
|
|
98
107
|
|
|
99
108
|
/**
|
|
100
|
-
* The running recorded run's reads and variables,
|
|
109
|
+
* The running recorded run's reads and variables, or null outside one: for
|
|
110
|
+
* tests, and for a caller that keeps a value only in a recorded run (doctor's
|
|
111
|
+
* kept checks).
|
|
101
112
|
* @returns {{reads: Map<string, string>, env: Map<string, string | null>} | null}
|
|
102
113
|
*/
|
|
103
114
|
export function recordedRun() {
|
|
@@ -225,11 +236,14 @@ export async function recordRunFor(argv, fn) {
|
|
|
225
236
|
if (
|
|
226
237
|
!command ||
|
|
227
238
|
!KEPT_COMMANDS.has(command) ||
|
|
239
|
+
(command === 'doctor' &&
|
|
240
|
+
argv.filter(arg => !arg.startsWith('-')).length > 1) ||
|
|
228
241
|
runsUnderPnp() ||
|
|
229
242
|
currentUid() == null ||
|
|
230
243
|
withoutRecording(buildId) == null ||
|
|
231
|
-
// Last, being a few file checks: those commands keep
|
|
232
|
-
//
|
|
244
|
+
// Last, being a few file checks: those commands keep what is worth
|
|
245
|
+
// keeping only where an integration can load, so a project with none
|
|
246
|
+
// records nothing.
|
|
233
247
|
(INTEGRATION_COMMANDS.has(command) &&
|
|
234
248
|
!withoutRecording(() => mayHaveIntegrations(process.cwd())))
|
|
235
249
|
) {
|
|
@@ -240,6 +254,10 @@ export async function recordRunFor(argv, fn) {
|
|
|
240
254
|
// it, so a one-off run never pays to store one.
|
|
241
255
|
const dir = cacheDirPath();
|
|
242
256
|
if (!withoutRecording(() => fs.existsSync(dir))) {
|
|
257
|
+
// Once the per-user cache folder exists doctor uses it; it never makes
|
|
258
|
+
// it, so a doctor alone changes nothing on the machine (nor its own
|
|
259
|
+
// cache row).
|
|
260
|
+
if (command === 'doctor') return fn();
|
|
243
261
|
try {
|
|
244
262
|
withoutRecording(() => fs.mkdirSync(dir, {recursive: true, mode: 0o700}));
|
|
245
263
|
} catch {
|
|
@@ -250,7 +268,10 @@ export async function recordRunFor(argv, fn) {
|
|
|
250
268
|
// A folder the cache would refuse (not the user's own, open to others, a
|
|
251
269
|
// link) leaves the run exactly as without the cache: no hook is installed.
|
|
252
270
|
if (withoutRecording(gatherCacheDir) == null) return fn();
|
|
253
|
-
|
|
271
|
+
// doctor's kept checks read docs modules that load between its gathers, so
|
|
272
|
+
// its run records modules and variables to the end, not only during each
|
|
273
|
+
// gather.
|
|
274
|
+
return recordRun(fn, {armedThroughout: command === 'doctor'});
|
|
254
275
|
}
|
|
255
276
|
|
|
256
277
|
/**
|
|
@@ -258,9 +279,12 @@ export async function recordRunFor(argv, fn) {
|
|
|
258
279
|
* tests; `recordRunFor` decides which runs are recorded.
|
|
259
280
|
* @template T
|
|
260
281
|
* @param {() => Promise<T>} fn
|
|
282
|
+
* @param {{armedThroughout?: boolean}} [options] - `armedThroughout`: record
|
|
283
|
+
* modules and variables until the run ends, not only until each gather
|
|
284
|
+
* ends, for a run whose later gathers read modules loaded in between.
|
|
261
285
|
* @returns {Promise<T>}
|
|
262
286
|
*/
|
|
263
|
-
export async function recordRun(fn) {
|
|
287
|
+
export async function recordRun(fn, {armedThroughout = false} = {}) {
|
|
264
288
|
const registerHooks = /** @type {any} */ (nodeModule).registerHooks;
|
|
265
289
|
if (typeof registerHooks !== 'function' || run != null) return fn();
|
|
266
290
|
/** @type {Map<string, string>} */
|
|
@@ -276,17 +300,31 @@ export async function recordRun(fn) {
|
|
|
276
300
|
env.set(name, envState(realEnv[name]));
|
|
277
301
|
}
|
|
278
302
|
};
|
|
303
|
+
// Asking whether a variable is set, as `in` does and as `Object.keys` does
|
|
304
|
+
// for every name it lists, reads no value: only whether it is set counts.
|
|
305
|
+
// Every read of a value goes through `get` (spread, Object.entries,
|
|
306
|
+
// Object.assign, JSON.stringify included). Known gap: a descriptor's
|
|
307
|
+
// `value` (Object.getOwnPropertyDescriptor(s) on process.env) is a value
|
|
308
|
+
// read with no `get`, so it counts only as set. Nothing the CLI, Core, its
|
|
309
|
+
// dependencies, jiti's bundled babel or the integrations we test reads the
|
|
310
|
+
// environment that way.
|
|
311
|
+
/** @param {string | symbol} name */
|
|
312
|
+
const notePresence = name => {
|
|
313
|
+
if (typeof name === 'string' && !env.has(PRESENCE + name)) {
|
|
314
|
+
env.set(PRESENCE + name, presenceState(realEnv, name));
|
|
315
|
+
}
|
|
316
|
+
};
|
|
279
317
|
const proxy = new Proxy(realEnv, {
|
|
280
318
|
get(target, name) {
|
|
281
319
|
noteEnv(name);
|
|
282
320
|
return Reflect.get(target, name);
|
|
283
321
|
},
|
|
284
322
|
has(target, name) {
|
|
285
|
-
|
|
323
|
+
notePresence(name);
|
|
286
324
|
return Reflect.has(target, name);
|
|
287
325
|
},
|
|
288
326
|
getOwnPropertyDescriptor(target, name) {
|
|
289
|
-
|
|
327
|
+
notePresence(name);
|
|
290
328
|
return Reflect.getOwnPropertyDescriptor(target, name);
|
|
291
329
|
},
|
|
292
330
|
ownKeys(target) {
|
|
@@ -346,7 +384,7 @@ export async function recordRun(fn) {
|
|
|
346
384
|
}
|
|
347
385
|
};
|
|
348
386
|
if (!arm()) return fn();
|
|
349
|
-
run = {reads, env, arm, disarm};
|
|
387
|
+
run = {reads, env, arm, disarm, armedThroughout, realEnv};
|
|
350
388
|
try {
|
|
351
389
|
return await recordReads(reads, fn, {exact: true});
|
|
352
390
|
} finally {
|
|
@@ -407,6 +445,19 @@ function lookupStamp(folder) {
|
|
|
407
445
|
}
|
|
408
446
|
}
|
|
409
447
|
|
|
448
|
+
/** The stamp name prefix for whether a variable is set, not its value. */
|
|
449
|
+
const PRESENCE = '\0set:';
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Whether `name` is set in `env`, as stored.
|
|
453
|
+
* @param {NodeJS.ProcessEnv} env
|
|
454
|
+
* @param {string} name
|
|
455
|
+
* @returns {string | null}
|
|
456
|
+
*/
|
|
457
|
+
function presenceState(env, name) {
|
|
458
|
+
return typeof env[name] === 'string' ? 'set' : UNSET;
|
|
459
|
+
}
|
|
460
|
+
|
|
410
461
|
/**
|
|
411
462
|
* How an environment variable the run read is kept: a digest of its value,
|
|
412
463
|
* never the value (it can be a token), or UNSET when it was not set.
|
|
@@ -471,10 +522,13 @@ function entryKey(key, id) {
|
|
|
471
522
|
* @returns {string | null} why not, or null when all hold
|
|
472
523
|
*/
|
|
473
524
|
function staleReason(stamps, env) {
|
|
525
|
+
// The environment as it is, never through the run's recording proxy:
|
|
526
|
+
// checking an entry is no read the run's own gathers depend on.
|
|
527
|
+
const real = run?.realEnv ?? process.env;
|
|
474
528
|
for (const [name, value] of env) {
|
|
475
|
-
const current =
|
|
476
|
-
|
|
477
|
-
|
|
529
|
+
const current = name.startsWith(PRESENCE)
|
|
530
|
+
? presenceState(real, name.slice(PRESENCE.length))
|
|
531
|
+
: envState(name === '\0names' ? namesOf(real) : real[name]);
|
|
478
532
|
if (current !== value) {
|
|
479
533
|
return name === '\0names'
|
|
480
534
|
? 'the environment has other variables'
|
|
@@ -494,8 +548,9 @@ function staleReason(stamps, env) {
|
|
|
494
548
|
* @param {unknown[]} key - What else decides the gather: its folder (a real
|
|
495
549
|
* path) and options.
|
|
496
550
|
* @param {() => Promise<T>} load
|
|
497
|
-
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec - A
|
|
498
|
-
* plain-JSON form of the value and back
|
|
551
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T, valid?: (value: T) => boolean}} codec - A
|
|
552
|
+
* plain-JSON form of the value and back, and optionally the shape a decoded
|
|
553
|
+
* value must have to be used (anything else is a miss).
|
|
499
554
|
* @param {(value: T) => boolean} [keep] whether a fresh gather may be
|
|
500
555
|
* stored: one that depends on something its stamps cannot see (a retry
|
|
501
556
|
* that waits on time) is used for this run only
|
|
@@ -509,7 +564,7 @@ export async function persistedGather(key, load, codec, keep = () => true) {
|
|
|
509
564
|
try {
|
|
510
565
|
return await gatherAt(key, load, codec, keep);
|
|
511
566
|
} finally {
|
|
512
|
-
if (--gatherDepth === 0) run?.disarm();
|
|
567
|
+
if (--gatherDepth === 0 && !run?.armedThroughout) run?.disarm();
|
|
513
568
|
}
|
|
514
569
|
}
|
|
515
570
|
|
|
@@ -519,7 +574,7 @@ export async function persistedGather(key, load, codec, keep = () => true) {
|
|
|
519
574
|
* @template T, E
|
|
520
575
|
* @param {unknown[]} key
|
|
521
576
|
* @param {() => Promise<T>} load
|
|
522
|
-
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec
|
|
577
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T, valid?: (value: T) => boolean}} codec
|
|
523
578
|
* @param {(value: T) => boolean} keep
|
|
524
579
|
* @returns {Promise<T>}
|
|
525
580
|
*/
|
|
@@ -553,9 +608,20 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
553
608
|
reason = 'an entry for other inputs';
|
|
554
609
|
} else {
|
|
555
610
|
const stale = staleReason(stored.stamps, stored.env);
|
|
556
|
-
|
|
557
|
-
|
|
611
|
+
const value = stale == null ? readBack(stored, codec) : undefined;
|
|
612
|
+
if (stale == null && value === undefined) {
|
|
613
|
+
// Gathered again below, and stored over the bad entry.
|
|
614
|
+
reason = 'a malformed value';
|
|
615
|
+
} else if (stale == null) {
|
|
558
616
|
recordStates(stored.stamps);
|
|
617
|
+
// A gather around this one depends on what this one read, the
|
|
618
|
+
// environment included: a hit hands its variables on, as a fresh
|
|
619
|
+
// gather's reads would be.
|
|
620
|
+
if (run) {
|
|
621
|
+
for (const [name, value] of stored.env) {
|
|
622
|
+
if (!run.env.has(name)) run.env.set(name, value);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
559
625
|
gatherCode = cliStates(stored.stamps);
|
|
560
626
|
lastOutcome = {hit: true, reason: 'unchanged'};
|
|
561
627
|
try {
|
|
@@ -565,8 +631,9 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
565
631
|
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
566
632
|
}
|
|
567
633
|
return value;
|
|
634
|
+
} else {
|
|
635
|
+
reason = stale;
|
|
568
636
|
}
|
|
569
|
-
reason = stale;
|
|
570
637
|
}
|
|
571
638
|
} catch (error) {
|
|
572
639
|
if (/** @type {any} */ (error)?.code !== 'ENOENT')
|
|
@@ -624,7 +691,7 @@ function codeStamp(code, inputs) {
|
|
|
624
691
|
* @template T, E
|
|
625
692
|
* @param {unknown[]} key - Everything the value is computed from.
|
|
626
693
|
* @param {() => T} compute
|
|
627
|
-
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec
|
|
694
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T, valid?: (value: T) => boolean}} codec
|
|
628
695
|
* @param {string[]} [inputs] - Files the computation reads, by path.
|
|
629
696
|
* @returns {T}
|
|
630
697
|
*/
|
|
@@ -640,12 +707,13 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
640
707
|
const stored = JSON.parse(
|
|
641
708
|
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
642
709
|
);
|
|
643
|
-
|
|
710
|
+
const value =
|
|
644
711
|
stored?.format === FORMAT &&
|
|
645
712
|
stored.derived === true &&
|
|
646
713
|
stored.key === entry
|
|
647
|
-
|
|
648
|
-
|
|
714
|
+
? readBack(stored, codec)
|
|
715
|
+
: undefined;
|
|
716
|
+
if (value !== undefined) {
|
|
649
717
|
try {
|
|
650
718
|
const now = new Date();
|
|
651
719
|
withoutRecording(() => fs.utimesSync(file, now, now));
|
|
@@ -679,6 +747,25 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
679
747
|
return value;
|
|
680
748
|
}
|
|
681
749
|
|
|
750
|
+
/**
|
|
751
|
+
* A stored entry's value, decoded, or undefined when it has none, its decode
|
|
752
|
+
* throws, or the decoded value fails the codec's shape check (`valid`): such
|
|
753
|
+
* an entry is a miss, worked out again and stored over.
|
|
754
|
+
* @param {any} stored
|
|
755
|
+
* @param {{decode: (stored: any) => any, valid?: (value: any) => boolean}} codec
|
|
756
|
+
* @returns {any}
|
|
757
|
+
*/
|
|
758
|
+
function readBack(stored, codec) {
|
|
759
|
+
if (!Object.hasOwn(stored, 'value') || stored.value == null) return undefined;
|
|
760
|
+
try {
|
|
761
|
+
const value = codec.decode(stored.value);
|
|
762
|
+
if (value == null) return undefined;
|
|
763
|
+
return !codec.valid || codec.valid(value) ? value : undefined;
|
|
764
|
+
} catch {
|
|
765
|
+
return undefined;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
682
769
|
/**
|
|
683
770
|
* Store a fresh gather with what the run read, unless its plain form does not
|
|
684
771
|
* read back as the same value. Silent on any failure.
|
|
@@ -687,7 +774,7 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
687
774
|
* @param {string} file
|
|
688
775
|
* @param {string} entry - The entry's key (entryKey).
|
|
689
776
|
* @param {T} value
|
|
690
|
-
* @param {{encode: (value: T) => E, decode: (stored: E) => T}} codec
|
|
777
|
+
* @param {{encode: (value: T) => E, decode: (stored: E) => T, valid?: (value: T) => boolean}} codec
|
|
691
778
|
*/
|
|
692
779
|
function store(dir, file, entry, value, codec) {
|
|
693
780
|
if (!run) return;
|
|
@@ -761,6 +848,12 @@ export function runsUnderPnp() {
|
|
|
761
848
|
* `pnp`: whether this run is under Yarn Plug'n'Play's loader (runsUnderPnp)
|
|
762
849
|
*/
|
|
763
850
|
export function gatherCacheSummary() {
|
|
851
|
+
// The cache's own bookkeeping, never an input of what it keeps.
|
|
852
|
+
return withoutRecording(summarize);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean} | null} */
|
|
856
|
+
function summarize() {
|
|
764
857
|
if (buildId() == null) return null;
|
|
765
858
|
const dir = gatherCacheDir();
|
|
766
859
|
if (dir == null) return null;
|
|
@@ -60,6 +60,20 @@ export function findCarriedCoreDir(startDir: string, { fetch }?: {
|
|
|
60
60
|
* @returns {string | null}
|
|
61
61
|
*/
|
|
62
62
|
export function findProjectCoreDir(startDir?: string): string | null;
|
|
63
|
+
/**
|
|
64
|
+
* `p` resolved through symlinks when it exists, so folders compare equal
|
|
65
|
+
* however they were reached.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} p
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function realDir(p: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* The home folder, resolved through symlinks, or null when there is none.
|
|
73
|
+
*
|
|
74
|
+
* @returns {string|null}
|
|
75
|
+
*/
|
|
76
|
+
export function homeFolder(): string | null;
|
|
63
77
|
/**
|
|
64
78
|
* The project root: the directory of the nearest package.json at or above
|
|
65
79
|
* `startDir`, or null when there is none.
|
|
@@ -68,6 +82,22 @@ export function findProjectCoreDir(startDir?: string): string | null;
|
|
|
68
82
|
* @returns {string|null}
|
|
69
83
|
*/
|
|
70
84
|
export function findPackageRoot(startDir: string): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* A path a command writes in a project, read the same way by every theme
|
|
87
|
+
* command: from the working folder when given, from the project root (the
|
|
88
|
+
* nearest folder with a package.json, else the working folder) when not,
|
|
89
|
+
* and with a backslash as a folder separator on every platform.
|
|
90
|
+
* @param {string} cwd
|
|
91
|
+
* @param {string | undefined} typed the path as given, or undefined
|
|
92
|
+
* @param {string} fallback the path from the project root when none is given
|
|
93
|
+
* @returns {{projectDir: string, typed: string | undefined, relative: string}}
|
|
94
|
+
* `typed`: the path as given with `/`; `relative`: from the project root
|
|
95
|
+
*/
|
|
96
|
+
export function projectWritePath(cwd: string, typed: string | undefined, fallback: string): {
|
|
97
|
+
projectDir: string;
|
|
98
|
+
typed: string | undefined;
|
|
99
|
+
relative: string;
|
|
100
|
+
};
|
|
71
101
|
/**
|
|
72
102
|
* The Astryx project `startDir` belongs to: the nearest folder at or above it
|
|
73
103
|
* whose package.json declares an Astryx package (`@astryxdesign/*`, or the
|
|
@@ -89,6 +119,15 @@ export function findAstryxProject(startDir: string): string | null;
|
|
|
89
119
|
* @returns {string}
|
|
90
120
|
*/
|
|
91
121
|
export function findWorkspaceRoot(startDir: string): string;
|
|
122
|
+
/**
|
|
123
|
+
* The nearest directory at or above `startDir` that declares a workspace,
|
|
124
|
+
* by a `pnpm-workspace.yaml` or a package.json `workspaces` field; null
|
|
125
|
+
* outside a workspace.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} startDir
|
|
128
|
+
* @returns {string|null}
|
|
129
|
+
*/
|
|
130
|
+
export function findDeclaredWorkspaceRoot(startDir: string): string | null;
|
|
92
131
|
/**
|
|
93
132
|
* The nearest `node_modules/<name>` at or above `startDir`, found the way
|
|
94
133
|
* Node's resolver finds a package, and the folder whose node_modules holds it.
|