@tarojs/plugin-vue-devtools 3.5.0-beta.4 → 3.5.0-beta.7

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.
Files changed (4) hide show
  1. package/dist/index.js +72 -72
  2. package/dist/runtime.js +167 -167
  3. package/package.json +12 -12
  4. package/LICENSE +0 -21
package/dist/index.js CHANGED
@@ -5,78 +5,78 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var helper = require('@tarojs/helper');
6
6
  var shared = require('@tarojs/shared');
7
7
 
8
- const spawn = require('cross-spawn');
9
- const detectPort = require('detect-port');
10
- function index (ctx, options) {
11
- if (process.env.NODE_ENV === 'production' || options.enabled === false)
12
- return;
13
- const port = Number(options.port || '8098');
14
- detectPort(port, (err, availablePort) => {
15
- if (err) {
16
- // eslint-disable-next-line no-console
17
- console.log(`detectport 错误:${err}`);
18
- }
19
- if (availablePort === port) {
20
- // eslint-disable-next-line no-console
21
- console.log(helper.chalk.yellow('\n提示 ') + '正在启动 vue-devtools...\n');
22
- spawn(require.resolve('@vue/devtools/bin'), { env: Object.assign(Object.assign({}, process.env), { PORT: port }) });
23
- }
24
- });
25
- ctx.registerMethod({
26
- name: 'onSetupClose',
27
- fn(platform) {
28
- injectRuntimePath(platform);
29
- }
30
- });
31
- ctx.modifyWebpackChain(({ chain }) => {
32
- chain
33
- .plugin('definePlugin')
34
- .tap(args => {
35
- const config = args[0];
36
- config.__VUE_DEVTOOLS_PORT__ = port;
37
- config.ENABLE_SIZE_APIS = true;
38
- config.ENABLE_CONTAINS = true;
39
- return args;
40
- });
41
- chain
42
- .plugin('providerPlugin')
43
- .tap(args => {
44
- const config = args[0];
45
- config.globalThis = ['@tarojs/runtime', 'window'];
46
- config.HTMLElement = ['@tarojs/runtime', 'TaroElement'];
47
- return args;
48
- });
49
- });
50
- ctx.modifyRunnerOpts(({ opts }) => {
51
- var _a;
52
- if (shared.isString(opts.compiler)) {
53
- opts.compiler = {
54
- type: opts.compiler
55
- };
56
- }
57
- if (opts.compiler.type === 'webpack5') {
58
- (_a = opts.compiler).prebundle || (_a.prebundle = {});
59
- const prebundle = opts.compiler.prebundle;
60
- if (prebundle.enable === false)
61
- return;
62
- prebundle.webpack || (prebundle.webpack = {});
63
- const webpackConfig = prebundle.webpack;
64
- webpackConfig.provide || (webpackConfig.provide = []);
65
- webpackConfig.provide.push(function (obj, taroRuntimeBundlePath) {
66
- obj.globalThis = [taroRuntimeBundlePath, 'window'];
67
- obj.HTMLElement = [taroRuntimeBundlePath, 'TaroElement'];
68
- });
69
- }
70
- });
71
- }
72
- function injectRuntimePath(platform) {
73
- const injectedPath = 'post:@tarojs/plugin-vue-devtools/dist/runtime';
74
- if (shared.isArray(platform.runtimePath)) {
75
- platform.runtimePath.push(injectedPath);
76
- }
77
- else if (shared.isString(platform.runtimePath)) {
78
- platform.runtimePath = [platform.runtimePath, injectedPath];
79
- }
8
+ const spawn = require('cross-spawn');
9
+ const detectPort = require('detect-port');
10
+ function index (ctx, options) {
11
+ if (process.env.NODE_ENV === 'production' || options.enabled === false)
12
+ return;
13
+ const port = Number(options.port || '8098');
14
+ detectPort(port, (err, availablePort) => {
15
+ if (err) {
16
+ // eslint-disable-next-line no-console
17
+ console.log(`detectport 错误:${err}`);
18
+ }
19
+ if (availablePort === port) {
20
+ // eslint-disable-next-line no-console
21
+ console.log(helper.chalk.yellow('\n提示 ') + '正在启动 vue-devtools...\n');
22
+ spawn(require.resolve('@vue/devtools/bin'), { env: Object.assign(Object.assign({}, process.env), { PORT: port }) });
23
+ }
24
+ });
25
+ ctx.registerMethod({
26
+ name: 'onSetupClose',
27
+ fn(platform) {
28
+ injectRuntimePath(platform);
29
+ }
30
+ });
31
+ ctx.modifyWebpackChain(({ chain }) => {
32
+ chain
33
+ .plugin('definePlugin')
34
+ .tap(args => {
35
+ const config = args[0];
36
+ config.__VUE_DEVTOOLS_PORT__ = port;
37
+ config.ENABLE_SIZE_APIS = true;
38
+ config.ENABLE_CONTAINS = true;
39
+ return args;
40
+ });
41
+ chain
42
+ .plugin('providerPlugin')
43
+ .tap(args => {
44
+ const config = args[0];
45
+ config.globalThis = ['@tarojs/runtime', 'window'];
46
+ config.HTMLElement = ['@tarojs/runtime', 'TaroElement'];
47
+ return args;
48
+ });
49
+ });
50
+ ctx.modifyRunnerOpts(({ opts }) => {
51
+ var _a;
52
+ if (shared.isString(opts.compiler)) {
53
+ opts.compiler = {
54
+ type: opts.compiler
55
+ };
56
+ }
57
+ if (opts.compiler.type === 'webpack5') {
58
+ (_a = opts.compiler).prebundle || (_a.prebundle = {});
59
+ const prebundle = opts.compiler.prebundle;
60
+ if (prebundle.enable === false)
61
+ return;
62
+ prebundle.webpack || (prebundle.webpack = {});
63
+ const webpackConfig = prebundle.webpack;
64
+ webpackConfig.provide || (webpackConfig.provide = []);
65
+ webpackConfig.provide.push(function (obj, taroRuntimeBundlePath) {
66
+ obj.globalThis = [taroRuntimeBundlePath, 'window'];
67
+ obj.HTMLElement = [taroRuntimeBundlePath, 'TaroElement'];
68
+ });
69
+ }
70
+ });
71
+ }
72
+ function injectRuntimePath(platform) {
73
+ const injectedPath = 'post:@tarojs/plugin-vue-devtools/dist/runtime';
74
+ if (shared.isArray(platform.runtimePath)) {
75
+ platform.runtimePath.push(injectedPath);
76
+ }
77
+ else if (shared.isString(platform.runtimePath)) {
78
+ platform.runtimePath = [platform.runtimePath, injectedPath];
79
+ }
80
80
  }
81
81
 
82
82
  exports["default"] = index;
package/dist/runtime.js CHANGED
@@ -1,175 +1,175 @@
1
1
  import Taro from '@tarojs/taro';
2
2
 
3
- const ALIPAY = 'alipay';
4
- class WebSocket {
5
- constructor(url) {
6
- this.url = url;
7
- this.readyState = this.CONNECTING;
8
- Taro.connectSocket({
9
- url
10
- })
11
- .then(ws => {
12
- this._ws = ws;
13
- ws.onClose(res => {
14
- this.readyState = this.CLOSED;
15
- this.onclose(res);
16
- });
17
- ws.onError(res => {
18
- this.readyState = this.CLOSED;
19
- this.onerror(res);
20
- });
21
- ws.onMessage(res => {
22
- this.onmessage(res);
23
- });
24
- if (this.readyState !== this.OPEN) {
25
- ws.onOpen(res => {
26
- this.readyState = this.OPEN;
27
- this.onopen(res);
28
- });
29
- }
30
- else {
31
- // 支付宝全局的 onSocketOpen 已触发过了,直接调用 onopen
32
- this.onopen({});
33
- }
34
- });
35
- // 支付宝只支持一个 socket 连接,且 onSocketOpen 的触发时机比 connectSocket 回调的时机早
36
- if (process.env.TARO_ENV === ALIPAY) {
37
- Taro.onSocketOpen(() => {
38
- this.readyState = this.OPEN;
39
- });
40
- }
41
- }
42
- send(data) {
43
- this._ws.send({
44
- data
45
- });
46
- }
47
- close(code, reason) {
48
- this.readyState = this.CLOSING;
49
- this._ws.close({
50
- code: code || 1000,
51
- reason: reason || ''
52
- });
53
- }
54
- get CONNECTING() {
55
- return 0;
56
- }
57
- get OPEN() {
58
- return 1;
59
- }
60
- get CLOSING() {
61
- return 2;
62
- }
63
- get CLOSED() {
64
- return 3;
65
- }
3
+ const ALIPAY = 'alipay';
4
+ class WebSocket {
5
+ constructor(url) {
6
+ this.url = url;
7
+ this.readyState = this.CONNECTING;
8
+ Taro.connectSocket({
9
+ url
10
+ })
11
+ .then(ws => {
12
+ this._ws = ws;
13
+ ws.onClose(res => {
14
+ this.readyState = this.CLOSED;
15
+ this.onclose(res);
16
+ });
17
+ ws.onError(res => {
18
+ this.readyState = this.CLOSED;
19
+ this.onerror(res);
20
+ });
21
+ ws.onMessage(res => {
22
+ this.onmessage(res);
23
+ });
24
+ if (this.readyState !== this.OPEN) {
25
+ ws.onOpen(res => {
26
+ this.readyState = this.OPEN;
27
+ this.onopen(res);
28
+ });
29
+ }
30
+ else {
31
+ // 支付宝全局的 onSocketOpen 已触发过了,直接调用 onopen
32
+ this.onopen({});
33
+ }
34
+ });
35
+ // 支付宝只支持一个 socket 连接,且 onSocketOpen 的触发时机比 connectSocket 回调的时机早
36
+ if (process.env.TARO_ENV === ALIPAY) {
37
+ Taro.onSocketOpen(() => {
38
+ this.readyState = this.OPEN;
39
+ });
40
+ }
41
+ }
42
+ send(data) {
43
+ this._ws.send({
44
+ data
45
+ });
46
+ }
47
+ close(code, reason) {
48
+ this.readyState = this.CLOSING;
49
+ this._ws.close({
50
+ code: code || 1000,
51
+ reason: reason || ''
52
+ });
53
+ }
54
+ get CONNECTING() {
55
+ return 0;
56
+ }
57
+ get OPEN() {
58
+ return 1;
59
+ }
60
+ get CLOSING() {
61
+ return 2;
62
+ }
63
+ get CLOSED() {
64
+ return 3;
65
+ }
66
66
  }
67
67
 
68
- function createSocket(host) {
69
- class Socket {
70
- constructor() {
71
- this.isClosed = false;
72
- this.connect();
73
- }
74
- connect() {
75
- Taro.request({
76
- url: `http://${host}/socket.io/?EIO=3&transport=polling`
77
- })
78
- .then(({ data }) => {
79
- var _a;
80
- const target = ((_a = /{.*}/.exec(data)) === null || _a === void 0 ? void 0 : _a[0]) || '';
81
- try {
82
- const res = JSON.parse(target);
83
- this.sid = res.sid;
84
- this.ackTimeout = res.pingTimeout;
85
- this.initWS();
86
- }
87
- catch (error) {
88
- console.error('Vue DevTools 握手失败: ', error);
89
- }
90
- })
91
- .catch(() => {
92
- console.warn('请打开 Vue DevTools');
93
- });
94
- }
95
- on(event, cb) {
96
- this[`on-${event}`] = cb;
97
- }
98
- emit(event, data) {
99
- if (this.isClosed)
100
- return;
101
- // heart break
102
- clearTimeout(this.ack);
103
- this.ack = setTimeout(() => this._ws.send('2'), 5000);
104
- const msgList = data ? [event, data] : [event];
105
- const msg = JSON.stringify(msgList);
106
- // message: 4 + parser.EVENT: 2
107
- this._ws.send('42' + msg);
108
- }
109
- initWS() {
110
- const ws = new WebSocket(`ws://${host}/socket.io/?EIO=3&transport=websocket&sid=${this.sid}`);
111
- ws.onopen = () => {
112
- // close: 1
113
- // message: 4
114
- // noop: 6
115
- // open: 0
116
- // ping: 2
117
- // pong: 3
118
- // upgrade: 5
119
- ws.send('2probe');
120
- };
121
- ws.onmessage = ({ data }) => {
122
- if (data === '3probe') {
123
- // upgrade: 5
124
- ws.send('5');
125
- this['on-connect']();
126
- }
127
- else if (data === '3') {
128
- // pong
129
- this.ack = setTimeout(() => ws.send('2'), 5000);
130
- }
131
- else {
132
- const match = /\[.*\]/.exec(data);
133
- if (!match)
134
- return;
135
- try {
136
- const [event, args = []] = JSON.parse(match[0]);
137
- const cb = this[`on-${event}`];
138
- if (typeof cb === 'function') {
139
- // @TODO: 元素高亮暂时不实现,需要魔改 backend 的代码
140
- const _args = args.filter(arg => arg.event.indexOf(':mouse-over') === -1);
141
- cb(_args);
142
- }
143
- }
144
- catch (error) {
145
- console.error('Vue DevTools 解析 socket message 失败: ', error);
146
- }
147
- }
148
- };
149
- ws.onclose = reason => {
150
- this.isClosed = true;
151
- this['on-disconnect'](reason);
152
- };
153
- ws.onerror = err => console.error('[Taro Socket]onerror', err);
154
- this._ws = ws;
155
- }
156
- disconnect() {
157
- this.clean();
158
- if (!this.isClosed) {
159
- // message: 4 + close: 1
160
- this._ws.send('41');
161
- this._ws.close();
162
- }
163
- }
164
- clean() {
165
- clearTimeout(this.ack);
166
- }
167
- }
168
- return new Socket();
68
+ function createSocket(host) {
69
+ class Socket {
70
+ constructor() {
71
+ this.isClosed = false;
72
+ this.connect();
73
+ }
74
+ connect() {
75
+ Taro.request({
76
+ url: `http://${host}/socket.io/?EIO=3&transport=polling`
77
+ })
78
+ .then(({ data }) => {
79
+ var _a;
80
+ const target = ((_a = /{.*}/.exec(data)) === null || _a === void 0 ? void 0 : _a[0]) || '';
81
+ try {
82
+ const res = JSON.parse(target);
83
+ this.sid = res.sid;
84
+ this.ackTimeout = res.pingTimeout;
85
+ this.initWS();
86
+ }
87
+ catch (error) {
88
+ console.error('Vue DevTools 握手失败: ', error);
89
+ }
90
+ })
91
+ .catch(() => {
92
+ console.warn('请打开 Vue DevTools');
93
+ });
94
+ }
95
+ on(event, cb) {
96
+ this[`on-${event}`] = cb;
97
+ }
98
+ emit(event, data) {
99
+ if (this.isClosed)
100
+ return;
101
+ // heart break
102
+ clearTimeout(this.ack);
103
+ this.ack = setTimeout(() => this._ws.send('2'), 5000);
104
+ const msgList = data ? [event, data] : [event];
105
+ const msg = JSON.stringify(msgList);
106
+ // message: 4 + parser.EVENT: 2
107
+ this._ws.send('42' + msg);
108
+ }
109
+ initWS() {
110
+ const ws = new WebSocket(`ws://${host}/socket.io/?EIO=3&transport=websocket&sid=${this.sid}`);
111
+ ws.onopen = () => {
112
+ // close: 1
113
+ // message: 4
114
+ // noop: 6
115
+ // open: 0
116
+ // ping: 2
117
+ // pong: 3
118
+ // upgrade: 5
119
+ ws.send('2probe');
120
+ };
121
+ ws.onmessage = ({ data }) => {
122
+ if (data === '3probe') {
123
+ // upgrade: 5
124
+ ws.send('5');
125
+ this['on-connect']();
126
+ }
127
+ else if (data === '3') {
128
+ // pong
129
+ this.ack = setTimeout(() => ws.send('2'), 5000);
130
+ }
131
+ else {
132
+ const match = /\[.*\]/.exec(data);
133
+ if (!match)
134
+ return;
135
+ try {
136
+ const [event, args = []] = JSON.parse(match[0]);
137
+ const cb = this[`on-${event}`];
138
+ if (typeof cb === 'function') {
139
+ // @TODO: 元素高亮暂时不实现,需要魔改 backend 的代码
140
+ const _args = args.filter(arg => arg.event.indexOf(':mouse-over') === -1);
141
+ cb(_args);
142
+ }
143
+ }
144
+ catch (error) {
145
+ console.error('Vue DevTools 解析 socket message 失败: ', error);
146
+ }
147
+ }
148
+ };
149
+ ws.onclose = reason => {
150
+ this.isClosed = true;
151
+ this['on-disconnect'](reason);
152
+ };
153
+ ws.onerror = err => console.error('[Taro Socket]onerror', err);
154
+ this._ws = ws;
155
+ }
156
+ disconnect() {
157
+ this.clean();
158
+ if (!this.isClosed) {
159
+ // message: 4 + close: 1
160
+ this._ws.send('41');
161
+ this._ws.close();
162
+ }
163
+ }
164
+ clean() {
165
+ clearTimeout(this.ack);
166
+ }
167
+ }
168
+ return new Socket();
169
169
  }
170
170
 
171
- const { connect } = require('./backend');
172
- connect('localhost', __VUE_DEVTOOLS_PORT__, {
173
- io: createSocket
171
+ const { connect } = require('./backend');
172
+ connect('localhost', __VUE_DEVTOOLS_PORT__, {
173
+ io: createSocket
174
174
  });
175
175
  //# sourceMappingURL=runtime.js.map
package/package.json CHANGED
@@ -1,14 +1,8 @@
1
1
  {
2
2
  "name": "@tarojs/plugin-vue-devtools",
3
- "version": "3.5.0-beta.4",
3
+ "version": "3.5.0-beta.7",
4
4
  "description": "Taro 小程序端支持使用 Vue DevTools 的插件",
5
5
  "main": "index.js",
6
- "scripts": {
7
- "dev": "rollup -c -w",
8
- "build": "rollup -c",
9
- "test": "jest",
10
- "test:dev": "jest --watch"
11
- },
12
6
  "files": [
13
7
  "dist",
14
8
  "index.js",
@@ -28,12 +22,18 @@
28
22
  },
29
23
  "homepage": "https://github.com/NervJS/taro#readme",
30
24
  "dependencies": {
31
- "@tarojs/helper": "3.5.0-beta.4",
32
- "@tarojs/shared": "3.5.0-beta.4",
33
- "@tarojs/taro": "3.5.0-beta.4",
25
+ "@tarojs/helper": "3.5.0-beta.7",
26
+ "@tarojs/service": "3.5.0-beta.7",
27
+ "@tarojs/shared": "3.5.0-beta.7",
28
+ "@tarojs/taro": "3.5.0-beta.7",
34
29
  "@vue/devtools": "6.0.0-beta.15",
35
30
  "cross-spawn": "^7.0.3",
36
31
  "detect-port": "^1.3.0"
37
32
  },
38
- "gitHead": "7aca7841ed7e2af1b182ff5d24e91f44730ce783"
39
- }
33
+ "scripts": {
34
+ "dev": "rollup -c -w",
35
+ "build": "rollup -c",
36
+ "test": "jest",
37
+ "test:dev": "jest --watch"
38
+ }
39
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.