@astryxdesign/cli 0.7.4 → 0.7.5-canary.0418c47
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 +20 -20
- package/api/component/_adapter.mjs +16 -1
- package/api/component/component.test.mjs +31 -0
- package/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +5 -2
- package/api/docs/_adapter.mjs +24 -16
- package/api/docs/docs.test.mjs +18 -0
- package/api/docs/integrationDocs.test.mjs +2 -2
- package/api/experimental.d.mts +5 -0
- package/api/experimental.mjs +15 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +16 -3
- package/api/icon/_authoring.d.mts +5 -1
- package/api/icon/_authoring.mjs +478 -63
- package/api/icon/_options.d.mts +11 -0
- package/api/icon/_options.mjs +39 -4
- package/api/icon/_records.d.mts +19 -0
- package/api/icon/_records.mjs +25 -0
- package/api/icon/add/add.d.mts +3 -3
- package/api/icon/add/add.mjs +227 -14
- package/api/icon/all-or-nothing.test.mjs +283 -0
- package/api/icon/detail/detail.mjs +2 -13
- package/api/icon/error-codes.test.mjs +14 -7
- package/api/icon/icon.d.mts +2 -2
- package/api/icon/icon.doc.mjs +30 -2
- package/api/icon/icon.mjs +57 -8
- package/api/icon/icon.test.mjs +133 -1
- package/api/icon/icon.type.d.mts +126 -1
- package/api/icon/icon.type.mjs +67 -3
- package/api/icon/iconAdd.doc.mjs +22 -6
- package/api/icon/iconMap.doc.mjs +24 -8
- package/api/icon/iconNewDefinition.doc.mjs +2 -2
- package/api/icon/iconNewSet.doc.mjs +30 -2
- package/api/icon/iconUse.doc.mjs +4 -1
- package/api/icon/map/map.d.mts +4 -4
- package/api/icon/map/map.mjs +134 -9
- package/api/icon/new-definition/new-definition.mjs +6 -2
- package/api/icon/new-set/new-set.mjs +2 -2
- package/api/icon/new-set/new-set.test.mjs +60 -10
- package/api/icon/option-pairs.test.mjs +368 -0
- package/api/icon/search/search.d.mts +10 -0
- package/api/icon/search/search.mjs +55 -14
- package/api/icon/use/use.mjs +2 -13
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
- package/api/integration/pack-check.mjs +10 -4
- package/api/integration/pack-check.test.mjs +5 -1
- package/api/integration/validate-integration.type.d.mts +3 -2
- package/api/integration/validate-integration.type.mjs +3 -2
- package/api/render/_adapter.d.mts +28 -0
- package/api/render/_adapter.mjs +540 -0
- package/api/render/render.d.mts +15 -0
- package/api/render/render.doc.d.mts +9 -0
- package/api/render/render.doc.mjs +112 -0
- package/api/render/render.mjs +113 -0
- package/api/render/render.test.mjs +1155 -0
- package/api/render/render.type.d.mts +74 -0
- package/api/render/render.type.mjs +64 -0
- package/api/search/_adapter.test.mjs +21 -2
- package/api/search/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- package/api/template/template.mjs +3 -1
- package/api/template/template.type.d.mts +2 -1
- package/api/template/template.type.mjs +1 -1
- package/api/template/tokenizer-showcase.test.mjs +47 -0
- package/api/template/unknown-name.test.mjs +63 -0
- package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
- package/api/theme/build/build.icon-variants.test.mjs +105 -0
- package/api/theme/build/build.mjs +36 -7
- package/api/theme/build/build.test.mjs +27 -0
- package/api/upgrade/_adapter.d.mts +47 -2
- package/api/upgrade/_adapter.mjs +58 -2
- package/api/upgrade/run/failure-receipt.test.mjs +212 -0
- package/api/upgrade/run/outcomes.test.mjs +646 -0
- package/api/upgrade/run/run.d.mts +36 -0
- package/api/upgrade/run/run.mjs +670 -44
- package/api/upgrade/upgrade.doc.mjs +4 -4
- package/api/upgrade/upgrade.mjs +19 -4
- package/api/upgrade/upgrade.type.d.mts +36 -1
- package/api/upgrade/upgrade.type.mjs +29 -4
- package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
- package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
- package/assets/codemods/integration-runner.mjs +8 -2
- package/assets/codemods/integration-runner.protection.test.mjs +53 -0
- package/assets/codemods/outcome.mjs +79 -0
- package/assets/codemods/outcome.test.mjs +40 -0
- package/assets/codemods/parse.mjs +94 -0
- package/assets/codemods/run-codemod.mjs +109 -5
- package/assets/codemods/runner.mjs +119 -13
- package/assets/codemods/transform-prop.mjs +99 -49
- package/assets/codemods/transform-prop.test.mjs +36 -1
- package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
- package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
- package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
- package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
- package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
- package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +143 -70
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
- package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +23 -78
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +71 -1
- package/assets/docs/theme.doc.dense.mjs +8 -0
- package/assets/docs/theme.doc.mjs +16 -0
- package/assets/docs/theme.doc.zh.mjs +11 -0
- package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
- package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +50 -20
- package/assets/docs/tree/render-pages.doc.mjs +94 -0
- package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +1 -1
- package/assets/docs/tree/tokens-color.doc.mjs +145 -1
- package/assets/docs/tree/tokens.doc.mjs +1 -1
- package/assets/icons/definitions/activity.doc.mjs +1 -1
- package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
- package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
- package/assets/icons/definitions/alignStart.doc.mjs +10 -0
- package/assets/icons/definitions/archive.doc.mjs +1 -1
- package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
- package/assets/icons/definitions/attach.doc.mjs +1 -1
- package/assets/icons/definitions/audio.doc.mjs +1 -1
- package/assets/icons/definitions/cart.doc.mjs +1 -1
- package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
- package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
- package/assets/icons/definitions/close.doc.mjs +1 -1
- package/assets/icons/definitions/collapse.doc.mjs +1 -1
- package/assets/icons/definitions/compose.doc.mjs +1 -1
- package/assets/icons/definitions/conversation.doc.mjs +1 -1
- package/assets/icons/definitions/copy.doc.mjs +1 -1
- package/assets/icons/definitions/cpu.doc.mjs +9 -0
- package/assets/icons/definitions/database.doc.mjs +1 -1
- package/assets/icons/definitions/desktop.doc.mjs +1 -1
- package/assets/icons/definitions/discount.doc.mjs +1 -1
- package/assets/icons/definitions/download.doc.mjs +1 -1
- package/assets/icons/definitions/emoji.doc.mjs +1 -1
- package/assets/icons/definitions/error.doc.mjs +1 -1
- package/assets/icons/definitions/expand.doc.mjs +1 -1
- package/assets/icons/definitions/experiment.doc.mjs +1 -1
- package/assets/icons/definitions/externalLink.doc.mjs +7 -1
- package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
- package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
- package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
- package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
- package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
- package/assets/icons/definitions/gitFork.doc.mjs +9 -0
- package/assets/icons/definitions/info.doc.mjs +1 -1
- package/assets/icons/definitions/location.doc.mjs +1 -1
- package/assets/icons/definitions/mention.doc.mjs +1 -1
- package/assets/icons/definitions/menu.doc.mjs +1 -1
- package/assets/icons/definitions/microphone.doc.mjs +1 -1
- package/assets/icons/definitions/mobile.doc.mjs +1 -1
- package/assets/icons/definitions/money.doc.mjs +1 -1
- package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
- package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
- package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
- package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
- package/assets/icons/definitions/panelRight.doc.mjs +10 -0
- package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
- package/assets/icons/definitions/redo.doc.mjs +1 -1
- package/assets/icons/definitions/refresh.doc.mjs +1 -1
- package/assets/icons/definitions/rotate.doc.mjs +9 -0
- package/assets/icons/definitions/scale.doc.mjs +10 -0
- package/assets/icons/definitions/search.doc.mjs +1 -1
- package/assets/icons/definitions/send.doc.mjs +1 -1
- package/assets/icons/definitions/settings.doc.mjs +1 -1
- package/assets/icons/definitions/star.doc.mjs +1 -1
- package/assets/icons/definitions/stop.doc.mjs +1 -1
- package/assets/icons/definitions/success.doc.mjs +1 -1
- package/assets/icons/definitions/textCase.doc.mjs +9 -0
- package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
- package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
- package/assets/icons/definitions/trendDown.doc.mjs +7 -1
- package/assets/icons/definitions/trendUp.doc.mjs +1 -1
- package/assets/icons/definitions/undo.doc.mjs +1 -1
- package/assets/icons/definitions/upload.doc.mjs +1 -1
- package/assets/icons/definitions/userAdd.doc.mjs +1 -1
- package/assets/icons/definitions/warning.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
- package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
- package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +22 -14
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
- package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
- package/assets/templates/pages/library/page.tsx +1 -2
- package/assets/templates/pages/table-comparison/page.tsx +12 -3
- package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
- package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
- package/assets/templates/themes/butter/butterTheme.ts +47 -44
- package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
- package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
- package/assets/templates/themes/stone/stoneTheme.ts +46 -21
- package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
- package/assets/theme.template.ts +18 -5
- package/authoring/codemod/type.ts +10 -0
- package/authoring/debug/parse.d.mts +2 -2
- package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
- package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
- package/authoring/doctypes/icon-set/parse.d.mts +1 -0
- package/authoring/doctypes/icon-set/parse.mjs +1 -0
- package/authoring/doctypes/icon-set/type.ts +5 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +2 -1
- package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
- package/clients/cli/commands/doctor.mjs +16 -17
- package/clients/cli/commands/experimental/icon.mjs +167 -35
- package/clients/cli/commands/experimental/index.mjs +2 -0
- package/clients/cli/commands/experimental/render.mjs +113 -0
- package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
- package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
- package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
- package/clients/cli/commands/experimental-render.doc.mjs +60 -0
- package/clients/cli/commands/experimental.doc.mjs +4 -2
- package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
- package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
- package/clients/cli/commands/icon.test.mjs +1 -1
- package/clients/cli/commands/template.mjs +4 -1
- package/clients/cli/commands/text-json-parity.test.mjs +46 -0
- package/clients/cli/commands/upgrade.doc.mjs +47 -2
- package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
- package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
- package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
- package/clients/cli/commands/upgrade.mjs +9 -2
- package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
- package/clients/cli/index.mjs +1 -0
- package/foundation/agent-docs/agent-docs.mjs +1 -0
- package/foundation/agent-docs/agent-docs.test.mjs +5 -0
- package/foundation/discovery/component-discovery.d.mts +2 -1
- package/foundation/discovery/component-discovery.export-names.test.mjs +41 -0
- package/foundation/discovery/component-discovery.mjs +13 -7
- package/foundation/discovery/icon-set-checks.d.mts +43 -9
- package/foundation/discovery/icon-set-checks.mjs +296 -21
- package/foundation/discovery/icon-set-checks.test.mjs +125 -12
- package/foundation/discovery/icon-set-writer.d.mts +192 -3
- package/foundation/discovery/icon-set-writer.mjs +608 -34
- package/foundation/discovery/icon-set-writer.test.mjs +26 -0
- package/foundation/discovery/module-exports.mjs +82 -25
- package/foundation/discovery/module-exports.test.mjs +38 -1
- package/foundation/discovery/package-exports.d.mts +13 -0
- package/foundation/discovery/package-exports.mjs +40 -1
- package/foundation/discovery/template-icons.d.mts +6 -0
- package/foundation/discovery/template-icons.mjs +98 -10
- package/foundation/discovery/template-icons.test.mjs +103 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
- package/foundation/doc-compiler/import.mjs +81 -8
- package/foundation/doc-compiler/read.d.mts +4 -3
- package/foundation/doc-compiler/read.mjs +15 -10
- package/foundation/doc-compiler/read.test.mjs +59 -1
- package/foundation/doc-compiler/tree.mjs +3 -1
- package/foundation/fs/module-loader.d.mts +3 -2
- package/foundation/fs/module-loader.mjs +3 -2
- package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
- package/foundation/fs/read-record.d.mts +27 -0
- package/foundation/fs/read-record.mjs +83 -15
- package/foundation/fs/read-record.test.mjs +88 -1
- package/foundation/render/assets.d.mts +31 -0
- package/foundation/render/assets.mjs +102 -0
- package/foundation/render/component-map.d.mts +52 -0
- package/foundation/render/component-map.mjs +141 -0
- package/foundation/render/css-cut.d.mts +29 -0
- package/foundation/render/css-cut.mjs +144 -0
- package/foundation/render/embedded-files.d.mts +28 -0
- package/foundation/render/embedded-files.mjs +108 -0
- package/foundation/render/embedded-imports.d.mts +61 -0
- package/foundation/render/embedded-imports.mjs +315 -0
- package/foundation/render/html-reader.d.mts +37 -0
- package/foundation/render/html-reader.mjs +121 -0
- package/foundation/render/page-worker.d.mts +7 -0
- package/foundation/render/page-worker.mjs +519 -0
- package/foundation/render/rebuild.d.mts +19 -0
- package/foundation/render/rebuild.mjs +269 -0
- package/foundation/render/render-page.d.mts +85 -0
- package/foundation/render/render-page.mjs +612 -0
- package/foundation/render/render.test.mjs +117 -0
- package/foundation/render/source-block.d.mts +52 -0
- package/foundation/render/source-block.mjs +106 -0
- package/foundation/response/base.d.ts +7 -0
- package/foundation/response/error-codes.d.mts +10 -1
- package/foundation/response/error-codes.doc.mjs +59 -2
- package/foundation/response/error-codes.mjs +62 -1
- package/foundation/response/json.d.mts +10 -3
- package/foundation/response/json.mjs +16 -4
- package/foundation/response/response-types.doc.mjs +39 -2
- package/foundation/text/string-utils.mjs +33 -0
- package/foundation/text/string-utils.test.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +17 -3
- package/foundation/text/suggest-order.mjs +58 -13
- package/foundation/text/suggest-order.test.mjs +53 -0
- package/package.json +15 -9
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @file Icon ids from export names (AST-084): a dimension stays one word. */
|
|
4
|
+
|
|
5
|
+
import {describe, expect, it} from 'vitest';
|
|
6
|
+
import {iconIdOf} from './icon-set-writer.mjs';
|
|
7
|
+
|
|
8
|
+
describe('iconIdOf', () => {
|
|
9
|
+
it.each([
|
|
10
|
+
['XMarkIcon', 'x-mark'],
|
|
11
|
+
['Trash2', 'trash-2'],
|
|
12
|
+
['ArrowUpDown', 'arrow-up-down'],
|
|
13
|
+
['Squares2X2Icon', 'squares-2x2'],
|
|
14
|
+
['Grid2x2', 'grid-2x2'],
|
|
15
|
+
['Grid2X2Check', 'grid-2x2-check'],
|
|
16
|
+
['Grid3x3', 'grid-3x3'],
|
|
17
|
+
['Tally5', 'tally-5'],
|
|
18
|
+
['H1Icon', 'h1'],
|
|
19
|
+
['Box', 'box'],
|
|
20
|
+
['CalendarX2', 'calendar-x-2'],
|
|
21
|
+
['MapPinXInside', 'map-pin-x-inside'],
|
|
22
|
+
['Heading1', 'heading-1'],
|
|
23
|
+
])('%s → %s', (name, id) => {
|
|
24
|
+
expect(iconIdOf(name)).toBe(id);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -146,15 +146,44 @@ const NOT_CHILDREN = new Set([
|
|
|
146
146
|
]);
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* Every node of `type`
|
|
149
|
+
* Every node of `type` under each tree walked, by tree and type: a parsed
|
|
150
|
+
* module is cached and never changes, so a library of a thousand icons is
|
|
151
|
+
* walked once per type, not once per export looked up.
|
|
152
|
+
* @type {WeakMap<object, Map<string, readonly any[]>>}
|
|
153
|
+
*/
|
|
154
|
+
const nodesByTree = new WeakMap();
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Every node of `type` in the tree, at any depth, in source order. The
|
|
158
|
+
* answer is shared: callers only read it.
|
|
159
|
+
* @param {any} node
|
|
160
|
+
* @param {string} type
|
|
161
|
+
* @returns {readonly any[]}
|
|
162
|
+
*/
|
|
163
|
+
function nodesOfType(node, type) {
|
|
164
|
+
if (node == null || typeof node !== 'object') return [];
|
|
165
|
+
let byType = nodesByTree.get(node);
|
|
166
|
+
if (!byType) {
|
|
167
|
+
byType = new Map();
|
|
168
|
+
nodesByTree.set(node, byType);
|
|
169
|
+
}
|
|
170
|
+
let found = byType.get(type);
|
|
171
|
+
if (!found) {
|
|
172
|
+
found = collectNodesOfType(node, type, []);
|
|
173
|
+
byType.set(type, found);
|
|
174
|
+
}
|
|
175
|
+
return found;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
150
179
|
* @param {any} node
|
|
151
180
|
* @param {string} type
|
|
152
|
-
* @param {any[]}
|
|
181
|
+
* @param {any[]} found
|
|
153
182
|
* @returns {any[]}
|
|
154
183
|
*/
|
|
155
|
-
function
|
|
184
|
+
function collectNodesOfType(node, type, found) {
|
|
156
185
|
if (Array.isArray(node)) {
|
|
157
|
-
for (const child of node)
|
|
186
|
+
for (const child of node) collectNodesOfType(child, type, found);
|
|
158
187
|
return found;
|
|
159
188
|
}
|
|
160
189
|
if (node == null || typeof node !== 'object') return found;
|
|
@@ -163,7 +192,7 @@ function nodesOfType(node, type, found = []) {
|
|
|
163
192
|
if (NOT_CHILDREN.has(key)) continue;
|
|
164
193
|
const child = node[key];
|
|
165
194
|
if (child != null && typeof child === 'object') {
|
|
166
|
-
|
|
195
|
+
collectNodesOfType(child, type, found);
|
|
167
196
|
}
|
|
168
197
|
}
|
|
169
198
|
return found;
|
|
@@ -890,6 +919,43 @@ export function staticExportObject(file, exportNames) {
|
|
|
890
919
|
return null;
|
|
891
920
|
}
|
|
892
921
|
|
|
922
|
+
/**
|
|
923
|
+
* A module's runtime named exports, indexed once per parsed tree: the
|
|
924
|
+
* export declarations that declare something, and each export specifier by
|
|
925
|
+
* the name it exports, in source order.
|
|
926
|
+
* @type {WeakMap<object, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>}
|
|
927
|
+
*/
|
|
928
|
+
const namedExportIndexes = new WeakMap();
|
|
929
|
+
|
|
930
|
+
/** @param {any} program */
|
|
931
|
+
function namedExportIndex(program) {
|
|
932
|
+
const cached = namedExportIndexes.get(program);
|
|
933
|
+
if (cached) return cached;
|
|
934
|
+
/** @type {any[]} */
|
|
935
|
+
const declarations = [];
|
|
936
|
+
/** @type {Map<string, Array<{node: any, specifier: any}>>} */
|
|
937
|
+
const specifiers = new Map();
|
|
938
|
+
for (const node of nodesOfType(program, 'ExportNamedDeclaration')) {
|
|
939
|
+
if (node.exportKind === 'type') continue;
|
|
940
|
+
if (node.declaration) declarations.push(node);
|
|
941
|
+
for (const specifier of node.specifiers ?? []) {
|
|
942
|
+
if (
|
|
943
|
+
specifier.type !== 'ExportSpecifier' ||
|
|
944
|
+
specifier.exportKind === 'type'
|
|
945
|
+
) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
const exported = specifier.exported?.name ?? specifier.exported?.value;
|
|
949
|
+
const list = specifiers.get(exported) ?? [];
|
|
950
|
+
list.push({node, specifier});
|
|
951
|
+
specifiers.set(exported, list);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
const index = {declarations, specifiers};
|
|
955
|
+
namedExportIndexes.set(program, index);
|
|
956
|
+
return index;
|
|
957
|
+
}
|
|
958
|
+
|
|
893
959
|
/**
|
|
894
960
|
* Where a module's runtime export is declared, as the file and the name it
|
|
895
961
|
* has there, without executing anything: local re-exports, renames, and
|
|
@@ -911,30 +977,21 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
|
|
|
911
977
|
} catch {
|
|
912
978
|
return null;
|
|
913
979
|
}
|
|
914
|
-
|
|
915
|
-
|
|
980
|
+
const {declarations, specifiers} = namedExportIndex(ast.program);
|
|
981
|
+
for (const node of declarations) {
|
|
916
982
|
if (declarationExports(node.declaration, exportName)) {
|
|
917
983
|
return {file, name: exportName};
|
|
918
984
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
)
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
if (exported !== exportName) continue;
|
|
928
|
-
const local =
|
|
929
|
-
specifier.local?.name ?? specifier.local?.value ?? exportName;
|
|
930
|
-
if (node.source) {
|
|
931
|
-
const target = resolveModuleOrPackage(node.source.value, file);
|
|
932
|
-
const origin = target ? moduleExportOrigin(target, local, seen) : null;
|
|
933
|
-
if (origin) return origin;
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
return bindingOrigin(ast, file, local, seen);
|
|
985
|
+
}
|
|
986
|
+
for (const {node, specifier} of specifiers.get(exportName) ?? []) {
|
|
987
|
+
const local = specifier.local?.name ?? specifier.local?.value ?? exportName;
|
|
988
|
+
if (node.source) {
|
|
989
|
+
const target = resolveModuleOrPackage(node.source.value, file);
|
|
990
|
+
const origin = target ? moduleExportOrigin(target, local, seen) : null;
|
|
991
|
+
if (origin) return origin;
|
|
992
|
+
continue;
|
|
937
993
|
}
|
|
994
|
+
return bindingOrigin(ast, file, local, seen);
|
|
938
995
|
}
|
|
939
996
|
if (exportName === 'default') {
|
|
940
997
|
for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
|
|
@@ -9,7 +9,11 @@ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
|
9
9
|
import * as fs from 'node:fs';
|
|
10
10
|
import * as os from 'node:os';
|
|
11
11
|
import * as path from 'node:path';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
moduleExportOrigin,
|
|
14
|
+
moduleExportSource,
|
|
15
|
+
staticExportObject,
|
|
16
|
+
} from './module-exports.mjs';
|
|
13
17
|
|
|
14
18
|
/** @type {string} */
|
|
15
19
|
let dir;
|
|
@@ -170,3 +174,36 @@ describe('moduleExportSource', () => {
|
|
|
170
174
|
expect(moduleExportSource(file, 'AcmePanel')).toBeNull();
|
|
171
175
|
});
|
|
172
176
|
});
|
|
177
|
+
|
|
178
|
+
describe('a library of thousands of icons', () => {
|
|
179
|
+
it('finds the origin of every export in about linear time', () => {
|
|
180
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-many-exports-'));
|
|
181
|
+
try {
|
|
182
|
+
const count = 3000;
|
|
183
|
+
fs.writeFileSync(
|
|
184
|
+
path.join(dir, 'icon.js'),
|
|
185
|
+
'export function make(name) { return function Icon() { return name; }; }\n',
|
|
186
|
+
);
|
|
187
|
+
const lines = ["import {make} from './icon.js';"];
|
|
188
|
+
for (let i = 0; i < count; i++) {
|
|
189
|
+
lines.push(`const Glyph${i} = make('g${i}');`);
|
|
190
|
+
lines.push(
|
|
191
|
+
`export {Glyph${i}, Glyph${i} as Glyph${i}Icon, Glyph${i} as LucideGlyph${i}};`,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const file = path.join(dir, 'index.js');
|
|
195
|
+
fs.writeFileSync(file, `${lines.join('\n')}\n`);
|
|
196
|
+
const started = Date.now();
|
|
197
|
+
for (let i = 0; i < count; i++) {
|
|
198
|
+
expect(moduleExportOrigin(file, `Glyph${i}Icon`)).toEqual({
|
|
199
|
+
file,
|
|
200
|
+
name: `Glyph${i}`,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// Walking the whole module once per lookup took minutes.
|
|
204
|
+
expect(Date.now() - started).toBeLessThan(10_000);
|
|
205
|
+
} finally {
|
|
206
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
207
|
+
}
|
|
208
|
+
}, 60_000);
|
|
209
|
+
});
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The file a subpath's `source` condition names, when that file is in the
|
|
6
|
+
* package. A package that ships its source (or a workspace package before it
|
|
7
|
+
* is built) declares it beside the built target, so reading it answers the
|
|
8
|
+
* same with or without a build. Null when there is no such condition or file.
|
|
9
|
+
* @param {{exports?: unknown}} pkg
|
|
10
|
+
* @param {string} packageDir
|
|
11
|
+
* @param {string} subpath `.` or a `./`-prefixed subpath
|
|
12
|
+
* @returns {string|null}
|
|
13
|
+
*/
|
|
14
|
+
export function sourceExportTarget(pkg: {
|
|
15
|
+
exports?: unknown;
|
|
16
|
+
}, packageDir: string, subpath: string): string | null;
|
|
4
17
|
/**
|
|
5
18
|
* @typedef {object} PackageExportResult
|
|
6
19
|
* @property {string} subpath
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* their legacy public deep paths and are resolved from files on disk.
|
|
9
9
|
*
|
|
10
10
|
* @input Parsed package.json, package directory, and a public subpath
|
|
11
|
-
* @output The public specifier and confined target file, when exported
|
|
11
|
+
* @output The public specifier and confined target file, when exported, and
|
|
12
|
+
* the file a subpath's `source` condition names, when the package has it
|
|
12
13
|
* @position packages/cli/foundation/discovery — shared package import metadata
|
|
13
14
|
*/
|
|
14
15
|
|
|
@@ -165,6 +166,44 @@ function resolveLegacy(packageDir, subpath) {
|
|
|
165
166
|
return candidates.find(regularFile) ?? null;
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
/**
|
|
170
|
+
* The raw export value one subpath maps to, with the wildcard it matched.
|
|
171
|
+
* @param {unknown} exportsField
|
|
172
|
+
* @param {string} subpath
|
|
173
|
+
* @returns {{value: unknown, wildcard: string} | null}
|
|
174
|
+
*/
|
|
175
|
+
function rawExportValue(exportsField, subpath) {
|
|
176
|
+
if (exportsField == null) return null;
|
|
177
|
+
if (!isRecord(exportsField)) {
|
|
178
|
+
return subpath === '.' ? {value: exportsField, wildcard: ''} : null;
|
|
179
|
+
}
|
|
180
|
+
if (!Object.keys(exportsField).some(key => key.startsWith('.'))) {
|
|
181
|
+
return subpath === '.' ? {value: exportsField, wildcard: ''} : null;
|
|
182
|
+
}
|
|
183
|
+
const selected = subpathValue(exportsField, subpath);
|
|
184
|
+
return selected.found
|
|
185
|
+
? {value: selected.value, wildcard: selected.wildcard}
|
|
186
|
+
: null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The file a subpath's `source` condition names, when that file is in the
|
|
191
|
+
* package. A package that ships its source (or a workspace package before it
|
|
192
|
+
* is built) declares it beside the built target, so reading it answers the
|
|
193
|
+
* same with or without a build. Null when there is no such condition or file.
|
|
194
|
+
* @param {{exports?: unknown}} pkg
|
|
195
|
+
* @param {string} packageDir
|
|
196
|
+
* @param {string} subpath `.` or a `./`-prefixed subpath
|
|
197
|
+
* @returns {string|null}
|
|
198
|
+
*/
|
|
199
|
+
export function sourceExportTarget(pkg, packageDir, subpath) {
|
|
200
|
+
const selected = rawExportValue(pkg.exports, subpath);
|
|
201
|
+
if (!selected || !isRecord(selected.value)) return null;
|
|
202
|
+
const source = selected.value.source;
|
|
203
|
+
if (typeof source !== 'string') return null;
|
|
204
|
+
return resolveTarget(packageDir, source.replaceAll('*', selected.wildcard));
|
|
205
|
+
}
|
|
206
|
+
|
|
168
207
|
/**
|
|
169
208
|
* @typedef {object} PackageExportResult
|
|
170
209
|
* @property {string} subpath
|
|
@@ -103,6 +103,12 @@ export type MappedIcon = {
|
|
|
103
103
|
module: string;
|
|
104
104
|
export: string;
|
|
105
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* the library's sizing props (`size`,
|
|
108
|
+
* `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
|
|
109
|
+
* set's icons take their size from CSS
|
|
110
|
+
*/
|
|
111
|
+
dropped?: string[] | undefined;
|
|
106
112
|
/**
|
|
107
113
|
* `match`: a reviewed
|
|
108
114
|
* `exact` or `strong` match in the project set's data names the source
|
|
@@ -63,6 +63,9 @@ import {astryxDefinitionsByName} from './icon-definition-discovery.mjs';
|
|
|
63
63
|
* @typedef {object} MappedIcon
|
|
64
64
|
* @property {{module: string, export: string}} source
|
|
65
65
|
* @property {{set: string, package: string, id: string, module: string, export: string}} target
|
|
66
|
+
* @property {string[]} [dropped] the library's sizing props (`size`,
|
|
67
|
+
* `strokeWidth`, `absoluteStrokeWidth`) removed from its elements: an icon
|
|
68
|
+
* set's icons take their size from CSS
|
|
66
69
|
* @property {'match' | 'definition'} by `match`: a reviewed
|
|
67
70
|
* `exact` or `strong` match in the project set's data names the source
|
|
68
71
|
* icon; `definition`: the target's `map` names it for the Astryx icon
|
|
@@ -390,6 +393,12 @@ export function iconsNotImported(source, declared) {
|
|
|
390
393
|
return Object.keys(declared).filter(key => !keys.has(key));
|
|
391
394
|
}
|
|
392
395
|
|
|
396
|
+
/**
|
|
397
|
+
* A library's own sizing props, dropped from a mapped icon: an icon set's
|
|
398
|
+
* icons take their size from CSS.
|
|
399
|
+
*/
|
|
400
|
+
const SIZING_PROPS = new Set(['size', 'strokeWidth', 'absoluteStrokeWidth']);
|
|
401
|
+
|
|
393
402
|
/** What a template reads with no icon-set state given: nothing is mapped. */
|
|
394
403
|
export const NO_ICON_SETS = Object.freeze({
|
|
395
404
|
sets: [],
|
|
@@ -520,6 +529,10 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
520
529
|
let insertAt = -1;
|
|
521
530
|
/** The declared keys reported as mapped or kept so far. */
|
|
522
531
|
const accounted = new Set();
|
|
532
|
+
/** The local names of mapped imports, as the template wrote them. */
|
|
533
|
+
const mappedLocals = new Set();
|
|
534
|
+
/** @type {Array<[MappedIcon, string]>} each mapped icon and its local name */
|
|
535
|
+
const mappedEntries = [];
|
|
523
536
|
|
|
524
537
|
for (const node of ast.program.body) {
|
|
525
538
|
if (node.type !== 'ImportDeclaration') continue;
|
|
@@ -582,7 +595,9 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
582
595
|
added.set(key, entry);
|
|
583
596
|
}
|
|
584
597
|
if (local !== entry.local) renames.set(local, entry.local);
|
|
585
|
-
|
|
598
|
+
mappedLocals.add(local);
|
|
599
|
+
/** @type {MappedIcon} */
|
|
600
|
+
const mappedIcon = {
|
|
586
601
|
source: {module, export: imported},
|
|
587
602
|
target: {
|
|
588
603
|
set: target.name,
|
|
@@ -592,30 +607,74 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
592
607
|
export: chosen.export,
|
|
593
608
|
},
|
|
594
609
|
by: match.by,
|
|
595
|
-
}
|
|
610
|
+
};
|
|
611
|
+
icons.mapped.push(mappedIcon);
|
|
612
|
+
mappedEntries.push([mappedIcon, local]);
|
|
596
613
|
}
|
|
597
614
|
|
|
598
615
|
if (keep.length === node.specifiers.length) continue;
|
|
599
616
|
if (insertAt === -1) insertAt = node.start;
|
|
617
|
+
// Comments inside the statement, and one that trails it on its line,
|
|
618
|
+
// survive the rewrite: those a kept specifier does not carry move to
|
|
619
|
+
// their own lines above it.
|
|
620
|
+
// A kept specifier carries a comment beside it with only whitespace
|
|
621
|
+
// between (`Pencil /* pen */`).
|
|
622
|
+
const keptRanges = keep.map(each => {
|
|
623
|
+
let [a, b] = [each.start, each.end];
|
|
624
|
+
for (const comment of ast.comments ?? []) {
|
|
625
|
+
if (comment.start < node.start || comment.end > node.end) continue;
|
|
626
|
+
if (comment.start >= b && /^\s*$/u.test(source.slice(b, comment.start)))
|
|
627
|
+
b = comment.end;
|
|
628
|
+
}
|
|
629
|
+
for (const comment of [...(ast.comments ?? [])].reverse()) {
|
|
630
|
+
if (comment.start < node.start || comment.end > node.end) continue;
|
|
631
|
+
if (comment.end <= a && /^\s*$/u.test(source.slice(comment.end, a)))
|
|
632
|
+
a = comment.start;
|
|
633
|
+
}
|
|
634
|
+
return [a, b];
|
|
635
|
+
});
|
|
636
|
+
const inside = (ast.comments ?? []).filter(
|
|
637
|
+
(/** @type {any} */ comment) =>
|
|
638
|
+
comment.start >= node.start &&
|
|
639
|
+
comment.end <= node.end &&
|
|
640
|
+
!keptRanges.some(([a, b]) => comment.start >= a && comment.end <= b),
|
|
641
|
+
);
|
|
642
|
+
const trailing = /^[ \t]*(\/\/[^\n]*|\/\*[^\n]*?\*\/)[ \t]*(?=\n|$)/u.exec(
|
|
643
|
+
source.slice(node.end),
|
|
644
|
+
);
|
|
645
|
+
/** @type {string[]} */
|
|
646
|
+
const moved = inside.map((/** @type {any} */ comment) =>
|
|
647
|
+
source.slice(comment.start, comment.end),
|
|
648
|
+
);
|
|
649
|
+
const above = moved.map(comment => `${comment}\n`).join('');
|
|
600
650
|
if (keep.length === 0) {
|
|
601
651
|
let end = node.end;
|
|
652
|
+
if (trailing) {
|
|
653
|
+
moved.push(trailing[1]);
|
|
654
|
+
end += trailing[0].length;
|
|
655
|
+
}
|
|
602
656
|
if (source[end] === '\n') end += 1;
|
|
603
|
-
edits.push({
|
|
657
|
+
edits.push({
|
|
658
|
+
start: node.start,
|
|
659
|
+
end,
|
|
660
|
+
text: moved.map(comment => `${comment}\n`).join(''),
|
|
661
|
+
});
|
|
604
662
|
} else {
|
|
663
|
+
/** @param {any} each */
|
|
664
|
+
const textOf = each => {
|
|
665
|
+
const [a, b] = keptRanges[keep.indexOf(each)];
|
|
666
|
+
return source.slice(a, b);
|
|
667
|
+
};
|
|
605
668
|
const defaults = keep.filter(each => each.type !== 'ImportSpecifier');
|
|
606
669
|
const named = keep.filter(each => each.type === 'ImportSpecifier');
|
|
607
670
|
const parts = [
|
|
608
|
-
...defaults.map(
|
|
609
|
-
...(named.length > 0
|
|
610
|
-
? [
|
|
611
|
-
`{${named.map(each => source.slice(each.start, each.end)).join(', ')}}`,
|
|
612
|
-
]
|
|
613
|
-
: []),
|
|
671
|
+
...defaults.map(textOf),
|
|
672
|
+
...(named.length > 0 ? [`{${named.map(textOf).join(', ')}}`] : []),
|
|
614
673
|
];
|
|
615
674
|
edits.push({
|
|
616
675
|
start: node.start,
|
|
617
676
|
end: node.end,
|
|
618
|
-
text:
|
|
677
|
+
text: `${above}import ${parts.join(', ')} from ${source.slice(node.source.start, node.source.end)};`,
|
|
619
678
|
});
|
|
620
679
|
}
|
|
621
680
|
}
|
|
@@ -678,6 +737,35 @@ export function mapTemplateIcons(source, {sets, choice}, declared = {}) {
|
|
|
678
737
|
edits.push({start: node.start, end: node.end, text: next});
|
|
679
738
|
}
|
|
680
739
|
});
|
|
740
|
+
// Size comes from CSS in every icon set (its export contract), so a
|
|
741
|
+
// library's own sizing props on a mapped icon are dropped and reported.
|
|
742
|
+
/** @type {Map<string, Set<string>>} local name → props dropped */
|
|
743
|
+
const dropped = new Map();
|
|
744
|
+
walk(ast.program, node => {
|
|
745
|
+
if (node.type !== 'JSXOpeningElement' || node.name.type !== 'JSXIdentifier')
|
|
746
|
+
return;
|
|
747
|
+
const local = node.name.name;
|
|
748
|
+
if (!mappedLocals.has(local)) return;
|
|
749
|
+
for (const attribute of node.attributes) {
|
|
750
|
+
if (
|
|
751
|
+
attribute.type !== 'JSXAttribute' ||
|
|
752
|
+
attribute.name.type !== 'JSXIdentifier' ||
|
|
753
|
+
!SIZING_PROPS.has(attribute.name.name)
|
|
754
|
+
) {
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
let start = attribute.start;
|
|
758
|
+
while (start > 0 && /\s/u.test(source[start - 1])) start -= 1;
|
|
759
|
+
edits.push({start, end: attribute.end, text: ''});
|
|
760
|
+
const set = dropped.get(local) ?? new Set();
|
|
761
|
+
set.add(attribute.name.name);
|
|
762
|
+
dropped.set(local, set);
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
for (const [entry, local] of mappedEntries) {
|
|
766
|
+
const props = dropped.get(local);
|
|
767
|
+
if (props) entry.dropped = [...props].sort();
|
|
768
|
+
}
|
|
681
769
|
// A shorthand property is visited as both key and value; keep one edit.
|
|
682
770
|
const unique = new Map();
|
|
683
771
|
for (const edit of edits) {
|
|
@@ -125,6 +125,59 @@ describe('mapTemplateIcons', () => {
|
|
|
125
125
|
]);
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
it("drops a library's sizing props from a mapped icon and reports them", () => {
|
|
129
|
+
const {source, icons} = map(
|
|
130
|
+
[
|
|
131
|
+
"import {CloseGlyph, PencilGlyph} from '@acme/library';",
|
|
132
|
+
'',
|
|
133
|
+
'export const A = () => (',
|
|
134
|
+
' <div>',
|
|
135
|
+
' <CloseGlyph size={16} strokeWidth={2} className="x" />',
|
|
136
|
+
' <CloseGlyph',
|
|
137
|
+
' absoluteStrokeWidth',
|
|
138
|
+
' />',
|
|
139
|
+
' <PencilGlyph size={16} />',
|
|
140
|
+
' </div>',
|
|
141
|
+
');',
|
|
142
|
+
'',
|
|
143
|
+
].join('\n'),
|
|
144
|
+
DECLARED,
|
|
145
|
+
);
|
|
146
|
+
expect(source).toContain('<XIcon className="x" />');
|
|
147
|
+
expect(source).toMatch(/<XIcon\s*\/>/u);
|
|
148
|
+
expect(source).not.toContain('absoluteStrokeWidth');
|
|
149
|
+
// A kept icon keeps its props.
|
|
150
|
+
expect(source).toContain('<PencilGlyph size={16} />');
|
|
151
|
+
expect(icons.mapped[0].dropped).toEqual([
|
|
152
|
+
'absoluteStrokeWidth',
|
|
153
|
+
'size',
|
|
154
|
+
'strokeWidth',
|
|
155
|
+
]);
|
|
156
|
+
expect(icons.kept[0]).not.toHaveProperty('dropped');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('keeps comments inside and after a rewritten import line', () => {
|
|
160
|
+
const {source} = map(
|
|
161
|
+
[
|
|
162
|
+
"import {CloseGlyph /* close */, PencilGlyph /* pen */} from '@acme/library'; // tools",
|
|
163
|
+
"import {HomeGlyph} from '@acme/library/home'; // the home link",
|
|
164
|
+
'',
|
|
165
|
+
'export const A = () => <><CloseGlyph /><PencilGlyph /><HomeGlyph /></>;',
|
|
166
|
+
'',
|
|
167
|
+
].join('\n'),
|
|
168
|
+
DECLARED,
|
|
169
|
+
);
|
|
170
|
+
expect(source).toContain('/* close */');
|
|
171
|
+
expect(source).toContain('/* pen */');
|
|
172
|
+
expect(source).toContain('// tools');
|
|
173
|
+
expect(source).toContain('// the home link');
|
|
174
|
+
// Each comment is outside any code it would swallow.
|
|
175
|
+
expect(source).toContain(
|
|
176
|
+
"import {PencilGlyph /* pen */} from '@acme/library'; // tools",
|
|
177
|
+
);
|
|
178
|
+
expect(source).toMatch(/^\/\/ the home link$/mu);
|
|
179
|
+
});
|
|
180
|
+
|
|
128
181
|
it('an undeclared import is not an icon: it is left alone and not reported', () => {
|
|
129
182
|
const source =
|
|
130
183
|
"import {CloseGlyph} from '@acme/library';\nexport const A = () => <CloseGlyph />;\n";
|
|
@@ -455,3 +508,53 @@ describe('icons another installed set ships', () => {
|
|
|
455
508
|
]);
|
|
456
509
|
});
|
|
457
510
|
});
|
|
511
|
+
|
|
512
|
+
describe('one key for a name imported from two modules (FR9)', () => {
|
|
513
|
+
it('maps both imports by the one key, and each keeps its variant', () => {
|
|
514
|
+
const LINES = /** @type {any} */ ({
|
|
515
|
+
name: 'lines',
|
|
516
|
+
package: '@acme/lines',
|
|
517
|
+
data: {
|
|
518
|
+
schemaVersion: 1,
|
|
519
|
+
module: '@acme/lines',
|
|
520
|
+
variants: ['outline', 'solid'],
|
|
521
|
+
default: {variant: 'outline'},
|
|
522
|
+
map: {delete: 'trash'},
|
|
523
|
+
icons: [
|
|
524
|
+
{
|
|
525
|
+
id: 'trash',
|
|
526
|
+
export: 'TrashIcon',
|
|
527
|
+
words: ['trash'],
|
|
528
|
+
variants: [
|
|
529
|
+
{
|
|
530
|
+
variant: 'solid',
|
|
531
|
+
export: 'TrashIcon',
|
|
532
|
+
module: '@acme/lines/solid',
|
|
533
|
+
},
|
|
534
|
+
],
|
|
535
|
+
},
|
|
536
|
+
],
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
const {source, icons} = map(
|
|
540
|
+
[
|
|
541
|
+
"import {TrashIcon} from '@acme/lines';",
|
|
542
|
+
"import {TrashIcon as TrashSolid} from '@acme/lines/solid';",
|
|
543
|
+
'export const A = () => <><TrashIcon /><TrashSolid /></>;',
|
|
544
|
+
'',
|
|
545
|
+
].join('\n'),
|
|
546
|
+
{TrashIcon: 'delete'},
|
|
547
|
+
SELECTED,
|
|
548
|
+
[SET, LINES],
|
|
549
|
+
);
|
|
550
|
+
expect(
|
|
551
|
+
icons.mapped.map(each => [each.source.module, each.target.export]),
|
|
552
|
+
).toEqual([
|
|
553
|
+
['@acme/lines', 'TrashIcon'],
|
|
554
|
+
['@acme/lines/solid', 'TrashSolidIcon'],
|
|
555
|
+
]);
|
|
556
|
+
expect(source).toContain(
|
|
557
|
+
"import {TrashIcon, TrashSolidIcon} from '@acme/glyphs';",
|
|
558
|
+
);
|
|
559
|
+
});
|
|
560
|
+
});
|
|
@@ -123,6 +123,13 @@ const RUNNERS = {
|
|
|
123
123
|
runs: SELF_DOCS,
|
|
124
124
|
sites: ['import ../experimental.doc.mjs'],
|
|
125
125
|
},
|
|
126
|
+
'clients/cli/commands/experimental/render.mjs': {
|
|
127
|
+
runs: SELF_DOCS,
|
|
128
|
+
sites: [
|
|
129
|
+
'import ../../../../api/render/render.doc.mjs',
|
|
130
|
+
'import ../experimental-render.doc.mjs',
|
|
131
|
+
],
|
|
132
|
+
},
|
|
126
133
|
'clients/cli/commands/manifest.mjs': {
|
|
127
134
|
runs: SELF_DOCS,
|
|
128
135
|
sites: ['import ./manifest.doc.mjs'],
|
|
@@ -338,18 +345,26 @@ const RUNNERS = {
|
|
|
338
345
|
sites: ['require(@babel/parser)', 'require(jscodeshift)'],
|
|
339
346
|
},
|
|
340
347
|
'foundation/doc-compiler/import.mjs': {
|
|
341
|
-
runs: 'authored doc files, for the doc reader and discovery',
|
|
348
|
+
runs: 'authored doc files, for the doc reader and discovery, and again after an edit',
|
|
342
349
|
sites: [
|
|
343
|
-
'.import()',
|
|
344
|
-
'createJiti',
|
|
345
|
-
'import(<computed>) ×
|
|
346
|
-
'importUserModule',
|
|
350
|
+
'.import() ×2',
|
|
351
|
+
'createJiti ×2',
|
|
352
|
+
'import(<computed>) ×4',
|
|
353
|
+
'importUserModule ×2',
|
|
347
354
|
],
|
|
348
355
|
},
|
|
349
356
|
'foundation/doc-compiler/read.mjs': {
|
|
350
357
|
runs: 'authored doc files, each one handed to the compiler, with the loader its reader has always used',
|
|
351
358
|
sites: ['importDocModule', 'importNativeModule ×3', 'importTemplateModule'],
|
|
352
359
|
},
|
|
360
|
+
'foundation/render/page-worker.mjs': {
|
|
361
|
+
runs: 'the page `astryx experimental render` renders, its local modules, React, and the StyleX compiler, in a worker',
|
|
362
|
+
sites: ['.import() ×3', 'createJiti ×2', 'require(@stylexjs/babel-plugin)'],
|
|
363
|
+
},
|
|
364
|
+
'foundation/render/render-page.mjs': {
|
|
365
|
+
runs: 'the render worker, so a page that never finishes can be stopped',
|
|
366
|
+
sites: ['worker_threads.Worker'],
|
|
367
|
+
},
|
|
353
368
|
'foundation/fs/module-loader.mjs': {
|
|
354
369
|
runs: 'user modules (config, manifests, handlers, codemods): natively, through jiti, or by require for a fresh CommonJS read',
|
|
355
370
|
sites: [
|