From 29e142a3ce41c53b75b5078b2d233ad04cc007fa Mon Sep 17 00:00:00 2001 From: Ben Holloway Date: Thu, 20 May 2021 19:46:16 +1000 Subject: [PATCH] normalise windows absolute paths to posix format in log messages --- .../lib/join-function/debug.js | 2 +- .../lib/join-function/debug.test.js | 40 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/resolve-url-loader/lib/join-function/debug.js b/packages/resolve-url-loader/lib/join-function/debug.js index 7224f3d..eafe3f8 100644 --- a/packages/resolve-url-loader/lib/join-function/debug.js +++ b/packages/resolve-url-loader/lib/join-function/debug.js @@ -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('/'); } }; diff --git a/packages/resolve-url-loader/lib/join-function/debug.test.js b/packages/resolve-url-loader/lib/join-function/debug.test.js index 07067e0..0c1f35f 100644 --- a/packages/resolve-url-loader/lib/join-function/debug.test.js +++ b/packages/resolve-url-loader/lib/join-function/debug.test.js @@ -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'); @@ -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}) => { @@ -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 } ] @@ -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 ` ],