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

fix: Ensure devServer info message uses actual devServer config #1770

Merged
merged 2 commits into from
Jan 7, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/curvy-clouds-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Fix for devServer info output possibly not matching up against devServer config
1 change: 0 additions & 1 deletion packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports.build = async function buildCommand(src, argv) {
argv.src = src || argv.src;
// add `default:true`s, `--no-*` disables
argv.prerender = toBool(argv.prerender);
argv.production = toBool(argv.production);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

production is not a valid CLI flag, so it's been moved into run-webpack.js with the other derived env values.


let cwd = resolve(argv.cwd);

Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports.watch = async function watchCommand(src, argv) {
argv.refresh = argv.rhl;
}
argv.src = src || argv.src;
argv.production = false;
if (argv.sw) {
argv.sw = toBool(argv.sw);
}
Expand All @@ -22,9 +21,14 @@ exports.watch = async function watchCommand(src, argv) {
// and the current directory differ.
require('dotenv').config({ path: resolve(cwd, '.env') });

argv.https = toBool(process.env.HTTPS || argv.https);
argv.host = process.env.HOST || argv.host;
if (argv.host === '0.0.0.0' && process.platform === 'win32') {
argv.host = 'localhost';
}
argv.port = await determinePort(argv.port);

if (argv.https || process.env.HTTPS) {
if (argv.https) {
let { key, cert, cacert } = argv;
if (key && cert) {
argv.https = { key, cert, ca: cacert };
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/lib/webpack/run-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ async function devBuild(env) {

compiler.hooks.done.tap('CliDevPlugin', stats => {
let devServer = config.devServer;
let protocol = process.env.HTTPS || devServer.https ? 'https' : 'http';
let host = process.env.HOST || devServer.host || 'localhost';
if (host === '0.0.0.0' && process.platform === 'win32') {
host = 'localhost';
}
let serverAddr = `${protocol}://${host}:${bold(env.port)}`;
let localIpAddr = `${protocol}://${ip.address()}:${bold(env.port)}`;
let protocol = devServer.https ? 'https' : 'http';

let serverAddr = `${protocol}://${devServer.host}:${bold(
devServer.port
)}`;
let localIpAddr = `${protocol}://${ip.address()}:${bold(devServer.port)}`;

if (stats.hasErrors()) {
process.stdout.write(red('Build failed!\n\n'));
Expand Down Expand Up @@ -232,6 +231,7 @@ function stripLoaderFromModuleNames(m) {
}

module.exports = function (env, watch = false) {
env.production = !watch;
env.isProd = env.production; // shorthand
env.isWatch = !!watch; // use HMR?
env.cwd = resolve(env.cwd || process.cwd());
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function isDev(env) {
},
https: env.https,
port: env.port,
host: process.env.HOST || env.host || '0.0.0.0',
host: env.host,
allowedHosts: 'all',
historyApiFallback: true,
client: {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports.normalizeTemplatesResponse = function (repos = []) {
};

exports.toBool = function (val) {
return val === void 0 || (val === 'false' ? false : val);
return val !== void 0 && val !== false && !/false|0/.test(val);
};

exports.esmImport = require('esm')(module);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tests/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports.build = async function (cwd, options, installNodeModules = false) {
src: 'src',
dest: 'build',
config: 'preact.config.js',
prerender: true,
prerenderUrls: 'prerender-urls.json',
'inline-css': true,
};
Expand Down