Skip to content

Commit

Permalink
normalise windows absolute paths to posix format in log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bholloway committed May 20, 2021
1 parent aab579b commit 29e142a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/resolve-url-loader/lib/join-function/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const pathToString = (absolutePath) => {
const segments =
(relative[0] !== '..') ? ['.'].concat(relative).filter(Boolean) :
(relative.lastIndexOf('..') < 2) ? relative :
absolutePath.split(path.sep);
absolutePath.replace(/^[A-Z]\:/, '').split(path.sep);
return segments.join('/');
}
};
Expand Down
40 changes: 25 additions & 15 deletions packages/resolve-url-loader/lib/join-function/debug.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/
'use strict';

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

const cwd = (...args) =>
resolve(...String.raw(...args).split('/'));

const root = (...args) =>
resolve(
platform() === 'win32' ? (process.cwd().split(sep).shift() + sep) : sep,
...String.raw(...args).split('/')
);

tape(
'debug',
({name, test, end: end1, equal, looseEqual}) => {
Expand All @@ -25,16 +35,16 @@ tape(
// absolute within cwd
[
[
resolve('my-source-file.js'),
cwd`my-source-file.js`,
'my-asset.png',
[
{
base: resolve('foo'),
joined: resolve('foo', 'my-asset.png'),
base: cwd`foo`,
joined: cwd`foo/my-asset.png`,
isSuccess: false
}, {
base: resolve('bar', 'baz'),
joined: resolve('bar', 'baz', 'my-asset.png'),
base: cwd`bar/baz`,
joined: cwd`bar/baz/my-asset.png`,
isSuccess: true
}
]
Expand All @@ -49,24 +59,24 @@ tape(
// absolute otherwise
[
[
'/my-source-file.js',
'#anything\\./goes',
root`my-source-file.js`,
'#anything@./goes',
[
{
base: '/foo',
joined: '/foo/#anything\\./goes',
base: root`foo`,
joined: root`foo/#anything@./goes`,
isSuccess: false
}, {
base: '/bar/baz',
joined: '/bar/baz/#anything\\./goes',
base: root`bar/baz`,
joined: root`bar/baz/#anything@./goes`,
isSuccess: false
}
]
],
outdent`
resolve-url-loader: /my-source-file.js: #anything\\./goes
/foo --> /foo/#anything\\./goes
/bar/baz --> /bar/baz/#anything\\./goes
resolve-url-loader: /my-source-file.js: #anything@./goes
/foo --> /foo/#anything@./goes
/bar/baz --> /bar/baz/#anything@./goes
NOT FOUND
`
],
Expand Down

0 comments on commit 29e142a

Please sign in to comment.