@modern-js/plugin-proxy 2.4.1-beta.0 → 2.6.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,11 +1,28 @@
1
1
  # @modern-js/plugin-proxy
2
2
 
3
- ## 2.4.1-beta.0
3
+ ## 2.6.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - Updated dependencies [e1f799e]
8
+ - Updated dependencies [7915ab3]
9
+ - Updated dependencies [0fe658a]
10
+ - @modern-js/utils@2.6.0
11
+
12
+ ## 2.5.0
13
+
14
+ ### Patch Changes
15
+
16
+ - 89ca6cc: refactor: merge build-config into scripts/build
17
+
18
+ refactor: 把 build-config 合并进 scripts/build
19
+
20
+ - 30614fa: chore: modify package.json entry fields and build config
21
+ chore: 更改 package.json entry 字段以及构建配置
22
+ - Updated dependencies [30614fa]
23
+ - Updated dependencies [1b0ce87]
7
24
  - Updated dependencies [11c053b]
8
- - @modern-js/utils@2.4.1-beta.0
25
+ - @modern-js/utils@2.5.0
9
26
 
10
27
  ## 2.4.0
11
28
 
@@ -17,30 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
23
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
28
  var src_exports = {};
45
29
  __export(src_exports, {
46
30
  default: () => src_default
@@ -57,17 +41,15 @@ var src_default = () => {
57
41
  validateSchema() {
58
42
  return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
59
43
  },
60
- afterDev() {
61
- return __async(this, null, function* () {
62
- const { dev } = api.useResolvedConfigContext();
63
- const { internalDirectory } = api.useAppContext();
64
- if (!(dev == null ? void 0 : dev.proxy)) {
65
- return;
66
- }
67
- const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
68
- proxyServer = new import_whistleProxy.default({ port: 8899, rule });
69
- yield proxyServer.start();
70
- });
44
+ async afterDev() {
45
+ const { dev } = api.useResolvedConfigContext();
46
+ const { internalDirectory } = api.useAppContext();
47
+ if (!(dev == null ? void 0 : dev.proxy)) {
48
+ return;
49
+ }
50
+ const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
51
+ proxyServer = new import_whistleProxy.default({ port: 8899, rule });
52
+ await proxyServer.start();
71
53
  },
72
54
  beforeExit() {
73
55
  proxyServer == null ? void 0 : proxyServer.close();
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -17,30 +17,14 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
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.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
23
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var __async = (__this, __arguments, generator) => {
25
- return new Promise((resolve, reject) => {
26
- var fulfilled = (value) => {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var rejected = (value) => {
34
- try {
35
- step(generator.throw(value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- };
40
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
- step((generator = generator.apply(__this, __arguments)).next());
42
- });
43
- };
44
28
  var whistleProxy_exports = {};
45
29
  __export(whistleProxy_exports, {
46
30
  default: () => WhistleProxy
@@ -61,29 +45,25 @@ class WhistleProxy {
61
45
  );
62
46
  this.certDir = import_path.default.dirname(import_macCAManager.defaultRootCA);
63
47
  }
64
- installRootCA() {
65
- return __async(this, null, function* () {
66
- try {
67
- if (!(0, import_macCAManager.isRootCAExists)()) {
68
- yield (0, import_macCAManager.generateRootCA)(this.port);
69
- (0, import_macCAManager.trustRootCA)();
70
- }
71
- } catch (err) {
72
- this.close();
73
- throw err;
48
+ async installRootCA() {
49
+ try {
50
+ if (!(0, import_macCAManager.isRootCAExists)()) {
51
+ await (0, import_macCAManager.generateRootCA)(this.port);
52
+ (0, import_macCAManager.trustRootCA)();
74
53
  }
75
- });
54
+ } catch (err) {
55
+ this.close();
56
+ throw err;
57
+ }
76
58
  }
77
- start() {
78
- return __async(this, null, function* () {
79
- import_utils.logger.info(`Starting the proxy server.....`);
80
- (0, import_execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
81
- (0, import_execSync.default)(`${this.bin} use ${this.rule} --force`);
82
- yield this.installRootCA();
83
- enableGlobalProxy("localhost", this.port);
84
- import_utils.logger.info(`Proxy Server start on localhost:${this.port}
59
+ 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`);
63
+ await this.installRootCA();
64
+ enableGlobalProxy("localhost", this.port);
65
+ import_utils.logger.info(`Proxy Server start on localhost:${this.port}
85
66
  `);
86
- });
87
67
  }
88
68
  close() {
89
69
  (0, import_execSync.default)(`${this.bin} stop`);
@@ -0,0 +1,30 @@
1
+ import { PLUGIN_SCHEMAS } from "@modern-js/utils";
2
+ import { createProxyRule } from "./utils/createProxyRule";
3
+ import WhistleProxy from "./utils/whistleProxy";
4
+ var src_default = () => {
5
+ let proxyServer;
6
+ return {
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;
17
+ }
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
+ })
26
+ };
27
+ };
28
+ export {
29
+ src_default as default
30
+ };
@@ -0,0 +1,49 @@
1
+ import path from "path";
2
+ import { logger } from "@modern-js/utils";
3
+ import execSync from "./execSync";
4
+ import {
5
+ isRootCAExists,
6
+ generateRootCA,
7
+ defaultRootCA,
8
+ trustRootCA
9
+ } from "./macCAManager";
10
+ const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
11
+ 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
+ async installRootCA() {
22
+ try {
23
+ if (!isRootCAExists()) {
24
+ await generateRootCA(this.port);
25
+ trustRootCA();
26
+ }
27
+ } catch (err) {
28
+ this.close();
29
+ throw err;
30
+ }
31
+ }
32
+ async start() {
33
+ logger.info(`Starting the proxy server.....`);
34
+ execSync(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
35
+ execSync(`${this.bin} use ${this.rule} --force`);
36
+ await this.installRootCA();
37
+ enableGlobalProxy("localhost", this.port);
38
+ logger.info(`Proxy Server start on localhost:${this.port}
39
+ `);
40
+ }
41
+ close() {
42
+ execSync(`${this.bin} stop`);
43
+ disableGlobalProxy();
44
+ logger.info(`Proxy Server has been closed`);
45
+ }
46
+ }
47
+ export {
48
+ WhistleProxy as default
49
+ };
package/package.json CHANGED
@@ -11,38 +11,37 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.4.1-beta.0",
14
+ "version": "2.6.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
- "main": "./dist/js/node/index.js",
18
- "jsnext:modern": "./dist/js/modern/index.js",
17
+ "main": "./dist/cjs/index.js",
19
18
  "exports": {
20
19
  ".": {
21
20
  "node": {
22
21
  "jsnext:source": "./src/index.ts",
23
- "import": "./dist/js/modern/index.js",
24
- "require": "./dist/js/node/index.js"
22
+ "import": "./dist/esm/index.js",
23
+ "require": "./dist/cjs/index.js"
25
24
  },
26
- "default": "./dist/js/node/index.js"
25
+ "default": "./dist/cjs/index.js"
27
26
  },
28
27
  "./cli": {
29
28
  "jsnext:source": "./src/index.ts",
30
- "default": "./dist/js/node/index.js"
29
+ "default": "./dist/cjs/index.js"
31
30
  }
32
31
  },
33
32
  "dependencies": {
34
33
  "@babel/runtime": "^7.18.0",
35
34
  "whistle": "^2.7.18",
36
- "@modern-js/utils": "2.4.1-beta.0"
35
+ "@modern-js/utils": "2.6.0"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@types/jest": "^27",
40
39
  "@types/node": "^14",
41
40
  "typescript": "^4",
42
41
  "jest": "^27",
43
- "@modern-js/core": "2.4.1-beta.0",
44
- "@scripts/jest-config": "2.4.0",
45
- "@scripts/build": "2.4.0"
42
+ "@modern-js/core": "2.6.0",
43
+ "@scripts/jest-config": "2.6.0",
44
+ "@scripts/build": "2.6.0"
46
45
  },
47
46
  "sideEffects": false,
48
47
  "publishConfig": {
@@ -1,52 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { PLUGIN_SCHEMAS } from "@modern-js/utils";
22
- import { createProxyRule } from "./utils/createProxyRule";
23
- import WhistleProxy from "./utils/whistleProxy";
24
- var src_default = () => {
25
- let proxyServer;
26
- return {
27
- name: "@modern-js/plugin-proxy",
28
- setup: (api) => ({
29
- validateSchema() {
30
- return PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
31
- },
32
- afterDev() {
33
- return __async(this, null, function* () {
34
- const { dev } = api.useResolvedConfigContext();
35
- const { internalDirectory } = api.useAppContext();
36
- if (!(dev == null ? void 0 : dev.proxy)) {
37
- return;
38
- }
39
- const rule = createProxyRule(internalDirectory, dev.proxy);
40
- proxyServer = new WhistleProxy({ port: 8899, rule });
41
- yield proxyServer.start();
42
- });
43
- },
44
- beforeExit() {
45
- proxyServer == null ? void 0 : proxyServer.close();
46
- }
47
- })
48
- };
49
- };
50
- export {
51
- src_default as default
52
- };
@@ -1,73 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import path from "path";
22
- import { logger } from "@modern-js/utils";
23
- import execSync from "./execSync";
24
- import {
25
- isRootCAExists,
26
- generateRootCA,
27
- defaultRootCA,
28
- trustRootCA
29
- } from "./macCAManager";
30
- const { disableGlobalProxy, enableGlobalProxy } = require("./macProxyManager");
31
- class WhistleProxy {
32
- constructor(config) {
33
- this.rule = config.rule;
34
- this.port = config.port;
35
- this.bin = path.resolve(
36
- path.dirname(require.resolve("whistle")),
37
- "bin/whistle.js"
38
- );
39
- this.certDir = path.dirname(defaultRootCA);
40
- }
41
- installRootCA() {
42
- return __async(this, null, function* () {
43
- try {
44
- if (!isRootCAExists()) {
45
- yield generateRootCA(this.port);
46
- trustRootCA();
47
- }
48
- } catch (err) {
49
- this.close();
50
- throw err;
51
- }
52
- });
53
- }
54
- start() {
55
- return __async(this, null, function* () {
56
- logger.info(`Starting the proxy server.....`);
57
- execSync(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
58
- execSync(`${this.bin} use ${this.rule} --force`);
59
- yield this.installRootCA();
60
- enableGlobalProxy("localhost", this.port);
61
- logger.info(`Proxy Server start on localhost:${this.port}
62
- `);
63
- });
64
- }
65
- close() {
66
- execSync(`${this.bin} stop`);
67
- disableGlobalProxy();
68
- logger.info(`Proxy Server has been closed`);
69
- }
70
- }
71
- export {
72
- WhistleProxy as default
73
- };
File without changes
File without changes
File without changes