@playcademy/vite-plugin 0.0.1-beta.18 → 0.0.1-beta.19

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/dist/index.js CHANGED
@@ -109287,7 +109287,8 @@ function setupAuth() {
109287
109287
  };
109288
109288
  }
109289
109289
  var isBrowser = () => {
109290
- return typeof window !== "undefined" && typeof document !== "undefined";
109290
+ const g5 = globalThis;
109291
+ return typeof g5.window !== "undefined" && typeof g5.document !== "undefined";
109291
109292
  };
109292
109293
  var colors = {
109293
109294
  reset: "\x1B[0m",
@@ -111020,8 +111021,8 @@ async function startRealtimeServer(realtimeOptions, betterAuthSecret) {
111020
111021
  betterAuthSecret,
111021
111022
  quiet: true
111022
111023
  });
111023
- } catch (err2) {
111024
- console.warn("[sandbox] Bun runtime not detected - fallback realtime server failed to start.", err2);
111024
+ } catch (error2) {
111025
+ console.error("Failed to start realtime server:", error2);
111025
111026
  return null;
111026
111027
  }
111027
111028
  }
@@ -121164,37 +121165,54 @@ async function startServer(options) {
121164
121165
  var version3 = package_default.version;
121165
121166
 
121166
121167
  // src/lib/sandbox.ts
121167
- function printSandboxInfo(viteConfig, availablePort, projectInfo) {
121168
+ function printSandboxInfo(viteConfig, apiPort, realtimePort, projectInfo) {
121168
121169
  viteConfig.logger.info("");
121169
121170
  viteConfig.logger.info(` ${import_picocolors2.default.green(import_picocolors2.default.bold("PLAYCADEMY"))} ${import_picocolors2.default.green(`v${version3}`)}`);
121170
121171
  viteConfig.logger.info("");
121171
121172
  viteConfig.logger.info(` ${import_picocolors2.default.green("➜")} ${import_picocolors2.default.bold("Game:")} ${import_picocolors2.default.cyan(projectInfo.slug)}`);
121172
- viteConfig.logger.info(` ${import_picocolors2.default.green("➜")} ${import_picocolors2.default.bold("Sandbox:")} ${import_picocolors2.default.cyan(`http://localhost:${import_picocolors2.default.bold(availablePort.toString())}/api`)}`);
121173
+ viteConfig.logger.info(` ${import_picocolors2.default.green("➜")} ${import_picocolors2.default.bold("Sandbox:")} ${import_picocolors2.default.cyan(`http://localhost:${import_picocolors2.default.bold(apiPort.toString())}/api`)}`);
121174
+ viteConfig.logger.info(` ${import_picocolors2.default.green("➜")} ${import_picocolors2.default.bold("Realtime:")} ${import_picocolors2.default.cyan(`ws://localhost:${import_picocolors2.default.bold(realtimePort.toString())}`)}`);
121173
121175
  viteConfig.logger.info("");
121174
121176
  }
121175
121177
  async function startSandbox(viteConfig, autoStart = true, verbose = false, customUrl) {
121176
121178
  if (!autoStart || viteConfig.command !== "serve") {
121179
+ const baseUrl = customUrl ?? "http://localhost:4321/api";
121180
+ const deriveRealtimeUrl = (url) => {
121181
+ try {
121182
+ const u3 = new URL(url);
121183
+ const port = Number(u3.port || (u3.protocol === "https:" ? 443 : 80));
121184
+ const wsProto = u3.protocol === "https:" ? "wss:" : "ws:";
121185
+ return `${wsProto}//${u3.hostname}:${port + 1}`;
121186
+ } catch {
121187
+ return "ws://localhost:4322";
121188
+ }
121189
+ };
121177
121190
  return {
121178
- url: customUrl ?? "http://localhost:4321/api",
121191
+ baseUrl,
121192
+ realtimeUrl: deriveRealtimeUrl(baseUrl),
121179
121193
  project: null,
121180
121194
  cleanup: () => {}
121181
121195
  };
121182
121196
  }
121183
121197
  try {
121184
- const availablePort = await findAvailablePort(4321);
121185
- const sandboxUrl = `http://localhost:${availablePort}/api`;
121198
+ const sandboxPort = await findAvailablePort(4321);
121199
+ const baseUrl = `http://localhost:${sandboxPort}/api`;
121200
+ const realtimePort = await findAvailablePort(sandboxPort + 1);
121201
+ const realtimeUrl = `ws://localhost:${realtimePort}`;
121186
121202
  const projectInfo = extractProjectInfo(viteConfig);
121187
121203
  const server = await startServer({
121188
- port: availablePort,
121204
+ port: sandboxPort,
121189
121205
  verbose,
121190
121206
  seed: true,
121191
- project: projectInfo
121207
+ project: projectInfo,
121208
+ realtime: { enabled: true, port: realtimePort }
121192
121209
  });
121193
121210
  setTimeout(() => {
121194
- printSandboxInfo(viteConfig, availablePort, projectInfo);
121211
+ printSandboxInfo(viteConfig, sandboxPort, realtimePort, projectInfo);
121195
121212
  }, 100);
121196
121213
  return {
121197
- url: sandboxUrl,
121214
+ baseUrl,
121215
+ realtimeUrl,
121198
121216
  project: projectInfo,
121199
121217
  cleanup: () => {
121200
121218
  if (server && typeof server.stop === "function") {
@@ -121206,7 +121224,8 @@ async function startSandbox(viteConfig, autoStart = true, verbose = false, custo
121206
121224
  } catch (error2) {
121207
121225
  viteConfig.logger.error(import_picocolors2.default.red(`[Playcademy] Failed to start sandbox: ${error2}`));
121208
121226
  return {
121209
- url: "http://localhost:4321/api",
121227
+ baseUrl: "http://localhost:4321/api",
121228
+ realtimeUrl: "ws://localhost:4322",
121210
121229
  project: null,
121211
121230
  cleanup: () => {}
121212
121231
  };
@@ -121395,6 +121414,7 @@ var shell_default = `<!doctype html>
121395
121414
  baseUrl: '{{SANDBOX_URL}}',
121396
121415
  token: 'sandbox-demo-token',
121397
121416
  gameId: '{{GAME_ID}}',
121417
+ realtimeUrl: '{{REALTIME_URL}}',
121398
121418
  },
121399
121419
  {
121400
121420
  target: gameFrame.contentWindow,
@@ -121437,15 +121457,15 @@ var shell_default = `<!doctype html>
121437
121457
  `;
121438
121458
 
121439
121459
  // src/lib/server.ts
121440
- function generateLoaderHTML(sandboxUrl, gameId) {
121441
- return shell_default.replace(/{{SANDBOX_URL}}/g, sandboxUrl).replace(/{{GAME_ID}}/g, gameId);
121460
+ function generateLoaderHTML(sandboxUrl, gameId, realtimeUrl) {
121461
+ return shell_default.replace(/{{SANDBOX_URL}}/g, sandboxUrl).replace(/{{GAME_ID}}/g, gameId).replace(/{{REALTIME_URL}}/g, realtimeUrl);
121442
121462
  }
121443
- function devServerMiddleware(server, sandboxUrl, project) {
121463
+ function devServerMiddleware(server, sandbox) {
121444
121464
  server.middlewares.use("/", (req, res, next) => {
121445
121465
  if (req.url === "/" && req.method === "GET") {
121446
121466
  res.setHeader("Content-Type", "text/html");
121447
- const gameId = project.slug;
121448
- res.end(generateLoaderHTML(sandboxUrl, gameId));
121467
+ const gameId = sandbox.project?.slug;
121468
+ res.end(generateLoaderHTML(sandbox.baseUrl, gameId ?? "", sandbox.realtimeUrl));
121449
121469
  return;
121450
121470
  }
121451
121471
  if (req.url === "/game" && req.method === "GET") {
@@ -121461,7 +121481,6 @@ function devServerMiddleware(server, sandboxUrl, project) {
121461
121481
  function playcademy(options = {}) {
121462
121482
  let viteConfig;
121463
121483
  let currentBuildOutputs = {};
121464
- let sandboxCleanup = null;
121465
121484
  const exportOptions = options.export ?? {};
121466
121485
  const sandboxOptions = options.sandbox ?? {};
121467
121486
  const _options = {
@@ -121485,12 +121504,11 @@ function playcademy(options = {}) {
121485
121504
  },
121486
121505
  async configureServer(server) {
121487
121506
  const sandbox = await startSandbox(viteConfig, _options.startSandbox, _options.verbose, _options.sandboxUrl);
121488
- sandboxCleanup = sandbox.cleanup;
121489
121507
  if (sandbox.project) {
121490
- devServerMiddleware(server, sandbox.url, sandbox.project);
121508
+ devServerMiddleware(server, sandbox);
121491
121509
  }
121492
121510
  server.httpServer?.on("close", () => {
121493
- sandboxCleanup?.();
121511
+ sandbox.cleanup();
121494
121512
  });
121495
121513
  },
121496
121514
  async writeBundle() {
@@ -1,3 +1,3 @@
1
1
  import type { ViteDevServer } from 'vite';
2
- import type { ProjectInfo } from '../types';
3
- export declare function devServerMiddleware(server: ViteDevServer, sandboxUrl: string, project: ProjectInfo): void;
2
+ import type { SandboxManager } from '../types';
3
+ export declare function devServerMiddleware(server: ViteDevServer, sandbox: SandboxManager): void;
package/dist/types.d.ts CHANGED
@@ -58,7 +58,8 @@ export interface ManifestOptions {
58
58
  * Sandbox manager interface for controlling sandbox lifecycle
59
59
  */
60
60
  export interface SandboxManager {
61
- url: string;
61
+ baseUrl: string;
62
+ realtimeUrl: string;
62
63
  project: ProjectInfo | null;
63
64
  cleanup: () => void;
64
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/vite-plugin",
3
- "version": "0.0.1-beta.18",
3
+ "version": "0.0.1-beta.19",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {