unplugin-https-reverse-proxy 1.0.0-beta.1 → 1.0.0-beta.3

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.
@@ -17,11 +17,21 @@ var __spreadValues = (a, b) => {
17
17
 
18
18
  // src/utils.ts
19
19
  import process from "process";
20
+ import path from "path";
21
+ import { chmod, readdir, stat } from "fs/promises";
20
22
  import { execSync } from "child_process";
21
23
  import { createConsola } from "consola";
22
24
  var consola = createConsola({
23
25
  level: 3
24
26
  }).withTag("reverse-proxy");
27
+ async function chmodRecursive(_path, mode) {
28
+ await chmod(_path, mode);
29
+ if ((await stat(_path)).isDirectory()) {
30
+ const children = await readdir(_path);
31
+ for (const child of children)
32
+ await chmodRecursive(path.join(_path, child), mode);
33
+ }
34
+ }
25
35
  function once(fn) {
26
36
  let called = false;
27
37
  return (...args) => {
@@ -47,6 +57,7 @@ function isAdmin() {
47
57
  export {
48
58
  __spreadValues,
49
59
  consola,
60
+ chmodRecursive,
50
61
  once,
51
62
  isAdmin
52
63
  };
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  __spreadValues,
3
+ chmodRecursive,
3
4
  consola,
4
- isAdmin
5
- } from "./chunk-NNO3ZUSU.js";
5
+ isAdmin,
6
+ once
7
+ } from "./chunk-RUJE3YFB.js";
6
8
 
7
9
  // src/index.ts
8
10
  import process4 from "process";
9
- import { chmodSync as chmodSync3, existsSync as existsSync2 } from "fs";
11
+ import { existsSync as existsSync2 } from "fs";
10
12
  import { createUnplugin } from "unplugin";
11
13
  import c from "picocolors";
12
14
 
@@ -390,15 +392,15 @@ var CaddyInstant = class {
390
392
  // src/index.ts
391
393
  var config;
392
394
  var caddy;
393
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
395
+ var pwd = process4.cwd();
396
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
394
397
  _printUrls == null ? void 0 : _printUrls();
395
- const pwd = process4.cwd();
396
398
  const viteCacheDir = `${pwd}/node_modules/.vite`;
397
399
  if (existsSync2(viteCacheDir))
398
- chmodSync3(viteCacheDir, 511);
400
+ chmodRecursive(viteCacheDir, 511);
399
401
  const nuxtCacheDir = `${pwd}/.nuxt`;
400
402
  if (existsSync2(nuxtCacheDir))
401
- chmodSync3(nuxtCacheDir, 511);
403
+ chmodRecursive(nuxtCacheDir, 511);
402
404
  try {
403
405
  if (caddy)
404
406
  return;
@@ -414,7 +416,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
414
416
  } catch (e) {
415
417
  consola.error(e);
416
418
  }
417
- }
419
+ });
418
420
  var unpluginFactory = (options) => ({
419
421
  name: "unplugin-https-reverse-proxy",
420
422
  enforce: "pre",
@@ -448,7 +450,7 @@ var unpluginFactory = (options) => ({
448
450
  source = u.host;
449
451
  }
450
452
  const base = server.config.base || "/";
451
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
453
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
452
454
  }
453
455
  },
454
456
  webpack(compiler) {
@@ -469,6 +471,9 @@ var unpluginFactory = (options) => ({
469
471
  consola.fail("please provide target");
470
472
  return;
471
473
  }
474
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`;
475
+ if (existsSync2(nuxtCacheDir))
476
+ chmodRecursive(nuxtCacheDir, 511);
472
477
  try {
473
478
  const devServer = __spreadValues(__spreadValues({
474
479
  host: "localhost",
package/dist/esbuild.cjs CHANGED
@@ -57,11 +57,30 @@ var import_picocolors = __toESM(require("picocolors"), 1);
57
57
 
58
58
  // src/utils.ts
59
59
  var import_node_process = __toESM(require("process"), 1);
60
+ var import_node_path = __toESM(require("path"), 1);
61
+ var import_promises = require("fs/promises");
60
62
  var import_node_child_process = require("child_process");
61
63
  var import_consola = require("consola");
62
64
  var consola = (0, import_consola.createConsola)({
63
65
  level: 3
64
66
  }).withTag("reverse-proxy");
67
+ async function chmodRecursive(_path, mode) {
68
+ await (0, import_promises.chmod)(_path, mode);
69
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
70
+ const children = await (0, import_promises.readdir)(_path);
71
+ for (const child of children)
72
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
73
+ }
74
+ }
75
+ function once(fn) {
76
+ let called = false;
77
+ return (...args) => {
78
+ if (called)
79
+ return;
80
+ called = true;
81
+ return fn(...args);
82
+ };
83
+ }
65
84
  function isAdmin() {
66
85
  if (import_node_process.default.platform === "win32") {
67
86
  try {
@@ -133,11 +152,11 @@ async function removeHost(ip, host) {
133
152
  }
134
153
 
135
154
  // src/caddy/constants.ts
136
- var import_node_path = require("path");
155
+ var import_node_path2 = require("path");
137
156
  var import_node_process3 = __toESM(require("process"), 1);
138
157
  var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
139
- var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
140
- var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
158
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
141
160
  var supportList = [
142
161
  {
143
162
  platform: "dragonfly",
@@ -455,15 +474,15 @@ var CaddyInstant = class {
455
474
  // src/index.ts
456
475
  var config;
457
476
  var caddy;
458
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
477
+ var pwd = import_node_process5.default.cwd();
478
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
459
479
  _printUrls == null ? void 0 : _printUrls();
460
- const pwd = import_node_process5.default.cwd();
461
480
  const viteCacheDir = `${pwd}/node_modules/.vite`;
462
481
  if ((0, import_node_fs3.existsSync)(viteCacheDir))
463
- (0, import_node_fs3.chmodSync)(viteCacheDir, 511);
482
+ chmodRecursive(viteCacheDir, 511);
464
483
  const nuxtCacheDir = `${pwd}/.nuxt`;
465
484
  if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
466
- (0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
485
+ chmodRecursive(nuxtCacheDir, 511);
467
486
  try {
468
487
  if (caddy)
469
488
  return;
@@ -479,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
479
498
  } catch (e) {
480
499
  consola.error(e);
481
500
  }
482
- }
501
+ });
483
502
  var unpluginFactory = (options) => ({
484
503
  name: "unplugin-https-reverse-proxy",
485
504
  enforce: "pre",
@@ -513,7 +532,7 @@ var unpluginFactory = (options) => ({
513
532
  source = u.host;
514
533
  }
515
534
  const base = server.config.base || "/";
516
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
535
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
517
536
  }
518
537
  },
519
538
  webpack(compiler) {
@@ -534,6 +553,9 @@ var unpluginFactory = (options) => ({
534
553
  consola.fail("please provide target");
535
554
  return;
536
555
  }
556
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`;
557
+ if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
558
+ chmodRecursive(nuxtCacheDir, 511);
537
559
  try {
538
560
  const devServer = __spreadValues(__spreadValues({
539
561
  host: "localhost",
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-DUCXH7CX.js";
4
- import "./chunk-NNO3ZUSU.js";
3
+ } from "./chunk-ZAZWZOPZ.js";
4
+ import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  import { createEsbuildPlugin } from "unplugin";
package/dist/index.cjs CHANGED
@@ -57,11 +57,30 @@ var import_picocolors = __toESM(require("picocolors"), 1);
57
57
 
58
58
  // src/utils.ts
59
59
  var import_node_process = __toESM(require("process"), 1);
60
+ var import_node_path = __toESM(require("path"), 1);
61
+ var import_promises = require("fs/promises");
60
62
  var import_node_child_process = require("child_process");
61
63
  var import_consola = require("consola");
62
64
  var consola = (0, import_consola.createConsola)({
63
65
  level: 3
64
66
  }).withTag("reverse-proxy");
67
+ async function chmodRecursive(_path, mode) {
68
+ await (0, import_promises.chmod)(_path, mode);
69
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
70
+ const children = await (0, import_promises.readdir)(_path);
71
+ for (const child of children)
72
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
73
+ }
74
+ }
75
+ function once(fn) {
76
+ let called = false;
77
+ return (...args) => {
78
+ if (called)
79
+ return;
80
+ called = true;
81
+ return fn(...args);
82
+ };
83
+ }
65
84
  function isAdmin() {
66
85
  if (import_node_process.default.platform === "win32") {
67
86
  try {
@@ -133,11 +152,11 @@ async function removeHost(ip, host) {
133
152
  }
134
153
 
135
154
  // src/caddy/constants.ts
136
- var import_node_path = require("path");
155
+ var import_node_path2 = require("path");
137
156
  var import_node_process3 = __toESM(require("process"), 1);
138
157
  var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
139
- var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
140
- var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
158
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
141
160
  var supportList = [
142
161
  {
143
162
  platform: "dragonfly",
@@ -455,15 +474,15 @@ var CaddyInstant = class {
455
474
  // src/index.ts
456
475
  var config;
457
476
  var caddy;
458
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
477
+ var pwd = import_node_process5.default.cwd();
478
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
459
479
  _printUrls == null ? void 0 : _printUrls();
460
- const pwd = import_node_process5.default.cwd();
461
480
  const viteCacheDir = `${pwd}/node_modules/.vite`;
462
481
  if ((0, import_node_fs3.existsSync)(viteCacheDir))
463
- (0, import_node_fs3.chmodSync)(viteCacheDir, 511);
482
+ chmodRecursive(viteCacheDir, 511);
464
483
  const nuxtCacheDir = `${pwd}/.nuxt`;
465
484
  if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
466
- (0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
485
+ chmodRecursive(nuxtCacheDir, 511);
467
486
  try {
468
487
  if (caddy)
469
488
  return;
@@ -479,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
479
498
  } catch (e) {
480
499
  consola.error(e);
481
500
  }
482
- }
501
+ });
483
502
  var unpluginFactory = (options) => ({
484
503
  name: "unplugin-https-reverse-proxy",
485
504
  enforce: "pre",
@@ -513,7 +532,7 @@ var unpluginFactory = (options) => ({
513
532
  source = u.host;
514
533
  }
515
534
  const base = server.config.base || "/";
516
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
535
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
517
536
  }
518
537
  },
519
538
  webpack(compiler) {
@@ -534,6 +553,9 @@ var unpluginFactory = (options) => ({
534
553
  consola.fail("please provide target");
535
554
  return;
536
555
  }
556
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`;
557
+ if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
558
+ chmodRecursive(nuxtCacheDir, 511);
537
559
  try {
538
560
  const devServer = __spreadValues(__spreadValues({
539
561
  host: "localhost",
package/dist/index.d.cts CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as _unplugin from 'unplugin';
2
2
  import { UnpluginFactory } from 'unplugin';
3
- import { ViteDevServer } from 'vite';
4
3
  import { Options } from './types.cjs';
5
4
 
6
- declare function vitePrintUrls(server: ViteDevServer, options: Options, source: string, target: string, base?: string, _printUrls?: () => void): void;
5
+ declare const vitePrintUrls: (options: Options, source: string, target: string, base?: string | undefined, _printUrls?: (() => void) | undefined) => void;
7
6
  declare const unpluginFactory: UnpluginFactory<Options>;
8
7
  declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
9
8
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as _unplugin from 'unplugin';
2
2
  import { UnpluginFactory } from 'unplugin';
3
- import { ViteDevServer } from 'vite';
4
3
  import { Options } from './types.js';
5
4
 
6
- declare function vitePrintUrls(server: ViteDevServer, options: Options, source: string, target: string, base?: string, _printUrls?: () => void): void;
5
+ declare const vitePrintUrls: (options: Options, source: string, target: string, base?: string | undefined, _printUrls?: (() => void) | undefined) => void;
7
6
  declare const unpluginFactory: UnpluginFactory<Options>;
8
7
  declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
9
8
 
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-DUCXH7CX.js";
7
- import "./chunk-NNO3ZUSU.js";
6
+ } from "./chunk-ZAZWZOPZ.js";
7
+ import "./chunk-RUJE3YFB.js";
8
8
  export {
9
9
  src_default as default,
10
10
  unplugin,
package/dist/nuxt.cjs CHANGED
@@ -47,24 +47,27 @@ __export(nuxt_exports, {
47
47
  default: () => nuxt_default
48
48
  });
49
49
  module.exports = __toCommonJS(nuxt_exports);
50
+ var import_node_process6 = __toESM(require("process"), 1);
50
51
  var import_kit = require("@nuxt/kit");
51
-
52
- // src/vite.ts
53
- var import_unplugin2 = require("unplugin");
54
-
55
- // src/index.ts
56
- var import_node_process5 = __toESM(require("process"), 1);
57
- var import_node_fs3 = require("fs");
58
- var import_unplugin = require("unplugin");
59
- var import_picocolors = __toESM(require("picocolors"), 1);
52
+ var import_schema = require("@nuxt/schema");
60
53
 
61
54
  // src/utils.ts
62
55
  var import_node_process = __toESM(require("process"), 1);
56
+ var import_node_path = __toESM(require("path"), 1);
57
+ var import_promises = require("fs/promises");
63
58
  var import_node_child_process = require("child_process");
64
59
  var import_consola = require("consola");
65
60
  var consola = (0, import_consola.createConsola)({
66
61
  level: 3
67
62
  }).withTag("reverse-proxy");
63
+ async function chmodRecursive(_path, mode) {
64
+ await (0, import_promises.chmod)(_path, mode);
65
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
66
+ const children = await (0, import_promises.readdir)(_path);
67
+ for (const child of children)
68
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
69
+ }
70
+ }
68
71
  function once(fn) {
69
72
  let called = false;
70
73
  return (...args) => {
@@ -87,6 +90,12 @@ function isAdmin() {
87
90
  }
88
91
  }
89
92
 
93
+ // src/index.ts
94
+ var import_node_process5 = __toESM(require("process"), 1);
95
+ var import_node_fs3 = require("fs");
96
+ var import_unplugin = require("unplugin");
97
+ var import_picocolors = __toESM(require("picocolors"), 1);
98
+
90
99
  // src/caddy/index.ts
91
100
  var import_node_os = require("os");
92
101
  var import_node_process4 = __toESM(require("process"), 1);
@@ -145,11 +154,11 @@ async function removeHost(ip, host) {
145
154
  }
146
155
 
147
156
  // src/caddy/constants.ts
148
- var import_node_path = require("path");
157
+ var import_node_path2 = require("path");
149
158
  var import_node_process3 = __toESM(require("process"), 1);
150
159
  var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
151
- var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
152
- var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
160
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
161
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
153
162
  var supportList = [
154
163
  {
155
164
  platform: "dragonfly",
@@ -465,17 +474,16 @@ var CaddyInstant = class {
465
474
  };
466
475
 
467
476
  // src/index.ts
468
- var config;
469
477
  var caddy;
470
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
478
+ var pwd = import_node_process5.default.cwd();
479
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
471
480
  _printUrls == null ? void 0 : _printUrls();
472
- const pwd = import_node_process5.default.cwd();
473
481
  const viteCacheDir = `${pwd}/node_modules/.vite`;
474
482
  if ((0, import_node_fs3.existsSync)(viteCacheDir))
475
- (0, import_node_fs3.chmodSync)(viteCacheDir, 511);
483
+ chmodRecursive(viteCacheDir, 511);
476
484
  const nuxtCacheDir = `${pwd}/.nuxt`;
477
485
  if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
478
- (0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
486
+ chmodRecursive(nuxtCacheDir, 511);
479
487
  try {
480
488
  if (caddy)
481
489
  return;
@@ -491,50 +499,20 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
491
499
  } catch (e) {
492
500
  consola.error(e);
493
501
  }
494
- }
495
- var unpluginFactory = (options) => ({
496
- name: "unplugin-https-reverse-proxy",
497
- enforce: "pre",
498
- vite: {
499
- configResolved(_config) {
500
- config = _config;
501
- },
502
- configureServer(server) {
503
- var _a;
504
- if (!isAdmin()) {
505
- consola.warn("please run as administrator");
506
- return;
507
- }
508
- if (config.command === "build")
509
- return;
510
- const {
511
- enable = true,
512
- target = ""
513
- } = options;
514
- if (!enable)
515
- return;
516
- if (!target) {
517
- consola.fail("please provide target");
518
- return;
519
- }
520
- const _printUrls = server.printUrls.bind(server);
521
- let source = `localhost:${config.server.port || 5173}`;
522
- const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
523
- if (url) {
524
- const u = new URL(url);
525
- source = u.host;
526
- }
527
- const base = server.config.base || "/";
528
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
529
- }
502
+ });
503
+
504
+ // src/nuxt.ts
505
+ var nuxt_default = (0, import_kit.defineNuxtModule)({
506
+ meta: {
507
+ name: "nuxt-unplugin-https-reverse-proxy",
508
+ configKey: "unpluginHttpsReverseProxy"
530
509
  },
531
- webpack(compiler) {
532
- var _a;
510
+ setup(options, _nuxt) {
533
511
  if (!isAdmin()) {
534
512
  consola.warn("please run as administrator");
535
513
  return;
536
514
  }
537
- if (import_node_process5.default.env.NODE_ENV !== "development")
515
+ if (import_node_process6.default.env.NODE_ENV !== "development")
538
516
  return;
539
517
  const {
540
518
  enable = true,
@@ -546,69 +524,12 @@ var unpluginFactory = (options) => ({
546
524
  consola.fail("please provide target");
547
525
  return;
548
526
  }
549
- try {
550
- const devServer = __spreadValues(__spreadValues({
551
- host: "localhost",
552
- port: 8080
553
- }, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
554
- const source = `${devServer.host}:${devServer.port}`;
555
- if (caddy)
556
- return;
557
- const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
558
- if (_close) {
559
- compiler.close = async (callback) => {
560
- import_node_process5.default.on("exit", () => {
561
- _close && _close(callback);
562
- });
563
- };
564
- } else {
565
- options.https = false;
566
- }
567
- caddy = new CaddyInstant();
568
- caddy.run(source, target, __spreadValues({}, options)).then(() => {
569
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
570
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
571
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
572
- });
573
- }).catch((e) => {
574
- throw e;
575
- });
576
- } catch (e) {
577
- consola.error(e);
578
- }
579
- }
580
- });
581
-
582
- // src/vite.ts
583
- var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
584
-
585
- // src/webpack.ts
586
- var import_unplugin3 = require("unplugin");
587
- var webpack_default = (0, import_unplugin3.createWebpackPlugin)(unpluginFactory);
588
-
589
- // src/nuxt.ts
590
- var import_schema = require("@nuxt/schema");
591
- var nuxt_default = (0, import_kit.defineNuxtModule)({
592
- meta: {
593
- name: "nuxt-unplugin-https-reverse-proxy",
594
- configKey: "unpluginHttpsReverseProxy"
595
- },
596
- setup(options, _nuxt) {
597
- (0, import_kit.addVitePlugin)(() => vite_default(options));
598
- (0, import_kit.addWebpackPlugin)(() => webpack_default(options));
599
- let url = "";
600
527
  _nuxt.hook("listen", (_, listener) => {
601
- url = listener.url;
602
- });
603
- _nuxt.hook("vite:serverCreated", once((server) => {
528
+ const url = listener.url;
604
529
  const source = new URL(url).host;
605
- if (!options.target) {
606
- consola.fail("please provide target");
607
- return;
608
- }
609
530
  const base = _nuxt.options.app.baseURL || "/";
610
- vitePrintUrls(server, options, source, options.target, base);
611
- }));
531
+ vitePrintUrls(options, source, options.target, base);
532
+ });
612
533
  }
613
534
  });
614
535
  exports.default = module.exports;
package/dist/nuxt.js CHANGED
@@ -1,19 +1,14 @@
1
- import {
2
- vite_default
3
- } from "./chunk-Y5ZVZOMP.js";
4
- import {
5
- webpack_default
6
- } from "./chunk-QIKJQBZH.js";
7
1
  import {
8
2
  vitePrintUrls
9
- } from "./chunk-DUCXH7CX.js";
3
+ } from "./chunk-ZAZWZOPZ.js";
10
4
  import {
11
5
  consola,
12
- once
13
- } from "./chunk-NNO3ZUSU.js";
6
+ isAdmin
7
+ } from "./chunk-RUJE3YFB.js";
14
8
 
15
9
  // src/nuxt.ts
16
- import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
10
+ import process from "process";
11
+ import { defineNuxtModule } from "@nuxt/kit";
17
12
  import "@nuxt/schema";
18
13
  var nuxt_default = defineNuxtModule({
19
14
  meta: {
@@ -21,21 +16,28 @@ var nuxt_default = defineNuxtModule({
21
16
  configKey: "unpluginHttpsReverseProxy"
22
17
  },
23
18
  setup(options, _nuxt) {
24
- addVitePlugin(() => vite_default(options));
25
- addWebpackPlugin(() => webpack_default(options));
26
- let url = "";
19
+ if (!isAdmin()) {
20
+ consola.warn("please run as administrator");
21
+ return;
22
+ }
23
+ if (process.env.NODE_ENV !== "development")
24
+ return;
25
+ const {
26
+ enable = true,
27
+ target = ""
28
+ } = options;
29
+ if (!enable)
30
+ return;
31
+ if (!target) {
32
+ consola.fail("please provide target");
33
+ return;
34
+ }
27
35
  _nuxt.hook("listen", (_, listener) => {
28
- url = listener.url;
29
- });
30
- _nuxt.hook("vite:serverCreated", once((server) => {
36
+ const url = listener.url;
31
37
  const source = new URL(url).host;
32
- if (!options.target) {
33
- consola.fail("please provide target");
34
- return;
35
- }
36
38
  const base = _nuxt.options.app.baseURL || "/";
37
- vitePrintUrls(server, options, source, options.target, base);
38
- }));
39
+ vitePrintUrls(options, source, options.target, base);
40
+ });
39
41
  }
40
42
  });
41
43
  export {
package/dist/rollup.cjs CHANGED
@@ -57,11 +57,30 @@ var import_picocolors = __toESM(require("picocolors"), 1);
57
57
 
58
58
  // src/utils.ts
59
59
  var import_node_process = __toESM(require("process"), 1);
60
+ var import_node_path = __toESM(require("path"), 1);
61
+ var import_promises = require("fs/promises");
60
62
  var import_node_child_process = require("child_process");
61
63
  var import_consola = require("consola");
62
64
  var consola = (0, import_consola.createConsola)({
63
65
  level: 3
64
66
  }).withTag("reverse-proxy");
67
+ async function chmodRecursive(_path, mode) {
68
+ await (0, import_promises.chmod)(_path, mode);
69
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
70
+ const children = await (0, import_promises.readdir)(_path);
71
+ for (const child of children)
72
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
73
+ }
74
+ }
75
+ function once(fn) {
76
+ let called = false;
77
+ return (...args) => {
78
+ if (called)
79
+ return;
80
+ called = true;
81
+ return fn(...args);
82
+ };
83
+ }
65
84
  function isAdmin() {
66
85
  if (import_node_process.default.platform === "win32") {
67
86
  try {
@@ -133,11 +152,11 @@ async function removeHost(ip, host) {
133
152
  }
134
153
 
135
154
  // src/caddy/constants.ts
136
- var import_node_path = require("path");
155
+ var import_node_path2 = require("path");
137
156
  var import_node_process3 = __toESM(require("process"), 1);
138
157
  var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
139
- var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
140
- var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
158
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
141
160
  var supportList = [
142
161
  {
143
162
  platform: "dragonfly",
@@ -455,15 +474,15 @@ var CaddyInstant = class {
455
474
  // src/index.ts
456
475
  var config;
457
476
  var caddy;
458
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
477
+ var pwd = import_node_process5.default.cwd();
478
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
459
479
  _printUrls == null ? void 0 : _printUrls();
460
- const pwd = import_node_process5.default.cwd();
461
480
  const viteCacheDir = `${pwd}/node_modules/.vite`;
462
481
  if ((0, import_node_fs3.existsSync)(viteCacheDir))
463
- (0, import_node_fs3.chmodSync)(viteCacheDir, 511);
482
+ chmodRecursive(viteCacheDir, 511);
464
483
  const nuxtCacheDir = `${pwd}/.nuxt`;
465
484
  if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
466
- (0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
485
+ chmodRecursive(nuxtCacheDir, 511);
467
486
  try {
468
487
  if (caddy)
469
488
  return;
@@ -479,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
479
498
  } catch (e) {
480
499
  consola.error(e);
481
500
  }
482
- }
501
+ });
483
502
  var unpluginFactory = (options) => ({
484
503
  name: "unplugin-https-reverse-proxy",
485
504
  enforce: "pre",
@@ -513,7 +532,7 @@ var unpluginFactory = (options) => ({
513
532
  source = u.host;
514
533
  }
515
534
  const base = server.config.base || "/";
516
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
535
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
517
536
  }
518
537
  },
519
538
  webpack(compiler) {
@@ -534,6 +553,9 @@ var unpluginFactory = (options) => ({
534
553
  consola.fail("please provide target");
535
554
  return;
536
555
  }
556
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`;
557
+ if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
558
+ chmodRecursive(nuxtCacheDir, 511);
537
559
  try {
538
560
  const devServer = __spreadValues(__spreadValues({
539
561
  host: "localhost",
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-DUCXH7CX.js";
4
- import "./chunk-NNO3ZUSU.js";
3
+ } from "./chunk-ZAZWZOPZ.js";
4
+ import "./chunk-RUJE3YFB.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  import { createRollupPlugin } from "unplugin";
package/dist/utils.cjs CHANGED
@@ -30,17 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/utils.ts
31
31
  var utils_exports = {};
32
32
  __export(utils_exports, {
33
+ chmodRecursive: () => chmodRecursive,
33
34
  consola: () => consola,
34
35
  isAdmin: () => isAdmin,
35
36
  once: () => once
36
37
  });
37
38
  module.exports = __toCommonJS(utils_exports);
38
39
  var import_node_process = __toESM(require("process"), 1);
40
+ var import_node_path = __toESM(require("path"), 1);
41
+ var import_promises = require("fs/promises");
39
42
  var import_node_child_process = require("child_process");
40
43
  var import_consola = require("consola");
41
44
  var consola = (0, import_consola.createConsola)({
42
45
  level: 3
43
46
  }).withTag("reverse-proxy");
47
+ async function chmodRecursive(_path, mode) {
48
+ await (0, import_promises.chmod)(_path, mode);
49
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
50
+ const children = await (0, import_promises.readdir)(_path);
51
+ for (const child of children)
52
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
53
+ }
54
+ }
44
55
  function once(fn) {
45
56
  let called = false;
46
57
  return (...args) => {
@@ -64,6 +75,7 @@ function isAdmin() {
64
75
  }
65
76
  // Annotate the CommonJS export names for ESM import in node:
66
77
  0 && (module.exports = {
78
+ chmodRecursive,
67
79
  consola,
68
80
  isAdmin,
69
81
  once
package/dist/utils.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as consola_dist_core from 'consola/dist/core';
2
2
 
3
3
  declare const consola: consola_dist_core.ConsolaInstance;
4
+ declare function chmodRecursive(_path: string, mode: number): Promise<void>;
4
5
  declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
5
6
  declare function isAdmin(): boolean | undefined;
6
7
 
7
- export { consola, isAdmin, once };
8
+ export { chmodRecursive, consola, isAdmin, once };
package/dist/utils.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as consola_dist_core from 'consola/dist/core';
2
2
 
3
3
  declare const consola: consola_dist_core.ConsolaInstance;
4
+ declare function chmodRecursive(_path: string, mode: number): Promise<void>;
4
5
  declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
5
6
  declare function isAdmin(): boolean | undefined;
6
7
 
7
- export { consola, isAdmin, once };
8
+ export { chmodRecursive, consola, isAdmin, once };
package/dist/utils.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import {
2
+ chmodRecursive,
2
3
  consola,
3
4
  isAdmin,
4
5
  once
5
- } from "./chunk-NNO3ZUSU.js";
6
+ } from "./chunk-RUJE3YFB.js";
6
7
  export {
8
+ chmodRecursive,
7
9
  consola,
8
10
  isAdmin,
9
11
  once
package/dist/vite.cjs CHANGED
@@ -57,11 +57,30 @@ var import_picocolors = __toESM(require("picocolors"), 1);
57
57
 
58
58
  // src/utils.ts
59
59
  var import_node_process = __toESM(require("process"), 1);
60
+ var import_node_path = __toESM(require("path"), 1);
61
+ var import_promises = require("fs/promises");
60
62
  var import_node_child_process = require("child_process");
61
63
  var import_consola = require("consola");
62
64
  var consola = (0, import_consola.createConsola)({
63
65
  level: 3
64
66
  }).withTag("reverse-proxy");
67
+ async function chmodRecursive(_path, mode) {
68
+ await (0, import_promises.chmod)(_path, mode);
69
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
70
+ const children = await (0, import_promises.readdir)(_path);
71
+ for (const child of children)
72
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
73
+ }
74
+ }
75
+ function once(fn) {
76
+ let called = false;
77
+ return (...args) => {
78
+ if (called)
79
+ return;
80
+ called = true;
81
+ return fn(...args);
82
+ };
83
+ }
65
84
  function isAdmin() {
66
85
  if (import_node_process.default.platform === "win32") {
67
86
  try {
@@ -133,11 +152,11 @@ async function removeHost(ip, host) {
133
152
  }
134
153
 
135
154
  // src/caddy/constants.ts
136
- var import_node_path = require("path");
155
+ var import_node_path2 = require("path");
137
156
  var import_node_process3 = __toESM(require("process"), 1);
138
157
  var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
139
- var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
140
- var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
158
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
141
160
  var supportList = [
142
161
  {
143
162
  platform: "dragonfly",
@@ -455,15 +474,15 @@ var CaddyInstant = class {
455
474
  // src/index.ts
456
475
  var config;
457
476
  var caddy;
458
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
477
+ var pwd = import_node_process5.default.cwd();
478
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
459
479
  _printUrls == null ? void 0 : _printUrls();
460
- const pwd = import_node_process5.default.cwd();
461
480
  const viteCacheDir = `${pwd}/node_modules/.vite`;
462
481
  if ((0, import_node_fs3.existsSync)(viteCacheDir))
463
- (0, import_node_fs3.chmodSync)(viteCacheDir, 511);
482
+ chmodRecursive(viteCacheDir, 511);
464
483
  const nuxtCacheDir = `${pwd}/.nuxt`;
465
484
  if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
466
- (0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
485
+ chmodRecursive(nuxtCacheDir, 511);
467
486
  try {
468
487
  if (caddy)
469
488
  return;
@@ -479,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
479
498
  } catch (e) {
480
499
  consola.error(e);
481
500
  }
482
- }
501
+ });
483
502
  var unpluginFactory = (options) => ({
484
503
  name: "unplugin-https-reverse-proxy",
485
504
  enforce: "pre",
@@ -513,7 +532,7 @@ var unpluginFactory = (options) => ({
513
532
  source = u.host;
514
533
  }
515
534
  const base = server.config.base || "/";
516
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
535
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
517
536
  }
518
537
  },
519
538
  webpack(compiler) {
@@ -534,6 +553,9 @@ var unpluginFactory = (options) => ({
534
553
  consola.fail("please provide target");
535
554
  return;
536
555
  }
556
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`;
557
+ if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
558
+ chmodRecursive(nuxtCacheDir, 511);
537
559
  try {
538
560
  const devServer = __spreadValues(__spreadValues({
539
561
  host: "localhost",
package/dist/vite.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import {
2
- vite_default
3
- } from "./chunk-Y5ZVZOMP.js";
4
- import "./chunk-DUCXH7CX.js";
5
- import "./chunk-NNO3ZUSU.js";
2
+ unpluginFactory
3
+ } from "./chunk-ZAZWZOPZ.js";
4
+ import "./chunk-RUJE3YFB.js";
5
+
6
+ // src/vite.ts
7
+ import { createVitePlugin } from "unplugin";
8
+ var vite_default = createVitePlugin(unpluginFactory);
6
9
  export {
7
10
  vite_default as default
8
11
  };
package/dist/webpack.cjs CHANGED
@@ -57,11 +57,30 @@ var import_picocolors = __toESM(require("picocolors"), 1);
57
57
 
58
58
  // src/utils.ts
59
59
  var import_node_process = __toESM(require("process"), 1);
60
+ var import_node_path = __toESM(require("path"), 1);
61
+ var import_promises = require("fs/promises");
60
62
  var import_node_child_process = require("child_process");
61
63
  var import_consola = require("consola");
62
64
  var consola = (0, import_consola.createConsola)({
63
65
  level: 3
64
66
  }).withTag("reverse-proxy");
67
+ async function chmodRecursive(_path, mode) {
68
+ await (0, import_promises.chmod)(_path, mode);
69
+ if ((await (0, import_promises.stat)(_path)).isDirectory()) {
70
+ const children = await (0, import_promises.readdir)(_path);
71
+ for (const child of children)
72
+ await chmodRecursive(import_node_path.default.join(_path, child), mode);
73
+ }
74
+ }
75
+ function once(fn) {
76
+ let called = false;
77
+ return (...args) => {
78
+ if (called)
79
+ return;
80
+ called = true;
81
+ return fn(...args);
82
+ };
83
+ }
65
84
  function isAdmin() {
66
85
  if (import_node_process.default.platform === "win32") {
67
86
  try {
@@ -133,11 +152,11 @@ async function removeHost(ip, host) {
133
152
  }
134
153
 
135
154
  // src/caddy/constants.ts
136
- var import_node_path = require("path");
155
+ var import_node_path2 = require("path");
137
156
  var import_node_process3 = __toESM(require("process"), 1);
138
157
  var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
139
- var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
140
- var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
158
+ var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
159
+ var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
141
160
  var supportList = [
142
161
  {
143
162
  platform: "dragonfly",
@@ -455,15 +474,15 @@ var CaddyInstant = class {
455
474
  // src/index.ts
456
475
  var config;
457
476
  var caddy;
458
- function vitePrintUrls(server, options, source, target, base = "/", _printUrls) {
477
+ var pwd = import_node_process5.default.cwd();
478
+ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
459
479
  _printUrls == null ? void 0 : _printUrls();
460
- const pwd = import_node_process5.default.cwd();
461
480
  const viteCacheDir = `${pwd}/node_modules/.vite`;
462
481
  if ((0, import_node_fs3.existsSync)(viteCacheDir))
463
- (0, import_node_fs3.chmodSync)(viteCacheDir, 511);
482
+ chmodRecursive(viteCacheDir, 511);
464
483
  const nuxtCacheDir = `${pwd}/.nuxt`;
465
484
  if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
466
- (0, import_node_fs3.chmodSync)(nuxtCacheDir, 511);
485
+ chmodRecursive(nuxtCacheDir, 511);
467
486
  try {
468
487
  if (caddy)
469
488
  return;
@@ -479,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
479
498
  } catch (e) {
480
499
  consola.error(e);
481
500
  }
482
- }
501
+ });
483
502
  var unpluginFactory = (options) => ({
484
503
  name: "unplugin-https-reverse-proxy",
485
504
  enforce: "pre",
@@ -513,7 +532,7 @@ var unpluginFactory = (options) => ({
513
532
  source = u.host;
514
533
  }
515
534
  const base = server.config.base || "/";
516
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
535
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
517
536
  }
518
537
  },
519
538
  webpack(compiler) {
@@ -534,6 +553,9 @@ var unpluginFactory = (options) => ({
534
553
  consola.fail("please provide target");
535
554
  return;
536
555
  }
556
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`;
557
+ if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
558
+ chmodRecursive(nuxtCacheDir, 511);
537
559
  try {
538
560
  const devServer = __spreadValues(__spreadValues({
539
561
  host: "localhost",
package/dist/webpack.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import {
2
- webpack_default
3
- } from "./chunk-QIKJQBZH.js";
4
- import "./chunk-DUCXH7CX.js";
5
- import "./chunk-NNO3ZUSU.js";
2
+ unpluginFactory
3
+ } from "./chunk-ZAZWZOPZ.js";
4
+ import "./chunk-RUJE3YFB.js";
5
+
6
+ // src/webpack.ts
7
+ import { createWebpackPlugin } from "unplugin";
8
+ var webpack_default = createWebpackPlugin(unpluginFactory);
6
9
  export {
7
10
  webpack_default as default
8
11
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-https-reverse-proxy",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.1",
4
+ "version": "1.0.0-beta.3",
5
5
  "packageManager": "pnpm@8.6.12",
6
6
  "description": "",
7
7
  "license": "MIT",
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import process from 'node:process'
2
- import { chmodSync, existsSync } from 'node:fs'
2
+ import { existsSync } from 'node:fs'
3
3
  import type { UnpluginFactory } from 'unplugin'
4
4
  import { createUnplugin } from 'unplugin'
5
- import type { ResolvedConfig, ViteDevServer } from 'vite'
5
+ import type { ResolvedConfig } from 'vite'
6
6
  import c from 'picocolors'
7
- import { consola, isAdmin } from './utils'
7
+ import { chmodRecursive, consola, isAdmin, once } from './utils'
8
8
  import type { Options } from './types'
9
9
  import { CaddyInstant } from './caddy'
10
10
 
@@ -12,24 +12,24 @@ let config: ResolvedConfig
12
12
 
13
13
  let caddy: CaddyInstant
14
14
 
15
- export function vitePrintUrls(
16
- server: ViteDevServer,
15
+ const pwd = process.cwd()
16
+
17
+ export const vitePrintUrls = once((
17
18
  options: Options,
18
19
  source: string,
19
20
  target: string,
20
21
  base: string = '/',
21
22
  _printUrls?: () => void,
22
- ) {
23
+ ) => {
23
24
  _printUrls?.()
24
25
 
25
26
  // fix `Error: EPERM: operation not permitted`
26
- const pwd = process.cwd()
27
27
  const viteCacheDir = `${pwd}/node_modules/.vite`
28
28
  if (existsSync(viteCacheDir))
29
- chmodSync(viteCacheDir, 0o777)
29
+ chmodRecursive(viteCacheDir, 0o777)
30
30
  const nuxtCacheDir = `${pwd}/.nuxt`
31
31
  if (existsSync(nuxtCacheDir))
32
- chmodSync(nuxtCacheDir, 0o777)
32
+ chmodRecursive(nuxtCacheDir, 0o777)
33
33
 
34
34
  try {
35
35
  if (caddy)
@@ -48,7 +48,7 @@ export function vitePrintUrls(
48
48
  catch (e) {
49
49
  consola.error(e)
50
50
  }
51
- }
51
+ })
52
52
 
53
53
  export const unpluginFactory: UnpluginFactory<Options> = options => ({
54
54
  name: 'unplugin-https-reverse-proxy',
@@ -88,7 +88,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
88
88
 
89
89
  const base = server.config.base || '/'
90
90
 
91
- server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls)
91
+ server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls)
92
92
  },
93
93
  },
94
94
  webpack(compiler) {
@@ -111,6 +111,10 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
111
111
  return
112
112
  }
113
113
 
114
+ const nuxtCacheDir = `${pwd}/node_modules/.cache`
115
+ if (existsSync(nuxtCacheDir))
116
+ chmodRecursive(nuxtCacheDir, 0o777)
117
+
114
118
  try {
115
119
  const devServer = {
116
120
  host: 'localhost',
package/src/nuxt.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from '@nuxt/kit'
2
- import type { ViteDevServer } from 'vite'
3
- import vite from './vite'
4
- import webpack from './webpack'
1
+ import process from 'node:process'
2
+ import { defineNuxtModule } from '@nuxt/kit'
5
3
  import type { Options } from './types'
6
4
  import '@nuxt/schema'
7
- import { consola, once } from './utils'
5
+ import { consola, isAdmin } from './utils'
8
6
  import { vitePrintUrls } from '.'
9
7
 
10
8
  export interface ModuleOptions extends Options {
@@ -17,26 +15,33 @@ export default defineNuxtModule<ModuleOptions>({
17
15
  configKey: 'unpluginHttpsReverseProxy',
18
16
  },
19
17
  setup(options, _nuxt) {
20
- addVitePlugin(() => vite(options))
21
- addWebpackPlugin(() => webpack(options))
18
+ if (!isAdmin()) {
19
+ consola.warn('please run as administrator')
20
+ return
21
+ }
22
+
23
+ if (process.env.NODE_ENV !== 'development')
24
+ return
25
+
26
+ const {
27
+ enable = true,
28
+ target = '',
29
+ } = options
30
+ if (!enable)
31
+ return
32
+ if (!target) {
33
+ consola.fail('please provide target')
34
+ return
35
+ }
22
36
 
23
37
  // https://github.com/nuxt/cli/issues/220#issuecomment-1735394141
24
- let url = ''
25
38
  _nuxt.hook('listen', (_, listener) => {
26
- url = listener.url
27
- })
28
-
29
- _nuxt.hook('vite:serverCreated', once((server: ViteDevServer) => {
39
+ const url = listener.url
30
40
  const source = new URL(url).host
31
41
 
32
- if (!options.target) {
33
- consola.fail('please provide target')
34
- return
35
- }
36
-
37
42
  const base = _nuxt.options.app.baseURL || '/'
38
43
 
39
- vitePrintUrls(server, options, source, options.target, base)
40
- }))
44
+ vitePrintUrls(options, source, options.target, base)
45
+ })
41
46
  },
42
47
  })
package/src/utils.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import process from 'node:process'
2
+ import path from 'node:path'
3
+ import { chmod, readdir, stat } from 'node:fs/promises'
2
4
  import { execSync } from 'node:child_process'
3
5
  import { createConsola } from 'consola'
4
6
 
@@ -6,6 +8,15 @@ export const consola = createConsola({
6
8
  level: 3,
7
9
  }).withTag('reverse-proxy')
8
10
 
11
+ export async function chmodRecursive(_path: string, mode: number) {
12
+ await chmod(_path, mode)
13
+ if ((await stat(_path)).isDirectory()) {
14
+ const children = await readdir(_path)
15
+ for (const child of children)
16
+ await chmodRecursive(path.join(_path, child), mode)
17
+ }
18
+ }
19
+
9
20
  export function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T> {
10
21
  let called = false
11
22
  return (...args: any[]) => {
@@ -1,11 +0,0 @@
1
- import {
2
- unpluginFactory
3
- } from "./chunk-DUCXH7CX.js";
4
-
5
- // src/webpack.ts
6
- import { createWebpackPlugin } from "unplugin";
7
- var webpack_default = createWebpackPlugin(unpluginFactory);
8
-
9
- export {
10
- webpack_default
11
- };
@@ -1,11 +0,0 @@
1
- import {
2
- unpluginFactory
3
- } from "./chunk-DUCXH7CX.js";
4
-
5
- // src/vite.ts
6
- import { createVitePlugin } from "unplugin";
7
- var vite_default = createVitePlugin(unpluginFactory);
8
-
9
- export {
10
- vite_default
11
- };