@tomjs/vite-plugin-vscode 2.5.3 → 2.5.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @tomjs/vite-plugin-vscode
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@tomjs/vite-plugin-vscode)](https://www.npmjs.com/package/@tomjs/vite-plugin-vscode) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vite-plugin-vscode) ![NPM](https://img.shields.io/npm/l/@tomjs/vite-plugin-vscode)
3
+ [![npm](https://img.shields.io/npm/v/@tomjs/vite-plugin-vscode)](https://www.npmjs.com/package/@tomjs/vite-plugin-vscode) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vite-plugin-vscode) ![NPM](https://img.shields.io/npm/l/@tomjs/vite-plugin-vscode) [![Docs](https://raw.githubusercontent.com/tomjs/assets/main/npm/api.svg)](https://www.unpkg.com/browse/@tomjs/vite-plugin-vscode/dist/index.d.ts)
4
4
 
5
5
  **English** | [中文](./README.zh_CN.md)
6
6
 
package/README.zh_CN.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @tomjs/vite-plugin-vscode
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@tomjs/vite-plugin-vscode)](https://www.npmjs.com/package/@tomjs/vite-plugin-vscode) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vite-plugin-vscode) ![NPM](https://img.shields.io/npm/l/@tomjs/vite-plugin-vscode)
3
+ [![npm](https://img.shields.io/npm/v/@tomjs/vite-plugin-vscode)](https://www.npmjs.com/package/@tomjs/vite-plugin-vscode) ![node-current (scoped)](https://img.shields.io/node/v/@tomjs/vite-plugin-vscode) ![NPM](https://img.shields.io/npm/l/@tomjs/vite-plugin-vscode) [![Docs](https://raw.githubusercontent.com/tomjs/assets/main/npm/api.svg)](https://www.unpkg.com/browse/@tomjs/vite-plugin-vscode/dist/index.d.ts)
4
4
 
5
5
  [English](./README.md) | **中文**
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/vite-plugin-vscode",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "Use vue/react to develop 'vscode extension webview', supporting esm/cjs",
5
5
  "keywords": [
6
6
  "vite",
@@ -1,98 +0,0 @@
1
- "use strict";
2
- (() => {
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
- };
7
-
8
- // src/webview/client.ts
9
- var require_client = __commonJS({
10
- "src/webview/client.ts"() {
11
- if (window.top === window.self) {
12
- return;
13
- }
14
- var TAG = "[@tomjs:vscode:client] ";
15
- patchAcquireVsCodeApi();
16
- function onDomReady(callback) {
17
- if (document.readyState === "interactive" || document.readyState === "complete") {
18
- callback();
19
- } else {
20
- document.addEventListener("DOMContentLoaded", callback);
21
- }
22
- }
23
- function patchInitData(data) {
24
- onDomReady(() => {
25
- console.log(TAG, "patch client style");
26
- const { style, body, root } = data;
27
- document.documentElement.style.cssText = root.cssText;
28
- document.body.className = body.className;
29
- Object.keys(body.dataset).forEach((key) => {
30
- document.body.dataset[key] = body.dataset[key];
31
- });
32
- const defaultStyles = document.createElement("style");
33
- defaultStyles.id = "_defaultStyles";
34
- defaultStyles.textContent = style;
35
- document.head.appendChild(defaultStyles);
36
- });
37
- }
38
- var GET_STATE_TYPE = "[vscode:client]:getState";
39
- var SET_STATE_TYPE = "[vscode:client]:setState";
40
- var POST_MESSAGE_TYPE = "[vscode:client]:postMessage";
41
- function patchAcquireVsCodeApi() {
42
- class AcquireVsCodeApi {
43
- postMessage(message) {
44
- console.log(TAG, "mock acquireVsCodeApi.postMessage:", message);
45
- window.parent.postMessage({ type: POST_MESSAGE_TYPE, data: message }, "*");
46
- }
47
- getState() {
48
- console.log(TAG, "mock acquireVsCodeApi.getState");
49
- return new Promise((resolve, reject) => {
50
- function post() {
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
- });
70
- }
71
- setState(newState) {
72
- console.log(TAG, "mock acquireVsCodeApi.setState:", newState);
73
- window.parent.postMessage({ type: SET_STATE_TYPE, data: newState }, "*");
74
- }
75
- }
76
- console.log(TAG, "patch acquireVsCodeApi");
77
- let api;
78
- window.acquireVsCodeApi = () => {
79
- if (!api) {
80
- api = new AcquireVsCodeApi();
81
- return api;
82
- } else {
83
- return api;
84
- }
85
- };
86
- }
87
- var INIT_TYPE = "[vscode:extension]:init";
88
- window.addEventListener("message", (e) => {
89
- const { type, data } = e.data || {};
90
- if (!e.origin.startsWith("vscode-webview://") || type !== INIT_TYPE) {
91
- return;
92
- }
93
- patchInitData(data);
94
- });
95
- }
96
- });
97
- require_client();
98
- })();
package/dist/index.d.mts DELETED
@@ -1,95 +0,0 @@
1
- import { Plugin } from 'vite';
2
- import { Options } from 'tsup';
3
-
4
- /**
5
- * vscode extension options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
6
- */
7
- interface ExtensionOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess' | 'skipNodeModulesBundle'> {
8
- /**
9
- * The extension entry file.
10
- * @default "extension/index.ts"
11
- */
12
- entry?: string;
13
- /**
14
- * The output directory for the extension files. Default is `dist-extension`.
15
- * @default "dist-extension"
16
- */
17
- outDir?: string;
18
- /**
19
- * The bundle format. Currently only supports cjs.
20
- */
21
- format?: 'cjs';
22
- /**
23
- * Skip dependencies and peerDependencies bundle. Default is false.
24
- */
25
- skipNodeModulesBundle?: boolean;
26
- /**
27
- * A function that will be executed after the build succeeds.
28
- */
29
- onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
30
- }
31
- /**
32
- * vscode webview options.
33
- */
34
- interface WebviewOption {
35
- /**
36
- * The method name to inject. Default is '__getWebviewHtml__'
37
- */
38
- name?: string;
39
- /**
40
- * The CSP meta for the webview. Default is `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src {{cspSource}} 'unsafe-inline'; script-src 'nonce-{{nonce}}' 'unsafe-eval';">`
41
- */
42
- csp?: string;
43
- }
44
- /**
45
- * vite plugin options.
46
- */
47
- interface PluginOptions {
48
- /**
49
- * Recommended switch. Default is true.
50
- * if true, will have the following default behavior:
51
- * * will change the extension/webview outDir to be parallel outDir;
52
- * eg. if vite build.outDir is 'dist', will change extension/webview to 'dist/extension' and 'dist/webview'
53
- * @default true
54
- */
55
- recommended?: boolean;
56
- /**
57
- * Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
58
- *
59
- * * vite serve
60
- * * extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
61
- * * web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
62
- * * vite build
63
- * * extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
64
- *
65
- * If is string, will set inject method name. Default is '__getWebviewHtml__'.
66
- *
67
- * @example
68
- * extension file
69
- * ```ts
70
- *function setupHtml(webview: Webview, context: ExtensionContext) {
71
- * if (process.env.VITE_DEV_SERVER_URL) {
72
- * return __getWebviewHtml__(process.env.VITE_DEV_SERVER_URL);
73
- * }
74
- * return __getWebviewHtml__(webview, context);
75
- *}
76
- * ```
77
- * webview client
78
- * ```html
79
- * <html>
80
- * <head>
81
- * <script>inject code</script>
82
- * </head>
83
- * </html>
84
- * ```
85
- */
86
- webview?: boolean | string | WebviewOption;
87
- /**
88
- * extension vite config.
89
- */
90
- extension?: ExtensionOptions;
91
- }
92
-
93
- declare function useVSCodePlugin(options?: PluginOptions): Plugin[];
94
-
95
- export { useVSCodePlugin as default, useVSCodePlugin };
package/dist/index.d.ts DELETED
@@ -1,95 +0,0 @@
1
- import { Plugin } from 'vite';
2
- import { Options } from 'tsup';
3
-
4
- /**
5
- * vscode extension options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
6
- */
7
- interface ExtensionOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess' | 'skipNodeModulesBundle'> {
8
- /**
9
- * The extension entry file.
10
- * @default "extension/index.ts"
11
- */
12
- entry?: string;
13
- /**
14
- * The output directory for the extension files. Default is `dist-extension`.
15
- * @default "dist-extension"
16
- */
17
- outDir?: string;
18
- /**
19
- * The bundle format. Currently only supports cjs.
20
- */
21
- format?: 'cjs';
22
- /**
23
- * Skip dependencies and peerDependencies bundle. Default is false.
24
- */
25
- skipNodeModulesBundle?: boolean;
26
- /**
27
- * A function that will be executed after the build succeeds.
28
- */
29
- onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
30
- }
31
- /**
32
- * vscode webview options.
33
- */
34
- interface WebviewOption {
35
- /**
36
- * The method name to inject. Default is '__getWebviewHtml__'
37
- */
38
- name?: string;
39
- /**
40
- * The CSP meta for the webview. Default is `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src {{cspSource}} 'unsafe-inline'; script-src 'nonce-{{nonce}}' 'unsafe-eval';">`
41
- */
42
- csp?: string;
43
- }
44
- /**
45
- * vite plugin options.
46
- */
47
- interface PluginOptions {
48
- /**
49
- * Recommended switch. Default is true.
50
- * if true, will have the following default behavior:
51
- * * will change the extension/webview outDir to be parallel outDir;
52
- * eg. if vite build.outDir is 'dist', will change extension/webview to 'dist/extension' and 'dist/webview'
53
- * @default true
54
- */
55
- recommended?: boolean;
56
- /**
57
- * Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
58
- *
59
- * * vite serve
60
- * * extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
61
- * * web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
62
- * * vite build
63
- * * extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
64
- *
65
- * If is string, will set inject method name. Default is '__getWebviewHtml__'.
66
- *
67
- * @example
68
- * extension file
69
- * ```ts
70
- *function setupHtml(webview: Webview, context: ExtensionContext) {
71
- * if (process.env.VITE_DEV_SERVER_URL) {
72
- * return __getWebviewHtml__(process.env.VITE_DEV_SERVER_URL);
73
- * }
74
- * return __getWebviewHtml__(webview, context);
75
- *}
76
- * ```
77
- * webview client
78
- * ```html
79
- * <html>
80
- * <head>
81
- * <script>inject code</script>
82
- * </head>
83
- * </html>
84
- * ```
85
- */
86
- webview?: boolean | string | WebviewOption;
87
- /**
88
- * extension vite config.
89
- */
90
- extension?: ExtensionOptions;
91
- }
92
-
93
- declare function useVSCodePlugin(options?: PluginOptions): Plugin[];
94
-
95
- export { useVSCodePlugin as default, useVSCodePlugin };