@modern-js/plugin-proxy 1.1.2-rc.0 → 1.2.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,18 +1,21 @@
1
1
  # @modern-js/plugin-proxy
2
2
 
3
- ## 1.1.2-rc.0
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cfe11628: Make Modern.js self bootstraping
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - Updated dependencies [d927bc83]
8
- - Updated dependencies [d73ff455]
9
- - Updated dependencies [9c1ab865]
10
- - Updated dependencies [d73ff455]
11
- - Updated dependencies [d73ff455]
12
- - Updated dependencies [d73ff455]
13
- - Updated dependencies [d73ff455]
14
- - @modern-js/utils@1.1.4-rc.0
15
- - @modern-js/core@1.1.4-rc.0
11
+ - f6932de7: fix proxy bin error
12
+ - bc87647d: fix: terminate whistle proxy when exiting the process
13
+ - Updated dependencies [2da09c69]
14
+ - Updated dependencies [fc71e36f]
15
+ - Updated dependencies [c3d46ee4]
16
+ - Updated dependencies [cfe11628]
17
+ - @modern-js/utils@1.2.0
18
+ - @modern-js/core@1.3.0
16
19
 
17
20
  ## 1.1.1
18
21
 
@@ -2,6 +2,7 @@ import { createPlugin, useAppContext, useResolvedConfigContext } from '@modern-j
2
2
  import { PLUGIN_SCHEMAS } from '@modern-js/utils';
3
3
  import { createProxyRule } from "./utils/createProxyRule";
4
4
  import WhistleProxy from "./utils/whistleProxy";
5
+ let proxyServer;
5
6
  export default createPlugin(() => ({
6
7
  validateSchema() {
7
8
  return PLUGIN_SCHEMAS['@modern-js/plugin-proxy'];
@@ -22,15 +23,18 @@ export default createPlugin(() => ({
22
23
  }
23
24
 
24
25
  const rule = createProxyRule(internalDirectory, dev.proxy);
25
- const proxyServer = new WhistleProxy({
26
+ proxyServer = new WhistleProxy({
26
27
  port: 8899,
27
28
  rule
28
29
  });
29
- await proxyServer.start(); // TODO
30
- // should exit proxy server before process exit
31
- // api.on('process-exit', () => {
32
- // proxyServer.close();
33
- // });
30
+ await proxyServer.start();
31
+ },
32
+
33
+ beforeExit() {
34
+ var _proxyServer;
35
+
36
+ // terminate whistle proxy
37
+ (_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
34
38
  }
35
39
 
36
40
  }), {
@@ -35,7 +35,7 @@ export const generateRootCA = () => new Promise((resolve, reject) => {
35
35
 
36
36
  fs.ensureDirSync(defaultCertDir);
37
37
  const stream = fs.createWriteStream(defaultRootCA);
38
- http.get('http://127.0.0.1:8899/cgi-bin/rootca', response => {
38
+ http.get('http://localhost:8899/cgi-bin/rootca', response => {
39
39
  response.pipe(stream);
40
40
  stream.on('finish', () => {
41
41
  resolve(defaultRootCA);
@@ -16,7 +16,7 @@ const getNetworkType = () => {
16
16
  };
17
17
 
18
18
  export const enableGlobalProxy = (ip, port) => {
19
- const networkType = getNetworkType(); // && networksetup -setproxybypassdomains ${networkType} 127.0.0.1 localhost
19
+ const networkType = getNetworkType(); // && networksetup -setproxybypassdomains ${networkType} localhost localhost
20
20
 
21
21
  execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
22
22
  execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
@@ -39,14 +39,14 @@ export default class WhistleProxy {
39
39
  execSync(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
40
40
  execSync(`${this.bin} use ${this.rule} --force`);
41
41
  await this.installRootCA();
42
- enableGlobalProxy('127.0.0.1', this.port);
42
+ enableGlobalProxy('localhost', this.port);
43
43
  logger.info(`Proxy Server start on localhost:${this.port}\n`);
44
44
  }
45
45
 
46
46
  close() {
47
47
  execSync(`${this.bin} stop`);
48
48
  disableGlobalProxy();
49
- logger.info(`Proxy Server has closed`);
49
+ logger.info(`Proxy Server has been closed`);
50
50
  }
51
51
 
52
52
  }
@@ -15,6 +15,8 @@ var _whistleProxy = _interopRequireDefault(require("./utils/whistleProxy"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
+ let proxyServer;
19
+
18
20
  var _default = (0, _core.createPlugin)(() => ({
19
21
  validateSchema() {
20
22
  return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-proxy'];
@@ -35,15 +37,18 @@ var _default = (0, _core.createPlugin)(() => ({
35
37
  }
36
38
 
37
39
  const rule = (0, _createProxyRule.createProxyRule)(internalDirectory, dev.proxy);
38
- const proxyServer = new _whistleProxy.default({
40
+ proxyServer = new _whistleProxy.default({
39
41
  port: 8899,
40
42
  rule
41
43
  });
42
- await proxyServer.start(); // TODO
43
- // should exit proxy server before process exit
44
- // api.on('process-exit', () => {
45
- // proxyServer.close();
46
- // });
44
+ await proxyServer.start();
45
+ },
46
+
47
+ beforeExit() {
48
+ var _proxyServer;
49
+
50
+ // terminate whistle proxy
51
+ (_proxyServer = proxyServer) === null || _proxyServer === void 0 ? void 0 : _proxyServer.close();
47
52
  }
48
53
 
49
54
  }), {
@@ -62,7 +62,7 @@ const generateRootCA = () => new Promise((resolve, reject) => {
62
62
 
63
63
  const stream = _utils.fs.createWriteStream(defaultRootCA);
64
64
 
65
- _http.default.get('http://127.0.0.1:8899/cgi-bin/rootca', response => {
65
+ _http.default.get('http://localhost:8899/cgi-bin/rootca', response => {
66
66
  response.pipe(stream);
67
67
  stream.on('finish', () => {
68
68
  resolve(defaultRootCA);
@@ -26,7 +26,7 @@ const getNetworkType = () => {
26
26
  };
27
27
 
28
28
  const enableGlobalProxy = (ip, port) => {
29
- const networkType = getNetworkType(); // && networksetup -setproxybypassdomains ${networkType} 127.0.0.1 localhost
29
+ const networkType = getNetworkType(); // && networksetup -setproxybypassdomains ${networkType} localhost localhost
30
30
 
31
31
  (0, _execSync.default)(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
32
32
  (0, _execSync.default)(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
@@ -52,7 +52,7 @@ class WhistleProxy {
52
52
  (0, _execSync.default)(`${this.bin} start --certDir=${this.certDir} --port=${this.port}`);
53
53
  (0, _execSync.default)(`${this.bin} use ${this.rule} --force`);
54
54
  await this.installRootCA();
55
- enableGlobalProxy('127.0.0.1', this.port);
55
+ enableGlobalProxy('localhost', this.port);
56
56
 
57
57
  _utils.logger.info(`Proxy Server start on localhost:${this.port}\n`);
58
58
  }
@@ -61,7 +61,7 @@ class WhistleProxy {
61
61
  (0, _execSync.default)(`${this.bin} stop`);
62
62
  disableGlobalProxy();
63
63
 
64
- _utils.logger.info(`Proxy Server has closed`);
64
+ _utils.logger.info(`Proxy Server has been closed`);
65
65
  }
66
66
 
67
67
  }
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/modern.config.js CHANGED
@@ -1,10 +1,2 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {
3
- testing: {
4
- jest: {
5
- collectCoverage: true,
6
- collectCoverageFrom: ['src/**/*.ts'],
7
- coveragePathIgnorePatterns: ['/node_modules/'],
8
- },
9
- },
10
- };
2
+ module.exports = {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.2-rc.0",
14
+ "version": "1.2.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -20,31 +20,33 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "node": {
23
+ "jsnext:source": "./src/index.ts",
23
24
  "import": "./dist/js/modern/index.js",
24
25
  "require": "./dist/js/node/index.js"
25
26
  },
26
27
  "default": "./dist/js/treeshaking/index.js"
27
28
  },
28
- "./cli": "./dist/js/node/index.js"
29
- },
30
- "bin": {
31
- "modern": "./bin/modern.js"
29
+ "./cli": {
30
+ "jsnext:source": "./src/index.ts",
31
+ "default": "./dist/js/node/index.js"
32
+ }
32
33
  },
33
34
  "dependencies": {
34
35
  "@babel/runtime": "^7",
35
- "@modern-js/utils": "^1.1.4-rc.0",
36
+ "@modern-js/utils": "^1.2.0",
36
37
  "whistle": "^2.7.18"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@types/jest": "^26",
40
41
  "@types/node": "^14",
41
42
  "typescript": "^4",
42
- "@modern-js/core": "^1.1.4-rc.0",
43
- "@modern-js/plugin-testing": "^1.1.1",
44
- "@modern-js/module-tools": "^1.1.1"
43
+ "@modern-js/core": "^1.3.0",
44
+ "@scripts/build": "0.0.0",
45
+ "jest": "^27",
46
+ "@scripts/jest-config": "0.0.0"
45
47
  },
46
48
  "peerDependencies": {
47
- "@modern-js/core": "^1.1.4-rc.0"
49
+ "@modern-js/core": "^1.3.0"
48
50
  },
49
51
  "sideEffects": false,
50
52
  "modernConfig": {
@@ -54,12 +56,13 @@
54
56
  },
55
57
  "publishConfig": {
56
58
  "registry": "https://registry.npmjs.org/",
57
- "access": "public"
59
+ "access": "public",
60
+ "types": "./dist/types/index.d.ts"
58
61
  },
59
62
  "scripts": {
60
63
  "new": "modern new",
61
64
  "build": "modern build",
62
- "test": "modern test --passWithNoTests"
65
+ "test": "jest --passWithNoTests"
63
66
  },
64
67
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
65
68
  }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import { PLUGIN_SCHEMAS } from '@modern-js/utils';
7
7
  import { createProxyRule } from './utils/createProxyRule';
8
8
  import WhistleProxy from './utils/whistleProxy';
9
9
 
10
+ let proxyServer: WhistleProxy;
10
11
  export default createPlugin(
11
12
  () => ({
12
13
  validateSchema() {
@@ -23,14 +24,12 @@ export default createPlugin(
23
24
  }
24
25
 
25
26
  const rule = createProxyRule(internalDirectory, (dev as any).proxy);
26
- const proxyServer = new WhistleProxy({ port: 8899, rule });
27
+ proxyServer = new WhistleProxy({ port: 8899, rule });
27
28
  await proxyServer.start();
28
-
29
- // TODO
30
- // should exit proxy server before process exit
31
- // api.on('process-exit', () => {
32
- // proxyServer.close();
33
- // });
29
+ },
30
+ beforeExit() {
31
+ // terminate whistle proxy
32
+ proxyServer?.close();
34
33
  },
35
34
  }),
36
35
  { name: '@modern-js/plugin-proxy' },
@@ -41,7 +41,7 @@ export const generateRootCA = () =>
41
41
  const stream = fs.createWriteStream(defaultRootCA);
42
42
 
43
43
  http
44
- .get('http://127.0.0.1:8899/cgi-bin/rootca', response => {
44
+ .get('http://localhost:8899/cgi-bin/rootca', response => {
45
45
  response.pipe(stream);
46
46
  stream
47
47
  .on('finish', () => {
@@ -19,7 +19,7 @@ const getNetworkType = () => {
19
19
  export const enableGlobalProxy = (ip: string, port: string) => {
20
20
  const networkType = getNetworkType();
21
21
 
22
- // && networksetup -setproxybypassdomains ${networkType} 127.0.0.1 localhost
22
+ // && networksetup -setproxybypassdomains ${networkType} localhost localhost
23
23
  execSync(`networksetup -setwebproxy ${networkType} ${ip} ${port}`);
24
24
  execSync(`networksetup -setsecurewebproxy ${networkType} ${ip} ${port}`);
25
25
  };
@@ -55,13 +55,13 @@ export default class WhistleProxy {
55
55
  execSync(`${this.bin} use ${this.rule} --force`);
56
56
  await this.installRootCA();
57
57
 
58
- enableGlobalProxy('127.0.0.1', this.port);
58
+ enableGlobalProxy('localhost', this.port);
59
59
  logger.info(`Proxy Server start on localhost:${this.port}\n`);
60
60
  }
61
61
 
62
62
  close() {
63
63
  execSync(`${this.bin} stop`);
64
64
  disableGlobalProxy();
65
- logger.info(`Proxy Server has closed`);
65
+ logger.info(`Proxy Server has been closed`);
66
66
  }
67
67
  }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ extends: ['@modern-js'],
3
+ parserOptions: {
4
+ project: require.resolve('./tsconfig.json'),
5
+ },
6
+ };
@@ -0,0 +1,19 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`plugin proxy test config 1`] = `Array []`;
4
+
5
+ exports[`plugin proxy test schema 1`] = `
6
+ Array [
7
+ Array [
8
+ Object {
9
+ "schema": Object {
10
+ "typeof": Array [
11
+ "string",
12
+ "object",
13
+ ],
14
+ },
15
+ "target": "dev.proxy",
16
+ },
17
+ ],
18
+ ]
19
+ `;
@@ -0,0 +1,39 @@
1
+ import path from 'path';
2
+ import { manager } from '@modern-js/core';
3
+ import plugin from '../src';
4
+
5
+ const root = path.normalize(path.resolve(__dirname, '../../../../'));
6
+ expect.addSnapshotSerializer({
7
+ test: val =>
8
+ typeof val === 'string' &&
9
+ (val.includes('modern.js') ||
10
+ val.includes('node_modules') ||
11
+ val.includes(root)),
12
+ print: val =>
13
+ // eslint-disable-next-line no-nested-ternary
14
+ typeof val === 'string'
15
+ ? // eslint-disable-next-line no-nested-ternary
16
+ val.includes('node_modules')
17
+ ? `"${val.replace(/.+node_modules/, '')}"`
18
+ : val.includes('modern.js')
19
+ ? `"${val.replace(/.+modern\.js/, '')}"`
20
+ : `"${val.replace(root, '')}"`
21
+ : (val as string),
22
+ });
23
+
24
+ describe('plugin proxy test', () => {
25
+ it('schema', async () => {
26
+ const main = manager.clone().usePlugin(plugin);
27
+ const runner = await main.init();
28
+ const result = await runner.validateSchema();
29
+
30
+ expect(result).toMatchSnapshot();
31
+ });
32
+
33
+ it('config', async () => {
34
+ const main = manager.clone().usePlugin(plugin);
35
+ const runner = await main.init();
36
+ const result = await runner.config();
37
+ expect(result).toMatchSnapshot();
38
+ });
39
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "@modern-js/tsconfig/base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "jsx": "preserve",
6
+ "baseUrl": ".",
7
+ "noEmit": true,
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "isolatedModules": true,
11
+ "paths": {},
12
+ "types": ["node", "jest"]
13
+ }
14
+ }
package/tsconfig.json CHANGED
@@ -5,9 +5,7 @@
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
- "paths": {
9
- "@/*": ["./src/*"]
10
- }
8
+ "paths": {}
11
9
  },
12
10
  "include": ["src"]
13
11
  }