@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.cjs CHANGED
@@ -36,7 +36,7 @@ __export(astro_exports, {
36
36
  });
37
37
  module.exports = __toCommonJS(astro_exports);
38
38
 
39
- // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.10_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js
39
+ // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.14_typescript@5.9.3_yaml@2.8.4/node_modules/tsup/assets/cjs_shims.js
40
40
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
41
41
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
42
42
 
@@ -1185,6 +1185,24 @@ function resolveProjectRoot() {
1185
1185
  return gitRoot;
1186
1186
  }
1187
1187
 
1188
+ // src/server/server-url.ts
1189
+ function resolveServerHost(cwd, configRoot) {
1190
+ const userConfig = loadUserConfigSync(false, cwd, configRoot);
1191
+ const configuredHost = userConfig["server.host"]?.trim();
1192
+ if (configuredHost) return configuredHost;
1193
+ if (process.env["VITEST"]) return "127.0.0.1";
1194
+ return "127.0.0.1";
1195
+ }
1196
+ function resolvePublicServerUrl(args) {
1197
+ const userConfig = loadUserConfigSync(false, args.cwd, args.configRoot);
1198
+ const configuredPublicUrl = userConfig["server.publicUrl"]?.trim();
1199
+ if (configuredPublicUrl) {
1200
+ return configuredPublicUrl.replace(/\/$/, "");
1201
+ }
1202
+ const host = resolveServerHost(args.cwd, args.configRoot);
1203
+ return `http://${host}:${args.port}`;
1204
+ }
1205
+
1188
1206
  // src/server/index.ts
1189
1207
  var serverLogger4 = createLogger("inspecto:server", { logLevel: getGlobalLogLevel() });
1190
1208
  var PORT_FILE_NAME = "inspecto.port.json";
@@ -1239,6 +1257,7 @@ async function startServer() {
1239
1257
  serverState.projectRoot = resolveProjectRoot();
1240
1258
  serverState.configRoot = serverState.projectRoot;
1241
1259
  serverState.cwd = process.cwd();
1260
+ const serverHost = resolveServerHost(serverState.cwd, serverState.configRoot);
1242
1261
  import_portfinder.default.basePort = 5678;
1243
1262
  const port = await import_portfinder.default.getPortPromise();
1244
1263
  watchConfig(
@@ -1265,7 +1284,7 @@ async function startServer() {
1265
1284
  });
1266
1285
  });
1267
1286
  await new Promise((resolve2, reject) => {
1268
- serverInstance.listen(port, "0.0.0.0", () => {
1287
+ serverInstance.listen(port, serverHost, () => {
1269
1288
  serverInstance.unref();
1270
1289
  resolve2();
1271
1290
  });
@@ -1287,7 +1306,7 @@ async function startServer() {
1287
1306
  } catch {
1288
1307
  }
1289
1308
  });
1290
- serverLogger4.info(`server running at http://0.0.0.0:${port}`);
1309
+ serverLogger4.info(`server running at http://${serverHost}:${port}`);
1291
1310
  return port;
1292
1311
  }
1293
1312
  async function readBody(req) {
@@ -2411,26 +2430,28 @@ var resolveClientModule = () => {
2411
2430
  };
2412
2431
 
2413
2432
  // src/injectors/webpack.ts
2414
- function getWebpackHtmlScript(serverPort) {
2433
+ function getWebpackHtmlScript(serverPort, publicServerUrl) {
2415
2434
  return `
2416
2435
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2436
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2417
2437
  window.addEventListener('load', () => {
2418
2438
  if (window.InspectoClient) {
2419
2439
  window.InspectoClient.mountInspector({
2420
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2440
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2421
2441
  });
2422
2442
  }
2423
2443
  });
2424
2444
  `;
2425
2445
  }
2426
- function getWebpackAssetScript(serverPort) {
2446
+ function getWebpackAssetScript(serverPort, publicServerUrl) {
2427
2447
  return `
2428
2448
  if (typeof window !== 'undefined') {
2429
2449
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2450
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2430
2451
  const _initInspecto = () => {
2431
2452
  if (window.InspectoClient) {
2432
2453
  window.InspectoClient.mountInspector({
2433
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2454
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2434
2455
  });
2435
2456
  } else {
2436
2457
  setTimeout(_initInspecto, 100);
@@ -2444,7 +2465,7 @@ if (typeof window !== 'undefined') {
2444
2465
  }
2445
2466
  `;
2446
2467
  }
2447
- function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2468
+ function injectWebpack(compiler, serverPortFn, publicServerUrlFn, resolveClientModule2) {
2448
2469
  const inspectoClientPath = resolveClientModule2();
2449
2470
  if (compiler.webpack && compiler.webpack.EntryPlugin) {
2450
2471
  new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {
@@ -2459,11 +2480,12 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2459
2480
  const hooks = HtmlWebpackPlugin.constructor.getHooks(compilation);
2460
2481
  hooks.alterAssetTagGroups.tapPromise("inspecto-overlay", async (data) => {
2461
2482
  const port = await serverPortFn();
2483
+ const publicServerUrl = publicServerUrlFn(port);
2462
2484
  data.headTags.unshift({
2463
2485
  tagName: "script",
2464
2486
  voidTag: false,
2465
2487
  meta: { plugin: "inspecto-overlay" },
2466
- innerHTML: getWebpackHtmlScript(port)
2488
+ innerHTML: getWebpackHtmlScript(port, publicServerUrl)
2467
2489
  });
2468
2490
  return data;
2469
2491
  });
@@ -2476,13 +2498,14 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2476
2498
  },
2477
2499
  async (assets) => {
2478
2500
  const port = await serverPortFn();
2501
+ const publicServerUrl = publicServerUrlFn(port);
2479
2502
  const mainAssetKey = Object.keys(assets).find(
2480
2503
  (key) => key.endsWith(".js") && (key.includes("main") || key.includes("app") || key.includes("umi"))
2481
2504
  );
2482
2505
  if (!mainAssetKey) return;
2483
2506
  const originalSource = assets[mainAssetKey].source();
2484
2507
  assets[mainAssetKey] = new compiler.webpack.sources.RawSource(
2485
- getWebpackAssetScript(port) + "\n" + originalSource
2508
+ getWebpackAssetScript(port, publicServerUrl) + "\n" + originalSource
2486
2509
  );
2487
2510
  }
2488
2511
  );
@@ -2516,12 +2539,13 @@ function injectRspack(compiler, serverPortFn, resolveClientModule2) {
2516
2539
  }
2517
2540
 
2518
2541
  // src/injectors/vite.ts
2519
- function getViteVirtualModuleScript(serverPort) {
2542
+ function getViteVirtualModuleScript(serverPort, publicServerUrl) {
2520
2543
  return `
2521
2544
  import { mountInspector } from '@inspecto-dev/core';
2522
2545
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2546
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2523
2547
  mountInspector({
2524
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2548
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2525
2549
  });
2526
2550
  `;
2527
2551
  }
@@ -2554,6 +2578,11 @@ var InspectoPlugin = (0, import_unplugin.createUnplugin)((userOptions = {}) => {
2554
2578
  }
2555
2579
  return serverPort;
2556
2580
  };
2581
+ const getPublicServerUrl = (port) => resolvePublicServerUrl({
2582
+ cwd: serverState.cwd || process.cwd(),
2583
+ configRoot: serverState.configRoot || projectRoot,
2584
+ port
2585
+ });
2557
2586
  return {
2558
2587
  name: "inspecto-overlay",
2559
2588
  enforce: "pre",
@@ -2566,7 +2595,7 @@ var InspectoPlugin = (0, import_unplugin.createUnplugin)((userOptions = {}) => {
2566
2595
  },
2567
2596
  webpack: (compiler) => {
2568
2597
  if (isProduction) return;
2569
- injectWebpack(compiler, ensureServer, resolveClientModule);
2598
+ injectWebpack(compiler, ensureServer, getPublicServerUrl, resolveClientModule);
2570
2599
  },
2571
2600
  rspack: (compiler) => {
2572
2601
  if (isProduction) return;
@@ -2592,7 +2621,10 @@ var InspectoPlugin = (0, import_unplugin.createUnplugin)((userOptions = {}) => {
2592
2621
  },
2593
2622
  load(id) {
2594
2623
  if (id === VITE_VIRTUAL_MODULE_ID) {
2595
- return getViteVirtualModuleScript(serverPort ?? DEFAULT_PORT);
2624
+ return getViteVirtualModuleScript(
2625
+ serverPort ?? DEFAULT_PORT,
2626
+ getPublicServerUrl(serverPort ?? DEFAULT_PORT)
2627
+ );
2596
2628
  }
2597
2629
  return null;
2598
2630
  },
@@ -2650,10 +2682,10 @@ var rollupPlugin = InspectoPlugin.rollup;
2650
2682
  var esbuildPlugin = InspectoPlugin.esbuild;
2651
2683
 
2652
2684
  // src/astro.ts
2653
- function getAstroInjectedScript(serverPort) {
2685
+ function getAstroInjectedScript(serverPort, publicServerUrl) {
2654
2686
  return `
2655
2687
  import { mountInspector } from '@inspecto-dev/core';
2656
- window.__AI_INSPECTOR_SERVER_URL__ = 'http://0.0.0.0:${serverPort}';
2688
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2657
2689
  mountInspector({
2658
2690
  serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2659
2691
  });
@@ -2673,7 +2705,17 @@ function astroIntegration(options) {
2673
2705
  return;
2674
2706
  }
2675
2707
  const serverPort = await startServer();
2676
- injectScript("page", getAstroInjectedScript(serverPort));
2708
+ injectScript(
2709
+ "page",
2710
+ getAstroInjectedScript(
2711
+ serverPort,
2712
+ resolvePublicServerUrl({
2713
+ cwd: serverState.cwd || process.cwd(),
2714
+ configRoot: serverState.configRoot || process.cwd(),
2715
+ port: serverPort
2716
+ })
2717
+ )
2718
+ );
2677
2719
  }
2678
2720
  }
2679
2721
  };