@modern-js/server 1.4.16 → 1.4.17

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,18 @@
1
1
  # @modern-js/server
2
2
 
3
+ ## 1.4.17
4
+
5
+ ### Patch Changes
6
+
7
+ - d4afeba71: fix: remove cors for prod-server
8
+ - f8e713253: fix(server): using correct webpack instance
9
+ - Updated dependencies [6c8ab42dd]
10
+ - Updated dependencies [ed90859ba]
11
+ - Updated dependencies [0ef2431cb]
12
+ - Updated dependencies [d4afeba71]
13
+ - @modern-js/webpack@1.9.1
14
+ - @modern-js/prod-server@1.1.7
15
+
3
16
  ## 1.4.16
4
17
 
5
18
  ### Patch Changes
@@ -1,9 +1,9 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
- import Webpack from 'webpack';
3
+ import { webpack } from '@modern-js/webpack';
4
4
  const {
5
5
  EntryPlugin
6
- } = Webpack;
6
+ } = webpack;
7
7
  export default class DevServerPlugin {
8
8
  constructor(options) {
9
9
  _defineProperty(this, "options", void 0);
@@ -31,9 +31,9 @@ export default class DevServerPlugin {
31
31
  const compilerOptions = compiler.options;
32
32
  compilerOptions.plugins = compilerOptions.plugins || [];
33
33
 
34
- if (!compilerOptions.plugins.find(p => p.constructor === Webpack.HotModuleReplacementPlugin)) {
34
+ if (!compilerOptions.plugins.find(p => p.constructor === webpack.HotModuleReplacementPlugin)) {
35
35
  // apply the HMR plugin, if it didn't exist before.
36
- const plugin = new Webpack.HotModuleReplacementPlugin();
36
+ const plugin = new webpack.HotModuleReplacementPlugin();
37
37
  plugin.apply(compiler);
38
38
  }
39
39
  }
@@ -69,6 +69,15 @@ export class ModernDevServer extends ModernServer {
69
69
  } = ctx;
70
70
  return handler(req, res, next);
71
71
  });
72
+ });
73
+ this.addHandler((ctx, next) => {
74
+ // allow hmr request cross-domain, because the user may use global proxy
75
+ if (ctx.path.includes('hot-update')) {
76
+ ctx.res.setHeader('Access-Control-Allow-Origin', '*');
77
+ ctx.res.setHeader('Access-Control-Allow-Credentials', 'false');
78
+ }
79
+
80
+ next();
72
81
  }); // mock handler
73
82
 
74
83
  this.mockHandler = createMockHandler({
@@ -5,15 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _webpack = _interopRequireDefault(require("webpack"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ var _webpack = require("@modern-js/webpack");
11
9
 
12
10
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
11
 
14
12
  const {
15
13
  EntryPlugin
16
- } = _webpack.default;
14
+ } = _webpack.webpack;
17
15
 
18
16
  class DevServerPlugin {
19
17
  constructor(options) {
@@ -42,9 +40,9 @@ class DevServerPlugin {
42
40
  const compilerOptions = compiler.options;
43
41
  compilerOptions.plugins = compilerOptions.plugins || [];
44
42
 
45
- if (!compilerOptions.plugins.find(p => p.constructor === _webpack.default.HotModuleReplacementPlugin)) {
43
+ if (!compilerOptions.plugins.find(p => p.constructor === _webpack.webpack.HotModuleReplacementPlugin)) {
46
44
  // apply the HMR plugin, if it didn't exist before.
47
- const plugin = new _webpack.default.HotModuleReplacementPlugin();
45
+ const plugin = new _webpack.webpack.HotModuleReplacementPlugin();
48
46
  plugin.apply(compiler);
49
47
  }
50
48
  }
@@ -90,6 +90,15 @@ class ModernDevServer extends _prodServer.ModernServer {
90
90
  } = ctx;
91
91
  return handler(req, res, next);
92
92
  });
93
+ });
94
+ this.addHandler((ctx, next) => {
95
+ // allow hmr request cross-domain, because the user may use global proxy
96
+ if (ctx.path.includes('hot-update')) {
97
+ ctx.res.setHeader('Access-Control-Allow-Origin', '*');
98
+ ctx.res.setHeader('Access-Control-Allow-Credentials', 'false');
99
+ }
100
+
101
+ next();
93
102
  }); // mock handler
94
103
 
95
104
  this.mockHandler = (0, _mock.createMockHandler)({
@@ -1,7 +1,7 @@
1
- import Webpack from 'webpack';
1
+ import { webpack } from '@modern-js/webpack';
2
2
  import { DevServerOptions } from '../types';
3
3
  export default class DevServerPlugin {
4
4
  private readonly options;
5
5
  constructor(options: DevServerOptions);
6
- apply(compiler: Webpack.Compiler): void;
6
+ apply(compiler: webpack.Compiler): void;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Server } from 'http';
3
3
  import ws from 'ws';
4
- import type { Stats } from 'webpack';
4
+ import type { webpack } from '@modern-js/webpack';
5
5
  import { DevServerOptions } from '../types';
6
6
  export default class SocketServer {
7
7
  private wsServer;
@@ -12,7 +12,7 @@ export default class SocketServer {
12
12
  private timer;
13
13
  constructor(options: DevServerOptions);
14
14
  prepare(app: Server): void;
15
- updateStats(stats: Stats): void;
15
+ updateStats(stats: webpack.Stats): void;
16
16
  sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
17
17
  singleWrite(socket: ws, type: string, data?: Record<string, any> | string | boolean): void;
18
18
  close(): void;
@@ -1,5 +1,5 @@
1
1
  import { ModernServerOptions } from '@modern-js/prod-server';
2
- import type Webpack from 'webpack';
2
+ import type { webpack } from '@modern-js/webpack';
3
3
  export declare type DevServerOptions = {
4
4
  client: {
5
5
  path?: string;
@@ -23,6 +23,6 @@ export declare type DevServerOptions = {
23
23
  };
24
24
  export declare type ExtraOptions = {
25
25
  dev?: boolean | Partial<DevServerOptions>;
26
- compiler?: Webpack.MultiCompiler | Webpack.Compiler | null;
26
+ compiler?: webpack.MultiCompiler | webpack.Compiler | null;
27
27
  };
28
28
  export declare type ModernDevServerOptions = ModernServerOptions & ExtraOptions;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.16",
14
+ "version": "1.4.17",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -32,9 +32,9 @@
32
32
  "@babel/register": "^7.15.3",
33
33
  "@modern-js/bff-utils": "^1.2.8",
34
34
  "@modern-js/hmr-client": "^1.2.7",
35
- "@modern-js/prod-server": "^1.1.6",
35
+ "@modern-js/prod-server": "^1.1.7",
36
36
  "@modern-js/server-utils": "^1.2.9",
37
- "@modern-js/webpack": "^1.9.0",
37
+ "@modern-js/webpack": "^1.9.1",
38
38
  "@modern-js/utils": "^1.7.6",
39
39
  "devcert": "1.2.0",
40
40
  "minimatch": "^3.0.4",
@@ -53,7 +53,6 @@
53
53
  "@types/ws": "^7.4.7",
54
54
  "jest": "^27",
55
55
  "typescript": "^4",
56
- "webpack": "^5.71.0",
57
56
  "websocket": "^1"
58
57
  },
59
58
  "sideEffects": false,