@modern-js/plugin-proxy 2.35.0 → 2.36.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/dist/cjs/index.js +41 -25
- package/dist/cjs/utils/createProxyRule.js +39 -13
- package/dist/cjs/utils/execSync.js +23 -10
- package/dist/cjs/utils/macCAManager.js +57 -40
- package/dist/cjs/utils/macProxyManager.js +48 -22
- package/dist/cjs/utils/whistleProxy.js +50 -28
- package/dist/esm/index.js +8 -6
- package/dist/esm/utils/createProxyRule.js +4 -1
- package/dist/esm/utils/execSync.js +4 -1
- package/dist/esm/utils/macCAManager.js +10 -4
- package/dist/esm/utils/macProxyManager.js +13 -2
- package/dist/esm/utils/whistleProxy.js +5 -3
- package/package.json +5 -5
package/dist/cjs/index.js
CHANGED
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return proxyPlugin;
|
|
15
|
-
},
|
|
16
|
-
default: function() {
|
|
17
|
-
return _default;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => src_default,
|
|
32
|
+
proxyPlugin: () => proxyPlugin
|
|
19
33
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_createProxyRule = require("./utils/createProxyRule");
|
|
36
|
+
var import_whistleProxy = __toESM(require("./utils/whistleProxy"));
|
|
23
37
|
const proxyPlugin = () => {
|
|
24
38
|
let proxyServer;
|
|
25
39
|
return {
|
|
@@ -39,15 +53,14 @@ const proxyPlugin = () => {
|
|
|
39
53
|
];
|
|
40
54
|
},
|
|
41
55
|
async afterDev() {
|
|
42
|
-
var _dev;
|
|
43
56
|
const { dev } = api.useResolvedConfigContext();
|
|
44
57
|
const { internalDirectory } = api.useAppContext();
|
|
45
|
-
if (!(
|
|
58
|
+
if (!(dev === null || dev === void 0 ? void 0 : dev.proxy)) {
|
|
46
59
|
return;
|
|
47
60
|
}
|
|
48
|
-
const rule = (0,
|
|
61
|
+
const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
|
|
49
62
|
if (!proxyServer) {
|
|
50
|
-
proxyServer = new
|
|
63
|
+
proxyServer = new import_whistleProxy.default({
|
|
51
64
|
port: 8899,
|
|
52
65
|
rule
|
|
53
66
|
});
|
|
@@ -55,10 +68,13 @@ const proxyPlugin = () => {
|
|
|
55
68
|
}
|
|
56
69
|
},
|
|
57
70
|
beforeExit() {
|
|
58
|
-
|
|
59
|
-
(_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
|
|
71
|
+
proxyServer === null || proxyServer === void 0 ? void 0 : proxyServer.close();
|
|
60
72
|
}
|
|
61
73
|
})
|
|
62
74
|
};
|
|
63
75
|
};
|
|
64
|
-
|
|
76
|
+
var src_default = proxyPlugin;
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
proxyPlugin
|
|
80
|
+
});
|
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var createProxyRule_exports = {};
|
|
30
|
+
__export(createProxyRule_exports, {
|
|
31
|
+
createProxyRule: () => createProxyRule
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
33
|
+
module.exports = __toCommonJS(createProxyRule_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
14
36
|
const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
15
|
-
const dest =
|
|
37
|
+
const dest = import_path.default.resolve(ruleDirectory, "proxy.rule.js");
|
|
16
38
|
let code = `/.*/ enable://intercept
|
|
17
39
|
`;
|
|
18
40
|
for (const rule of rules) {
|
|
@@ -20,7 +42,7 @@ const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
|
20
42
|
code += `${pattern} ${target}
|
|
21
43
|
`;
|
|
22
44
|
}
|
|
23
|
-
|
|
45
|
+
import_utils.fs.outputFileSync(dest, `exports.name = 'modernjs proxy rule';
|
|
24
46
|
exports.rules = \`${code}\`;`);
|
|
25
47
|
return dest;
|
|
26
48
|
};
|
|
@@ -33,7 +55,7 @@ const createProxyRule = (appDirectory, proxyOptions) => {
|
|
|
33
55
|
for (const pattern of Object.keys(proxyOptions)) {
|
|
34
56
|
const target = proxyOptions[pattern];
|
|
35
57
|
if (!target || typeof target !== "string") {
|
|
36
|
-
|
|
58
|
+
import_utils.logger.error(`dev.proxy.${pattern} value should be string type`);
|
|
37
59
|
process.exit(1);
|
|
38
60
|
}
|
|
39
61
|
rules.push({
|
|
@@ -44,3 +66,7 @@ const createProxyRule = (appDirectory, proxyOptions) => {
|
|
|
44
66
|
}
|
|
45
67
|
return createWhistleProxyRule(appDirectory, rules);
|
|
46
68
|
};
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
createProxyRule
|
|
72
|
+
});
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var execSync_exports = {};
|
|
20
|
+
__export(execSync_exports, {
|
|
21
|
+
default: () => execSync_default
|
|
10
22
|
});
|
|
11
|
-
|
|
23
|
+
module.exports = __toCommonJS(execSync_exports);
|
|
24
|
+
var import_child_process = require("child_process");
|
|
12
25
|
function execSync(cmd) {
|
|
13
26
|
let stdout;
|
|
14
27
|
let status = 0;
|
|
15
28
|
try {
|
|
16
|
-
stdout = (0,
|
|
29
|
+
stdout = (0, import_child_process.execSync)(cmd);
|
|
17
30
|
} catch (err) {
|
|
18
31
|
stdout = err.stdout;
|
|
19
32
|
status = err.status;
|
|
@@ -23,4 +36,4 @@ function execSync(cmd) {
|
|
|
23
36
|
status
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
var execSync_default = execSync;
|
|
@@ -1,60 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return defaultRootCA;
|
|
15
|
-
},
|
|
16
|
-
trustRootCA: function() {
|
|
17
|
-
return trustRootCA;
|
|
18
|
-
},
|
|
19
|
-
isRootCAExists: function() {
|
|
20
|
-
return isRootCAExists;
|
|
21
|
-
},
|
|
22
|
-
generateRootCA: function() {
|
|
23
|
-
return generateRootCA;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var macCAManager_exports = {};
|
|
30
|
+
__export(macCAManager_exports, {
|
|
31
|
+
defaultRootCA: () => defaultRootCA,
|
|
32
|
+
generateRootCA: () => generateRootCA,
|
|
33
|
+
isRootCAExists: () => isRootCAExists,
|
|
34
|
+
trustRootCA: () => trustRootCA
|
|
25
35
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const defaultCertDir =
|
|
33
|
-
const defaultRootCA =
|
|
36
|
+
module.exports = __toCommonJS(macCAManager_exports);
|
|
37
|
+
var import_os = __toESM(require("os"));
|
|
38
|
+
var import_http = __toESM(require("http"));
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_utils = require("@modern-js/utils");
|
|
41
|
+
var import_execSync = __toESM(require("./execSync"));
|
|
42
|
+
const defaultCertDir = import_path.default.resolve(import_os.default.homedir(), "./.whistle-proxy");
|
|
43
|
+
const defaultRootCA = import_path.default.resolve(defaultCertDir, "./rootCA.crt");
|
|
34
44
|
const trustRootCA = () => {
|
|
35
|
-
|
|
36
|
-
const { status } = (0,
|
|
45
|
+
import_utils.logger.info(`please type the password to trust the https certificate`);
|
|
46
|
+
const { status } = (0, import_execSync.default)(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
|
|
37
47
|
if (status === 0) {
|
|
38
|
-
|
|
48
|
+
import_utils.logger.info("Root CA install, you are ready to intercept the https now");
|
|
39
49
|
} else {
|
|
40
|
-
|
|
50
|
+
import_utils.logger.info("Failed to trust the root CA, please trust it manually");
|
|
41
51
|
}
|
|
42
52
|
};
|
|
43
53
|
const isRootCATrusted = () => {
|
|
44
54
|
};
|
|
45
55
|
const isRootCAExists = () => {
|
|
46
|
-
if (
|
|
56
|
+
if (import_utils.fs.existsSync(defaultRootCA)) {
|
|
47
57
|
return true;
|
|
48
58
|
}
|
|
49
59
|
return false;
|
|
50
60
|
};
|
|
51
61
|
const generateRootCA = (port) => new Promise((resolve, reject) => {
|
|
52
|
-
if (
|
|
53
|
-
|
|
62
|
+
if (import_utils.fs.existsSync(defaultRootCA)) {
|
|
63
|
+
import_utils.fs.removeSync(defaultRootCA);
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
const stream =
|
|
57
|
-
|
|
65
|
+
import_utils.fs.ensureDirSync(defaultCertDir);
|
|
66
|
+
const stream = import_utils.fs.createWriteStream(defaultRootCA);
|
|
67
|
+
import_http.default.get(`http://localhost:${port}/cgi-bin/rootca`, (response) => {
|
|
58
68
|
response.pipe(stream);
|
|
59
69
|
stream.on("finish", () => {
|
|
60
70
|
resolve(defaultRootCA);
|
|
@@ -62,7 +72,14 @@ const generateRootCA = (port) => new Promise((resolve, reject) => {
|
|
|
62
72
|
reject(err);
|
|
63
73
|
});
|
|
64
74
|
}).on("error", (err) => {
|
|
65
|
-
|
|
75
|
+
import_utils.fs.unlink(defaultRootCA);
|
|
66
76
|
reject(err);
|
|
67
77
|
});
|
|
68
78
|
});
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
defaultRootCA,
|
|
82
|
+
generateRootCA,
|
|
83
|
+
isRootCAExists,
|
|
84
|
+
trustRootCA
|
|
85
|
+
});
|
|
@@ -1,33 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
6
9
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return enableGlobalProxy;
|
|
15
|
-
},
|
|
16
|
-
disableGlobalProxy: function() {
|
|
17
|
-
return disableGlobalProxy;
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var macProxyManager_exports = {};
|
|
30
|
+
__export(macProxyManager_exports, {
|
|
31
|
+
disableGlobalProxy: () => disableGlobalProxy,
|
|
32
|
+
enableGlobalProxy: () => enableGlobalProxy
|
|
19
33
|
});
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
module.exports = __toCommonJS(macProxyManager_exports);
|
|
35
|
+
var import_execSync = __toESM(require("./execSync"));
|
|
22
36
|
const networkTypes = [
|
|
23
37
|
"Ethernet",
|
|
24
38
|
"Thunderbolt Ethernet",
|
|
25
39
|
"Wi-Fi"
|
|
26
40
|
];
|
|
41
|
+
const isMacOS = () => process.platform === "darwin";
|
|
27
42
|
const getNetworkType = () => {
|
|
28
43
|
for (let i = 0; i < networkTypes.length; i++) {
|
|
29
44
|
const type = networkTypes[i];
|
|
30
|
-
const result = (0,
|
|
45
|
+
const result = (0, import_execSync.default)(`networksetup -getwebproxy ${type}`);
|
|
31
46
|
if (result.status === 0) {
|
|
32
47
|
return type;
|
|
33
48
|
}
|
|
@@ -35,12 +50,23 @@ const getNetworkType = () => {
|
|
|
35
50
|
throw new Error("Unknown network type");
|
|
36
51
|
};
|
|
37
52
|
const enableGlobalProxy = (ip, port) => {
|
|
53
|
+
if (!isMacOS()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
38
56
|
const networkType = getNetworkType();
|
|
39
|
-
(0,
|
|
40
|
-
(0,
|
|
57
|
+
(0, import_execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
58
|
+
(0, import_execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
41
59
|
};
|
|
42
60
|
const disableGlobalProxy = () => {
|
|
61
|
+
if (!isMacOS()) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
43
64
|
const networkType = getNetworkType();
|
|
44
|
-
(0,
|
|
45
|
-
(0,
|
|
65
|
+
(0, import_execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
|
|
66
|
+
(0, import_execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
|
|
46
67
|
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
disableGlobalProxy,
|
|
71
|
+
enableGlobalProxy
|
|
72
|
+
});
|
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var whistleProxy_exports = {};
|
|
30
|
+
__export(whistleProxy_exports, {
|
|
31
|
+
default: () => WhistleProxy
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
33
|
+
module.exports = __toCommonJS(whistleProxy_exports);
|
|
34
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
var import_execSync = __toESM(require("./execSync"));
|
|
38
|
+
var import_macCAManager = require("./macCAManager");
|
|
17
39
|
const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
|
|
18
40
|
class WhistleProxy {
|
|
19
41
|
async installRootCA() {
|
|
20
42
|
try {
|
|
21
|
-
if (!(0,
|
|
22
|
-
await (0,
|
|
23
|
-
(0,
|
|
43
|
+
if (!(0, import_macCAManager.isRootCAExists)()) {
|
|
44
|
+
await (0, import_macCAManager.generateRootCA)(this.port);
|
|
45
|
+
(0, import_macCAManager.trustRootCA)();
|
|
24
46
|
}
|
|
25
47
|
} catch (err) {
|
|
26
48
|
this.close();
|
|
@@ -28,27 +50,27 @@ class WhistleProxy {
|
|
|
28
50
|
}
|
|
29
51
|
}
|
|
30
52
|
async start() {
|
|
31
|
-
|
|
32
|
-
(0,
|
|
33
|
-
(0,
|
|
53
|
+
import_utils.logger.info(`Starting proxy server.....`);
|
|
54
|
+
(0, import_execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
|
|
55
|
+
(0, import_execSync.default)(`${this.bin} use ${this.rule} --force`);
|
|
34
56
|
await this.installRootCA();
|
|
35
57
|
enableGlobalProxy("localhost", this.port);
|
|
36
|
-
|
|
58
|
+
import_utils.logger.info(`Proxy server start on localhost:${this.port}
|
|
37
59
|
`);
|
|
38
60
|
}
|
|
39
61
|
close() {
|
|
40
|
-
(0,
|
|
62
|
+
(0, import_execSync.default)(`${this.bin} stop`);
|
|
41
63
|
disableGlobalProxy();
|
|
42
|
-
|
|
64
|
+
import_utils.logger.info(`Proxy Server has been closed`);
|
|
43
65
|
}
|
|
44
66
|
constructor(config) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
(0, import_define_property._)(this, "rule", void 0);
|
|
68
|
+
(0, import_define_property._)(this, "port", void 0);
|
|
69
|
+
(0, import_define_property._)(this, "bin", void 0);
|
|
70
|
+
(0, import_define_property._)(this, "certDir", void 0);
|
|
49
71
|
this.rule = config.rule;
|
|
50
72
|
this.port = config.port;
|
|
51
|
-
this.bin =
|
|
52
|
-
this.certDir =
|
|
73
|
+
this.bin = import_path.default.resolve(import_path.default.dirname(require.resolve("whistle")), "bin/whistle.js");
|
|
74
|
+
this.certDir = import_path.default.dirname(import_macCAManager.defaultRootCA);
|
|
53
75
|
}
|
|
54
76
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createProxyRule } from "./utils/createProxyRule";
|
|
2
2
|
import WhistleProxy from "./utils/whistleProxy";
|
|
3
|
-
|
|
3
|
+
const proxyPlugin = () => {
|
|
4
4
|
let proxyServer;
|
|
5
5
|
return {
|
|
6
6
|
name: "@modern-js/plugin-proxy",
|
|
@@ -19,10 +19,9 @@ export const proxyPlugin = () => {
|
|
|
19
19
|
];
|
|
20
20
|
},
|
|
21
21
|
async afterDev() {
|
|
22
|
-
var _dev;
|
|
23
22
|
const { dev } = api.useResolvedConfigContext();
|
|
24
23
|
const { internalDirectory } = api.useAppContext();
|
|
25
|
-
if (!(
|
|
24
|
+
if (!(dev === null || dev === void 0 ? void 0 : dev.proxy)) {
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
const rule = createProxyRule(internalDirectory, dev.proxy);
|
|
@@ -35,10 +34,13 @@ export const proxyPlugin = () => {
|
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
beforeExit() {
|
|
38
|
-
|
|
39
|
-
(_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
|
|
37
|
+
proxyServer === null || proxyServer === void 0 ? void 0 : proxyServer.close();
|
|
40
38
|
}
|
|
41
39
|
})
|
|
42
40
|
};
|
|
43
41
|
};
|
|
44
|
-
|
|
42
|
+
var src_default = proxyPlugin;
|
|
43
|
+
export {
|
|
44
|
+
src_default as default,
|
|
45
|
+
proxyPlugin
|
|
46
|
+
};
|
|
@@ -13,7 +13,7 @@ const createWhistleProxyRule = (ruleDirectory, rules) => {
|
|
|
13
13
|
exports.rules = \`${code}\`;`);
|
|
14
14
|
return dest;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
const createProxyRule = (appDirectory, proxyOptions) => {
|
|
17
17
|
const rules = [];
|
|
18
18
|
if (proxyOptions && typeof proxyOptions === "string") {
|
|
19
19
|
return proxyOptions;
|
|
@@ -33,3 +33,6 @@ export const createProxyRule = (appDirectory, proxyOptions) => {
|
|
|
33
33
|
}
|
|
34
34
|
return createWhistleProxyRule(appDirectory, rules);
|
|
35
35
|
};
|
|
36
|
+
export {
|
|
37
|
+
createProxyRule
|
|
38
|
+
};
|
|
@@ -4,8 +4,8 @@ import path from "path";
|
|
|
4
4
|
import { fs, logger } from "@modern-js/utils";
|
|
5
5
|
import execSync from "./execSync";
|
|
6
6
|
const defaultCertDir = path.resolve(os.homedir(), "./.whistle-proxy");
|
|
7
|
-
|
|
8
|
-
|
|
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
10
|
const { status } = execSync(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
|
|
11
11
|
if (status === 0) {
|
|
@@ -16,13 +16,13 @@ export const trustRootCA = () => {
|
|
|
16
16
|
};
|
|
17
17
|
const isRootCATrusted = () => {
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
const isRootCAExists = () => {
|
|
20
20
|
if (fs.existsSync(defaultRootCA)) {
|
|
21
21
|
return true;
|
|
22
22
|
}
|
|
23
23
|
return false;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
const generateRootCA = (port) => new Promise((resolve, reject) => {
|
|
26
26
|
if (fs.existsSync(defaultRootCA)) {
|
|
27
27
|
fs.removeSync(defaultRootCA);
|
|
28
28
|
}
|
|
@@ -40,3 +40,9 @@ export const generateRootCA = (port) => new Promise((resolve, reject) => {
|
|
|
40
40
|
reject(err);
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
|
+
export {
|
|
44
|
+
defaultRootCA,
|
|
45
|
+
generateRootCA,
|
|
46
|
+
isRootCAExists,
|
|
47
|
+
trustRootCA
|
|
48
|
+
};
|
|
@@ -4,6 +4,7 @@ const networkTypes = [
|
|
|
4
4
|
"Thunderbolt Ethernet",
|
|
5
5
|
"Wi-Fi"
|
|
6
6
|
];
|
|
7
|
+
const isMacOS = () => process.platform === "darwin";
|
|
7
8
|
const getNetworkType = () => {
|
|
8
9
|
for (let i = 0; i < networkTypes.length; i++) {
|
|
9
10
|
const type = networkTypes[i];
|
|
@@ -14,13 +15,23 @@ const getNetworkType = () => {
|
|
|
14
15
|
}
|
|
15
16
|
throw new Error("Unknown network type");
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
+
const enableGlobalProxy = (ip, port) => {
|
|
19
|
+
if (!isMacOS()) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
18
22
|
const networkType = getNetworkType();
|
|
19
23
|
execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
|
|
20
24
|
execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
|
|
21
25
|
};
|
|
22
|
-
|
|
26
|
+
const disableGlobalProxy = () => {
|
|
27
|
+
if (!isMacOS()) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
23
30
|
const networkType = getNetworkType();
|
|
24
31
|
execSync(`networksetup -setwebproxystate ${networkType} off`);
|
|
25
32
|
execSync(`networksetup -setsecurewebproxystate ${networkType} off`);
|
|
26
33
|
};
|
|
34
|
+
export {
|
|
35
|
+
disableGlobalProxy,
|
|
36
|
+
enableGlobalProxy
|
|
37
|
+
};
|
|
@@ -17,12 +17,12 @@ class WhistleProxy {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
async start() {
|
|
20
|
-
logger.info(`Starting
|
|
20
|
+
logger.info(`Starting proxy server.....`);
|
|
21
21
|
execSync(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
|
|
22
22
|
execSync(`${this.bin} use ${this.rule} --force`);
|
|
23
23
|
await this.installRootCA();
|
|
24
24
|
enableGlobalProxy("localhost", this.port);
|
|
25
|
-
logger.info(`Proxy
|
|
25
|
+
logger.info(`Proxy server start on localhost:${this.port}
|
|
26
26
|
`);
|
|
27
27
|
}
|
|
28
28
|
close() {
|
|
@@ -41,4 +41,6 @@ class WhistleProxy {
|
|
|
41
41
|
this.certDir = path.dirname(defaultRootCA);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
export {
|
|
44
|
+
export {
|
|
45
|
+
WhistleProxy as default
|
|
46
|
+
};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.36.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.
|
|
39
|
+
"@modern-js/utils": "2.36.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
|
-
"@scripts/
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
46
|
+
"@scripts/build": "2.36.0",
|
|
47
|
+
"@scripts/jest-config": "2.36.0",
|
|
48
|
+
"@modern-js/core": "2.36.0"
|
|
49
49
|
},
|
|
50
50
|
"sideEffects": false,
|
|
51
51
|
"publishConfig": {
|