@modern-js/plugin-proxy 2.4.1-beta.0 → 2.5.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,19 @@
1
1
  # @modern-js/plugin-proxy
2
2
 
3
- ## 2.4.1-beta.0
3
+ ## 2.5.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - 89ca6cc: refactor: merge build-config into scripts/build
8
+
9
+ refactor: 把 build-config 合并进 scripts/build
10
+
11
+ - 30614fa: chore: modify package.json entry fields and build config
12
+ chore: 更改 package.json entry 字段以及构建配置
13
+ - Updated dependencies [30614fa]
14
+ - Updated dependencies [1b0ce87]
7
15
  - Updated dependencies [11c053b]
8
- - @modern-js/utils@2.4.1-beta.0
16
+ - @modern-js/utils@2.5.0
9
17
 
10
18
  ## 2.4.0
11
19
 
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  mod
22
22
  ));
23
23
  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
24
  var src_exports = {};
45
25
  __export(src_exports, {
46
26
  default: () => src_default
@@ -57,17 +37,15 @@ var src_default = () => {
57
37
  validateSchema() {
58
38
  return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-proxy"];
59
39
  },
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
- });
40
+ async afterDev() {
41
+ const { dev } = api.useResolvedConfigContext();
42
+ const { internalDirectory } = api.useAppContext();
43
+ if (!(dev == null ? void 0 : dev.proxy)) {
44
+ return;
45
+ }
46
+ const rule = (0, import_createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
47
+ proxyServer = new import_whistleProxy.default({ port: 8899, rule });
48
+ await proxyServer.start();
71
49
  },
72
50
  beforeExit() {
73
51
  proxyServer == null ? void 0 : proxyServer.close();
File without changes
File without changes
File without changes
File without changes
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  mod
22
22
  ));
23
23
  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
24
  var whistleProxy_exports = {};
45
25
  __export(whistleProxy_exports, {
46
26
  default: () => WhistleProxy
@@ -61,29 +41,25 @@ class WhistleProxy {
61
41
  );
62
42
  this.certDir = import_path.default.dirname(import_macCAManager.defaultRootCA);
63
43
  }
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;
44
+ async installRootCA() {
45
+ try {
46
+ if (!(0, import_macCAManager.isRootCAExists)()) {
47
+ await (0, import_macCAManager.generateRootCA)(this.port);
48
+ (0, import_macCAManager.trustRootCA)();
74
49
  }
75
- });
50
+ } catch (err) {
51
+ this.close();
52
+ throw err;
53
+ }
76
54
  }
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}
55
+ async start() {
56
+ import_utils.logger.info(`Starting the proxy server.....`);
57
+ (0, import_execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
58
+ (0, import_execSync.default)(`${this.bin} use ${this.rule} --force`);
59
+ await this.installRootCA();
60
+ enableGlobalProxy("localhost", this.port);
61
+ import_utils.logger.info(`Proxy Server start on localhost:${this.port}
85
62
  `);
86
- });
87
63
  }
88
64
  close() {
89
65
  (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
+ };
File without changes
File without changes
File without changes
File without changes
@@ -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.5.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.5.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.5.0",
43
+ "@scripts/build": "2.5.0",
44
+ "@scripts/jest-config": "2.5.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
- };