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
This commit is contained in:
Jhen 2016-12-27 14:40:34 -08:00 committed by Facebook Github Bot
parent 8e9549fb2b
commit 033e7a0d6f
2 changed files with 2 additions and 2 deletions

View File

@ -77,7 +77,7 @@ module.exports = class Package {
let relPath = './' + path.relative(this.root, name); let relPath = './' + path.relative(this.root, name);
if (path.sep !== '/') { if (path.sep !== '/') {
relPath = relPath.replace(path.sep, '/'); relPath = relPath.replace(new RegExp('\\' + path.sep, 'g'), '/');
} }
let redirect = replacements[relPath]; let redirect = replacements[relPath];

View File

@ -97,7 +97,7 @@ class Package {
let relPath = './' + path.relative(this.root, name); let relPath = './' + path.relative(this.root, name);
if (path.sep !== '/') { if (path.sep !== '/') {
relPath = relPath.replace(path.sep, '/'); relPath = relPath.replace(new RegExp('\\' + path.sep, 'g'), '/');
} }
let redirect = replacements[relPath]; let redirect = replacements[relPath];