@dcloudio/uni-vue-devtools 3.0.0-alpha-3060920221117001
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 +120 -0
- package/dist/uni.compiler.js +73 -0
- package/package.json +26 -0
|
@@ -0,0 +1,120 @@
|
|
|
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 my !== 'undefined') {
|
|
11
|
+
return my;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class Socket {
|
|
15
|
+
constructor(host) {
|
|
16
|
+
this.sid = '';
|
|
17
|
+
this.ackTimeout = 5000;
|
|
18
|
+
this.closed = false;
|
|
19
|
+
this._ackTimer = 0;
|
|
20
|
+
this._onCallbacks = {};
|
|
21
|
+
this.host = host;
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
this.connect();
|
|
24
|
+
}, 50);
|
|
25
|
+
}
|
|
26
|
+
connect() {
|
|
27
|
+
// close: 1
|
|
28
|
+
// message: 4
|
|
29
|
+
// noop: 6
|
|
30
|
+
// open: 0
|
|
31
|
+
// ping: 2
|
|
32
|
+
// pong: 3
|
|
33
|
+
// upgrade: 5
|
|
34
|
+
this._socket = uni.connectSocket({
|
|
35
|
+
url: `ws://${this.host}/socket.io/?EIO=4&transport=websocket`,
|
|
36
|
+
complete() {
|
|
37
|
+
// NOOP
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
this._socket.onOpen((res) => {
|
|
41
|
+
// NOOP
|
|
42
|
+
});
|
|
43
|
+
this._socket.onMessage(({ data }) => {
|
|
44
|
+
if (typeof data !== 'string') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (data[0] === '0') {
|
|
48
|
+
this._send('40');
|
|
49
|
+
const res = JSON.parse(data.slice(1));
|
|
50
|
+
this.sid = res.sid;
|
|
51
|
+
}
|
|
52
|
+
else if (data[0] + data[1] === '40') {
|
|
53
|
+
this.sid = JSON.parse(data.slice(2)).sid;
|
|
54
|
+
this._trigger('connect');
|
|
55
|
+
}
|
|
56
|
+
else if (data === '3') {
|
|
57
|
+
this._send('2');
|
|
58
|
+
}
|
|
59
|
+
else if (data === '2') {
|
|
60
|
+
this._send('3');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const match = /\[.*\]/.exec(data);
|
|
64
|
+
if (!match)
|
|
65
|
+
return;
|
|
66
|
+
try {
|
|
67
|
+
const [event, args] = JSON.parse(match[0]);
|
|
68
|
+
this._trigger(event, args);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error('Vue DevTools onMessage: ', err);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
this._socket.onClose((res) => {
|
|
76
|
+
this.closed = true;
|
|
77
|
+
this._trigger('disconnect', res);
|
|
78
|
+
});
|
|
79
|
+
this._socket.onError((res) => {
|
|
80
|
+
console.error(res.errMsg);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
on(event, callback) {
|
|
84
|
+
(this._onCallbacks[event] || (this._onCallbacks[event] = [])).push(callback);
|
|
85
|
+
}
|
|
86
|
+
emit(event, data) {
|
|
87
|
+
if (this.closed) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this._heartbeat();
|
|
91
|
+
// message: 4 + parser.EVENT: 2
|
|
92
|
+
this._send(`42${JSON.stringify(typeof data !== 'undefined' ? [event, data] : [event])}`);
|
|
93
|
+
}
|
|
94
|
+
disconnect() {
|
|
95
|
+
clearTimeout(this._ackTimer);
|
|
96
|
+
if (this._socket && !this.closed) {
|
|
97
|
+
// message: 4 + close: 1
|
|
98
|
+
this._send('41');
|
|
99
|
+
this._socket.close({});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
_heartbeat() {
|
|
103
|
+
clearTimeout(this._ackTimer);
|
|
104
|
+
this._ackTimer = setTimeout(() => {
|
|
105
|
+
this._socket && this._socket.send({ data: '3' });
|
|
106
|
+
}, this.ackTimeout);
|
|
107
|
+
}
|
|
108
|
+
_send(data) {
|
|
109
|
+
this._socket && this._socket.send({ data });
|
|
110
|
+
}
|
|
111
|
+
_trigger(event, args) {
|
|
112
|
+
const callbacks = this._onCallbacks[event];
|
|
113
|
+
if (callbacks) {
|
|
114
|
+
callbacks.forEach((callback) => {
|
|
115
|
+
callback(args);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
getTarget().__VUE_DEVTOOLS_SOCKET__ = new Socket(__VUE_DEVTOOLS_HOST__ + ':' + __VUE_DEVTOOLS_PORT__);
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
const uniVueDevtoolsPlugin = () => {
|
|
13
|
+
let copied = false;
|
|
14
|
+
return {
|
|
15
|
+
name: 'uni:vue-devtools',
|
|
16
|
+
config() {
|
|
17
|
+
return {
|
|
18
|
+
define: {
|
|
19
|
+
__VUE_PROD_DEVTOOLS__: process.env.__VUE_PROD_DEVTOOLS__ === 'true',
|
|
20
|
+
__VUE_DEVTOOLS_HOST__: JSON.stringify(process.env.__VUE_DEVTOOLS_HOST__ || 'localhost'),
|
|
21
|
+
__VUE_DEVTOOLS_PORT__: JSON.stringify(process.env.__VUE_DEVTOOLS_PORT__ || '8098'),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
generateBundle() {
|
|
26
|
+
// 仅处理小程序
|
|
27
|
+
if (!uniCliShared.isMiniProgramPlatform()) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (copied || process.env.__VUE_PROD_DEVTOOLS__ !== 'true') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
copied = true;
|
|
34
|
+
const vueDevtoolsDir = path__default["default"].resolve(process.env.UNI_OUTPUT_DIR, 'vue-devtools');
|
|
35
|
+
if (!fs__default["default"].existsSync(vueDevtoolsDir)) {
|
|
36
|
+
fs__default["default"].mkdirSync(vueDevtoolsDir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
fs__default["default"].copyFileSync(path__default["default"].resolve(__dirname, '../lib/mp/backend.js'), path__default["default"].resolve(vueDevtoolsDir, 'backend.js'));
|
|
39
|
+
fs__default["default"].copyFileSync(path__default["default"].resolve(__dirname, '../lib/mp/hook.js'), path__default["default"].resolve(vueDevtoolsDir, 'hook.js'));
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var index = () => [
|
|
44
|
+
uniVueDevtoolsPlugin(),
|
|
45
|
+
uniCliShared.defineUniMainJsPlugin((opts) => {
|
|
46
|
+
let devtoolsCode = `;import '@dcloudio/uni-vue-devtools';`;
|
|
47
|
+
if (uniCliShared.isMiniProgramPlatform()) {
|
|
48
|
+
devtoolsCode += `require('./vue-devtools/hook.js');require('./vue-devtools/backend.js');`;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const dir = process.env.UNI_PLATFORM === 'app' ? 'app' : 'web';
|
|
52
|
+
devtoolsCode += `import '@dcloudio/uni-vue-devtools/lib/${dir}/hook.js';import '@dcloudio/uni-vue-devtools/lib/${dir}/backend.js';`;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
name: 'uni:vue-devtools-main-js',
|
|
56
|
+
enforce: 'post',
|
|
57
|
+
transform(code, id) {
|
|
58
|
+
if (process.env.__VUE_PROD_DEVTOOLS__ !== 'true') {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!opts.filter(id)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
code: devtoolsCode + code,
|
|
66
|
+
map: null,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}),
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
module.exports = index;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcloudio/uni-vue-devtools",
|
|
3
|
+
"version": "3.0.0-alpha-3060920221117001",
|
|
4
|
+
"description": "uni-vue-devtools",
|
|
5
|
+
"main": "dist/runtime.es.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/dcloudio/uni-app.git",
|
|
12
|
+
"directory": "packages/uni-vue-devtools"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"uni-app": {
|
|
19
|
+
"name": "vue-devtools",
|
|
20
|
+
"title": "Vue Devtools",
|
|
21
|
+
"main": "dist/uni.compiler.js"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3060920221117001"
|
|
25
|
+
}
|
|
26
|
+
}
|