Skip to content

Commit

Permalink
chore: use modules in client
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed May 10, 2021
1 parent 297a649 commit a251431
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 62 deletions.
8 changes: 8 additions & 0 deletions client-src/.eslintrc.js
@@ -0,0 +1,8 @@
module.exports = {
extends: ['../.eslintrc.js'],
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
allowImportExportEverywhere: true,
},
};
6 changes: 3 additions & 3 deletions client-src/clients/BaseClient.js
@@ -1,8 +1,8 @@
'use strict';

module.exports = class BaseClient {

export default class BaseClient {
// eslint-disable-next-line no-unused-vars
static getClientPath(options) {
throw new Error('Client needs implementation');
}
};
}
12 changes: 6 additions & 6 deletions client-src/clients/SockJSClient.js
@@ -1,10 +1,10 @@
'use strict';

const SockJS = require('../modules/sockjs-client');
const { log } = require('../utils/log');
const BaseClient = require('./BaseClient');

module.exports = class SockJSClient extends BaseClient {
import SockJS from '../modules/sockjs-client';
import { log } from '../utils/log';
import BaseClient from './BaseClient';

export default class SockJSClient extends BaseClient {
constructor(url) {
super();

Expand Down Expand Up @@ -36,4 +36,4 @@ module.exports = class SockJSClient extends BaseClient {
f(e.data);
};
}
};
}
10 changes: 5 additions & 5 deletions client-src/clients/WebsocketClient.js
@@ -1,9 +1,9 @@
'use strict';

const { log } = require('../utils/log');
const BaseClient = require('./BaseClient');

module.exports = class WebsocketClient extends BaseClient {
import { log } from '../utils/log';
import BaseClient from './BaseClient';

export default class WebsocketClient extends BaseClient {
constructor(url) {
super();

Expand Down Expand Up @@ -32,4 +32,4 @@ module.exports = class WebsocketClient extends BaseClient {
f(e.data);
};
}
};
}
21 changes: 11 additions & 10 deletions client-src/index.js
@@ -1,16 +1,17 @@
'use strict';


/* global __resourceQuery WorkerGlobalScope */

const webpackHotLog = require('webpack/hot/log');
const stripAnsi = require('./modules/strip-ansi');
const parseURL = require('./utils/parseURL');
const socket = require('./socket');
const overlay = require('./overlay');
const { log, setLogLevel } = require('./utils/log');
const sendMessage = require('./utils/sendMessage');
const reloadApp = require('./utils/reloadApp');
const createSocketURL = require('./utils/createSocketURL');
// eslint-disable-next-line import/no-extraneous-dependencies
import webpackHotLog from 'webpack/hot/log';
import stripAnsi from './modules/strip-ansi';
import parseURL from './utils/parseURL';
import socket from './socket';
import overlay from './overlay';
import { log, setLogLevel } from './utils/log';
import sendMessage from './utils/sendMessage';
import reloadApp from './utils/reloadApp';
import createSocketURL from './utils/createSocketURL';

const status = {
isUnloading: false,
Expand Down
6 changes: 3 additions & 3 deletions client-src/modules/logger/SyncBailHookFake.js
@@ -1,10 +1,10 @@
'use strict';


/**
* Client stub for tapable SyncBailHook
*/
module.exports = function clientTapableSyncBailHook() {
export default function clientTapableSyncBailHook() {
return {
call() {},
};
};
}
7 changes: 4 additions & 3 deletions client-src/modules/logger/index.js
@@ -1,6 +1,7 @@
'use strict';


// eslint-disable-next-line import/no-extraneous-dependencies
require('core-js/stable/symbol');
import 'core-js/stable/symbol';

module.exports = require('webpack/lib/logging/runtime');
// eslint-disable-next-line import/no-extraneous-dependencies
export * from 'webpack/lib/logging/runtime';
4 changes: 2 additions & 2 deletions client-src/modules/sockjs-client/index.js
@@ -1,4 +1,4 @@
'use strict';


// eslint-disable-next-line import/no-extraneous-dependencies
module.exports = require('sockjs-client');
export * from 'sockjs-client';
5 changes: 3 additions & 2 deletions client-src/modules/strip-ansi/index.js
@@ -1,3 +1,4 @@
'use strict';

module.exports = require('strip-ansi');

// eslint-disable-next-line import/no-extraneous-dependencies
export * from 'strip-ansi';
10 changes: 6 additions & 4 deletions client-src/overlay.js
@@ -1,10 +1,12 @@
'use strict';


// The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app)
// They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware).

const ansiHTML = require('ansi-html');
const { encode } = require('html-entities');
// eslint-disable-next-line import/no-extraneous-dependencies
import ansiHTML from 'ansi-html';
// eslint-disable-next-line import/no-extraneous-dependencies
import { encode } from 'html-entities';

const colors = {
reset: ['transparent', 'transparent'],
Expand Down Expand Up @@ -125,7 +127,7 @@ function showMessage(messages) {
});
}

module.exports = {
export default {
clear,
showMessage,
};
4 changes: 2 additions & 2 deletions client-src/socket.js
@@ -1,4 +1,4 @@
'use strict';


/* global __webpack_dev_server_client__ */
/* eslint-disable
Expand Down Expand Up @@ -54,4 +54,4 @@ const socket = function initSocket(url, handlers) {
});
};

module.exports = socket;
export default socket;
6 changes: 3 additions & 3 deletions client-src/utils/createSocketURL.js
@@ -1,6 +1,6 @@
'use strict';

const url = require('url');

import url from 'url';

// We handle legacy API that is Node.js specific, and a newer API that implements the same WHATWG URL Standard used by web browsers
// Please look at https://nodejs.org/api/url.html#url_url_strings_and_url_objects
Expand Down Expand Up @@ -93,4 +93,4 @@ function createSocketURL(parsedURL) {
});
}

module.exports = createSocketURL;
export default createSocketURL;
4 changes: 2 additions & 2 deletions client-src/utils/getCurrentScriptSource.js
@@ -1,4 +1,4 @@
'use strict';


function getCurrentScriptSource() {
// `document.currentScript` is the most accurate way to find the current script,
Expand All @@ -25,4 +25,4 @@ function getCurrentScriptSource() {
throw new Error('[webpack-dev-server] Failed to get current script source.');
}

module.exports = getCurrentScriptSource;
export default getCurrentScriptSource;
6 changes: 3 additions & 3 deletions client-src/utils/log.js
@@ -1,6 +1,6 @@
'use strict';

const logger = require('../modules/logger');

import logger from '../modules/logger';

const name = 'webpack-dev-server';
// default level is set on the client side, so it does not need
Expand All @@ -13,4 +13,4 @@ function setLogLevel(level) {

setLogLevel(defaultLevel);

module.exports = { log: logger.getLogger(name), setLogLevel };
export default { log: logger.getLogger(name), setLogLevel };
8 changes: 4 additions & 4 deletions client-src/utils/parseURL.js
@@ -1,7 +1,7 @@
'use strict';

const url = require('url');
const getCurrentScriptSource = require('./getCurrentScriptSource');

import url from 'url';
import getCurrentScriptSource from './getCurrentScriptSource';

function parseURL(resourceQuery) {
let options;
Expand Down Expand Up @@ -45,4 +45,4 @@ function parseURL(resourceQuery) {
return options;
}

module.exports = parseURL;
export default parseURL;
7 changes: 4 additions & 3 deletions client-src/utils/reloadApp.js
@@ -1,6 +1,6 @@
'use strict';

const { log } = require('./log');

import { log } from './log';

function reloadApp(
{ hotReload, hot, liveReload },
Expand All @@ -13,6 +13,7 @@ function reloadApp(
if (hot) {
log.info('App hot update...');

// eslint-disable-next-line import/no-extraneous-dependencies
const hotEmitter = require('webpack/hot/emitter');

hotEmitter.emit('webpackHotUpdate', currentHash);
Expand Down Expand Up @@ -51,4 +52,4 @@ function reloadApp(
}
}

module.exports = reloadApp;
export default reloadApp;
4 changes: 2 additions & 2 deletions client-src/utils/sendMessage.js
@@ -1,4 +1,4 @@
'use strict';


/* global __resourceQuery WorkerGlobalScope */

Expand All @@ -13,4 +13,4 @@ function sendMsg(type, data) {
}
}

module.exports = sendMsg;
export default sendMsg;
12 changes: 7 additions & 5 deletions client-src/webpack.config.js
@@ -1,8 +1,10 @@
'use strict';

const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');

import path from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
import webpack from 'webpack';
// eslint-disable-next-line import/no-extraneous-dependencies
import { merge } from 'webpack-merge';

const baseForModules = {
devtool: false,
Expand All @@ -26,7 +28,7 @@ const baseForModules = {
},
};

module.exports = [
export default [
merge(baseForModules, {
entry: path.join(__dirname, 'modules/logger/index.js'),
output: {
Expand Down
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -64,6 +64,7 @@
"devDependencies": {
"@babel/cli": "^7.13.16",
"@babel/core": "^7.14.0",
"@babel/eslint-parser": "^7.13.14",
"@babel/plugin-transform-object-assign": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.14.1",
Expand Down

0 comments on commit a251431

Please sign in to comment.