@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa
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 +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- 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/doctor/theme-checks.mjs +56 -21
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- 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.d.mts +17 -1
- package/api/theme/_adapter.mjs +185 -40
- package/api/theme/build/build.d.mts +29 -1
- package/api/theme/build/build.mjs +426 -65
- package/api/theme/eject/eject.mjs +10 -6
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- 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/tree/checks.doc.mjs +22 -1
- 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/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- 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-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +374 -42
- 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/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- 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 +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- 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 +22 -15
- 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 +741 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- 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/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +8 -6
|
@@ -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);
|
|
@@ -487,7 +487,7 @@ export const doc = {
|
|
|
487
487
|
{
|
|
488
488
|
value: 'integration.validate',
|
|
489
489
|
description:
|
|
490
|
-
'The validation result: validated (false when nothing was validated: with no package.json the issues list carries one no_package error so the command exits 1, and with a package.json but no integration manifest the issues list is empty and proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning | error, message, fix?, file?, line?} (fix: the change that resolves it; file and line: where, relative to the package), and notes when there are any: {code, message, next?} information beside the issues (text output marks a next note [next minor]); a note fails nothing by default, and one with next: true counts as a warning under integration check --next, fails integration check --strict --next, and fails --strict from the next minor release. Notes include invalid_cli_command for a malformed cliCommand and cli_peer_version when the running CLI is outside the @astryxdesign/cli peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message (duplicate_component_doc, symlinked_root, unreadable_file, invalid_package_json, no_provider_id, source_without_component_doc where a doc and its source still pair), and doc_name_mismatch and unknown_block_component, until they become warnings in the next minor release. For the commands a topic writes, runner_command (written with a package runner), plain_command (written bare), package_manager_command (written for one package manager) and doc_token (a token that does not parse) notes each give the file, line and the token to write. A doc_target_not_found note names a doc whose replaces or extends names no topic and no guide of the CLI docs or the docs of the package (such as a namespace), and a doc_section_unplaced note a section whose before or after names no section of what it extends (it is added at the end), and a duplicate_guide_replacement note two docs of the package that replace one guide; they become warnings in the next minor release. When the manifest loads, docTypes checks each doc against its published authoring type: status (checked | skipped), reason, typescript, docs, findings (all warnings, each naming the field and a fix), unchecked, and fixtures (test fixture docs not checked). When the manifest loads, docNames lists the component doc names it could not judge: status (checked), findings (always empty; a doc name the module its import names provably does not export is a doc_name_mismatch note, with its fix in the message) and unchecked ({file, name, reason}: a doc whose name differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, blockComponents lists the component names templates give in exampleFor or componentsUsed that could not be judged: status (checked), findings (always empty; a name neither the package nor Core has, and the template does not import, is an unknown_block_component note, with its fix in the message) and unchecked ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is also a note (its fix in the message), listed only and failing --strict from the next minor. So are the examples a package ships: component_without_example (a published component no block shows with exampleFor and isShowcase: true, or names in alsoShowcaseFor), template_category (a category written as a path, such as components/X), showcase_not_standalone (a showcase importing server-only code or reading process.env past NODE_ENV) and template_asset_not_packed (a new URL(…, import.meta.url) asset missing, or left out by npm pack --dry-run). When npm cannot list the files, an asset no files entry can reach is still a note and any other is listed in exampleAssets ({status: checked, findings: [], unchecked}, only when it lists any) as {file, asset, reason}. publicImports ({status: checked, findings: [], unchecked}) lists each import the check could not judge as {file, specifier, reason}; never counted or failed on. For the package being authored, olderCliNotes ({file, kind: template | namespace, field, message}) lists each descriptor field a CLI before 0.7.4 refuses, such as stability on a template or namespace doc; it is present only when it has entries, and is never counted or fails a check.',
|
|
490
|
+
'The validation result: validated (false when nothing was validated: with no package.json the issues list carries one no_package error so the command exits 1, and with a package.json but no integration manifest the issues list is empty and proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning | error, message, fix?, file?, line?} (fix: the change that resolves it; file and line: where, relative to the package), and notes when there are any: {code, message, next?} information beside the issues (text output marks a next note [next minor]); a note fails nothing by default, and one with next: true counts as a warning under integration check --next, fails integration check --strict --next, and fails --strict from the next minor release. Notes include invalid_cli_command for a malformed cliCommand and cli_peer_version when the running CLI is outside the @astryxdesign/cli peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message (duplicate_component_doc, symlinked_root, unreadable_file, invalid_package_json, no_provider_id, source_without_component_doc where a doc and its source still pair), and doc_name_mismatch and unknown_block_component, until they become warnings in the next minor release. For the commands a topic writes, runner_command (written with a package runner), plain_command (written bare), package_manager_command (written for one package manager) and doc_token (a token that does not parse) notes each give the file, line and the token to write. A doc_target_not_found note names a doc whose replaces or extends names no topic and no guide of the CLI docs or the docs of the package (such as a namespace), and a doc_section_unplaced note a section whose before or after names no section of what it extends (it is added at the end), and a duplicate_guide_replacement note two docs of the package that replace one guide; they become warnings in the next minor release. When the manifest loads, docTypes checks each doc against its published authoring type: status (checked | skipped), reason, typescript, docs, findings (all warnings, each naming the field and a fix), unchecked, and fixtures (test fixture docs not checked). When the manifest loads, docNames lists the component doc names it could not judge: status (checked), findings (always empty; a doc name the module its import names provably does not export is a doc_name_mismatch note, with its fix in the message) and unchecked ({file, name, reason}: a doc whose name differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, blockComponents lists the component names templates give in exampleFor or componentsUsed that could not be judged: status (checked), findings (always empty; a name neither the package nor Core has, and the template does not import, is an unknown_block_component note, with its fix in the message) and unchecked ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is also a note (its fix in the message), listed only and failing --strict from the next minor. So are the examples a package ships: component_without_example (a published component no block shows with exampleFor and isShowcase: true, or names in alsoShowcaseFor), template_category (a category written as a path, such as components/X), showcase_not_standalone (a showcase importing server-only code or reading process.env past NODE_ENV) and template_asset_not_packed (a new URL(…, import.meta.url) asset missing, or left out by npm pack --dry-run). When npm cannot list the files, an asset no files entry can reach is still a note and any other is listed in exampleAssets ({status: checked, findings: [], unchecked}, only when it lists any) as {file, asset, reason}. Since 0.7.15, package_without_logo (logo.light in the integration file, or a logo.dark that is set, names no packed PNG, JPEG, WebP or shapes-only SVG of at most 512 KB in the package; package.json marketplace.logo is read when the integration file has no logo) and package_without_example (components, other than those component_without_example exempts, but no block with isShowcase: true and exampleFor, or alsoShowcaseFor; themes-, docs- or codemods-only packages need none) say what a catalog needs to list the package, as notes without next that fail no check under any flag; a logo npm cannot be asked about is listed in exampleAssets with the file that names it. publicImports ({status: checked, findings: [], unchecked}) lists each import the check could not judge as {file, specifier, reason}; never counted or failed on. For the package being authored, olderCliNotes ({file, kind: template | namespace, field, message}) lists each descriptor field a CLI before 0.7.4 refuses, such as stability on a template or namespace doc; it is present only when it has entries, and is never counted or fails a check.',
|
|
491
491
|
},
|
|
492
492
|
{
|
|
493
493
|
value: 'integration.template-conflicts',
|
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.g061b2fa",
|
|
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.g061b2fa"
|
|
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.g061b2fa",
|
|
138
|
+
"@astryxdesign/core": "0.7.15-canary.g061b2fa",
|
|
139
|
+
"@astryxdesign/lab": "0.7.15-canary.g061b2fa",
|
|
140
|
+
"@astryxdesign/theme-neutral": "0.7.15-canary.g061b2fa",
|
|
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
|
}
|