Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(options): Move options from createConfig to normalizeOptions #2174

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
06f6c53
chore: don't support Node6 (#1976)
hiroppy Jun 5, 2019
af76891
refactor(client): make use of ESM instead of CJS (#1967)
hiroppy Jun 5, 2019
fad833a
chore(deps): update dependency ws to v7 (#1834)
renovate[bot] Jun 5, 2019
b32f7a3
chore(deps): update dependency file-loader to v4 (#1971)
renovate[bot] Jun 5, 2019
342fa6a
chore(deps): update dependency chokidar to v3 (#1902)
renovate[bot] Jun 5, 2019
7901428
chore(deps): introduce open and remove opn (#1865)
hiroppy Jun 5, 2019
898461a
chore: fix tests (#1997)
hiroppy Jun 8, 2019
7526664
test: make use of async/await (#1996)
hiroppy Jun 10, 2019
ec86384
feat(client): delete `none` and `warning` from clientLogLevel (#1998)
hiroppy Jun 10, 2019
742aa13
chore: fix code from master
hiroppy Jun 10, 2019
b136055
chore(deps): update dependency p-retry to v4 (#2009)
hiroppy Jun 10, 2019
50b99b6
fix(options): delete none and warning from optinos.json
hiroppy Jun 15, 2019
5c0dced
chore(deps): update url-loader to 2.1.0
hiroppy Aug 5, 2019
1679797
test: update syntax
hiroppy Aug 5, 2019
c600b0e
refactor(server): remove some variables of options (#2175)
hiroppy Aug 5, 2019
27b1913
chore(deps): update del, supports-color, import-local and execa (#2178)
hiroppy Aug 6, 2019
e819cfe
feat(server): add stdin option to API (#2186)
knagaitsev Aug 10, 2019
64036a0
refactor(server): move socket handling into server.listen (#2061)
knagaitsev Aug 22, 2019
97bf133
refactor(options): wip moving options between helpers
knagaitsev Aug 3, 2019
1135766
fix(cli): move back some options that must be in createConfig
knagaitsev Aug 5, 2019
9c087e5
fix(options): only map to absolute paths if not urls
knagaitsev Aug 5, 2019
46a5b6c
test(options): fixed existing normalize opts tests
knagaitsev Aug 5, 2019
a54897b
test(server): add public path option tests to normalize tests
knagaitsev Aug 5, 2019
5d6502e
test(options): add normalize options tests, remove create config tests
knagaitsev Aug 6, 2019
2f5f3b3
refactor(options): removed comments, changed eslint slightly
knagaitsev Aug 7, 2019
80f1f33
refactor(options): move public path option setting to single line
knagaitsev Aug 7, 2019
d942373
refactor(options): fix eslint double empty line, public path two lines
knagaitsev Aug 7, 2019
0e5ede9
refactor(cli): move over more options from create config
knagaitsev Aug 20, 2019
e7ab9f1
style(cli): add eslint no undefined for single line only
knagaitsev Aug 22, 2019
c674e87
refactor(stats): moved stats and colors handling to normalize options
knagaitsev Sep 10, 2019
3e8d32c
test(options): update normalize options snapshot
knagaitsev Sep 11, 2019
69aa911
test(options): mock supports color and fix transport mode
knagaitsev Sep 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc
Expand Up @@ -2,7 +2,11 @@
"extends": ["webpack", "prettier"],
"globals": {
"document": true,
"window": true
"window": true,
"self": true,
"WorkerGlobalScope": true,
"__resourceQuery": true,
"__webpack_dev_server_client__": true
},
"parserOptions": {
"sourceType": "script",
Expand Down
9 changes: 0 additions & 9 deletions azure-pipelines.yml
Expand Up @@ -47,9 +47,6 @@ jobs:
node-8:
node_version: ^8.9.0
webpack_version: latest
node-6:
node_version: ^6.9.0
webpack_version: latest
steps:
- task: NodeTool@0
inputs:
Expand Down Expand Up @@ -98,9 +95,6 @@ jobs:
node-8:
node_version: ^8.9.0
webpack_version: latest
node-6:
node_version: ^6.9.0
webpack_version: latest
steps:
- task: NodeTool@0
inputs:
Expand Down Expand Up @@ -149,9 +143,6 @@ jobs:
node-8:
node_version: ^8.9.0
webpack_version: latest
node-6:
node_version: ^6.9.0
webpack_version: latest
steps:
- script: 'git config --global core.autocrlf input'
displayName: 'Config git core.autocrlf'
Expand Down
34 changes: 0 additions & 34 deletions bin/webpack-dev-server.js
Expand Up @@ -4,8 +4,6 @@

/* eslint-disable no-shadow, no-console */

const fs = require('fs');
const net = require('net');
const debug = require('debug')('webpack-dev-server');
const importLocal = require('import-local');
const yargs = require('yargs');
Expand Down Expand Up @@ -116,42 +114,10 @@ function startDevServer(config, options) {
}

if (options.socket) {
server.listeningApp.on('error', (e) => {
if (e.code === 'EADDRINUSE') {
const clientSocket = new net.Socket();

clientSocket.on('error', (err) => {
if (err.code === 'ECONNREFUSED') {
// No other server listening on this socket so it can be safely removed
fs.unlinkSync(options.socket);

server.listen(options.socket, options.host, (error) => {
if (error) {
throw error;
}
});
}
});

clientSocket.connect({ path: options.socket }, () => {
throw new Error('This socket is already used');
});
}
});

server.listen(options.socket, options.host, (err) => {
if (err) {
throw err;
}

// chmod 666 (rw rw rw)
const READ_WRITE = 438;

fs.chmod(options.socket, READ_WRITE, (err) => {
if (err) {
throw err;
}
});
});
} else {
server.listen(options.port, options.host, (err) => {
Expand Down
5 changes: 5 additions & 0 deletions client-src/.eslintrc
@@ -0,0 +1,5 @@
{
"parserOptions": {
"sourceType": "module"
}
}
2 changes: 0 additions & 2 deletions client-src/clients/BaseClient.js
@@ -1,5 +1,3 @@
'use strict';

/* eslint-disable
no-unused-vars
*/
Expand Down
2 changes: 0 additions & 2 deletions client-src/clients/SockJSClient.js
@@ -1,5 +1,3 @@
'use strict';

/* eslint-disable
no-unused-vars
*/
Expand Down
2 changes: 0 additions & 2 deletions client-src/clients/WebsocketClient.js
@@ -1,5 +1,3 @@
'use strict';

/* global WebSocket */

/* eslint-disable
Expand Down
30 changes: 15 additions & 15 deletions client-src/default/index.js
@@ -1,14 +1,14 @@
'use strict';

/* global __resourceQuery WorkerGlobalScope self */
/* eslint prefer-destructuring: off */
const stripAnsi = require('strip-ansi');
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');
import stripAnsi from 'strip-ansi';
import socket from './socket';
import {
clear as clearOverlay,
showMessage as showMessageOverlay,
} 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 Expand Up @@ -47,7 +47,7 @@ const onSocketMessage = {
log.info('[WDS] App updated. Recompiling...');
// fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
if (options.useWarningOverlay || options.useErrorOverlay) {
overlay.clear();
clearOverlay();
}
sendMessage('Invalid');
},
Expand All @@ -57,7 +57,7 @@ const onSocketMessage = {
'still-ok': function stillOk() {
log.info('[WDS] Nothing changed.');
if (options.useWarningOverlay || options.useErrorOverlay) {
overlay.clear();
clearOverlay();
}
sendMessage('StillOk');
},
Expand Down Expand Up @@ -93,7 +93,7 @@ const onSocketMessage = {
ok() {
sendMessage('Ok');
if (options.useWarningOverlay || options.useErrorOverlay) {
overlay.clear();
clearOverlay();
}
if (options.initial) {
return (options.initial = false);
Expand All @@ -112,7 +112,7 @@ const onSocketMessage = {
log.warn(strippedWarnings[i]);
}
if (options.useWarningOverlay) {
overlay.showMessage(warnings);
showMessageOverlay(warnings);
}

if (options.initial) {
Expand All @@ -128,7 +128,7 @@ const onSocketMessage = {
log.error(strippedErrors[i]);
}
if (options.useErrorOverlay) {
overlay.showMessage(errors);
showMessageOverlay(errors);
}
options.initial = false;
},
Expand Down
19 changes: 6 additions & 13 deletions client-src/default/overlay.js
@@ -1,12 +1,10 @@
'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 { AllHtmlEntities } = require('html-entities');
import ansiHTML from 'ansi-html';
import { AllHtmlEntities as Entities } from 'html-entities';

const entities = new AllHtmlEntities();
const entities = new Entities();
const colors = {
reset: ['transparent', 'transparent'],
black: '181818',
Expand Down Expand Up @@ -95,8 +93,8 @@ function ensureOverlayDivExists(onOverlayDivReady) {
document.body.appendChild(overlayIframe);
}

// Successful compilation.
function clear() {
// successful compilation.
export function clear() {
if (!overlayDiv) {
// It is not there in the first place.
return;
Expand All @@ -110,7 +108,7 @@ function clear() {
}

// Compilation with errors (e.g. syntax error or missing modules).
function showMessage(messages) {
export function showMessage(messages) {
ensureOverlayDivExists((div) => {
// Make it look similar to our terminal.
div.innerHTML = `<span style="color: #${
Expand All @@ -120,8 +118,3 @@ function showMessage(messages) {
)}`;
});
}

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

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

module.exports = socket;
export default socket;
12 changes: 4 additions & 8 deletions client-src/default/utils/createSocketUrl.js
@@ -1,10 +1,6 @@
'use strict';

/* global self */

const url = require('url');
const querystring = require('querystring');
const getCurrentScriptSource = require('./getCurrentScriptSource');
import url from 'url';
import querystring from 'querystring';
import getCurrentScriptSource from './getCurrentScriptSource';

function createSocketUrl(resourceQuery) {
let urlParts;
Expand Down Expand Up @@ -82,4 +78,4 @@ function createSocketUrl(resourceQuery) {
});
}

module.exports = createSocketUrl;
export default createSocketUrl;
4 changes: 1 addition & 3 deletions client-src/default/utils/getCurrentScriptSource.js
@@ -1,5 +1,3 @@
'use strict';

function getCurrentScriptSource() {
// `document.currentScript` is the most accurate way to find the current script,
// but is not supported in all browsers.
Expand All @@ -17,4 +15,4 @@ function getCurrentScriptSource() {
throw new Error('[WDS] Failed to get current script source.');
}

module.exports = getCurrentScriptSource;
export default getCurrentScriptSource;
23 changes: 3 additions & 20 deletions client-src/default/utils/log.js
@@ -1,23 +1,18 @@
'use strict';
import { getLogger } from 'loglevel';

const log = require('loglevel').getLogger('webpack-dev-server');
export const log = getLogger('webpack-dev-server');

const INFO = 'info';
const WARN = 'warn';
const ERROR = 'error';
const DEBUG = 'debug';
const TRACE = 'trace';
const SILENT = 'silent';
// deprecated
// TODO: remove these at major released
// https://github.com/webpack/webpack-dev-server/pull/1825
const WARNING = 'warning';
const NONE = 'none';

// Set the default log level
log.setDefaultLevel(INFO);

function setLogLevel(level) {
export function setLogLevel(level) {
switch (level) {
case INFO:
case WARN:
Expand All @@ -26,22 +21,10 @@ function setLogLevel(level) {
case TRACE:
log.setLevel(level);
break;
// deprecated
case WARNING:
// loglevel's warning name is different from webpack's
log.setLevel('warn');
break;
// deprecated
case NONE:
case SILENT:
log.disableAll();
break;
default:
log.error(`[WDS] Unknown clientLogLevel '${level}'`);
}
}

module.exports = {
log,
setLogLevel,
};
8 changes: 2 additions & 6 deletions client-src/default/utils/reloadApp.js
@@ -1,8 +1,4 @@
'use strict';

/* global WorkerGlobalScope self */

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

function reloadApp(
{ hotReload, hot, liveReload },
Expand Down Expand Up @@ -45,4 +41,4 @@ function reloadApp(
}
}

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

/* global __resourceQuery WorkerGlobalScope self */

// Send messages to the outside, so plugins can consume it.
function sendMsg(type, data) {
function sendMessage(type, data) {
if (
typeof self !== 'undefined' &&
(typeof WorkerGlobalScope === 'undefined' ||
Expand All @@ -19,4 +15,4 @@ function sendMsg(type, data) {
}
}

module.exports = sendMsg;
export default sendMessage;
2 changes: 0 additions & 2 deletions client-src/default/webpack.config.js
@@ -1,5 +1,3 @@
'use strict';

const webpack = require('webpack');

module.exports = {
Expand Down
10 changes: 4 additions & 6 deletions client-src/live/index.js
@@ -1,11 +1,9 @@
'use strict';

/* eslint import/no-extraneous-dependencies: off */

const $ = require('jquery');
const stripAnsi = require('strip-ansi');
const socket = require('../default/socket');
require('./style.css');
import $ from 'jquery';
import stripAnsi from 'strip-ansi';
import socket from '../default/socket';
import './style.css';

let hot = false;
let currentHash = '';
Expand Down
2 changes: 0 additions & 2 deletions client-src/live/webpack.config.js
@@ -1,5 +1,3 @@
'use strict';

const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
Expand Down
4 changes: 2 additions & 2 deletions client-src/sockjs/index.js
@@ -1,3 +1,3 @@
'use strict';
import client from 'sockjs-client';

module.exports = require('sockjs-client');
export default client;