@@ -11,6 +11,8 @@ const crypto = require('crypto');
1111const invariant = require ( 'invariant' ) ;
1212const path = require ( 'path' ) ;
1313
14+ const backwardSlashRegExp = / \\ / g;
15+
1416const OFFLINE_CACHE_EXTENSION = `.zip` ;
1517
1618type PackageInformation = { |
@@ -100,7 +102,7 @@ function generateFindPackageLocator(packageInformationStores: PackageInformation
100102
101103 // Generate a function that, given a file path, returns the associated package name
102104 code += `exports.findPackageLocator = function findPackageLocator(location) {\n` ;
103- code += ` let relativeLocation = path.relative(__dirname, location);\n` ;
105+ code += ` let relativeLocation = normalizePath( path.relative(__dirname, location) );\n` ;
104106 code += `\n` ;
105107 code += ` if (!relativeLocation.match(isStrictRegExp))\n` ;
106108 code += ` relativeLocation = \`./\${relativeLocation}\`;\n` ;
@@ -136,7 +138,7 @@ async function getPackageInformationStores(
136138 const blacklistedLocations : Set < string > = new Set ( ) ;
137139
138140 const getCachePath = ( fsPath : string ) => {
139- const cacheRelativePath = path . relative ( config . cacheFolder , fsPath ) ;
141+ const cacheRelativePath = normalizePath ( path . relative ( config . cacheFolder , fsPath ) ) ;
140142
141143 // if fsPath is not inside cacheRelativePath, we just skip it
142144 if ( cacheRelativePath . match ( / ^ \. \. \/ / ) ) {
@@ -164,8 +166,12 @@ async function getPackageInformationStores(
164166 return path . resolve ( offlineCacheFolder , `${ cacheEntry } ${ OFFLINE_CACHE_EXTENSION } ` , internalPath . join ( '/' ) ) ;
165167 } ;
166168
169+ const normalizePath = ( fsPath : string ) = > {
170+ return process . platform === 'win32' ? fsPath . replace ( backwardSlashRegExp , '/' ) : fsPath ;
171+ } ;
172+
167173 const normalizeDirectoryPath = ( fsPath : string ) => {
168- let relativePath = path . relative ( targetDirectory , resolveOfflineCacheFolder ( fsPath ) ) ;
174+ let relativePath = normalizePath ( path . relative ( targetDirectory , resolveOfflineCacheFolder ( fsPath ) ) ) ;
169175
170176 if ( ! relativePath . match ( / ^ \. { 0 , 2 } \/ / ) ) {
171177 relativePath = `./${ relativePath } ` ;
0 commit comments