@fluid-app/fluid-cli-portal 0.1.46 → 0.1.48

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.
@@ -0,0 +1,64 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-twds-ZHy.mjs";
2
+ //#region src/vite-plugin/backend-dev-plugin.ts
3
+ var backend_dev_plugin_exports = /* @__PURE__ */ __exportAll({ backendDevPlugin: () => backendDevPlugin });
4
+ /**
5
+ * Serves dev-compatible responses at production asset paths so the Rails
6
+ * backend can point `PORTAL_CDN_BASE` at `http://localhost:5173` and get
7
+ * HMR + live source without any template changes.
8
+ *
9
+ * Handles:
10
+ * - `/portal.js` → ESM shim that loads `@vite/client` + the real entry
11
+ * - `/portal.css` → empty (Vite injects CSS via JS in dev)
12
+ * - `/vendor.js`, `/query.js` → empty ES modules (no chunks in dev)
13
+ */
14
+ function backendDevPlugin(options) {
15
+ const entry = options?.entry ?? "/src/main.tsx";
16
+ const chunks = options?.chunks ?? ["vendor.js", "query.js"];
17
+ return {
18
+ name: "fluid-backend-dev",
19
+ apply: "serve",
20
+ configureServer(server) {
21
+ const flagged = server;
22
+ if (flagged.__fluidBackendDevWired) return;
23
+ flagged.__fluidBackendDevWired = true;
24
+ server.middlewares.use((req, res, next) => {
25
+ const raw = req.url ?? "";
26
+ const qIndex = raw.indexOf("?");
27
+ const url = qIndex === -1 ? raw : raw.slice(0, qIndex);
28
+ if (url === "/portal.js") {
29
+ serve(res, "application/javascript", [
30
+ `import RefreshRuntime from "/@react-refresh";`,
31
+ `import "/@vite/client";`,
32
+ `RefreshRuntime.injectIntoGlobalHook(window);`,
33
+ `window.$RefreshReg$ = () => {};`,
34
+ `window.$RefreshSig$ = () => (type) => type;`,
35
+ `window.__vite_plugin_react_preamble_installed__ = true;`,
36
+ `await import("${entry}");`
37
+ ].join("\n"));
38
+ return;
39
+ }
40
+ if (url === "/portal.css") {
41
+ serve(res, "text/css", "/* dev: CSS injected via JS */");
42
+ return;
43
+ }
44
+ const chunkName = url.startsWith("/") ? url.slice(1) : url;
45
+ if (chunks.includes(chunkName)) {
46
+ serve(res, "application/javascript", "export {};");
47
+ return;
48
+ }
49
+ next();
50
+ });
51
+ }
52
+ };
53
+ }
54
+ function serve(res, contentType, body) {
55
+ res.setHeader("Content-Type", `${contentType}; charset=utf-8`);
56
+ res.setHeader("Cache-Control", "no-store");
57
+ res.setHeader("Access-Control-Allow-Origin", "*");
58
+ res.statusCode = 200;
59
+ res.end(body);
60
+ }
61
+ //#endregion
62
+ export { backend_dev_plugin_exports as n, backendDevPlugin as t };
63
+
64
+ //# sourceMappingURL=backend-dev-plugin-B9-S4Is-.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-dev-plugin-B9-S4Is-.mjs","names":[],"sources":["../src/vite-plugin/backend-dev-plugin.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\n\nexport interface BackendDevPluginOptions {\n /** Entry module path relative to project root. @default \"/src/main.tsx\" */\n entry?: string;\n /** Production chunk filenames to stub as empty ES modules. */\n chunks?: string[];\n}\n\n/**\n * Serves dev-compatible responses at production asset paths so the Rails\n * backend can point `PORTAL_CDN_BASE` at `http://localhost:5173` and get\n * HMR + live source without any template changes.\n *\n * Handles:\n * - `/portal.js` → ESM shim that loads `@vite/client` + the real entry\n * - `/portal.css` → empty (Vite injects CSS via JS in dev)\n * - `/vendor.js`, `/query.js` → empty ES modules (no chunks in dev)\n */\nexport function backendDevPlugin(options?: BackendDevPluginOptions): Plugin {\n const entry = options?.entry ?? \"/src/main.tsx\";\n const chunks = options?.chunks ?? [\"vendor.js\", \"query.js\"];\n\n return {\n name: \"fluid-backend-dev\",\n apply: \"serve\",\n\n // Register BEFORE Vite's SPA fallback so these paths don't\n // get caught by the index.html catch-all.\n configureServer(server) {\n // Idempotency guard: the CLI injects this plugin and a vite.config may\n // also wire it — only register the middleware once.\n const flagged = server as unknown as { __fluidBackendDevWired?: boolean };\n if (flagged.__fluidBackendDevWired) return;\n flagged.__fluidBackendDevWired = true;\n\n server.middlewares.use((req, res, next) => {\n const raw = req.url ?? \"\";\n const qIndex = raw.indexOf(\"?\");\n const url = qIndex === -1 ? raw : raw.slice(0, qIndex);\n\n if (url === \"/portal.js\") {\n serve(\n res,\n \"application/javascript\",\n [\n `import RefreshRuntime from \"/@react-refresh\";`,\n `import \"/@vite/client\";`,\n `RefreshRuntime.injectIntoGlobalHook(window);`,\n `window.$RefreshReg$ = () => {};`,\n `window.$RefreshSig$ = () => (type) => type;`,\n `window.__vite_plugin_react_preamble_installed__ = true;`,\n `await import(\"${entry}\");`,\n ].join(\"\\n\"),\n );\n return;\n }\n\n if (url === \"/portal.css\") {\n serve(res, \"text/css\", \"/* dev: CSS injected via JS */\");\n return;\n }\n\n const chunkName = url.startsWith(\"/\") ? url.slice(1) : url;\n if (chunks.includes(chunkName)) {\n serve(res, \"application/javascript\", \"export {};\");\n return;\n }\n\n next();\n });\n },\n };\n}\n\nfunction serve(\n res: import(\"http\").ServerResponse,\n contentType: string,\n body: string,\n) {\n res.setHeader(\"Content-Type\", `${contentType}; charset=utf-8`);\n res.setHeader(\"Cache-Control\", \"no-store\");\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.statusCode = 200;\n res.end(body);\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,SAA2C;CAC1E,MAAM,QAAQ,SAAS,SAAS;CAChC,MAAM,SAAS,SAAS,UAAU,CAAC,aAAa,WAAW;AAE3D,QAAO;EACL,MAAM;EACN,OAAO;EAIP,gBAAgB,QAAQ;GAGtB,MAAM,UAAU;AAChB,OAAI,QAAQ,uBAAwB;AACpC,WAAQ,yBAAyB;AAEjC,UAAO,YAAY,KAAK,KAAK,KAAK,SAAS;IACzC,MAAM,MAAM,IAAI,OAAO;IACvB,MAAM,SAAS,IAAI,QAAQ,IAAI;IAC/B,MAAM,MAAM,WAAW,KAAK,MAAM,IAAI,MAAM,GAAG,OAAO;AAEtD,QAAI,QAAQ,cAAc;AACxB,WACE,KACA,0BACA;MACE;MACA;MACA;MACA;MACA;MACA;MACA,iBAAiB,MAAM;MACxB,CAAC,KAAK,KAAK,CACb;AACD;;AAGF,QAAI,QAAQ,eAAe;AACzB,WAAM,KAAK,YAAY,iCAAiC;AACxD;;IAGF,MAAM,YAAY,IAAI,WAAW,IAAI,GAAG,IAAI,MAAM,EAAE,GAAG;AACvD,QAAI,OAAO,SAAS,UAAU,EAAE;AAC9B,WAAM,KAAK,0BAA0B,aAAa;AAClD;;AAGF,UAAM;KACN;;EAEL;;AAGH,SAAS,MACP,KACA,aACA,MACA;AACA,KAAI,UAAU,gBAAgB,GAAG,YAAY,iBAAiB;AAC9D,KAAI,UAAU,iBAAiB,WAAW;AAC1C,KAAI,UAAU,+BAA+B,IAAI;AACjD,KAAI,aAAa;AACjB,KAAI,IAAI,KAAK"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { A as fluid_os_v0_create_fluid_osversion, B as fluid_os_v0_update_fluid_osnavigation, C as writeMappings, D as fluid_os_v0_create_fluid_osprofile, E as fluid_os_v0_create_fluid_osnavigation_item, F as fluid_os_v0_delete_fluid_osscreen, G as fluid_os_v0_update_fluid_osversion, H as fluid_os_v0_update_fluid_osprofile, I as fluid_os_v0_delete_fluid_ostheme, K as createFetchClient, L as fluid_os_v0_list_fluid_osdefinitions, M as fluid_os_v0_delete_fluid_osnavigation, N as fluid_os_v0_delete_fluid_osnavigation_item, O as fluid_os_v0_create_fluid_osscreen, P as fluid_os_v0_delete_fluid_osprofile, R as fluid_os_v0_list_fluid_osnavigation_items, S as updateMapping, T as fluid_os_v0_create_fluid_osnavigation, U as fluid_os_v0_update_fluid_osscreen, V as fluid_os_v0_update_fluid_osnavigation_item, W as fluid_os_v0_update_fluid_ostheme, _ as deriveSlug, a as buildThemeIdToSlugMap, b as resolveIdToSlug, c as transformNavigationItems, d as transformTheme, f as buildSnapshot, g as writeSnapshot, h as readSnapshot, i as buildNavigationIdToSlugMap, j as fluid_os_v0_create_widget_package_version, k as fluid_os_v0_create_fluid_ostheme, l as transformProfile, m as diffAgainstSnapshot, o as deriveScreenSlug, p as computeFileHash, r as buildIdToSlugMap, s as transformNavigation, t as pullCommand, u as transformScreen, v as readMappings, w as fluid_os_v0_complete_widget_package_version_upload, x as resolveSlugToId, y as removeMapping, z as fluid_os_v0_list_fluid_osversions } from "./pull-CG5dELOX.mjs";
1
+ import { A as fluid_os_v0_create_fluid_osversion, B as fluid_os_v0_update_fluid_osnavigation, C as writeMappings, D as fluid_os_v0_create_fluid_osprofile, E as fluid_os_v0_create_fluid_osnavigation_item, F as fluid_os_v0_delete_fluid_osscreen, G as fluid_os_v0_update_fluid_osversion, H as fluid_os_v0_update_fluid_osprofile, I as fluid_os_v0_delete_fluid_ostheme, K as createFetchClient, L as fluid_os_v0_list_fluid_osdefinitions, M as fluid_os_v0_delete_fluid_osnavigation, N as fluid_os_v0_delete_fluid_osnavigation_item, O as fluid_os_v0_create_fluid_osscreen, P as fluid_os_v0_delete_fluid_osprofile, R as fluid_os_v0_list_fluid_osnavigation_items, S as updateMapping, T as fluid_os_v0_create_fluid_osnavigation, U as fluid_os_v0_update_fluid_osscreen, V as fluid_os_v0_update_fluid_osnavigation_item, W as fluid_os_v0_update_fluid_ostheme, _ as deriveSlug, a as buildThemeIdToSlugMap, b as resolveIdToSlug, c as transformNavigationItems, d as transformTheme, f as buildSnapshot, g as writeSnapshot, h as readSnapshot, i as buildNavigationIdToSlugMap, j as fluid_os_v0_create_widget_package_version, k as fluid_os_v0_create_fluid_ostheme, l as transformProfile, m as diffAgainstSnapshot, o as deriveScreenSlug, p as computeFileHash, r as buildIdToSlugMap, s as transformNavigation, t as pullCommand, u as transformScreen, v as readMappings, w as fluid_os_v0_complete_widget_package_version_upload, x as resolveSlugToId, y as removeMapping, z as fluid_os_v0_list_fluid_osversions } from "./pull-XOsFaqz2.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { Command } from "commander";
4
4
  import chalk from "chalk";
@@ -1158,7 +1158,7 @@ async function autoPull(cwd) {
1158
1158
  console.log(chalk.yellow("No portal/ directory found.") + " Attempting to pull content...");
1159
1159
  console.log();
1160
1160
  try {
1161
- const { pullCommand } = await import("./pull-CG5dELOX.mjs").then((n) => n.n);
1161
+ const { pullCommand } = await import("./pull-XOsFaqz2.mjs").then((n) => n.n);
1162
1162
  await pullCommand.parseAsync([], { from: "user" });
1163
1163
  return hasPortalContent(cwd);
1164
1164
  } catch (err) {
@@ -1177,7 +1177,8 @@ const devCommand = new Command("dev").description("Start the development server
1177
1177
  console.error(chalk.yellow("Make sure you're in a Fluid project directory"));
1178
1178
  process.exit(1);
1179
1179
  }
1180
- if (!existsSync(join(cwd, "vite.config.ts"))) {
1180
+ const viteConfigPath = join(cwd, "vite.config.ts");
1181
+ if (!existsSync(viteConfigPath)) {
1181
1182
  console.error(chalk.red("Error: No vite.config.ts found"));
1182
1183
  console.error(chalk.yellow("This command must be run from a Fluid project directory"));
1183
1184
  process.exit(1);
@@ -1192,24 +1193,51 @@ const devCommand = new Command("dev").description("Start the development server
1192
1193
  if (hasPortalContent(cwd)) {
1193
1194
  console.log();
1194
1195
  console.log(chalk.green("Portal dev mode: ") + "local content from " + chalk.cyan("portal/") + " will be served");
1195
- console.log(chalk.gray(" Manifest requests intercepted at /api/fluid_os/definitions/active"));
1196
+ console.log(chalk.gray(" Manifest requests intercepted at /api/app/manifest (+ /api/fluid_os/definitions/active)"));
1196
1197
  console.log(chalk.gray(" File changes in portal/ will trigger a page reload"));
1197
1198
  }
1198
- const viteArgs = ["vite"];
1199
- if (options.port) viteArgs.push("--port", String(options.port));
1200
- if (options.host) viteArgs.push("--host");
1201
1199
  console.log();
1202
1200
  console.log(chalk.bold("Starting development server..."));
1203
1201
  console.log();
1202
+ const viteArgs = ["vite"];
1203
+ if (options.port) viteArgs.push("--port", String(options.port));
1204
+ if (options.host) viteArgs.push("--host");
1205
+ const parsedPort = Number(options.port);
1206
+ const port = Number.isFinite(parsedPort) ? parsedPort : 5173;
1204
1207
  try {
1205
- await execa("pnpm", viteArgs, {
1206
- cwd,
1207
- stdio: "inherit"
1208
+ const { createServer } = await import("vite");
1209
+ const { portalDevPlugin } = await import("./portal-dev-plugin-CytSDvBy.mjs").then((n) => n.n);
1210
+ const { backendDevPlugin } = await import("./backend-dev-plugin-B9-S4Is-.mjs").then((n) => n.n);
1211
+ const server = await createServer({
1212
+ configFile: viteConfigPath,
1213
+ envPrefix: ["VITE_", "NEXT_PUBLIC_"],
1214
+ plugins: [portalDevPlugin(), backendDevPlugin()],
1215
+ server: {
1216
+ port,
1217
+ host: options.host ? true : void 0
1218
+ }
1208
1219
  });
1220
+ await server.listen();
1221
+ server.printUrls();
1222
+ const shutdown = () => {
1223
+ server.close().finally(() => process.exit(0));
1224
+ };
1225
+ process.on("SIGINT", shutdown);
1226
+ process.on("SIGTERM", shutdown);
1227
+ await new Promise(() => {});
1209
1228
  } catch (error) {
1210
- if (error.signal === "SIGINT") return;
1211
- console.error(chalk.red("Development server exited with an error"));
1212
- process.exit(1);
1229
+ console.warn(chalk.yellow("Could not start the enriched dev server; falling back to `vite`. Local portal content requires portalDevPlugin in vite.config for the fallback path."), error instanceof Error ? error.message : String(error));
1230
+ try {
1231
+ await execa("pnpm", viteArgs, {
1232
+ cwd,
1233
+ stdio: "inherit"
1234
+ });
1235
+ } catch (fallbackErr) {
1236
+ const execaError = fallbackErr;
1237
+ if (execaError.signal === "SIGINT" || execaError.signal === "SIGTERM") return;
1238
+ console.error(chalk.red("Development server exited with an error"));
1239
+ process.exit(1);
1240
+ }
1213
1241
  }
1214
1242
  });
1215
1243
  //#endregion