Skip to content

Commit

Permalink
refactoring for 2.0.0 (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape authored Dec 13, 2017
1 parent 8db8794 commit e9407b7
Show file tree
Hide file tree
Showing 38 changed files with 8,448 additions and 1,607 deletions.
16 changes: 10 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
root = true
# editorconfig.org

[*.js]
indent_style=tab
trim_trailing_whitespace=true

[*.yml,package.json]
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[.md]
insert_final_newline = false
trim_trailing_whitespace = false
65 changes: 13 additions & 52 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,54 +1,15 @@
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"rules": {
"indent": [2, "tab", { "SwitchCase": 1 }],
"brace-style": ["error", "1tbs"],
"quotes": ["error", "double"],
"semi": "error",
"no-eval": "error",
"eol-last": "error",
"no-redeclare": "error",
"no-extra-bind": "error",
"no-process-exit": "error",
"no-inner-declarations": "warn",
"no-loop-func": "warn",
"no-undef": "error",
"no-trailing-spaces": "error",
"space-before-function-paren": ["error", "never"],
"no-multi-spaces": "error",
"space-in-parens": "error",
"space-before-blocks": "error",
"no-unused-vars": "error",
"no-dupe-keys": "error",
"valid-typeof": "error",
"object-curly-spacing": ["error", "always"],
"key-spacing": "error",
"space-infix-ops": "error",
"no-negated-in-lhs": "error",
"no-octal": "error",
"no-regex-spaces": "error",
"no-self-assign": "error",
"no-sparse-arrays": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-invalid-regexp": "error",
"keyword-spacing": ["error", {
"after": false,
"overrides": {
"try": {"after": true},
"else": {"after": true},
"throw": {"after": true},
"case": {"after": true},
"return": {"after": true},
"finally": {"after": true},
"do": {"after": true}
}
}]
}
"extends": "webpack",
"parserOptions": {
"sourceType": "script"
},
"rules": {
"brace-style": ["error", "1tbs", { allowSingleLine: false }],
"comma-dangle": ["error", "never"],
"curly": ["error"],
"consistent-return": "off",
"no-param-reassign": "off",
"no-undefined": "off",
"strict": ["error", "safe"]
}
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/node_modules
/coverage
node_modules
coverage
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
sudo: false
language: node_js

node_js:
- "4"
- "6"
- "7"
- "8"
script: npm run travis
- '9'
- '8'
- '6'

script:
npm run ci

after_success:
- cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js
- rm -rf ./coverage
18 changes: 18 additions & 0 deletions breaking-changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Node Version Support

webpack-dev-middleware version 2 and higher will only support Node 6.x and higher. Active
LTS for Node 4.x ended October 31st, 2017 and entered maintenance on that date.
Likewise, the version 1.x branch of webpack-dev-middleware will enter maintenance on
that date.

## Informative Changes

- logging is now handled by `log-level` and follows the same patterns as
`webpack-dev-server`.

## Breaking Changes

- `reportTime` option renamed to `logTime`
- `noInfo` option removed in favor of setting a `logLevel` higher than `'info'`
- `quiet` option removed in favor of `logLevel: 'silent'`
- `reporter` signature changed to `reporter(middlewareOptions, reporterOptions)`
95 changes: 95 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

const mime = require('mime');
const createContext = require('./lib/context');
const middleware = require('./lib/middleware');
const reporter = require('./lib/reporter');
const { getFilenameFromUrl, noop, ready, setFs } = require('./lib/util');

require('loud-rejection/register');

const defaults = {
logLevel: 'info',
logTime: false,
logger: null,
mimeTypes: null,
reporter,
stats: {
context: process.cwd()
},
watchOptions: {
aggregateTimeout: 200
}
};

module.exports = function wdm(compiler, opts) {
const options = Object.assign({}, defaults, opts);

if (options.lazy) {
if (typeof options.filename === 'string') {
const filename = options.filename
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') // eslint-disable-line no-useless-escape
.replace(/\\\[[a-z]+\\\]/ig, '.+');

options.filename = new RegExp(`^[/]{0,1}${filename}$`);
}
}

// defining custom MIME type
if (options.mimeTypes) {
mime.define(options.mimeTypes);
}

const context = createContext(compiler, options);

// start watching
if (!options.lazy) {
const watching = compiler.watch(options.watchOptions, (err) => {
if (err) {
context.log.error(err.stack || err);
if (err.details) {
context.log.error(err.details);
}
}
});

context.watching = watching;
} else {
context.state = true;
}

setFs(context, compiler);

return Object.assign(middleware(context), {
close(callback) {
callback = callback || noop;

if (context.watching) {
context.watching.close(callback);
} else {
callback();
}
},

context,

fileSystem: context.fs,

getFilenameFromUrl: getFilenameFromUrl.bind(this, context.options.publicPath, context.compiler),

invalidate(callback) {
callback = callback || noop;
if (context.watching) {
ready(context, callback, {});
context.watching.invalidate();
} else {
callback();
}
},

waitUntilValid(callback) {
callback = callback || noop;
ready(context, callback, {});
}
});
};
63 changes: 0 additions & 63 deletions lib/GetFilenameFromUrl.js

This file was deleted.

5 changes: 0 additions & 5 deletions lib/PathJoin.js

This file was deleted.

Loading

0 comments on commit e9407b7

Please sign in to comment.