Skip to content

Commit e9407b7

Browse files
authored
refactoring for 2.0.0 (#233)
1 parent 8db8794 commit e9407b7

38 files changed

+8448
-1607
lines changed

.editorconfig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
root = true
1+
# editorconfig.org
22

3-
[*.js]
4-
indent_style=tab
5-
trim_trailing_whitespace=true
6-
7-
[*.yml,package.json]
3+
[*]
4+
charset = utf-8
85
indent_style = space
96
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[.md]
12+
insert_final_newline = false
13+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,15 @@
11
{
2-
"env": {
3-
"es6": true,
4-
"node": true,
5-
"mocha": true
6-
},
7-
"rules": {
8-
"indent": [2, "tab", { "SwitchCase": 1 }],
9-
"brace-style": ["error", "1tbs"],
10-
"quotes": ["error", "double"],
11-
"semi": "error",
12-
"no-eval": "error",
13-
"eol-last": "error",
14-
"no-redeclare": "error",
15-
"no-extra-bind": "error",
16-
"no-process-exit": "error",
17-
"no-inner-declarations": "warn",
18-
"no-loop-func": "warn",
19-
"no-undef": "error",
20-
"no-trailing-spaces": "error",
21-
"space-before-function-paren": ["error", "never"],
22-
"no-multi-spaces": "error",
23-
"space-in-parens": "error",
24-
"space-before-blocks": "error",
25-
"no-unused-vars": "error",
26-
"no-dupe-keys": "error",
27-
"valid-typeof": "error",
28-
"object-curly-spacing": ["error", "always"],
29-
"key-spacing": "error",
30-
"space-infix-ops": "error",
31-
"no-negated-in-lhs": "error",
32-
"no-octal": "error",
33-
"no-regex-spaces": "error",
34-
"no-self-assign": "error",
35-
"no-sparse-arrays": "error",
36-
"no-unexpected-multiline": "error",
37-
"no-unreachable": "error",
38-
"no-extra-semi": "error",
39-
"no-func-assign": "error",
40-
"no-invalid-regexp": "error",
41-
"keyword-spacing": ["error", {
42-
"after": false,
43-
"overrides": {
44-
"try": {"after": true},
45-
"else": {"after": true},
46-
"throw": {"after": true},
47-
"case": {"after": true},
48-
"return": {"after": true},
49-
"finally": {"after": true},
50-
"do": {"after": true}
51-
}
52-
}]
53-
}
2+
"extends": "webpack",
3+
"parserOptions": {
4+
"sourceType": "script"
5+
},
6+
"rules": {
7+
"brace-style": ["error", "1tbs", { allowSingleLine: false }],
8+
"comma-dangle": ["error", "never"],
9+
"curly": ["error"],
10+
"consistent-return": "off",
11+
"no-param-reassign": "off",
12+
"no-undefined": "off",
13+
"strict": ["error", "safe"]
14+
}
5415
}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/node_modules
2-
/coverage
1+
node_modules
2+
coverage

.travis.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
sudo: false
22
language: node_js
3+
34
node_js:
4-
- "4"
5-
- "6"
6-
- "7"
7-
- "8"
8-
script: npm run travis
5+
- '9'
6+
- '8'
7+
- '6'
8+
9+
script:
10+
npm run ci
11+
912
after_success:
1013
- cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js
1114
- rm -rf ./coverage

breaking-changes.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Node Version Support
2+
3+
webpack-dev-middleware version 2 and higher will only support Node 6.x and higher. Active
4+
LTS for Node 4.x ended October 31st, 2017 and entered maintenance on that date.
5+
Likewise, the version 1.x branch of webpack-dev-middleware will enter maintenance on
6+
that date.
7+
8+
## Informative Changes
9+
10+
- logging is now handled by `log-level` and follows the same patterns as
11+
`webpack-dev-server`.
12+
13+
## Breaking Changes
14+
15+
- `reportTime` option renamed to `logTime`
16+
- `noInfo` option removed in favor of setting a `logLevel` higher than `'info'`
17+
- `quiet` option removed in favor of `logLevel: 'silent'`
18+
- `reporter` signature changed to `reporter(middlewareOptions, reporterOptions)`

index.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
3+
const mime = require('mime');
4+
const createContext = require('./lib/context');
5+
const middleware = require('./lib/middleware');
6+
const reporter = require('./lib/reporter');
7+
const { getFilenameFromUrl, noop, ready, setFs } = require('./lib/util');
8+
9+
require('loud-rejection/register');
10+
11+
const defaults = {
12+
logLevel: 'info',
13+
logTime: false,
14+
logger: null,
15+
mimeTypes: null,
16+
reporter,
17+
stats: {
18+
context: process.cwd()
19+
},
20+
watchOptions: {
21+
aggregateTimeout: 200
22+
}
23+
};
24+
25+
module.exports = function wdm(compiler, opts) {
26+
const options = Object.assign({}, defaults, opts);
27+
28+
if (options.lazy) {
29+
if (typeof options.filename === 'string') {
30+
const filename = options.filename
31+
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') // eslint-disable-line no-useless-escape
32+
.replace(/\\\[[a-z]+\\\]/ig, '.+');
33+
34+
options.filename = new RegExp(`^[/]{0,1}${filename}$`);
35+
}
36+
}
37+
38+
// defining custom MIME type
39+
if (options.mimeTypes) {
40+
mime.define(options.mimeTypes);
41+
}
42+
43+
const context = createContext(compiler, options);
44+
45+
// start watching
46+
if (!options.lazy) {
47+
const watching = compiler.watch(options.watchOptions, (err) => {
48+
if (err) {
49+
context.log.error(err.stack || err);
50+
if (err.details) {
51+
context.log.error(err.details);
52+
}
53+
}
54+
});
55+
56+
context.watching = watching;
57+
} else {
58+
context.state = true;
59+
}
60+
61+
setFs(context, compiler);
62+
63+
return Object.assign(middleware(context), {
64+
close(callback) {
65+
callback = callback || noop;
66+
67+
if (context.watching) {
68+
context.watching.close(callback);
69+
} else {
70+
callback();
71+
}
72+
},
73+
74+
context,
75+
76+
fileSystem: context.fs,
77+
78+
getFilenameFromUrl: getFilenameFromUrl.bind(this, context.options.publicPath, context.compiler),
79+
80+
invalidate(callback) {
81+
callback = callback || noop;
82+
if (context.watching) {
83+
ready(context, callback, {});
84+
context.watching.invalidate();
85+
} else {
86+
callback();
87+
}
88+
},
89+
90+
waitUntilValid(callback) {
91+
callback = callback || noop;
92+
ready(context, callback, {});
93+
}
94+
});
95+
};

lib/GetFilenameFromUrl.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

lib/PathJoin.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)