@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/index.cjs CHANGED
@@ -43,7 +43,7 @@ __export(src_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(src_exports);
45
45
 
46
- // ../../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
46
+ // ../../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
47
47
  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;
48
48
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
49
49
 
@@ -1899,6 +1899,24 @@ function resolveProjectRoot() {
1899
1899
  return gitRoot;
1900
1900
  }
1901
1901
 
1902
+ // src/server/server-url.ts
1903
+ function resolveServerHost(cwd, configRoot) {
1904
+ const userConfig = loadUserConfigSync(false, cwd, configRoot);
1905
+ const configuredHost = userConfig["server.host"]?.trim();
1906
+ if (configuredHost) return configuredHost;
1907
+ if (process.env["VITEST"]) return "127.0.0.1";
1908
+ return "127.0.0.1";
1909
+ }
1910
+ function resolvePublicServerUrl(args) {
1911
+ const userConfig = loadUserConfigSync(false, args.cwd, args.configRoot);
1912
+ const configuredPublicUrl = userConfig["server.publicUrl"]?.trim();
1913
+ if (configuredPublicUrl) {
1914
+ return configuredPublicUrl.replace(/\/$/, "");
1915
+ }
1916
+ const host = resolveServerHost(args.cwd, args.configRoot);
1917
+ return `http://${host}:${args.port}`;
1918
+ }
1919
+
1902
1920
  // src/server/index.ts
1903
1921
  var serverLogger4 = createLogger("inspecto:server", { logLevel: getGlobalLogLevel() });
1904
1922
  var PORT_FILE_NAME = "inspecto.port.json";
@@ -1953,6 +1971,7 @@ async function startServer() {
1953
1971
  serverState.projectRoot = resolveProjectRoot();
1954
1972
  serverState.configRoot = serverState.projectRoot;
1955
1973
  serverState.cwd = process.cwd();
1974
+ const serverHost = resolveServerHost(serverState.cwd, serverState.configRoot);
1956
1975
  import_portfinder.default.basePort = 5678;
1957
1976
  const port = await import_portfinder.default.getPortPromise();
1958
1977
  watchConfig(
@@ -1979,7 +1998,7 @@ async function startServer() {
1979
1998
  });
1980
1999
  });
1981
2000
  await new Promise((resolve2, reject) => {
1982
- serverInstance.listen(port, "0.0.0.0", () => {
2001
+ serverInstance.listen(port, serverHost, () => {
1983
2002
  serverInstance.unref();
1984
2003
  resolve2();
1985
2004
  });
@@ -2001,7 +2020,7 @@ async function startServer() {
2001
2020
  } catch {
2002
2021
  }
2003
2022
  });
2004
- serverLogger4.info(`server running at http://0.0.0.0:${port}`);
2023
+ serverLogger4.info(`server running at http://${serverHost}:${port}`);
2005
2024
  return port;
2006
2025
  }
2007
2026
  async function readBody(req) {
@@ -2418,26 +2437,28 @@ var resolveClientModule = () => {
2418
2437
  };
2419
2438
 
2420
2439
  // src/injectors/webpack.ts
2421
- function getWebpackHtmlScript(serverPort) {
2440
+ function getWebpackHtmlScript(serverPort, publicServerUrl) {
2422
2441
  return `
2423
2442
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2443
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2424
2444
  window.addEventListener('load', () => {
2425
2445
  if (window.InspectoClient) {
2426
2446
  window.InspectoClient.mountInspector({
2427
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2447
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2428
2448
  });
2429
2449
  }
2430
2450
  });
2431
2451
  `;
2432
2452
  }
2433
- function getWebpackAssetScript(serverPort) {
2453
+ function getWebpackAssetScript(serverPort, publicServerUrl) {
2434
2454
  return `
2435
2455
  if (typeof window !== 'undefined') {
2436
2456
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2457
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2437
2458
  const _initInspecto = () => {
2438
2459
  if (window.InspectoClient) {
2439
2460
  window.InspectoClient.mountInspector({
2440
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2461
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2441
2462
  });
2442
2463
  } else {
2443
2464
  setTimeout(_initInspecto, 100);
@@ -2451,7 +2472,7 @@ if (typeof window !== 'undefined') {
2451
2472
  }
2452
2473
  `;
2453
2474
  }
2454
- function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2475
+ function injectWebpack(compiler, serverPortFn, publicServerUrlFn, resolveClientModule2) {
2455
2476
  const inspectoClientPath = resolveClientModule2();
2456
2477
  if (compiler.webpack && compiler.webpack.EntryPlugin) {
2457
2478
  new compiler.webpack.EntryPlugin(compiler.context, inspectoClientPath, {
@@ -2466,11 +2487,12 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2466
2487
  const hooks = HtmlWebpackPlugin.constructor.getHooks(compilation);
2467
2488
  hooks.alterAssetTagGroups.tapPromise("inspecto-overlay", async (data) => {
2468
2489
  const port = await serverPortFn();
2490
+ const publicServerUrl = publicServerUrlFn(port);
2469
2491
  data.headTags.unshift({
2470
2492
  tagName: "script",
2471
2493
  voidTag: false,
2472
2494
  meta: { plugin: "inspecto-overlay" },
2473
- innerHTML: getWebpackHtmlScript(port)
2495
+ innerHTML: getWebpackHtmlScript(port, publicServerUrl)
2474
2496
  });
2475
2497
  return data;
2476
2498
  });
@@ -2483,13 +2505,14 @@ function injectWebpack(compiler, serverPortFn, resolveClientModule2) {
2483
2505
  },
2484
2506
  async (assets) => {
2485
2507
  const port = await serverPortFn();
2508
+ const publicServerUrl = publicServerUrlFn(port);
2486
2509
  const mainAssetKey = Object.keys(assets).find(
2487
2510
  (key) => key.endsWith(".js") && (key.includes("main") || key.includes("app") || key.includes("umi"))
2488
2511
  );
2489
2512
  if (!mainAssetKey) return;
2490
2513
  const originalSource = assets[mainAssetKey].source();
2491
2514
  assets[mainAssetKey] = new compiler.webpack.sources.RawSource(
2492
- getWebpackAssetScript(port) + "\n" + originalSource
2515
+ getWebpackAssetScript(port, publicServerUrl) + "\n" + originalSource
2493
2516
  );
2494
2517
  }
2495
2518
  );
@@ -2523,12 +2546,13 @@ function injectRspack(compiler, serverPortFn, resolveClientModule2) {
2523
2546
  }
2524
2547
 
2525
2548
  // src/injectors/vite.ts
2526
- function getViteVirtualModuleScript(serverPort) {
2549
+ function getViteVirtualModuleScript(serverPort, publicServerUrl) {
2527
2550
  return `
2528
2551
  import { mountInspector } from '@inspecto-dev/core';
2529
2552
  window.__AI_INSPECTOR_PORT__ = ${serverPort};
2553
+ window.__AI_INSPECTOR_SERVER_URL__ = '${publicServerUrl ?? `http://127.0.0.1:${serverPort}`}';
2530
2554
  mountInspector({
2531
- serverUrl: 'http://0.0.0.0:' + window.__AI_INSPECTOR_PORT__,
2555
+ serverUrl: window.__AI_INSPECTOR_SERVER_URL__,
2532
2556
  });
2533
2557
  `;
2534
2558
  }
@@ -2561,6 +2585,11 @@ var InspectoPlugin = (0, import_unplugin.createUnplugin)((userOptions = {}) => {
2561
2585
  }
2562
2586
  return serverPort;
2563
2587
  };
2588
+ const getPublicServerUrl = (port) => resolvePublicServerUrl({
2589
+ cwd: serverState.cwd || process.cwd(),
2590
+ configRoot: serverState.configRoot || projectRoot,
2591
+ port
2592
+ });
2564
2593
  return {
2565
2594
  name: "inspecto-overlay",
2566
2595
  enforce: "pre",
@@ -2573,7 +2602,7 @@ var InspectoPlugin = (0, import_unplugin.createUnplugin)((userOptions = {}) => {
2573
2602
  },
2574
2603
  webpack: (compiler) => {
2575
2604
  if (isProduction) return;
2576
- injectWebpack(compiler, ensureServer, resolveClientModule);
2605
+ injectWebpack(compiler, ensureServer, getPublicServerUrl, resolveClientModule);
2577
2606
  },
2578
2607
  rspack: (compiler) => {
2579
2608
  if (isProduction) return;
@@ -2599,7 +2628,10 @@ var InspectoPlugin = (0, import_unplugin.createUnplugin)((userOptions = {}) => {
2599
2628
  },
2600
2629
  load(id) {
2601
2630
  if (id === VITE_VIRTUAL_MODULE_ID) {
2602
- return getViteVirtualModuleScript(serverPort ?? DEFAULT_PORT);
2631
+ return getViteVirtualModuleScript(
2632
+ serverPort ?? DEFAULT_PORT,
2633
+ getPublicServerUrl(serverPort ?? DEFAULT_PORT)
2634
+ );
2603
2635
  }
2604
2636
  return null;
2605
2637
  },