From 033e7a0d6f401e6f2c3f91f1bd0055d51f940376 Mon Sep 17 00:00:00 2001 From: Jhen Date: Tue, 27 Dec 2016 14:40:34 -0800 Subject: [PATCH] Fix the `path.sep` replacement of node-haste for Windows Summary: Fix the `path.sep` replacement for Windows, currently it just replace one segment: ```js // Result: './lib/random\random-byte.js' './lib\\random\\random-byte.js'.replace(path.sep, '/') ``` Change to regex will work fine: ```js // Result: './lib/random/random-byte.js' (correct) './lib\\random\\random-byte.js'.replace(new RegExp('\\' + path.sep, 'g'), '/') ``` Closes https://github.com/facebook/react-native/pull/11641 Differential Revision: D4368402 fbshipit-source-id: 46f456359d1cd2ca790881773e8a76af8616cd21 --- react-packager/src/ModuleGraph/node-haste/Package.js | 2 +- react-packager/src/node-haste/Package.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/react-packager/src/ModuleGraph/node-haste/Package.js b/react-packager/src/ModuleGraph/node-haste/Package.js index 861a15f2..ad328d7a 100644 --- a/react-packager/src/ModuleGraph/node-haste/Package.js +++ b/react-packager/src/ModuleGraph/node-haste/Package.js @@ -77,7 +77,7 @@ module.exports = class Package { let relPath = './' + path.relative(this.root, name); if (path.sep !== '/') { - relPath = relPath.replace(path.sep, '/'); + relPath = relPath.replace(new RegExp('\\' + path.sep, 'g'), '/'); } let redirect = replacements[relPath]; diff --git a/react-packager/src/node-haste/Package.js b/react-packager/src/node-haste/Package.js index 118e822c..e77f9c22 100644 --- a/react-packager/src/node-haste/Package.js +++ b/react-packager/src/node-haste/Package.js @@ -97,7 +97,7 @@ class Package { let relPath = './' + path.relative(this.root, name); if (path.sep !== '/') { - relPath = relPath.replace(path.sep, '/'); + relPath = relPath.replace(new RegExp('\\' + path.sep, 'g'), '/'); } let redirect = replacements[relPath];