@iota-uz/sdk 0.4.8 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,7 +52,7 @@ applet rpc gen --name <applet-name>
52
52
  applet rpc check --name <applet-name>
53
53
  applet deps check
54
54
  applet check # deps + RPC drift for all applets
55
- applet dev [name] # start dev environment
55
+ applet dev # start dev environment (all configured applets)
56
56
  applet build [name] # build production bundle
57
57
  applet list # list configured applets
58
58
  ```
@@ -66,52 +66,33 @@ applet list # list configured applets
66
66
 
67
67
  The CLI expects a project root where `.applets/config.toml` exists (or, for `applet deps check`, a repo with a `go.mod` for `github.com/iota-uz/iota-sdk` or `github.com/iota-uz/eai`).
68
68
 
69
- Example `.applets/config.toml` with all options documented in comments:
69
+ Minimal `.applets/config.toml` only `base_path` is required per applet:
70
70
 
71
71
  ```toml
72
- # --- Dev (project-level) ---
73
- [dev]
74
- # Backend port for dev manifest. Default: 3200
75
- backend_port = 3200
76
-
77
- # Project-level processes (e.g. air, templ). At least one required.
78
- # Each process: name (required), command (required), args (optional), critical (optional), env (optional).
72
+ # Project-level dev processes
79
73
  [[dev.processes]]
80
74
  name = "air"
81
75
  command = "air"
82
- args = ["-c", ".air.toml"]
83
76
  critical = true
84
- # env = { FOO = "bar" }
85
77
 
86
78
  [[dev.processes]]
87
79
  name = "templ"
88
80
  command = "templ"
89
81
  args = ["generate", "--watch"]
90
82
 
91
- # --- Applets (per-app) ---
92
- # Each applet: base_path (required), module, web, entry (optional; see defaults below).
83
+ # Applets: only base_path is required. Everything else is convention.
93
84
  [applets.bichat]
94
85
  base_path = "/bi-chat"
95
- # module = "modules/bichat" # default: modules/<name>
96
- # web = "modules/bichat/presentation/web" # default: modules/<name>/presentation/web
97
- # entry = "/src/main.tsx" # default: /src/main.tsx
98
-
99
- [applets.bichat.dev]
100
- # Vite dev server port. Default: unique per applet (5173, 5174, …)
101
- vite_port = 5173
102
-
103
- [applets.bichat.rpc]
104
- # Go function name for RPC codegen. Default: "Router"
105
- router_func = "Router"
106
- # If true, the applet module re-exports the RPC contract from the SDK package. Default: false
107
- needs_reexport_shim = false
108
-
109
- # Second applet: only required fields + overrides; rest use defaults
110
- [applets.otherapp]
111
- base_path = "/other"
112
- module = "modules/otherapp"
113
- web = "modules/otherapp/frontend"
114
- # dev.vite_port and rpc.* use defaults (unique port, Router, false)
115
86
  ```
116
87
 
117
- Defaults are applied in sorted applet name order; `vite_port` is made unique when not set to avoid conflicts. Run `applet doctor` to validate config and environment.
88
+ **Convention defaults:**
89
+ - `web` = `modules/<name>/presentation/web`
90
+ - `vite_port` = auto-assigned (5173, 5174, …) by sorted name order
91
+ - RPC router function = `Router` (hardcoded convention)
92
+ - Entry point = `/src/main.tsx` (Vite standard)
93
+
94
+ **Optional overrides:**
95
+ - `web` — custom web directory path (rare)
96
+ - `[applets.<name>.rpc] needs_reexport_shim = true` — for SDK applets that re-export RPC contracts
97
+
98
+ Run `applet doctor` to validate config and environment.
@@ -1,58 +1,34 @@
1
1
  'use strict';
2
2
 
3
- var fs2 = require('fs');
4
3
  var path2 = require('path');
5
4
  var child_process = require('child_process');
6
5
  var crypto = require('crypto');
6
+ var fs = require('fs');
7
7
  var module$1 = require('module');
8
8
  var os = require('os');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
12
- var fs2__default = /*#__PURE__*/_interopDefault(fs2);
13
12
  var path2__default = /*#__PURE__*/_interopDefault(path2);
14
13
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
14
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
15
15
  var os__default = /*#__PURE__*/_interopDefault(os);
16
16
 
17
17
  // ui/src/applet-vite/vite.ts
18
- var APPLET_DEV_MANIFEST = "applet-dev.json";
19
- function readAppletDevManifest(viteDir) {
20
- const dir = viteDir ?? process.cwd();
21
- const filePath = path2__default.default.join(dir, APPLET_DEV_MANIFEST);
22
- try {
23
- const raw = fs2__default.default.readFileSync(filePath, "utf-8");
24
- const data = JSON.parse(raw);
25
- if (typeof data.basePath === "string" && typeof data.assetsBase === "string" && typeof data.vitePort === "number" && typeof data.backendUrl === "string") {
26
- return data;
27
- }
28
- } catch {
29
- }
30
- return null;
31
- }
32
18
  var DEFAULT_DEDUPE = ["react", "react-dom", "react-router-dom", "react-is"];
33
- function getAppletAssetsBase(viteDir, manifest) {
34
- const resolved = manifest ?? readAppletDevManifest(viteDir);
35
- if (resolved) {
36
- const base2 = resolved.assetsBase;
37
- return base2.endsWith("/") ? base2 : base2 + "/";
38
- }
39
- const base = process.env.APPLET_ASSETS_BASE ?? "";
40
- return base.endsWith("/") ? base : base ? base + "/" : "/";
19
+ function getAppletAssetsBase(basePath) {
20
+ const base = process.env.APPLET_ASSETS_BASE ?? basePath + "/assets/";
21
+ return base.endsWith("/") ? base : base + "/";
41
22
  }
42
- function getAppletVitePort(defaultPort = 5173, viteDir, manifest) {
43
- const resolved = manifest ?? readAppletDevManifest(viteDir);
44
- if (resolved) return resolved.vitePort;
23
+ function getAppletVitePort(defaultPort = 5173) {
45
24
  const p = process.env.APPLET_VITE_PORT;
46
25
  if (p === void 0 || p === "") return defaultPort;
47
26
  const n = Number(p);
48
27
  return Number.isFinite(n) ? n : defaultPort;
49
28
  }
50
29
  function createAppletViteConfig(opts) {
51
- const manifest = readAppletDevManifest(opts.viteConfigDir);
52
- const base = getAppletAssetsBase(opts.viteConfigDir, manifest);
53
- const port = getAppletVitePort(5173, opts.viteConfigDir, manifest);
54
- const basePath = manifest?.basePath ?? opts.basePath;
55
- const backendUrl = manifest?.backendUrl ?? opts.backendUrl;
30
+ const base = getAppletAssetsBase(opts.basePath);
31
+ const port = getAppletVitePort(5173);
56
32
  const config = {
57
33
  base,
58
34
  resolve: {
@@ -66,8 +42,8 @@ function createAppletViteConfig(opts) {
66
42
  port,
67
43
  strictPort: true,
68
44
  proxy: createAppletBackendProxy({
69
- basePath,
70
- backendUrl
45
+ basePath: opts.basePath,
46
+ backendUrl: opts.backendUrl
71
47
  })
72
48
  }
73
49
  };
@@ -161,19 +137,19 @@ function createAppletStylesVirtualModulePlugin(options = {}) {
161
137
  const full = resolvePrependPath(p, root);
162
138
  if (full) {
163
139
  try {
164
- parts.push(fs2__default.default.readFileSync(full, "utf-8"));
140
+ parts.push(fs__default.default.readFileSync(full, "utf-8"));
165
141
  } catch {
166
142
  }
167
143
  }
168
144
  }
169
145
  const inputPath = path2__default.default.join(root, inputCss);
170
146
  let mainCss = null;
171
- if (fs2__default.default.existsSync(inputPath)) {
147
+ if (fs__default.default.existsSync(inputPath)) {
172
148
  const tmpFile = path2__default.default.join(os__default.default.tmpdir(), `applet-styles-${Date.now()}-${crypto__default.default.randomUUID()}.css`);
173
149
  const args = ["-i", inputPath, "-o", tmpFile];
174
150
  if (tailwindConfigPath) {
175
151
  const configPath = path2__default.default.join(root, tailwindConfigPath);
176
- if (fs2__default.default.existsSync(configPath)) {
152
+ if (fs__default.default.existsSync(configPath)) {
177
153
  args.push("-c", configPath);
178
154
  }
179
155
  }
@@ -182,10 +158,10 @@ function createAppletStylesVirtualModulePlugin(options = {}) {
182
158
  cwd: root,
183
159
  stdio: "pipe"
184
160
  });
185
- if (result.status === 0 && fs2__default.default.existsSync(tmpFile)) {
186
- mainCss = fs2__default.default.readFileSync(tmpFile, "utf-8");
161
+ if (result.status === 0 && fs__default.default.existsSync(tmpFile)) {
162
+ mainCss = fs__default.default.readFileSync(tmpFile, "utf-8");
187
163
  try {
188
- fs2__default.default.unlinkSync(tmpFile);
164
+ fs__default.default.unlinkSync(tmpFile);
189
165
  } catch {
190
166
  }
191
167
  }
@@ -193,7 +169,7 @@ function createAppletStylesVirtualModulePlugin(options = {}) {
193
169
  if (mainCss === null) {
194
170
  const fallbackPath = path2__default.default.isAbsolute(outputCssPath) ? outputCssPath : path2__default.default.join(root, outputCssPath);
195
171
  try {
196
- mainCss = fs2__default.default.readFileSync(fallbackPath, "utf-8");
172
+ mainCss = fs__default.default.readFileSync(fallbackPath, "utf-8");
197
173
  } catch {
198
174
  if (process.env.NODE_ENV !== "production") {
199
175
  console.warn(
@@ -226,6 +202,5 @@ exports.createBichatStylesPlugin = createBichatStylesPlugin;
226
202
  exports.createLocalSdkAliases = createLocalSdkAliases;
227
203
  exports.getAppletAssetsBase = getAppletAssetsBase;
228
204
  exports.getAppletVitePort = getAppletVitePort;
229
- exports.readAppletDevManifest = readAppletDevManifest;
230
205
  //# sourceMappingURL=vite.cjs.map
231
206
  //# sourceMappingURL=vite.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],"names":["path","fs","base","createRequire","os","crypto","spawnSync"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,IAAM,mBAAA,GAAsB,iBAAA;AAMrB,SAAS,sBAAsB,OAAA,EAA4C;AAChF,EAAA,MAAM,GAAA,GAAM,OAAA,IAAW,OAAA,CAAQ,GAAA,EAAI;AACnC,EAAA,MAAM,QAAA,GAAWA,sBAAA,CAAK,IAAA,CAAK,GAAA,EAAK,mBAAmB,CAAA;AACnD,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAMC,oBAAA,CAAG,YAAA,CAAa,QAAA,EAAU,OAAO,CAAA;AAC7C,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC3B,IAAA,IAAI,OAAO,IAAA,CAAK,QAAA,KAAa,QAAA,IAAY,OAAO,IAAA,CAAK,UAAA,KAAe,QAAA,IAAY,OAAO,KAAK,QAAA,KAAa,QAAA,IAAY,OAAO,IAAA,CAAK,eAAe,QAAA,EAAU;AACxJ,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,IAAA;AACT;AAEA,IAAM,cAAA,GAAiB,CAAC,OAAA,EAAS,WAAA,EAAa,oBAAoB,UAAU,CAAA;AAOrE,SAAS,mB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AA,KAAa,YAAA,EAAc;AACzC,YAAA,OAAA,CAAQ,IAAA;AAAA,cACN,0DAA0D,YAAY,CAAA,uFAAA;AAAA,aACxE;AAAA,UACF;AACA,UAAA,OAAA,GAAU,EAAA;AAAA,QACZ;AAAA,MACF;AAEA,MAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,MAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAC3B,MAAA,OAAO,CAAA,eAAA,EAAkB,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA,CAAA;AAAA,IAC9C;AAAA,GACF;AACF;AAMO,SAAS,wBAAA,CACd,OAAA,GAAgE,EAAC,EACzD;AACR,EAAA,OAAO,qCAAA,CAAsC;AAAA,IAC3C,GAAG,OAAA;AAAA,IACH,QAAA,EAAU,QAAQ,QAAA,IAAY,eAAA;AAAA,IAC9B,aAAA,EAAe,QAAQ,aAAA,IAAiB,gBAAA;AAAA,IACxC,UAAA,EAAY,CAAC,gCAAgC;AAAA,GAC9C,CAAA;AACH","file":"vite.cjs","sourcesContent":["/**\n * Applet Frontend Kit: Vite config helpers for applets running behind a base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"); overridden by applet-dev.json when present. */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"); overridden by applet-dev.json when present. */\n backendUrl: string\n /** Directory containing applet-dev.json (default: process.cwd()). When set, base/port/proxy use manifest if present. */\n viteConfigDir?: string\n /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\n/** Shape of applet-dev.json written by the Go dev runner (single source of truth when using `just dev <name>`). */\nexport type AppletDevManifest = {\n basePath: string\n assetsBase: string\n vitePort: number\n backendUrl: string\n}\n\nconst APPLET_DEV_MANIFEST = 'applet-dev.json'\n\n/**\n * Reads applet-dev.json from viteDir (default process.cwd()). When using `just dev <name>`, the Go runner writes this file.\n * Returns null if file is missing or invalid (env vars remain the fallback).\n */\nexport function readAppletDevManifest(viteDir?: string): AppletDevManifest | null {\n const dir = viteDir ?? process.cwd()\n const filePath = path.join(dir, APPLET_DEV_MANIFEST)\n try {\n const raw = fs.readFileSync(filePath, 'utf-8')\n const data = JSON.parse(raw) as AppletDevManifest\n if (typeof data.basePath === 'string' && typeof data.assetsBase === 'string' && typeof data.vitePort === 'number' && typeof data.backendUrl === 'string') {\n return data\n }\n } catch {\n // file missing or invalid\n }\n return null\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is']\n\nexport type AppletDevManifestOrNull = AppletDevManifest | null\n\n/**\n * Returns base URL for assets (with trailing slash). Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_ASSETS_BASE env.\n */\nexport function getAppletAssetsBase(viteDir?: string, manifest?: AppletDevManifestOrNull): string {\n const resolved = manifest ?? readAppletDevManifest(viteDir)\n if (resolved) {\n const base = resolved.assetsBase\n return base.endsWith('/') ? base : base + '/'\n }\n const base = process.env.APPLET_ASSETS_BASE ?? ''\n return base.endsWith('/') ? base : base ? base + '/' : '/'\n}\n\n/**\n * Returns dev server port. Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_VITE_PORT env.\n */\nexport function getAppletVitePort(defaultPort = 5173, viteDir?: string, manifest?: AppletDevManifestOrNull): number {\n const resolved = manifest ?? readAppletDevManifest(viteDir)\n if (resolved) return resolved.vitePort\n const p = process.env.APPLET_VITE_PORT\n if (p === undefined || p === '') return defaultPort\n const n = Number(p)\n return Number.isFinite(n) ? n : defaultPort\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n * When applet-dev.json is present (e.g. when using `just dev <name>`), base, port, basePath, and backendUrl come from it.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const manifest = readAppletDevManifest(opts.viteConfigDir)\n const base = getAppletAssetsBase(opts.viteConfigDir, manifest)\n const port = getAppletVitePort(5173, opts.viteConfigDir, manifest)\n const basePath = manifest?.basePath ?? opts.basePath\n const backendUrl = manifest?.backendUrl ?? opts.backendUrl\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),\n sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath,\n backendUrl,\n }),\n },\n }\n if (opts.extend) {\n return mergeConfig(config, opts.extend)\n }\n return config\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '')\n const target = opts.backendUrl.replace(/\\/+$/, '')\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n }\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST)\n const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST\n if (!enabled || !dir) return []\n const sdkDist = path.resolve(dir)\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ]\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve\n const bResolve = b.resolve\n const aServer = a.server\n const bServer = b.server\n const aPlugins = a.plugins\n const bPlugins = b.plugins\n\n const merged: UserConfig = { ...a, ...b }\n\n if (bResolve) {\n const aAlias = aResolve?.alias\n const bAlias = bResolve.alias\n const aIsArray = Array.isArray(aAlias)\n const bIsArray = Array.isArray(bAlias)\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias)\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n }\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer }\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins]\n }\n return merged\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite'\nimport { spawnSync } from 'node:child_process'\nimport crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport { createRequire } from 'node:module'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles'\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'))\n return req.resolve(specifierOrPath)\n } catch {\n return null\n }\n }\n return path.join(root, specifierOrPath)\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css'\n const outputCssPath = options.outputCssPath ?? 'dist/style.css'\n const tailwindConfigPath = options.tailwindConfigPath\n const prependCss = options.prependCss ?? []\n let root = process.cwd()\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) return RESOLVED_ID\n return null\n },\n load(id: string) {\n if (id !== RESOLVED_ID) return null\n\n const parts: string[] = []\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root)\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'))\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss)\n let mainCss: string | null = null\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`)\n const args = ['-i', inputPath, '-o', tmpFile]\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath)\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath)\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n })\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8')\n try {\n fs.unlinkSync(tmpFile)\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath)\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8')\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n )\n }\n mainCss = ''\n }\n }\n\n parts.push(mainCss)\n const css = parts.join('\\n')\n return `export default ${JSON.stringify(css)}`\n },\n }\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n })\n}\n"]}
1
+ {"version":3,"sources":["../../ui/src/applet-vite/vite.ts","../../ui/src/applet-vite/styles-plugin.ts"],"names":["path","createRequire","fs","os","crypto","spawnSync"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,IAAM,cAAA,GAAiB,CAAC,OAAA,EAAS,WAAA,EAAa,oBAAoB,UAAU,CAAA;AAKrE,SAAS,oBAAoB,QAAA,EAA0B;AAC5D,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,GAAA,CAAI,kBAAA,IAAsB,QAAA,GAAW,UAAA;AAC1D,EAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAG,CAAA,GAAI,OAAO,IAAA,GAAO,GAAA;AAC5C;AAKO,SAAS,iBAAA,CAAkB,cAAc,IAAA,EAAc;AAC5D,EAAA,MAAM,CAAA,GAAI,QAAQ,GAAA,CAAI,gBAAA;AACtB,EAAA,IAAI,CAAA,KAAM,MAAA,IAAa,CAAA,KAAM,EAAA,EAAI,OAAO,WAAA;AACxC,EAAA,MAAM,CAAA,GAAI,OAAO,CAAC,CAAA;AAClB,EAAA,OAAO,MAAA,CAAO,QAAA,CAAS,CAAC,CAAA,GAAI,CAAA,GAAI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c,OAAO,CAAA;AAAA,QACjD,CAAA,CAAA,MAAQ;AACN,UAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,YAAA,OAAA,CAAQ,IAAA;AAAA,cACN,0DAA0D,YAAY,CAAA,uFAAA;AAAA,aACxE;AAAA,UACF;AACA,UAAA,OAAA,GAAU,EAAA;AAAA,QACZ;AAAA,MACF;AAEA,MAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,MAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAC3B,MAAA,OAAO,CAAA,eAAA,EAAkB,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA,CAAA;AAAA,IAC9C;AAAA,GACF;AACF;AAMO,SAAS,wBAAA,CACd,OAAA,GAAgE,EAAC,EACzD;AACR,EAAA,OAAO,qCAAA,CAAsC;AAAA,IAC3C,GAAG,OAAA;AAAA,IACH,QAAA,EAAU,QAAQ,QAAA,IAAY,eAAA;AAAA,IAC9B,aAAA,EAAe,QAAQ,aAAA,IAAiB,gBAAA;AAAA,IACxC,UAAA,EAAY,CAAC,gCAAgC;AAAA,GAC9C,CAAA;AACH","file":"vite.cjs","sourcesContent":["/**\n * Applet Frontend Kit: Vite config helpers for applets running behind a base path\n * with dev proxy and optional local SDK aliasing.\n */\nimport type { UserConfig } from 'vite'\nimport path from 'node:path'\n\nexport type AppletViteOptions = {\n /** Applet base path (e.g. \"/admin/ali/chat\" or \"/bi-chat\"). */\n basePath: string\n /** Backend URL for proxy (e.g. \"http://localhost:3200\"). */\n backendUrl: string\n /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */\n enableLocalSdkAliases?: boolean\n /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */\n sdkDistDir?: string\n /** Merge additional Vite config */\n extend?: UserConfig\n}\n\nconst DEFAULT_DEDUPE = ['react', 'react-dom', 'react-router-dom', 'react-is']\n\n/**\n * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.\n */\nexport function getAppletAssetsBase(basePath: string): string {\n const base = process.env.APPLET_ASSETS_BASE ?? basePath + '/assets/'\n return base.endsWith('/') ? base : base + '/'\n}\n\n/**\n * Returns dev server port from APPLET_VITE_PORT env, or the given default.\n */\nexport function getAppletVitePort(defaultPort = 5173): number {\n const p = process.env.APPLET_VITE_PORT\n if (p === undefined || p === '') return defaultPort\n const n = Number(p)\n return Number.isFinite(n) ? n : defaultPort\n}\n\n/**\n * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.\n *\n * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:\n * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).\n * - **plugins**: arrays are concatenated (base plugins first, then extend plugins).\n * - **server**, **base**, **resolve.dedupe** and other scalar/object fields: extend overrides base (Object.assign-style).\n * To fully override the base config, spread first: `defineConfig({ ...createAppletViteConfig(opts), ...yourOverrides })`.\n */\nexport function createAppletViteConfig(opts: AppletViteOptions): UserConfig {\n const base = getAppletAssetsBase(opts.basePath)\n const port = getAppletVitePort(5173)\n const config: UserConfig = {\n base,\n resolve: {\n dedupe: DEFAULT_DEDUPE,\n alias: createLocalSdkAliases({\n enabled: opts.enableLocalSdkAliases ?? Boolean(process.env.IOTA_SDK_DIST),\n sdkDistDir: opts.sdkDistDir ?? process.env.IOTA_SDK_DIST,\n }),\n },\n server: {\n port,\n strictPort: true,\n proxy: createAppletBackendProxy({\n basePath: opts.basePath,\n backendUrl: opts.backendUrl,\n }),\n },\n }\n if (opts.extend) {\n return mergeConfig(config, opts.extend)\n }\n return config\n}\n\n/**\n * Returns proxy entries for applet RPC and stream under basePath.\n * Use as server.proxy in Vite config.\n * Note: /stream is SSE; plain string targets do not set ws or changeOrigin. If WebSocket upgrade or SSE proxying issues arise, configure proxy with ws: true or a custom configure.\n */\nexport function createAppletBackendProxy(opts: {\n basePath: string\n backendUrl: string\n}): Record<string, string> {\n const base = opts.basePath.replace(/\\/+$/, '')\n const target = opts.backendUrl.replace(/\\/+$/, '')\n return {\n [base + '/rpc']: target,\n [base + '/stream']: target,\n }\n}\n\n/**\n * Returns resolve.alias entries to point @iota-uz/sdk and @iota-uz/sdk/bichat to a local dist.\n * Use when IOTA_SDK_DIST is set or sdkDistDir is passed, so the app uses the local SDK build with HMR.\n */\nexport function createLocalSdkAliases(opts?: {\n enabled?: boolean\n sdkDistDir?: string\n}): Array<{ find: string | RegExp; replacement: string }> {\n const enabled = opts?.enabled ?? Boolean(opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST)\n const dir = opts?.sdkDistDir ?? process.env.IOTA_SDK_DIST\n if (!enabled || !dir) return []\n const sdkDist = path.resolve(dir)\n return [\n { find: /^@iota-uz\\/sdk\\/bichat$/, replacement: path.join(sdkDist, 'bichat/index.mjs') },\n { find: /^@iota-uz\\/sdk$/, replacement: path.join(sdkDist, 'index.mjs') },\n ]\n}\n\n/**\n * Merges base config with extend. Start with merged = { ...a, ...b } so no Vite fields from b are dropped.\n * We capture a.resolve, b.resolve, a.server, b.server, a.plugins, b.plugins before the spread so we never\n * read b's values as \"original\" a when merging. resolve.alias: only coerce to array when both sides are\n * actually arrays (concat); otherwise leave Record/object as-is and prefer b's value then a's.\n */\nfunction mergeConfig(a: UserConfig, b: UserConfig): UserConfig {\n const aResolve = a.resolve\n const bResolve = b.resolve\n const aServer = a.server\n const bServer = b.server\n const aPlugins = a.plugins\n const bPlugins = b.plugins\n\n const merged: UserConfig = { ...a, ...b }\n\n if (bResolve) {\n const aAlias = aResolve?.alias\n const bAlias = bResolve.alias\n const aIsArray = Array.isArray(aAlias)\n const bIsArray = Array.isArray(bAlias)\n const alias =\n aIsArray && bIsArray\n ? [...(aAlias as Array<{ find: string | RegExp; replacement: string }>), ...(bAlias as Array<{ find: string | RegExp; replacement: string }>)]\n : (bAlias !== undefined ? bAlias : aResolve?.alias)\n merged.resolve = {\n ...aResolve,\n ...bResolve,\n alias,\n dedupe: bResolve.dedupe ?? merged.resolve?.dedupe ?? aResolve?.dedupe,\n }\n }\n if (bServer) {\n merged.server = { ...aServer, ...bServer }\n }\n if (bPlugins) {\n merged.plugins = [...(aPlugins ?? []), ...bPlugins]\n }\n return merged\n}\n","/**\n * Vite plugin that provides a virtual module exporting the compiled applet CSS string\n * for Shadow DOM injection (defineReactAppletElement({ styles })).\n * Can compile CSS via Tailwind CLI in the plugin or fall back to reading a prebuilt file.\n */\nimport type { Plugin } from 'vite'\nimport { spawnSync } from 'node:child_process'\nimport crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport { createRequire } from 'node:module'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport const VIRTUAL_APPLET_STYLES_ID = 'virtual:applet-styles'\nconst RESOLVED_ID = '\\0' + VIRTUAL_APPLET_STYLES_ID\n\nexport type AppletStylesVirtualModuleOptions = {\n /**\n * Input CSS for Tailwind (e.g. src/index.css). When set, the plugin tries to run Tailwind CLI to compile.\n * Default: \"src/index.css\"\n */\n inputCss?: string\n /**\n * Path to Tailwind config (optional). If not set, CLI uses its default lookup.\n */\n tailwindConfigPath?: string\n /**\n * Path to the compiled CSS file when not using Tailwind CLI (fallback), or when Tailwind is not available.\n * Default: \"dist/style.css\"\n */\n outputCssPath?: string\n /**\n * CSS to prepend: package specifiers (e.g. \"@iota-uz/sdk/bichat/styles.css\") or paths relative to project root.\n * Specifiers are resolved via Node resolution from the project root.\n * Default: []\n */\n prependCss?: string[]\n}\n\n/**\n * Resolves a prepend CSS entry: absolute paths returned as-is; non-relative, non-absolute\n * specifiers (e.g. @iota-uz/sdk/bichat/styles.css or some-lib/styles.css) are resolved via\n * Node module resolution first; relative paths are joined to root.\n */\nfunction resolvePrependPath(specifierOrPath: string, root: string): string | null {\n if (path.isAbsolute(specifierOrPath)) {\n return specifierOrPath\n }\n if (!specifierOrPath.startsWith('.') && !specifierOrPath.startsWith('/')) {\n try {\n const req = createRequire(path.join(root, 'package.json'))\n return req.resolve(specifierOrPath)\n } catch {\n return null\n }\n }\n return path.join(root, specifierOrPath)\n}\n\n/**\n * Creates a Vite plugin that registers virtual:applet-styles and exports the compiled CSS string.\n * When inputCss is set, tries to run Tailwind CLI to compile; if Tailwind is not available, falls back to reading outputCssPath.\n */\nexport function createAppletStylesVirtualModulePlugin(\n options: AppletStylesVirtualModuleOptions = {}\n): Plugin {\n const inputCss = options.inputCss ?? 'src/index.css'\n const outputCssPath = options.outputCssPath ?? 'dist/style.css'\n const tailwindConfigPath = options.tailwindConfigPath\n const prependCss = options.prependCss ?? []\n let root = process.cwd()\n\n return {\n name: 'applet-styles-virtual-module',\n configResolved(config) {\n root = config.root\n },\n resolveId(id: string) {\n if (id === VIRTUAL_APPLET_STYLES_ID) return RESOLVED_ID\n return null\n },\n load(id: string) {\n if (id !== RESOLVED_ID) return null\n\n const parts: string[] = []\n\n for (const p of prependCss) {\n const full = resolvePrependPath(p, root)\n if (full) {\n try {\n parts.push(fs.readFileSync(full, 'utf-8'))\n } catch {\n // Prepend file missing (e.g. optional SDK styles); skip\n }\n }\n }\n\n const inputPath = path.join(root, inputCss)\n let mainCss: string | null = null\n\n // Try Tailwind CLI if input file exists. spawnSync blocks the event loop; for parallel builds consider a random suffix (e.g. crypto.randomUUID()).\n if (fs.existsSync(inputPath)) {\n const tmpFile = path.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`)\n const args = ['-i', inputPath, '-o', tmpFile]\n if (tailwindConfigPath) {\n const configPath = path.join(root, tailwindConfigPath)\n if (fs.existsSync(configPath)) {\n args.push('-c', configPath)\n }\n }\n // Use platform-specific executable and no shell so args (paths with spaces) are passed safely on Windows.\n const pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'\n const result = spawnSync(pnpmCmd, ['exec', 'tailwindcss', ...args], {\n cwd: root,\n stdio: 'pipe',\n })\n if (result.status === 0 && fs.existsSync(tmpFile)) {\n mainCss = fs.readFileSync(tmpFile, 'utf-8')\n try {\n fs.unlinkSync(tmpFile)\n } catch {\n /* ignore */\n }\n }\n }\n\n if (mainCss === null) {\n const fallbackPath = path.isAbsolute(outputCssPath) ? outputCssPath : path.join(root, outputCssPath)\n try {\n mainCss = fs.readFileSync(fallbackPath, 'utf-8')\n } catch {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[applet-styles] Could not compile via Tailwind CLI and ${fallbackPath} not found; export empty string. Install tailwindcss in the project or build CSS first.`\n )\n }\n mainCss = ''\n }\n }\n\n parts.push(mainCss)\n const css = parts.join('\\n')\n return `export default ${JSON.stringify(css)}`\n },\n }\n}\n\n/**\n * Convenience plugin for BiChat applets: compiles app CSS and prepends SDK BiChat styles.\n * Uses default input src/index.css and package specifier @iota-uz/sdk/bichat/styles.css.\n */\nexport function createBichatStylesPlugin(\n options: Omit<AppletStylesVirtualModuleOptions, 'prependCss'> = {}\n): Plugin {\n return createAppletStylesVirtualModulePlugin({\n ...options,\n inputCss: options.inputCss ?? 'src/index.css',\n outputCssPath: options.outputCssPath ?? 'dist/style.css',\n prependCss: ['@iota-uz/sdk/bichat/styles.css'],\n })\n}\n"]}
@@ -6,12 +6,10 @@ import { UserConfig, Plugin } from 'vite';
6
6
  */
7
7
 
8
8
  type AppletViteOptions = {
9
- /** Applet base path (e.g. "/admin/ali/chat" or "/bi-chat"); overridden by applet-dev.json when present. */
9
+ /** Applet base path (e.g. "/admin/ali/chat" or "/bi-chat"). */
10
10
  basePath: string;
11
- /** Backend URL for proxy (e.g. "http://localhost:3200"); overridden by applet-dev.json when present. */
11
+ /** Backend URL for proxy (e.g. "http://localhost:3200"). */
12
12
  backendUrl: string;
13
- /** Directory containing applet-dev.json (default: process.cwd()). When set, base/port/proxy use manifest if present. */
14
- viteConfigDir?: string;
15
13
  /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */
16
14
  enableLocalSdkAliases?: boolean;
17
15
  /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */
@@ -19,30 +17,16 @@ type AppletViteOptions = {
19
17
  /** Merge additional Vite config */
20
18
  extend?: UserConfig;
21
19
  };
22
- /** Shape of applet-dev.json written by the Go dev runner (single source of truth when using `just dev <name>`). */
23
- type AppletDevManifest = {
24
- basePath: string;
25
- assetsBase: string;
26
- vitePort: number;
27
- backendUrl: string;
28
- };
29
- /**
30
- * Reads applet-dev.json from viteDir (default process.cwd()). When using `just dev <name>`, the Go runner writes this file.
31
- * Returns null if file is missing or invalid (env vars remain the fallback).
32
- */
33
- declare function readAppletDevManifest(viteDir?: string): AppletDevManifest | null;
34
- type AppletDevManifestOrNull = AppletDevManifest | null;
35
20
  /**
36
- * Returns base URL for assets (with trailing slash). Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_ASSETS_BASE env.
21
+ * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.
37
22
  */
38
- declare function getAppletAssetsBase(viteDir?: string, manifest?: AppletDevManifestOrNull): string;
23
+ declare function getAppletAssetsBase(basePath: string): string;
39
24
  /**
40
- * Returns dev server port. Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_VITE_PORT env.
25
+ * Returns dev server port from APPLET_VITE_PORT env, or the given default.
41
26
  */
42
- declare function getAppletVitePort(defaultPort?: number, viteDir?: string, manifest?: AppletDevManifestOrNull): number;
27
+ declare function getAppletVitePort(defaultPort?: number): number;
43
28
  /**
44
29
  * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.
45
- * When applet-dev.json is present (e.g. when using `just dev <name>`), base, port, basePath, and backendUrl come from it.
46
30
  *
47
31
  * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:
48
32
  * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).
@@ -112,4 +96,4 @@ declare function createAppletStylesVirtualModulePlugin(options?: AppletStylesVir
112
96
  */
113
97
  declare function createBichatStylesPlugin(options?: Omit<AppletStylesVirtualModuleOptions, 'prependCss'>): Plugin;
114
98
 
115
- export { type AppletDevManifest, type AppletStylesVirtualModuleOptions, type AppletViteOptions, VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort, readAppletDevManifest };
99
+ export { type AppletStylesVirtualModuleOptions, type AppletViteOptions, VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort };
@@ -6,12 +6,10 @@ import { UserConfig, Plugin } from 'vite';
6
6
  */
7
7
 
8
8
  type AppletViteOptions = {
9
- /** Applet base path (e.g. "/admin/ali/chat" or "/bi-chat"); overridden by applet-dev.json when present. */
9
+ /** Applet base path (e.g. "/admin/ali/chat" or "/bi-chat"). */
10
10
  basePath: string;
11
- /** Backend URL for proxy (e.g. "http://localhost:3200"); overridden by applet-dev.json when present. */
11
+ /** Backend URL for proxy (e.g. "http://localhost:3200"). */
12
12
  backendUrl: string;
13
- /** Directory containing applet-dev.json (default: process.cwd()). When set, base/port/proxy use manifest if present. */
14
- viteConfigDir?: string;
15
13
  /** Enable Vite aliases to local SDK dist for HMR when iterating on SDK (default: from IOTA_SDK_DIST) */
16
14
  enableLocalSdkAliases?: boolean;
17
15
  /** Override SDK dist directory when enableLocalSdkAliases is true (default: process.env.IOTA_SDK_DIST) */
@@ -19,30 +17,16 @@ type AppletViteOptions = {
19
17
  /** Merge additional Vite config */
20
18
  extend?: UserConfig;
21
19
  };
22
- /** Shape of applet-dev.json written by the Go dev runner (single source of truth when using `just dev <name>`). */
23
- type AppletDevManifest = {
24
- basePath: string;
25
- assetsBase: string;
26
- vitePort: number;
27
- backendUrl: string;
28
- };
29
- /**
30
- * Reads applet-dev.json from viteDir (default process.cwd()). When using `just dev <name>`, the Go runner writes this file.
31
- * Returns null if file is missing or invalid (env vars remain the fallback).
32
- */
33
- declare function readAppletDevManifest(viteDir?: string): AppletDevManifest | null;
34
- type AppletDevManifestOrNull = AppletDevManifest | null;
35
20
  /**
36
- * Returns base URL for assets (with trailing slash). Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_ASSETS_BASE env.
21
+ * Returns base URL for assets (with trailing slash). Uses APPLET_ASSETS_BASE env if set, otherwise derives from basePath.
37
22
  */
38
- declare function getAppletAssetsBase(viteDir?: string, manifest?: AppletDevManifestOrNull): string;
23
+ declare function getAppletAssetsBase(basePath: string): string;
39
24
  /**
40
- * Returns dev server port. Prefers manifest when provided (avoids re-reading file), then applet-dev.json, then APPLET_VITE_PORT env.
25
+ * Returns dev server port from APPLET_VITE_PORT env, or the given default.
41
26
  */
42
- declare function getAppletVitePort(defaultPort?: number, viteDir?: string, manifest?: AppletDevManifestOrNull): number;
27
+ declare function getAppletVitePort(defaultPort?: number): number;
43
28
  /**
44
29
  * Builds a full Vite config for an applet: base, port, dedupe, proxy, optional local SDK aliases.
45
- * When applet-dev.json is present (e.g. when using `just dev <name>`), base, port, basePath, and backendUrl come from it.
46
30
  *
47
31
  * **Merge semantics for `extend`:** When you pass `extend`, it is merged with the base config as follows:
48
32
  * - **resolve.alias**: arrays are concatenated (base aliases first, then extend aliases).
@@ -112,4 +96,4 @@ declare function createAppletStylesVirtualModulePlugin(options?: AppletStylesVir
112
96
  */
113
97
  declare function createBichatStylesPlugin(options?: Omit<AppletStylesVirtualModuleOptions, 'prependCss'>): Plugin;
114
98
 
115
- export { type AppletDevManifest, type AppletStylesVirtualModuleOptions, type AppletViteOptions, VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort, readAppletDevManifest };
99
+ export { type AppletStylesVirtualModuleOptions, type AppletViteOptions, VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort };
@@ -1,49 +1,25 @@
1
- import fs2 from 'fs';
2
1
  import path2 from 'path';
3
2
  import { spawnSync } from 'child_process';
4
3
  import crypto from 'crypto';
4
+ import fs from 'fs';
5
5
  import { createRequire } from 'module';
6
6
  import os from 'os';
7
7
 
8
8
  // ui/src/applet-vite/vite.ts
9
- var APPLET_DEV_MANIFEST = "applet-dev.json";
10
- function readAppletDevManifest(viteDir) {
11
- const dir = viteDir ?? process.cwd();
12
- const filePath = path2.join(dir, APPLET_DEV_MANIFEST);
13
- try {
14
- const raw = fs2.readFileSync(filePath, "utf-8");
15
- const data = JSON.parse(raw);
16
- if (typeof data.basePath === "string" && typeof data.assetsBase === "string" && typeof data.vitePort === "number" && typeof data.backendUrl === "string") {
17
- return data;
18
- }
19
- } catch {
20
- }
21
- return null;
22
- }
23
9
  var DEFAULT_DEDUPE = ["react", "react-dom", "react-router-dom", "react-is"];
24
- function getAppletAssetsBase(viteDir, manifest) {
25
- const resolved = manifest ?? readAppletDevManifest(viteDir);
26
- if (resolved) {
27
- const base2 = resolved.assetsBase;
28
- return base2.endsWith("/") ? base2 : base2 + "/";
29
- }
30
- const base = process.env.APPLET_ASSETS_BASE ?? "";
31
- return base.endsWith("/") ? base : base ? base + "/" : "/";
10
+ function getAppletAssetsBase(basePath) {
11
+ const base = process.env.APPLET_ASSETS_BASE ?? basePath + "/assets/";
12
+ return base.endsWith("/") ? base : base + "/";
32
13
  }
33
- function getAppletVitePort(defaultPort = 5173, viteDir, manifest) {
34
- const resolved = manifest ?? readAppletDevManifest(viteDir);
35
- if (resolved) return resolved.vitePort;
14
+ function getAppletVitePort(defaultPort = 5173) {
36
15
  const p = process.env.APPLET_VITE_PORT;
37
16
  if (p === void 0 || p === "") return defaultPort;
38
17
  const n = Number(p);
39
18
  return Number.isFinite(n) ? n : defaultPort;
40
19
  }
41
20
  function createAppletViteConfig(opts) {
42
- const manifest = readAppletDevManifest(opts.viteConfigDir);
43
- const base = getAppletAssetsBase(opts.viteConfigDir, manifest);
44
- const port = getAppletVitePort(5173, opts.viteConfigDir, manifest);
45
- const basePath = manifest?.basePath ?? opts.basePath;
46
- const backendUrl = manifest?.backendUrl ?? opts.backendUrl;
21
+ const base = getAppletAssetsBase(opts.basePath);
22
+ const port = getAppletVitePort(5173);
47
23
  const config = {
48
24
  base,
49
25
  resolve: {
@@ -57,8 +33,8 @@ function createAppletViteConfig(opts) {
57
33
  port,
58
34
  strictPort: true,
59
35
  proxy: createAppletBackendProxy({
60
- basePath,
61
- backendUrl
36
+ basePath: opts.basePath,
37
+ backendUrl: opts.backendUrl
62
38
  })
63
39
  }
64
40
  };
@@ -152,19 +128,19 @@ function createAppletStylesVirtualModulePlugin(options = {}) {
152
128
  const full = resolvePrependPath(p, root);
153
129
  if (full) {
154
130
  try {
155
- parts.push(fs2.readFileSync(full, "utf-8"));
131
+ parts.push(fs.readFileSync(full, "utf-8"));
156
132
  } catch {
157
133
  }
158
134
  }
159
135
  }
160
136
  const inputPath = path2.join(root, inputCss);
161
137
  let mainCss = null;
162
- if (fs2.existsSync(inputPath)) {
138
+ if (fs.existsSync(inputPath)) {
163
139
  const tmpFile = path2.join(os.tmpdir(), `applet-styles-${Date.now()}-${crypto.randomUUID()}.css`);
164
140
  const args = ["-i", inputPath, "-o", tmpFile];
165
141
  if (tailwindConfigPath) {
166
142
  const configPath = path2.join(root, tailwindConfigPath);
167
- if (fs2.existsSync(configPath)) {
143
+ if (fs.existsSync(configPath)) {
168
144
  args.push("-c", configPath);
169
145
  }
170
146
  }
@@ -173,10 +149,10 @@ function createAppletStylesVirtualModulePlugin(options = {}) {
173
149
  cwd: root,
174
150
  stdio: "pipe"
175
151
  });
176
- if (result.status === 0 && fs2.existsSync(tmpFile)) {
177
- mainCss = fs2.readFileSync(tmpFile, "utf-8");
152
+ if (result.status === 0 && fs.existsSync(tmpFile)) {
153
+ mainCss = fs.readFileSync(tmpFile, "utf-8");
178
154
  try {
179
- fs2.unlinkSync(tmpFile);
155
+ fs.unlinkSync(tmpFile);
180
156
  } catch {
181
157
  }
182
158
  }
@@ -184,7 +160,7 @@ function createAppletStylesVirtualModulePlugin(options = {}) {
184
160
  if (mainCss === null) {
185
161
  const fallbackPath = path2.isAbsolute(outputCssPath) ? outputCssPath : path2.join(root, outputCssPath);
186
162
  try {
187
- mainCss = fs2.readFileSync(fallbackPath, "utf-8");
163
+ mainCss = fs.readFileSync(fallbackPath, "utf-8");
188
164
  } catch {
189
165
  if (process.env.NODE_ENV !== "production") {
190
166
  console.warn(
@@ -209,6 +185,6 @@ function createBichatStylesPlugin(options = {}) {
209
185
  });
210
186
  }
211
187
 
212
- export { VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort, readAppletDevManifest };
188
+ export { VIRTUAL_APPLET_STYLES_ID, createAppletBackendProxy, createAppletStylesVirtualModulePlugin, createAppletViteConfig, createBichatStylesPlugin, createLocalSdkAliases, getAppletAssetsBase, getAppletVitePort };
213
189
  //# sourceMappingURL=vite.mjs.map
214
190
  //# sourceMappingURL=vite.mjs.map