unplugin-https-reverse-proxy 0.0.7 → 0.0.8

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
@@ -10,6 +10,12 @@ A plugin for https reverse proxy, support `vite` and `webpack`.
10
10
  npm i unplugin-https-reverse-proxy
11
11
  ```
12
12
 
13
+ ```ts
14
+ interface Options {
15
+ target: string // <- https target hostname
16
+ }
17
+ ```
18
+
13
19
  <details>
14
20
  <summary>Vite</summary><br>
15
21
 
@@ -40,6 +46,7 @@ module.exports = {
40
46
  // ↓ for HMR
41
47
  webSocketURL: {
42
48
  protocol: 'wss',
49
+ hostname: 'xxx', // <- target hostname
43
50
  port: 443,
44
51
  },
45
52
  },
@@ -79,6 +86,7 @@ module.exports = {
79
86
  // ↓ for HMR
80
87
  webSocketURL: {
81
88
  protocol: 'wss',
89
+ hostname: 'xxx', // <- target hostname
82
90
  port: 443,
83
91
  },
84
92
  },
@@ -0,0 +1,9 @@
1
+ // src/utils.ts
2
+ import { createConsola } from "consola";
3
+ var consola = createConsola({
4
+ level: 3
5
+ }).withTag("reverse-proxy");
6
+
7
+ export {
8
+ consola
9
+ };
@@ -1,3 +1,7 @@
1
+ import {
2
+ consola
3
+ } from "./chunk-3HKPYCSE.js";
4
+
1
5
  // src/index.ts
2
6
  import process3 from "process";
3
7
  import { createUnplugin } from "unplugin";
@@ -293,15 +297,14 @@ var CaddyInstant = class {
293
297
  }
294
298
  });
295
299
  child.stdout.on("data", (_data) => {
296
- console.log(_data.toString());
300
+ consola.info(_data.toString());
297
301
  resolve(async () => {
298
302
  if (!restore)
299
303
  return;
300
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
301
- console.log("restore host success\n");
302
- } else {
303
- console.error("restore host failed\n");
304
- }
304
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
305
+ consola.success("restore host success\n");
306
+ else
307
+ consola.fail("restore host failed\n");
305
308
  child.kill();
306
309
  });
307
310
  });
@@ -324,11 +327,13 @@ var unpluginFactory = (options) => ({
324
327
  target = ""
325
328
  } = options;
326
329
  if (!target) {
327
- console.log("please provide target");
330
+ consola.fail("please provide target");
328
331
  return;
329
332
  }
333
+ const _printUrls = server.printUrls;
330
334
  server.printUrls = () => {
331
335
  var _a;
336
+ _printUrls();
332
337
  let source = `localhost:${config.server.port}`;
333
338
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
334
339
  if (url) {
@@ -342,7 +347,7 @@ var unpluginFactory = (options) => ({
342
347
  base
343
348
  }).then((stop) => {
344
349
  const colorUrl = (url2) => c.green(url2.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
345
- console.log(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
350
+ consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
346
351
  process3.on("SIGINT", async () => {
347
352
  await stop();
348
353
  server.close();
@@ -350,7 +355,7 @@ var unpluginFactory = (options) => ({
350
355
  });
351
356
  });
352
357
  } catch (e) {
353
- console.error(e);
358
+ consola.error(e);
354
359
  }
355
360
  };
356
361
  }
@@ -360,7 +365,7 @@ var unpluginFactory = (options) => ({
360
365
  target = ""
361
366
  } = options;
362
367
  if (!target) {
363
- console.log("please provide target");
368
+ consola.fail("please provide target");
364
369
  return;
365
370
  }
366
371
  try {
@@ -374,7 +379,7 @@ var unpluginFactory = (options) => ({
374
379
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
375
380
  if (stats.hasErrors())
376
381
  return;
377
- console.log(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
382
+ consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
378
383
  });
379
384
  process3.on("SIGINT", async () => {
380
385
  await stop();
@@ -384,7 +389,7 @@ var unpluginFactory = (options) => ({
384
389
  throw e;
385
390
  });
386
391
  } catch (e) {
387
- console.error(e);
392
+ consola.error(e);
388
393
  }
389
394
  }
390
395
  });
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-BWNBY4RY.js";
3
+ } from "./chunk-H5P77DDT.js";
4
4
 
5
5
  // src/vite.ts
6
6
  import { createVitePlugin } from "unplugin";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-BWNBY4RY.js";
3
+ } from "./chunk-H5P77DDT.js";
4
4
 
5
5
  // src/webpack.ts
6
6
  import { createWebpackPlugin } from "unplugin";
package/dist/esbuild.cjs CHANGED
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
40
40
  var import_unplugin = require("unplugin");
41
41
  var import_picocolors = __toESM(require("picocolors"), 1);
42
42
 
43
+ // src/utils.ts
44
+ var import_consola = require("consola");
45
+ var consola = (0, import_consola.createConsola)({
46
+ level: 3
47
+ }).withTag("reverse-proxy");
48
+
43
49
  // src/caddy/index.ts
44
50
  var import_node_os = require("os");
45
51
  var import_node_process2 = __toESM(require("process"), 1);
@@ -330,15 +336,14 @@ var CaddyInstant = class {
330
336
  }
331
337
  });
332
338
  child.stdout.on("data", (_data) => {
333
- console.log(_data.toString());
339
+ consola.info(_data.toString());
334
340
  resolve(async () => {
335
341
  if (!restore)
336
342
  return;
337
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
338
- console.log("restore host success\n");
339
- } else {
340
- console.error("restore host failed\n");
341
- }
343
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
344
+ consola.success("restore host success\n");
345
+ else
346
+ consola.fail("restore host failed\n");
342
347
  child.kill();
343
348
  });
344
349
  });
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
361
366
  target = ""
362
367
  } = options;
363
368
  if (!target) {
364
- console.log("please provide target");
369
+ consola.fail("please provide target");
365
370
  return;
366
371
  }
372
+ const _printUrls = server.printUrls;
367
373
  server.printUrls = () => {
368
374
  var _a;
375
+ _printUrls();
369
376
  let source = `localhost:${config.server.port}`;
370
377
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
371
378
  if (url) {
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
379
386
  base
380
387
  }).then((stop) => {
381
388
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
382
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
389
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
383
390
  import_node_process3.default.on("SIGINT", async () => {
384
391
  await stop();
385
392
  server.close();
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
387
394
  });
388
395
  });
389
396
  } catch (e) {
390
- console.error(e);
397
+ consola.error(e);
391
398
  }
392
399
  };
393
400
  }
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
397
404
  target = ""
398
405
  } = options;
399
406
  if (!target) {
400
- console.log("please provide target");
407
+ consola.fail("please provide target");
401
408
  return;
402
409
  }
403
410
  try {
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
411
418
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
412
419
  if (stats.hasErrors())
413
420
  return;
414
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
421
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
415
422
  });
416
423
  import_node_process3.default.on("SIGINT", async () => {
417
424
  await stop();
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
421
428
  throw e;
422
429
  });
423
430
  } catch (e) {
424
- console.error(e);
431
+ consola.error(e);
425
432
  }
426
433
  }
427
434
  });
package/dist/esbuild.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-BWNBY4RY.js";
3
+ } from "./chunk-H5P77DDT.js";
4
+ import "./chunk-3HKPYCSE.js";
4
5
 
5
6
  // src/esbuild.ts
6
7
  import { createEsbuildPlugin } from "unplugin";
package/dist/index.cjs CHANGED
@@ -39,6 +39,12 @@ var import_node_process3 = __toESM(require("process"), 1);
39
39
  var import_unplugin = require("unplugin");
40
40
  var import_picocolors = __toESM(require("picocolors"), 1);
41
41
 
42
+ // src/utils.ts
43
+ var import_consola = require("consola");
44
+ var consola = (0, import_consola.createConsola)({
45
+ level: 3
46
+ }).withTag("reverse-proxy");
47
+
42
48
  // src/caddy/index.ts
43
49
  var import_node_os = require("os");
44
50
  var import_node_process2 = __toESM(require("process"), 1);
@@ -329,15 +335,14 @@ var CaddyInstant = class {
329
335
  }
330
336
  });
331
337
  child.stdout.on("data", (_data) => {
332
- console.log(_data.toString());
338
+ consola.info(_data.toString());
333
339
  resolve(async () => {
334
340
  if (!restore)
335
341
  return;
336
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
337
- console.log("restore host success\n");
338
- } else {
339
- console.error("restore host failed\n");
340
- }
342
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
343
+ consola.success("restore host success\n");
344
+ else
345
+ consola.fail("restore host failed\n");
341
346
  child.kill();
342
347
  });
343
348
  });
@@ -360,11 +365,13 @@ var unpluginFactory = (options) => ({
360
365
  target = ""
361
366
  } = options;
362
367
  if (!target) {
363
- console.log("please provide target");
368
+ consola.fail("please provide target");
364
369
  return;
365
370
  }
371
+ const _printUrls = server.printUrls;
366
372
  server.printUrls = () => {
367
373
  var _a;
374
+ _printUrls();
368
375
  let source = `localhost:${config.server.port}`;
369
376
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
370
377
  if (url) {
@@ -378,7 +385,7 @@ var unpluginFactory = (options) => ({
378
385
  base
379
386
  }).then((stop) => {
380
387
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
381
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
388
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
382
389
  import_node_process3.default.on("SIGINT", async () => {
383
390
  await stop();
384
391
  server.close();
@@ -386,7 +393,7 @@ var unpluginFactory = (options) => ({
386
393
  });
387
394
  });
388
395
  } catch (e) {
389
- console.error(e);
396
+ consola.error(e);
390
397
  }
391
398
  };
392
399
  }
@@ -396,7 +403,7 @@ var unpluginFactory = (options) => ({
396
403
  target = ""
397
404
  } = options;
398
405
  if (!target) {
399
- console.log("please provide target");
406
+ consola.fail("please provide target");
400
407
  return;
401
408
  }
402
409
  try {
@@ -410,7 +417,7 @@ var unpluginFactory = (options) => ({
410
417
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
411
418
  if (stats.hasErrors())
412
419
  return;
413
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
420
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
414
421
  });
415
422
  import_node_process3.default.on("SIGINT", async () => {
416
423
  await stop();
@@ -420,7 +427,7 @@ var unpluginFactory = (options) => ({
420
427
  throw e;
421
428
  });
422
429
  } catch (e) {
423
- console.error(e);
430
+ consola.error(e);
424
431
  }
425
432
  }
426
433
  });
package/dist/index.js CHANGED
@@ -2,7 +2,8 @@ import {
2
2
  src_default,
3
3
  unplugin,
4
4
  unpluginFactory
5
- } from "./chunk-BWNBY4RY.js";
5
+ } from "./chunk-H5P77DDT.js";
6
+ import "./chunk-3HKPYCSE.js";
6
7
  export {
7
8
  src_default as default,
8
9
  unplugin,
package/dist/nuxt.cjs CHANGED
@@ -43,6 +43,12 @@ var import_node_process3 = __toESM(require("process"), 1);
43
43
  var import_unplugin = require("unplugin");
44
44
  var import_picocolors = __toESM(require("picocolors"), 1);
45
45
 
46
+ // src/utils.ts
47
+ var import_consola = require("consola");
48
+ var consola = (0, import_consola.createConsola)({
49
+ level: 3
50
+ }).withTag("reverse-proxy");
51
+
46
52
  // src/caddy/index.ts
47
53
  var import_node_os = require("os");
48
54
  var import_node_process2 = __toESM(require("process"), 1);
@@ -333,15 +339,14 @@ var CaddyInstant = class {
333
339
  }
334
340
  });
335
341
  child.stdout.on("data", (_data) => {
336
- console.log(_data.toString());
342
+ consola.info(_data.toString());
337
343
  resolve(async () => {
338
344
  if (!restore)
339
345
  return;
340
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
341
- console.log("restore host success\n");
342
- } else {
343
- console.error("restore host failed\n");
344
- }
346
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
347
+ consola.success("restore host success\n");
348
+ else
349
+ consola.fail("restore host failed\n");
345
350
  child.kill();
346
351
  });
347
352
  });
@@ -364,11 +369,13 @@ var unpluginFactory = (options) => ({
364
369
  target = ""
365
370
  } = options;
366
371
  if (!target) {
367
- console.log("please provide target");
372
+ consola.fail("please provide target");
368
373
  return;
369
374
  }
375
+ const _printUrls = server.printUrls;
370
376
  server.printUrls = () => {
371
377
  var _a;
378
+ _printUrls();
372
379
  let source = `localhost:${config.server.port}`;
373
380
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
374
381
  if (url) {
@@ -382,7 +389,7 @@ var unpluginFactory = (options) => ({
382
389
  base
383
390
  }).then((stop) => {
384
391
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
385
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
392
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
386
393
  import_node_process3.default.on("SIGINT", async () => {
387
394
  await stop();
388
395
  server.close();
@@ -390,7 +397,7 @@ var unpluginFactory = (options) => ({
390
397
  });
391
398
  });
392
399
  } catch (e) {
393
- console.error(e);
400
+ consola.error(e);
394
401
  }
395
402
  };
396
403
  }
@@ -400,7 +407,7 @@ var unpluginFactory = (options) => ({
400
407
  target = ""
401
408
  } = options;
402
409
  if (!target) {
403
- console.log("please provide target");
410
+ consola.fail("please provide target");
404
411
  return;
405
412
  }
406
413
  try {
@@ -414,7 +421,7 @@ var unpluginFactory = (options) => ({
414
421
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
415
422
  if (stats.hasErrors())
416
423
  return;
417
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
424
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
418
425
  });
419
426
  import_node_process3.default.on("SIGINT", async () => {
420
427
  await stop();
@@ -424,7 +431,7 @@ var unpluginFactory = (options) => ({
424
431
  throw e;
425
432
  });
426
433
  } catch (e) {
427
- console.error(e);
434
+ consola.error(e);
428
435
  }
429
436
  }
430
437
  });
package/dist/nuxt.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-CCEFFLWU.js";
3
+ } from "./chunk-HSJJYR6E.js";
4
4
  import {
5
5
  webpack_default
6
- } from "./chunk-YJTJH7KX.js";
7
- import "./chunk-BWNBY4RY.js";
6
+ } from "./chunk-JN5C2QIT.js";
7
+ import "./chunk-H5P77DDT.js";
8
+ import "./chunk-3HKPYCSE.js";
8
9
 
9
10
  // src/nuxt.ts
10
11
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
package/dist/rollup.cjs CHANGED
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
40
40
  var import_unplugin = require("unplugin");
41
41
  var import_picocolors = __toESM(require("picocolors"), 1);
42
42
 
43
+ // src/utils.ts
44
+ var import_consola = require("consola");
45
+ var consola = (0, import_consola.createConsola)({
46
+ level: 3
47
+ }).withTag("reverse-proxy");
48
+
43
49
  // src/caddy/index.ts
44
50
  var import_node_os = require("os");
45
51
  var import_node_process2 = __toESM(require("process"), 1);
@@ -330,15 +336,14 @@ var CaddyInstant = class {
330
336
  }
331
337
  });
332
338
  child.stdout.on("data", (_data) => {
333
- console.log(_data.toString());
339
+ consola.info(_data.toString());
334
340
  resolve(async () => {
335
341
  if (!restore)
336
342
  return;
337
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
338
- console.log("restore host success\n");
339
- } else {
340
- console.error("restore host failed\n");
341
- }
343
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
344
+ consola.success("restore host success\n");
345
+ else
346
+ consola.fail("restore host failed\n");
342
347
  child.kill();
343
348
  });
344
349
  });
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
361
366
  target = ""
362
367
  } = options;
363
368
  if (!target) {
364
- console.log("please provide target");
369
+ consola.fail("please provide target");
365
370
  return;
366
371
  }
372
+ const _printUrls = server.printUrls;
367
373
  server.printUrls = () => {
368
374
  var _a;
375
+ _printUrls();
369
376
  let source = `localhost:${config.server.port}`;
370
377
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
371
378
  if (url) {
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
379
386
  base
380
387
  }).then((stop) => {
381
388
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
382
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
389
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
383
390
  import_node_process3.default.on("SIGINT", async () => {
384
391
  await stop();
385
392
  server.close();
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
387
394
  });
388
395
  });
389
396
  } catch (e) {
390
- console.error(e);
397
+ consola.error(e);
391
398
  }
392
399
  };
393
400
  }
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
397
404
  target = ""
398
405
  } = options;
399
406
  if (!target) {
400
- console.log("please provide target");
407
+ consola.fail("please provide target");
401
408
  return;
402
409
  }
403
410
  try {
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
411
418
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
412
419
  if (stats.hasErrors())
413
420
  return;
414
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
421
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
415
422
  });
416
423
  import_node_process3.default.on("SIGINT", async () => {
417
424
  await stop();
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
421
428
  throw e;
422
429
  });
423
430
  } catch (e) {
424
- console.error(e);
431
+ consola.error(e);
425
432
  }
426
433
  }
427
434
  });
package/dist/rollup.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-BWNBY4RY.js";
3
+ } from "./chunk-H5P77DDT.js";
4
+ import "./chunk-3HKPYCSE.js";
4
5
 
5
6
  // src/rollup.ts
6
7
  import { createRollupPlugin } from "unplugin";
package/dist/utils.cjs ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils.ts
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ consola: () => consola
24
+ });
25
+ module.exports = __toCommonJS(utils_exports);
26
+ var import_consola = require("consola");
27
+ var consola = (0, import_consola.createConsola)({
28
+ level: 3
29
+ }).withTag("reverse-proxy");
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ consola
33
+ });
34
+ exports.default = module.exports;
@@ -0,0 +1,5 @@
1
+ import * as consola_dist_core from 'consola/dist/core';
2
+
3
+ declare const consola: consola_dist_core.ConsolaInstance;
4
+
5
+ export { consola };
@@ -0,0 +1,5 @@
1
+ import * as consola_dist_core from 'consola/dist/core';
2
+
3
+ declare const consola: consola_dist_core.ConsolaInstance;
4
+
5
+ export { consola };
package/dist/utils.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ consola
3
+ } from "./chunk-3HKPYCSE.js";
4
+ export {
5
+ consola
6
+ };
package/dist/vite.cjs CHANGED
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
40
40
  var import_unplugin = require("unplugin");
41
41
  var import_picocolors = __toESM(require("picocolors"), 1);
42
42
 
43
+ // src/utils.ts
44
+ var import_consola = require("consola");
45
+ var consola = (0, import_consola.createConsola)({
46
+ level: 3
47
+ }).withTag("reverse-proxy");
48
+
43
49
  // src/caddy/index.ts
44
50
  var import_node_os = require("os");
45
51
  var import_node_process2 = __toESM(require("process"), 1);
@@ -330,15 +336,14 @@ var CaddyInstant = class {
330
336
  }
331
337
  });
332
338
  child.stdout.on("data", (_data) => {
333
- console.log(_data.toString());
339
+ consola.info(_data.toString());
334
340
  resolve(async () => {
335
341
  if (!restore)
336
342
  return;
337
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
338
- console.log("restore host success\n");
339
- } else {
340
- console.error("restore host failed\n");
341
- }
343
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
344
+ consola.success("restore host success\n");
345
+ else
346
+ consola.fail("restore host failed\n");
342
347
  child.kill();
343
348
  });
344
349
  });
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
361
366
  target = ""
362
367
  } = options;
363
368
  if (!target) {
364
- console.log("please provide target");
369
+ consola.fail("please provide target");
365
370
  return;
366
371
  }
372
+ const _printUrls = server.printUrls;
367
373
  server.printUrls = () => {
368
374
  var _a;
375
+ _printUrls();
369
376
  let source = `localhost:${config.server.port}`;
370
377
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
371
378
  if (url) {
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
379
386
  base
380
387
  }).then((stop) => {
381
388
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
382
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
389
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
383
390
  import_node_process3.default.on("SIGINT", async () => {
384
391
  await stop();
385
392
  server.close();
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
387
394
  });
388
395
  });
389
396
  } catch (e) {
390
- console.error(e);
397
+ consola.error(e);
391
398
  }
392
399
  };
393
400
  }
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
397
404
  target = ""
398
405
  } = options;
399
406
  if (!target) {
400
- console.log("please provide target");
407
+ consola.fail("please provide target");
401
408
  return;
402
409
  }
403
410
  try {
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
411
418
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
412
419
  if (stats.hasErrors())
413
420
  return;
414
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
421
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
415
422
  });
416
423
  import_node_process3.default.on("SIGINT", async () => {
417
424
  await stop();
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
421
428
  throw e;
422
429
  });
423
430
  } catch (e) {
424
- console.error(e);
431
+ consola.error(e);
425
432
  }
426
433
  }
427
434
  });
package/dist/vite.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-CCEFFLWU.js";
4
- import "./chunk-BWNBY4RY.js";
3
+ } from "./chunk-HSJJYR6E.js";
4
+ import "./chunk-H5P77DDT.js";
5
+ import "./chunk-3HKPYCSE.js";
5
6
  export {
6
7
  vite_default as default
7
8
  };
package/dist/webpack.cjs CHANGED
@@ -40,6 +40,12 @@ var import_node_process3 = __toESM(require("process"), 1);
40
40
  var import_unplugin = require("unplugin");
41
41
  var import_picocolors = __toESM(require("picocolors"), 1);
42
42
 
43
+ // src/utils.ts
44
+ var import_consola = require("consola");
45
+ var consola = (0, import_consola.createConsola)({
46
+ level: 3
47
+ }).withTag("reverse-proxy");
48
+
43
49
  // src/caddy/index.ts
44
50
  var import_node_os = require("os");
45
51
  var import_node_process2 = __toESM(require("process"), 1);
@@ -330,15 +336,14 @@ var CaddyInstant = class {
330
336
  }
331
337
  });
332
338
  child.stdout.on("data", (_data) => {
333
- console.log(_data.toString());
339
+ consola.info(_data.toString());
334
340
  resolve(async () => {
335
341
  if (!restore)
336
342
  return;
337
- if (await this.restoreHost(source.split(":")[0], target.split(":")[0])) {
338
- console.log("restore host success\n");
339
- } else {
340
- console.error("restore host failed\n");
341
- }
343
+ if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
344
+ consola.success("restore host success\n");
345
+ else
346
+ consola.fail("restore host failed\n");
342
347
  child.kill();
343
348
  });
344
349
  });
@@ -361,11 +366,13 @@ var unpluginFactory = (options) => ({
361
366
  target = ""
362
367
  } = options;
363
368
  if (!target) {
364
- console.log("please provide target");
369
+ consola.fail("please provide target");
365
370
  return;
366
371
  }
372
+ const _printUrls = server.printUrls;
367
373
  server.printUrls = () => {
368
374
  var _a;
375
+ _printUrls();
369
376
  let source = `localhost:${config.server.port}`;
370
377
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
371
378
  if (url) {
@@ -379,7 +386,7 @@ var unpluginFactory = (options) => ({
379
386
  base
380
387
  }).then((stop) => {
381
388
  const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
382
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
389
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
383
390
  import_node_process3.default.on("SIGINT", async () => {
384
391
  await stop();
385
392
  server.close();
@@ -387,7 +394,7 @@ var unpluginFactory = (options) => ({
387
394
  });
388
395
  });
389
396
  } catch (e) {
390
- console.error(e);
397
+ consola.error(e);
391
398
  }
392
399
  };
393
400
  }
@@ -397,7 +404,7 @@ var unpluginFactory = (options) => ({
397
404
  target = ""
398
405
  } = options;
399
406
  if (!target) {
400
- console.log("please provide target");
407
+ consola.fail("please provide target");
401
408
  return;
402
409
  }
403
410
  try {
@@ -411,7 +418,7 @@ var unpluginFactory = (options) => ({
411
418
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", (stats) => {
412
419
  if (stats.hasErrors())
413
420
  return;
414
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
421
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
415
422
  });
416
423
  import_node_process3.default.on("SIGINT", async () => {
417
424
  await stop();
@@ -421,7 +428,7 @@ var unpluginFactory = (options) => ({
421
428
  throw e;
422
429
  });
423
430
  } catch (e) {
424
- console.error(e);
431
+ consola.error(e);
425
432
  }
426
433
  }
427
434
  });
package/dist/webpack.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  webpack_default
3
- } from "./chunk-YJTJH7KX.js";
4
- import "./chunk-BWNBY4RY.js";
3
+ } from "./chunk-JN5C2QIT.js";
4
+ import "./chunk-H5P77DDT.js";
5
+ import "./chunk-3HKPYCSE.js";
5
6
  export {
6
7
  webpack_default as default
7
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-https-reverse-proxy",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "packageManager": "pnpm@8.6.12",
6
6
  "description": "",
7
7
  "license": "MIT",
@@ -103,6 +103,7 @@
103
103
  }
104
104
  },
105
105
  "dependencies": {
106
+ "consola": "^3.2.3",
106
107
  "esno": "^0.17.0",
107
108
  "got-cjs": "^12.5.4",
108
109
  "hostile": "^1.3.3",
@@ -1,4 +1,5 @@
1
1
  import { existsSync, unlinkSync } from 'node:fs'
2
+ import { consola } from '../src/utils'
2
3
  import { download } from '../src/caddy'
3
4
  import { caddyPath } from '../src/caddy/constants'
4
5
 
@@ -8,7 +9,7 @@ async function run() {
8
9
  await download()
9
10
  }
10
11
  catch (e: any) {
11
- console.log(e.code)
12
+ consola.error(e.code)
12
13
  }
13
14
  }
14
15
 
@@ -7,6 +7,7 @@ import { HttpProxyAgent } from 'http-proxy-agent'
7
7
  import { HttpsProxyAgent } from 'https-proxy-agent'
8
8
  import * as hostile from 'hostile'
9
9
  import kill from 'kill-port'
10
+ import { consola } from '../utils'
10
11
  import { caddyPath, supportList } from './constants'
11
12
  import { tryPort } from './utils'
12
13
 
@@ -53,7 +54,7 @@ export async function download() {
53
54
  chmodSync(caddyPath, 0o755)
54
55
  resolve(caddyPath)
55
56
  }).on('error', (err) => {
56
- // console.log(err)
57
+ // consola.error(err)
57
58
  reject(err)
58
59
  })
59
60
  })
@@ -191,19 +192,17 @@ export class CaddyInstant {
191
192
  })
192
193
 
193
194
  child.stdout.on('data', (_data) => {
194
- // eslint-disable-next-line no-console
195
- console.log(_data.toString())
195
+ consola.info(_data.toString())
196
196
  resolve(async () => {
197
197
  if (!restore)
198
198
  return
199
199
 
200
- if (await this.restoreHost(source.split(':')[0], target.split(':')[0])) {
201
- // eslint-disable-next-line no-console
202
- console.log('restore host success\n')
203
- }
204
- else {
205
- console.error('restore host failed\n')
206
- }
200
+ if (await this.restoreHost(source.split(':')[0], target.split(':')[0]))
201
+ consola.success('restore host success\n')
202
+
203
+ else
204
+ consola.fail('restore host failed\n')
205
+
207
206
  child.kill()
208
207
  })
209
208
  })
@@ -19,7 +19,6 @@ export function tryPort(port: number) {
19
19
  })
20
20
  }
21
21
  catch (e) {
22
- // console.log(e)
23
22
  resolve(true)
24
23
  }
25
24
  })
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import type { UnpluginFactory } from 'unplugin'
3
3
  import { createUnplugin } from 'unplugin'
4
4
  import type { ResolvedConfig } from 'vite'
5
5
  import c from 'picocolors'
6
+ import { consola } from './utils'
6
7
  import type { Options } from './types'
7
8
  import { CaddyInstant } from './caddy'
8
9
 
@@ -22,11 +23,12 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
22
23
  target = '',
23
24
  } = options
24
25
  if (!target) {
25
- // eslint-disable-next-line no-console
26
- console.log('please provide target')
26
+ consola.fail('please provide target')
27
27
  return
28
28
  }
29
+ const _printUrls = server.printUrls
29
30
  server.printUrls = () => {
31
+ _printUrls()
30
32
  let source = `localhost:${config.server.port}`
31
33
  const url = server.resolvedUrls?.local[0]
32
34
  if (url) {
@@ -40,8 +42,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
40
42
  base,
41
43
  }).then((stop) => {
42
44
  const colorUrl = (url: string) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`))
43
- // eslint-disable-next-line no-console
44
- console.log(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}${base}`)}`)
45
+ consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}${base}`)}`)
45
46
 
46
47
  process.on('SIGINT', async () => {
47
48
  await stop()
@@ -51,7 +52,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
51
52
  })
52
53
  }
53
54
  catch (e) {
54
- console.error(e)
55
+ consola.error(e)
55
56
  }
56
57
  }
57
58
  },
@@ -61,8 +62,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
61
62
  target = '',
62
63
  } = options
63
64
  if (!target) {
64
- // eslint-disable-next-line no-console
65
- console.log('please provide target')
65
+ consola.fail('please provide target')
66
66
  return
67
67
  }
68
68
  try {
@@ -82,8 +82,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
82
82
  if (stats.hasErrors())
83
83
  return
84
84
 
85
- // eslint-disable-next-line no-console
86
- console.log(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}`)}`)
85
+ consola.success(` ${c.green('➜')} ${c.bold('run caddy reverse proxy success')}: ${colorUrl(`https://${target}`)}`)
87
86
  })
88
87
 
89
88
  process.on('SIGINT', async () => {
@@ -95,7 +94,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
95
94
  })
96
95
  }
97
96
  catch (e) {
98
- console.error(e)
97
+ consola.error(e)
99
98
  }
100
99
  },
101
100
  })
package/src/utils.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { createConsola } from 'consola'
2
+
3
+ export const consola = createConsola({
4
+ level: 3,
5
+ }).withTag('reverse-proxy')