@modern-js/plugin-proxy 2.35.1 → 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 CHANGED
@@ -1,25 +1,39 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- proxyPlugin: function() {
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
- const _createProxyRule = require("./utils/createProxyRule");
22
- const _whistleProxy = /* @__PURE__ */ _interop_require_default._(require("./utils/whistleProxy"));
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 {
@@ -44,9 +58,9 @@ const proxyPlugin = () => {
44
58
  if (!(dev === null || dev === void 0 ? void 0 : dev.proxy)) {
45
59
  return;
46
60
  }
47
- const rule = (0, _createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
61
+ const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
48
62
  if (!proxyServer) {
49
- proxyServer = new _whistleProxy.default({
63
+ proxyServer = new import_whistleProxy.default({
50
64
  port: 8899,
51
65
  rule
52
66
  });
@@ -59,4 +73,8 @@ const proxyPlugin = () => {
59
73
  })
60
74
  };
61
75
  };
62
- const _default = proxyPlugin;
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createProxyRule", {
6
- enumerable: true,
7
- get: function() {
8
- return createProxyRule;
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
13
- const _utils = require("@modern-js/utils");
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 = _path.default.resolve(ruleDirectory, "proxy.rule.js");
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
- _utils.fs.outputFileSync(dest, `exports.name = 'modernjs proxy rule';
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
- _utils.logger.error(`dev.proxy.${pattern} value should be string type`);
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(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return _default;
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
- const _child_process = require("child_process");
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, _child_process.execSync)(cmd);
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
- const _default = execSync;
39
+ var execSync_default = execSync;
@@ -1,60 +1,70 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- defaultRootCA: function() {
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
27
- const _os = /* @__PURE__ */ _interop_require_default._(require("os"));
28
- const _http = /* @__PURE__ */ _interop_require_default._(require("http"));
29
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
30
- const _utils = require("@modern-js/utils");
31
- const _execSync = /* @__PURE__ */ _interop_require_default._(require("./execSync"));
32
- const defaultCertDir = _path.default.resolve(_os.default.homedir(), "./.whistle-proxy");
33
- const defaultRootCA = _path.default.resolve(defaultCertDir, "./rootCA.crt");
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
- _utils.logger.info(`please type the password to trust the https certificate`);
36
- const { status } = (0, _execSync.default)(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
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
- _utils.logger.info("Root CA install, you are ready to intercept the https now");
48
+ import_utils.logger.info("Root CA install, you are ready to intercept the https now");
39
49
  } else {
40
- _utils.logger.info("Failed to trust the root CA, please trust it manually");
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 (_utils.fs.existsSync(defaultRootCA)) {
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 (_utils.fs.existsSync(defaultRootCA)) {
53
- _utils.fs.removeSync(defaultRootCA);
62
+ if (import_utils.fs.existsSync(defaultRootCA)) {
63
+ import_utils.fs.removeSync(defaultRootCA);
54
64
  }
55
- _utils.fs.ensureDirSync(defaultCertDir);
56
- const stream = _utils.fs.createWriteStream(defaultRootCA);
57
- _http.default.get(`http://localhost:${port}/cgi-bin/rootca`, (response) => {
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
- _utils.fs.unlink(defaultRootCA);
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- enableGlobalProxy: function() {
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
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
- const _execSync = /* @__PURE__ */ _interop_require_default._(require("./execSync"));
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, _execSync.default)(`networksetup -getwebproxy ${type}`);
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, _execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
40
- (0, _execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
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, _execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
45
- (0, _execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
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.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
8
- return WhistleProxy;
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
- const _define_property = require("@swc/helpers/_/_define_property");
12
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
14
- const _utils = require("@modern-js/utils");
15
- const _execSync = /* @__PURE__ */ _interop_require_default._(require("./execSync"));
16
- const _macCAManager = require("./macCAManager");
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, _macCAManager.isRootCAExists)()) {
22
- await (0, _macCAManager.generateRootCA)(this.port);
23
- (0, _macCAManager.trustRootCA)();
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
- _utils.logger.info(`Starting proxy server.....`);
32
- (0, _execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
33
- (0, _execSync.default)(`${this.bin} use ${this.rule} --force`);
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
- _utils.logger.info(`Proxy server start on localhost:${this.port}
58
+ import_utils.logger.info(`Proxy server start on localhost:${this.port}
37
59
  `);
38
60
  }
39
61
  close() {
40
- (0, _execSync.default)(`${this.bin} stop`);
62
+ (0, import_execSync.default)(`${this.bin} stop`);
41
63
  disableGlobalProxy();
42
- _utils.logger.info(`Proxy Server has been closed`);
64
+ import_utils.logger.info(`Proxy Server has been closed`);
43
65
  }
44
66
  constructor(config) {
45
- _define_property._(this, "rule", void 0);
46
- _define_property._(this, "port", void 0);
47
- _define_property._(this, "bin", void 0);
48
- _define_property._(this, "certDir", void 0);
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 = _path.default.resolve(_path.default.dirname(require.resolve("whistle")), "bin/whistle.js");
52
- this.certDir = _path.default.dirname(_macCAManager.defaultRootCA);
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
- export const proxyPlugin = () => {
3
+ const proxyPlugin = () => {
4
4
  let proxyServer;
5
5
  return {
6
6
  name: "@modern-js/plugin-proxy",
@@ -39,4 +39,8 @@ export const proxyPlugin = () => {
39
39
  })
40
40
  };
41
41
  };
42
- export default proxyPlugin;
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
- export const createProxyRule = (appDirectory, proxyOptions) => {
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
+ };
@@ -13,4 +13,7 @@ function execSync(cmd) {
13
13
  status
14
14
  };
15
15
  }
16
- export default execSync;
16
+ var execSync_default = execSync;
17
+ export {
18
+ execSync_default as default
19
+ };
@@ -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
- export const defaultRootCA = path.resolve(defaultCertDir, "./rootCA.crt");
8
- export const trustRootCA = () => {
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
- export const isRootCAExists = () => {
19
+ const isRootCAExists = () => {
20
20
  if (fs.existsSync(defaultRootCA)) {
21
21
  return true;
22
22
  }
23
23
  return false;
24
24
  };
25
- export const generateRootCA = (port) => new Promise((resolve, reject) => {
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
- export const enableGlobalProxy = (ip, port) => {
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
- export const disableGlobalProxy = () => {
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
+ };
@@ -41,4 +41,6 @@ class WhistleProxy {
41
41
  this.certDir = path.dirname(defaultRootCA);
42
42
  }
43
43
  }
44
- export { WhistleProxy as default };
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.35.1",
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.35.1"
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
- "@modern-js/core": "2.35.1",
47
- "@scripts/build": "2.35.1",
48
- "@scripts/jest-config": "2.35.1"
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": {