@astryxdesign/cli 0.7.9-canary.bb7702c → 0.7.9-canary.bfc1dcc
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/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.mjs +9 -4
- package/api/theme/build/build.mjs +21 -1
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/foundation/config/project.mjs +27 -9
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
|
|
6
|
+
* Windows), found without running it. The copy receipt offers its
|
|
7
|
+
* `gh issue create` line on it. Running `gh` would make every copy wait on a
|
|
8
|
+
* process start, and for `gh auth status` on GitHub, before it reports.
|
|
9
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
10
|
+
* @param {NodeJS.Platform} [platform]
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export function checkGhCli(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
4
14
|
/**
|
|
5
15
|
* The integration component that replaces the Core component `name`
|
|
6
16
|
* (spec:AST-035 FR11), or undefined when none does.
|
package/api/swizzle/_adapter.mjs
CHANGED
|
@@ -8,14 +8,37 @@
|
|
|
8
8
|
* of swizzlable components: `list` returns the names directly, `copy` uses them
|
|
9
9
|
* for its "component not found" suggestions. Resolving core + listing lives
|
|
10
10
|
* here once so neither leaf re-walks the filesystem. Throws AstryxError
|
|
11
|
-
* (ERR_CORE_NOT_FOUND) when core can't be located.
|
|
11
|
+
* (ERR_CORE_NOT_FOUND) when core can't be located. The copy receipt's `gh`
|
|
12
|
+
* lookup is here too, on the shared search-path walk.
|
|
12
13
|
*/
|
|
13
14
|
|
|
15
|
+
import {executablesOnSearchPath} from '../../foundation/env/search-path.mjs';
|
|
14
16
|
import {findProjectCoreDir, listComponents} from '../../foundation/fs/paths.mjs';
|
|
15
17
|
import {resolveComponentReplacements} from '../../foundation/discovery/component-replacement.mjs';
|
|
16
18
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
19
|
import {AstryxError} from '../error.mjs';
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
|
|
23
|
+
* Windows), found without running it. The copy receipt offers its
|
|
24
|
+
* `gh issue create` line on it. Running `gh` would make every copy wait on a
|
|
25
|
+
* process start, and for `gh auth status` on GitHub, before it reports.
|
|
26
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
27
|
+
* @param {NodeJS.Platform} [platform]
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export function checkGhCli(env = process.env, platform = process.platform) {
|
|
31
|
+
const names =
|
|
32
|
+
platform === 'win32'
|
|
33
|
+
? (env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD')
|
|
34
|
+
.split(';')
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.map(extension => `gh${extension.toLowerCase()}`)
|
|
37
|
+
: ['gh'];
|
|
38
|
+
const searchPath = env.PATH ?? env.Path ?? '';
|
|
39
|
+
return executablesOnSearchPath(names, {searchPath, platform}).length > 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
19
42
|
/** The package that owns Core's components, hooks, and codemods. */
|
|
20
43
|
export {CORE_PROVIDER_ID as CORE_PACKAGE} from '../../foundation/identity/providers.mjs';
|
|
21
44
|
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
|
|
16
16
|
import * as fs from 'node:fs';
|
|
17
17
|
import * as path from 'node:path';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
checkGhCli,
|
|
20
|
+
resolveComponentReplacement,
|
|
21
|
+
resolveCore,
|
|
22
|
+
} from '../_adapter.mjs';
|
|
19
23
|
import {assertWithin, sanitizeName, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
|
|
20
|
-
import {checkGhCli} from '../_github.mjs';
|
|
21
24
|
import {Project} from '../../../foundation/config/project.mjs';
|
|
22
25
|
import {
|
|
23
26
|
CORE_PACKAGE,
|
|
@@ -299,6 +302,10 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
299
302
|
const outputBase = confineWrite(output, cwd, {label: 'output directory'});
|
|
300
303
|
const outputDir = path.join(outputBase, dirName);
|
|
301
304
|
|
|
305
|
+
// The receipt's feedback first: a swizzle that fails must fail before it
|
|
306
|
+
// writes anything.
|
|
307
|
+
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
308
|
+
|
|
302
309
|
// Pre-flight path and overwrite checks before any mkdir/writeFile.
|
|
303
310
|
const sourceFiles = fs.readdirSync(componentDir).filter(file => {
|
|
304
311
|
if (isExcludedFromCopy(file)) return false;
|
|
@@ -380,8 +387,6 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
380
387
|
!isExcludedFromCopy(f) &&
|
|
381
388
|
fs.statSync(path.join(componentDir, f)).isFile(),
|
|
382
389
|
);
|
|
383
|
-
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
384
|
-
|
|
385
390
|
/** @type {import('../swizzle.type.mjs').SwizzleCopyResponse['data']} */
|
|
386
391
|
const data = {
|
|
387
392
|
component: dirName,
|
|
@@ -2844,12 +2844,29 @@ async function themeBuildInternal(
|
|
|
2844
2844
|
let themeExportName;
|
|
2845
2845
|
/** Paths through the load that interception could not fully observe. */
|
|
2846
2846
|
let loadDegradation;
|
|
2847
|
+
/**
|
|
2848
|
+
* The theme file's bytes as loaded: read before and after the load, and the
|
|
2849
|
+
* registry scan below reads these rather than the file again. An editor's
|
|
2850
|
+
* in-place save truncates before it writes, so a later read can find an
|
|
2851
|
+
* empty file the load never saw; a file that changed while it loaded is not
|
|
2852
|
+
* built from.
|
|
2853
|
+
* @type {string}
|
|
2854
|
+
*/
|
|
2855
|
+
let themeSource;
|
|
2847
2856
|
try {
|
|
2857
|
+
const before = fs.readFileSync(filePath, 'utf8');
|
|
2848
2858
|
const loaded = await extractThemeDefinition(
|
|
2849
2859
|
filePath,
|
|
2850
2860
|
interception,
|
|
2851
2861
|
options.__familyLoader,
|
|
2852
2862
|
);
|
|
2863
|
+
const after = fs.readFileSync(filePath, 'utf8');
|
|
2864
|
+
if (before !== after || before === '') {
|
|
2865
|
+
throw new Error(
|
|
2866
|
+
`${filePath} changed while it was loading. Build again once it is saved.`,
|
|
2867
|
+
);
|
|
2868
|
+
}
|
|
2869
|
+
themeSource = before;
|
|
2853
2870
|
themeDef = loaded.theme;
|
|
2854
2871
|
themeExportName = loaded.exportName;
|
|
2855
2872
|
loadDegradation = loaded.degraded;
|
|
@@ -2939,7 +2956,10 @@ async function themeBuildInternal(
|
|
|
2939
2956
|
: []),
|
|
2940
2957
|
];
|
|
2941
2958
|
const iconResolution = {
|
|
2942
|
-
readSource: (/** @type {string} */ file) =>
|
|
2959
|
+
readSource: (/** @type {string} */ file) =>
|
|
2960
|
+
path.resolve(file) === path.resolve(filePath)
|
|
2961
|
+
? themeSource
|
|
2962
|
+
: fs.readFileSync(file, 'utf8'),
|
|
2943
2963
|
resolveModule: resolveThemeModule,
|
|
2944
2964
|
reservedNames: reservedNames(functionEntries),
|
|
2945
2965
|
functionEntries,
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx docs calendars/calendar-systems`: choosing a calendar, the
|
|
5
|
+
* supported calendars, loading Temporal on the server and in the browser, the
|
|
6
|
+
* lunisolar calendars, and week numbers.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
|
|
10
|
+
|
|
11
|
+
export const docs = {
|
|
12
|
+
type: 'generic',
|
|
13
|
+
name: 'calendar-systems',
|
|
14
|
+
title: 'Calendar systems',
|
|
15
|
+
placement: {
|
|
16
|
+
parent: 'namespace:calendars',
|
|
17
|
+
slot: 'guides',
|
|
18
|
+
order: 10,
|
|
19
|
+
},
|
|
20
|
+
category: 'guide',
|
|
21
|
+
description:
|
|
22
|
+
'Choosing a calendar, which calendars need Temporal, server rendering, the lunisolar calendars, and week numbers.',
|
|
23
|
+
|
|
24
|
+
sections: [
|
|
25
|
+
{
|
|
26
|
+
title: 'Choose a calendar',
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: 'prose',
|
|
30
|
+
text: '`Calendar` shows the Gregorian calendar unless you choose another one. Pass `calendar` to `<InternationalizationProvider>` to set it for a subtree. A locale on its own never changes the calendar: `fa-IR` shows Gregorian dates in Persian until you pass `calendar="persian"`. A locale with a `-u-ca-` keyword, such as `th-TH-u-ca-buddhist`, keeps Gregorian dates too; set `calendar` to choose one.',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'code',
|
|
34
|
+
lang: 'tsx',
|
|
35
|
+
label: 'Persian dates in a Persian interface',
|
|
36
|
+
code: `import {InternationalizationProvider} from '@astryxdesign/core/i18n';
|
|
37
|
+
import {Calendar} from '@astryxdesign/core/Calendar';
|
|
38
|
+
|
|
39
|
+
<InternationalizationProvider locale="fa-IR" calendar="persian">
|
|
40
|
+
{/* shows Aban 1405; value and onChange stay '2026-10-30' */}
|
|
41
|
+
<Calendar value={date} onChange={setDate} />
|
|
42
|
+
</InternationalizationProvider>;`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'prose',
|
|
46
|
+
text: 'Calendar and language are independent: `locale="en" calendar="hebrew"` shows Hebrew dates in English. `Calendar` also takes its own `calendar`, which wins over the provider. Use it when one screen shows two calendars side by side.',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'prose',
|
|
50
|
+
text: 'Values never change with the calendar. `value`, `defaultValue`, `onChange`, `min`, and `max` stay Gregorian ISO dates (`YYYY-MM-DD`) in every calendar, so your data, server code, and existing handlers keep working.',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: 'Supported calendars',
|
|
56
|
+
content: [
|
|
57
|
+
{
|
|
58
|
+
type: 'table',
|
|
59
|
+
headers: ['Calendar', 'Identifiers', 'Needs Temporal'],
|
|
60
|
+
rows: [
|
|
61
|
+
['Gregorian', '`gregory`, `iso8601`', 'No'],
|
|
62
|
+
['Buddhist (Thai)', '`buddhist`', 'No'],
|
|
63
|
+
['Minguo', '`roc`', 'No'],
|
|
64
|
+
['Japanese (eras)', '`japanese`', 'No'],
|
|
65
|
+
['Persian (Solar Hijri)', '`persian`', 'Yes'],
|
|
66
|
+
['Indian national (Saka)', '`indian`', 'Yes'],
|
|
67
|
+
['Hebrew', '`hebrew`', 'Yes'],
|
|
68
|
+
[
|
|
69
|
+
'Islamic (Hijri)',
|
|
70
|
+
'`islamic-umalqura`, `islamic-civil`, `islamic-tbla`',
|
|
71
|
+
'Yes',
|
|
72
|
+
],
|
|
73
|
+
['Lunisolar', '`chinese`, `dangi`', 'Yes'],
|
|
74
|
+
['Coptic', '`coptic`', 'Yes'],
|
|
75
|
+
['Ethiopian', '`ethiopic`, `ethioaa`', 'Yes'],
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'prose',
|
|
80
|
+
text: 'Any other identifier, such as `islamic`, shows Gregorian dates and warns once in development.',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
title: 'Load Temporal where the runtime lacks it',
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
type: 'prose',
|
|
89
|
+
text: "Calendars whose months are not Gregorian use the runtime's `Temporal` for their month lengths, leap months, and years. Chrome and Edge 144 and later, Firefox 139 and later, and Node.js 26 and later ship it. Safari and older runtimes do not. Astryx bundles no polyfill, so Gregorian applications pay nothing.",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: 'prose',
|
|
93
|
+
text: 'Where `Temporal` is missing, load the full build of `temporal-polyfill` before your app renders. The default build has no non-ISO calendars. Load it only where `Temporal` is missing: a native implementation is more accurate for the lunisolar calendars.',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'code',
|
|
97
|
+
lang: 'ts',
|
|
98
|
+
label: 'Load the polyfill only where Temporal is missing',
|
|
99
|
+
code: `// temporal-setup.ts: import before your app renders, on the server and in the browser
|
|
100
|
+
if (!('Temporal' in globalThis)) {
|
|
101
|
+
await import('temporal-polyfill/full/global');
|
|
102
|
+
}`,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: 'prose',
|
|
106
|
+
text: 'If you render on the server, load it there too. `Calendar` resolves its calendar during render, so a server without `Temporal` renders Gregorian dates, and a browser with it renders Persian ones: hydration then fails. When both have `Temporal`, or both lack it, they render the same markup.',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: 'prose',
|
|
110
|
+
text: 'Without a `Temporal` that supports it, a calendar that needs one shows Gregorian dates and warns once in development, on the server and in the browser. The Gregorian-aligned calendars (`buddhist`, `roc`, `japanese`) work everywhere without it.',
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
title: 'Lunisolar calendars',
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: 'prose',
|
|
119
|
+
text: "In the lunisolar calendars, months start on new moons computed from astronomy, and runtimes do not all agree on a few of them. Astryx follows the runtime's `Temporal` and does not correct it.",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: 'list',
|
|
123
|
+
style: 'unordered',
|
|
124
|
+
items: [
|
|
125
|
+
'Native `Temporal` in Chrome, Edge, Firefox, and Node.js 26 agrees with official observatory data from 1900 through 2100.',
|
|
126
|
+
"A polyfill reads the platform's `Intl` data instead. Under a polyfill, Node.js 24 starts nine `chinese` and four `dangi` months in that range one day apart from the native result: the first month of the 2027 `chinese` year starts on February 6 with native `Temporal` and on February 7 under the polyfill. Safari uses the same kind of `Intl` data, so expect the same differences there.",
|
|
127
|
+
'Within one browser, the day numbers a person sees, the dates a screen reader announces, and the value they pick agree. Only two different runtimes can disagree.',
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: 'prose',
|
|
132
|
+
text: 'If you render on the server, a server and a browser that use different implementations can disagree on one of these month starts. The browser then renders that month differently from the server markup, and React renders that part again on the client during hydration. The `temporal-polyfill/full/global` import keeps a native `Temporal` where one exists, so on its own it leaves Chrome, Edge, and Firefox on native `Temporal` and a Node.js 24 server on the polyfill. When identical server and browser markup for these calendars matters more than matching official data, call `installImplementation()` from `temporal-polyfill/full/shim` on the server and in the browser before rendering: it installs the polyfill even over a native `Temporal`. A server runtime with native `Temporal`, such as Node.js 26, also matches native browsers. Otherwise, do not replace a native `Temporal`: that makes native environments less accurate.',
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
title: 'Week numbers',
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'prose',
|
|
141
|
+
text: "`Calendar`'s `hasWeekNumbers` shows ISO 8601 week numbers in every calendar. Temporal defines week numbering only for the ISO calendar.",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx docs calendars`: calendar systems in detail. Which calendars
|
|
5
|
+
* date components show, how to load Temporal, server rendering, and the
|
|
6
|
+
* lunisolar calendars. The `internationalization/i18n-calendars` guide has the
|
|
7
|
+
* short version.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @type {import('@astryxdesign/cli/authoring').NamespaceDoc} */
|
|
11
|
+
export const docs = {
|
|
12
|
+
type: 'namespace',
|
|
13
|
+
name: 'calendars',
|
|
14
|
+
// The docsite lists guide pages by title, so this one sorts directly below
|
|
15
|
+
// Internationalization, the page that links here.
|
|
16
|
+
title: 'Internationalization: calendars',
|
|
17
|
+
summary:
|
|
18
|
+
'Show dates in the Persian, Hebrew, Islamic, Buddhist, Japanese, lunisolar, and other calendars while values stay Gregorian ISO dates.',
|
|
19
|
+
keywords: [
|
|
20
|
+
'calendar',
|
|
21
|
+
'calendar system',
|
|
22
|
+
'Persian',
|
|
23
|
+
'Jalali',
|
|
24
|
+
'Hebrew',
|
|
25
|
+
'Hijri',
|
|
26
|
+
'Islamic',
|
|
27
|
+
'Buddhist',
|
|
28
|
+
'Japanese era',
|
|
29
|
+
'lunisolar',
|
|
30
|
+
'chinese',
|
|
31
|
+
'dangi',
|
|
32
|
+
'Ethiopian',
|
|
33
|
+
'Temporal',
|
|
34
|
+
'polyfill',
|
|
35
|
+
'u-ca',
|
|
36
|
+
],
|
|
37
|
+
slots: {
|
|
38
|
+
guides: {title: 'Guides', accepts: {kinds: ['generic']}},
|
|
39
|
+
},
|
|
40
|
+
blocks: [
|
|
41
|
+
{
|
|
42
|
+
type: 'prose',
|
|
43
|
+
text: '`Calendar`, DateInput, DateRangeInput, and DateTimeInput show the Gregorian calendar unless the application chooses another one. Values never change with the calendar: they stay Gregorian ISO dates. {@link generic:i18n-calendars} has the short version.',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file `astryx docs internationalization/i18n-calendars`: the short version of
|
|
5
|
+
* showing dates in another calendar. The `calendars` namespace holds the
|
|
6
|
+
* detail.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
|
|
10
|
+
|
|
11
|
+
export const docs = {
|
|
12
|
+
type: 'generic',
|
|
13
|
+
name: 'i18n-calendars',
|
|
14
|
+
title: 'Other calendars',
|
|
15
|
+
placement: {
|
|
16
|
+
parent: 'namespace:internationalization',
|
|
17
|
+
slot: 'guides',
|
|
18
|
+
order: 25,
|
|
19
|
+
},
|
|
20
|
+
category: 'guide',
|
|
21
|
+
description:
|
|
22
|
+
'Show dates in the Persian, Hebrew, Islamic, Buddhist, Japanese, and other calendars while values stay Gregorian ISO dates.',
|
|
23
|
+
|
|
24
|
+
sections: [
|
|
25
|
+
{
|
|
26
|
+
title: 'Show dates in another calendar',
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: 'prose',
|
|
30
|
+
text: 'Set `calendar` on `<InternationalizationProvider>` for a subtree, or on `Calendar` itself; without it, `Calendar` is Gregorian. Values stay Gregorian ISO dates (`YYYY-MM-DD`) in every calendar.',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'code',
|
|
34
|
+
lang: 'tsx',
|
|
35
|
+
label: 'Persian dates in a Persian interface',
|
|
36
|
+
code: `import {InternationalizationProvider} from '@astryxdesign/core/i18n';
|
|
37
|
+
import {Calendar} from '@astryxdesign/core/Calendar';
|
|
38
|
+
|
|
39
|
+
<InternationalizationProvider locale="fa-IR" calendar="persian">
|
|
40
|
+
{/* shows Aban 1405; value and onChange stay '2026-10-30' */}
|
|
41
|
+
<Calendar value={date} onChange={setDate} />
|
|
42
|
+
</InternationalizationProvider>;`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'prose',
|
|
46
|
+
text: "Most calendars need the runtime's `Temporal`. Safari and older runtimes lack it: load `temporal-polyfill/full/global` there, on the server and in the browser. Without it, those calendars show Gregorian dates. See {@link namespace:calendars} for the supported calendars, server rendering, and the lunisolar calendars.",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file `astryx docs internationalization`: the internationalization namespace.
|
|
5
|
-
* Groups guides for quick-start locale setup, library integration,
|
|
6
|
-
* RTL + testing.
|
|
5
|
+
* Groups guides for quick-start locale setup, library integration, calendars,
|
|
6
|
+
* and RTL + testing.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
/** @type {import('@astryxdesign/cli/authoring').NamespaceDoc} */
|
|
@@ -12,7 +12,7 @@ export const docs = {
|
|
|
12
12
|
name: 'internationalization',
|
|
13
13
|
title: 'Internationalization',
|
|
14
14
|
summary:
|
|
15
|
-
'Set the active locale, load catalogs, coexist with your own i18n library, handle RTL, and test translations.',
|
|
15
|
+
'Set the active locale, load catalogs, coexist with your own i18n library, show other calendars, handle RTL, and test translations.',
|
|
16
16
|
keywords: [
|
|
17
17
|
'i18n',
|
|
18
18
|
'internationalization',
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @file Shared test helper:
|
|
4
|
+
* @file Shared test helper: builds @astryxdesign/core once per run, race-free.
|
|
5
|
+
* @input Core's sources, translations and build scripts; this checkout's lock
|
|
6
|
+
* and run leases in the system temp directory.
|
|
7
|
+
* @output A packages/core/dist whose last output is newer than every source.
|
|
8
|
+
* @position Called by the node global setup and the build-theme suites.
|
|
5
9
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* built core. The CI `test` job runs `pnpm test` without a prior core build,
|
|
9
|
-
* and Vitest runs test files in parallel worker forks. When two build-theme
|
|
10
|
-
* suites each ran `if (!exists) pnpm -F @astryxdesign/core build` in their own
|
|
11
|
-
* beforeAll, both workers saw dist missing and launched concurrent builds that
|
|
12
|
-
* collided on the shared packages/core/dist: one worker cleaned dist while the
|
|
13
|
-
* other was mid-write, failing nondeterministically ("Could not resolve
|
|
14
|
-
* dist/index.js" / "ENOTEMPTY rmdir dist/hooks").
|
|
15
|
-
*
|
|
16
|
-
* This serializes the build behind a filesystem lock so exactly one worker
|
|
17
|
-
* builds and the rest wait for it to finish before reading dist.
|
|
10
|
+
* A Core build deletes dist first. Only the global setup rebuilds a stale
|
|
11
|
+
* build, before the workers start, and only after earlier runs end.
|
|
18
12
|
*/
|
|
19
13
|
|
|
20
14
|
import {execFileSync} from 'node:child_process';
|
|
15
|
+
import {createHash} from 'node:crypto';
|
|
21
16
|
import * as fs from 'node:fs';
|
|
22
17
|
import * as os from 'node:os';
|
|
23
18
|
import * as path from 'node:path';
|
|
@@ -27,12 +22,153 @@ const REPO_ROOT = path.resolve(
|
|
|
27
22
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
28
23
|
'../../../../..',
|
|
29
24
|
);
|
|
30
|
-
|
|
25
|
+
// The build's last output. `build:css` writes it after the compiled modules,
|
|
26
|
+
// their declarations and the declaration extensions. So a build that was
|
|
27
|
+
// interrupted or failed before it finished has no marker, and reads as missing.
|
|
28
|
+
// (`dist/theme/index.js`, which the build-theme suites import, comes about
|
|
29
|
+
// 11 s into a 38 s build.)
|
|
30
|
+
export const CORE_BUILD_MARKER = path.join(
|
|
31
31
|
REPO_ROOT,
|
|
32
|
-
'packages/core/dist/
|
|
32
|
+
'packages/core/dist/astryx.css',
|
|
33
33
|
);
|
|
34
|
-
//
|
|
35
|
-
|
|
34
|
+
// What the build compiles, and the scripts and config it compiles with: a file
|
|
35
|
+
// here newer than the marker means dist is stale. A checkout rewrites the files
|
|
36
|
+
// it changes, so they read as newer. The translations live outside src, in
|
|
37
|
+
// locales. The scripts are the ones Core's `build*` scripts run that write
|
|
38
|
+
// output (not its checks).
|
|
39
|
+
export const CORE_SOURCES = [
|
|
40
|
+
path.join(REPO_ROOT, 'packages/core/src'),
|
|
41
|
+
path.join(REPO_ROOT, 'packages/core/locales'),
|
|
42
|
+
path.join(REPO_ROOT, 'packages/core/package.json'),
|
|
43
|
+
path.join(REPO_ROOT, 'packages/core/babel.config.json'),
|
|
44
|
+
path.join(REPO_ROOT, 'packages/core/babel-plugin-add-extensions.cjs'),
|
|
45
|
+
path.join(REPO_ROOT, 'packages/core/tsconfig.build.json'),
|
|
46
|
+
path.join(REPO_ROOT, 'tsconfig.json'),
|
|
47
|
+
path.join(REPO_ROOT, 'packages/core/scripts/build-pseudo-locale.mjs'),
|
|
48
|
+
path.join(REPO_ROOT, 'scripts/generate-i18n-runtime.mjs'),
|
|
49
|
+
path.join(REPO_ROOT, 'scripts/i18n-english-fallback.mjs'),
|
|
50
|
+
path.join(REPO_ROOT, 'scripts/add-declaration-extensions.mjs'),
|
|
51
|
+
path.join(REPO_ROOT, 'scripts/build-css.mjs'),
|
|
52
|
+
path.join(REPO_ROOT, 'scripts/lib/stylex-generated-variable.mjs'),
|
|
53
|
+
path.join(REPO_ROOT, 'scripts/stylex-module-resolution.cjs'),
|
|
54
|
+
];
|
|
55
|
+
// Git-ignored output generated from those sources, by the build and again by
|
|
56
|
+
// the Vitest global setup (internal/test-utils/src/globalSetup.ts). Rewritten
|
|
57
|
+
// after a build, it would read as newer than that build.
|
|
58
|
+
export const CORE_GENERATED = [
|
|
59
|
+
path.join(REPO_ROOT, 'packages/core/src/i18n/generated-english'),
|
|
60
|
+
path.join(REPO_ROOT, 'packages/core/src/i18n/generated-locales'),
|
|
61
|
+
path.join(REPO_ROOT, 'packages/core/locales/pseudo.json'),
|
|
62
|
+
];
|
|
63
|
+
/**
|
|
64
|
+
* The lock directory (mkdir is atomic across processes) that guards the Core
|
|
65
|
+
* build of the checkout at `repoRoot`: one per checkout.
|
|
66
|
+
* @param {string} repoRoot
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
export function coreBuildLockDir(repoRoot) {
|
|
70
|
+
const key = createHash('sha256')
|
|
71
|
+
.update(path.resolve(repoRoot))
|
|
72
|
+
.digest('hex')
|
|
73
|
+
.slice(0, 16);
|
|
74
|
+
return path.join(os.tmpdir(), `astryx-core-build-${key}.lock`);
|
|
75
|
+
}
|
|
76
|
+
const LOCK_DIR = coreBuildLockDir(REPO_ROOT);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The directory where each node test run of the checkout at `repoRoot` holds
|
|
80
|
+
* a lease for as long as it runs. Each run has one file, named by its process
|
|
81
|
+
* id and holding the time it started.
|
|
82
|
+
* @param {string} repoRoot
|
|
83
|
+
*/
|
|
84
|
+
export function coreRunLeaseDir(repoRoot) {
|
|
85
|
+
return coreBuildLockDir(repoRoot).replace(/\.lock$/, '.runs');
|
|
86
|
+
}
|
|
87
|
+
const RUN_LEASE_DIR = coreRunLeaseDir(REPO_ROOT);
|
|
88
|
+
|
|
89
|
+
/** @param {number} pid */
|
|
90
|
+
function processIsAlive(pid) {
|
|
91
|
+
try {
|
|
92
|
+
process.kill(pid, 0);
|
|
93
|
+
return true;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const {code} = /** @type {NodeJS.ErrnoException} */ (error);
|
|
96
|
+
// ESRCH: no such process, so it has ended. EPERM: it runs as another user.
|
|
97
|
+
if (code === 'ESRCH') return false;
|
|
98
|
+
if (code === 'EPERM') return true;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Registers this process as a running test run of the checkout, and returns
|
|
105
|
+
* the function that ends its lease (the global setup's teardown).
|
|
106
|
+
* @param {{leaseDir?: string, pid?: number, now?: number}} [options]
|
|
107
|
+
*/
|
|
108
|
+
export function registerTestRun({
|
|
109
|
+
leaseDir = RUN_LEASE_DIR,
|
|
110
|
+
pid = process.pid,
|
|
111
|
+
now = Date.now(),
|
|
112
|
+
} = {}) {
|
|
113
|
+
fs.mkdirSync(leaseDir, {recursive: true});
|
|
114
|
+
const file = path.join(leaseDir, String(pid));
|
|
115
|
+
fs.writeFileSync(file, String(now));
|
|
116
|
+
return () => fs.rmSync(file, {force: true});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The runs in `leaseDir` that started before this one (by start time, then
|
|
121
|
+
* process id) and are still alive. Those may be reading the build now. A run
|
|
122
|
+
* that started later waits for this one instead, so two runs never wait for
|
|
123
|
+
* each other. A lease whose process is gone is removed.
|
|
124
|
+
* @param {string} leaseDir
|
|
125
|
+
* @param {{pid?: number, isAlive?: (pid: number) => boolean}} [options]
|
|
126
|
+
*/
|
|
127
|
+
export function earlierLiveRuns(
|
|
128
|
+
leaseDir,
|
|
129
|
+
{pid = process.pid, isAlive = processIsAlive} = {},
|
|
130
|
+
) {
|
|
131
|
+
/** @type {string[]} */
|
|
132
|
+
let names;
|
|
133
|
+
try {
|
|
134
|
+
names = fs.readdirSync(leaseDir);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
// No run has registered in this checkout yet.
|
|
137
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
/** @param {string} name */
|
|
143
|
+
const startOf = name => {
|
|
144
|
+
try {
|
|
145
|
+
return Number(fs.readFileSync(path.join(leaseDir, name), 'utf8'));
|
|
146
|
+
} catch (error) {
|
|
147
|
+
// The run ended, and its lease went, between the listing and this read.
|
|
148
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') {
|
|
149
|
+
return NaN;
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const own = startOf(String(pid));
|
|
155
|
+
const ownStart = Number.isFinite(own) ? own : Infinity;
|
|
156
|
+
/** @type {number[]} */
|
|
157
|
+
const earlier = [];
|
|
158
|
+
for (const name of names) {
|
|
159
|
+
const other = Number(name);
|
|
160
|
+
if (!Number.isInteger(other) || other === pid) continue;
|
|
161
|
+
if (!isAlive(other)) {
|
|
162
|
+
fs.rmSync(path.join(leaseDir, name), {force: true});
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const start = startOf(name);
|
|
166
|
+
if (start < ownStart || (start === ownStart && other < pid)) {
|
|
167
|
+
earlier.push(other);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return earlier;
|
|
171
|
+
}
|
|
36
172
|
|
|
37
173
|
const BUILD_TIMEOUT_MS = 180_000;
|
|
38
174
|
// A lock older than this is assumed abandoned by a crashed/killed worker.
|
|
@@ -44,6 +180,56 @@ function sleepSync(ms) {
|
|
|
44
180
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
45
181
|
}
|
|
46
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Whether `entry` is missing or older than any file under `roots` (files or
|
|
185
|
+
* directories; `node_modules`, `dist` and the paths in `generated` are
|
|
186
|
+
* skipped).
|
|
187
|
+
* @param {string} entry
|
|
188
|
+
* @param {readonly string[]} roots
|
|
189
|
+
* @param {readonly string[]} [generated]
|
|
190
|
+
* @returns {boolean}
|
|
191
|
+
*/
|
|
192
|
+
export function coreBuildIsStale(entry, roots, generated = []) {
|
|
193
|
+
let built;
|
|
194
|
+
try {
|
|
195
|
+
built = fs.statSync(entry).mtimeMs;
|
|
196
|
+
} catch (error) {
|
|
197
|
+
// Not built yet.
|
|
198
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
const skipped = new Set(generated.map(p => path.resolve(p)));
|
|
204
|
+
const pending = [...roots];
|
|
205
|
+
while (pending.length > 0) {
|
|
206
|
+
const current = /** @type {string} */ (pending.pop());
|
|
207
|
+
if (skipped.has(path.resolve(current))) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
let stat;
|
|
211
|
+
try {
|
|
212
|
+
stat = fs.statSync(current);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
// Removed while the walk ran.
|
|
215
|
+
if (/** @type {NodeJS.ErrnoException} */ (error).code === 'ENOENT') {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
if (stat.isDirectory()) {
|
|
221
|
+
for (const name of fs.readdirSync(current)) {
|
|
222
|
+
if (name !== 'node_modules' && name !== 'dist') {
|
|
223
|
+
pending.push(path.join(current, name));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
} else if (stat.mtimeMs > built) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
|
|
47
233
|
function buildCore() {
|
|
48
234
|
execFileSync('pnpm', ['-F', '@astryxdesign/core', 'build'], {
|
|
49
235
|
cwd: REPO_ROOT,
|
|
@@ -52,28 +238,46 @@ function buildCore() {
|
|
|
52
238
|
});
|
|
53
239
|
}
|
|
54
240
|
|
|
55
|
-
|
|
241
|
+
/**
|
|
242
|
+
* @param {string} lockDir
|
|
243
|
+
* @param {number} staleLockMs
|
|
244
|
+
*/
|
|
245
|
+
function lockIsStale(lockDir, staleLockMs) {
|
|
56
246
|
try {
|
|
57
|
-
return Date.now() - fs.statSync(
|
|
247
|
+
return Date.now() - fs.statSync(lockDir).mtimeMs > staleLockMs;
|
|
58
248
|
} catch {
|
|
59
249
|
// Vanished between the exists check and stat — treat as released.
|
|
60
250
|
return false;
|
|
61
251
|
}
|
|
62
252
|
}
|
|
63
253
|
|
|
64
|
-
/**
|
|
65
|
-
|
|
254
|
+
/**
|
|
255
|
+
* Whether another worker holds the lock: it is building, and dist is not
|
|
256
|
+
* whole yet.
|
|
257
|
+
* @param {string} lockDir
|
|
258
|
+
* @param {number} staleLockMs
|
|
259
|
+
*/
|
|
260
|
+
function lockIsHeld(lockDir, staleLockMs) {
|
|
261
|
+
return fs.existsSync(lockDir) && !lockIsStale(lockDir, staleLockMs);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Try to acquire the lock. Returns true if this worker now holds it.
|
|
266
|
+
* @param {string} lockDir
|
|
267
|
+
* @param {number} staleLockMs
|
|
268
|
+
*/
|
|
269
|
+
function tryAcquire(lockDir, staleLockMs) {
|
|
66
270
|
try {
|
|
67
|
-
fs.mkdirSync(
|
|
271
|
+
fs.mkdirSync(lockDir);
|
|
68
272
|
return true;
|
|
69
273
|
} catch (err) {
|
|
70
274
|
if (/** @type {NodeJS.ErrnoException} */ (err).code !== 'EEXIST') {
|
|
71
275
|
throw err;
|
|
72
276
|
}
|
|
73
|
-
if (lockIsStale()) {
|
|
74
|
-
fs.rmSync(
|
|
277
|
+
if (lockIsStale(lockDir, staleLockMs)) {
|
|
278
|
+
fs.rmSync(lockDir, {recursive: true, force: true});
|
|
75
279
|
try {
|
|
76
|
-
fs.mkdirSync(
|
|
280
|
+
fs.mkdirSync(lockDir);
|
|
77
281
|
return true;
|
|
78
282
|
} catch (retryErr) {
|
|
79
283
|
if (/** @type {NodeJS.ErrnoException} */ (retryErr).code !== 'EEXIST') {
|
|
@@ -86,35 +290,187 @@ function tryAcquire() {
|
|
|
86
290
|
}
|
|
87
291
|
|
|
88
292
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* build
|
|
293
|
+
* Run `build` unless `isBuilt()`, in exactly one process at a time: the one
|
|
294
|
+
* holding `lockDir`. Every other caller returns only once no process holds
|
|
295
|
+
* the lock and the build is current, so none reads a build still being
|
|
296
|
+
* written.
|
|
297
|
+
* @param {{isBuilt: () => boolean, build: () => void, lockDir: string, staleLockMs?: number, pollMs?: number}} options
|
|
92
298
|
*/
|
|
93
|
-
export function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
299
|
+
export function ensureBuiltOnce({
|
|
300
|
+
isBuilt,
|
|
301
|
+
build,
|
|
302
|
+
lockDir,
|
|
303
|
+
staleLockMs = STALE_LOCK_MS,
|
|
304
|
+
pollMs = POLL_MS,
|
|
305
|
+
}) {
|
|
306
|
+
const deadline = Date.now() + staleLockMs;
|
|
99
307
|
while (Date.now() < deadline) {
|
|
100
|
-
if (
|
|
308
|
+
if (!lockIsHeld(lockDir, staleLockMs) && isBuilt()) {
|
|
101
309
|
return;
|
|
102
310
|
}
|
|
103
|
-
if (tryAcquire()) {
|
|
311
|
+
if (tryAcquire(lockDir, staleLockMs)) {
|
|
104
312
|
try {
|
|
105
|
-
if (!
|
|
106
|
-
|
|
313
|
+
if (!isBuilt()) {
|
|
314
|
+
build();
|
|
107
315
|
}
|
|
108
316
|
} finally {
|
|
109
|
-
fs.rmSync(
|
|
317
|
+
fs.rmSync(lockDir, {recursive: true, force: true});
|
|
110
318
|
}
|
|
111
319
|
return;
|
|
112
320
|
}
|
|
113
|
-
// Another worker is building; wait for it to
|
|
114
|
-
sleepSync(
|
|
321
|
+
// Another worker is building; wait for it to release the lock.
|
|
322
|
+
sleepSync(pollMs);
|
|
115
323
|
}
|
|
116
324
|
|
|
117
|
-
// Waited past the stale threshold without the
|
|
325
|
+
// Waited past the stale threshold without the lock coming free — build it
|
|
118
326
|
// ourselves rather than let the suite fail on a missing entry.
|
|
119
|
-
|
|
327
|
+
build();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Build Core when `entry` is missing, or also when it is older than
|
|
332
|
+
* `roots` with `rebuildStale`, in one process at a time.
|
|
333
|
+
* @param {{entry: string, roots: readonly string[], generated?: readonly string[], build: () => void, lockDir: string, rebuildStale?: boolean, staleLockMs?: number, pollMs?: number}} options
|
|
334
|
+
*/
|
|
335
|
+
export function ensureCoreBuiltAt({
|
|
336
|
+
entry,
|
|
337
|
+
roots,
|
|
338
|
+
generated = [],
|
|
339
|
+
build,
|
|
340
|
+
lockDir,
|
|
341
|
+
rebuildStale = false,
|
|
342
|
+
staleLockMs,
|
|
343
|
+
pollMs = POLL_MS,
|
|
344
|
+
}) {
|
|
345
|
+
ensureBuiltOnce({
|
|
346
|
+
isBuilt: rebuildStale
|
|
347
|
+
? () => !coreBuildIsStale(entry, roots, generated)
|
|
348
|
+
: () => fs.existsSync(entry),
|
|
349
|
+
build,
|
|
350
|
+
lockDir,
|
|
351
|
+
staleLockMs,
|
|
352
|
+
pollMs,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Ensure packages/core/dist is built exactly once, even when called
|
|
358
|
+
* concurrently from parallel Vitest workers. A build-theme suite's beforeAll
|
|
359
|
+
* calls it with no options, and it builds only a missing Core. The node global
|
|
360
|
+
* setup rebuilds a build older than Core's sources (`ensureCoreBuiltForRun`).
|
|
361
|
+
* It does so before any worker forks, once every run that started before it
|
|
362
|
+
* has ended, so never under a running suite.
|
|
363
|
+
* @param {{rebuildStale?: boolean}} [options]
|
|
364
|
+
*/
|
|
365
|
+
export function ensureCoreBuilt({rebuildStale = false} = {}) {
|
|
366
|
+
ensureCoreBuiltAt({
|
|
367
|
+
entry: CORE_BUILD_MARKER,
|
|
368
|
+
roots: CORE_SOURCES,
|
|
369
|
+
generated: CORE_GENERATED,
|
|
370
|
+
build: buildCore,
|
|
371
|
+
lockDir: LOCK_DIR,
|
|
372
|
+
rebuildStale,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** How long a run waits for the runs that started before it, ms. */
|
|
377
|
+
export const EARLIER_RUN_WAIT_MS = 120_000;
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Waits while the build is stale and a run that started before this one is
|
|
381
|
+
* still live (`leaseDir`). It waits on a timer, so the event loop stays free
|
|
382
|
+
* and Ctrl-C still stops the run. Gives up after `limitMs`. Resolves to the runs still
|
|
383
|
+
* live when it gave up, or to none.
|
|
384
|
+
* @param {{entry: string, roots: readonly string[], generated?: readonly string[], leaseDir: string, isAlive?: (pid: number) => boolean, pid?: number, pollMs?: number, limitMs?: number}} options
|
|
385
|
+
* @returns {Promise<number[]>}
|
|
386
|
+
*/
|
|
387
|
+
export async function waitForEarlierRuns({
|
|
388
|
+
entry,
|
|
389
|
+
roots,
|
|
390
|
+
generated = [],
|
|
391
|
+
leaseDir,
|
|
392
|
+
isAlive,
|
|
393
|
+
pid,
|
|
394
|
+
pollMs = POLL_MS,
|
|
395
|
+
limitMs = EARLIER_RUN_WAIT_MS,
|
|
396
|
+
}) {
|
|
397
|
+
const deadline = Date.now() + limitMs;
|
|
398
|
+
let announced = false;
|
|
399
|
+
for (;;) {
|
|
400
|
+
if (!fs.existsSync(entry) || !coreBuildIsStale(entry, roots, generated)) {
|
|
401
|
+
return [];
|
|
402
|
+
}
|
|
403
|
+
const earlier = earlierLiveRuns(leaseDir, {pid, isAlive});
|
|
404
|
+
if (earlier.length === 0 || Date.now() >= deadline) {
|
|
405
|
+
return earlier;
|
|
406
|
+
}
|
|
407
|
+
if (!announced) {
|
|
408
|
+
console.warn(
|
|
409
|
+
`[ensure-core-built] Core changed; waiting up to ${Math.round(limitMs / 1000)} s for the test run already running in this checkout (pid ${earlier.join(', ')}) to end before rebuilding it.`,
|
|
410
|
+
);
|
|
411
|
+
announced = true;
|
|
412
|
+
}
|
|
413
|
+
await new Promise(resolve => setTimeout(resolve, pollMs));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* The node global setup's Core step: once the runs that started earlier have
|
|
419
|
+
* ended, a stale build is rebuilt. If one is still live at the limit, this run
|
|
420
|
+
* stops with an error naming it. Rebuilding would delete dist under that run,
|
|
421
|
+
* and testing the stale build would test old code.
|
|
422
|
+
* @param {{entry: string, roots: readonly string[], generated?: readonly string[], build: () => void, lockDir: string, leaseDir: string, isAlive?: (pid: number) => boolean, pid?: number, pollMs?: number, limitMs?: number}} options
|
|
423
|
+
*/
|
|
424
|
+
export async function ensureCoreBuiltForRunAt({
|
|
425
|
+
entry,
|
|
426
|
+
roots,
|
|
427
|
+
generated = [],
|
|
428
|
+
build,
|
|
429
|
+
lockDir,
|
|
430
|
+
leaseDir,
|
|
431
|
+
isAlive,
|
|
432
|
+
pid,
|
|
433
|
+
pollMs,
|
|
434
|
+
limitMs,
|
|
435
|
+
}) {
|
|
436
|
+
const stillLive = await waitForEarlierRuns({
|
|
437
|
+
entry,
|
|
438
|
+
roots,
|
|
439
|
+
generated,
|
|
440
|
+
leaseDir,
|
|
441
|
+
isAlive,
|
|
442
|
+
pid,
|
|
443
|
+
pollMs,
|
|
444
|
+
limitMs,
|
|
445
|
+
});
|
|
446
|
+
if (stillLive.length > 0) {
|
|
447
|
+
throw new Error(
|
|
448
|
+
`[ensure-core-built] Core's sources changed since packages/core/dist was built, and test run ${stillLive.join(', ')} in this checkout still uses that build after ${Math.round((limitMs ?? EARLIER_RUN_WAIT_MS) / 1000)} s: rebuilding would delete dist under it, and this run would test old code. Run again once it ends; if that process is not a test run, remove its lease: ${stillLive.map(pid => path.join(leaseDir, String(pid))).join(', ')}.`,
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
ensureCoreBuiltAt({
|
|
452
|
+
entry,
|
|
453
|
+
roots,
|
|
454
|
+
generated,
|
|
455
|
+
build,
|
|
456
|
+
lockDir,
|
|
457
|
+
rebuildStale: true,
|
|
458
|
+
pollMs,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* `ensureCoreBuiltForRunAt` for this checkout: the node global setup's step.
|
|
464
|
+
* @param {{limitMs?: number}} [options]
|
|
465
|
+
*/
|
|
466
|
+
export function ensureCoreBuiltForRun({limitMs} = {}) {
|
|
467
|
+
return ensureCoreBuiltForRunAt({
|
|
468
|
+
entry: CORE_BUILD_MARKER,
|
|
469
|
+
roots: CORE_SOURCES,
|
|
470
|
+
generated: CORE_GENERATED,
|
|
471
|
+
build: buildCore,
|
|
472
|
+
lockDir: LOCK_DIR,
|
|
473
|
+
leaseDir: RUN_LEASE_DIR,
|
|
474
|
+
limitMs,
|
|
475
|
+
});
|
|
120
476
|
}
|
|
@@ -383,6 +383,15 @@ export function providerLedgerOf(project) {
|
|
|
383
383
|
return PROVIDER_LEDGERS.get(project) ?? new Map();
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
+
/**
|
|
387
|
+
* True when an integration's templates root exists, the only place its
|
|
388
|
+
* templates come from (discoverIntegrationTemplatesForOne).
|
|
389
|
+
* @param {any} integration
|
|
390
|
+
* @returns {boolean}
|
|
391
|
+
*/
|
|
392
|
+
const hasTemplatesRoot = integration =>
|
|
393
|
+
integration?.templates != null && fs.existsSync(integration.templates);
|
|
394
|
+
|
|
386
395
|
/**
|
|
387
396
|
* The single API for reading resolved project configuration. Construct via the
|
|
388
397
|
* async {@link Project.load} factory.
|
|
@@ -1259,15 +1268,24 @@ export class Project {
|
|
|
1259
1268
|
* @returns {Promise<ProjectIntegrationIssue[]>}
|
|
1260
1269
|
*/
|
|
1261
1270
|
async issues() {
|
|
1262
|
-
//
|
|
1263
|
-
//
|
|
1264
|
-
//
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
+
// Each issue these passes find belongs to an integration, because Core's
|
|
1272
|
+
// templates and components declare no replacement. A project with no
|
|
1273
|
+
// integration skips them.
|
|
1274
|
+
if (this.#loadedIntegrations.length > 0) {
|
|
1275
|
+
// Template replacement validity depends on the combined Core +
|
|
1276
|
+
// integration catalog. Resolve it first so issue results never depend
|
|
1277
|
+
// on which discovery method the caller happened to invoke earlier. Only
|
|
1278
|
+
// an integration's own templates can replace one, so with none, Core's
|
|
1279
|
+
// templates stay unread.
|
|
1280
|
+
if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
|
|
1281
|
+
await this.templates();
|
|
1282
|
+
}
|
|
1283
|
+
// Component replacement validity likewise depends on Core plus every
|
|
1284
|
+
// integration's components.
|
|
1285
|
+
await this.componentReplacements();
|
|
1286
|
+
for (const integration of this.#loadedIntegrations) {
|
|
1287
|
+
await this.#collectIssues(integration);
|
|
1288
|
+
}
|
|
1271
1289
|
}
|
|
1272
1290
|
// Return a stable copy so callers can't mutate internal state.
|
|
1273
1291
|
return this.#issues.map(i => ({...i}));
|
|
@@ -7,6 +7,18 @@
|
|
|
7
7
|
* @returns {string | null}
|
|
8
8
|
*/
|
|
9
9
|
export function astryxCliRootOf(file: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* The executable files on the search path named one of `names`, in the order
|
|
12
|
+
* a shell tries them. In each folder, it takes the first name that is a file
|
|
13
|
+
* this user may run. Nothing is started.
|
|
14
|
+
* @param {readonly string[]} names
|
|
15
|
+
* @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
|
|
16
|
+
* @returns {string[]}
|
|
17
|
+
*/
|
|
18
|
+
export function executablesOnSearchPath(names: readonly string[], { searchPath, platform, }?: {
|
|
19
|
+
searchPath?: string;
|
|
20
|
+
platform?: NodeJS.Platform;
|
|
21
|
+
}): string[];
|
|
10
22
|
/**
|
|
11
23
|
* Every `astryx` command on the search path, in the order a shell tries
|
|
12
24
|
* them. The first row is the one that runs.
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* package folder is read from the shim's text.
|
|
14
14
|
*
|
|
15
15
|
* @input the search path and, on Windows, its executable names
|
|
16
|
-
* @output one row per `astryx` command found
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* @output one row per `astryx` command found, and the executable files that
|
|
17
|
+
* any command name finds there
|
|
18
|
+
* @position packages/cli/foundation/env — read by doctor, init --user, the
|
|
19
|
+
* update notices, and swizzle's `gh` lookup.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
import * as fs from 'node:fs';
|
|
@@ -146,6 +147,53 @@ function namesCliPackage(file) {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Whether `file` is a file this user may run. On Windows, any file counts.
|
|
152
|
+
* @param {string} file
|
|
153
|
+
* @param {boolean} windows
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
function isRunnableFile(file, windows) {
|
|
157
|
+
try {
|
|
158
|
+
if (!fs.statSync(file).isFile()) return false;
|
|
159
|
+
if (!windows) fs.accessSync(file, fs.constants.X_OK);
|
|
160
|
+
return true;
|
|
161
|
+
} catch {
|
|
162
|
+
// The shell skips a candidate the system cannot read: a missing folder, a
|
|
163
|
+
// stale mount, a symlink loop. `which` and execvp read PATH the same way.
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The executable files on the search path named one of `names`, in the order
|
|
170
|
+
* a shell tries them. In each folder, it takes the first name that is a file
|
|
171
|
+
* this user may run. Nothing is started.
|
|
172
|
+
* @param {readonly string[]} names
|
|
173
|
+
* @param {{searchPath?: string, platform?: NodeJS.Platform}} [options]
|
|
174
|
+
* @returns {string[]}
|
|
175
|
+
*/
|
|
176
|
+
export function executablesOnSearchPath(
|
|
177
|
+
names,
|
|
178
|
+
{
|
|
179
|
+
searchPath = process.env.PATH ?? process.env.Path ?? '',
|
|
180
|
+
platform = process.platform,
|
|
181
|
+
} = {},
|
|
182
|
+
) {
|
|
183
|
+
const windows = platform === 'win32';
|
|
184
|
+
/** @type {string[]} */
|
|
185
|
+
const files = [];
|
|
186
|
+
for (const dir of searchPath.split(windows ? ';' : path.delimiter)) {
|
|
187
|
+
if (!dir) continue;
|
|
188
|
+
// One command per folder: the shell runs the first name it finds.
|
|
189
|
+
const file = names
|
|
190
|
+
.map(name => path.join(dir, name))
|
|
191
|
+
.find(candidate => isRunnableFile(candidate, windows));
|
|
192
|
+
if (file !== undefined) files.push(file);
|
|
193
|
+
}
|
|
194
|
+
return files;
|
|
195
|
+
}
|
|
196
|
+
|
|
149
197
|
/**
|
|
150
198
|
* Every `astryx` command on the search path, in the order a shell tries
|
|
151
199
|
* them. The first row is the one that runs.
|
|
@@ -156,50 +204,30 @@ export function astryxCommandsOnSearchPath({
|
|
|
156
204
|
searchPath = process.env.PATH ?? process.env.Path ?? '',
|
|
157
205
|
platform = process.platform,
|
|
158
206
|
} = {}) {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
207
|
+
const names =
|
|
208
|
+
platform === 'win32'
|
|
209
|
+
? ['astryx.cmd', 'astryx.exe', 'astryx.ps1', 'astryx']
|
|
210
|
+
: [COMMAND];
|
|
163
211
|
/** @type {SearchPathCommand[]} */
|
|
164
212
|
const rows = [];
|
|
165
213
|
const seen = new Set();
|
|
166
|
-
for (const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
stat = fs.statSync(file);
|
|
173
|
-
} catch {
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (!stat.isFile()) continue;
|
|
177
|
-
if (!windows) {
|
|
178
|
-
try {
|
|
179
|
-
fs.accessSync(file, fs.constants.X_OK);
|
|
180
|
-
} catch {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
let key = file;
|
|
185
|
-
try {
|
|
186
|
-
key = fs.realpathSync(file);
|
|
187
|
-
} catch {
|
|
188
|
-
// Keep the path as found.
|
|
189
|
-
}
|
|
190
|
-
if (seen.has(key)) break;
|
|
191
|
-
seen.add(key);
|
|
192
|
-
const cliRoot = astryxCliRootOf(file);
|
|
193
|
-
rows.push({
|
|
194
|
-
file,
|
|
195
|
-
astryx: cliRoot !== null || namesCliPackage(file),
|
|
196
|
-
cliRoot,
|
|
197
|
-
version: cliRoot ? cliVersionAt(cliRoot) : null,
|
|
198
|
-
handsOff: cliRoot ? handsOffAt(cliRoot) : null,
|
|
199
|
-
});
|
|
200
|
-
// One command per folder: the shell runs the first name it finds.
|
|
201
|
-
break;
|
|
214
|
+
for (const file of executablesOnSearchPath(names, {searchPath, platform})) {
|
|
215
|
+
let key = file;
|
|
216
|
+
try {
|
|
217
|
+
key = fs.realpathSync(file);
|
|
218
|
+
} catch {
|
|
219
|
+
// Keep the path as found.
|
|
202
220
|
}
|
|
221
|
+
if (seen.has(key)) continue;
|
|
222
|
+
seen.add(key);
|
|
223
|
+
const cliRoot = astryxCliRootOf(file);
|
|
224
|
+
rows.push({
|
|
225
|
+
file,
|
|
226
|
+
astryx: cliRoot !== null || namesCliPackage(file),
|
|
227
|
+
cliRoot,
|
|
228
|
+
version: cliRoot ? cliVersionAt(cliRoot) : null,
|
|
229
|
+
handsOff: cliRoot ? handsOffAt(cliRoot) : null,
|
|
230
|
+
});
|
|
203
231
|
}
|
|
204
232
|
return rows;
|
|
205
233
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.9-canary.
|
|
3
|
+
"version": "0.7.9-canary.bfc1dcc",
|
|
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",
|
|
@@ -124,10 +124,10 @@
|
|
|
124
124
|
"zod": "^4.4.3"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@astryxdesign/charts": "0.7.9-canary.
|
|
128
|
-
"@astryxdesign/core": "0.7.9-canary.
|
|
129
|
-
"@astryxdesign/lab": "0.7.9-canary.
|
|
130
|
-
"@astryxdesign/theme-neutral": "0.7.9-canary.
|
|
127
|
+
"@astryxdesign/charts": "0.7.9-canary.bfc1dcc",
|
|
128
|
+
"@astryxdesign/core": "0.7.9-canary.bfc1dcc",
|
|
129
|
+
"@astryxdesign/lab": "0.7.9-canary.bfc1dcc",
|
|
130
|
+
"@astryxdesign/theme-neutral": "0.7.9-canary.bfc1dcc"
|
|
131
131
|
},
|
|
132
132
|
"peerDependenciesMeta": {
|
|
133
133
|
"@astryxdesign/charts": {
|
|
@@ -144,10 +144,10 @@
|
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
|
-
"@astryxdesign/charts": "0.7.9-canary.
|
|
148
|
-
"@astryxdesign/core": "0.7.9-canary.
|
|
149
|
-
"@astryxdesign/lab": "0.7.9-canary.
|
|
150
|
-
"@astryxdesign/theme-neutral": "0.7.9-canary.
|
|
147
|
+
"@astryxdesign/charts": "0.7.9-canary.bfc1dcc",
|
|
148
|
+
"@astryxdesign/core": "0.7.9-canary.bfc1dcc",
|
|
149
|
+
"@astryxdesign/lab": "0.7.9-canary.bfc1dcc",
|
|
150
|
+
"@astryxdesign/theme-neutral": "0.7.9-canary.bfc1dcc",
|
|
151
151
|
"@heroicons/react": "^2.2.0",
|
|
152
152
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
153
|
"@types/babel__core": "^7.20.5",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
-
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Check if `gh` CLI is installed and authenticated.
|
|
6
|
-
* Returns true if ready, false otherwise.
|
|
7
|
-
*/
|
|
8
|
-
export function checkGhCli(): boolean;
|
package/api/swizzle/_github.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file GitHub utilities for Astryx CLI
|
|
5
|
-
*
|
|
6
|
-
* Shared helpers for interacting with the GitHub CLI (`gh`).
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {execFileSync} from 'node:child_process';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Check if `gh` CLI is installed and authenticated.
|
|
13
|
-
* Returns true if ready, false otherwise.
|
|
14
|
-
*/
|
|
15
|
-
export function checkGhCli() {
|
|
16
|
-
try {
|
|
17
|
-
execFileSync('gh', ['auth', 'status'], {stdio: 'ignore'});
|
|
18
|
-
return true;
|
|
19
|
-
} catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|