@rien7/seji 0.0.0 → 0.6.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/bin/design-surface.mjs +6 -0
- package/bin/postinstall.mjs +19 -0
- package/bin/seji.mjs +573 -0
- package/dist/agent/host.d.mts +34 -0
- package/dist/agent/host.mjs +387 -0
- package/dist/agent/messages.d.mts +9 -0
- package/dist/agent/messages.mjs +70 -0
- package/dist/agent/runtimes.mjs +157 -0
- package/dist/cli/app.mjs +321 -0
- package/dist/cli/appScan.mjs +284 -0
- package/dist/cli/catalog.mjs +78 -0
- package/dist/cli/component.mjs +165 -0
- package/dist/cli/consolidate.mjs +159 -0
- package/dist/cli/cssImport.mjs +68 -0
- package/dist/cli/dev.mjs +335 -0
- package/dist/cli/doctor.mjs +306 -0
- package/dist/cli/init.mjs +338 -0
- package/dist/cli/legacyNames.mjs +266 -0
- package/dist/cli/migrate.mjs +163 -0
- package/dist/cli/prompt.mjs +34 -0
- package/dist/cli/propose.mjs +208 -0
- package/dist/cli/providers.mjs +344 -0
- package/dist/cli/reviewOps.mjs +110 -0
- package/dist/cli/semver.mjs +45 -0
- package/dist/cli/setup.mjs +357 -0
- package/dist/cli/sketches.mjs +47 -0
- package/dist/cli/skills.mjs +150 -0
- package/dist/cli/snapshot.mjs +107 -0
- package/dist/cli/tokenOps.mjs +120 -0
- package/dist/cli/types.mjs +191 -0
- package/dist/cli/updater.mjs +274 -0
- package/dist/components/astIndex.mjs +992 -0
- package/dist/components/ops.mjs +1069 -0
- package/dist/editor/AgentProposalCard.d.ts +10 -0
- package/dist/editor/AgentProposalCard.d.ts.map +1 -0
- package/dist/editor/AgentProposalCard.js +31 -0
- package/dist/editor/AgentProposalCard.js.map +1 -0
- package/dist/editor/App.d.ts +2 -0
- package/dist/editor/App.d.ts.map +1 -0
- package/dist/editor/App.js +2832 -0
- package/dist/editor/App.js.map +1 -0
- package/dist/editor/CanvasHud.d.ts +12 -0
- package/dist/editor/CanvasHud.d.ts.map +1 -0
- package/dist/editor/CanvasHud.js +13 -0
- package/dist/editor/CanvasHud.js.map +1 -0
- package/dist/editor/CanvasSurface.d.ts +31 -0
- package/dist/editor/CanvasSurface.d.ts.map +1 -0
- package/dist/editor/CanvasSurface.js +270 -0
- package/dist/editor/CanvasSurface.js.map +1 -0
- package/dist/editor/CommentPopover.d.ts +17 -0
- package/dist/editor/CommentPopover.d.ts.map +1 -0
- package/dist/editor/CommentPopover.js +62 -0
- package/dist/editor/CommentPopover.js.map +1 -0
- package/dist/editor/Comments.d.ts +13 -0
- package/dist/editor/Comments.d.ts.map +1 -0
- package/dist/editor/Comments.js +41 -0
- package/dist/editor/Comments.js.map +1 -0
- package/dist/editor/ComponentPage.d.ts +28 -0
- package/dist/editor/ComponentPage.d.ts.map +1 -0
- package/dist/editor/ComponentPage.js +55 -0
- package/dist/editor/ComponentPage.js.map +1 -0
- package/dist/editor/ComponentPanel.d.ts +38 -0
- package/dist/editor/ComponentPanel.d.ts.map +1 -0
- package/dist/editor/ComponentPanel.js +275 -0
- package/dist/editor/ComponentPanel.js.map +1 -0
- package/dist/editor/Glyph.d.ts +51 -0
- package/dist/editor/Glyph.d.ts.map +1 -0
- package/dist/editor/Glyph.js +50 -0
- package/dist/editor/Glyph.js.map +1 -0
- package/dist/editor/History.d.ts +7 -0
- package/dist/editor/History.d.ts.map +1 -0
- package/dist/editor/History.js +51 -0
- package/dist/editor/History.js.map +1 -0
- package/dist/editor/Inspector.d.ts +56 -0
- package/dist/editor/Inspector.d.ts.map +1 -0
- package/dist/editor/Inspector.js +510 -0
- package/dist/editor/Inspector.js.map +1 -0
- package/dist/editor/LazyMount.d.ts +10 -0
- package/dist/editor/LazyMount.d.ts.map +1 -0
- package/dist/editor/LazyMount.js +29 -0
- package/dist/editor/LazyMount.js.map +1 -0
- package/dist/editor/LocaleSwitch.d.ts +3 -0
- package/dist/editor/LocaleSwitch.d.ts.map +1 -0
- package/dist/editor/LocaleSwitch.js +9 -0
- package/dist/editor/LocaleSwitch.js.map +1 -0
- package/dist/editor/PreviewFrame.d.ts +10 -0
- package/dist/editor/PreviewFrame.d.ts.map +1 -0
- package/dist/editor/PreviewFrame.js +22 -0
- package/dist/editor/PreviewFrame.js.map +1 -0
- package/dist/editor/ProjectIndex.d.ts +12 -0
- package/dist/editor/ProjectIndex.d.ts.map +1 -0
- package/dist/editor/ProjectIndex.js +43 -0
- package/dist/editor/ProjectIndex.js.map +1 -0
- package/dist/editor/PromoteComponent.d.ts +28 -0
- package/dist/editor/PromoteComponent.d.ts.map +1 -0
- package/dist/editor/PromoteComponent.js +33 -0
- package/dist/editor/PromoteComponent.js.map +1 -0
- package/dist/editor/PromoteForm.d.ts +18 -0
- package/dist/editor/PromoteForm.d.ts.map +1 -0
- package/dist/editor/PromoteForm.js +35 -0
- package/dist/editor/PromoteForm.js.map +1 -0
- package/dist/editor/PromoteToken.d.ts +31 -0
- package/dist/editor/PromoteToken.d.ts.map +1 -0
- package/dist/editor/PromoteToken.js +94 -0
- package/dist/editor/PromoteToken.js.map +1 -0
- package/dist/editor/StatePreviews.d.ts +28 -0
- package/dist/editor/StatePreviews.d.ts.map +1 -0
- package/dist/editor/StatePreviews.js +113 -0
- package/dist/editor/StatePreviews.js.map +1 -0
- package/dist/editor/ValueCombo.d.ts +51 -0
- package/dist/editor/ValueCombo.d.ts.map +1 -0
- package/dist/editor/ValueCombo.js +260 -0
- package/dist/editor/ValueCombo.js.map +1 -0
- package/dist/editor/agent/AgentPanel.d.ts +19 -0
- package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
- package/dist/editor/agent/AgentPanel.js +271 -0
- package/dist/editor/agent/AgentPanel.js.map +1 -0
- package/dist/editor/agent/Markdown.d.ts +5 -0
- package/dist/editor/agent/Markdown.d.ts.map +1 -0
- package/dist/editor/agent/Markdown.js +28 -0
- package/dist/editor/agent/Markdown.js.map +1 -0
- package/dist/editor/agent/agentApi.d.ts +106 -0
- package/dist/editor/agent/agentApi.d.ts.map +1 -0
- package/dist/editor/agent/agentApi.js +66 -0
- package/dist/editor/agent/agentApi.js.map +1 -0
- package/dist/editor/agent/toolLines.d.ts +38 -0
- package/dist/editor/agent/toolLines.d.ts.map +1 -0
- package/dist/editor/agent/toolLines.js +159 -0
- package/dist/editor/agent/toolLines.js.map +1 -0
- package/dist/editor/agent/useAgent.d.ts +15 -0
- package/dist/editor/agent/useAgent.d.ts.map +1 -0
- package/dist/editor/agent/useAgent.js +65 -0
- package/dist/editor/agent/useAgent.js.map +1 -0
- package/dist/editor/api.d.ts +378 -0
- package/dist/editor/api.d.ts.map +1 -0
- package/dist/editor/api.js +247 -0
- package/dist/editor/api.js.map +1 -0
- package/dist/editor/camera.d.ts +18 -0
- package/dist/editor/camera.d.ts.map +1 -0
- package/dist/editor/camera.js +40 -0
- package/dist/editor/camera.js.map +1 -0
- package/dist/editor/canvas.d.ts +25 -0
- package/dist/editor/canvas.d.ts.map +1 -0
- package/dist/editor/canvas.js +35 -0
- package/dist/editor/canvas.js.map +1 -0
- package/dist/editor/changes/ChangesPage.d.ts +25 -0
- package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
- package/dist/editor/changes/ChangesPage.js +132 -0
- package/dist/editor/changes/ChangesPage.js.map +1 -0
- package/dist/editor/changes/changeModel.d.ts +25 -0
- package/dist/editor/changes/changeModel.d.ts.map +1 -0
- package/dist/editor/changes/changeModel.js +81 -0
- package/dist/editor/changes/changeModel.js.map +1 -0
- package/dist/editor/changes/changeState.d.mts +29 -0
- package/dist/editor/changes/changeState.mjs +187 -0
- package/dist/editor/chrome/EditorChrome.d.ts +49 -0
- package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
- package/dist/editor/chrome/EditorChrome.js +21 -0
- package/dist/editor/chrome/EditorChrome.js.map +1 -0
- package/dist/editor/drafts.d.ts +46 -0
- package/dist/editor/drafts.d.ts.map +1 -0
- package/dist/editor/drafts.js +38 -0
- package/dist/editor/drafts.js.map +1 -0
- package/dist/editor/i18n.d.ts +29 -0
- package/dist/editor/i18n.d.ts.map +1 -0
- package/dist/editor/i18n.js +2320 -0
- package/dist/editor/i18n.js.map +1 -0
- package/dist/editor/iconStroke.d.ts +6 -0
- package/dist/editor/iconStroke.d.ts.map +1 -0
- package/dist/editor/iconStroke.js +6 -0
- package/dist/editor/iconStroke.js.map +1 -0
- package/dist/editor/main.d.ts +2 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/main.js +14 -0
- package/dist/editor/main.js.map +1 -0
- package/dist/editor/model.d.ts +16 -0
- package/dist/editor/model.d.ts.map +1 -0
- package/dist/editor/model.js +11 -0
- package/dist/editor/model.js.map +1 -0
- package/dist/editor/reasons.d.ts +44 -0
- package/dist/editor/reasons.d.ts.map +1 -0
- package/dist/editor/reasons.js +131 -0
- package/dist/editor/reasons.js.map +1 -0
- package/dist/editor/reviewLifecycle.d.ts +8 -0
- package/dist/editor/reviewLifecycle.d.ts.map +1 -0
- package/dist/editor/reviewLifecycle.js +21 -0
- package/dist/editor/reviewLifecycle.js.map +1 -0
- package/dist/editor/styles.css +8737 -0
- package/dist/editor/tokenMatch.d.ts +59 -0
- package/dist/editor/tokenMatch.d.ts.map +1 -0
- package/dist/editor/tokenMatch.js +198 -0
- package/dist/editor/tokenMatch.js.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.js +244 -0
- package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
- package/dist/editor/tokens/TokenActivity.d.ts +18 -0
- package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
- package/dist/editor/tokens/TokenActivity.js +18 -0
- package/dist/editor/tokens/TokenActivity.js.map +1 -0
- package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
- package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
- package/dist/editor/tokens/TokenDialogs.js +119 -0
- package/dist/editor/tokens/TokenDialogs.js.map +1 -0
- package/dist/editor/tokens/TokenList.d.ts +21 -0
- package/dist/editor/tokens/TokenList.d.ts.map +1 -0
- package/dist/editor/tokens/TokenList.js +98 -0
- package/dist/editor/tokens/TokenList.js.map +1 -0
- package/dist/editor/tokens/TokenPage.d.ts +25 -0
- package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
- package/dist/editor/tokens/TokenPage.js +108 -0
- package/dist/editor/tokens/TokenPage.js.map +1 -0
- package/dist/editor/tokens/tokenModel.d.ts +35 -0
- package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
- package/dist/editor/tokens/tokenModel.js +72 -0
- package/dist/editor/tokens/tokenModel.js.map +1 -0
- package/dist/editor/ui/Button.d.ts +3 -0
- package/dist/editor/ui/Button.d.ts.map +1 -0
- package/dist/editor/ui/Button.js +6 -0
- package/dist/editor/ui/Button.js.map +1 -0
- package/dist/editor/ui/CommentBox.d.ts +23 -0
- package/dist/editor/ui/CommentBox.d.ts.map +1 -0
- package/dist/editor/ui/CommentBox.js +41 -0
- package/dist/editor/ui/CommentBox.js.map +1 -0
- package/dist/editor/ui/Icon.d.ts +8 -0
- package/dist/editor/ui/Icon.d.ts.map +1 -0
- package/dist/editor/ui/Icon.js +6 -0
- package/dist/editor/ui/Icon.js.map +1 -0
- package/dist/editor/ui/IconButton.d.ts +11 -0
- package/dist/editor/ui/IconButton.d.ts.map +1 -0
- package/dist/editor/ui/IconButton.js +6 -0
- package/dist/editor/ui/IconButton.js.map +1 -0
- package/dist/editor/ui/NumberInput.d.ts +14 -0
- package/dist/editor/ui/NumberInput.d.ts.map +1 -0
- package/dist/editor/ui/NumberInput.js +6 -0
- package/dist/editor/ui/NumberInput.js.map +1 -0
- package/dist/editor/ui/PageLine.d.ts +14 -0
- package/dist/editor/ui/PageLine.d.ts.map +1 -0
- package/dist/editor/ui/PageLine.js +7 -0
- package/dist/editor/ui/PageLine.js.map +1 -0
- package/dist/editor/ui/SearchPicker.d.ts +41 -0
- package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
- package/dist/editor/ui/SearchPicker.js +82 -0
- package/dist/editor/ui/SearchPicker.js.map +1 -0
- package/dist/editor/ui/Select.d.ts +19 -0
- package/dist/editor/ui/Select.d.ts.map +1 -0
- package/dist/editor/ui/Select.js +12 -0
- package/dist/editor/ui/Select.js.map +1 -0
- package/dist/editor/ui/TokenField.d.ts +14 -0
- package/dist/editor/ui/TokenField.d.ts.map +1 -0
- package/dist/editor/ui/TokenField.js +41 -0
- package/dist/editor/ui/TokenField.js.map +1 -0
- package/dist/editor/ui/TokenPicker.d.ts +31 -0
- package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
- package/dist/editor/ui/TokenPicker.js +26 -0
- package/dist/editor/ui/TokenPicker.js.map +1 -0
- package/dist/editor/useBuildError.d.ts +7 -0
- package/dist/editor/useBuildError.d.ts.map +1 -0
- package/dist/editor/useBuildError.js +30 -0
- package/dist/editor/useBuildError.js.map +1 -0
- package/dist/editor/useLatestRequest.d.ts +22 -0
- package/dist/editor/useLatestRequest.d.ts.map +1 -0
- package/dist/editor/useLatestRequest.js +49 -0
- package/dist/editor/useLatestRequest.js.map +1 -0
- package/dist/editor-bundle/editor.css +2 -0
- package/dist/editor-bundle/editor.js +83 -0
- package/dist/editor-ui.d.ts +15 -0
- package/dist/editor-ui.d.ts.map +1 -0
- package/dist/editor-ui.js +14 -0
- package/dist/editor-ui.js.map +1 -0
- package/dist/inspector/runtime.d.ts +18 -0
- package/dist/inspector/runtime.d.ts.map +1 -0
- package/dist/inspector/runtime.js +1280 -0
- package/dist/inspector/runtime.js.map +1 -0
- package/dist/preview/main.d.ts +3 -0
- package/dist/preview/main.d.ts.map +1 -0
- package/dist/preview/main.js +320 -0
- package/dist/preview/main.js.map +1 -0
- package/dist/preview/preview.css +40 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/shared/buildError.d.mts +27 -0
- package/dist/shared/buildError.mjs +141 -0
- package/dist/shared/cameraFit.d.mts +16 -0
- package/dist/shared/cameraFit.mjs +47 -0
- package/dist/shared/canvasLayout.d.mts +13 -0
- package/dist/shared/canvasLayout.mjs +171 -0
- package/dist/shared/commentShots.d.mts +12 -0
- package/dist/shared/commentShots.mjs +53 -0
- package/dist/shared/componentExtract.d.mts +43 -0
- package/dist/shared/componentExtract.mjs +136 -0
- package/dist/shared/componentMeta.d.mts +26 -0
- package/dist/shared/componentMeta.mjs +87 -0
- package/dist/shared/componentOps.d.mts +70 -0
- package/dist/shared/componentOps.mjs +407 -0
- package/dist/shared/componentTarget.d.mts +15 -0
- package/dist/shared/componentTarget.mjs +58 -0
- package/dist/shared/components.d.mts +30 -0
- package/dist/shared/components.mjs +106 -0
- package/dist/shared/consolidateCategories.d.mts +2 -0
- package/dist/shared/consolidateCategories.mjs +6 -0
- package/dist/shared/env.d.mts +4 -0
- package/dist/shared/env.mjs +18 -0
- package/dist/shared/gitChanges.d.mts +2 -0
- package/dist/shared/gitChanges.mjs +30 -0
- package/dist/shared/oklab.d.mts +6 -0
- package/dist/shared/oklab.mjs +56 -0
- package/dist/shared/optimizeEntries.d.mts +5 -0
- package/dist/shared/optimizeEntries.mjs +24 -0
- package/dist/shared/packages.d.mts +11 -0
- package/dist/shared/packages.mjs +96 -0
- package/dist/shared/projectFiles.d.mts +23 -0
- package/dist/shared/projectFiles.mjs +72 -0
- package/dist/shared/prompt.d.mts +20 -0
- package/dist/shared/prompt.mjs +201 -0
- package/dist/shared/proposals.d.mts +11 -0
- package/dist/shared/proposals.mjs +42 -0
- package/dist/shared/protocol.d.ts +122 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +7 -0
- package/dist/shared/protocol.js.map +1 -0
- package/dist/shared/reviewArchive.d.mts +4 -0
- package/dist/shared/reviewArchive.mjs +19 -0
- package/dist/shared/reviewStore.d.mts +30 -0
- package/dist/shared/reviewStore.mjs +218 -0
- package/dist/shared/reviewVerify.d.mts +21 -0
- package/dist/shared/reviewVerify.mjs +158 -0
- package/dist/shared/sizeModes.d.mts +15 -0
- package/dist/shared/sizeModes.mjs +53 -0
- package/dist/shared/sketches.d.mts +10 -0
- package/dist/shared/sketches.mjs +64 -0
- package/dist/shared/snapshotCheck.d.mts +13 -0
- package/dist/shared/snapshotCheck.mjs +81 -0
- package/dist/shared/timeout.d.mts +1 -0
- package/dist/shared/timeout.mjs +15 -0
- package/dist/shared/tokens.d.ts +2 -0
- package/dist/shared/tokens.d.ts.map +1 -0
- package/dist/shared/tokens.js +2 -0
- package/dist/shared/tokens.js.map +1 -0
- package/dist/shared/types.d.ts +689 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +13 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/wheelRouting.d.mts +9 -0
- package/dist/shared/wheelRouting.mjs +31 -0
- package/dist/shared/writeScope.mjs +96 -0
- package/dist/snapshots/diff.d.mts +28 -0
- package/dist/snapshots/diff.mjs +263 -0
- package/dist/snapshots/index.d.mts +110 -0
- package/dist/snapshots/index.mjs +638 -0
- package/dist/snapshots/render.d.mts +24 -0
- package/dist/snapshots/render.mjs +250 -0
- package/dist/snapshots/toolOps.d.mts +25 -0
- package/dist/snapshots/toolOps.mjs +69 -0
- package/dist/tokens/adapters/css.mjs +51 -0
- package/dist/tokens/adapters/cssInCode.mjs +314 -0
- package/dist/tokens/adapters/oxcShared.mjs +80 -0
- package/dist/tokens/adapters/preprocessor.mjs +63 -0
- package/dist/tokens/adapters/registry.mjs +53 -0
- package/dist/tokens/adapters/tailwindcss.mjs +424 -0
- package/dist/tokens/adapters/types.mjs +117 -0
- package/dist/tokens/consolidate/index.d.mts +42 -0
- package/dist/tokens/consolidate/index.mjs +111 -0
- package/dist/tokens/consolidate/normalize.mjs +479 -0
- package/dist/tokens/consolidate/plan.mjs +726 -0
- package/dist/tokens/consolidate/scan.mjs +928 -0
- package/dist/tokens/extract.mjs +441 -0
- package/dist/tokens/moduleData.d.mts +14 -0
- package/dist/tokens/moduleData.mjs +32 -0
- package/dist/tokens/opLock.d.mts +4 -0
- package/dist/tokens/opLock.mjs +108 -0
- package/dist/tokens/ops.d.mts +71 -0
- package/dist/tokens/ops.mjs +1511 -0
- package/dist/tokens/pipeline.mjs +813 -0
- package/dist/tokens/report.d.mts +47 -0
- package/dist/tokens/report.mjs +257 -0
- package/dist/tokens/rewrite/code.mjs +172 -0
- package/dist/tokens/rewrite/css.mjs +154 -0
- package/dist/tokens/rewrite/index.mjs +244 -0
- package/dist/tokens/rewrite/tailwind.mjs +288 -0
- package/dist/tokens/rewrite/text.mjs +116 -0
- package/dist/tokens/rewrite/value.mjs +115 -0
- package/dist/tokens/usage.d.mts +97 -0
- package/dist/tokens/usage.mjs +680 -0
- package/dist/vite/agent.d.ts +21 -0
- package/dist/vite/agent.d.ts.map +1 -0
- package/dist/vite/agent.js +165 -0
- package/dist/vite/agent.js.map +1 -0
- package/dist/vite/events.d.ts +27 -0
- package/dist/vite/events.d.ts.map +1 -0
- package/dist/vite/events.js +156 -0
- package/dist/vite/events.js.map +1 -0
- package/dist/vite/layout.d.ts +2 -0
- package/dist/vite/layout.d.ts.map +1 -0
- package/dist/vite/layout.js +4 -0
- package/dist/vite/layout.js.map +1 -0
- package/dist/vite/plugin.d.ts +40 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +1255 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite/requestGuard.d.mts +3 -0
- package/dist/vite/requestGuard.mjs +43 -0
- package/dist/vite/review.d.ts +11 -0
- package/dist/vite/review.d.ts.map +1 -0
- package/dist/vite/review.js +283 -0
- package/dist/vite/review.js.map +1 -0
- package/package.json +106 -1
- package/skills/seji/SKILL.md +395 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
package/dist/cli/app.mjs
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// Which package is the app? `setup`, `dev` and `doctor` all run inside one Vite + React app
|
|
2
|
+
// package. From the working directory: the package around it when that is an app; else the
|
|
3
|
+
// workspace around it (pnpm-workspace.yaml, package.json#workspaces) or the repository (.git) is
|
|
4
|
+
// searched for app packages. One → that one (printed as `APP <path>`). Several → the caller lists
|
|
5
|
+
// `--app <path>` for each. None → a clear error (Next.js / Vue / no Vite are not supported).
|
|
6
|
+
// Nothing here writes; a workspace root that is not itself the app is never a target.
|
|
7
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
8
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
9
|
+
|
|
10
|
+
import { glob, globSync } from 'tinyglobby'
|
|
11
|
+
|
|
12
|
+
import { findPackageDir } from '../shared/packages.mjs'
|
|
13
|
+
|
|
14
|
+
export const VITE_CONFIG_NAMES = ['vite.config.ts', 'vite.config.mts', 'vite.config.js', 'vite.config.mjs', 'vite.config.cts', 'vite.config.cjs']
|
|
15
|
+
export const REACT_PLUGINS = ['@vitejs/plugin-react', '@vitejs/plugin-react-swc', '@vitejs/plugin-react-oxc']
|
|
16
|
+
|
|
17
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
18
|
+
|
|
19
|
+
export const readPackageJson = (dir) => {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
22
|
+
} catch {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const viteConfigOf = (dir) => VITE_CONFIG_NAMES.find((name) => existsSync(join(dir, name))) ?? null
|
|
28
|
+
|
|
29
|
+
const declaredDeps = (pkg) => ({
|
|
30
|
+
...(pkg?.peerDependencies ?? {}),
|
|
31
|
+
...(pkg?.optionalDependencies ?? {}),
|
|
32
|
+
...(pkg?.devDependencies ?? {}),
|
|
33
|
+
...(pkg?.dependencies ?? {}),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/** What a package is: its Vite config, React, the React plugin, and what else it might be. */
|
|
37
|
+
export function appTraits(dir) {
|
|
38
|
+
const pkg = readPackageJson(dir)
|
|
39
|
+
const deps = declaredDeps(pkg)
|
|
40
|
+
const config = viteConfigOf(dir)
|
|
41
|
+
return {
|
|
42
|
+
dir,
|
|
43
|
+
name: pkg?.name ?? null,
|
|
44
|
+
hasPackageJson: Boolean(pkg),
|
|
45
|
+
config,
|
|
46
|
+
vite: 'vite' in deps || Boolean(config),
|
|
47
|
+
react: 'react' in deps,
|
|
48
|
+
reactPlugin: REACT_PLUGINS.find((name) => name in deps) ?? null,
|
|
49
|
+
next: 'next' in deps,
|
|
50
|
+
vue: 'vue' in deps || '@vitejs/plugin-vue' in deps,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const isViteReactApp = (traits) => Boolean(traits.hasPackageJson && traits.config && traits.react && traits.reactPlugin)
|
|
55
|
+
|
|
56
|
+
/** Why a package is not a Vite + React app, in one phrase. */
|
|
57
|
+
export function notAppReason(traits) {
|
|
58
|
+
if (!traits.hasPackageJson) return 'no package.json'
|
|
59
|
+
if (traits.next) return 'a Next.js app (not supported: seji needs Vite + React)'
|
|
60
|
+
if (traits.vue) return 'a Vue app (not supported: seji needs Vite + React)'
|
|
61
|
+
if (!traits.config) return 'no vite.config.* file'
|
|
62
|
+
if (!traits.react) return 'react is not a dependency'
|
|
63
|
+
if (!traits.reactPlugin) return `no React plugin for Vite (${REACT_PLUGINS.slice(0, 2).join(' or ')}) in its dependencies`
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Nearest directory at or above `from` with a package.json, or null. */
|
|
68
|
+
export function nearestPackageDir(from) {
|
|
69
|
+
let dir = resolve(from)
|
|
70
|
+
for (;;) {
|
|
71
|
+
if (existsSync(join(dir, 'package.json'))) return dir
|
|
72
|
+
const parent = dirname(dir)
|
|
73
|
+
if (parent === dir) return null
|
|
74
|
+
dir = parent
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The packages listed in pnpm-workspace.yaml (`packages:` sequence only; no YAML library needed). */
|
|
79
|
+
export function pnpmWorkspacePatterns(file) {
|
|
80
|
+
const patterns = []
|
|
81
|
+
let inPackages = false
|
|
82
|
+
for (const raw of readFileSync(file, 'utf8').split(/\r?\n/)) {
|
|
83
|
+
const line = raw.replace(/\s+#.*$/, '')
|
|
84
|
+
if (!line.trim()) continue
|
|
85
|
+
if (/^packages\s*:/.test(line)) {
|
|
86
|
+
inPackages = true
|
|
87
|
+
const inline = /^packages\s*:\s*\[(.*)\]\s*$/.exec(line)
|
|
88
|
+
if (inline) {
|
|
89
|
+
for (const item of inline[1].split(',')) {
|
|
90
|
+
const value = item.trim().replace(/^['"]|['"]$/g, '')
|
|
91
|
+
if (value) patterns.push(value)
|
|
92
|
+
}
|
|
93
|
+
inPackages = false
|
|
94
|
+
}
|
|
95
|
+
continue
|
|
96
|
+
}
|
|
97
|
+
if (inPackages) {
|
|
98
|
+
const item = /^\s*-\s*(.+?)\s*$/.exec(line)
|
|
99
|
+
if (item) patterns.push(item[1].replace(/^['"]|['"]$/g, ''))
|
|
100
|
+
else if (!/^\s/.test(line)) inPackages = false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return patterns
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The workspace around `from`: `{ root, patterns }` from pnpm-workspace.yaml or a package.json
|
|
108
|
+
* with `workspaces`, else null.
|
|
109
|
+
*/
|
|
110
|
+
export function findWorkspace(from) {
|
|
111
|
+
let dir = resolve(from)
|
|
112
|
+
for (;;) {
|
|
113
|
+
const pnpm = join(dir, 'pnpm-workspace.yaml')
|
|
114
|
+
if (existsSync(pnpm)) return { root: dir, patterns: pnpmWorkspacePatterns(pnpm), kind: 'pnpm' }
|
|
115
|
+
const pkg = readPackageJson(dir)
|
|
116
|
+
if (pkg?.workspaces) {
|
|
117
|
+
const patterns = Array.isArray(pkg.workspaces) ? pkg.workspaces : Array.isArray(pkg.workspaces.packages) ? pkg.workspaces.packages : []
|
|
118
|
+
return { root: dir, patterns, kind: 'package.json' }
|
|
119
|
+
}
|
|
120
|
+
const parent = dirname(dir)
|
|
121
|
+
if (parent === dir) return null
|
|
122
|
+
dir = parent
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The repository root above `from` (.git), or null. */
|
|
127
|
+
export function findRepoRoot(from) {
|
|
128
|
+
let dir = resolve(from)
|
|
129
|
+
for (;;) {
|
|
130
|
+
if (existsSync(join(dir, '.git'))) return dir
|
|
131
|
+
const parent = dirname(dir)
|
|
132
|
+
if (parent === dir) return null
|
|
133
|
+
dir = parent
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const IGNORED_DIRS = ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/build/**', '**/.seji/**']
|
|
138
|
+
|
|
139
|
+
/** Package directories of a workspace (its patterns), sorted. */
|
|
140
|
+
export async function workspacePackages(workspace) {
|
|
141
|
+
const include = workspace.patterns.filter((pattern) => !pattern.startsWith('!')).map((pattern) => `${pattern.replace(/\/+$/, '')}/package.json`)
|
|
142
|
+
const exclude = workspace.patterns.filter((pattern) => pattern.startsWith('!')).map((pattern) => `${pattern.slice(1).replace(/\/+$/, '')}/package.json`)
|
|
143
|
+
if (!include.length) return []
|
|
144
|
+
const files = await glob(include, { cwd: workspace.root, absolute: true, onlyFiles: true, ignore: [...IGNORED_DIRS, ...exclude] })
|
|
145
|
+
return [...new Set(files.map((file) => dirname(file)))].sort()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Packages in a repository without workspaces: up to two levels below its root. */
|
|
149
|
+
async function nestedPackages(root) {
|
|
150
|
+
const files = await glob(['*/package.json', '*/*/package.json'], { cwd: root, absolute: true, onlyFiles: true, ignore: IGNORED_DIRS })
|
|
151
|
+
return [...new Set(files.map((file) => dirname(file)))].sort()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** A `design/` directory that holds designs: surface.config.json or any `<id>/design.tsx`. */
|
|
155
|
+
export function looksLikeDesignDir(dir) {
|
|
156
|
+
if (!existsSync(dir)) return false
|
|
157
|
+
if (existsSync(join(dir, 'surface.config.json'))) return true
|
|
158
|
+
try {
|
|
159
|
+
return readdirSync(dir, { withFileTypes: true }).some((entry) => entry.isDirectory() && !entry.name.startsWith('.') && existsSync(join(dir, entry.name, 'design.tsx')))
|
|
160
|
+
} catch {
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The design directory for `appRoot`: its own `design/` when present; else an existing design
|
|
167
|
+
* directory at the cwd or the workspace / repository root the app was found from (a 0.4.2-era
|
|
168
|
+
* repo keeps `design/` at its root while the Vite app is `apps/web`). Nothing is created or moved.
|
|
169
|
+
*/
|
|
170
|
+
export function findExistingDesignDir(start, base, appRoot) {
|
|
171
|
+
const own = join(appRoot, 'design')
|
|
172
|
+
if (existsSync(own)) return own
|
|
173
|
+
for (const dir of [...new Set([resolve(start), base && resolve(base)].filter(Boolean))]) {
|
|
174
|
+
if (dir === appRoot) continue
|
|
175
|
+
const candidate = join(dir, 'design')
|
|
176
|
+
if (looksLikeDesignDir(candidate)) return candidate
|
|
177
|
+
}
|
|
178
|
+
return own
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Find the app for `cwd` (or the explicit `app` directory).
|
|
183
|
+
*
|
|
184
|
+
* `{ status: 'ok', root, rel, how, traits, designDir }` (`designDir`: absolute, usually `<root>/design`) | `{ status: 'multiple', base, candidates: [{ root, rel }] }` |
|
|
185
|
+
* `{ status: 'none', base, searched: [{ rel, reason }], message }` | `{ status: 'invalid', root, rel, reason, message }`.
|
|
186
|
+
* `rel` is relative to `base` (the workspace / repository root, else cwd) for display.
|
|
187
|
+
*/
|
|
188
|
+
export async function resolveApp({ cwd = process.cwd(), app } = {}) {
|
|
189
|
+
const start = resolve(cwd)
|
|
190
|
+
if (app) {
|
|
191
|
+
const root = resolve(start, app)
|
|
192
|
+
const traits = appTraits(root)
|
|
193
|
+
const rel = toPosix(relative(start, root)) || '.'
|
|
194
|
+
if (!isViteReactApp(traits)) {
|
|
195
|
+
const reason = existsSync(root) ? notAppReason(traits) : 'the directory does not exist'
|
|
196
|
+
return { status: 'invalid', root, rel, reason, message: `--app ${app}: not a Vite + React app (${reason})` }
|
|
197
|
+
}
|
|
198
|
+
return { status: 'ok', root, rel, how: 'flag', traits, designDir: join(root, 'design') }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const nearest = nearestPackageDir(start)
|
|
202
|
+
if (nearest) {
|
|
203
|
+
const traits = appTraits(nearest)
|
|
204
|
+
if (isViteReactApp(traits)) {
|
|
205
|
+
return { status: 'ok', root: nearest, rel: toPosix(relative(start, nearest)) || '.', how: 'cwd', traits, designDir: join(nearest, 'design') }
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const workspace = findWorkspace(start)
|
|
210
|
+
const base = workspace?.root ?? findRepoRoot(start) ?? nearest ?? start
|
|
211
|
+
const dirs = workspace ? await workspacePackages(workspace) : await nestedPackages(base)
|
|
212
|
+
if (nearest && !dirs.includes(nearest)) dirs.unshift(nearest)
|
|
213
|
+
const searched = []
|
|
214
|
+
const candidates = []
|
|
215
|
+
for (const dir of dirs) {
|
|
216
|
+
const traits = appTraits(dir)
|
|
217
|
+
const rel = toPosix(relative(base, dir)) || '.'
|
|
218
|
+
if (isViteReactApp(traits)) candidates.push({ root: dir, rel, traits })
|
|
219
|
+
else searched.push({ rel, reason: notAppReason(traits) })
|
|
220
|
+
}
|
|
221
|
+
if (candidates.length === 1) {
|
|
222
|
+
const [only] = candidates
|
|
223
|
+
const designDir = findExistingDesignDir(start, base, only.root)
|
|
224
|
+
return { status: 'ok', root: only.root, rel: only.rel, how: workspace ? 'workspace' : 'search', traits: only.traits, base, designDir }
|
|
225
|
+
}
|
|
226
|
+
if (candidates.length > 1) {
|
|
227
|
+
return {
|
|
228
|
+
status: 'multiple',
|
|
229
|
+
base,
|
|
230
|
+
candidates: candidates.map(({ root, rel }) => ({ root, rel, arg: toPosix(relative(start, root)) || '.' })),
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const unsupported = searched.find((entry) => /Next\.js|Vue/.test(entry.reason ?? ''))
|
|
234
|
+
return {
|
|
235
|
+
status: 'none',
|
|
236
|
+
base,
|
|
237
|
+
searched,
|
|
238
|
+
message: unsupported
|
|
239
|
+
? `no Vite + React app found: ${unsupported.rel} is ${unsupported.reason}`
|
|
240
|
+
: 'no Vite + React app found here (a package with vite.config.*, react and @vitejs/plugin-react). Next.js and Vue apps are not supported.',
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** `{ designDir, home, external, rel }` for an ok `resolveApp` result: `home` is the design dir's parent. */
|
|
245
|
+
export function designLocation(found, cwd = process.cwd()) {
|
|
246
|
+
const designDir = found.designDir ?? join(found.root, 'design')
|
|
247
|
+
const external = resolve(designDir) !== resolve(join(found.root, 'design'))
|
|
248
|
+
return { designDir, home: dirname(designDir), external, rel: toPosix(relative(resolve(cwd), designDir)) || '.' }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const appForHome = new Map()
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The one Vite + React app a design home (the directory holding `design/`) belongs to: the
|
|
255
|
+
* home itself when it is the app, else the only app among its workspace packages (a 0.4.2-era
|
|
256
|
+
* repo keeps `design/` at its root while the app is `apps/web`), else null. Synchronous.
|
|
257
|
+
*/
|
|
258
|
+
export function appRootForDesignHome(home) {
|
|
259
|
+
const key = resolve(home)
|
|
260
|
+
if (appForHome.has(key)) return appForHome.get(key)
|
|
261
|
+
let found = null
|
|
262
|
+
if (isViteReactApp(appTraits(key))) found = key
|
|
263
|
+
else {
|
|
264
|
+
const workspace = findWorkspace(key)
|
|
265
|
+
if (workspace && workspace.root === key) {
|
|
266
|
+
const include = workspace.patterns.filter((pattern) => !pattern.startsWith('!')).map((pattern) => `${pattern.replace(/\/+$/, '')}/package.json`)
|
|
267
|
+
const exclude = workspace.patterns.filter((pattern) => pattern.startsWith('!')).map((pattern) => `${pattern.slice(1).replace(/\/+$/, '')}/package.json`)
|
|
268
|
+
const dirs = include.length ? [...new Set(globSync(include, { cwd: key, absolute: true, onlyFiles: true, ignore: [...IGNORED_DIRS, ...exclude] }).map((file) => dirname(resolve(file))))] : []
|
|
269
|
+
const apps = dirs.filter((dir) => isViteReactApp(appTraits(dir)))
|
|
270
|
+
if (apps.length === 1) found = apps[0]
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
appForHome.set(key, found)
|
|
274
|
+
return found
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Where the generated token CSS lives: the single owner of that path. `cssOut` (tokens.config.json,
|
|
279
|
+
* default `src/tokens.generated.css`) is relative to the app. For a design dir inside the app that
|
|
280
|
+
* is the design home itself; for an existing design/ at the repository root it is the app
|
|
281
|
+
* (apps/web), unless `cssOut` already names a path inside the app from the root
|
|
282
|
+
* (`apps/web/src/tokens.generated.css`).
|
|
283
|
+
*/
|
|
284
|
+
export function generatedCssPath(home, cssOut) {
|
|
285
|
+
const fromHome = resolve(home, cssOut)
|
|
286
|
+
if (isAbsolute(cssOut)) return fromHome
|
|
287
|
+
const app = appRootForDesignHome(home)
|
|
288
|
+
if (!app || app === resolve(home)) return fromHome
|
|
289
|
+
const inApp = relative(app, fromHome)
|
|
290
|
+
if (inApp && !inApp.startsWith('..') && !isAbsolute(inApp)) return fromHome
|
|
291
|
+
return resolve(app, cssOut)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** The text a command prints when `resolveApp` did not settle on one app. */
|
|
295
|
+
export function appProblemText(found, command = 'setup') {
|
|
296
|
+
if (found.status === 'multiple') {
|
|
297
|
+
return [
|
|
298
|
+
`several Vite + React apps found under ${found.base}; pick one:`,
|
|
299
|
+
...found.candidates.map((candidate) => ` seji ${command} --app ${candidate.arg}`),
|
|
300
|
+
].join('\n')
|
|
301
|
+
}
|
|
302
|
+
if (found.status === 'none') {
|
|
303
|
+
const lines = [found.message]
|
|
304
|
+
for (const entry of found.searched.slice(0, 12)) lines.push(` ${entry.rel}: ${entry.reason}`)
|
|
305
|
+
return lines.join('\n')
|
|
306
|
+
}
|
|
307
|
+
return found.message ?? ''
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The packages the editor needs, resolved from the app (node_modules walk):
|
|
312
|
+
* `{ vite, react, reactDom, reactPlugin }` → directory or null.
|
|
313
|
+
*/
|
|
314
|
+
export function appPackages(root, traits = appTraits(root)) {
|
|
315
|
+
return {
|
|
316
|
+
vite: findPackageDir(root, 'vite'),
|
|
317
|
+
react: findPackageDir(root, 'react'),
|
|
318
|
+
'react-dom': findPackageDir(root, 'react-dom'),
|
|
319
|
+
[traits.reactPlugin ?? '@vitejs/plugin-react']: findPackageDir(root, traits.reactPlugin ?? '@vitejs/plugin-react'),
|
|
320
|
+
}
|
|
321
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Reads an app's real setup for `setup` / `doctor`, never its text by pattern: the Vite config
|
|
2
|
+
// through the app's own Vite (`loadConfigFromFile`: aliases, plugins), the entry module from
|
|
3
|
+
// index.html, the entry's CSS imports and its provider tree from the entry's syntax tree
|
|
4
|
+
// (@babel/parser), Tailwind from the plugins / the CSS syntax tree (postcss).
|
|
5
|
+
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
6
|
+
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
7
|
+
import { pathToFileURL } from 'node:url'
|
|
8
|
+
|
|
9
|
+
import { parse } from '@babel/parser'
|
|
10
|
+
import postcss from 'postcss'
|
|
11
|
+
|
|
12
|
+
import { findPackageDir } from '../shared/packages.mjs'
|
|
13
|
+
import { readPackageJson, viteConfigOf } from './app.mjs'
|
|
14
|
+
|
|
15
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
16
|
+
|
|
17
|
+
const readJson = (file) => {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(readFileSync(file, 'utf8'))
|
|
20
|
+
} catch {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function pickExport(value) {
|
|
26
|
+
if (typeof value === 'string') return value
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
for (const item of value) {
|
|
29
|
+
const found = pickExport(item)
|
|
30
|
+
if (found) return found
|
|
31
|
+
}
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
if (value && typeof value === 'object') {
|
|
35
|
+
for (const key of ['import', 'node', 'default', 'module']) {
|
|
36
|
+
if (key in value) {
|
|
37
|
+
const found = pickExport(value[key])
|
|
38
|
+
if (found) return found
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The ESM entry file of the package in `dir` (exports "." → import / node / default, else module / main). */
|
|
46
|
+
export function packageEntry(dir) {
|
|
47
|
+
const pkg = readJson(join(dir, 'package.json')) ?? {}
|
|
48
|
+
let target = null
|
|
49
|
+
const exportsField = pkg.exports
|
|
50
|
+
if (exportsField) {
|
|
51
|
+
const dot =
|
|
52
|
+
typeof exportsField === 'string' || Array.isArray(exportsField) || !Object.keys(exportsField).some((key) => key.startsWith('.'))
|
|
53
|
+
? exportsField
|
|
54
|
+
: exportsField['.']
|
|
55
|
+
target = pickExport(dot)
|
|
56
|
+
}
|
|
57
|
+
return join(dir, target ?? pkg.module ?? pkg.main ?? 'index.js')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Import package `name` as the app resolves it (its node_modules), or null. */
|
|
61
|
+
export async function importFromApp(appRoot, name) {
|
|
62
|
+
const dir = findPackageDir(appRoot, name)
|
|
63
|
+
if (!dir) return null
|
|
64
|
+
return import(pathToFileURL(packageEntry(dir)).href)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function flatPlugins(list, out = []) {
|
|
68
|
+
for (const entry of Array.isArray(list) ? list : [list]) {
|
|
69
|
+
const value = await entry
|
|
70
|
+
if (!value) continue
|
|
71
|
+
if (Array.isArray(value)) await flatPlugins(value, out)
|
|
72
|
+
else out.push(value)
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Vite `resolve.alias` (object or array) as `[{ find, replacement }]`. */
|
|
78
|
+
export function normalizeAliases(alias) {
|
|
79
|
+
if (!alias) return []
|
|
80
|
+
if (Array.isArray(alias)) return alias.filter((entry) => entry && entry.find !== undefined && typeof entry.replacement === 'string')
|
|
81
|
+
return Object.entries(alias)
|
|
82
|
+
.filter(([, replacement]) => typeof replacement === 'string')
|
|
83
|
+
.map(([find, replacement]) => ({ find, replacement }))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The app's Vite config, loaded by the app's own Vite: `{ ok, file, config, pluginNames,
|
|
88
|
+
* aliases, tailwind, designPlugin }`, or `{ ok: false, error }`.
|
|
89
|
+
*/
|
|
90
|
+
export async function loadAppViteConfig(appRoot) {
|
|
91
|
+
const file = viteConfigOf(appRoot)
|
|
92
|
+
if (!file) return { ok: false, error: 'no vite.config.* file' }
|
|
93
|
+
let vite
|
|
94
|
+
try {
|
|
95
|
+
vite = await importFromApp(appRoot, 'vite')
|
|
96
|
+
} catch (error) {
|
|
97
|
+
return { ok: false, file, error: `vite could not be loaded from the app: ${error instanceof Error ? error.message : String(error)}` }
|
|
98
|
+
}
|
|
99
|
+
if (!vite || typeof vite.loadConfigFromFile !== 'function') {
|
|
100
|
+
return { ok: false, file, error: 'vite is not installed in the app (run the app\'s package install first)' }
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const loaded = await vite.loadConfigFromFile({ command: 'serve', mode: 'development' }, join(appRoot, file), appRoot, 'silent')
|
|
104
|
+
const config = loaded?.config ?? {}
|
|
105
|
+
const plugins = await flatPlugins(config.plugins ?? [])
|
|
106
|
+
const pluginNames = plugins.map((plugin) => plugin?.name).filter((name) => typeof name === 'string')
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
file,
|
|
110
|
+
vite,
|
|
111
|
+
viteVersion: typeof vite.version === 'string' ? vite.version : null,
|
|
112
|
+
config,
|
|
113
|
+
pluginNames,
|
|
114
|
+
aliases: normalizeAliases(config.resolve?.alias),
|
|
115
|
+
tailwind: pluginNames.some((name) => name.startsWith('@tailwindcss/vite')),
|
|
116
|
+
designPlugin: pluginNames.includes('seji'),
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return { ok: false, file, error: `${file} could not be loaded: ${error instanceof Error ? error.message.split('\n')[0] : String(error)}` }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const SOURCE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.mts']
|
|
124
|
+
|
|
125
|
+
/** A module file for `base` (as is, + extension, /index + extension), or null. */
|
|
126
|
+
export function resolveModuleFile(base) {
|
|
127
|
+
if (isFile(base)) return base
|
|
128
|
+
for (const ext of SOURCE_EXTENSIONS) if (isFile(`${base}${ext}`)) return `${base}${ext}`
|
|
129
|
+
for (const ext of SOURCE_EXTENSIONS) if (isFile(join(base, `index${ext}`))) return join(base, `index${ext}`)
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const isFile = (file) => {
|
|
134
|
+
try {
|
|
135
|
+
return statSync(file).isFile()
|
|
136
|
+
} catch {
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Where `spec` (imported from `importerDir`) points on disk, through the app's aliases; null for
|
|
143
|
+
* a bare package import.
|
|
144
|
+
*/
|
|
145
|
+
export function resolveSpecifier(spec, { importerDir, appRoot, aliases = [] }) {
|
|
146
|
+
const clean = spec.replace(/[?#].*$/, '')
|
|
147
|
+
const target = (replacement) => {
|
|
148
|
+
if (isAbsolute(replacement) && existsSync(dirname(replacement))) return replacement
|
|
149
|
+
if (replacement.startsWith('/')) return join(appRoot, replacement.slice(1))
|
|
150
|
+
if (/^[./]/.test(replacement)) return resolve(appRoot, replacement)
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
for (const { find, replacement } of aliases) {
|
|
154
|
+
if (typeof find === 'string') {
|
|
155
|
+
if (clean === find || clean.startsWith(find.endsWith('/') ? find : `${find}/`)) return target(replacement + clean.slice(find.length))
|
|
156
|
+
} else if (find instanceof RegExp && find.test(clean)) {
|
|
157
|
+
return target(clean.replace(find, replacement))
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (clean.startsWith('.')) return resolve(importerDir, clean)
|
|
161
|
+
if (clean.startsWith('/')) return join(appRoot, clean.slice(1))
|
|
162
|
+
return null
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The entry module: index.html's module script, else a usual entry file. */
|
|
166
|
+
export function findEntry(appRoot) {
|
|
167
|
+
const html = join(appRoot, 'index.html')
|
|
168
|
+
if (existsSync(html)) {
|
|
169
|
+
const text = readFileSync(html, 'utf8')
|
|
170
|
+
// index.html is read, never written: its script tags name the entry module.
|
|
171
|
+
for (const match of text.matchAll(/<script\b([^>]*)>/gi)) {
|
|
172
|
+
const attrs = match[1]
|
|
173
|
+
const src = /\bsrc\s*=\s*["']([^"']+)["']/i.exec(attrs)?.[1]
|
|
174
|
+
if (!src || /^[a-z]+:\/\//i.test(src) || src.startsWith('/@')) continue
|
|
175
|
+
const file = src.startsWith('/') ? join(appRoot, src.slice(1)) : resolve(appRoot, src)
|
|
176
|
+
if (existsSync(file)) return { file, from: 'index.html' }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
for (const rel of ['src/main.tsx', 'src/main.jsx', 'src/index.tsx', 'src/index.jsx', 'src/main.ts', 'src/main.js']) {
|
|
180
|
+
if (existsSync(join(appRoot, rel))) return { file: join(appRoot, rel), from: 'default' }
|
|
181
|
+
}
|
|
182
|
+
return null
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Stylesheets index.html links (`<link rel="stylesheet" href="/src/…">`) inside the app. */
|
|
186
|
+
function htmlStylesheets(appRoot) {
|
|
187
|
+
const html = join(appRoot, 'index.html')
|
|
188
|
+
if (!existsSync(html)) return []
|
|
189
|
+
const out = []
|
|
190
|
+
for (const match of readFileSync(html, 'utf8').matchAll(/<link\b([^>]*)>/gi)) {
|
|
191
|
+
const attrs = match[1]
|
|
192
|
+
if (!/\brel\s*=\s*["']stylesheet["']/i.test(attrs)) continue
|
|
193
|
+
const href = /\bhref\s*=\s*["']([^"']+)["']/i.exec(attrs)?.[1]
|
|
194
|
+
if (!href || /^[a-z]+:\/\//i.test(href)) continue
|
|
195
|
+
const file = href.startsWith('/') ? join(appRoot, href.slice(1)) : resolve(appRoot, href)
|
|
196
|
+
if (existsSync(file)) out.push(file)
|
|
197
|
+
}
|
|
198
|
+
return out
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function parseModule(file, code = readFileSync(file, 'utf8')) {
|
|
202
|
+
const plugins = /\.(?:ts|mts|cts)$/i.test(file) ? ['typescript'] : /\.tsx$/i.test(file) ? ['typescript', 'jsx'] : ['jsx']
|
|
203
|
+
return parse(code, { sourceType: 'module', errorRecovery: true, plugins })
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const STYLE_RE = /\.(?:css|scss|sass|less|styl|stylus|pcss|postcss)$/i
|
|
207
|
+
|
|
208
|
+
/** Stylesheets the entry module imports (side-effect / default imports), as files that exist. */
|
|
209
|
+
export function entryStylesheets(entryFile, { appRoot, aliases = [] }) {
|
|
210
|
+
const out = []
|
|
211
|
+
let ast
|
|
212
|
+
try {
|
|
213
|
+
ast = parseModule(entryFile)
|
|
214
|
+
} catch {
|
|
215
|
+
return htmlStylesheets(appRoot)
|
|
216
|
+
}
|
|
217
|
+
for (const node of ast.program.body) {
|
|
218
|
+
if (node.type !== 'ImportDeclaration') continue
|
|
219
|
+
const spec = node.source.value
|
|
220
|
+
if (/[?&](?:inline|url|raw)\b/.test(spec)) continue
|
|
221
|
+
if (!STYLE_RE.test(spec.replace(/[?#].*$/, ''))) continue
|
|
222
|
+
const file = resolveSpecifier(spec, { importerDir: dirname(entryFile), appRoot, aliases })
|
|
223
|
+
if (file && existsSync(file)) out.push(file)
|
|
224
|
+
}
|
|
225
|
+
for (const file of htmlStylesheets(appRoot)) if (!out.includes(file)) out.push(file)
|
|
226
|
+
return out
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** `@import` at-rules of a stylesheet: `[{ node, target }]` (target = the imported url / name). */
|
|
230
|
+
export function cssImports(root) {
|
|
231
|
+
const out = []
|
|
232
|
+
root.walkAtRules('import', (node) => {
|
|
233
|
+
const match = /^\s*(?:url\(\s*)?["']?([^"')\s]+)["']?\s*\)?/.exec(node.params)
|
|
234
|
+
if (match) out.push({ node, target: match[1] })
|
|
235
|
+
})
|
|
236
|
+
return out
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function parseStylesheet(file, text = readFileSync(file, 'utf8')) {
|
|
240
|
+
return postcss.parse(text, { from: file })
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Tailwind in a stylesheet: 4 (`@import "tailwindcss"`), 3 (`@tailwind base`), or null. */
|
|
244
|
+
export function stylesheetTailwind(file) {
|
|
245
|
+
try {
|
|
246
|
+
const root = parseStylesheet(file)
|
|
247
|
+
if (cssImports(root).some(({ target }) => target === 'tailwindcss' || target.startsWith('tailwindcss/'))) return 4
|
|
248
|
+
let v3 = false
|
|
249
|
+
root.walkAtRules('tailwind', () => {
|
|
250
|
+
v3 = true
|
|
251
|
+
})
|
|
252
|
+
return v3 ? 3 : null
|
|
253
|
+
} catch {
|
|
254
|
+
return null
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Tailwind's major version from the app's dependencies, or null. */
|
|
259
|
+
function declaredTailwind(appRoot) {
|
|
260
|
+
const pkg = readPackageJson(appRoot)
|
|
261
|
+
const deps = { ...(pkg?.devDependencies ?? {}), ...(pkg?.dependencies ?? {}) }
|
|
262
|
+
if ('@tailwindcss/vite' in deps || '@tailwindcss/postcss' in deps) return 4
|
|
263
|
+
const range = deps.tailwindcss
|
|
264
|
+
if (typeof range !== 'string') return null
|
|
265
|
+
const major = /(\d+)/.exec(range)?.[1]
|
|
266
|
+
return major ? Number(major) : null
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The app's styles: `{ entry, stylesheets, cssEntry, tailwind, cssFormat }`.
|
|
271
|
+
* cssEntry: the entry stylesheet that imports Tailwind, else the first one (null when the entry
|
|
272
|
+
* imports none). cssFormat: `theme` for Tailwind 4 (tokens in `@theme`), else `root`.
|
|
273
|
+
*/
|
|
274
|
+
export function appStyles(appRoot, { aliases = [], tailwindPlugin = false } = {}) {
|
|
275
|
+
const entry = findEntry(appRoot)
|
|
276
|
+
const stylesheets = entry ? entryStylesheets(entry.file, { appRoot, aliases }) : htmlStylesheets(appRoot)
|
|
277
|
+
const versions = new Map(stylesheets.map((file) => [file, stylesheetTailwind(file)]))
|
|
278
|
+
const cssEntry = stylesheets.find((file) => versions.get(file)) ?? stylesheets.find((file) => /\.css$/i.test(file)) ?? stylesheets[0] ?? null
|
|
279
|
+
const fromCss = cssEntry ? versions.get(cssEntry) : null
|
|
280
|
+
const tailwind = fromCss ?? (tailwindPlugin ? 4 : declaredTailwind(appRoot))
|
|
281
|
+
return { entry, stylesheets, cssEntry, tailwind, cssFormat: tailwind === 4 ? 'theme' : 'root' }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export const rootRelative = (appRoot, file) => `/${toPosix(relative(appRoot, file))}`
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The component catalog the CLI uses, so `seji component …` lists the same set
|
|
2
|
+
// as the editor and /__seji/api/components: the `componentGroups` of the seji
|
|
3
|
+
// Vite plugin, scanned with the same function the plugin uses (scanComponentGroups).
|
|
4
|
+
//
|
|
5
|
+
// Where the groups come from, in the order the dev server would use them:
|
|
6
|
+
// 1. the project's Vite config (`vite.config.*`): the `seji` plugin exposes its
|
|
7
|
+
// resolved options on `plugin.api.componentGroups`;
|
|
8
|
+
// 2. otherwise `design/surface.config.json` / the defaults `seji dev` uses.
|
|
9
|
+
import { existsSync } from 'node:fs'
|
|
10
|
+
import { createRequire } from 'node:module'
|
|
11
|
+
import { join } from 'node:path'
|
|
12
|
+
import { pathToFileURL } from 'node:url'
|
|
13
|
+
|
|
14
|
+
import { scanComponentGroups } from '../shared/components.mjs'
|
|
15
|
+
|
|
16
|
+
const VITE_CONFIGS = ['vite.config.ts', 'vite.config.mts', 'vite.config.js', 'vite.config.mjs', 'vite.config.cts', 'vite.config.cjs']
|
|
17
|
+
|
|
18
|
+
async function importVite(root) {
|
|
19
|
+
const hostPkg = join(root, 'package.json')
|
|
20
|
+
if (existsSync(hostPkg)) {
|
|
21
|
+
try {
|
|
22
|
+
const resolved = createRequire(hostPkg).resolve('vite')
|
|
23
|
+
const mod = await import(pathToFileURL(resolved).href)
|
|
24
|
+
if (typeof mod.loadConfigFromFile === 'function') return mod
|
|
25
|
+
} catch {
|
|
26
|
+
// fall back to the package's own vite
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const mod = await import('vite')
|
|
31
|
+
if (typeof mod.loadConfigFromFile === 'function') return mod
|
|
32
|
+
} catch {
|
|
33
|
+
// no vite
|
|
34
|
+
}
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function flatPlugins(list, out = []) {
|
|
39
|
+
for (const entry of Array.isArray(list) ? list : [list]) {
|
|
40
|
+
const value = await entry
|
|
41
|
+
if (!value) continue
|
|
42
|
+
if (Array.isArray(value)) await flatPlugins(value, out)
|
|
43
|
+
else out.push(value)
|
|
44
|
+
}
|
|
45
|
+
return out
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `componentGroups` of the seji plugin in the project's Vite config, or null. */
|
|
49
|
+
export async function viteComponentGroups(root, configFile) {
|
|
50
|
+
const file = configFile ? join(root, configFile) : VITE_CONFIGS.map((name) => join(root, name)).find((candidate) => existsSync(candidate))
|
|
51
|
+
if (!file) return null
|
|
52
|
+
const vite = await importVite(root)
|
|
53
|
+
if (!vite) return null
|
|
54
|
+
const loaded = await vite.loadConfigFromFile({ command: 'serve', mode: 'development' }, file, root, 'silent')
|
|
55
|
+
const plugins = await flatPlugins(loaded?.config?.plugins ?? [])
|
|
56
|
+
const plugin = plugins.find((entry) => entry?.name === 'seji' && entry.api?.componentGroups)
|
|
57
|
+
return plugin ? plugin.api.componentGroups : null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The scanned catalog (DesignComponent[]) for the project, or undefined when no groups are
|
|
62
|
+
* configured anywhere (then the component operations fall back to registered pages).
|
|
63
|
+
*/
|
|
64
|
+
export async function loadComponentCatalog(root, { configFile } = {}) {
|
|
65
|
+
let groups = null
|
|
66
|
+
try {
|
|
67
|
+
groups = await viteComponentGroups(root, configFile)
|
|
68
|
+
} catch {
|
|
69
|
+
groups = null
|
|
70
|
+
}
|
|
71
|
+
if (!groups) {
|
|
72
|
+
const { loadSurfaceConfig } = await import('./dev.mjs')
|
|
73
|
+
groups = loadSurfaceConfig(root).componentGroups ?? null
|
|
74
|
+
}
|
|
75
|
+
if (!Array.isArray(groups) || !groups.length) return undefined
|
|
76
|
+
const scanned = await scanComponentGroups(root, groups)
|
|
77
|
+
return scanned.flatMap((group) => group.components)
|
|
78
|
+
}
|