0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,160 @@
'use strict';
const webpack = require('webpack');
const createDomain = require('./createDomain');
/**
* A Entry, it can be of type string or string[] or Object<string | string[],string>
* @typedef {(string[] | string | Object<string | string[],string>)} Entry
*/
/**
* Add entries Method
* @param {?Object} config - Webpack config
* @param {?Object} options - Dev-Server options
* @param {?Object} server
* @returns {void}
*/
function addEntries(config, options, server) {
if (options.inline !== false) {
// we're stubbing the app in this method as it's static and doesn't require
// a server to be supplied. createDomain requires an app with the
// address() signature.
const app = server || {
address() {
return { port: options.port };
},
};
/** @type {string} */
const domain = createDomain(options, app);
/** @type {string} */
const sockHost = options.sockHost ? `&sockHost=${options.sockHost}` : '';
/** @type {string} */
const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : '';
/** @type {string} */
const sockPort = options.sockPort ? `&sockPort=${options.sockPort}` : '';
/** @type {string} */
const clientEntry = `${require.resolve(
'../../client/'
)}?${domain}${sockHost}${sockPath}${sockPort}`;
/** @type {(string[] | string)} */
let hotEntry;
if (options.hotOnly) {
hotEntry = require.resolve('webpack/hot/only-dev-server');
} else if (options.hot) {
hotEntry = require.resolve('webpack/hot/dev-server');
}
/**
* prependEntry Method
* @param {Entry} originalEntry
* @param {Entry} additionalEntries
* @returns {Entry}
*/
const prependEntry = (originalEntry, additionalEntries) => {
if (typeof originalEntry === 'function') {
return () =>
Promise.resolve(originalEntry()).then((entry) =>
prependEntry(entry, additionalEntries)
);
}
if (typeof originalEntry === 'object' && !Array.isArray(originalEntry)) {
/** @type {Object<string,string>} */
const clone = {};
Object.keys(originalEntry).forEach((key) => {
// entry[key] should be a string here
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;
}
// in this case, entry is a string or an array.
// make sure that we do not add duplicates.
/** @type {Entry} */
const entriesClone = additionalEntries.slice(0);
[].concat(originalEntry).forEach((newEntry) => {
if (!entriesClone.includes(newEntry)) {
entriesClone.push(newEntry);
}
});
return entriesClone;
};
/**
*
* Description of the option for checkInject method
* @typedef {Function} checkInjectOptionsParam
* @param {Object} _config - compilerConfig
* @return {Boolean}
*/
/**
*
* @param {Boolean | checkInjectOptionsParam} option - inject(Hot|Client) it is Boolean | fn => Boolean
* @param {Object} _config
* @param {Boolean} defaultValue
* @return {Boolean}
*/
// eslint-disable-next-line no-shadow
const checkInject = (option, _config, defaultValue) => {
if (typeof option === 'boolean') return option;
if (typeof option === 'function') return option(_config);
return defaultValue;
};
// eslint-disable-next-line no-shadow
[].concat(config).forEach((config) => {
/** @type {Boolean} */
const webTarget = [
'web',
'webworker',
'electron-renderer',
'node-webkit',
undefined, // eslint-disable-line
null,
].includes(config.target);
/** @type {Entry} */
const additionalEntries = checkInject(
options.injectClient,
config,
webTarget
)
? [clientEntry]
: [];
if (hotEntry && checkInject(options.injectHot, config, true)) {
additionalEntries.push(hotEntry);
}
config.entry = prependEntry(config.entry || './src', additionalEntries);
if (options.hot || options.hotOnly) {
config.plugins = config.plugins || [];
if (
!config.plugins.find(
// Check for the name rather than the constructor reference in case
// there are multiple copies of webpack installed
(plugin) => plugin.constructor.name === 'HotModuleReplacementPlugin'
)
) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
}
});
}
}
module.exports = addEntries;

View file

@ -0,0 +1,22 @@
'use strict';
const colors = {
info(useColor, msg) {
if (useColor) {
// Make text blue and bold, so it *pops*
return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`;
}
return msg;
},
error(useColor, msg) {
if (useColor) {
// Make text red and bold, so it *pops*
return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`;
}
return msg;
},
};
module.exports = colors;

View file

@ -0,0 +1,69 @@
'use strict';
const selfsigned = require('selfsigned');
function createCertificate(attributes) {
return selfsigned.generate(attributes, {
algorithm: 'sha256',
days: 30,
keySize: 2048,
extensions: [
// {
// name: 'basicConstraints',
// cA: true,
// },
{
name: 'keyUsage',
keyCertSign: true,
digitalSignature: true,
nonRepudiation: true,
keyEncipherment: true,
dataEncipherment: true,
},
{
name: 'extKeyUsage',
serverAuth: true,
clientAuth: true,
codeSigning: true,
timeStamping: true,
},
{
name: 'subjectAltName',
altNames: [
{
// type 2 is DNS
type: 2,
value: 'localhost',
},
{
type: 2,
value: 'localhost.localdomain',
},
{
type: 2,
value: 'lvh.me',
},
{
type: 2,
value: '*.lvh.me',
},
{
type: 2,
value: '[::1]',
},
{
// type 7 is IP
type: 7,
ip: '127.0.0.1',
},
{
type: 7,
ip: 'fe80::1',
},
],
},
],
});
}
module.exports = createCertificate;

View file

@ -0,0 +1,233 @@
'use strict';
const path = require('path');
const isAbsoluteUrl = require('is-absolute-url');
const defaultTo = require('./defaultTo');
function createConfig(config, argv, { port }) {
const firstWpOpt = Array.isArray(config) ? config[0] : config;
const options = firstWpOpt.devServer || {};
// This updates both config and firstWpOpt
firstWpOpt.mode = defaultTo(firstWpOpt.mode, 'development');
if (argv.bonjour) {
options.bonjour = true;
}
if (argv.host && (argv.host !== 'localhost' || !options.host)) {
options.host = argv.host;
}
if (argv.allowedHosts) {
options.allowedHosts = argv.allowedHosts.split(',');
}
if (argv.public) {
options.public = argv.public;
}
if (argv.socket) {
options.socket = argv.socket;
}
if (argv.sockHost) {
options.sockHost = argv.sockHost;
}
if (argv.sockPath) {
options.sockPath = argv.sockPath;
}
if (argv.sockPort) {
options.sockPort = argv.sockPort;
}
if (argv.liveReload === false) {
options.liveReload = false;
}
if (argv.profile) {
options.profile = argv.profile;
}
if (argv.progress) {
options.progress = argv.progress;
}
if (argv.overlay) {
options.overlay = argv.overlay;
}
if (!options.publicPath) {
// eslint-disable-next-line
options.publicPath =
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';
if (
!isAbsoluteUrl(String(options.publicPath)) &&
options.publicPath[0] !== '/'
) {
options.publicPath = `/${options.publicPath}`;
}
}
if (!options.filename && firstWpOpt.output && firstWpOpt.output.filename) {
options.filename = firstWpOpt.output && firstWpOpt.output.filename;
}
if (!options.watchOptions && firstWpOpt.watchOptions) {
options.watchOptions = firstWpOpt.watchOptions;
}
if (argv.stdin) {
process.stdin.on('end', () => {
// eslint-disable-next-line no-process-exit
process.exit(0);
});
process.stdin.resume();
}
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
// We should prefer CLI arg under config, now we always prefer `hot` from `devServer`
if (!options.hot) {
options.hot = argv.hot;
}
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
// We should prefer CLI arg under config, now we always prefer `hotOnly` from `devServer`
if (!options.hotOnly) {
options.hotOnly = argv.hotOnly;
}
// TODO https://github.com/webpack/webpack-dev-server/issues/616 (v4)
// We should prefer CLI arg under config, now we always prefer `clientLogLevel` from `devServer`
if (!options.clientLogLevel && argv.clientLogLevel) {
options.clientLogLevel = argv.clientLogLevel;
}
if (argv.contentBase) {
options.contentBase = argv.contentBase;
if (Array.isArray(options.contentBase)) {
options.contentBase = options.contentBase.map((p) => path.resolve(p));
} else if (/^[0-9]$/.test(options.contentBase)) {
options.contentBase = +options.contentBase;
} else if (!isAbsoluteUrl(String(options.contentBase))) {
options.contentBase = path.resolve(options.contentBase);
}
}
// It is possible to disable the contentBase by using
// `--no-content-base`, which results in arg["content-base"] = false
else if (argv.contentBase === false) {
options.contentBase = false;
}
if (argv.watchContentBase) {
options.watchContentBase = true;
}
if (!options.stats) {
options.stats = defaultTo(firstWpOpt.stats, {
cached: false,
cachedAssets: false,
});
}
if (
typeof options.stats === 'object' &&
typeof options.stats.colors === 'undefined' &&
argv.color
) {
options.stats = Object.assign({}, options.stats, { colors: argv.color });
}
if (argv.lazy) {
options.lazy = true;
}
// TODO remove in `v4`
if (!argv.info) {
options.noInfo = true;
}
// TODO remove in `v4`
if (argv.quiet) {
options.quiet = true;
}
if (argv.https) {
options.https = true;
}
if (argv.http2) {
options.http2 = true;
}
if (argv.key) {
options.key = argv.key;
}
if (argv.cert) {
options.cert = argv.cert;
}
if (argv.cacert) {
options.ca = argv.cacert;
}
if (argv.pfx) {
options.pfx = argv.pfx;
}
if (argv.pfxPassphrase) {
options.pfxPassphrase = argv.pfxPassphrase;
}
if (argv.inline === false) {
options.inline = false;
}
if (argv.historyApiFallback) {
options.historyApiFallback = true;
}
if (argv.compress) {
options.compress = true;
}
if (argv.disableHostCheck) {
options.disableHostCheck = true;
}
if (argv.openPage) {
options.open = true;
options.openPage = argv.openPage.split(',');
}
if (typeof argv.open !== 'undefined') {
options.open = argv.open !== '' ? argv.open : true;
}
if (options.open && !options.openPage) {
options.openPage = '';
}
if (argv.useLocalIp) {
options.useLocalIp = true;
}
// Kind of weird, but ensures prior behavior isn't broken in cases
// that wouldn't throw errors. E.g. both argv.port and options.port
// were specified, but since argv.port is 8080, options.port will be
// tried first instead.
options.port =
argv.port === port
? defaultTo(options.port, argv.port)
: defaultTo(argv.port, options.port);
return options;
}
module.exports = createConfig;

View file

@ -0,0 +1,29 @@
'use strict';
const url = require('url');
const ip = require('internal-ip');
function createDomain(options, server) {
const protocol = options.https ? 'https' : 'http';
const hostname = options.useLocalIp
? ip.v4.sync() || 'localhost'
: options.host || 'localhost';
// eslint-disable-next-line no-nested-ternary
const port = options.socket ? 0 : server ? server.address().port : 0;
// use explicitly defined public url
// (prefix with protocol if not explicitly given)
if (options.public) {
return /^[a-zA-Z]+:\/\//.test(options.public)
? `${options.public}`
: `${protocol}://${options.public}`;
}
// the formatted domain (url without path) of the webpack server
return url.format({
protocol,
hostname,
port,
});
}
module.exports = createDomain;

View file

@ -0,0 +1,23 @@
'use strict';
const log = require('webpack-log');
function createLogger(options = {}) {
let level = options.logLevel || 'info';
if (options.noInfo === true) {
level = 'warn';
}
if (options.quiet === true) {
level = 'silent';
}
return log({
name: 'wds',
level,
timestamp: options.logTime,
});
}
module.exports = createLogger;

View file

@ -0,0 +1,3 @@
'use strict';
module.exports = 8080;

View file

@ -0,0 +1,7 @@
'use strict';
function defaultTo(value, def) {
return value == null ? def : value;
}
module.exports = defaultTo;

View file

@ -0,0 +1,39 @@
'use strict';
const pRetry = require('p-retry');
const portfinder = require('portfinder');
const defaultPort = require('./defaultPort');
const defaultTo = require('./defaultTo');
const tryParseInt = require('./tryParseInt');
function runPortFinder() {
return new Promise((resolve, reject) => {
portfinder.basePort = defaultPort;
portfinder.getPort((error, port) => {
if (error) {
return reject(error);
}
return resolve(port);
});
});
}
function findPort(port) {
if (port) {
return Promise.resolve(port);
}
// Try to find unused port and listen on it for 3 times,
// if port is not specified in options.
// Because NaN == null is false, defaultTo fails if parseInt returns NaN
// so the tryParseInt function is introduced to handle NaN
const defaultPortRetry = defaultTo(
tryParseInt(process.env.DEFAULT_PORT_RETRY),
3
);
return pRetry(runPortFinder, { retries: defaultPortRetry });
}
module.exports = findPort;

View file

@ -0,0 +1,45 @@
'use strict';
const path = require('path');
const fs = require('fs');
const del = require('del');
const createCertificate = require('./createCertificate');
function getCertificate(logger) {
// Use a self-signed certificate if no certificate was configured.
// Cycle certs every 24 hours
const certificatePath = path.join(__dirname, '../../ssl/server.pem');
let certificateExists = fs.existsSync(certificatePath);
if (certificateExists) {
const certificateTtl = 1000 * 60 * 60 * 24;
const certificateStat = fs.statSync(certificatePath);
const now = new Date();
// cert is more than 30 days old, kill it with fire
if ((now - certificateStat.ctime) / certificateTtl > 30) {
logger.info('SSL Certificate is more than 30 days old. Removing.');
del.sync([certificatePath], { force: true });
certificateExists = false;
}
}
if (!certificateExists) {
logger.info('Generating SSL Certificate');
const attributes = [{ name: 'commonName', value: 'localhost' }];
const pems = createCertificate(attributes);
fs.writeFileSync(certificatePath, pems.private + pems.cert, {
encoding: 'utf8',
});
}
return fs.readFileSync(certificatePath);
}
module.exports = getCertificate;

View file

@ -0,0 +1,37 @@
'use strict';
function getSocketClientPath(options) {
let ClientImplementation;
let clientImplFound = true;
switch (typeof options.transportMode.client) {
case 'string':
// could be 'sockjs', 'ws', or a path that should be required
if (options.transportMode.client === 'sockjs') {
ClientImplementation = require('../../client/clients/SockJSClient');
} else if (options.transportMode.client === 'ws') {
ClientImplementation = require('../../client/clients/WebsocketClient');
} else {
try {
// eslint-disable-next-line import/no-dynamic-require
ClientImplementation = require(options.transportMode.client);
} catch (e) {
clientImplFound = false;
}
}
break;
default:
clientImplFound = false;
}
if (!clientImplFound) {
throw new Error(
"transportMode.client must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to " +
'a JS file which exports a class extending BaseClient (webpack-dev-server/client-src/clients/BaseClient) ' +
'via require.resolve(...)'
);
}
return ClientImplementation.getClientPath(options);
}
module.exports = getSocketClientPath;

View file

@ -0,0 +1,42 @@
'use strict';
function getSocketServerImplementation(options) {
let ServerImplementation;
let serverImplFound = true;
switch (typeof options.transportMode.server) {
case 'string':
// could be 'sockjs', in the future 'ws', or a path that should be required
if (options.transportMode.server === 'sockjs') {
ServerImplementation = require('../servers/SockJSServer');
} else if (options.transportMode.server === 'ws') {
ServerImplementation = require('../servers/WebsocketServer');
} else {
try {
// eslint-disable-next-line import/no-dynamic-require
ServerImplementation = require(options.transportMode.server);
} catch (e) {
serverImplFound = false;
}
}
break;
case 'function':
// potentially do more checks here to confirm that the user implemented this properlly
// since errors could be difficult to understand
ServerImplementation = options.transportMode.server;
break;
default:
serverImplFound = false;
}
if (!serverImplFound) {
throw new Error(
"transportMode.server must be a string denoting a default implementation (e.g. 'sockjs', 'ws'), a full path to " +
'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
'via require.resolve(...), or the class itself which extends BaseServer'
);
}
return ServerImplementation;
}
module.exports = getSocketServerImplementation;

View file

@ -0,0 +1,10 @@
'use strict';
function getVersions() {
return (
`webpack-dev-server ${require('../../package.json').version}\n` +
`webpack ${require('webpack/package.json').version}`
);
}
module.exports = getVersions;

View file

@ -0,0 +1,41 @@
'use strict';
/* eslint-disable
no-undefined
*/
function normalizeOptions(compiler, options) {
// Setup default value
options.contentBase =
options.contentBase !== undefined ? options.contentBase : process.cwd();
// Setup default value
options.contentBasePublicPath = options.contentBasePublicPath || '/';
// normalize transportMode option
if (options.transportMode === undefined) {
options.transportMode = {
server: 'sockjs',
client: 'sockjs',
};
} else {
switch (typeof options.transportMode) {
case 'string':
options.transportMode = {
server: options.transportMode,
client: options.transportMode,
};
break;
// if not a string, it is an object
default:
options.transportMode.server = options.transportMode.server || 'sockjs';
options.transportMode.client = options.transportMode.client || 'sockjs';
}
}
if (!options.watchOptions) {
options.watchOptions = {};
}
}
module.exports = normalizeOptions;

View file

@ -0,0 +1,44 @@
'use strict';
const createConfig = require('./createConfig');
const defaultPort = require('./defaultPort');
const findPort = require('./findPort');
function processOptions(config, argv, callback) {
// processOptions {Promise}
if (typeof config.then === 'function') {
config
.then((conf) => processOptions(conf, argv, callback))
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err.stack || err);
// eslint-disable-next-line no-process-exit
process.exit(1);
});
return;
}
// Taken out of yargs because we must know if
// it wasn't given by the user, in which case
// we should use portfinder.
const options = createConfig(config, argv, { port: defaultPort });
if (options.socket) {
callback(config, options);
} else {
findPort(options.port)
.then((port) => {
options.port = port;
callback(config, options);
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err.stack || err);
// eslint-disable-next-line no-process-exit
process.exit(1);
});
}
}
module.exports = processOptions;

View file

@ -0,0 +1,98 @@
'use strict';
const { createReadStream } = require('fs');
const { join } = require('path');
const clientBasePath = join(__dirname, '..', '..', 'client');
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');
createReadStream(join(clientBasePath, 'live.bundle.js')).pipe(res);
});
app.get('/__webpack_dev_server__/sockjs.bundle.js', (req, res) => {
res.setHeader('Content-Type', 'application/javascript');
createReadStream(join(clientBasePath, 'sockjs.bundle.js')).pipe(res);
});
app.get('/webpack-dev-server.js', (req, res) => {
res.setHeader('Content-Type', 'application/javascript');
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');
createReadStream(join(clientBasePath, 'live.html')).pipe(res);
});
app.get('/webpack-dev-server', (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.write(
'<!DOCTYPE html><html><head><meta charset="utf-8"/></head><body>'
);
const outputPath = middleware.getFilenameFromUrl(options.publicPath || '/');
const filesystem = middleware.fileSystem;
writeDirectory(options.publicPath || '/', outputPath);
res.end('</body></html>');
function writeDirectory(baseUrl, basePath) {
const content = filesystem.readdirSync(basePath);
res.write('<ul>');
content.forEach((item) => {
const p = `${basePath}/${item}`;
if (filesystem.statSync(p).isFile()) {
res.write(`<li><a href="${baseUrl + item}">${item}</a></li>`);
if (/\.js$/.test(item)) {
const html = item.substr(0, item.length - 3);
const containerHref = baseUrl + html;
const magicHtmlHref =
baseUrl.replace(
// eslint-disable-next-line
/(^(https?:\/\/[^\/]+)?\/)/,
'$1webpack-dev-server/'
) + html;
res.write(
`<li><a href="${containerHref}">${html}</a>` +
` (magic html for ${item}) (<a href="${magicHtmlHref}">webpack-dev-server</a>)` +
`</li>`
);
}
} else {
res.write(`<li>${item}<br>`);
writeDirectory(`${baseUrl + item}/`, p);
res.write('</li>');
}
});
res.write('</ul>');
}
});
}
module.exports = routes;

View file

@ -0,0 +1,21 @@
'use strict';
function runBonjour({ port }) {
const bonjour = require('bonjour')();
const os = require('os');
bonjour.publish({
name: `Webpack Dev Server ${os.hostname()}:${port}`,
port,
type: 'http',
subtypes: ['webpack'],
});
process.on('exit', () => {
bonjour.unpublishAll(() => {
bonjour.destroy();
});
});
}
module.exports = runBonjour;

View file

@ -0,0 +1,37 @@
'use strict';
const open = require('opn');
const isAbsoluteUrl = require('is-absolute-url');
function runOpen(uri, options, log) {
// https://github.com/webpack/webpack-dev-server/issues/1990
let openOptions = { wait: false };
let openOptionValue = '';
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 =
typeof options.openPage === 'string'
? [options.openPage]
: options.openPage || [''];
return Promise.all(
pages.map((page) => {
const pageUrl = page && isAbsoluteUrl(page) ? page : `${uri}${page}`;
return open(pageUrl, openOptions).catch(() => {
log.warn(
`Unable to open "${pageUrl}" in browser${openOptionValue}. If you are running in a headless environment, please do not use the --open flag`
);
});
})
);
}
module.exports = runOpen;

View file

@ -0,0 +1,21 @@
'use strict';
const signals = ['SIGINT', 'SIGTERM'];
function setupExitSignals(serverData) {
signals.forEach((signal) => {
process.on(signal, () => {
if (serverData && serverData.server) {
serverData.server.close(() => {
// eslint-disable-next-line no-process-exit
process.exit();
});
} else {
// eslint-disable-next-line no-process-exit
process.exit();
}
});
});
}
module.exports = setupExitSignals;

View file

@ -0,0 +1,61 @@
'use strict';
const logger = require('webpack-log');
const colors = require('./colors');
const runOpen = require('./runOpen');
// TODO: don't emit logs when webpack-dev-server is used via Node.js API
function status(uri, options, log, useColor) {
if (options.quiet === true) {
// Add temporary logger to output just the status of the dev server
log = logger({
name: 'wds',
level: 'info',
timestamp: options.logTime,
});
}
const contentBase = Array.isArray(options.contentBase)
? options.contentBase.join(', ')
: options.contentBase;
if (options.socket) {
log.info(`Listening to socket at ${colors.info(useColor, options.socket)}`);
} else {
log.info(`Project is running at ${colors.info(useColor, uri)}`);
}
log.info(
`webpack output is served from ${colors.info(useColor, options.publicPath)}`
);
if (contentBase) {
log.info(
`Content not from webpack is served from ${colors.info(
useColor,
contentBase
)}`
);
}
if (options.historyApiFallback) {
log.info(
`404s will fallback to ${colors.info(
useColor,
options.historyApiFallback.index || '/index.html'
)}`
);
}
if (options.bonjour) {
log.info(
'Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'
);
}
if (options.open) {
runOpen(uri, options, log);
}
}
module.exports = status;

View file

@ -0,0 +1,13 @@
'use strict';
function tryParseInt(input) {
const output = parseInt(input, 10);
if (Number.isNaN(output)) {
return null;
}
return output;
}
module.exports = tryParseInt;

View file

@ -0,0 +1,73 @@
'use strict';
/* eslint-disable
no-shadow,
no-undefined
*/
const webpack = require('webpack');
const addEntries = require('./addEntries');
const getSocketClientPath = require('./getSocketClientPath');
function updateCompiler(compiler, options) {
if (options.inline !== false) {
const findHMRPlugin = (config) => {
if (!config.plugins) {
return undefined;
}
return config.plugins.find(
(plugin) => plugin.constructor === webpack.HotModuleReplacementPlugin
);
};
const compilers = [];
const compilersWithoutHMR = [];
let webpackConfig;
if (compiler.compilers) {
webpackConfig = [];
compiler.compilers.forEach((compiler) => {
webpackConfig.push(compiler.options);
compilers.push(compiler);
if (!findHMRPlugin(compiler.options)) {
compilersWithoutHMR.push(compiler);
}
});
} else {
webpackConfig = compiler.options;
compilers.push(compiler);
if (!findHMRPlugin(compiler.options)) {
compilersWithoutHMR.push(compiler);
}
}
// it's possible that we should clone the config before doing
// this, but it seems safe not to since it actually reflects
// the changes we are making to the compiler
// important: this relies on the fact that addEntries now
// prevents duplicate new entries.
addEntries(webpackConfig, options);
compilers.forEach((compiler) => {
const config = compiler.options;
compiler.hooks.entryOption.call(config.context, config.entry);
const providePlugin = new webpack.ProvidePlugin({
__webpack_dev_server_client__: getSocketClientPath(options),
});
providePlugin.apply(compiler);
});
// do not apply the plugin unless it didn't exist before.
if (options.hot || options.hotOnly) {
compilersWithoutHMR.forEach((compiler) => {
// addDevServerEntrypoints above should have added the plugin
// to the compiler options
const plugin = findHMRPlugin(compiler.options);
if (plugin) {
plugin.apply(compiler);
}
});
}
}
}
module.exports = updateCompiler;