forgebook 0.3.3 → 0.4.0
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 +914 -72
- package/dist/bin/forgebook/agentClient.d.ts +2 -1
- package/dist/bin/forgebook/agentClient.js +13 -6
- package/dist/bin/forgebook/agentGuide.d.ts +59 -0
- package/dist/bin/forgebook/agentGuide.js +203 -0
- package/dist/bin/forgebook/agentLoopCommands.mjs +22 -42
- package/dist/bin/forgebook/agentSetup/agentFiles.d.ts +55 -0
- package/dist/bin/forgebook/agentSetup/agentFiles.js +319 -0
- package/dist/bin/forgebook/agentSetup/assistantHooks.d.ts +71 -0
- package/dist/bin/forgebook/agentSetup/assistantHooks.js +125 -0
- package/dist/bin/forgebook/agentSetup/ciWorkflow.d.ts +23 -0
- package/dist/bin/forgebook/agentSetup/ciWorkflow.js +55 -0
- package/dist/bin/forgebook/agentSetup/drawCandidates.d.ts +25 -0
- package/dist/bin/forgebook/agentSetup/drawCandidates.js +116 -0
- package/dist/bin/forgebook/agentSetup/drawDiagnosis.d.ts +28 -0
- package/dist/bin/forgebook/agentSetup/drawDiagnosis.js +134 -0
- package/dist/bin/forgebook/agentSetup/drawRun.d.ts +91 -0
- package/dist/bin/forgebook/agentSetup/drawRun.js +353 -0
- package/dist/bin/forgebook/agentSetup/hookNames.d.ts +7 -0
- package/dist/bin/forgebook/agentSetup/hookNames.js +7 -0
- package/dist/bin/forgebook/agentSetup/initAgentSteps.d.ts +48 -0
- package/dist/bin/forgebook/agentSetup/initAgentSteps.js +104 -0
- package/dist/bin/forgebook/agentSetup/liftedProviders.d.ts +17 -0
- package/dist/bin/forgebook/agentSetup/liftedProviders.js +186 -0
- package/dist/bin/forgebook/agentSetup/projectRunner.d.ts +46 -0
- package/dist/bin/forgebook/agentSetup/projectRunner.js +85 -0
- package/dist/bin/forgebook/agentSetup/stopHook.d.ts +65 -0
- package/dist/bin/forgebook/agentSetup/stopHook.js +202 -0
- package/dist/bin/forgebook/agentSetup/uniformPicture.d.ts +7 -0
- package/dist/bin/forgebook/agentSetup/uniformPicture.js +98 -0
- package/dist/bin/forgebook/agentSetupCommands.d.mts +14 -0
- package/dist/bin/forgebook/agentSetupCommands.mjs +98 -0
- package/dist/bin/forgebook/agentText.d.ts +23 -3
- package/dist/bin/forgebook/agentText.js +175 -28
- package/dist/bin/forgebook/agents.md +20 -191
- package/dist/bin/forgebook/agentsText.js +2 -1
- package/dist/bin/forgebook/appBuild/appBuild.d.ts +59 -0
- package/dist/bin/forgebook/appBuild/appBuild.js +213 -0
- package/dist/bin/forgebook/appBuild/appViteConfig.d.ts +96 -0
- package/dist/bin/forgebook/appBuild/appViteConfig.js +320 -0
- package/dist/bin/forgebook/appBuild/tsconfigPaths.d.ts +14 -0
- package/dist/bin/forgebook/appBuild/tsconfigPaths.js +80 -0
- package/dist/bin/forgebook/auditCommand.d.mts +8 -0
- package/dist/bin/forgebook/auditCommand.mjs +75 -0
- package/dist/bin/forgebook/auditRun.d.ts +95 -0
- package/dist/bin/forgebook/auditRun.js +270 -0
- package/dist/bin/forgebook/browserRun.d.ts +21 -0
- package/dist/bin/forgebook/browserRun.js +57 -0
- package/dist/bin/forgebook/buildFailure.d.ts +7 -0
- package/dist/bin/forgebook/buildFailure.js +47 -0
- package/dist/bin/forgebook/buildWatch.d.ts +52 -0
- package/dist/bin/forgebook/buildWatch.js +137 -0
- package/dist/bin/forgebook/builtCatalogue.js +9 -5
- package/dist/bin/forgebook/catalogueCommands.d.ts +9 -0
- package/dist/bin/forgebook/catalogueCommands.js +23 -0
- package/dist/bin/forgebook/catalogueVite.d.ts +5 -1
- package/dist/bin/forgebook/catalogueVite.js +14 -6
- package/dist/bin/forgebook/commandCacheClaim.d.ts +18 -0
- package/dist/bin/forgebook/commandCacheClaim.js +170 -0
- package/dist/bin/forgebook/commandServer.d.ts +8 -0
- package/dist/bin/forgebook/commandServer.js +61 -13
- package/dist/bin/forgebook/forgebookCommands.mjs +105 -28
- package/dist/bin/forgebook/graphCommand.d.mts +8 -0
- package/dist/bin/forgebook/graphCommand.mjs +84 -0
- package/dist/bin/forgebook/guide/commands.md +57 -0
- package/dist/bin/forgebook/guide/devices.md +17 -0
- package/dist/bin/forgebook/guide/docs-pages.md +13 -0
- package/dist/bin/forgebook/guide/frameworks/angular.md +22 -0
- package/dist/bin/forgebook/guide/frameworks/html.md +22 -0
- package/dist/bin/forgebook/guide/frameworks/nextjs.md +23 -0
- package/dist/bin/forgebook/guide/frameworks/nuxt.md +22 -0
- package/dist/bin/forgebook/guide/frameworks/preact.md +16 -0
- package/dist/bin/forgebook/guide/frameworks/react-native-web.md +21 -0
- package/dist/bin/forgebook/guide/frameworks/react.md +16 -0
- package/dist/bin/forgebook/guide/frameworks/solid.md +18 -0
- package/dist/bin/forgebook/guide/frameworks/svelte.md +18 -0
- package/dist/bin/forgebook/guide/frameworks/sveltekit.md +23 -0
- package/dist/bin/forgebook/guide/frameworks/vue.md +18 -0
- package/dist/bin/forgebook/guide/frameworks/web-components.md +21 -0
- package/dist/bin/forgebook/guide/links.md +29 -0
- package/dist/bin/forgebook/guide/setup.md +23 -0
- package/dist/bin/forgebook/guide/stories.md +90 -0
- package/dist/bin/forgebook/guide/switches.md +43 -0
- package/dist/bin/forgebook/guideCommand.d.mts +13 -0
- package/dist/bin/forgebook/guideCommand.mjs +37 -0
- package/dist/bin/forgebook/importers/storybook.d.ts +21 -0
- package/dist/bin/forgebook/importers/storybook.js +11 -5
- package/dist/bin/forgebook/importers/storybookFrameworks.js +1 -1
- package/dist/bin/forgebook/initCommands.d.mts +11 -0
- package/dist/bin/forgebook/initCommands.mjs +51 -78
- package/dist/bin/forgebook/initConfig.d.ts +5 -3
- package/dist/bin/forgebook/initConfig.js +6 -3
- package/dist/bin/forgebook/initInstall.d.ts +15 -0
- package/dist/bin/forgebook/initInstall.js +77 -0
- package/dist/bin/forgebook/initPrint.d.ts +9 -0
- package/dist/bin/forgebook/initPrint.js +60 -0
- package/dist/bin/forgebook/initRefusals.d.ts +45 -0
- package/dist/bin/forgebook/initRefusals.js +91 -0
- package/dist/bin/forgebook/initRun.d.ts +28 -0
- package/dist/bin/forgebook/initRun.js +311 -0
- package/dist/bin/forgebook/mcpCommand.mjs +38 -4
- package/dist/bin/forgebook/mcpGraph.d.ts +13 -0
- package/dist/bin/forgebook/mcpGraph.js +24 -0
- package/dist/bin/forgebook/mcpTokens.d.ts +14 -0
- package/dist/bin/forgebook/mcpTokens.js +58 -0
- package/dist/bin/forgebook/mcpToolParts.d.ts +7 -0
- package/dist/bin/forgebook/mcpToolParts.js +10 -0
- package/dist/bin/forgebook/mcpTools.d.ts +13 -6
- package/dist/bin/forgebook/mcpTools.js +57 -90
- package/dist/bin/forgebook/mcpVerify.d.ts +16 -0
- package/dist/bin/forgebook/mcpVerify.js +36 -0
- package/dist/bin/forgebook/migrate/codemods.d.ts +11 -0
- package/dist/bin/forgebook/migrate/codemods.js +61 -0
- package/dist/bin/forgebook/migrate/migrate.types.d.ts +117 -0
- package/dist/bin/forgebook/migrate/migrate.types.js +5 -0
- package/dist/bin/forgebook/migrate/migrateCommand.d.mts +8 -0
- package/dist/bin/forgebook/migrate/migrateCommand.mjs +76 -0
- package/dist/bin/forgebook/migrate/migrateRun.d.ts +61 -0
- package/dist/bin/forgebook/migrate/migrateRun.js +210 -0
- package/dist/bin/forgebook/migrate/migrateText.d.ts +12 -0
- package/dist/bin/forgebook/migrate/migrateText.js +30 -0
- package/dist/bin/forgebook/migrate/migrateWrite.d.ts +27 -0
- package/dist/bin/forgebook/migrate/migrateWrite.js +66 -0
- package/dist/bin/forgebook/migrate/objectEdits.d.ts +70 -0
- package/dist/bin/forgebook/migrate/objectEdits.js +241 -0
- package/dist/bin/forgebook/migrate/playOnInBuilds.d.ts +3 -0
- package/dist/bin/forgebook/migrate/playOnInBuilds.js +86 -0
- package/dist/bin/forgebook/migrate/propGroupStrings.d.ts +5 -0
- package/dist/bin/forgebook/migrate/propGroupStrings.js +81 -0
- package/dist/bin/forgebook/newProject/newProject.d.ts +39 -0
- package/dist/bin/forgebook/newProject/newProject.js +180 -0
- package/dist/bin/forgebook/newProject/newProject.types.d.ts +97 -0
- package/dist/bin/forgebook/newProject/newProject.types.js +6 -0
- package/dist/bin/forgebook/newProject/packageManagers.d.ts +51 -0
- package/dist/bin/forgebook/newProject/packageManagers.js +121 -0
- package/dist/bin/forgebook/newProject/projectEntries.d.ts +62 -0
- package/dist/bin/forgebook/newProject/projectEntries.js +191 -0
- package/dist/bin/forgebook/newProject/projectFrameworks.d.ts +57 -0
- package/dist/bin/forgebook/newProject/projectFrameworks.js +148 -0
- package/dist/bin/forgebook/newProject/projectLook.d.ts +23 -0
- package/dist/bin/forgebook/newProject/projectLook.js +293 -0
- package/dist/bin/forgebook/newProject/projectPackages.d.ts +66 -0
- package/dist/bin/forgebook/newProject/projectPackages.js +178 -0
- package/dist/bin/forgebook/newRepair.d.ts +45 -0
- package/dist/bin/forgebook/newRepair.js +157 -0
- package/dist/bin/forgebook/newRepairRun.d.ts +69 -0
- package/dist/bin/forgebook/newRepairRun.js +148 -0
- package/dist/bin/forgebook/newStories.d.ts +23 -1
- package/dist/bin/forgebook/newStories.js +101 -11
- package/dist/bin/forgebook/newStoriesFile.d.ts +20 -1
- package/dist/bin/forgebook/newStoriesFile.js +43 -4
- package/dist/bin/forgebook/prebundleRun.d.ts +3 -1
- package/dist/bin/forgebook/prebundleRun.js +28 -8
- package/dist/bin/forgebook/proofCommand.d.mts +15 -0
- package/dist/bin/forgebook/proofCommand.mjs +212 -0
- package/dist/bin/forgebook/proofRun.d.ts +63 -0
- package/dist/bin/forgebook/proofRun.js +412 -0
- package/dist/bin/forgebook/proofText.d.ts +36 -0
- package/dist/bin/forgebook/proofText.js +131 -0
- package/dist/bin/forgebook/proofWorkflow.d.ts +29 -0
- package/dist/bin/forgebook/proofWorkflow.js +205 -0
- package/dist/bin/forgebook/setArgsTool.d.ts +8 -0
- package/dist/bin/forgebook/setArgsTool.js +70 -0
- package/dist/bin/forgebook/storyCheckCommands.mjs +42 -3
- package/dist/bin/forgebook/storyCheckRun.d.ts +50 -0
- package/dist/bin/forgebook/storyCheckRun.js +83 -9
- package/dist/bin/forgebook/storyFileIds.d.ts +15 -0
- package/dist/bin/forgebook/storyFileIds.js +14 -0
- package/dist/bin/forgebook/stressCases.d.ts +31 -0
- package/dist/bin/forgebook/stressCases.js +79 -0
- package/dist/bin/forgebook/stressRun.d.ts +12 -0
- package/dist/bin/forgebook/stressRun.js +61 -0
- package/dist/bin/forgebook/stressText.d.ts +27 -0
- package/dist/bin/forgebook/stressText.js +46 -0
- package/dist/bin/forgebook/verifyBase.d.ts +45 -0
- package/dist/bin/forgebook/verifyBase.js +196 -0
- package/dist/bin/forgebook/verifyCommand.d.mts +13 -0
- package/dist/bin/forgebook/verifyCommand.mjs +125 -0
- package/dist/bin/forgebook/verifyRun.d.ts +63 -0
- package/dist/bin/forgebook/verifyRun.js +108 -0
- package/dist/bin/forgebook/verifyVerdict.d.ts +40 -0
- package/dist/bin/forgebook/verifyVerdict.js +297 -0
- package/dist/bin/forgebook/workflowActions.d.ts +23 -0
- package/dist/bin/forgebook/workflowActions.js +23 -0
- package/dist/bin/forgebook-docs/catalogueMarkdown.js +12 -1
- package/dist/src/addressArgs.d.ts +29 -5
- package/dist/src/addressArgs.js +58 -16
- package/dist/src/addressArgsParam.d.ts +54 -0
- package/dist/src/addressArgsParam.js +51 -0
- package/dist/src/addressTexts.d.ts +14 -0
- package/dist/src/addressTexts.js +28 -21
- package/dist/src/agentIndexFile.d.ts +11 -0
- package/dist/src/agentIndexFile.js +11 -0
- package/dist/src/argConditions.d.ts +52 -0
- package/dist/src/argConditions.js +80 -0
- package/dist/src/argControl.d.ts +100 -0
- package/dist/src/argControl.js +0 -0
- package/dist/src/argExpression.d.ts +21 -0
- package/dist/src/argExpression.js +30 -0
- package/dist/src/argTypes.d.ts +40 -51
- package/dist/src/argTypes.js +66 -184
- package/dist/src/argsProps.d.ts +3 -3
- package/dist/src/argsProps.js +11 -5
- package/dist/src/bundlerErrors.d.ts +29 -0
- package/dist/src/bundlerErrors.js +49 -0
- package/dist/src/catalogue.d.ts +31 -0
- package/dist/src/catalogue.js +13 -2
- package/dist/src/catalogueRefs.d.ts +75 -0
- package/dist/src/catalogueRefs.js +122 -0
- package/dist/src/componentDocs.d.ts +71 -0
- package/dist/src/componentDocs.js +15 -2
- package/dist/src/frame/callValues.d.ts +19 -0
- package/dist/src/frame/callValues.js +58 -0
- package/dist/src/frame/canvasScheme.d.ts +33 -0
- package/dist/src/frame/canvasScheme.js +67 -0
- package/dist/src/frame/frame.css +36 -3
- package/dist/src/frame/frameStatus.d.ts +16 -1
- package/dist/src/frame/frameStatus.js +16 -1
- package/dist/src/frame/frameView.js +4 -3
- package/dist/src/frame/mountFrame.d.ts +7 -1
- package/dist/src/frame/mountFrame.js +153 -46
- package/dist/src/frame/panelValues.d.ts +35 -0
- package/dist/src/frame/panelValues.js +127 -0
- package/dist/src/frame/playActions.d.ts +39 -0
- package/dist/src/frame/playActions.js +98 -0
- package/dist/src/frame/playStepper.d.ts +28 -0
- package/dist/src/frame/playStepper.js +38 -0
- package/dist/src/frame/playStory.d.ts +9 -1
- package/dist/src/frame/playStory.js +49 -3
- package/dist/src/frame/renderer.d.ts +34 -1
- package/dist/src/frame/renderer.js +24 -0
- package/dist/src/frame/shellChannel.d.ts +1 -1
- package/dist/src/frame/shellChannel.js +1 -1
- package/dist/src/frame/shellCheck.d.ts +17 -0
- package/dist/src/frame/shellCheck.js +25 -0
- package/dist/src/frame/shellMessageCheck.d.ts +7 -0
- package/dist/src/frame/shellMessageCheck.js +53 -0
- package/dist/src/frame/storyContent.d.ts +50 -0
- package/dist/src/frame/storyContent.js +73 -0
- package/dist/src/frame/storyModule.d.ts +9 -0
- package/dist/src/frame/storyModule.js +20 -2
- package/dist/src/frame/storyRun.d.ts +15 -7
- package/dist/src/frame/storyRun.js +64 -15
- package/dist/src/frame/valueSheets.d.ts +35 -0
- package/dist/src/frame/valueSheets.js +99 -0
- package/dist/src/hotModules.d.ts +20 -0
- package/dist/src/hotModules.js +23 -0
- package/dist/src/jsxCode.d.ts +1 -14
- package/dist/src/jsxCode.js +46 -10
- package/dist/src/liveErrors.d.ts +30 -4
- package/dist/src/liveErrors.js +18 -3
- package/dist/src/messages.d.ts +77 -27
- package/dist/src/messages.js +58 -100
- package/dist/src/namedValues.d.ts +2 -26
- package/dist/src/namedValues.js +0 -47
- package/dist/src/pageConfig.d.ts +2 -0
- package/dist/src/playTrace.d.ts +19 -2
- package/dist/src/playTrace.js +10 -5
- package/dist/src/plugin.d.ts +10 -3
- package/dist/src/previewRelay.js +9 -1
- package/dist/src/printable.d.ts +12 -0
- package/dist/src/printable.js +22 -0
- package/dist/src/propsSignature.d.ts +37 -0
- package/dist/src/propsSignature.js +40 -0
- package/dist/src/search.d.ts +41 -5
- package/dist/src/search.js +93 -23
- package/dist/src/searchMatch.d.ts +4 -1
- package/dist/src/searchMatch.js +26 -5
- package/dist/src/searchTypos.d.ts +88 -0
- package/dist/src/searchTypos.js +178 -0
- package/dist/src/shapeValues.d.ts +86 -0
- package/dist/src/shapeValues.js +295 -0
- package/dist/src/shell/ApiReference.js +6 -3
- package/dist/src/shell/ApiTableBox.d.ts +15 -0
- package/dist/src/shell/ApiTableBox.js +11 -0
- package/dist/src/shell/AppearanceMenu.d.ts +4 -1
- package/dist/src/shell/AppearanceMenu.js +9 -6
- package/dist/src/shell/CodeTab.d.ts +3 -2
- package/dist/src/shell/CodeTab.js +3 -2
- package/dist/src/shell/CodeText.d.ts +1 -1
- package/dist/src/shell/CodeText.js +2 -3
- package/dist/src/shell/CompareGrid.js +1 -1
- package/dist/src/shell/ComponentPage.d.ts +1 -1
- package/dist/src/shell/ComponentPage.js +5 -1
- package/dist/src/shell/CustomControl.d.ts +34 -0
- package/dist/src/shell/CustomControl.js +132 -0
- package/dist/src/shell/DocContainers.js +1 -1
- package/dist/src/shell/DocPage.js +2 -2
- package/dist/src/shell/DroppedArgsList.d.ts +2 -2
- package/dist/src/shell/DroppedArgsList.js +1 -1
- package/dist/src/shell/EmbedPage.js +30 -12
- package/dist/src/shell/Example.d.ts +5 -1
- package/dist/src/shell/Example.js +16 -8
- package/dist/src/shell/FrameView.d.ts +6 -3
- package/dist/src/shell/FrameView.js +2 -2
- package/dist/src/shell/HomePage.d.ts +3 -1
- package/dist/src/shell/HomePage.js +16 -6
- package/dist/src/shell/InfoTip.js +2 -2
- package/dist/src/shell/InteractionsTab.d.ts +11 -4
- package/dist/src/shell/InteractionsTab.js +18 -2
- package/dist/src/shell/LazyPage.js +1 -1
- package/dist/src/shell/PackageHtml.js +3 -1
- package/dist/src/shell/PinnedControl.js +14 -62
- package/dist/src/shell/PinnedControlMenu.d.ts +44 -0
- package/dist/src/shell/PinnedControlMenu.js +72 -0
- package/dist/src/shell/PropFields.d.ts +3 -1
- package/dist/src/shell/PropFields.js +9 -6
- package/dist/src/shell/PropRows.d.ts +23 -2
- package/dist/src/shell/PropRows.js +58 -19
- package/dist/src/shell/PropsTab.d.ts +12 -5
- package/dist/src/shell/PropsTab.js +9 -21
- package/dist/src/shell/RefStoryPage.d.ts +33 -0
- package/dist/src/shell/RefStoryPage.js +123 -0
- package/dist/src/shell/SearchPanel.js +51 -24
- package/dist/src/shell/Shell.d.ts +18 -0
- package/dist/src/shell/Shell.js +137 -22
- package/dist/src/shell/ShortcutHelp.d.ts +22 -0
- package/dist/src/shell/ShortcutHelp.js +66 -0
- package/dist/src/shell/Sidebar.d.ts +17 -4
- package/dist/src/shell/Sidebar.js +92 -41
- package/dist/src/shell/SidebarDocs.js +2 -2
- package/dist/src/shell/SidebarEntries.js +5 -3
- package/dist/src/shell/SidebarHandle.d.ts +3 -5
- package/dist/src/shell/SidebarHandle.js +4 -4
- package/dist/src/shell/SidebarRefs.d.ts +39 -0
- package/dist/src/shell/SidebarRefs.js +99 -0
- package/dist/src/shell/SidebarSearch.js +37 -9
- package/dist/src/shell/SignatureReference.js +3 -1
- package/dist/src/shell/Stage.d.ts +10 -2
- package/dist/src/shell/Stage.js +29 -49
- package/dist/src/shell/StatusBadges.d.ts +54 -0
- package/dist/src/shell/StatusBadges.js +77 -0
- package/dist/src/shell/StoryCodeBlock.d.ts +8 -19
- package/dist/src/shell/StoryCodeBlock.js +7 -6
- package/dist/src/shell/SwitchGallery.d.ts +36 -0
- package/dist/src/shell/SwitchGallery.js +17 -0
- package/dist/src/shell/SwitchGalleryPanel.d.ts +37 -0
- package/dist/src/shell/SwitchGalleryPanel.js +99 -0
- package/dist/src/shell/TagFilter.d.ts +24 -0
- package/dist/src/shell/TagFilter.js +45 -0
- package/dist/src/shell/TagViews.d.ts +39 -0
- package/dist/src/shell/TagViews.js +20 -0
- package/dist/src/shell/Toolbar.d.ts +4 -1
- package/dist/src/shell/Toolbar.js +17 -7
- package/dist/src/shell/ToolbarControl.d.ts +3 -0
- package/dist/src/shell/ToolbarControl.js +23 -6
- package/dist/src/shell/ViewMenuPanel.js +6 -1
- package/dist/src/shell/argChecks.d.ts +22 -0
- package/dist/src/shell/argChecks.js +20 -0
- package/dist/src/shell/asideStory.js +7 -2
- package/dist/src/shell/audienceSections.css +9 -9
- package/dist/src/shell/catalogueContext.d.ts +1 -1
- package/dist/src/shell/catalogueContext.js +6 -1
- package/dist/src/shell/codeSpans.d.ts +27 -0
- package/dist/src/shell/codeSpans.js +76 -0
- package/dist/src/shell/compareVariants.d.ts +4 -2
- package/dist/src/shell/compareVariants.js +16 -8
- package/dist/src/shell/composition.d.ts +23 -0
- package/dist/src/shell/composition.js +26 -0
- package/dist/src/shell/controlCycle.d.ts +1 -1
- package/dist/src/shell/controlCycle.js +3 -2
- package/dist/src/shell/customControls.d.ts +55 -0
- package/dist/src/shell/customControls.js +70 -0
- package/dist/src/shell/docPage.css +22 -22
- package/dist/src/shell/dockTabs.d.ts +19 -3
- package/dist/src/shell/dockTabs.js +28 -20
- package/dist/src/shell/embed.css +7 -7
- package/dist/src/shell/framesOrigin.d.ts +7 -0
- package/dist/src/shell/framesOrigin.js +1 -1
- package/dist/src/shell/galleryPlace.d.ts +20 -0
- package/dist/src/shell/galleryPlace.js +26 -0
- package/dist/src/shell/icons.d.ts +1 -0
- package/dist/src/shell/icons.js +1 -0
- package/dist/src/shell/keyboard.d.ts +14 -12
- package/dist/src/shell/keyboard.js +21 -6
- package/dist/src/shell/laterStrings.d.ts +29 -0
- package/dist/src/shell/laterStrings.js +42 -3
- package/dist/src/shell/mountShell.js +3 -0
- package/dist/src/shell/pageStrings.d.ts +4 -0
- package/dist/src/shell/pageStrings.js +4 -0
- package/dist/src/shell/pageTagView.d.ts +18 -0
- package/dist/src/shell/pageTagView.js +10 -0
- package/dist/src/shell/playMemory.d.ts +14 -0
- package/dist/src/shell/playMemory.js +8 -0
- package/dist/src/shell/propNotes.d.ts +23 -0
- package/dist/src/shell/propNotes.js +37 -0
- package/dist/src/shell/refIndexLoad.d.ts +17 -0
- package/dist/src/shell/refIndexLoad.js +38 -0
- package/dist/src/shell/refParts.d.ts +34 -0
- package/dist/src/shell/refParts.js +9 -0
- package/dist/src/shell/refStory.css +21 -0
- package/dist/src/shell/refStrings.d.ts +13 -0
- package/dist/src/shell/refStrings.js +21 -0
- package/dist/src/shell/search.css +11 -11
- package/dist/src/shell/shell.css +348 -168
- package/dist/src/shell/shellScheme.js +2 -2
- package/dist/src/shell/shortcutHelp.css +64 -0
- package/dist/src/shell/stageArgs.d.ts +53 -0
- package/dist/src/shell/stageArgs.js +64 -0
- package/dist/src/shell/statusBadges.css +51 -0
- package/dist/src/shell/strings.d.ts +7 -16
- package/dist/src/shell/strings.js +12 -17
- package/dist/src/shell/switchGallery.css +104 -0
- package/dist/src/shell/tagFilter.css +46 -0
- package/dist/src/shell/tagView.d.ts +20 -0
- package/dist/src/shell/tagView.js +10 -0
- package/dist/src/shell/useAddressArgs.d.ts +9 -0
- package/dist/src/shell/useAddressArgs.js +56 -11
- package/dist/src/shell/useControlKeys.js +2 -2
- package/dist/src/shell/useEditedProblems.d.ts +6 -0
- package/dist/src/shell/useEditedProblems.js +40 -0
- package/dist/src/shell/useFrameMessages.js +3 -0
- package/dist/src/shell/useListedTree.d.ts +13 -0
- package/dist/src/shell/useListedTree.js +32 -0
- package/dist/src/shell/usePageFrames.js +2 -2
- package/dist/src/shell/usePopover.d.ts +5 -0
- package/dist/src/shell/usePopover.js +7 -1
- package/dist/src/shell/useRefIndex.d.ts +22 -0
- package/dist/src/shell/useRefIndex.js +36 -0
- package/dist/src/shell/useScrollStops.d.ts +20 -0
- package/dist/src/shell/useScrollStops.js +41 -0
- package/dist/src/shell/useShortcutHelp.d.ts +18 -0
- package/dist/src/shell/useShortcutHelp.js +32 -0
- package/dist/src/shell/useSidebarOverlay.d.ts +2 -1
- package/dist/src/shell/useSidebarOverlay.js +12 -4
- package/dist/src/shell/useStoryCode.d.ts +2 -1
- package/dist/src/shell/useStoryCode.js +12 -7
- package/dist/src/shell/useToolbarLayout.d.ts +5 -1
- package/dist/src/shell/useToolbarLayout.js +2 -2
- package/dist/src/shell/useWorstCase.d.ts +8 -2
- package/dist/src/shell/useWorstCase.js +2 -2
- package/dist/src/shell/valueEditors/FileEditor.d.ts +28 -0
- package/dist/src/shell/valueEditors/FileEditor.js +66 -0
- package/dist/src/shell/valueEditors/JsonEditor.d.ts +14 -0
- package/dist/src/shell/valueEditors/JsonEditor.js +53 -0
- package/dist/src/shell/valueEditors/ListEditor.d.ts +24 -0
- package/dist/src/shell/valueEditors/ListEditor.js +82 -0
- package/dist/src/shell/valueEditors/ObjectEditor.d.ts +32 -0
- package/dist/src/shell/valueEditors/ObjectEditor.js +70 -0
- package/dist/src/shell/valueEditors/PropEditor.d.ts +37 -0
- package/dist/src/shell/valueEditors/PropEditor.js +53 -0
- package/dist/src/shell/valueEditors/RecordEditor.d.ts +20 -0
- package/dist/src/shell/valueEditors/RecordEditor.js +84 -0
- package/dist/src/shell/valueEditors/SearchSelect.d.ts +42 -0
- package/dist/src/shell/valueEditors/SearchSelect.js +80 -0
- package/dist/src/shell/valueEditors/TokenEditor.d.ts +49 -0
- package/dist/src/shell/valueEditors/TokenEditor.js +74 -0
- package/dist/src/shell/valueEditors/UnionEditor.d.ts +20 -0
- package/dist/src/shell/valueEditors/UnionEditor.js +64 -0
- package/dist/src/shell/valueEditors/ValueField.d.ts +15 -0
- package/dist/src/shell/valueEditors/ValueField.js +147 -0
- package/dist/src/shell/valueEditors/editorStrings.d.ts +56 -0
- package/dist/src/shell/valueEditors/editorStrings.js +66 -0
- package/dist/src/shell/valueEditors/fieldTypes.d.ts +31 -0
- package/dist/src/shell/valueEditors/fieldTypes.js +0 -0
- package/dist/src/shell/valueEditors/valueEditors.css +153 -0
- package/dist/src/shell/worstArgs.d.ts +8 -5
- package/dist/src/shell/worstArgs.js +14 -7
- package/dist/src/shellTheme.d.ts +1 -1
- package/dist/src/shellTheme.js +15 -1
- package/dist/src/shellTheme.types.d.ts +4 -0
- package/dist/src/shellWord.d.ts +12 -0
- package/dist/src/shellWord.js +15 -0
- package/dist/src/sourceFiles.js +2 -1
- package/dist/src/storyArgTypes.d.ts +57 -0
- package/dist/src/storyArgTypes.js +195 -0
- package/dist/src/storyBackground.js +14 -3
- package/dist/src/storyCheck.d.ts +85 -3
- package/dist/src/storyCheck.js +23 -1
- package/dist/src/storyCodeText.d.ts +46 -0
- package/dist/src/storyCodeText.js +27 -0
- package/dist/src/storyControls.d.ts +100 -0
- package/dist/src/storyControls.js +100 -0
- package/dist/src/storyStatuses.d.ts +55 -0
- package/dist/src/storyStatuses.js +104 -0
- package/dist/src/storyTagNames.d.ts +25 -0
- package/dist/src/storyTagNames.js +25 -0
- package/dist/src/storyTags.d.ts +29 -0
- package/dist/src/storyTags.js +85 -0
- package/dist/src/storyTree.d.ts +13 -0
- package/dist/src/storyTree.js +24 -4
- package/dist/src/storybookArgs.d.ts +24 -0
- package/dist/src/storybookArgs.js +185 -0
- package/dist/src/switches.d.ts +66 -3
- package/dist/src/switches.js +42 -1
- package/dist/src/valueSchema.d.ts +28 -0
- package/dist/src/valueSchema.js +196 -0
- package/dist/src/valueShape.d.ts +94 -0
- package/dist/src/valueShape.js +25 -0
- package/dist/src/viewState.d.ts +8 -3
- package/dist/src/viewState.js +27 -10
- package/dist/src/vite/adapter.d.ts +40 -2
- package/dist/src/vite/adapter.js +1 -0
- package/dist/src/vite/agent.types.d.ts +347 -7
- package/dist/src/vite/agentApi.d.ts +23 -0
- package/dist/src/vite/agentApi.js +90 -17
- package/dist/src/vite/agentIndex.d.ts +0 -2
- package/dist/src/vite/agentIndex.js +5 -6
- package/dist/src/vite/agentRoutes.d.ts +20 -1
- package/dist/src/vite/agentRoutes.js +106 -65
- package/dist/src/vite/agentStatuses.d.ts +42 -0
- package/dist/src/vite/agentStatuses.js +67 -0
- package/dist/src/vite/agentStoryCode.d.ts +48 -0
- package/dist/src/vite/agentStoryCode.js +38 -0
- package/dist/src/vite/agentVisibility.d.ts +47 -0
- package/dist/src/vite/agentVisibility.js +174 -0
- package/dist/src/vite/appAudit.d.ts +134 -0
- package/dist/src/vite/appAudit.js +333 -0
- package/dist/src/vite/appBuildOption.d.ts +53 -0
- package/dist/src/vite/appBuildOption.js +55 -0
- package/dist/src/vite/appTokenFiles.d.ts +92 -0
- package/dist/src/vite/appTokenFiles.js +433 -0
- package/dist/src/vite/appTokens.d.ts +23 -0
- package/dist/src/vite/appTokens.js +275 -0
- package/dist/src/vite/builtTexts.d.ts +10 -0
- package/dist/src/vite/builtTexts.js +59 -22
- package/dist/src/vite/catalogueConfig.d.ts +3 -1
- package/dist/src/vite/catalogueConfig.js +15 -3
- package/dist/src/vite/changeCoverage.d.ts +74 -0
- package/dist/src/vite/changeCoverage.js +120 -0
- package/dist/src/vite/changedRoute.d.ts +30 -0
- package/dist/src/vite/changedRoute.js +197 -0
- package/dist/src/vite/checkCode.d.ts +105 -3
- package/dist/src/vite/checkCode.js +323 -36
- package/dist/src/vite/checkoutWatch.d.ts +97 -0
- package/dist/src/vite/checkoutWatch.js +287 -0
- package/dist/src/vite/closeWatch.d.ts +8 -0
- package/dist/src/vite/closeWatch.js +1 -1
- package/dist/src/vite/componentCache.d.ts +8 -0
- package/dist/src/vite/componentCache.js +66 -0
- package/dist/src/vite/componentGraph.d.ts +71 -0
- package/dist/src/vite/componentGraph.js +133 -0
- package/dist/src/vite/componentRules.d.ts +33 -0
- package/dist/src/vite/componentRules.js +105 -0
- package/dist/src/vite/componentScan.d.ts +69 -0
- package/dist/src/vite/componentScan.js +418 -0
- package/dist/src/vite/compositionCheck.d.ts +15 -0
- package/dist/src/vite/compositionCheck.js +243 -0
- package/dist/src/vite/config.d.ts +32 -1
- package/dist/src/vite/configFile.d.ts +14 -2
- package/dist/src/vite/configFile.js +124 -40
- package/dist/src/vite/configKeys.d.ts +15 -0
- package/dist/src/vite/configKeys.js +171 -0
- package/dist/src/vite/configLoadError.d.ts +23 -0
- package/dist/src/vite/configLoadError.js +71 -0
- package/dist/src/vite/cssDeclarations.d.ts +71 -0
- package/dist/src/vite/cssDeclarations.js +290 -0
- package/dist/src/vite/cssImports.d.ts +14 -0
- package/dist/src/vite/cssImports.js +48 -0
- package/dist/src/vite/cssReferences.d.ts +54 -0
- package/dist/src/vite/cssReferences.js +157 -0
- package/dist/src/vite/cssTokenValues.d.ts +50 -0
- package/dist/src/vite/cssTokenValues.js +233 -0
- package/dist/src/vite/designTokens.d.ts +24 -0
- package/dist/src/vite/designTokens.js +5 -1
- package/dist/src/vite/docsExtractor.d.ts +9 -3
- package/dist/src/vite/docsExtractor.js +11 -3
- package/dist/src/vite/docsProgram.d.ts +17 -4
- package/dist/src/vite/docsProgram.js +52 -11
- package/dist/src/vite/docsWorker.js +7 -2
- package/dist/src/vite/emptyStoryGlobs.d.ts +41 -0
- package/dist/src/vite/emptyStoryGlobs.js +52 -0
- package/dist/src/vite/fileImports.d.ts +17 -0
- package/dist/src/vite/fileImports.js +57 -0
- package/dist/src/vite/findComponent.d.ts +10 -2
- package/dist/src/vite/findComponent.js +27 -22
- package/dist/src/vite/findRoute.js +3 -2
- package/dist/src/vite/forcedStates.d.ts +9 -2
- package/dist/src/vite/forcedStates.js +12 -3
- package/dist/src/vite/forgebookPlugin.d.ts +2 -0
- package/dist/src/vite/forgebookPlugin.js +52 -72
- package/dist/src/vite/frameErrors.d.ts +19 -0
- package/dist/src/vite/frameErrors.js +70 -0
- package/dist/src/vite/framesServer.d.ts +12 -0
- package/dist/src/vite/framesServer.js +21 -4
- package/dist/src/vite/functionComponentDocs.js +81 -12
- package/dist/src/vite/generatedModules.js +4 -2
- package/dist/src/vite/gitChange.d.ts +38 -5
- package/dist/src/vite/gitChange.js +71 -11
- package/dist/src/vite/hiddenStoryFiles.d.ts +23 -0
- package/dist/src/vite/hiddenStoryFiles.js +107 -0
- package/dist/src/vite/hotSnippets.d.ts +38 -14
- package/dist/src/vite/hotSnippets.js +137 -39
- package/dist/src/vite/importedNames.d.ts +37 -0
- package/dist/src/vite/importedNames.js +138 -0
- package/dist/src/vite/indexFields.d.ts +6 -0
- package/dist/src/vite/indexFields.js +21 -0
- package/dist/src/vite/indexStoryFile.d.ts +8 -1
- package/dist/src/vite/indexStoryFile.js +22 -157
- package/dist/src/vite/jsxCallSites.d.ts +33 -0
- package/dist/src/vite/jsxCallSites.js +200 -0
- package/dist/src/vite/jsxInScripts.d.ts +67 -0
- package/dist/src/vite/jsxInScripts.js +138 -0
- package/dist/src/vite/jsxTree.d.ts +20 -0
- package/dist/src/vite/jsxTree.js +163 -0
- package/dist/src/vite/lineAndColumn.d.ts +13 -0
- package/dist/src/vite/lineAndColumn.js +18 -0
- package/dist/src/vite/lookAlikes.d.ts +65 -0
- package/dist/src/vite/lookAlikes.js +228 -0
- package/dist/src/vite/nearestToken.d.ts +17 -0
- package/dist/src/vite/nearestToken.js +9 -2
- package/dist/src/vite/packageEntries.d.ts +42 -0
- package/dist/src/vite/packageEntries.js +127 -0
- package/dist/src/vite/pages.d.ts +9 -1
- package/dist/src/vite/pages.js +108 -4
- package/dist/src/vite/pluginConfig.js +4 -0
- package/dist/src/vite/pluginIds.d.ts +2 -0
- package/dist/src/vite/pluginIds.js +5 -1
- package/dist/src/vite/pluginModules.d.ts +81 -11
- package/dist/src/vite/pluginModules.js +109 -21
- package/dist/src/vite/prebundled.d.ts +57 -15
- package/dist/src/vite/prebundled.js +80 -0
- package/dist/src/vite/previewTags.d.ts +25 -0
- package/dist/src/vite/previewTags.js +56 -0
- package/dist/src/vite/projectFiles.d.ts +54 -0
- package/dist/src/vite/projectFiles.js +116 -0
- package/dist/src/vite/projectPostcss.d.ts +70 -0
- package/dist/src/vite/projectPostcss.js +250 -0
- package/dist/src/vite/propDocs.d.ts +12 -0
- package/dist/src/vite/propDocs.js +130 -58
- package/dist/src/vite/propKind.d.ts +40 -0
- package/dist/src/vite/propKind.js +71 -0
- package/dist/src/vite/propTypeNotes.d.ts +22 -0
- package/dist/src/vite/propTypeNotes.js +51 -0
- package/dist/src/vite/publishedExports.d.ts +27 -0
- package/dist/src/vite/publishedExports.js +298 -0
- package/dist/src/vite/realFolder.d.ts +6 -0
- package/dist/src/vite/realFolder.js +25 -0
- package/dist/src/vite/refsConfig.d.ts +39 -0
- package/dist/src/vite/refsConfig.js +54 -0
- package/dist/src/vite/reuseCheck.d.ts +45 -0
- package/dist/src/vite/reuseCheck.js +260 -0
- package/dist/src/vite/runningVersions.d.ts +33 -0
- package/dist/src/vite/runningVersions.js +25 -0
- package/dist/src/vite/scriptProblems.d.ts +60 -0
- package/dist/src/vite/scriptProblems.js +155 -0
- package/dist/src/vite/searchModule.js +3 -2
- package/dist/src/vite/searchRoute.js +4 -2
- package/dist/src/vite/shapeDocs.d.ts +36 -0
- package/dist/src/vite/shapeDocs.js +177 -0
- package/dist/src/vite/singleFileComponent.d.ts +17 -0
- package/dist/src/vite/singleFileComponent.js +83 -0
- package/dist/src/vite/sourceText.d.ts +34 -0
- package/dist/src/vite/sourceText.js +72 -0
- package/dist/src/vite/sourceTokens.d.ts +7 -0
- package/dist/src/vite/sourceTokens.js +7 -2
- package/dist/src/vite/stackLines.d.ts +49 -0
- package/dist/src/vite/stackLines.js +96 -0
- package/dist/src/vite/storyCode.d.ts +22 -7
- package/dist/src/vite/storyCode.js +263 -37
- package/dist/src/vite/storyCoverage.d.ts +48 -0
- package/dist/src/vite/storyCoverage.js +179 -0
- package/dist/src/vite/storyFilesModule.d.ts +48 -3
- package/dist/src/vite/storyFilesModule.js +105 -15
- package/dist/src/vite/storyPatterns.d.ts +31 -0
- package/dist/src/vite/storyPatterns.js +140 -5
- package/dist/src/vite/storyReach.d.ts +10 -2
- package/dist/src/vite/storyReach.js +15 -11
- package/dist/src/vite/storyTopLevel.d.ts +51 -0
- package/dist/src/vite/storyTopLevel.js +146 -0
- package/dist/src/vite/storylessRoutes.d.ts +4 -3
- package/dist/src/vite/storylessRoutes.js +210 -19
- package/dist/src/vite/switchValuesCheck.d.ts +19 -0
- package/dist/src/vite/switchValuesCheck.js +164 -0
- package/dist/src/vite/switchesDocument.d.ts +15 -0
- package/dist/src/vite/switchesDocument.js +47 -0
- package/dist/src/vite/tailwindConfigTokens.d.ts +41 -0
- package/dist/src/vite/tailwindConfigTokens.js +306 -0
- package/dist/src/vite/textImports.d.ts +15 -0
- package/dist/src/vite/textImports.js +58 -0
- package/dist/src/vite/textModules.d.ts +6 -5
- package/dist/src/vite/textModules.js +13 -8
- package/dist/src/vite/tokenAnswers.d.ts +6 -2
- package/dist/src/vite/tokenAnswers.js +11 -7
- package/dist/src/vite/typeParameters.d.ts +83 -0
- package/dist/src/vite/typeParameters.js +270 -0
- package/dist/src/vite/unionProps.d.ts +37 -0
- package/dist/src/vite/unionProps.js +121 -0
- package/dist/src/vite/unresolvedTokens.d.ts +20 -0
- package/dist/src/vite/unresolvedTokens.js +193 -0
- package/dist/src/vite/usageGraph.js +10 -52
- package/dist/src/vite/usageGuidance.d.ts +9 -2
- package/dist/src/vite/usageGuidance.js +36 -8
- package/dist/src/vite/usageImports.d.ts +35 -0
- package/dist/src/vite/usageImports.js +280 -0
- package/dist/src/vite/visibilityRoute.d.ts +16 -0
- package/dist/src/vite/visibilityRoute.js +320 -0
- package/dist/src/worstCase.d.ts +2 -0
- package/dist/src/worstCase.js +2 -0
- package/package.json +28 -8
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files a checkout rewrote, told to the dev server's watcher: `git switch`, `git reset --hard`, a pull or a rebase
|
|
3
|
+
* moves the repository to another commit and rewrites its files at once, and the system's file events for such a burst
|
|
4
|
+
* may come many seconds late, or never.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Vite's watcher on macOS reads FSEvents, which a busy machine delivers late and coalesces; a branch switch writes,
|
|
8
|
+
* removes and adds files within milliseconds, and its events can be lost outright. Missed, a story removed by the switch
|
|
9
|
+
* stays in the sidebar, one it added never shows, a story file's old module keeps being served, and nothing ever renews
|
|
10
|
+
* them: every later answer comes from the stale module. A watch of git's own `HEAD` and `index` files, each on its own
|
|
11
|
+
* (a kernel event, kqueue on macOS), hears every checkout at once; the commit `HEAD` names before and after says which
|
|
12
|
+
* files changed, and each that the checkout wrote is handed to Vite's watcher as its own event, so every path a real
|
|
13
|
+
* event takes (the lists, the modules, the pages' reload) runs as it would have.
|
|
14
|
+
*
|
|
15
|
+
* The moves come from git's reflog of `HEAD`, read from where the last check stopped: a switch and a switch back that
|
|
16
|
+
* land between two checks leave `HEAD` where it was, yet rewrote files, and a page that loaded in between holds the
|
|
17
|
+
* other branch's stories. Each move's files are handed on, the later move standing for a file both wrote. With no
|
|
18
|
+
* reflog, the commit seen last is compared with the one now.
|
|
19
|
+
*
|
|
20
|
+
* Only files the checkout wrote are handed on: one git lists that is untouched on disk since the last checkout seen (a
|
|
21
|
+
* commit, which changes `HEAD` and rewrites nothing) is not, nor a file it says was removed that is still there. A
|
|
22
|
+
* checkout that keeps `HEAD` where it was (`git checkout -- <file>`, `git stash`) changes no commit and is left to the
|
|
23
|
+
* system's events. Where the watcher hears of changes at once or polls, there is nothing to make up for.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*/
|
|
27
|
+
import { execFile } from "node:child_process";
|
|
28
|
+
import { closeSync, openSync, readSync, statSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { promisify } from "node:util";
|
|
31
|
+
import { isWatchingByFileEvents, nodeWatchFile } from "./closeWatch.js";
|
|
32
|
+
import { VITE_PATHS } from "./vitePaths.js";
|
|
33
|
+
const run = promisify(execFile);
|
|
34
|
+
/**
|
|
35
|
+
* How long before the last checkout seen a file's change still counts as this checkout's, in milliseconds: a file
|
|
36
|
+
* system writes times with its own clock and grain, so a file written by the checkout may carry a time a little early.
|
|
37
|
+
*/
|
|
38
|
+
const CHECKOUT_MARGIN_MS = 2_000;
|
|
39
|
+
/** How long the watch waits for git to finish writing before it reads `HEAD`, in milliseconds. */
|
|
40
|
+
const SETTLE_MS = 100;
|
|
41
|
+
/** How long after a file's watch is opened it is checked to still hold the file, in milliseconds. */
|
|
42
|
+
const REWATCH_MS = 50;
|
|
43
|
+
/** Which file a path names now: its device and inode; none when nothing is there. */
|
|
44
|
+
const identityOf = (file) => {
|
|
45
|
+
const stats = statSync(file, { throwIfNoEntry: false });
|
|
46
|
+
return stats === undefined ? undefined : `${stats.dev}:${stats.ino}`;
|
|
47
|
+
};
|
|
48
|
+
/** A dependency's file, which Vite's watcher ignores. */
|
|
49
|
+
const DEPENDENCY = /(?:^|\/)node_modules\//;
|
|
50
|
+
/** A file's status from the disk. */
|
|
51
|
+
const diskStatus = (file) => {
|
|
52
|
+
const stats = statSync(file, { throwIfNoEntry: false });
|
|
53
|
+
return stats === undefined ? undefined : { changedAt: stats.ctimeMs };
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The events a checkout's files make: what `git diff --name-status -z --no-renames` lists between two commits, kept to
|
|
57
|
+
* the files the checkout wrote.
|
|
58
|
+
*
|
|
59
|
+
* @param listed - git's output.
|
|
60
|
+
* @param top - the repository's folder, which git's paths are relative to.
|
|
61
|
+
* @param since - when the commit before was seen, in milliseconds: a file unchanged since is not the checkout's.
|
|
62
|
+
* @param status - a file's status now; the disk's by default.
|
|
63
|
+
*/
|
|
64
|
+
export const checkoutEvents = (listed, top, since, status = diskStatus) => {
|
|
65
|
+
const parts = listed.split("\0");
|
|
66
|
+
const events = [];
|
|
67
|
+
for (let at = 0; at + 1 < parts.length; at += 2) {
|
|
68
|
+
const [letter = "", path = ""] = [parts[at], parts[at + 1]];
|
|
69
|
+
if (path === "" || DEPENDENCY.test(path))
|
|
70
|
+
continue;
|
|
71
|
+
const file = VITE_PATHS.normalize(join(top, path));
|
|
72
|
+
const now = status(file);
|
|
73
|
+
if (letter.startsWith("D")) {
|
|
74
|
+
if (now === undefined)
|
|
75
|
+
events.push({ kind: "unlink", file });
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (now === undefined || now.changedAt < since - CHECKOUT_MARGIN_MS)
|
|
79
|
+
continue;
|
|
80
|
+
events.push({ kind: letter.startsWith("A") ? "add" : "change", file });
|
|
81
|
+
}
|
|
82
|
+
return events;
|
|
83
|
+
};
|
|
84
|
+
/** A reflog line's two commits, before the name and the message: 40 or 64 hexadecimal digits each. */
|
|
85
|
+
const REFLOG_LINE = /^([0-9a-f]{40}(?:[0-9a-f]{24})?) ([0-9a-f]{40}(?:[0-9a-f]{24})?) /;
|
|
86
|
+
/**
|
|
87
|
+
* The moves of `HEAD` in what git appended to its reflog, in order, each that changed the commit: a branch switched and
|
|
88
|
+
* switched back before a check reads `HEAD` is two moves, though `HEAD` ends where it was.
|
|
89
|
+
*
|
|
90
|
+
* @param appended - the reflog's lines written since the last check.
|
|
91
|
+
*/
|
|
92
|
+
export const headMoves = (appended) => appended.split("\n").flatMap((line) => {
|
|
93
|
+
const [, from = "", to = ""] = REFLOG_LINE.exec(line) ?? [];
|
|
94
|
+
return from === "" || from === to || /^0+$/.test(from) ? [] : [{ from, to }];
|
|
95
|
+
});
|
|
96
|
+
/** What a reflog holds past a point, and where it ends; none when it cannot be read or was rewritten shorter. */
|
|
97
|
+
const reflogFrom = (file, offset) => {
|
|
98
|
+
const size = statSync(file, { throwIfNoEntry: false })?.size;
|
|
99
|
+
if (size === undefined || size < offset)
|
|
100
|
+
return undefined;
|
|
101
|
+
const buffer = Buffer.alloc(size - offset);
|
|
102
|
+
const handle = openSync(file, "r");
|
|
103
|
+
try {
|
|
104
|
+
readSync(handle, buffer, 0, buffer.length, offset);
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
closeSync(handle);
|
|
108
|
+
}
|
|
109
|
+
// a line git is still writing is read at the next check
|
|
110
|
+
const text = buffer.toString("utf8");
|
|
111
|
+
const complete = text.lastIndexOf("\n") + 1;
|
|
112
|
+
return { text: text.slice(0, complete), end: offset + Buffer.byteLength(text.slice(0, complete)) };
|
|
113
|
+
};
|
|
114
|
+
/** Git, as installed, with no option of the user's that changes how it lists. */
|
|
115
|
+
const runGit = async (dir, args) => {
|
|
116
|
+
try {
|
|
117
|
+
const { stdout } = await run("git", ["-c", "core.quotePath=false", ...args], {
|
|
118
|
+
cwd: dir,
|
|
119
|
+
maxBuffer: 64 * 1024 * 1024
|
|
120
|
+
});
|
|
121
|
+
return stdout.trim();
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Watches a repository's checkouts and hands the files each one wrote to `onEvent`.
|
|
129
|
+
*
|
|
130
|
+
* @param options - the repository, where events go, and how files are watched and git is run.
|
|
131
|
+
*/
|
|
132
|
+
export const checkoutWatch = (options) => {
|
|
133
|
+
const watchFile = options.watchFile ?? nodeWatchFile;
|
|
134
|
+
const git = options.git ?? runGit;
|
|
135
|
+
const settleMs = options.settleMs ?? SETTLE_MS;
|
|
136
|
+
const watches = new Map();
|
|
137
|
+
let isClosed = false;
|
|
138
|
+
let head;
|
|
139
|
+
let since = Date.now();
|
|
140
|
+
let top = "";
|
|
141
|
+
// the reflog of `HEAD`, and how far it was read
|
|
142
|
+
let reflog = "";
|
|
143
|
+
let reflogEnd = 0;
|
|
144
|
+
let timer;
|
|
145
|
+
// one check at a time, in order: two checkouts in a row are compared each with the one before
|
|
146
|
+
let checking = Promise.resolve();
|
|
147
|
+
/**
|
|
148
|
+
* The moves since the last check: from the reflog of `HEAD`, which records a switch and a switch back that leave
|
|
149
|
+
* `HEAD` where it was; else the one move from the commit seen last to the one now.
|
|
150
|
+
*/
|
|
151
|
+
const movesTo = (now) => {
|
|
152
|
+
const appended = reflog === "" ? undefined : reflogFrom(reflog, reflogEnd);
|
|
153
|
+
if (appended !== undefined) {
|
|
154
|
+
reflogEnd = appended.end;
|
|
155
|
+
const moves = headMoves(appended.text);
|
|
156
|
+
if (moves.length > 0 && moves.at(-1)?.to === now)
|
|
157
|
+
return moves;
|
|
158
|
+
}
|
|
159
|
+
return head === undefined || head === now ? [] : [{ from: head, to: now }];
|
|
160
|
+
};
|
|
161
|
+
/** Each move's files, the later standing: a file written by two moves is told once, as the disk has it now. */
|
|
162
|
+
const movesEvents = async (moves) => {
|
|
163
|
+
const events = new Map();
|
|
164
|
+
for (const { from, to } of moves) {
|
|
165
|
+
const listed = await git(options.dir, [
|
|
166
|
+
"diff",
|
|
167
|
+
"--name-status",
|
|
168
|
+
"-z",
|
|
169
|
+
"--no-renames",
|
|
170
|
+
"--no-ext-diff",
|
|
171
|
+
from,
|
|
172
|
+
to
|
|
173
|
+
]);
|
|
174
|
+
for (const event of checkoutEvents(listed ?? "", top, since, options.status))
|
|
175
|
+
events.set(event.file, event);
|
|
176
|
+
}
|
|
177
|
+
return [...events.values()];
|
|
178
|
+
};
|
|
179
|
+
const check = async () => {
|
|
180
|
+
const seenAt = Date.now();
|
|
181
|
+
const now = await git(options.dir, ["rev-parse", "--verify", "--quiet", "HEAD"]);
|
|
182
|
+
if (isClosed || now === undefined)
|
|
183
|
+
return;
|
|
184
|
+
const moves = head === undefined ? [] : movesTo(now);
|
|
185
|
+
head = now;
|
|
186
|
+
const events = await movesEvents(moves);
|
|
187
|
+
if (!isClosed)
|
|
188
|
+
for (const event of events)
|
|
189
|
+
options.onEvent(event);
|
|
190
|
+
since = seenAt;
|
|
191
|
+
};
|
|
192
|
+
const schedule = () => {
|
|
193
|
+
if (timer !== undefined)
|
|
194
|
+
clearTimeout(timer);
|
|
195
|
+
timer = setTimeout(() => {
|
|
196
|
+
timer = undefined;
|
|
197
|
+
checking = checking.then(check);
|
|
198
|
+
}, settleMs);
|
|
199
|
+
};
|
|
200
|
+
const follow = (file) => {
|
|
201
|
+
if (isClosed)
|
|
202
|
+
return;
|
|
203
|
+
watches.get(file)?.close();
|
|
204
|
+
watches.delete(file);
|
|
205
|
+
const watched = identityOf(file);
|
|
206
|
+
try {
|
|
207
|
+
watches.set(file, watchFile(file, (kind) => {
|
|
208
|
+
// git replaces the file through a new one, which the old watch never hears of
|
|
209
|
+
if (kind !== "change")
|
|
210
|
+
setTimeout(() => follow(file), 0);
|
|
211
|
+
schedule();
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// not there yet (a repository with no commit has no index): the next event of the other file looks again
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
// a watch is taken by the system on the loop's next turn, and hears nothing of a file replaced before that: then
|
|
219
|
+
// the file it holds is gone for good, so it is opened again and the checkout that replaced it is looked for
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
if (isClosed || identityOf(file) === watched)
|
|
222
|
+
return;
|
|
223
|
+
follow(file);
|
|
224
|
+
schedule();
|
|
225
|
+
}, REWATCH_MS);
|
|
226
|
+
};
|
|
227
|
+
const ready = (async () => {
|
|
228
|
+
const gitDir = await git(options.dir, ["rev-parse", "--absolute-git-dir"]);
|
|
229
|
+
const shown = await git(options.dir, ["rev-parse", "--show-toplevel"]);
|
|
230
|
+
if (gitDir === undefined || shown === undefined || isClosed)
|
|
231
|
+
return;
|
|
232
|
+
top = shown;
|
|
233
|
+
head = await git(options.dir, ["rev-parse", "--verify", "--quiet", "HEAD"]);
|
|
234
|
+
reflog = join(gitDir, "logs", "HEAD");
|
|
235
|
+
reflogEnd = statSync(reflog, { throwIfNoEntry: false })?.size ?? 0;
|
|
236
|
+
since = Date.now();
|
|
237
|
+
// `HEAD` moves with a switch; the index is rewritten by every checkout, a reset of the branch included
|
|
238
|
+
for (const name of ["HEAD", "index"])
|
|
239
|
+
follow(join(gitDir, name));
|
|
240
|
+
})();
|
|
241
|
+
return {
|
|
242
|
+
ready,
|
|
243
|
+
settled: async () => {
|
|
244
|
+
await ready;
|
|
245
|
+
await new Promise((resolve) => setTimeout(resolve, settleMs * 2));
|
|
246
|
+
await checking;
|
|
247
|
+
},
|
|
248
|
+
close: () => {
|
|
249
|
+
isClosed = true;
|
|
250
|
+
if (timer !== undefined)
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
for (const watch of watches.values())
|
|
253
|
+
watch.close();
|
|
254
|
+
watches.clear();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* A dev server's checkout watch, where its watcher reads FSEvents and it sends updates: what a checkout wrote goes to
|
|
260
|
+
* its watcher. Closed with the server's HTTP server.
|
|
261
|
+
*
|
|
262
|
+
* @param server - the dev server.
|
|
263
|
+
* @param platform - the system, `process.platform` by default.
|
|
264
|
+
* @returns the watch; none where the watcher hears of changes at once, or polls.
|
|
265
|
+
*/
|
|
266
|
+
export const serverCheckoutWatch = (server, platform = process.platform) => {
|
|
267
|
+
const { watch, hmr } = server.config.server;
|
|
268
|
+
if (!isWatchingByFileEvents(watch, platform) || hmr === false)
|
|
269
|
+
return undefined;
|
|
270
|
+
const watching = checkoutWatch({
|
|
271
|
+
dir: server.config.root,
|
|
272
|
+
onEvent: ({ kind, file }) => void server.watcher.emit(kind, file)
|
|
273
|
+
});
|
|
274
|
+
server.httpServer?.on("close", () => watching.close());
|
|
275
|
+
return watching;
|
|
276
|
+
};
|
|
277
|
+
/** The checkout watch of the dev server that runs now; none watches until a server is served. */
|
|
278
|
+
export const currentCheckoutWatch = () => {
|
|
279
|
+
let current;
|
|
280
|
+
return {
|
|
281
|
+
serve: (server, platform = process.platform) => {
|
|
282
|
+
current?.close();
|
|
283
|
+
current = server === undefined ? undefined : serverCheckoutWatch(server, platform);
|
|
284
|
+
},
|
|
285
|
+
close: () => current?.close()
|
|
286
|
+
};
|
|
287
|
+
};
|
|
@@ -55,6 +55,14 @@ export type CloseWatchOptions = {
|
|
|
55
55
|
*/
|
|
56
56
|
readonly readText?: (file: string) => string | undefined;
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Node's watch of one file: a kernel event per change (kqueue on macOS). Not persistent, so it never keeps a process
|
|
60
|
+
* that is ending alive.
|
|
61
|
+
*
|
|
62
|
+
* @param file - the file.
|
|
63
|
+
* @param onEvent - the watch's events.
|
|
64
|
+
*/
|
|
65
|
+
export declare const nodeWatchFile: WatchFile;
|
|
58
66
|
/**
|
|
59
67
|
* Whether a dev server's watcher hears of changes through FSEvents, which deliver them late: Vite's on macOS, unless
|
|
60
68
|
* it polls, was told not to use them, or waits for writes to finish; none when the dev server watches nothing.
|
|
@@ -37,7 +37,7 @@ export const CLOSE_WATCH_LIMIT = 64;
|
|
|
37
37
|
* @param file - the file.
|
|
38
38
|
* @param onEvent - the watch's events.
|
|
39
39
|
*/
|
|
40
|
-
const nodeWatchFile = (file, onEvent) => {
|
|
40
|
+
export const nodeWatchFile = (file, onEvent) => {
|
|
41
41
|
const watcher = watch(file, { persistent: false }, (kind) => onEvent(kind === "rename" ? "rename" : "change"));
|
|
42
42
|
watcher.on("error", () => onEvent("error"));
|
|
43
43
|
return { close: () => watcher.close() };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ScannedComponent } from "./componentScan.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Every component of a project as its files are now.
|
|
4
|
+
*
|
|
5
|
+
* @param dir - its folder.
|
|
6
|
+
* @param notes - told of what is left out.
|
|
7
|
+
*/
|
|
8
|
+
export declare const currentComponents: (dir: string, notes: string[]) => ScannedComponent[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A project's components, read from disk and kept by each file's size and time, so a running dev server that is asked again
|
|
3
|
+
* reads only what changed.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Every `check-code` reads the whole repository, and a long-lived server is asked often. Only components are kept, not
|
|
7
|
+
* files' text, since a repository's text is more than a server should hold.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { statSync } from "node:fs";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { repositoryOf, smallFileText } from "./appTokenFiles.js";
|
|
14
|
+
import { LEFT_ALONE } from "./checkCode.js";
|
|
15
|
+
import { rulesOfFile } from "./componentRules.js";
|
|
16
|
+
import { COMPONENT_FILE, projectComponents } from "./componentScan.js";
|
|
17
|
+
import { listedProjectFiles, MOST_BYTES } from "./projectFiles.js";
|
|
18
|
+
import { isInside } from "./sourceTokens.js";
|
|
19
|
+
/** What has been read, by absolute path. */
|
|
20
|
+
const KEPT = new Map();
|
|
21
|
+
/**
|
|
22
|
+
* A file's components with what a rules file beside it says of them, by the file's name or the component's (`radio-group.tsx`
|
|
23
|
+
* may have `RadioGroup.rules.json`). Read each time: it is short and rare.
|
|
24
|
+
*/
|
|
25
|
+
const withRulesBeside = (components, path, root) => components.map((each) => {
|
|
26
|
+
const names = [path.replace(/\.[^./\\]+$/, ""), join(dirname(path), each.name)];
|
|
27
|
+
const own = names
|
|
28
|
+
.map((name) => `${name}.rules.json`)
|
|
29
|
+
// a link beside a component may lead anywhere
|
|
30
|
+
.flatMap((name) => (isInside(root, name) ? (smallFileText(name) ?? []) : []))
|
|
31
|
+
.map((text) => rulesOfFile(text).get(each.name))
|
|
32
|
+
.find((rules) => rules !== undefined);
|
|
33
|
+
return own === undefined ? each : { ...each, rules: { ...each.rules, ...own } };
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Every component of a project as its files are now.
|
|
37
|
+
*
|
|
38
|
+
* @param dir - its folder.
|
|
39
|
+
* @param notes - told of what is left out.
|
|
40
|
+
*/
|
|
41
|
+
export const currentComponents = (dir, notes) => {
|
|
42
|
+
let bytes = 0;
|
|
43
|
+
const root = repositoryOf(dir);
|
|
44
|
+
return listedProjectFiles(dir, notes)
|
|
45
|
+
.filter((file) => COMPONENT_FILE.test(file) && !LEFT_ALONE.test(file))
|
|
46
|
+
.flatMap((file) => {
|
|
47
|
+
const path = join(dir, file);
|
|
48
|
+
try {
|
|
49
|
+
const { size, mtimeMs } = statSync(path);
|
|
50
|
+
const stamp = `${size}:${mtimeMs}`;
|
|
51
|
+
const known = KEPT.get(path);
|
|
52
|
+
if (known?.stamp === stamp)
|
|
53
|
+
return withRulesBeside(known.components, path, root);
|
|
54
|
+
if (bytes > MOST_BYTES)
|
|
55
|
+
return [];
|
|
56
|
+
bytes += size;
|
|
57
|
+
const text = smallFileText(path);
|
|
58
|
+
const components = text === undefined ? [] : projectComponents([{ file, text }]);
|
|
59
|
+
KEPT.set(path, { stamp, components });
|
|
60
|
+
return withRulesBeside(components, path, root);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A map of a project's components and tokens, for an agent to read instead of everything: what exists, what each is for,
|
|
3
|
+
* what renders what and which tokens each file uses.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Generated from the source, so it cannot drift from it, and small on purpose: a list of names first, and a component's
|
|
7
|
+
* neighbourhood or an intent's choices on request. A store of decisions written apart would be a second source of truth.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import type { UsageGuidance } from "../componentDocs.ts";
|
|
12
|
+
import type { ComponentIntent, ComponentRules } from "./componentRules.ts";
|
|
13
|
+
/** A component in the map. */
|
|
14
|
+
export type GraphComponent = {
|
|
15
|
+
/** Its name. */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** Where it is, `file:line`. */
|
|
18
|
+
readonly at: string;
|
|
19
|
+
/** When to use it and when not. */
|
|
20
|
+
readonly guidance?: UsageGuidance;
|
|
21
|
+
/** How it is chosen and how it fits. */
|
|
22
|
+
readonly rules?: ComponentRules;
|
|
23
|
+
/** The project's components it renders. */
|
|
24
|
+
readonly renders: readonly string[];
|
|
25
|
+
/** How many of the project's components render it. */
|
|
26
|
+
readonly usedBy: number;
|
|
27
|
+
};
|
|
28
|
+
/** A component in detail, with those around it. */
|
|
29
|
+
export type GraphDetail = GraphComponent & {
|
|
30
|
+
/** The components that render it. */
|
|
31
|
+
readonly renderedBy: readonly string[];
|
|
32
|
+
/** The tokens its file uses. */
|
|
33
|
+
readonly tokens: readonly string[];
|
|
34
|
+
/** Where else a component of this name is: `usedBy` counts them together. */
|
|
35
|
+
readonly alsoAt: readonly string[];
|
|
36
|
+
};
|
|
37
|
+
/** The map. */
|
|
38
|
+
export type GraphDocument = {
|
|
39
|
+
/** The shape's version. */
|
|
40
|
+
readonly schema: 1;
|
|
41
|
+
/** How many components there are, whatever the answer lists. */
|
|
42
|
+
readonly total: number;
|
|
43
|
+
/** The components, those with something to say first. */
|
|
44
|
+
readonly components: readonly GraphComponent[];
|
|
45
|
+
/** The choices for each situation, by what it is called. */
|
|
46
|
+
readonly intents: Readonly<Record<string, readonly (ComponentIntent & {
|
|
47
|
+
readonly component: string;
|
|
48
|
+
})[]>>;
|
|
49
|
+
/** The tokens known, by type, and how many of each. */
|
|
50
|
+
readonly tokens: Readonly<Record<string, number>>;
|
|
51
|
+
/** The one asked about, in detail. */
|
|
52
|
+
readonly detail?: GraphDetail;
|
|
53
|
+
/** What could not be read. */
|
|
54
|
+
readonly notes: readonly string[];
|
|
55
|
+
};
|
|
56
|
+
/** What is asked of the map. */
|
|
57
|
+
export type GraphQuestion = {
|
|
58
|
+
/** A component to give in detail. */
|
|
59
|
+
readonly component?: string | undefined;
|
|
60
|
+
/** An intent to list only the choices of. */
|
|
61
|
+
readonly intent?: string | undefined;
|
|
62
|
+
/** How many components to list. */
|
|
63
|
+
readonly limit?: number | undefined;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The map of a project.
|
|
67
|
+
*
|
|
68
|
+
* @param dir - its folder.
|
|
69
|
+
* @param question - what is asked.
|
|
70
|
+
*/
|
|
71
|
+
export declare const graphDocument: (dir: string, question: GraphQuestion) => GraphDocument;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A map of a project's components and tokens, for an agent to read instead of everything: what exists, what each is for,
|
|
3
|
+
* what renders what and which tokens each file uses.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Generated from the source, so it cannot drift from it, and small on purpose: a list of names first, and a component's
|
|
7
|
+
* neighbourhood or an intent's choices on request. A store of decisions written apart would be a second source of truth.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { COLOR_CLASS, FONT_CLASS, RADIUS_CLASS, SPACE_CLASS } from "./appAudit.js";
|
|
13
|
+
import { smallFileText } from "./appTokenFiles.js";
|
|
14
|
+
import { readAppTokens } from "./appTokens.js";
|
|
15
|
+
import { currentComponents } from "./componentCache.js";
|
|
16
|
+
import { plainWords } from "./sourceText.js";
|
|
17
|
+
/** How many components a map lists unless asked otherwise: an agent degrades on long answers. */
|
|
18
|
+
const LIMIT = 100;
|
|
19
|
+
/** How much of what an author wrote the map repeats, for each thing. */
|
|
20
|
+
const LONGEST_WORDS = 200;
|
|
21
|
+
/** How many things of a kind (situations, choices) the map gives. */
|
|
22
|
+
const MOST_WORDS = 20;
|
|
23
|
+
/** A custom property a file uses. */
|
|
24
|
+
const VAR_USE = /var\(\s*(--[\w-]+)/g;
|
|
25
|
+
/** What an author wrote, as data and short. */
|
|
26
|
+
const plainGuidance = (guidance) => {
|
|
27
|
+
const plain = (text) => plainWords(text, LONGEST_WORDS);
|
|
28
|
+
const list = (texts) => texts?.slice(0, MOST_WORDS).map(plain);
|
|
29
|
+
const { useWhen, avoidWhen, alternatives, deprecated, replacedBy } = guidance;
|
|
30
|
+
const [when, avoid, others] = [list(useWhen), list(avoidWhen), list(alternatives)];
|
|
31
|
+
return {
|
|
32
|
+
...(when === undefined ? {} : { useWhen: when }),
|
|
33
|
+
...(avoid === undefined ? {} : { avoidWhen: avoid }),
|
|
34
|
+
...(others === undefined ? {} : { alternatives: others }),
|
|
35
|
+
...(deprecated === undefined ? {} : { deprecated: plain(deprecated) }),
|
|
36
|
+
...(replacedBy === undefined ? {} : { replacedBy: plain(replacedBy) })
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** A component in the map's short form. */
|
|
40
|
+
const shortForm = (each, usedBy, known) => ({
|
|
41
|
+
name: each.name,
|
|
42
|
+
at: plainWords(`${each.file}:${each.line}`, LONGEST_WORDS),
|
|
43
|
+
...(each.guidance === undefined ? {} : { guidance: plainGuidance(each.guidance) }),
|
|
44
|
+
...(each.rules === undefined ? {} : { rules: each.rules }),
|
|
45
|
+
renders: each.renders.filter((name) => known.has(name) && name !== each.name),
|
|
46
|
+
usedBy: usedBy.get(each.name)?.length ?? 0
|
|
47
|
+
});
|
|
48
|
+
/** The tokens a component's file uses: by reference, and by the classes that write them. */
|
|
49
|
+
const tokensOfFile = (text, tokens) => {
|
|
50
|
+
const names = new Set(tokens.map(({ name }) => name));
|
|
51
|
+
const colors = new Map(tokens.flatMap(({ utility, name, type }) => utility !== undefined && type === "color" ? [[utility, name]] : []));
|
|
52
|
+
const used = [...text.matchAll(VAR_USE)].flatMap((match) => match[1] ?? []);
|
|
53
|
+
const classed = [
|
|
54
|
+
...[...text.matchAll(COLOR_CLASS)].flatMap((match) => colors.get(match[1] ?? "") ?? []),
|
|
55
|
+
...[...text.matchAll(SPACE_CLASS)].map((match) => `--spacing-${match[1] ?? ""}`),
|
|
56
|
+
...[...text.matchAll(RADIUS_CLASS)].map((match) => `--radius-${match[1] ?? ""}`),
|
|
57
|
+
...[...text.matchAll(FONT_CLASS)].map((match) => `--text-${match[1] ?? ""}`)
|
|
58
|
+
];
|
|
59
|
+
return [...new Set([...used, ...classed])].filter((name) => names.has(name)).toSorted();
|
|
60
|
+
};
|
|
61
|
+
/** Which components render each, by name. */
|
|
62
|
+
const usersOf = (components, known) => {
|
|
63
|
+
const users = new Map();
|
|
64
|
+
for (const each of components) {
|
|
65
|
+
for (const name of each.renders) {
|
|
66
|
+
if (known.has(name) && name !== each.name)
|
|
67
|
+
users.set(name, [...(users.get(name) ?? []), each.name]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return users;
|
|
71
|
+
};
|
|
72
|
+
/** The choices for each situation, by what it is called; a Map, since an author may call one `constructor`. */
|
|
73
|
+
const intentsOf = (components) => {
|
|
74
|
+
const intents = new Map();
|
|
75
|
+
for (const each of components) {
|
|
76
|
+
for (const intent of each.rules?.intents ?? []) {
|
|
77
|
+
intents.set(intent.id, [...(intents.get(intent.id) ?? []), { ...intent, component: each.name }]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return intents;
|
|
81
|
+
};
|
|
82
|
+
/** How many tokens of each type. */
|
|
83
|
+
const countsOf = (tokens) => {
|
|
84
|
+
const types = {};
|
|
85
|
+
for (const { type } of tokens)
|
|
86
|
+
types[type] = (types[type] ?? 0) + 1;
|
|
87
|
+
return types;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The map of a project.
|
|
91
|
+
*
|
|
92
|
+
* @param dir - its folder.
|
|
93
|
+
* @param question - what is asked.
|
|
94
|
+
*/
|
|
95
|
+
export const graphDocument = (dir, question) => {
|
|
96
|
+
const notes = [];
|
|
97
|
+
const everything = currentComponents(dir, notes);
|
|
98
|
+
const components = everything.filter((each) => each.isExported);
|
|
99
|
+
const { tokens, unread } = readAppTokens(dir);
|
|
100
|
+
const known = new Set(components.map(({ name }) => name));
|
|
101
|
+
const usedBy = usersOf(everything, known);
|
|
102
|
+
const intents = intentsOf(components);
|
|
103
|
+
const uses = (name) => usedBy.get(name)?.length ?? 0;
|
|
104
|
+
const isSilent = (each) => Number(each.rules === undefined && each.guidance === undefined);
|
|
105
|
+
const choices = new Set((intents.get(question.intent ?? "") ?? []).map(({ component }) => component));
|
|
106
|
+
const listed = (question.intent === undefined ? components : components.filter((each) => choices.has(each.name)))
|
|
107
|
+
.toSorted((first, second) => isSilent(first) - isSilent(second) || uses(second.name) - uses(first.name))
|
|
108
|
+
.slice(0, question.limit ?? LIMIT)
|
|
109
|
+
.map((each) => shortForm(each, usedBy, known));
|
|
110
|
+
const asked = components.find((each) => each.name === question.component);
|
|
111
|
+
return {
|
|
112
|
+
schema: 1,
|
|
113
|
+
total: components.length,
|
|
114
|
+
components: listed,
|
|
115
|
+
intents: Object.fromEntries((question.intent === undefined
|
|
116
|
+
? [...intents].slice(0, question.limit ?? LIMIT)
|
|
117
|
+
: [[question.intent, intents.get(question.intent) ?? []]]).map(([id, list]) => [id, list.slice(0, question.limit ?? LIMIT)])),
|
|
118
|
+
tokens: countsOf(tokens),
|
|
119
|
+
...(asked === undefined
|
|
120
|
+
? {}
|
|
121
|
+
: {
|
|
122
|
+
detail: {
|
|
123
|
+
...shortForm(asked, usedBy, known),
|
|
124
|
+
renderedBy: usedBy.get(asked.name) ?? [],
|
|
125
|
+
tokens: tokensOfFile(smallFileText(join(dir, asked.file)) ?? "", tokens),
|
|
126
|
+
alsoAt: components
|
|
127
|
+
.filter((each) => each.name === asked.name && each !== asked)
|
|
128
|
+
.map(({ file, line }) => `${file}:${line}`)
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
notes: [...notes, ...unread]
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DocTag } from "./usageGuidance.ts";
|
|
2
|
+
/** A situation a component answers. */
|
|
3
|
+
export type ComponentIntent = {
|
|
4
|
+
/** What it is for, in the words of whoever wrote it: components sharing it are the choices for it. */
|
|
5
|
+
readonly id: string;
|
|
6
|
+
/** When this one is the right one. */
|
|
7
|
+
readonly when?: string;
|
|
8
|
+
};
|
|
9
|
+
/** How a component is chosen and how it fits with others. */
|
|
10
|
+
export type ComponentRules = {
|
|
11
|
+
/** The situations it answers. */
|
|
12
|
+
readonly intents?: readonly ComponentIntent[];
|
|
13
|
+
/** What it may stand inside, at any depth; none for anywhere. */
|
|
14
|
+
readonly parents?: readonly string[];
|
|
15
|
+
/** What may stand directly inside it; none for anything. */
|
|
16
|
+
readonly children?: readonly string[];
|
|
17
|
+
/** What may stand beside it; none for anything. */
|
|
18
|
+
readonly siblings?: readonly string[];
|
|
19
|
+
/** The plain elements it stands in for: writing one by hand is a mistake. */
|
|
20
|
+
readonly insteadOf?: readonly string[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A component's rules, from its tags.
|
|
24
|
+
*
|
|
25
|
+
* @param tags - its TSDoc tags.
|
|
26
|
+
*/
|
|
27
|
+
export declare const rulesOfTags: (tags: readonly DocTag[]) => ComponentRules | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* What a rules file says, by component, read as data: one that cannot be read says nothing.
|
|
30
|
+
*
|
|
31
|
+
* @param text - the file's text.
|
|
32
|
+
*/
|
|
33
|
+
export declare const rulesOfFile: (text: string) => ReadonlyMap<string, ComponentRules>;
|