Support `false` mappings in `"browser"` fields

Summary:
This adds support for `false` values in `package.json` `"browser"` and `"react-native"` mappings.
All `false` values are not longer silently ignored, but redirected to an empty file.

Fixes #9854 #9518

Reviewed By: bestander

Differential Revision: D3876521

fbshipit-source-id: 96d1ba03518812bc88c51672c374956eabd40c9b
This commit is contained in:
David Aurelio 2016-09-16 06:05:22 -07:00 committed by Facebook Github Bot 7
parent 0c157bea36
commit 5710b230a2
2 changed files with 13 additions and 3 deletions

View File

@ -17,6 +17,8 @@ const realPath = require('path');
const isAbsolutePath = require('absolute-path');
const getAssetDataFromName = require('../lib/getAssetDataFromName');
const emptyModule = require.resolve('./assets/empty-module.js');
class ResolutionRequest {
constructor({
platform,
@ -193,7 +195,7 @@ class ResolutionRequest {
if (recursive) {
// doesn't block the return of this function invocation, but defers
// the resulution of collectionsInProgress.done.then()
// the resulution of collectionsInProgress.done.then(...)
dependencyModules
.forEach(dependency => collectedDependencies.get(dependency));
}
@ -322,7 +324,7 @@ class ResolutionRequest {
return this._redirectRequire(fromModule, potentialModulePath).then(
realModuleName => {
if (realModuleName === false) {
return null;
return this._loadAsFile(emptyModule, fromModule, toModuleName);
}
return this._tryResolve(
@ -341,7 +343,7 @@ class ResolutionRequest {
realModuleName => {
// exclude
if (realModuleName === false) {
return null;
return this._loadAsFile(emptyModule, fromModule, toModuleName);
}
if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) {

View File

@ -0,0 +1,8 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/