@inspecto-dev/plugin 0.3.9 → 0.3.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/dist/astro.d.cts CHANGED
@@ -6,7 +6,7 @@ interface AstroConfigSetupContext {
6
6
  injectScript: (stage: 'page' | 'head-inline' | 'before-hydration' | 'page-ssr', content: string) => void;
7
7
  updateConfig: (newConfig: Record<string, unknown>) => unknown;
8
8
  }
9
- declare function getAstroInjectedScript(serverPort: number): string;
9
+ declare function getAstroInjectedScript(serverPort: number, publicServerUrl?: string): string;
10
10
  declare function astroIntegration(options?: UnpluginOptions): {
11
11
  name: string;
12
12
  hooks: {
package/dist/astro.d.ts CHANGED
@@ -6,7 +6,7 @@ interface AstroConfigSetupContext {
6
6
  injectScript: (stage: 'page' | 'head-inline' | 'before-hydration' | 'page-ssr', content: string) => void;
7
7
  updateConfig: (newConfig: Record<string, unknown>) => unknown;
8
8
  }
9
- declare function getAstroInjectedScript(serverPort: number): string;
9
+ declare function getAstroInjectedScript(serverPort: number, publicServerUrl?: string): string;
10
10
  declare function astroIntegration(options?: UnpluginOptions): {
11
11
  name: string;
12
12
  hooks: {
package/dist/astro.js CHANGED
@@ -1154,6 +1154,24 @@ function resolveProjectRoot() {
1154
1154
  return gitRoot;
1155
1155
  }
1156
1156
 
1157
+ // src/server/server-url.ts
1158
+ function resolveServerHost(cwd, configRoot) {
1159
+ const userConfig = loadUserConfigSync(false, cwd, configRoot);
1160
+ const configuredHost = userConfig["server.host"]?.trim();
1161
+ if (configuredHost) return configuredHost;
1162
+ if (process.env["VITEST"]) return "127.0.0.1";
1163
+ return "127.0.0.1";
1164
+ }
1165
+ function resolvePublicServerUrl(args) {
1166
+ const userConfig = loadUserConfigSync(false, args.cwd, args.configRoot);
1167
+ const configuredPublicUrl = userConfig["server.publicUrl"]?.trim();
1168
+ if (configuredPublicUrl) {
1169
+ return configuredPublicUrl.replace(/\/$/, "");
1170
+ }
1171
+ const host = resolveServerHost(args.cwd, args.configRoot);
1172
+ return `http://${host}:${args.port}`;
1173
+ }
1174
+
1157
1175
  // src/server/index.ts
1158
1176
  var serverLogger4 = createLogger("inspecto:server", { logLevel: getGlobalLogLevel() });
1159
1177
  var PORT_FILE_NAME = "inspecto.port.json";
@@ -1208,6 +1226,7 @@ async function startServer() {
1208
1226
  serverState.projectRoot = resolveProjectRoot();
1209
1227
  serverState.configRoot = serverState.projectRoot;
1210
1228
  serverState.cwd = process.cwd();
1229
+ const serverHost = resolveServerHost(serverState.cwd, serverState.configRoot);
1211
1230
  portfinder.basePort = 5678;
1212
1231
  const port = await portfinder.getPortPromise();
1213
1232
  watchConfig(
@@ -1234,7 +1253,7 @@ async function startServer() {
1234
1253
  });
1235
1254
  });
1236
1255
  await new Promise((resolve2, reject) => {
1237
- serverInstance.listen(port, "0.0.0.0", () => {
1256
+ serverInstance.listen(port, serverHost, () => {
1238
1257
  serverInstance.unref();
1239
1258
  resolve2();
1240
1259
  });
@@ -1256,7 +1275,7 @@ async function startServer() {
1256
1275
  } catch {
1257
1276
  }
1258
1277
  });
1259
- serverLogger4.info(`server running at http://0.0.0.0:${port}`);
1278
+ serverLogger4.info(`server running at http://${serverHost}:${port}`);
1260
1279
  return port;
1261
1280
  }
1262
1281
  async function readBody(req) {
@@ -2380,26 +2399,28 @@ var resolveClientModule = () => {
2380
2399
  };
2381
2400
 
2382
2401
  // src/injectors/webpack.ts
2383
- function getWebpackHtmlScript(serverPort) {
2402
+ function getWebpackHtmlScript(serverPort, publicServerUrl) {
2384
2403
  return `
2385
2404
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2405
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2386
2406
  window.addEventListener('load', () => {
2387
2407
  if (window.InspectoClient) {
2388
2408
  window.InspectoClient.mountInspector({
2389
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2409
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2390
2410
  });
2391
2411
  }
2392
2412
  });
2393
2413
  `;
2394
2414
  }
2395
- function getWebpackAssetScript(serverPort) {
2415
+ function getWebpackAssetScript(serverPort, publicServerUrl) {
2396
2416
  return `
2397
2417
  if (typeof window !== 'undefined') {
2398
2418
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2419
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2399
2420
  const _initInspecto = () => {
2400
2421
  if (window.InspectoClient) {
2401
2422
  window.InspectoClient.mountInspector({
2402
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2423
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2403
2424
  });
2404
2425
  } else {
2405
2426
  setTimeout(_initInspecto, 100);
@@ -2413,7 +2434,7 @@ if (typeof window !== 'undefined') {
2413
2434
  }
2414
2435
  `;
2415
2436
  }
2416
- function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2437
+ function injectWebpack(compiler, serverPortFn, publicServerUrlFn, resolveClientModule2) {
2417
2438
  const inspectoClientPath = resolveClientModule2();
2418
2439
  if (compiler.webpack && compiler.webpack.EntryPlugin) {
2419
2440
  new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {
@@ -2428,11 +2449,12 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2428
2449
  const hooks = HtmlWebpackPlugin.constructor.getHooks(compilation);
2429
2450
  hooks.alterAssetTagGroups.tapPromise("inspecto-overlay", async (data) => {
2430
2451
  const port = await serverPortFn();
2452
+ const publicServerUrl = publicServerUrlFn(port);
2431
2453
  data.headTags.unshift({
2432
2454
  tagName: "script",
2433
2455
  voidTag: false,
2434
2456
  meta: { plugin: "inspecto-overlay" },
2435
- innerHTML: getWebpackHtmlScript(port)
2457
+ innerHTML: getWebpackHtmlScript(port, publicServerUrl)
2436
2458
  });
2437
2459
  return data;
2438
2460
  });
@@ -2445,13 +2467,14 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2445
2467
  },
2446
2468
  async (assets) => {
2447
2469
  const port = await serverPortFn();
2470
+ const publicServerUrl = publicServerUrlFn(port);
2448
2471
  const mainAssetKey = Object.keys(assets).find(
2449
2472
  (key) => key.endsWith(".js") && (key.includes("main") || key.includes("app") || key.includes("umi"))
2450
2473
  );
2451
2474
  if (!mainAssetKey) return;
2452
2475
  const originalSource = assets[mainAssetKey].source();
2453
2476
  assets[mainAssetKey] = new compiler.webpack.sources.RawSource(
2454
- getWebpackAssetScript(port) + "\n" + originalSource
2477
+ getWebpackAssetScript(port, publicServerUrl) + "\n" + originalSource
2455
2478
  );
2456
2479
  }
2457
2480
  );
@@ -2485,12 +2508,13 @@ function injectRspack(compiler, serverPortFn, resolveClientModule2) {
2485
2508
  }
2486
2509
 
2487
2510
  // src/injectors/vite.ts
2488
- function getViteVirtualModuleScript(serverPort) {
2511
+ function getViteVirtualModuleScript(serverPort, publicServerUrl) {
2489
2512
  return `
2490
2513
  import { mountInspector } from '@inspecto-dev/core';
2491
2514
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2515
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2492
2516
  mountInspector({
2493
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2517
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2494
2518
  });
2495
2519
  `;
2496
2520
  }
@@ -2523,6 +2547,11 @@ var InspectoPlugin = createUnplugin((userOptions = {}) => {
2523
2547
  }
2524
2548
  return serverPort;
2525
2549
  };
2550
+ const getPublicServerUrl = (port) => resolvePublicServerUrl({
2551
+ cwd: serverState.cwd || process.cwd(),
2552
+ configRoot: serverState.configRoot || projectRoot,
2553
+ port
2554
+ });
2526
2555
  return {
2527
2556
  name: "inspecto-overlay",
2528
2557
  enforce: "pre",
@@ -2535,7 +2564,7 @@ var InspectoPlugin = createUnplugin((userOptions = {}) => {
2535
2564
  },
2536
2565
  webpack: (compiler) => {
2537
2566
  if (isProduction) return;
2538
- injectWebpack(compiler, ensureServer, resolveClientModule);
2567
+ injectWebpack(compiler, ensureServer, getPublicServerUrl, resolveClientModule);
2539
2568
  },
2540
2569
  rspack: (compiler) => {
2541
2570
  if (isProduction) return;
@@ -2561,7 +2590,10 @@ var InspectoPlugin = createUnplugin((userOptions = {}) => {
2561
2590
  },
2562
2591
  load(id) {
2563
2592
  if (id === VITE_VIRTUAL_MODULE_ID) {
2564
- return getViteVirtualModuleScript(serverPort ?? DEFAULT_PORT);
2593
+ return getViteVirtualModuleScript(
2594
+ serverPort ?? DEFAULT_PORT,
2595
+ getPublicServerUrl(serverPort ?? DEFAULT_PORT)
2596
+ );
2565
2597
  }
2566
2598
  return null;
2567
2599
  },
@@ -2619,10 +2651,10 @@ var rollupPlugin = InspectoPlugin.rollup;
2619
2651
  var esbuildPlugin = InspectoPlugin.esbuild;
2620
2652
 
2621
2653
  // src/astro.ts
2622
- function getAstroInjectedScript(serverPort) {
2654
+ function getAstroInjectedScript(serverPort, publicServerUrl) {
2623
2655
  return `
2624
2656
  import { mountInspector } from '@inspecto-dev/core';
2625
- window.__AI_INSPECTOR_SERVER_URL__ = 'http://0.0.0.0:${serverPort}';
2657
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2626
2658
  mountInspector({
2627
2659
  serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2628
2660
  });
@@ -2642,7 +2674,17 @@ function astroIntegration(options) {
2642
2674
  return;
2643
2675
  }
2644
2676
  const serverPort = await startServer();
2645
- injectScript("page", getAstroInjectedScript(serverPort));
2677
+ injectScript(
2678
+ "page",
2679
+ getAstroInjectedScript(
2680
+ serverPort,
2681
+ resolvePublicServerUrl({
2682
+ cwd: serverState.cwd || process.cwd(),
2683
+ configRoot: serverState.configRoot || process.cwd(),
2684
+ port: serverPort
2685
+ })
2686
+ )
2687
+ );
2646
2688
  }
2647
2689
  }
2648
2690
  };