@astryxdesign/cli 0.7.11-canary.ec945c9 → 0.7.11

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/api/build/kit/rank.mjs +4 -21
  3. package/api/build/kit/words.d.mts +0 -1
  4. package/api/build/kit/words.mjs +1 -1
  5. package/api/icon/_adapter.d.mts +2 -3
  6. package/api/icon/_adapter.mjs +2 -8
  7. package/api/icon/_authoring.d.mts +0 -1
  8. package/api/icon/_authoring.mjs +66 -586
  9. package/api/icon/_records.d.mts +1 -1
  10. package/api/icon/_records.mjs +0 -1
  11. package/api/icon/add/add.mjs +38 -224
  12. package/api/icon/icon.type.d.mts +2 -22
  13. package/api/icon/icon.type.mjs +2 -6
  14. package/api/icon/iconAdd.doc.mjs +2 -2
  15. package/api/icon/iconNewDefinition.doc.mjs +2 -3
  16. package/api/icon/iconNewSet.doc.mjs +4 -4
  17. package/api/icon/search/search.mjs +9 -10
  18. package/api/integration/add-helpers.d.mts +1 -11
  19. package/api/integration/add-helpers.mjs +2 -5
  20. package/api/integration/authoring-checks.d.mts +2 -0
  21. package/api/integration/authoring-checks.mjs +6 -1
  22. package/api/logger.mjs +1 -2
  23. package/api/swizzle/_adapter.d.mts +0 -1
  24. package/api/swizzle/_adapter.mjs +1 -4
  25. package/api/swizzle/copy/copy.d.mts +43 -2
  26. package/api/swizzle/copy/copy.mjs +314 -194
  27. package/api/swizzle/swizzle.d.mts +2 -0
  28. package/api/swizzle/swizzle.doc.mjs +4 -8
  29. package/api/swizzle/swizzle.mjs +7 -3
  30. package/api/swizzle/swizzle.type.d.mts +1 -1
  31. package/api/swizzle/swizzle.type.mjs +2 -2
  32. package/assets/discover/official-packages.json +0 -12
  33. package/assets/docs/tree/icon-sets.doc.mjs +5 -11
  34. package/assets/templates/pages/file-explorer/page.tsx +79 -103
  35. package/assets/templates/pages/table-grouped/page.tsx +232 -160
  36. package/assets/templates/pages/table-grouped/template.doc.mjs +2 -0
  37. package/assets/templates/pages/theme-showcase/page.tsx +792 -724
  38. package/assets/templates/pages/theme-showcase/template.doc.mjs +5 -4
  39. package/clients/cli/commands/experimental/icon.mjs +10 -31
  40. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  41. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -2
  42. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  43. package/clients/cli/commands/swizzle.doc.mjs +3 -6
  44. package/clients/cli/commands/swizzle.mjs +9 -8
  45. package/foundation/discovery/component-loader.d.mts +1 -1
  46. package/foundation/discovery/doc-types.mjs +2 -9
  47. package/foundation/discovery/icon-ranking.d.mts +3 -27
  48. package/foundation/discovery/icon-ranking.mjs +8 -125
  49. package/foundation/discovery/icon-set-checks.mjs +35 -44
  50. package/foundation/discovery/icon-set-discovery.d.mts +0 -13
  51. package/foundation/discovery/icon-set-discovery.mjs +0 -25
  52. package/foundation/discovery/icon-set-writer.d.mts +16 -238
  53. package/foundation/discovery/icon-set-writer.mjs +79 -676
  54. package/foundation/discovery/module-exports.d.mts +2 -3
  55. package/foundation/discovery/module-exports.mjs +37 -167
  56. package/foundation/fs/paths.d.mts +1 -2
  57. package/foundation/fs/paths.mjs +4 -3
  58. package/package.json +6 -6
  59. package/api/icon/_default-look.d.mts +0 -155
  60. package/api/icon/_default-look.mjs +0 -474
  61. package/api/swizzle/_moduleGraph.d.mts +0 -162
  62. package/api/swizzle/_moduleGraph.mjs +0 -754
  63. package/foundation/text/shell-arg.d.mts +0 -14
  64. package/foundation/text/shell-arg.mjs +0 -17
@@ -1,474 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file The one rule for an icon set's default variant: it is the look each
5
- * icon's own export draws.
6
- * @input the set's data and generated module, the wrapped library's look
7
- * words, and the variants and default variant a command names
8
- * @output the variants and default variant to write, or an AstryxError that
9
- * names the library's look words, the command that moves the look, or the
10
- * variant to add when the library's names name no looks
11
- * @position used by `new-set` (create, refresh, in place) and by
12
- * `add --variant` (one icon or `--all`); every command that writes or keeps
13
- * `default.variant`, or adds a look, asks this module first
14
- */
15
-
16
- import {AstryxError} from '../error.mjs';
17
- import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
18
- import {
19
- generatedModulePath,
20
- generatedOrigins,
21
- iconIdOf,
22
- preferredLook,
23
- sameIconModule,
24
- splitLook,
25
- } from '../../foundation/discovery/icon-set-writer.mjs';
26
- import {shellArg} from '../../foundation/text/shell-arg.mjs';
27
-
28
- /**
29
- * The variants and default variant a command declares.
30
- * @typedef {object} Looks
31
- * @property {string[]} variants
32
- * @property {string} default
33
- * @property {boolean} [named] whether `--default-variant` named the default
34
- */
35
-
36
- /**
37
- * What a set's icons draw now, read from the look words of the library
38
- * exports its generated module re-exports.
39
- * @typedef {object} DrawnLooks
40
- * @property {string} module the library most of the set's icons come from
41
- * @property {Array<Set<string>>} positions that library's look positions,
42
- * the last word of a name first; empty when its names encode no looks
43
- * @property {Array<string | null>} words the word most icons' exports have
44
- * at each position
45
- * @property {number} icons how many of the set's icons come from it
46
- */
47
-
48
- /**
49
- * @typedef {import('../../foundation/discovery/icon-set-discovery.mjs').DiscoveredIconSet} LookSet
50
- */
51
-
52
- /**
53
- * A library's look words in the order its names write them, one position
54
- * after another: `filled or outline; 24; wght300, wght400, wght500`.
55
- * @param {string[][]} positions each position's words, sorted, the last
56
- * word of a name first
57
- */
58
- export function describedLooks(positions) {
59
- return [...positions]
60
- .reverse()
61
- .map(words =>
62
- words.length > 3
63
- ? `${words[0]} to ${words.at(-1)}`
64
- : words.join(words.length === 2 ? ' or ' : ', '),
65
- )
66
- .join('; ');
67
- }
68
-
69
- /** @param {Array<Set<string>>} positions */
70
- const sortedWords = positions =>
71
- positions.map(position => [...position].sort());
72
-
73
- /**
74
- * The words of the positions that name a style (`filled`, `outline`), not
75
- * only numbers (`24`, `wght400`): the words a variant is usually named by.
76
- * @param {Array<Set<string>>} positions
77
- */
78
- function styleWords(positions) {
79
- return sortedWords(positions)
80
- .filter(words => words.some(word => !/^[a-z]*\d+$/u.test(word)))
81
- .reverse()
82
- .flat();
83
- }
84
-
85
- /**
86
- * The look the set's icons draw at the first position, in name order, whose
87
- * drawn word is one of `among`; else at the first style position.
88
- * @param {Array<Set<string>>} positions
89
- * @param {Array<string | null>} words the drawn word at each position
90
- * @param {string[]} [among]
91
- * @returns {string | null}
92
- */
93
- function drawnWord(positions, words, among = []) {
94
- for (let index = positions.length - 1; index >= 0; index--) {
95
- const word = words[index];
96
- if (word != null && among.includes(word)) return word;
97
- }
98
- for (let index = positions.length - 1; index >= 0; index--) {
99
- const word = words[index];
100
- if (
101
- word != null &&
102
- [...positions[index]].some(w => !/^[a-z]*\d+$/u.test(w))
103
- )
104
- return word;
105
- }
106
- return null;
107
- }
108
-
109
- /**
110
- * What the set's icons draw now ({@link DrawnLooks}), or null when no icon
111
- * re-exports a named library export.
112
- * @param {LookSet} set
113
- * @param {string} packageDir
114
- * @param {(module: string) => Array<Set<string>> | null} positionsOf the
115
- * look positions of a library the set's generated module names
116
- * @param {{module?: string}} [options] `module`: read only the icons that
117
- * come from this library
118
- * @returns {DrawnLooks | null}
119
- */
120
- export function drawnLooks(set, packageDir, positionsOf, options = {}) {
121
- const origins = generatedOrigins(
122
- packageDir,
123
- generatedModulePath(set, packageDir),
124
- );
125
- /** @type {Map<string, string[]>} */
126
- const byModule = new Map();
127
- for (const icon of set.data.icons) {
128
- if ((icon.module ?? set.data.module) !== set.data.module) continue;
129
- const origin = origins.get(icon.export);
130
- if (!origin || origin.source === 'default') continue;
131
- if (
132
- options.module != null &&
133
- !sameIconModule(origin.module, options.module)
134
- )
135
- continue;
136
- const sources = byModule.get(origin.module) ?? [];
137
- sources.push(origin.source);
138
- byModule.set(origin.module, sources);
139
- }
140
- const ranked = [...byModule].sort(
141
- (a, b) =>
142
- b[1].length - a[1].length || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0),
143
- );
144
- if (ranked.length === 0) return null;
145
- for (const [module, sources] of ranked) {
146
- const positions = positionsOf(module) ?? [];
147
- if (positions.length === 0) continue;
148
- /** @type {Array<Map<string, number>>} */
149
- const counts = positions.map(() => new Map());
150
- for (const source of sources) {
151
- const {look} = splitLook(iconIdOf(source).split('-'), positions);
152
- look.forEach((word, index) => {
153
- if (word != null) {
154
- counts[index].set(word, (counts[index].get(word) ?? 0) + 1);
155
- }
156
- });
157
- }
158
- const words = counts.map(count => {
159
- /** @type {string | null} */
160
- let best = null;
161
- let most = 0;
162
- for (const [word, n] of [...count].sort((a, b) =>
163
- a[0] < b[0] ? -1 : 1,
164
- )) {
165
- if (n > most) {
166
- best = word;
167
- most = n;
168
- }
169
- }
170
- return best;
171
- });
172
- return {module, positions, words, icons: sources.length};
173
- }
174
- const [module, sources] = ranked[0];
175
- return {module, positions: [], words: [], icons: sources.length};
176
- }
177
-
178
- /**
179
- * The refusal for a look word the library does not have.
180
- * @param {string} word
181
- * @param {string} flag `--default-variant` or `--variant`
182
- * @param {string} module
183
- * @param {Array<Set<string>>} positions
184
- */
185
- function unknownLook(word, flag, module, positions) {
186
- return new AstryxError(
187
- `"${word}" is no look of ${module}: its exports name their looks with ${describedLooks(sortedWords(positions))}. Name one of these words, so each icon's export draws that look.`,
188
- styleWords(positions).map(each => ({
189
- name: `${flag} ${each}`,
190
- reason: `a look ${module} names`,
191
- })),
192
- ERROR_CODES.ERR_INVALID_ARGUMENT,
193
- );
194
- }
195
-
196
- /**
197
- * The command that wraps the library again in a new default look.
198
- * @param {string} name
199
- * @param {string | undefined} module
200
- * @param {Looks} looks
201
- */
202
- function refreshCommand(name, module, looks) {
203
- return `astryx experimental icon new-set ${name} --from ${module ? shellArg(module) : '<module>'} --variants ${looks.variants.join(',')} --default-variant ${looks.default}`;
204
- }
205
-
206
- /**
207
- * The refusal for a default variant that would move in place.
208
- * @param {string} name
209
- * @param {number} count icons that draw `now`
210
- * @param {string} now the look they draw
211
- * @param {Looks} looks
212
- * @param {string | undefined} module
213
- * @param {string | undefined} current
214
- */
215
- function inPlaceMove(name, count, now, looks, module, current) {
216
- return new AstryxError(
217
- `Icon set "${name}" can't ${current != null ? `move its default variant from "${current}" to "${looks.default}"` : `take "${looks.default}" as its default variant`} in place: each of its ${count} icons still draws "${now}". Wrap the library again with the new default, so each icon takes that look.`,
218
- [
219
- {
220
- name: refreshCommand(name, module, looks),
221
- reason: 'wrap the library again in the new default look',
222
- },
223
- ],
224
- ERROR_CODES.ERR_INVALID_ARGUMENT,
225
- );
226
- }
227
-
228
- /**
229
- * The refusal for a default variant that would move on a set whose
230
- * library's export names name no looks. The icons' exports stay as they
231
- * are on every path, so only another variant gives them another look.
232
- * @param {string} name
233
- * @param {number} count the set's icons
234
- * @param {string} current the set's default variant
235
- * @param {Looks} looks
236
- */
237
- function unencodedMove(name, count, current, looks) {
238
- const variants = [...new Set([current, ...looks.variants])];
239
- return new AstryxError(
240
- `Icon set "${name}" can't move its default variant from "${current}" to "${looks.default}": its icons' export names name no looks, so each of its ${count} icons draws "${current}", the look its icons' module draws. Keep "${current}" as the default, declare "${looks.default}" as a variant, and add it from the module that draws it (fill <module> with that module).`,
241
- [
242
- {
243
- name: `astryx experimental icon new-set ${name} --variants ${variants.join(',')} --default-variant ${current}`,
244
- reason: `declare ${looks.default} as a variant and keep ${current} as the default`,
245
- },
246
- {
247
- name: `astryx experimental icon add --variant ${looks.default} --from <module> --all --set ${name}`,
248
- reason: `give each icon its ${looks.default} look from the module that draws it`,
249
- },
250
- ],
251
- ERROR_CODES.ERR_INVALID_ARGUMENT,
252
- );
253
- }
254
-
255
- /**
256
- * The refusal for `--variants` that leave out the default variant of a set
257
- * whose library's export names name no looks. Its icons keep their exports,
258
- * so they still draw the default, and the set must keep declaring it.
259
- * @param {string} name
260
- * @param {number} count the set's icons
261
- * @param {string} current the set's default variant
262
- * @param {Looks} looks
263
- * @param {string} from ` --from <module>` on a refresh, else empty
264
- */
265
- function droppedDefault(name, count, current, looks, from) {
266
- const others = looks.variants.filter(variant => variant !== current);
267
- return new AstryxError(
268
- `--variants (${looks.variants.join(', ')}) leaves out "${current}", the default variant of icon set "${name}". Its icons' export names name no looks, so each of its ${count} icons still draws "${current}", the look its icons' module draws. List "${current}" in --variants, and add each other look as a variant from the module that draws it (fill <module> with that module).`,
269
- [
270
- {
271
- name: `astryx experimental icon new-set ${name}${from} --variants ${[current, ...others].join(',')}`,
272
- reason: `keep ${current}, the look each icon draws, as the default`,
273
- },
274
- ...others.map(variant => ({
275
- name: `astryx experimental icon add --variant ${variant} --from <module> --all --set ${name}`,
276
- reason: `give each icon its ${variant} look from the module that draws it`,
277
- })),
278
- ],
279
- ERROR_CODES.ERR_INVALID_OPTION,
280
- );
281
- }
282
-
283
- /**
284
- * The variants and default variant to write for a command that declares
285
- * looks, and whether the set's icons must move to a new look. Every path
286
- * that writes `default.variant` uses it:
287
- *
288
- * - The drawn look is read from every look word of the exports the set
289
- * wraps (`drawn`), or, with no icons from the library yet, is the look
290
- * the library is wrapped in by default.
291
- * - A named default must be a look word the library has.
292
- * - A named default other than the drawn look moves the icons only on a
293
- * refresh (`library` given), where each glyph that has the look takes it;
294
- * in place it is refused with the refresh command.
295
- * - With none named, the default is the drawn look, which `--variants` must
296
- * list.
297
- *
298
- * A library whose names encode no looks has no look words: there the named
299
- * variant, the set's current default, or the first variant is the default.
300
- * Its icons keep their exports on every path, so a set with icons keeps a
301
- * declared default, `--variants` must list it, and with none declared the
302
- * command names it.
303
- * @param {object} args
304
- * @param {string} args.name the set
305
- * @param {Looks | null} args.given the variants and default the command names
306
- * @param {string | undefined} args.current the set's `default.variant`
307
- * @param {number} args.icons how many icons the set has
308
- * @param {DrawnLooks | null} args.drawn what the set's icons draw now
309
- * @param {{module: string, positions: Array<Set<string>>} | null} args.library
310
- * the library `--from` wraps; null in place
311
- * @returns {{looks: Looks | null, moved: boolean}}
312
- */
313
- export function resolveDefaultLook({
314
- name,
315
- given,
316
- current,
317
- icons,
318
- drawn,
319
- library,
320
- }) {
321
- if (!given) return {looks: null, moved: false};
322
- const refresh = library != null;
323
- const positions =
324
- library != null ? library.positions : (drawn?.positions ?? []);
325
- const module = library?.module ?? drawn?.module;
326
- const now = drawn != null && drawn.positions.length > 0 ? drawn : null;
327
- if (positions.length === 0) {
328
- return unencodedDefault({name, given, current, icons, module, refresh});
329
- }
330
- if (given.named) {
331
- const chosen = given.default;
332
- const index = positions.findIndex(position => position.has(chosen));
333
- if (index < 0) {
334
- throw unknownLook(
335
- chosen,
336
- '--default-variant',
337
- /** @type {string} */ (module),
338
- positions,
339
- );
340
- }
341
- const drawnHere = now?.words[index] ?? null;
342
- if (now != null && drawnHere != null && drawnHere !== chosen) {
343
- if (!refresh) {
344
- throw inPlaceMove(name, now.icons, drawnHere, given, module, current);
345
- }
346
- return {looks: given, moved: true};
347
- }
348
- return {looks: given, moved: false};
349
- }
350
- const words = now != null ? now.words : preferredLook(positions, []);
351
- const look = drawnWord(positions, words, given.variants);
352
- if (look == null || !given.variants.includes(look)) {
353
- const shown = look ?? '<look>';
354
- throw new AstryxError(
355
- `None of --variants (${given.variants.join(', ')}) is the look ${now != null ? `the set's ${now.icons} icons draw` : `${module} is wrapped in by default`} ("${shown}"), and each icon's own export draws the default variant. List it in --variants, or name the default with --default-variant.`,
356
- [
357
- {
358
- name: `astryx experimental icon new-set ${name}${refresh ? ` --from ${shellArg(/** @type {string} */ (module))}` : ''} --variants ${[shown, ...given.variants].join(',')}`,
359
- reason: `declare ${shown}, the look each icon draws, as the default`,
360
- },
361
- ],
362
- ERROR_CODES.ERR_INVALID_OPTION,
363
- );
364
- }
365
- return {looks: {...given, default: look}, moved: false};
366
- }
367
-
368
- /**
369
- * {@link resolveDefaultLook} for a library whose names encode no looks.
370
- * @param {{name: string, given: Looks, current: string | undefined, icons: number, module: string | undefined, refresh: boolean}} args
371
- * @returns {{looks: Looks, moved: boolean}}
372
- */
373
- function unencodedDefault({name, given, current, icons, module, refresh}) {
374
- if (given.named) {
375
- if (current != null && given.default !== current && icons > 0) {
376
- throw unencodedMove(name, icons, current, given);
377
- }
378
- return {looks: given, moved: false};
379
- }
380
- if (current != null && given.variants.includes(current)) {
381
- return {looks: {...given, default: current}, moved: false};
382
- }
383
- const from = refresh && module ? ` --from ${shellArg(module)}` : '';
384
- if (current != null && icons > 0) {
385
- throw droppedDefault(name, icons, current, given, from);
386
- }
387
- if (current == null && icons > 0) {
388
- throw new AstryxError(
389
- `Icon set "${name}" declares no default variant, and its icons' export names name none of ${given.variants.join(', ')}. Name the look its ${icons} icons draw with --default-variant.`,
390
- given.variants.map(variant => ({
391
- name: `astryx experimental icon new-set ${name}${from} --variants ${given.variants.join(',')} --default-variant ${variant}`,
392
- reason: `if each icon draws ${variant}`,
393
- })),
394
- ERROR_CODES.ERR_INVALID_OPTION,
395
- );
396
- }
397
- return {looks: given, moved: false};
398
- }
399
-
400
- /**
401
- * The default variant a command that declares `variant` beside the set's
402
- * variants names: the set's own, else the look its icons draw.
403
- * @param {LookSet} set
404
- * @param {DrawnLooks | null} drawn
405
- * @returns {string | null}
406
- */
407
- function keptDefault(set, drawn) {
408
- const current = set.data.default?.variant;
409
- if (current) return current;
410
- if (drawn == null || drawn.positions.length === 0) return null;
411
- return drawnWord(drawn.positions, drawn.words, set.data.variants ?? []);
412
- }
413
-
414
- /**
415
- * The command that declares `variant` beside the set's variants. It names
416
- * the default variant the set keeps, so it runs as printed.
417
- * @param {LookSet} set
418
- * @param {string} variant
419
- * @param {DrawnLooks | null} drawn
420
- * @returns {{name: string, reason: string}}
421
- */
422
- export function declareVariantSuggestion(set, variant, drawn) {
423
- const kept = keptDefault(set, drawn) ?? '<default>';
424
- const declared = set.data.variants ?? [];
425
- const variants = [
426
- ...new Set([
427
- ...(declared.includes(kept) ? [] : [kept]),
428
- ...declared,
429
- variant,
430
- ]),
431
- ];
432
- return {
433
- name: `astryx experimental icon new-set ${set.name} --variants ${variants.join(',')} --default-variant ${kept}`,
434
- reason:
435
- kept === '<default>'
436
- ? 'declare the variants; fill <default> with the look the icons draw'
437
- : 'declare the variants',
438
- };
439
- }
440
-
441
- /**
442
- * Check that `add --variant` may add `variant` to the set's icons: a look
443
- * word the library has, not the look each icon's own export draws (the
444
- * default, declared or drawn), and declared by the set.
445
- * @param {object} args
446
- * @param {LookSet} args.set
447
- * @param {string} args.variant
448
- * @param {string} args.module the module the variant comes from
449
- * @param {Array<Set<string>>} args.positions that module's look positions
450
- * @param {DrawnLooks | null} args.drawn what the set's icons draw now
451
- */
452
- export function checkVariantLook({set, variant, module, positions, drawn}) {
453
- if (positions.length > 0 && !positions.some(each => each.has(variant))) {
454
- throw unknownLook(variant, '--variant', module, positions);
455
- }
456
- const drawnPositions = drawn?.positions ?? [];
457
- const index = drawnPositions.findIndex(each => each.has(variant));
458
- const drawnHere = index >= 0 ? drawn?.words[index] : null;
459
- if (set.data.default?.variant === variant || drawnHere === variant) {
460
- throw new AstryxError(
461
- `"${variant}" is the look each icon's own export in "${set.name}" already draws${set.data.default?.variant === variant ? ' (its default variant)' : ''}, so a variant of it would export the same artwork twice.`,
462
- undefined,
463
- ERROR_CODES.ERR_INVALID_ARGUMENT,
464
- );
465
- }
466
- const declared = set.data.variants ?? [];
467
- if (!declared.includes(variant)) {
468
- throw new AstryxError(
469
- `Icon set "${set.name}" declares no variant "${variant}"${declared.length > 0 ? ` (it declares ${declared.join(', ')})` : ''}. Declare it first${keptDefault(set, drawn) == null ? ', and name the look its icons draw now as the default variant in place of <default>' : ''}.`,
470
- [declareVariantSuggestion(set, variant, drawn)],
471
- ERROR_CODES.ERR_INVALID_ARGUMENT,
472
- );
473
- }
474
- }
@@ -1,162 +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
- * A specifier that is either fixed (a public subpath) or computed from where
6
- * two copied files land.
7
- * @typedef {string | {from: string, to: string}} SpecifierChoice
8
- *
9
- * @typedef {object} PlannedEdit
10
- * @property {number} start
11
- * @property {number} end
12
- * @property {(specifierOf: (choice: SpecifierChoice) => string) => string} render
13
- *
14
- * @typedef {object} CopyPlan
15
- * @property {Map<string, {code: string, edits: PlannedEdit[]}>} files every
16
- * file the copy holds (absolute source path), with the edits its imports need
17
- * @property {Map<string, Set<string>>} dependsOn file -> carried files its
18
- * computed specifiers point at
19
- */
20
- /**
21
- * Follow a component's module graph from its entry files and decide what the
22
- * copy holds. A module inside the component folder is copied. A module
23
- * outside it is reached through the owner package's public exports when every
24
- * name taken from it is public there; otherwise the module that defines the
25
- * name is copied, and imported by relative path. Tests, stories and docs are
26
- * never reached, so they are never copied.
27
- *
28
- * @param {object} options
29
- * @param {string} options.packageDir the owner package root
30
- * @param {string} options.srcRoot its source root
31
- * @param {string} options.componentDir
32
- * @param {string} options.ownerPackage
33
- * @param {string[]} options.entries absolute entry files of the component
34
- * @returns {CopyPlan}
35
- */
36
- export function planCopy({ packageDir, srcRoot, componentDir, ownerPackage, entries, }: {
37
- packageDir: string;
38
- srcRoot: string;
39
- componentDir: string;
40
- ownerPackage: string;
41
- entries: string[];
42
- }): CopyPlan;
43
- /**
44
- * The source of a planned file with its edits applied.
45
- * @param {{code: string, edits: PlannedEdit[]}} planned
46
- * @param {(choice: SpecifierChoice) => string} specifierOf
47
- */
48
- export function renderFile(planned: {
49
- code: string;
50
- edits: PlannedEdit[];
51
- }, specifierOf: (choice: SpecifierChoice) => string): string;
52
- /**
53
- * The relative specifier from one written file to another.
54
- * @param {string} fromDest
55
- * @param {string} toDest
56
- */
57
- export function relativeSpecifierBetween(fromDest: string, toDest: string): string;
58
- export type ImportSpecifier = {
59
- /**
60
- * the exported name (`default` for a default import)
61
- */
62
- imported: string;
63
- local: string;
64
- typeOnly: boolean;
65
- };
66
- export type ModuleReference = {
67
- kind: "named" | "namespace" | "sideEffect" | "dynamic" | "reexportAll" | "reexportNamed";
68
- /**
69
- * the specifier as written
70
- */
71
- source: string;
72
- /**
73
- * statement (or, for `import()`, string literal) start
74
- */
75
- start: number;
76
- end: number;
77
- /**
78
- * the whole statement is `import type` / `export type`
79
- */
80
- typeOnly: boolean;
81
- specifiers: ImportSpecifier[];
82
- /**
83
- * the local name of `* as X`
84
- */
85
- namespace?: string | undefined;
86
- };
87
- export type ParsedModule = {
88
- code: string;
89
- references: ModuleReference[];
90
- /**
91
- * names the module declares and exports
92
- */
93
- declares: Set<string>;
94
- };
95
- /**
96
- * `value` reads runtime exports only;
97
- * `type` reads type-only exports too
98
- */
99
- export type ExportKind = "value" | "type";
100
- /**
101
- * every name a module exports, with where it is declared
102
- */
103
- export type OriginsOf = (file: string, kind: ExportKind) => Map<string, {
104
- file: string;
105
- name: string;
106
- }>;
107
- /**
108
- * `file#name` of a declaration -> the subpaths that export it, and as what
109
- */
110
- export type ExportersByOrigin = Map<string, Array<{
111
- subpath: string;
112
- name: string;
113
- }>>;
114
- export type PublicSurface = {
115
- /**
116
- * the subpaths
117
- * that export each declaration as a value, and as a value or a type
118
- */
119
- byOrigin: Record<ExportKind, ExportersByOrigin>;
120
- /**
121
- * source file -> the subpath that
122
- * exports exactly that file
123
- */
124
- byFile: Map<string, string>;
125
- exportsField: Record<string, unknown> | undefined;
126
- };
127
- /**
128
- * A specifier that is either fixed (a public subpath) or computed from where
129
- * two copied files land.
130
- */
131
- export type SpecifierChoice = string | {
132
- from: string;
133
- to: string;
134
- };
135
- /**
136
- * A specifier that is either fixed (a public subpath) or computed from where
137
- * two copied files land.
138
- */
139
- export type PlannedEdit = {
140
- start: number;
141
- end: number;
142
- render: (specifierOf: (choice: SpecifierChoice) => string) => string;
143
- };
144
- /**
145
- * A specifier that is either fixed (a public subpath) or computed from where
146
- * two copied files land.
147
- */
148
- export type CopyPlan = {
149
- /**
150
- * every
151
- * file the copy holds (absolute source path), with the edits its imports need
152
- */
153
- files: Map<string, {
154
- code: string;
155
- edits: PlannedEdit[];
156
- }>;
157
- /**
158
- * file -> carried files its
159
- * computed specifiers point at
160
- */
161
- dependsOn: Map<string, Set<string>>;
162
- };