@dcloudio/uni-vue-devtools 3.0.0-3061320221209001
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/runtime.es.js +130 -0
- package/dist/uni.compiler.js +84 -0
- package/lib/app/backend.js +10934 -0
- package/lib/app/hook.js +3963 -0
- package/lib/front/app.html +60 -0
- package/lib/front/devtools.js +118049 -0
- package/lib/front/icons/128.png +0 -0
- package/lib/front/icons/favicon.ico +0 -0
- package/lib/front/server.js +111 -0
- package/lib/mp/backend.js +11001 -0
- package/lib/mp/hook.js +3962 -0
- package/lib/web/backend.js +10958 -0
- package/lib/web/hook.js +3958 -0
- package/package.json +31 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
function getTarget() {
|
|
2
|
+
// eslint-disable-next-line no-restricted-globals
|
|
3
|
+
if (typeof window !== 'undefined') {
|
|
4
|
+
// eslint-disable-next-line no-restricted-globals
|
|
5
|
+
return window;
|
|
6
|
+
}
|
|
7
|
+
if (typeof globalThis !== 'undefined') {
|
|
8
|
+
return globalThis;
|
|
9
|
+
}
|
|
10
|
+
if (typeof global !== 'undefined') {
|
|
11
|
+
return global;
|
|
12
|
+
}
|
|
13
|
+
if (typeof my !== 'undefined') {
|
|
14
|
+
return my;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class Socket {
|
|
18
|
+
constructor(host) {
|
|
19
|
+
this.sid = '';
|
|
20
|
+
this.ackTimeout = 5000;
|
|
21
|
+
this.closed = false;
|
|
22
|
+
this._ackTimer = 0;
|
|
23
|
+
this._onCallbacks = {};
|
|
24
|
+
this.host = host;
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
this.connect();
|
|
27
|
+
}, 50);
|
|
28
|
+
}
|
|
29
|
+
connect() {
|
|
30
|
+
// close: 1
|
|
31
|
+
// message: 4
|
|
32
|
+
// noop: 6
|
|
33
|
+
// open: 0
|
|
34
|
+
// ping: 2
|
|
35
|
+
// pong: 3
|
|
36
|
+
// upgrade: 5
|
|
37
|
+
this._socket = uni.connectSocket({
|
|
38
|
+
url: `ws://${this.host}/socket.io/?EIO=4&transport=websocket`,
|
|
39
|
+
multiple: true,
|
|
40
|
+
complete(res) {
|
|
41
|
+
// NOOP
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
this._socket.onOpen((res) => {
|
|
45
|
+
// NOOP
|
|
46
|
+
});
|
|
47
|
+
this._socket.onMessage(({ data }) => {
|
|
48
|
+
if (typeof my !== 'undefined') {
|
|
49
|
+
data = data.data;
|
|
50
|
+
}
|
|
51
|
+
if (typeof data !== 'string') {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (data[0] === '0') {
|
|
55
|
+
this._send('40');
|
|
56
|
+
const res = JSON.parse(data.slice(1));
|
|
57
|
+
this.sid = res.sid;
|
|
58
|
+
}
|
|
59
|
+
else if (data[0] + data[1] === '40') {
|
|
60
|
+
this.sid = JSON.parse(data.slice(2)).sid;
|
|
61
|
+
this._trigger('connect');
|
|
62
|
+
}
|
|
63
|
+
else if (data === '3') {
|
|
64
|
+
this._send('2');
|
|
65
|
+
}
|
|
66
|
+
else if (data === '2') {
|
|
67
|
+
this._send('3');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const match = /\[.*\]/.exec(data);
|
|
71
|
+
if (!match)
|
|
72
|
+
return;
|
|
73
|
+
try {
|
|
74
|
+
const [event, args] = JSON.parse(match[0]);
|
|
75
|
+
this._trigger(event, args);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
console.error('Vue DevTools onMessage: ', err);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this._socket.onClose((res) => {
|
|
83
|
+
this.closed = true;
|
|
84
|
+
this._trigger('disconnect', res);
|
|
85
|
+
});
|
|
86
|
+
this._socket.onError((res) => {
|
|
87
|
+
console.error(res.errMsg);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
on(event, callback) {
|
|
91
|
+
(this._onCallbacks[event] || (this._onCallbacks[event] = [])).push(callback);
|
|
92
|
+
}
|
|
93
|
+
emit(event, data) {
|
|
94
|
+
if (this.closed) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this._heartbeat();
|
|
98
|
+
// message: 4 + parser.EVENT: 2
|
|
99
|
+
this._send(`42${JSON.stringify(typeof data !== 'undefined' ? [event, data] : [event])}`);
|
|
100
|
+
}
|
|
101
|
+
disconnect() {
|
|
102
|
+
clearTimeout(this._ackTimer);
|
|
103
|
+
if (this._socket && !this.closed) {
|
|
104
|
+
// message: 4 + close: 1
|
|
105
|
+
this._send('41');
|
|
106
|
+
this._socket.close({});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
_heartbeat() {
|
|
110
|
+
clearTimeout(this._ackTimer);
|
|
111
|
+
this._ackTimer = setTimeout(() => {
|
|
112
|
+
this._socket && this._socket.send({ data: '3' });
|
|
113
|
+
}, this.ackTimeout);
|
|
114
|
+
}
|
|
115
|
+
_send(data) {
|
|
116
|
+
this._socket && this._socket.send({ data });
|
|
117
|
+
}
|
|
118
|
+
_trigger(event, args) {
|
|
119
|
+
const callbacks = this._onCallbacks[event];
|
|
120
|
+
if (callbacks) {
|
|
121
|
+
callbacks.forEach((callback) => {
|
|
122
|
+
callback(args);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getTarget().__VUE_DEVTOOLS_SOCKET__ = new Socket(__VUE_DEVTOOLS_HOST__ + ':' + __VUE_DEVTOOLS_PORT__);
|
|
128
|
+
var runtime = {};
|
|
129
|
+
|
|
130
|
+
export { runtime as default };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var uniCliShared = require('@dcloudio/uni-cli-shared');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
10
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line no-restricted-globals
|
|
13
|
+
const { initDevtoolsServer } = require('../lib/front/server.js');
|
|
14
|
+
let copied = false;
|
|
15
|
+
let initializedServer = false;
|
|
16
|
+
const uniVueDevtoolsPlugin = () => {
|
|
17
|
+
return {
|
|
18
|
+
name: 'uni:vue-devtools',
|
|
19
|
+
config() {
|
|
20
|
+
return new Promise(async (resolve) => {
|
|
21
|
+
let __VUE_DEVTOOLS_HOST__ = 'localhost';
|
|
22
|
+
let __VUE_DEVTOOLS_PORT__ = 8098;
|
|
23
|
+
if (process.env.__VUE_PROD_DEVTOOLS__ && !initializedServer) {
|
|
24
|
+
initializedServer = true;
|
|
25
|
+
const { socketHost, socketPort } = await initDevtoolsServer();
|
|
26
|
+
__VUE_DEVTOOLS_HOST__ = socketHost;
|
|
27
|
+
__VUE_DEVTOOLS_PORT__ = socketPort;
|
|
28
|
+
}
|
|
29
|
+
resolve({
|
|
30
|
+
define: {
|
|
31
|
+
__VUE_PROD_DEVTOOLS__: process.env.__VUE_PROD_DEVTOOLS__ === 'true',
|
|
32
|
+
__VUE_DEVTOOLS_HOST__: JSON.stringify(`${__VUE_DEVTOOLS_HOST__}`),
|
|
33
|
+
__VUE_DEVTOOLS_PORT__: JSON.stringify(`${__VUE_DEVTOOLS_PORT__}`),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
generateBundle() {
|
|
39
|
+
if (copied || process.env.__VUE_PROD_DEVTOOLS__ !== 'true') {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
copied = true;
|
|
43
|
+
const vueDevtoolsDir = path__default["default"].resolve(process.env.UNI_OUTPUT_DIR, 'vue-devtools');
|
|
44
|
+
if (!fs__default["default"].existsSync(vueDevtoolsDir)) {
|
|
45
|
+
fs__default["default"].mkdirSync(vueDevtoolsDir, { recursive: true });
|
|
46
|
+
}
|
|
47
|
+
fs__default["default"].copyFileSync(path__default["default"].resolve(__dirname, '../lib/mp/backend.js'), path__default["default"].resolve(vueDevtoolsDir, 'backend.js'));
|
|
48
|
+
fs__default["default"].copyFileSync(path__default["default"].resolve(__dirname, '../lib/mp/hook.js'), path__default["default"].resolve(vueDevtoolsDir, 'hook.js'));
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
var index = () => {
|
|
53
|
+
return [
|
|
54
|
+
uniVueDevtoolsPlugin(),
|
|
55
|
+
uniCliShared.defineUniMainJsPlugin((opts) => {
|
|
56
|
+
let devtoolsCode = `;import '@dcloudio/uni-vue-devtools';`;
|
|
57
|
+
if (uniCliShared.isMiniProgramPlatform()) {
|
|
58
|
+
devtoolsCode += `require('./vue-devtools/hook.js');require('./vue-devtools/backend.js');`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const dir = process.env.UNI_PLATFORM === 'app' ? 'app' : 'web';
|
|
62
|
+
devtoolsCode += `import '@dcloudio/uni-vue-devtools/lib/${dir}/hook.js';import '@dcloudio/uni-vue-devtools/lib/${dir}/backend.js';`;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
name: 'uni:vue-devtools-main-js',
|
|
66
|
+
enforce: 'post',
|
|
67
|
+
transform(code, id) {
|
|
68
|
+
if (process.env.__VUE_PROD_DEVTOOLS__ !== 'true') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!opts.filter(id)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
code: devtoolsCode + code,
|
|
76
|
+
map: null,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}),
|
|
81
|
+
];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
module.exports = index;
|