Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rlamana/webpack-dev-server
Browse files Browse the repository at this point in the history
…into hmr-use-location-port

# Conflicts:
#	package-lock.json
  • Loading branch information
rlamana committed Feb 27, 2019
2 parents a50b5ab + cb10f83 commit 41222a3
Show file tree
Hide file tree
Showing 33 changed files with 2,650 additions and 446 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @evilebottnawi @michael-ciniawsky
* @evilebottnawi @hiroppy
42 changes: 26 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
sudo: false

git:
depth: 10

branches:
only:
- master
- next

language: node_js

cache:
directories:
- node_modules
- $HOME/.npm

jobs:
matrix:
fast_finish: true
include:
- stage: Lint
env: SCRIPT=lint
node_js: 'stable'
- env: JOB_PART=lint
node_js: 11
- &linux
stage: Test (Linux)
env: SCRIPT=test
node_js: 'stable'
- <<: *linux
env: JOB_PART=test
node_js: 11
- <<: *linux
node_js: 10
Expand All @@ -23,9 +30,8 @@ jobs:
- <<: *linux
node_js: 6
- &osx
stage: Test (MacOS)
os: 'osx'
env: SCRIPT=test
env: JOB_PART=test
node_js: 11
- <<: *osx
node_js: 10
Expand All @@ -34,15 +40,19 @@ jobs:
- <<: *osx
node_js: 6

install:
before_install:
- npm i -g npm@latest
- npm i

script: npm run $SCRIPT
install:
- npm ci

before_script:
- node --version
- npm --version

script:
- npm run $JOB_PART

after_success:
- npm i codecov
- $(npm bin)/codecov

notifications:
email: false
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [3.2.1](https://github.com/webpack/webpack-dev-server/compare/v3.2.0...v3.2.1) (2019-02-25)


### Bug Fixes

* deprecation message about `setup` now warning about `v4` ([#1684](https://github.com/webpack/webpack-dev-server/issues/1684)) ([523a6ec](https://github.com/webpack/webpack-dev-server/commit/523a6ec))
* **regression:** allow `ca`, `key` and `cert` will be string ([#1676](https://github.com/webpack/webpack-dev-server/issues/1676)) ([b8d5c1e](https://github.com/webpack/webpack-dev-server/commit/b8d5c1e))
* **regression:** handle `key`, `cert`, `cacert` and `pfx` in CLI ([#1688](https://github.com/webpack/webpack-dev-server/issues/1688)) ([4b2076c](https://github.com/webpack/webpack-dev-server/commit/4b2076c))
* **regression:** problem with `idb-connector` after update `internal-ip` ([#1691](https://github.com/webpack/webpack-dev-server/issues/1691)) ([eb48691](https://github.com/webpack/webpack-dev-server/commit/eb48691))



<a name="3.1.14"></a>
## [3.1.14](https://github.com/webpack/webpack-dev-server/compare/v3.1.13...v3.1.14) (2018-12-24)

Expand Down
21 changes: 1 addition & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ state, the project only officially supports the _last two versions of major
browsers_. We simply don't have the resources to support every whacky
browser out there.

If you find an bug with an obscure / old browser, we would actively welcome a
If you find a bug with an obscure / old browser, we would actively welcome a
Pull Request to resolve the bug.

## Support
Expand Down Expand Up @@ -128,25 +128,6 @@ out completely._

We welcome your contributions! Please have a read of [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to get involved.

## Maintainers

<table>
<tbody>
<tr>
<td align="center">
<img src="https://avatars.githubusercontent.com/SpaceK33z?v=4&s=150">
<br />
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
</td>
<td align="center">
<img src="https://i.imgur.com/4v6pgxh.png">
<br />
<a href="https://github.com/shellscape">Andrew Powell</a>
</td>
</tr>
</tbody>
</table>

## Attribution

This project is heavily inspired by [peerigon/nof5](https://github.com/peerigon/nof5).
Expand Down
16 changes: 12 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
build: 'off'

cache:
- node_modules
branches:
only:
- master
- next

init:
- git config --global core.autocrlf input

cache:
- node_modules
- '%APPDATA%\npm-cache'

environment:
matrix:
- nodejs_version: '11'
Expand All @@ -23,10 +29,12 @@ matrix:
install:
- ps: Install-Product node $env:nodejs_version x64
- npm i -g npm@latest
- npm i
- npm ci

before_test:
- cmd: npm i webpack@%webpack_version%

test_script:
- cmd: npm t
- node --version
- npm --version
- cmd: npm test
80 changes: 43 additions & 37 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,33 @@

/* eslint-disable
import/order,
import/no-extraneous-dependencies,
global-require,
no-shadow,
no-console,
multiline-ternary,
arrow-parens,
array-bracket-spacing,
space-before-function-paren
no-console
*/
const debug = require('debug')('webpack-dev-server');

const fs = require('fs');
const net = require('net');

const portfinder = require('portfinder');
const importLocal = require('import-local');

const yargs = require('yargs');
const webpack = require('webpack');

const options = require('./options');

const { colors, status, version, bonjour } = require('./utils');

const Server = require('../lib/Server');

const addEntries = require('../lib/utils/addEntries');
const colors = require('../lib/utils/colors');
const createConfig = require('../lib/utils/createConfig');
const createDomain = require('../lib/utils/createDomain');
const createLogger = require('../lib/utils/createLogger');
const createConfig = require('../lib/utils/createConfig');
const defaultTo = require('../lib/utils/defaultTo');
const findPort = require('../lib/utils/findPort');
const getVersions = require('../lib/utils/getVersions');
const runBonjour = require('../lib/utils/runBonjour');
const status = require('../lib/utils/status');
const tryParseInt = require('../lib/utils/tryParseInt');

let server;

Expand Down Expand Up @@ -74,17 +71,20 @@ try {
}

yargs.usage(
`${version()}\nUsage: https://webpack.js.org/configuration/dev-server/`
`${getVersions()}\nUsage: https://webpack.js.org/configuration/dev-server/`
);

// eslint-disable-next-line import/no-extraneous-dependencies
require('webpack-cli/bin/config-yargs')(yargs);

// It is important that this is done after the webpack yargs config,
// so it overrides webpack's version info.
yargs.version(version());
yargs.version(getVersions());
yargs.options(options);

const argv = yargs.argv;

// eslint-disable-next-line import/no-extraneous-dependencies
const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
outputFilename: '/bundle.js',
});
Expand All @@ -94,6 +94,15 @@ const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
// we should use portfinder.
const DEFAULT_PORT = 8080;

// 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
);

function processOptions(config) {
// processOptions {Promise}
if (typeof config.then === 'function') {
Expand All @@ -107,24 +116,7 @@ function processOptions(config) {
}

const options = createConfig(config, argv, { port: DEFAULT_PORT });

portfinder.basePort = DEFAULT_PORT;

if (options.port != null) {
startDevServer(config, options);

return;
}

portfinder.getPort((err, port) => {
if (err) {
throw err;
}

options.port = port;

startDevServer(config, options);
});
startDevServer(config, options);
}

function startDevServer(config, options) {
Expand Down Expand Up @@ -210,21 +202,35 @@ function startDevServer(config, options) {
status(uri, options, log, argv.color);
});
});
} else {
return;
}

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

if (options.bonjour) {
bonjour(options);
runBonjour(options);
}

const uri = createDomain(options, server.listeningApp) + suffix;

status(uri, options, log, argv.color);
});
};

if (options.port) {
startServer();
return;
}

// only run port finder if no port as been specified
findPort(server, DEFAULT_PORT, defaultPortRetry, (err, port) => {
if (err) {
throw err;
}
options.port = port;
startServer();
});
}

processOptions(config);
17 changes: 15 additions & 2 deletions examples/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ const webpack = require('webpack');
module.exports = {
setup(config) {
const defaults = { mode: 'development', plugins: [], devServer: {} };

if (config.entry) {
if (typeof config.entry === 'string') {
config.entry = path.resolve(config.entry);
} else if (Array.isArray(config.entry)) {
config.entry = config.entry.map((entry) => path.resolve(entry));
} else if (typeof config.entry === 'object') {
Object.entries(config.entry).forEach(([key, value]) => {
config.entry[key] = path.resolve(value);
});
}
}

const result = Object.assign(defaults, config);
const before = function before(app) {
app.get('/.assets/*', (req, res) => {
Expand Down Expand Up @@ -40,12 +53,12 @@ module.exports = {

let exampleTitle = '';

renderer.heading = function headingProxy(text, level, raw) {
renderer.heading = function headingProxy(text, level, raw, slugger) {
if (level === 1 && !exampleTitle) {
exampleTitle = text;
}

return heading.call(this, text, level, raw);
return heading.call(this, text, level, raw, slugger);
};

marked.setOptions(markedOptions);
Expand Down
1 change: 1 addition & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"testURL": "http://localhost/",
"collectCoverage": true,
"coveragePathIgnorePatterns": ["test"],
"moduleFileExtensions": ["js", "json"],
"testMatch": ["**/test/**/*.test.js"],
"setupFilesAfterEnv": ["<rootDir>/setupTest.js"]
Expand Down

0 comments on commit 41222a3

Please sign in to comment.