@astryxdesign/cli 0.7.9-canary.de1be1f → 0.7.9-canary.dedecd0
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 +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +2 -2
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.d.mts +17 -1
- package/api/swizzle/copy/copy.mjs +249 -9
- package/api/swizzle/swizzle.doc.mjs +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/theme/build/build.mjs +21 -1
- package/assets/discover/official-packages.json +4 -0
- 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/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
- package/assets/templates/blocks/components/createPanGesture/PanPlayingCardVanilla.doc.mjs +14 -0
- package/assets/templates/blocks/components/createPanGesture/PanPlayingCardVanilla.tsx +156 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +143 -0
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/foundation/config/project.mjs +27 -9
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/release/cache.d.mts +11 -4
- package/foundation/release/cache.mjs +15 -7
- package/foundation/response/response-types.doc.mjs +1 -1
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -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,
|
|
@@ -56,10 +59,16 @@ const DEFAULT_ISSUES_URL = 'https://github.com/meta/astryx/issues/new';
|
|
|
56
59
|
*
|
|
57
60
|
* @param {string} content
|
|
58
61
|
* @param {string} [ownerPackage]
|
|
62
|
+
* @param {(importPath: string) => boolean} [keep] Imports to leave relative:
|
|
63
|
+
* the modules the copy carries in the same layout (see `sharedModulesOf`).
|
|
59
64
|
*/
|
|
60
|
-
export function rewriteImports(content, ownerPackage = CORE_PACKAGE) {
|
|
65
|
+
export function rewriteImports(content, ownerPackage = CORE_PACKAGE, keep = () => false) {
|
|
61
66
|
/** @param {string} importPath */
|
|
62
67
|
const mapTarget = importPath => {
|
|
68
|
+
// A module the copy carries beside the component keeps its relative path.
|
|
69
|
+
if (keep(importPath)) {
|
|
70
|
+
return importPath;
|
|
71
|
+
}
|
|
63
72
|
// Strip ALL leading `../` so a two-levels-up path never yields `<pkg>/..`.
|
|
64
73
|
const rest = importPath.replace(/^(?:\.\.\/)+/, '');
|
|
65
74
|
const parts = rest.split('/');
|
|
@@ -87,6 +96,153 @@ export function rewriteImports(content, ownerPackage = CORE_PACKAGE) {
|
|
|
87
96
|
);
|
|
88
97
|
}
|
|
89
98
|
|
|
99
|
+
/** A private data attribute's owner module (`architecture:public-component-api` INV23). */
|
|
100
|
+
const OWNER_MODULE = /^privateAttributes\/[^/]+\.stylex$/;
|
|
101
|
+
/** A StyleX module, with or without its file extension. */
|
|
102
|
+
const STYLEX_MODULE = /\.stylex(?:\.[cm]?[jt]sx?)?$/;
|
|
103
|
+
/** The extensions an extensionless import may name, in resolution order. */
|
|
104
|
+
const SOURCE_EXTENSIONS = ['.ts', '.tsx', '.mjs', '.js'];
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The relative import specifiers in a module's source.
|
|
108
|
+
* @param {string} content
|
|
109
|
+
* @returns {string[]}
|
|
110
|
+
*/
|
|
111
|
+
function relativeImportsOf(content) {
|
|
112
|
+
const found = [];
|
|
113
|
+
for (const re of [
|
|
114
|
+
/from\s+['"](\.\.?\/[^'"]+)['"]/g,
|
|
115
|
+
/import\(\s*['"](\.\.?\/[^'"]+)['"]/g,
|
|
116
|
+
]) {
|
|
117
|
+
for (const m of content.matchAll(re)) found.push(m[1]);
|
|
118
|
+
}
|
|
119
|
+
return found;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The source file an import resolves to under `srcRoot`, as a path relative to
|
|
124
|
+
* `srcRoot` without its extension (`privateAttributes/press.stylex`), and the
|
|
125
|
+
* file's own relative path; null when it resolves outside `srcRoot` or to no
|
|
126
|
+
* file.
|
|
127
|
+
* @param {string} srcRoot
|
|
128
|
+
* @param {string} fromDir directory of the importing file, relative to srcRoot
|
|
129
|
+
* @param {string} importPath
|
|
130
|
+
* @returns {{module: string, file: string} | null}
|
|
131
|
+
*/
|
|
132
|
+
function resolveSourceModule(srcRoot, fromDir, importPath) {
|
|
133
|
+
const module = path.posix.normalize(path.posix.join(fromDir, importPath));
|
|
134
|
+
if (module.startsWith('..') || path.posix.isAbsolute(module)) return null;
|
|
135
|
+
for (const ext of ['', ...SOURCE_EXTENSIONS]) {
|
|
136
|
+
const file = module + ext;
|
|
137
|
+
const abs = path.join(srcRoot, file);
|
|
138
|
+
if (fs.existsSync(abs) && fs.statSync(abs).isFile()) {
|
|
139
|
+
return {
|
|
140
|
+
module: ext ? module : module.replace(/\.[cm]?[jt]sx?$/, ''),
|
|
141
|
+
file,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The subpaths the owner package exports (`./theme/tokens.stylex`), read from
|
|
150
|
+
* the nearest package.json above its source root.
|
|
151
|
+
* @param {string} srcRoot
|
|
152
|
+
* @returns {Set<string>}
|
|
153
|
+
*/
|
|
154
|
+
function exportedSubpathsOf(srcRoot) {
|
|
155
|
+
let dir = srcRoot;
|
|
156
|
+
for (;;) {
|
|
157
|
+
const manifest = path.join(dir, 'package.json');
|
|
158
|
+
if (fs.existsSync(manifest)) {
|
|
159
|
+
try {
|
|
160
|
+
const {exports} = JSON.parse(fs.readFileSync(manifest, 'utf-8'));
|
|
161
|
+
return new Set(
|
|
162
|
+
exports && typeof exports === 'object' ? Object.keys(exports) : [],
|
|
163
|
+
);
|
|
164
|
+
} catch {
|
|
165
|
+
return new Set();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const parent = path.dirname(dir);
|
|
169
|
+
if (parent === dir) return new Set();
|
|
170
|
+
dir = parent;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The modules a copy carries beside the component, in the package's own
|
|
176
|
+
* layout under the output directory (`spec:AST-110` FR4): each private
|
|
177
|
+
* attribute owner module the component imports, and every unexported StyleX
|
|
178
|
+
* module such a carried module imports, transitively. The component's own
|
|
179
|
+
* imports of them, and theirs of each other, stay relative.
|
|
180
|
+
*
|
|
181
|
+
* @param {string} srcRoot the owner package's source root
|
|
182
|
+
* @param {string} componentDir
|
|
183
|
+
* @param {string[]} componentFiles files of the component that are copied
|
|
184
|
+
* @returns {Map<string, string>} module path (relative to srcRoot, no
|
|
185
|
+
* extension) -> its file path relative to srcRoot
|
|
186
|
+
*/
|
|
187
|
+
export function sharedModulesOf(srcRoot, componentDir, componentFiles) {
|
|
188
|
+
const exported = exportedSubpathsOf(srcRoot);
|
|
189
|
+
const componentRel = path
|
|
190
|
+
.relative(srcRoot, componentDir)
|
|
191
|
+
.split(path.sep)
|
|
192
|
+
.join('/');
|
|
193
|
+
/** @type {Map<string, string>} */
|
|
194
|
+
const carried = new Map();
|
|
195
|
+
/** @type {Array<{fromDir: string, content: string, owner: boolean}>} */
|
|
196
|
+
const queue = componentFiles
|
|
197
|
+
.filter(f => /\.[cm]?[jt]sx?$/.test(f))
|
|
198
|
+
.map(f => ({
|
|
199
|
+
fromDir: componentRel,
|
|
200
|
+
content: fs.readFileSync(path.join(componentDir, f), 'utf-8'),
|
|
201
|
+
owner: false,
|
|
202
|
+
}));
|
|
203
|
+
while (queue.length > 0) {
|
|
204
|
+
const {fromDir, content, owner} = /** @type {typeof queue[number]} */ (
|
|
205
|
+
queue.shift()
|
|
206
|
+
);
|
|
207
|
+
for (const importPath of relativeImportsOf(content)) {
|
|
208
|
+
const target = resolveSourceModule(srcRoot, fromDir, importPath);
|
|
209
|
+
if (target == null || carried.has(target.module)) continue;
|
|
210
|
+
if (target.module.startsWith(componentRel + '/')) continue;
|
|
211
|
+
const isOwner = OWNER_MODULE.test(target.module);
|
|
212
|
+
// A carried module's unexported StyleX dependency travels with it; a
|
|
213
|
+
// component's own imports of other modules are rewritten as before.
|
|
214
|
+
const isPrivateStyle =
|
|
215
|
+
owner &&
|
|
216
|
+
STYLEX_MODULE.test(target.module) &&
|
|
217
|
+
!exported.has(`./${target.module}`);
|
|
218
|
+
if (!isOwner && !isPrivateStyle) continue;
|
|
219
|
+
carried.set(target.module, target.file);
|
|
220
|
+
queue.push({
|
|
221
|
+
fromDir: path.posix.dirname(target.module),
|
|
222
|
+
content: fs.readFileSync(path.join(srcRoot, target.file), 'utf-8'),
|
|
223
|
+
owner: true,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return carried;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* A `keep` predicate for `rewriteImports`: true for an import that names one
|
|
232
|
+
* of the carried modules from a file in `fromDir`.
|
|
233
|
+
* @param {Map<string, string>} carried
|
|
234
|
+
* @param {string} fromDir relative to the source root
|
|
235
|
+
* @returns {(importPath: string) => boolean}
|
|
236
|
+
*/
|
|
237
|
+
function keepCarried(carried, fromDir) {
|
|
238
|
+
return importPath => {
|
|
239
|
+
const module = path.posix
|
|
240
|
+
.normalize(path.posix.join(fromDir, importPath))
|
|
241
|
+
.replace(/\.[cm]?[jt]sx?$/, '');
|
|
242
|
+
return carried.has(module);
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
90
246
|
/**
|
|
91
247
|
* Build the maintainer feedback note for a swizzled component.
|
|
92
248
|
* @param {string} component
|
|
@@ -299,6 +455,10 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
299
455
|
const outputBase = confineWrite(output, cwd, {label: 'output directory'});
|
|
300
456
|
const outputDir = path.join(outputBase, dirName);
|
|
301
457
|
|
|
458
|
+
// The receipt's feedback first: a swizzle that fails must fail before it
|
|
459
|
+
// writes anything.
|
|
460
|
+
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
461
|
+
|
|
302
462
|
// Pre-flight path and overwrite checks before any mkdir/writeFile.
|
|
303
463
|
const sourceFiles = fs.readdirSync(componentDir).filter(file => {
|
|
304
464
|
if (isExcludedFromCopy(file)) return false;
|
|
@@ -310,19 +470,64 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
310
470
|
label: 'output file',
|
|
311
471
|
});
|
|
312
472
|
}
|
|
473
|
+
// The owner modules the component imports, and their unexported StyleX
|
|
474
|
+
// dependencies, travel with it in the package's layout (spec:AST-110 FR4).
|
|
475
|
+
const srcRoot = path.dirname(componentDir);
|
|
476
|
+
const componentRel = path
|
|
477
|
+
.relative(srcRoot, componentDir)
|
|
478
|
+
.split(path.sep)
|
|
479
|
+
.join('/');
|
|
480
|
+
const carried = sharedModulesOf(srcRoot, componentDir, sourceFiles);
|
|
481
|
+
const shared = [...carried.values()].map(file => {
|
|
482
|
+
const content = rewriteImports(
|
|
483
|
+
fs.readFileSync(path.join(srcRoot, file), 'utf-8'),
|
|
484
|
+
owner.ownerPackage,
|
|
485
|
+
keepCarried(carried, path.posix.dirname(file)),
|
|
486
|
+
);
|
|
487
|
+
const dest = confineWrite(path.join(outputBase, file), cwd, {
|
|
488
|
+
allowAbsolute: true,
|
|
489
|
+
label: 'output file',
|
|
490
|
+
});
|
|
491
|
+
// Something that is not a readable file in its place counts as changed.
|
|
492
|
+
let existing = null;
|
|
493
|
+
if (fs.existsSync(dest)) {
|
|
494
|
+
try {
|
|
495
|
+
existing = fs.readFileSync(dest, 'utf-8');
|
|
496
|
+
} catch {
|
|
497
|
+
existing = '';
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// A copy another component's swizzle already wrote is reused when it is
|
|
501
|
+
// the same; a changed one is a file this run would overwrite.
|
|
502
|
+
return {
|
|
503
|
+
file,
|
|
504
|
+
dest,
|
|
505
|
+
content,
|
|
506
|
+
unchanged: existing === content,
|
|
507
|
+
exists: existing != null,
|
|
508
|
+
};
|
|
509
|
+
});
|
|
313
510
|
const existingFiles = sourceFiles.filter(f =>
|
|
314
511
|
fs.existsSync(path.join(outputDir, f)),
|
|
315
512
|
);
|
|
316
|
-
|
|
513
|
+
const changedShared = shared.filter(s => s.exists && !s.unchanged);
|
|
514
|
+
if ((existingFiles.length > 0 || changedShared.length > 0) && !overwrite) {
|
|
317
515
|
const relOutputForMsg = path.relative(cwd, outputDir) || '.';
|
|
516
|
+
const sharedNote =
|
|
517
|
+
changedShared.length > 0
|
|
518
|
+
? ` and ${changedShared.length} changed shared module(s) (${changedShared
|
|
519
|
+
.map(s => path.relative(cwd, s.dest))
|
|
520
|
+
.join(', ')})`
|
|
521
|
+
: '';
|
|
318
522
|
throw new AstryxError(
|
|
319
|
-
`Refusing to overwrite ${existingFiles.length} existing file(s) in ${relOutputForMsg}
|
|
523
|
+
`Refusing to overwrite ${existingFiles.length} existing file(s) in ${relOutputForMsg}/${sharedNote}. ` +
|
|
320
524
|
`Re-run with --overwrite (or -f) to replace them.`,
|
|
321
525
|
[],
|
|
322
526
|
ERROR_CODES.ERR_FILE_EXISTS,
|
|
323
527
|
);
|
|
324
528
|
}
|
|
325
529
|
|
|
530
|
+
|
|
326
531
|
const outputDirExisted = fs.existsSync(outputDir);
|
|
327
532
|
try {
|
|
328
533
|
fs.mkdirSync(outputDir, {recursive: true});
|
|
@@ -344,7 +549,7 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
344
549
|
if (!fs.statSync(srcPath).isFile()) continue;
|
|
345
550
|
let content = fs.readFileSync(srcPath, 'utf-8');
|
|
346
551
|
if (file.endsWith('.ts') || file.endsWith('.tsx')) {
|
|
347
|
-
content = rewriteImports(content, owner.ownerPackage);
|
|
552
|
+
content = rewriteImports(content, owner.ownerPackage, keepCarried(carried, componentRel));
|
|
348
553
|
}
|
|
349
554
|
if (
|
|
350
555
|
(file.endsWith('.ts') || file.endsWith('.tsx')) &&
|
|
@@ -374,21 +579,56 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
374
579
|
copied++;
|
|
375
580
|
}
|
|
376
581
|
|
|
582
|
+
/** @type {string[]} folders this run created for carried modules, outermost first */
|
|
583
|
+
const createdDirs = [];
|
|
584
|
+
for (const module of shared) {
|
|
585
|
+
// An identical copy is already in place: it is part of this copy, unwritten.
|
|
586
|
+
if (module.unchanged) {
|
|
587
|
+
copied++;
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
const original = fs.existsSync(module.dest)
|
|
592
|
+
? fs.readFileSync(module.dest)
|
|
593
|
+
: null;
|
|
594
|
+
const firstCreated = fs.mkdirSync(path.dirname(module.dest), {recursive: true});
|
|
595
|
+
if (firstCreated != null) createdDirs.push(firstCreated);
|
|
596
|
+
written.push({dest: module.dest, original});
|
|
597
|
+
fs.writeFileSync(module.dest, module.content);
|
|
598
|
+
copied++;
|
|
599
|
+
} catch (err) {
|
|
600
|
+
const unrestored = undoCopy(written);
|
|
601
|
+
// Remove the folders this run created, as a failed component-file write
|
|
602
|
+
// does, so a retry finds the output as it was.
|
|
603
|
+
for (const dir of [...createdDirs].reverse()) {
|
|
604
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
605
|
+
}
|
|
606
|
+
if (!outputDirExisted) {
|
|
607
|
+
fs.rmSync(outputDir, {recursive: true, force: true});
|
|
608
|
+
}
|
|
609
|
+
throw writeFailed(module.dest, cwd, err, unrestored);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (shared.length > 0) usesStyleX = true;
|
|
613
|
+
|
|
377
614
|
const relOutput = path.relative(cwd, outputDir);
|
|
378
615
|
const copiedFiles = files.filter(
|
|
379
616
|
f =>
|
|
380
617
|
!isExcludedFromCopy(f) &&
|
|
381
618
|
fs.statSync(path.join(componentDir, f)).isFile(),
|
|
382
619
|
);
|
|
383
|
-
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
384
|
-
|
|
385
620
|
/** @type {import('../swizzle.type.mjs').SwizzleCopyResponse['data']} */
|
|
386
621
|
const data = {
|
|
387
622
|
component: dirName,
|
|
388
623
|
package: owner.package,
|
|
389
624
|
outputDir: relOutput,
|
|
390
625
|
filesCopied: copied,
|
|
391
|
-
|
|
626
|
+
// The owner modules and their unexported style dependencies the copy
|
|
627
|
+
// carries beside the component (spec:AST-110 FR4) are its files too.
|
|
628
|
+
files: [
|
|
629
|
+
...copiedFiles.map(f => f),
|
|
630
|
+
...shared.map(m => path.relative(outputDir, m.dest).split(path.sep).join('/')),
|
|
631
|
+
],
|
|
392
632
|
usesStyleX,
|
|
393
633
|
};
|
|
394
634
|
if (feedback) data.feedback = feedback;
|
|
@@ -76,7 +76,7 @@ export const doc = {
|
|
|
76
76
|
{
|
|
77
77
|
type: 'swizzle.copy',
|
|
78
78
|
description:
|
|
79
|
-
'A receipt after copying the component into the project: the component name, owning package, output directory, files-copied count, the
|
|
79
|
+
'A receipt after copying the component into the project: the component name, owning package, output directory, files-copied count, the copied file names (relative to the component folder, including the private attribute owner modules and their unexported style modules copied beside it, e.g. `../privateAttributes/press.stylex.ts`), whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling.',
|
|
80
80
|
},
|
|
81
81
|
],
|
|
82
82
|
throws: [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* @property {string} data.package Owner package the component source was copied from.
|
|
35
35
|
* @property {string} data.outputDir
|
|
36
36
|
* @property {number} data.filesCopied
|
|
37
|
-
* @property {string[]} data.files
|
|
37
|
+
* @property {string[]} data.files Copied file names, relative to the component folder; owner modules and their unexported style modules copied beside it start with `../` (spec:AST-110 FR4).
|
|
38
38
|
* @property {boolean} data.usesStyleX Whether any copied file uses StyleX (requires build-time setup).
|
|
39
39
|
* @property {SwizzleFeedback} [data.feedback]
|
|
40
40
|
*/
|
|
@@ -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',
|