@shware/workflow-ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +180 -2
- package/dist/assets/iphone-17-pro-DzaacWSl.png +0 -0
- package/dist/assets/pixel-10-pro-back-7MDj1_lz.webp +0 -0
- package/dist/assets/pixel-10-pro-mask-Bi1deQ9Y.webp +0 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +673 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/config.d.mts +247 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +27 -0
- package/dist/config.mjs.map +1 -0
- package/dist/index.d.mts +451 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2722 -0
- package/dist/index.mjs.map +1 -0
- package/dist/postgres.d.mts +34 -0
- package/dist/postgres.d.mts.map +1 -0
- package/dist/postgres.mjs +313 -0
- package/dist/postgres.mjs.map +1 -0
- package/package.json +93 -3
- package/src/app/assets/devices/iphone-17-pro.png +0 -0
- package/src/app/assets/devices/pixel-10-pro-back.webp +0 -0
- package/src/app/assets/devices/pixel-10-pro-mask.webp +0 -0
- package/src/app/assets/flags/AC.svg +1 -0
- package/src/app/assets/flags/AD.svg +1 -0
- package/src/app/assets/flags/AE.svg +1 -0
- package/src/app/assets/flags/AF.svg +1 -0
- package/src/app/assets/flags/AG.svg +1 -0
- package/src/app/assets/flags/AI.svg +1 -0
- package/src/app/assets/flags/AL.svg +1 -0
- package/src/app/assets/flags/AM.svg +1 -0
- package/src/app/assets/flags/AO.svg +1 -0
- package/src/app/assets/flags/AQ.svg +1 -0
- package/src/app/assets/flags/AR.svg +1 -0
- package/src/app/assets/flags/AS.svg +1 -0
- package/src/app/assets/flags/AT.svg +1 -0
- package/src/app/assets/flags/AU.svg +1 -0
- package/src/app/assets/flags/AW.svg +1 -0
- package/src/app/assets/flags/AX.svg +1 -0
- package/src/app/assets/flags/AZ.svg +1 -0
- package/src/app/assets/flags/BA.svg +1 -0
- package/src/app/assets/flags/BB.svg +1 -0
- package/src/app/assets/flags/BD.svg +1 -0
- package/src/app/assets/flags/BE.svg +1 -0
- package/src/app/assets/flags/BF.svg +1 -0
- package/src/app/assets/flags/BG.svg +1 -0
- package/src/app/assets/flags/BH.svg +1 -0
- package/src/app/assets/flags/BI.svg +1 -0
- package/src/app/assets/flags/BJ.svg +1 -0
- package/src/app/assets/flags/BL.svg +1 -0
- package/src/app/assets/flags/BM.svg +1 -0
- package/src/app/assets/flags/BN.svg +1 -0
- package/src/app/assets/flags/BO.svg +1 -0
- package/src/app/assets/flags/BQ-BO.svg +1 -0
- package/src/app/assets/flags/BQ-SA.svg +1 -0
- package/src/app/assets/flags/BQ-SE.svg +1 -0
- package/src/app/assets/flags/BQ.svg +1 -0
- package/src/app/assets/flags/BR.svg +1 -0
- package/src/app/assets/flags/BS.svg +1 -0
- package/src/app/assets/flags/BT.svg +1 -0
- package/src/app/assets/flags/BV.svg +1 -0
- package/src/app/assets/flags/BW.svg +1 -0
- package/src/app/assets/flags/BY.svg +1 -0
- package/src/app/assets/flags/BZ.svg +1 -0
- package/src/app/assets/flags/CA.svg +1 -0
- package/src/app/assets/flags/CC.svg +1 -0
- package/src/app/assets/flags/CD.svg +1 -0
- package/src/app/assets/flags/CF.svg +1 -0
- package/src/app/assets/flags/CG.svg +1 -0
- package/src/app/assets/flags/CH.svg +1 -0
- package/src/app/assets/flags/CI.svg +1 -0
- package/src/app/assets/flags/CK.svg +1 -0
- package/src/app/assets/flags/CL.svg +1 -0
- package/src/app/assets/flags/CM.svg +1 -0
- package/src/app/assets/flags/CN.svg +1 -0
- package/src/app/assets/flags/CO.svg +1 -0
- package/src/app/assets/flags/CR.svg +1 -0
- package/src/app/assets/flags/CU.svg +1 -0
- package/src/app/assets/flags/CV.svg +1 -0
- package/src/app/assets/flags/CW.svg +1 -0
- package/src/app/assets/flags/CX.svg +1 -0
- package/src/app/assets/flags/CY.svg +1 -0
- package/src/app/assets/flags/CZ.svg +1 -0
- package/src/app/assets/flags/DE.svg +1 -0
- package/src/app/assets/flags/DJ.svg +1 -0
- package/src/app/assets/flags/DK.svg +1 -0
- package/src/app/assets/flags/DM.svg +1 -0
- package/src/app/assets/flags/DO.svg +1 -0
- package/src/app/assets/flags/DZ.svg +1 -0
- package/src/app/assets/flags/EC.svg +1 -0
- package/src/app/assets/flags/EE.svg +1 -0
- package/src/app/assets/flags/EG.svg +1 -0
- package/src/app/assets/flags/EH.svg +1 -0
- package/src/app/assets/flags/ER.svg +1 -0
- package/src/app/assets/flags/ES-CT.svg +1 -0
- package/src/app/assets/flags/ES.svg +1 -0
- package/src/app/assets/flags/ET.svg +1 -0
- package/src/app/assets/flags/EU.svg +1 -0
- package/src/app/assets/flags/FI.svg +1 -0
- package/src/app/assets/flags/FJ.svg +1 -0
- package/src/app/assets/flags/FK.svg +1 -0
- package/src/app/assets/flags/FM.svg +1 -0
- package/src/app/assets/flags/FO.svg +1 -0
- package/src/app/assets/flags/FR.svg +1 -0
- package/src/app/assets/flags/GA.svg +1 -0
- package/src/app/assets/flags/GB-ENG.svg +1 -0
- package/src/app/assets/flags/GB-NIR.svg +1 -0
- package/src/app/assets/flags/GB-SCT.svg +1 -0
- package/src/app/assets/flags/GB-WLS.svg +1 -0
- package/src/app/assets/flags/GB.svg +1 -0
- package/src/app/assets/flags/GD.svg +1 -0
- package/src/app/assets/flags/GE.svg +1 -0
- package/src/app/assets/flags/GF.svg +1 -0
- package/src/app/assets/flags/GG.svg +1 -0
- package/src/app/assets/flags/GH.svg +1 -0
- package/src/app/assets/flags/GI.svg +1 -0
- package/src/app/assets/flags/GL.svg +1 -0
- package/src/app/assets/flags/GM.svg +1 -0
- package/src/app/assets/flags/GN.svg +1 -0
- package/src/app/assets/flags/GP.svg +1 -0
- package/src/app/assets/flags/GQ.svg +1 -0
- package/src/app/assets/flags/GR.svg +1 -0
- package/src/app/assets/flags/GS.svg +1 -0
- package/src/app/assets/flags/GT.svg +1 -0
- package/src/app/assets/flags/GU.svg +1 -0
- package/src/app/assets/flags/GW.svg +1 -0
- package/src/app/assets/flags/GY.svg +1 -0
- package/src/app/assets/flags/HK.svg +1 -0
- package/src/app/assets/flags/HM.svg +1 -0
- package/src/app/assets/flags/HN.svg +1 -0
- package/src/app/assets/flags/HR.svg +1 -0
- package/src/app/assets/flags/HT.svg +1 -0
- package/src/app/assets/flags/HU.svg +1 -0
- package/src/app/assets/flags/IC.svg +1 -0
- package/src/app/assets/flags/ID.svg +1 -0
- package/src/app/assets/flags/IE.svg +1 -0
- package/src/app/assets/flags/IL.svg +1 -0
- package/src/app/assets/flags/IM.svg +1 -0
- package/src/app/assets/flags/IN.svg +1 -0
- package/src/app/assets/flags/IO.svg +1 -0
- package/src/app/assets/flags/IQ.svg +1 -0
- package/src/app/assets/flags/IR.svg +1 -0
- package/src/app/assets/flags/IS.svg +1 -0
- package/src/app/assets/flags/IT.svg +1 -0
- package/src/app/assets/flags/JE.svg +1 -0
- package/src/app/assets/flags/JM.svg +1 -0
- package/src/app/assets/flags/JO.svg +1 -0
- package/src/app/assets/flags/JP.svg +1 -0
- package/src/app/assets/flags/KE.svg +1 -0
- package/src/app/assets/flags/KG.svg +1 -0
- package/src/app/assets/flags/KH.svg +1 -0
- package/src/app/assets/flags/KI.svg +1 -0
- package/src/app/assets/flags/KM.svg +1 -0
- package/src/app/assets/flags/KN.svg +1 -0
- package/src/app/assets/flags/KP.svg +1 -0
- package/src/app/assets/flags/KR.svg +1 -0
- package/src/app/assets/flags/KW.svg +1 -0
- package/src/app/assets/flags/KY.svg +1 -0
- package/src/app/assets/flags/KZ.svg +1 -0
- package/src/app/assets/flags/LA.svg +1 -0
- package/src/app/assets/flags/LB.svg +1 -0
- package/src/app/assets/flags/LC.svg +1 -0
- package/src/app/assets/flags/LI.svg +1 -0
- package/src/app/assets/flags/LK.svg +1 -0
- package/src/app/assets/flags/LR.svg +1 -0
- package/src/app/assets/flags/LS.svg +1 -0
- package/src/app/assets/flags/LT.svg +1 -0
- package/src/app/assets/flags/LU.svg +1 -0
- package/src/app/assets/flags/LV.svg +1 -0
- package/src/app/assets/flags/LY.svg +1 -0
- package/src/app/assets/flags/MA.svg +1 -0
- package/src/app/assets/flags/MC.svg +1 -0
- package/src/app/assets/flags/MD.svg +1 -0
- package/src/app/assets/flags/ME.svg +1 -0
- package/src/app/assets/flags/MF.svg +1 -0
- package/src/app/assets/flags/MG.svg +1 -0
- package/src/app/assets/flags/MH.svg +1 -0
- package/src/app/assets/flags/MK.svg +1 -0
- package/src/app/assets/flags/ML.svg +1 -0
- package/src/app/assets/flags/MM.svg +1 -0
- package/src/app/assets/flags/MN.svg +1 -0
- package/src/app/assets/flags/MO.svg +1 -0
- package/src/app/assets/flags/MP.svg +1 -0
- package/src/app/assets/flags/MQ.svg +1 -0
- package/src/app/assets/flags/MR.svg +1 -0
- package/src/app/assets/flags/MS.svg +1 -0
- package/src/app/assets/flags/MT.svg +1 -0
- package/src/app/assets/flags/MU.svg +1 -0
- package/src/app/assets/flags/MV.svg +1 -0
- package/src/app/assets/flags/MW.svg +1 -0
- package/src/app/assets/flags/MX.svg +1 -0
- package/src/app/assets/flags/MY.svg +1 -0
- package/src/app/assets/flags/MZ.svg +1 -0
- package/src/app/assets/flags/NA.svg +1 -0
- package/src/app/assets/flags/NC.svg +1 -0
- package/src/app/assets/flags/NE.svg +1 -0
- package/src/app/assets/flags/NF.svg +1 -0
- package/src/app/assets/flags/NG.svg +1 -0
- package/src/app/assets/flags/NI.svg +1 -0
- package/src/app/assets/flags/NL.svg +1 -0
- package/src/app/assets/flags/NO.svg +1 -0
- package/src/app/assets/flags/NP.svg +1 -0
- package/src/app/assets/flags/NR.svg +1 -0
- package/src/app/assets/flags/NU.svg +1 -0
- package/src/app/assets/flags/NZ.svg +1 -0
- package/src/app/assets/flags/OM.svg +1 -0
- package/src/app/assets/flags/PA.svg +1 -0
- package/src/app/assets/flags/PE.svg +1 -0
- package/src/app/assets/flags/PF.svg +1 -0
- package/src/app/assets/flags/PG.svg +1 -0
- package/src/app/assets/flags/PH.svg +1 -0
- package/src/app/assets/flags/PK.svg +1 -0
- package/src/app/assets/flags/PL.svg +1 -0
- package/src/app/assets/flags/PM.svg +1 -0
- package/src/app/assets/flags/PN.svg +1 -0
- package/src/app/assets/flags/PR.svg +1 -0
- package/src/app/assets/flags/PS.svg +1 -0
- package/src/app/assets/flags/PT.svg +1 -0
- package/src/app/assets/flags/PW.svg +1 -0
- package/src/app/assets/flags/PY.svg +1 -0
- package/src/app/assets/flags/QA.svg +1 -0
- package/src/app/assets/flags/RE.svg +1 -0
- package/src/app/assets/flags/README.md +6 -0
- package/src/app/assets/flags/RO.svg +1 -0
- package/src/app/assets/flags/RS.svg +1 -0
- package/src/app/assets/flags/RU.svg +1 -0
- package/src/app/assets/flags/RW.svg +1 -0
- package/src/app/assets/flags/SA.svg +1 -0
- package/src/app/assets/flags/SB.svg +1 -0
- package/src/app/assets/flags/SC.svg +1 -0
- package/src/app/assets/flags/SD.svg +1 -0
- package/src/app/assets/flags/SE.svg +1 -0
- package/src/app/assets/flags/SG.svg +1 -0
- package/src/app/assets/flags/SH.svg +1 -0
- package/src/app/assets/flags/SI.svg +1 -0
- package/src/app/assets/flags/SJ.svg +1 -0
- package/src/app/assets/flags/SK.svg +1 -0
- package/src/app/assets/flags/SL.svg +1 -0
- package/src/app/assets/flags/SM.svg +1 -0
- package/src/app/assets/flags/SN.svg +1 -0
- package/src/app/assets/flags/SO.svg +1 -0
- package/src/app/assets/flags/SR.svg +1 -0
- package/src/app/assets/flags/SS.svg +1 -0
- package/src/app/assets/flags/ST.svg +1 -0
- package/src/app/assets/flags/SV.svg +1 -0
- package/src/app/assets/flags/SX.svg +1 -0
- package/src/app/assets/flags/SY.svg +1 -0
- package/src/app/assets/flags/SZ.svg +1 -0
- package/src/app/assets/flags/TA.svg +1 -0
- package/src/app/assets/flags/TC.svg +1 -0
- package/src/app/assets/flags/TD.svg +1 -0
- package/src/app/assets/flags/TF.svg +1 -0
- package/src/app/assets/flags/TG.svg +1 -0
- package/src/app/assets/flags/TH.svg +1 -0
- package/src/app/assets/flags/TJ.svg +1 -0
- package/src/app/assets/flags/TK.svg +1 -0
- package/src/app/assets/flags/TL.svg +1 -0
- package/src/app/assets/flags/TM.svg +1 -0
- package/src/app/assets/flags/TN.svg +1 -0
- package/src/app/assets/flags/TO.svg +1 -0
- package/src/app/assets/flags/TR.svg +1 -0
- package/src/app/assets/flags/TT.svg +1 -0
- package/src/app/assets/flags/TV.svg +1 -0
- package/src/app/assets/flags/TW.svg +1 -0
- package/src/app/assets/flags/TZ.svg +1 -0
- package/src/app/assets/flags/UA.svg +1 -0
- package/src/app/assets/flags/UG.svg +1 -0
- package/src/app/assets/flags/UM.svg +1 -0
- package/src/app/assets/flags/US.svg +1 -0
- package/src/app/assets/flags/UY.svg +1 -0
- package/src/app/assets/flags/UZ.svg +1 -0
- package/src/app/assets/flags/VA.svg +1 -0
- package/src/app/assets/flags/VC.svg +1 -0
- package/src/app/assets/flags/VE.svg +1 -0
- package/src/app/assets/flags/VG.svg +1 -0
- package/src/app/assets/flags/VI.svg +1 -0
- package/src/app/assets/flags/VN.svg +1 -0
- package/src/app/assets/flags/VU.svg +1 -0
- package/src/app/assets/flags/WF.svg +1 -0
- package/src/app/assets/flags/WS.svg +1 -0
- package/src/app/assets/flags/XA.svg +1 -0
- package/src/app/assets/flags/XC.svg +1 -0
- package/src/app/assets/flags/XK.svg +1 -0
- package/src/app/assets/flags/XO.svg +1 -0
- package/src/app/assets/flags/YE.svg +1 -0
- package/src/app/assets/flags/YT.svg +1 -0
- package/src/app/assets/flags/ZA.svg +1 -0
- package/src/app/assets/flags/ZM.svg +1 -0
- package/src/app/assets/flags/ZW.svg +1 -0
- package/src/app/email-preview.ts +46 -0
- package/src/app/index.css +203 -0
- package/src/app/index.html +12 -0
- package/src/app/integrations/i18n/react-i18next.d.ts +11 -0
- package/src/app/integrations/i18n/root-provider.tsx +62 -0
- package/src/app/integrations/tanstack-query/devtools.tsx +6 -0
- package/src/app/integrations/tanstack-query/root-provider.tsx +37 -0
- package/src/app/integrations/theme/root-provider.tsx +75 -0
- package/src/app/integrations/toast/toast-provider.tsx +46 -0
- package/src/app/locales/en-US/common.ts +268 -0
- package/src/app/locales/zh-CN/common.ts +263 -0
- package/src/app/main.tsx +40 -0
- package/src/app/page-chrome.tsx +79 -0
- package/src/app/router.tsx +40 -0
- package/src/app/routes/__root.tsx +293 -0
- package/src/app/routes/emails.tsx +199 -0
- package/src/app/routes/home.tsx +87 -0
- package/src/app/routes/index.ts +19 -0
- package/src/app/routes/metrics.tsx +541 -0
- package/src/app/routes/segment-overview.tsx +211 -0
- package/src/app/routes/segments.tsx +236 -0
- package/src/app/routes/settings.tsx +90 -0
- package/src/app/routes/workflows.tsx +348 -0
- package/src/app/studio.ts +16 -0
- package/src/app/svg.d.ts +17 -0
- package/src/app/virtual-config.d.ts +6 -0
- package/src/cli.ts +110 -0
- package/src/components/avatar.tsx +57 -0
- package/src/components/breadcrumb.tsx +49 -0
- package/src/components/button/index.tsx +86 -0
- package/src/components/channel-icon.ts +39 -0
- package/src/components/chat-markup.tsx +109 -0
- package/src/components/corner-shape.ts +13 -0
- package/src/components/date-range.tsx +181 -0
- package/src/components/discord-preview.tsx +165 -0
- package/src/components/dropdown/index.tsx +172 -0
- package/src/components/email-defaults.tsx +40 -0
- package/src/components/email-list.tsx +149 -0
- package/src/components/email-thumbnail.tsx +123 -0
- package/src/components/flag.tsx +40 -0
- package/src/components/input/index.tsx +40 -0
- package/src/components/input/search-input.tsx +24 -0
- package/src/components/layout.ts +403 -0
- package/src/components/menu/index.tsx +118 -0
- package/src/components/metric-card.tsx +321 -0
- package/src/components/modal/index.tsx +70 -0
- package/src/components/nav-drawer.tsx +84 -0
- package/src/components/node-inspector.tsx +242 -0
- package/src/components/profile-drawer.tsx +331 -0
- package/src/components/push-preview.tsx +470 -0
- package/src/components/push-thumbnail.tsx +78 -0
- package/src/components/segment-list.tsx +184 -0
- package/src/components/select/index.tsx +70 -0
- package/src/components/series-chart.tsx +120 -0
- package/src/components/slack-preview.tsx +223 -0
- package/src/components/sparkline.tsx +58 -0
- package/src/components/tabs/index.tsx +45 -0
- package/src/components/template-refs.ts +110 -0
- package/src/components/templates-page.tsx +601 -0
- package/src/components/textarea/index.tsx +37 -0
- package/src/components/thumbnail-window.tsx +65 -0
- package/src/components/workflow-canvas.tsx +503 -0
- package/src/components/workflow-list.tsx +231 -0
- package/src/config.ts +288 -0
- package/src/generate.ts +56 -0
- package/src/index.ts +35 -0
- package/src/postgres.ts +415 -0
- package/src/server/project.ts +290 -0
- package/src/server.ts +500 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/label.ts +12 -0
- package/src/utils/lookup.ts +11 -0
- package/src/utils/template-content.ts +213 -0
package/src/server.ts
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
6
|
+
import react from '@vitejs/plugin-react';
|
|
7
|
+
import { type Plugin, type ViteDevServer, createServer, searchForWorkspaceRoot } from 'vite';
|
|
8
|
+
import svgr from 'vite-plugin-svgr';
|
|
9
|
+
import {
|
|
10
|
+
STATS_METHODS,
|
|
11
|
+
type StatsMethod,
|
|
12
|
+
loadSnapshot,
|
|
13
|
+
ssrModulesOf,
|
|
14
|
+
virtualModule,
|
|
15
|
+
} from './server/project';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The studio dev server.
|
|
19
|
+
*
|
|
20
|
+
* Rather than shipping a prebuilt SPA and a JSON API, the CLI runs Vite over
|
|
21
|
+
* the app source with the project injected as a virtual module: compiled on
|
|
22
|
+
* the server, the template registries imported by the browser from their own
|
|
23
|
+
* modules. Vite serves our app and the user's react-email components as one
|
|
24
|
+
* graph — HMR on every one of them for free, and email previews render with
|
|
25
|
+
* exactly the component code on disk.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
29
|
+
|
|
30
|
+
/** `src/app` when running from source in the monorepo, the published copy otherwise. */
|
|
31
|
+
function resolveAppRoot(): string {
|
|
32
|
+
const candidates = [resolve(packageRoot, 'src/app'), resolve(packageRoot, '../src/app')];
|
|
33
|
+
const found = candidates.find((path) => existsSync(resolve(path, 'index.html')));
|
|
34
|
+
if (!found) throw new Error('workflow-ui: could not locate the app root');
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const CONFIG_CANDIDATES = [
|
|
39
|
+
'workflow.config.ts',
|
|
40
|
+
'workflow.config.tsx',
|
|
41
|
+
'workflow.config.js',
|
|
42
|
+
'workflow.config.mjs',
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The project file — `export default defineConfig({...})` from
|
|
47
|
+
* `@shware/workflow`. Required: it is the only place the studio reads
|
|
48
|
+
* definitions from.
|
|
49
|
+
*/
|
|
50
|
+
export function findConfig(cwd: string, explicit?: string): string {
|
|
51
|
+
if (explicit !== undefined) {
|
|
52
|
+
const path = resolve(cwd, explicit);
|
|
53
|
+
if (!existsSync(path)) throw new Error(`workflow-ui: config not found at ${path}`);
|
|
54
|
+
return path;
|
|
55
|
+
}
|
|
56
|
+
const found = CONFIG_CANDIDATES.map((name) => resolve(cwd, name)).find((path) =>
|
|
57
|
+
existsSync(path)
|
|
58
|
+
);
|
|
59
|
+
if (found === undefined) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`workflow-ui: no workflow.config.ts in ${cwd}.\n` +
|
|
62
|
+
`Export defineConfig({ workflows, templates }) from '@shware/workflow' there, or pass --config <path>.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const STATS_CANDIDATES = ['workflow.stats.ts', 'workflow.stats.tsx', 'workflow.stats.js'];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The studio's optional stats source, apart from the project: an explicit
|
|
72
|
+
* path must exist; otherwise `workflow.stats.ts` beside the config, if any.
|
|
73
|
+
*/
|
|
74
|
+
export function findStats(cwd: string, explicit?: string): string | undefined {
|
|
75
|
+
if (explicit !== undefined) {
|
|
76
|
+
const path = resolve(cwd, explicit);
|
|
77
|
+
if (!existsSync(path)) throw new Error(`workflow-ui: stats source not found at ${path}`);
|
|
78
|
+
return path;
|
|
79
|
+
}
|
|
80
|
+
return STATS_CANDIDATES.map((name) => resolve(cwd, name)).find((path) => existsSync(path));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* ---------------------------------- Project --------------------------------- */
|
|
84
|
+
|
|
85
|
+
const VIRTUAL_ID = 'virtual:workflow-config';
|
|
86
|
+
const RESOLVED_ID = `\0${VIRTUAL_ID}`;
|
|
87
|
+
|
|
88
|
+
const NODE_MODULES = /[/\\]node_modules[/\\]/;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Every file the last project load evaluated: the config and, transitively,
|
|
92
|
+
* whatever it imported in Vite's SSR module graph — wherever those files live.
|
|
93
|
+
* Dependencies under node_modules are left out: they change with an install,
|
|
94
|
+
* not an edit.
|
|
95
|
+
*/
|
|
96
|
+
function evaluatedFiles(dev: ViteDevServer, configPath: string): Set<string> {
|
|
97
|
+
const files = new Set<string>([resolve(configPath)]);
|
|
98
|
+
const graph = dev.environments.ssr.moduleGraph;
|
|
99
|
+
const queue = [...(graph.getModulesByFile(configPath) ?? [])];
|
|
100
|
+
const seen = new Set(queue);
|
|
101
|
+
while (queue.length > 0) {
|
|
102
|
+
const mod = queue.pop();
|
|
103
|
+
if (mod === undefined) continue;
|
|
104
|
+
if (mod.file !== null) {
|
|
105
|
+
if (NODE_MODULES.test(mod.file)) continue;
|
|
106
|
+
files.add(resolve(mod.file));
|
|
107
|
+
}
|
|
108
|
+
for (const imported of mod.importedModules) {
|
|
109
|
+
if (!seen.has(imported)) {
|
|
110
|
+
seen.add(imported);
|
|
111
|
+
queue.push(imported);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return files;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Serve `virtual:workflow-config` and keep it current.
|
|
120
|
+
*
|
|
121
|
+
* The project is evaluated on the server (ssrLoadModule) and compiled there;
|
|
122
|
+
* see server/project.ts for what reaches the browser. After every load the
|
|
123
|
+
* plugin records the files that load evaluated — the config and everything it
|
|
124
|
+
* imported, inside the working directory or not (`--config ../shared/...`,
|
|
125
|
+
* a contract in a sibling package) — and watches them. A change to any of
|
|
126
|
+
* them drops those evaluated modules and pushes a fresh snapshot over HMR, so
|
|
127
|
+
* adding a workflow or a template to the registration list shows up without a
|
|
128
|
+
* reload. Template components also update through their own client-side HMR,
|
|
129
|
+
* as any module does.
|
|
130
|
+
*/
|
|
131
|
+
/** The stats source's default export, evaluated on the dev server. */
|
|
132
|
+
async function loadStats(
|
|
133
|
+
dev: ViteDevServer,
|
|
134
|
+
statsPath: string
|
|
135
|
+
): Promise<Partial<Record<StatsMethod, (...args: unknown[]) => unknown>>> {
|
|
136
|
+
const mod = await dev.ssrLoadModule(statsPath);
|
|
137
|
+
const stats: unknown = mod.default;
|
|
138
|
+
if (typeof stats !== 'object' || stats === null) {
|
|
139
|
+
throw new Error(`workflow-ui: ${statsPath} must default-export defineStats({...})`);
|
|
140
|
+
}
|
|
141
|
+
return stats;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function readBody(req: IncomingMessage): Promise<string> {
|
|
145
|
+
return new Promise((resolveBody, reject) => {
|
|
146
|
+
let body = '';
|
|
147
|
+
req.setEncoding('utf8');
|
|
148
|
+
req.on('data', (chunk: string) => {
|
|
149
|
+
body += chunk;
|
|
150
|
+
});
|
|
151
|
+
req.on('end', () => resolveBody(body));
|
|
152
|
+
req.on('error', reject);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function projectPlugin(configPath: string, statsPath: string | undefined): Plugin {
|
|
157
|
+
let server: ViteDevServer | undefined;
|
|
158
|
+
let evaluated = new Set<string>([resolve(configPath)]);
|
|
159
|
+
return {
|
|
160
|
+
name: 'workflow-ui:project',
|
|
161
|
+
resolveId: (id) => (id === VIRTUAL_ID ? RESOLVED_ID : null),
|
|
162
|
+
async load(id) {
|
|
163
|
+
if (id !== RESOLVED_ID || server === undefined) return null;
|
|
164
|
+
const dev = server;
|
|
165
|
+
const snapshot = await loadSnapshot({
|
|
166
|
+
configPath,
|
|
167
|
+
load: (file) => dev.ssrLoadModule(file),
|
|
168
|
+
modules: ssrModulesOf(dev),
|
|
169
|
+
});
|
|
170
|
+
evaluated = evaluatedFiles(dev, configPath);
|
|
171
|
+
let methods: StatsMethod[] | undefined;
|
|
172
|
+
if (statsPath !== undefined) {
|
|
173
|
+
const stats = await loadStats(dev, statsPath);
|
|
174
|
+
methods = STATS_METHODS.filter((method) => typeof stats[method] === 'function');
|
|
175
|
+
for (const file of evaluatedFiles(dev, statsPath)) evaluated.add(file);
|
|
176
|
+
}
|
|
177
|
+
dev.watcher.add([...evaluated]);
|
|
178
|
+
return virtualModule(snapshot, methods);
|
|
179
|
+
},
|
|
180
|
+
configureServer(dev) {
|
|
181
|
+
server = dev;
|
|
182
|
+
/* Positions the DSL captures while the project is evaluated are then lines on disk. */
|
|
183
|
+
process.setSourceMapsEnabled(true);
|
|
184
|
+
for (const file of [configPath, statsPath]) {
|
|
185
|
+
if (file !== undefined) dev.watcher.add(file);
|
|
186
|
+
}
|
|
187
|
+
const refresh = (file: string): void => {
|
|
188
|
+
if (!evaluated.has(resolve(file))) return;
|
|
189
|
+
const virtual = dev.moduleGraph.getModuleById(RESOLVED_ID);
|
|
190
|
+
if (virtual === undefined) return;
|
|
191
|
+
/*
|
|
192
|
+
* ssrLoadModule keeps an evaluated module until it is invalidated, and
|
|
193
|
+
* the config caches everything it imported — so every evaluated module
|
|
194
|
+
* goes, not just the file that changed.
|
|
195
|
+
*/
|
|
196
|
+
for (const path of evaluated) {
|
|
197
|
+
for (const mod of dev.moduleGraph.getModulesByFile(path) ?? []) {
|
|
198
|
+
dev.moduleGraph.invalidateModule(mod);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
dev.moduleGraph.invalidateModule(virtual);
|
|
202
|
+
void dev.reloadModule(virtual);
|
|
203
|
+
};
|
|
204
|
+
dev.watcher.on('change', refresh);
|
|
205
|
+
dev.watcher.on('add', refresh);
|
|
206
|
+
dev.watcher.on('unlink', refresh);
|
|
207
|
+
|
|
208
|
+
/*
|
|
209
|
+
* The stats source runs here, not in the browser: it reads the project's
|
|
210
|
+
* own database or API, with credentials the page must never hold. The
|
|
211
|
+
* page calls one method per request — the arguments as a JSON array, the
|
|
212
|
+
* answer as JSON — and only the StatsSource method names are served.
|
|
213
|
+
*/
|
|
214
|
+
dev.middlewares.use('/__studio/stats/', (req, res) => {
|
|
215
|
+
const sendJson = (status: number, body: unknown): void => {
|
|
216
|
+
res.statusCode = status;
|
|
217
|
+
res.setHeader('content-type', 'application/json');
|
|
218
|
+
res.end(JSON.stringify(body));
|
|
219
|
+
};
|
|
220
|
+
void (async () => {
|
|
221
|
+
if (req.method !== 'POST') {
|
|
222
|
+
res.setHeader('allow', 'POST');
|
|
223
|
+
sendJson(405, { error: 'stats calls are POST' });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const rejection = studioRequestRejection(req);
|
|
227
|
+
if (rejection !== undefined) {
|
|
228
|
+
sendJson(403, { error: rejection });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const method = (req.url ?? '').replace(/^\//, '').split('?')[0] as StatsMethod;
|
|
232
|
+
if (statsPath === undefined || !STATS_METHODS.includes(method)) {
|
|
233
|
+
sendJson(404, { error: `no stats method '${method}'` });
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const args: unknown = JSON.parse((await readBody(req)) || '[]');
|
|
238
|
+
if (!Array.isArray(args)) {
|
|
239
|
+
sendJson(400, { error: 'the body is the arguments, as a JSON array' });
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const fn = (await loadStats(dev, statsPath))[method];
|
|
243
|
+
if (fn === undefined) {
|
|
244
|
+
sendJson(404, { error: `workflow.stats.ts defines no '${method}'` });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
sendJson(200, (await fn(...args)) ?? null);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
dev.config.logger.error(`[workflow-ui] stats ${method} failed: ${String(error)}`);
|
|
250
|
+
sendJson(500, { error: error instanceof Error ? error.message : String(error) });
|
|
251
|
+
}
|
|
252
|
+
})();
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* -------------------------------- Studio API -------------------------------- */
|
|
259
|
+
|
|
260
|
+
/** `Sec-Fetch-Site` values no other site can produce: our own page, or a direct navigation. */
|
|
261
|
+
const OWN_FETCH_SITES = new Set(['same-origin', 'none']);
|
|
262
|
+
|
|
263
|
+
function headerValue(raw: string | string[] | undefined): string | undefined {
|
|
264
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
265
|
+
return value === undefined || value === '' ? undefined : value;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Refuse any request another website could have caused, and say why.
|
|
270
|
+
*
|
|
271
|
+
* The node endpoint reads the developer's source files to answer, so a page
|
|
272
|
+
* they merely *visit* should not be able to probe it. Vite's CORS handling
|
|
273
|
+
* decides who may read a response; this decides whether the request is served
|
|
274
|
+
* at all.
|
|
275
|
+
*
|
|
276
|
+
* - `Sec-Fetch-Site` is attached by the browser and cannot be set from
|
|
277
|
+
* script, so anything but `same-origin` (our page) or `none` (the address
|
|
278
|
+
* bar) is a request some other page caused — including `same-site`, which
|
|
279
|
+
* covers another port on localhost.
|
|
280
|
+
* - `Origin` covers clients that send no fetch metadata: present and not our
|
|
281
|
+
* own host means cross-origin. Absent is allowed on purpose — a same-origin
|
|
282
|
+
* GET and a terminal `curl` both have no Origin at all, and a cross-origin
|
|
283
|
+
* browser request always has one.
|
|
284
|
+
*/
|
|
285
|
+
export function studioRequestRejection(req: Pick<IncomingMessage, 'headers'>): string | undefined {
|
|
286
|
+
const site = headerValue(req.headers['sec-fetch-site']);
|
|
287
|
+
if (site !== undefined && !OWN_FETCH_SITES.has(site)) {
|
|
288
|
+
return `refused: sec-fetch-site is '${site}', so another site caused this request`;
|
|
289
|
+
}
|
|
290
|
+
const origin = headerValue(req.headers.origin);
|
|
291
|
+
if (origin !== undefined) {
|
|
292
|
+
const host = headerValue(req.headers.host);
|
|
293
|
+
let originHost: string | undefined;
|
|
294
|
+
try {
|
|
295
|
+
originHost = new URL(origin).host;
|
|
296
|
+
} catch {
|
|
297
|
+
/* Opaque origins ('null' from a sandboxed frame or file://) never match. */
|
|
298
|
+
originHost = undefined;
|
|
299
|
+
}
|
|
300
|
+
if (host === undefined || originHost?.toLowerCase() !== host.toLowerCase()) {
|
|
301
|
+
return `refused: cross-origin request from ${origin}`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The studio's dev-server API — read-only. The studio views source and never
|
|
309
|
+
* writes it: edits happen in the editor, and Vite's watcher and HMR bring them
|
|
310
|
+
* to the page. The one endpoint resolves a node's captured position to a line
|
|
311
|
+
* on disk for display; everything else under `/__studio` answers 404, so the
|
|
312
|
+
* write routes earlier versions served (`/__studio/envelope`,
|
|
313
|
+
* `/__studio/addresses`, POST `/__studio/node`) are gone rather than hidden.
|
|
314
|
+
*/
|
|
315
|
+
export function studioApiPlugin(cwd: string): Plugin {
|
|
316
|
+
const sendJson = (res: ServerResponse, status: number, body: unknown): void => {
|
|
317
|
+
res.statusCode = status;
|
|
318
|
+
res.setHeader('content-type', 'application/json');
|
|
319
|
+
res.end(JSON.stringify(body));
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
name: 'workflow-ui:studio-api',
|
|
324
|
+
configureServer(server) {
|
|
325
|
+
/*
|
|
326
|
+
* The client sends the position the DSL captured (NodeMetaIR.loc). The
|
|
327
|
+
* project is evaluated on the server with source maps enabled, so that
|
|
328
|
+
* is already a line on disk; this checks the path stays inside the
|
|
329
|
+
* project and answers it relative to it. Navigation only: the panel
|
|
330
|
+
* shows the row when this answers and leaves it out when it does not.
|
|
331
|
+
*/
|
|
332
|
+
server.middlewares.use('/__studio/node', (req, res) => {
|
|
333
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
334
|
+
res.setHeader('allow', 'GET, HEAD');
|
|
335
|
+
sendJson(res, 405, { error: 'the studio is read-only: GET only' });
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const rejection = studioRequestRejection(req);
|
|
339
|
+
if (rejection !== undefined) {
|
|
340
|
+
sendJson(res, 403, { error: rejection });
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const params = new URL(req.url ?? '/', 'http://internal').searchParams;
|
|
344
|
+
const found = sourcePosition(cwd, params.get('file') ?? '', Number(params.get('line')));
|
|
345
|
+
if ('error' in found) {
|
|
346
|
+
sendJson(res, 422, { error: found.error });
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
sendJson(res, 200, { file: relative(cwd, found.file), line: found.line });
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
/* Registered after the routes above, so it only sees what none of them took. */
|
|
353
|
+
server.middlewares.use('/__studio', (_req, res) => {
|
|
354
|
+
sendJson(res, 404, { error: 'no such studio endpoint' });
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
type Located = { file: string; line: number } | { error: string };
|
|
361
|
+
|
|
362
|
+
/** The two `node:path` functions containment needs, so the suite can hand in `path.win32`. */
|
|
363
|
+
interface PathOps {
|
|
364
|
+
isAbsolute: (path: string) => boolean;
|
|
365
|
+
relative: (from: string, to: string) => string;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Is `candidate` `root` itself or something below it?
|
|
370
|
+
*
|
|
371
|
+
* Asked through `relative`, never a string prefix. A prefix test needs a
|
|
372
|
+
* trailing separator (or `/proj-evil` passes for `/proj`), and the separator it
|
|
373
|
+
* appends is the wrong one on Windows, where `resolve()` returns `C:\proj\…`:
|
|
374
|
+
* that mismatch failed every path on Windows, which is how the whole
|
|
375
|
+
* /__studio/node surface came to answer "outside the project" there.
|
|
376
|
+
*/
|
|
377
|
+
export function isInsideDir(
|
|
378
|
+
root: string,
|
|
379
|
+
candidate: string,
|
|
380
|
+
ops: PathOps = { isAbsolute, relative }
|
|
381
|
+
): boolean {
|
|
382
|
+
const rel = ops.relative(root, candidate);
|
|
383
|
+
if (rel === '') return true;
|
|
384
|
+
/* An absolute answer means there is no way down from root — another drive. */
|
|
385
|
+
if (ops.isAbsolute(rel)) return false;
|
|
386
|
+
/* Segment-wise, so a file legitimately named '..rc' is not read as an escape. */
|
|
387
|
+
return rel.split(/[/\\]/)[0] !== '..';
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Keep a path that arrived from the browser inside the project.
|
|
392
|
+
*
|
|
393
|
+
* The scope is `cwd` — the project the studio was started in — and not the
|
|
394
|
+
* workspace root `searchForWorkspaceRoot` walks up to: in a monorepo that root
|
|
395
|
+
* is the whole repo, so a studio started in `apps/marketing` accepted
|
|
396
|
+
* `file=../../packages/billing/src/rates.ts` and read it.
|
|
397
|
+
*/
|
|
398
|
+
export function isInsideProject(cwd: string, candidate: string): boolean {
|
|
399
|
+
const root = resolve(cwd);
|
|
400
|
+
const path = resolve(candidate);
|
|
401
|
+
if (!isInsideDir(root, path)) return false;
|
|
402
|
+
/*
|
|
403
|
+
* Then again on the real paths: a symlink inside the project may point
|
|
404
|
+
* anywhere, and the check above only ever sees the link's own path. A path
|
|
405
|
+
* that does not exist has nothing to resolve — the caller reports that.
|
|
406
|
+
*/
|
|
407
|
+
if (!existsSync(path)) return true;
|
|
408
|
+
return isInsideDir(realpathSync(root), realpathSync(path));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Check a captured position before answering with it.
|
|
413
|
+
*
|
|
414
|
+
* The path is validated against cwd before anything is touched: it arrives
|
|
415
|
+
* from the browser, and an endpoint that follows an arbitrary path is a
|
|
416
|
+
* read-anywhere endpoint.
|
|
417
|
+
*/
|
|
418
|
+
function sourcePosition(cwd: string, rawFile: string, line: number): Located {
|
|
419
|
+
let path = rawFile;
|
|
420
|
+
if (/^https?:\/\//.test(path)) path = new URL(path).pathname;
|
|
421
|
+
const fsPrefix = '/@fs';
|
|
422
|
+
if (path.startsWith(fsPrefix)) path = path.slice(fsPrefix.length);
|
|
423
|
+
path = resolve(cwd, decodeURIComponent(path));
|
|
424
|
+
|
|
425
|
+
if (!isInsideProject(cwd, path)) return { error: 'source file is outside the project' };
|
|
426
|
+
if (!existsSync(path)) return { error: `no such source file: ${path}` };
|
|
427
|
+
if (!Number.isInteger(line) || line < 1) return { error: 'expected a line number' };
|
|
428
|
+
return { file: path, line };
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export interface StartOptions {
|
|
432
|
+
cwd?: string;
|
|
433
|
+
config?: string;
|
|
434
|
+
/** The studio's stats source (default ./workflow.stats.ts, if present). */
|
|
435
|
+
stats?: string;
|
|
436
|
+
port?: number;
|
|
437
|
+
open?: boolean;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export async function startStudio(options: StartOptions = {}): Promise<ViteDevServer> {
|
|
441
|
+
const cwd = options.cwd ?? process.cwd();
|
|
442
|
+
// The config is required (findConfig throws); the stats source is optional.
|
|
443
|
+
// The resolved path is what the plugin loads — resolving again from cwd
|
|
444
|
+
// inside it is what once made --config point at a file it does not name.
|
|
445
|
+
const configPath = findConfig(cwd, options.config);
|
|
446
|
+
const statsPath = findStats(cwd, options.stats);
|
|
447
|
+
const appRoot = resolveAppRoot();
|
|
448
|
+
|
|
449
|
+
const server = await createServer({
|
|
450
|
+
root: appRoot,
|
|
451
|
+
configFile: false,
|
|
452
|
+
envDir: false,
|
|
453
|
+
plugins: [
|
|
454
|
+
react(),
|
|
455
|
+
svgr(),
|
|
456
|
+
tailwindcss(),
|
|
457
|
+
projectPlugin(configPath, statsPath),
|
|
458
|
+
studioApiPlugin(cwd),
|
|
459
|
+
],
|
|
460
|
+
server: {
|
|
461
|
+
port: options.port ?? 4321,
|
|
462
|
+
open: options.open ?? false,
|
|
463
|
+
/*
|
|
464
|
+
* Both workspace roots have to be readable: the user's project (the
|
|
465
|
+
* config and everything it imports) and ours — under pnpm our own
|
|
466
|
+
* dependencies (fonts, css) resolve into a store beside the workspace
|
|
467
|
+
* root rather than anywhere below the app.
|
|
468
|
+
*/
|
|
469
|
+
fs: {
|
|
470
|
+
allow: [
|
|
471
|
+
searchForWorkspaceRoot(cwd),
|
|
472
|
+
/* A config outside cwd brings its own workspace: the registries the browser imports live there. */
|
|
473
|
+
searchForWorkspaceRoot(dirname(configPath)),
|
|
474
|
+
searchForWorkspaceRoot(packageRoot),
|
|
475
|
+
appRoot,
|
|
476
|
+
],
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
// The app and the user's project each have their own react; one copy only
|
|
480
|
+
resolve: { dedupe: ['react', 'react-dom'] },
|
|
481
|
+
/*
|
|
482
|
+
* @react-email/render imports react-dom/server lazily, so the dep scan never
|
|
483
|
+
* sees it: the first email preview made Vite discover it, re-optimize and
|
|
484
|
+
* change the deps hash under a page that still held the old one — the
|
|
485
|
+
* preview then failed with "Failed to fetch dynamically imported module"
|
|
486
|
+
* (a 504 Outdated Optimize Dep) until a reload. Bundling both up front
|
|
487
|
+
* keeps the hash stable from the first request. The project's config is
|
|
488
|
+
* scanned too (never served — only crawled), so its templates'
|
|
489
|
+
* dependencies (@react-email/components, zod, …) are bundled before the
|
|
490
|
+
* first preview rather than discovered by it.
|
|
491
|
+
*/
|
|
492
|
+
optimizeDeps: {
|
|
493
|
+
entries: ['index.html', configPath],
|
|
494
|
+
include: ['@react-email/render', 'react-dom/server'],
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
await server.listen();
|
|
499
|
+
return server;
|
|
500
|
+
}
|
package/src/utils/cn.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to call a code-owned asset in the UI.
|
|
3
|
+
*
|
|
4
|
+
* Keys are wire identity — referenced by name in IR, keyed on by the engine —
|
|
5
|
+
* and nothing anyone should have to read. The label is `meta.name` when set;
|
|
6
|
+
* when it is not, an explicit placeholder, because a blank is easy to miss and
|
|
7
|
+
* "Untitled" is an invitation to name the thing.
|
|
8
|
+
*/
|
|
9
|
+
export function displayName(name: string | undefined, untitled: string): string {
|
|
10
|
+
const trimmed = name?.trim();
|
|
11
|
+
return trimmed !== undefined && trimmed !== '' ? trimmed : untitled;
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read one entry out of a discovered registry (workflows, emails).
|
|
3
|
+
*
|
|
4
|
+
* TypeScript types `record[key]` as always present, but every key the studio
|
|
5
|
+
* looks up comes from outside the type system — a route param, a template ref
|
|
6
|
+
* in the IR — so a miss is ordinary. This states the `| undefined` once, which
|
|
7
|
+
* is what makes the callers' guards real instead of dead code.
|
|
8
|
+
*/
|
|
9
|
+
export function lookup<T>(registry: Record<string, T>, key: string): T | undefined {
|
|
10
|
+
return registry[key];
|
|
11
|
+
}
|