webpack-dev-service 0.8.0 → 0.9.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.
Files changed (91) hide show
  1. package/README.md +26 -36
  2. package/client/cjs/client.cjs +14 -15
  3. package/client/cjs/events.cjs +2 -2
  4. package/client/cjs/hot.cjs +1 -1
  5. package/client/cjs/index.cjs +1 -1
  6. package/client/cjs/main.cjs +22 -41
  7. package/client/cjs/ui/overlay.cjs +7 -7
  8. package/client/cjs/ui/progress.cjs +1 -1
  9. package/client/cjs/ui/utils.cjs +1 -1
  10. package/client/esm/client.js +14 -15
  11. package/client/esm/events.js +2 -2
  12. package/client/esm/hot.js +1 -1
  13. package/client/esm/index.js +1 -1
  14. package/client/esm/main.js +22 -41
  15. package/client/esm/ui/overlay.js +7 -7
  16. package/client/esm/ui/progress.js +1 -1
  17. package/client/esm/ui/utils.js +1 -1
  18. package/package.json +12 -8
  19. package/server/cjs/{dev/utils/compose.cjs → compose.cjs} +8 -10
  20. package/server/cjs/dev/Service.cjs +269 -0
  21. package/server/cjs/dev/index.cjs +9 -11
  22. package/server/cjs/dev/middleware.cjs +54 -28
  23. package/server/cjs/dev/utils/fs.cjs +29 -0
  24. package/server/cjs/dev/utils/{boundary.cjs → hash.cjs} +14 -10
  25. package/server/cjs/dev/utils/http.cjs +168 -10
  26. package/server/cjs/dev/utils/path.cjs +46 -0
  27. package/server/cjs/dev/utils/paths.cjs +59 -0
  28. package/server/cjs/dev/utils/ready.cjs +6 -9
  29. package/server/cjs/dev/utils/setupHooks.cjs +51 -40
  30. package/server/cjs/dev/utils/setupOutputFileSystem.cjs +6 -39
  31. package/server/cjs/dev/utils/setupWatching.cjs +3 -3
  32. package/server/cjs/dev/utils/setupWriteToDisk.cjs +23 -31
  33. package/server/cjs/hot/Socket.cjs +88 -111
  34. package/server/cjs/hot/index.cjs +13 -15
  35. package/server/cjs/hot/utils.cjs +100 -0
  36. package/server/cjs/index.cjs +17 -7
  37. package/server/cjs/schema.cjs +127 -0
  38. package/server/cjs/utils.cjs +45 -0
  39. package/server/esm/{dev/utils/compose.js → compose.js} +8 -10
  40. package/server/esm/dev/Service.js +260 -0
  41. package/server/esm/dev/index.js +8 -10
  42. package/server/esm/dev/middleware.js +53 -27
  43. package/server/esm/dev/utils/fs.js +27 -0
  44. package/server/esm/dev/utils/{boundary.js → hash.js} +14 -10
  45. package/server/esm/dev/utils/http.js +159 -8
  46. package/server/esm/dev/utils/path.js +42 -0
  47. package/server/esm/dev/utils/paths.js +57 -0
  48. package/server/esm/dev/utils/ready.js +6 -9
  49. package/server/esm/dev/utils/setupHooks.js +46 -35
  50. package/server/esm/dev/utils/setupOutputFileSystem.js +5 -38
  51. package/server/esm/dev/utils/setupWatching.js +2 -2
  52. package/server/esm/dev/utils/setupWriteToDisk.js +22 -30
  53. package/server/esm/hot/Socket.js +87 -110
  54. package/server/esm/hot/index.js +13 -15
  55. package/server/esm/hot/utils.js +93 -0
  56. package/server/esm/index.js +17 -7
  57. package/server/esm/schema.js +125 -0
  58. package/server/esm/utils.js +37 -0
  59. package/types/client/client.d.ts +1 -1
  60. package/types/client/events.d.ts +6 -6
  61. package/types/client/message.d.ts +6 -5
  62. package/types/client/ui/overlay.d.ts +1 -1
  63. package/types/server/dev/Service.d.ts +82 -0
  64. package/types/server/dev/index.d.ts +4 -4
  65. package/types/server/dev/interface.d.ts +26 -34
  66. package/types/server/dev/utils/fs.d.ts +27 -0
  67. package/types/server/dev/utils/hash.d.ts +9 -0
  68. package/types/server/dev/utils/http.d.ts +31 -14
  69. package/types/server/dev/utils/path.d.ts +22 -0
  70. package/types/server/dev/utils/paths.d.ts +7 -0
  71. package/types/server/dev/utils/ready.d.ts +2 -2
  72. package/types/server/hot/Socket.d.ts +6 -10
  73. package/types/server/hot/index.d.ts +4 -9
  74. package/types/server/hot/interface.d.ts +20 -0
  75. package/types/server/hot/utils.d.ts +13 -0
  76. package/types/server/index.d.ts +8 -8
  77. package/types/server/interface.d.ts +9 -0
  78. package/types/server/schema.d.ts +7 -0
  79. package/types/server/utils.d.ts +12 -0
  80. package/global.d.ts +0 -16
  81. package/server/cjs/dev/Files.cjs +0 -394
  82. package/server/cjs/dev/utils/common.cjs +0 -98
  83. package/server/cjs/dev/utils/getPaths.cjs +0 -65
  84. package/server/esm/dev/Files.js +0 -384
  85. package/server/esm/dev/utils/common.js +0 -98
  86. package/server/esm/dev/utils/getPaths.js +0 -63
  87. package/types/server/dev/Files.d.ts +0 -83
  88. package/types/server/dev/utils/boundary.d.ts +0 -8
  89. package/types/server/dev/utils/common.d.ts +0 -44
  90. package/types/server/dev/utils/getPaths.d.ts +0 -10
  91. /package/types/server/{dev/utils/compose.d.ts → compose.d.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.0
4
+ * @version 0.9.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -9,143 +9,120 @@
9
9
 
10
10
  import WebSocket, { WebSocketServer } from 'ws';
11
11
  import webpack from 'webpack';
12
+ import { PLUGIN_NAME, getCompilers } from '../utils.js';
13
+ import { getOptions, getStatsOptions, getTimestamp, isUpgradable, hasIssues, WEBSOCKET_RE } from './utils.js';
12
14
 
13
15
  /**
14
16
  * @module Socket
15
17
  */
16
- const WEBSOCKET_RE = /^websocket$/i;
17
- const { toString } = Object.prototype;
18
- function isObject(value) {
19
- return toString.call(value) === '[object Object]';
20
- }
21
- function resolveStatsOptions(compiler) {
22
- const options = {
23
- all: false,
24
- hash: true,
25
- colors: true,
26
- errors: true,
27
- assets: false,
28
- builtAt: true,
29
- warnings: true,
30
- errorDetails: false
31
- };
32
- const { stats } = compiler.options;
33
- if (isObject(stats)) {
34
- const { warningsFilter } = stats;
35
- if (warningsFilter !== undefined) {
36
- options.warningsFilter = warningsFilter;
37
- }
38
- }
39
- return options;
40
- }
41
- function normalize(path) {
42
- const segments = [];
43
- const parts = path.split(/[\\/]+/);
44
- for (const segment of parts) {
45
- switch (segment) {
46
- case '.':
47
- break;
48
- case '..':
49
- segments.pop();
50
- break;
51
- default:
52
- segments.push(segment);
53
- break;
54
- }
55
- }
56
- const pathname = segments.join('/');
57
- return pathname.startsWith('/') ? pathname : `/${pathname}`;
58
- }
59
- function resolveOptions(options) {
60
- const settings = {
61
- hmr: true,
62
- path: '/hot',
63
- progress: true,
64
- ...options
65
- };
66
- settings.path = normalize(settings.path);
67
- return settings;
68
- }
69
- function isUpgradable(context, detector) {
70
- const { upgrade } = context.headers;
71
- return !!upgrade && detector.test(upgrade.trim());
72
- }
73
- function hasProblems(problems) {
74
- return !!problems && problems.length > 0;
75
- }
76
18
  class Socket {
77
19
  constructor(compiler, options) {
78
- this.name = 'webpack-hot-middleware';
20
+ this.stats = null;
79
21
  this.compiler = compiler;
80
- this.options = resolveOptions(options);
81
- this.logger = compiler.getInfrastructureLogger(this.name);
82
- this.server = new WebSocketServer({ path: this.options.path, noServer: true });
22
+ this.options = getOptions(options);
23
+ this.server = new WebSocketServer({
24
+ noServer: true,
25
+ path: this.options.path
26
+ });
27
+ this.logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
83
28
  this.setupWss();
84
29
  this.setupHooks();
85
30
  this.setupPlugins();
86
31
  }
87
32
  setupWss() {
88
33
  const { server, logger } = this;
89
- server.on('error', error => {
90
- logger.error(error.message);
91
- });
92
34
  server.on('connection', client => {
93
35
  if (this.stats) {
94
36
  this.broadcastStats([client], this.stats);
95
37
  }
38
+ logger.log('client connected');
39
+ });
40
+ server.on('error', error => {
41
+ logger.error(error);
42
+ });
43
+ server.on('close', function () {
44
+ logger.log('client disconnected');
96
45
  });
97
46
  }
98
47
  setupHooks() {
99
48
  const { compiler } = this;
100
49
  const { hooks } = compiler;
101
- const statsOptions = resolveStatsOptions(compiler);
102
- hooks.done.tapAsync(this.name, (stats, next) => {
103
- next();
104
- this.stats = stats.toJson(statsOptions);
105
- this.broadcastStats(this.clients(), this.stats);
50
+ const statsOptions = getStatsOptions(compiler);
51
+ hooks.done.tap(PLUGIN_NAME, stats => {
52
+ // Get json stats.
53
+ const jsonStats = stats.toJson(statsOptions);
54
+ // Hack builtAt.
55
+ if (jsonStats.builtAt == null) {
56
+ jsonStats.builtAt = getTimestamp(jsonStats);
57
+ }
58
+ // Cache stats.
59
+ this.stats = jsonStats;
60
+ // Do the stuff in nextTick, because bundle may be invalidated if a change happened while compiling.
61
+ process.nextTick(() => {
62
+ const { stats } = this;
63
+ // Broadcast stats.
64
+ if (stats) {
65
+ this.broadcastStats(this.clients(), stats);
66
+ }
67
+ });
106
68
  });
107
- hooks.invalid.tap(this.name, (path, builtAt) => {
108
- this.broadcast(this.clients(), 'invalid', { path, builtAt });
69
+ hooks.invalid.tap(PLUGIN_NAME, (path, timestamp) => {
70
+ // Set stats to null.
71
+ this.stats = null;
72
+ // Broadcast invalid.
73
+ this.broadcast(this.clients(), 'invalid', { path, timestamp });
109
74
  });
110
75
  }
111
76
  setupPlugins() {
112
77
  const { options, compiler } = this;
78
+ const compilers = getCompilers(compiler);
113
79
  const plugins = [
114
- new webpack.NoEmitOnErrorsPlugin(),
115
- new webpack.DefinePlugin({
116
- __WDS_HOT_OPTIONS__: JSON.stringify({
117
- ...options,
118
- name: compiler.name
119
- })
120
- })
80
+ () => {
81
+ return new webpack.NoEmitOnErrorsPlugin();
82
+ },
83
+ () => {
84
+ return new webpack.HotModuleReplacementPlugin();
85
+ },
86
+ ({ name, context }) => {
87
+ const params = new URLSearchParams();
88
+ params.set('path', options.path);
89
+ params.set('name', name || 'webpack');
90
+ params.set('hmr', options.hmr ? 'true' : 'false');
91
+ params.set('wss', options.wss ? 'true' : 'false');
92
+ params.set('reload', options.reload ? 'true' : 'false');
93
+ params.set('overlay', options.overlay ? 'true' : 'false');
94
+ params.set('progress', options.progress ? 'true' : 'false');
95
+ // Auto add hot client to entry.
96
+ return new webpack.EntryPlugin(context, `webpack-dev-service/client?${params}`, {
97
+ // Don't create runtime.
98
+ runtime: false
99
+ });
100
+ }
121
101
  ];
122
- if (options.hmr) {
123
- plugins.push(new webpack.HotModuleReplacementPlugin());
102
+ for (const compiler of compilers) {
103
+ for (const plugin of plugins) {
104
+ plugin(compiler).apply(compiler);
105
+ }
124
106
  }
125
107
  if (options.progress) {
126
108
  let value = 0;
127
- plugins.push(
128
- new webpack.ProgressPlugin((percentage, status, message) => {
129
- const nextValue = Math.floor(percentage * 100);
130
- if (nextValue > value || nextValue === 0) {
131
- value = nextValue;
132
- switch (value) {
133
- case 0:
134
- status = 'start';
135
- message = 'end idle';
136
- break;
137
- case 100:
138
- status = 'finish';
139
- message = 'begin idle';
140
- break;
141
- }
142
- this.broadcast(this.clients(), 'progress', { status, message, value });
109
+ new webpack.ProgressPlugin((percentage, status, message) => {
110
+ const nextValue = Math.floor(percentage * 100);
111
+ if (nextValue > value || nextValue === 0) {
112
+ value = nextValue;
113
+ switch (value) {
114
+ case 0:
115
+ status = 'start';
116
+ message = 'end idle';
117
+ break;
118
+ case 100:
119
+ status = 'finish';
120
+ message = 'begin idle';
121
+ break;
143
122
  }
144
- })
145
- );
146
- }
147
- for (const plugin of plugins) {
148
- plugin.apply(compiler);
123
+ this.broadcast(this.clients(), 'progress', { status, message, value });
124
+ }
125
+ }).apply(compiler);
149
126
  }
150
127
  }
151
128
  clients() {
@@ -174,12 +151,12 @@ class Socket {
174
151
  }
175
152
  broadcastStats(clients, stats) {
176
153
  if (clients.size > 0 || clients.length > 0) {
177
- const { hash, builtAt, errors, warnings } = stats;
178
- this.broadcast(clients, 'hash', { hash });
179
- if (hasProblems(errors) || hasProblems(warnings)) {
180
- this.broadcast(clients, 'problems', { errors, warnings, builtAt });
154
+ const { hash, errors, warnings, builtAt: timestamp } = stats;
155
+ this.broadcast(clients, 'hash', { hash, timestamp });
156
+ if (hasIssues(errors) || hasIssues(warnings)) {
157
+ this.broadcast(clients, 'issues', { errors, warnings, timestamp });
181
158
  } else {
182
- this.broadcast(clients, 'ok', { builtAt });
159
+ this.broadcast(clients, 'ok', { timestamp });
183
160
  }
184
161
  }
185
162
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.0
4
+ * @version 0.9.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -12,23 +12,21 @@ import { Socket } from './Socket.js';
12
12
  /**
13
13
  * @module index
14
14
  */
15
- function hot(compiler, options = {}) {
15
+ function hot(compiler, options) {
16
16
  const socket = new Socket(compiler, options);
17
- return Object.assign(
18
- async (ctx, next) => {
19
- if (!socket.upgrade(ctx)) {
20
- await next();
21
- }
17
+ const middleware = async (ctx, next) => {
18
+ if (!socket.upgrade(ctx)) {
19
+ await next();
20
+ }
21
+ };
22
+ return Object.assign(middleware, {
23
+ clients() {
24
+ return socket.clients();
22
25
  },
23
- {
24
- clients() {
25
- return socket.clients();
26
- },
27
- broadcast(clients, action, payload) {
28
- socket.broadcast(clients, action, payload);
29
- }
26
+ broadcast(clients, action, payload) {
27
+ socket.broadcast(clients, action, payload);
30
28
  }
31
- );
29
+ });
32
30
  }
33
31
 
34
32
  export { hot };
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.9.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ import { isMultiCompilerMode, isObject } from '../utils.js';
11
+
12
+ /**
13
+ * @module utils
14
+ */
15
+ const WEBSOCKET_RE = /^websocket$/i;
16
+ function normalize(path) {
17
+ const segments = [];
18
+ const parts = path.split(/[\\/]+/);
19
+ for (const segment of parts) {
20
+ switch (segment) {
21
+ case '.':
22
+ break;
23
+ case '..':
24
+ segments.pop();
25
+ break;
26
+ default:
27
+ segments.push(segment);
28
+ break;
29
+ }
30
+ }
31
+ const pathname = segments.join('/');
32
+ return pathname.startsWith('/') ? pathname : `/${pathname}`;
33
+ }
34
+ function getOptions(options) {
35
+ const settings = {
36
+ hmr: true,
37
+ wss: false,
38
+ path: '/hot',
39
+ reload: true,
40
+ overlay: true,
41
+ progress: true,
42
+ ...options
43
+ };
44
+ settings.path = normalize(settings.path);
45
+ return settings;
46
+ }
47
+ function isUpgradable(context, detector) {
48
+ const { upgrade } = context.headers;
49
+ return !!upgrade && detector.test(upgrade.trim());
50
+ }
51
+ function hasIssues(issues) {
52
+ return Array.isArray(issues) && issues.length > 0;
53
+ }
54
+ function normalizeStatsOptions(statsOptions) {
55
+ if (!isObject(statsOptions)) {
56
+ statsOptions = {};
57
+ }
58
+ return {
59
+ ...statsOptions,
60
+ all: false,
61
+ hash: true,
62
+ colors: true,
63
+ errors: true,
64
+ assets: false,
65
+ builtAt: true,
66
+ warnings: true,
67
+ errorDetails: false
68
+ };
69
+ }
70
+ function getStatsOptions(compiler) {
71
+ if (isMultiCompilerMode(compiler)) {
72
+ return {
73
+ children: compiler.compilers.map(({ options }) => {
74
+ return normalizeStatsOptions(options.stats);
75
+ })
76
+ };
77
+ }
78
+ return normalizeStatsOptions(compiler.options.stats);
79
+ }
80
+ function getTimestamp({ builtAt, children = [] }) {
81
+ if (builtAt != null) {
82
+ return builtAt;
83
+ }
84
+ let timestamp = -1;
85
+ for (const { builtAt = timestamp } of children) {
86
+ if (builtAt > timestamp) {
87
+ timestamp = builtAt;
88
+ }
89
+ }
90
+ return timestamp < 0 ? Date.now() : timestamp;
91
+ }
92
+
93
+ export { WEBSOCKET_RE, getOptions, getStatsOptions, getTimestamp, hasIssues, isUpgradable };
@@ -1,25 +1,35 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.0
4
+ * @version 0.9.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
8
8
  */
9
9
 
10
- import { compose } from './dev/utils/compose.js';
11
- import { dev } from './dev/index.js';
10
+ import { schema } from './schema.js';
11
+ import { compose } from './compose.js';
12
+ import { PLUGIN_NAME } from './utils.js';
13
+ import { validate } from 'schema-utils';
12
14
  import { hot } from './hot/index.js';
15
+ import { dev } from './dev/index.js';
13
16
 
14
17
  /**
15
18
  * @module index
16
19
  */
17
20
  function server(compiler, options = {}) {
18
- const devMiddleware = dev(compiler, options);
19
- if (options.hot === false) {
20
- return devMiddleware;
21
+ validate(schema, options, {
22
+ name: PLUGIN_NAME,
23
+ baseDataPath: 'options'
24
+ });
25
+ const { hot: hotOptions } = options;
26
+ if (hotOptions === false) {
27
+ return dev(compiler, options);
21
28
  }
22
- const hotMiddleware = hot(compiler, options.hot);
29
+ // All plugins must be initialized before watching.
30
+ // Because dev will start watching, so call hot before dev.
31
+ const hotMiddleware = hot(compiler, hotOptions);
32
+ const devMiddleware = dev(compiler, options);
23
33
  const middleware = compose(devMiddleware, hotMiddleware);
24
34
  return Object.assign(middleware, devMiddleware, hotMiddleware);
25
35
  }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.9.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ /**
11
+ * @module schema
12
+ */
13
+ const schema = {
14
+ type: 'object',
15
+ properties: {
16
+ hot: {
17
+ description: 'Enable or disable HMR server.',
18
+ anyOf: [
19
+ {
20
+ type: 'boolean',
21
+ enum: [false]
22
+ },
23
+ {
24
+ type: 'object',
25
+ properties: {
26
+ hmr: {
27
+ type: 'boolean',
28
+ description: 'Enable or disable Hot Module Replacement.'
29
+ },
30
+ path: {
31
+ type: 'string',
32
+ description: 'Specify the path used by the HMR server.'
33
+ },
34
+ wss: {
35
+ type: 'boolean',
36
+ description: 'Use WebSockets Secure (wss://) for HMR instead of the default WebSocket (ws://).'
37
+ },
38
+ reload: {
39
+ type: 'boolean',
40
+ description: 'Control whether the full page should be reloaded when HMR failure.'
41
+ },
42
+ overlay: {
43
+ type: 'boolean',
44
+ description: 'Enable or disable an error overlay in the browser when there are compilation errors.'
45
+ },
46
+ progress: {
47
+ type: 'boolean',
48
+ description: 'Display a progress bar in the browser during the build process.'
49
+ }
50
+ },
51
+ additionalProperties: false
52
+ }
53
+ ]
54
+ },
55
+ ignore: {
56
+ instanceof: 'Function',
57
+ description: 'Function that determines if a file should be ignored.'
58
+ },
59
+ etag: {
60
+ type: 'boolean',
61
+ description: 'Enable or disable the ETag functionality for file serving.'
62
+ },
63
+ acceptRanges: {
64
+ type: 'boolean',
65
+ description: 'Indicate whether the server supports range requests for file resources.'
66
+ },
67
+ lastModified: {
68
+ type: 'boolean',
69
+ description: 'Enable or disable sending last modified headers for file resources.'
70
+ },
71
+ headers: {
72
+ description: 'Headers to serve with files.',
73
+ anyOf: [
74
+ {
75
+ type: 'object',
76
+ additionalProperties: {
77
+ anyOf: [
78
+ {
79
+ type: 'string'
80
+ },
81
+ {
82
+ type: 'array',
83
+ items: {
84
+ type: 'string'
85
+ }
86
+ }
87
+ ]
88
+ },
89
+ description: 'Headers object to serve with files.'
90
+ },
91
+ {
92
+ instanceof: 'Function',
93
+ description: 'Function that returns headers to serve with files.'
94
+ }
95
+ ]
96
+ },
97
+ fs: {
98
+ type: 'object',
99
+ description: 'The output file system used by the dev server.'
100
+ },
101
+ stats: {
102
+ type: 'object',
103
+ description: 'Options for the statistics output.'
104
+ },
105
+ writeToDisk: {
106
+ anyOf: [
107
+ {
108
+ type: 'boolean',
109
+ description: 'Enable or disable writing files to disk.'
110
+ },
111
+ {
112
+ instanceof: 'Function',
113
+ description: 'Function that determines if a file should be written to disk based on its target path.'
114
+ }
115
+ ]
116
+ },
117
+ onCompilerDone: {
118
+ instanceof: 'Function',
119
+ description: 'Callback function when the compiler is done, providing statistics and options.'
120
+ }
121
+ },
122
+ additionalProperties: false
123
+ };
124
+
125
+ export { schema };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @package webpack-dev-service
3
+ * @license MIT
4
+ * @version 0.9.0
5
+ * @author nuintun <nuintun@qq.com>
6
+ * @description A koa 2 middleware for webpack development and hot reloading.
7
+ * @see https://github.com/nuintun/webpack-dev-service#readme
8
+ */
9
+
10
+ /**
11
+ * @module utils
12
+ */
13
+ const { toString } = Object.prototype;
14
+ const PLUGIN_NAME = 'webpack-dev-service';
15
+ function isObject(value) {
16
+ return toString.call(value) === '[object Object]';
17
+ }
18
+ function isString(value) {
19
+ return toString.call(value) === '[object String]';
20
+ }
21
+ function isBoolean(value) {
22
+ return toString.call(value) === '[object Boolean]';
23
+ }
24
+ function isFunction(value) {
25
+ return typeof value === 'function';
26
+ }
27
+ function getCompilers(compiler) {
28
+ if (isMultiCompilerMode(compiler)) {
29
+ return compiler.compilers;
30
+ }
31
+ return [compiler];
32
+ }
33
+ function isMultiCompilerMode(compiler) {
34
+ return 'compilers' in compiler;
35
+ }
36
+
37
+ export { PLUGIN_NAME, getCompilers, isBoolean, isFunction, isMultiCompilerMode, isObject, isString };
@@ -5,8 +5,8 @@ export interface Options {
5
5
  readonly hmr: boolean;
6
6
  readonly name: string;
7
7
  readonly path: string;
8
- readonly live: boolean;
9
8
  readonly origin: string;
9
+ readonly reload: boolean;
10
10
  readonly overlay: boolean;
11
11
  readonly progress: boolean;
12
12
  }
@@ -6,16 +6,16 @@ import * as Message from './message';
6
6
  interface Messages {
7
7
  ok: Message.OK['payload'];
8
8
  hash: Message.Hash['payload'];
9
+ issues: Message.Issues['payload'];
9
10
  invalid: Message.Invalid['payload'];
10
- problems: Message.Problems['payload'];
11
11
  progress: Message.Progress['payload'];
12
12
  }
13
13
  interface Events {
14
- ok: (message: Messages['ok'], options: Options) => void;
15
- hash: (message: Messages['hash'], options: Options) => void;
16
- invalid: (message: Messages['invalid'], options: Options) => void;
17
- problems: (message: Messages['problems'], options: Options) => void;
18
- progress: (message: Messages['progress'], options: Options) => void;
14
+ ok(message: Messages['ok'], options: Options): void;
15
+ hash(message: Messages['hash'], options: Options): void;
16
+ issues(message: Messages['issues'], options: Options): void;
17
+ invalid(message: Messages['invalid'], options: Options): void;
18
+ progress(message: Messages['progress'], options: Options): void;
19
19
  }
20
20
  /**
21
21
  * @function on
@@ -6,7 +6,7 @@ export interface Invalid {
6
6
  action: 'invalid';
7
7
  payload: {
8
8
  path: string;
9
- builtAt: number;
9
+ timestamp: number;
10
10
  };
11
11
  }
12
12
  export interface Progress {
@@ -21,12 +21,13 @@ export interface Hash {
21
21
  action: 'hash';
22
22
  payload: {
23
23
  hash: string;
24
+ timestamp: number;
24
25
  };
25
26
  }
26
- export interface Problems {
27
- action: 'problems';
27
+ export interface Issues {
28
+ action: 'issues';
28
29
  payload: {
29
- builtAt: number;
30
+ timestamp: number;
30
31
  errors: StatsError[];
31
32
  warnings: StatsError[];
32
33
  };
@@ -34,6 +35,6 @@ export interface Problems {
34
35
  export interface OK {
35
36
  action: 'ok';
36
37
  payload: {
37
- builtAt: number;
38
+ timestamp: number;
38
39
  };
39
40
  }
@@ -13,7 +13,7 @@ export default class Overlay {
13
13
  private readonly warningsList;
14
14
  private readonly warningsTitle;
15
15
  constructor(name: string);
16
- setProblems(type: 'errors' | 'warnings', problems: StatsError[]): void;
16
+ setIssues(type: 'errors' | 'warnings', issues: StatsError[]): void;
17
17
  show(): void;
18
18
  hide(): void;
19
19
  }