Skip to content

Commit 29e142a

Browse files
committed
normalise windows absolute paths to posix format in log messages
1 parent aab579b commit 29e142a

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

packages/resolve-url-loader/lib/join-function/debug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const pathToString = (absolutePath) => {
2222
const segments =
2323
(relative[0] !== '..') ? ['.'].concat(relative).filter(Boolean) :
2424
(relative.lastIndexOf('..') < 2) ? relative :
25-
absolutePath.split(path.sep);
25+
absolutePath.replace(/^[A-Z]\:/, '').split(path.sep);
2626
return segments.join('/');
2727
}
2828
};

packages/resolve-url-loader/lib/join-function/debug.test.js

+25-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55
'use strict';
66

7-
const {resolve} = require('path');
7+
const {resolve, sep} = require('path');
8+
const {platform} = require('os');
89
const tape = require('blue-tape');
910
const sinon = require('sinon');
1011
const outdent = require('outdent');
@@ -17,6 +18,15 @@ const json = (strings, ...substitutions) =>
1718
...substitutions.map(v => JSON.stringify(v, (_, vv) => Number.isNaN(vv) ? 'NaN' : vv))
1819
);
1920

21+
const cwd = (...args) =>
22+
resolve(...String.raw(...args).split('/'));
23+
24+
const root = (...args) =>
25+
resolve(
26+
platform() === 'win32' ? (process.cwd().split(sep).shift() + sep) : sep,
27+
...String.raw(...args).split('/')
28+
);
29+
2030
tape(
2131
'debug',
2232
({name, test, end: end1, equal, looseEqual}) => {
@@ -25,16 +35,16 @@ tape(
2535
// absolute within cwd
2636
[
2737
[
28-
resolve('my-source-file.js'),
38+
cwd`my-source-file.js`,
2939
'my-asset.png',
3040
[
3141
{
32-
base: resolve('foo'),
33-
joined: resolve('foo', 'my-asset.png'),
42+
base: cwd`foo`,
43+
joined: cwd`foo/my-asset.png`,
3444
isSuccess: false
3545
}, {
36-
base: resolve('bar', 'baz'),
37-
joined: resolve('bar', 'baz', 'my-asset.png'),
46+
base: cwd`bar/baz`,
47+
joined: cwd`bar/baz/my-asset.png`,
3848
isSuccess: true
3949
}
4050
]
@@ -49,24 +59,24 @@ tape(
4959
// absolute otherwise
5060
[
5161
[
52-
'/my-source-file.js',
53-
'#anything\\./goes',
62+
root`my-source-file.js`,
63+
'#anything@./goes',
5464
[
5565
{
56-
base: '/foo',
57-
joined: '/foo/#anything\\./goes',
66+
base: root`foo`,
67+
joined: root`foo/#anything@./goes`,
5868
isSuccess: false
5969
}, {
60-
base: '/bar/baz',
61-
joined: '/bar/baz/#anything\\./goes',
70+
base: root`bar/baz`,
71+
joined: root`bar/baz/#anything@./goes`,
6272
isSuccess: false
6373
}
6474
]
6575
],
6676
outdent`
67-
resolve-url-loader: /my-source-file.js: #anything\\./goes
68-
/foo --> /foo/#anything\\./goes
69-
/bar/baz --> /bar/baz/#anything\\./goes
77+
resolve-url-loader: /my-source-file.js: #anything@./goes
78+
/foo --> /foo/#anything@./goes
79+
/bar/baz --> /bar/baz/#anything@./goes
7080
NOT FOUND
7181
`
7282
],

0 commit comments

Comments
 (0)