xanix 1.0.14 → 1.0.15

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.
@@ -1,2 +1,2 @@
1
1
  import type { Plugin } from "rollup";
2
- export default function xanixReactRefresh(): Plugin;
2
+ export default function xanixReactRefresh(WebSocketPort: number): Plugin;
@@ -6,7 +6,7 @@ import generate from "@babel/generator";
6
6
  import * as t from "@babel/types";
7
7
  import { getClientRuntimeFile } from "../../include/utils.js";
8
8
  const root = process.cwd();
9
- export default function xanixReactRefresh() {
9
+ export default function xanixReactRefresh(WebSocketPort) {
10
10
  return {
11
11
  name: "xanix-react-refresh",
12
12
  load(id) {
@@ -22,7 +22,7 @@ ${code}
22
22
  RefreshRuntime.injectIntoGlobalHook(window);
23
23
  window.$RefreshReg$ = RefreshRuntime.register;
24
24
  window.$RefreshSig$ = () => (type) => type;
25
- const ws = new WebSocket("ws://localhost:8080");
25
+ const ws = new WebSocket("ws://localhost:" + ${WebSocketPort});
26
26
 
27
27
 
28
28
  ws.onmessage = async (event) => {
@@ -4,5 +4,6 @@ export interface XanixRollupOptions {
4
4
  development?: boolean;
5
5
  assetExternal?: boolean;
6
6
  onChange?: (entry: string, event?: string) => void;
7
+ WebSocketPort?: number;
7
8
  }
8
- export declare function xanixDefaultPlugins(options?: XanixRollupOptions): Plugin[];
9
+ export declare function xanixDefaultPlugins(options: XanixRollupOptions): Plugin[];
@@ -11,7 +11,7 @@ import xanixReactRefresh from "./XanixReactRefresh.js";
11
11
  import XanixEnvPlugin from "./XanixEnv.js";
12
12
  import xanixUseDataId from "./xanixUseDataId.js";
13
13
  import XanixServerTransform from "./XanixServerTransform.js";
14
- export function xanixDefaultPlugins(options = {}) {
14
+ export function xanixDefaultPlugins(options) {
15
15
  const target = options.target ?? "client";
16
16
  const development = options.development ?? true;
17
17
  const isClient = target === "client";
@@ -23,7 +23,7 @@ export function xanixDefaultPlugins(options = {}) {
23
23
  }
24
24
  else {
25
25
  if (development) {
26
- _plugins.push(xanixReactRefresh());
26
+ _plugins.push(xanixReactRefresh(options.WebSocketPort));
27
27
  }
28
28
  }
29
29
  return [
@@ -3,6 +3,7 @@ import { XanixClientEntry } from "../types.js";
3
3
  type Option = {
4
4
  onChange?: (entry: string, event?: string) => void;
5
5
  onBuildEnd?: () => void;
6
+ WebSocketPort: number;
6
7
  };
7
8
  declare const WatchClient: (entries: XanixClientEntry[], options: Option) => Promise<RollupWatcher>;
8
9
  export default WatchClient;
@@ -33,6 +33,7 @@ const WatchClient = async (entries, options) => {
33
33
  plugins: [
34
34
  XanixResolveCacheDeps(buildCache, entries),
35
35
  ...xanixDefaultPlugins({
36
+ WebSocketPort: options.WebSocketPort,
36
37
  target: "client",
37
38
  development: true,
38
39
  assetExternal: true,
@@ -7,6 +7,7 @@ import logger from "../include/logger.js";
7
7
  import { getEntries } from "../include/entry.js";
8
8
  import { WebSocketServer } from "ws";
9
9
  import outdirs from "../../outdirs.js";
10
+ import { getWebSocketPort } from "../include/utils.js";
10
11
  const root = process.cwd();
11
12
  let child;
12
13
  function start() {
@@ -20,8 +21,9 @@ function start() {
20
21
  });
21
22
  }
22
23
  const dev = async (rootEntry) => {
24
+ const WebSocketPort = getWebSocketPort();
23
25
  const wss = new WebSocketServer({
24
- port: 8080,
26
+ port: WebSocketPort,
25
27
  });
26
28
  let sockets = new Set();
27
29
  const broadcast = (message) => {
@@ -51,6 +53,7 @@ const dev = async (rootEntry) => {
51
53
  let changedFiles = new Set();
52
54
  _clientWatcher?.close();
53
55
  _clientWatcher = await watchClient(entries, {
56
+ WebSocketPort,
54
57
  onChange: (entry) => {
55
58
  const _entry = entries.find((e) => e.file === entry);
56
59
  let buildFile = _entry
@@ -1,3 +1,4 @@
1
1
  export declare function uid(value: string, length?: number): string;
2
2
  export declare const getClientRuntimeFile: () => string;
3
3
  export declare const getClientRuntimeFileName: (mode: "development" | "production") => string;
4
+ export declare function getWebSocketPort(): number;
@@ -13,3 +13,6 @@ export const getClientRuntimeFileName = (mode) => {
13
13
  let n = "xanix-runtime";
14
14
  return mode === "development" ? n : uid(n, 16);
15
15
  };
16
+ export function getWebSocketPort() {
17
+ return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xanix",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",