@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 +14 -8
- package/README.zh_CN.md +14 -8
- package/dist/client.iife.js +84 -0
- package/dist/index.d.ts +74 -78
- package/dist/index.js +289 -346
- package/dist/webview.d.ts +7 -6
- package/dist/webview.js +14 -199
- package/package.json +31 -35
- package/dist/client.global.js +0 -93
- package/dist/index.d.mts +0 -93
- package/dist/index.mjs +0 -396
- package/dist/webview.d.mts +0 -13
- package/dist/webview.mjs +0 -203
package/dist/index.js
CHANGED
|
@@ -1,164 +1,160 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import { cwd } from "node:process";
|
|
6
|
+
import { emptyDirSync, readFileSync, readJsonSync } from "@tomjs/node";
|
|
7
|
+
import { execa } from "execa";
|
|
8
|
+
import merge from "lodash.merge";
|
|
9
|
+
import { parse } from "node-html-parser";
|
|
10
|
+
import { build } from "tsdown";
|
|
11
|
+
import Logger from "@tomjs/logger";
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
//#region node_modules/.pnpm/tsdown@0.15.12_publint@0.3.15_typescript@5.8.3_unrun@0.2.14_synckit@0.11.11__vue-tsc@3.1.5_typescript@5.8.3_/node_modules/tsdown/esm-shims.js
|
|
14
|
+
const getFilename = () => fileURLToPath(import.meta.url);
|
|
15
|
+
const getDirname = () => path.dirname(getFilename());
|
|
16
|
+
const __dirname = /* @__PURE__ */ getDirname();
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/constants.ts
|
|
20
|
+
const PLUGIN_NAME = "tomjs:vscode";
|
|
21
|
+
const ORG_NAME = "@tomjs";
|
|
22
|
+
const PACKAGE_NAME = "@tomjs/vite-plugin-vscode";
|
|
23
|
+
const WEBVIEW_METHOD_NAME = "__getWebviewHtml__";
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/logger.ts
|
|
18
27
|
function createLogger() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
return new Logger({
|
|
29
|
+
prefix: `[${PLUGIN_NAME}]`,
|
|
30
|
+
time: true
|
|
31
|
+
});
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/utils.ts
|
|
36
|
+
/**
|
|
37
|
+
* @see https://github.com/vitejs/vite/blob/v4.0.1/packages/vite/src/node/constants.ts#L137-L147
|
|
38
|
+
*/
|
|
26
39
|
function resolveHostname(hostname) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const loopbackHosts = new Set([
|
|
41
|
+
"localhost",
|
|
42
|
+
"127.0.0.1",
|
|
43
|
+
"::1",
|
|
44
|
+
"0000:0000:0000:0000:0000:0000:0000:0001"
|
|
45
|
+
]);
|
|
46
|
+
const wildcardHosts = new Set([
|
|
47
|
+
"0.0.0.0",
|
|
48
|
+
"::",
|
|
49
|
+
"0000:0000:0000:0000:0000:0000:0000:0000"
|
|
50
|
+
]);
|
|
51
|
+
return loopbackHosts.has(hostname) || wildcardHosts.has(hostname) ? "localhost" : hostname;
|
|
35
52
|
}
|
|
36
53
|
function resolveServerUrl(server) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
54
|
+
const addressInfo = server.httpServer.address();
|
|
55
|
+
const isAddressInfo = (x) => x?.address;
|
|
56
|
+
if (isAddressInfo(addressInfo)) {
|
|
57
|
+
const { address, port } = addressInfo;
|
|
58
|
+
const hostname = resolveHostname(address);
|
|
59
|
+
const options = server.config.server;
|
|
60
|
+
const protocol = options.https ? "https" : "http";
|
|
61
|
+
const devBase = server.config.base;
|
|
62
|
+
const path$1 = typeof options.open === "string" ? options.open : devBase;
|
|
63
|
+
return path$1.startsWith("http") ? path$1 : `${protocol}://${hostname}:${port}${path$1}`;
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/index.ts
|
|
69
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
70
|
+
const logger = createLogger();
|
|
54
71
|
function getPkg() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!pkg.main) {
|
|
61
|
-
throw new Error("Main file is not specified, please check package.json");
|
|
62
|
-
}
|
|
63
|
-
return pkg;
|
|
72
|
+
const pkgFile = path.resolve(process.cwd(), "package.json");
|
|
73
|
+
if (!fs.existsSync(pkgFile)) throw new Error("Main file is not specified, and no package.json found");
|
|
74
|
+
const pkg = readJsonSync(pkgFile);
|
|
75
|
+
if (!pkg.main) throw new Error("Main file is not specified, please check package.json");
|
|
76
|
+
return pkg;
|
|
64
77
|
}
|
|
65
78
|
function preMergeOptions(options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (typeof opts.webview === "string") {
|
|
113
|
-
name = _nullishCoalesce(opts.webview, () => ( WEBVIEW_METHOD_NAME));
|
|
114
|
-
}
|
|
115
|
-
opts.webview = Object.assign({ name }, opts.webview);
|
|
116
|
-
}
|
|
117
|
-
return opts;
|
|
79
|
+
const pkg = getPkg();
|
|
80
|
+
const format = pkg.type === "module" ? "esm" : "cjs";
|
|
81
|
+
const opts = merge({
|
|
82
|
+
webview: true,
|
|
83
|
+
recommended: true,
|
|
84
|
+
extension: {
|
|
85
|
+
entry: "extension/index.ts",
|
|
86
|
+
outDir: "dist-extension",
|
|
87
|
+
target: format === "esm" ? ["node20"] : ["es2019", "node14"],
|
|
88
|
+
format,
|
|
89
|
+
shims: true,
|
|
90
|
+
clean: true,
|
|
91
|
+
dts: false,
|
|
92
|
+
treeshake: !isDev,
|
|
93
|
+
publint: false,
|
|
94
|
+
config: false,
|
|
95
|
+
outExtensions() {
|
|
96
|
+
return { js: ".js" };
|
|
97
|
+
},
|
|
98
|
+
external: ["vscode"]
|
|
99
|
+
}
|
|
100
|
+
}, options);
|
|
101
|
+
const opt = opts.extension || {};
|
|
102
|
+
if (isDev) opt.sourcemap = opt.sourcemap ?? true;
|
|
103
|
+
else {
|
|
104
|
+
opt.minify ??= true;
|
|
105
|
+
opt.clean ??= true;
|
|
106
|
+
}
|
|
107
|
+
if (typeof opt.external !== "function") {
|
|
108
|
+
opt.external = ["vscode"].concat(opt.external ?? []);
|
|
109
|
+
opt.external = [...new Set(opt.external)];
|
|
110
|
+
} else {
|
|
111
|
+
const fn = opt.external;
|
|
112
|
+
opt.external = function(id, parentId, isResolved) {
|
|
113
|
+
if (id === "vscode") return true;
|
|
114
|
+
return fn(id, parentId, isResolved);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (!isDev && !opt.skipNodeModulesBundle && !opt.noExternal) opt.noExternal = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.peerDependencies || {}));
|
|
118
|
+
opts.extension = opt;
|
|
119
|
+
if (opts.webview !== false) {
|
|
120
|
+
let name = WEBVIEW_METHOD_NAME;
|
|
121
|
+
if (typeof opts.webview === "string") name = opts.webview ?? WEBVIEW_METHOD_NAME;
|
|
122
|
+
opts.webview = Object.assign({ name }, opts.webview);
|
|
123
|
+
}
|
|
124
|
+
return opts;
|
|
118
125
|
}
|
|
119
|
-
|
|
126
|
+
const prodCachePkgName = `${PACKAGE_NAME}-inject`;
|
|
120
127
|
function genProdWebviewCode(cache, webview) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return root.removeWhitespace().toString();
|
|
150
|
-
}
|
|
151
|
-
const cacheCode = (
|
|
152
|
-
/* js */
|
|
153
|
-
`const htmlCode = {
|
|
154
|
-
${Object.keys(cache).map((s) => `'${s}': \`${handleHtmlCode(cache[s])}\`,`).join("\n")}
|
|
155
|
-
};`
|
|
156
|
-
);
|
|
157
|
-
const code = (
|
|
158
|
-
/* js */
|
|
159
|
-
`import { Uri } from 'vscode';
|
|
128
|
+
webview = Object.assign({}, webview);
|
|
129
|
+
const prodCacheFolder = path.join(cwd(), "node_modules", prodCachePkgName);
|
|
130
|
+
emptyDirSync(prodCacheFolder);
|
|
131
|
+
const destFile = path.join(prodCacheFolder, "index.js");
|
|
132
|
+
function handleHtmlCode(html) {
|
|
133
|
+
const root = parse(html);
|
|
134
|
+
const head = root.querySelector("head");
|
|
135
|
+
if (!head) root?.insertAdjacentHTML("beforeend", "<head></head>");
|
|
136
|
+
const csp = webview?.csp || `<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src {{cspSource}} 'unsafe-inline'; script-src 'nonce-{{nonce}}' 'unsafe-eval';">`;
|
|
137
|
+
head.insertAdjacentHTML("afterbegin", csp);
|
|
138
|
+
if (csp && csp.includes("{{nonce}}")) {
|
|
139
|
+
const tags = {
|
|
140
|
+
script: "src",
|
|
141
|
+
link: "href"
|
|
142
|
+
};
|
|
143
|
+
Object.keys(tags).forEach((tag) => {
|
|
144
|
+
root.querySelectorAll(tag).forEach((element) => {
|
|
145
|
+
const attr = element.getAttribute(tags[tag]);
|
|
146
|
+
if (attr) element.setAttribute(tags[tag], `{{baseUri}}${attr}`);
|
|
147
|
+
element.setAttribute("nonce", "{{nonce}}");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return root.removeWhitespace().toString();
|
|
152
|
+
}
|
|
153
|
+
const code = `import { Uri } from 'vscode';
|
|
160
154
|
|
|
161
|
-
${
|
|
155
|
+
${`const htmlCode = {
|
|
156
|
+
${Object.keys(cache).map((s) => `'${s}': \`${handleHtmlCode(cache[s])}\`,`).join("\n")}
|
|
157
|
+
};`}
|
|
162
158
|
|
|
163
159
|
function uuid() {
|
|
164
160
|
let text = '';
|
|
@@ -180,210 +176,157 @@ export default function getWebviewHtml(options){
|
|
|
180
176
|
|
|
181
177
|
return html.replaceAll('{{cspSource}}', webview.cspSource).replaceAll('{{nonce}}', nonce).replaceAll('{{baseUri}}', baseUri);
|
|
182
178
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return fixWindowsPath(destFile);
|
|
179
|
+
`;
|
|
180
|
+
fs.writeFileSync(destFile, code, { encoding: "utf8" });
|
|
181
|
+
return fixWindowsPath(destFile);
|
|
187
182
|
}
|
|
188
183
|
function fixWindowsPath(webviewPath) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
return webviewPath;
|
|
184
|
+
if (os.platform() === "win32") webviewPath = webviewPath.replaceAll("\\", "/");
|
|
185
|
+
return webviewPath;
|
|
193
186
|
}
|
|
194
187
|
function useVSCodePlugin(options) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
closeBundle() {
|
|
336
|
-
let webviewPath;
|
|
337
|
-
const webview = opts == null ? void 0 : opts.webview;
|
|
338
|
-
if (webview) {
|
|
339
|
-
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
340
|
-
}
|
|
341
|
-
let outDir = resolvedConfig.build.outDir.replace(_process.cwd.call(void 0, ), "").replaceAll("\\", "/");
|
|
342
|
-
if (outDir.startsWith("/")) {
|
|
343
|
-
outDir = outDir.substring(1);
|
|
344
|
-
}
|
|
345
|
-
const env = {
|
|
346
|
-
NODE_ENV: resolvedConfig.mode || "production",
|
|
347
|
-
VITE_WEBVIEW_DIST: outDir
|
|
348
|
-
};
|
|
349
|
-
logger.info("extension build start");
|
|
350
|
-
const { onSuccess: _onSuccess, ...tsupOptions } = opts.extension || {};
|
|
351
|
-
_tsup.build.call(void 0,
|
|
352
|
-
_lodashmerge2.default.call(void 0, tsupOptions, {
|
|
353
|
-
env,
|
|
354
|
-
silent: true,
|
|
355
|
-
esbuildPlugins: !webview ? [] : [
|
|
356
|
-
{
|
|
357
|
-
name: "@tomjs:vscode:inject",
|
|
358
|
-
setup(build) {
|
|
359
|
-
build.onLoad({ filter: /\.ts$/ }, async (args) => {
|
|
360
|
-
const file = _fs2.default.readFileSync(args.path, "utf-8");
|
|
361
|
-
if (file.includes(`${webview.name}(`)) {
|
|
362
|
-
return {
|
|
363
|
-
contents: `import ${webview.name} from \`${webviewPath}\`;
|
|
364
|
-
${file}`,
|
|
365
|
-
loader: "ts"
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
return {};
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
],
|
|
373
|
-
async onSuccess() {
|
|
374
|
-
if (typeof _onSuccess === "function") {
|
|
375
|
-
await _onSuccess();
|
|
376
|
-
}
|
|
377
|
-
logger.info("extension build success");
|
|
378
|
-
}
|
|
379
|
-
})
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
];
|
|
188
|
+
const opts = preMergeOptions(options);
|
|
189
|
+
const handleConfig = (config) => {
|
|
190
|
+
let outDir = config?.build?.outDir || "dist";
|
|
191
|
+
opts.extension ??= {};
|
|
192
|
+
if (opts.recommended) {
|
|
193
|
+
opts.extension.outDir = path.resolve(outDir, "extension");
|
|
194
|
+
outDir = path.resolve(outDir, "webview");
|
|
195
|
+
}
|
|
196
|
+
const assetsDir = config?.build?.assetsDir || "assets";
|
|
197
|
+
const output = {
|
|
198
|
+
chunkFileNames: `${assetsDir}/[name].js`,
|
|
199
|
+
entryFileNames: `${assetsDir}/[name].js`,
|
|
200
|
+
assetFileNames: `${assetsDir}/[name].[ext]`
|
|
201
|
+
};
|
|
202
|
+
let rollupOutput = config?.build?.rollupOptions?.output ?? {};
|
|
203
|
+
if (Array.isArray(rollupOutput)) rollupOutput.map((s) => Object.assign(s, output));
|
|
204
|
+
else rollupOutput = Object.assign({}, rollupOutput, output);
|
|
205
|
+
return { build: {
|
|
206
|
+
outDir,
|
|
207
|
+
sourcemap: isDev ? true : config?.build?.sourcemap,
|
|
208
|
+
rollupOptions: { output: rollupOutput }
|
|
209
|
+
} };
|
|
210
|
+
};
|
|
211
|
+
let devWebviewClient;
|
|
212
|
+
if (opts.webview) devWebviewClient = readFileSync(path.join(__dirname, "client.iife.js"));
|
|
213
|
+
let resolvedConfig;
|
|
214
|
+
const prodHtmlCache = {};
|
|
215
|
+
let devtoolsFlag = false;
|
|
216
|
+
return [{
|
|
217
|
+
name: "@tomjs:vscode",
|
|
218
|
+
apply: "serve",
|
|
219
|
+
config(config) {
|
|
220
|
+
return handleConfig(config);
|
|
221
|
+
},
|
|
222
|
+
configResolved(config) {
|
|
223
|
+
resolvedConfig = config;
|
|
224
|
+
},
|
|
225
|
+
configureServer(server) {
|
|
226
|
+
if (!server || !server.httpServer) return;
|
|
227
|
+
server.httpServer?.once("listening", async () => {
|
|
228
|
+
const env = {
|
|
229
|
+
NODE_ENV: server.config.mode || "development",
|
|
230
|
+
VITE_DEV_SERVER_URL: resolveServerUrl(server)
|
|
231
|
+
};
|
|
232
|
+
logger.info("extension build start");
|
|
233
|
+
let buildCount = 0;
|
|
234
|
+
const webview = opts?.webview;
|
|
235
|
+
const { onSuccess: _onSuccess, ignoreWatch, silent, watchFiles,...tsdownOptions } = opts.extension || {};
|
|
236
|
+
await build(merge(tsdownOptions, {
|
|
237
|
+
watch: watchFiles ?? (opts.recommended ? ["extension"] : true),
|
|
238
|
+
ignoreWatch: [
|
|
239
|
+
".history",
|
|
240
|
+
".temp",
|
|
241
|
+
".tmp",
|
|
242
|
+
".cache",
|
|
243
|
+
"dist"
|
|
244
|
+
].concat(Array.isArray(ignoreWatch) ? ignoreWatch : []),
|
|
245
|
+
env,
|
|
246
|
+
silent: silent ?? true,
|
|
247
|
+
plugins: !webview ? [] : [{
|
|
248
|
+
name: `${ORG_NAME}:vscode:inject`,
|
|
249
|
+
transform(code, id) {
|
|
250
|
+
if (id.includes("node_modules")) return;
|
|
251
|
+
if (code.includes(`${webview.name}(`)) return `import ${webview.name} from '${PACKAGE_NAME}/webview';\n${code}`;
|
|
252
|
+
return code;
|
|
253
|
+
}
|
|
254
|
+
}],
|
|
255
|
+
async onSuccess(config, signal) {
|
|
256
|
+
if (_onSuccess) {
|
|
257
|
+
if (typeof _onSuccess === "string") await execa(_onSuccess);
|
|
258
|
+
else if (typeof _onSuccess === "function") await _onSuccess(config, signal);
|
|
259
|
+
}
|
|
260
|
+
if (buildCount++ > 1) logger.info("extension rebuild success");
|
|
261
|
+
else logger.info("extension build success");
|
|
262
|
+
}
|
|
263
|
+
}));
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
transformIndexHtml(html) {
|
|
267
|
+
if (!opts.webview) return html;
|
|
268
|
+
if (opts.devtools ?? true) {
|
|
269
|
+
let port;
|
|
270
|
+
if (resolvedConfig.plugins.find((s) => ["vite:react-refresh", "vite:react-swc"].includes(s.name))) port = 8097;
|
|
271
|
+
else if (resolvedConfig.plugins.find((s) => ["vite:vue", "vite:vue2"].includes(s.name))) port = 8098;
|
|
272
|
+
if (port) html = html.replace(/<head>/i, `<head><script src="http://localhost:${port}"><\/script>`);
|
|
273
|
+
else if (!devtoolsFlag) {
|
|
274
|
+
devtoolsFlag = true;
|
|
275
|
+
logger.warn("Only support react-devtools and vue-devtools!");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return html.replace(/<head>/i, `<head><script>${devWebviewClient}<\/script>`);
|
|
279
|
+
}
|
|
280
|
+
}, {
|
|
281
|
+
name: "@tomjs:vscode",
|
|
282
|
+
apply: "build",
|
|
283
|
+
enforce: "post",
|
|
284
|
+
config(config) {
|
|
285
|
+
return handleConfig(config);
|
|
286
|
+
},
|
|
287
|
+
configResolved(config) {
|
|
288
|
+
resolvedConfig = config;
|
|
289
|
+
},
|
|
290
|
+
transformIndexHtml(html, ctx) {
|
|
291
|
+
if (!opts.webview) return html;
|
|
292
|
+
prodHtmlCache[ctx.chunk?.name] = html;
|
|
293
|
+
return html;
|
|
294
|
+
},
|
|
295
|
+
closeBundle() {
|
|
296
|
+
let webviewPath;
|
|
297
|
+
const webview = opts?.webview;
|
|
298
|
+
if (webview) webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
299
|
+
let outDir = resolvedConfig.build.outDir.replace(cwd(), "").replaceAll("\\", "/");
|
|
300
|
+
if (outDir.startsWith("/")) outDir = outDir.substring(1);
|
|
301
|
+
const env = {
|
|
302
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
303
|
+
VITE_WEBVIEW_DIST: outDir
|
|
304
|
+
};
|
|
305
|
+
logger.info("extension build start");
|
|
306
|
+
const { onSuccess: _onSuccess, silent,...tsupOptions } = opts.extension || {};
|
|
307
|
+
build(merge(tsupOptions, {
|
|
308
|
+
env,
|
|
309
|
+
silent: silent ?? true,
|
|
310
|
+
plugins: !webview ? [] : [{
|
|
311
|
+
name: `${ORG_NAME}:vscode:inject`,
|
|
312
|
+
transform(code, id) {
|
|
313
|
+
if (id.includes("node_modules")) return;
|
|
314
|
+
if (code.includes(`${webview.name}(`)) return `import ${webview.name} from "${webviewPath}";\n${code}`;
|
|
315
|
+
return code;
|
|
316
|
+
}
|
|
317
|
+
}],
|
|
318
|
+
async onSuccess(config, signal) {
|
|
319
|
+
if (_onSuccess) {
|
|
320
|
+
if (typeof _onSuccess === "string") await execa(_onSuccess);
|
|
321
|
+
else if (typeof _onSuccess === "function") await _onSuccess(config, signal);
|
|
322
|
+
}
|
|
323
|
+
logger.info("extension build success");
|
|
324
|
+
}
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
}];
|
|
384
328
|
}
|
|
385
|
-
var
|
|
386
|
-
|
|
387
|
-
|
|
329
|
+
var src_default = useVSCodePlugin;
|
|
388
330
|
|
|
389
|
-
|
|
331
|
+
//#endregion
|
|
332
|
+
export { src_default as default, useVSCodePlugin };
|