@tomjs/vite-plugin-vscode 4.3.0 → 5.1.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 CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  > Use `vue`/`react` to develop [vscode extension webview](https://code.visualstudio.com/api/references/vscode-api#WebviewPanel), supporting `esm` and `cjs`.
8
8
 
9
- In development mode, inject the same code of [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into `vscode extension code` and `web page code`, use To support `HMR`; during production build, the final generated `index.html` code is injected into `vscode extension code` to reduce the workload.
9
+ During development, inject code into both `vscode extension code` and `web page` code to support `HMR`; during production builds, inject the final generated `index.html` code into the `vscode extension code` to minimize manual effort.
10
10
 
11
11
  ## Features
12
12
 
13
- - Use [tsup](https://github.com/egoist/tsup) to quickly build `extension code`
13
+ - Use [tsdown](https://tsdown.dev/) to quickly build `extension code`
14
14
  - Simple configuration, focus on business
15
15
  - Support `esm` and `cjs`
16
16
  - Support ESM extension (vscode `v1.100.0+`)
@@ -296,13 +296,13 @@ During development, support standalone development tool applications for `react`
296
296
 
297
297
  ### ExtensionOptions
298
298
 
299
- Based on [Options](https://paka.dev/npm/tsup) of [tsup](https://tsup.egoist.dev/), some default values are added for ease of use.
299
+ Based on [Options](https://tsdown.dev/reference/api/Interface.Options) of [tsdown](https://tsdown.dev/), some default values are added for ease of use.
300
300
 
301
- | Property | Type | Default | Description |
302
- | --------- | ------------------------------------------------------------------- | --------------------- | ---------------------------------------------------------- |
303
- | entry | `string` | `extension/index.ts` | The vscode extension entry file. |
304
- | outDir | `string` | `dist-extension/main` | The output directory for the vscode extension file |
305
- | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | A function that will be executed after the build succeeds. |
301
+ | Property | Type | Default | Description |
302
+ | ---------- | -------------------- | --------------------- | -------------------------------------------------- |
303
+ | entry | `string` | `extension/index.ts` | The vscode extension entry file. |
304
+ | outDir | `string` | `dist-extension/main` | The output directory for the vscode extension file |
305
+ | watchFiles | `string`\/`string[]` | `` | Watch extension code files during development |
306
306
 
307
307
  ### WebviewOption
308
308
 
@@ -443,6 +443,12 @@ Open the [examples](./examples) directory, there are `vue` and `react` examples.
443
443
 
444
444
  ## Important Notes
445
445
 
446
+ ### v5.0.0
447
+
448
+ **Breaking Updates:**
449
+
450
+ - Using [tsdown](https://tsdown.dev/zh-CN) instead of [tsup](https://tsup.egoist.dev/), the vscode extension [extension](#ExtensionOptions) configuration is changed to inherit [tsdown](https://tsdown.dev/zh-CN).
451
+
446
452
  ### v4.0.0
447
453
 
448
454
  **Breaking Updates:**
package/README.zh_CN.md CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  > 用 `vue`/`react` 来开发 [vscode extension webview](https://code.visualstudio.com/api/references/vscode-api#WebviewPanel) ,支持 `esm` 和 `cjs`。
8
8
 
9
- 在开发模式时,给 `vscode 扩展代码` 和 `web 页面代码`中注入 [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) 相同的代码,用来支持 `HMR`;生产构建时,将最终生成的`index.html` 代码注入到 `vscode 扩展代码` 中,减少工作量。
9
+ 在开发模式时,给 `vscode 扩展代码` 和 `web 页面代码`中注入代码,用来支持 `HMR`;生产构建时,将最终生成的`index.html` 代码注入到 `vscode 扩展代码` 中,减少工作量。
10
10
 
11
11
  ## 特性
12
12
 
13
- - 使用 [tsup](https://github.com/egoist/tsup) 快速构建 `扩展代码`
13
+ - 使用 [tsdown](https://tsdown.dev/zh-CN/) 快速构建 `扩展代码`
14
14
  - 配置简单,专注业务
15
15
  - 支持 `esm`和 `cjs`
16
16
  - 支持 ESM 扩展(vscode `v1.100.0+`)
@@ -296,13 +296,13 @@ const value = await acquireVsCodeApi().getState();
296
296
 
297
297
  ### ExtensionOptions
298
298
 
299
- 继承自 [tsup](https://tsup.egoist.dev/) 的 [Options](https://paka.dev/npm/tsup),添加了一些默认值,方便使用。
299
+ 继承自 [tsdown](https://tsdown.dev/zh-CN/) 的 [Options](https://tsdown.dev/zh-CN/reference/api/Interface.Options),添加了一些默认值,方便使用。
300
300
 
301
- | 参数名 | 类型 | 默认值 | 说明 |
302
- | --------- | ------------------------------------------------------------------- | --------------------- | ------------------------ |
303
- | entry | `string` | `extension/index.ts` | 入口文件 |
304
- | outDir | `string` | `dist-extension/main` | 输出文件夹 |
305
- | onSuccess | `() => Promise<void \| undefined \| (() => void \| Promise<void>)>` | `undefined` | 构建成功后运行的回调函数 |
301
+ | 参数名 | 类型 | 默认值 | 说明 |
302
+ | ---------- | -------------------- | --------------------- | ------------------------ |
303
+ | entry | `string` | `extension/index.ts` | 入口文件 |
304
+ | outDir | `string` | `dist-extension/main` | 输出文件夹 |
305
+ | watchFiles | `string`\/`string[]` | `` | 开发时监听扩展代码的文件 |
306
306
 
307
307
  ### WebviewOption
308
308
 
@@ -447,6 +447,12 @@ pnpm build
447
447
 
448
448
  ## 重要说明
449
449
 
450
+ ### v5.0.0
451
+
452
+ **破坏性更新:**
453
+
454
+ - 使用 [tsdown](https://tsdown.dev/zh-CN) 替代 [tsup](https://tsup.egoist.dev/),vscode 扩展 [extension](#ExtensionOptions) 配置改为继承 [tsdown](https://tsdown.dev/zh-CN)
455
+
450
456
  ### v4.0.0
451
457
 
452
458
  **破坏性更新:**
@@ -0,0 +1,84 @@
1
+ (function() {
2
+
3
+
4
+ //#region src/webview/client.ts
5
+ if (window.top === window.self) throw new Error("[vscode:client]: must run in vscode webview");
6
+ const TAG = "[@tomjs:vscode:client] ";
7
+ patchAcquireVsCodeApi();
8
+ function onDomReady(callback) {
9
+ if (document.readyState === "interactive" || document.readyState === "complete") callback();
10
+ else document.addEventListener("DOMContentLoaded", callback);
11
+ }
12
+ function patchInitData(data) {
13
+ onDomReady(() => {
14
+ console.log(TAG, "patch client style");
15
+ const { style, body, root } = data;
16
+ document.documentElement.style.cssText = root.cssText;
17
+ document.body.className = body.className;
18
+ Object.keys(body.dataset).forEach((key) => {
19
+ document.body.dataset[key] = body.dataset[key];
20
+ });
21
+ const defaultStyles = document.createElement("style");
22
+ defaultStyles.id = "_defaultStyles";
23
+ defaultStyles.textContent = style;
24
+ document.head.appendChild(defaultStyles);
25
+ });
26
+ }
27
+ const POST_MESSAGE_TYPE = "[vscode:client]:postMessage";
28
+ function patchAcquireVsCodeApi() {
29
+ class AcquireVsCodeApi {
30
+ postMessage(message) {
31
+ console.log(TAG, "mock acquireVsCodeApi.postMessage:", message);
32
+ window.parent.postMessage({
33
+ type: POST_MESSAGE_TYPE,
34
+ data: message
35
+ }, "*");
36
+ }
37
+ getState() {
38
+ console.log(TAG, "mock acquireVsCodeApi.getState");
39
+ const state = sessionStorage.getItem("vscodeState");
40
+ return state ? JSON.parse(state) : void 0;
41
+ }
42
+ setState(newState) {
43
+ console.log(TAG, "mock acquireVsCodeApi.setState:", newState);
44
+ sessionStorage.setItem("vscodeState", JSON.stringify(newState));
45
+ return newState;
46
+ }
47
+ }
48
+ console.log(TAG, "patch acquireVsCodeApi");
49
+ let api;
50
+ window.acquireVsCodeApi = () => {
51
+ if (!api) {
52
+ api = new AcquireVsCodeApi();
53
+ return api;
54
+ } else return api;
55
+ };
56
+ }
57
+ const INIT_TYPE = "[vscode:extension]:init";
58
+ window.addEventListener("message", (e) => {
59
+ const { type, data } = e.data || {};
60
+ if (!e.origin.startsWith("vscode-webview://") || type !== INIT_TYPE) return;
61
+ patchInitData(data);
62
+ });
63
+ const KEYBOARD_EVENT_TYPE = "[vscode:client]:commands";
64
+ const isMac = navigator.userAgent.includes("Macintosh");
65
+ document.addEventListener("keydown", (e) => {
66
+ console.log(e);
67
+ const { metaKey, shiftKey, ctrlKey, altKey, key } = e;
68
+ if (key === "F1") window.parent.postMessage({
69
+ type: KEYBOARD_EVENT_TYPE,
70
+ data: "F1"
71
+ }, "*");
72
+ else if (isMac && metaKey && !altKey && !ctrlKey) {
73
+ if (shiftKey) {
74
+ if (key === "z") document.execCommand("redo");
75
+ } else if (key === "a") document.execCommand("selectAll");
76
+ else if (key === "c") document.execCommand("copy");
77
+ else if (key === "v") document.execCommand("paste");
78
+ else if (key === "x") document.execCommand("cut");
79
+ else if (key === "z") document.execCommand("undo");
80
+ }
81
+ });
82
+
83
+ //#endregion
84
+ })();
package/dist/index.d.ts CHANGED
@@ -1,93 +1,89 @@
1
- import { PluginOption } from 'vite';
2
- import { Options } from 'tsup';
1
+ import { Options } from "tsdown";
2
+ import { PluginOption } from "vite";
3
3
 
4
+ //#region src/types.d.ts
4
5
  /**
5
- * vscode extension options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
6
+ * vscode extension options. See [tsdown](https://tsdown.dev/) and [Config Options](https://tsdown.dev/reference/config-options) for more information.
6
7
  */
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>)>;
8
+ interface ExtensionOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch'> {
9
+ /**
10
+ * The extension entry file.
11
+ * @default "extension/index.ts"
12
+ */
13
+ entry?: string;
14
+ /**
15
+ * The output directory for the extension files. Default is `dist-extension`.
16
+ * @default "dist-extension"
17
+ */
18
+ outDir?: string;
19
+ /**
20
+ * `tsdown` watches the current working directory by default. You can set files that need to be watched, which may improve performance.
21
+ *
22
+ * If no value is specified, the default value of the "recommended" parameter is ["extension"] when it is true, otherwise it defaults to "true"
23
+ */
24
+ watchFiles?: string | string[];
30
25
  }
31
26
  /**
32
27
  * vscode webview options.
33
28
  */
34
29
  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;
30
+ /**
31
+ * The method name to inject. Default is `__getWebviewHtml__`
32
+ */
33
+ name?: string;
34
+ /**
35
+ * 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';">`
36
+ */
37
+ csp?: string;
43
38
  }
44
39
  /**
45
40
  * vite plugin options.
46
41
  */
47
42
  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 code 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/vite-plugin-vscode/webview';` at the top of the file that calls the `__getWebviewHtml__` method
61
- * - web: Add `<script>` tag to index.html and inject `@tomjs/vite-plugin-vscode/client` code
62
- * - vite build
63
- * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` at the top of the file that calls the `__getWebviewHtml__` method
64
- *
65
- * If is string, will set inject method name. Default is '__getWebviewHtml__'.
66
- *
67
- *
68
- * @example
69
- * extension file
70
- * ```ts
71
- *function setupHtml(webview: Webview, context: ExtensionContext) {
72
- * return __getWebviewHtml__({serverUrl:WebviewHtmlOptions, webview, context});
73
- *}
74
- * ```
75
- */
76
- webview?: boolean | string | WebviewOption;
77
- /**
78
- * extension vite config.
79
- */
80
- extension?: ExtensionOptions;
81
- /**
82
- * Whether to enable devtools. Inject `<script src="http://localhost:<devtools-port>"></script>` into webview client . Default is true.
83
- * - true:
84
- * - react: inject `<script src="http://localhost:8097"></script>`
85
- * - vue: inject `<script src="http://localhost:8098"></script>`
86
- * @default true
87
- */
88
- devtools?: boolean;
43
+ /**
44
+ * Recommended switch. Default is true.
45
+ * if true, will have the following default behavior:
46
+ * - will change the extension/webview outDir to be parallel outDir;
47
+ * - if vite build.outDir is 'dist', will change extension/webview to 'dist/extension' and 'dist/webview'
48
+ * @default true
49
+ */
50
+ recommended?: boolean;
51
+ /**
52
+ * Inject code into vscode extension code and web client code, so that webview can support HMR during the development stage.
53
+ *
54
+ * - vite serve
55
+ * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode/webview';` at the top of the file that calls the `__getWebviewHtml__` method
56
+ * - web: Add `<script>` tag to index.html and inject `@tomjs/vite-plugin-vscode/client` code
57
+ * - vite build
58
+ * - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` at the top of the file that calls the `__getWebviewHtml__` method
59
+ *
60
+ * If is string, will set inject method name. Default is '__getWebviewHtml__'.
61
+ *
62
+ *
63
+ * @example
64
+ * extension file
65
+ * ```ts
66
+ *function setupHtml(webview: Webview, context: ExtensionContext) {
67
+ * return __getWebviewHtml__({serverUrl:WebviewHtmlOptions, webview, context});
68
+ *}
69
+ * ```
70
+ */
71
+ webview?: boolean | string | WebviewOption;
72
+ /**
73
+ * extension vite config.
74
+ */
75
+ extension?: ExtensionOptions;
76
+ /**
77
+ * Whether to enable devtools. Inject `<script src="http://localhost:<devtools-port>"></script>` into webview client . Default is true.
78
+ * - true:
79
+ * - react: inject `<script src="http://localhost:8097"></script>`
80
+ * - vue: inject `<script src="http://localhost:8098"></script>`
81
+ * @default true
82
+ */
83
+ devtools?: boolean;
89
84
  }
90
-
85
+ //#endregion
86
+ //#region src/index.d.ts
91
87
  declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
92
-
93
- export { type ExtensionOptions, type PluginOptions, type WebviewOption, useVSCodePlugin as default, useVSCodePlugin };
88
+ //#endregion
89
+ export { ExtensionOptions, PluginOptions, WebviewOption, useVSCodePlugin as default, useVSCodePlugin };