Skip to content

Commit 58ca88f

Browse files
refactor: client
1 parent 5863640 commit 58ca88f

36 files changed

+192
-158
lines changed

babel.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ module.exports = (api) => {
44
api.cache(true);
55

66
return {
7-
presets: ['@babel/preset-env'],
7+
presets: [
8+
[
9+
'@babel/preset-env',
10+
{
11+
targets: {
12+
node: '0.12',
13+
},
14+
},
15+
],
16+
],
817
env: {
918
test: {
1019
plugins: ['@babel/plugin-transform-runtime'],

client-src/clients/SockJSClient.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict';
22

33
const SockJS = require('sockjs-client/dist/sockjs');
4-
const { log } = require('../default/utils/log');
4+
const { log } = require('../modules/logger');
55
const BaseClient = require('./BaseClient');
66

77
module.exports = class SockJSClient extends BaseClient {
88
constructor(url) {
99
super();
10+
1011
const sockUrl = url.replace(/^(?:chrome-extension|file)/i, 'http');
11-
this.sock = new SockJS(sockUrl);
1212

13+
this.sock = new SockJS(sockUrl);
1314
this.sock.onerror = (err) => {
1415
log.error(err);
1516
};

client-src/clients/WebsocketClient.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

3-
/* global WebSocket */
4-
5-
const { log } = require('../default/utils/log');
3+
const { log } = require('../modules/logger');
64
const BaseClient = require('./BaseClient');
75

86
module.exports = class WebsocketClient extends BaseClient {

client-src/default/webpack.config.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

client-src/default/index.js renamed to client-src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
/* global __resourceQuery WorkerGlobalScope self */
4-
const stripAnsi = require('../transpiled-modules/strip-ansi');
3+
/* global __resourceQuery WorkerGlobalScope */
4+
5+
const stripAnsi = require('./modules/strip-ansi');
56
const socket = require('./socket');
67
const overlay = require('./overlay');
78
const { log, setLogLevel } = require('./utils/log');

client-src/modules/logger/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
// eslint-disable-next-line import/no-extraneous-dependencies
4+
require('core-js/stable/symbol');
5+
6+
module.exports = require('webpack/lib/logging/runtime');
File renamed without changes.

client-src/default/socket.js renamed to client-src/socket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Client =
1111
typeof __webpack_dev_server_client__ !== 'undefined'
1212
? __webpack_dev_server_client__
1313
: // eslint-disable-next-line import/no-unresolved
14-
require('../clients/WebsocketClient');
14+
require('./clients/WebsocketClient');
1515

1616
let retries = 0;
1717
let client = null;
@@ -37,6 +37,7 @@ const socket = function initSocket(url, handlers) {
3737
// Respectfully copied from the package `got`.
3838
// eslint-disable-next-line no-mixed-operators, no-restricted-properties
3939
const retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
40+
4041
retries += 1;
4142

4243
setTimeout(() => {

client-src/sockjs/webpack.config.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

client-src/transpiled-modules/log.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

client-src/transpiled-modules/webpack.config.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

client-src/default/utils/createSocketUrl.js renamed to client-src/utils/createSocketUrl.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* global self */
4-
53
const url = require('url');
64
const getCurrentScriptSource = require('./getCurrentScriptSource');
75

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
'use strict';
22

3-
const log = require('../../transpiled-modules/log');
3+
const logger = require('../modules/logger');
44

55
const name = 'webpack-dev-server';
66
// default level is set on the client side, so it does not need
77
// to be set by the CLI or API
88
const defaultLevel = 'info';
99

1010
function setLogLevel(level) {
11-
log.configureDefaultLogger({
12-
level,
13-
});
11+
logger.configureDefaultLogger({ level });
1412
}
1513

1614
setLogLevel(defaultLevel);
1715

18-
module.exports = {
19-
log: log.getLogger(name),
20-
setLogLevel,
21-
};
16+
module.exports = { log: logger.getLogger(name), setLogLevel };

client-src/default/utils/reloadApp.js renamed to client-src/utils/reloadApp.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* global WorkerGlobalScope self */
4-
53
const { log } = require('./log');
64

75
function reloadApp(
@@ -11,10 +9,14 @@ function reloadApp(
119
if (isUnloading || !hotReload) {
1210
return;
1311
}
12+
1413
if (hot) {
1514
log.info('App hot update...');
15+
1616
const hotEmitter = require('webpack/hot/emitter');
17+
1718
hotEmitter.emit('webpackHotUpdate', currentHash);
19+
1820
if (typeof self !== 'undefined' && self.window) {
1921
// broadcast update to window
2022
self.postMessage(`webpackHotUpdate${currentHash}`, '*');
@@ -23,13 +25,15 @@ function reloadApp(
2325
// allow refreshing the page only if liveReload isn't disabled
2426
else if (liveReload) {
2527
let rootWindow = self;
28+
2629
// use parent window for reload (in case we're in an iframe with no valid src)
2730
const intervalId = self.setInterval(() => {
2831
if (rootWindow.location.protocol !== 'about:') {
2932
// reload immediately if protocol is valid
3033
applyReload(rootWindow, intervalId);
3134
} else {
3235
rootWindow = rootWindow.parent;
36+
3337
if (rootWindow.parent === rootWindow) {
3438
// if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
3539
applyReload(rootWindow, intervalId);

client-src/default/utils/sendMessage.js renamed to client-src/utils/sendMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
/* global __resourceQuery WorkerGlobalScope self */
3+
/* global __resourceQuery WorkerGlobalScope */
44

55
// Send messages to the outside, so plugins can consume it.
66
function sendMsg(type, data) {

client-src/webpack.config.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const webpack = require('webpack');
5+
const { merge } = require('webpack-merge');
6+
7+
const baseForModules = {
8+
devtool: false,
9+
mode: 'development',
10+
output: {
11+
path: path.resolve(__dirname, '../client/modules'),
12+
libraryTarget: 'commonjs2',
13+
},
14+
target: webpack.webpack ? ['web', 'es5'] : 'web',
15+
module: {
16+
rules: [
17+
{
18+
test: /\.js$/,
19+
use: [
20+
{
21+
loader: 'babel-loader',
22+
},
23+
],
24+
},
25+
],
26+
},
27+
};
28+
29+
module.exports = [
30+
merge(baseForModules, {
31+
entry: path.join(__dirname, 'modules/logger/index.js'),
32+
output: {
33+
filename: 'logger/index.js',
34+
},
35+
module: {
36+
rules: [
37+
{
38+
test: /\.js$/,
39+
use: [
40+
{
41+
loader: 'babel-loader',
42+
options: {
43+
plugins: ['@babel/plugin-transform-object-assign'],
44+
},
45+
},
46+
],
47+
},
48+
],
49+
},
50+
plugins: [
51+
new webpack.NormalModuleReplacementPlugin(
52+
/^tapable\/lib\/SyncBailHook/,
53+
path.join(__dirname, 'modules/logger/SyncBailHookFake.js')
54+
),
55+
],
56+
}),
57+
merge(baseForModules, {
58+
entry: path.join(__dirname, 'modules/strip-ansi/index.js'),
59+
output: {
60+
filename: 'strip-ansi/index.js',
61+
},
62+
}),
63+
merge(baseForModules, {
64+
entry: path.join(__dirname, 'modules/sockjs-client/index.js'),
65+
output: {
66+
filename: 'sockjs-client/index.js',
67+
library: 'SockJS',
68+
libraryTarget: 'umd',
69+
},
70+
}),
71+
];

lib/servers/SockJSServer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ const BaseServer = require('./BaseServer');
1212
{
1313
const SockjsSession = require('sockjs/lib/transport').Session;
1414
const decorateConnection = SockjsSession.prototype.decorateConnection;
15+
1516
// eslint-disable-next-line func-names
1617
SockjsSession.prototype.decorateConnection = function (req) {
1718
decorateConnection.call(this, req);
19+
1820
const connection = this.connection;
21+
1922
if (
2023
connection.headers &&
2124
!('origin' in connection.headers) &&

lib/utils/DevServerPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DevServerPlugin {
5555

5656
/** @type {string} */
5757
const clientEntry = `${require.resolve(
58-
'../../client/default/'
58+
'../../client/'
5959
)}?${domain}${host}${path}${port}`;
6060

6161
/** @type {(string[] | string)} */

lib/utils/getSocketClientPath.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
function getSocketClientPath(options) {
44
let ClientImplementation;
55
let clientImplFound = true;
6+
67
switch (typeof options.transportMode.client) {
78
case 'string':
89
// could be 'sockjs', 'ws', or a path that should be required

lib/utils/routes.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@ function routes(server) {
1313
app.get('/__webpack_dev_server__/sockjs.bundle.js', (req, res) => {
1414
res.setHeader('Content-Type', 'application/javascript');
1515

16-
createReadStream(join(clientBasePath, 'sockjs/sockjs.bundle.js')).pipe(res);
17-
});
18-
19-
app.get('/webpack-dev-server.js', (req, res) => {
20-
res.setHeader('Content-Type', 'application/javascript');
21-
22-
createReadStream(join(clientBasePath, 'default/index.bundle.js')).pipe(res);
16+
createReadStream(
17+
join(clientBasePath, 'modules/sockjs-client/index.js')
18+
).pipe(res);
2319
});
2420

2521
app.get('/webpack-dev-server/invalidate', (_req, res) => {

0 commit comments

Comments
 (0)