@modern-js/plugin-proxy 2.15.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @modern-js/plugin-proxy
2
2
 
3
+ ## 2.17.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @modern-js/utils@2.17.0
8
+
9
+ ## 2.16.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 4e876ab: chore: package.json include the monorepo-relative directory
14
+
15
+ chore: 在 package.json 中声明 monorepo 的子路径
16
+
17
+ - Updated dependencies [5954330]
18
+ - Updated dependencies [7596520]
19
+ - Updated dependencies [4e876ab]
20
+ - @modern-js/utils@2.16.0
21
+
3
22
  ## 2.15.0
4
23
 
5
24
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -1,61 +1,45 @@
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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var src_exports = {};
29
- __export(src_exports, {
30
- default: () => src_default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
31
4
  });
32
- module.exports = __toCommonJS(src_exports);
33
- var import_utils = require("@modern-js/utils");
34
- var import_createProxyRule = require("./utils/createProxyRule");
35
- var import_whistleProxy = __toESM(require("./utils/whistleProxy"));
36
- var src_default = () => {
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: () => _default
8
+ });
9
+ const _utils = require("@modern-js/utils");
10
+ const _createProxyRule = require("./utils/createProxyRule");
11
+ const _whistleProxy = /* @__PURE__ */ _interop_require_default(require("./utils/whistleProxy"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const _default = () => {
37
18
  let proxyServer;
38
19
  return {
39
20
  name: "@modern-js/plugin-proxy",
40
- setup: (api) => ({
41
- validateSchema() {
42
- return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
43
- },
44
- async afterDev() {
45
- const { dev } = api.useResolvedConfigContext();
46
- const { internalDirectory } = api.useAppContext();
47
- if (!(dev == null ? void 0 : dev.proxy)) {
48
- return;
21
+ setup: (api) => {
22
+ return {
23
+ validateSchema() {
24
+ return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
25
+ },
26
+ async afterDev() {
27
+ const { dev } = api.useResolvedConfigContext();
28
+ const { internalDirectory } = api.useAppContext();
29
+ if (!(dev === null || dev === void 0 ? void 0 : dev.proxy)) {
30
+ return;
31
+ }
32
+ const rule = (0, _createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
33
+ proxyServer = new _whistleProxy.default({
34
+ port: 8899,
35
+ rule
36
+ });
37
+ await proxyServer.start();
38
+ },
39
+ beforeExit() {
40
+ proxyServer === null || proxyServer === void 0 ? void 0 : proxyServer.close();
49
41
  }
50
- const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
51
- proxyServer = new import_whistleProxy.default({ port: 8899, rule });
52
- await proxyServer.start();
53
- },
54
- beforeExit() {
55
- proxyServer == null ? void 0 : proxyServer.close();
56
- }
57
- })
42
+ };
43
+ }
58
44
  };
59
45
  };
60
- // Annotate the CommonJS export names for ESM import in node:
61
- 0 && (module.exports = {});
@@ -1,39 +1,20 @@
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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var createProxyRule_exports = {};
29
- __export(createProxyRule_exports, {
30
- createProxyRule: () => createProxyRule
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
31
4
  });
32
- module.exports = __toCommonJS(createProxyRule_exports);
33
- var import_path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
5
+ Object.defineProperty(exports, "createProxyRule", {
6
+ enumerable: true,
7
+ get: () => createProxyRule
8
+ });
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ function _interop_require_default(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
35
16
  const createWhistleProxyRule = (ruleDirectory, rules) => {
36
- const dest = import_path.default.resolve(ruleDirectory, "proxy.rule.js");
17
+ const dest = _path.default.resolve(ruleDirectory, "proxy.rule.js");
37
18
  let code = `/.*/ enable://intercept
38
19
  `;
39
20
  for (const rule of rules) {
@@ -41,11 +22,8 @@ const createWhistleProxyRule = (ruleDirectory, rules) => {
41
22
  code += `${pattern} ${target}
42
23
  `;
43
24
  }
44
- import_utils.fs.outputFileSync(
45
- dest,
46
- `exports.name = 'modernjs proxy rule';
47
- exports.rules = \`${code}\`;`
48
- );
25
+ _utils.fs.outputFileSync(dest, `exports.name = 'modernjs proxy rule';
26
+ exports.rules = \`${code}\`;`);
49
27
  return dest;
50
28
  };
51
29
  const createProxyRule = (appDirectory, proxyOptions) => {
@@ -57,15 +35,14 @@ const createProxyRule = (appDirectory, proxyOptions) => {
57
35
  for (const pattern of Object.keys(proxyOptions)) {
58
36
  const target = proxyOptions[pattern];
59
37
  if (!target || typeof target !== "string") {
60
- import_utils.logger.error(`dev.proxy.${pattern} value should be string type`);
38
+ _utils.logger.error(`dev.proxy.${pattern} value should be string type`);
61
39
  process.exit(1);
62
40
  }
63
- rules.push({ pattern, target });
41
+ rules.push({
42
+ pattern,
43
+ target
44
+ });
64
45
  }
65
46
  }
66
47
  return createWhistleProxyRule(appDirectory, rules);
67
48
  };
68
- // Annotate the CommonJS export names for ESM import in node:
69
- 0 && (module.exports = {
70
- createProxyRule
71
- });
@@ -1,31 +1,17 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var execSync_exports = {};
19
- __export(execSync_exports, {
20
- default: () => execSync_default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: () => _default
21
8
  });
22
- module.exports = __toCommonJS(execSync_exports);
23
- var import_child_process = require("child_process");
9
+ const _child_process = require("child_process");
24
10
  function execSync(cmd) {
25
11
  let stdout;
26
12
  let status = 0;
27
13
  try {
28
- stdout = (0, import_child_process.execSync)(cmd);
14
+ stdout = (0, _child_process.execSync)(cmd);
29
15
  } catch (err) {
30
16
  stdout = err.stdout;
31
17
  status = err.status;
@@ -35,6 +21,4 @@ function execSync(cmd) {
35
21
  status
36
22
  };
37
23
  }
38
- var execSync_default = execSync;
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {});
24
+ const _default = execSync;
@@ -1,71 +1,56 @@
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) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var macCAManager_exports = {};
29
- __export(macCAManager_exports, {
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
30
13
  defaultRootCA: () => defaultRootCA,
31
- generateRootCA: () => generateRootCA,
14
+ trustRootCA: () => trustRootCA,
32
15
  isRootCAExists: () => isRootCAExists,
33
- trustRootCA: () => trustRootCA
16
+ generateRootCA: () => generateRootCA
34
17
  });
35
- module.exports = __toCommonJS(macCAManager_exports);
36
- var import_os = __toESM(require("os"));
37
- var import_http = __toESM(require("http"));
38
- var import_path = __toESM(require("path"));
39
- var import_utils = require("@modern-js/utils");
40
- var import_execSync = __toESM(require("./execSync"));
41
- const defaultCertDir = import_path.default.resolve(import_os.default.homedir(), "./.whistle-proxy");
42
- const defaultRootCA = import_path.default.resolve(defaultCertDir, "./rootCA.crt");
18
+ const _os = /* @__PURE__ */ _interop_require_default(require("os"));
19
+ const _http = /* @__PURE__ */ _interop_require_default(require("http"));
20
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
21
+ const _utils = require("@modern-js/utils");
22
+ const _execSync = /* @__PURE__ */ _interop_require_default(require("./execSync"));
23
+ function _interop_require_default(obj) {
24
+ return obj && obj.__esModule ? obj : {
25
+ default: obj
26
+ };
27
+ }
28
+ const defaultCertDir = _path.default.resolve(_os.default.homedir(), "./.whistle-proxy");
29
+ const defaultRootCA = _path.default.resolve(defaultCertDir, "./rootCA.crt");
43
30
  const trustRootCA = () => {
44
- import_utils.logger.info(`please type the password to trust the https certificate`);
45
- const { status } = (0, import_execSync.default)(
46
- `sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`
47
- );
31
+ _utils.logger.info(`please type the password to trust the https certificate`);
32
+ const { status } = (0, _execSync.default)(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
48
33
  if (status === 0) {
49
- import_utils.logger.info("Root CA install, you are ready to intercept the https now");
34
+ _utils.logger.info("Root CA install, you are ready to intercept the https now");
50
35
  } else {
51
- import_utils.logger.info("Failed to trust the root CA, please trust it manually");
36
+ _utils.logger.info("Failed to trust the root CA, please trust it manually");
52
37
  }
53
38
  };
54
39
  const isRootCATrusted = () => {
55
40
  };
56
41
  const isRootCAExists = () => {
57
- if (import_utils.fs.existsSync(defaultRootCA)) {
42
+ if (_utils.fs.existsSync(defaultRootCA)) {
58
43
  return true;
59
44
  }
60
45
  return false;
61
46
  };
62
47
  const generateRootCA = (port) => new Promise((resolve, reject) => {
63
- if (import_utils.fs.existsSync(defaultRootCA)) {
64
- import_utils.fs.removeSync(defaultRootCA);
48
+ if (_utils.fs.existsSync(defaultRootCA)) {
49
+ _utils.fs.removeSync(defaultRootCA);
65
50
  }
66
- import_utils.fs.ensureDirSync(defaultCertDir);
67
- const stream = import_utils.fs.createWriteStream(defaultRootCA);
68
- import_http.default.get(`http://localhost:${port}/cgi-bin/rootca`, (response) => {
51
+ _utils.fs.ensureDirSync(defaultCertDir);
52
+ const stream = _utils.fs.createWriteStream(defaultRootCA);
53
+ _http.default.get(`http://localhost:${port}/cgi-bin/rootca`, (response) => {
69
54
  response.pipe(stream);
70
55
  stream.on("finish", () => {
71
56
  resolve(defaultRootCA);
@@ -73,14 +58,7 @@ const generateRootCA = (port) => new Promise((resolve, reject) => {
73
58
  reject(err);
74
59
  });
75
60
  }).on("error", (err) => {
76
- import_utils.fs.unlink(defaultRootCA);
61
+ _utils.fs.unlink(defaultRootCA);
77
62
  reject(err);
78
63
  });
79
64
  });
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- defaultRootCA,
83
- generateRootCA,
84
- isRootCAExists,
85
- trustRootCA
86
- });
@@ -1,42 +1,33 @@
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) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var macProxyManager_exports = {};
29
- __export(macProxyManager_exports, {
30
- disableGlobalProxy: () => disableGlobalProxy,
31
- enableGlobalProxy: () => enableGlobalProxy
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ enableGlobalProxy: () => enableGlobalProxy,
14
+ disableGlobalProxy: () => disableGlobalProxy
32
15
  });
33
- module.exports = __toCommonJS(macProxyManager_exports);
34
- var import_execSync = __toESM(require("./execSync"));
35
- const networkTypes = ["Ethernet", "Thunderbolt Ethernet", "Wi-Fi"];
16
+ const _execSync = /* @__PURE__ */ _interop_require_default(require("./execSync"));
17
+ function _interop_require_default(obj) {
18
+ return obj && obj.__esModule ? obj : {
19
+ default: obj
20
+ };
21
+ }
22
+ const networkTypes = [
23
+ "Ethernet",
24
+ "Thunderbolt Ethernet",
25
+ "Wi-Fi"
26
+ ];
36
27
  const getNetworkType = () => {
37
28
  for (let i = 0; i < networkTypes.length; i++) {
38
29
  const type = networkTypes[i];
39
- const result = (0, import_execSync.default)(`networksetup -getwebproxy ${type}`);
30
+ const result = (0, _execSync.default)(`networksetup -getwebproxy ${type}`);
40
31
  if (result.status === 0) {
41
32
  return type;
42
33
  }
@@ -45,16 +36,11 @@ const getNetworkType = () => {
45
36
  };
46
37
  const enableGlobalProxy = (ip, port) => {
47
38
  const networkType = getNetworkType();
48
- (0, import_execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
49
- (0, import_execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
39
+ (0, _execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
40
+ (0, _execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
50
41
  };
51
42
  const disableGlobalProxy = () => {
52
43
  const networkType = getNetworkType();
53
- (0, import_execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
54
- (0, import_execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
44
+ (0, _execSync.default)(`networksetup -setwebproxystate ${networkType} off`);
45
+ (0, _execSync.default)(`networksetup -setsecurewebproxystate ${networkType} off`);
55
46
  };
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- disableGlobalProxy,
59
- enableGlobalProxy
60
- });
@@ -1,55 +1,40 @@
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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var whistleProxy_exports = {};
29
- __export(whistleProxy_exports, {
30
- default: () => WhistleProxy
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: () => WhistleProxy
31
8
  });
32
- module.exports = __toCommonJS(whistleProxy_exports);
33
- var import_path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
35
- var import_execSync = __toESM(require("./execSync"));
36
- var import_macCAManager = require("./macCAManager");
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ const _execSync = /* @__PURE__ */ _interop_require_default(require("./execSync"));
12
+ const _macCAManager = require("./macCAManager");
13
+ function _define_property(obj, key, value) {
14
+ if (key in obj) {
15
+ Object.defineProperty(obj, key, {
16
+ value,
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true
20
+ });
21
+ } else {
22
+ obj[key] = value;
23
+ }
24
+ return obj;
25
+ }
26
+ function _interop_require_default(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
37
31
  const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
38
32
  class WhistleProxy {
39
- constructor(config) {
40
- this.rule = config.rule;
41
- this.port = config.port;
42
- this.bin = import_path.default.resolve(
43
- import_path.default.dirname(require.resolve("whistle")),
44
- "bin/whistle.js"
45
- );
46
- this.certDir = import_path.default.dirname(import_macCAManager.defaultRootCA);
47
- }
48
33
  async installRootCA() {
49
34
  try {
50
- if (!(0, import_macCAManager.isRootCAExists)()) {
51
- await (0, import_macCAManager.generateRootCA)(this.port);
52
- (0, import_macCAManager.trustRootCA)();
35
+ if (!(0, _macCAManager.isRootCAExists)()) {
36
+ await (0, _macCAManager.generateRootCA)(this.port);
37
+ (0, _macCAManager.trustRootCA)();
53
38
  }
54
39
  } catch (err) {
55
40
  this.close();
@@ -57,19 +42,27 @@ class WhistleProxy {
57
42
  }
58
43
  }
59
44
  async start() {
60
- import_utils.logger.info(`Starting the proxy server.....`);
61
- (0, import_execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
62
- (0, import_execSync.default)(`${this.bin} use ${this.rule} --force`);
45
+ _utils.logger.info(`Starting the proxy server.....`);
46
+ (0, _execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
47
+ (0, _execSync.default)(`${this.bin} use ${this.rule} --force`);
63
48
  await this.installRootCA();
64
49
  enableGlobalProxy("localhost", this.port);
65
- import_utils.logger.info(`Proxy Server start on localhost:${this.port}
50
+ _utils.logger.info(`Proxy Server start on localhost:${this.port}
66
51
  `);
67
52
  }
68
53
  close() {
69
- (0, import_execSync.default)(`${this.bin} stop`);
54
+ (0, _execSync.default)(`${this.bin} stop`);
70
55
  disableGlobalProxy();
71
- import_utils.logger.info(`Proxy Server has been closed`);
56
+ _utils.logger.info(`Proxy Server has been closed`);
57
+ }
58
+ constructor(config) {
59
+ _define_property(this, "rule", void 0);
60
+ _define_property(this, "port", void 0);
61
+ _define_property(this, "bin", void 0);
62
+ _define_property(this, "certDir", void 0);
63
+ this.rule = config.rule;
64
+ this.port = config.port;
65
+ this.bin = _path.default.resolve(_path.default.dirname(require.resolve("whistle")), "bin/whistle.js");
66
+ this.certDir = _path.default.dirname(_macCAManager.defaultRootCA);
72
67
  }
73
68
  }
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {});
package/dist/esm/index.js CHANGED
@@ -1,30 +1,32 @@
1
1
  import { PLUGIN_SCHEMAS } from "@modern-js/utils";
2
2
  import { createProxyRule } from "./utils/createProxyRule";
3
3
  import WhistleProxy from "./utils/whistleProxy";
4
- var src_default = () => {
4
+ export default () => {
5
5
  let proxyServer;
6
6
  return {
7
7
  name: "@modern-js/plugin-proxy",
8
- setup: (api) => ({
9
- validateSchema() {
10
- return PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
11
- },
12
- async afterDev() {
13
- const { dev } = api.useResolvedConfigContext();
14
- const { internalDirectory } = api.useAppContext();
15
- if (!(dev == null ? void 0 : dev.proxy)) {
16
- return;
8
+ setup: (api) => {
9
+ return {
10
+ validateSchema() {
11
+ return PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
12
+ },
13
+ async afterDev() {
14
+ const { dev } = api.useResolvedConfigContext();
15
+ const { internalDirectory } = api.useAppContext();
16
+ if (!(dev === null || dev === void 0 ? void 0 : dev.proxy)) {
17
+ return;
18
+ }
19
+ const rule = createProxyRule(internalDirectory, dev.proxy);
20
+ proxyServer = new WhistleProxy({
21
+ port: 8899,
22
+ rule
23
+ });
24
+ await proxyServer.start();
25
+ },
26
+ beforeExit() {
27
+ proxyServer === null || proxyServer === void 0 ? void 0 : proxyServer.close();
17
28
  }
18
- const rule = createProxyRule(internalDirectory, dev.proxy);
19
- proxyServer = new WhistleProxy({ port: 8899, rule });
20
- await proxyServer.start();
21
- },
22
- beforeExit() {
23
- proxyServer == null ? void 0 : proxyServer.close();
24
- }
25
- })
29
+ };
30
+ }
26
31
  };
27
32
  };
28
- export {
29
- src_default as default
30
- };
@@ -9,14 +9,11 @@ const createWhistleProxyRule = (ruleDirectory, rules) => {
9
9
  code += `${pattern} ${target}
10
10
  `;
11
11
  }
12
- fs.outputFileSync(
13
- dest,
14
- `exports.name = 'modernjs proxy rule';
15
- exports.rules = \`${code}\`;`
16
- );
12
+ fs.outputFileSync(dest, `exports.name = 'modernjs proxy rule';
13
+ exports.rules = \`${code}\`;`);
17
14
  return dest;
18
15
  };
19
- const createProxyRule = (appDirectory, proxyOptions) => {
16
+ export const createProxyRule = (appDirectory, proxyOptions) => {
20
17
  const rules = [];
21
18
  if (proxyOptions && typeof proxyOptions === "string") {
22
19
  return proxyOptions;
@@ -28,11 +25,11 @@ const createProxyRule = (appDirectory, proxyOptions) => {
28
25
  logger.error(`dev.proxy.${pattern} value should be string type`);
29
26
  process.exit(1);
30
27
  }
31
- rules.push({ pattern, target });
28
+ rules.push({
29
+ pattern,
30
+ target
31
+ });
32
32
  }
33
33
  }
34
34
  return createWhistleProxyRule(appDirectory, rules);
35
35
  };
36
- export {
37
- createProxyRule
38
- };
@@ -13,7 +13,4 @@ function execSync(cmd) {
13
13
  status
14
14
  };
15
15
  }
16
- var execSync_default = execSync;
17
- export {
18
- execSync_default as default
19
- };
16
+ export default execSync;
@@ -4,12 +4,10 @@ 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
- const defaultRootCA = path.resolve(defaultCertDir, "./rootCA.crt");
8
- const trustRootCA = () => {
7
+ export const defaultRootCA = path.resolve(defaultCertDir, "./rootCA.crt");
8
+ export const trustRootCA = () => {
9
9
  logger.info(`please type the password to trust the https certificate`);
10
- const { status } = execSync(
11
- `sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`
12
- );
10
+ const { status } = execSync(`sudo security add-trusted-cert -d -k /Library/Keychains/System.keychain ${defaultRootCA}`);
13
11
  if (status === 0) {
14
12
  logger.info("Root CA install, you are ready to intercept the https now");
15
13
  } else {
@@ -18,13 +16,13 @@ const trustRootCA = () => {
18
16
  };
19
17
  const isRootCATrusted = () => {
20
18
  };
21
- const isRootCAExists = () => {
19
+ export const isRootCAExists = () => {
22
20
  if (fs.existsSync(defaultRootCA)) {
23
21
  return true;
24
22
  }
25
23
  return false;
26
24
  };
27
- const generateRootCA = (port) => new Promise((resolve, reject) => {
25
+ export const generateRootCA = (port) => new Promise((resolve, reject) => {
28
26
  if (fs.existsSync(defaultRootCA)) {
29
27
  fs.removeSync(defaultRootCA);
30
28
  }
@@ -42,9 +40,3 @@ const generateRootCA = (port) => new Promise((resolve, reject) => {
42
40
  reject(err);
43
41
  });
44
42
  });
45
- export {
46
- defaultRootCA,
47
- generateRootCA,
48
- isRootCAExists,
49
- trustRootCA
50
- };
@@ -1,5 +1,9 @@
1
1
  import execSync from "./execSync";
2
- const networkTypes = ["Ethernet", "Thunderbolt Ethernet", "Wi-Fi"];
2
+ const networkTypes = [
3
+ "Ethernet",
4
+ "Thunderbolt Ethernet",
5
+ "Wi-Fi"
6
+ ];
3
7
  const getNetworkType = () => {
4
8
  for (let i = 0; i < networkTypes.length; i++) {
5
9
  const type = networkTypes[i];
@@ -10,17 +14,13 @@ const getNetworkType = () => {
10
14
  }
11
15
  throw new Error("Unknown network type");
12
16
  };
13
- const enableGlobalProxy = (ip, port) => {
17
+ export const enableGlobalProxy = (ip, port) => {
14
18
  const networkType = getNetworkType();
15
19
  execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
16
20
  execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
17
21
  };
18
- const disableGlobalProxy = () => {
22
+ export const disableGlobalProxy = () => {
19
23
  const networkType = getNetworkType();
20
24
  execSync(`networksetup -setwebproxystate ${networkType} off`);
21
25
  execSync(`networksetup -setsecurewebproxystate ${networkType} off`);
22
26
  };
23
- export {
24
- disableGlobalProxy,
25
- enableGlobalProxy
26
- };
@@ -1,23 +1,22 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import path from "path";
2
15
  import { logger } from "@modern-js/utils";
3
16
  import execSync from "./execSync";
4
- import {
5
- isRootCAExists,
6
- generateRootCA,
7
- defaultRootCA,
8
- trustRootCA
9
- } from "./macCAManager";
17
+ import { isRootCAExists, generateRootCA, defaultRootCA, trustRootCA } from "./macCAManager";
10
18
  const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
11
19
  class WhistleProxy {
12
- constructor(config) {
13
- this.rule = config.rule;
14
- this.port = config.port;
15
- this.bin = path.resolve(
16
- path.dirname(require.resolve("whistle")),
17
- "bin/whistle.js"
18
- );
19
- this.certDir = path.dirname(defaultRootCA);
20
- }
21
20
  async installRootCA() {
22
21
  try {
23
22
  if (!isRootCAExists()) {
@@ -43,7 +42,15 @@ class WhistleProxy {
43
42
  disableGlobalProxy();
44
43
  logger.info(`Proxy Server has been closed`);
45
44
  }
45
+ constructor(config) {
46
+ _define_property(this, "rule", void 0);
47
+ _define_property(this, "port", void 0);
48
+ _define_property(this, "bin", void 0);
49
+ _define_property(this, "certDir", void 0);
50
+ this.rule = config.rule;
51
+ this.port = config.port;
52
+ this.bin = path.resolve(path.dirname(require.resolve("whistle")), "bin/whistle.js");
53
+ this.certDir = path.dirname(defaultRootCA);
54
+ }
46
55
  }
47
- export {
48
- WhistleProxy as default
49
- };
56
+ export { WhistleProxy as default };
package/package.json CHANGED
@@ -3,7 +3,11 @@
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
5
  "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
- "repository": "web-infra-dev/modern.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/modern.js",
9
+ "directory": "packages/cli/plugin-proxy"
10
+ },
7
11
  "license": "MIT",
8
12
  "keywords": [
9
13
  "react",
@@ -11,7 +15,7 @@
11
15
  "modern",
12
16
  "modern.js"
13
17
  ],
14
- "version": "2.15.0",
18
+ "version": "2.17.0",
15
19
  "jsnext:source": "./src/index.ts",
16
20
  "types": "./dist/types/index.d.ts",
17
21
  "main": "./dist/cjs/index.js",
@@ -32,16 +36,16 @@
32
36
  "dependencies": {
33
37
  "@babel/runtime": "^7.18.0",
34
38
  "whistle": "^2.7.18",
35
- "@modern-js/utils": "2.15.0"
39
+ "@modern-js/utils": "2.17.0"
36
40
  },
37
41
  "devDependencies": {
38
42
  "@types/jest": "^29",
39
43
  "@types/node": "^14",
40
44
  "typescript": "^4",
41
45
  "jest": "^29",
42
- "@modern-js/core": "2.15.0",
43
- "@scripts/build": "2.15.0",
44
- "@scripts/jest-config": "2.15.0"
46
+ "@modern-js/core": "2.17.0",
47
+ "@scripts/jest-config": "2.17.0",
48
+ "@scripts/build": "2.17.0"
45
49
  },
46
50
  "sideEffects": false,
47
51
  "publishConfig": {