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(server): move publicPath changes from CLI to API #2099

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
5 changes: 5 additions & 0 deletions client-src/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parserOptions": {
"sourceType": "module"
}
}
2 changes: 0 additions & 2 deletions client-src/clients/BaseClient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

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

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

/* global WebSocket */

/* eslint-disable
Expand Down
30 changes: 15 additions & 15 deletions client-src/default/index.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
import client from 'sockjs-client';

module.exports = require('sockjs-client');
export default client;
2 changes: 0 additions & 2 deletions client-src/sockjs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

module.exports = {
mode: 'production',
output: {
Expand Down
3 changes: 1 addition & 2 deletions globalSetupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const ports = require('./test/ports-map');
async function validatePorts() {
const samples = [];

Object.keys(ports).forEach((key) => {
const value = ports[key];
Object.entries(ports).forEach(([key, value]) => {
const arr = Array.isArray(value) ? value : [value];

arr.forEach((port) => {
Expand Down
13 changes: 2 additions & 11 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@
]
},
"clientLogLevel": {
"enum": [
"info",
"warn",
"error",
"debug",
"trace",
"silent",
"none",
"warning"
]
"enum": ["info", "warn", "error", "debug", "trace", "silent"]
},
"clientMode": {
"type": "string"
Expand Down Expand Up @@ -395,7 +386,7 @@
"bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverbonjour)",
"ca": "should be {String|Buffer}",
"cert": "should be {String|Buffer}",
"clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'none', 'silent', 'info', 'debug', 'trace', 'error', 'warning', 'warn' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
"clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'silent', 'info', 'debug', 'trace', 'error', 'warn' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)",
"clientMode": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserverclientmode)",
"compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)",
"contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)",
Expand Down
Loading