@tomjs/vite-plugin-vscode 6.1.0 → 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 CHANGED
@@ -406,7 +406,7 @@ Run `Debug Extension` through `vscode` to debug. For debugging tools, refer to [
406
406
  "background": {
407
407
  "activeOnStart": true,
408
408
  "beginsPattern": "^.*extension build start*$",
409
- "endsPattern": "^.*extension (build|rebuild) success.*$"
409
+ "endsPattern": "^.*extension build success.*$"
410
410
  }
411
411
  },
412
412
  "isBackground": true,
@@ -446,6 +446,7 @@ Open the [examples](./examples) directory, there are `vue` and `react` examples.
446
446
  - [vue](./examples/vue): Simple vue example.
447
447
  - [vue-esm](./examples/vue-esm): Simple vue (ESM Extension) example.
448
448
  - [vue-import](./examples/vue-import): Dynamic import() and multi-page examples.
449
+ - [vue-vite8](./examples/vue-rolldown): [vite8](https://vite.dev/) example.
449
450
 
450
451
  ## Related
451
452
 
package/README.zh_CN.md CHANGED
@@ -406,7 +406,7 @@ const value = await acquireVsCodeApi().getState();
406
406
  "background": {
407
407
  "activeOnStart": true,
408
408
  "beginsPattern": "^.*extension build start*$",
409
- "endsPattern": "^.*extension (build|rebuild) success.*$"
409
+ "endsPattern": "^.*extension build success.*$"
410
410
  }
411
411
  },
412
412
  "isBackground": true,
@@ -450,6 +450,7 @@ pnpm build
450
450
  - [vue](./examples/vue):简单的 vue 示例。
451
451
  - [vue-esm](./examples/vue-esm):简单的 vue(ESM 扩展)示例。
452
452
  - [vue-import](./examples/vue-import):动态 import() 和多页面示例。
453
+ - [vue-vite8](./examples/vue-rolldown): [vite8](https://cn.vite.dev/) 示例。
453
454
 
454
455
  ## 关联
455
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 Logger from "@tomjs/logger";
11
+ import { createLogger } from "vite";
11
12
 
12
- //#region node_modules/.pnpm/tsdown@0.18.4_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
+ //#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
- return new Logger({
27
+ function createLogger$1(logLevel) {
28
+ const logger$1 = createLogger(logLevel, {
28
29
  prefix: `[${PLUGIN_NAME}]`,
29
- time: true
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");
@@ -170,7 +186,7 @@ export default getWebviewHtml;
170
186
  }
171
187
  function useVSCodePlugin(options) {
172
188
  const opts = preMergeOptions(options);
173
- const handleConfig = (config) => {
189
+ const handleConfig = (config, isRolldown) => {
174
190
  let outDir = config?.build?.outDir || "dist";
175
191
  opts.extension ??= {};
176
192
  if (opts.recommended) {
@@ -178,18 +194,22 @@ function useVSCodePlugin(options) {
178
194
  outDir = path.resolve(outDir, "webview");
179
195
  }
180
196
  const assetsDir = config?.build?.assetsDir || "assets";
181
- const output = {
197
+ const outputDefault = {
182
198
  chunkFileNames: `${assetsDir}/[name].js`,
183
199
  entryFileNames: `${assetsDir}/[name].js`,
184
200
  assetFileNames: `${assetsDir}/[name].[ext]`
185
201
  };
186
- let rollupOutput = config?.build?.rollupOptions?.output ?? {};
187
- if (Array.isArray(rollupOutput)) rollupOutput.map((s) => Object.assign(s, output));
188
- else rollupOutput = Object.assign({}, rollupOutput, output);
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 });
189
209
  return { build: {
190
210
  outDir,
191
211
  sourcemap: isDev ? true : config?.build?.sourcemap,
192
- rollupOptions: { output: rollupOutput }
212
+ ...outputOptions
193
213
  } };
194
214
  };
195
215
  let devWebviewClientCode;
@@ -201,7 +221,7 @@ function useVSCodePlugin(options) {
201
221
  name: "@tomjs:vscode",
202
222
  apply: "serve",
203
223
  config(config) {
204
- return handleConfig(config);
224
+ return handleConfig(config, this && "rolldownVersion" in this.meta);
205
225
  },
206
226
  configResolved(config) {
207
227
  resolvedConfig = config;
@@ -218,9 +238,10 @@ function useVSCodePlugin(options) {
218
238
  VITE_DEV_SERVER_URL: resolveServerUrl(server)
219
239
  };
220
240
  logger.info("extension build start");
221
- let buildCount = 0;
222
241
  const webview = opts?.webview;
223
242
  const { onSuccess: _onSuccess, ignoreWatch, logLevel, watchFiles, ...tsdownOptions } = opts.extension || {};
243
+ const entryDir = path.dirname(tsdownOptions.entry);
244
+ let buildFlag = false;
224
245
  await build(merge(tsdownOptions, {
225
246
  watch: watchFiles ?? (opts.recommended ? ["extension"] : true),
226
247
  ignoreWatch: [
@@ -239,6 +260,13 @@ function useVSCodePlugin(options) {
239
260
  },
240
261
  load(id) {
241
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))}`);
242
270
  }
243
271
  }],
244
272
  async onSuccess(config, signal) {
@@ -246,9 +274,12 @@ function useVSCodePlugin(options) {
246
274
  if (typeof _onSuccess === "string") await execa(_onSuccess);
247
275
  else if (typeof _onSuccess === "function") await _onSuccess(config, signal);
248
276
  }
249
- if (buildCount++ > 1) logger.info("extension rebuild success");
250
- else logger.info("extension build success");
251
- }
277
+ if (!buildFlag) {
278
+ buildFlag = true;
279
+ logger.info("extension build success");
280
+ }
281
+ },
282
+ buildOptions: {}
252
283
  }));
253
284
  });
254
285
  },
@@ -271,7 +302,7 @@ function useVSCodePlugin(options) {
271
302
  apply: "build",
272
303
  enforce: "post",
273
304
  config(config) {
274
- return handleConfig(config);
305
+ return handleConfig(config, this && "rolldownVersion" in this.meta);
275
306
  },
276
307
  configResolved(config) {
277
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.1.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",
@@ -50,23 +50,22 @@
50
50
  "vite": ">=2"
51
51
  },
52
52
  "dependencies": {
53
- "@tomjs/logger": "^1.4.0",
54
53
  "@tomjs/node": "^2.2.3",
55
54
  "execa": "^9.6.1",
56
55
  "lodash.merge": "^4.6.2",
57
- "node-html-parser": "^7.0.1",
58
- "tsdown": "~0.18.4"
56
+ "node-html-parser": "^7.0.2",
57
+ "picocolors": "^1.1.1",
58
+ "tsdown": "~0.19.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@antfu/eslint-config": "^6.7.3",
62
- "@commitlint/cli": "^20.2.0",
62
+ "@commitlint/cli": "^20.3.1",
63
63
  "@tomjs/commitlint": "^5.0.0",
64
- "@tomjs/eslint": "^6.3.0",
65
- "@tomjs/stylelint": "^7.0.0",
66
- "@tomjs/tsconfig": "^3.0.1",
64
+ "@tomjs/eslint": "^6.5.0",
65
+ "@tomjs/stylelint": "^7.1.1",
66
+ "@tomjs/tsconfig": "^3.2.0",
67
67
  "@types/lodash.merge": "^4.6.9",
68
- "@types/node": "^20.19.27",
69
- "@vitejs/plugin-vue": "^6.0.3",
68
+ "@types/node": "^20.19.28",
70
69
  "cross-env": "^10.1.0",
71
70
  "eslint": "^9.39.2",
72
71
  "globals": "^16.5.0",
@@ -78,8 +77,7 @@
78
77
  "stylelint": "^16.26.1",
79
78
  "tsx": "^4.21.0",
80
79
  "typescript": "~5.9.3",
81
- "vite": "^7.3.0",
82
- "vue-tsc": "^3.2.1"
80
+ "vite": "^7.3.1"
83
81
  },
84
82
  "scripts": {
85
83
  "dev": "pnpm clean && tsdown --watch",