composer and npm

This commit is contained in:
Henry Whitaker
2020-08-25 00:59:44 +01:00
parent 6726d93cc6
commit c8f853dc84
2504 changed files with 88530 additions and 41367 deletions

View File

@@ -118,7 +118,7 @@ class Server {
this.setupDevMiddleware();
// set express routes
routes(this.app, this.middleware, this.options);
routes(this);
// Keep track of websocket proxies for external websocket upgrade.
this.websocketProxies = [];
@@ -155,6 +155,10 @@ class Server {
}
this.sockWrite(this.sockets, 'progress-update', { percent, msg });
if (this.listeningApp) {
this.listeningApp.emit('progress-update', { percent, msg });
}
}).apply(this.compiler);
}
@@ -342,8 +346,17 @@ class Server {
const contentBasePublicPath = this.options.contentBasePublicPath;
if (Array.isArray(contentBase)) {
contentBase.forEach((item) => {
this.app.use(contentBasePublicPath, express.static(item));
contentBase.forEach((item, index) => {
let publicPath = contentBasePublicPath;
if (
Array.isArray(contentBasePublicPath) &&
contentBasePublicPath[index]
) {
publicPath = contentBasePublicPath[index] || contentBasePublicPath[0];
}
this.app.use(publicPath, express.static(item));
});
} else if (isAbsoluteUrl(String(contentBase))) {
this.log.warn(
@@ -401,7 +414,7 @@ class Server {
return next();
}
serveIndex(item)(req, res, next);
serveIndex(item, { icons: true })(req, res, next);
});
});
} else if (
@@ -414,7 +427,7 @@ class Server {
return next();
}
serveIndex(contentBase)(req, res, next);
serveIndex(contentBase, { icons: true })(req, res, next);
});
}
}
@@ -674,6 +687,10 @@ class Server {
} else {
this.listeningApp = http.createServer(this.app);
}
this.listeningApp.on('error', (err) => {
this.log.error(err);
});
}
createSocketServer() {

View File

@@ -52,7 +52,18 @@
"type": "boolean"
},
"contentBasePublicPath": {
"type": "string"
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
},
"minItems": 1
}
]
},
"contentBase": {
"anyOf": [
@@ -208,6 +219,9 @@
},
{
"type": "boolean"
},
{
"type": "object"
}
]
},
@@ -449,7 +463,7 @@
"mimeTypes": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devservermimetypes-)",
"noInfo": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservernoinfo-)",
"onListening": "should be {Function} (https://webpack.js.org/configuration/dev-server/#onlistening)",
"open": "should be {String|Boolean} (https://webpack.js.org/configuration/dev-server/#devserveropen)",
"open": "should be {String|Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserveropen)",
"openPage": "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devserveropenpage)",
"overlay": "should be {Boolean|Object} (https://webpack.js.org/configuration/dev-server/#devserveroverlay)",
"pfx": "should be {String|Buffer} (https://webpack.js.org/configuration/dev-server/#devserverpfx)",
@@ -463,7 +477,7 @@
"quiet": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverquiet-)",
"reporter": "should be {Function} (https://github.com/webpack/webpack-dev-middleware#reporter)",
"requestCert": "should be {Boolean}",
"contentBasePublicPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devservercontentbasepublicpath)",
"contentBasePublicPath": "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbasepublicpath)",
"serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)",
"serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)",
"setup": "should be {Function} (https://webpack.js.org/configuration/dev-server/#devserversetup)",

View File

@@ -31,11 +31,13 @@ module.exports = class WebsocketServer extends BaseServer {
const noop = () => {};
setInterval(() => {
this.wsServer.clients.forEach((ws) => {
if (ws.isAlive === false) return ws.terminate();
this.wsServer.clients.forEach((socket) => {
if (socket.isAlive === false) {
return socket.terminate();
}
ws.isAlive = false;
ws.ping(noop);
socket.isAlive = false;
socket.ping(noop);
});
}, this.server.heartbeatInterval);
}

View File

@@ -68,7 +68,14 @@ function addEntries(config, options, server) {
Object.keys(originalEntry).forEach((key) => {
// entry[key] should be a string here
clone[key] = prependEntry(originalEntry[key], additionalEntries);
const entryDescription = originalEntry[key];
if (typeof entryDescription === 'object' && entryDescription.import) {
clone[key] = Object.assign({}, entryDescription, {
import: prependEntry(entryDescription.import, additionalEntries),
});
} else {
clone[key] = prependEntry(entryDescription, additionalEntries);
}
});
return clone;

View File

@@ -5,7 +5,11 @@ const { join } = require('path');
const clientBasePath = join(__dirname, '..', '..', 'client');
function routes(app, middleware, options) {
function routes(server) {
const app = server.app;
const middleware = server.middleware;
const options = server.options;
app.get('/__webpack_dev_server__/live.bundle.js', (req, res) => {
res.setHeader('Content-Type', 'application/javascript');
@@ -24,6 +28,11 @@ function routes(app, middleware, options) {
createReadStream(join(clientBasePath, 'index.bundle.js')).pipe(res);
});
app.get('/webpack-dev-server/invalidate', (_req, res) => {
server.invalidate();
res.end();
});
app.get('/webpack-dev-server/*', (req, res) => {
res.setHeader('Content-Type', 'text/html');

View File

@@ -11,6 +11,9 @@ function runOpen(uri, options, log) {
if (typeof options.open === 'string') {
openOptions = Object.assign({}, openOptions, { app: options.open });
openOptionValue = `: "${options.open}"`;
} else if (typeof options.open === 'object') {
openOptions = options.open;
openOptionValue = `: "${JSON.stringify(options.open)}"`;
}
const pages =

View File

@@ -5,7 +5,7 @@ const signals = ['SIGINT', 'SIGTERM'];
function setupExitSignals(serverData) {
signals.forEach((signal) => {
process.on(signal, () => {
if (serverData.server) {
if (serverData && serverData.server) {
serverData.server.close(() => {
// eslint-disable-next-line no-process-exit
process.exit();