Skip to content

Commit

Permalink
Fix asset httpServerLocation on Windows.
Browse files Browse the repository at this point in the history
Summary:
Functions from the path module return paths with the native file system path separator. generateAssetModule is using path.join and path.dirname to generate httpServerLocation.  That means that on Windows systems, the generated URL path has backslashes rather than forward slashes which breaks the app's ability to retrieve image assets using require('./image.png').  This change fixes this by checking path.sep and replacing backslashes with slashes on systems that require it.
Closes #4416

Reviewed By: svcscm

Differential Revision: D2740529

Pulled By: mkonicek

fb-gh-sync-id: edae0f6762c7dc1db7af078209e38a2feab1e0a1
  • Loading branch information
David Anderson authored and facebook-github-bot-9 committed Dec 9, 2015
1 parent 053a229 commit fe3686e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packager/react-packager/src/Bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ class Bundler {

generateAssetModule(bundle, module, platform = null) {
const relPath = getPathRelativeToRoot(this._projectRoots, module.path);
var assetUrlPath = path.join('/assets', path.dirname(relPath));

// On Windows, change backslashes to slashes to get proper URL path from file path.
if (path.sep === '\\') {
assetUrlPath = assetUrlPath.replace(/\\/g, '/');
}

return Promise.all([
sizeOf(module.path),
Expand All @@ -374,7 +380,7 @@ class Bundler {
const img = {
__packager_asset: true,
fileSystemLocation: path.dirname(module.path),
httpServerLocation: path.join('/assets', path.dirname(relPath)),
httpServerLocation: assetUrlPath,
width: dimensions.width / module.resolution,
height: dimensions.height / module.resolution,
scales: assetData.scales,
Expand Down

1 comment on commit fe3686e

@bosung90
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you my friend!

Please sign in to comment.