From 7827a02e32ff173d8f2a3ef2458b13f0f6668363 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 25 Sep 2015 07:39:06 -0700 Subject: [PATCH] Revert packager module randomization --- .../DependencyGraph/HasteMap.js | 45 +++++-------------- .../DependencyGraph/ResolutionRequest.js | 7 +-- .../src/lib/getPlatformExtension.js | 2 +- 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js b/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js index 0b87cd1e..576ea3e0 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/HasteMap.js @@ -8,9 +8,8 @@ */ 'use strict'; -const chalk = require('chalk'); const path = require('path'); -const getPlatformExtension = require('../../lib/getPlatformExtension'); +const getPontentialPlatformExt = require('../../lib/getPlatformExtension'); class HasteMap { constructor({ fastfs, moduleCache, helpers }) { @@ -18,7 +17,6 @@ class HasteMap { this._moduleCache = moduleCache; this._helpers = helpers; this._map = Object.create(null); - this._warnedAbout = Object.create(null); } build() { @@ -37,9 +35,6 @@ class HasteMap { processFileChange(type, absPath) { return Promise.resolve().then(() => { - // Rewarn after file changes. - this._warnedAbout = Object.create(null); - /*eslint no-labels: 0 */ if (type === 'delete' || type === 'change') { loop: for (let name in this._map) { @@ -69,39 +64,19 @@ class HasteMap { } getModule(name, platform = null) { - if (!this._map[name]) { - return null; - } - - const modules = this._map[name]; - if (platform != null) { - for (let i = 0; i < modules.length; i++) { - if (getPlatformExtension(modules[i].path) === platform) { - return modules[i]; + if (this._map[name]) { + const modules = this._map[name]; + if (platform != null) { + for (let i = 0; i < modules.length; i++) { + if (getPontentialPlatformExt(modules[i].path) === platform) { + return modules[i]; + } } } - if (modules.length > 1) { - if (!this._warnedAbout[name]) { - this._warnedAbout[name] = true; - console.warn( - chalk.yellow( - '\nWARNING: Found multiple haste modules or packages ' + - 'with the name `%s`. Please fix this by adding it to ' + - 'the blacklist or deleting the modules keeping only one.\n' + - 'One of the following modules will be selected at random:\n%s\n' - ), - name, - modules.map(m => m.path).join('\n'), - ); - } - - const randomIndex = Math.floor(Math.random() * modules.length); - return modules[randomIndex]; - } + return modules[0]; } - - return modules[0]; + return null; } _processHasteModule(file) { diff --git a/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js b/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js index 2ed0dc9f..3be6abd9 100644 --- a/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js +++ b/react-packager/src/DependencyResolver/DependencyGraph/ResolutionRequest.js @@ -252,11 +252,6 @@ class ResolutionRequest { _loadAsFile(potentialModulePath) { return Promise.resolve().then(() => { if (this._helpers.isAssetFile(potentialModulePath)) { - const dirname = path.dirname(potentialModulePath); - if (!this._fastfs.dirExists(dirname)) { - throw new UnableToResolveError(`Directory ${dirname} doesn't exist`); - } - const {name, type} = getAssetDataFromName(potentialModulePath); let pattern = '^' + name + '(@[\\d\\.]+x)?'; @@ -268,7 +263,7 @@ class ResolutionRequest { // We arbitrarly grab the first one, because scale selection // will happen somewhere const [assetFile] = this._fastfs.matches( - dirname, + path.dirname(potentialModulePath), new RegExp(pattern) ); diff --git a/react-packager/src/lib/getPlatformExtension.js b/react-packager/src/lib/getPlatformExtension.js index 417cd866..3f34da42 100644 --- a/react-packager/src/lib/getPlatformExtension.js +++ b/react-packager/src/lib/getPlatformExtension.js @@ -10,7 +10,7 @@ const path = require('path'); -const SUPPORTED_PLATFORM_EXTS = ['android', 'ios', 'web']; +const SUPPORTED_PLATFORM_EXTS = ['android', 'ios']; const re = new RegExp( '[^\\.]+\\.(' + SUPPORTED_PLATFORM_EXTS.join('|') + ')\\.\\w+$'