unplugin-https-reverse-proxy 1.0.0-beta.2 → 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.
- package/dist/{chunk-N6ZBBGYD.js → chunk-ZAZWZOPZ.js} +5 -4
- package/dist/esbuild.cjs +12 -3
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +12 -3
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +21 -113
- package/dist/nuxt.js +23 -21
- package/dist/rollup.cjs +12 -3
- package/dist/rollup.js +1 -1
- package/dist/vite.cjs +12 -3
- package/dist/vite.js +6 -3
- package/dist/webpack.cjs +12 -3
- package/dist/webpack.js +6 -3
- package/package.json +1 -1
- package/src/index.ts +6 -7
- package/src/nuxt.ts +24 -19
- package/dist/chunk-DDD5N75Y.js +0 -11
- package/dist/chunk-VGLXVBHU.js +0 -11
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
__spreadValues,
|
|
3
3
|
chmodRecursive,
|
|
4
4
|
consola,
|
|
5
|
-
isAdmin
|
|
5
|
+
isAdmin,
|
|
6
|
+
once
|
|
6
7
|
} from "./chunk-RUJE3YFB.js";
|
|
7
8
|
|
|
8
9
|
// src/index.ts
|
|
@@ -392,7 +393,7 @@ var CaddyInstant = class {
|
|
|
392
393
|
var config;
|
|
393
394
|
var caddy;
|
|
394
395
|
var pwd = process4.cwd();
|
|
395
|
-
|
|
396
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
396
397
|
_printUrls == null ? void 0 : _printUrls();
|
|
397
398
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
398
399
|
if (existsSync2(viteCacheDir))
|
|
@@ -415,7 +416,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
415
416
|
} catch (e) {
|
|
416
417
|
consola.error(e);
|
|
417
418
|
}
|
|
418
|
-
}
|
|
419
|
+
});
|
|
419
420
|
var unpluginFactory = (options) => ({
|
|
420
421
|
name: "unplugin-https-reverse-proxy",
|
|
421
422
|
enforce: "pre",
|
|
@@ -449,7 +450,7 @@ var unpluginFactory = (options) => ({
|
|
|
449
450
|
source = u.host;
|
|
450
451
|
}
|
|
451
452
|
const base = server.config.base || "/";
|
|
452
|
-
server.printUrls = () => vitePrintUrls(
|
|
453
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
453
454
|
}
|
|
454
455
|
},
|
|
455
456
|
webpack(compiler) {
|
package/dist/esbuild.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
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
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -466,7 +475,7 @@ var CaddyInstant = class {
|
|
|
466
475
|
var config;
|
|
467
476
|
var caddy;
|
|
468
477
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
478
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
479
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
480
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
481
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
498
|
} catch (e) {
|
|
490
499
|
consola.error(e);
|
|
491
500
|
}
|
|
492
|
-
}
|
|
501
|
+
});
|
|
493
502
|
var unpluginFactory = (options) => ({
|
|
494
503
|
name: "unplugin-https-reverse-proxy",
|
|
495
504
|
enforce: "pre",
|
|
@@ -523,7 +532,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
532
|
source = u.host;
|
|
524
533
|
}
|
|
525
534
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
535
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
536
|
}
|
|
528
537
|
},
|
|
529
538
|
webpack(compiler) {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
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
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -466,7 +475,7 @@ var CaddyInstant = class {
|
|
|
466
475
|
var config;
|
|
467
476
|
var caddy;
|
|
468
477
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
478
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
479
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
480
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
481
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
498
|
} catch (e) {
|
|
490
499
|
consola.error(e);
|
|
491
500
|
}
|
|
492
|
-
}
|
|
501
|
+
});
|
|
493
502
|
var unpluginFactory = (options) => ({
|
|
494
503
|
name: "unplugin-https-reverse-proxy",
|
|
495
504
|
enforce: "pre",
|
|
@@ -523,7 +532,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
532
|
source = u.host;
|
|
524
533
|
}
|
|
525
534
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
535
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
536
|
}
|
|
528
537
|
},
|
|
529
538
|
webpack(compiler) {
|
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
|
|
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
|
|
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
package/dist/nuxt.cjs
CHANGED
|
@@ -47,16 +47,9 @@ __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);
|
|
@@ -97,6 +90,12 @@ function isAdmin() {
|
|
|
97
90
|
}
|
|
98
91
|
}
|
|
99
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
|
+
|
|
100
99
|
// src/caddy/index.ts
|
|
101
100
|
var import_node_os = require("os");
|
|
102
101
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
@@ -475,10 +474,9 @@ var CaddyInstant = class {
|
|
|
475
474
|
};
|
|
476
475
|
|
|
477
476
|
// src/index.ts
|
|
478
|
-
var config;
|
|
479
477
|
var caddy;
|
|
480
478
|
var pwd = import_node_process5.default.cwd();
|
|
481
|
-
|
|
479
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
482
480
|
_printUrls == null ? void 0 : _printUrls();
|
|
483
481
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
484
482
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -501,50 +499,20 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
501
499
|
} catch (e) {
|
|
502
500
|
consola.error(e);
|
|
503
501
|
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
},
|
|
512
|
-
configureServer(server) {
|
|
513
|
-
var _a;
|
|
514
|
-
if (!isAdmin()) {
|
|
515
|
-
consola.warn("please run as administrator");
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
if (config.command === "build")
|
|
519
|
-
return;
|
|
520
|
-
const {
|
|
521
|
-
enable = true,
|
|
522
|
-
target = ""
|
|
523
|
-
} = options;
|
|
524
|
-
if (!enable)
|
|
525
|
-
return;
|
|
526
|
-
if (!target) {
|
|
527
|
-
consola.fail("please provide target");
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const _printUrls = server.printUrls.bind(server);
|
|
531
|
-
let source = `localhost:${config.server.port || 5173}`;
|
|
532
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
533
|
-
if (url) {
|
|
534
|
-
const u = new URL(url);
|
|
535
|
-
source = u.host;
|
|
536
|
-
}
|
|
537
|
-
const base = server.config.base || "/";
|
|
538
|
-
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
539
|
-
}
|
|
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"
|
|
540
509
|
},
|
|
541
|
-
|
|
542
|
-
var _a;
|
|
510
|
+
setup(options, _nuxt) {
|
|
543
511
|
if (!isAdmin()) {
|
|
544
512
|
consola.warn("please run as administrator");
|
|
545
513
|
return;
|
|
546
514
|
}
|
|
547
|
-
if (
|
|
515
|
+
if (import_node_process6.default.env.NODE_ENV !== "development")
|
|
548
516
|
return;
|
|
549
517
|
const {
|
|
550
518
|
enable = true,
|
|
@@ -556,72 +524,12 @@ var unpluginFactory = (options) => ({
|
|
|
556
524
|
consola.fail("please provide target");
|
|
557
525
|
return;
|
|
558
526
|
}
|
|
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}`)}`);
|
|
585
|
-
});
|
|
586
|
-
}).catch((e) => {
|
|
587
|
-
throw e;
|
|
588
|
-
});
|
|
589
|
-
} catch (e) {
|
|
590
|
-
consola.error(e);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
// src/vite.ts
|
|
596
|
-
var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
|
|
597
|
-
|
|
598
|
-
// src/webpack.ts
|
|
599
|
-
var import_unplugin3 = require("unplugin");
|
|
600
|
-
var webpack_default = (0, import_unplugin3.createWebpackPlugin)(unpluginFactory);
|
|
601
|
-
|
|
602
|
-
// src/nuxt.ts
|
|
603
|
-
var import_schema = require("@nuxt/schema");
|
|
604
|
-
var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
605
|
-
meta: {
|
|
606
|
-
name: "nuxt-unplugin-https-reverse-proxy",
|
|
607
|
-
configKey: "unpluginHttpsReverseProxy"
|
|
608
|
-
},
|
|
609
|
-
setup(options, _nuxt) {
|
|
610
|
-
(0, import_kit.addVitePlugin)(() => vite_default(options));
|
|
611
|
-
(0, import_kit.addWebpackPlugin)(() => webpack_default(options));
|
|
612
|
-
let url = "";
|
|
613
527
|
_nuxt.hook("listen", (_, listener) => {
|
|
614
|
-
url = listener.url;
|
|
615
|
-
});
|
|
616
|
-
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
528
|
+
const url = listener.url;
|
|
617
529
|
const source = new URL(url).host;
|
|
618
|
-
if (!options.target) {
|
|
619
|
-
consola.fail("please provide target");
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
530
|
const base = _nuxt.options.app.baseURL || "/";
|
|
623
|
-
vitePrintUrls(
|
|
624
|
-
})
|
|
531
|
+
vitePrintUrls(options, source, options.target, base);
|
|
532
|
+
});
|
|
625
533
|
}
|
|
626
534
|
});
|
|
627
535
|
exports.default = module.exports;
|
package/dist/nuxt.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
vite_default
|
|
3
|
-
} from "./chunk-DDD5N75Y.js";
|
|
4
|
-
import {
|
|
5
|
-
webpack_default
|
|
6
|
-
} from "./chunk-VGLXVBHU.js";
|
|
7
1
|
import {
|
|
8
2
|
vitePrintUrls
|
|
9
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZAZWZOPZ.js";
|
|
10
4
|
import {
|
|
11
5
|
consola,
|
|
12
|
-
|
|
6
|
+
isAdmin
|
|
13
7
|
} from "./chunk-RUJE3YFB.js";
|
|
14
8
|
|
|
15
9
|
// src/nuxt.ts
|
|
16
|
-
import
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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(
|
|
38
|
-
})
|
|
39
|
+
vitePrintUrls(options, source, options.target, base);
|
|
40
|
+
});
|
|
39
41
|
}
|
|
40
42
|
});
|
|
41
43
|
export {
|
package/dist/rollup.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
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
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -466,7 +475,7 @@ var CaddyInstant = class {
|
|
|
466
475
|
var config;
|
|
467
476
|
var caddy;
|
|
468
477
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
478
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
479
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
480
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
481
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
498
|
} catch (e) {
|
|
490
499
|
consola.error(e);
|
|
491
500
|
}
|
|
492
|
-
}
|
|
501
|
+
});
|
|
493
502
|
var unpluginFactory = (options) => ({
|
|
494
503
|
name: "unplugin-https-reverse-proxy",
|
|
495
504
|
enforce: "pre",
|
|
@@ -523,7 +532,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
532
|
source = u.host;
|
|
524
533
|
}
|
|
525
534
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
535
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
536
|
}
|
|
528
537
|
},
|
|
529
538
|
webpack(compiler) {
|
package/dist/rollup.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
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
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -466,7 +475,7 @@ var CaddyInstant = class {
|
|
|
466
475
|
var config;
|
|
467
476
|
var caddy;
|
|
468
477
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
478
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
479
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
480
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
481
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
498
|
} catch (e) {
|
|
490
499
|
consola.error(e);
|
|
491
500
|
}
|
|
492
|
-
}
|
|
501
|
+
});
|
|
493
502
|
var unpluginFactory = (options) => ({
|
|
494
503
|
name: "unplugin-https-reverse-proxy",
|
|
495
504
|
enforce: "pre",
|
|
@@ -523,7 +532,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
532
|
source = u.host;
|
|
524
533
|
}
|
|
525
534
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
535
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
536
|
}
|
|
528
537
|
},
|
|
529
538
|
webpack(compiler) {
|
package/dist/vite.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-N6ZBBGYD.js";
|
|
2
|
+
unpluginFactory
|
|
3
|
+
} from "./chunk-ZAZWZOPZ.js";
|
|
5
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
|
@@ -72,6 +72,15 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
72
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
73
|
}
|
|
74
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
|
+
}
|
|
75
84
|
function isAdmin() {
|
|
76
85
|
if (import_node_process.default.platform === "win32") {
|
|
77
86
|
try {
|
|
@@ -466,7 +475,7 @@ var CaddyInstant = class {
|
|
|
466
475
|
var config;
|
|
467
476
|
var caddy;
|
|
468
477
|
var pwd = import_node_process5.default.cwd();
|
|
469
|
-
|
|
478
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
479
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
480
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
472
481
|
if ((0, import_node_fs3.existsSync)(viteCacheDir))
|
|
@@ -489,7 +498,7 @@ function vitePrintUrls(server, options, source, target, base = "/", _printUrls)
|
|
|
489
498
|
} catch (e) {
|
|
490
499
|
consola.error(e);
|
|
491
500
|
}
|
|
492
|
-
}
|
|
501
|
+
});
|
|
493
502
|
var unpluginFactory = (options) => ({
|
|
494
503
|
name: "unplugin-https-reverse-proxy",
|
|
495
504
|
enforce: "pre",
|
|
@@ -523,7 +532,7 @@ var unpluginFactory = (options) => ({
|
|
|
523
532
|
source = u.host;
|
|
524
533
|
}
|
|
525
534
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
535
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
536
|
}
|
|
528
537
|
},
|
|
529
538
|
webpack(compiler) {
|
package/dist/webpack.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-N6ZBBGYD.js";
|
|
2
|
+
unpluginFactory
|
|
3
|
+
} from "./chunk-ZAZWZOPZ.js";
|
|
5
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
package/src/index.ts
CHANGED
|
@@ -2,9 +2,9 @@ import process from 'node:process'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import type { UnpluginFactory } from 'unplugin'
|
|
4
4
|
import { createUnplugin } from 'unplugin'
|
|
5
|
-
import type { ResolvedConfig
|
|
5
|
+
import type { ResolvedConfig } from 'vite'
|
|
6
6
|
import c from 'picocolors'
|
|
7
|
-
import { chmodRecursive, 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
|
|
|
@@ -14,14 +14,13 @@ let caddy: CaddyInstant
|
|
|
14
14
|
|
|
15
15
|
const pwd = process.cwd()
|
|
16
16
|
|
|
17
|
-
export
|
|
18
|
-
server: ViteDevServer,
|
|
17
|
+
export const vitePrintUrls = once((
|
|
19
18
|
options: Options,
|
|
20
19
|
source: string,
|
|
21
20
|
target: string,
|
|
22
21
|
base: string = '/',
|
|
23
22
|
_printUrls?: () => void,
|
|
24
|
-
) {
|
|
23
|
+
) => {
|
|
25
24
|
_printUrls?.()
|
|
26
25
|
|
|
27
26
|
// fix `Error: EPERM: operation not permitted`
|
|
@@ -49,7 +48,7 @@ export function vitePrintUrls(
|
|
|
49
48
|
catch (e) {
|
|
50
49
|
consola.error(e)
|
|
51
50
|
}
|
|
52
|
-
}
|
|
51
|
+
})
|
|
53
52
|
|
|
54
53
|
export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
55
54
|
name: 'unplugin-https-reverse-proxy',
|
|
@@ -89,7 +88,7 @@ export const unpluginFactory: UnpluginFactory<Options> = options => ({
|
|
|
89
88
|
|
|
90
89
|
const base = server.config.base || '/'
|
|
91
90
|
|
|
92
|
-
server.printUrls = () => vitePrintUrls(
|
|
91
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls)
|
|
93
92
|
},
|
|
94
93
|
},
|
|
95
94
|
webpack(compiler) {
|
package/src/nuxt.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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,
|
|
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
|
-
|
|
21
|
-
|
|
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(
|
|
40
|
-
})
|
|
44
|
+
vitePrintUrls(options, source, options.target, base)
|
|
45
|
+
})
|
|
41
46
|
},
|
|
42
47
|
})
|
package/dist/chunk-DDD5N75Y.js
DELETED
package/dist/chunk-VGLXVBHU.js
DELETED