Skip to content

Commit

Permalink
fix: replace url-join with path.join, fixes webpack#333
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang committed Aug 25, 2018
1 parent 610e260 commit e0d9350
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const mime = require('mime');
const urlJoin = require('url-join');
const DevMiddlewareError = require('./DevMiddlewareError');
const { getFilenameFromUrl, handleRangeHeaders, handleRequest, ready } = require('./util');

Expand Down Expand Up @@ -51,7 +51,7 @@ module.exports = function wrapper(context) {
throw new DevMiddlewareError('next');
}

filename = urlJoin(filename, index);
filename = path.join(filename, index);
stat = context.fs.statSync(filename);
if (!stat.isFile()) {
throw new DevMiddlewareError('next');
Expand Down
6 changes: 3 additions & 3 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const path = require('path');
const { parse } = require('url');
const querystring = require('querystring');
const pathabs = require('path-is-absolute');
const parseRange = require('range-parser');
const urlJoin = require('url-join');

const HASH_REGEXP = /[0-9a-f]{10,}/;

Expand Down Expand Up @@ -92,7 +92,7 @@ module.exports = {
if (process.platform === 'win32') {
// Path Handling for Microsoft Windows
if (filename) {
uri = urlJoin((outputPath || ''), querystring.unescape(filename));
uri = path.join((outputPath || ''), querystring.unescape(filename));

if (!pathabs.win32(uri)) {
uri = `/${uri}`;
Expand All @@ -104,7 +104,7 @@ module.exports = {

// Path Handling for all other operating systems
if (filename) {
uri = urlJoin((outputPath || ''), filename);
uri = path.join((outputPath || ''), filename);

if (!pathabs.posix(uri)) {
uri = `/${uri}`;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"mime": "^2.3.1",
"path-is-absolute": "^1.0.0",
"range-parser": "^1.0.3",
"url-join": "^4.0.0",
"webpack-log": "^2.0.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions test/tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ describe('GetFilenameFromUrl', () => {
outputPath: '/root',
publicPath: '/test/',
expected: '/root/sample.txt'
},
{
url: '/test/sample.txt',
outputPath: '/test/#leadinghash',
publicPath: '/',
expected: '/test/#leadinghash/test/sample.txt'
}
];

Expand Down

0 comments on commit e0d9350

Please sign in to comment.