unplugin-https-reverse-proxy 1.0.0-beta.4 → 1.0.0-beta.6

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.
@@ -8,14 +8,13 @@ import {
8
8
 
9
9
  // src/index.ts
10
10
  import process4 from "process";
11
- import { existsSync as existsSync2 } from "fs";
12
11
  import { createUnplugin } from "unplugin";
13
12
  import c from "picocolors";
14
13
 
15
14
  // src/caddy/index.ts
16
15
  import { platform } from "os";
17
16
  import process3 from "process";
18
- import { chmodSync as chmodSync2, createWriteStream, existsSync, unlinkSync } from "fs";
17
+ import { chmodSync as chmodSync2, createWriteStream, existsSync, mkdirSync, unlinkSync } from "fs";
19
18
  import { spawn } from "child_process";
20
19
  import { got } from "got-cjs";
21
20
  import { HttpProxyAgent } from "http-proxy-agent";
@@ -72,7 +71,7 @@ async function removeHost(ip, host) {
72
71
  // src/caddy/constants.ts
73
72
  import { join } from "path";
74
73
  import process2 from "process";
75
- var TEMP_DIR = process2.env.TEMP || process2.env.TMPDIR || "/tmp";
74
+ var TEMP_DIR = process2.env.UHRP_CADDY_PATH || process2.env.TEMP || process2.env.TMPDIR || "/tmp";
76
75
  var caddyPath = join(TEMP_DIR, `caddy${process2.platform === "win32" ? ".exe" : ""}`);
77
76
  var caddyFilePath = join(TEMP_DIR, "CADDYFILE");
78
77
  var supportList = [
@@ -246,6 +245,10 @@ async function download() {
246
245
  if (await testCaddy())
247
246
  return caddyPath;
248
247
  return new Promise((resolve, reject) => {
248
+ if (!existsSync(TEMP_DIR)) {
249
+ mkdirSync(TEMP_DIR, { recursive: true });
250
+ chmodSync2(TEMP_DIR, 511);
251
+ }
249
252
  const file = createWriteStream(caddyPath);
250
253
  let _platform = platform().toString();
251
254
  _platform === "win32" && (_platform = "windows");
@@ -260,6 +263,9 @@ async function download() {
260
263
  const httpsProxy = process3.env.HTTPS_PROXY || process3.env.https_proxy;
261
264
  const httpAgent = httpProxy ? new HttpProxyAgent(httpProxy) : void 0;
262
265
  const httpsAgent = httpsProxy ? new HttpsProxyAgent(httpsProxy) : void 0;
266
+ const chmodCaddyOnce = once(() => {
267
+ chmodSync2(caddyPath, 511);
268
+ });
263
269
  got.stream(dowmloadLink, {
264
270
  agent: {
265
271
  http: httpAgent,
@@ -267,11 +273,12 @@ async function download() {
267
273
  }
268
274
  }).on("downloadProgress", (progress) => {
269
275
  logProgress(progress.percent);
276
+ chmodCaddyOnce();
270
277
  }).pipe(file).on("finish", () => {
271
278
  logProgressOver();
272
279
  if (process3.platform === "win32")
273
280
  return resolve(caddyPath);
274
- chmodSync2(caddyPath, 493);
281
+ chmodSync2(caddyPath, 511);
275
282
  resolve(caddyPath);
276
283
  }).on("error", (err) => {
277
284
  reject(err);
@@ -357,6 +364,16 @@ var CaddyInstant = class {
357
364
  const port = Number(source.split(":")[1]);
358
365
  if (!Number.isNaN(port) && await tryPort(port))
359
366
  await kill(port, "tcp");
367
+ const pwd2 = process3.cwd();
368
+ const viteCacheDir = `${pwd2}/node_modules/.vite`;
369
+ if (existsSync(viteCacheDir))
370
+ chmodRecursive(viteCacheDir, 511);
371
+ const nuxtCacheDir = `${pwd2}/.nuxt`;
372
+ if (existsSync(nuxtCacheDir))
373
+ await chmodRecursive(nuxtCacheDir, 511);
374
+ const webpackCacheDir = `${pwd2}/node_modules/.cache`;
375
+ if (existsSync(webpackCacheDir))
376
+ chmodRecursive(webpackCacheDir, 511);
360
377
  if (!restore || this.stoped)
361
378
  return originalExit(code);
362
379
  try {
@@ -398,27 +415,17 @@ var caddy;
398
415
  var pwd = process4.cwd();
399
416
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
400
417
  _printUrls == null ? void 0 : _printUrls();
401
- const viteCacheDir = `${pwd}/node_modules/.vite`;
402
- if (existsSync2(viteCacheDir))
403
- chmodRecursive(viteCacheDir, 511);
404
- const nuxtCacheDir = `${pwd}/.nuxt`;
405
- if (existsSync2(nuxtCacheDir))
406
- chmodRecursive(nuxtCacheDir, 511);
407
- try {
408
- if (caddy)
409
- return;
410
- caddy = new CaddyInstant();
411
- caddy.run(source, target, __spreadValues({
412
- base
413
- }, options)).then(() => {
414
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
415
- consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
416
- }).catch((e) => {
417
- throw e;
418
- });
419
- } catch (e) {
420
- consola.error(e);
421
- }
418
+ if (caddy)
419
+ return;
420
+ caddy = new CaddyInstant();
421
+ caddy.run(source, target, __spreadValues({
422
+ base
423
+ }, options)).then(() => {
424
+ const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
425
+ consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
426
+ }).catch((e) => {
427
+ throw e;
428
+ });
422
429
  });
423
430
  var unpluginFactory = (options) => ({
424
431
  name: "unplugin-https-reverse-proxy",
@@ -429,12 +436,12 @@ var unpluginFactory = (options) => ({
429
436
  },
430
437
  configureServer(server) {
431
438
  var _a;
439
+ if (config.command !== "serve")
440
+ return;
432
441
  if (!isAdmin()) {
433
442
  consola.warn("please run as administrator");
434
443
  return;
435
444
  }
436
- if (config.command === "build")
437
- return;
438
445
  const {
439
446
  enable = true,
440
447
  target = ""
@@ -458,12 +465,12 @@ var unpluginFactory = (options) => ({
458
465
  },
459
466
  webpack(compiler) {
460
467
  var _a;
468
+ if (process4.env.NODE_ENV !== "development")
469
+ return;
461
470
  if (!isAdmin()) {
462
471
  consola.warn("please run as administrator");
463
472
  return;
464
473
  }
465
- if (process4.env.NODE_ENV !== "development")
466
- return;
467
474
  const {
468
475
  enable = true,
469
476
  target = ""
@@ -474,39 +481,32 @@ var unpluginFactory = (options) => ({
474
481
  consola.fail("please provide target");
475
482
  return;
476
483
  }
477
- const nuxtCacheDir = `${pwd}/node_modules/.cache`;
478
- if (existsSync2(nuxtCacheDir))
479
- chmodRecursive(nuxtCacheDir, 511);
480
- try {
481
- const devServer = __spreadValues(__spreadValues({
482
- host: "localhost",
483
- port: 8080
484
- }, compiler.options.devServer), process4.VUE_CLI_SERVICE.projectOptions.devServer);
485
- const source = `${devServer.host}:${devServer.port}`;
486
- if (caddy)
487
- return;
488
- const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
489
- if (_close) {
490
- compiler.close = async (callback) => {
491
- process4.on("exit", () => {
492
- _close && _close(callback);
493
- });
494
- };
495
- } else {
496
- options.https = false;
497
- }
498
- caddy = new CaddyInstant();
499
- caddy.run(source, target, __spreadValues({}, options)).then(() => {
500
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
501
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
502
- consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
484
+ const devServer = __spreadValues(__spreadValues({
485
+ host: "localhost",
486
+ port: 8080
487
+ }, compiler.options.devServer), process4.VUE_CLI_SERVICE.projectOptions.devServer);
488
+ const source = `${devServer.host}:${devServer.port}`;
489
+ if (caddy)
490
+ return;
491
+ const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
492
+ if (_close) {
493
+ compiler.close = async (callback) => {
494
+ process4.on("exit", () => {
495
+ _close && _close(callback);
503
496
  });
504
- }).catch((e) => {
505
- throw e;
506
- });
507
- } catch (e) {
508
- consola.error(e);
497
+ };
498
+ } else {
499
+ options.https = false;
509
500
  }
501
+ caddy = new CaddyInstant();
502
+ caddy.run(source, target, __spreadValues({}, options)).then(() => {
503
+ const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
504
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
505
+ consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
506
+ });
507
+ }).catch((e) => {
508
+ throw e;
509
+ });
510
510
  }
511
511
  });
512
512
  var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
package/dist/esbuild.cjs CHANGED
@@ -51,7 +51,6 @@ var import_unplugin2 = require("unplugin");
51
51
 
52
52
  // src/index.ts
53
53
  var import_node_process5 = __toESM(require("process"), 1);
54
- var import_node_fs3 = require("fs");
55
54
  var import_unplugin = require("unplugin");
56
55
  var import_picocolors = __toESM(require("picocolors"), 1);
57
56
 
@@ -154,7 +153,7 @@ async function removeHost(ip, host) {
154
153
  // src/caddy/constants.ts
155
154
  var import_node_path2 = require("path");
156
155
  var import_node_process3 = __toESM(require("process"), 1);
157
- var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
156
+ var TEMP_DIR = import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
158
157
  var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
158
  var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
160
159
  var supportList = [
@@ -328,6 +327,10 @@ async function download() {
328
327
  if (await testCaddy())
329
328
  return caddyPath;
330
329
  return new Promise((resolve, reject) => {
330
+ if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
331
+ (0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
332
+ (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
333
+ }
331
334
  const file = (0, import_node_fs2.createWriteStream)(caddyPath);
332
335
  let _platform = (0, import_node_os.platform)().toString();
333
336
  _platform === "win32" && (_platform = "windows");
@@ -342,6 +345,9 @@ async function download() {
342
345
  const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
343
346
  const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
344
347
  const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
348
+ const chmodCaddyOnce = once(() => {
349
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
350
+ });
345
351
  import_got_cjs.got.stream(dowmloadLink, {
346
352
  agent: {
347
353
  http: httpAgent,
@@ -349,11 +355,12 @@ async function download() {
349
355
  }
350
356
  }).on("downloadProgress", (progress) => {
351
357
  logProgress(progress.percent);
358
+ chmodCaddyOnce();
352
359
  }).pipe(file).on("finish", () => {
353
360
  logProgressOver();
354
361
  if (import_node_process4.default.platform === "win32")
355
362
  return resolve(caddyPath);
356
- (0, import_node_fs2.chmodSync)(caddyPath, 493);
363
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
357
364
  resolve(caddyPath);
358
365
  }).on("error", (err) => {
359
366
  reject(err);
@@ -439,6 +446,16 @@ var CaddyInstant = class {
439
446
  const port = Number(source.split(":")[1]);
440
447
  if (!Number.isNaN(port) && await tryPort(port))
441
448
  await (0, import_kill_port.default)(port, "tcp");
449
+ const pwd2 = import_node_process4.default.cwd();
450
+ const viteCacheDir = `${pwd2}/node_modules/.vite`;
451
+ if ((0, import_node_fs2.existsSync)(viteCacheDir))
452
+ chmodRecursive(viteCacheDir, 511);
453
+ const nuxtCacheDir = `${pwd2}/.nuxt`;
454
+ if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
455
+ await chmodRecursive(nuxtCacheDir, 511);
456
+ const webpackCacheDir = `${pwd2}/node_modules/.cache`;
457
+ if ((0, import_node_fs2.existsSync)(webpackCacheDir))
458
+ chmodRecursive(webpackCacheDir, 511);
442
459
  if (!restore || this.stoped)
443
460
  return originalExit(code);
444
461
  try {
@@ -480,27 +497,17 @@ var caddy;
480
497
  var pwd = import_node_process5.default.cwd();
481
498
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
482
499
  _printUrls == null ? void 0 : _printUrls();
483
- const viteCacheDir = `${pwd}/node_modules/.vite`;
484
- if ((0, import_node_fs3.existsSync)(viteCacheDir))
485
- chmodRecursive(viteCacheDir, 511);
486
- const nuxtCacheDir = `${pwd}/.nuxt`;
487
- if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
488
- chmodRecursive(nuxtCacheDir, 511);
489
- try {
490
- if (caddy)
491
- return;
492
- caddy = new CaddyInstant();
493
- caddy.run(source, target, __spreadValues({
494
- base
495
- }, options)).then(() => {
496
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
497
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
498
- }).catch((e) => {
499
- throw e;
500
- });
501
- } catch (e) {
502
- consola.error(e);
503
- }
500
+ if (caddy)
501
+ return;
502
+ caddy = new CaddyInstant();
503
+ caddy.run(source, target, __spreadValues({
504
+ base
505
+ }, options)).then(() => {
506
+ const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
507
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
508
+ }).catch((e) => {
509
+ throw e;
510
+ });
504
511
  });
505
512
  var unpluginFactory = (options) => ({
506
513
  name: "unplugin-https-reverse-proxy",
@@ -511,12 +518,12 @@ var unpluginFactory = (options) => ({
511
518
  },
512
519
  configureServer(server) {
513
520
  var _a;
521
+ if (config.command !== "serve")
522
+ return;
514
523
  if (!isAdmin()) {
515
524
  consola.warn("please run as administrator");
516
525
  return;
517
526
  }
518
- if (config.command === "build")
519
- return;
520
527
  const {
521
528
  enable = true,
522
529
  target = ""
@@ -540,12 +547,12 @@ var unpluginFactory = (options) => ({
540
547
  },
541
548
  webpack(compiler) {
542
549
  var _a;
550
+ if (import_node_process5.default.env.NODE_ENV !== "development")
551
+ return;
543
552
  if (!isAdmin()) {
544
553
  consola.warn("please run as administrator");
545
554
  return;
546
555
  }
547
- if (import_node_process5.default.env.NODE_ENV !== "development")
548
- return;
549
556
  const {
550
557
  enable = true,
551
558
  target = ""
@@ -556,39 +563,32 @@ var unpluginFactory = (options) => ({
556
563
  consola.fail("please provide target");
557
564
  return;
558
565
  }
559
- const nuxtCacheDir = `${pwd}/node_modules/.cache`;
560
- if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
561
- chmodRecursive(nuxtCacheDir, 511);
562
- try {
563
- const devServer = __spreadValues(__spreadValues({
564
- host: "localhost",
565
- port: 8080
566
- }, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
567
- const source = `${devServer.host}:${devServer.port}`;
568
- if (caddy)
569
- return;
570
- const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
571
- if (_close) {
572
- compiler.close = async (callback) => {
573
- import_node_process5.default.on("exit", () => {
574
- _close && _close(callback);
575
- });
576
- };
577
- } else {
578
- options.https = false;
579
- }
580
- caddy = new CaddyInstant();
581
- caddy.run(source, target, __spreadValues({}, options)).then(() => {
582
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
583
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
584
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
566
+ const devServer = __spreadValues(__spreadValues({
567
+ host: "localhost",
568
+ port: 8080
569
+ }, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
570
+ const source = `${devServer.host}:${devServer.port}`;
571
+ if (caddy)
572
+ return;
573
+ const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
574
+ if (_close) {
575
+ compiler.close = async (callback) => {
576
+ import_node_process5.default.on("exit", () => {
577
+ _close && _close(callback);
585
578
  });
586
- }).catch((e) => {
587
- throw e;
588
- });
589
- } catch (e) {
590
- consola.error(e);
579
+ };
580
+ } else {
581
+ options.https = false;
591
582
  }
583
+ caddy = new CaddyInstant();
584
+ caddy.run(source, target, __spreadValues({}, options)).then(() => {
585
+ const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
586
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
587
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
588
+ });
589
+ }).catch((e) => {
590
+ throw e;
591
+ });
592
592
  }
593
593
  });
594
594
 
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-GAKOA5LE.js";
3
+ } from "./chunk-NBFRMP2Y.js";
4
4
  import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -51,7 +51,6 @@ __export(src_exports, {
51
51
  });
52
52
  module.exports = __toCommonJS(src_exports);
53
53
  var import_node_process5 = __toESM(require("process"), 1);
54
- var import_node_fs3 = require("fs");
55
54
  var import_unplugin = require("unplugin");
56
55
  var import_picocolors = __toESM(require("picocolors"), 1);
57
56
 
@@ -154,7 +153,7 @@ async function removeHost(ip, host) {
154
153
  // src/caddy/constants.ts
155
154
  var import_node_path2 = require("path");
156
155
  var import_node_process3 = __toESM(require("process"), 1);
157
- var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
156
+ var TEMP_DIR = import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
158
157
  var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
158
  var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
160
159
  var supportList = [
@@ -328,6 +327,10 @@ async function download() {
328
327
  if (await testCaddy())
329
328
  return caddyPath;
330
329
  return new Promise((resolve, reject) => {
330
+ if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
331
+ (0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
332
+ (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
333
+ }
331
334
  const file = (0, import_node_fs2.createWriteStream)(caddyPath);
332
335
  let _platform = (0, import_node_os.platform)().toString();
333
336
  _platform === "win32" && (_platform = "windows");
@@ -342,6 +345,9 @@ async function download() {
342
345
  const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
343
346
  const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
344
347
  const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
348
+ const chmodCaddyOnce = once(() => {
349
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
350
+ });
345
351
  import_got_cjs.got.stream(dowmloadLink, {
346
352
  agent: {
347
353
  http: httpAgent,
@@ -349,11 +355,12 @@ async function download() {
349
355
  }
350
356
  }).on("downloadProgress", (progress) => {
351
357
  logProgress(progress.percent);
358
+ chmodCaddyOnce();
352
359
  }).pipe(file).on("finish", () => {
353
360
  logProgressOver();
354
361
  if (import_node_process4.default.platform === "win32")
355
362
  return resolve(caddyPath);
356
- (0, import_node_fs2.chmodSync)(caddyPath, 493);
363
+ (0, import_node_fs2.chmodSync)(caddyPath, 511);
357
364
  resolve(caddyPath);
358
365
  }).on("error", (err) => {
359
366
  reject(err);
@@ -439,6 +446,16 @@ var CaddyInstant = class {
439
446
  const port = Number(source.split(":")[1]);
440
447
  if (!Number.isNaN(port) && await tryPort(port))
441
448
  await (0, import_kill_port.default)(port, "tcp");
449
+ const pwd2 = import_node_process4.default.cwd();
450
+ const viteCacheDir = `${pwd2}/node_modules/.vite`;
451
+ if ((0, import_node_fs2.existsSync)(viteCacheDir))
452
+ chmodRecursive(viteCacheDir, 511);
453
+ const nuxtCacheDir = `${pwd2}/.nuxt`;
454
+ if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
455
+ await chmodRecursive(nuxtCacheDir, 511);
456
+ const webpackCacheDir = `${pwd2}/node_modules/.cache`;
457
+ if ((0, import_node_fs2.existsSync)(webpackCacheDir))
458
+ chmodRecursive(webpackCacheDir, 511);
442
459
  if (!restore || this.stoped)
443
460
  return originalExit(code);
444
461
  try {
@@ -480,27 +497,17 @@ var caddy;
480
497
  var pwd = import_node_process5.default.cwd();
481
498
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
482
499
  _printUrls == null ? void 0 : _printUrls();
483
- const viteCacheDir = `${pwd}/node_modules/.vite`;
484
- if ((0, import_node_fs3.existsSync)(viteCacheDir))
485
- chmodRecursive(viteCacheDir, 511);
486
- const nuxtCacheDir = `${pwd}/.nuxt`;
487
- if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
488
- chmodRecursive(nuxtCacheDir, 511);
489
- try {
490
- if (caddy)
491
- return;
492
- caddy = new CaddyInstant();
493
- caddy.run(source, target, __spreadValues({
494
- base
495
- }, options)).then(() => {
496
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
497
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
498
- }).catch((e) => {
499
- throw e;
500
- });
501
- } catch (e) {
502
- consola.error(e);
503
- }
500
+ if (caddy)
501
+ return;
502
+ caddy = new CaddyInstant();
503
+ caddy.run(source, target, __spreadValues({
504
+ base
505
+ }, options)).then(() => {
506
+ const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
507
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
508
+ }).catch((e) => {
509
+ throw e;
510
+ });
504
511
  });
505
512
  var unpluginFactory = (options) => ({
506
513
  name: "unplugin-https-reverse-proxy",
@@ -511,12 +518,12 @@ var unpluginFactory = (options) => ({
511
518
  },
512
519
  configureServer(server) {
513
520
  var _a;
521
+ if (config.command !== "serve")
522
+ return;
514
523
  if (!isAdmin()) {
515
524
  consola.warn("please run as administrator");
516
525
  return;
517
526
  }
518
- if (config.command === "build")
519
- return;
520
527
  const {
521
528
  enable = true,
522
529
  target = ""
@@ -540,12 +547,12 @@ var unpluginFactory = (options) => ({
540
547
  },
541
548
  webpack(compiler) {
542
549
  var _a;
550
+ if (import_node_process5.default.env.NODE_ENV !== "development")
551
+ return;
543
552
  if (!isAdmin()) {
544
553
  consola.warn("please run as administrator");
545
554
  return;
546
555
  }
547
- if (import_node_process5.default.env.NODE_ENV !== "development")
548
- return;
549
556
  const {
550
557
  enable = true,
551
558
  target = ""
@@ -556,39 +563,32 @@ var unpluginFactory = (options) => ({
556
563
  consola.fail("please provide target");
557
564
  return;
558
565
  }
559
- const nuxtCacheDir = `${pwd}/node_modules/.cache`;
560
- if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
561
- chmodRecursive(nuxtCacheDir, 511);
562
- try {
563
- const devServer = __spreadValues(__spreadValues({
564
- host: "localhost",
565
- port: 8080
566
- }, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
567
- const source = `${devServer.host}:${devServer.port}`;
568
- if (caddy)
569
- return;
570
- const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
571
- if (_close) {
572
- compiler.close = async (callback) => {
573
- import_node_process5.default.on("exit", () => {
574
- _close && _close(callback);
575
- });
576
- };
577
- } else {
578
- options.https = false;
579
- }
580
- caddy = new CaddyInstant();
581
- caddy.run(source, target, __spreadValues({}, options)).then(() => {
582
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
583
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
584
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
566
+ const devServer = __spreadValues(__spreadValues({
567
+ host: "localhost",
568
+ port: 8080
569
+ }, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
570
+ const source = `${devServer.host}:${devServer.port}`;
571
+ if (caddy)
572
+ return;
573
+ const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
574
+ if (_close) {
575
+ compiler.close = async (callback) => {
576
+ import_node_process5.default.on("exit", () => {
577
+ _close && _close(callback);
585
578
  });
586
- }).catch((e) => {
587
- throw e;
588
- });
589
- } catch (e) {
590
- consola.error(e);
579
+ };
580
+ } else {
581
+ options.https = false;
591
582
  }
583
+ caddy = new CaddyInstant();
584
+ caddy.run(source, target, __spreadValues({}, options)).then(() => {
585
+ const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
586
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
587
+ consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
588
+ });
589
+ }).catch((e) => {
590
+ throw e;
591
+ });
592
592
  }
593
593
  });
594
594
  var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-GAKOA5LE.js";
6
+ } from "./chunk-NBFRMP2Y.js";
7
7
  import "./chunk-RUJE3YFB.js";
8
8
  export {
9
9
  src_default as default,