Skip to content

Commit ae89882

Browse files
committed
chore(release): 1.5.1
1 parent b5d4011 commit ae89882

File tree

3 files changed

+96
-100
lines changed

3 files changed

+96
-100
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-vue-devtools",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "A NativeScript-Vue plugin for connecting to the standalone vue-devtools",
55
"main": "dist/index.js",
66
"nativescript": {
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"build": "tsc",
13-
"prepublish": "npm run build"
13+
"prepare": "npm run build"
1414
},
1515
"files": [
1616
"dist"

src/index.ts

+92-96
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,131 @@
11
import devtools from "@vue/devtools";
22
import { isAndroid } from "@nativescript/core";
3-
import * as toasty from "@triniwiz/nativescript-toasty";
4-
import * as nsSocketIo from "@triniwiz/nativescript-socketio";
53
import type { VueConstructor } from "vue";
64

75
if (!global.performance) {
8-
(global.performance as any) = {};
6+
(global.performance as any) = {};
97
}
108

119
if (!global.performance.now) {
12-
const nowOffset = Date.now();
10+
const nowOffset = Date.now();
1311

14-
global.performance.now = function now() {
15-
return Date.now() - nowOffset;
16-
};
12+
global.performance.now = function now() {
13+
return Date.now() - nowOffset;
14+
};
1715
}
1816

1917
if (!global.requestAnimationFrame) {
20-
global.requestAnimationFrame = function raf(cb) {
21-
return setTimeout(cb, 1000 / 60);
22-
};
18+
global.requestAnimationFrame = function raf(cb) {
19+
return setTimeout(cb, 1000 / 60);
20+
};
2321
}
2422

2523
// fixes a crash when running VueDevtools
2624
if (!global.HTMLElement) {
27-
(global.HTMLElement as any) = function () {
28-
return false;
29-
};
25+
(global.HTMLElement as any) = function () {
26+
return false;
27+
};
3028
}
3129

3230
/**
3331
* Returns the correct address for the host machine when running on emulator
3432
*/
3533
const getServerIpAddress = (host: string | null, port: number): string => {
36-
if (host) {
37-
return `${host}:${port}`;
34+
if (host) {
35+
return `${host}:${port}`;
36+
}
37+
38+
if (isAndroid) {
39+
// @ts-ignore
40+
const FINGERPRINT = android.os.Build.FINGERPRINT;
41+
if (FINGERPRINT.includes("vbox")) {
42+
// running on genymotion
43+
return `10.0.3.2:${port}`;
44+
} else if (FINGERPRINT.includes("generic")) {
45+
// running on android emulator
46+
return `10.0.2.2:${port}`;
3847
}
48+
}
3949

40-
if (isAndroid) {
41-
// @ts-ignore
42-
const FINGERPRINT = android.os.Build.FINGERPRINT;
43-
if (FINGERPRINT.includes("vbox")) {
44-
// running on genymotion
45-
return `10.0.3.2:${port}`;
46-
} else if (FINGERPRINT.includes("generic")) {
47-
// running on android emulator
48-
return `10.0.2.2:${port}`;
49-
}
50-
}
51-
52-
// ios simulator uses localhost
53-
return `127.0.0.1:${port}`;
50+
// ios simulator uses localhost
51+
return `127.0.0.1:${port}`;
5452
};
5553

5654
// Wrap the toast message in a try, devtool still work without toaster
5755
const showToast = (message: string): void => {
58-
try {
59-
const { Toasty } = toasty;
60-
new Toasty({
61-
text: message,
62-
backgroundColor: "#53ba82",
63-
yAxisOffset: 50,
64-
}).show();
65-
} catch (error) {
66-
console.log(error);
67-
}
56+
try {
57+
const { Toasty } = require("@triniwiz/nativescript-toasty");
58+
new Toasty({
59+
text: message,
60+
backgroundColor: "#53ba82",
61+
yAxisOffset: 50,
62+
}).show();
63+
} catch (error) {
64+
console.log(`[nativescript-vue-devtools] ${message}`);
65+
}
6866
};
6967

7068
const install = (
71-
Vue: VueConstructor,
72-
{ debug = false, host = null, port = 8098 } = {}
69+
Vue: VueConstructor,
70+
{ debug = false, host = null, port = 8098 } = {}
7371
): void => {
74-
// ensure all dependencies are available and bail out if anything is missing
75-
try {
76-
require.resolve("@vue/devtools");
77-
} catch (e) {
78-
console.log(
79-
"[nativescript-vue-devtools] skipping install due to missing dependencies.\n\n",
80-
e,
81-
"\n\n"
82-
);
83-
return;
84-
}
85-
86-
const startApp = Vue.prototype.$start;
87-
88-
Vue.prototype.$start = function () {
89-
const setupDevtools = () => {
90-
const options = {
91-
app: this,
92-
showToast,
93-
io() {
94-
try {
95-
const { SocketIO } = nsSocketIo;
96-
const address = `http://${getServerIpAddress(
97-
host,
98-
port
99-
)}`;
100-
// this line causes a crash. the socketio plugin needs to be updated to nativescript version 8.0
101-
let socketIO = new SocketIO(address, { debug: debug });
102-
socketIO.connect();
103-
return socketIO;
104-
} catch (error) {
105-
console.log(error);
106-
// prevent crashing by returning a noop stub
107-
return {
108-
on() {},
109-
emit() {},
110-
};
111-
}
112-
},
72+
// ensure all dependencies are available and bail out if anything is missing
73+
try {
74+
require.resolve("@vue/devtools");
75+
require.resolve("@triniwiz/nativescript-socketio");
76+
} catch (e) {
77+
console.log(
78+
"[nativescript-vue-devtools] skipping install due to missing dependencies.\n\n",
79+
e,
80+
"\n\n"
81+
);
82+
return;
83+
}
84+
85+
const startApp = Vue.prototype.$start;
86+
87+
Vue.prototype.$start = function () {
88+
const setupDevtools = () => {
89+
const options = {
90+
app: this,
91+
showToast,
92+
io() {
93+
try {
94+
const { SocketIO } = require("@triniwiz/nativescript-socketio");
95+
const address = `http://${getServerIpAddress(host, port)}`;
96+
// this line causes a crash. the socketio plugin needs to be updated to nativescript version 8.0
97+
let socketIO = new SocketIO(address, { debug: debug });
98+
socketIO.connect();
99+
return socketIO;
100+
} catch (error) {
101+
console.log(error);
102+
// prevent crashing by returning a noop stub
103+
return {
104+
on() {},
105+
emit() {},
113106
};
107+
}
108+
},
109+
};
114110

115-
// vue-dev-tools type files are outdated so this is to get around that
116-
(devtools as any).connect("ws://localhost", port, options);
117-
(devtools as any).init(Vue);
118-
};
119-
120-
if (isAndroid) {
121-
setupDevtools();
122-
} else {
123-
// on ios we need to delay the call because the socket connection is not established
124-
// if called too early in the application startup process
125-
// we might need to add a delay to the setTimeout in the future
126-
setTimeout(setupDevtools);
127-
}
128-
129-
return startApp.call(this);
111+
// vue-dev-tools type files are outdated so this is to get around that
112+
(devtools as any).connect("ws://localhost", port, options);
113+
(devtools as any).init(Vue);
130114
};
115+
116+
if (isAndroid) {
117+
setupDevtools();
118+
} else {
119+
// on ios we need to delay the call because the socket connection is not established
120+
// if called too early in the application startup process
121+
// we might need to add a delay to the setTimeout in the future
122+
setTimeout(setupDevtools);
123+
}
124+
125+
return startApp.call(this);
126+
};
131127
};
132128

133129
export default {
134-
install,
130+
install,
135131
};

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"target": "ES2017",
4-
"module": "CommonJS",
5-
"sourceMap": true,
4+
"module": "esnext",
65
"moduleResolution": "node",
6+
"sourceMap": true,
77
"declaration": true,
88
"strict": true,
99
"esModuleInterop": true,

0 commit comments

Comments
 (0)