@astryxdesign/cli 0.7.9-canary.b215c3e → 0.7.9-canary.b779b26
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/discover/_adapter.d.mts +1 -1
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_result.d.mts +5 -5
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/search/search.d.mts +1 -1
- 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 +50 -2
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +29 -0
- package/assets/docs/motion.doc.mjs +1 -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/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
- 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/PowerSearch/PowerSearchContentSearch.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchPresetFilters.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx +12 -10
- package/assets/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx +8 -7
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
- package/assets/templates/pages/table-inbox/page.tsx +11 -8
- package/assets/templates/pages/work-item-detail/page.tsx +6 -2
- package/assets/theme.template.ts +11 -2
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/base/type.ts +41 -0
- package/authoring/doctypes/component/component.doc.mjs +7 -1
- package/authoring/doctypes/component/type.ts +5 -0
- package/authoring/index.d.ts +2 -0
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/clients/cli/index.mjs +11 -6
- package/clients/cli/lib/component-format.mjs +49 -0
- package/foundation/agent-docs/agent-docs-target.d.mts +49 -0
- package/foundation/agent-docs/agent-docs-target.mjs +201 -0
- package/foundation/agent-docs/agent-docs.d.mts +1 -38
- package/foundation/agent-docs/agent-docs.mjs +16 -181
- package/foundation/config/config-path.d.mts +13 -0
- package/foundation/config/config-path.mjs +42 -0
- package/foundation/config/project.d.mts +1 -10
- package/foundation/config/project.mjs +31 -35
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/icon-set-paths.d.mts +18 -0
- package/foundation/discovery/icon-set-paths.mjs +23 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -7
- package/foundation/discovery/icon-set-writer.mjs +3 -12
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/fs/module-loader.d.mts +2 -8
- package/foundation/fs/module-loader.mjs +3 -12
- package/foundation/fs/present-files.d.mts +11 -0
- package/foundation/fs/present-files.mjs +25 -0
- package/foundation/integrations/autolink.d.mts +2 -21
- package/foundation/integrations/autolink.mjs +6 -42
- package/foundation/integrations/contribution-fixes.mjs +26 -3
- package/foundation/integrations/contribution-inventory.mjs +1 -1
- package/foundation/integrations/installed-package.d.mts +36 -0
- package/foundation/integrations/installed-package.mjs +57 -0
- package/foundation/integrations/integrations.d.mts +3 -75
- package/foundation/integrations/integrations.mjs +3 -16
- package/foundation/integrations/manifest-paths.d.mts +13 -0
- package/foundation/integrations/manifest-paths.mjs +31 -0
- 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/runtime/locked-versions.mjs +1 -1
- package/foundation/runtime/package-set.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
|
@@ -25,8 +25,24 @@
|
|
|
25
25
|
*
|
|
26
26
|
* @param {string} content
|
|
27
27
|
* @param {string} [ownerPackage]
|
|
28
|
+
* @param {(importPath: string) => boolean} [keep] Imports to leave relative:
|
|
29
|
+
* the modules the copy carries in the same layout (see `sharedModulesOf`).
|
|
28
30
|
*/
|
|
29
|
-
export function rewriteImports(content: string, ownerPackage?: string): string;
|
|
31
|
+
export function rewriteImports(content: string, ownerPackage?: string, keep?: (importPath: string) => boolean): string;
|
|
32
|
+
/**
|
|
33
|
+
* The modules a copy carries beside the component, in the package's own
|
|
34
|
+
* layout under the output directory (`spec:AST-110` FR4): each private
|
|
35
|
+
* attribute owner module the component imports, and every unexported StyleX
|
|
36
|
+
* module such a carried module imports, transitively. The component's own
|
|
37
|
+
* imports of them, and theirs of each other, stay relative.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} srcRoot the owner package's source root
|
|
40
|
+
* @param {string} componentDir
|
|
41
|
+
* @param {string[]} componentFiles files of the component that are copied
|
|
42
|
+
* @returns {Map<string, string>} module path (relative to srcRoot, no
|
|
43
|
+
* extension) -> its file path relative to srcRoot
|
|
44
|
+
*/
|
|
45
|
+
export function sharedModulesOf(srcRoot: string, componentDir: string, componentFiles: string[]): Map<string, string>;
|
|
30
46
|
/**
|
|
31
47
|
* Copy one component's source into the consumer project for customization,
|
|
32
48
|
* rewriting escaping relative imports to the owner package's subpaths.
|
|
@@ -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
|
*/
|
|
@@ -2198,6 +2198,17 @@ function iconNodesExpression(entries, entriesName, nodesName) {
|
|
|
2198
2198
|
})()`;
|
|
2199
2199
|
}
|
|
2200
2200
|
|
|
2201
|
+
/**
|
|
2202
|
+
* A theme's component icon slot values: a theme from defineTheme keeps them
|
|
2203
|
+
* in `__componentIcons` when any is a function (its `componentIcons` is the
|
|
2204
|
+
* static view); otherwise `componentIcons` holds them.
|
|
2205
|
+
* @param {any} theme
|
|
2206
|
+
* @returns {Record<string, unknown> | undefined}
|
|
2207
|
+
*/
|
|
2208
|
+
function themeComponentIcons(theme) {
|
|
2209
|
+
return theme?.__componentIcons ?? theme?.componentIcons;
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2201
2212
|
/**
|
|
2202
2213
|
* Generate a minimal JS module for a built theme.
|
|
2203
2214
|
* Includes the theme name, marker, and re-exports the icon registry.
|
|
@@ -2224,6 +2235,9 @@ function iconNodesExpression(entries, entriesName, nodesName) {
|
|
|
2224
2235
|
* renders, and the theme's `icons` and the re-exported registry are the node
|
|
2225
2236
|
* view, each function read at `{size: 'md'}` as `DefinedTheme['icons']` is.
|
|
2226
2237
|
*
|
|
2238
|
+
* Component icon slot values are names, `null`, and requests, written as
|
|
2239
|
+
* JSON. A slot function cannot be serialized, so it fails the build.
|
|
2240
|
+
*
|
|
2227
2241
|
* @param {any} themeDef
|
|
2228
2242
|
* @param {import('./icon-imports.mjs').IconImports | null} iconInfo
|
|
2229
2243
|
* @param {string} [iconsSpecifier] - Overrides the selected registry specifier.
|
|
@@ -2295,6 +2309,19 @@ function generateBuiltModule(
|
|
|
2295
2309
|
: `\nexport { ${iconInfo.exportName} };\n`
|
|
2296
2310
|
: '';
|
|
2297
2311
|
|
|
2312
|
+
const componentIcons = themeComponentIcons(themeDef);
|
|
2313
|
+
const slotFunction = Object.entries(componentIcons ?? {}).find(
|
|
2314
|
+
([, value]) => typeof value === 'function',
|
|
2315
|
+
);
|
|
2316
|
+
if (slotFunction) {
|
|
2317
|
+
throw new AstryxError(
|
|
2318
|
+
`Theme "${themeDef.name}" sets componentIcons["${slotFunction[0]}"] to a slot function, which a built theme cannot carry. ` +
|
|
2319
|
+
'A built theme keeps names, null, and requests. Use one of those, or apply the source theme at runtime.',
|
|
2320
|
+
undefined,
|
|
2321
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
2322
|
+
);
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2298
2325
|
// Resolve token values — tuples become light-dark() strings
|
|
2299
2326
|
/** @type {Record<string, unknown>} */
|
|
2300
2327
|
const resolvedTokens = {};
|
|
@@ -2365,7 +2392,8 @@ function generateBuiltModule(
|
|
|
2365
2392
|
list ?? [],
|
|
2366
2393
|
]),
|
|
2367
2394
|
),
|
|
2368
|
-
)
|
|
2395
|
+
) +
|
|
2396
|
+
serializeField('componentIcons', componentIcons, true);
|
|
2369
2397
|
|
|
2370
2398
|
return `${iconImport}${iconDeclaration}${iconNodesDeclaration}/**
|
|
2371
2399
|
* ${themeDef.name} theme — built by \`${getCliInvocation()} theme build\`
|
|
@@ -2844,12 +2872,29 @@ async function themeBuildInternal(
|
|
|
2844
2872
|
let themeExportName;
|
|
2845
2873
|
/** Paths through the load that interception could not fully observe. */
|
|
2846
2874
|
let loadDegradation;
|
|
2875
|
+
/**
|
|
2876
|
+
* The theme file's bytes as loaded: read before and after the load, and the
|
|
2877
|
+
* registry scan below reads these rather than the file again. An editor's
|
|
2878
|
+
* in-place save truncates before it writes, so a later read can find an
|
|
2879
|
+
* empty file the load never saw; a file that changed while it loaded is not
|
|
2880
|
+
* built from.
|
|
2881
|
+
* @type {string}
|
|
2882
|
+
*/
|
|
2883
|
+
let themeSource;
|
|
2847
2884
|
try {
|
|
2885
|
+
const before = fs.readFileSync(filePath, 'utf8');
|
|
2848
2886
|
const loaded = await extractThemeDefinition(
|
|
2849
2887
|
filePath,
|
|
2850
2888
|
interception,
|
|
2851
2889
|
options.__familyLoader,
|
|
2852
2890
|
);
|
|
2891
|
+
const after = fs.readFileSync(filePath, 'utf8');
|
|
2892
|
+
if (before !== after || before === '') {
|
|
2893
|
+
throw new Error(
|
|
2894
|
+
`${filePath} changed while it was loading. Build again once it is saved.`,
|
|
2895
|
+
);
|
|
2896
|
+
}
|
|
2897
|
+
themeSource = before;
|
|
2853
2898
|
themeDef = loaded.theme;
|
|
2854
2899
|
themeExportName = loaded.exportName;
|
|
2855
2900
|
loadDegradation = loaded.degraded;
|
|
@@ -2939,7 +2984,10 @@ async function themeBuildInternal(
|
|
|
2939
2984
|
: []),
|
|
2940
2985
|
];
|
|
2941
2986
|
const iconResolution = {
|
|
2942
|
-
readSource: (/** @type {string} */ file) =>
|
|
2987
|
+
readSource: (/** @type {string} */ file) =>
|
|
2988
|
+
path.resolve(file) === path.resolve(filePath)
|
|
2989
|
+
? themeSource
|
|
2990
|
+
: fs.readFileSync(file, 'utf8'),
|
|
2943
2991
|
resolveModule: resolveThemeModule,
|
|
2944
2992
|
reservedNames: reservedNames(functionEntries),
|
|
2945
2993
|
functionEntries,
|
|
@@ -41,7 +41,7 @@ export const docs = {
|
|
|
41
41
|
['typography.scale', '--text-heading-*-size/weight/leading, --text-body-size/weight/leading', 'base (px), ratio'],
|
|
42
42
|
['typography.body/heading/code', '--font-family-body, --font-family-heading, --font-family-code', 'family, fallbacks?, url?, weight?'],
|
|
43
43
|
['radius', '--radius-inner, --radius-element, --radius-container, --radius-page, --radius-chat', 'base (px), multiplier (0–2)'],
|
|
44
|
-
['motion', 'Every --duration-* token, --ease-entrance and --ease-move (
|
|
44
|
+
['motion', 'Every --duration-* token, --ease-entrance and --ease-move (tempo also times the touch springs)', 'tempo? (0.75–1.5), character? (crisp|standard|expressive); and/or a duration scale: fast (ms), medium (ms), ratio, slow?, easing?. The scale wins over tempo for the durations it sets, and explicit tokens win over both. Fixed whatever the knobs say: drags and momentum, rubber band, keyboard, press onset/cancel/flash, hover intent, gesture thresholds, Spinner/Skeleton loops, the 200 ms Reduce Motion cap. See {@link generic:motion}.'],
|
|
45
45
|
]},
|
|
46
46
|
{type: 'prose', text: 'For dark mode tuples in token values, see the Dark mode section of {@link generic:use-a-theme}.'},
|
|
47
47
|
],
|
|
@@ -56,6 +56,7 @@ export const docs = {
|
|
|
56
56
|
['components', 'Deep-merged: child component rules override matching keys from the base.'],
|
|
57
57
|
['icons', 'Shallow-merged: child icons override matching names from the base.'],
|
|
58
58
|
['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
|
|
59
|
+
['componentIcons', 'Merged by slot: a child entry replaces the base entry for that slot whole; an omitted or undefined entry keeps the inherited one.'],
|
|
59
60
|
['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
|
|
60
61
|
['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
|
|
61
62
|
['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio. Each knob (`tempo`, `character`) the child leaves unset keeps the base's."],
|
|
@@ -138,6 +139,7 @@ export const docs = {
|
|
|
138
139
|
{type: 'prose', text: 'Keep `react` and the icon library external so the registry does not bundle its own copies of those dependencies.'},
|
|
139
140
|
{type: 'prose', text: "A registry entry can be a function of `{size, variant}`. The built theme keeps the function, so `Icon` asks it for the size and variant it renders, as the runtime theme does, including for entries inherited from a built or package theme. The built theme's `icons` field and the registry its module re-exports are React nodes, with each function read at size `md`. A function written in the theme file itself cannot be carried, so the build fails; move it into the registry module."},
|
|
140
141
|
{type: 'prose', text: "A theme that lists `iconVariants` also writes an `IconVariantMap` augmentation into `<theme>.variants.d.ts`, so `Icon`'s `variant` accepts those names wherever the theme's types load. Its declaration carries the list too, so a theme that extends the built theme types `variant` in its icon entries by that list."},
|
|
142
|
+
{type: 'prose', text: "A built theme keeps its `componentIcons` names, `null` values, and static requests, so component slots resolve the same for the built theme as for the runtime theme. A slot function cannot be written into the module, so a theme with one fails the build: use a static value, or apply the source theme at runtime."},
|
|
141
143
|
],
|
|
142
144
|
},
|
|
143
145
|
{
|
|
@@ -214,5 +214,34 @@ export const brandTheme = defineTheme({
|
|
|
214
214
|
},
|
|
215
215
|
],
|
|
216
216
|
},
|
|
217
|
+
{
|
|
218
|
+
title: 'Component Icon Slots',
|
|
219
|
+
category: 'foundations',
|
|
220
|
+
content: [
|
|
221
|
+
{
|
|
222
|
+
type: 'prose',
|
|
223
|
+
text: "A component icon slot names why an icon appears in one component, such as `code-block-copy` for CodeBlock's copy button. `defineTheme({componentIcons})` maps a slot to one of the shared icon names. A theme can then change the icon one component uses without changing that name's artwork everywhere; `icons` still chooses the artwork for each name. Each component's docs list its slots, their state, and their fallbacks (`astryx component CodeBlock`).",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
type: 'code',
|
|
227
|
+
lang: 'tsx',
|
|
228
|
+
label: 'Mapping a slot, with its state',
|
|
229
|
+
code: `export const brandTheme = defineTheme({
|
|
230
|
+
name: 'brand',
|
|
231
|
+
componentIcons: {
|
|
232
|
+
'code-block-copy': ({copied}) => ({icon: copied ? 'checkDouble' : 'copy'}),
|
|
233
|
+
},
|
|
234
|
+
});`,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
type: 'prose',
|
|
238
|
+
text: "A slot value is a shared icon name, `null` to hide the icon, or a partial request of `icon`, `variant`, and `size`. A field the request leaves out keeps the component's own value. A slot with state also accepts a pure, synchronous function of that state that returns a request: returning `null` hides the icon, and returning `undefined` changes nothing. A request `size` changes only the icon, never the control around it. Icon content a component's caller passes wins over the slot.",
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
type: 'prose',
|
|
242
|
+
text: "An unknown icon name, a variant the theme does not list, or a size other than `xsm`, `sm`, `md`, or `lg` is ignored for that field, with one development warning. A theme that extends another merges `componentIcons` by slot ({@link generic:author-a-theme}). `theme.componentIcons` reads back names, `null` values, and static requests, and leaves out the slots a function resolves.",
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
},
|
|
217
246
|
],
|
|
218
247
|
};
|
|
@@ -150,7 +150,7 @@ const styles = stylex.create({
|
|
|
150
150
|
content: [
|
|
151
151
|
{
|
|
152
152
|
type: 'prose',
|
|
153
|
-
text: "A theme sets how motion feels with two knobs in `defineTheme`'s `motion`. They drive the CSS motion tokens
|
|
153
|
+
text: "A theme sets how motion feels with two knobs in `defineTheme`'s `motion`. They drive the CSS motion tokens, and `tempo` also times the springs of touch motion; those springs don't follow `character` yet. Every theme follows each person's Reduce Motion setting; no theme loosens it.",
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
type: 'list',
|