From 014fd4d0380e738355d830e9132740ab419e9f79 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 6 Sep 2017 10:14:39 -0400 Subject: [PATCH 1/4] Switch to unix path separators before normalizing path for Windows compatibility --- packages/react-error-overlay/src/utils/unmapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-error-overlay/src/utils/unmapper.js b/packages/react-error-overlay/src/utils/unmapper.js index 60b2bee432..524b525875 100644 --- a/packages/react-error-overlay/src/utils/unmapper.js +++ b/packages/react-error-overlay/src/utils/unmapper.js @@ -56,7 +56,7 @@ async function unmap( } let { fileName } = frame; if (fileName) { - fileName = path.normalize(fileName); + fileName = path.normalize(fileName.replace(/[\\]+/g, '/')); } if (fileName == null) { return frame; From 742baceef97e767527498a2ad8b2ab66ad748333 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 6 Sep 2017 11:10:41 -0400 Subject: [PATCH 2/4] Add comment for posterity --- .../react-error-overlay/src/utils/unmapper.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/react-error-overlay/src/utils/unmapper.js b/packages/react-error-overlay/src/utils/unmapper.js index 524b525875..dc34af3265 100644 --- a/packages/react-error-overlay/src/utils/unmapper.js +++ b/packages/react-error-overlay/src/utils/unmapper.js @@ -27,6 +27,25 @@ function count(search: string, string: string): number { return count; } +function normalizePath(_path: string): string { + // `path.normalize` cleans a file path, (e.g. /foo//baz/..//bar/ becomes + // /foo/bar/). + // The web version of this module only provides POSIX support, so Windows + // paths like C:\foo\\baz\..\\bar\ cannot be normalized. + // A simple solution to this is to replace all `\` with `/`, then normalize + // afterwards. + // + // Note: + // `path.normalize` supports POSIX forward slashes on Windows, but not the + // other way around. Converting all backslashes to forward slashes before + // normalizing makes this cross platform if it were isomorphic (used server + // side). + return path.normalize( + // Match contiguous backslashes + _path.replace(/[\\]+/g, '/') + ); +} + /** * Turns a set of mapped StackFrames back into their generated code position and enhances them with code. * @param {string} fileUri The URI of the bundle.js file. @@ -56,7 +75,7 @@ async function unmap( } let { fileName } = frame; if (fileName) { - fileName = path.normalize(fileName.replace(/[\\]+/g, '/')); + fileName = normalizePath(fileName); } if (fileName == null) { return frame; @@ -64,7 +83,7 @@ async function unmap( const fN: string = fileName; const source = map .getSources() - .map(s => s.replace(/[\\]+/g, '/')) + .map(normalizePath) .filter(p => { p = path.normalize(p); const i = p.lastIndexOf(fN); From 8441f95d82648f801d9e9fb1bbc8499b82ecf71e Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 6 Sep 2017 11:15:07 -0400 Subject: [PATCH 3/4] Revert "Add comment for posterity" This reverts commit 742baceef97e767527498a2ad8b2ab66ad748333. --- .../react-error-overlay/src/utils/unmapper.js | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/packages/react-error-overlay/src/utils/unmapper.js b/packages/react-error-overlay/src/utils/unmapper.js index dc34af3265..524b525875 100644 --- a/packages/react-error-overlay/src/utils/unmapper.js +++ b/packages/react-error-overlay/src/utils/unmapper.js @@ -27,25 +27,6 @@ function count(search: string, string: string): number { return count; } -function normalizePath(_path: string): string { - // `path.normalize` cleans a file path, (e.g. /foo//baz/..//bar/ becomes - // /foo/bar/). - // The web version of this module only provides POSIX support, so Windows - // paths like C:\foo\\baz\..\\bar\ cannot be normalized. - // A simple solution to this is to replace all `\` with `/`, then normalize - // afterwards. - // - // Note: - // `path.normalize` supports POSIX forward slashes on Windows, but not the - // other way around. Converting all backslashes to forward slashes before - // normalizing makes this cross platform if it were isomorphic (used server - // side). - return path.normalize( - // Match contiguous backslashes - _path.replace(/[\\]+/g, '/') - ); -} - /** * Turns a set of mapped StackFrames back into their generated code position and enhances them with code. * @param {string} fileUri The URI of the bundle.js file. @@ -75,7 +56,7 @@ async function unmap( } let { fileName } = frame; if (fileName) { - fileName = normalizePath(fileName); + fileName = path.normalize(fileName.replace(/[\\]+/g, '/')); } if (fileName == null) { return frame; @@ -83,7 +64,7 @@ async function unmap( const fN: string = fileName; const source = map .getSources() - .map(normalizePath) + .map(s => s.replace(/[\\]+/g, '/')) .filter(p => { p = path.normalize(p); const i = p.lastIndexOf(fN); From 5be590a108f9fe5f18eabb7ff916f72f4bae7229 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 6 Sep 2017 11:16:57 -0400 Subject: [PATCH 4/4] Strictly add comment --- packages/react-error-overlay/src/utils/unmapper.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-error-overlay/src/utils/unmapper.js b/packages/react-error-overlay/src/utils/unmapper.js index 524b525875..40f4528c0e 100644 --- a/packages/react-error-overlay/src/utils/unmapper.js +++ b/packages/react-error-overlay/src/utils/unmapper.js @@ -56,6 +56,10 @@ async function unmap( } let { fileName } = frame; if (fileName) { + // The web version of this module only provides POSIX support, so Windows + // paths like C:\foo\\baz\..\\bar\ cannot be normalized. + // A simple solution to this is to replace all `\` with `/`, then + // normalize afterwards. fileName = path.normalize(fileName.replace(/[\\]+/g, '/')); } if (fileName == null) { @@ -64,6 +68,7 @@ async function unmap( const fN: string = fileName; const source = map .getSources() + // Prepare path for normalization; see comment above for reasoning. .map(s => s.replace(/[\\]+/g, '/')) .filter(p => { p = path.normalize(p);