@tomjs/vite-plugin-vscode 2.6.0 → 3.0.0
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/README.md +9 -0
- package/README.zh_CN.md +9 -0
- package/dist/client.global.js +3 -24
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/index.mjs +2 -3
- package/dist/webview.js +0 -10
- package/dist/webview.mjs +0 -10
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ In development mode, inject the same code of [@tomjs/vscode-extension-webview](h
|
|
|
14
14
|
- Simple configuration, focus on business
|
|
15
15
|
- Support `esm` and `cjs`
|
|
16
16
|
- Support webview `HMR`
|
|
17
|
+
- Support `acquireVsCodeApi` of [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview)
|
|
17
18
|
- Support [Multi-Page App](https://vitejs.dev/guide/build.html#multi-page-app)
|
|
18
19
|
- Supports `vue` and `react` and other [frameworks](https://cn.vitejs.dev/guide/#trying-vite-online) supported by `vite`
|
|
19
20
|
|
|
@@ -384,3 +385,11 @@ Open the [examples](./examples) directory, there are `vue` and `react` examples.
|
|
|
384
385
|
- [@tomjs/vscode](https://npmjs.com/package/@tomjs/vscode): Some utilities to simplify the development of [VSCode Extensions](https://marketplace.visualstudio.com/VSCode).
|
|
385
386
|
- [@tomjs/vscode-dev](https://npmjs.com/package/@tomjs/vscode-dev): Some development tools to simplify the development of [vscode extensions](https://marketplace.visualstudio.com/VSCode).
|
|
386
387
|
- [@tomjs/vscode-webview](https://npmjs.com/package/@tomjs/vscode-webview): Optimize the `postMessage` issue between `webview` page and [vscode extensions](https://marketplace.visualstudio.com/VSCode)
|
|
388
|
+
|
|
389
|
+
## Important Notes
|
|
390
|
+
|
|
391
|
+
### v3.0.0
|
|
392
|
+
|
|
393
|
+
**Breaking Updates:**
|
|
394
|
+
|
|
395
|
+
- The simulated `acquireVsCodeApi` is consistent with the `acquireVsCodeApi` of [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview), and `sessionStorage.getItem` and `sessionStorage.setItem` are used to implement `getState` and `setState`.
|
package/README.zh_CN.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
- 配置简单,专注业务
|
|
15
15
|
- 支持 `esm`和 `cjs`
|
|
16
16
|
- 支持 webview `HMR`
|
|
17
|
+
- 支持 [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview) 的 `acquireVsCodeApi`
|
|
17
18
|
- 支持[多页面应用](https://cn.vitejs.dev/guide/build.html#multi-page-app)
|
|
18
19
|
- 支持 `vue` 、`react` 等其他 `vite` 支持的[框架](https://cn.vitejs.dev/guide/#trying-vite-online)
|
|
19
20
|
|
|
@@ -387,3 +388,11 @@ pnpm build
|
|
|
387
388
|
- [@tomjs/vscode](https://npmjs.com/package/@tomjs/vscode): 一些实用工具,用于简化 [vscode 扩展](https://marketplace.visualstudio.com/VSCode) 的开发。
|
|
388
389
|
- [@tomjs/vscode-dev](https://npmjs.com/package/@tomjs/vscode-dev): 一些开发工具,用于简化 [vscode 扩展](https://marketplace.visualstudio.com/VSCode) 的开发。
|
|
389
390
|
- [@tomjs/vscode-webview](https://npmjs.com/package/@tomjs/vscode-webview): 优化 `webview` 页面与 [vscode 扩展](https://marketplace.visualstudio.com/VSCode) 的 `postMessage` 问题
|
|
391
|
+
|
|
392
|
+
## 重要说明
|
|
393
|
+
|
|
394
|
+
### v3.0.0
|
|
395
|
+
|
|
396
|
+
**破坏性更新:**
|
|
397
|
+
|
|
398
|
+
- 模拟的 `acquireVsCodeApi` 与 [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview) 的 `acquireVsCodeApi` 保持一致,改用 `sessionStorage.getItem` 和 `sessionStorage.setItem` 来实现 `getState` 和 `setState`。
|
package/dist/client.global.js
CHANGED
|
@@ -35,8 +35,6 @@
|
|
|
35
35
|
document.head.appendChild(defaultStyles);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
var GET_STATE_TYPE = "[vscode:client]:getState";
|
|
39
|
-
var SET_STATE_TYPE = "[vscode:client]:setState";
|
|
40
38
|
var POST_MESSAGE_TYPE = "[vscode:client]:postMessage";
|
|
41
39
|
function patchAcquireVsCodeApi() {
|
|
42
40
|
class AcquireVsCodeApi {
|
|
@@ -46,31 +44,12 @@
|
|
|
46
44
|
}
|
|
47
45
|
getState() {
|
|
48
46
|
console.log(TAG, "mock acquireVsCodeApi.getState");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
window.parent.postMessage({ type: GET_STATE_TYPE }, "*");
|
|
52
|
-
}
|
|
53
|
-
const timeoutId = setTimeout(() => {
|
|
54
|
-
window.removeEventListener("message", receive);
|
|
55
|
-
reject(new Error("Timeout"));
|
|
56
|
-
}, 2e3);
|
|
57
|
-
function receive(e) {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
console.log(e);
|
|
60
|
-
if (!e.origin.startsWith("vscode-webview://") || ((_a = e.data) == null ? void 0 : _a.type) !== GET_STATE_TYPE) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
window.removeEventListener("message", receive);
|
|
64
|
-
clearTimeout(timeoutId);
|
|
65
|
-
resolve((_b = e.data) == null ? void 0 : _b.data);
|
|
66
|
-
}
|
|
67
|
-
window.addEventListener("message", receive);
|
|
68
|
-
post();
|
|
69
|
-
});
|
|
47
|
+
const state = sessionStorage.getItem("vscodeState");
|
|
48
|
+
return state ? JSON.parse(state) : void 0;
|
|
70
49
|
}
|
|
71
50
|
setState(newState) {
|
|
72
51
|
console.log(TAG, "mock acquireVsCodeApi.setState:", newState);
|
|
73
|
-
|
|
52
|
+
sessionStorage.setItem("vscodeState", JSON.stringify(newState));
|
|
74
53
|
return newState;
|
|
75
54
|
}
|
|
76
55
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
2
|
import { Options } from 'tsup';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -90,6 +90,6 @@ interface PluginOptions {
|
|
|
90
90
|
extension?: ExtensionOptions;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
declare function useVSCodePlugin(options?: PluginOptions):
|
|
93
|
+
declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
|
|
94
94
|
|
|
95
95
|
export { ExtensionOptions, PluginOptions, WebviewOption, useVSCodePlugin as default, useVSCodePlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
2
|
import { Options } from 'tsup';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -90,6 +90,6 @@ interface PluginOptions {
|
|
|
90
90
|
extension?: ExtensionOptions;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
declare function useVSCodePlugin(options?: PluginOptions):
|
|
93
|
+
declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
|
|
94
94
|
|
|
95
95
|
export { ExtensionOptions, PluginOptions, WebviewOption, useVSCodePlugin as default, useVSCodePlugin };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
|
3
3
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
4
4
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
5
5
|
var _process = require('process');
|
|
6
|
-
var _lodashclonedeep = require('lodash.clonedeep'); var _lodashclonedeep2 = _interopRequireDefault(_lodashclonedeep);
|
|
7
6
|
var _lodashmerge = require('lodash.merge'); var _lodashmerge2 = _interopRequireDefault(_lodashmerge);
|
|
8
7
|
var _nodehtmlparser = require('node-html-parser');
|
|
9
8
|
var _tsup = require('tsup');
|
|
@@ -119,7 +118,7 @@ function preMergeOptions(options) {
|
|
|
119
118
|
skipNodeModulesBundle: isDev
|
|
120
119
|
}
|
|
121
120
|
},
|
|
122
|
-
|
|
121
|
+
options
|
|
123
122
|
);
|
|
124
123
|
const opt = opts.extension || {};
|
|
125
124
|
["entry", "format"].forEach((prop) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// node_modules/.pnpm/tsup@7.2.0_@swc+core@1.
|
|
1
|
+
// node_modules/.pnpm/tsup@7.2.0_@swc+core@1.7.26_postcss@8.4.32_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import path from "path";
|
|
4
4
|
var getFilename = () => fileURLToPath(import.meta.url);
|
|
@@ -10,7 +10,6 @@ import fs from "fs";
|
|
|
10
10
|
import os from "os";
|
|
11
11
|
import path2 from "path";
|
|
12
12
|
import { cwd } from "process";
|
|
13
|
-
import cloneDeep from "lodash.clonedeep";
|
|
14
13
|
import merge from "lodash.merge";
|
|
15
14
|
import { parse as htmlParser } from "node-html-parser";
|
|
16
15
|
import { build as tsupBuild } from "tsup";
|
|
@@ -126,7 +125,7 @@ function preMergeOptions(options) {
|
|
|
126
125
|
skipNodeModulesBundle: isDev
|
|
127
126
|
}
|
|
128
127
|
},
|
|
129
|
-
|
|
128
|
+
options
|
|
130
129
|
);
|
|
131
130
|
const opt = opts.extension || {};
|
|
132
131
|
["entry", "format"].forEach((prop) => {
|
package/dist/webview.js
CHANGED
|
@@ -102,16 +102,6 @@ var template_default = `<!doctype html>
|
|
|
102
102
|
console.log(TAG + ' received:', e.data);
|
|
103
103
|
if (type === '[vscode:client]:postMessage') {
|
|
104
104
|
getApi().postMessage(data);
|
|
105
|
-
} else if (type === '[vscode:client]:getState') {
|
|
106
|
-
iframe.contentWindow.postMessage(
|
|
107
|
-
{
|
|
108
|
-
type: '[vscode:client]:getState',
|
|
109
|
-
data: getApi().getState(),
|
|
110
|
-
},
|
|
111
|
-
'*',
|
|
112
|
-
);
|
|
113
|
-
} else if (type === '[vscode:client]:setState') {
|
|
114
|
-
getApi().setState(data);
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
}
|
package/dist/webview.mjs
CHANGED
|
@@ -102,16 +102,6 @@ var template_default = `<!doctype html>
|
|
|
102
102
|
console.log(TAG + ' received:', e.data);
|
|
103
103
|
if (type === '[vscode:client]:postMessage') {
|
|
104
104
|
getApi().postMessage(data);
|
|
105
|
-
} else if (type === '[vscode:client]:getState') {
|
|
106
|
-
iframe.contentWindow.postMessage(
|
|
107
|
-
{
|
|
108
|
-
type: '[vscode:client]:getState',
|
|
109
|
-
data: getApi().getState(),
|
|
110
|
-
},
|
|
111
|
-
'*',
|
|
112
|
-
);
|
|
113
|
-
} else if (type === '[vscode:client]:setState') {
|
|
114
|
-
getApi().setState(data);
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/vite-plugin-vscode",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Use vue/react to develop 'vscode extension webview', supporting esm/cjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@tomjs/tsconfig": "^1.3.0",
|
|
80
80
|
"@types/lodash.clonedeep": "^4.5.9",
|
|
81
81
|
"@types/lodash.merge": "^4.6.9",
|
|
82
|
-
"@types/node": "
|
|
82
|
+
"@types/node": "18.19.55",
|
|
83
83
|
"cross-env": "^7.0.3",
|
|
84
84
|
"eslint": "^8.56.0",
|
|
85
85
|
"husky": "^8.0.3",
|
|
@@ -89,7 +89,8 @@
|
|
|
89
89
|
"rimraf": "^5.0.5",
|
|
90
90
|
"stylelint": "^16.1.0",
|
|
91
91
|
"tsx": "^4.7.0",
|
|
92
|
-
"typescript": "~5.3.3"
|
|
92
|
+
"typescript": "~5.3.3",
|
|
93
|
+
"vite": "5.4.8"
|
|
93
94
|
},
|
|
94
95
|
"peerDependencies": {
|
|
95
96
|
"vite": ">=2"
|