@modern-js/plugin-proxy 2.0.0-beta.3 → 2.0.0-beta.4
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 +30 -0
- package/dist/js/modern/index.js +40 -24
- package/dist/js/modern/utils/createProxyRule.js +22 -23
- package/dist/js/modern/utils/execSync.js +5 -5
- package/dist/js/modern/utils/macCAManager.js +26 -23
- package/dist/js/modern/utils/macProxyManager.js +9 -8
- package/dist/js/modern/utils/whistleProxy.js +59 -33
- package/dist/js/node/index.js +65 -32
- package/dist/js/node/utils/createProxyRule.js +45 -26
- package/dist/js/node/utils/execSync.js +24 -12
- package/dist/js/node/utils/macCAManager.js +53 -36
- package/dist/js/node/utils/macProxyManager.js +36 -19
- package/dist/js/node/utils/whistleProxy.js +80 -42
- package/dist/types/index.d.ts +2 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @modern-js/plugin-proxy
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7879e8f]
|
|
12
|
+
- Updated dependencies [6aca875]
|
|
13
|
+
- Updated dependencies [2e6031955e]
|
|
14
|
+
- Updated dependencies [7b7d12c]
|
|
15
|
+
- Updated dependencies [92f0eade39]
|
|
16
|
+
- Updated dependencies [edd1cfb1af]
|
|
17
|
+
- Updated dependencies [cc971eabfc]
|
|
18
|
+
- Updated dependencies [5b9049f2e9]
|
|
19
|
+
- Updated dependencies [92004d1906]
|
|
20
|
+
- Updated dependencies [b8bbe036c7]
|
|
21
|
+
- Updated dependencies [d5a31df781]
|
|
22
|
+
- Updated dependencies [dda38c9c3e]
|
|
23
|
+
- Updated dependencies [3bbea92b2a]
|
|
24
|
+
- Updated dependencies [b710adb843]
|
|
25
|
+
- Updated dependencies [ea7cf06]
|
|
26
|
+
- Updated dependencies [bbe4c4a]
|
|
27
|
+
- Updated dependencies [e4558a0]
|
|
28
|
+
- Updated dependencies [abf3421a75]
|
|
29
|
+
- Updated dependencies [543be9558e]
|
|
30
|
+
- Updated dependencies [14b712da84]
|
|
31
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
32
|
+
|
|
3
33
|
## 2.0.0-beta.3
|
|
4
34
|
|
|
5
35
|
### Major Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,36 +1,52 @@
|
|
|
1
|
-
|
|
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";
|
|
2
22
|
import { createProxyRule } from "./utils/createProxyRule";
|
|
3
23
|
import WhistleProxy from "./utils/whistleProxy";
|
|
4
|
-
|
|
24
|
+
var src_default = () => {
|
|
5
25
|
let proxyServer;
|
|
6
26
|
return {
|
|
7
|
-
name:
|
|
8
|
-
setup: api => ({
|
|
27
|
+
name: "@modern-js/plugin-proxy",
|
|
28
|
+
setup: (api) => ({
|
|
9
29
|
validateSchema() {
|
|
10
|
-
return PLUGIN_SCHEMAS[
|
|
30
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
|
|
11
31
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
dev
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const rule = createProxyRule(internalDirectory, dev.proxy);
|
|
23
|
-
proxyServer = new WhistleProxy({
|
|
24
|
-
port: 8899,
|
|
25
|
-
rule
|
|
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();
|
|
26
42
|
});
|
|
27
|
-
await proxyServer.start();
|
|
28
43
|
},
|
|
29
44
|
beforeExit() {
|
|
30
|
-
|
|
31
|
-
// terminate whistle proxy
|
|
32
|
-
(_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
|
|
45
|
+
proxyServer == null ? void 0 : proxyServer.close();
|
|
33
46
|
}
|
|
34
47
|
})
|
|
35
48
|
};
|
|
36
|
-
}
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
src_default as default
|
|
52
|
+
};
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import { logger, fs } from
|
|
3
|
-
// FIXME: import DevProxyOptions from somewhere
|
|
4
|
-
// import type { DevProxyOptions } from '@modern-js/core';
|
|
5
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { logger, fs } from "@modern-js/utils";
|
|
6
3
|
const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
7
|
-
const dest = path.resolve(ruleDirectory,
|
|
8
|
-
let code = `/.*/ enable://intercept
|
|
4
|
+
const dest = path.resolve(ruleDirectory, "proxy.rule.js");
|
|
5
|
+
let code = `/.*/ enable://intercept
|
|
6
|
+
`;
|
|
9
7
|
for (const rule of rules) {
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = rule;
|
|
14
|
-
code += `${pattern} ${target}\n`;
|
|
8
|
+
const { pattern, target } = rule;
|
|
9
|
+
code += `${pattern} ${target}
|
|
10
|
+
`;
|
|
15
11
|
}
|
|
16
|
-
fs.outputFileSync(
|
|
12
|
+
fs.outputFileSync(
|
|
13
|
+
dest,
|
|
14
|
+
`exports.name = 'modernjs proxy rule';
|
|
15
|
+
exports.rules = \`${code}\`;`
|
|
16
|
+
);
|
|
17
17
|
return dest;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
const createProxyRule = (appDirectory, proxyOptions) => {
|
|
20
20
|
const rules = [];
|
|
21
|
-
if (proxyOptions && typeof proxyOptions ===
|
|
21
|
+
if (proxyOptions && typeof proxyOptions === "string") {
|
|
22
22
|
return proxyOptions;
|
|
23
23
|
}
|
|
24
|
-
if (typeof proxyOptions ===
|
|
24
|
+
if (typeof proxyOptions === "object") {
|
|
25
25
|
for (const pattern of Object.keys(proxyOptions)) {
|
|
26
26
|
const target = proxyOptions[pattern];
|
|
27
|
-
if (!target || typeof target !==
|
|
27
|
+
if (!target || typeof target !== "string") {
|
|
28
28
|
logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
29
|
-
// eslint-disable-next-line no-process-exit
|
|
30
29
|
process.exit(1);
|
|
31
30
|
}
|
|
32
|
-
rules.push({
|
|
33
|
-
pattern,
|
|
34
|
-
target
|
|
35
|
-
});
|
|
31
|
+
rules.push({ pattern, target });
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
34
|
return createWhistleProxyRule(appDirectory, rules);
|
|
39
|
-
};
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
createProxyRule
|
|
38
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { execSync as nodeExecSync } from
|
|
1
|
+
import { execSync as nodeExecSync } from "child_process";
|
|
2
2
|
function execSync(cmd) {
|
|
3
3
|
let stdout;
|
|
4
4
|
let status = 0;
|
|
5
5
|
try {
|
|
6
6
|
stdout = nodeExecSync(cmd);
|
|
7
7
|
} catch (err) {
|
|
8
|
-
/* eslint-disable prefer-destructuring */
|
|
9
8
|
stdout = err.stdout;
|
|
10
9
|
status = err.status;
|
|
11
|
-
/* eslint-enable prefer-destructuring */
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return {
|
|
15
12
|
stdout: stdout.toString(),
|
|
16
13
|
status
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
|
-
|
|
16
|
+
var execSync_default = execSync;
|
|
17
|
+
export {
|
|
18
|
+
execSync_default as default
|
|
19
|
+
};
|
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
import os from
|
|
2
|
-
import http from
|
|
3
|
-
import path from
|
|
4
|
-
import { fs, logger } from
|
|
1
|
+
import os from "os";
|
|
2
|
+
import http from "http";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fs, logger } from "@modern-js/utils";
|
|
5
5
|
import execSync from "./execSync";
|
|
6
|
-
const defaultCertDir = path.resolve(os.homedir(),
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const defaultCertDir = path.resolve(os.homedir(), "./.whistle-proxy");
|
|
7
|
+
const defaultRootCA = path.resolve(defaultCertDir, "./rootCA.crt");
|
|
8
|
+
const trustRootCA = () => {
|
|
9
9
|
logger.info(`please type the password to trust the https certificate`);
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const { status } = execSync(
|
|
11
|
+
`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`
|
|
12
|
+
);
|
|
13
13
|
if (status === 0) {
|
|
14
|
-
logger.info(
|
|
14
|
+
logger.info("Root CA install, you are ready to intercept the https now");
|
|
15
15
|
} else {
|
|
16
|
-
logger.info(
|
|
16
|
+
logger.info("Failed to trust the root CA, please trust it manually");
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
19
|
const isRootCATrusted = () => {
|
|
22
|
-
// current empty
|
|
23
20
|
};
|
|
24
|
-
|
|
21
|
+
const isRootCAExists = () => {
|
|
25
22
|
if (fs.existsSync(defaultRootCA)) {
|
|
26
23
|
return true;
|
|
27
24
|
}
|
|
28
25
|
return false;
|
|
29
26
|
};
|
|
30
|
-
|
|
27
|
+
const generateRootCA = () => new Promise((resolve, reject) => {
|
|
31
28
|
if (fs.existsSync(defaultRootCA)) {
|
|
32
29
|
fs.removeSync(defaultRootCA);
|
|
33
30
|
}
|
|
34
31
|
fs.ensureDirSync(defaultCertDir);
|
|
35
32
|
const stream = fs.createWriteStream(defaultRootCA);
|
|
36
|
-
http.get(
|
|
33
|
+
http.get("http://localhost:8899/cgi-bin/rootca", (response) => {
|
|
37
34
|
response.pipe(stream);
|
|
38
|
-
stream.on(
|
|
35
|
+
stream.on("finish", () => {
|
|
39
36
|
resolve(defaultRootCA);
|
|
40
|
-
}).on(
|
|
37
|
+
}).on("error", (err) => {
|
|
41
38
|
reject(err);
|
|
42
39
|
});
|
|
43
|
-
}).on(
|
|
44
|
-
fs.unlink(defaultRootCA);
|
|
40
|
+
}).on("error", (err) => {
|
|
41
|
+
fs.unlink(defaultRootCA);
|
|
45
42
|
reject(err);
|
|
46
43
|
});
|
|
47
|
-
});
|
|
44
|
+
});
|
|
45
|
+
export {
|
|
46
|
+
defaultRootCA,
|
|
47
|
+
generateRootCA,
|
|
48
|
+
isRootCAExists,
|
|
49
|
+
trustRootCA
|
|
50
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import execSync from "./execSync";
|
|
2
|
-
const networkTypes = [
|
|
2
|
+
const networkTypes = ["Ethernet", "Thunderbolt Ethernet", "Wi-Fi"];
|
|
3
3
|
const getNetworkType = () => {
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
5
4
|
for (let i = 0; i < networkTypes.length; i++) {
|
|
6
5
|
const type = networkTypes[i];
|
|
7
6
|
const result = execSync(`networksetup -getwebproxy ${type}`);
|
|
@@ -9,17 +8,19 @@ const getNetworkType = () => {
|
|
|
9
8
|
return type;
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
throw new Error(
|
|
11
|
+
throw new Error("Unknown network type");
|
|
13
12
|
};
|
|
14
|
-
|
|
13
|
+
const enableGlobalProxy = (ip, port) => {
|
|
15
14
|
const networkType = getNetworkType();
|
|
16
|
-
|
|
17
|
-
// && networksetup -setproxybypassdomains ${networkType} localhost localhost
|
|
18
15
|
execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
19
16
|
execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
20
17
|
};
|
|
21
|
-
|
|
18
|
+
const disableGlobalProxy = () => {
|
|
22
19
|
const networkType = getNetworkType();
|
|
23
20
|
execSync(`networksetup -setwebproxystate ${networkType} off`);
|
|
24
21
|
execSync(`networksetup -setsecurewebproxystate ${networkType} off`);
|
|
25
|
-
};
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
disableGlobalProxy,
|
|
25
|
+
enableGlobalProxy
|
|
26
|
+
};
|
|
@@ -1,47 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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";
|
|
4
23
|
import execSync from "./execSync";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
24
|
+
import {
|
|
25
|
+
isRootCAExists,
|
|
26
|
+
generateRootCA,
|
|
27
|
+
defaultRootCA,
|
|
28
|
+
trustRootCA
|
|
29
|
+
} from "./macCAManager";
|
|
30
|
+
const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
|
|
31
|
+
class WhistleProxy {
|
|
11
32
|
constructor(config) {
|
|
12
|
-
_defineProperty(this, "rule", void 0);
|
|
13
|
-
_defineProperty(this, "port", void 0);
|
|
14
|
-
_defineProperty(this, "bin", void 0);
|
|
15
|
-
_defineProperty(this, "certDir", void 0);
|
|
16
33
|
this.rule = config.rule;
|
|
17
34
|
this.port = config.port;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
35
|
+
this.bin = path.resolve(
|
|
36
|
+
path.dirname(require.resolve("whistle")),
|
|
37
|
+
"bin/whistle.js"
|
|
38
|
+
);
|
|
21
39
|
this.certDir = path.dirname(defaultRootCA);
|
|
22
40
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
installRootCA() {
|
|
42
|
+
return __async(this, null, function* () {
|
|
43
|
+
try {
|
|
44
|
+
if (!isRootCAExists()) {
|
|
45
|
+
yield generateRootCA();
|
|
46
|
+
trustRootCA();
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
this.close();
|
|
50
|
+
throw err;
|
|
28
51
|
}
|
|
29
|
-
}
|
|
30
|
-
this.close();
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
52
|
+
});
|
|
33
53
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
});
|
|
41
64
|
}
|
|
42
65
|
close() {
|
|
43
66
|
execSync(`${this.bin} stop`);
|
|
44
67
|
disableGlobalProxy();
|
|
45
68
|
logger.info(`Proxy Server has been closed`);
|
|
46
69
|
}
|
|
47
|
-
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
WhistleProxy as default
|
|
73
|
+
};
|
package/dist/js/node/index.js
CHANGED
|
@@ -1,44 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
default: () => src_default
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_utils = require("@modern-js/utils");
|
|
30
|
+
var import_createProxyRule = require("./utils/createProxyRule");
|
|
31
|
+
var import_whistleProxy = __toESM(require("./utils/whistleProxy"));
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
var src_default = () => {
|
|
12
53
|
let proxyServer;
|
|
13
54
|
return {
|
|
14
|
-
name:
|
|
15
|
-
setup: api => ({
|
|
55
|
+
name: "@modern-js/plugin-proxy",
|
|
56
|
+
setup: (api) => ({
|
|
16
57
|
validateSchema() {
|
|
17
|
-
return
|
|
58
|
+
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
|
|
18
59
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
dev
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const rule = (0, _createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
|
|
30
|
-
proxyServer = new _whistleProxy.default({
|
|
31
|
-
port: 8899,
|
|
32
|
-
rule
|
|
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();
|
|
33
70
|
});
|
|
34
|
-
await proxyServer.start();
|
|
35
71
|
},
|
|
36
72
|
beforeExit() {
|
|
37
|
-
|
|
38
|
-
// terminate whistle proxy
|
|
39
|
-
(_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
|
|
73
|
+
proxyServer == null ? void 0 : proxyServer.close();
|
|
40
74
|
}
|
|
41
75
|
})
|
|
42
76
|
};
|
|
43
77
|
};
|
|
44
|
-
exports.default = _default;
|
|
@@ -1,44 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
createProxyRule: () => createProxyRule
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
10
31
|
const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
11
|
-
const dest =
|
|
12
|
-
let code = `/.*/ enable://intercept
|
|
32
|
+
const dest = import_path.default.resolve(ruleDirectory, "proxy.rule.js");
|
|
33
|
+
let code = `/.*/ enable://intercept
|
|
34
|
+
`;
|
|
13
35
|
for (const rule of rules) {
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} = rule;
|
|
18
|
-
code += `${pattern} ${target}\n`;
|
|
36
|
+
const { pattern, target } = rule;
|
|
37
|
+
code += `${pattern} ${target}
|
|
38
|
+
`;
|
|
19
39
|
}
|
|
20
|
-
|
|
40
|
+
import_utils.fs.outputFileSync(
|
|
41
|
+
dest,
|
|
42
|
+
`exports.name = 'modernjs proxy rule';
|
|
43
|
+
exports.rules = \`${code}\`;`
|
|
44
|
+
);
|
|
21
45
|
return dest;
|
|
22
46
|
};
|
|
23
47
|
const createProxyRule = (appDirectory, proxyOptions) => {
|
|
24
48
|
const rules = [];
|
|
25
|
-
if (proxyOptions && typeof proxyOptions ===
|
|
49
|
+
if (proxyOptions && typeof proxyOptions === "string") {
|
|
26
50
|
return proxyOptions;
|
|
27
51
|
}
|
|
28
|
-
if (typeof proxyOptions ===
|
|
52
|
+
if (typeof proxyOptions === "object") {
|
|
29
53
|
for (const pattern of Object.keys(proxyOptions)) {
|
|
30
54
|
const target = proxyOptions[pattern];
|
|
31
|
-
if (!target || typeof target !==
|
|
32
|
-
|
|
33
|
-
// eslint-disable-next-line no-process-exit
|
|
55
|
+
if (!target || typeof target !== "string") {
|
|
56
|
+
import_utils.logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
34
57
|
process.exit(1);
|
|
35
58
|
}
|
|
36
|
-
rules.push({
|
|
37
|
-
pattern,
|
|
38
|
-
target
|
|
39
|
-
});
|
|
59
|
+
rules.push({ pattern, target });
|
|
40
60
|
}
|
|
41
61
|
}
|
|
42
62
|
return createWhistleProxyRule(appDirectory, rules);
|
|
43
63
|
};
|
|
44
|
-
exports.createProxyRule = createProxyRule;
|
|
@@ -1,26 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
default: () => execSync_default
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
var import_child_process = require("child_process");
|
|
8
24
|
function execSync(cmd) {
|
|
9
25
|
let stdout;
|
|
10
26
|
let status = 0;
|
|
11
27
|
try {
|
|
12
|
-
stdout = (0,
|
|
28
|
+
stdout = (0, import_child_process.execSync)(cmd);
|
|
13
29
|
} catch (err) {
|
|
14
|
-
/* eslint-disable prefer-destructuring */
|
|
15
30
|
stdout = err.stdout;
|
|
16
31
|
status = err.status;
|
|
17
|
-
/* eslint-enable prefer-destructuring */
|
|
18
32
|
}
|
|
19
|
-
|
|
20
33
|
return {
|
|
21
34
|
stdout: stdout.toString(),
|
|
22
35
|
status
|
|
23
36
|
};
|
|
24
37
|
}
|
|
25
|
-
var
|
|
26
|
-
exports.default = _default;
|
|
38
|
+
var execSync_default = execSync;
|
|
@@ -1,58 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
defaultRootCA: () => defaultRootCA,
|
|
27
|
+
generateRootCA: () => generateRootCA,
|
|
28
|
+
isRootCAExists: () => isRootCAExists,
|
|
29
|
+
trustRootCA: () => trustRootCA
|
|
5
30
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const defaultRootCA = _path.default.resolve(defaultCertDir, './rootCA.crt');
|
|
15
|
-
exports.defaultRootCA = defaultRootCA;
|
|
31
|
+
module.exports = __toCommonJS(stdin_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");
|
|
16
39
|
const trustRootCA = () => {
|
|
17
|
-
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
);
|
|
21
44
|
if (status === 0) {
|
|
22
|
-
|
|
45
|
+
import_utils.logger.info("Root CA install, you are ready to intercept the https now");
|
|
23
46
|
} else {
|
|
24
|
-
|
|
47
|
+
import_utils.logger.info("Failed to trust the root CA, please trust it manually");
|
|
25
48
|
}
|
|
26
49
|
};
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
-
exports.trustRootCA = trustRootCA;
|
|
30
50
|
const isRootCATrusted = () => {
|
|
31
|
-
// current empty
|
|
32
51
|
};
|
|
33
52
|
const isRootCAExists = () => {
|
|
34
|
-
if (
|
|
53
|
+
if (import_utils.fs.existsSync(defaultRootCA)) {
|
|
35
54
|
return true;
|
|
36
55
|
}
|
|
37
56
|
return false;
|
|
38
57
|
};
|
|
39
|
-
exports.isRootCAExists = isRootCAExists;
|
|
40
58
|
const generateRootCA = () => new Promise((resolve, reject) => {
|
|
41
|
-
if (
|
|
42
|
-
|
|
59
|
+
if (import_utils.fs.existsSync(defaultRootCA)) {
|
|
60
|
+
import_utils.fs.removeSync(defaultRootCA);
|
|
43
61
|
}
|
|
44
|
-
|
|
45
|
-
const stream =
|
|
46
|
-
|
|
62
|
+
import_utils.fs.ensureDirSync(defaultCertDir);
|
|
63
|
+
const stream = import_utils.fs.createWriteStream(defaultRootCA);
|
|
64
|
+
import_http.default.get("http://localhost:8899/cgi-bin/rootca", (response) => {
|
|
47
65
|
response.pipe(stream);
|
|
48
|
-
stream.on(
|
|
66
|
+
stream.on("finish", () => {
|
|
49
67
|
resolve(defaultRootCA);
|
|
50
|
-
}).on(
|
|
68
|
+
}).on("error", (err) => {
|
|
51
69
|
reject(err);
|
|
52
70
|
});
|
|
53
|
-
}).on(
|
|
54
|
-
|
|
71
|
+
}).on("error", (err) => {
|
|
72
|
+
import_utils.fs.unlink(defaultRootCA);
|
|
55
73
|
reject(err);
|
|
56
74
|
});
|
|
57
75
|
});
|
|
58
|
-
exports.generateRootCA = generateRootCA;
|
|
@@ -1,34 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
disableGlobalProxy: () => disableGlobalProxy,
|
|
27
|
+
enableGlobalProxy: () => enableGlobalProxy
|
|
5
28
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
const networkTypes = ['Ethernet', 'Thunderbolt Ethernet', 'Wi-Fi'];
|
|
29
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
30
|
+
var import_execSync = __toESM(require("./execSync"));
|
|
31
|
+
const networkTypes = ["Ethernet", "Thunderbolt Ethernet", "Wi-Fi"];
|
|
10
32
|
const getNetworkType = () => {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
12
33
|
for (let i = 0; i < networkTypes.length; i++) {
|
|
13
34
|
const type = networkTypes[i];
|
|
14
|
-
const result = (0,
|
|
35
|
+
const result = (0, import_execSync.default)(`networksetup -getwebproxy ${type}`);
|
|
15
36
|
if (result.status === 0) {
|
|
16
37
|
return type;
|
|
17
38
|
}
|
|
18
39
|
}
|
|
19
|
-
throw new Error(
|
|
40
|
+
throw new Error("Unknown network type");
|
|
20
41
|
};
|
|
21
42
|
const enableGlobalProxy = (ip, port) => {
|
|
22
43
|
const networkType = getNetworkType();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(0, _execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
26
|
-
(0, _execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
44
|
+
(0, import_execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
45
|
+
(0, import_execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
27
46
|
};
|
|
28
|
-
exports.enableGlobalProxy = enableGlobalProxy;
|
|
29
47
|
const disableGlobalProxy = () => {
|
|
30
48
|
const networkType = getNetworkType();
|
|
31
|
-
(0,
|
|
32
|
-
(0,
|
|
49
|
+
(0, import_execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
|
|
50
|
+
(0, import_execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
|
|
33
51
|
};
|
|
34
|
-
exports.disableGlobalProxy = disableGlobalProxy;
|
|
@@ -1,55 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
default: () => WhistleProxy
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
28
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
+
var import_path = __toESM(require("path"));
|
|
30
|
+
var import_utils = require("@modern-js/utils");
|
|
31
|
+
var import_execSync = __toESM(require("./execSync"));
|
|
32
|
+
var import_macCAManager = require("./macCAManager");
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
|
|
17
54
|
class WhistleProxy {
|
|
18
55
|
constructor(config) {
|
|
19
|
-
_defineProperty(this, "rule", void 0);
|
|
20
|
-
_defineProperty(this, "port", void 0);
|
|
21
|
-
_defineProperty(this, "bin", void 0);
|
|
22
|
-
_defineProperty(this, "certDir", void 0);
|
|
23
56
|
this.rule = config.rule;
|
|
24
57
|
this.port = config.port;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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);
|
|
29
63
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
installRootCA() {
|
|
65
|
+
return __async(this, null, function* () {
|
|
66
|
+
try {
|
|
67
|
+
if (!(0, import_macCAManager.isRootCAExists)()) {
|
|
68
|
+
yield (0, import_macCAManager.generateRootCA)();
|
|
69
|
+
(0, import_macCAManager.trustRootCA)();
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
this.close();
|
|
73
|
+
throw err;
|
|
35
74
|
}
|
|
36
|
-
}
|
|
37
|
-
this.close();
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
75
|
+
});
|
|
40
76
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
});
|
|
48
87
|
}
|
|
49
88
|
close() {
|
|
50
|
-
(0,
|
|
89
|
+
(0, import_execSync.default)(`${this.bin} stop`);
|
|
51
90
|
disableGlobalProxy();
|
|
52
|
-
|
|
91
|
+
import_utils.logger.info(`Proxy Server has been closed`);
|
|
53
92
|
}
|
|
54
93
|
}
|
|
55
|
-
exports.default = WhistleProxy;
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.4",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.18.0",
|
|
35
35
|
"whistle": "^2.7.18",
|
|
36
|
-
"@modern-js/utils": "2.0.0-beta.
|
|
36
|
+
"@modern-js/utils": "2.0.0-beta.4"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/jest": "^27",
|
|
40
40
|
"@types/node": "^14",
|
|
41
41
|
"typescript": "^4",
|
|
42
42
|
"jest": "^27",
|
|
43
|
-
"@modern-js/core": "2.0.0-beta.
|
|
44
|
-
"@scripts/build": "2.0.0-beta.
|
|
45
|
-
"@scripts/jest-config": "2.0.0-beta.
|
|
43
|
+
"@modern-js/core": "2.0.0-beta.4",
|
|
44
|
+
"@scripts/build": "2.0.0-beta.4",
|
|
45
|
+
"@scripts/jest-config": "2.0.0-beta.4"
|
|
46
46
|
},
|
|
47
47
|
"sideEffects": false,
|
|
48
48
|
"publishConfig": {
|