@vxrn/vite-native-hmr 1.1.320 → 1.1.321

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.
@@ -0,0 +1,128 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var devServerClient_exports = {};
24
+ __export(devServerClient_exports, {
25
+ client: () => client,
26
+ disable: () => disable,
27
+ enable: () => enable,
28
+ log: () => log,
29
+ registerBundle: () => registerBundle,
30
+ setup: () => setup
31
+ });
32
+ module.exports = __toCommonJS(devServerClient_exports);
33
+ var import_pretty_format = __toESM(require("pretty-format")), import_getDevServerLocation = require("./getDevServerLocation"), import_hmr_client = require("./hmr-client");
34
+ (0, import_hmr_client.loadHMRClient)();
35
+ class DevServerClient {
36
+ socket;
37
+ buffer = [];
38
+ constructor() {
39
+ const initSocket = () => {
40
+ const address = `ws://${(0, import_getDevServerLocation.getDevServerLocation)().host}/__client`;
41
+ this.socket = new WebSocket(address);
42
+ const onClose = (event) => {
43
+ console.warn(
44
+ "Disconnected from the Dev Server:",
45
+ event.message
46
+ ), this.socket = void 0;
47
+ };
48
+ this.socket.onclose = onClose, this.socket.onerror = onClose, this.socket.onopen = () => {
49
+ this.flushBuffer();
50
+ };
51
+ };
52
+ process.env.NODE_ENV === "development" && initSocket();
53
+ }
54
+ send(level, data) {
55
+ try {
56
+ this.socket?.send(
57
+ JSON.stringify({
58
+ type: "client-log",
59
+ level,
60
+ data: data.map(
61
+ (item) => typeof item == "string" ? item : (0, import_pretty_format.default)(item, {
62
+ escapeString: !0,
63
+ highlight: !0,
64
+ maxDepth: 3,
65
+ min: !0,
66
+ plugins: [
67
+ // @ts-expect-error
68
+ import_pretty_format.default.plugins.ReactElement
69
+ ]
70
+ })
71
+ )
72
+ })
73
+ );
74
+ } catch {
75
+ try {
76
+ this.socket?.send(
77
+ JSON.stringify({
78
+ type: "client-log",
79
+ level,
80
+ data: data.map((item, index) => {
81
+ try {
82
+ return typeof item == "string" ? item : JSON.stringify(item);
83
+ } catch (err) {
84
+ return `Error stringifying item at index ${index} - ${item} - ${err}`;
85
+ }
86
+ })
87
+ })
88
+ );
89
+ } catch (err) {
90
+ try {
91
+ this.socket?.send(
92
+ JSON.stringify({
93
+ type: "client-log",
94
+ level: "error",
95
+ data: ["error sending client log: " + err]
96
+ })
97
+ );
98
+ } catch {
99
+ }
100
+ }
101
+ }
102
+ }
103
+ flushBuffer() {
104
+ globalThis.__vxrnTmpLogs && (globalThis.__vxrnTmpLogs.forEach(({ level, data }) => {
105
+ this.buffer.push({ level, data });
106
+ }), delete globalThis.__vxrnTmpLogs);
107
+ for (const { level, data } of this.buffer)
108
+ this.send(level, data);
109
+ this.buffer = [];
110
+ }
111
+ log(level, data) {
112
+ if (level !== "groupEnd")
113
+ if (this.socket && this.socket.readyState === WebSocket.OPEN)
114
+ this.flushBuffer(), this.send(level, data);
115
+ else {
116
+ if (globalThis.__vxrnTmpLogs) return;
117
+ this.buffer.push({ level, data });
118
+ }
119
+ }
120
+ }
121
+ const client = new DevServerClient(), setup = () => {
122
+ }, enable = () => {
123
+ }, disable = () => {
124
+ }, registerBundle = () => {
125
+ }, log = (level, data) => {
126
+ client.log(level, data);
127
+ };
128
+ //# sourceMappingURL=devServerClient.js.map
@@ -0,0 +1,45 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var getDevServerLocation_exports = {};
24
+ __export(getDevServerLocation_exports, {
25
+ getDevServerLocation: () => getDevServerLocation
26
+ });
27
+ module.exports = __toCommonJS(getDevServerLocation_exports);
28
+ var import_getDevServer = __toESM(require("react-native/Libraries/Core/Devtools/getDevServer"));
29
+ let location;
30
+ function getDevServerLocation() {
31
+ if (!location) {
32
+ const { url } = (0, import_getDevServer.default)(), origin = url.replace(/\/$/, ""), host = origin.replace(/https?:\/\//, "");
33
+ location = {
34
+ host,
35
+ hostname: host.split(":")[0],
36
+ href: url,
37
+ origin,
38
+ pathname: url.split(host)[1],
39
+ port: host.split(":")[1],
40
+ protocol: (url.match(/^([a-z])+:\/\//) || [void 0, void 0])[1]
41
+ };
42
+ }
43
+ return location;
44
+ }
45
+ //# sourceMappingURL=getDevServerLocation.js.map
@@ -0,0 +1,120 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var hmr_client_exports = {};
16
+ __export(hmr_client_exports, {
17
+ loadHMRClient: () => loadHMRClient
18
+ });
19
+ module.exports = __toCommonJS(hmr_client_exports);
20
+ var import_getDevServerLocation = require("./getDevServerLocation");
21
+ class HMRClient {
22
+ constructor(app) {
23
+ this.app = app;
24
+ const port = process.env.REACT_NATIVE_SERVER_PUBLIC_PORT || 8081;
25
+ this.url = `ws://${(0, import_getDevServerLocation.getDevServerLocation)().hostname}:${port}/__hmr?platform=${process.env.REACT_NATIVE_PLATFORM || "ios"}`, this.socket = new WebSocket(this.url), console.info(" \u24F5 [hmr] connecting..."), this.socket.onopen = () => {
26
+ console.info(" \u24F5 [hmr] connected");
27
+ }, this.socket.onclose = () => {
28
+ console.info(` \u24F5 [hmr] disconnected ${this.url}`);
29
+ }, this.socket.onerror = (event) => {
30
+ console.error(" \u24F5 [hmr] error", event);
31
+ }, this.socket.onmessage = (event) => {
32
+ try {
33
+ const data = JSON.parse(event.data.toString());
34
+ this.processMessage(data);
35
+ } catch (error) {
36
+ console.warn(" \u24F5 [hmr] invalid message", error);
37
+ }
38
+ };
39
+ }
40
+ url;
41
+ socket;
42
+ lastHash = "";
43
+ upToDate(hash) {
44
+ return hash && (this.lastHash = hash), this.lastHash === __webpack_hash__;
45
+ }
46
+ processMessage(message) {
47
+ switch (message.action) {
48
+ case "building":
49
+ this.app.LoadingView.showMessage("Rebuilding...", "refresh"), console.info(" \u24F5 [hmr] bundle rebuilding", {
50
+ name: message.body?.name
51
+ });
52
+ break;
53
+ // biome-ignore lint/suspicious/noFallthroughSwitchClause: <explanation>
54
+ case "built":
55
+ console.info(" \u24F5 [hmr] bundle rebuilt", {
56
+ name: message.body?.name,
57
+ time: message.body?.time
58
+ });
59
+ // Fall through
60
+ case "sync":
61
+ if (!message.body) {
62
+ console.warn(" \u24F5 [hmr] message body is empty");
63
+ return;
64
+ }
65
+ if (message.body.errors?.length) {
66
+ message.body.errors.forEach((error) => {
67
+ console.error("Cannot apply update due to error:", error);
68
+ }), this.app.LoadingView.hide();
69
+ return;
70
+ }
71
+ message.body.warnings?.length && message.body.warnings.forEach((warning) => {
72
+ console.warn(" \u24F5 [hmr] bundle contains warnings:", warning);
73
+ }), this.applyUpdate(message.body);
74
+ }
75
+ }
76
+ applyUpdate(update) {
77
+ if (!module.hot)
78
+ throw new Error(" \u24F5 [hmr] hot Module Replacement is disabled.");
79
+ !this.upToDate(update.hash) && module.hot.status() === "idle" && (console.info(" \u24F5 [hmr] checking for updates on the server..."), this.checkUpdates(update));
80
+ }
81
+ checkUpdates(update) {
82
+ try {
83
+ this.app.LoadingView.showMessage("Refreshing...", "refresh"), module.hot?.check(!1).then((updatedModules) => {
84
+ if (!updatedModules) {
85
+ console.warn(" \u24F5 [hmr] cannot find update - full reload needed"), this.app.reload();
86
+ return;
87
+ }
88
+ module.hot?.apply({
89
+ ignoreDeclined: !0,
90
+ ignoreUnaccepted: !1,
91
+ ignoreErrored: !1,
92
+ onDeclined: (data) => {
93
+ console.warn(" \u24F5 [hmr] ignored an update due to declined module", {
94
+ chain: data.chain
95
+ });
96
+ }
97
+ }).then((renewedModules) => {
98
+ this.upToDate() || this.checkUpdates(update);
99
+ const unacceptedModules = updatedModules.filter((moduleId) => renewedModules && renewedModules.indexOf(moduleId) < 0);
100
+ unacceptedModules.length ? (console.warn(" \u24F5 [hmr] not every module was accepted - full reload needed", {
101
+ unacceptedModules
102
+ }), this.app.reload()) : (console.info(" \u24F5 [hmr] renewed modules - app is up to date", {
103
+ renewedModules
104
+ }), this.app.dismissErrors());
105
+ });
106
+ });
107
+ } catch (error) {
108
+ module.hot?.status() === "fail" || module.hot?.status() === "abort" ? (console.warn(" \u24F5 [hmr] cannot check for update - full reload needed"), console.warn("[hmr]", error), this.app.reload()) : console.warn(" \u24F5 [hmr] update check failed", { error });
109
+ } finally {
110
+ this.app.LoadingView.hide();
111
+ }
112
+ }
113
+ }
114
+ const loadHMRClient = () => {
115
+ const { DevSettings, Platform } = require("react-native-web"), LoadingView = require("react-native/Libraries/Utilities/LoadingView"), reload = () => DevSettings.reload(), dismissErrors = () => {
116
+ Platform.OS === "ios" ? require("react-native/Libraries/NativeModules/specs/NativeRedBox").default?.dismiss?.() : require("react-native/Libraries/Core/NativeExceptionsManager").default?.dismissRedbox(), require("react-native/Libraries/LogBox/Data/LogBoxData").clear();
117
+ };
118
+ new HMRClient({ reload, dismissErrors, LoadingView });
119
+ };
120
+ //# sourceMappingURL=hmr-client.js.map
@@ -0,0 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var src_exports = {};
16
+ __export(src_exports, {
17
+ default: () => src_default
18
+ });
19
+ module.exports = __toCommonJS(src_exports);
20
+ __reExport(src_exports, require("./devServerClient"), module.exports);
21
+ var import_devServerClient = require("./devServerClient"), src_default = import_devServerClient.client;
22
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/vite-native-hmr",
3
- "version": "1.1.320",
3
+ "version": "1.1.321",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -37,7 +37,7 @@
37
37
  "pretty-format": "^28.1.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@tamagui/build": "^1.115.0",
40
+ "@tamagui/build": "^1.116.4",
41
41
  "react-native": "0.74.5"
42
42
  },
43
43
  "peerDependencies": {
File without changes