@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
|
@@ -24,7 +24,6 @@ import {AsyncLocalStorage} from 'node:async_hooks';
|
|
|
24
24
|
import {createRequire} from 'node:module';
|
|
25
25
|
import {pathToFileURL} from 'node:url';
|
|
26
26
|
import * as fs from 'node:fs';
|
|
27
|
-
import {createJiti} from 'jiti';
|
|
28
27
|
import {findPresentFiles} from './present-files.mjs';
|
|
29
28
|
import {importUrl} from './import-url.mjs';
|
|
30
29
|
|
|
@@ -34,6 +33,13 @@ export {findPresentFiles};
|
|
|
34
33
|
let jitiInstance;
|
|
35
34
|
let freshImportNonce = 0;
|
|
36
35
|
const requireFromHere = createRequire(import.meta.url);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* jiti, loaded on first use: only TypeScript files and built theme modules
|
|
39
|
+
* need it, so a run that reads neither never loads it.
|
|
40
|
+
* @type {typeof import('jiti').createJiti}
|
|
41
|
+
*/
|
|
42
|
+
const createJiti = (...args) => requireFromHere('jiti').createJiti(...args);
|
|
37
43
|
function getJiti() {
|
|
38
44
|
if (!jitiInstance) {
|
|
39
45
|
jitiInstance = createJiti(import.meta.url);
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
* @returns {string}
|
|
10
10
|
*/
|
|
11
11
|
export function fileStamp(file: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a recorded path is still in the state recorded for it, by the kind
|
|
14
|
+
* of state that was recorded.
|
|
15
|
+
* @param {string} file
|
|
16
|
+
* @param {string} state
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
export function stillInState(file: string, state: string): boolean;
|
|
12
20
|
/**
|
|
13
21
|
* Whether every recorded path is still in the state it had when it was read.
|
|
14
22
|
* @param {Map<string, string>} recorded - From recordReads.
|
|
@@ -22,15 +30,37 @@ export function unchangedSince(recorded: Map<string, string>): boolean;
|
|
|
22
30
|
* @param {string} file
|
|
23
31
|
*/
|
|
24
32
|
export function recordContentRead(file: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Run `fn` with nothing it reads recorded: a cache's own bookkeeping, which
|
|
35
|
+
* is not an input of what it keeps.
|
|
36
|
+
* @template T
|
|
37
|
+
* @param {() => T} fn
|
|
38
|
+
* @returns {T}
|
|
39
|
+
*/
|
|
40
|
+
export function withoutRecording<T>(fn: () => T): T;
|
|
41
|
+
/**
|
|
42
|
+
* Count paths as read by the running operations, each with the state given:
|
|
43
|
+
* what a value kept from an earlier read read. Outside `recordReads` it does
|
|
44
|
+
* nothing.
|
|
45
|
+
* @param {Iterable<[string, string]>} states
|
|
46
|
+
*/
|
|
47
|
+
export function recordStates(states: Iterable<[string, string]>): void;
|
|
25
48
|
/**
|
|
26
49
|
* Run `fn`, adding to `seen` each path it reads, with that path's state when
|
|
27
50
|
* it was first read (see the file header).
|
|
28
51
|
* @template T
|
|
29
52
|
* @param {Map<string, string>} seen
|
|
30
53
|
* @param {() => T} fn
|
|
54
|
+
* @param {{exact?: boolean}} [options] - `exact`: record a probe (an
|
|
55
|
+
* existence check, a stat, a real path) by the path probed, with its state,
|
|
56
|
+
* instead of by its folder; a listing and a content read are recorded as
|
|
57
|
+
* ever. A folder's time changes whenever any entry in it is added or
|
|
58
|
+
* renamed, so a record kept between runs stays valid longer this way.
|
|
31
59
|
* @returns {T}
|
|
32
60
|
*/
|
|
33
|
-
export function recordReads<T>(seen: Map<string, string>, fn: () => T
|
|
61
|
+
export function recordReads<T>(seen: Map<string, string>, fn: () => T, { exact }?: {
|
|
62
|
+
exact?: boolean;
|
|
63
|
+
}): T;
|
|
34
64
|
/**
|
|
35
65
|
* A loader whose value is kept while every file and folder it read is
|
|
36
66
|
* unchanged, and loaded again after a change, so a long-running process sees
|
|
@@ -34,15 +34,41 @@ const reads = new AsyncLocalStorage();
|
|
|
34
34
|
* Add `file` to every running operation's map, with its state now, unless it
|
|
35
35
|
* is there already.
|
|
36
36
|
* @param {Map<string, string>[]} runs
|
|
37
|
-
* @param {string} file
|
|
37
|
+
* @param {string} file - What a run checks: the file read, or the folder of
|
|
38
|
+
* the path probed.
|
|
39
|
+
* @param {string} [probed] - The path itself, which an exact run checks.
|
|
38
40
|
*/
|
|
39
|
-
function note(runs, file) {
|
|
41
|
+
function note(runs, file, probed = file) {
|
|
40
42
|
let state;
|
|
43
|
+
let probedState;
|
|
41
44
|
for (const seen of runs) {
|
|
42
|
-
if (
|
|
45
|
+
if (exactRuns.has(seen)) {
|
|
46
|
+
const had = seen.get(probed);
|
|
47
|
+
if (had === undefined) {
|
|
48
|
+
seen.set(
|
|
49
|
+
probed,
|
|
50
|
+
(probedState ??=
|
|
51
|
+
probed === file ? stateOf(probed) : probeStamp(probed)),
|
|
52
|
+
);
|
|
53
|
+
} else if (probed === file && had.startsWith('dir:')) {
|
|
54
|
+
// A folder first only probed, now listed: its listing counts, so it
|
|
55
|
+
// is checked by its full stamp from here on.
|
|
56
|
+
seen.set(probed, (state ??= stateOf(file)));
|
|
57
|
+
}
|
|
58
|
+
} else if (!seen.has(file)) {
|
|
59
|
+
seen.set(file, (state ??= stateOf(file)));
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
62
|
}
|
|
45
63
|
|
|
64
|
+
/**
|
|
65
|
+
* The runs that record a probe by the path probed, not by its folder: a
|
|
66
|
+
* record kept across processes, whose folders change for reasons that do not
|
|
67
|
+
* touch the path (see `recordReads`).
|
|
68
|
+
* @type {WeakSet<Map<string, string>>}
|
|
69
|
+
*/
|
|
70
|
+
const exactRuns = new WeakSet();
|
|
71
|
+
|
|
46
72
|
/** node:fs's module object, whose functions every import of it shares. */
|
|
47
73
|
const fs = createRequire(import.meta.url)('node:fs');
|
|
48
74
|
|
|
@@ -98,7 +124,7 @@ function installRecorder() {
|
|
|
98
124
|
: path.dirname(file);
|
|
99
125
|
// Its state is taken when it is first read, before the read, so a
|
|
100
126
|
// change made while the operation runs shows as a change afterwards.
|
|
101
|
-
note(runs, checked);
|
|
127
|
+
note(runs, checked, file);
|
|
102
128
|
}
|
|
103
129
|
return original.apply(this, args);
|
|
104
130
|
};
|
|
@@ -127,6 +153,36 @@ export function fileStamp(file) {
|
|
|
127
153
|
|
|
128
154
|
const stateOf = fileStamp;
|
|
129
155
|
|
|
156
|
+
/**
|
|
157
|
+
* A probed path's state for an exact run: a folder's identity alone (a probe
|
|
158
|
+
* reads whether it is there and what it is, not what it holds, and its time
|
|
159
|
+
* changes whenever an entry in it changes), a file's full stamp, or absent.
|
|
160
|
+
* @param {string} file
|
|
161
|
+
* @returns {string}
|
|
162
|
+
*/
|
|
163
|
+
function probeStamp(file) {
|
|
164
|
+
try {
|
|
165
|
+
const stat = statSyncRaw(file);
|
|
166
|
+
if (stat.isDirectory()) return `dir:${stat.ino}`;
|
|
167
|
+
return `${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}:${stat.ino}`;
|
|
168
|
+
} catch {
|
|
169
|
+
return '-';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Whether a recorded path is still in the state recorded for it, by the kind
|
|
175
|
+
* of state that was recorded.
|
|
176
|
+
* @param {string} file
|
|
177
|
+
* @param {string} state
|
|
178
|
+
* @returns {boolean}
|
|
179
|
+
*/
|
|
180
|
+
export function stillInState(file, state) {
|
|
181
|
+
return (
|
|
182
|
+
(state.startsWith('dir:') ? probeStamp(file) : stateOf(file)) === state
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
130
186
|
/**
|
|
131
187
|
* Whether every recorded path is still in the state it had when it was read.
|
|
132
188
|
* @param {Map<string, string>} recorded - From recordReads.
|
|
@@ -134,7 +190,7 @@ const stateOf = fileStamp;
|
|
|
134
190
|
*/
|
|
135
191
|
export function unchangedSince(recorded) {
|
|
136
192
|
for (const [file, state] of recorded) {
|
|
137
|
-
if (
|
|
193
|
+
if (!stillInState(file, state)) return false;
|
|
138
194
|
}
|
|
139
195
|
return true;
|
|
140
196
|
}
|
|
@@ -150,16 +206,47 @@ export function recordContentRead(file) {
|
|
|
150
206
|
if (runs) note(runs, path.resolve(file));
|
|
151
207
|
}
|
|
152
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Run `fn` with nothing it reads recorded: a cache's own bookkeeping, which
|
|
211
|
+
* is not an input of what it keeps.
|
|
212
|
+
* @template T
|
|
213
|
+
* @param {() => T} fn
|
|
214
|
+
* @returns {T}
|
|
215
|
+
*/
|
|
216
|
+
export function withoutRecording(fn) {
|
|
217
|
+
return reads.exit(fn);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Count paths as read by the running operations, each with the state given:
|
|
222
|
+
* what a value kept from an earlier read read. Outside `recordReads` it does
|
|
223
|
+
* nothing.
|
|
224
|
+
* @param {Iterable<[string, string]>} states
|
|
225
|
+
*/
|
|
226
|
+
export function recordStates(states) {
|
|
227
|
+
const runs = reads.getStore();
|
|
228
|
+
if (!runs) return;
|
|
229
|
+
for (const [file, state] of states) {
|
|
230
|
+
for (const seen of runs) if (!seen.has(file)) seen.set(file, state);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
153
234
|
/**
|
|
154
235
|
* Run `fn`, adding to `seen` each path it reads, with that path's state when
|
|
155
236
|
* it was first read (see the file header).
|
|
156
237
|
* @template T
|
|
157
238
|
* @param {Map<string, string>} seen
|
|
158
239
|
* @param {() => T} fn
|
|
240
|
+
* @param {{exact?: boolean}} [options] - `exact`: record a probe (an
|
|
241
|
+
* existence check, a stat, a real path) by the path probed, with its state,
|
|
242
|
+
* instead of by its folder; a listing and a content read are recorded as
|
|
243
|
+
* ever. A folder's time changes whenever any entry in it is added or
|
|
244
|
+
* renamed, so a record kept between runs stays valid longer this way.
|
|
159
245
|
* @returns {T}
|
|
160
246
|
*/
|
|
161
|
-
export function recordReads(seen, fn) {
|
|
247
|
+
export function recordReads(seen, fn, {exact = false} = {}) {
|
|
162
248
|
installRecorder();
|
|
249
|
+
if (exact) exactRuns.add(seen);
|
|
163
250
|
return reads.run([...(reads.getStore() ?? []), seen], fn);
|
|
164
251
|
}
|
|
165
252
|
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
import * as fs from 'node:fs';
|
|
25
25
|
import * as path from 'node:path';
|
|
26
26
|
import {spawnSync} from 'node:child_process';
|
|
27
|
-
import {builtinModules} from 'node:module';
|
|
28
|
-
import {parse as parseModule} from '@babel/parser';
|
|
27
|
+
import {builtinModules, createRequire} from 'node:module';
|
|
29
28
|
import {isValidSemver} from '../env/semver.mjs';
|
|
30
29
|
import {findProjectCoreDir} from '../fs/paths.mjs';
|
|
31
30
|
import {KNOWN_INTEGRATION_KEYS} from '../../authoring/integration/schema.mjs';
|
|
@@ -64,6 +63,18 @@ import {
|
|
|
64
63
|
import {discoverIntegrationDocs} from '../discovery/docs-discovery.mjs';
|
|
65
64
|
import {discoverIntegrationThemes} from '../discovery/theme-discovery.mjs';
|
|
66
65
|
|
|
66
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* `@babel/parser`'s parse, loaded on first use: most commands that load the
|
|
70
|
+
* project's integrations never validate a contribution's source.
|
|
71
|
+
* @param {string} source
|
|
72
|
+
* @param {import('@babel/parser').ParserOptions} [options]
|
|
73
|
+
*/
|
|
74
|
+
function parseModule(source, options) {
|
|
75
|
+
return requireFromHere('@babel/parser').parse(source, options);
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
/**
|
|
68
79
|
* @typedef {import('./issue').AstryxIntegrationIssue} Issue
|
|
69
80
|
* @typedef {import('./integrations.mjs').LoadedIntegration} LoadedIntegration
|
|
@@ -1647,15 +1658,17 @@ export async function componentExamplesCheck(integration) {
|
|
|
1647
1658
|
: negated != null && !outsideFiles(assetRel, packedFiles)
|
|
1648
1659
|
? `${rel(template.filePath)}: loads ${assetRel}, which the \`files\` entry "${negated}" leaves out of the package, so the template breaks once installed. Fix: drop or narrow "${negated}" so it no longer matches ${assetRel}, and confirm with \`npm pack --dry-run\`.`
|
|
1649
1660
|
: Array.isArray(packedFiles) &&
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1661
|
+
(outsideFiles(assetRel, packedFiles) ||
|
|
1662
|
+
!ignoreFilesFor(base, assetRel).some(file =>
|
|
1663
|
+
file.includes('/'),
|
|
1664
|
+
))
|
|
1665
|
+
? `${rel(template.filePath)}: loads ${assetRel}, which npm leaves out of the package by its \`files\` field, so the template breaks once installed. Fix: add "${folder}" to \`files\`, drop any \`!\` entry that excludes it, and confirm with \`npm pack --dry-run\`.`
|
|
1666
|
+
: ignoreFix(
|
|
1667
|
+
base,
|
|
1668
|
+
rel(template.filePath),
|
|
1669
|
+
assetRel,
|
|
1670
|
+
Array.isArray(packedFiles),
|
|
1671
|
+
),
|
|
1659
1672
|
});
|
|
1660
1673
|
}
|
|
1661
1674
|
}
|
|
@@ -185,6 +185,12 @@ export function recentFailedInstall(version: string, cacheDir: string, now?: num
|
|
|
185
185
|
failures: number;
|
|
186
186
|
waitMs: number;
|
|
187
187
|
} | null;
|
|
188
|
+
/**
|
|
189
|
+
* Is process `pid` on this computer still running?
|
|
190
|
+
* @param {number} pid
|
|
191
|
+
* @returns {boolean}
|
|
192
|
+
*/
|
|
193
|
+
export function isAlive(pid: number): boolean;
|
|
188
194
|
/**
|
|
189
195
|
* Take a lock folder, or return false when another live run holds it. A lock
|
|
190
196
|
* whose holder has gone, such as a run stopped with Ctrl-C or killed, is taken
|
|
@@ -224,17 +230,20 @@ export function isReleaseInstall(argv: string[], version: string, { node }?: {
|
|
|
224
230
|
* since a recorded process id can name an unrelated process once the install
|
|
225
231
|
* ended.
|
|
226
232
|
* @param {string} lockDir a `.lock-<version>` folder
|
|
227
|
-
* @param {{now?: number, procRoot?: string, factsOf?: (pid: number) => {argv: string[] | null, startedAt: number | null}}} [options]
|
|
233
|
+
* @param {{now?: number, procRoot?: string, factsOf?: (pid: number) => {argv: string[] | null, startedAt: number | null}, version?: string}} [options]
|
|
234
|
+
* `version` names the release when the folder's name does not (a lock
|
|
235
|
+
* moved aside).
|
|
228
236
|
* the clock, the process table's folder, and the fact reader, for tests
|
|
229
237
|
* @returns {'ended' | 'left'} whether a process group was ended
|
|
230
238
|
*/
|
|
231
|
-
export function endRecordedInstall(lockDir: string, { now, procRoot, factsOf }?: {
|
|
239
|
+
export function endRecordedInstall(lockDir: string, { now, procRoot, factsOf, version: named }?: {
|
|
232
240
|
now?: number;
|
|
233
241
|
procRoot?: string;
|
|
234
242
|
factsOf?: (pid: number) => {
|
|
235
243
|
argv: string[] | null;
|
|
236
244
|
startedAt: number | null;
|
|
237
245
|
};
|
|
246
|
+
version?: string;
|
|
238
247
|
}): "ended" | "left";
|
|
239
248
|
/**
|
|
240
249
|
* Why a release could not be made available.
|
|
@@ -654,7 +654,7 @@ const UNOWNED_LOCK_MS = 10_000;
|
|
|
654
654
|
* @param {number} pid
|
|
655
655
|
* @returns {boolean}
|
|
656
656
|
*/
|
|
657
|
-
function isAlive(pid) {
|
|
657
|
+
export function isAlive(pid) {
|
|
658
658
|
try {
|
|
659
659
|
process.kill(pid, 0);
|
|
660
660
|
return true;
|
|
@@ -691,6 +691,18 @@ function lockIsStale(lockDir, now) {
|
|
|
691
691
|
return !isAlive(owner.pid);
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
+
/**
|
|
695
|
+
* The text of a lock's owner record, or '' when it has none.
|
|
696
|
+
* @param {string} lockDir
|
|
697
|
+
*/
|
|
698
|
+
function ownerText(lockDir) {
|
|
699
|
+
try {
|
|
700
|
+
return fs.readFileSync(path.join(lockDir, 'owner.json'), 'utf-8');
|
|
701
|
+
} catch {
|
|
702
|
+
return '';
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
694
706
|
/**
|
|
695
707
|
* Take a lock folder, or return false when another live run holds it. A lock
|
|
696
708
|
* whose holder has gone, such as a run stopped with Ctrl-C or killed, is taken
|
|
@@ -708,10 +720,12 @@ export function tryLock(lockDir, {now = Date.now()} = {}) {
|
|
|
708
720
|
if (/** @type {NodeJS.ErrnoException} */ (error).code !== 'EEXIST') {
|
|
709
721
|
throw error;
|
|
710
722
|
}
|
|
711
|
-
|
|
712
|
-
//
|
|
713
|
-
//
|
|
714
|
-
|
|
723
|
+
// The lock judged stale, read before the judgement: the folder moved
|
|
724
|
+
// aside must be that same folder (by its identity on disk, not only its
|
|
725
|
+
// record, which a new lock lacks for a moment), or another run took the
|
|
726
|
+
// lock in between.
|
|
727
|
+
const judged = lockIdentity(lockDir);
|
|
728
|
+
if (!judged || !lockIsStale(lockDir, now)) return false;
|
|
715
729
|
const aside = `${lockDir}.stale-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
|
|
716
730
|
try {
|
|
717
731
|
fs.renameSync(lockDir, aside);
|
|
@@ -719,6 +733,24 @@ export function tryLock(lockDir, {now = Date.now()} = {}) {
|
|
|
719
733
|
// Another run took it over first.
|
|
720
734
|
return false;
|
|
721
735
|
}
|
|
736
|
+
if (lockIdentity(aside) !== judged) {
|
|
737
|
+
// A live lock taken after the judgement: put it back, and wait. When
|
|
738
|
+
// its place is taken again, it stays aside for its run: this run
|
|
739
|
+
// holds nothing and removes nothing.
|
|
740
|
+
try {
|
|
741
|
+
fs.renameSync(aside, lockDir);
|
|
742
|
+
} catch {
|
|
743
|
+
// Left for its run.
|
|
744
|
+
}
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
// The run that held it is gone; end the install it left running, if
|
|
748
|
+
// any, before starting another. The moved folder's name holds no
|
|
749
|
+
// version, so it is passed.
|
|
750
|
+
endRecordedInstall(aside, {
|
|
751
|
+
now,
|
|
752
|
+
version: /^\.lock-(.+)$/u.exec(path.basename(lockDir))?.[1],
|
|
753
|
+
});
|
|
722
754
|
fs.rmSync(aside, {recursive: true, force: true});
|
|
723
755
|
try {
|
|
724
756
|
fs.mkdirSync(lockDir);
|
|
@@ -737,6 +769,22 @@ export function tryLock(lockDir, {now = Date.now()} = {}) {
|
|
|
737
769
|
return true;
|
|
738
770
|
}
|
|
739
771
|
|
|
772
|
+
/**
|
|
773
|
+
* Which lock folder this is: its device, inode and creation time, and its
|
|
774
|
+
* owner record. A rename keeps them all; a lock made again in its place
|
|
775
|
+
* differs, even before it has a record. Null when there is no folder.
|
|
776
|
+
* @param {string} lockDir
|
|
777
|
+
* @returns {string | null}
|
|
778
|
+
*/
|
|
779
|
+
function lockIdentity(lockDir) {
|
|
780
|
+
try {
|
|
781
|
+
const st = fs.statSync(lockDir, {bigint: true});
|
|
782
|
+
return `${st.dev}:${st.ino}:${st.birthtimeNs}:${ownerText(lockDir)}`;
|
|
783
|
+
} catch {
|
|
784
|
+
return null;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
740
788
|
/**
|
|
741
789
|
* What the system says about the process `pid`: its arguments (exact from
|
|
742
790
|
* `/proc`; split on spaces from `ps` or PowerShell, so a path with a space in
|
|
@@ -866,13 +914,15 @@ export function isReleaseInstall(
|
|
|
866
914
|
* since a recorded process id can name an unrelated process once the install
|
|
867
915
|
* ended.
|
|
868
916
|
* @param {string} lockDir a `.lock-<version>` folder
|
|
869
|
-
* @param {{now?: number, procRoot?: string, factsOf?: (pid: number) => {argv: string[] | null, startedAt: number | null}}} [options]
|
|
917
|
+
* @param {{now?: number, procRoot?: string, factsOf?: (pid: number) => {argv: string[] | null, startedAt: number | null}, version?: string}} [options]
|
|
918
|
+
* `version` names the release when the folder's name does not (a lock
|
|
919
|
+
* moved aside).
|
|
870
920
|
* the clock, the process table's folder, and the fact reader, for tests
|
|
871
921
|
* @returns {'ended' | 'left'} whether a process group was ended
|
|
872
922
|
*/
|
|
873
923
|
export function endRecordedInstall(
|
|
874
924
|
lockDir,
|
|
875
|
-
{now = Date.now(), procRoot = '/proc', factsOf} = {},
|
|
925
|
+
{now = Date.now(), procRoot = '/proc', factsOf, version: named} = {},
|
|
876
926
|
) {
|
|
877
927
|
let pid;
|
|
878
928
|
try {
|
|
@@ -881,7 +931,7 @@ export function endRecordedInstall(
|
|
|
881
931
|
return 'left';
|
|
882
932
|
}
|
|
883
933
|
if (!Number.isInteger(pid) || pid <= 1 || !isAlive(pid)) return 'left';
|
|
884
|
-
const version = /^\.lock-(.+)$/u.exec(path.basename(lockDir))?.[1];
|
|
934
|
+
const version = named ?? /^\.lock-(.+)$/u.exec(path.basename(lockDir))?.[1];
|
|
885
935
|
if (!version) return 'left';
|
|
886
936
|
const owner = readJson(path.join(lockDir, 'owner.json'));
|
|
887
937
|
const at = typeof owner?.at === 'number' ? owner.at : null;
|
|
@@ -1055,8 +1105,7 @@ function ensureLocked(
|
|
|
1055
1105
|
for (const entry of safeList(root)) {
|
|
1056
1106
|
if (
|
|
1057
1107
|
entry.startsWith(`.tmp-${version}-`) ||
|
|
1058
|
-
entry.startsWith(`${version}.removing-`)
|
|
1059
|
-
entry.startsWith(`.lock-${version}.stale-`)
|
|
1108
|
+
entry.startsWith(`${version}.removing-`)
|
|
1060
1109
|
) {
|
|
1061
1110
|
fs.rmSync(path.join(root, entry), {recursive: true, force: true});
|
|
1062
1111
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
* Run `fn` holding the lock folder `lockDir`. A run waits while another
|
|
6
|
+
* holds it; the wait starts again each time the lock changes hands, and
|
|
7
|
+
* `onBusy` is called (it throws) when one holder keeps it longer than
|
|
8
|
+
* `waitMs`. The lock is renewed while `fn` runs.
|
|
9
|
+
* @template T
|
|
10
|
+
* @param {string} lockDir
|
|
11
|
+
* @param {() => Promise<T>} fn
|
|
12
|
+
* @param {{waitMs?: number, onBusy: (owner: any, heldSeconds: number | null) => never}} options
|
|
13
|
+
* @returns {Promise<T>}
|
|
14
|
+
*/
|
|
15
|
+
export function withFolderLock<T>(lockDir: string, fn: () => Promise<T>, { waitMs, onBusy }: {
|
|
16
|
+
waitMs?: number;
|
|
17
|
+
onBusy: (owner: any, heldSeconds: number | null) => never;
|
|
18
|
+
}): Promise<T>;
|
|
19
|
+
/** How long a held lock's record may stand unrenewed before it is taken over. */
|
|
20
|
+
export const SILENT_MS: number;
|
|
21
|
+
export function holdsFolderLock(lockDir: string): boolean;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file A folder lock for a command that may take a while: the release
|
|
5
|
+
* cache's lock (cache.mjs `tryLock`), held with its lease (lock-lease.mjs
|
|
6
|
+
* `renewLock`) for as long as the command runs, so a run on another computer
|
|
7
|
+
* or container never takes it over while it is held.
|
|
8
|
+
*
|
|
9
|
+
* @input a lock folder and the work to run under it
|
|
10
|
+
* @output the work's result; the lock is released on the way out, also on
|
|
11
|
+
* Ctrl-C, and only when it is still this run's own
|
|
12
|
+
* @position foundation/release — used by the theme editor (api/theme-edit/_adapter.mjs).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import * as fs from 'node:fs';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
import {tryLock} from './cache.mjs';
|
|
18
|
+
import {LEASE_RENEW_MS, renewLock} from './lock-lease.mjs';
|
|
19
|
+
|
|
20
|
+
/** How long a held lock's record may stand unrenewed before it is taken over. */
|
|
21
|
+
export const SILENT_MS = 3 * LEASE_RENEW_MS;
|
|
22
|
+
|
|
23
|
+
/** @param {string} file @returns {string} */
|
|
24
|
+
const recordText = file => {
|
|
25
|
+
try {
|
|
26
|
+
return fs.readFileSync(file, 'utf8');
|
|
27
|
+
} catch {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Move a silent lock aside and remove it; another run that moved it first
|
|
34
|
+
* wins, and this one tries again.
|
|
35
|
+
* @param {string} lockDir
|
|
36
|
+
* @param {string} judged the record seen silent
|
|
37
|
+
*/
|
|
38
|
+
function takeOver(lockDir, judged) {
|
|
39
|
+
const aside = `${lockDir}.silent-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
|
|
40
|
+
try {
|
|
41
|
+
fs.renameSync(lockDir, aside);
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// The lock moved aside must hold the record judged silent: a lock taken
|
|
46
|
+
// or renewed in between is put back.
|
|
47
|
+
if (recordText(path.join(aside, 'owner.json')) !== judged) {
|
|
48
|
+
try {
|
|
49
|
+
fs.renameSync(aside, lockDir);
|
|
50
|
+
} catch {
|
|
51
|
+
// Its place is taken again.
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
fs.rmSync(aside, {recursive: true, force: true});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The lock folders this process holds now. */
|
|
59
|
+
const HELD = new Set();
|
|
60
|
+
|
|
61
|
+
/** @param {number} ms */
|
|
62
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
63
|
+
|
|
64
|
+
/** @param {string} file @returns {any} */
|
|
65
|
+
const readOwner = file => {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Run `fn` holding the lock folder `lockDir`. A run waits while another
|
|
75
|
+
* holds it; the wait starts again each time the lock changes hands, and
|
|
76
|
+
* `onBusy` is called (it throws) when one holder keeps it longer than
|
|
77
|
+
* `waitMs`. The lock is renewed while `fn` runs.
|
|
78
|
+
* @template T
|
|
79
|
+
* @param {string} lockDir
|
|
80
|
+
* @param {() => Promise<T>} fn
|
|
81
|
+
* @param {{waitMs?: number, onBusy: (owner: any, heldSeconds: number | null) => never}} options
|
|
82
|
+
* @returns {Promise<T>}
|
|
83
|
+
*/
|
|
84
|
+
export async function withFolderLock(lockDir, fn, {waitMs = 30_000, onBusy}) {
|
|
85
|
+
const ownerFile = path.join(lockDir, 'owner.json');
|
|
86
|
+
/** @returns {number | null} seconds since the holder took the lock */
|
|
87
|
+
const held = () => {
|
|
88
|
+
const at = readOwner(ownerFile)?.at;
|
|
89
|
+
return typeof at === 'number'
|
|
90
|
+
? Math.max(0, Math.round((Date.now() - at) / 1000))
|
|
91
|
+
: null;
|
|
92
|
+
};
|
|
93
|
+
// A holder is its process, computer and the moment it took the lock: a
|
|
94
|
+
// new holder with the same process id (another container) is a new one.
|
|
95
|
+
const holderOf = () => {
|
|
96
|
+
const o = readOwner(ownerFile);
|
|
97
|
+
return JSON.stringify([o?.pid ?? null, o?.host ?? null, o?.at ?? null]);
|
|
98
|
+
};
|
|
99
|
+
let holder = holderOf();
|
|
100
|
+
// A holder renews its record every LEASE_RENEW_MS. One whose record has
|
|
101
|
+
// not changed for three of those, as this run sees it, has stopped,
|
|
102
|
+
// whatever computer or process id it names (pid 1 in a container, a
|
|
103
|
+
// computer whose processes this run cannot check).
|
|
104
|
+
let record = recordText(ownerFile);
|
|
105
|
+
let since = Date.now();
|
|
106
|
+
for (let waited = 0; !tryLock(lockDir); waited += 50) {
|
|
107
|
+
const text = recordText(ownerFile);
|
|
108
|
+
if (text !== record) {
|
|
109
|
+
record = text;
|
|
110
|
+
since = Date.now();
|
|
111
|
+
} else if (Date.now() - since >= SILENT_MS) {
|
|
112
|
+
takeOver(lockDir, record);
|
|
113
|
+
since = Date.now();
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const now = holderOf();
|
|
117
|
+
if (now !== holder) {
|
|
118
|
+
holder = now;
|
|
119
|
+
waited = 0;
|
|
120
|
+
}
|
|
121
|
+
if (waited > waitMs) onBusy(readOwner(ownerFile), held());
|
|
122
|
+
await sleep(50);
|
|
123
|
+
}
|
|
124
|
+
HELD.add(lockDir);
|
|
125
|
+
const mine = readOwner(ownerFile);
|
|
126
|
+
const same = (/** @type {any} */ o) =>
|
|
127
|
+
o != null &&
|
|
128
|
+
mine != null &&
|
|
129
|
+
o.pid === mine.pid &&
|
|
130
|
+
o.host === mine.host &&
|
|
131
|
+
o.at === mine.at;
|
|
132
|
+
// The lease: renewed while held, so a waiting run on another computer
|
|
133
|
+
// sees it change and never takes it over.
|
|
134
|
+
const lease = setInterval(() => {
|
|
135
|
+
if (same(readOwner(ownerFile))) renewLock(lockDir);
|
|
136
|
+
}, LEASE_RENEW_MS);
|
|
137
|
+
lease.unref();
|
|
138
|
+
// Only this run's own lock is removed, never one another took over.
|
|
139
|
+
const release = () => {
|
|
140
|
+
try {
|
|
141
|
+
if (same(readOwner(ownerFile)))
|
|
142
|
+
fs.rmSync(lockDir, {recursive: true, force: true});
|
|
143
|
+
} catch {
|
|
144
|
+
// Gone already.
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
// Stopped by a signal, the lock still goes.
|
|
148
|
+
const onSignal = (/** @type {NodeJS.Signals} */ sig) => {
|
|
149
|
+
release();
|
|
150
|
+
process.kill(process.pid, sig);
|
|
151
|
+
};
|
|
152
|
+
process.once('exit', release);
|
|
153
|
+
process.once('SIGINT', onSignal);
|
|
154
|
+
process.once('SIGTERM', onSignal);
|
|
155
|
+
try {
|
|
156
|
+
return await fn();
|
|
157
|
+
} finally {
|
|
158
|
+
clearInterval(lease);
|
|
159
|
+
release();
|
|
160
|
+
HELD.delete(lockDir);
|
|
161
|
+
process.removeListener('exit', release);
|
|
162
|
+
process.removeListener('SIGINT', onSignal);
|
|
163
|
+
process.removeListener('SIGTERM', onSignal);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Whether this process holds a lock folder now.
|
|
169
|
+
* @param {string} lockDir
|
|
170
|
+
*/
|
|
171
|
+
export const holdsFolderLock = lockDir => HELD.has(lockDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.15-canary.g79b95eb",
|
|
4
4
|
"displayName": "CLI",
|
|
5
5
|
"description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
"@stylexjs/babel-plugin": "^0.19.1",
|
|
115
115
|
"ast-types": "0.16.3",
|
|
116
116
|
"commander": "^12.1.0",
|
|
117
|
+
"css-tree": "3.2.1",
|
|
117
118
|
"ignore": "^7.0.14",
|
|
118
119
|
"jiti": "^2.7.0",
|
|
119
120
|
"jscodeshift": "^17.4.0",
|
|
@@ -125,7 +126,7 @@
|
|
|
125
126
|
"zod": "^4.6.7"
|
|
126
127
|
},
|
|
127
128
|
"peerDependencies": {
|
|
128
|
-
"@astryxdesign/core": "
|
|
129
|
+
"@astryxdesign/core": "0.7.15-canary.g79b95eb"
|
|
129
130
|
},
|
|
130
131
|
"peerDependenciesMeta": {
|
|
131
132
|
"@astryxdesign/core": {
|
|
@@ -133,10 +134,10 @@
|
|
|
133
134
|
}
|
|
134
135
|
},
|
|
135
136
|
"devDependencies": {
|
|
136
|
-
"@astryxdesign/charts": "
|
|
137
|
-
"@astryxdesign/core": "
|
|
138
|
-
"@astryxdesign/lab": "
|
|
139
|
-
"@astryxdesign/theme-neutral": "
|
|
137
|
+
"@astryxdesign/charts": "0.7.15-canary.g79b95eb",
|
|
138
|
+
"@astryxdesign/core": "0.7.15-canary.g79b95eb",
|
|
139
|
+
"@astryxdesign/lab": "0.7.15-canary.g79b95eb",
|
|
140
|
+
"@astryxdesign/theme-neutral": "0.7.15-canary.g79b95eb",
|
|
140
141
|
"@heroicons/react": "^2.2.0",
|
|
141
142
|
"@stylexjs/stylex": "^0.19.1",
|
|
142
143
|
"@types/babel__core": "^7.20.5",
|
|
@@ -154,6 +155,7 @@
|
|
|
154
155
|
"typecheck:strict": "tsc --project tsconfig.strict.json",
|
|
155
156
|
"typecheck:authoring": "tsc --project tsconfig.authoring-contract.json",
|
|
156
157
|
"sync:api-types": "node scripts/sync-api-types.mjs",
|
|
158
|
+
"generate:build-id": "node scripts/generate-build-id.mjs",
|
|
157
159
|
"readme": "node scripts/generate-cli-readme.mjs",
|
|
158
160
|
"readme:check": "node scripts/generate-cli-readme.mjs --check"
|
|
159
161
|
}
|