@modern-js/plugin-proxy 2.20.1-alpha.0 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @modern-js/plugin-proxy
2
2
 
3
+ ## 2.21.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 5424051: fix: the proxy should not recreated when exists
8
+ fix: proxy server 不应该被重新创建当存在时
9
+ - Updated dependencies [e81eeaf]
10
+ - Updated dependencies [26dcf3a]
11
+ - Updated dependencies [056627f]
12
+ - Updated dependencies [0fc15ca]
13
+ - Updated dependencies [43b4e83]
14
+ - Updated dependencies [ad78387]
15
+ - @modern-js/utils@2.21.0
16
+
3
17
  ## 2.20.0
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.20.1-alpha.0",
18
+ "version": "2.21.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -36,16 +36,16 @@
36
36
  "dependencies": {
37
37
  "whistle": "^2.7.18",
38
38
  "@swc/helpers": "0.5.1",
39
- "@modern-js/utils": "2.20.0"
39
+ "@modern-js/utils": "2.21.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/jest": "^29",
43
43
  "@types/node": "^14",
44
44
  "typescript": "^5",
45
45
  "jest": "^29",
46
- "@modern-js/core": "2.20.0",
47
- "@scripts/build": "2.20.0",
48
- "@scripts/jest-config": "2.20.0"
46
+ "@modern-js/core": "2.21.0",
47
+ "@scripts/jest-config": "2.21.0",
48
+ "@scripts/build": "2.21.0"
49
49
  },
50
50
  "sideEffects": false,
51
51
  "publishConfig": {
@@ -1,52 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { PLUGIN_SCHEMAS } from "@modern-js/utils";
22
- import { createProxyRule } from "./utils/createProxyRule";
23
- import WhistleProxy from "./utils/whistleProxy";
24
- var src_default = () => {
25
- let proxyServer;
26
- return {
27
- name: "@modern-js/plugin-proxy",
28
- setup: (api) => ({
29
- validateSchema() {
30
- return PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
31
- },
32
- afterDev() {
33
- return __async(this, null, function* () {
34
- const { dev } = api.useResolvedConfigContext();
35
- const { internalDirectory } = api.useAppContext();
36
- if (!(dev == null ? void 0 : dev.proxy)) {
37
- return;
38
- }
39
- const rule = createProxyRule(internalDirectory, dev.proxy);
40
- proxyServer = new WhistleProxy({ port: 8899, rule });
41
- yield proxyServer.start();
42
- });
43
- },
44
- beforeExit() {
45
- proxyServer == null ? void 0 : proxyServer.close();
46
- }
47
- })
48
- };
49
- };
50
- export {
51
- src_default as default
52
- };
@@ -1,38 +0,0 @@
1
- import path from "path";
2
- import { logger, fs } from "@modern-js/utils";
3
- const createWhistleProxyRule = (ruleDirectory, rules) => {
4
- const dest = path.resolve(ruleDirectory, "proxy.rule.js");
5
- let code = `/.*/ enable://intercept
6
- `;
7
- for (const rule of rules) {
8
- const { pattern, target } = rule;
9
- code += `${pattern} ${target}
10
- `;
11
- }
12
- fs.outputFileSync(
13
- dest,
14
- `exports.name = 'modernjs proxy rule';
15
- exports.rules = \`${code}\`;`
16
- );
17
- return dest;
18
- };
19
- const createProxyRule = (appDirectory, proxyOptions) => {
20
- const rules = [];
21
- if (proxyOptions && typeof proxyOptions === "string") {
22
- return proxyOptions;
23
- }
24
- if (typeof proxyOptions === "object") {
25
- for (const pattern of Object.keys(proxyOptions)) {
26
- const target = proxyOptions[pattern];
27
- if (!target || typeof target !== "string") {
28
- logger.error(`dev.proxy.${pattern} value should be string type`);
29
- process.exit(1);
30
- }
31
- rules.push({ pattern, target });
32
- }
33
- }
34
- return createWhistleProxyRule(appDirectory, rules);
35
- };
36
- export {
37
- createProxyRule
38
- };
@@ -1,19 +0,0 @@
1
- import { execSync as nodeExecSync } from "child_process";
2
- function execSync(cmd) {
3
- let stdout;
4
- let status = 0;
5
- try {
6
- stdout = nodeExecSync(cmd);
7
- } catch (err) {
8
- stdout = err.stdout;
9
- status = err.status;
10
- }
11
- return {
12
- stdout: stdout.toString(),
13
- status
14
- };
15
- }
16
- var execSync_default = execSync;
17
- export {
18
- execSync_default as default
19
- };
@@ -1,50 +0,0 @@
1
- import os from "os";
2
- import http from "http";
3
- import path from "path";
4
- import { fs, logger } from "@modern-js/utils";
5
- import execSync from "./execSync";
6
- const defaultCertDir = path.resolve(os.homedir(), "./.whistle-proxy");
7
- const defaultRootCA = path.resolve(defaultCertDir, "./rootCA.crt");
8
- const trustRootCA = () => {
9
- logger.info(`please type the password to trust the https certificate`);
10
- const { status } = execSync(
11
- `sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`
12
- );
13
- if (status === 0) {
14
- logger.info("Root CA install, you are ready to intercept the https now");
15
- } else {
16
- logger.info("Failed to trust the root CA, please trust it manually");
17
- }
18
- };
19
- const isRootCATrusted = () => {
20
- };
21
- const isRootCAExists = () => {
22
- if (fs.existsSync(defaultRootCA)) {
23
- return true;
24
- }
25
- return false;
26
- };
27
- const generateRootCA = (port) => new Promise((resolve, reject) => {
28
- if (fs.existsSync(defaultRootCA)) {
29
- fs.removeSync(defaultRootCA);
30
- }
31
- fs.ensureDirSync(defaultCertDir);
32
- const stream = fs.createWriteStream(defaultRootCA);
33
- http.get(`http://localhost:${port}/cgi-bin/rootca`, (response) => {
34
- response.pipe(stream);
35
- stream.on("finish", () => {
36
- resolve(defaultRootCA);
37
- }).on("error", (err) => {
38
- reject(err);
39
- });
40
- }).on("error", (err) => {
41
- fs.unlink(defaultRootCA);
42
- reject(err);
43
- });
44
- });
45
- export {
46
- defaultRootCA,
47
- generateRootCA,
48
- isRootCAExists,
49
- trustRootCA
50
- };
@@ -1,26 +0,0 @@
1
- import execSync from "./execSync";
2
- const networkTypes = ["Ethernet", "Thunderbolt Ethernet", "Wi-Fi"];
3
- const getNetworkType = () => {
4
- for (let i = 0; i < networkTypes.length; i++) {
5
- const type = networkTypes[i];
6
- const result = execSync(`networksetup -getwebproxy ${type}`);
7
- if (result.status === 0) {
8
- return type;
9
- }
10
- }
11
- throw new Error("Unknown network type");
12
- };
13
- const enableGlobalProxy = (ip, port) => {
14
- const networkType = getNetworkType();
15
- execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
16
- execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
17
- };
18
- const disableGlobalProxy = () => {
19
- const networkType = getNetworkType();
20
- execSync(`networksetup -setwebproxystate ${networkType} off`);
21
- execSync(`networksetup -setsecurewebproxystate ${networkType} off`);
22
- };
23
- export {
24
- disableGlobalProxy,
25
- enableGlobalProxy
26
- };
@@ -1,73 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import path from "path";
22
- import { logger } from "@modern-js/utils";
23
- import execSync from "./execSync";
24
- import {
25
- isRootCAExists,
26
- generateRootCA,
27
- defaultRootCA,
28
- trustRootCA
29
- } from "./macCAManager";
30
- const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
31
- class WhistleProxy {
32
- constructor(config) {
33
- this.rule = config.rule;
34
- this.port = config.port;
35
- this.bin = path.resolve(
36
- path.dirname(require.resolve("whistle")),
37
- "bin/whistle.js"
38
- );
39
- this.certDir = path.dirname(defaultRootCA);
40
- }
41
- installRootCA() {
42
- return __async(this, null, function* () {
43
- try {
44
- if (!isRootCAExists()) {
45
- yield generateRootCA(this.port);
46
- trustRootCA();
47
- }
48
- } catch (err) {
49
- this.close();
50
- throw err;
51
- }
52
- });
53
- }
54
- start() {
55
- return __async(this, null, function* () {
56
- logger.info(`Starting the proxy server.....`);
57
- execSync(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
58
- execSync(`${this.bin} use ${this.rule} --force`);
59
- yield this.installRootCA();
60
- enableGlobalProxy("localhost", this.port);
61
- logger.info(`Proxy Server start on localhost:${this.port}
62
- `);
63
- });
64
- }
65
- close() {
66
- execSync(`${this.bin} stop`);
67
- disableGlobalProxy();
68
- logger.info(`Proxy Server has been closed`);
69
- }
70
- }
71
- export {
72
- WhistleProxy as default
73
- };
@@ -1,79 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
- var src_exports = {};
45
- __export(src_exports, {
46
- default: () => src_default
47
- });
48
- module.exports = __toCommonJS(src_exports);
49
- var import_utils = require("@modern-js/utils");
50
- var import_createProxyRule = require("./utils/createProxyRule");
51
- var import_whistleProxy = __toESM(require("./utils/whistleProxy"));
52
- var src_default = () => {
53
- let proxyServer;
54
- return {
55
- name: "@modern-js/plugin-proxy",
56
- setup: (api) => ({
57
- validateSchema() {
58
- return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
59
- },
60
- afterDev() {
61
- return __async(this, null, function* () {
62
- const { dev } = api.useResolvedConfigContext();
63
- const { internalDirectory } = api.useAppContext();
64
- if (!(dev == null ? void 0 : dev.proxy)) {
65
- return;
66
- }
67
- const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
68
- proxyServer = new import_whistleProxy.default({ port: 8899, rule });
69
- yield proxyServer.start();
70
- });
71
- },
72
- beforeExit() {
73
- proxyServer == null ? void 0 : proxyServer.close();
74
- }
75
- })
76
- };
77
- };
78
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {});
@@ -1,67 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var createProxyRule_exports = {};
25
- __export(createProxyRule_exports, {
26
- createProxyRule: () => createProxyRule
27
- });
28
- module.exports = __toCommonJS(createProxyRule_exports);
29
- var import_path = __toESM(require("path"));
30
- var import_utils = require("@modern-js/utils");
31
- const createWhistleProxyRule = (ruleDirectory, rules) => {
32
- const dest = import_path.default.resolve(ruleDirectory, "proxy.rule.js");
33
- let code = `/.*/ enable://intercept
34
- `;
35
- for (const rule of rules) {
36
- const { pattern, target } = rule;
37
- code += `${pattern} ${target}
38
- `;
39
- }
40
- import_utils.fs.outputFileSync(
41
- dest,
42
- `exports.name = 'modernjs proxy rule';
43
- exports.rules = \`${code}\`;`
44
- );
45
- return dest;
46
- };
47
- const createProxyRule = (appDirectory, proxyOptions) => {
48
- const rules = [];
49
- if (proxyOptions && typeof proxyOptions === "string") {
50
- return proxyOptions;
51
- }
52
- if (typeof proxyOptions === "object") {
53
- for (const pattern of Object.keys(proxyOptions)) {
54
- const target = proxyOptions[pattern];
55
- if (!target || typeof target !== "string") {
56
- import_utils.logger.error(`dev.proxy.${pattern} value should be string type`);
57
- process.exit(1);
58
- }
59
- rules.push({ pattern, target });
60
- }
61
- }
62
- return createWhistleProxyRule(appDirectory, rules);
63
- };
64
- // Annotate the CommonJS export names for ESM import in node:
65
- 0 && (module.exports = {
66
- createProxyRule
67
- });
@@ -1,40 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var execSync_exports = {};
19
- __export(execSync_exports, {
20
- default: () => execSync_default
21
- });
22
- module.exports = __toCommonJS(execSync_exports);
23
- var import_child_process = require("child_process");
24
- function execSync(cmd) {
25
- let stdout;
26
- let status = 0;
27
- try {
28
- stdout = (0, import_child_process.execSync)(cmd);
29
- } catch (err) {
30
- stdout = err.stdout;
31
- status = err.status;
32
- }
33
- return {
34
- stdout: stdout.toString(),
35
- status
36
- };
37
- }
38
- var execSync_default = execSync;
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {});
@@ -1,82 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var macCAManager_exports = {};
25
- __export(macCAManager_exports, {
26
- defaultRootCA: () => defaultRootCA,
27
- generateRootCA: () => generateRootCA,
28
- isRootCAExists: () => isRootCAExists,
29
- trustRootCA: () => trustRootCA
30
- });
31
- module.exports = __toCommonJS(macCAManager_exports);
32
- var import_os = __toESM(require("os"));
33
- var import_http = __toESM(require("http"));
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_execSync = __toESM(require("./execSync"));
37
- const defaultCertDir = import_path.default.resolve(import_os.default.homedir(), "./.whistle-proxy");
38
- const defaultRootCA = import_path.default.resolve(defaultCertDir, "./rootCA.crt");
39
- const trustRootCA = () => {
40
- import_utils.logger.info(`please type the password to trust the https certificate`);
41
- const { status } = (0, import_execSync.default)(
42
- `sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`
43
- );
44
- if (status === 0) {
45
- import_utils.logger.info("Root CA install, you are ready to intercept the https now");
46
- } else {
47
- import_utils.logger.info("Failed to trust the root CA, please trust it manually");
48
- }
49
- };
50
- const isRootCATrusted = () => {
51
- };
52
- const isRootCAExists = () => {
53
- if (import_utils.fs.existsSync(defaultRootCA)) {
54
- return true;
55
- }
56
- return false;
57
- };
58
- const generateRootCA = (port) => new Promise((resolve, reject) => {
59
- if (import_utils.fs.existsSync(defaultRootCA)) {
60
- import_utils.fs.removeSync(defaultRootCA);
61
- }
62
- import_utils.fs.ensureDirSync(defaultCertDir);
63
- const stream = import_utils.fs.createWriteStream(defaultRootCA);
64
- import_http.default.get(`http://localhost:${port}/cgi-bin/rootca`, (response) => {
65
- response.pipe(stream);
66
- stream.on("finish", () => {
67
- resolve(defaultRootCA);
68
- }).on("error", (err) => {
69
- reject(err);
70
- });
71
- }).on("error", (err) => {
72
- import_utils.fs.unlink(defaultRootCA);
73
- reject(err);
74
- });
75
- });
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
78
- defaultRootCA,
79
- generateRootCA,
80
- isRootCAExists,
81
- trustRootCA
82
- });
@@ -1,56 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var macProxyManager_exports = {};
25
- __export(macProxyManager_exports, {
26
- disableGlobalProxy: () => disableGlobalProxy,
27
- enableGlobalProxy: () => enableGlobalProxy
28
- });
29
- module.exports = __toCommonJS(macProxyManager_exports);
30
- var import_execSync = __toESM(require("./execSync"));
31
- const networkTypes = ["Ethernet", "Thunderbolt Ethernet", "Wi-Fi"];
32
- const getNetworkType = () => {
33
- for (let i = 0; i < networkTypes.length; i++) {
34
- const type = networkTypes[i];
35
- const result = (0, import_execSync.default)(`networksetup -getwebproxy ${type}`);
36
- if (result.status === 0) {
37
- return type;
38
- }
39
- }
40
- throw new Error("Unknown network type");
41
- };
42
- const enableGlobalProxy = (ip, port) => {
43
- const networkType = getNetworkType();
44
- (0, import_execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
45
- (0, import_execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
46
- };
47
- const disableGlobalProxy = () => {
48
- const networkType = getNetworkType();
49
- (0, import_execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
50
- (0, import_execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
51
- };
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- disableGlobalProxy,
55
- enableGlobalProxy
56
- });
@@ -1,95 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
- var whistleProxy_exports = {};
45
- __export(whistleProxy_exports, {
46
- default: () => WhistleProxy
47
- });
48
- module.exports = __toCommonJS(whistleProxy_exports);
49
- var import_path = __toESM(require("path"));
50
- var import_utils = require("@modern-js/utils");
51
- var import_execSync = __toESM(require("./execSync"));
52
- var import_macCAManager = require("./macCAManager");
53
- const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
54
- class WhistleProxy {
55
- constructor(config) {
56
- this.rule = config.rule;
57
- this.port = config.port;
58
- this.bin = import_path.default.resolve(
59
- import_path.default.dirname(require.resolve("whistle")),
60
- "bin/whistle.js"
61
- );
62
- this.certDir = import_path.default.dirname(import_macCAManager.defaultRootCA);
63
- }
64
- installRootCA() {
65
- return __async(this, null, function* () {
66
- try {
67
- if (!(0, import_macCAManager.isRootCAExists)()) {
68
- yield (0, import_macCAManager.generateRootCA)(this.port);
69
- (0, import_macCAManager.trustRootCA)();
70
- }
71
- } catch (err) {
72
- this.close();
73
- throw err;
74
- }
75
- });
76
- }
77
- start() {
78
- return __async(this, null, function* () {
79
- import_utils.logger.info(`Starting the proxy server.....`);
80
- (0, import_execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
81
- (0, import_execSync.default)(`${this.bin} use ${this.rule} --force`);
82
- yield this.installRootCA();
83
- enableGlobalProxy("localhost", this.port);
84
- import_utils.logger.info(`Proxy Server start on localhost:${this.port}
85
- `);
86
- });
87
- }
88
- close() {
89
- (0, import_execSync.default)(`${this.bin} stop`);
90
- disableGlobalProxy();
91
- import_utils.logger.info(`Proxy Server has been closed`);
92
- }
93
- }
94
- // Annotate the CommonJS export names for ESM import in node:
95
- 0 && (module.exports = {});