@tomjs/vite-plugin-vscode 6.0.2 → 6.2.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 +28 -1
- package/README.zh_CN.md +28 -1
- package/dist/index.js +53 -20
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -101,6 +101,32 @@ panel.webview.html = getWebviewHtml({
|
|
|
101
101
|
});
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
+
- Add `"@tomjs/vite-plugin-vscode/types"` to `tsconfig.node.json` or `*.d.ts` file.
|
|
105
|
+
|
|
106
|
+
`tsconfig.node.json`
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"extends": "@tomjs/tsconfig/node.json",
|
|
111
|
+
"compilerOptions": {
|
|
112
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
113
|
+
"types": [
|
|
114
|
+
"@tomjs/vite-plugin-vscode/types"
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
"include": [
|
|
118
|
+
"extension",
|
|
119
|
+
"*.config.ts"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`*.dt.s`
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
/// <reference types="@tomjs/vite-plugin-vscode/types" />
|
|
128
|
+
```
|
|
129
|
+
|
|
104
130
|
- `package.json`
|
|
105
131
|
|
|
106
132
|
```json
|
|
@@ -380,7 +406,7 @@ Run `Debug Extension` through `vscode` to debug. For debugging tools, refer to [
|
|
|
380
406
|
"background": {
|
|
381
407
|
"activeOnStart": true,
|
|
382
408
|
"beginsPattern": "^.*extension build start*$",
|
|
383
|
-
"endsPattern": "^.*extension
|
|
409
|
+
"endsPattern": "^.*extension build success.*$"
|
|
384
410
|
}
|
|
385
411
|
},
|
|
386
412
|
"isBackground": true,
|
|
@@ -420,6 +446,7 @@ Open the [examples](./examples) directory, there are `vue` and `react` examples.
|
|
|
420
446
|
- [vue](./examples/vue): Simple vue example.
|
|
421
447
|
- [vue-esm](./examples/vue-esm): Simple vue (ESM Extension) example.
|
|
422
448
|
- [vue-import](./examples/vue-import): Dynamic import() and multi-page examples.
|
|
449
|
+
- [vue-vite8](./examples/vue-rolldown): [vite8](https://vite.dev/) example.
|
|
423
450
|
|
|
424
451
|
## Related
|
|
425
452
|
|
package/README.zh_CN.md
CHANGED
|
@@ -79,6 +79,32 @@ npm i @tomjs/vite-plugin-vscode -D
|
|
|
79
79
|
|
|
80
80
|
### extension
|
|
81
81
|
|
|
82
|
+
- 添加 `"@tomjs/vite-plugin-vscode/types"` 到 `tsconfig.node.json` 或 `*.d.ts`
|
|
83
|
+
|
|
84
|
+
`tsconfig.node.json`
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"extends": "@tomjs/tsconfig/node.json",
|
|
89
|
+
"compilerOptions": {
|
|
90
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
91
|
+
"types": [
|
|
92
|
+
"@tomjs/vite-plugin-vscode/types"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"include": [
|
|
96
|
+
"extension",
|
|
97
|
+
"*.config.ts"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`*.dt.s`
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
/// <reference types="@tomjs/vite-plugin-vscode/types" />
|
|
106
|
+
```
|
|
107
|
+
|
|
82
108
|
代码片段,更多配置看示例
|
|
83
109
|
|
|
84
110
|
```ts
|
|
@@ -380,7 +406,7 @@ const value = await acquireVsCodeApi().getState();
|
|
|
380
406
|
"background": {
|
|
381
407
|
"activeOnStart": true,
|
|
382
408
|
"beginsPattern": "^.*extension build start*$",
|
|
383
|
-
"endsPattern": "^.*extension
|
|
409
|
+
"endsPattern": "^.*extension build success.*$"
|
|
384
410
|
}
|
|
385
411
|
},
|
|
386
412
|
"isBackground": true,
|
|
@@ -424,6 +450,7 @@ pnpm build
|
|
|
424
450
|
- [vue](./examples/vue):简单的 vue 示例。
|
|
425
451
|
- [vue-esm](./examples/vue-esm):简单的 vue(ESM 扩展)示例。
|
|
426
452
|
- [vue-import](./examples/vue-import):动态 import() 和多页面示例。
|
|
453
|
+
- [vue-vite8](./examples/vue-rolldown): [vite8](https://cn.vite.dev/) 示例。
|
|
427
454
|
|
|
428
455
|
## 关联
|
|
429
456
|
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,11 @@ import { readFileSync, readJsonSync } from "@tomjs/node";
|
|
|
6
6
|
import { execa } from "execa";
|
|
7
7
|
import merge from "lodash.merge";
|
|
8
8
|
import { parse } from "node-html-parser";
|
|
9
|
+
import colors from "picocolors";
|
|
9
10
|
import { build } from "tsdown";
|
|
10
|
-
import
|
|
11
|
+
import { createLogger } from "vite";
|
|
11
12
|
|
|
12
|
-
//#region node_modules/.pnpm/tsdown@0.
|
|
13
|
+
//#region node_modules/.pnpm/tsdown@0.19.0_publint@0.3.16_synckit@0.11.11_typescript@5.9.3_vue-tsc@3.2.1_typescript@5.9.3_/node_modules/tsdown/esm-shims.js
|
|
13
14
|
const getFilename = () => fileURLToPath(import.meta.url);
|
|
14
15
|
const getDirname = () => path.dirname(getFilename());
|
|
15
16
|
const __dirname = /* @__PURE__ */ getDirname();
|
|
@@ -23,12 +24,28 @@ const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`;
|
|
|
23
24
|
|
|
24
25
|
//#endregion
|
|
25
26
|
//#region src/logger.ts
|
|
26
|
-
function createLogger() {
|
|
27
|
-
|
|
27
|
+
function createLogger$1(logLevel) {
|
|
28
|
+
const logger$1 = createLogger(logLevel, {
|
|
28
29
|
prefix: `[${PLUGIN_NAME}]`,
|
|
29
|
-
|
|
30
|
+
allowClearScreen: true
|
|
30
31
|
});
|
|
32
|
+
[
|
|
33
|
+
"info",
|
|
34
|
+
"warn",
|
|
35
|
+
"warnOnce",
|
|
36
|
+
"error"
|
|
37
|
+
].forEach((level) => {
|
|
38
|
+
const _level = logger$1[level];
|
|
39
|
+
logger$1[level] = (msg, options) => {
|
|
40
|
+
_level(msg, Object.assign({
|
|
41
|
+
timestamp: true,
|
|
42
|
+
clear: false
|
|
43
|
+
}, options));
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
return logger$1;
|
|
31
47
|
}
|
|
48
|
+
const logger = createLogger$1();
|
|
32
49
|
|
|
33
50
|
//#endregion
|
|
34
51
|
//#region src/utils.ts
|
|
@@ -66,7 +83,6 @@ function resolveServerUrl(server) {
|
|
|
66
83
|
//#endregion
|
|
67
84
|
//#region src/index.ts
|
|
68
85
|
const isDev = process.env.NODE_ENV === "development";
|
|
69
|
-
const logger = createLogger();
|
|
70
86
|
function getPkg() {
|
|
71
87
|
const pkgFile = path.resolve(process.cwd(), "package.json");
|
|
72
88
|
if (!fs.existsSync(pkgFile)) throw new Error("Main file is not specified, and no package.json found");
|
|
@@ -153,7 +169,7 @@ function uuid() {
|
|
|
153
169
|
return text;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
|
-
export
|
|
172
|
+
export function getWebviewHtml(options){
|
|
157
173
|
const { webview, context, inputName, injectCode } = options || {};
|
|
158
174
|
const nonce = uuid();
|
|
159
175
|
const baseUri = webview.asWebviewUri(Uri.joinPath(context.extensionUri, (process.env.VITE_WEBVIEW_DIST || 'dist')));
|
|
@@ -164,11 +180,13 @@ export default function getWebviewHtml(options){
|
|
|
164
180
|
|
|
165
181
|
return html.replaceAll('{{cspSource}}', webview.cspSource).replaceAll('{{nonce}}', nonce).replaceAll('{{baseUri}}', baseUri);
|
|
166
182
|
}
|
|
167
|
-
|
|
183
|
+
|
|
184
|
+
export default getWebviewHtml;
|
|
185
|
+
`;
|
|
168
186
|
}
|
|
169
187
|
function useVSCodePlugin(options) {
|
|
170
188
|
const opts = preMergeOptions(options);
|
|
171
|
-
const handleConfig = (config) => {
|
|
189
|
+
const handleConfig = (config, isRolldown) => {
|
|
172
190
|
let outDir = config?.build?.outDir || "dist";
|
|
173
191
|
opts.extension ??= {};
|
|
174
192
|
if (opts.recommended) {
|
|
@@ -176,18 +194,22 @@ function useVSCodePlugin(options) {
|
|
|
176
194
|
outDir = path.resolve(outDir, "webview");
|
|
177
195
|
}
|
|
178
196
|
const assetsDir = config?.build?.assetsDir || "assets";
|
|
179
|
-
const
|
|
197
|
+
const outputDefault = {
|
|
180
198
|
chunkFileNames: `${assetsDir}/[name].js`,
|
|
181
199
|
entryFileNames: `${assetsDir}/[name].js`,
|
|
182
200
|
assetFileNames: `${assetsDir}/[name].[ext]`
|
|
183
201
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
202
|
+
const outputOptions = {};
|
|
203
|
+
const buildConfig = config.build || {};
|
|
204
|
+
const optKey = isRolldown ? "rolldownOptions" : ["rolldownOptions", "rollupOptions"].find((s) => buildConfig[s]) || "rollupOptions";
|
|
205
|
+
let output = buildConfig[optKey]?.output || {};
|
|
206
|
+
if (Array.isArray(output)) output.map((s) => Object.assign(s, outputDefault));
|
|
207
|
+
else output = Object.assign({}, output, outputDefault);
|
|
208
|
+
outputOptions[optKey] = Object.assign(outputOptions[optKey] || {}, { output });
|
|
187
209
|
return { build: {
|
|
188
210
|
outDir,
|
|
189
211
|
sourcemap: isDev ? true : config?.build?.sourcemap,
|
|
190
|
-
|
|
212
|
+
...outputOptions
|
|
191
213
|
} };
|
|
192
214
|
};
|
|
193
215
|
let devWebviewClientCode;
|
|
@@ -199,7 +221,7 @@ function useVSCodePlugin(options) {
|
|
|
199
221
|
name: "@tomjs:vscode",
|
|
200
222
|
apply: "serve",
|
|
201
223
|
config(config) {
|
|
202
|
-
return handleConfig(config);
|
|
224
|
+
return handleConfig(config, this && "rolldownVersion" in this.meta);
|
|
203
225
|
},
|
|
204
226
|
configResolved(config) {
|
|
205
227
|
resolvedConfig = config;
|
|
@@ -216,9 +238,10 @@ function useVSCodePlugin(options) {
|
|
|
216
238
|
VITE_DEV_SERVER_URL: resolveServerUrl(server)
|
|
217
239
|
};
|
|
218
240
|
logger.info("extension build start");
|
|
219
|
-
let buildCount = 0;
|
|
220
241
|
const webview = opts?.webview;
|
|
221
242
|
const { onSuccess: _onSuccess, ignoreWatch, logLevel, watchFiles, ...tsdownOptions } = opts.extension || {};
|
|
243
|
+
const entryDir = path.dirname(tsdownOptions.entry);
|
|
244
|
+
let buildFlag = false;
|
|
222
245
|
await build(merge(tsdownOptions, {
|
|
223
246
|
watch: watchFiles ?? (opts.recommended ? ["extension"] : true),
|
|
224
247
|
ignoreWatch: [
|
|
@@ -237,6 +260,13 @@ function useVSCodePlugin(options) {
|
|
|
237
260
|
},
|
|
238
261
|
load(id) {
|
|
239
262
|
if (id === RESOLVED_VIRTUAL_MODULE_ID) return devWebviewVirtualCode;
|
|
263
|
+
},
|
|
264
|
+
watchChange(id, e) {
|
|
265
|
+
let event = "";
|
|
266
|
+
if (e.event === "update") event = colors.green(e.event);
|
|
267
|
+
else if (e.event === "delete") event = colors.red(e.event);
|
|
268
|
+
else event = colors.blue(e.event);
|
|
269
|
+
logger.info(`${event} ${colors.dim(path.relative(entryDir, id))}`);
|
|
240
270
|
}
|
|
241
271
|
}],
|
|
242
272
|
async onSuccess(config, signal) {
|
|
@@ -244,9 +274,12 @@ function useVSCodePlugin(options) {
|
|
|
244
274
|
if (typeof _onSuccess === "string") await execa(_onSuccess);
|
|
245
275
|
else if (typeof _onSuccess === "function") await _onSuccess(config, signal);
|
|
246
276
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
277
|
+
if (!buildFlag) {
|
|
278
|
+
buildFlag = true;
|
|
279
|
+
logger.info("extension build success");
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
buildOptions: {}
|
|
250
283
|
}));
|
|
251
284
|
});
|
|
252
285
|
},
|
|
@@ -269,7 +302,7 @@ function useVSCodePlugin(options) {
|
|
|
269
302
|
apply: "build",
|
|
270
303
|
enforce: "post",
|
|
271
304
|
config(config) {
|
|
272
|
-
return handleConfig(config);
|
|
305
|
+
return handleConfig(config, this && "rolldownVersion" in this.meta);
|
|
273
306
|
},
|
|
274
307
|
configResolved(config) {
|
|
275
308
|
resolvedConfig = config;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/vite-plugin-vscode",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.0
|
|
4
|
+
"version": "6.2.0",
|
|
5
5
|
"description": "Use vue/react to develop 'vscode extension webview', supporting esm/cjs",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Tom Gao",
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
".": "./dist/index.js",
|
|
28
28
|
"./webview": "./dist/webview.js",
|
|
29
29
|
"./client": "./dist/client.iife.js",
|
|
30
|
-
"./env": "./env.d.ts"
|
|
30
|
+
"./env": "./env.d.ts",
|
|
31
|
+
"./types": {
|
|
32
|
+
"types": "./env.d.ts"
|
|
33
|
+
}
|
|
31
34
|
},
|
|
32
35
|
"module": "./dist/index.js",
|
|
33
36
|
"types": "./dist/index.d.ts",
|
|
@@ -47,23 +50,22 @@
|
|
|
47
50
|
"vite": ">=2"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"@tomjs/logger": "^1.4.0",
|
|
51
53
|
"@tomjs/node": "^2.2.3",
|
|
52
54
|
"execa": "^9.6.1",
|
|
53
55
|
"lodash.merge": "^4.6.2",
|
|
54
|
-
"node-html-parser": "^7.0.
|
|
55
|
-
"
|
|
56
|
+
"node-html-parser": "^7.0.2",
|
|
57
|
+
"picocolors": "^1.1.1",
|
|
58
|
+
"tsdown": "~0.19.0"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
58
61
|
"@antfu/eslint-config": "^6.7.3",
|
|
59
|
-
"@commitlint/cli": "^20.
|
|
62
|
+
"@commitlint/cli": "^20.3.1",
|
|
60
63
|
"@tomjs/commitlint": "^5.0.0",
|
|
61
|
-
"@tomjs/eslint": "^6.
|
|
62
|
-
"@tomjs/stylelint": "^7.
|
|
63
|
-
"@tomjs/tsconfig": "^
|
|
64
|
+
"@tomjs/eslint": "^6.5.0",
|
|
65
|
+
"@tomjs/stylelint": "^7.1.1",
|
|
66
|
+
"@tomjs/tsconfig": "^3.2.0",
|
|
64
67
|
"@types/lodash.merge": "^4.6.9",
|
|
65
|
-
"@types/node": "^20.19.
|
|
66
|
-
"@vitejs/plugin-vue": "^6.0.3",
|
|
68
|
+
"@types/node": "^20.19.28",
|
|
67
69
|
"cross-env": "^10.1.0",
|
|
68
70
|
"eslint": "^9.39.2",
|
|
69
71
|
"globals": "^16.5.0",
|
|
@@ -75,8 +77,7 @@
|
|
|
75
77
|
"stylelint": "^16.26.1",
|
|
76
78
|
"tsx": "^4.21.0",
|
|
77
79
|
"typescript": "~5.9.3",
|
|
78
|
-
"vite": "^7.3.
|
|
79
|
-
"vue-tsc": "^3.2.0"
|
|
80
|
+
"vite": "^7.3.1"
|
|
80
81
|
},
|
|
81
82
|
"scripts": {
|
|
82
83
|
"dev": "pnpm clean && tsdown --watch",
|